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==""|| campo.value==nombre){
        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 += "Por favor ingrese un mail valido (Ej. usuario@dominio.com) \n" ;
           campo.style.color='#ff0000';
           campo.value="Por favor ingrese un mail valido (Ej. usuario@dominio.com)";
	   		
        }
        
        return alerta;
}    

function difundir()
	{
	var alerta="";
	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_nombre = document.getElementById("amigo_nombre");
	var amigo_email = document.getElementById("amigo_email");
	
	alerta = agregar_alert(amigo_nombre,"Nombre de tu amigo",alerta);
	alerta = validar_email(amigo_email, alerta);
	
	
	var parametros = "";
	
	parametros += "tu_nombre="+encodeURIComponent(tu_nombre.value);
	parametros += "&tu_email="+encodeURIComponent(tu_email.value);
	parametros += "&amigo_nombre="+encodeURIComponent(amigo_nombre.value);
	parametros += "&amigo_email="+encodeURIComponent(amigo_email.value);
	
	if(alerta==""){
		get_pagina({contenedor:"mensaje_difundir",page:"difundir.php",params:parametros});
		tu_nombre.value="Tu nombre";
		tu_email.value="Tu email";
		amigo_nombre.value="Nombre de tu amigo";
		amigo_email.value="Email de  tu amigo";
		
		return false;
		
    }else{
        alert(alerta);
        return false;
        
    }
	
}


function contacto()
{
	var alerta="";
	var tu_nombre = document.getElementById("tu_nombre");
	var tu_email = document.getElementById("tu_email");
	var donde = document.getElementById("donde");
	var profesion = document.getElementById("profesion");
	var conociste = document.getElementById("conociste");
	var comentario = document.getElementById("comentario");
	
	
	alerta = agregar_alert(tu_nombre,"Tu nombre",alerta);
	alerta = validar_email(tu_email, alerta);
	alerta = agregar_alert(donde,"De donde sos",alerta);
	alerta = agregar_alert(profesion,"Profesion",alerta);
	alerta = agregar_alert(comentario,"Comentario",alerta);
	
	
	var parametros = "";
	
	parametros += "tu_nombre="+encodeURIComponent(tu_nombre.value);
	parametros += "&tu_email="+encodeURIComponent(tu_email.value);
	parametros += "&donde="+encodeURIComponent(donde.value);
	parametros += "&profesion="+encodeURIComponent(profesion.value);
	parametros += "&conociste="+encodeURIComponent(conociste.value);
	parametros += "&comentario="+encodeURIComponent(comentario.value);
	
	if(alerta==""){
		get_pagina({contenedor:"mensaje_contacto",page:"contactar.php",params:parametros});
		tu_nombre.value="";
		tu_email.value="";
		donde.value="";
		profesion.value="";
		comentario.value="";
		
		return false;
		
	}else{
	    alert(alerta);
	    return false;
	    
	}

}



function guardar_mensaje()
{
	var alerta="";
	var tu_nombre = document.getElementById("tu_nombre");
	var tu_email = document.getElementById("tu_email");
	var comentario = document.getElementById("comentario");
	
	
	alerta = agregar_alert(tu_nombre,"Tu nombre",alerta);
	alerta = validar_email(tu_email, alerta);
	alerta = agregar_alert(comentario,"Comentario",alerta);
	
	
	var parametros = "";
	
	parametros += "tu_nombre="+encodeURIComponent(tu_nombre.value);
	parametros += "&tu_email="+encodeURIComponent(tu_email.value);

	parametros += "&comentario="+encodeURIComponent(comentario.value);
	
	if(alerta==""){
		get_pagina({contenedor:"mensaje_contacto",page:"guardar_mensaje.php",params:parametros});
		tu_nombre.value="";
		tu_email.value="";
		comentario.value="";
		
		return false;
		
	}else{
	    alert(alerta);
	    return false;
	    
	}

}


function newsletter()
	{
	var alerta="";
	var newsletter_nombre = document.getElementById("newsletter_nombre");
	var newsletter_email = document.getElementById("newsletter_email");
	
   	alerta = agregar_alert(newsletter_nombre,"Tu nombre",alerta);
	alerta = validar_email(newsletter_email, alerta);
  	
	var parametros = "";
	
	parametros += "nombre="+encodeURIComponent(newsletter_nombre.value);
	parametros += "&email="+encodeURIComponent(newsletter_email.value);
	
	if(alerta==""){
		get_pagina({contenedor:"mensaje_newsletter",page:"newsletter.php",params:parametros});
		newsletter_nombre.value="Tu nombre";
		newsletter_email.value="Tu email";
		
		return false;
		
    }else{
        alert(alerta);
        return false;
        
    }
	
}

