
var platform		= navigator.platform;
var browser			= navigator.appName;
var version			= navigator.appVersion;
var agent			= navigator.userAgent;
var idbrowser;

if (platform=="MacPPC") {
	if (browser=="Microsoft Internet Explorer") {
		if (version=="4.0 (compatible; MSIE 5.0; Macintosh; I; PPC)") { idbrowser = "iepc" }
		else { idbrowser = "iemac" }
	}
	if (browser=="Netscape") { idbrowser = "nsmac" }
}

if (platform=="Win32") {
	if (browser=="Microsoft Internet Explorer") { idbrowser = "iepc" }
	if (browser=="Netscape") { idbrowser = "nspc" }
}

var id = idbrowser;



function DOMAvailable() {
	return (document.getElementById?true:false);
}

function isNetscape() {
	return (browser == "Netscape");
}

function isNetscape4() {
	return (isNetscape() && (getBrowserVersion() < 5));
}

function isExplorer() {
	return (browser == "Microsoft Internet Explorer");
}

function isExplorer4() {
	return (isExplorer() && !DOMAvailable())
}

function isOpera() {
	return (agent.indexOf("Opera", 0) != -1);
}

function isMac() {
	return (platform == "MacPPC");
}

function isPC() {
	return (platform == "Win32");
}

function isDynamic() {
	return (DOMAvailable() || isExplorer4() || isNetscape())
}



function getBrowserVersion() {
	if ((idbrowser == 'iepc') || (idbrowser == 'iemac')) {
		iStart = version.indexOf("MSIE") + 5;
		iEnd = version.indexOf(";",iStart);
		sVersion = version.substr(iStart, (iEnd - iStart));
		return sVersion.valueOf();
	} else if ((idbrowser == 'nspc') || (idbrowser == 'nsmac')) {
		return new Number(version.substring(0, version.indexOf(" ")));
	} else {
		return -1
	}
}



// --- -----------------------------------------------------------------------
// --- Layout dimension functions
// --- -----------------------------------------------------------------------

var _pagelayoutWidth, _pagelayoutHeight = 0;

function setLayoutDimensions(iWidth, iHeight) {
	_pagelayoutWidth = new Number(iWidth);
	_pagelayoutHeight = new Number(iHeight);
}


function getLayoutTop() {
	return Math.round((getDocumentHeight() - _pagelayoutHeight) / 2);
}


function getLayoutLeft() {
	return Math.round((getDocumentWidth() - _pagelayoutWidth) / 2);
}



// --- -----------------------------------------------------------------------
// --- Netscape compatible mouse location reader
// --- 
// --- Use getMouseX() and getMouseY() to retrieve coordinates.
// ---
// --- Compatibility:
// --- IE4		Unconfirmed
// --- IE4.5+	OK
// --- NS4		OK
// --- NS6		OK
// --- Opera	Unconfirmed
// --- -----------------------------------------------------------------------

var _iMouseX, _iMouseY = 0;

if (isNetscape()) {
	document.captureEvents(Event.MOUSEMOVE)
}

document.onmousemove = _updateMouseLocation;

function _updateMouseLocation(e) {
	_iMouseX = (isNetscape()) ? e.pageX : (event.clientX + document.body.scrollLeft);
	_iMouseY = (isNetscape()) ? e.pageY : (event.clientY + document.body.scrollTop);
}



// --- -----------------------------------------------------------------------
// --- Info retrieval functions
// --- -----------------------------------------------------------------------

function getDocumentHeight() {
	if (isOpera())
		return window.innerHeight;
	else if (isNetscape())
		return window.innerHeight;
	else
		return document.body.clientHeight;
}


function getDocumentWidth() {
	if (isOpera())
		return window.innerWidth;
	else if (isNetscape())
		return window.innerWidth;
	else
		return document.body.clientWidth;
}



function getDocumentFullHeight() {
	if (isNetscape4()) {
		return window.innerHeight + window.pageYOffset;
	} else {
// NOT IMPLEMENTED YET!
		return document.body.offsetHeight;
	}
}


function getDocumentFullWidth() {
	if (isNetscape4()) {
		return window.innerWidth + window.pageXOffset;
	} else {
// NOT IMPLEMENTED YET!
		return document.body.offsetWidth;
	}
}



function getScreenHeight() {
	return screen.height;
}


function getScreenWidth() {
	return screen.width;
}



function getScreenDepth() {
	return screen.colorDepth;
}



function getAbsoluteTop(elem) {
	var topPosition = 0;

	while (elem) {
		if (elem.tagName == 'BODY')
			break;
		topPosition += elem.offsetTop;
		elem = elem.offsetParent;
	}
	return topPosition;
}

function getAbsoluteLeft(elem) {
	var leftPosition = 0;

	while (elem) {
		if (elem.tagName == 'BODY')
			break;
		leftPosition += elem.offsetLeft;
		elem = elem.offsetParent;
	}
	return leftPosition;
}



function getElementWidth(oElement) {
	if (isNetscape() && (getBrowserVersion() < 6))
		return (DOMAvailable()) ? oElement.offsetWidth : oElement.document.width;
	else
		return oElement.clientWidth;
}

function getElementHeight(oElement) {
	if (isNetscape() && (getBrowserVersion() < 6)) {
		return (DOMAvailable()) ? oElement.offsetHeight : oElement.document.height;
	} else {
		return oElement.clientHeight;
	}
}



function getMouseX() {
	return _iMouseX;
}

function getMouseY() {
	return _iMouseY;
}



// --- -----------------------------------------------------------------------
// --- Document object functions
// --- -----------------------------------------------------------------------

function getElementByIdNew(sName) {
	if (DOMAvailable())
		return document.getElementById(sName);

	if (isExplorer4())
		return document.all[sName];

	if (isNetscape4())
		return document.layers[sName];

	return null;
}



function getStyle(sName) {
	if (isNetscape4())
		return getElementByIdNew(sName);
	else
		return getElementByIdNew(sName).style;
} 



// --- -----------------------------------------------------------------------
// --- Window popup functions
// --- -----------------------------------------------------------------------

function openPopupwindow(sUrl, sPrivData) {
	var iWidth = 350;
	var iHeight = 250;
	var sScroll, sResize, sStatus, sMenu, sToolbar = "no";

	if (sPrivData.length > 0) {
		var aPrivData = sPrivData.split(";");
		for (var i = 0; i < aPrivData.length; i++)
			switch (aPrivData[i].split(":")[0]) {
				case "width":		iWidth	= new Number(aPrivData[i].split(":")[1]); break;
				case "height":		iHeight	= new Number(aPrivData[i].split(":")[1]); break;
				case "scroll":		sScroll	= "yes"; break;
				case "resize":		sResize	= "yes"; break;
				case "status":		sStatus	= "yes"; break;
				case "menu":		sMenu		= "yes"; break;
				case "toolbar":	sToolbar	= "yes"; break;
			}
	}
	openPopupFull(sUrl, "", iWidth, iHeight, 16, 16, sScroll, sResize, sStatus, sMenu, sToolbar, "no")
}



function openPopupFull(popUrl, winName, width, height, top, left, scrollbars, resizable, status, menubar, toolbar, directories) {
	switch (id) {
		case "iepc":
			winWidth = (width + 16);
			break;
		case "iemac":
			winWidth = (width + 20);
			break;
		case "nspc":
			winWidth = (width + 4);
			break;
		case "nsmac":
			winWidth = (width + 4);
			break;
		default:
			winWidth = width;
	}

	winWidth		= "width=" + winWidth;
	winHeight		= "height=" + height;
	winTop			= "top=" + top;
	winLeft			= "left=" + left;
	winScrollbars	= (scrollbars == "yes") ? ",scrollbars=" + scrollbars : "";
	winResizable	= (resizable == "yes") ? ",resizable=" + resizable : "";
	winStatus		= (status == "yes") ? ",status=" + status : "";
	winMenubar		= (menubar == "yes") ? ",menubar=" + menubar : "";
	winToolbar		= (toolbar == "yes") ? ",toolbar=" + toolbar : "";
	winDirectories	= (directories == "yes") ? ",directories=" + directories : "";

	arguments = winWidth + "," + winHeight + "," + winTop + "," + winLeft + winScrollbars + winResizable + winStatus + winMenubar + winToolbar + winDirectories;

	window.open(popUrl,winName,arguments);
}


// --- -----------------------------------------------------------------------
// --- Cookie-related functions
// --- -----------------------------------------------------------------------

function getCookie(Name) {
	var search = Name + "=";

	if (document.cookie.length > 0) {
		// if there are any cookies
		offset = document.cookie.indexOf(search);

		if (offset != -1) {
			// if cookie exists
			offset += search.length;

			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);

			// set index of end of cookie value
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
}


function setCookie(sName, sValue) {
	document.cookie = "@" + sName + "=" + sValue;
}
