// JavaScript Document
//Oscar Quattrini: 2615527850
var paso1 = "";
var paso2 = "";
var paso3 = "";
var Evento = "";
var navegador = "";
var Envio = "";
var Can = "";
var pe = "";
var IE = document.all ? true : false;
var ventmensajes = "";
var Decreto = "";

var win = window;    // Con frames usar top.nombre.window;
var Bn   = 0;
var quebusca="";


var mtdoc		= "";
var mdoc		= "";
var mnombre		= "";
var mapellido	= "";
var mcuit1		= "";
var mcuit2		= "";
var mcuit3		= "";
var mrazon		= "";
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";


/*	...........................................	*/
		// BUSCAR PALABRAS EN LA PAGINA
/*	...........................................	*/
function BuscarEnPagina(str) {
var txt, i, found;
if (str == "") {return false;}

if (quebusca != str) {
	quebusca = str;
	Bn = 0;
	}
if (!IE) {
	if (Bn < 1) {document.body.focus();}
	if (!win.find(str)) {
		while(win.find(str, false, true)) {Bn = Bn + 1;}
		}
    else {Bn = Bn + 1;}

	if (Bn == 0) {alert("El texto solicitado '" + str + "' No se ha encontrado");}
	}

if (IE) {
	txt = win.document.body.createTextRange();
	for (i = 0; i <= Bn && (found = txt.findText(str)) != false; i++) {
		txt.moveStart("character", 1);
		txt.moveEnd("textedit");
		}
	if (found) {
		txt.moveStart("character", -1);
		txt.findText(str);
		txt.select();
		txt.scrollIntoView();
		Bn++;
		}
	else {
		if (Bn > 0) {
			Bn = 0;
			BuscarEnPagina(str);
			}
		else {alert("El texto solicitado '" + str + "' No se ha encontrado");}
		}
	}
return false;
}

/*	............................................	*/
		// DRAG AND DROP
/*	............................................	*/
posicion=0;
// IE
if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0;
// Otros
else navegador=1;
/*	............................................	*/
 
function evitaEventos(event) {
// Funcion que evita que se ejecuten eventos adicionales
if(navegador==0) {
	window.event.cancelBubble=true;
	window.event.returnValue=false;
	}
if(navegador==1) {event.preventDefault();}
}
 
function comienzoMovimiento(event, id) {
elMovimiento=document.getElementById(id);
// Obtengo la posicion del cursor
if(navegador==0) {
	cursorComienzoX=window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft;
	cursorComienzoY=window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop;
	document.attachEvent("onmousemove", enMovimiento);
	document.attachEvent("onmouseup", finMovimiento);
	}
if(navegador==1) {    
	cursorComienzoX=event.clientX+window.scrollX;
	cursorComienzoY=event.clientY+window.scrollY;
	document.addEventListener("mousemove", enMovimiento, true); 
	document.addEventListener("mouseup", finMovimiento, true);
	}
    
elComienzoX=parseInt(elMovimiento.style.left);
elComienzoY=parseInt(elMovimiento.style.top);
// Actualizo el posicion del elemento
//elMovimiento.style.zIndex=++posicion;
elMovimiento.style.zIndex=1010;
evitaEventos(event);
}
 
function enMovimiento(event) {  
var xActual, yActual;
if(navegador==0) {    
	xActual=window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft;
	yActual=window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop;
	}  
if(navegador==1) {
	xActual=event.clientX+window.scrollX;
	yActual=event.clientY+window.scrollY;
	}
elMovimiento.style.left=(elComienzoX+xActual-cursorComienzoX)+"px";
elMovimiento.style.top=(elComienzoY+yActual-cursorComienzoY)+"px";
evitaEventos(event);
}
 
function finMovimiento(event) {
if(navegador==0) {    
	document.detachEvent("onmousemove", enMovimiento);
	document.detachEvent("onmouseup", finMovimiento);
	}
if(navegador==1) {
	document.removeEventListener("mousemove", enMovimiento, true);
	document.removeEventListener("mouseup", finMovimiento, true);
	}
}
 
//window.onload=carga;
//onmousedown="comienzoMovimiento(event, 'Cdoc');" onmouseover="this.style.cursor='move'"
/*	............................................	*/


/*	........................................	*/
		// VALIDAR CAMPOS
		// d= solo digitos
		// n= numérico
		// s= string
		// @= direccion de correo
/*	........................................	*/
function Valida(str,control) {
if (!str) {return;}

if (control == 'd')	{
	str = str.replace(/^\s*|\s*$|\W/g,"");
	str = str.replace(/\D|\.|\,|\-/g,"");
	}
if (control == 'n')	{
	str = str.replace(/^\s*|\s*$|\W/g,"");
	str = str.replace(/\D|\,|\-/g,"");
	}
if (control == 's') {
	str = str.replace(/^\s+|\s+$/g,"");
	str = str.replace(/\.|\||\,|\-/g,"");
	str = str.replace(/\d/g,"");
	str = str.replace(/\@|\\|\/|\!|\"|\·|\#|\$|\%|\(|\)|\=|\?|\¿/g,"");
	while (str.indexOf("  ") != -1) {str = str.replace("  "," ");}
	}
if (control == '@') {
	if(!(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(str))){return false;}
	return true;
	}	
return str;
}

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

if (Tipo == "updater") {

new Ajax.Updater(Destino, 'control/control_inhibiciones.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_inhibiciones.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 Ingreso_Externo() {
var Param = "accion=Ingreso_Externo";
var Despues = "cargaLinks();location.href='#';";

iajax("IContenedor","updater",Param,Despues);
}


/*	..........................................	*/
	// ACTIVA PANTALLA DE LOGIN
/*	..........................................	*/
function LoginInhibiciones() { 
	var Despues = "location.href='#';$('Cusuario').focus()";
	iajax("Cuerpo","updater","accion=LoginInhibiciones",Despues);
}

/*	..........................................	*/
	// USUARIO LOGEADO.. VERIFICA USUARIO
/*	..........................................	*/
function Inhibiciones_Login() {
var usuario = $('Cusuario').value;
var clave   = $('Cclave').value

if ( !usuario || !clave) {return;}

var Param = "accion=LoginInhibiciones&usuario=" + usuario + "&clave=" + clave;
var Despues = "var i = transport.responseText.split('@');if(i[0]!=0){$('Inferior').innerHTML = i[2];paso3 = $('IContenedor').innerHTML;cargaLinks();Contabilizar_Mensajes();}else{$('Cuerpo').innerHTML = i[2];}";

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



/*	..........................................	*/
	// USUARIO LOGEADO.. VERIFICA USUARIO
/*	..........................................	*/
function Alta_Inhibiciones() {
paso1 = $('Inferior').innerHTML;
var Param = "accion=Alta_Inhibiciones";
var Despues = "";

iajax("IAccion","updater",Param,Despues);
}


/*	.......................................	*/
	// BUSCA MEDIDA = BuscarExpediente
/*	.......................................	*/
function EditarMedida(tribunal,expediente,activo,e) {
var origen = $('Morigen').value;

BuscarExpediente(tribunal,expediente,'',activo,origen);
if(navegador == 0) {window.event.cancelBubble = true;}
if(navegador == 1) {e.stopPropagation();}
}




/*	..........................................	*/
	// ALTA INHIBICIONES: BUSCAR EXPEDIENTE
/*	..........................................	*/
function BuscarExpediente(t,e,z,activo,origen) {
var men = "";
if (activo != undefined) {
	if (activo == 0) {
		alert(error + "El expediente solicitado ha sido declarado: NO ACTIVO por Jefatura.\n\n\tEl mismo no puede ser abierto");
		return;
		}
	}


if (!t) {var tribunal = $('Atribunal').value;}
	else {var tribunal = t;}
if (!e) {var expediente = $('Aexpediente').value;}
	else {var expediente = e;}

if (z==1) {destino = "#Lista";}
else {destino = "#";}
if (z == undefined) {z = "";}
if (tribunal == 0)     {men = "Tribunal\t\t: Debe seleccionar un tribunal\n";}
expediente = Valida(expediente,'n');
if (isNaN(expediente)) {men += "Expediente\t: Ingrese un numero valido\n";}

if (men) {
	men = "SE HAN ENCONTRADO LOS SIGUIENTES ERRORES:...\n\n" + men;
	alert(error + men);
	return;
	}

if (!t && !e) {paso2 = $('IContenedor').innerHTML;}
var Param = "accion=BuscarExpediente&tribunal=" + tribunal + "&expediente=" + expediente + "&origen=" + z;
if (origen) {Param += "&origen=" + origen;}

var Despues = "var i=transport.responseText.split('@');if (i[0]==0){$('MBexpediente').innerHTML = i[1];} else {$('IContenedor').innerHTML = i[1];document.GetElementById('Adocumento').focus();}";
//location.href='" + destino + "'; esto fue quitado de Despues
iajax("IContenedor","request",Param,Despues);
}


/*	..........................................	*/
	// MODIFICAR EXPEDIENTE; x= id expediente
/*	..........................................	*/
function ModificarExpediente(x) {
if (!x) {return;}
var origen = $('origen').value;
if (origen != "tribunal") {origen == "";}
var Param = "accion=ModificarExpediente&id=" + x + "&origen=" + origen;
$('VerFicha').style.top =  "100px";
$('VerFicha').style.left = '100px';
$('VOpaca').style.width = screen.availWidth;
$('VOpaca').style.height= screen.availHeight + document.documentElement.scrollTop;
$('VOpaca').style.display = 'block';
$('VerFicha').style.display = 'block';

var Despues = "var i=transport.responseText.split('@');if (i[0]==0){alert(error + 'El expediente solicitado NO EXISTE EN EL SISTEMA');} else {$('VerFicha').innerHTML = i[1];}";

iajax("VerFicha","request",Param,Despues);
}


/*	..........................................	*/
	// GUARDA DATOS EXPEDIENTES
	// x= indica si es modal o no
	// x == 3 indica LLAMADO POR EL JUZGADO
/*	..........................................	*/
function GuardarExpediente(x) {
var men = "";
var origen = $('origen').value;
if (origen == "tribunal") {x = 3;}
//var tribunal_id  = $('tribunal_id').value;

if ($('Btribunal')) {var tribunal_id  = $('Btribunal').value;}
else {var tribunal_id  = $('tribunal_id').value;}

var numero		 = $('numero').value;
var actor		 = $('actor').value;
var demandado	 = $('demandado').value;
var por			 = $('por').value;
var usuario 	 = $('usuarios_id').value;
var id			 = $('expediente_id').value;

if (!usuario || usuario == '0') {men = "Usuario: Debe Indicar el Nombre de Usuario que solicita la medida o tramite el expediente.\n";}
if (!numero || !actor || !demandado || !por) {men += "\tNumero, Actor, Demandado y Motivo:\n\n\tDEBEN TENER INFORMACION";}

if (men) {
	alert(error + men);
	return;
	}

var Param = "accion=GuardarExpediente&tribunal_id=" + tribunal_id + "&numero=" + numero + "&actor=" + actor + "&demandado=" + demandado + "&por=" + por + "&expediente_id=" + id + "&usuarios_id=" + usuario + "&origen=" + origen;

if (x == 3) {
	var Despues = "var i=transport.responseText;if (i=='1'){CierraVentanaModal();alert('Expediente Guardado Satisfactoriamente');Tribunales_BuscarExpediente();} else {alert('Error de sistema... \\nNo se pudo guardar el expediente');}";
	}
else {
	var Despues = "var i=transport.responseText;if (i=='1'){CierraVentanaModal();BuscarExpediente('"+tribunal_id+"','"+numero+"');} else {alert('Error de sistema... \\nNo se pudo guardar el expediente');}";
	}

iajax("IContenedor","request",Param,Despues);
}

/*	..........................................	*/
	// ALTA INHIBICIONES: BUSCAR PERSONA
	// x=crear; para crear nueva persona
/*	..........................................	*/
function Inhibiciones_BuscarPersonas(x) {
var men = "";
var pos = "";
var tdoc = $('Atdoc').value;
var doc  = $('Adocumento').value;
var cuit1 = $('Acuit1').value;
var cuit = $('Acuit').value;
var cuit2 = $('Acuit2').value;
var nombre   = $('Anombre').value;
var apellido = $('Aapellido').value;
var razon    = $('Arazon').value;
var tribunal_id	= $('Itribunal_id').value;
var expediente  = $('Iexpediente').value;
var cuittotal;

if (cuit1 && cuit && cuit2) {
	cuit = Valida(cuit,'n');
	cuit1 = Valida(cuit1,'n');
	cuit2 = Valida(cuit2,'n');
	$('Acuit').value = cuit;
	$('Acuit1').value = cuit1;
	$('Acuit2').value = cuit2;
	cuittotal = cuit1 + "-" + cuit + "-" + cuit2;
	if (isNaN(cuit) || isNaN(cuit1) || isNaN(cuit2)) {men += "C.UIT\t\t: Ingrese un numero valido\n";}
	}
	
if ( (tdoc || doc || nombre || apellido) && (cuittotal || razon) ) {
		alert(error + "Debe seleccionar entre PERSONA FISICA o PERSONA JURIDICA");
		return;
		}
if (!doc && !cuittotal && !apellido && !razon) {men += "Debe ingresar informacion para buscar\n";pos = 1;}
if (!doc && !cuittotal && !apellido && !razon && nombre) {men = "No se permite buscar solo por nombre\n";pos = 3;}
if (!doc && !cuittotal && apellido && !razon && !nombre) {men = "No se permite buscar solo por apellido\n";pos = 2;}


if (doc) {
	if (!tdoc) {men += "Tipo Documento  \t: Debe seleccionar un tipo de documento\n";}
	doc = Valida(doc,'n');
	$('Adocumento').value = doc;
	if (isNaN(doc)) {men += "Documento  \t: Ingrese un numero valido\n";}
	}

if (nombre) {
	nombre = Valida(nombre,'s');
	$('Anombre').value = nombre;	
	}
if (apellido) {
	apellido = Valida(apellido,'s');
	$('Aapellido').value = apellido;
	if (apellido.length < 3) {men += "Apellido  \t: Debe tener 3 o mas caracteres.\n";}
	}


if (men) {
	men = "SE HAN ENCONTRADO LOS SIGUIENTES ERRORES:...\n\n" + men;
	alert(men);
	switch (pos) {
		case 1 : $('Adocumento').focus();break;
		case 2 : $('Anombre').focus();break;
		case 3 : $('Aapellido').focus();break;
		}
	return;
	}

if (x == 'crear') {
	if ( (tdoc || doc || nombre || apellido) && (cuittotal || razon) ) {
		alert(error + "Debe seleccionar entre PERSONA FISICA o PERSONA JURIDICA");
		return;
		}
	if (!razon && !cuittotal && !nombre && !apellido) {
		alert(error + "Debe consignar NOMBRE Y APELLIDO o CUIT Y RAZON SOCIAL");
		return;
		}
	if (nombre || apellido || tdoc || doc) {
		if (!tdoc)     {men += "Tipo Doc   \t: No ha Seleccionado un TIPO DE DOCUMENTO\n";}
		if (!doc)      {men += "Documento\t: No ha Ingresado un DOCUMENTO DE IDENTIDAD\n";}
		if (!nombre)   {men += "Nombre\t\t: Debe indicar el Nombre.\n";}
		if (!apellido) {men += "Apellido\t\t: Es indispensable indicar el apellido.\n";}		
		}
	
	if (razon || cuittotal) {
		if (razon && !cuittotal) {men = "Cuit \t\t: No ha Ingresaro el C.U.I.T correctamente\n";}	
		if (cuittotal && !razon) {men += "Razon\t\t: Ha ingresado CUIT pero no RAZON SOCIAL\n";}	
		}
	
	if (men) {
		alert(error + men);
		return;
		}
		
	var ok=confirm(cambios + "Se recomienda verificar la informacion.\nDisponer de todos los datos necesarios para identificar a una persona FISICA O JURIDICA\n\n" + men + "\n\t\t\tContinua con la operacion...???");
	if (!ok) {return;}
	var Param = "accion=CrearPersonas" + "&tribunal_id=" + tribunal_id + "&expediente=" + expediente + "&tdoc=" + tdoc + "&nombre=" + nombre + "&apellido=" + apellido;
	var Despues = "var i=transport.responseText;if (i=='1') {Inhibiciones_BuscarPersonas();} else {alert('Problemas al crear persona... comuniquese con informatica');}";
	var modalidad = "request";
	}
	
else {
	var Param = "accion=BuscarPersonas" + "&tribunal_id=" + tribunal_id + "&expediente=" + expediente;
	var Despues = "";
	var modalidad = "updater";
	}

if (doc)     {Param += "&doc=" + doc + "&tdoc=" + tdoc;}
if (cuit)    {Param += "&cuit=" + cuittotal;}
if(nombre)   {Param += "&nombre=" + nombre;}
if(apellido) {Param += "&apellido=" + apellido;}
if(razon)    {Param += "&razon=" + razon;}



iajax("Pencontradas",modalidad,Param,Despues);
}


/*	.........................................	*/
		// ACCION DEL BOTON ATRAS
/*	.........................................	*/
function Atras(x,origen) {
if (!x) {return;}
if (x == 'paso1') {x = paso1;}
if (x == 'paso2') {x = paso2;}
if (x == 'paso3') {x = paso3;}

if (origen && origen != undefined) {
	var i = origen.split('.');
	if (i[0] == 'medida') {
		BuscarMedidas(i[1]);
		return;
		}
	}

$('IContenedor').innerHTML = x;
location.href = "#";
return;
}


/*	..........................................	*/
	// Analiza la tecla pulsada
/*	..........................................	*/
function Avanzar(x) {
if (!x) {return;}
var avanza = 0;

if (x == "Adocumento" && $('Adocumento').value) {avanza = 1;}
if (x == "Aapellido" && $('Aapellido').value) {
	if ($('Anombre').value || $('Adocumento').value) {avanza = 1;}
	else {
		if (!$('Anombre').value) {$('Anombre').focus();return;}
		if (!$('Adocumento').value) {$('Adocumento').focus();return;}
		}
	}
if (x == "Acuit" && $('Acuit').value) {avanza = 1;}
if (x == "Arazon" && $('Arazon').value) {avanza = 1;}

if (x == "Acuit1" || x == "Acuit" || x == "Acuit2") {
	if ($('Acuit1').value && $('Acuit').value && $('Acuit2').value) {avanza = 1;}
	else {
		if (!$('Acuit1').value) {$('Acuit1').focus();return;}
		if (!$('Acuit').value) {$('Acuit').focus();return;}
		if (!$('Acuit2').value) {$('Acuit2').focus();return;}
		}
	}

if (avanza == 1) {Inhibiciones_BuscarPersonas();}

return;
}

/*	..........................................	*/
	// ABRIR VENANA MODAL
/*	..........................................	*/
function CierraVentanaModal() {
if ($('VOpaca')) {$('VOpaca').style.display='none';}
if ($('light'))  {$('light').style.display='none';}
if ($('VerFicha')) {
	$('VerFicha').style.display='none';
	$('VerFicha').innerHTML = "";
	}
}


/*	..........................................	*/
  // PRESENTAR PAGINA PARA MODIFICAR PERSONA
  // x = fila seleccionada
/*	..........................................	*/
function Pagina_Modificar_Persona(x,e) {
if (!x) {return;}

var tipodoc	  	= $('Itipodoc_' + x).value;
var documento	= $('Idocumento_' + x).value;
var nombre		= $('Inombre_' + x).value;
var apellido	= $('Iapellido_' + x).value;
var razon		= $('Irazon_' + x).value;
var cuit		= $('Icuit_' + x).value;
var id_persona  = $('Iidpersona_' + x).value;

var Param = "control/control_inhibiciones.php?accion=Pagina_Modificar_Persona&fila="+x+"&tipodoc=" + tipodoc + "&documento="+documento+"&nombre="+nombre+"&apellido="+apellido+"&razon="+razon+"&cuit="+cuit+"&id_persona="+id_persona;
ventmensajes = TINY_BOX.box;
ventmensajes.show(Param,1,0,0,1,0);
e.cancelBubble = true;
}

/*	..........................................	*/
// REALIZAR CAMBIOS DE PERSONA EN PANTALL
//control= tipo persona =  1=fisica; 2=juridica
/*	..........................................	*/
function Procede_Modificar_Persona(control) {
var id_persona    = $F('Newid_persona');
var fila		  = $F('fila');
var documento	  = $F('Idocumento_' + fila);
var tipodoc	  	  = $F('Itipodoc_' + fila);
var vnombre		  = $F('Inombre_' + fila);
var vapellido	  = $F('Iapellido_' + fila);
var cuit		  = $F('Icuit_' + fila);
var vrazon		  = $F('Irazon_' + fila);
var expediente_id = $F('Iexpediente_id');
var origen		  = $F('origen');
var caratula	  = $F('Icaratula');
var numero		  = $F('Iexpediente');
var tribunal_id   = $F('Itribunal_id');
var z = 100;

var ok = confirm(cambios + "Ha solicitado CAMBIAR EL NOMBRE DE UNA PERSONA y Asociarla al expediente.\nContinua con esta operacion....????");
if (!ok) {return;}

var Param = "accion=AsociarPersona&expediente_id=" + expediente_id + "&metodo=100&id_persona=" + id_persona;
var Despues = "var i=transport.responseText;if (i=='101'){alert('Operacion no permitida...!!!\\nLa NUEVA PERSONA :: YA EXISTE EN EL BANCO DE DATOS ::\\n\\tPuede buscarla y asociarla');}if (i=='1'){alert('Pedido Guardado satisfactoriamente');";

if (control == 1) { // PERSONA FISICA
	var nombre	 = $F('Newnombre');
	var apellido = $F('Newapellido');
	if (!nombre || !apellido) {
		alert(error + "Debe completar Nombre y Apellido (sin abreviaturas)");
		return;
		}
	var datos = nombre + " " + apellido;
	Param	+= "&documento=" + documento + "&tipodoc=" + tipodoc + "&nombre=" + nombre + "&apellido=" + apellido + "&vnombre=" + vnombre + "&vapellido=" + vapellido;
	Despues += "$('Inombre_" + fila+"').value='"+nombre+"';$('Iapellido_" + fila+"').value='"+ apellido+"';";
	}
	
if (control == 2) {
	var razon = $F('Newrazon');
	if (!razon) {
		alert(error + "Debe completar la Razon Social (sin abreviaturas)");
		return;
		}
	var datos = razon;
	Param	+= "&cuit=" + cuit + "&razon=" + razon + "&vrazon=" + vrazon;
	Despues += "$('Irazon_" + fila +"').value ='" +razon+"';";
	}

Despues += "ventmensajes.hide();BuscarExpediente('"+tribunal_id+"','"+numero+"','','1','"+origen+"');}if (i==0){alert('PROBLEMAS al guardar registro');}";
//Despues += "ventmensajes.hide();$('DatosPersonaBuscada_"+fila+"').innerHTML ='"+datos+"';BuscarExpediente('"+tribunal_id+"','"+numero+"','','1','"+origen+"');}if (i==0){alert('PROBLEMAS al guardar registro');}";

iajax("IContenedor","request",Param,Despues);
}





/*	..........................................	*/
  // ASOCIAR PERSONA AL EXPEDIENTE (EXPER)
/*	..........................................	*/
function AsociarPersona(x,y,z,e) {
var documento	= $('Idocumento_' + x).value;
var nombre		= $('Inombre_' + x).value;
var apellido	= $('Iapellido_' + x).value;
var razon		= $('Irazon_' + x).value;
var cuit		= $('Icuit_' + x).value;
var expediente_id= $('Iexpediente_id').value;
var caratula	= $('Icaratula').value;
var numero		= $('Iexpediente').value;
var tribunal_id = $('Itribunal_id').value;
var id_persona  = $('Iidpersona_' + x).value;
var tipodoc	  	= $('Itipodoc_' + x).value;
var origen		= $('origen').value;

if (y == 0) {
	$('Show_documento').innerHTML	= tipodoc + " " + documento;
	$('Show_nombre').innerHTML		= nombre + " " + apellido;
	$('Show_razon').innerHTML		= razon;
	$('Show_cuit').innerHTML		= cuit;
	$('x_persona').value			= x;
	$('light').style.display = 'block';
	if (IE)  {
		var vent = screen.availHeight;
		var alto = $('light').offsetHeight;
		var pos  = e.clientY + document.documentElement.scrollTop;
		var newpos = pos - alto;
		$('light').style.top  = newpos + "px";
		$('VOpaca').style.display = 'block';
		$('VOpaca').style.width = screen.availWidth;
		$('VOpaca').style.height= screen.availHeight;
		}
	if (!IE) {$('light').style.top  = e.layerY + "px";}
	$('light').style.display = 'block';
	$('VOpaca').style.display = 'block';
	}

if (y == 1) {
	$('light').style.display = 'none';
	var Param = "accion=AsociarPersona&documento=" + documento + "&nombre=" + nombre + "&apellido=" + apellido + "&cuit=" + cuit + "&razon=" + razon + "&expediente_id=" + expediente_id + "&metodo=" + z + "&id_persona=" + id_persona + "&tipodoc=" + tipodoc;

var Despues = "CierraVentanaModal();var i=transport.responseText;if (i==1) {alert('Pedido Guardado satisfactoriamente');BuscarExpediente('"+tribunal_id+"','"+numero+"','"+origen+"');} else {alert('PROBLEMAS al guardar registro');}";

	iajax("IContenedor","request",Param,Despues);

	}

}


/*	..........................................	*/
	// CERRAR MODIFICAR PEDIDO DE MEDIDAS
	// x = id del tribunal; y= id expediente
	// z = 1 busca ancla Lista
/*	..........................................	*/
function CierraPedidosForm(x,y,z) {
CierraVentanaModal();
if ($('origen').value == 'tribunal') {z = $('origen').value;}
BuscarExpediente(x,y,z);
}

/*	..........................................	*/
	// MODIFICAR UN PEDIDO DE MEDIDAS
/*	..........................................	*/
function CambiarRegistro_Medidas(x,e,despues) {
if (!x) {return;}
paso3 = $('IContenedor').innerHTML;
if (e) {Evento = e;}
if (!e) {e = Evento;}
x = x.replace('A','');
//if (IE || !IE)  {
		var vent = screen.availHeight;
		var top  = e.screenY;
		var desp = document.documentElement.scrollTop;
		if (desp > 100) {
			if (desp > vent) {top = desp + 100;}
			else {top = vent/2 + desp/2;}
			}
		else {top = vent - 680;}
		$('VerFicha').style.top =  top + "px";
		$('VerFicha').style.left = '60px';
		$('VOpaca').style.width = screen.availWidth;
		$('VOpaca').style.height= screen.availHeight + document.documentElement.scrollTop;
	//	}
	//if (!IE) {$('VerFicha').style.top  = e.layerY + "px";}
$('VOpaca').style.display = 'block';
$('VerFicha').style.display = 'block';

var Despues = "";
var Param = "accion=CambiarRegistro_Medidas&exper_id=" + x + "&event=" + e;

if (despues == '1') {
	var Despues = "$('tipo_id').value = 4;AnalizaMedida('4');$('BBembargar').disabled = 0";
	}


iajax("VerFicha","updater",Param,Despues);

}

/*	..........................................	*/
	// ANALIZA PEDIDO DE MEDIDA: PARA AMPLIAR
	// x = id del pedido
	// y = Estado del Pedido
	// Z = TIPO DE PEDIDO
/*	..........................................	*/
function AnalizarRegistro_Medidas(id,estado,tipo,e) {
if (!id) {return;}
var nivel = $('nivel').value;
var cancelar = 0;
var origen = $('origen').value;

if (tipo == 13 && nivel == 29) {
	if (estado == 1) {cancelar = 1;}
	else {cancelar = 0;}
	}
if (origen == "tribunal" && (estado == 2 || estado == 3)) {
	Tribunal_VerFicha(id,e);
	return;
	}
if (estado < 4 && cancelar == 0) {
	alert("Conforme al Estado Actual del Pedido...\n\nNo hay cambios que se puedan realizar");
	return;
	}

if (tipo == 12 && cancelar == 0) {
	alert("REINSCRIPCION DE INHIBICION YA EJECUTADA\n\nNo hay cambios que se puedan realizar");
	return;
	}
if (tipo == 13 && cancelar == 0) {
	alert("CANCELACION DE INHIBICION YA EJECUTADA.\n\nNo hay cambios que se puedan realizar");
	return;
	} 
	
if (e) {Evento = e;}
if (!e) {e = Evento;}

var vent = screen.availHeight;
var top  = e.screenY;
var desp = document.documentElement.scrollTop;
if (desp > 100) {
	if (desp > vent) {top = desp + 100;}
	else {top = vent/2 + desp/2;}
	}
else {top = vent - 680;}
$('VerFicha').innerHTML = "";
$('VerFicha').style.top =  top + "px";
$('VerFicha').style.left = '60px';
$('VOpaca').style.width = screen.availWidth;
$('VOpaca').style.height= screen.availHeight + document.documentElement.scrollTop;
$('VOpaca').style.display = 'block';
$('VerFicha').style.display = 'block';

var Param = "accion=AnalizarRegistro_Medidas&pedido_id=" + id + "&tipo_id=" + tipo + "&cancelar=" + cancelar;

var Despues = "";
iajax("VerFicha","updater",Param,Despues);
}



/*	..........................................	*/
	// MODIFICAR UN PEDIDO DE INHIBICION
/*	..........................................	*/
function BorrarPedido(x) {
if (!x) {return;}
var caratula = $('Icaratula').value;
var persona  = $('CCpersona').value

var ok = confirm(cambios + "Esta por BORRAR la asociacion de una persona al expediente:\n\n" + caratula + "\n" + persona + "\n\n\tContinua con esta operacion....???");
if (!ok) {return;}

var Param = "accion=BorrarAsociacion&exper_id=" + x;

var Despues = "var i=transport.responseText;if (i=='1') {$('BBCancelar').onclick();alert('Persona Eliminada del expediente satisfactoriamente');} else {alert('PROBLEMAS en el servidor al intentar Borrar Registro....');}";

iajax("IContenedor","request",Param,Despues);
}



/*	......................................................	*/
		// Enviar Pedido de Cancelacion de Inhibicion
/*	......................................................	*/
function EnviarCancelacionInhibicion(x) {
if (!x) {return;}
var exper		= $('CCexper_id').value;
var ok = confirm(cambios + "Esta por ENVIAR UN PEDIDO DE CANCELACION DE INHIBICION\n\nContinua con esta operacion....???");
if (!ok) {return;}

var Param = "accion=EnviarCancelacionInhibicion&pedidos_id=" + x;
var Despues = "var i=transport.responseText;if (i=='1') {alert('Registro Enviado Satisfactoriamente');BBCancelar.click();} if (i=='0') {alert('PROBLEMAS en el servidor al intentar Guardar Registro....');}";

iajax("IContenedor","request",Param,Despues);
}



/*	..........	GUARDAR CAMBIOS EN INHIBICIONES ..........	*/
// x = 1 GUARDAR NO INHIBIR
// x = 2 GUARDAR E INHIBIR
/*	......................................................	*/
function GuardarCambiosMedidas(x,y) {
if (!x) {return;}
var men = "";
var numero		= $('Iexpediente').value;
var tribunal_id = $('Itribunal_id').value;
var documento	= $('Cdocumento').value;
var documento1	= $('CCdocumento').value;
var exper		= $('CCexper_id').value;

var Param = "accion=GuardarCambiosMedidas&exper_id=" + exper + "&tipo=" + x;
if (x == 11 || x == 12 || x == 13) {
	var pedido_id = $('Cpedidos_id').value;
	Param += "&pedido_id=" + pedido_id;
	}

if (y == 1) { // captura elementos para embargo
	var emonto		= $('emonto').value;
	var monto		= $('monto').value;
	var matricula	= $('nro_matricula').value;
	var inscripcion = $('nro_inscripcion').value;
	var tomo		= $('nro_tomo').value;
	var fojas		= $('nro_fojas').value;
	var ctomo		= $('cod_tomo').value;
	var depto		= $('departamento').value;
	/* ..... VALIDA DATOS PROPIEDAD ..... */
	if (!monto && !emonto) {men += "Monto\t\t: Debe indicar el monto del embargo.\n";}
	else {
		monto  = monto.replace(".","");
		emonto = emonto.replace(".","");
		$('emonto').value = emonto;
		$('monto').value  = monto;
		if (isNaN(monto))  {men += "Monto\t\t: Debe ser un numero valido.\n";}
		if (isNaN(emonto)) {men += "Monto Prop.\t: Debe ser un numero valido.\n";}
		}
	var matricula1	= Valida(matricula,'d');
	var inscripcion1= Valida(inscripcion,'d');
	var tomo1		= Valida(tomo,'d');
	var fojas1		= Valida(fojas,'d');
	var ctomo1		= Valida(ctomo,'s');
	
	if (matricula && matricula != matricula1){men += "Matricula\t\t: Debe ser un numero valido.\n";}
	if (inscripcion && inscripcion != inscripcion1){men += "Inscripcion\t: Debe ser un numero valido.\n";}
	if (tomo && tomo != tomo1 )				 {men += "Tomo\t\t: Debe ser un numero valido.\n";}
	if (fojas && fojas != fojas1)			 {men += "Fojas\t\t: Debe ser un numero valido.\n";}
	if (ctomo && ctomo != ctomo1)			 {men += "Cod.Tomo\t: Debe ser un valor valido solo LETRAS.\n";}
	/* .................................. */
	
	
	
	if (monto && emonto) {men = "HA COLOCADO DOS MONTOS DE EMBARGO.\n\nDebe indicar un Monto General que afecte a todas las propiedades o bien Indicar un Monto para cada Propiedad";}
	if (!matricula) {
		if (!inscripcion) {men += "Inscripcion\t: Debe ingresar esta informacion.\n";}
		if (!tomo)        {men += "Tomo\t\t: Debe ingresar esta informacion.\n";}
		if (!fojas)       {men += "Fojas\t\t: Debe ingresar esta informacion.\n";}
		if (!depto)       {men += "Departamento\t: Seleccione el Departamento de la Propiedad.\n";}
		}
	if (matricula && (inscripcion || tomo || fojas || depto)) {men = "Ha indicado datos en los dos sistemas de INSCRIPCION.\n\nPor favor Utilice FOLIO REAL o sistema de TOMOS.\n";}
	if (!matricula && !inscripcion && !tomo && !fojas && !depto) {men = "No ha indicado los Datos de Registro del Inmueble involucrado en la Medida.";}
	Param += "&monto=" + monto + "&emonto=" + emonto + "&matricula=" + matricula + "&inscripcion=" + inscripcion + "&tomo=" + tomo + "&fojas=" + fojas + "&ctomo=" + ctomo + "&departamento=" + depto;
	}

if (men) {
	alert(error + men);
	return;
	}

men += "Esta por INICIAR UN PEDIDO DE MEDIDA CAUTELAR... y no podra ser MODIFICADO o ANULADO\n\n";
men += "\t......................";
if (x==1) {men += " INHIBICION COMUN GENERAL ......................";}
if (x == 13) {men += " CANCELACION DE INHIBICION ..................";}
var ok = confirm(cambios + men + "\n\n\tQueda bajo su responsabilidad la fiabilidad de la informacion que esta por enviar.\n\t\tContinua con la operacion....???");
if (!ok) {return;}

var Despues = "var i=transport.responseText;if (i=='1') {$('BBCancelar').onclick();alert('Registro Guardado Satisfactoriamente');}if (i=='4') {CambiarRegistro_Medidas('"+exper+"','','1');}if (i=='0') {alert('PROBLEMAS en el servidor al intentar Guardar Registro....');}";

iajax("IContenedor","request",Param,Despues);

}


/*	.......................................	*/
		// ENVIAR EMBARGOS
/*	.......................................	*/
function EnviarEmbargos(x) {
var exper = $('CCexper_id').value;

var Param = "accion=EnviarEmbargos&pedidos_id=" + x + "&exper_id=" + exper;
var Despues = "var i=transport.responseText;if (i=='1') {CambiarRegistro_Medidas('"+exper+"');alert('Medidas Guardadas y Enviadas');} else {alert('Problemas al Guardar y enviar medidas');}";

iajax("IContenedor","request",Param,Despues);
}


/*	.......................................	*/
// LISTAR EXPEDIENTES
// x = 1 BUSQUEDA POR TIPO DE TRIBUNAL
// x = 2 BUSQUEDA EXPTE CON CANCELACIONES PEDIDAS
/*	.......................................	*/
function ListarExpedientes(x) {
if (!x) {return;}

var tribunal	= $('Btribunal').value;
var activo		= $('Bactivo').value;

if (x == 1) {var Param = "accion=ListarExpedientes&tribunal=" + tribunal + "&activo=" + activo;}
if (x == 2) {var Param = "accion=ListarExpedientes&tribunal=0&activo=1&medidas=13";}

var Despues = "paso2 = $('IContenedor').innerHTML;";
iajax("IAccion","updater",Param,Despues);
}

/*	........................................	*/
		//NAVEGADOR DE EXPEDIENTES
/*	........................................	*/
function Navegar_Expedientes(x) {
var totalreg = $('totalreg').value;
var pagina   = $('pagina').value;
var mensaje  = $('mensaje').value;

if (x == '0') {pagina -= 2;}
var Param = "accion=Navegar_Expedientes&totalreg=" + totalreg + "&pagina=" + pagina + "&mensaje=" + mensaje + "&archivo=expedientes_list.php";

iajax("IAccion","updater",Param);
}

/*	.......................................	*/
// ANALIZA EL TIPO DE MEDIDA
// x = 1 INHIBICIONES
// X = 2 EMBARGOS HABILITA DATOS INMUEBLE
/*	.......................................	*/
function AnalizaMedida(x) {
if (!x) {return;}
var exper_id = $('CCexper_id').value;
$('Aembargos').innerHTML = "&nbsp;";

switch (x) {
	case	"1" :
	case	"2" :
	case	"12":
	case	"3" :$('BBinhibir').disabled = 0;$('BBinhibir').value = "Inhibir";
				$('Aembargos').innerHTML = " <center>Pulse el bot&oacute;n -Inhibir- para iniciar la medida</center> ";
				return;
				break;				
	case	"4":$('BBinhibir').disabled = 1;
				var Param = "accion=Pagina_Embargos&exper_id=" + exper_id + "&medida=" + x;
				var Despues = "$('emonto').focus()";
				iajax("Aembargos","updater",Param,Despues);
				break;
	case	"13": $('BBinhibir').disabled = 0;$('BBinhibir').value = "Cancelar Inhibicion";
				  $('Aembargos').innerHTML = " <center>Pulse el bot&oacute;n - Cancelar Inhibicion- para iniciar el nuevo Pedido:: Recuerde que las Cancelaciones necesitan la aprobaci&oacute;n de Encargados de Departamento</center>";
				  return;break;
	default:	$('BBinhibir').disabled = 1;break;
	} // fin del case
}

/*	.....................................	*/
// CERRAR VENTANA DE EMBARGOS
/*	.....................................	*/
function CerrarVEmbargos() {
var ok = confirm("...Cierra la ventana de embargos...???");
if (!ok) {return;}
AnalizaMedida('0');
$('tipo_id').value='0';
}


/*	.......................................	*/
// OCULTA O VISUALIZA EL BUSCADOR DE PERSONAS
/*	.......................................	*/
function OcultarBuscador() {
if ($('OB').value == "Ocultar Buscador") {
		$('Buscador').style.display='none';
		$('OB').value = "Visualizar Buscador";
		return;
		}
if ($('OB').value == "Visualizar Buscador") {
		$('Buscador').style.display='block';
		$('OB').value = "Ocultar Buscador";
		return;
		}
}


/*	.................................................	*/
// LISTAR MEDIDAS
// x=1 (este mes); x=2 (3meses); 
// x=3 (por rango fechas); x=4 (no enviadas)
/*	.................................................	*/
function BuscarMedidas(x) {
if (!x) {return;}
var Param = "accion=BuscarMedidas&buscar=" + x;

if (x==3) {
	var fecha1 = $('fecha1').value;
	var fecha2 = $('fecha2').value;
	if (!fecha1) {
			alert(error + "Debe indicar una Fecha de Partida");
			return;
			}
	Param += "&fecha1=" + fecha1 + "&fecha2=" + fecha2;
	} // x==3
	

paso2 = $('IContenedor').innerHTML;

var Despues ="sorter.pagesize = 10;sorter.init('Medidas_Table',1)";

iajax("IContenedor","updater",Param,Despues);
}

/*	.............................	*/
	// ADMINISTRACION
	// ASIGNAR EXPTE A USUAIOS
/*	.............................	*/
function Admin_Expte_Usuarios(x) { 
if (!x || x != '9') {
	alert(error + "Usted no tiene permisos suficientes para ADMINISTRAR USUARIOS");
	return;
	}
paso3 = $('IContenedor').innerHTML;
var Param = "accion=Admin_Expte_Usuarios";
iajax("IContenedor","updater",Param);
}


/*	.......................................	*/
// LOCALIZAR USUARIO Y MOSTRAR EXPEDIENTES
/*	.......................................	*/
function Admin_UsuariosVer_Expedientes(x,activo) {
if (!x) {return;}
$(x).style.fontWeight = 'bolder';


var Param = "accion=Admin_UsuariosVer_Expedientes&usuario=" +x;
if (activo) {Param += "&activo=" + activo;}
iajax("LUExpedientes","updater",Param);

}

/*	.......................................	*/
// VENTANA QUE PERMITE CAMBIAR USUARIOS
/*	.......................................	*/
function Admin_Cambiar_UsuarioExpediente(x,e) {
if (!x) {return;}
var usuario = $('usuarios_id').value;
$('VerFicha').innerHTML = "";

var vent = screen.availHeight;
var top  = e.screenY;
var desp = document.documentElement.scrollTop;
if (desp > 0) {
	if (desp > vent) {top = desp + 100;}
	else {top = vent/2 + desp/2;}
	}
else {top = vent - 680;}
	$('VerFicha').style.top =  top + "px";
	$('VerFicha').style.left = '200px';
	$('VOpaca').style.width = screen.availWidth;
	$('VOpaca').style.height= screen.availHeight + document.documentElement.scrollTop;
$('VerFicha').style.width = "500px";
$('VOpaca').style.display = 'block';
$('VerFicha').style.display = 'block';

var Param = "accion=Admin_Cambiar_UsuarioExpediente&expediente_id=" + x + "&usuario_id=" + usuario;
var Despue = "Admin_UsuariosVer_Expedientes('"+usuario+"')";
iajax("VerFicha","updater",Param);
}


/*	.......................................	*/
// GUARDAR CAMBIOS DE USUARIO Y/O ESTADO EXTE
/*	.......................................	*/
function Admin_GuardarCambiosUexpedientes() {
var vusuario	= $('EVusuario').value;
var nusuario	= $('ENusuario').value;
var activo		= $('Eactivo').value;
var expediente	= $('Cexpediente_id').value;
//if (nusuario == "0") {return;}
var ok = confirm(cambios + "Guarda los cambios realizados en la ficha de expediente....\n\n");
if (!ok) {return;}

var Param = "accion=Admin_GuardarCambiosUexpedientes&expediente_id=" + expediente + "&nusuario=" + nusuario + "&activo=" + activo;
var Despues = "var i=transport.responseText;if (i==0) {alert('Problemas al Guardar Cambios en el Expediente.');} else {Admin_UsuariosVer_Expedientes('"+vusuario+"');CierraVentanaModal();alert('Cambios Guardados Satisfactoriamente');}";

iajax("VerFicha","request",Param,Despues);

}


/*	..............................................	*/
	// VER LA FICHA DE EXPEDIENTE Y MEDIDA
	// x = ID DEL PEDIDO
/*	..............................................	*/
function Admin_Medidas_info(x) {
/*$('VerFicha').innerHTML = MCargando;
$('VerFicha').style.top =  "100px";
$('VerFicha').style.left = '100px';
$('VOpaca').style.width = screen.availWidth;
$('VOpaca').style.height= screen.availHeight + document.documentElement.scrollTop;
$('VOpaca').style.display = 'block';
$('VerFicha').style.display = 'block';

var Param = "accion=Admin_Medidas_info&pedidos=" + x;
var Despues = "";

iajax("VerFicha","updater",Param,Despues);
*/
var Param = "control/control_inhibiciones.php?accion=Admin_Medidas_info&pedidos=" + x;
TINY_BOX.box.show(Param,1,0,0,1,0);

}


/*	..............................................	*/
// LISTADO DE MEDIDA, EXPEDIENTES, ESTADO EN EXCEL
/*	..............................................	*/
function Admin_Listar_Excel(origen) {
var Destino = "control/control_inhibiciones.php?accion=Admin_Listar_Excel";
if (origen) {Destino += "&origen=" + origen;}

var vent = window.open(Destino);
}


/*	..............................................	*/
// VER OFICIO AL REGISTRO DEL AUTOMOTOR
/*	..............................................	*/
function VerOficio(x,e) {
var Status = "menubar=no,resizable=yes,scrollbars=yes";
var vent = window.open("control/control_inhibiciones.php?accion=VerOficio&pedido=" + x,"",Status);
e.cancelBubble = true;

}

/*	..............................................	*/
// VER PDF ORDEN FIRMADO DEL TRIBUNAL
// x= id del pedido o número de entrada
// tipo= comunicado / firmada / oficio
/*	..............................................	*/
function VerDocumentacionFirmada(x,tipo,e) {
var Status = "menubar=no,resizable=yes,scrollbars=yes";
var vent = window.open("control/control_inhibiciones.php?accion=VerDocumentacionFirmada&tipo=" + tipo + "&pedido=" + x,"",Status);
e.cancelBubble = true;

}


/*	..............................................	*/
// LEER MENSAJES ENVIADOS DESDE EL TRIBUNAL
/*	..............................................	*/
function Leer_Mensaje(expediente,usuario) {
var Status = "top=100,left=100,menubar=no,resizable=no,scrollbars=yes,width=760px,height=550px";
var Param = "control/control_inhibiciones.php?accion=Leer_Mensaje";
if (expediente && usuario) {Param += "&expediente_id=" + expediente + "&usuario=" + usuario;}

var vent = window.open(Param,'',Status);
vent.focus();

}

/*	..............................................	*/
// LEER MENSAJES RECIBIDOS DE TRIBUNAL
// DETENER PERIODICALuPDATER DE MENSAJES
/*	..............................................	*/
function StopMensajes() {Envio.stop();}

function Contabilizar_Mensajes() {
paso2 = $('IContenedor').innerHTML;
Envio = "";
Envio =  new Ajax.PeriodicalUpdater('TotalMensajes', 'control/control_inhibiciones.php', {
				parameters : "accion=Contabilizar_Mensajes",
				method: 'post', 
				frequency: 60,
				onComplete: function(transport) {
					if (200 == transport.status) {
							if (isNaN(transport.responseText)){transport.responseText = "Error";}
							}
					}	// fin función transport
				//decay: 2
				});
}


/*--------------------------------------------------------------------------------------------------*/

			/*	............................................	*/
					// FUNCIONES PARA TRIBUNALES
			/*	............................................	*/

/*	.............................	*/
	// LISTAR TODOS LOS PEDIDOS
/*	.............................	*/
function Tribunales_ListarPedidos(x) {
if (!x) {return;}
//Envio.start();
var Param = "accion=Tribunales_ListarPedidos&pedido=" + x;

var Despues = "sorter.pagesize = 10;sorter.init('Expedientes_Table',1)";
iajax("ITAccion","updater",Param,Despues);
}


/*	.............................	*/
// PANTALLA PARA BUSCAR EXPEDIENTE
/*	.............................	*/
function Tribunales_Pantalla_BuscarExpediente() {
//Tribunales_NOBuscarMedidas();
//Envio.stop();
var Param = "accion=Tribunales_Pantalla_BuscarExpediente";
var Despues = "";
iajax("ITAccion","updater",Param,Despues);
}

/*	.............................	*/
// BUSCAR PEDIDOS PARA UN EXPEDIENTE
/*	.............................	*/
function Tribunales_BuscarExpediente() {
var men = "";
if (!$F('BBnumero') && !$F('BBactor') && !$F('BBdemandado')) {
		alert(error + " Es necesario indidar Numero de Expediente o Actor o Demandado para poder realizar una consulta");
		return;
		}
if ($('BBnumero').value) {
	var num = Valida($('BBnumero').value,'d');
	if (isNaN(num) || num != $('BBnumero').value) {
		alert(error + " Numero Expediente\t: Debe utilizar valores numericos validos. Si puntos, comas o letras.");
		return;
		}
	}

var Param = "accion=Tribunales_BuscarExpediente&" + Form.serialize('FBexpedientes');
var Despues = "sorter.pagesize = 10;sorter.init('Expedientes_Table',1)";
iajax("ListaExpedientes","updater",Param,Despues);
}



/*	........................................	*/
		//NAVEGADOR DE EXPEDIENTES
/*	........................................	*/
function Tribunales_Navegar_Expedientes(x) {
var totalreg = $('totalreg').value;
var pagina   = $('pagina').value;
var mensaje  = $('mensaje').value;

if (x == '0') {pagina -= 2;}
var Param = "accion=Navegar_Expedientes&totalreg=" + totalreg + "&pagina=" + pagina + "&mensaje=" + mensaje + "&archivo=tribunales_expedientes_list.php";

iajax("ListaExpedientes","updater",Param);
}


/*	........................................	*/
// BORRAR FORMULARIO PARA BUSCAR EXPEDIENTES
/*	........................................	*/
function Tribunales_BorrarBexpedientes() {
$('BBnumero').value = "";
$('BBactor').value  = "";
$('BBdemandado').value = "";
$('BBnumero').focus();

}


/*	.................................................	*/
	// CAPTURA LOS DATOS DE PERSONA PARA UNA MEDIDA
/*	.................................................	*/
function Captura_FichaMedidas() {
mtdoc		= $('Ctipo_doc').value;
mdoc		= $('Cdocumento').value;
mnombre		= $('Cnombre').value;
mapellido	= $('Capellido').value;
mcuit1		= $('Ccuit1').value;
mcuit2		= $('Ccuit2').value;
mcuit3		= $('Ccuit3').value;
mrazon		= $('Crazon').value;
}

/*	.............................	*/
	// Ver ficha de pedido
/*	.............................	*/
function Tribunal_VerFicha(x,e) {
if (!x) {return;}

//$(x).style.backgroundColor = "#6089DF";

		var vent = screen.availHeight;
		var top  = e.screenY;
		var desp = document.documentElement.scrollTop;
		if (desp > 100) {
			if (desp > vent) {top = desp + 100;}
			else {top = vent/2 + desp/2;}
			}
		else {top = vent - 680;}
		$('VerFicha').innerHTML = "";
		$('VerFicha').style.top =  top + "px";
		$('VerFicha').style.left = '30px';
		$('VerFicha').style.width = '90%'
		$('VOpaca').style.width = screen.availWidth;
		$('VOpaca').style.height= screen.availHeight + document.documentElement.scrollTop;
		
		$('VOpaca').style.display = 'block';
		$('VerFicha').style.display = 'block';
		$('VerFicha').innerHTML = "Cargando Aplicacion.....";

var Despues = "$('VerFicha').style.display = 'block';$('VOpaca').style.display = 'block';Captura_FichaMedidas();";
var Param = "accion=Tribunal_VerFicha_Medidas&pedidos_id=" + x;

iajax("VerFicha","updater",Param,Despues);
}


/*	....................................................	*/
// ANALIZA DATOS DE LA PERSONA ANTES DE EJECUTAR MEDIDA
/*	.....................................................	*/
function Analiza_Persona() {
if (
	mtdoc	!=	$('Ctipo_doc').value ||
	mdoc	!=	$('Cdocumento').value ||
	mnombre	!=	$('Cnombre').value ||
	mapellido != $('Capellido').value ||
	mcuit1	!=	$('Ccuit1').value ||
	mcuit2	!=	$('Ccuit2').value ||
	mcuit3	!=	$('Ccuit3').value ||
	mrazon	!=	$('Crazon').value) {return false;}

return true;
}


/*	..................................	*/
	// PIDE ANALISIS DE DECRETO
/*	..................................	*/
function Pedir_Decreto(tipo) {
var Param = "control/control_inhibiciones.php?accion=Tribunal_ComponerDecreto&tipo_id=" + tipo;
ventmensajes = TINY_BOX.box;
ventmensajes.show(Param,1,0,0,1,0);
}

/*	..................................	*/
	//Generar Nuevo Decreto
/*	..................................	*/
function Tribunal_GenerarDecreto() {
var texto = "";
for (var i = 0; i < $('TextoAgregado').length; i++) {
	if (texto) {texto += "<br>";}
	texto += document.getElementById('TextoAgregado').options[i].text;
	}

if (texto) {texto += "<br>";}
texto += $F('OtroTexto');
Decreto = texto;
}


	// SELECCIONAR TEXTO DE DECRETO
/*	..................................	*/
function SeleccionarDecreto(x) {
if (x==0) { //Quitar decreto
	for (var i = 0; i < $('textos_id').length; i++) {
		if ($('textos_id').options[i].selected) {
			var texto = document.getElementById('textos_id').options[i].text;
			var id    = document.getElementById('textos_id').options[i].value;			

			var newElem = document.createElement("option");
			newElem.text  = texto;
			newElem.value = id;
			
			document.getElementById('TextoAgregado').options.add(newElem);			
			document.getElementById('textos_id').options.remove(i);
			}
		}
	}
if (x==1) {
	for (var i = 0; i < $('TextoAgregado').length; i++) {
		if ($('TextoAgregado').options[i].selected) {
			var texto = document.getElementById('TextoAgregado').options[i].text;
			var id    = document.getElementById('TextoAgregado').options[i].value;			

			var newElem = document.createElement("option");
			newElem.text  = texto;
			newElem.value = id;
			
			document.getElementById('textos_id').options.add(newElem);			
			document.getElementById('TextoAgregado').options.remove(i);
			}
		}
	}
}


/*	..................................	*/
	// GUARDAR CAMBIOS E INHIBIR
	// y= 1  Guardar NO INHIBIR
	// y= 2  Guardar INHIBIR(pasa al registro)
	// x = ID del pedido
/*	..................................	*/
function Tribunal_GuardarCambiosMedidas(x,y) {
if (!x) {return;}
var modalidad = "";
var tipo = $('Ctipo_medida').value;
var titulo = $('Ctitulo_medida').value;
var Despues = "";
var lin = "";
var camb = "";
var Pdistinta = 0;

var Param = "accion=Tribunal_GuardarCambiosMedidas&pedidos_id=" + x + "&modo=" + y;
if (tipo == 4) {lin = "&" + Form.serialize('FormEmbargo');}

var cabecera = "<script>location.href = 'control/control_inhibiciones.php?accion=Tribunal_GuardarCambiosMedidas&id=" + x + "&modo=" + y + lin +"'</script>";

if (y == 3) {
	var tipo = $('Ctipo_medida').value;
	if (tipo == 4) {lin += "&" +Form.serialize('FormEmbargo');}
	modalidad = "request";
// .......... PARA CANCELACIONES ARMA EL DECRETO ..........
	//if (tipo != 1) {Pedir_Decreto(tipo);} SOLO UTILIZAR PARA COMPONER DECRETO
// ........................................................
	var vent = window.open("control/control_inhibiciones.php?accion=Tribunal_GuardarCambiosMedidas&id=" + x + "&modo=" + y + lin);
	$('Bejecutarmedida').disabled = 1;
	$('Bejecutarmedida').className = "LetraNormal_10";
	$('BRechazarMedida').disabled = 1;
	$('BRechazarMedida').className = "LetraNormal_10";
	$('VerDecreto').innerHTML = "<a href='javascript:void(0)' onclick='Tribunales_VerDecreto(" + x +")'>Ver Decreto Generado</a>";
	return;
	}

if (y == 2) {
	if (!Analiza_Persona()) {
		camb = "*** SE HAN MODIFICADO LOS DATOS DE LA PERSONA ***\n\n\t1. Se Guardara primero la persona.\n\t2. Se Procedera con la Medida.\n";
		Pdistinta = 1;
		}
		else {
			camb = "*** NO SE HAN MODIFICADO LOS DATOS DE LA PERSONA ***\n\n\t1. Se Procedera con la Medida.";
			Pdistinta = 0;
			}
	if (tipo == 4) {
		var contador = 0;
		var te = $('Totalembargos').value;
		for (var i = 0; i < $('FormEmbargo').length; i++) {
			if ($('FormEmbargo').elements[i].name.indexOf("-procede",0)>-1) {
				if ($('FormEmbargo').elements[i].checked) {contador += 1;}
				}
			} // fin del for
	if (contador == 0) {
		alert(error + "Al no existir inmuebles para EMBARGAR...\n\n\tDeberia RECHAZAR LA MEDIDA EN GENERAL");
		return;
		}
	} // fin tipo == 4

	var men = "Esta por PROCEDER CON: " + titulo + " Medida ID: " + x + "\n\n" + camb + "\n\nEste proceso no podra ser revertido.  Continua con la operacion....????";

	var ok = confirm(cambios + men);
	if (!ok)  {return;}

	if (Pdistinta == 0) {
		top.location.href = "control/control_inhibiciones.php?accion=Tribunal_GuardarCambiosMedidas&id=" + x + "&modo=" + y + lin;
		}
	if (Pdistinta == 1) {
		var ff = "&" + Form.serialize('FormMPersonas');
		top.location.href = "control/control_inhibiciones.php?accion=Tribunal_GuardarCambiosMedidas&id=" + x + "&modo=" + y + lin + "&cambios=1" + ff;
		}
	$('Bprepararmedida').style.display='none';
	//$('Bprepararmedida').className = "LetraNormal_10";
	$('Bejecutarmedida').disabled = 0;
	if (tipo == 4) {$('FormEmbargo').disabled = 1;}
	return;
	}

if (y == 1) {
	var Despues = "var i=transport.responseText;if (i=='1') {alert('Inhibicion Rechazada.....');CierraVentanaModal();Tribunales_ListarPedidos('pedidos');} else {alert('Se han encontrado PROBLEMAS EN EL SERVIDOR.... por favor comuniquese con INFORMATICA');}";
	//var Param = "accion=Tribunal_GuardarCambiosMedidas&pedidos_id=" + x + "&modo=" + y;
	//modalidad = "request";
	}

//var Param = "accion=Tribunal_GuardarCambiosMedidas&pedidos_id=" + x + "&modo=" + y;

iajax("VerFicha",modalidad,Param,Despues);
}




/*	..................................	*/
	// RECHAZAR PEDIDO DE INHIBICION
/*	..................................	*/
function Tribunales_RechazarPedido(x) {
if (!x) {return;}
var ok = confirm(cambios + "\tHa solicitado RECHAZAR UNA MEDIDA CAUTELAR " + x +"\n\n\tProcede con la operacion....????");
if (!ok) {return;}
var observaciones = $('Cobservaciones').value;
var Despues = "var i=transport.responseText;if (i=='1') {alert('MEDIDA CAUTELAR  Procesada: No hacer lugar.....');$('VerDecreto').innerHTML = '<a href=javascript:void(0) onclick=Tribunales_VerDecreto(" + x +")>Ver Decreto Generado</a>';$('Bejecutarmedida').disabled = 1;$('Bprepararmedida').disabled = 1;$('Bprepararmedida').className='LetraNormal_10';$('Bejecutarmedida').className='LetraNormal_10';$('BRechazarMedida').disabled=1;	$('BRechazarMedida').className='LetraNormal_10';} if (i=='0') {alert('Se han encontrado PROBLEMAS EN EL SERVIDOR.... por favor comuniquese con INFORMATICA');} if (i=='-100') {alert('IMPOSIBLE PROCEDER CON SU PEDIDO: ...Medida RECHAZADA con anterioridad...');} if (i=='-101') {alert('IMPOSIBLE PROCEDER CON SU PEDIDO:  ... Medida PROCESADA con anterioridad');}";

var Param = "accion=Tribunales_RechazarPedido&id=" + x + "&observaciones=" + observaciones;

iajax("VerFicha","request",Param,Despues);

}

/*	....................................	*/
	// ANALIZA EMBARGO POR EMBARGO
	// CHECK BOX
/*	....................................	*/
function Tribunales_ProcedeEmbargo(x) {
var id = x.substr(0,x.indexOf('-'));
var campo = id + "-observaciones";

if (!$(x).checked) {
	$(campo).disabled = 0;
	$(campo).style.backgroundColor = "#FFFFFF";
	$(campo).value = "Indique por que NO Procede";
	$(campo).focus();
	}
if ($(x).checked) {
	$(campo).value = "";
	$(campo).style.backgroundColor = "#CCCCCC";
	$(campo).disabled = 1;
	}

}

/*	.....................................	*/
	// PREPARA CAMPO OBSERVACIONES
/*	.....................................	*/
function Tribunales_CampoObservaciones(x) {
if (!x) {return;}
if ($(x).value == "Indique por que NO Procede") {$(x).value = "";}
}



/*	.....................................	*/
	// CREAR NUEVO EXPEDIENTE
/*	.....................................	*/
function Tribunales_CrearExpediente(x) {
if (!x) {return;}

var Param = "accion=Tribunales_CrarExpediente&numero=" + x + "&modal=1";
$('VerFicha').style.top		=  "100px";
$('VerFicha').style.left	= '100px';
$('VOpaca').style.display	= 'block';
$('VerFicha').style.display	= 'block';

var Despues = "";

iajax("VerFicha","updater",Param,Despues);

}


/*	........................................	*/
	// VER FICHA DE EXPEDIENTE
	// x= id del expediente
/*	........................................	*/
function Tribunales_VerFichaExpediente(x) {
if (!x) {return;}
var tribunal_id = $('Itribunal_id').value;
var numero		= $('Iexpediente').value;

if (x == -1) {
	BuscarExpediente(tribunal_id,numero,'tribunal')
	return;
	}


var Param = "accion=Tribunales_VerFichaExpediente&expediente_id=" + x + "&origen=tribunal";
var Despues = "";

iajax("IContenedor","updater",Param,Despues);
}

/*	.......................................	*/
 // MOSTRAR DECRETO GENERADO PARA IMPRIMIR
/*	.......................................	*/
function Tribunales_VerDecreto(x,e) {
if (!x) {return;}
var vent = window.open("control/control_inhibiciones.php?accion=Tribunales_VerDecreto&pedido_id=" + x);
if (e) {e.cancelBubble = true;}
}

/*	.......................................	*/
// MOSTRAR PAGINA PARA INFORMES ESTADISTICOS
// oficina: 1= TRIBUNALES; 2= RECAUDADORES
/*	.......................................	*/
function Ver_InformesEstadisticos(oficina) {
if (!oficina) {return;}
var Param = "accion=Ver_InformesEstadisticos&oficina=" + oficina;
var Despues = "Menu_Estadisticas('1',"+oficina+");";
iajax("IContenedor","updater",Param,Despues);
}

/*	.......................................	*/
// TRIBUNALES:: PRESENTAR ESTADISTICAS
// tipo = indica que estadistica muestra
// oficina => 1= TRIBUNALES; 2= RECAUDADORES
/*	.......................................	*/
function Menu_Estadisticas(tipo,oficina) {
if (!oficina) {return;}
var ano = $F('fechas_id');
var Param = "accion=Activar_PresentaEstadisticas&tipo=" + tipo + "&oficina=" + oficina + "&ano=" + ano;
var Despues = "$('opmenu').value = " + tipo;
iajax("EstPrincipal","updater",Param,Despues);
}

/*	................................................	*/
// TRIBUNALES:: BANDEJA DE ENTRADAS DE COMUNICADOS
/*	................................................	*/
function Tribunales_ListarComunicados(estado) {
if (!estado) {return;}
var Param = "accion=Tribunales_ListarComunicados&estado=" + estado;
var Despues ="";
//var Despues = "sorter.pagesize = 10;sorter.init('Medidas_Table',0)";
iajax("ITAccion","updater",Param,Despues);
}

/*	................................................	*/
// TRIBUNALES:: ABRIR COMUNICADO .PDF
/*	................................................	*/
function Tribunales_AbrirComunicado(entrada,pedido) {
if ( (!entrada || entrada == 0) && (!pedido || pedido ==0) ) {return;}
var Status = "menubar=no,resizable=yes,scrollbars=yes";
var vent = window.open("control/control_inhibiciones.php?accion=Tribunales_AbrirComunicado&entrada=" + entrada + "&pedido=" + pedido,"",Status);
Tribunales_ListarComunicados('comunicados_noleidos');
}


/*	.......................................	*/
// FUNCION BUSCADOR AUTOMATICO DE MEDIDAS
/*	.......................................	*/
function Tribunales_NOBuscarMedidas() {Envio.stop();}

function Tribunales_BuscarMedidas() {
Envio = "";
Envio =  new Ajax.PeriodicalUpdater('ITAccion', 'control/control_inhibiciones.php', {
				parameters : "accion=Tribunales_ListarPedidos&pedido=pedidos",
				method: 'post', 
				frequency: 20
				//decay: 2
				});
}

function Administrador__BuscarCancelaciones() {
Can =  new Ajax.PeriodicalUpdater('VerCancelaciones', 'control/control_inhibiciones.php', {
				parameters : "accion=Admin_ContarCancelaciones",
				method: 'post', 
				frequency: 20
				//decay: 2
				});
}

function Arranque() {
if (!$('uu').value) {Tribunales_BuscarMedidas();}
if ($('uu').value == '29') {Administrador__BuscarCancelaciones();}
}


/*	........................................... */
// ENVIAR MENSAJES DE TRIBUNAL AL PROFESIONAL
// el mensaje siempre está asociado a un usuario(tribunal)
// al expediente desde donde se llamo y al profesional 
// que lo tiene asignado
/*	........................................... */

function Tribunal_EnviarMensaje(expediente,para) {
if (!expediente || !para) {return;}
var Param = "control/control_inhibiciones.php?accion=Tribunal_EnviarMensaje&expediente=" + expediente + "&para=" + para;
ventmensajes = TINY_BOX.box;
ventmensajes.show(Param,1,0,0,1,0);
}


/*	........................................... */
// ELIMINA LA PANTALLA DE MENSAJERÍA
/*	........................................... */
function Tribunal_Mensaje_Cancelar() {ventmensajes.hide();}

/*	........................................... */
// ELIMINA LA PANTALLA DE MENSAJERÍA
/*	........................................... */
function Tribunal_GuardarMensaje() {
var expte	= $F('expedientes_id');
var de		= $F('de_id');
var para	= $F('para_id');
var mensaje = $F('mensaje');

if (!mensaje) {
	alert(error + "Debe ingresar un mensaje para enviar....");
	return;
	}

var ok = confirm(cambios + "Envia mensaje al Profesional que tramita este expediente\nUna vez enviados no podra modificarlo");
if (!ok) {return;}

var Param = "accion=Tribunal_GuardarMensaje&expte=" + expte + "&de=" + de + "&para=" + para + "&mensaje=" + mensaje;
var Despues = "var i=transport.responseText.split('@');if (i[0]==0){alert('Problemas en el sistema. \\nSu mensaje no pudo enviarse.');}if (i[0]==1) {alert('Su MENSAJE fue enviado....');ventmensajes.hide();$('leyendaMensajes').innerHTML=i[1];}";
iajax("EstPrincipal","request",Param,Despues);

}



				/*	////////////////////////////////////////////////////////////	*/
								// FUNCIONES PARA EL REGISTRO
				/*	////////////////////////////////////////////////////////////	*/
/*	........................................... */
		// CANCELAR LANZADO DE FIRMADOR
/*	........................................... */
function FirmarTerminar_Inhibiciones_Cancelar() {
if (!pe) {return;}
var ok = confirm( cambios + "Ha solicitado cancelar el pedido de FIRMAR COMUNICADO DE MEDIDA CAUTELAR: PASO FINAL\n\nTiene que cerrar el firmador si es que el mismo está lanzado.Confirma la operacion....???");
if (!ok) {return;}
pe.stop();
pe = "";
		Conexion(0);
		$('FDoc').disabled = 0;
		$('nentrada').value='';
		$('nentrada').focus();
}
/*	...........................................	*/
		// FIRMADOR DE INFORMES FINALES
/*	...........................................	*/
function FirmarTerminar_Inhibiciones() {
var men = "";
var numero = $('nentrada').value;

if (!numero) {men = "Numero Entrada\t: Este campo no puede estar vacio.\n";}
if (isNaN(numero)) {men = "Numero Entrada\t: Debe contener un numero valido.\n";}
if (numero.indexOf('.') > -1) {men = "Numero Entrada\t: No debe contener punto ni comas.\n";}

if (men) {
	alert(error + men);
	return;
	}

	var Param = "accion=FirmarTerminar_Inhibiciones&numero=" + numero;
	
	//var Despues = "var i=transport.responseText;if (i=='-1'){alert('El comunicado solicitado ya ha sido firmado');$('FDoc').disabled = 0;}if (i=='0'){alert('No se encontro comunicado para la entrada solicitada');$('FDoc').disabled = 0;}if (i=='1'){FirmarComunidado("+numero+");}";
	
	var Despues = "var i=transport.responseText;if (i=='-1'){var ok=confirm('El comunicado solicitado: " + numero + " ya ha sido firmado\\n\\n Desea ver el documento firmado...???');if (ok){window.open('documentacion/medidas_terminadas/MT_"+numero+".pdf');}	$('FDoc').disabled = 0;}if (i=='0'){alert('No se encontro comunicado para la entrada solicitada');$('FDoc').disabled = 0;}if (i=='1'){FirmarComunidado("+numero+");}";
//	var Despues = "var i=transport.responseText;if (i=='-1'){var ok=confirm('El comunicado solicitado: " + numero + " ya ha sido firmado\\n\\n Desea ver el documento firmado...???');if (ok){window.open('http://www.jus.mendoza.gov.ar/registros/drp/documentacion/medidas_terminadas/MT_"+numero+".pdf');}	$('FDoc').disabled = 0;}if (i=='0'){alert('No se encontro comunicado para la entrada solicitada');$('FDoc').disabled = 0;}if (i=='1'){FirmarComunidado("+numero+");}";
		
		iajax("EstPrincipal","request",Param,Despues);
		

$('FDoc').disabled = 1;

}

/*	................................................	*/

/*	................................................	*/
function FirmarComunidado(numero) {
	top.location.href = "control/control_inhibiciones.php?accion=FirmarComunidado&numero=" + numero;
	BuscarFinal(numero);
}

/*	......................................................	*/
// FUNCION COMPROBAR SI FUE FIRMADO EL PDE DE TERMINAR
/*	......................................................	*/

function BuscarFinal(numero) { //Listado_TotalMedida
if (!numero) {return;}
var contador = 0;
pe = new PeriodicalExecuter(function(pez) {
	if (++contador > 12) {
		pe.stop();
		Conexion(0);		
		$('ListadoMedidas').innerHTML =numero +": Tiempo excedido... Documento No Firmado";
		$('FDoc').disabled = 0;
		$('nentrada').value='';
		$('nentrada').focus();
		return;
		}
		
	var Param = "accion=BuscarFinal&numero=" + numero;
	var Despues = "var i=transport.responseText.split('@');if (i[0]=='0'){$('ListadoMedidas').innerHTML ='<center>"+numero +": No Firmada</center>';} if (i[0]=='1'){$('ListadoMedidas').innerHTML ='"+numero+": Documento Firmado';pe.stop();Conexion(0);$('FDoc').disabled = 0;PonerArray(i[1]);$('nentrada').value='';$('nentrada').focus();}";
	iajax("EstPrincipal","request",Param,Despues);
	}, 2);

}

function PonerArray(datos) {
$('Listado_TotalMedida').innerHTML += datos + "<br>";
}
