function envia(){
	var mensaje= document.getElementById("mensaje");
	var asunto= document.getElementById("asunto");
	var email= document.getElementById("email");
	
	if(!esCorreo(email.value)){
		alert("Escriba una direccion de correo valida.");
		email.focus();
		return false;
	}
	
	if(trim(asunto.value)==''){
	 	alert("El Asunto es obligatorio.");
	 	asunto.focus();
	 	return false;
	}
	if(trim(mensaje.value)==''){
		alert("El Mensaje es obligatorio.");
		mensaje.focus();
		return false;
	}

    $.ajax({
         type: "POST",
         url: "email.php",
         data:"mensaje="+mensaje.value+"&asunto="+asunto.value+"&email="+email.value,
         success: function(msg){
            document.getElementById("estado").innerHTML="Enviado";
            alert("El mensaje ha sido enviado.");

						mensaje.value="";
						asunto.value="";
						email.value="";
         }
     });

	

}

function trim(str){
	return str.replace(/^\s*|\s*$/g,"");
}

function esCorreo(valor){

	return  (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor));

}


function enviaDist(){
  var interes= document.getElementById("interes");
	var nombre= document.getElementById("nombre");
	var mail= document.getElementById("mail");
	var telefono= document.getElementById("telefono");
	var empresa= document.getElementById("empresa");
	
	if(trim(nombre.value)==''){
		alert("El nombre es obligatorio.");
		nombre.focus();
		return false;
	}
	if(!esCorreo(mail.value)){
		alert("Escriba una direccion de correo valida.");
		mail.focus();
		return false;
	}
	
	if(trim(telefono.value)==''){
		alert("El telefono es obligatorio.");
		telefono.focus();
		return false;
	}
	if(trim(empresa.value)==''){
		alert("La empresa es obligatoria.");
		empresa.focus();
		return false;
	}
	if(trim(interes.value)==''){
	 	alert("Los productos de interes son obligatorios.");
	 	interes.focus();
	 	return false;
	}

    $.ajax({
         type: "POST",
         url: "sendit.php",
         data:"interes="+interes.value+"&nombre="+nombre.value+"&mail="+mail.value+"&telefono="+telefono.value+"&empresa="+empresa.value,
         success: function(msg){
            alert(msg);
			if(msg.indexOf('enviado')!=-1)
			{			
				interes.value="";
				nombre.value="";
				mail.value="";
				telefono.value="";
				empresa.value="";
				window.location="index.htm";
 			}
         }
     });

}