/////////////////////////////////////////////
// common.js
//
// This file provides JavaScript functions
// common to all GUHSD portal page skins
//
// Revised: 2/22/2008 by J Tisserat
/////////////////////////////////////////////

/////////////////////////////////////
// function to return current date //
/////////////////////////////////////

function currentDate() {
	var now = new Date();
	var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
	function fourdigits(number) {
		return (number < 1000) ? number + 1900 : number;}
	today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear()));
  return today;
}


/////////////////////////////////////////////////
// functions to render menus in OraclAS Portal //
/////////////////////////////////////////////////

menuItem = new Array();
menuCounter = 1;

function menuStart(newName) {
	menuItem.push("~S~"+newName);  // push start-of-menu token into array
}

function menuAddItem(newLabel,newUrl) {
	menuItem.push(newLabel); // push URL label into array
	menuItem.push(newUrl);   // push URL into array
}

function menuEnd(newName) {
	menuItem.push("~E~"); // push end-of-menu token into array
}

function menuRender(name) {
	renderMenu = 0;
	// traverse array
	for (i=0;i<menuItem.length;i++) {
		// check for start of menu token
		if (menuItem[i].substring(0,3)=="~S~" && menuItem[i].substring(3,menuItem[i].length)==name) {
			renderMenu=1;
			document.write("<div id='nav"+menuCounter+"'>");
			menuCounter++;
			document.write(" <ul>");
			//document.write(" <ul id='nav"+menuCounter+"'>");
			document.write(" <li>"+menuItem[i].substring(3,menuItem[i].length));
			document.write(" <ul>");
		}
		// check for end of menu token
		else if (menuItem[i].substring(0,3)=="~E~") {
			document.write(" </ul>");
			document.write(" </li>");
			document.write(" </ul>");
			document.write("</div>");
			renderMenu=0;
		}
		// if rendering then render item in current menu
		else if (renderMenu==1) {
			document.write("    <li><a href='"+menuItem[i+1]+"'>"+menuItem[i]+"</a></li>");
			i++;
		}
	}
}


function menuRenderPlain(name) {
	renderMenu = 0;
	// traverse array
	for (i=0;i<menuItem.length;i++) {
		// check for start of menu token
		if (menuItem[i].substring(0,3)=="~S~" && menuItem[i].substring(3,menuItem[i].length)==name) {
			renderMenu=1;
			document.write("<div id='navPlainMenu'>");
			menuCounter++;
			document.write(" <ul>");
			document.write(" <li>"+menuItem[i].substring(3,menuItem[i].length));
			document.write(" <ul>");
		}
		// check for end of menu token
		else if (menuItem[i].substring(0,3)=="~E~") {
			document.write(" </ul>");
			document.write(" </li>");
			document.write(" </ul>");
			document.write("</div>");
			renderMenu=0;
		}
		// if rendering then render item in current menu
		else if (renderMenu==1) {
			document.write("    <li><a href='"+menuItem[i+1]+"'>"+menuItem[i]+"</a></li>");
			i++;
		}
	}
}

/////////////////////////////////////
// functions to handle hover in IE //
/////////////////////////////////////


sfHover = function() {

	var sfEls = document.getElementById("nav1").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}

	var sfEls = document.getElementById("nav2").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}

	var sfEls = document.getElementById("nav3").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

