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 incializacion(tempuri){
	window.location.href=tempuri;
}
function valida(){
	if (document.comunicado.tip.value==""){
			alert("Ingrese el Tipo de Documento");
			return false;
	}else{
		if (document.comunicado.dni.value==""){
			alert("Ingrese su Número de Documento");
			return false;
		}
	}
	document.comunicado.accion.value ='ENV';
}
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 mostrar_captcha(){
	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(){
	cod = document.getElementById('code').value;
	tdc = document.getElementById('tip').value;
	ndc = document.getElementById('dni').value;
	error_string = "";
	if(cod == ""){error_string += "Ingrese el código 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", "fichaoptica.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('fichaoptica').innerHTML = ajax.responseText
		}
	}
	ajax.send(parametros);
	/* Fin de la validación */
	}
}
function reimprimir_constancia(){
	tdc = document.getElementById('tip').value;
	ndc = document.getElementById('dni').value;
	url = "constancia.php?ca="+ndc+"&cb="+tdc;
	window.open(url,'','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=1, height=1, top=5000, left=5000');
}