//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------
function Browser() {

	var ua, s, i;

	this.isIE    = false;  // Internet Explorer
	this.isOP    = false;  // Opera
	this.isNS    = false;  // Netscape
	this.version = null;
	this.hasDOM  = false;
	this.isGecko = false;
	this.isNS4   = false;
	this.isMac = (navigator.userAgent.indexOf('Mac') != -1) ? 1 : 0;
	ua = navigator.userAgent;

	s = "Opera";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isOP = true;
		this.version = parseFloat(ua.substr(i + s.length));
		this.hasDOM  = true;
		return;
	}
	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		this.hasDOM  = true;
		return;
	}
	// Treat any other "Gecko" browser as Netscape 6.1.
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.isGecko = true;
		this.version = 6.1;
		this.hasDOM  = true;
		return;
	}
	s = "MSIE";
	if ((i = ua.indexOf(s))) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		this.hasDOM  = true;
		this.isIEMac = (this.isMac) ? 1 : 0;
		return;
	}
	if (document.layers) {
		this.isNS4 = true;
		this.version = 4;
		this.hasDOM  = true;
		return;
	}
}

var browser = new Browser();

//----------------------------------------------------------------------------
// Code to determine dimensions.
//----------------------------------------------------------------------------
function GetWindowHeight() {
	if (browser.isIE) {
		maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
		  (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
	}
	if (browser.isOP) {
		maxY = document.documentElement.scrollTop  + window.innerHeight;
	}
	if (browser.isNS) {
		maxY = window.scrollY + window.innerHeight;
	}
	return maxY;
}

function GetWindowWidth() {
	if (browser.isIE) {
		maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
		  (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
	}
	if (browser.isOP) {
		maxX = document.documentElement.scrollLeft + window.innerWidth;
	}
	if (browser.isNS) {
		maxX = window.scrollX + window.innerWidth;
	}
	return maxX;
}

// textareas with width of 100% resize themselves on keypress
// unless pixelwidth specified
function FixTextAreaWidth() {
	var w;
	var aTAs = document.body.getElementsByTagName("TEXTAREA");
	for (var i = 0; i < aTAs.length; i++) {
		w = aTAs[i].offsetWidth;
		aTAs[i].style.width = w + "px";
	}
}


//----------------------------------------------------------------------------
// Code to determine positions.
//----------------------------------------------------------------------------
function getPageOffsetLeft(el) {

	var x;

	// Return the x coordinate of an element relative to the page.
	x = el.offsetLeft;
	if (el.offsetParent != null)
		x += getPageOffsetLeft(el.offsetParent);
	
	return x;
}

function getPageOffsetTop(el) {

	var y;

	// Return the y coordinate of an element relative to the page.
	y = el.offsetTop;
	if (el.offsetParent != null)
		y += getPageOffsetTop(el.offsetParent);
	
	return y;
}

//----------------------------------------------------------------------------
// Date and time functions
//----------------------------------------------------------------------------

function GetDayOfWeek(nday) {
	var aDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	return aDays[nday];
}

function GetMonthName(nMon) {
	var aMons = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September");
	aMons = aMons.concat("October", "November", "December");
	return aMons[nMon];
}

// Utility function to stop the event from cascading
function endEvent(event) {
	// Stop the event from bubbling to menuMouseover.
	if (browser.isIE)
		window.event.cancelBubble = true;
	else
		event.stopPropagation();
}

//----------------------------------------------------------------------------
function SubmitJob(sjob) {
	document.forms[0].job.value = sjob;
	document.forms[0].submit();
}

//----------------------------------------------------------------------------
function assignHandler(oObject, sEvent, ptrFunction) {
	if (oObject.addEventListener) {
		oObject.addEventListener(sEvent, ptrFunction, true);
		return true;
	}
	else if (oObject.attachEvent) {
		sEvent = "on" + sEvent;
		return oObject.attachEvent(sEvent, ptrFunction);
	}
	else
		return false;
}
