

function nuevoAjax(){

var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
//Validamos el formulario
var nombre = new LiveValidation( 'nombre', {
    onlyOnSubmit: true
} );
nombre.add( Validate.Presence );
var apellido = new LiveValidation( 'apellido', {
    onlyOnSubmit: true
} );
apellido.add( Validate.Presence );
var direccion = new LiveValidation( 'direccion', {
    onlyOnSubmit: true
} );
direccion.add( Validate.Presence );
var poblacion = new LiveValidation( 'poblacion', {
    onlyOnSubmit: true
} );
poblacion.add( Validate.Presence );
var telef = new LiveValidation( 'telef', {
    onlyOnSubmit: true
} );
telef.add( Validate.Presence );
telef.add(Validate.Numericality);
var email = new LiveValidation( 'email', {
    onlyOnSubmit: true
} );
email.add( Validate.Email );
email.add( Validate.Presence );

//Cuando el formulario es válido se envia al correo
var automaticOnSubmit = nombre.form.onsubmit;
nombre.form.onsubmit = function(){
    var valid = automaticOnSubmit();
    if(valid){
       
        c = document.getElementById('resultado_mensaje');
      //variable=documenet.nombre_del_form.nombre_del_control.value
	nom=document.myform.nombre.value;
	ape=document.myform.apellido.value;
	dir=document.myform.direccion.value;
        pob=document.myform.poblacion.value;
	tel=document.myform.telef.value;
	ema=document.myform.email.value;
        men=document.myform.mensaje.value;
        pai=document.myform.pais.value;

	ajax=nuevoAjax();
	c.innerHTML = '<div id="cargador"><img src="Scripts/enviamail/ajax-loader.gif"/></div><p style="text-align:center;">Enviando formulario</p>';
	ajax.open("POST", "Scripts/enviamail/envio.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			setTimeout("c.innerHTML = "+ajax.responseText+"", 18000);
		}
		borrarCampos()
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("nombre="+nom+"&email="+ema+"&mensaje="+men+"&apellidos="+ape+"&direccion="+dir
                    +"&poblacion="+pob+"&telef="+tel+"&pais="+pai);
}


return false;
}
function borrarCampos(){
	document.myform.nombre.value="";
	document.myform.apellido.value="";
	document.myform.direccion.value="";
        document.myform.poblacion.value="";
	document.myform.telef.value="";
	document.myform.email.value="";
        document.myform.mensaje.value="";
        document.myform.pais.value="";

}
  // 
