//***********************************************************************
//*	Dynamic Drop Down Menu Generation System	V 0.9b					*
//*		setTopMenu() :	generates top menu items						*
//*		setSubMenu() :	generates drop down menus						*
//*		drawMenu() :	renders and initializes menu system				*
//*			If you have an empty menu system call setSubMenu with		*
//*			the	menuText and href properties set to ''					*
//*			The menu system assumes at least one call to setSubMenu per	*
//*			call to setTopMenu											*
//*																		*
//* Syntax :															*
//*		setTopMenu(topMenuID,menuText,toolTip,href)						*
//*		setSubMenu(dropMenuID,menuText,href)							*
//*		drawMenu()														*
//*																		*
//* Created By : James Zimmerman										*
//*	01/18/2000															*
//***********************************************************************

var initialized = 0;
var	navTitleStr;				//Holds the top table

var navMenuTopStartStr;			//Holds the start of top menu items table
var navMenuTopTemplate;			//Holds the top menu items template
var navMenuTopEndStr;			//Holds the end of top menu items table

var navMenuItemsStartStr;		//Holds the start of top nav drop down tables
var navMenuItemsTemplate;		//Holds the top nav items template
var navMenuItemsEndStr;			//Holds the end of top nav drop down tables

var menuLength = 0;				//Holds the number of top menus
var arrayTopMenuData = new Array; //Array holding top menu data

var arrayDropDownData = new Array; //Array holding all drop menu data

var i = 0;						//Pointer holder
var dropDownLength = 0;			//Holds the number of drop items
var dropMenuOffsetHeight = 26;  //Default value for offsetHeight when no logo is shown. 

var dropMenus = new Array();	//Holds the objects for the drop menus
var menuTops = new Array();		//Holds the objects for the menu tops 
var menuStatus = new Array();	//Holds the status of the menus

//build the title table and store it
//navTitleStr = '<TABLE BORDER=0 BACKGROUND=http://meathead/images/nav/bg.gif class=navTitle onMouseOver=komenu()><TR>';
//navTitleStr = navTitleStr + '<TD CLASS=navTitleItem><NOBR><A HREF="/asp/menuMain.asp" STYLE="color: #ffffff;">Realcomp II Ltd. Realcomp Online</A></NOBR></TD>';
//navTitleStr = navTitleStr + '<TD CLASS=navTitleItem><A class=afus HREF="javascript:showModalDialog(' + "'announcementPopup.asp','','center=yes;dialogWidth=510pt;dialogHeight=300pt');" + '"' + ' title="Read Today' + "'" + "s Notes" + '"><center><NOBR> ' + GetDate()[0] + ' </NOBR></center></A></TD>';
//navTitleStr = navTitleStr + '<TD ALIGN="right" CLASS=navTitleItem><A class=afus HREF="javascript:helpopen();">&nbsp;Help&nbsp;&nbsp;&nbsp;&nbsp;</A></TD>';
//navTitleStr = navTitleStr + '</TR></TABLE>';
//navTitleStr = navTitleStr + '<TABLE CELLSPACING=0 CELLPADDING=0 WIDTH="100%" BGCOLOR="#AAAAAA" BORDER="0" BACKGROUND="../images/navtop.gif" HEIGHT="2"><TR><TD></TD></TR></TABLE>';

//build the nav table templates
navMenuTopStartStr = '<TABLE CELLSPACING=0 CELLPADDING=0 WIDTH="100%" BGCOLOR="#AAAAAA" BORDER="0"><TR>';
navMenuTopTemplate = '<TD ID="<!-- id name -->" CLASS="navOff" WIDTH="<!-- width -->%" STYLE="cursor: <!-- cursor -->" TITLE="<!-- title -->" onMouseOver="show(<!-- menu number -->);" onClick="<!-- on click -->"><!-- insert data --></TD>';
navMenuTopEndStr = '</TR></TABLE><TABLE CELLSPACING=0 CELLPADDING=0 WIDTH="100%" BGCOLOR="#AAAAAA" BORDER="0" BACKGROUND="../images/navbottom.gif" HEIGHT="2"><TR><TD></TD></TR></TABLE>'

//build the nav dropdown table templates
navMenuItemsStartStr = '<DIV ID="<!-- id name -->" CLASS="dropMenu" STYLE="display : <!-- display -->;POSITION: absolute; VISIBILITY: hidden;Z-INDEX: 10"><TABLE BORDER=0 WIDTH="100%" CELLPADDING=0 CELLSPACING=0><TR><TD><TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=0 CLASS="menu">';
navMenuItemsTemplate = '<TR><TD CLASS="menuOff" onMouseover="this.className = ' + "'menuOn';" + '" onMouseout="this.className = ' + "'menuOff';" + '" TITLE="<!-- title -->" onClick="<!-- href -->"><!-- insert data --></TD></TR>';
navMenuItemsEndStr = '</TABLE></TD></TR></TABLE></DIV>';


//**************************************   CROSS BROWSER SCRIPTS   ************************************************************************

var detect = navigator.userAgent.toLowerCase();
var OS,varPlatform,browser,version,total,thestring;
var varBrowser ,cookieBrowserVal;
OS = navigator.appVersion ;
GetBrowserType();
GetPlatform();

//********************************************************************************************************************
function GetBrowserType(){    
    if (checkIt('safari')) varBrowser = "Safari"
    else if (checkIt('omniweb')) varBrowser = "OmniWeb"
    else if (checkIt('opera')) varBrowser = "Opera"
    else if (checkIt('webtv')) varBrowser = "WebTV";
    else if (checkIt('icab')) varBrowser = "iCab"
    else if (checkIt('msie')) varBrowser = "IE"
    else if (checkIt('mozilla')) varBrowser = "mozilla"
    else if (!checkIt('compatible'))
    {
	    browser = "Netscape Navigator"
	    version = detect.charAt(8);
    }
    else varBrowser = "An unknown browser";

    if (!version) version = detect.charAt(place + thestring.length);
     
}

function GetPlatform(){    
    if (checkOS('Mac')) varPlatform = "Mac"
    else if (checkOS('Windows')) varPlatform = "Windows"    
    else varPlatform = "An unknown Platform";     
}
        
function checkOS(string) {
	place = OS.indexOf(string) + 1;
	thestring = string;
	return place;
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
//*******************************************************************************************************************


//*******************************************************************************************************************

// 0-January 1st, 2000 1- 13:00:00 2- 1:00 PM 3-Wednesday 4-January 5-1 6-1st, 7-2000 8-1/1/2000 9-Wed Jan 1 13:00:00 PST 2000
function GetDate(vdate) {
	var arrDaysOfTheWeek = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
	var arrMonthsOfTheYear = new Array('January', 'February ', 'March', 'April', 'May', 'June',
					   'July', 'August', 'September', 'October', 'November', 'December')
//dtmNow - Wed Jan 1 13:00:00 PST 2000
  var dtmNow = (vdate) ? new Date(vdate) : new Date;
  var arDate = new Array();
  arDate[1] = dtmNow.getHours() + ':' + dtmNow.getMinutes() + ':' + dtmNow.getSeconds();
  arDate[2] = ((dtmNow.getHours()<=12) ? ((dtmNow.getHours()==0) ? '12' : dtmNow.getHours()) : dtmNow.getHours() - 12) + ':' + ((dtmNow.getMinutes()<10) ? '0' + dtmNow.getMinutes() : dtmNow.getMinutes()) + ((dtmNow.getHours()<12) ? ' AM' : ' PM'); 
  arDate[3] = arrDaysOfTheWeek[dtmNow.getDay()];
  arDate[4] = arrMonthsOfTheYear[dtmNow.getMonth()]; 
  arDate[5] = dtmNow.getDate()
  switch (dtmNow.getDate()) {
	case 1:
	case 21:
	case 31:
	  arDate[6] = dtmNow.getDate() + 'st, ';
	  break;
	case 2:
	case 22:
	  arDate[6] =  dtmNow.getDate() + 'nd, ';
	  break;
	case 3:
	case 23:
	  arDate[6] = dtmNow.getDate() + 'rd, ';
	  break;
	default:
	  arDate[6] = dtmNow.getDate() + 'th, ';
  }
  arDate[7] = dtmNow.getFullYear();
  arDate[8] = dtmNow.getMonth() + 1 + '/' + dtmNow.getDate() + '/' + (dtmNow.getYear() < 1000 ? 1900+dtmNow.getYear() : dtmNow.getYear())
  arDate[9] = dtmNow;
  arDate[0] = arDate[4] + ' ' + arDate[6] + ' ' + arDate[7];
  return(arDate);
}


function buildDate() {
  var dtmNow = new Date;
  var strToday;
  switch (dtmNow.getMonth()) {
	case 0:
	  strToday = 'January ';
	  break;
	case 1:
	  strToday = 'Febuary ';
	  break;
	case 2:
	  strTody = 'March ';
	  break;
	case 3:
	  strToday = 'April ';
	  break;
	case 4:
	  strToday = 'May ';
	  break;
	case 5:
	  strToday = 'June ';
	  break;
	case 6:
	  strToday = 'July ';
	  break;
	case 7:
	  strToday = 'August ';
	  break;
	case 8:
	  strToday = 'September ';
	  break;
	case 9:
	  strToday = 'October ';
	  break;
	case 10:
	  strToday = 'November ';
	  break;
	case 11:
	  strToday = 'December ';
	  break;
  }
  switch (dtmNow.getDate()) {
	case 1:
	case 21:
	case 31:
	  strToday = strToday + dtmNow.getDate() + 'st, ';
	  break;
	case 2:
	case 22:
	  strToday = strToday + dtmNow.getDate() + 'nd, ';
	  break;
	case 3:
	case 23:
	  strToday = strToday + dtmNow.getDate() + 'rd, ';
	  break;
	default:
	  strToday = strToday + dtmNow.getDate() + 'th, ';
  }
  strToday = strToday + dtmNow.getFullYear();
  return(strToday);
}
function setTopMenu(menuID,menuText,menuTitle,href) {
  arrayTopMenuData[menuLength] = new Array();
  arrayTopMenuData[menuLength][0] = menuID;
  arrayTopMenuData[menuLength][1] = menuText;
  arrayTopMenuData[menuLength][2] = (href.indexOf("|") > -1) ? href.split("|")[1] : "";
  if (href.split("|")[0] != '') {
	arrayTopMenuData[menuLength][3] = 'hand';
  }
  else {
	arrayTopMenuData[menuLength][3] = 'default'
  }
  arrayTopMenuData[menuLength][4] = href.split("|")[0];  
  menuLength = menuLength + 1;
}

function setSubMenu(menuID,menuText,href) {
  arrayDropDownData[dropDownLength] = new Array();
  arrayDropDownData[dropDownLength][0] = menuID;
  arrayDropDownData[dropDownLength][1] = menuText;
  if (menuText == '') {
	arrayDropDownData[dropDownLength][2] = 'none';
  }
  else {
	arrayDropDownData[dropDownLength][2] = 'inline';
  }
  arrayDropDownData[dropDownLength][3] = href.split("|")[0];
  arrayDropDownData[dropDownLength][4] = (href.indexOf("|") > -1) ? href.split("|")[1] : "";
  dropDownLength = dropDownLength + 1;
}

function buildTopMenuItems(menuID,menuText,cursor,tdTitle,menuNumber,href) {
  width = 100 / menuLength;
  tempStr = navMenuTopTemplate.replace('<!-- id name -->',menuID);
  tempStr = tempStr.replace('<!-- insert data -->',menuText);
  tempStr = tempStr.replace('<!-- width -->',width);
  tempStr = tempStr.replace('<!-- cursor -->',"hand");
  tempStr = tempStr.replace('<!-- title -->',tdTitle);
  tempStr = tempStr.replace('<!-- menu number -->',menuNumber);
  if (href.length > 0) {
	  if (href.substring(0,1) == "^") {
		href = href.substring(1, href.length);
		href = "window.open('" + href + "','', '')";
	  } else {
		href = 'top.location.href=' + "'" + href + "'"
	  }
	  tempStr = tempStr.replace('<!-- on click -->',href);
  }
  else {
	tempStr = tempStr.replace('<!-- on click -->','');
  }
  return(tempStr);
}

function buildNavMenuItems(menuText,href,title) {
  if (href.substring(0,1) == "^") {
	href = href.substring(1, href.length);
	href = "window.open('" + href + "','', '')";
  } else {
	href = 'top.location.href=' + "'" + href + "'"
  }
  tempStr = navMenuItemsTemplate.replace('<!-- insert data -->',menuText);
  tempStr = tempStr.replace('<!-- href -->',href);
  tempStr = tempStr.replace('<!-- title -->',title);
  return(tempStr);
}

function drawMenu() {
  HTMLWrite = navMenuTopStartStr;
  for (i = 0; i < menuLength; i++) {
	HTMLWrite = HTMLWrite + buildTopMenuItems(arrayTopMenuData[i][0],arrayTopMenuData[i][1],arrayTopMenuData[i][3],arrayTopMenuData[i][2],i,arrayTopMenuData[i][4]);
  }
  HTMLWrite = HTMLWrite + navMenuTopEndStr;
  document.write(HTMLWrite);
  strTemp = navMenuItemsStartStr.replace('<!-- id name -->',arrayDropDownData[0][0]);
  strTemp = strTemp.replace('<!-- display -->',arrayDropDownData[0][2]);
  HTMLWrite = strTemp.replace('<!-- display -->',arrayDropDownData[0][2]);
  for (i = 0; i < dropDownLength; i++) {	//Checks to see if it is @ the end of drop menu array
	if (i != dropDownLength - 1) {
	  if (arrayDropDownData[i][0] == arrayDropDownData[i + 1][0]) {
		strTemp = buildNavMenuItems(arrayDropDownData[i][1],arrayDropDownData[i][3],arrayDropDownData[i][4]);
	  } else {
		strTemp = buildNavMenuItems(arrayDropDownData[i][1],arrayDropDownData[i][3],arrayDropDownData[i][4]);
		strTemp = strTemp + navMenuItemsEndStr + '\n';
		strTemp = strTemp + (navMenuItemsStartStr.replace('<!-- id name -->',arrayDropDownData[i + 1][0])).replace('<!-- display -->',arrayDropDownData[i + 1][2]);
		//strTemp = strTemp + strTemp2.replace('<!-- display -->',arrayDropDownData[i + 1][2]);
	  }
	} else {
	  strTemp = buildNavMenuItems(arrayDropDownData[i][1],arrayDropDownData[i][3],arrayDropDownData[i][4]);
	  strTemp = strTemp + navMenuItemsEndStr;
	}
	HTMLWrite = HTMLWrite + strTemp;
  }
  document.write(HTMLWrite);

  i = 0;
  initMenu();
}

// initializes the menu system
function initMenu() {
  for (i = 0; i < menuLength; i++) {
	menuTops[i] = document.all[arrayTopMenuData[i][0]];
	menuStatus[i] = 'closed';
  }

  var pointer = 0;

  for (i =0; i < dropDownLength; i++) {
	if (i != dropDownLength - 1) {
	  if (arrayDropDownData[i][0] != arrayDropDownData[i + 1][0]) {
		dropMenus[pointer] = document.all[arrayDropDownData[i][0]];
		pointer = pointer + 1;
	  }
	}
	else {
	  if (arrayDropDownData[i][0] == arrayDropDownData[i - 1][0]) {
		dropMenus[pointer] = document.all[arrayDropDownData[i][0]];
	  }
	}
  }

  initialized = 1;
}

// Sets the selected menu to visible
function show(menuNumber) {
  elem = menuTops[menuNumber];
  var dropMenuHeight = 0;

  // This resets the variable for when the logo section is to be shown.	
  if (typeof(Logo) == 'string' && Logo == "True") dropMenuOffsetHeight = 50;
  
  if (initialized == 1) {
    komenu();
	menuTops[menuNumber].className = 'navOn';
	dropMenus[menuNumber].style.width = 135; // window.event.srcElement.offsetWidth + 2;
	//dropMenus[menuNumber].style.pixelLeft = (elem.offsetLeft - 1 + 135 < ((document.body.clientWidth * 1 > 0) ? document.body.clientWidth  : window.innerWidth)) ? elem.offsetLeft : ((document.body.clientWidth * 1 > 0) ? document.body.clientWidth  : window.innerWidth-15) - 135;
	dropMenus[menuNumber].style.left = (elem.offsetLeft - 1 + 135 < ((document.body.clientWidth * 1 > 0) ? document.body.clientWidth  : window.innerWidth)) ? elem.offsetLeft : ((document.body.clientWidth * 1 > 0) ? document.body.clientWidth  : window.innerWidth-15) - 135;
	dropMenus[menuNumber].style.pixelTop = elem.offsetHeight + dropMenuOffsetHeight -1;
	//**************************** BEGIN cross browser scripts ******************************************
	//Drop down menus position doesn't work properly in Safari compared to other browsers. The code below fixes it.
	if (varPlatform == "Mac") {
	    if (!( menuNumber==7 || menuNumber == 9)) {	     //if parent menu item spans into 2 lines, the dropdown position is not correct.
	        dropMenus[menuNumber].style.pixelTop = elem.offsetHeight + dropMenuOffsetHeight + 11;	
	    }
    }
    //**************************** END cross browser scripts ******************************************
	dropMenus[menuNumber].style.visibility = 'visible';
	menuStatus[menuNumber] = 'open';
	if (dropMenus[menuNumber].innerHTML.match(/class=menuOff/gi) && dropMenus[menuNumber].innerHTML.match(/class=menuOff/gi).length > 1) dropMenuHeight = elem.offsetHeight + dropMenuOffsetHeight + (dropMenus[menuNumber].innerHTML.match(/class=menuOff/gi).length*20);
	hideElement("SELECT", dropMenus[menuNumber].style.pixelLeft, dropMenus[menuNumber].style.pixelLeft+135, dropMenuHeight, dropMenuOffsetHeight)
	hideElement("IFRAME", dropMenus[menuNumber].style.pixelLeft, dropMenus[menuNumber].style.pixelLeft+135, dropMenuHeight, dropMenuOffsetHeight)
	hideElement("APPLET", dropMenus[menuNumber].style.pixelLeft, dropMenus[menuNumber].style.pixelLeft+135, dropMenuHeight, dropMenuOffsetHeight)
  }
}

// KO's all menus
function komenu() {
	for (i=0; i < menuTops.length; i++) {
		if (menuStatus[i] == 'open') {
			menuTops[i].className = 'navOff';
			dropMenus[i].style.visibility = 'hidden';
			menuStatus[i] = 'closed';
		}
	}
	showElement("SELECT")
	showElement("IFRAME")
	showElement("APPLET")
}

function hideElement(elmName, x, x1, y, y1) {
	arrElements = (document.all.tags) ? document.all.tags(elmName) : document.getElementsByTagName(elmName);	//Holds the objects for the select tags
	for (i = 0; i < arrElements.length; i++)	{
		obj = arrElements[i];
		if (! obj || ! obj.offsetParent) continue;

		// Find the element's offsetTop and offsetLeft relative to the BODY tag.
		objLeft   = obj.offsetLeft;
		objTop    = obj.offsetTop;
		objParent = obj.offsetParent;
		while (objParent.tagName.toUpperCase() != "BODY") {
			objLeft  += objParent.offsetLeft;
			objTop   += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}
		// Adjust the element's offsetTop relative to the dropdown menu
		objTop = objTop - y1;

		if (x > (objLeft + obj.offsetWidth) || objLeft > (x + y));
		else if (objTop > y);
		else if ((y1 + y) <= 80);
		else obj.style.visibility = "hidden";
	}
}

function showElement(elmID) {
	arrElements = (document.all.tags) ? document.all.tags(elmID) : document.getElementsByTagName(elmID);	//Holds the objects for the select tags
	for (i = 0; i < arrElements.length; i++) {
		obj = arrElements[i];
		if (! obj || ! obj.offsetParent) continue;
		obj.style.visibility = "";
	}
}

function getAllCollection() {
	if (typeof(document.getElementsByTagName) == "function" && document.getElementsByTagName("*")) {
	   document.all = document.getElementsByTagName("*") 
	} 
}
if (!document.all) getAllCollection();
