var url="http://www.todohobby.cl" 
var titulo="Todohobby.cl - Aeromodelismo, RC Hobby y Accesorios"

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : agregar_favoritos()                                                ---*/
/*---Parámetros  : Ninguno.                                                           ---*/
/*---Retorno     : ninguno.                                                           ---*/
/*---Descripción : Agrega a favoritos la página de todohobby.                         ---*/
/*---Bitácora	 : 07/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/
function agregar_favoritos()
{
	if (document.all)
	window.external.AddFavorite(url,titulo)
}

function desactiva_cuotas()
{
	var f = document.frm;
	
	f.n_cuotas.disabled = true;
	
}
function activa_cuotas()
{
	var f = document.frm;
	
	f.n_cuotas.disabled = false;
	
}

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : valida_ingreso_busqueda()                                          ---*/
/*---Parámetros  : Ninguno.                                                           ---*/
/*---Retorno     : ninguno.                                                           ---*/
/*---Descripción : Agrega a favoritos la página de todohobby.                         ---*/
/*---Bitácora	 : 07/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/
function valida_ingreso_busqueda()
{
	var f = document.frm_buscador;
	
	if(f.strTextoBuscar.value == '')
	{
		alert("Ingrese el texto a buscar");
		f.strTextoBuscar.focus();
		return 0;
	}
	else
		f.submit();
} 

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : derecho()                                                          ---*/
/*---Parámetros  : Ninguno.                                                           ---*/
/*---Retorno     : Ninguno.                                                           ---*/
/*---Descripción : Deshabilita botón derecho en el sitio.                             ---*/
/*---Bitácora	 : 20/04/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/
function derecho(e) 
{
	if (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3))
		return false;
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 3 || event.button == 2)) 
	{
		alert("TodoHobby");
		return false;
	}
	return true;
}

document.onmousedown=derecho;

if (document.layers) window.captureEvents(Event.MOUSEDOWN);
	window.onmousedown=derecho;

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : valida_login()                                                     ---*/
/*---Parámetros  : Ninguno.                                                           ---*/
/*---Retorno     : True or False.                                                     ---*/
/*---Descripción : Valida que se ingresa al menos un usuario y una clave.             ---*/
/*---Bitácora	 : 08/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/
function valida_login()
{
	if(document.login.strUsuario.value=="")
	{
	 	alert("Debe ingresar el usuario");
		document.login.strUsuario.focus();
		return 0;
	}
	else if(document.login.strClave.value=="")
	{
		alert("Debe ingresar su contraseña");
		document.login.strClave.focus();
		return 0;
	}
	else
		document.login.submit();
}

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : valida_recuperaClave()                                             ---*/
/*---Parámetros  : Ninguno.                                                           ---*/
/*---Retorno     : Submit de formulario.                                              ---*/
/*---Descripción : Valida que se ingresa un mail correcto para el envio de clave.     ---*/
/*---Bitácora	 : 09/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/
function valida_recuperaClave()
{
	if(document.envia_clave.strEmail.value=="" || document.envia_clave.strEmail.value.indexOf('@')<0)
	{
	 	alert("Debe ingresar un mail válido");
		document.envia_clave.strEmail.focus();
		return 0;
	}
	else
		document.envia_clave.submit();	
}

/********************************************************************************/
/** FUNCIONES MAMEJO CARRO DE COMPRAS *******************************************/
/********************************************************************************/
function eliminar(codigo)
{
	location.href="agregar_carro.php?accion=q&id="+codigo;
}

function actualizar(codigo,cantidad)
{
	if (trim(document.getElementById(cantidad).value)!="")
	{
		location.href="agregar_carro.php?accion=actualizar&id="+codigo+"&cant="+document.getElementById(cantidad).value;
	}
	else
	{
		alert('valor no valido');
	}
}
	
function entero()
{
	var k=event.keyCode
	//alert(k);
	if (k>=32 && k<45 || k==47 || k>57)
	{
		event.returnValue = false;
	}
				
}

	
/*FUNCION PARA SACAR ESPACIOS EN BLANCO*/
function trim(s)
{
  	while (s.substring(0,1) == ' ') 
	{
    	s = s.substring(1,s.length);
  	}
  	while (s.substring(s.length-1,s.length) == ' ') 
	{
    	s = s.substring(0,s.length-1);
  	}
  	return s;
}

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : siguiente()                                                        ---*/
/*---Parámetros  : Ninguno.                                                           ---*/
/*---Retorno     : Submit de formulario.                                              ---*/
/*---Descripción : Genera el avance de paginas en el carro de compras.                ---*/
/*---Bitácora	 : 09/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/
function siguiente(origen,modo_envio)
{
	/* origen = 2, viene de formas de envio */
	if(origen == 1)
		document.frm.submit();
	else if(origen == 3)
	{
		var valor = document.frm.selFormaPago.options[document.frm.selFormaPago.selectedIndex].value;
		
		if(document.frm.selFormaPago.selectedIndex == 0)
		{
			alert("Seleccione una forma de pago");	
			document.frm.selFormaPago.focus();
			return 0;
		}	
		else if(valor == 6)
		{
			if(document.frm.selNombreTarjeta.selectedIndex == 0)
			{
				alert("Debe seleccionar el nombre de la tarjeta");	
				document.frm.selNombreTarjeta.focus();
				return 0;
			}
			else if(document.frm.numero_tarjeta.value == "")
			{
				alert("Debe ingresar el número de la tarjeta");	
				document.frm.numero_tarjeta.focus();
				return 0;
			}	
			else if(document.frm.mes_vencimiento.selectedIndex == 0)
			{
				alert("Debe ingresar el mes de vencimiento");	
				document.frm.mes_vencimiento.focus();
				return 0;
			}
			else if(document.frm.ano_vencimiento.selectedIndex == 0)
			{
				alert("Debe ingresar el año de vencimiento");	
				document.frm.ano_vencimiento.focus();
				return 0;
			}			
			else
				document.frm.submit();	
		}
		else
			document.frm.submit();
	}
	else
	{
		var contador=0;
		
		for (i=0;i<document.frm.elements.length;i++) 
      		if(document.frm.elements[i].type == "radio")
			{
         		if(document.frm.elements[i].checked) 
					contador++;
			}
			
		if(contador == 0)
		{
			alert("Selecione una forma de envío")
			return 0;
		}
		else if(modo_envio == 3)
		{
			if(document.frm.selTipoCorreo.selectedIndex == 0)
			{
				alert("Debe seleccionar un correo de envío");
				document.frm.selTipoCorreo.focus();
				return 0;
			}
			else
			{
					/* Correo Courier */
				if(document.frm.selTipoCorreo.selectedIndex == 1)
				{
					if(document.frm.selZonaCourier.selectedIndex == 0)
					{
						alert("Debe seleccionar la zona de envío");
						document.frm.selZonaCourier.focus();
						return 0;
					}
					else
						document.frm.submit();
				}
				/* Correo común */
				else if(document.frm.selTipoCorreo.selectedIndex == 2)
				{
		
					if(document.frm.selZonaComun.selectedIndex == 0)
					{
						alert("Debe seleccionar la zona de envío");
						document.frm.selZonaComun.focus();
						return 0;
					}
					else
						document.frm.submit();
				}		
				else
					document.frm.submit();			
			}		
		}
		else
			document.frm.submit();
	}
}

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : cambia_campos_formaPago()                                          ---*/
/*---Parámetros  : Ninguno.                                                           ---*/
/*---Retorno     : Submit de formulario.                                              ---*/
/*---Descripción : Automitiza combo con forma de pago para cargar datos de tarjeta.   ---*/
/*---Bitácora	 : 28/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/
function cambia_campos_formaPago()
{
	var valor = document.frm.selFormaPago.options[document.frm.selFormaPago.selectedIndex].value;
	
	if(valor == 6)
		document.getElementById('info_tarjeta').style.display = '';
	else
		document.getElementById('info_tarjeta').style.display = 'none';

	if(valor == 11)
		document.getElementById('info_deposito').style.display = '';
	else
		document.getElementById('info_deposito').style.display = 'none';

}

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : cagrega_Carro()                                                    ---*/
/*---Parámetros  : stock,ID,glosa.                                                    ---*/
/*---Retorno     : agregar_carro.php.                                                 ---*/
/*---Descripción : Verifica Stock antes de agregar carro y muestra mensaje            ---*/
/*---Bitácora	 : 28/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/
function agrega_carro(intStock,strID,strGlosa)
{
	
	if ( intStock == 0 )
	 alert (strGlosa);
	url = 'carro/agregar_carro.php?accion=agregar&id="';
	url = url.concat(strID,'"');
	window.location= url;
	
}

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : valida_numero(): CalcKeyCode();                                    ---*/
/*---Parámetros  : text object                                                        ---*/
/*---Retorno     : agregar_carro.php.                                                 ---*/
/*---Descripción : Verifica solo numeros                                              ---*/
/*---Bitácora	 : 28/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/

// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function valida_numero(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);
  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

/*---------------------------------------------------------------------------------------*/ 
/*---Función	 : pop_video(url)                                                     ---*/
/*---Parámetros  : URL                                                                ---*/
/*---Retorno     :                                                                    ---*/
/*---Descripción : abre popup                                                         ---*/
/*---Bitácora	 : 28/03/2007 Daniel Bastian: Creación y programación.                ---*/
/*---------------------------------------------------------------------------------------*/

function pop_video(val,vol)
{

var video = val.value;
var num = vol.value;

url="video_popup.php?codigo=";
url= url.concat(video,"&video=");
url = url.concat(num,"");

window.open(url,'Todohobby','width=550,height=600,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=0,left=0');
}