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 resolver(cpm){
	padre = document.getElementById('sel_reg_'+cpm).value;
	ajax=Ajax();
	ajax.open("GET", "out_file.php?tip="+cpm+"&campo="+padre);
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			document.getElementById('file'+cpm).innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
}

function mostrar_captcha(tipo){
	document.getElementById('tdoc').disabled=true;
	document.getElementById('ndoc').disabled=true;
	if (document.getElementById('ndoc').value==""){
		alert("INGRESE SU NUMERO DE DOCUMENTO");
		document.getElementById('tdoc').disabled=false;
		document.getElementById('ndoc').disabled=false;
	}else{
		ajax=Ajax();
		ajax.open("GET", "captcha.php");
		ajax.onreadystatechange=function(){
			if (ajax.readyState==4){
				document.getElementById('captcha').innerHTML = ajax.responseText;
			}
		}
		ajax.send(null);
	}
}

function validar_captcha(){
	document.getElementById('code').disabled=true;
	document.getElementById('continuar').disabled=true;
	cod = document.getElementById('code').value;
	tdc = document.getElementById('tdoc').value;
	ndc = document.getElementById('ndoc').value;
	error_string = "";
	if (cod == ""){error_string += "INGRESE EL CODIGO MOSTRADO.\n";}
	if (error_string != ""){
		alert (error_string);
	}else{
	/* Inicio de validación */
		parametros = "code="+cod+"&tdoc="+tdc+"&ndoc="+ndc;
		ajax=Ajax();
		ajax.open("POST", "resultado.php");
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", parametros.length);
		ajax.setRequestHeader("Connection", "close");
		ajax.onreadystatechange=function(){
			if (ajax.readyState==4){
				document.getElementById('resultado').innerHTML = ajax.responseText;
			}
		}
		ajax.send(parametros);
		/* Fin de la validación */
	}
}

function solonumeros(e){
	var key;
	if(window.event){key = e.keyCode;} // IE
	else if(e.which){key = e.which;} // Netscape/Firefox/Opera
	if(key < 48 || key > 57){
		//return false;
		if(key == 13){
			valida();
		}else{
			return false;
		}
	}else{
		return true;
	}
}

function reimprimir_constancia(tip){
	tdc = document.getElementById('tdoc').value;
	ndc = document.getElementById('ndoc').value;
	url = "detalle.php?ndoc="+ndc+"&tdoc="+tdc+"&tipc="+tip;
	window.open(url,'','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=500, height=500, top=5000, left=5000');
}
