// 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 valorcheckbox(){ 
    var i 	
    for (i=0;i<document.form2.sexo.length;i++){ 
       if (document.form2.sexo[i].checked)           		  
		  break;	  
    } 
    //document.bgColor = document.form2.sexo[i].value 
	return document.form2.sexo[i].value ;
} 
*/
/*
var checkboxes = document.getElementById("contacto").opcion;

var cont = 0;  
for (var x=0; x < checkboxes.length; x++) 
{ 
	if (checkboxes[x].checked) 
	{  
		//cont = cont + 1; 
		var op[x] = checkboxes[x].value ;
	}
}
*/

function crea_query_string3() {

//var checkboxes = document.getElementById("contacto").opcion;

/*var pro = document.getElementById("proxy");
var iplo = document.getElementById("iplocal");
var hosname1 = document.getElementById("hostname1");
var ippu = document.getElementById("ippublica");*/
var nom = document.getElementById("nombre");
var em = document.getElementById("empresa");
var car = document.getElementById("cargo");
var sw = document.getElementById("sitioweb");
var ciu = document.getElementById("ciudad");
var pai = document.getElementById("pais");
var tel = document.getElementById("telefono");
var tel_movil = document.getElementById("telefono_movil");
var emai = document.getElementById("email");
var men = document.getElementById("mensaje");
var cod = document.getElementById("code");

return "nombre=" + encodeURIComponent(nom.value) + 
"&ciudad=" + encodeURIComponent(ciu.value)  +
"&pais=" + encodeURIComponent(pai.value)  + "&telefono=" + encodeURIComponent(tel.value)  +
"&telefono_movil=" + encodeURIComponent(tel_movil.value)  +
"&empresa=" + encodeURIComponent(em.value)  + "&cargo=" + encodeURIComponent(car.value)  +
"&sitioweb=" + encodeURIComponent(sw.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", "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 enviar3() {
peticion_http3 = inicializa_xhr3();
if(peticion_http3) {
peticion_http3.onreadystatechange = procesaRespuesta4;
peticion_http3.open("POST", "mailer-contacto.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.getElementById("respuestacontacto").innerHTML = "Procesando su envio ...";
		//enviar3();
		document.contacto.action = "mailer-contacto.php";
		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;
	}
}
}
}

/*
function procesaRespuesta4() {
if(peticion_http3.readyState == READY_STATE_COMPLETE) {
if (peticion_http3.status == 200) {
	var param5 = peticion_http3.responseText;
	if(param5=="enviado")
	{
		//alert("Se ha registrado con exito.");
		//document.location.href = "contacto-rta.php";
		//document.getElementById("respuestas").innerHTML = "Procesando su envio ...";
		//enviar();
		//location.href = "rta.php?resultado=exito";
		document.getElementById("respuestaboletin").innerHTML = "<img src='images/icono-ok.gif' border='0' align='middle'/><br> Su suscripci&oacute;n ha sido enviada.";
		document.boletin.reset();
		//window.parent.img.location.reload();
		//window.close();
		//document.form1.submit();
		//document.getElementById("respuesta").innerHTML = "Se ha registrado con exito. <br>";
		//document.getElementById("form2").reset();
	}
	else
	{
		//location.href = "rta.php?resultado=exito";
		document.getElementById("respuestaboletin").innerHTML = "<img src='images/icono-ok.gif' border='0' align='middle'/><br> Su suscripci&oacute;n ha sido enviada.";
		document.boletin.reset();
		//window.parent.img.location.reload();
		//document.getElementById("respuestas").innerHTML = peticion_http.responseText;
	}
}
}
}
*/