// ------------------------------------------
// Detectar navegador
// ------------------------------------------
function BrowserCheck() {
  var b = navigator.appName;
  if (b=="Netscape") this.b = "ns";
  else if (b=="Microsoft Internet Explorer") this.b = "ie";
  else this.b = b;
  this.version = navigator.appVersion;
  this.v = parseInt(this.version);
  this.ns = (this.b=="ns" && this.v>=4);
  this.ns4 = (this.b=="ns" && this.v==4);
  this.ns6 = (this.b=="ns" && this.v==5);
  this.ie = (this.b=="ie" && this.v>=4);
  this.ie4 = (this.version.indexOf('MSIE 4')>0);
  this.ie5 = (this.version.indexOf('MSIE 5')>0);
  this.min = (this.ns||this.ie);
  if(this.ns6){
  	document.all = document.getElementsByTagName("*");
  	this.ns=false;
  	this.ns4=false;
  	this.ns5=true;
  	this.ie=true;
	this.ie4=true;
	this.ie5=true;
  }
}
is = new BrowserCheck();
// ------------------------------------------
// Mover capas
// ------------------------------------------
function MoverA(capa, x, y){
  if(is.ie){
    EstaCapa = document.getElementById(capa).style;
  }else{
    EstaCapa = eval("document." + capa);
  }
  if(x!=null){EstaCapa.left = x};
  if(y!=null){EstaCapa.top = y};
}
// ------------------------------------------
// Mostrar/Ocultar capas
// ------------------------------------------
function Mostrar(capa){
  if(is.ie){
	EstaCapa = document.getElementById(capa).style;
	Muestra = "visible";
  }else{
    EstaCapa = eval("document." + capa);
	Muestra = "show";
  }
  EstaCapa.visibility = Muestra;
}

function Ocultar(capa){
  Muestra = "hidden";
  if(is.ie){
	EstaCapa = document.getElementById(capa).style;
  }else{
    EstaCapa = eval("document." + capa);
  }
  EstaCapa.visibility = Muestra;
}
// ------------------------------------------
// Cambiar imágenes
// ------------------------------------------
function CambiaImagen(capa, nombre, imagen){
  // alert("comun.js // CambiaImagen // capa= " + capa + ", nombre= " + nombre + ", imagen= " + imagen);
  EstaImagenSrc = eval(imagen + ".src");
  if(((is.ns && !capa) || (is.ns && capa == null)) || is.ie){
	document[nombre].src = EstaImagenSrc;
  }else{
  	document.layers[capa].document.images[nombre].src = EstaImagenSrc;
  }
}
// ------------------------------------------
// Abrir nueva ventana
// ------------------------------------------
function AbrirVentana(actUrl, actW, actH, actName, scrBar, toolBar, actX, actY){
  self.focus();
  if((!actName) || (actName == null)){
  	actName = parseInt(Math.random()*100000);
	actName = "nm" + actName.toString(8) + actName.toString(16);
  }
  if((!actX) || (actX == null)){actX="0"};
  if((!actY) || (actY == null)){actY="0"};
  if((!scrBar) || (scrBar == null)){scrBar="0"};
  if((!toolBar) || (toolBar == null)){toolBar="0"}  
  actProp = "status=1,top=0,toolbar=" + toolBar + ",scrollbars=" + scrBar + ",menubar=0,directories=0,left=" + actX + ",top=" + actY + ",width=" + actW + ",height=" + actH;
  window.open(actUrl, actName, actProp);
}
// ------------------------------------------
// Escribir en capas
// ------------------------------------------
function EscribirCapa(capa, contenido){
  if(is.ie){
	EstaCapa = document.getElementById(capa);
	EstaCapa.innerHTML = contenido;
  }else{
    document.layers[capa].document.open();
    document.layers[capa].document.write(contenido);
    document.layers[capa].document.close();
  }
}
// ------------------------------------------
// cONTROL DE IMPRESIÓN
// ------------------------------------------
function PrepararImpresion(act1, act2){
	BufferBreak = parseInt(act2);
	BufferLocation = act1;
	BufferBreak = BufferLocation.lastIndexOf(".");
	BufferLocation = BufferLocation.substring(0,BufferBreak) + "Imprimir" + BufferLocation.substring(BufferBreak,BufferLocation.length);
	location.href = "/java/X?cgi=" + BufferLocation;
}
function ImprimirEsto(){  
	if (window.print) {
    	window.print() ;  
	} else {
    	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}
// ------------------------------------------
// Control del menúe
// ------------------------------------------
function ControlMenuPrincipal(capa, name, source) {
	if (name != MenuActivo) {
		CambiaImagen(capa, name, source);
	}
}
// ------------------------------------------
// Funcion para los menús emergentes
// ------------------------------------------

var MenuActivo = false;
var TopMenuEmerg, BottomMenuEmerg, LeftMenuEmerg, RightMenuEmerg;

function InicializarMenuEmerg(){

	TopMenuEmerg = parseInt(document.getElementById("DesplegableGraficasDiv").style.top) - 19;
	BottomMenuEmerg = parseInt(document.getElementById("DesplegableGraficasDiv").style.top) + parseInt(document.all.DesplegableGraficasDiv.offsetHeight);
	LeftMenuEmerg = parseInt(document.getElementById("DesplegableGraficasDiv").style.left);
	RightMenuEmerg = parseInt(document.getElementById("DesplegableGraficasDiv").style.left) + parseInt(document.all.DesplegableGraficasDiv.offsetWidth);

}

function EnseniarMenuEmerg(){
  EstaCapa = "DesplegableGraficasDiv";
  Mostrar(EstaCapa);
  MenuActivo = true;
}

function OcultarMenuEmerg(){
  EstaCapa = "DesplegableGraficasDiv";
  Ocultar(EstaCapa);
}

function InicializaCaptureMouse(){
	
	InicializarMenuEmerg();

	if (is.ns){ document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);}
	document.onmousemove = mouseMove;

}

function mouseMove(e) {
	var xx = (is.ns) ? e.pageX : event.x+document.body.scrollLeft;
	var yy = (is.ns) ? e.pageY : event.y+document.body.scrollTop;

	/*if(MenuActivo != false){
	  if(((yy < TopMenuEmerg) || (yy > BottomMenuEmerg)) || ((xx < LeftMenuEmerg) || (xx > RightMenuEmerg))){
		OcultarMenuEmerg();
		MenuActivo = false;		
	  }
	}*/
	return true;
}

// ------------------------------------------
// Funcion para cambiar estilos
// ------------------------------------------
function cambiarEstilo(_id, _e){
  if(is.ie){
	element = document.getElementById(_id);
  }	
  element.className = _e;
}