/*
Copyright Michael Nilsson ©
Contact: info@lumos.nu
You can use this code as long you don't change anything and let all text/code be intact.
------------------------------------------------------------------------------------------------------------------------------
New in Version 1.6
------------------------------------------------------------------------------------------------------------------------------
Juni 2006.
This is the first changes since 2001. Basicly make it work more loose in the new browsers no need for position:absolute etc, 
I only change methods one by one as i need it and without test in old 4.x browsers so this is a beta version use 1.5 for more 
stable version.
------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------
New in Version 1.5
------------------------------------------------------------------------------------------------------------------------------
Small fixes in the code to fix some problem when using frames..
------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------
New in Version 1.4
------------------------------------------------------------------------------------------------------------------------------
There is no new functions in this version. The Big difrense is that this supports nestled layers for Netscape..
You use it like this: ex. document.layers.THE_LAYER_NAME.document.layers.THE_LAYER_NAME_INSIDE_THEOTHER
So you only send that into a function insted of just the layer name.. in IE and N6 you do like before(send in the layer name). 
So strLayer is maybe not so good name anymore becorse it can also be a objReferense, 
but that has not been changed in this version..
------------------------------------------------------------------------------------------------------------------------------
*/

// set the file to send user who dont suports layers!
strFile = "http://www.bona.com/global/481/Showroom/noDhtml.htm"

//---------------------- 
//  BROWSER VERSION  
//----------------------
var IE = document.all; // IE 4x
var NN = document.layers; //NN 4x
var IENN = document.getElementById; // IE 5x and N6x
var isN6 = false; //N6 true or false to make difrense betwen IE5 and N6..
if (navigator.appName == 'Netscape') 
{
  	if (navigator.appVersion.charAt(0) == "5")
  	{
		isN6 = true;// N6x
	}
}	
		
//------------------- 
// PLATFORM 
//-------------------
var agt = navigator.userAgent.toLowerCase(); // convert all characters to lowercase to simplify testing 
var isWin = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var isMac = (agt.indexOf("mac")!=-1);


var coll="";
var styleObj="";
//--------------------------- 
// Layer Check
//---------------------------
if (IENN)
{
	coll = "getElementById('";
	styleObj = "').style";
}
else if(IE)
{
	coll = "all('";
	styleObj = "').style"
}
else if(NN)
{
	coll = "layers['";
	styleObj = "']";
}
else
{
	document.location.href= strFile;
}

// call the handleResize function if the window is resized in NN
if (NN)
{
	captureEvents(Event.RESIZE);
	onresize = handleResize;
}
/*
-----------------------------------------
function handleResize()
-----------------------------------------
Desc:	reload the page, specialy used to
		fix the resize bugg i NN   		
Arg:	
Ret:	false
-----------------------------------------
*/
function handleResize()
{
	document.location.reload();
	//return false
}

/*
-----------------------------------------
function getObj(strLayer)
-----------------------------------------
Desc:	Return a object reference to 
		the layer. Works for IE 4x, IE5x,
		NN4x, NN6x  		
Arg:	strLayer = the name of the layer.
Ret:	Object Reference
-----------------------------------------
*/
function getObj(strLayer)
{
	var objRef;
	if(typeof strLayer == "string")
	{
		return objRef = eval("document." + coll  + strLayer  + styleObj);
	}
	else
	{
		return objRef = strLayer
	}
}
/*
-----------------------------------------
function hideLayer(strLayer)
-----------------------------------------
Desc:	hide the specific layer works in
		IE 4x, IE5x, NN4x, NN6x
Arg:	strLayer = the name of the layer
		to hide.
Ret:	none.
-----------------------------------------
*/
function hideLayer(strLayer)
{
	var objRef = getObj(strLayer);
	if(IE || IENN)
	{
		objRef.visibility = "hidden";
	}
	else if(document.layers)
	{
		objRef.visibility = "hide";
	}
}
/*
-----------------------------------------
function showLayer(strLayer)
-----------------------------------------
Desc:	show the specific layer works in
		IE 4x, IE5x, NN4x, NN6x
Arg:	strLayer = the name of the layer
		to show.
Ret:	none.
-----------------------------------------
*/
function showLayer(strLayer)
{
	var objRef = getObj(strLayer);
	
	if(document.layers)
	{
		objRef.visibility = "show";
	}
	else
	{
		objRef.visibility = "visible";
	}
}
/*
-----------------------------------------
function writeToLayer(strLayer, strText)
-----------------------------------------
Desc:	write content to the specific 
		layer works in IE 4x, IE5x, NN4x
		NN6x
Arg:	strLayer = the name of the layer
		to write in.
		strText = the string to be writen
		to the layer
Ret:	none.
-----------------------------------------
*/
function writeToLayer(strLayer,strText)
{
	if(IENN)
	{
		document.getElementById(strLayer).innerHTML = strText;
	}
	else if(IE)
	{
		IE[strLayer].innerHTML = strText;
	}
	else if(document.layers)
	{
		//objRef = getObj(strLayer);
		document.layers[strLayer].document.open();
		document.layers[strLayer].document.write(strText);
		document.layers[strLayer].document.close();
	}
}
/*
-----------------------------------------
function moveLayerTo(strLayer, intX, intY)
-----------------------------------------
Desc:	Move the specefic layer to the 
		x and y cordinats. Works for 
		IE 4x, IE5x, NN4x, NN6x  		
Arg:	strLayer = the name of the layer.
		intX = pixels from left
		intY = pixels from top
Ret:	none
-----------------------------------------
*/
function moveLayerTo(strLayer, intX, intY)
{
	
		var objRef = getObj(strLayer);
		objRef.top = intY + "px";
		objRef.left = intX + "px";
	
	
}
/*
-----------------------------------------
function setZIndex(strLayer, intZ)
-----------------------------------------
Desc:	Setting the z-order of the layer
		IE 4x, IE5x, NN4x, NN6x  		
Arg:	strLayer = the name of the layer.
		intZ = the index number to set
Ret:	none
-----------------------------------------
*/
function setZIndex(strLayer, intZ)
{
	var objRef = getObj(strLayer);
	objRef.zIndex = intZ;
}
/*
-----------------------------------------
function setBGColor(strLayer, strColor)
-----------------------------------------
Desc:	Setting the background color of
		the layer. works in IE 4x, IE5x,
		NN4x, NN6x  		
Arg:	strLayer = the name of the layer.
		strColor = colorName or RGB
Ret:	none
-----------------------------------------
*/
function setBGColor(strLayer, strColor)
{
	var objRef = getObj(strLayer);
	if (document.layers)
	{
		objRef.bgColor = strColor;
	}
	else 
	{
		objRef.backgroundColor = strColor;
	}
}

/*
-----------------------------------------
function getObjLeft(strLayer)
-----------------------------------------
Desc:	get the position from left in 
		pixels. works in IE 4x, IE5x,
		NN4x, NN6x
		OBS! this attribute must in some
		browsers (IE5x and N6x) been set
		before you can read it. You can
		do this in to ways,
		set the left attribute in a init()
		function onLoad, or you have to  
		set the style attribute in the tag
		instead of setting it as a id in a 
		"style" tag.   		

Arg:	strLayer = the name of the layer.
Ret:	integer how many pixels from left
-----------------------------------------
*/
function getObjLeft(strLayer)
{
	var objRef = getObj(strLayer);
	if (document.layers)
	{
		return objRef.left;
	}
	else if (IENN)
	{
		return parseInt(document.getElementById(strLayer).offsetLeft);
		//return parseInt(objRef.left);
	}
	else if (IE)
	{
		return parseInt(objRef.pixelLeft);
	}
}
/*
-----------------------------------------
function getObjTop(strLayer)
-----------------------------------------
Desc:	get the position from top in 
		pixels. works in IE 4x, IE5x,
		NN4x, NN6x
		OBS! this attribute must in some
		browsers (IE5x and N6x) been set
		before you can read it. You can
		do this in to ways,
		set the left attribute in a init()
		function onLoad, or you have to  
		set the style attribute in the tag
		instead of setting it as a id in a 
		<style> tag.   		

Arg:	strLayer = the name of the layer.
Ret:	integer how many pixels from top
-----------------------------------------
*/
function getObjTop(strLayer)
{
	var objRef = getObj(strLayer);
	if (document.layers)
	{
		return objRef.top
	}
	else if(IENN)
	{
		return parseInt(document.getElementById(strLayer).offsetTop);
		//return parseInt(objRef.offsetTop);
	}
	else if (IE)
	{
		return parseInt(objRef.pixelTop);
	}
}

/*
-----------------------------------------
function moveLayer(strLayer, intX, intY)
-----------------------------------------
Desc:	Move the specefic layer  x and y 
		pixels from the curent position. 
		Works for IE 4x, IE5x, NN4x, NN6x  		
Arg:	strLayer = the name of the layer.
		intX = pixels to move in x cordinate
		intY = pixels to move in y cordinate
Ret:	none
-----------------------------------------
*/
function moveLayer(strLayer, intX, intY)
{
	var objRef = getObj(strLayer);
	var intCurentY = getObjTop(strLayer);
	var intCurentX = getObjLeft(strLayer);
	objRef.top = intCurentY + intY;
	objRef.left = intCurentX + intX;
}

/*
-----------------------------------------
function getObjHeight(strLayer)
-----------------------------------------
Desc:	gets the Height of the Layer
		IE 4x, IE5x, NN4x, NN6x
Arg:	strLayer = the name of the layer.
Ret:	integer (Height) in pixels
-----------------------------------------
*/
function getObjHeight(strLayer)
{
	var intHeight;
	if(IENN)
	{
		return intHeight = parseInt(document.getElementById(strLayer).offsetHeight);
	}
	else if(IE)
	{
		return intHeight = parseInt(document.all[strLayer].clientHeight);
	}
	else if(document.layers)
	{
		var objRef = getObj(strLayer);
		intHeight = parseInt(eval(objRef.clip.height));
		return intHeight 
	}
	
}

/*
-----------------------------------------
function getObjWidth(strLayer)
-----------------------------------------
Desc:	gets the Height of the Layer
		IE 4x, IE5x, NN4x, NN6x
Arg:	strLayer = the name of the layer.
Ret:	integer (Width) in pixels
-----------------------------------------
*/
function getObjWidth(strLayer)
{
	var intWidth;
	if(IENN)
	{
		return intWidth = parseInt(document.getElementById(strLayer).offsetWidth);
	}
	else if(IE)
	{
		return intWidth = parseInt(document.all[strLayer].clientWidth);
	}
	else if(document.layers)
	{
		return intWidth = parseInt(document.layers[strLayer].clip.width);
	}
}

/*
-----------------------------------------
function getWindowWidth()
-----------------------------------------
Desc:	Gets the Window Width
		IE 4x, IE5x, NN4x, NN6x
		Note: IE don have a property for 
		the window width so I had to take 
		the body width. This can do that 
		it is not the exakt pixels width
		in exploer.  
Arg:	
Ret:	integer: the WindowWidth
-----------------------------------------
*/
function getWindowWidth()
{
	if (document.layers)
	{
		return parseInt(window.innerWidth);
	}
	if (IE)
	{
		return parseInt(document.body.offsetWidth);
	}
	else if (IENN && isN6)
	{
		return parseInt(window.innerWidth);
	}
}

/*
-----------------------------------------
function getWindowHeight()
-----------------------------------------
Desc:	Gets the Windows Height
		IE 4x, IE5x, NN4x, NN6x
		Note: IE don have a property for 
		the window Height so I had to take 
		the body Height. This can do that 
		it is not the exakt pixels Height
		in exploer.  
Arg:	
Ret:	integer: the WindowHeight
-----------------------------------------
*/
function getWindowHeight()
{
	if (document.layers)
	{
		return parseInt(window.innerHeight);
	}
	if (IE)
	{
		return parseInt(document.body.offsetHeight);
	}
	else if (IENN && isN6)
	{
		return parseInt(window.innerHeight);
	}
}

/*
-----------------------------------------
function centerLayer(strLayer)
-----------------------------------------
Desc:	Center the specific layer
		IE 4x, IE5x, NN4x, NN6x
Arg:	strLayer = the name of the layer.
Ret:	none.
-----------------------------------------
*/
function centerLayer(strLayer)
{
	var intWindowWidth  = getWindowWidth();
	var intWindowHeight = getWindowHeight();
	var intLayerWidth   = getObjWidth(strLayer);
	var intLayerHeight  = getObjHeight(strLayer);
	var intX = (intWindowWidth/2)  - (intLayerWidth/2);
	var intY = (intWindowHeight/2) - (intLayerHeight/2);
	moveLayerTo(strLayer, intX, intY );
}



/*
-----------------------------------------
function getObjNoStyle(strLayer)
-----------------------------------------
Desc:	Return a object reference to 
		the layer. Works for IE 4x, IE5x,
		NN4x, NN6x  		
Arg:	strLayer = the name of the layer.
Ret:	Object Reference
-----------------------------------------
*/
function getObjNoStyle(strLayer)
{
	var objRef;
	if(typeof strLayer == "string")
	{
		return objRef = eval("document." + coll + strLayer);
	}
	else
	{
		return objRef = strLayer
	}
}