// ------------------------------------------
// 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.ie6 = (this.version.indexOf('MSIE 6')>0);
  this.ie7 = (this.version.indexOf('MSIE 7')>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;
	this.ie6=true;
	this.ie7=true;
  }
}
is = new BrowserCheck();
// ------------------------------------------
// Cambiar imágenes
// ------------------------------------------
function CambiaImagen(capa, nombre, 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;
  }
}
// ------------------------------------------
// Switch row colors
// Pasar (this) como valor para (name) si se llama desde una celda de la fila, es suficiente
// ------------------------------------------
function paintRow(name, style){
	if(is.ie){
		var rowObj = name.parentElement;
		rowObj.className = style;
		for(var i=0; i < (rowObj.childNodes).length; i++){
			rowObj.childNodes[i].className = style;
		}
	}
}
// ------------------------------------------
// Abrir nueva ventana
// ------------------------------------------
function AbrirVentana(actUrl, actW, actH, actName, scrBar, actX, actY, actR, actTB){
	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"
	}else if(actX<0){
		if(getScreenWidth()>0 && getScreenWidth()>(actW/2)){
			actX=(getScreenWidth()/2)-(actW/2);
		}else{
			actX="0";
		}
	}
	if((!actY) || (actY == null)){
		actY="0"
	}else if(actY<0){
		if(getScreenHeight()>0 && getScreenHeight()>(actH/2)){
			actY=(getScreenHeight()/2)-(actH/2);

		}else{
			actY="0";
		}
	}
	if((!scrBar) || (scrBar == null)){scrBar="0"}
	if((!actR) || (actR == null)){actR="0"}
	if((!actTB) || (actTB == null)){actTB="0"}
	actProp = "status=1,top=0,toolbar=" + actTB + ",scrollbars=" + scrBar + ",menubar=0,directories=0,left=" + actX + ",top=" + actY + ",width=" + actW + ",height=" + actH + ", resizable=" + actR;
	window.open(actUrl, actName, actProp);
}
// ------------------------------------------
// Alternancia entre capas ocultas/visibles
// ------------------------------------------
function toggleBox(szDivID, iState){ // 1 visible, 0 hidden
    if(document.layers){	//NN4+
    
       document.layers[szDivID].visibility = iState ? "show" : "hide";
       document.layers[szDivID].display = iState ? "block" : "none";
    }else if(document.getElementById){	//gecko(NN6) + IE 5+
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
        obj.style.display = iState ? "block" : "none";
    }else if(document.all){	// IE 4
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
        document.all[szDivID].style.display = iState ? "block" : "none";
    }
}
// ------------------------------------------
// Altura y anchura del navegador
// ------------------------------------------
function getBrowseWidth(){
 if (window.innerWidth) return window.innerWidth;
 else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
 else return 0;
}
function getBrowseHeight(){
 if (window.innerHeight) return window.innerHeight  ;
 else if (document.body && document.body.offsetHeight) return document.body.offsetHeight;
 else return 0;
}
function getScreenWidth(){
 if (window.screen.width) return window.screen.width;
 else return 0;
}
function getScreenHeight(){
 if (window.screen.height) return window.screen.height;
 else return 0;
}
// ------------------------------------------
// URLEncode
// ------------------------------------------
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}
// ------------------------------------------
// Ajuste de las alturas
// ------------------------------------------
function altura(){
  al = new Array(); max = 0;
	try{
	  if(document.getElementById){
		  for(i=0;i<arguments.length;i++){
			if(document.getElementById(arguments[i]))
			  al[i] = document.getElementById(arguments[i]).offsetHeight;
		  }
		  max = mayor(al);
		  if(max > 0){
			for(i=0;i<arguments.length;i++){
			  if(document.getElementById(arguments[i]))
				document.getElementById(arguments[i]).style.height = max + 'px';
			  }
		  }
	  }
	}
	catch (exc) {
	  alert("Se ha producido un error en la carga del CSS.");
	  throw exc;
	}
}
//
function mayor(datos){  
  salida = 0;  
  for(i=0;i<datos.length;i++){  
	  if(parseInt(datos[i]) > salida )  
	  	  salida = datos[i];  
  }  
  return salida;
}