// JavaScript Document

function hidelayers(lay){
	if(document.getElementById([lay]).style.display == "none"){
		document.getElementById([lay]).style.display = "block";
	}else{
		document.getElementById([lay]).style.display = "none";
	}		
}

function validar(){
	if(document.frm.nombre.value==""){
		alert("CUIDADO: Por favor introduzca su nombre");
		document.frm.nombre.focus();
		return false;
	}else if(document.frm.apellido.value==""){
		alert("CUIDADO:Por favor introduzca su apellido");
		document.frm.apellido.focus();
		return false;
	}else if(document.frm.telefono.value==""){
		alert("CUIDADO: Por favor escriba al menos un telefono");
		document.frm.telefono.focus();
		return false;
	}else if(document.frm.email.value==""){
		alert("CUIDADO: Por favor escriba su e-mail");
		document.frm.email.focus();
		return false;
	}else if(document.frm.mensaje.value==""){
		alert("CUIDADO: Por favor escriba el mensaje");
		document.frm.mensaje.focus();
		return false;
	}else{
		return true;	
	}
}



function validar_acceso(url){
	if(document.f1.email.value==""){
		alert("ERROR: ingrese su email ");
		document.f1.email.focus();
		return false;
	}else if(checkemail(document.f1.email.value)== false){
		document.f1.email.value="";
		document.f1.email.focus();
		return false;
	}else if(document.f1.password.value==""){
		alert("ERROR: ingrese password ");
		document.f1.password.focus();
		return false;
	}else{
		document.f1.action = url + "?cuenta=acceso";
		document.f1.submit();
	}	
}

function valida_diselo(){
	if(document.f1.nombre.value==""){
		alert("ERROR: ingrese su nombre ");
		document.f1.nombre.focus()
		return false;
	}else if(document.f1.email.value==""){
		alert("ERROR: ingrese su email ");
		document.f1.email.focus()
		return false;
	}else if(document.f1.nombre_amigo.value==""){
		alert("ERROR: ingrese el nombre de su amigo ");
		document.f1.nombre_amigo.focus()
		return false;
	}else if(document.f1.email_amigo.value==""){
		alert("ERROR: ingrese el email de su amigo ");
		document.f1.email_amigo.focus()
		return false;
	}else if(document.f1.titulo.value==""){
		alert("ERROR: ingrese el titulo de mensaje ");
		document.f1.titulo.focus()
		return false;
	}else if(document.f1.mansaje.value==""){
		alert("ERROR: ingrese el mensaje ");
		document.f1.mansaje.focus()
		return false;
	}else {
		document.f1.action="recomienda.php";
		document.f1.submit();
	}	
}


function validpsw(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	//alert(tecla)
    if (tecla==8 || tecla==46 || tecla==13) 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); 
    verifica= patron.test(te);
	if(verifica==false){
		alert("El caracter que esta tratando de ingresar no se permite");		
		return false;
	}else{
		return true
	}	
	// uso  onKeyPress="return validpsw(event)"
}

function validacaracter(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	//alert(tecla)
    if (tecla==8 || tecla==46 || tecla==13 || tecla==32) 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 validacaracter(event)"
}

function actualiza_producto(){
	document.cesta.action="cesta.php?car=update";
	document.cesta.submit();	
}

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)"
}

function buscar(url,texto){
	document.f2.action=url+'&q='+ texto.value;
	document.f2.submit();
}

	var testresults
	function checkemail(value){
		var str = value
		var filter=/^.+@.+\..{2,3}$/

		if (filter.test(str))
			testresults=true
		else{
			alert("Por favor ingrese un e-mail valido...");
			testresults=false
		}
		return (testresults)
	}	
	
	function clave(value){
		var str = value
		var filter=/^.+@.+\..{2,3}$/
			if (filter.test(str))
		testresults=true
			else{
			alert(" Do not accept specials caracters ")
			testresults=false
		}
		return (testresults)
	}


