// JavaScript Document

var READY_STATE_COMPLETE=4;
var peticion_http = null;

function inicializa_xhr() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}


/*function valorradiobutton(){ 
    var i 	
    for (i=0;i<document.form2.meses.length;i++){ 
       if (document.form2.meses[i].checked)           		  
		  break;	  
    } 
    //document.bgColor = document.form2.sexo[i].value 
	return document.form2.meses[i].value ;
} 
*/
function crea_query_string() {

var nom = document.getElementById("nombre");
var ru = document.getElementById("ruc");
var fecha_ani = document.getElementById("fecha-aniversario");
var nacion = document.getElementById("nacionalidad");
var profes = document.getElementById("profesion");
var dir = document.getElementById("direccion");
var ciu = document.getElementById("ciudad");
var dep = document.getElementById("departamento");
//var recibir = document.getElementById("recibir-revista");
var tel = document.getElementById("telefono");
var fa = document.getElementById("fax");
var movi = document.getElementById("movil");
var emai = document.getElementById("email");
var web = document.getElementById("website");
/*var rub = document.getElementById("rubro");
var empresa = document.getElementById("titulo-empresa");
var desc = document.getElementById("descripcion");*/
//var mes = valorradiobutton();


return "nombre=" + nom.value + "&ruc=" + ru.value + "&fecha-aniversario=" + fecha_ani.value +
"&nacionalidad=" + nacion.value + "&profesion=" + profes.value + "&direccion=" + dir.value + 
"&ciudad=" + ciu.value + "&departamento=" + dep.value + //"&recibir-revista=" + recibir.value + 
"&telefono=" + tel.value + "&fax=" + fa.value + 
"&movil=" + movi.value + "&email=" + emai.value + "&website=" + web.value + 
"&nocache=" + Math.random();
}
function valida() {
peticion_http = inicializa_xhr();
if(peticion_http) {
peticion_http.onreadystatechange = procesaRespuesta;
peticion_http.open("POST", "validatarifario.php", true);
var query_string = crea_query_string();
peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
peticion_http.send(query_string);
}
}
function procesaRespuesta() {
if(peticion_http.readyState == READY_STATE_COMPLETE) {
if (peticion_http.status == 200) {
	var param = peticion_http.responseText;
	if(param=="exito")
	{
		//alert("Se ha registrado con exito.");
		//document.location.href = "contacto-rta.php";
		document.getElementById("respuestas").innerHTML = "Procesando su envio ...";
		document.form2.submit();
		//document.getElementById("respuesta").innerHTML = "Se ha registrado con exito. <br>";
		//document.getElementById("form2").reset();
	}
	else
	{
		document.getElementById("respuestas").innerHTML = peticion_http.responseText;
	}
}
}
}
