var nav4 = window.Event ? true : false;

function validaMail(obj){
	var correo = obj.value;
	if (correo == "" || correo == "undefined") { return true; }
	var listcorreo = correo.split(";");
	var campo = "";
	for (i=0; i < listcorreo.length; i++) {
		campo = listcorreo[i];
		if(campo != ""){
			if ( campo.search(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/ig) ) { 
				alert("El correo electronico "+campo+" no es valido. \n\n Debe escribirlo de esta forma: nombre@servidor.dominio");
				obj.focus();
				obj.select();
				return false;
			}
		}
	}
	return true;
}


function fn_ajax() {
 try{ 
   ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Esto es para IExplorer
 }catch(e){
    try{
      ajax= new ActiveXObject("Microsoft.XMLHTTP");  // Si se cuelga intenta con este
    }catch(E){
      ajax= false;
    }
 }
 //Si llega hasta aca y ajax es false quiere decir que no es explorer.
 if(!ajax && typeof XMLHttpRequest!='undefined'){ 
    ajax = new XMLHttpRequest(); // Para Mozilla o Safari :)
 }
 return ajax //Retornamos el objeto
}

// Esta clase es para mostrar un iframe dentro de un formulario
	function MyIFrame(_name,_title,_src,_img, _html){
		//Constructor
		// Propiedades
		this.html = _html == undefined ? "" : _html;
		this.name = _name;
		this.src = _src;
		this.title = _title;
		this.imgdir = _img;

		this.status = "contracted";
		
		//Metodos
		this.create = MyIFrame_Create;
		this.show = MyIFrame_Show;
		this.hide = MyIFrame_Hide;
		this.expand = MyIFrame_Expand;
		this.contract = MyIFrame_Contract;
		this.changestatus = MyIFrame_ChangeStatus; // Utilizado solo por el componente
		this.create();
		this.onContract = "";
		this.onExpand = "";
	}

	function MyIFrame_Create(){
		var HTML = '<table id="table_'+this.name+'" style="width:100%;" cellpadding="0" cellspacing="0" border="0">'+
					' <tr id="tr_1'+this.name+'" onclick="javascript:'+this.name+'.changestatus(\'\')" class="FILA_bg" style="background-image:url('+this.imgdir+'FILA_bg.gif);background-repeat: repeat-x;" onmousemove="this.style.cursor = \'pointer\'">'+
					'  <td id="td_1'+this.name+'">&nbsp;<img id="img_'+this.name+'" /> &nbsp;&nbsp;'+this.title+'</td>'+
					' </tr>'+
					' <tr id="tr_2'+this.name+'">'+
					'  <td id="td_2'+this.name+'" colspan="2" valign="top" style="background-color:#F8F8F8;background-image:url('+this.imgdir+'../bg.jpg)">';
		if (this.html != "") {
			HTML += this.html;
		} else {
			HTML += '   <iframe id="iframe_'+this.name+'" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" style="height:100%;width:100%" AllowTransparency></iframe>';
		}
		HTML += '  </td>'+
				' </tr>'+
				'</table>';
		document.write(HTML);
		this.hide();
	}

	function MyIFrame_Expand(){
		this.changestatus("expanded");
	}
	
	function MyIFrame_Contract(){
		this.changestatus("contracted");
	}
	
	function MyIFrame_ChangeStatus(status){
		var tr = document.getElementById("tr_2"+this.name);
		var img = document.getElementById("img_"+this.name);
		if(status == ""){
			if(this.status == 'contracted'){
				status = 'expanded';
			}else if(this.status == 'expanded'){
				status = 'contracted';
			}
		}
		
		if(status == 'contracted'){
			tr.style.visibility = "hidden";
			tr.style.position = "absolute";
			img.title = "Mostrar";
			img.src = this.imgdir+'FILA_mas.gif';
			this.status = 'contracted';
			if(this.onContract != "")eval(this.onContract);
		}else if(status == 'expanded'){
			tr.style.visibility = "visible";
			tr.style.position = "relative";
			img.title = "Ocultar";
			img.src = this.imgdir+'FILA_menos.gif';
			this.status = 'expanded';
			if(this.onExpand != "")eval(this.onExpand);
		}
	}
	
	
	function MyIFrame_Show(){
		var table = document.getElementById("table_"+this.name);
		var tr = document.getElementById("tr_2"+this.name);
		var td = document.getElementById("td_2"+this.name);
		if (this.src != "") {
			var iframe = document.getElementById("iframe_"+this.name);
			iframe.src = this.src;
		}
		table.style.visibility = "visible";
		table.style.position = "relative";
		tr.style.visibility = "visible";
		tr.style.position = "relative";
		td.style.height = this.height;
		this.changestatus("expanded");
	}
	
	function MyIFrame_Hide(){
		var table = document.getElementById("table_"+this.name);
		var tr = document.getElementById("tr_2"+this.name);
		table.style.visibility = "hidden";
		table.style.position = "absolute";
		tr.style.visibility = "hidden";
		tr.style.position = "absolute";
		
	}
	
	// Fin Clase
	
	function XMLError(root){
	var err =  root.getElementsByTagName("error")[0];
	var info = err.getElementsByTagName("info")[0];
	var data = err.getElementsByTagName("database")[0];
	
	try{var mensaje = info.getElementsByTagName("mensaje")[0].childNodes[0].nodeValue;}catch(e){};
	try{var descripcion = info.getElementsByTagName("descripcion")[0].childNodes[0].nodeValue;}catch(e){};
	try{var modulo = info.getElementsByTagName("modulo")[0].childNodes[0].nodeValue;}catch(e){};
	alert(mensaje);
}
//-------------------------------------------------------------------funcion para validar rut segun modulo 11--------------------------
function revisarDigito2( dvr,idelementso)
{        
        dv = dvr + ""        
        if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')        
        {                
                alert("Debe ingresar un digito verificador valido");                
                eval ("document.formulario."+idelementso+
".focus();");                
                eval ("document.formulario."+idelementso+
".select();");        
                return false;        
        }        
        return true;
}

function revisarDigito22( crut ,idelementso)
{        
        largo = crut.length;        
        if ( largo < 2 )        
        {                
                alert("Debe ingresar el rut completo")                
                eval ("document.formulario."+idelementso+
".focus();");                
                eval ("document.formulario."+idelementso+
".select();");                
                return false;        
        }        
        if ( largo > 2 )                
                rut = crut.substring(0, largo - 1);        
        else                
                rut = crut.charAt(0);        
        dv = crut.charAt(largo-1);        
        revisarDigito2( dv,idelementso );        

        if ( rut == null || dv == null )
                return 0        

        var dvr = '0'        
        suma = 0        
        mul  = 2        

        for (i= rut.length -1 ; i >= 0; i--)        
        {        
                suma = suma + rut.charAt(i) * mul                
                if (mul == 7)                        
                        mul = 2                
                else                            
                        mul++        
        }        
        res = suma % 11        
        if (res==1)                
                dvr = 'k'        
        else if (res==0)                
                dvr = '0'        
        else        
        {                
                dvi = 11-res                
                dvr = dvi + ""        
        }
        if ( dvr != dv.toLowerCase() )        
        {                
                alert("EL rut es incorrecto")  
                document.getElementById(idelementso).focus();
                document.getElementById(idelementso).select();
                return false        
        }

        return true
}

function Rut(texto,idelementso)
{        
        texto = LimpiaRut(texto);
        var tmpstr = "";        
        for ( i=0; i < texto.length ; i++ )                
                if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
                        tmpstr = tmpstr + texto.charAt(i);        
        texto = tmpstr;        
        largo = texto.length;        

        if ( largo < 2 )        
        {                
                /*alert("Debe ingresar el rut completo")                
                window.document.formulario.rut_extra.focus();                
                window.document.formulario.rut_extra.select();                
                return false;        */
        }
        else
        {

                                for (i=0; i < largo ; i++ )        
                                {                        
                                        if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
                                        {                        
                                                alert("El valor ingresado no corresponde a un R.U.T válido");                        
                                                eval ("document.formulario."
+idelementso+".focus();");                        
                                                eval ("document.formulario."
+idelementso+".select();");                        
                                                return false;                
                                        }        
                                }        
                        
                                var invertido = "";        
                                for ( i=(largo-1),j=0; i>=0; i--,j++ )                
                                        invertido = invertido + texto.charAt(i);        
                                var dtexto = "";        
                                dtexto = dtexto + invertido.charAt(0);        
                                dtexto = dtexto + '-';        
                                cnt = 0;        
                        
                                for ( i=1,j=2; i<largo; i++,j++ )        
                                {                
                                        if ( cnt == 3 )                
                                        {                        
                                                dtexto = dtexto + '';                        
                                                j++;                        
                                                dtexto = dtexto + invertido.charAt(i);                        
                                                cnt = 1;                
                                        }                
                                        else                
                                        {                                
                                                dtexto = dtexto + invertido.charAt(i);                        
                                                cnt++;                
                                        }        
                                }        
                        
                                invertido = "";        
                                for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )                
                                        invertido = invertido + dtexto.charAt(i);        
                        
                                eval ("document.formulario."
+idelementso+".value = invertido.toUpperCase();");                
                        
                                if ( revisarDigito22(texto,idelementso) )                
                                        return true;        
                        
                                return false;
        }
}

function LimpiaRut(VALUE){
	//Eliminamos ceros no significativos.
	var w_space = String.fromCharCode(48); 
	if(v_length < 1){
		return "";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
	if(VALUE.charAt(iTemp) == w_space){
	}
	else{
	strTemp = VALUE.substring(iTemp,v_length);
	break;
	}
	iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

//-------------------------------fin validacion del rut---------------------------------------------

function IsPopupHabilitados(){
var w = window.open();

if (!w) {
//popups Bloqueados
return false;
} else {
//popups Habilitados
if (!w.closed) w.close();
return true;
}
}

function popUpWin (url, win, width, height, options) {
var leftPos = (screen.availWidth - width) / 2;
var topPos = (screen.availHeight - height) / 2;
//options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;

//return window.open(url, win, options);
var w = window.open(url, win, options);

if (!w) {
//popups Bloqueados
alert('Su navegador tiene activado un sistema de bloqueo de ventanas emergentes.\n La pagina solicitada no se pudo abrir.');
}
else {
	return w;
}

}

function solonumeros(evento){
	//ejemplo <input type="text" onkeypress="return solonumeros(event)" />
	var key = evento.keyCode ? evento.keyCode : evento.which;
	if (key>=32){
		if(key>=48 && key<= 57 || key==35 || key==36 || key==46){
			return
		}else{
			return false;
		}
	}
}

function solonumeroshora(evento){
//	alert("validar solonumeroshora");
  //ejemplo <input type="text" onkeypress="return solonumeros(event)" />
  // key = 35 (Fin)
  // Key = 36 (Inicio)
  // Key = 37 (<-)
  // Key = 38 (Fecha Arriba)
  // Key = 39 (->)
  // Key = 40 (Flecha Abajo)
  // Key = 46 (Supr)  
  // Key = 58 (:)    
  
  var key = evento.keyCode ? evento.keyCode : evento.which;
//  alert(key);
  if (key>32){
   if(key>=48 && key<= 57 || key==46 || key==35 || key==36  || key==37 || key==38 || key==39 || key==40 || key==58){
    return
   }else{
    return false;
  }
 }
}

function getkey(evento){
  //Ejemplo <input type="text" onkeyup="javascript:alert(getkey(event));" />
  //Retorna el codigo de la tecla pulsada
  key = evento.keyCode ? evento.keyCode : evento.which;
  return key;
}

function setfocus(obj,select){
  //Otorga el foco al objeto especificado
  try{
    document.getElementById(obj).focus();
    try{
      if(select == true){
       document.getElementById(obj).select()
      }
    }catch(e){
      return;
    }
  }catch(e){
    return;
  }
}

function hora_inicial_final(inicial, termino, mensaje)
{
	// inicial = "14:30"
	// termino = "15:45"				
	
	var valor;
	var hora1, minuto1, hora2, minuto2;
	
	valor = inicial;
	minuto1 = valor.substring(3);				
	hora1 = valor.substring(0,2);	

	valor = termino;
	minuto2 = valor.substring(3);				
	hora2 = valor.substring(0,2);	
	
	if (hora1 == hora2)
	{	
		if (minuto1 > minuto2)
		{
			alert(mensaje);
			return false;						
		}
	}
	else
	{	
		if (hora1 > hora2)
		{
			alert(mensaje);
			return false;						
		}
	}
	return true;
}
//-------------------------------------------------------------------------------------------------------------------------		
function validar_hora(valor, key, name)
{ 
	var largo = valor.length;

	if (largo > 5)
	{
		alert('El formato de hora no es correcto');
		eval("document.getElementById('"+name+"').focus();");
		
		//document.getElementById(name).focus();				
		return false;
	}

	if(largo==0){if(key==58){eval("document.getElementById('"+name+"').value=12;");return;}}
	if(largo==1){if(key==58){eval("document.getElementById('"+name+"').value='0'+document.getElementById('"+name+"').value;");return;}}
	if(largo==2){if(key!=58){eval("document.getElementById('"+name+"').value=document.getElementById('"+name+"').value+':';");return;}}
	if(largo==4){if(key==58){eval("document.getElementById('"+name+"').value=document.getElementById('"+name+"').value+'0';");return;}}
}
//-------------------------------------------------------------------------------------------------------------------------			
function validar_valor_hora(valor, name)
{
	var largo = valor.length;			
	var hora, minuto;

	if (largo == 0) return;
	
	minuto = valor.substring(3);				
	hora = valor.substring(0,2);	// Por 1 para convertirlo en nÃºmeros.
	//alert(hora);
	//alert(minuto);
	if (!(hora >= 0 && hora <= 23))
	{
		alert('La hora debe estar entre las 0 y 23.');
		alert(name);
		eval("document.getElementById('"+name+"').value='';");				
		eval("document.getElementById('"+name+"').focus();");				
		return;
	}
	if (!(minuto >= 0 && minuto <= 59))
	{
		alert('El minuto debe estar entre 0 y 59.');
		eval("document.getElementById('"+name+"').value='';");				
		eval("document.getElementById('"+name+"').focus();");				
		return;
	}
}




/*
function solonumeros(evento)
{
  
  var k = nav4 ? evento.which : evento.keyCode;
  if (k>32){
   if( k>=48 &&  k<= 57){
    return
   }else{
    return false;
  }
 }
}
*/

//----------------------------------------------------------------------------VER PAGINA FULL
//window.moveTo(0,-115);window.resizeTo(screen.width,screen.height+115);
//----------------------------------------------------------------------------FIN
//----------------------------------------------------------------------------FUNCION PARA RELACIONAR EQUIPOS CON EDIFICIOs
function relacionar_equipos(valor,ided)
{
	var dir;
	dir = "../../form/popup/buscar/buscagrilla.php?tabla="+valor+"&ided="+ided;
	popup=window.open(dir,"buscador","toolbar=0,width=900, height=500, scrollbars=1,left=0,top=0,resizable=1");
	popup.focus();
	popup.moveTo(0,0);
	popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
	void(0);
}
//--------------------------------------------------------------------------------------------------------------------------------FIN
//----------------------------------------------------------------------------FUNCION PARA QUITAR EQUIPOS CON EDIFICIOs
function quitar_equipos(valor,ided)
{
	var dir;
	dir = "../../form/popup/buscar/buscagrilla_mod.php?tabla="+valor+"&ided="+ided;
	popup=window.open(dir,"buscador","toolbar=0,width=900, height=500, scrollbars=1,left=0,top=0,resizable=1");
	popup.focus();
	popup.moveTo(0,0);
	popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
	void(0);
}
//--------------------------------------------------------------------------------------------------------------------------------FIN
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
//------------------------------------------------------------------------------------------funcion para navegar y recaragar los IFRAMES
function fnNavigate(nombre,dir){
//nombre 	= nombre del iframe
//dir		= url de la pagina a incluir en el iframe
   /*
    for(i=0;i<document.all.length;i++)
    {
       window.onerror=null; 
	  if(document.all(i).tagName=="IFRAME" && document.all(i).name==nombre)
      {
	       eval("document."+nombre+".disabled=false;");
		   document.all(i).contentWindow.location = dir;
		   eval("document."+nombre+".src='"+dir+"';");
      }
    }
    */
   document.getElementById(nombre).src=dir;
}
//-------------------------------------------------------------------------------------------------funcion que abre el buscador estatico
function buscador3(tabla,ex,ca,parametro,campito)
//campito es el campoa filtrar ej: idcliente
//parametro es el valor ej:2
{
	var dir;
	dir = "form/popup_seleccion/buscagrilla.php?tabla="+tabla+"&extra="+ex+"&campo="+ca+"&parametro="+parametro+"&campito="+campito;
	popup=window.open(dir,"buscador","toolbar=0,scrollbars=1,left=0,top=0,resizable=1");
	popup.focus();
	popup.moveTo(0,0);
	popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
	void(0);
}
function buscador33(tabla,ex,ca,parametro,campito)
//campito es el campoa filtrar ej: idcliente
//parametro es el valor ej:2
{
	var dir;
	dir = "popup_seleccion/buscagrilla.php?tabla="+tabla+"&extra="+ex+"&campo="+ca+"&parametro="+parametro+"&campito="+campito;
	popup=window.open(dir,"buscador","toolbar=0,scrollbars=1,left=0,top=0,resizable=1");
	popup.focus();
	popup.moveTo(0,0);
	popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
	void(0);
}

//-----------------------funcionque abre un popup especial para clientes
function independiente_contacto(user)
{
        var dir;
        dir = "form/independientes_form/contacto.php?user="+user;
        popup=window.open(dir,"equipo","toolbar=0,titlebar=0,status=0,width=600, height=340, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus();
		screen_height = window.screen.availHeight; 
		screen_width = window.screen.availWidth; 
		left_point = parseInt(screen_width/2)-(600/2); //parseInt(screen_width/2)-(ancho de la pagina/2)
		top_point = parseInt(screen_height/2)-(340/2); //parseInt(screen_height/2)-(alto de la pagina/2)
		setTimeout('popup.moveTo(left_point,top_point)',100); 
		void(0);
}
//-----------------------funcionque abre un popup especial para clientes
function independiente_serie(id_serie,user,grilla)
{
        var dir;
        dir = "marcaserie.php?id="+id_serie+"&user="+user+"&grilla="+grilla;
        popup=window.open(dir,"serie","toolbar=0,titlebar=0,status=0,width=350, height=140, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus()
		screen_height = window.screen.availHeight; 
		screen_width = window.screen.availWidth; 
		left_point = parseInt(screen_width/2)-(350/2); //parseInt(screen_width/2)-(ancho de la pagina/2)
		top_point = parseInt(screen_height/2)-(140/2); //parseInt(screen_height/2)-(alto de la pagina/2)
		setTimeout('popup.moveTo(left_point,top_point)',100); 
		void(0);
}
//-----------------------funcionque abre un popup especial para clientes
function independiente_equipo(id_edificio,user,grilla)
{
        var dir;
        dir = "equipos.php?id_edificio="+id_edificio+"&user="+user+"&grilla="+grilla;
        popup=window.open(dir,"equipo","toolbar=0,titlebar=0,status=0,width=500, height=360, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus()
		screen_height = window.screen.availHeight; 
		screen_width = window.screen.availWidth; 
		left_point = parseInt(screen_width/2)-(500/2); //parseInt(screen_width/2)-(ancho de la pagina/2)
		top_point = parseInt(screen_height/2)-(360/2); //parseInt(screen_height/2)-(alto de la pagina/2)
		setTimeout('popup.moveTo(left_point,top_point)',100); 
		void(0);
}
//-------------------------------------------------------------------------------------------------funcion que abre el buscador estatico
function buscador(tabla,ex,ca)
{
	var dir;
	dir = "form/popup_seleccion/buscagrilla.php?tabla="+tabla+"&extra="+ex+"&campo="+ca;
	popup=window.open(dir,"buscador","toolbar=0,width=900, height=500, scrollbars=1,left=0,top=0,resizable=1");
	popup.focus();
	popup.moveTo(0,0);
	popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
	void(0);
}
//---------------------------------------------------------------------------------FUNCION PARA CONTACTOS/CLIENTES y CONTACTOS/EDIFICIOS
function lista_clientes_contactos(id_cliente,id_edificio)
{
	var dir;

	//alert(id_cliente);alert(id_edificio);
	dir = "form/popup_seleccion/listado_clientes_contactos.php?id_cliente="+id_cliente+"&id_edificio="+id_edificio;
	popup=window.open(dir,"lista_clientes_contactos","toolbar=0, scrollbars=yes, left=0, top=0, resizable=1");
	popup.focus();
	popup.moveTo(0,0);
	popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
}
//--------------------------------------------------------------------------------------------------------------------------------------
//-----------------------funcionque abre un popup especial para clientes
function cliente()
{
        var dir;
        dir = "form/popup_seleccion/clientes.php";
        popup=window.open(dir,"equipo","toolbar=0,width=600, height=250, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus();
}
//---------------------------------------------------------------------------funcion que retorna valores al formulario de equipos
function retornar_valorequipo(a,b,c,d)
{
        window.opener.formulario.va3.value = a;
        window.opener.formulario.extra1.value = b;
        window.opener.formulario.va2.value = c;
        window.opener.formulario.extra2.value = d;
        window.close();
}
//---------------------------------------------------------------------------------funcion que abre un popup especial para equipos
function equipo()
{
        var dir;
        dir = "form/popup_seleccion/listadoequipo.php";
        popup=window.open(dir,"equipo","toolbar=0,width=600, height=250, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus();
}
//-------------------------------------funcion que lista segun la tabla que se requiera-----------------------------------------
function lista_tablasfiltro(id,tabla,campo)//campo es el filtro
{
        var dir;
        dir = "form/popup/lista_tablasfiltro.php?tabla="+tabla+"&id="+id+"&campo="+campo;
        popup=window.open(dir,"lista_tablasfiltro","toolbar=0,width=700, height=200, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus();
}
//-------------------------------------funcion que abre un popup con el formulario relacionado-----------------------------------------
function comunas(extra,valor)
{
        var dir;
        dir = "comunas.php?extra="+extra+"&valor="+valor;
        popup=window.open(dir,"comunas","toolbar=0,width=300, height=100, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus();
		screen_height = window.screen.availHeight; 
		screen_width = window.screen.availWidth; 
		left_point = parseInt(screen_width/2)-(300/2); //parseInt(screen_width/2)-(ancho de la pagina/2)
		top_point = parseInt(screen_height/2)-(100/2); //parseInt(screen_height/2)-(alto de la pagina/2)
		setTimeout('popup.moveTo(left_point,top_point)',100); 
		void(0);
}
//-------------------------------------funcion que abre un popup con el formulario relacionado-----------------------------------------

function relacionado(id,tabla)
{
        var dir;
        dir = "form/popup/relacion.php?tabla="+tabla+"&id="+id;
        popup=window.open(dir,"relacionado","toolbar=0,width=600, height=500, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus();
}
//-------------------------------------activa los botones para realizar tareas x------------------------------------------------------
function retornar_valor(texto1,nombre_ctr1,texto2,nombre_ctr2,swe,nextras,idtraspaso)
{
        eval('window.opener.formulario.'+ nombre_ctr1+'.value="'+texto1+'";')
        eval('window.opener.formulario.'+ nombre_ctr2+'.value="'+texto2+'";')
        if(swe==1 && nextras!=0)
        {eval('window.opener.formulario.extra'+ nextras +'.disabled=false;')
        eval("window.opener.formulario.extra"+ nextras +".className='txt_obligatorio';")}

        window.close();
}
//-------------------------------------activa los botones para realizar tareas x------------------------------------------------------
function opt_activar(id)
{
        location.href="popup.php?id_reg="+id;
}
//-------------------------------------direccionar dentro de la ventana popup---------------------------------------------------------
function direccionar(form,enter)
{
        location.href="popup.php?enter="+enter+"&form="+form;
}
//-------------FIN-----------------------
//-------------funcion que abre un popup y le traspasa valores como el id de un registro y la ruta de la pagina-----------------------
function popup_lista(tabla,btn,id_form,user,id_cliente,nom_campo)//id_cliente,solo envia el formulario de contrato
{
//nom_campo, contiene el nombre del campo al que se debe consultar
        var id_reg;
        var popup;
        dir = "form/popup/popup.php?id_reg_popup="+id_cliente+"&tabla="+tabla+"&btn="+btn+"&id_form="+id_form+"&user="+user+"&nom_campo="+nom_campo;
        popup=window.open(dir,"popup_lista","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
        popup.focus();
        popup.moveTo(0,0);
        popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
}
//-------------FIN-----------------------
//-------------funcion que abre un popup que se encarga de listar y de retornar valores-----------------------
//donde nombre2 corresponde a la var que tiene el id
//swe indica que el popup debe habilitar los extras
//nextras indica el numero del extra que debe habilitar
//swe_popup=identifica si la funcion fue llamada desde el popup
function popup_seleccion(tabla,nombre1,nombre2,swe,nextras,swe_popup)
{

        var popup;
        var dir;
        var idtraspaso;
        //habilitar_save_undo()
        if(swe==1 && nextras!=0)
        {eval('document.formulario.'+nombre2+'.value="";')
        eval('document.formulario.extra'+ nextras +'.value="";')}

        if(swe_popup==0)//direccionara de acuredo a swe_popup
        {dir = "form/popup_seleccion/listado.php?tabla="+tabla+"&nombre1="+nombre1+"&nombre2="+nombre2+"&swe="+swe+"&nextras="+nextras+"&idtraspaso="+idtraspaso;}
        else
        {dir = "../../form/popup_seleccion/listado.php?tabla="+tabla+"&nombre1="+nombre1+"&nombre2="+nombre2+"&swe="+swe+"&nextras="+nextras+"&idtraspaso="+idtraspaso;}

        popup=window.open(dir,"popup_seleccion","toolbar=0,width=600, height=250, scrollbars=1,left=0,top=0,resizable=1");
        popup.focus();
}
//-------------FIN-----------------------

function limpia_edificio_TAB()
{
	document.formulario.edificio3.value='';
	document.formulario.edificio4.value='';
	document.formulario.edificio5.value='';
	document.formulario.edificio12.value='';
	document.formulario.edificio_extra1.value='';
	document.formulario.edificio6.value='';
	document.formulario.edificio8.value='';
	document.formulario.edificio9.value='';
	document.formulario.edificio7.value='';
	document.formulario.edificio10.value='';
	document.formulario.edificio13.value='';
	document.formulario.edificio11.options[0].selected=true;
}
function limpia_contactos_TAB()
{
	document.formulario.ce_contacto7.value='';
	document.formulario.ce_contacto1.value='';
	document.formulario.ce_contacto_extra1.value='';
	document.formulario.ce_contacto2.value='';
	document.formulario.ce_contacto3.value='';
	document.formulario.ce_contacto_extra3.value='';
	document.formulario.ce_contacto6.checked=false;
	document.formulario.ce_contacto4.options[0].selected=true;
	document.formulario.ce_contacto5.options[0].selected=true;
}
function limpia_contratos_TAB()
{
	document.formulario.contrato2.value='';document.formulario.contrato3.checked=false;document.formulario.contrato4.value='';
	document.formulario.contrato5.value='';document.formulario.contrato6.value='';document.formulario.contrato7.value='';
	document.formulario.contrato8.value='';document.formulario.contrato9.value='';document.formulario.contrato10.value='';
	document.formulario.contrato11.options[0].selected=true;
	document.formulario.contrato12.value='';document.formulario.contrato13.value='';document.formulario.contrato14.value='';
	document.formulario.contrato15.value='';document.formulario.contrato16.options[0].selected=true;
	document.formulario.contrato17.value='';document.formulario.contrato18.value='';document.formulario.contrato19.value='';
	document.formulario.contrato20.value='';document.formulario.contrato21.value='';
	document.formulario.contrato22.options[0].selected=true;
	document.formulario.contrato23.value='';document.formulario.contrato24.value='';document.formulario.contrato25.value=''
	document.formulario.contrato26.value='';document.formulario.contrato27.value='';
}
function limpia_clientes_TAB()
{
	document.formulario.cliente1.disabled=true;document.formulario.cliente2.disabled=true;document.formulario.cliente3.disabled=true;
	document.formulario.cliente4.disabled=true;document.formulario.cliente5.disabled=true;document.formulario.cliente6.disabled=true;
	document.formulario.cliente7.disabled=true;document.formulario.cliente8.disabled=true;document.formulario.cliente9.disabled=true;
	document.formulario.cliente10.disabled=true;document.formulario.cliente11.disabled=true;document.formulario.cliente12.disabled=true;
	
	document.formulario.cliente1.className='txt_no_editables';document.formulario.cliente2.className='txt_no_editables';document.formulario.cliente3.className='txt_no_editables';
	document.formulario.cliente4.className='txt_no_editables';document.formulario.cliente5.className='txt_no_editables';document.formulario.cliente6.className='txt_no_editables';
	document.formulario.cliente7.className='txt_no_editables';document.formulario.cliente8.className='txt_no_editables';document.formulario.cliente9.className='txt_no_editables';
	document.formulario.cliente10.className='txt_no_editables';document.formulario.cliente11.className='txt_no_editables';document.formulario.cliente12.className='txt_no_editables';
}

