// 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 ced = document.getElementById("ci");
var fecha_nac = document.getElementById("fecha-nacimiento");
var nacion = document.getElementById("nacionalidad");
var profes = document.getElementById("profesion");
var bar = document.getElementById("barrio");
var ciu = document.getElementById("ciudad");
var dep = document.getElementById("departamento");
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 dir_par = document.getElementById("direccion-particular");
var razon = document.getElementById("razon-social");
var ru = document.getElementById("ruc");
var dir_lab = document.getElementById("direccion");
var bar_com = document.getElementById("barrio_comercial");
var ciu_com = document.getElementById("ciudad_comercial");
var dep_com = document.getElementById("departamento_comercial");
var pai = document.getElementById("pais");
var conta = document.getElementById("contacto");
var car = document.getElementById("cargo");
var tel_com = document.getElementById("telefono_comercial");
var fax_com = document.getElementById("fax_comercial");
var movi_com = document.getElementById("movil_comercial");
var ani = document.getElementById("aniversario");
var email_com = document.getElementById("email_comercial");
var website_com = document.getElementById("website_comercial");
var mes = valorradiobutton();


return "nombre=" + nom.value + "&ci=" + ced.value + "&fecha-nacimiento=" + fecha_nac.value +
"&nacionalidad=" + nacion.value + "&profesion=" + profes.value + "&barrio=" + bar.value + 
"&ciudad=" + ciu.value + "&departamento=" + dep.value + "&telefono=" + tel.value + "&fax=" + fa.value + 
"&movil=" + movi.value + "&email=" + emai.value + "&website=" + web.value + "&direccion-particular=" + dir_par.value + 
"&razon-social=" + razon.value + "&ruc=" + ru.value + "&direccion=" + dir_lab.value + "&barrio_comercial=" + bar_com.value + 
"&ciudad_comercial=" + ciu_com.value + "&departamento_comercial=" + dep_com.value + "&pais=" + pai.value + 
"&contacto=" + conta.value + "&cargo=" + car.value + "&telefono_comercial=" + tel_com.value + "&fax_comercial=" + fax_com.value + 
"&movil_comercial=" + movi_com.value + "&aniversario=" + ani.value + "&email_comercial=" + email_com.value + 
"&website_comercial=" + website_com.value + "&meses=" + mes + "&nocache=" + Math.random();
}
function valida() {
peticion_http = inicializa_xhr();
if(peticion_http) {
peticion_http.onreadystatechange = procesaRespuesta;
peticion_http.open("POST", "validasuscribase.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.form2.submit();
		//document.getElementById("respuesta").innerHTML = "Se ha registrado con exito. <br>";
		//document.getElementById("form2").reset();
	}
	else
	{
		document.getElementById("respuestas").innerHTML = peticion_http.responseText;
	}
}
}
}
