/*
for (i=0;i<document.getElementById(form).elements.length;i++) {
	if (document.getElementById(form).elements[i].name) {
		if (!ControlaCampo(document.getElementById(form).elements[i].id,document.getElementById(form).elements[i].name)) {
			return;
			}//encuentra error y termina
		}
	} // fin del for RECORRE TODO EL FORMULARIO
*/



// JavaScript Document
var IE = document.all ? true : false;
var Info = 0;
var MCargando = "<br><br><br><center>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... Cargando ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</center><br><br><br>";
var error = "!! PRECAUCION !!\n---------------------------------------------------------------------------------\n\tSe han encontrado los siguientes inconvenientes:\n---------------------------------------------------------------------------------\n\n";
var cambios = "!! PRECAUCION !!\n-------------------------------------------------------------------------------------------\n\tEsta por realizar una accion critica:\n-------------------------------------------------------------------------------------------\n\n";


/*	................................................	*/
			// TRABAJANDO CON STRING
/*	................................................	*/
function lTrim(sStr) {
while (sStr.charAt(0) == " ") {sStr = sStr.substr(1, sStr.length - 1);}
return sStr;
}

function rTrim(sStr) {
while (sStr.charAt(sStr.length - 1) == " ") {sStr = sStr.substr(0, sStr.length - 1);}
return sStr;
}

function allTrim(sStr) {
return rTrim(lTrim(sStr));
}


/*	.................................................	*/
		// MENSAJES DE VALIDACION FORMULARIOS
/*	.................................................	*/
function Mensajes(campo,mensaje) {
if (!campo) {return;}
if (!mensaje) {mensaje = "Se han detectado problemas en este campo...";}

mensaje = "<span class='LetraNormal_10'>" + mensaje + "</span>";
inlineMsg(campo,mensaje,5);
}



/*	......................................	*/
	//	LANZADOR UNIVERSAL DE AJAX
/*	......................................	*/
function infajax(Destino,Tipo,Param,Despues) {
if (!Destino || !Tipo) {return;}
Conexion(1);

if (Tipo == "updater") {

new Ajax.Updater(Destino, 'control/control_informes.php', {
	parameters : Param,
	onFailure : function(transport) {
								Conexion(0);
								alert("Problemas en las comunicaciones....");
								$(Destino).innerHTML = transport.responseText;
								alert(transport.responseText);
								return;
								},
		
	onComplete: function(transport) {
				Conexion(0);
				if (Despues) {
					if (200 == transport.status) {eval(Despues);}
					} // fin hay Despues
				}	// fin función transport
	});
} // fin updater

if (Tipo == "request") {
new Ajax.Request('control/control_informes.php', {
	parameters : Param,
	onFailure : function(transport) {
								Conexion(0);
								alert("Problemas en las comunicaciones....");
								return;
								},
	onComplete: function(transport) {
				Conexion(0);
				if (Despues) {
					if (200 == transport.status) {eval(Despues);}
					} // fin Despues
				} // fin función transport
	});
} // fin request

}

/*	..........................................	*/
	// PAGINA PRINCIPAL: EXTERNOS
/*	..........................................	*/
function InformesPrincipal() {
var Param = "accion=InformesPrincipal";
var Despues = "";

infajax("Cuerpo","updater",Param,Despues);
}


/*	..........................................	*/
	// MUESTRA DETALLE DE CADA FORMULARIO
/*	..........................................	*/
function VerFormulario(id,callback) {
if (!id) {return;}
var Param = "accion=VerFormulario&id=" + id;
var Despues = "";
if (callback) {Despues =callback;}
infajax("Resultados","updater",Param,Despues);
}

/*	..........................................	*/
	// LLAMAR AL FORMULARIO
	//id = TIPO DE FORMULARIO
	//t = tipo (doc,cuit)
	//n = numero identificacion
/*	..........................................	*/
function IniciarTramite(id,t,n) {
if (!id) {return;}
var Param = "accion=IniciarTramite&id=" + id + "&paso=1";
var Despues = "";
if (t && n) {
	Despues = "$('"+t+"').value="+n+";ValidarDatos();";
	}

infajax("Cuerpo","updater",Param,Despues);
}


/*	.................................................	*/
			// BORRAR DATOS DEL BUSCADOR
/*	.................................................	*/
function Borrar_Buscador() {
$('Sdocumento').value = "";
$('Scuit').value = "";
//$('cuit1').value = "";
//$('cuit2').value = "";
//$('cuit3').value = "";
$('Sdocumento').focus();
}





/*	......................................	*/
	// VALIDAR Y GUARDAR PERSONA
/*	......................................	*/
function Inf_GuardarPersona(form) {
if ($('paso')) {var paso = $F('paso');}
if ($('continua')) {var continua = $F('continua');}
if ($('vacuit')) {var vacuit = $F('vacuit');}
var informe	 = $F('informes_id');
var formulario = $F('formularios_id');

var arra = new Array();
	arra['documento']	= 'n';
	arra['nombre']		= 'l';
	arra['apellido']	= 'l';
	arra['ecivil_id']	= 's';
	arra['nacimiento']	= 's';
	arra['padre']		= 'Ns';
	arra['madre']		= 'Ns';

if (formulario == 4) {continua = 0;}
if (!continua) {continua = 0;}
if (paso == 1) {
		var Datos_id = 'solicitante';
		var Datos_Persona  = 'PerSolicitante';
		}
if (paso == 11) {//formulario C
		var Datos_id = 'solicitante2';
		var Datos_Persona  = 'PerSolicitante_2';
		}
if (paso == 2) {
		var Datos_id = 'conyuge';
		var Datos_Persona  = 'PerConyuge';
		}
if (paso == 3) {
		var Datos_id = 'hijos';
		var Datos_Persona  = 'PerHijos';
		}

//var paso2 = parseInt(paso) + 1;

for (i=0;i<document.getElementById(form).elements.length;i++) {
	var campo = document.getElementById(form).elements[i].id;
	if (!ControlaCampo(document.getElementById(form).elements[i].id,arra[campo])) {return;}//encuentra error y termina
	} // fin del for RECORRE TODO EL FORMULARIO

// ..... SI HO HAY ERROR ENVIA FORMULARIO .....

if (formulario == 4) {var Despues = "ArmarComboSolicitantes(transport.responseText);";}
else {
	var Despues = "var i=transport.responseText.split('@');if (i[0]==0 || i[0]== -1){$('Result_Formulario').innerHTML = i[1];} if (i[0]>0){$('"+Datos_id+"').value = i[0];$('"+Datos_Persona+"').innerHTML=i[1];alert('Registro Guardado Satisfactoriamente');$('Mensaje_Guardado').innerHTML='Registro Guardado';$('personas_id').value=i[0];$('Sub-Titulo').innerHTML = 'Ingrese Documento';if ("+continua +"==0) {$('Result_Formulario').innerHTML = i[2];}}";
}

var Param = "accion=Inf_GuardarPersona&formularios_id=" + formulario + "&paso=" + paso + "&continua=" + continua + "&vacuit=" + vacuit + "&" + Form.serialize(form);

var ok = confirm(cambios + "Ha verificado que la informacion que esta por enviar SEA CORRECTA ???");
if (!ok) {return;}

infajax("Cuerpo","request",Param,Despues);
}

/*	.................................................	*/
	// FORMULARIO D = ARMA EL COMBO DE SOLICITANTES
/*	.................................................	*/
function ArmarComboSolicitantes(resulta) {
if (!resulta) {return;}
var i = resulta.split('@');
if (i[0]==0 || i[0]== -1) {$('Result_Formulario').innerHTML = i[1];}
if (i[0]>0){
	EliminarSolicitante();
	var campo = $('LosSolicitantes');
	var pos = $('LosSolicitantes').length;
	$('Result_Formulario').innerHTML = i[2];
	op = document.createElement("OPTION");//pasamos a crear el option
	op.value = i[0];
	op.text  = i[1];
	campo.options[pos] = op;	
	alert('Solicitante Guardado Satisfactoriamente');
	}
}

/*	.................................................	*/
	// FORMULARIO D = REMOVER SOLICITANTE
/*	.................................................	*/
function EliminarSolicitante() {
var sel = $('LosSolicitantes').selectedIndex;
if (sel > -1) {$('LosSolicitantes').remove(sel);}
}


/*	.................................................	*/
		// PREPARA PANTALLA PARA DATOS CONYUGE
/*	.................................................	*/
function Prepara_Conyuge() {
var formulario	= $F('formularios_id');
$('Result_Formulario').innerHTML = "";
$('Buscador_Personas').style.display='block';
$('paso').value = 2;

if (formulario == 4) {
	var titulo = "1)&nbsp;&#8211;&#8250;&nbsp;Datos del SOLICITANTE";
	$('LosSolicitantes').selectedIndex = -1;
	$('LosSolicitantes').blur();
	}
else {
	var titulo = "(2)&nbsp;&#8211;&#8250;&nbsp;Datos del CONYUGE";
	$('Linea_Cuit').style.display = 'none';
	}

$('Sub-Titulo').innerHTML = titulo;

$('Sdocumento').value = '';
$('Sdocumento').focus();

}



/*	.................................................	*/
		// GENERA INFORME - GUARDA DATOS Y PDF
/*	.................................................	*/
function GenerarInforme() {
var informes	= $F('informes_id');
var formulario	= $F('formularios_id');
if ($('solicitante'))  {var solicitante	 = $F('solicitante');}
if ($('solicitante2')) {var solicitante2 = $F('solicitante2');}
if ($('conyuge'))      {var conyuge = $F('conyuge');}
var valor = "";
var men = "";

if (formulario < 4) {
	if (!solicitante || solicitante == 0 ) {
		alert(error + 'No se ha detectado SOLICITANTE.\n\n\tOperacion no permitida');
		return;
		}
	var Param = "accion=GenerarInforme&informes_id=" + informes + "&formularios_id=" + formulario + "&solicitante=" + solicitante + "&conyuge=" + conyuge + "&solicitante2=" + solicitante2;
	var Despues = "var i=transport.responseText.split('@');if (i[0]==0) {$('Result_Formulario').innerHTML = i[1];} if (i[0]==1){$('Cuerpo').innerHTML = i[1];}";
	}// fin proceso para formularios 1,2 y 3

if (formulario == 4) {
	var infoinmu_id = $F('infoinmu_id');
	var inmueble_id = $F('inmueble_id');
	if ($('LosSolicitantes').length == 0) {men = "Debe ingresar Datos del o de los solicitantes...\n";}
	if (!$F('inmueble_id')) {men += "Debe ingresar Datos del inmueble...";}
	if (men) {
		alert(error + men);
		return;
		}
	for (i=0;i<$('LosSolicitantes').length;i++) {
		if (valor) {valor += '_';}
		valor += $('LosSolicitantes').options[i].value;
		}
	var Param = "accion=GenerarInforme&informes_id=" + informes + "&formularios_id=" + formulario + "&solicitantes=" + valor + "&inmueble_id=" + inmueble_id + "&infoinmu_id=" + infoinmu_id;	
	}// fin formulario 4 (D)

var Despues = "transport.responseText;var i=transport.responseText.split('@');if (i[0]==0) {$('Result_Formulario').innerHTML = i[1];} if (i[0]==1){$('Cuerpo').innerHTML = i[1];}";

infajax("Cuerpo","request",Param,Despues);
}


/*	..................................................	*/
	// GENERAR PDF CON EL FORMULARIO RESPECTIVO
/*	..................................................	*/
function Generar_PDF(informes) {
if (!informes) {
	alert(error + 'Se han detectado problemas en el sistema.\n\nPor favor intente mas tarde');
	return;
	}

var Param = "accion=Generar_PDF&informes_id=" + informes;
var Despues = "var i=transport.responseText.split('@');if (i[0]==0) {alert('Problemas al generar INFORME.... \\nIntente nuevamente');} if (i[0]==1){window.open(i[1]);}";

infajax("Cuerpo","request",Param,Despues);
return;
}




/*	..................................................	*/
	// GERRAR EL PEDIDO Y ENVIARLO AL REGISTRO
/*	..................................................	*/
function CerrarPedido(id) {
if (!id) {return;}
var ok = confirm(cambios + "Al CERRAR Y ENVIAR el pedido actual no podra modificarlo.\n\n\t1. Se dara por terminado el actual pedido.\n\t2. Se enviara el pedido al sistema de la Direccion de Registros Publicos.\n\n\tCerrar y Enviar este pedido de informes...???");
if (!ok) {return;}

var Param = "accion=CerrarPedido&informes_id=" + id;
var Despues = "var i=transport.responseText.split('@');if (i[0]==0) {alert(i[1]);} if (i[0]==1){$('Cuerpo').innerHTML = i[1];}";

infajax("Cuerpo","request",Param,Despues);

}





/*	.................................................	*/
	//CONTROLA CONTENIDO DE CAMPOS
	//campo = campo del formulario a verificar
	//tipo = 's' :: string todos los caracters
	//tipo = 'l' :: string solo letras
	//tipo = 'n' :: solo números
	//tipo = 'Ns' :: s y puede ser nulo
/*	.................................................	*/
function ControlaCampo(campo,tipo) {
if (!campo) {return;}
var paso = $('paso').value;
if (tipo != 'l' && tipo != 'n' && tipo != 's') {return true;}
if (paso == 3 && (campo == 'padre' || campo == 'madre')) {return true;}
//var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
var nameRegex = /[\d|\.|\,|\@|\||\$|\&]+/; //elementos que no tiene que tener una cadena con letras

if (tipo == 'Ns') {
	if (!$F(campo)) {return true;}
	tipo = 's';
	}
if (!$(campo).value) {
	men = campo.toUpperCase( ) + ": Debe tener INFORMACION";
	Mensajes(campo,men);
	return false;
	}
if (tipo == 'l') {
	//alert($(campo).value.search(nameRegex));
	if ($(campo).value.match(nameRegex)) {
		men = campo.toUpperCase( ) + ": Solo se permiten LETRAS";
		Mensajes(campo,men);
		return false;
		}
	}
if (tipo == 'n') {
	if (isNaN($(campo).value)) {
		men = campo.toUpperCase( ) + ": Solo se permiten N&Uacute;MEROS";
		Mensajes(campo,men);
		return false;
		}
	}
return true;
}


/*	.................................................	*/
	// VALIDAR FORMULARIO USUARIOS => GUARDAR
	//Continua= indica si continua un tramite ya iniciado
/*	.................................................	*/
function Continua_Tramite(tramite) {
var formulario = $F('formularios_id');

var Param = "accion=Continua_Tramite&tramite=" + tramite;
if (formulario < 4) {var Despues = "ValidarDatos(1);";}
if (formulario == 4) {var Despues = "MostrarPantallaFin_D()";}

infajax("Informe_Datos","updater",Param,Despues);
return;
}


/*	.................................................	*/
		// MOSTRAR PANTALLA DE SEGUIR PROCESO::D
/*	.................................................	*/	
function MostrarPantallaFin_D() {
var Param = "accion=MostrarPantallaFin_D&formulario=4";
var Despues = "";

infajax("Result_Formulario","updater",Param,Despues);
}


/*	.................................................	*/
		// MOSTRAR U OCULTAR BUSCADOR DE PERSONAS
/*	.................................................	*/	
function MostrarBuscador(x,y) {
if (x == 0) {var mostrar = 'none';}
if (x == 1) {var mostrar = 'block';}
$('Buscador_Personas').style.display = mostrar;
if (x==1) {$('Sdocumento').focus();}

if (y == 1) {$('Sub-Titulo').innerHTML = "(1)&nbsp;&#8211;&#8250;&nbsp;Datos del SOLICITANTE";}
if (y == 2) {
	$('Sub-Titulo').innerHTML = "(2)&nbsp;&#8211;&#8250;&nbsp;Datos del CONYUGE";
	$('Linea_Cuit').style.display = 'none';
	}
if (y == 3) {
	$('Sub-Titulo').innerHTML = "(3)&nbsp;&#8211;&#8250;&nbsp;Datos del HIJO";
	$('Linea_Cuit').style.display = 'none';
	}
if (y == 4) {$('Sub-Titulo').innerHTML = "(1)&nbsp;&#8211;&#8250;&nbsp;Datos del SOLICITANTE-2";}
$('Sdocumento').value = "";
$('Scuit').value = "";
}

/*	.................................................	*/
		// BUSCA UNA PERSONA Y PRESENTA FICHA
/*	.................................................	*/
function InfBuscarPersona(datos,hijo_id) {
var formularios = $F('formularios_id');
if ($('continua')) {var continua = $F('continua');}
if ($('solicitante'))  {var solicitante  = $F('solicitante');}
if ($('solicitante2')) {var solicitante2 = $F('solicitante2');}
if ($('conyuge')) {var conyuge = $F('conyuge');}

if (formularios != 4) {
	if (datos == 'conyuge' && $('vacuit').value == 'si' ) {
		alert(error + "No se puede cargar un CONYUGE de una Persona Juridica");
		return;
		}
	if (datos == 'hijos' && $('vacuit').value == 'si' ) {
		alert(error + "No se puede cargar datos de HIJOS para una Persona Juridica");
		return;
		}
	if ( (datos == 'conyuge' || datos == 'hijos') && !solicitante) {
		alert(error + "Primero se debera indicar quien es el SOLICITANTE DEL TRAMITE.");
		return;
		}
	if (datos == 'solicitante2' && !solicitante) {
		alert(error + "Primero se debera indicar quien es el PRIMER SOLICITANTE DEL TRAMITE.");
		return;
		}

	if (datos == 'solicitante' || datos == 'solicitante2') {
		if (datos == 'solicitante') {var paso = 1;}
		if (datos == 'solicitante2') {var paso = 11;}
		if ((datos == 'solicitante' && !solicitante) || (datos == 'solicitante2' && !solicitante2)) {
			$('Result_Formulario').innerHTML = '';
			if (datos == 'solicitante2') {MostrarBuscador(1,4);}
			if (datos == 'solicitante') {MostrarBuscador(1,1);}
			$('Sdocumento').value = '';
			$('paso').value = paso;
			return;
			}
		else {
			if (datos == 'solicitante')  {id = solicitante;}
			if (datos == 'solicitante2') {id = solicitante2;}
			MostrarBuscador(0);
			}
	}

	if (datos == 'conyuge') {
		var paso = 2;
		if (!conyuge) {
			$('Result_Formulario').innerHTML = '';
			MostrarBuscador(1,2);
			$('Sdocumento').value = '';
			$('paso').value = paso;
			return;
			}
		if (conyuge > 0) {
			id = conyuge;
			MostrarBuscador(0);
			}
		}

	if (datos == 'hijos') {
		var paso = 3;
		if (!hijo_id) {
		$('Result_Formulario').innerHTML = '';
		MostrarBuscador(1,3);
		$('Sdocumento').value = '';
		$('paso').value = paso;
		return;
		}
	if (hijo_id > 0) {
		id = hijo_id;
		MostrarBuscador(0);
		}
	}

	$('paso').value = paso;
	
	var Param = "accion=BuscarPersona&id=" + id + "&continua=" + continua + "&paso=" + paso + "&formularios_id=" + formularios;
	}// fin formularios != 4

var Despues = "cargaLinks();";

if (formularios == 4) {
	var total = $('LosSolicitantes').length;
	var Param = "accion=BuscarPersona&id=" + datos + "&formularios_id=" + formularios + "&TotalSolicitantes=" + total;
	MostrarBuscador(0);
	}


infajax("Result_Formulario","updater",Param,Despues);
}



/*	.................................................	*/
// CONTROLA QUE EL HIJO NO SEA SOLICITANTE O CONYUGE
/*	.................................................	*/
function ControlPersona(paso) {
var men = "";
if (!paso || !$('personas_id').value) {return;}

/*	.......... CONTROL PERSONAS PARA FORMULARIO 4 .............	*/
if (paso == 0) {
var persona = $F('personas_id');

for (var i = 0; i < $('LosSolicitantes').length; i++) {
    if ($('LosSolicitantes').options[i].value == persona) {men="El Solicitante Ingresado coincide con otro ya Ingresado.";}
	}
} // fin formulario 4
/*	.......................................................	...	*/
if (paso == 1) { // solicitante
	if($('personas_id').value == $('conyuge').value){men="El Solicitante coincide con el Conyuge";}
	}
if ($F('formularios_id') == 3) {
	if (paso == 11) { // solicitante_2 (formulario c)
		if($('personas_id').value == $F('solicitante')){men="El Solicitante 1 coincide con el Solicitante 2";}
		}
	if (paso == 1) { // solicitante_2 (formulario c)
		if($('personas_id').value == $F('solicitante2')){men="El Solicitante 1 coincide con el Solicitante 2";}
		}
	}
if (paso == 2) { // conyuge
	if($('personas_id').value == $('solicitante').value){men="El Conyue coincide con el Solicitante";}
	}
if (paso == 3) { // solicitante
	if($('personas_id').value == $('solicitante').value || $('personas_id').value == $('conyuge').value){men="El Hijo indicado coincide con el Solicitante / Conyuge";}
	}

if (men) {
	alert(error + men + "\n\tOperacion no permitida...");
	$('Result_Formulario').innerHTML = '';
	MostrarBuscador(1,paso);
	$('Sdocumento').value = '';
	return;
	}

}

/*	.................................................	*/
	// VALIDAR FORMULARIO USUARIOS => GUARDAR
	//Continua= indica si continua un tramite ya iniciado
/*	.................................................	*/
function ValidarDatos() {
var campo = "";
var men   = "";
var formularios = $F('formularios_id');
if ($('paso')) {var paso = $F('paso');}
if ($('continua')) {var continua = $F('continua');}
if ($('solicitante')) {var solicitante = $F('solicitante');}

  var nameRegex  = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var numRegex   = /^[\d|\-]+$/;

var Param = "accion=BuscarPersona&formularios_id=" + formularios + "&paso=" + paso;
if (continua == 1) {Param += "&continua=" + continua;}

var documento	= $('Sdocumento').value;
var cuit		= allTrim($F('Scuit'));

if (!documento && !cuit) {
    	campo = 'Sdocumento';
		men = "Debe ingresar el N&uacute;mero de Documento o el CUIT.";
		Mensajes(campo,men);
		return;
		}
	else {
		if (documento) {
			var opt = 0;
			if (isNaN(documento)) {
				men = "Documento: debe contener un Numero Valido.<br>";
				opt = 1;
				}
			if (documento.length > 8) {
				men = "Documento: debe contener un Numero Valido.<br>";
				opt = 1;
				}
			if (opt == 1) {
					campo = 'Sdocumento';
					Mensajes(campo,men);
					return;
					}
			}
		if (!documento && cuit) {
			if (cuit.search(numRegex) == -1 ) {
					campo = 'Scuit';
					men = "CUIT: debe contener un Numero Valido.<br>";
					Mensajes(campo,men);
					return;
					}
			}//fin no documento si cuit
		}
	
	if (documento) {Param += "&documento=" + documento;}
	else {
		Param += "&cuit=" + cuit;
		$('vacuit').value = "si";
		}
	
	var Despues = "$('Result_Formulario').style.display='block';cargaLinks(); $('Buscador_Personas').style.display='none';";
	if (formularios != 4) {Despues += "ControlPersona('"+paso+"');";}
	if (formularios == 4) {Despues += "ControlPersona('0');";}
	if (paso == 3) {Despues += "$('padre_id').value = " + solicitante;}
	infajax("Result_Formulario","updater",Param,Despues);
	return;

}


/*	..............................................	*/
	// YES YES YES:: ELIMINAMOS A LA CONYUGE
/*	..............................................	*/
function QuitarConyuge() {
var conyuge  = $('conyuge').value;
var informes = $('informes_id').value;
var ok = confirm(cambios + "Ha solicitado QUITAR DEL PEDIDO DE TITULARIDAD A SU CONYUGE.\n\nConfirma el pedido...???");
if (!ok) {return;}

var Param = "accion=QuitarConyuge&informe=" + informes;
var Despues = "var i=transport.responseText;if (i=='-1'){alert('Que cosa RARA... No se ha encontrado el informe');} if (i=='0'){alert('Se han detectado problemas en las comunicaciones...\\n\\nIntente mas tarde.\\n\\n\\tGracias');} if (i=='1'){$('PerConyuge').innerHTML='...';$('conyuge').value = '';Prepara_Conyuge();}";

infajax("Result_Formulario","request",Param,Despues);
}


/*	..............................................	*/
			// QUITAR HIJO DE UN FORMULARIO
/*	..............................................	*/
function QuitarHijo(id) {
if (!id) {return;}

var Param = "accion=QuitarHijo&id=" + id;
var Despues = "var i=transport.responseText.split('@');if (i[0]==-1){alert('La persona solicitada no se ha encontrado en el sistema');} if (i[0]==0){alert('Se han detectado problemas en las comunicaciones...\\n\\nIntente mas tarde.\\n\\n\\tGracias');} if (i[0]==1){$('PerHijos').innerHTML=i[1];BuscarPersona('hijos');}";

infajax("Result_Formulario","request",Param,Despues);

}


/*	..............................................	*/
		// QUITAR SOLICITANTE 2 FORMULARIO C
/*	..............................................	*/
function QuitarSolicitante2() {
var informes = $F('informes_id');
var id = $F('solicitante2');
var ok = confirm(cambios + "Ha solicitado QUITAR DEL FORMULARIO 'C' AL SOLICITANTE 2.\n\nConfirma el pedido...???");
if (!ok) {return;}
var Param = "accion=QuitarSolicitante2&id=" + id + "&informe_id=" + informes;
var Despues = "var i=transport.responseText;if (i=='-1'){alert('No se ha encontrado el informe solicitado');} if (i=='0'){alert('Se han detectado problemas en las comunicaciones...\\n\\nIntente mas tarde.\\n\\n\\tGracias');} if (i=='1'){$('PerSolicitante_2').innerHTML='...';$('solicitante2').value = '';BuscarPersona('solicitante2');}";
infajax("Result_Formulario","request",Param,Despues);

}


/*	..............................................	*/
		// QUITAR SOLICITANTE FORMULARIO D
/*	..............................................	*/
function QuitarSolicitanteFormD() {
var ok = confirm(cambios + "Ha solicitado QUITAR UN SOLICITANTE DEL FORMULARIO 'D'.\n\nConfirma el pedido...???");
if (!ok) {return;}

var informes = $F('informes_id');
var id		 = $F('personas_id');

var Param = "accion=QuitarSolicitante_D&id=" + id + "&informe_id=" + informes;
var Despues = "var i=transport.responseText;if (i=='0'){alert('Se han detectado problemas en las comunicaciones...\\n\\nIntente mas tarde.\\n\\n\\tGracias');} if (i=='1'){EliminarSolicitante();$('Result_Formulario').innerHTML ='';MostrarBuscador(1,1);}";
infajax("Result_Formulario","request",Param,Despues);
}

/*	.................................................	*/
	//PRESENTA PANTALLA PARA INMUEBLES
/*	.................................................	*/
function FichaInmueble() {
var id = $F('inmueble_id');
MostrarBuscador(0);
$('LosSolicitantes').selectedIndex = -1;
var Param = "accion=FichaInmueble&id=" + id;
var Despues = "";
infajax("Result_Formulario","updater",Param,Despues);
}


/*	.................................................	*/
	//CAMBIA EL FOCO DEL COMBO DEPARTAMENTOS
/*	.................................................	*/
function ControlDepartamentos() {
$('direccion').focus();
}


/*	.................................................	*/
	//PROCESA INMUEBLE CARGADO
/*	.................................................	*/
function GuardarInmueble() {
var men = "";
var matricula	= $F('matricula');// Folio Real
var inscripcion = $F('inscripcion');
var tomo		= $F('tomo');
var cod_tomo	= $F('cod_tomo');
var fojas		= $F('fojas');
var direccion	= $F('direccion');
var superficie	= $F('superficie');
var departamento= $F('departamentos_id');

if (!matricula && !inscripcion) {
	men = "Debe indicar algun dato de inscripcion del inmueble:\n\nNumero Matricula (Folio Real) o Datos Sistema de Tomos.\n\n";
	var foco = "matricula";
	}
	
if (matricula) {
	matricula = allTrim(matricula);
	if (isNaN(matricula) || matricula.indexOf('.',0) > -1) {men = "Numero Matricula\t: Debe ingresar un numero valido.\n";}
	var foco = "matricula";
	}
if (inscripcion) {
	if (!tomo || !fojas) {men += "Tomo / Fojas\t: Estos campos no pueden estar vacios.\n";}
	inscripcion = allTrim(inscripcion);
	if (isNaN(inscripcion) || inscripcion.indexOf('.',0) > -1) {
		men += "Numero Asiento\t: Debe ingresar un numero valido.\n";
		var foco = "inscripcion";
		}	
	if (tomo) {
		tomo = allTrim(tomo);
		if (isNaN(tomo) || tomo.indexOf('.',0) > -1) {men += "Tomo\t\t: Debe ingresar un numero valido.\n";}
		var foco = "tomo";
		}
	if (fojas) {
		fojas = allTrim(fojas);
		if (isNaN(fojas) || fojas.indexOf('.',0) > -1) {men += "Fojas\t\t: Debe ingresar un numero valido.\n";}
		var foco = "fojas";
		}
	}// fin de inscripcion

if (departamento == 0) {men += "Departamento\t: Debe indicar el departamento donde esta el inmueble.\n";}

if (men) {
	alert(error + men);
	$(foco).focus();
	return;
	}

var Param = "accion=GuardarInmueble&" + Form.serialize('formInmuebles');
var Despues = "var i=transport.responseText;if(i==0){alert(error + 'No se ha encontrado el inmueble solicitado');} if (i>1){alert('Inmueble Guardado Satisfactoriamente');$('inmueble_id').value=i;$('id').value=i;} if (i==-1){alert(error + 'Problemas en las comunicaciones... no se pudo acceder al banco de datos.');}";
infajax("Result_Formulario","request",Param,Despues);
}



function MostrarBuscadorInformes() {
if (Info == 0) {
	$('ContenedorBuscarInformes').style.display = "block";
	$('TituloBuscarInforme').innerHTML = "Cerrar B&uacute;squeda de Informes";
	var dat = 1;
	}
if (Info == 1) {
	$('ContenedorBuscarInformes').style.display = "none";
	$('TituloBuscarInforme').innerHTML = "Buscar Informes Tramitados";
	var dat = 0;
	}

Info = dat;
}

/*	.......................................................	*/
	//LISTAR INFORMES ENVIADOS, RESPONDIDOS, LEIDOS, ETC
	//reparticion = id de la reparticion que consulta
	//estado:
		//0: Iniciados NO ENVIADOS
		//4: Terminados (DRP) No Leidos por reparticion
/*	.......................................................	*/
function VerInformes_SOnline(reparticion,estado) {
if (!reparticion) {return;}
if (estado == "") {estado = 0;}

var Param = "accion=VerInformes_SOnline&estado=" + estado + "&reparticion=" + reparticion;

if (estado == -100) {
	var nom = Base64.encode($F('InfNombre').toLowerCase());
	var doc = $F('InfDocumento');
	var raz = Base64.encode($F('InfRazon').toLowerCase());
	var cui = $F('InfCuit');
	if ( !nom && !doc && !raz && !cui ) {return;}
	
	if (isNaN(doc)) {
		alert(error + "Numero de Documento\t: Debe ser un numero valido.");
		return;
		}
	
	Param += "&apellido=" + nom + "&documento=" + doc + "&razonsocial=" + raz + "&cuit=" + cui;
	}// fin estado -100

var Despues = "";

infajax("Cuerpo","updater",Param,Despues);
}


/*	.......................................................	*/
	// Ver informe terminado y Marcar como leído
/*	.......................................................	*/
function TomarInformeTerminado(id,reparticion,creado) {
if (!id || !reparticion) {return;}
var estado = 4; //informe terminado
var status = 'menubar=no,resizable=yes,scrollbars=yes,top=100';

var Param = "accion=TomarInformeTerminado&informe_id=" + id + "&reparticion_id=" + reparticion + "&creado=" + creado;
var Despues = "var i=transport.responseText.split('@');if (i[0]==0) {alert(i[1]);}if (i[0]==1) {var vent = window.open('control/control_informes.php?accion=MostrarPDF_Terminado&archivo='+i[1]);}";
if (!creado || creado == 0) {Despues += "VerInformes_SOnline(" + reparticion + ",4);";}

infajax("Cuerpo","request",Param,Despues);
}

function LLamarMenu(opcion) {
consultas = "";
Ejecutar(opcion);
}





/*	............................................................................................................
*****			SISTEMA DE INFORMES ESPECIALES ::: CONTRATO LOCACION FRECUENCIA DE PEDIDOS DE INFORMES
................................................................................................................	*/



/*	............................................................	*/
	// BUSCAR RESULTADOS EN TABLA DE DATOS::: GARANTIAS
	// TIPO = 1 :: FOLIO REAL ; TIPO =2 :: SISTEMA TOMOS
/*	............................................................	*/
function Informes_FrecuenciaPedidos(tipo) {
var men = "";
/* ..... DATOS DE TERCEROS .....	*/
var tel			= $F('Btelefono');
var matricul	= $F('Bmatricul');
var nombre		= $F('Bnombre').toLowerCase();
$('Bnombre').value = nombre;
/* .............................	*/

if (tipo == 1) {//folio real
	$('Bmatricula').value = allTrim($F('Bmatricula'));
	$('Bmatricula').value = $F('Bmatricula').replace('.','');
	$('Bmatricula').value = $F('Bmatricula').replace(',','');
	var mat = $F('Bmatricula');
	if (!mat )		{men += " Matricula\t: No puede estar sin DATOS\n";}
	if (isNaN(mat)) {men += " Matricula\t: Debe Indicar un numero valido\n";}
	if (mat.indexOf('.') > -1 || mat.indexOf(',') > -1) {men += " Matricula\t: No puede contener letras ni simbolos\n";}
	if (men) {
		alert(error + men);
		return;
		}
	var Param = "accion=BuscarInformeGarantias&tipo="+tipo+"&matricula=" + mat;
	}//Fin tipo=1

if (tipo == 2) {//sistema de tomos
	$('Btomo').value = allTrim($F('Btomo'));
	$('Btomo').value = $F('Btomo').replace('.','');
	$('Btomo').value = $F('Btomo').replace(',','');
	var Btomo  = $F('Btomo');
	
	var Bctomo = $F('Bctomo').toLowerCase();
	
	$('Bfojas').value = allTrim($F('Bfojas'));
	$('Bfojas').value = $F('Bfojas').replace('.','');
	$('Bfojas').value = $F('Bfojas').replace(',','');
	var Bfojas = $F('Bfojas');
	var Bdepto = $('departamentos_id').value;
	
	if (!Btomo)												{men += " Tomo \t: Debe Indicar un numero de Tomo  (debe ser un numero valido)\n";}
	if (isNaN(Btomo))										{men += " Tomo \t: Debe Indicar un numero valido\n";}
	if (Btomo.indexOf('.') > -1 || Btomo.indexOf(',') > -1) {men += " Tomo \t: No puede contener letras ni simbolos\n";}

	if (!Bfojas)												{men += " Fojas\t: Debe Indicar un numero de Fojas (debe ser un numero valido)\n";}
	if (isNaN(Bfojas))											{men += " Fojas\t: Debe Indicar un numero valido\n";}
	if (Bfojas.indexOf('.') > -1 || Bfojas.indexOf(',') > -1)	{men += " Fojas\t: No puede contener letras ni simbolos\n";}
	
	if (Bdepto == 0)	{men += " Depto\t: Seleccione un Departamento\n";}
	if (men) {
		alert(error + men);
		return;
		}
	
	$('Bfojas').value = $F('Bfojas') * 1;
	$('Btomo').value  = $F('Btomo') * 1;
	
	var Param = "accion=BuscarInformeGarantias&tipo="+tipo+"&Tomo=" + Btomo + "&CTomo=" + Bctomo + "&Fojas=" + Bfojas + "&Depto=" + Bdepto;
	}//Fin tipo=2

var Despues = "";
//var Despues = "var i=transport.responseText.split('@');if (i[0]==0) {alert(i[1]);} if (i[0]==1) {var vent = window.open('control/control_informes.php?accion=MostrarPDF_Terminado&archivo='+i[1]);}";

if (tel || matricul || nombre) {Param += "&telefono=" + tel + "&matricul=" + matricul + "&nombre= " + nombre;}
Lanzador("Cuerpo","updater",Param,Despues);
}


/*	............................................................	*/
	// IMPRIMIR RESULTADOS ::: GARANTIAS
/*	............................................................	*/
function Informes_FrecuenciaPedidosPRINT() {
var inicio = "";
var titulos = "";
var cabecera = "";
var contenido = "";
var t1 = $('FPI_titulo1').innerHTML;
var t2 = $('FPI_titulo2').innerHTML;
var t3 = $('FPI_titulo3').innerHTML;

cabecera  = '\n<div style="float:left;">\n<img src="imagenes/logo/logo_cort_color.jpg" width="150" height="70" />\n</div>\n';
cabecera += '<div align="center" style="width:700px;float:left;margin-top:2px;margin-left:80px;">\n<p style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:24px"><strong>DIRECCI&Oacute;N DE REGISTROS P&uacute;BLICOS</strong><br />\n<strong class="LetraNormal_10">\n1ra. 3ra. y 4ta. Circunscripci&oacute;n Judicial - Provincia de Mendoza\n</strong>\n</p><br>\n<p style="font-size:20px;">' + t1 + '</p>\n</div>\n';
cabecera += '\n<div align="center" style="float:left;padding-top:15px;margin-top:30px;width:999px;border-top:#CCCCCC solid 1px;">\n' + t2 + '\n</div>\n';

inicio  = '\n<link rel="stylesheet" type="text/css" href="funciones/estilos.css">\n';
inicio += '\n<link rel="stylesheet" type="text/css" href="funciones/letras.css">\n';
contenido = '<div align="center" style="float:left;padding-top:8px;margin-top:20px;width:999px; font-size:15px;">';
contenido += $('FPI_Result').innerHTML + "</div>";

var vent = window.open('','IMPRIMIR');
vent.document.write(inicio + cabecera + contenido);
//vent.document.getElementById('IDButton').style.display = "none";
vent.document.close();
}
