
// Set global browser boolean flags

var isIE	= document.all;
var isIE6	= isIE && document.implementation;
var isIE5	= isIE && window.print && !isIE6;
var isIEDOM2	= isIE5 || isIE6;
var isIE4	= isIE && !isIEDOM2 &&
         	  navigator.cookieEnabled;
var isIE3	= isIE && !isIE4 && !isIEDOM2;
var isNS	= navigator.mimeTypes && !isIE;
var isNS3	= isNS && !navigator.language;
var isNS4	= document.layers;
var isNS6	= document.getElementById && !isIE;
var isNS7	= isNS6;
var isNS71	= document.designMode;
var isNSDOM2	= isNS6;
var isDOM2	= isIEDOM2 || isNSDOM2;

/* variables Elementos.jsp */
var currenDiv; 

/* variables Atlas.jsp */
var zindex=100;
var currentMenu;
var posicX = 0;
var posicY = 0;

var retardo;

/* comienzan las funciones */

function no_cerrar (mensaje) {
	if (isIE) {
				function onUnloadIE () {
					event.returnValue =mensaje;
				}
				window.onbeforeunload=onUnloadIE;
				window.onclose=onUnloadIE;
			}
			else {
			/*	function onUnload(){
					if (confirm ('Si cambia de ventana, debe cerrar el explorador para poder utilizar el Visor IDE de nuevo')) {
					}
					else {
						 if (window.event.preventDefault) { window.event.preventDefault();}
					}
					window.onunload =onUnload;
					window.onclose = onUnload;			
				} */
				/*function onUnload(){
					var e= event;
					alert('cerrando');

					e.preventDefault();
				} 

				window.onunload = onUnload;*/	
			}
}

function mostrar_plugin (ip, puerto, aplicacion, idioma, mensaje_descargar, mensaje_nocerrar, mensaje_nocompatible) {
 	if (window.ActiveXObject) 
	  	{
			document.writeln('<OBJECT ID="Gato" WIDTH=100% HEIGHT=100% CLASSID="CLSID:9DBAFCCF-592F-101B-85CE-00608CEC297B" CODEBASE="http://213.172.57.238/GATOSERVER/gatoinstaller.cab">');
			document.writeln('<PARAM NAME="_Version" VALUE="65536">');
			document.writeln('<PARAM NAME="_ExtentX" VALUE="2646">');
			document.writeln('<PARAM NAME="_ExtentY" VALUE="2646">');
			document.writeln('<PARAM NAME="_StockProps" VALUE="15">');
			document.writeln('<PARAM NAME="Note" VALUE="Version 13">');
			   		    
			document.writeln('<PARAM NAME="application" VALUE="' + aplicacion + '">');
			document.writeln('<PARAM NAME="ip" VALUE="' + ip + '">'); 
			document.writeln('<PARAM NAME="port" VALUE="' + puerto + '">');
			document.writeln('<PARAM NAME="catalog" VALUE="Condor">');
			document.writeln('<PARAM NAME="version" VALUE="recommended">');
                        document.writeln('<PARAM NAME="action" VALUE="download_execute">');
                        document.writeln('<PARAM NAME="log" VALUE="true">');
			document.writeln('</OBJECT>');
			no_cerrar(mensaje_nocerrar);				
   		}
	else if(navigator.mimeTypes) 
		{ 
                        document.writeln('<embed type="application/gato-plugin"');
                        document.writeln(' width=100%');
                        document.writeln(' height=100%');
                        document.writeln(' pluginspage="http://213.172.57.238/GATOSERVER/gatoinstaller.xpi"');
                        document.writeln(' application="' + aplicacion + '"');
                        document.writeln(' ip="' + ip + '"');
                        document.writeln(' port="' + puerto + '"');
                        document.writeln(' catalog="Condor"');
                        document.writeln(' version="recommended"');
                        document.writeln(' action="download_execute"');
                        document.writeln(' log="true">');					
                        document.writeln('</embed>');
		}

		else {
			document.writeln(mensaje_nocompatible);
		}
 
		

} /* fin function mostrar_plugin */

function ventana_visor(url, titulo) {
		if (isIE) {
			var ventana = window.open(url,'visor','top=0,left=0,width=screen.Width,height=screen.Height,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes');	
			ventana.document.title = titulo;		
		}
		else {
			var ventana = window.open(url,'visor','top=0,left=0,window.outerWidth=screen.Width,window.outerHeight=screen.Height,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes');	
			ventana.sizetoContent();
			ventana.top.document.title = titulo;	
		}
	
		
		ventana.focus();
} /* fin function ventana_visor */


/* Elementos.jsp */
/*var currenDiv;*/

function mostrar_div(menu) {
	var fon= document.getElementById('FONDO');
	fon.style.visibility='hidden';
	ocultar_div();
	currenDiv = document.getElementById(menu); 
	currenDiv.style.visibility='visible';
}

function ocultar_div() {
		if (currenDiv)
		currenDiv.style.visibility='hidden';
}
/* FIN Elementos.jsp */


/* Atlas.jsp*/
function ocultar_menu() {
	if (currentMenu) {
		currentMenu.style.visibility='hidden';
	}
}

var tiempo;
		
function mostrar_menu(menu) {
		ocultar_menu();
		currentMenu = document.getElementById(menu); 
		currentMenu.style.left= posicX;
		currentMenu.style.top= posicY;
		currentMenu.style.visibility='visible';
		
		
}

function mostrar_menu2(menu, posx, posy) {
	ocultar_menu();
	currentMenu = document.getElementById(menu); 
	currentMenu.style.left=posx;
	currentMenu.style.top=posy;
	currentMenu.style.visibility='visible';
}

function getElementLeft(Elem) {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;

}


function getElementTop(Elem) {
		var elem;
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;

}

function posicRatonXY(e) {
	if (isIE) { 
		posicX = event.clientX + document.body.scrollLeft;
		posicY = event.clientY + document.body.scrollTop;
	}
	else { posicX = e.pageX; posicY = e.pageY; }
	if (posicX < 0) {posicX = 0;}
	if (posicY < 0) {posicY = 0;}
	
	
	return true;
} 

/* FIN Atlas.jsp*/

function nuevaVentana(url, w, h) {
  if (w==0) w=screen.availWidth;
  if (h==0) h=screen.availHeight;
  var ventana = window.open(url,'','width='+w+',height='+h+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');	
  ventana.focus();
}    


function dejardeesperar() {
     clearTimeout(retardo);

    /* for (i=0; i<document.links.length; i++) {
        var oncl=document.links[i].onclick;
        
        if (oncl == null) {
            //no hace nada
            //document.links[i].onclick=function() {esperar();}
        } else {
            document.links[i].onclick=function() {esperar(); return oncl();}
        }
     
      }
      */
     retardo = setTimeout("todasImagenes()",500);
}

function todasImagenes() {
  clearTimeout(retardo);
  var todos=1;
  var imagenes = document.getElementsByTagName('img');
  
  for (var i=0; i<imagenes.length; i++) {
    if (imagenes[i].complete==false) {
        todos=0;
    }
  }
  
  if (todos==0) {
     esperar();   
     retardo = setTimeout("todasImagenes()",500);
  }
  else {
    var divesp = document.getElementById('esperando');
    if (divesp) divesp.style.visibility="hidden";
    clearTimeout(retardo); 
  }
}



function esperar() {
   var divesp = document.getElementById('esperando');
    if (divesp) {
        //divesp.className="divEspere";
        if (isIE) {
            //alert("W: "+screen.Width+" H:"+screen.Height);
            width=parseInt((screen.Width/2) - (321/2)) + document.body.scrollLeft; 
            height=parseInt((screen.Height/2) -(174/2)) + document.body.scrollTop;
        }
        else {
            //alert("W: "+screen.outerWidth+" H:"+screen.outerHeight);
            width=parseInt((window.outerWidth/2) - (321/2)) + document.body.scrollLeft; //=screen.Width;
            height=parseInt((window.outerHeight/2) - (174/2)) + document.body.scrollTop; //=screen.Height;
        }
        divesp.style.top=height;
        divesp.style.left=width;
        divesp.style.visibility="visible";
    }    
}


function ver_esperar() {
   esperar();
}

var http_request = false;

function makeRequest(url) {
   
    http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
            // Ver nota sobre esta linea al final
        }
    } else if (window.ActiveXObject) { // IE
            var ids = ["Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0",
                      "Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP",
                      "Microsoft.XMLHTTP"];
            for(var i=0; !http_request  && i<ids.length; i++) {
                try { http_request = new ActiveXObject(ids[i]); }
                catch(ex) { http_request = false; }
            }
    }
   
    if (!http_request) {
        alert('Falla :( No es posible crear una instancia XMLHTTP');
        return false;
    }
   
    http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
    http_request.send(url);
    esperar();
}



function alertContents() {
   
    if (http_request.readyState == 4) {
        if (http_request.status == 200 || http_request.status == 0) {
            
            //var TEXTO = rescatar_script(http_request.responseText)
            //hay que comprobar si funciona asi, porque si no, hay que codificar con urlencoder/urlencode 
            //la cadena desde el action.
            var TEXTO=unescape(http_request.responseText);
            TEXTO=TEXTO.replace(/\+/gi," ");
            document.getElementById("descripcion").innerHTML = TEXTO;
            dejardeesperar();
            
        } else {
            alert('Hubo problemas con la petición.');
        }

    }

}

 

 //  if (!isIE) document.captureEvents(Event.MOUSEMOVE)
 //  document.onmousemove = posicRatonXY;

  

 /*for (i=0; i<document.forms.length; i++) {
    var onsub= document.forms[i].onsubmit;
    if (onsub != undefined && onsub != null) {
        document.forms[i].onsubmit=function() {esperar(); return onsub();}
    } else {
        document.forms[i].onsubmit=function() {esperar();}
    }
  }
*/