// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;

IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

IE5plus = IE5 || IE6;
IEMajor = 0;

if (IE4plus)
{
	var start = navigator.appVersion.indexOf("MSIE");
	var end = navigator.appVersion.indexOf(".",start);
	IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
	IE5plus = (IEMajor>=5) ? true : false;
}

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

function isInt(numIn)
{
	var checknum = parseInt(numIn);
	return !isNaN(checknum);
}

// Make an object visible
function showObject(obj) 
{
        if (NS4) obj.visibility = "show";
        else if (IE4plus||NS6) obj.visibility = "visible";
}

// Hides an object
function hideObject(obj) 
{
        if (NS4) obj.visibility = "hide";
        else if (IE4plus||NS6) obj.visibility = "hidden";
}

// Move a layer
function moveTo(obj,xL,yL) 
{
        obj.left = xL;
        obj.top = yL;
}

// Browser window width
function getWindowWidth()
{
	if (NS4 || NS6)
		return window.innerWidth;
	else if (IE4plus)
		return document.body.clientWidth;
}

function getObjLoc(oIn)
{
	var oOut = new Object();
	oOut.top = 0;
	oOut.left = 0;

	if ((IE4plus && !isMac) || (IEmac && IE5) )
	{
		oOut.left = oIn.offsetLeft;
		oOut.top = oIn.offsetTop;
		var newp = oIn.offsetParent;
		while(newp != null)
		{
			oOut.left += newp.offsetLeft;
			oOut.top += newp.offsetTop;
			newp = newp.offsetParent;
		}
		if (IEmac)
		{	
			oOut.left += parseInt(document.body.leftMargin);
			oOut.top +=  parseInt(document.body.topMargin);
		}
	}
	else if (NS4)
	{
		oOut.left = oIn.x;
		oOut.top = oIn.y;
	}
	else if (isMac && IE4)
	{
		var el = oIn;
		do
		{	
			if (isInt(el.offsetTop))
				oOut.top += el.offsetTop;
			if (isInt(el.offsetLeft))
				oOut.left += el.offsetLeft;
			el = el.parentElement;
		} while (el.tagName != "BODY");
		if (navigator.appVersion.indexOf("4.5")>=0)
			oOut.top = oOut.top - 15;
	}
	else if (NS6)
	{
		var b=document.getElementsByTagName('body')[0];
		oOut.left = oIn.offsetLeft+b.offsetLeft;
		oOut.top = oIn.offsetTop+b.offsetTop;
	}
	return oOut;
} 


function createLayer(name,left,top,width,height,html)
{
	var nL;
	
	if (IE4plus)
	{
		var divhtml = '<div id=' + name + ' style="visibility:hidden;left:' + left + 
			'px;top:' + top + 'px;width:' + width + 
			'px;height:' + height + 'px;position:absolute">' + 
			html + '</div>';
		document.body.insertAdjacentHTML('beforeEnd', divhtml);
		nL = document.all[name].style
	}
	else if (NS4)
	{
		nL=new Layer(width);
		nL.name = name;
		nL.left=left;
		nL.top=top;
		nL.clip.width=width;
		nL.clip.height=height;
		nL.document.open();
		nL.document.write(html);
		nL.document.close();
	}
	else if (NS6)
	{
		nL = document.createElement("DIV");
		nL.innerHTML = html;
		var mybody=document.body;
		mybody.appendChild(nL);
		nL.style.position = "absolute";
		nL.style.visibility = "hidden";
		nL.style.left = left;
		nL.style.top = top;
		nL.style.width = width;
		nL.style.height = height;
		nL.id = name;
		nL = nL.style;
	}
	return nL;
}

