function getNode( nodeId ) {
	if( document.getElementById )
		return document.getElementById( nodeId );
	else if( document.all && document.all( nodeId ) )
		return document.all( nodeId );
	else if( document.layers && document.layers[ nodeId ] )
		return document.layers[ nodeId ];
	else
		return false;
}

/* TODO EL CODIGO DE AQUI EN ADELANTE HAY QUE DEPURARLO PARA ELIMINAR OBSOLETOS */

function getStyle(el, style) {
   if(!document.getElementById) return;

     var value = el.style[toCamelCase(style)];

    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);

        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];

     return value;
}

function setStyle(objId, style, value) {
    document.getElementById(objId).style[style] = value;
}

function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ?
       oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}
// JavaScript Document
Mouse_Over = false

function MO(e){
	Mouse_Over =true
	if (!e)	var e=window.event;
	var S=e.srcElement;
	while (S.tagName!="TD")
		{S=S.parentElement;}

	if(S.className!="TD_MENU_OFF_ACTIVO")
		S.className="TD_MENU_ON";
}

function MU(e){
	Mouse_Over = false
	if (!e)
	var e=window.event;
	var S=e.srcElement;
	while (S.tagName!="TD")
		{S=S.parentElement;}
	if(S.className!="TD_MENU_OFF_ACTIVO")
		S.className="TD_MENU_OFF";
}

function IR(url){
	location.href=url;
}

function mostrar(){
	var layer= document.getElementById("Layer1");
	layer.style.visibility='visible';
}

function cerrar(){
	var layer= document.getElementById("Layer1");
	layer.style.visibility='hidden';
}

function mOverMenuP(event,ObjMenu){
	if (!e)
	var e=window.event;
	/*var pCurrMenuObj=ROP(ObjMenu);

	alert(pCurrMenuObj.showing)*/
	var S=e.srcElement;
	ObjMenu=ROP(ObjMenu);

	if(ObjMenu.style.visibility!='visible'){
		while (S.tagName!="TD")
			{S=S.parentElement;}
		if(S.className!="TD_MENU_OFF_ACTIVO")
			S.className="TD_MENU_ON";
	}
}

function mOutMenuP(event,ObjMenu){
	if (!e)
	var e=window.event;
	/*var pCurrMenuObj=ROP(ObjMenu);
	alert(pCurrMenuObj.showing)*/
	var S=e.srcElement;
	ObjMenu=ROP(ObjMenu);

	if(ObjMenu.style.visibility!='visible'){
		while (S.tagName!="TD")
			{S=S.parentElement;}
		if(S.className!="TD_MENU_OFF_ACTIVO")
			S.className="TD_MENU_OFF";
	}
}

function ABRIR(event,ObjMenu){
	MenuTimeout();
	for (i=0;i<MOL.length;i=i+2){
		if (ObjMenu!=MOL[i]){
			layer=document.getElementById(MOL[i]);
			layer.style.visibility='hidden';
			MenuTD=document.getElementById(MOL[i+1]);
			if(MenuTD.className!="TD_MENU_OFF_ACTIVO")
				MenuTD.className="TD_MENU_OFF";
		}
	}

	var e=window.event;

	if (!e){return false;}
	var S=e.srcElement;

	ObjMenu=ROP(ObjMenu);

	if (!ObjMenu) { return false; }
	if (S.id=="") { S=S.parentElement; }

	var pos= document.getElementById(S.id);

	var posi=getXY(pos);
	if(S.className!="TD_MENU_OFF_ACTIVO")
		S.className="TD_MENU_ON_P";

	var layer= ObjMenu//document.getElementById();
	layer.style.left= posi.left+5;
	layer.style.top=posi.top+25;


	//alert(layer.style.visibility)
	if (layer.style.visibility=='' || layer.style.visibility=='hidden'){
		layer.style.visibility='visible';
	}else{
		layer.style.visibility='hidden';
		if(S.className!="TD_MENU_OFF_ACTIVO")
			S.className="TD_MENU_OFF";
	}
}

function ROP(ObjRef){
	var theObj=null;
	if (ObjRef){
		if (typeof ObjRef != 'object'){
			theObj=eval(ObjRef);
		}else{
			theObj=ObjRef;
		}
		return theObj;
	}else{
		return false;
	}
}

function getXY(Obj){
	for (var sumTop=0,sumLeft=0;Obj!=document.body;sumTop+=Obj.offsetTop,sumLeft+=Obj.offsetLeft, Obj=Obj.offsetParent);
	return {left:sumLeft,top:sumTop}
}

/// OCULTACION AUTOMÁTICA
timeoutDelay=2000
var timeoutId = false;

function MenuTimeout(){

	timeoutId=setTimeout('ocultar_menuOP();',timeoutDelay);
   // window.status=window.status+' reiniciar'

}

function reiniciar_tiempo(){
	if (timeoutId) clearTimeout(timeoutId);
}

function ocultar_menuOP(){
	if (Mouse_Over){
		reiniciar_tiempo();
		MenuTimeout();
	}else{
		for (i=0;i<MOL.length;i=i+2){
			//if (ObjMenu!=MOL[i]){
				layer=document.getElementById(MOL[i]);
				layer.style.visibility='hidden';
				MenuTD=document.getElementById(MOL[i+1]);
				if(MenuTD.className!="TD_MENU_OFF_ACTIVO")
					MenuTD.className="TD_MENU_OFF";
			//}
		}
	}
}

//*** SCRIPT PARA LOS MENSAJES
N = (document.all) ? 0 : 1;
var ob_mensaje;
var over = false;
var capa_oculta="LayerMensaje";
var tempX;
var tempY;
//var X;
//var Y;

function MD_MSG(e) {
	if (over){
		if (N) {
		ob_mensaje = document.getElementById(capa_oculta);
		X=e.layerX;
		Y=e.layerY;
		return false;
		}else {
			ob_mensaje = document.getElementById(capa_oculta);
			ob_mensaje = ob_mensaje.style;
			X=event.offsetX;
			Y=event.offsetY;
		}

	}
}

function MM_MSG(e) {
	if (ob_mensaje) {
		if (N) {
			ob_mensaje.style.top = e.pageY-Y;
			ob_mensaje.style.left = e.pageX-X;
//				alert("depurado 1");
		}else {
			ob_mensaje.pixelLeft = event.clientX-X + document.documentElement.scrollLeft;
			ob_mensaje.pixelTop = event.clientY-Y;
			if (document.documentElement && document.documentElement.scrollTop)
				ob_mensaje.pixelTop = ob_mensaje.pixelTop +  document.documentElement.scrollTop;
			else if (document.body)
				ob_mensaje.pixelTop = ob_mensaje.pixelTop +  document.body.scrollTop;

//				alert(ob_mensaje.pixelTop);
			return false;
		}
   }
//	   var e=window.event;
   if(N){
	tempX = e.pageX;
	tempY = e.pageY;
   }else{

	tempX = event.clientX;
	tempY = event.clientY;
	if (document.documentElement && document.documentElement.scrollTop)
		tempY = tempY + document.documentElement.scrollTop;
	else if (document.body)
		tempY = tempY + document.body.scrollTop;

   }
   //scrollPosY=document.documentElement.scrollTop;

   if (tempX < 0){tempX = 0}
   if (tempY < 0){tempY = 0}
}

function MU_MSG() {
		ob_mensaje = null;
}

if (N) {
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}

document.onmousedown = MD_MSG;
document.onmousemove = MM_MSG;
document.onmouseup = MU_MSG;

function cerrar_mensaje(nombre){
	ob_temp = document.getElementById(nombre);
	ob_temp.style.visibility='hidden';
}

function mostrar_mensaje(nombre) {
	ob_temp = document.getElementById(nombre);
	ob_temp.style.visibility='visible';
}

function mostrar_capa_oculta(nombre,pos) {
	var anchoobjeto;
	ob_temp = document.getElementById(nombre);
	anchoobjeto=parseInt(getStyle(ob_temp,"width"));
//		ob_mensaje.pixelLeft = event.clientX-X + document.documentElement.scrollLeft;
//				ob_temp.pixelTop = event.clientY-Y + document.documentElement.scrollTop;
		ob_temp.style.top=tempY;
		if(pos==1)	ob_temp.style.left=tempX - anchoobjeto;
		else		ob_temp.style.left=tempX;
	ob_temp.style.visibility='visible';
}

//*** Codigo para abrir ventanas modales (que mantienen el foco por sobre las padres)
// Global for browser version branching.
var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));
// One object tracks the current modal dialog opened from this window.
var dialogWin = new Object();
var IntervalID_DGDialog = "";

// Generate a modal dialog.
function openDGDialog(url, width, height, args) {
   if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {
      // Initialize properties of the modal dialog object.
      //dialogWin.returnFunc = returnFunc;
      dialogWin.returnedValue = "";
      dialogWin.args = args;
      dialogWin.url = url + "?" +args;
      dialogWin.width = width;
      dialogWin.height = height;
      // Keep name unique so Navigator doesn't overwrite an existing dialog.
      dialogWin.name = (new Date()).getSeconds().toString();
      // Assemble window attributes and try to center the dialog.
      if (Nav4) {
         // Center on the main window.
         dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2);
         dialogWin.top = window.screenY + ((window.outerHeight - dialogWin.height) / 2);
         dialogWin.left=0;dialogWin.top=0;
         var attr = "screenX=" + dialogWin.left + ",screenY=" + dialogWin.top + ",resizable=yes,width=" + dialogWin.width + ",height=" + dialogWin.height;
      } else {
         // The best we can do is center in screen.
         dialogWin.left = (screen.width - dialogWin.width) / 2;
         dialogWin.top = (screen.height - dialogWin.height) / 2;
         dialogWin.left=0;dialogWin.top=0;
         var attr = "left=" + dialogWin.left + ",top=" + dialogWin.top + ",resizable=yes,width=" + dialogWin.width + ",height=" + dialogWin.height;
      }
      attr = attr + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes";
      // Generate the dialog and make sure it has focus.
      dialogWin.win=window.open(dialogWin.url, dialogWin.name, attr);
      dialogWin.win.focus();
   } else {
      dialogWin.win.focus();
   }
   //IntervalID_DGDialog = setInterval('finishChecking()',100);
   if (Nav4) {
      window.captureEvents(Event.FOCUS)
      //window.onfocus = finishChecking;
   }
   window.onfocus = checkModal;
   gPopupMask = document.getElementById("popupMask");
   gPopupMask.style.display = "block";
   hideSelectBoxes();
}

function checkModal() {
   setTimeout("finishChecking()", 50);
   return true;
}

function finishChecking() {
   if (dialogWin.win && !dialogWin.win.closed) {
      dialogWin.win.focus();
   }
   else{
      //clearInterval(IntervalID_DGDialog);
       if (Nav4) {
	      window.releaseEvents(Event.FOCUS)
	      //window.onfocus = finishChecking;
	   }
   window.onfocus = null;
   gPopupMask = document.getElementById("popupMask");
   gPopupMask.style.display = "none";
   displaySelectBoxes();
   }
}
/**
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*
* Thanks for the code Scott!
*/
function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}

/**
* Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function displaySelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

function abrir_ventana(nombre_pagina,ancho,alto,argumentos) {
	var ventana=(new Date()).getSeconds().toString();
	var pagina = nombre_pagina+"?"+argumentos;
	var pos_x; var pos_y;
	if (Nav4) {
	     pos_x = window.screenX + ((ancho) / 2);
	     pos_y = window.screenY + ((alto) / 2);
	  } else {
	     pos_x = (screen.width - ancho) / 2;
	     pos_y = (screen.height - alto) / 2;
	  }
	pos_x=0;
	pos_y=0;
	window.open(pagina,ventana,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+ancho+',height='+alto+',top='+pos_y+',left='+pos_x+'');
}

function f_setfocus() {
	if(typeof(document.forms[0])=="object") {
		var aForm = document.forms[0];
		if( aForm.elements[0]!=null) {
			var i;
			var max = aForm.length;
			for( i = 0; i < max; i++ ) {
				if( (aForm.elements[ i ].type == "text" || aForm.elements[ i ].type == "textarea") &&
					!aForm.elements[ i ].disabled &&
					!aForm.elements[ i ].readOnly ) {
					aForm.elements[ i ].focus();
					break;
				}
			}
		}
	}
}

function cerrar_cargar_padre(pagina){
	self.opener.location.href=pagina;
	window.close();
}
function cargar_padre(pagina){
	self.opener.location.href=pagina;
}

function cerrar_recargar_padre(parametros){
	var ploc = self.opener.location;
	var pag_padre = ploc.protocol+"//"+ploc.host+ploc.pathname;
	if(parametros=="" || typeof(parametros)=="undefined") {
		ploc.href=ploc.href;
	}else {
		ploc.href=pag_padre+"?"+parametros;
	}
	window.close();
}
function recargar_padre(parametros){
	var ploc = self.opener.location;
	var pag_padre = ploc.protocol+"//"+ploc.host+ploc.pathname;
	if(parametros=="" || typeof(parametros)=="undefined") {
		ploc.href=ploc.href;
	}else {
		ploc.href=pag_padre+"?"+parametros;
	}
}

function cerrar_ventana(){
	window.close();
}

//Este es el codigo para cambiar los colores de las casillas seleccionadas
function seleccionar_todo(objForm,nombre_col) {
	var f = objForm;
	if(typeof(f=="object")) {
		for (var i = 0; i < f.elements.length; i++) {
			var e = f.elements[i];
//			alert (e.name);
			if (e.type == 'checkbox') {
				if (e.name===nombre_col){
					e.checked = !e.checked;
					cambiar_color(e);
				}
			}
		}
	}
}
function seleccionar_todo_nocolor(objForm,nombre_col) {
	var f = objForm;
	if(typeof(f=="object")) {
		for (var i = 0; i < f.elements.length; i++) {
			var e = f.elements[i];
//			alert (e.name);
			if (e.type == 'checkbox') {
				if (e.name===nombre_col){
					e.checked = !e.checked;
				}
			}
		}
	}
}
function cambiar_color(objchk) {
	var encontrado = false;
	var fila=objchk;
	while(!encontrado) {
		if(/tr/i.test(fila.parentNode.nodeName)) {
			encontrado=true;
		}
		fila=fila.parentNode;
	}
	var impar = false;
	if(/odd/i.test(fila.className)) {
		impar=true;
	}
	if(objchk.checked && impar) {
		fila.className="selecodd";
	} else if(objchk.checked && !impar) {
		fila.className="selec";
	} else if(impar) {
		fila.className="odd";
	} else if(!impar) {
		fila.className="";
	}
	return true;

}

function background_action(activate) {
	Position.absolutize('activity');
	centrar_elemento($('activity'));
	if(activate) {
		$('activity').show();
		hideSelectBoxes();
		$('popupMask').setStyle({'display':'block'});
	}else {
		$('popupMask').setStyle({'display':'none'});
		displaySelectBoxes();
		$('activity').hide();
	}
}
function GetWindowSize() {
    var w = window;
    var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
    var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
    return [width, height]
}
function centrar_elemento(element) {
	element = $(element);
	var w, h, pw, ph;
    var d = Element.getDimensions(element);
    w = d.width;
    h = d.height;
    Position.prepare();
    var ws = GetWindowSize();
    pw = ws[0];
    ph = ws[1];
    element.setStyle({"top":(ph/2) - (h/2) -  Position.deltaY + "px"});
    element.setStyle({"left":(pw/2) - (w/2) -  Position.deltaX + "px"});
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function borrar_campo(nombre_campo){	
	var objeto=eval('document.formapara.'+nombre_campo);
	objeto.value="";
}

function habilitarSeguridadPagina() {
    //Deshabilita la seleccion de texto en la pagina
    if (typeof document.onselectstart!="undefined") {
      document.onselectstart=new Function ("return false"); 
      var eles = document.getElementsByTagName("textarea");
        for(var i=0; i< eles.length; i++) {
            if(eles[i].nodeName=="TEXTAREA") {
                eles[i].onselectstart=function() {};                
            }
        }
    }
    else{
      document.onmousedown=new Function ("return false");
      document.onmouseup=new Function ("return true");
      var eles = document.getElementsByTagName ("textarea");
        for(var i=0; i< eles.length; i++) {
            if(eles[i].nodeName=="TEXTAREA") {
                eles[i].onmousedown=function() {};
                eles[i].onmouseup=function() {}; 
            }
        }
    }
    
    //Deshabilita el menu contextual con clic derecho
    document.oncontextmenu = function() {
        return false;
    }
}

