// JavaScript Document

var READY_STATE_COMPLETE=4;
var peticion_http3 = null;

function inicializa_xhr3() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}

 

function crea_query_string3() {

//var checkboxes = document.getElementById("contacto").opcion;
var nom = document.getElementById("nombre");
var ape = document.getElementById("apellido");
var emai = document.getElementById("email");
var men = document.getElementById("mensaje");
var cod = document.getElementById("code");

return "nombre=" + encodeURIComponent(nom.value) + 
"&apellido=" + encodeURIComponent(ape.value)  +
"&email=" + encodeURIComponent(emai.value)  + "&mensaje=" + encodeURIComponent(men.value)  +
"&code=" + encodeURIComponent(cod.value)  + "&nocache=" + Math.random();



}

function valida_contacto() {
peticion_http3 = inicializa_xhr3();
if(peticion_http3) {
peticion_http3.onreadystatechange = procesaRespuesta3;
peticion_http3.open("POST", "validaciones/validacontacto.php", true);
var query_string3 = crea_query_string3();
peticion_http3.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
peticion_http3.send(query_string3);
}
}


function procesaRespuesta3() {
if(peticion_http3.readyState == READY_STATE_COMPLETE) {
if (peticion_http3.status == 200) {
	var param4 = peticion_http3.responseText;
	if(param4=="exito")
	{
		//alert("Se ha registrado con exito.");
		//document.location.href = "contacto-rta.php";
		document.contacto.action = "validaciones/mailer-contacto.php";
		document.getElementById("respuestacontacto").innerHTML = "Procesando el envio ...";
		//enviar3();
		
		document.contacto.submit();
		//document.contacto.submit();
		//document.getElementById("respuesta").innerHTML = "Se ha registrado con exito. <br>";
		//document.getElementById("form2").reset();
	}
	else
	{
		document.getElementById("respuestacontacto").innerHTML = peticion_http3.responseText;
	}
}
}
}


