// JavaScript Document

function limpiar (campo, valor){
	elemento = document.getElementById(campo);
	if (elemento.value==valor){
		elemento.value='';
	}
	
}

function agregar_alert(campo, nombre, alerta){

    if(campo.value=="0"||campo.value==""){
        alerta += "El campo "+ nombre + " es obligatorio \n";
        campo.value=nombre;
		campo.style.color='#ff0000';
    }
    return alerta;
    
}


function validar_email(campo, alerta){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   
   	if (!filter.test(campo.value) ) {
           alerta += "Email invalido (Ej. usuario@dominio.com) \n" ;
           campo.style.color='#ff0000';
           campo.value="Email invalido (Ej. usuario@dominio.com)";
	   		
        }
        
        return alerta;
}    

function guardar_comentario()
	{
	var alerta="";
	
	var nombre = document.getElementById("nombre");
	var apellido = document.getElementById("apellido");
	var email = document.getElementById("email");
	var edad = document.getElementById("edad");
	var conociste = document.getElementById("conociste");
	var motivo = document.getElementById("motivo");
	var comentario = document.getElementById("comentario");
	
   	alerta = agregar_alert(nombre,"Nombre",alerta);
	alerta = agregar_alert(apellido,"Apellido",alerta);
	alerta = validar_email(email, alerta);
	
	var parametros = "";
	
	parametros += "nombre="+encodeURIComponent(nombre.value);
	parametros += "&email="+encodeURIComponent(email.value);
	parametros += "&apellido="+encodeURIComponent(apellido.value);
	parametros += "&edad="+encodeURIComponent(edad.value);
	parametros += "&conociste="+encodeURIComponent(conociste.value);
	parametros += "&motivo="+encodeURIComponent(motivo.value);
	parametros += "&comentario="+encodeURIComponent(comentario.value);
	
	if(alerta==""){
		get_pagina({contenedor:"mensaje",page:"admin/comentario/ajax_agregar.php",params:parametros});
		nombre.value="";
		email.value="";
		apellido.value="";
		edad.value="";
		conociste.value="";
		motivo.value="";
		comentario.value="";
		return false;
		
    }else{
        alert(alerta);
        return false;
        
    }
	
}




function guardar_pedido()
	{
	var alerta="";
	
	var nombre = document.getElementById("nombre");
	var apellido = document.getElementById("apellido");
	var email = document.getElementById("email");
	var telefono = document.getElementById("telefono");
	var tabla = document.getElementById("tabla");
	var direccion = document.getElementById("direccion");
	var comentario = document.getElementById("comentario");
	
   	alerta = agregar_alert(nombre,"Nombre",alerta);
	alerta = agregar_alert(apellido,"Apellido",alerta);
	alerta = validar_email(email, alerta);
	alerta = agregar_alert(telefono,"Telefono",alerta);
	alerta = agregar_alert(direccion,"Direccion",alerta);
	
	var parametros = "";
	
	parametros += "nombre="+encodeURIComponent(nombre.value);
	parametros += "&email="+encodeURIComponent(email.value);
	parametros += "&apellido="+encodeURIComponent(apellido.value);
	parametros += "&telefono="+encodeURIComponent(telefono.value);
	parametros += "&tabla="+encodeURIComponent(tabla.value);
	parametros += "&direccion="+encodeURIComponent(direccion.value);
	parametros += "&comentario="+encodeURIComponent(comentario.value);
	
	if(alerta==""){
		get_pagina({contenedor:"mensaje",page:"admin/delivery/ajax_agregar.php",params:parametros});
		nombre.value="";
		email.value="";
		apellido.value="";
		telefono.value="";
		direccion.value="";
		tabla.value="";
		comentario.value="";
		return false;
		
    }else{
        alert(alerta);
        return false;
        
    }
	
}



function guardar_newsletter()
	{
	var alerta="";
	
	var nombre = document.getElementById("nombre_footer");
	var email = document.getElementById("email_footer");
	var conociste = document.getElementById("conociste_footer");
	
   	alerta = agregar_alert(nombre,"Nombre",alerta);
	alerta = validar_email(email, alerta);
	
	var parametros = "";
	
	parametros += "nombre="+encodeURIComponent(nombre.value);
	parametros += "&email="+encodeURIComponent(email.value);
	parametros += "&conociste="+encodeURIComponent(conociste.value);

	
	if(alerta==""){
		get_pagina({contenedor:"mensaje",page:"admin/comentario/ajax_agregar.php",params:parametros});
		nombre.value="";
		email.value="";
		
		return false;
		
    }else{
        alert(alerta);
        return false;
        
    }
	
}



function enviar_amigo()
	{
	var alerta="";
	
	var imagen = document.getElementById("imagen");
	var promo = document.getElementById("promo");
	
	var tu_nombre = document.getElementById("tu_nombre");
	var tu_email = document.getElementById("tu_email");
	
   	alerta = agregar_alert(tu_nombre,"Tu nombre",alerta);
	alerta = validar_email(tu_email, alerta);
    
	var amigo_nombre1 = document.getElementById("amigo_nombre1");
	var amigo_email1 = document.getElementById("amigo_email1");
	

	alerta = agregar_alert(amigo_nombre1,"Nombre de tu amigo",alerta);
	alerta = validar_email(amigo_email1, alerta);
	
	var amigo_nombre2 = document.getElementById("amigo_nombre2");
	var amigo_email2 = document.getElementById("amigo_email2");
	
	if(amigo_nombre2.value!='' && amigo_nombre2.value!='Nombre de tu amigo'){	
		alerta = agregar_alert(amigo_nombre2,"Nombre de tu amigo",alerta);
		alerta = validar_email(amigo_email2, alerta);
	}
	
	var amigo_nombre3 = document.getElementById("amigo_nombre3");
	var amigo_email3 = document.getElementById("amigo_email3");
	
	if(amigo_nombre3.value!='' && amigo_nombre3.value!='Nombre de tu amigo'){	
		alerta = agregar_alert(amigo_nombre3,"Nombre de tu amigo",alerta);
		alerta = validar_email(amigo_email3, alerta);
	}
	
	var amigo_nombre4 = document.getElementById("amigo_nombre4");
	var amigo_email4 = document.getElementById("amigo_email4");
	
	if(amigo_nombre4.value!='' && amigo_nombre4.value!='Nombre de tu amigo'){	
		alerta = agregar_alert(amigo_nombre4,"Nombre de tu amigo",alerta);
		alerta = validar_email(amigo_email4, alerta);
	}
	
	var amigo_nombre5 = document.getElementById("amigo_nombre5");
	var amigo_email5 = document.getElementById("amigo_email5");
	    
	if(amigo_nombre5.value!='' && amigo_nombre5.value!='Nombre de tu amigo'){	
		alerta = agregar_alert(amigo_nombre5,"Nombre de tu amigo",alerta);
		alerta = validar_email(amigo_email5, alerta);
	}


	
	var parametros = "";
	
	parametros += "tu_nombre="+encodeURIComponent(tu_nombre.value);
	parametros += "&tu_email="+encodeURIComponent(tu_email.value);
	parametros += "&amigo_nombre1="+encodeURIComponent(amigo_nombre1.value);
	parametros += "&amigo_email1="+encodeURIComponent(amigo_email1.value);
	parametros += "&imagen="+encodeURIComponent(imagen.value);
	parametros += "&promo="+encodeURIComponent(promo.value);
	
	
	if(amigo_nombre2.value!='' && amigo_nombre2.value!='Nombre de tu amigo'){	
		parametros += "&amigo_nombre2="+encodeURIComponent(amigo_nombre2.value);
		parametros += "&amigo_email2="+encodeURIComponent(amigo_email2.value);
	}
	if(amigo_nombre3.value!='' && amigo_nombre3.value!='Nombre de tu amigo'){	
		parametros += "&amigo_nombre3="+encodeURIComponent(amigo_nombre3.value);
		parametros += "&amigo_email3="+encodeURIComponent(amigo_email3.value);
	}
	if(amigo_nombre4.value!='' && amigo_nombre4.value!='Nombre de tu amigo'){	
		parametros += "&amigo_nombre4="+encodeURIComponent(amigo_nombre4.value);
		parametros += "&amigo_email4="+encodeURIComponent(amigo_email4.value);
	}
	if(amigo_nombre5.value!='' && amigo_nombre5.value!='Nombre de tu amigo'){	
		parametros += "&amigo_nombre5="+encodeURIComponent(amigo_nombre5.value);
		parametros += "&amigo_email5="+encodeURIComponent(amigo_email5.value);
	}
	if(alerta==""){
		get_pagina({contenedor:"mensaje_enviar",page:"admin/amigo/ajax_agregar.php",params:parametros});
		tu_nombre.value="Tu nombre";
		tu_email.value="Tu email";
		amigo_nombre1.value="Nombre de tu amigo";
		amigo_email1.value="Email de  tu amigo";
		amigo_nombre2.value="Nombre de tu amigo";
		amigo_email2.value="Email de  tu amigo";
		amigo_nombre3.value="Nombre de tu amigo";
		amigo_email3.value="Email de  tu amigo";
		amigo_nombre4.value="Nombre de tu amigo";
		amigo_email4.value="Email de  tu amigo";
		amigo_nombre5.value="Nombre de tu amigo";
		amigo_email5.value="Email de  tu amigo";
		return false;
		
    }else{
        alert(alerta);
        return false;
        
    }
	
}
