// JavaScript Document
function recuperar_acceso(){
		location.replace('index.php?action=recuperar');
}

function eliminar_sesion(){
	location.replace('salir.php');
}

function mantenimiento(url,id,opcion){
	if(opcion!="delete"){ 
		location.replace(url+'?id='+id+'&action='+opcion);
	}else if(opcion=="delete"){
		if(!confirm("Esta Seguro que desea Eliminar el Registro")){
			return false;	
		}else{
			location.replace(url+'?id='+id+'&action='+opcion);			
		}		
	}
}
/*function validar_delete(url){	
	if(!confirm("Esta Seguro que desea Eliminar el Registro")){
		return false;	
	}
}*/
function validar_temas(opcion, id1, id){
	var name=document.f1.nombre;

	if(name.value==""){
		alert(" ERROR: Por favor ingrese el nombre del Tema ");
		name.focus();
		return false
	}	
	if(document.f1.imagen.value=="" && opcion == "addc"){
		alert(" ERROR: Por favor ingrese la imagen del tema ");
		document.f1.imagen.focus();
		return false	
	}else{
		document.f1.action='productos.php?action='+opcion+'&id1='+id1+'&id='+id
		document.f1.submit();
	}
}

function validar_productos(opcion, id1, id){
	
	var name=eval('document.f1.nombre');
	var desc=eval('document.f1.descripcion');

		if(name.value==""){
			alert(" ERROR: Por favor ingrese el nombre del producto ");
			name.focus();
			return false
		}
		if(desc.value==""){
			alert(" ERROR: Por favor ingrese el nombre del Tema ");
			desc.focus();
			return false
		}

	
	document.f1.action='productos.php?action='+opcion+'&id1='+id1+'&id='+id
	document.f1.submit();
	
}

function validar_delete(){
	if(!confirm("Esta Seguro que desea Eliminar el Registro")){
		return false;	
	}else{
		return true;	
	}	
}

function pasa_precio(Obj, receptor, oferta){
	if(Obj.value!=""){
		var indice= Obj.selectedIndex;
		var texto=Obj.options[indice].text;
		var precio=texto.split("�");
		receptor.value=precio[1];
		oferta.readOnly="";
		oferta.focus();
	}else{
		receptor.value="";
		oferta.readOnly="true";
	}
}
	
function compara_monto(precio, oferta){
	if(precio.value!=""){
		if(parseFloat(oferta.value)>=parseFloat(precio.value)){
			alert("El precio de la oferta tiene que ser menor al precio del producto: "+precio.value )		
		}	
	}		
}	

function busqueda(url,texto){
	document.fbuscar.action = url+'&q=' + texto.value;
	document.fbuscar.submit();
}


function checkTheKey(keyCode){
	if(event.keyCode==13){	
		valida();
		return true ;
	}
	return false ;
}
function validnum(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	//alert(tecla)
    if (tecla==8 || tecla==46) return true; //Tecla de retroceso (para poder borrar) 
    // dejar la l�nea de patron que se necesite y borrar el resto 
    //patron =/[A-Za-z]/; // Solo acepta letras 
    patron = /\d/; // Solo acepta n�meros
    //patron = /\w/; // Acepta n�meros y letras 
    //patron = /\D/; // No acepta n�meros 
    // patron = /[\d.-]/; numeros el punto y el signo -
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
	// uso  onKeyPress="return validnum(event)"
}

/* Carrito de Compras */
function actualiza_producto(){
	document.cesta.action="index.php?car=update";
	document.cesta.submit();	
}

function ajax_departamentos(iddis,iddep,idpais,prefijo,sufijo){
	//var d = Math.random();
	//var iddep = $("#cli_departamento").val();
	$("#"+prefijo+"divDepartamento"+sufijo).html('<img src="http://sbs.com.pe/aplication/public_root/imgs/frontend/ajax-loader_barra.gif" width="220" height="19" />');
	$("#"+prefijo+"divDepartamento"+sufijo).load('/sql_departamentos.php?iddis='+iddis+'&iddep='+iddep+'&idpais='+idpais+'&prefijo='+prefijo+'&sufijo='+sufijo);
}

function ajax_distritos(iddis,iddep,prefijo,sufijo){
		//var d = Math.random();
	//var iddep = $("#cli_departamento").val();
	$("#"+prefijo+"divDistrito"+sufijo).html('<img src="http://sbs.com.pe/aplication/public_root/imgs/frontend/ajax-loader_barra.gif" width="220" height="19" />');
	$("#"+prefijo+"divDistrito"+sufijo).load('/sql_distritos.php?iddis='+iddis+'&iddep='+iddep+'&prefijo='+prefijo+'&sufijo='+sufijo);
}

function ajax_calculotarifaenvio(idmen, idpais, iddep, iddis, tipocambio){
	$("#div_tarifaenvio").html('<img src="http://sbs.com.pe/aplication/public_root/imgs/frontend/ajax-loader_barra.gif" width="220" height="19" />');
	$("#div_tarifaenvio").load('/sql_tarifaenvio.php?idmen='+idmen+'&idpais='+idpais+'&iddep='+iddep+'&iddis='+iddis+'&tipocambio='+tipocambio);
}

function ajax_slideshow(idslide, id_idioma_){
	$("#div_slidelibros").html('<img src="http://sbs.com.pe/aplication/public_root/imgs/frontend/ajax-loader_round.gif" width="54" height="55" />');
	$("#div_slidelibros").load('/ajaxslideshow.php?id_slide='+idslide,id_idioma_);
}

function veralert(mensaje){
	alert(mensaje);
}

function mycarousel_initCallback(carousel){
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

/* Validaciones de Formulario */
function validar_registro(tipoForm, nombreForm, id_idioma_){
	
	//alert("1\xDA2\xE13\xE94\xED5\xF36\xFA7\xF18\xD1");
	
	if ((nombreForm.email.value.indexOf ('@', 0) == -1)||(nombreForm.email.value.length < 9)||(nombreForm.email.value.indexOf ('.', 0) == -1)||(nombreForm.email.value == "")){
		
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Por favor ingrese un email v\xe1lido ");
			break;
			case 2:
				alert(" ERROR: Please enter valid ");
			break;
		}
		nombreForm.email.focus();
		nombreForm.email.select();
		return (false);
		
	} else if(document.getElementById('telefono').value==""){
		
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Por favor ingrese el tel\xe9fono ");
			break;
			case 2:
				alert(" ERROR: Please enter the phone ");
			break;
		}
		document.getElementById('telefono').select();				
		document.getElementById('telefono').focus();
		return false;
		
	} else if( document.getElementById('id_pais_fact').selectedIndex==0 ){
		
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Seleccione por favor el pa\xEDs (Facturaci\xf3n)");
			break;
			case 2:
				alert(" ERROR: Please select the country (Billing)");
			break;
		}
		return false;
		
	}
	
  /* Direccion de Facturacion */
	if ( document.getElementById('id_pais_fact').selectedIndex==167 ){
		
		if( document.getElementById('reg_id_departamento_fact').selectedIndex==0 ){
			switch(id_idioma_){
				case 1:
					alert(" ERROR: Seleccione por favor el departamento (Facturaci\xf3n)");
					break;
				case 2:
					alert(" ERROR: Please select the state (Billing)");
					break;
			}
			return false;
		}
		 
		if( document.getElementById('reg_id_departamento_fact').selectedIndex==14 ){
			if(document.getElementById('reg_id_distrito_fact').selectedIndex==0) {
				switch(id_idioma_){
					case 1:
						alert(" ERROR: Seleccione por favor el distrito (Facturaci\xf3n)");
						break;
					case 2:
						alert(" ERROR: Please select the county (Billing)");
						break;
				}
				return false;
			}
		} else {
			if (document.getElementById('reg_distrito_fact').value==""){
				switch(id_idioma_){
					case 1:
						alert(" ERROR: Por favor ingrese el distrito (Facturaci\xf3n)");
						break;
					case 2:
						alert(" ERROR: Please enter the county (Billing)");
						break;
				}
				document.getElementById('reg_distrito_fact').focus();
				document.getElementById('reg_distrito_fact').select();		
				return false;
			}
		}	
	}	else {
		if( document.getElementById('reg_departamento_fact').value=="" ){
			switch(id_idioma_){
				case 1:
					alert(" ERROR: Por favor ingrese el departamento (Facturaci\xf3n)");
					break;
				case 2:
					alert(" ERROR: Please enter the state (Billing)");
					break;
			}
			document.getElementById('reg_departamento_fact').focus();
			document.getElementById('reg_departamento_fact').select();		
			return false;
		} 
		if( document.getElementById('reg_distrito_fact').value=="" ){
			
			switch(id_idioma_){
				case 1:
					alert(" ERROR: Por favor ingrese ingrese el distrito (Facturaci\xf3n)");
					break;
				case 2:
					alert(" ERROR: Please enter the county (Billing)");
					break;
			}
			document.getElementById('reg_distrito_fact').focus();
			document.getElementById('reg_distrito_fact').select();		
			return false;
		} 
	}
	
	if (document.getElementById('direccion_fact').value==""){
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Por favor ingrese su direcci\xf3n (Facturaci\xf3n)");
			break;
			case 2:
				alert(" ERROR: Please enter your address (Billing)");
			break;
		}
		document.getElementById('direccion_fact').focus();
		document.getElementById('direccion_fact').select();		
		return false;
	}
	
  /* Direccion de Envio */
	if( document.getElementById('id_pais_envio').selectedIndex==0 ){
		
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Seleccione por favor el pa\xEDs (Envio)");
			break;
			case 2:
				alert(" ERROR: Please select the country (Shipping)");
			break;
		}
		return false;
		
	}	
	
	if ( document.getElementById('id_pais_envio').selectedIndex==167 ){
		
		if( document.getElementById('reg_id_departamento_envio').selectedIndex==0 ){
			switch(id_idioma_){
				case 1:
					alert(" ERROR: Seleccione por favor el departamento (Envio)");
					break;
				case 2:
					alert(" ERROR: Please select the state (Shipping)");
					break;
			}
			return false;
		}
		 
		if( document.getElementById('reg_id_departamento_envio').selectedIndex==14 ){
			if(document.getElementById('reg_id_distrito_envio').selectedIndex==0) {
				switch(id_idioma_){
					case 1:
						alert(" ERROR: Seleccione por favor el distrito (Envio)");
						break;
					case 2:
						alert(" ERROR: Please select the county (Shipping)");
						break;
				}
				return false;
			}
		} else {
			if (document.getElementById('reg_distrito_envio').value==""){
				switch(id_idioma_){
					case 1:
						alert(" ERROR: Por favor ingrese el distrito (Envio)");
						break;
					case 2:
						alert(" ERROR: Please enter the county (Shipping)");
						break;
				}
				document.getElementById('reg_distrito_envio').focus();
				document.getElementById('reg_distrito_envio').select();		
				return false;
			}
		}	
	}	else {
		if( document.getElementById('reg_departamento_envio').value=="" ){
			switch(id_idioma_){
				case 1:
					alert(" ERROR: Por favor ingrese el departamento (Envio)");
					break;
				case 2:
					alert(" ERROR: Please enter the state (Shipping)");
					break;
			}
			document.getElementById('reg_departamento_envio').focus();
			document.getElementById('reg_departamento_envio').select();		
			return false;
		} 
		if( document.getElementById('reg_distrito_envio').value=="" ){
			
			switch(id_idioma_){
				case 1:
					alert(" ERROR: Por favor ingrese ingrese el distrito (Envio)");
					break;
				case 2:
					alert(" ERROR: Please enter the county (Shipping)");
					break;
			}
			document.getElementById('reg_distrito_envio').focus();
			document.getElementById('reg_distrito_envio').select();		
			return false;
		} 
	}
	
	if (document.getElementById('direccion_envio').value==""){
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Por favor ingrese su direcci\xf3n (Envio)");
			break;
			case 2:
				alert(" ERROR: Please enter your address (Shipping)");
			break;
		}
		document.getElementById('direccion_envio').focus();
		document.getElementById('direccion_envio').select();		
		return false;
	}
	/* ------------------ */
	if (tipoForm=="add"){  // Verificacion del password
		if(document.getElementById('nuevo_password').value==""){
			switch(id_idioma_){
				case 1:
					alert(" ERROR: Por favor ingrese la contrase\xf1a ");
				break;
				case 2:
					alert(" ERROR: Please enter the password ");
				break;
			}
			document.getElementById('nuevo_password').focus();
			return false	
		} else if(document.getElementById('nuevo_password').value!=document.getElementById('password_confirma').value){
			switch(id_idioma_){
				case 1:
					alert(" ERROR: La 'contrase\xf1a' tiene que ser identica al valoe del campo 'confirmar contrase\xf1a' ");
				break;
				case 2:
					alert(" The 'password' must be identical to 'confirm password' field ");
				break;
			}
			document.getElementById('nuevo_password').value=="";
			document.getElementById('password_confirma').value=="";
			document.getElementById('nuevo_password').focus();
			return false;
		}
	}


	return true;
}

/* Validaciones Generales */
/*
function validacaracter(e,ID_DIOMA_) {
	tecla = (document.all) ? e.keyCode : e.which; 
    if (tecla==8 || tecla==46 || tecla==13 || tecla==32) return true; //Tecla de retroceso (para poder borrar) 
    patron = /[[:word:]]\w/;; // Acepta n�meros y letras 
    te = String.fromCharCode(tecla);
    verifica= patron.test(te);
	if(verifica==false){
		if (ID_DIOMA_==1){
			alert("El caracter que esta tratando de ingresar no se permite");
		} else if (ID_DIOMA_==2){		
			alert("The character you are trying to access was not allowed");
		}
		return false;
	}else{
		return true
	}	
}
*/

function validar_change_password(id_idioma_){
	if(document.getElementById('nuevo_password').value==""){
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Por favor ingrese la contrase\xf1a ");
			break;
			case 2:
				alert(" ERROR: Please enter the password ");
			break;
		}
		document.getElementById('nuevo_password').focus();
		return false	
	} else if(document.getElementById('nuevo_password').value!=document.getElementById('password_confirma').value){
		switch(id_idioma_){
			case 1:
				alert(" ERROR: La 'contrase\xf1a' tiene que ser identica al valor del campo 'confirmar contrase\xf1a' ");
			break;
			case 2:
				alert(" ERROR: The 'password' must be identical to 'confirm password' field ");
			break;
		}
		document.getElementById('nuevo_password').value=="";
		document.getElementById('password_confirma').value=="";
		document.getElementById('nuevo_password').focus();
		return false;
	}
	
	if (document.getElementById('nuevo_password').value.length<6){
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Se aceptan un m\xednimo de 6 caracteres para la contrase\xf1a.");
			break;
			case 2:
				alert(" ERROR: Accepted a minimum of 6 characters for the password.");
			break;
		}
		return false;
	}
	
	return true;
}	

function validar_email(id_idioma_){
	if(document.getElementById('email').value==""){
		switch(id_idioma_){
			case 1:
				alert(" ERROR: Por favor ingrese el email ");
			break;
			case 2:
				alert(" ERROR: Please enter your email ");
			break;
		}
		document.getElementById('email').focus();
		return false	
	}
	
	return true;
}	

function goUrl(currentUrl){
	location.href = currentUrl;
}
