// 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." + 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);
}

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 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;
}
