/*	
--------------------------------------------------------------------------------
Name:		layerFunctions.js
Purpose:	A number of functions used to handle layers
Revision:
2000-10-04		Henrik Engqvist		Created
2000-11-16		Henrik Engqvist		Layer function made more dynamic, allowing 
									any level of nesting
2005-06-01		Daniel Joelsson		Inluding handling for Mozilla FireFox 
--------------------------------------------------------------------------------
FUNCTIONS:

Name:		showLayer(layerName)
Purpose:	Display a given layer
Arguments:	layerName	Layer to be displayed. If nested - arguments are 
						received in order from bottom and up,
						starting off with the layer to be manipulated.

Name:		hideLayer(layerName)
Purpose:	Hide a given layer
Arguments:	layerName	Layer to be hidden. If nested - arguments are 
						received in order from bottom and up,
						starting off with the layer to be manipulated.

Name:		writeLayer(layerName, str)
Purpose:	Write a text string into a given layer
Arguments:	str			Text string to be displayed
			layerName	Name of the layer containing the information to be displayed.
						If nested - arguments are received in order from bottom and 
						up, starting off with the layer to be manipulated.
			

Name:		loadLayer(url, width, layerName)
Purpose:	Upload a new document into a layer (NS) or iframe (MSIE) 
Arguments:	url			Location of new documnet
			width		Width dedicated to uploaded document - optional, NS only
			layerName	Name of the layer or iframe. If nested - arguments are 
						received in order from bottom and up, starting off with 
						the layer to be manipulated.
--------------------------------------------------------------------------------
*/

function showLayer(layerName) {
	var layerobj;
	var layerstr="";
	
	if (navigator.appName == 'Netscape' && document.layers) {
		// Netscape
		for(var i=(arguments.length - 1); i >= 0; i--) {
			layerstr = layerstr + 'document.layers[\'' + arguments[i] + '\']'; 
			if (i > 0) layerstr = layerstr + '.';
		}
		layerobj = eval(layerstr);
		if (layerobj) layerobj.visibility = 'show';
	} else if (document.all) {
		// Explorer
		layerobj = eval('document.all[\'' + layerName + '\']');
		if (layerobj) layerobj.style.visibility = 'visible';
	}
	else
	{
		layerobj = eval('document.getElementById(layerName)');
		if (layerobj) layerobj.style.visibility = 'visible';
	}
}

function hideLayer(layerName, scrollWin, scrollCont){
	var layerobj;
	var layerstr="";
	
	if (navigator.appName == 'Netscape' && document.layers) {
		// Netscape
		for(var i=(arguments.length - 1); i >= 0; i--) {
			layerstr = layerstr + 'document.layers[\'' + arguments[i] + '\']'; 
			if (i > 0) layerstr = layerstr + '.';
		}
		layerobj = eval(layerstr);
		if (layerobj) layerobj.visibility = 'hide';
	} else if (document.all) {
		// Explorer
		layerobj = eval('document.all[\'' + layerName + '\']');
		if (layerobj) layerobj.style.visibility = 'hidden';
	}
	else
	{
		layerobj = eval('document.getElementById(layerName)');
		if (layerobj) layerobj.style.visibility = 'hidden';
	}
}

function writeLayer(str, layerName){
	var layerobj;
	var layerstr = "";
	if(navigator.appName == 'Netscape' && document.layers != null){
/*DEBUG*/ alert("Trace Netscape");

		// Netscape
		for(var i=(arguments.length - 1); i >= 1; i--){
			layerstr = layerstr + 'document.layers[\'' + arguments[i] + '\']'; 
			if (i > 1){
				layerstr = layerstr + '.';
			}
		}
		layerobj = eval(layerstr);
//************ ERROR I NETSCAPE *************
		if (layerobj){
			layerobj.document.open();
			layerobj.document.write(str);
			layerobj.document.close();
		}
//*********** / ERROR I NETSCAPE ************
	}
	else if(document.all != null){
		// Explorer
		layerobj = eval('document.all[\'' + layerName + '\']');
		if (layerobj){
			layerobj.innerHTML = str;
		}
	}
	else
	{
	layerobj = eval('document.getElementById(layerName)');
		if (layerobj){
			layerobj.innerHTML = str;
		}
	}
	
	
}

function loadLayer(url, width, layerName){
	var layerobj;
	var layerstr="";
	
	if (navigator.appName=='Netscape' && document.layers) {
		// Netscape
		for(var i=(arguments.length - 1); i >= 2; i--) {
			layerstr = layerstr + 'document.layers[\'' + arguments[i] + '\']'; 
			if (i > 2) layerstr = layerstr + '.';
		}
		layerobj = eval(layerstr);
		if (layerobj) layerobj.load(url, width);
	} else if(document.all) {
		// Explorer
		document.frames[layerName].location = url;
	}
	else
	{
		document.frames[layerName].location = url;
	}
}
