var tiempo=0;

function checkBrowser(){
	ns4 = (document.layers)? true:false
	ns6 = (document.getElementById && !document.all)
	ie4 = (document.all)? true:false
	ie5 = (document.all && document.getElementById);
}

function getLayerByName(layerName){
	if (ns4) elem = DSm_findLayer(layerName);
	if (ie5) elem = document.getElementById(layerName);
	if (ns6) elem = document.getElementById(layerName).style;
	if (ie4) elem = eval(layerName+".style");
	return elem;
}

function DSm_findLayer(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=DSm_findLayer(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function findPosX(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}

taopen = false;
function showLayer(capa,opc,tiempo_espera){
	//alert(opc);
	var obj = getLayerByName(capa);
	if(opc == 3){
		//alert(3);
		clearTimeout(this.tiempo);
		return true;
	}else{
		if (opc == 1 && taopen == true){
			//alert("tanca");
			clearTimeout(this.tiempo);
			if (document.all || document.getElementById){ obj.visibility = "hidden"; }
			else { obj.visibility = "hide";	}
			taopen = false;
		}else{
			if (opc == 1){
				//alert("obre");
				clearTimeout(tiempo);
				if (document.all || document.getElementById){ obj.visibility = "visible"; }
				else {  obj.visibility = "show"; }
				taopen = true;
			}
			else{
				if (opc == 0){
					//alert("this.tiempo=setTimeout(\"showLayer('"+capa+"',2)\","+tiempo_espera+")");
					eval("this.tiempo=setTimeout(\"showLayer('"+capa+"',2)\","+tiempo_espera+")");
				}
				else{
					if (opc != 3){
					//alert("llamada despues del settimeout");
						clearTimeout(this.tiempo);
						if (document.all || document.getElementById){ obj.visibility = "hidden"; }
						else { obj.visibility = "hide";	}
						taopen = false;
					}
				}
			}
		}
	}
}

function enableLayer(capa,opc,tiempo_espera){
	//alert(opc);
	var obj = getLayerByName(capa);
	if(opc == 3){
		//alert(3);
		clearTimeout(this.tiempo);
		return true;
	}else{
		if (opc == 1 && taopen == true){
			//alert("tanca");
			clearTimeout(this.tiempo);
			if (document.all || document.getElementById){ obj.display = "none"; }
			else { obj.display = "none";	}
			taopen = false;
		}else{
			if (opc == 1){
				//alert("obre");
				clearTimeout(tiempo);
				if (document.all || document.getElementById){ obj.display = "block"; }
				else {  obj.display = "block"; }
				taopen = true;
			}
			else{
				if (opc == 0){
					//alert("this.tiempo=setTimeout(\"showLayer('"+capa+"',2)\","+tiempo_espera+")");
					eval("this.tiempo=setTimeout(\"showLayer('"+capa+"',2)\","+tiempo_espera+")");
				}
				else{
					if (opc != 3){
					//alert("llamada despues del settimeout");
						clearTimeout(this.tiempo);
						if (document.all || document.getElementById){ obj.display = "none"; }
						else { obj.display = "none";	}
						taopen = false;
					}
				}
			}
		}
	}
}