var dayArray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

function openWindow(url,name,width,height,resizable,scrollbars,statusbar,menubar,toolbar)
{
	var win = (window.name) ? eval(name) : null;
	var optionString = "";
	if (width) optionString += "width=" + width + ",";
	if (height) optionString += "height=" + height + ",";
	if (resizable) optionString += "resizable=" + resizable + ",";
	if (scrollbars) optionString += "scrollbars=" + scrollbars + ",";
	if (statusbar) optionString += "status=" + statusbar + ",";
	if (menubar) optionString += "menubar=" + menubar + ",";
	if (toolbar) optionString += "toolbar=" + toolbar + ",";
	win = window.open(url,name,optionString);
	win.focus();
}

function printPage()
{
	if (window.print) window.print();
	else alert("Please select \"Print...\" from the File menu.");
}

function openAcidTest()
{
	openWindow("AcidTest.aspx", "AcidTest", 750, 500, 0, 1, 0, 0, 0);
}

function openCompetition()
{
	if (window.opener && !window.opener.closed)
	{
		window.opener.location.href = "AcidTestCompetition.aspx";
		window.opener.focus();
	}
	else
	{
		newWin = window.open("AcidTestCompetition.aspx","newWin");
		newWin.focus();
	}
}

function clearForm(theForm)
{
	for (i=0; i<theForm.elements.length; i++)
	{
	//	alert(theForm.elements[i].type)
		switch (theForm.elements[i].type)
		{
			case "text" :
				theForm.elements[i].value = "";
				break;
			case "textarea" :
				theForm.elements[i].value = "";
				break;
			case "select-one" :
				theForm.elements[i].selectedIndex = 0;
				break;
			case "select-multiple" :
				for (j=0; j<theForm.elements[i].options.length; j++)
					theForm.elements[i].options[j].selected = false;
				break; 
			case "checkbox" :
				theForm.elements[i].checked = false;
				break;
			case "radio" :
				theForm.elements[i].checked = false;
				break;
		}
	}
}

function resetForm(theForm)
{
	theForm.reset();
}

function trim(theString)
{
	var newString = theString;
	while (newString.charAt(0) == " " || newString.charCodeAt(0) == 10 || newString.charCodeAt(0) == 13 || newString.charCodeAt(0) == 9) {
		newString = newString.substring(1,newString.length);
	}
	while (newString.charAt(newString.length - 1) == " " || newString.charCodeAt(newString.length - 1) == 10 || newString.charCodeAt(newString.length - 1) == 13 || newString.charCodeAt(newString.length - 1) == 9) {
		newString = newString.substring(0,newString.length - 1);
	}
	return newString;
}

function printVersion(url)
{
	openWindow(url, 'print', 640, 500, 0, 1, 0, 1, 0);
}

function showPointer(obj)
{
	if (document.all)
		obj.style.cursor = "hand";
	else
		obj.style.cursor = "pointer";
}

if (typeof Element != "undefined" && Element.prototype && document.createRange)
{
	Element.prototype.__defineGetter__(
		"innerText",
		function ()
		{
			var range = document.createRange();
			range.selectNodeContents(this);
			return range.toString();
		}
	);
	Element.prototype.__defineSetter__(
		"innerText",
		function (text)
		{
			var range = document.createRange();
			range.selectNodeContents(this);
			range.deleteContents();
			this.appendChild(document.createTextNode(text));
		}
	);
}

function getDateString(date)
{
	var date = new Date(Date.parse(date));
	if (isNaN(date)) return false;
	else
	{
		var year = (date.getYear() < 1900) ? date.getYear() + 1900 : date.getYear();
		return date.getDate() + " " + monthArray[date.getMonth()] + " " + year;
	}
}

// Given a 0-indexed month, returns the month name.
// If second parameter is suppled, truncates to the passed length. 
function getMonthName(month, numChars)
{
	var dpMonth = dpMonthNames[month].toString();
	if (numChars > 0) dpMonth = dpMonth.substr(0,numChars);
	return dpMonth;
}

// Returns a new Date representing the today's date.
function getTodaysDate(date)
{
	return new Date(date.getFullYear(), date.getMonth(), date.getDate());
}

// Returns a new Date representing the first day of the month of the passed Date.
function getFirstDayOfMonth(date)
{
	return new Date(date.getFullYear(), date.getMonth());
}

// Returns a new Date representing the first day of the previous month of the passed Date.
function getPreviousMonth(date)
{
	return getFirstDayOfMonth(new Date(date.getFullYear(), date.getMonth(), 0));
}

// Returns a new Date representing the first day of the next month of the passed Date.
function getNextMonth(date)
{
	return getFirstDayOfMonth(new Date(date.getFullYear(), date.getMonth(), 32));
}

// Returns the number of days in the month of the passed Date.
function getDaysInMonth(date)
{
	var dpDayCount = 0;
	var dpPrevDay = 0;
	for (var i=0; i<32; i++)
	{
		var dpTempDate = new Date(date.getFullYear(), date.getMonth(), i+1);
		if (dpTempDate.getDate() < dpPrevDay) break;
		dpDayCount++;
		dpPrevDay = i+1;
	}
	return dpDayCount;
}

handleHover = function()
{
	if (document.all && document.getElementById)
	{
		navRoot = document.getElementById("NavList");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName == "LI")
			{
				node.onmouseover = function()
				{
					this.className += "Hover";
				}
				node.onmouseout = function()
				{
					this.className = this.className.replace("Hover", "");
				}
			}
		}
	}
}
window.onload = handleHover;
