

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() < 6));
}

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
	}
}



// --- -----------------------------------------------------------------------
// --- Netscape compatible mouse location reader
// --- 
// --- Use getMouseX() and getMouseY() to retrieve coordinates.
// --- -----------------------------------------------------------------------

var iNSMouseX, iNSMouseY = 0;

if (isNetscape()) {
	document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getNSMouseLoc;

	function getNSMouseLoc(e) {
		iNSMouseX = e.pageX;
		iNSMouseY = e.pageY;
	}
}



// --- -----------------------------------------------------------------------
// --- Info retrieval functions
// --- -----------------------------------------------------------------------

function getDocumentHeight() {
	if (isNetscape())
		return window.innerHeight;
	else
		return document.body.clientHeight;
}


function getDocumentWidth() {
	if (isNetscape())
		return window.innerWidth;
	else
		return document.body.clientWidth;
}



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() {
	if (isNetscape())
		return iNSMouseX;
	else
		return event.x + document.body.scrollLeft;
}

function getMouseY() {
	if (isNetscape())
		return iNSMouseY;
	else
		return event.y + document.body.scrollTop;
}



// --- -----------------------------------------------------------------------
// --- Document object functions
// --- -----------------------------------------------------------------------

function getElementByIdNew(sName) {
	if (DOMAvailable())
		return document.getElementById(sName);

	if (isExplorer4())
		return document.all[sName];

	if (isNetscape())
		return document.layers[sName];

	return null;
}



function getStyle(sName) {
	if (isNetscape())
		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";
				case "resize":	sResize		= "yes";
				case "status":	sStatus		= "yes";
				case "menu":	sMenu		= "yes";
				case "toolbar":	sToolbar	= "yes";
			}
	}
	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=" + scrollbars;
	winResizable	= "resizable=" + resizable;
	winStatus		= "status=" + status;
	winMenubar		= "menubar=" + menubar;
	winToolbar		= "toolbar=" + toolbar;
	winDirectories	= "directories=" + directories;

	arguments = winWidth + "," + winHeight + "," + winTop + "," + winLeft + "," + winScrollbars + "," + winResizable + "," + winStatus + "," + winMenubar + "," + winToolbar + "," + winDirectories;

	window.open(popUrl,winName,arguments);
}

