// Browser check
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
ns6 = (document.getElementById && !document.all)
ie5 = (document.all && document.getElementById)? true:false

//alert(ns4);
//alert(ie4);
//alert(ns6);
//alert(ie5);


NOM = 0;
PUNTER = 1;
capes = new Array();

// Declarem una nova capa a utilitzar
function DSregCapa(nomCapa){
	actual = capes.length;
	capes[actual] = new Array(2);
	capes[actual][NOM] = nomCapa;

	if (ie4) eval("capes[actual][PUNTER] = " + nomCapa + ".style");
	//if (ie5) eval("capes[actual][PUNTER] = document.getElementById('" + nomCapa + "')");
	if (ns4) eval("capes[actual][PUNTER] = document.layers['" + nomCapa + "']");
	if (ns6) eval("capes[actual][PUNTER] = document.getElementById('" + nomCapa + "').style");
}

function DSgetPunter(nomCapa){
	for (i=0; i<capes.length; i++){
		if(capes[i][NOM]==nomCapa) return capes[i][PUNTER];
	}
}

function DSgetProp(nomCapa, nomProp){
	return eval("DSgetPunter(nomCapa)." + nomProp);
}

function DSsetProp(nomCapa, nomProp, valor){
	eval("DSgetPunter(nomCapa)." + nomProp + " = " + valor);
}

//function DSshow(nomCapa){
//	if(ns4) DSgetPunter(nomCapa).visibility = "show";
//	if(ie4 || ie5 || ns6) DSgetPunter(nomCapa).visibility = "visible";
//	DSsetProp(nomCapa, "zIndex", 100);
//}

lacapa =""

function DSshow(nomCapa){
lacapa=nomCapa;
setTimeout("mostra()", 100);
}

function mostra(){
nomCapa=lacapa;
if (typeof(gofuera)=="boolean"){
	if (gofuera == false){
		if(ns4) DSgetPunter(nomCapa).visibility = "show";
		if(ie4 || ie5 || ns6) DSgetPunter(nomCapa).visibility = "visible";
		DSsetProp(nomCapa, "zIndex", 100);
	}
}
}


function DShide(nomCapa){
	if(ns4) DSgetPunter(nomCapa).visibility = "hide";
	if(ie4 || ie5 || ns6) DSgetPunter(nomCapa).visibility = "hidden";
	DSsetProp(nomCapa, "zIndex", 2);
}

function DSmoveTo(nomCapa, nomObjectiu){
	if(ns6){
		DSsetProp(nomCapa, "left", eval("findPosX(document." + nomObjectiu + ")-1"));
	}else{
		DSsetProp(nomCapa, "left", eval("findPosX(document." + nomObjectiu + ")"));
	}
	if(ns4){
		DSsetProp(nomCapa, "top", eval("findPosY(document." + nomObjectiu + ")-16"));
	}else{
		DSsetProp(nomCapa, "top", eval("findPosY(document." + nomObjectiu + ")-5"));
	}
}

function DSmoveRight(nomCapa, inc){
	DSsetProp(nomCapa, "left", parseInt(DSgetProp(nomCapa, "left"))+inc);
}

function DSmoveDown(nomCapa, inc){
	DSsetProp(nomCapa, "top", parseInt(DSgetProp(nomCapa, "top"))+inc);
}

function DSmoveToX(nomCapa, nomObjectiu){
	if(ns6){
		DSsetProp(nomCapa, "left", eval("findPosX(document." + nomObjectiu + ")-1"));
	}else{
		DSsetProp(nomCapa, "left", eval("findPosX(document." + nomObjectiu + ")"));	
	}
}

function DSmoveToY(nomCapa, nomObjectiu){
	if(ns4){
		DSsetProp(nomCapa, "top", eval("findPosY(document." + nomObjectiu + ")-16"));
	}else{
		DSsetProp(nomCapa, "top", eval("findPosY(document." + nomObjectiu + ")"));
	}
}

function debug(objeto){
	var result = ""; datos=window.open("","datos");
	for (var i in objeto) {result += "." + i + " = " + objeto[i] + "<br>";} datos.document.writeln(result);
	return true;
}

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;
	if (document.getElementById && !document.all) curleft+=1;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	var printstring = '';
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}

/**********************************************************************************************************************
-----------------------------------------------------------------------------------------------------------------------
	Function name:		createLayer
	Description:		Permite crear una capa dinamicamente simplemente especificando sus propiedades y nombre.
	Example:
						createLayer(identificador_del_layer,posX,posY,Ancho_capa,Alto_capa,Estado_visibilidad);
-----------------------------------------------------------------------------------------------------------------------
**********************************************************************************************************************/
function createLayer (id_layer,posX,posY,width,height,vision){
	var brow = (document.layers)? true:false;
	if(brow){
		document.layers[id_layer] = new Layer(width);
		aux = document.layers[id_layer];
		aux.name = id_layer;
		aux.left = posX;
		aux.top = posY;
		aux.nombre = id_layer;  //propiedad extra
		if(width!=null){aux.width=width;}
		if(height!=null){aux.height=height;}
		(vision == "hide")? aux.visibility = "hide" : aux.visibility = "show";
	}
	else{
		aux = '<div id="'+id_layer+'" style="z-index:20;position:absolute;left:'+posX+'px;top:'+posY+'px;';
		if(width != null){aux += 'width:'+width+'px;';}
		if(height != null){aux += 'height:'+height+'px;';}
		(vision=='hide')? aux += 'visibility:hidden;' : aux += 'visibility:visible;';
		aux += '" onMouseOver="gofuera=false" onMouseOut="vete()"></div>';

		if (ns6){
			var lyr = document.createElement("DIV");
			lyr.id = id_layer;
			lyr.style.position = "absolute";
			lyr.style.left = posX+"px";
			lyr.style.top = posY+"px";
			lyr.style.width = width+"px";
			lyr.style.height = height+"px";
			(vision=="hide")? lyr.style.visibility="hidden" : lyr.style.visibility="visible";
			document.body.appendChild(lyr);
		}
		else{
			document.body.insertAdjacentHTML("BeforeEnd",aux);
		}
	}
}

/**********************************************************************************************************************
-----------------------------------------------------------------------------------------------------------------------
	Function name:		drawInLayer
	Description:		Permite escribir una cadena de texto dentro de una capa especificada, borrando su contenido
						anterior.
	Example:
						drawInLayer(identificador_del_layer,cadena_html);
-----------------------------------------------------------------------------------------------------------------------
**********************************************************************************************************************/
function drawInLayer(id,contenido){
	if(document.all){
		document.all[id].innerHTML = contenido;
	}
	else{
		if (ns6){
			document.getElementById(id).innerHTML = contenido;
		}
		else{
			document.layers[id].document.open();
			document.layers[id].document.write('<body>'+contenido+'</body>');
			document.layers[id].document.close();
		}
	}
}

/**********************************************************************************************************************
-----------------------------------------------------------------------------------------------------------------------
	Function name:		getLayerByName
	Description:		Permite obtener un objeto layer de una forma estandarizada, a partir de su identificador.
	Example:
						objMiCapa = getLayerByName("nuevacapa");        elem = document.layers['content'].layers[layerName];
-----------------------------------------------------------------------------------------------------------------------
**********************************************************************************************************************/
function getLayerByName(layerName){
	if (ns4) {
		continuaFlag=true;
		for (i=0;i<document.layers.length && continuaFlag;i++)
			//alert("busca "+ layerName+" encuentra "+document.layers[i].nombre);
			if (document.layers[i].name==layerName || document.layers[i].nombre==layerName) {
				elem = document.layers[i];
				continuaFlag=false; //alert("encontrado");
			}
		//alert("fin");
	}
	if (ie5) elem = document.getElementById(layerName);
	if (ns6) elem = document.getElementById(layerName).style;
	if (ie4) elem = eval(layerName+".style");
	return elem;
}