
function Ajax(){
	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;
}

function buscar(frm, opc, ventana){	

	values = "accion=buscarParaRegistrar";
	
	tdoc = frm.tdoc.value;
	ndoc = frm.txtNdoc.value;
		
	tdocId = frm.tdoc.selectedIndex
	dtdoc  = frm.tdoc.options(tdocId).text;	
	
	values = values+"&tdoc="+tdoc+"&dtdoc="+dtdoc+"&ndoc="+ndoc; 
	url = "../controller/controller.inscripcion.php"; 

	ajax=Ajax(); 	
	ajax.open("POST", url, true); 
	//alert(values);
	ajax.onreadystatechange = function() { 
		if(ajax.readyState==1){
			document.getElementById('cargando').innerHTML = "Buscando...";
		}
		else if (ajax.readyState == 4){ 
			document.getElementById('cargando').innerHTML = "";	
			if(ajax.responseText == "existe"){				
				alert("El " + dtdoc + " Nro " + ndoc + " ya se encuentra registrado");
			}
		 	else{
				document.getElementById('detformulario').innerHTML = ajax.responseText;
			}
		} 
	} 
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	ajax.send(values); 
}

function grabarInscripcion(opcion){
	
	url = "procesar_incorporacion.php"; 
	
	tdoc = document.getElementById('tdoc').value;
	dtdoc = document.getElementById('dtdoc').value;
	ndoc = document.getElementById('ndoc').value;
	apaterno = document.getElementById('txtApaterno').value; 
	amaterno = document.getElementById('txtAmaterno').value; 
	nombres = document.getElementById('txtNombres').value; 
	correo = document.getElementById('txtCorreo').value; 
	telefono = document.getElementById('txtTelefono').value; 
	
	neducativo = document.getElementById('cboNivelEducativo').value;
	neducativoId = document.getElementById('cboNivelEducativo').selectedIndex
	neducativoDesc = document.getElementById('cboNivelEducativo').options(neducativoId).text;
	
	neducativopostula = document.getElementById('cboNivelEducativoPostula').value;
	neducativopostulaId = document.getElementById('cboNivelEducativoPostula').selectedIndex
	neducativopostulaDesc = document.getElementById('cboNivelEducativoPostula').options(neducativopostulaId).text;
	
	titulo = document.getElementById('txtTitulo').value;
	
	ubirendira = document.getElementById('cboSedes').value;	
	ubirendiraSedId = document.getElementById('cboSedes').selectedIndex
	ubirendiraSed = document.getElementById('cboSedes').options(ubirendiraSedId).text;
	
	ubirendiraRegId = document.getElementById('cboRegionesSedes').selectedIndex
	ubirendiraReg = document.getElementById('cboRegionesSedes').options(ubirendiraRegId).text;
	/*
	ubirendiraProId = document.getElementById('cboProvincias').selectedIndex
	ubirendiraPro = document.getElementById('cboProvincias').options(ubirendiraProId).text;
	*/
	ubipostula = document.getElementById('cboRegionesPostula').value; 
	ubipostulaId = document.getElementById('cboRegionesPostula').selectedIndex
	ubipostulaReg = document.getElementById('cboRegionesPostula').options(ubipostulaId).text;
	
	ajax=Ajax(); 
	
	values = "accion=grabarInscripcion&tdoc="+tdoc+"&dtdoc="+dtdoc+"&ndoc="+ndoc+"&apaterno="+apaterno+"&amaterno="+amaterno+"&nombres="+nombres+"&correo="+correo+"&telefono="+telefono+"&neducativo="+neducativo+"&neducativoDesc="+neducativoDesc+"&neducativopostula="+neducativopostula+"&neducativopostulaDesc="+neducativopostulaDesc+"&titulo="+titulo+"&ubirendira="+ubirendira+"&ubirendiraSed="+ubirendiraSed+"&ubirendiraReg="+ubirendiraReg+"&ubipostula="+ubipostula+"&ubipostulaReg="+ubipostulaReg+"&ventana="+opcion;
	
	//alert(values);	
	ajax.open("POST", url, true); 
	
	ajax.onreadystatechange = function() { 			
		if (ajax.readyState == 4){ 
			document.getElementById('resultado').innerHTML = ajax.responseText;
		} 
	} 
	
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	ajax.send(values); 
}
