// JavaScript Document

/****************************** BEGIN: JAVASCRIPT FOR HEADER & FOOTER ******************************/
//IMAGES
stainedGlassTop1 = new Image();
stainedGlassTop1.src = "/images/stainedGlassTop1.jpg";
stainedGlassBottom1 = new Image();
stainedGlassBottom1.src = "/images/stainedGlassBottom1.jpg";

stainedGlassTop2 = new Image();
stainedGlassTop2.src = "/images/stainedGlassTop2.jpg";
stainedGlassBottom2 = new Image();
stainedGlassBottom2.src = "/images/stainedGlassBottom2.jpg";

stainedGlassTop3 = new Image();
stainedGlassTop3.src = "/images/stainedGlassTop3.jpg";
stainedGlassBottom3 = new Image();
stainedGlassBottom3.src = "/images/stainedGlassBottom3.jpg";

//FUNCTIONS
//--------------------------------------------------------------------
//Display a random set of pics for the header and footer images
function displayStainedGlass(){
	var randNum = Math.floor(Math.random()*3);  //Gets a random integer between 0 and 2
	randNum = randNum + 1;  //Add one so that it's between 1 and 3
	
	//Header
	var headerImage = document.getElementById("headerImg");
	if (randNum == 1) {
		headerImage.src = stainedGlassTop1.src;
	} else if (randNum == 2) {
		headerImage.src = stainedGlassTop2.src;
	} else {
		headerImage.src = stainedGlassTop3.src;
	}
	
	//Footer
	var footerImage = document.getElementById("footerImg");
	if(null != footerImage){
		if (randNum == 1) {
			footerImage.src = stainedGlassBottom1.src;
		} else if (randNum == 2) {
			footerImage.src = stainedGlassBottom2.src;
		} else {
			footerImage.src = stainedGlassBottom3.src;
		}
	}
}

/******************************* END: JAVASCRIPT FOR HEADER & FOOTER *******************************/

/****************************** BEGIN: JAVASCRIPT FOR LEFT MENU ******************************/

//IMAGES
//Image objects used to make the arrow point to the right or downward
imageA = new Image();
imageA.src = "/images/arrow-black.gif";	  //Could be changed to "../images/arrow-white.gif"
imageB = new Image();
imageB.src = "/images/arrow-black-down.gif";  //Could be changed to "../images/arrow-white-down.gif"

//VARIABLES
//Set the selected left menu item
var selectedMenuItem;

//FUNCTIONS
//--------------------------------------------------------------------
//Display the appropriate submenu for the menu item that was clicked
function showSubmenu(div){  //Takes in the id of the menu item that was clicked
	var submenu = div + "Sub";
	var baseClass = document.getElementById(div).className.slice(0,1);
	var allParents = document.getElementById("leftMenu").getElementsByTagName("div");
	var allSiblings = document.getElementById("leftMenu").getElementsByTagName("span");

  <!--If the submenu IS NOT expanded...-->
	if(document.getElementById(submenu).style.display != "inline"){

    <!--Collapse all other Parent submenus, then...-->
		if (document.getElementById(div).className.slice(0,1) == "p"){  //If a parent or top-level menu item was clicked...
			for (var i = 0; i < allParents.length; i++){ //Loop through all the items in the menu and do the following to each...
				var menuItemImage = allParents[i].id + "I";  //Get the image id
				if (document.images[menuItemImage] != null && document.images[menuItemImage].src == imageB.src)  //If the image is present and the arrow is pointing down...
					getImage(menuItemImage, "false");  //Make the arrow point to the right
			}
			for (var i = 0; i < allSiblings.length; i++){ //Loop through all the children groups in the menu and do the following to each...
				if (allSiblings[i].className == "submenu")  //If the menu item contains a submenu, collapse it
					allSiblings[i].style.display = "none";
			}
		}
		for (var i = 0; i < allParents.length; i++){ //Loop through all the items in the menu
			var menuItemBaseClass = allParents[i].className.slice(0,1);  //Get the class of the menu item
			if (allParents[i].className == menuItemBaseClass + "-chosen")  //If the item was previously chosen...
				allParents[i].className = menuItemBaseClass;  //Return the item to the normal state (base class)
		}

    <!--Expand this submenu.-->
		document.getElementById(div).className = (baseClass + "-chosen");  //Put the menu item in the chosen state
		var tdImage = div + "I";  //Get the image id of the chosen menu item
		getImage(tdImage, "true");  //Make the arrow point down
		document.getElementById(submenu).style.display = "inline"; //Expand the appropriate submenu
	
  <!--If the submenu IS expanded...-->
    }else{
  
    <!--Collapse all other Parent submenus, then...-->
		if (document.getElementById(div).title == "Parent"){  //If a parent or top-level menu item was clicked...
			for (var j = 0; j < allParents.length; j++){ //Loop through all the items in the menu and do the following to each...
				var menuItemImage = allParents[j].id + "I";  //Get the image id
				if (document.images[menuItemImage] != null && document.images[menuItemImage].src == imageB.src)  //If the image is present and the arrow is pointing down...
					getImage(menuItemImage, "false");  //Make the arrow point to the right
				//if (allParents[j].className == "submenu")  //If the menu item contains a submenu, collapse it
					//allParents[j].style.display = "none";
			}
		}
		
    <!--Collapse it.-->
		document.getElementById(div).className = (baseClass + "-hover");  //Return the menu item to the normal (hover) state
		var tdImage = div + "I";  //Get the image id of the chosen menu item
		getImage(tdImage, "false");  //Make the arrow point to the right
		document.getElementById(submenu).style.display = "none";  //Collapse the appropriate submenu
	}
	
  <!--Set the selected menu item.-->
	selectedMenuItem = div;
	
}
//--------------------------------------------------------------------
//Point the arrow in the appropriate direction
function getImage(imageID, expanded) {

	if (expanded == "true"){  //If the submenu has been expanded
		document.images[imageID].src = imageB.src;  //Change the arrow to point down
	}else{  //If the submenu has been collapsed
		document.images[imageID].src = imageA.src;  //Change the arrow to point to the right
	}
}
//--------------------------------------------------------------------
//Follow links in table cells...This is done so that Google can crawl the link AND javascript can be called
function followLink(div) {
	var linkID = div + "L";
	var baseClass = document.getElementById(div).className.slice(0,1);
	var menuRows = document.getElementById("leftMenu").getElementsByTagName("div");
	//var linkPrefix = document.getElementById(linkID).href.slice(0,13);
	//var first4 = document.getElementById(linkID).href.slice(0,4);
	
	window.location = document.getElementById(linkID).href;
	
	/*selectedMenuItem = div;  //Sets the selectedMenuItem variable to the menu item that was clicked
	
	if (document.getElementById(cell).name == "Parent"){  //If a parent or top-level cell was clicked...
		for (var i = 0; i < menuRows.length; i++){ //Loop through all the rows in the menu
				
			var menuRowCells = menuRows[i].cells;
			var otherBaseClass = menuRowCells[0].className.slice(0,1);
				
			menuRowCells[0].className = otherBaseClass;  //Return the cell to the normal state
			var menuItemImage = menuRowCells[0].id + "I";
		
			if (menuRowCells[0].className != "" && document.images[menuItemImage].src == imageB.src)  //If the cell is not a spacer and the arrow is pointing down...
				getImage(menuItemImage, "false");  //Make the arrow point to the right
				
			if (menuRows[i].className == "submenu")  //If the row contains a submenu, collapse it
				menuRows[i].style.display = "none";
			
		}
	}else{
		for (var i = 0; i < menuRows.length; i++){ //Loop through all the rows in the menu
				
			var menuRowCells = menuRows[i].cells;
			var otherBaseClass = menuRowCells[0].className.slice(0,1);
				
			menuRowCells[0].className = otherBaseClass;  //Return the cell to the normal state
		}
	}
	
	//Set the menu item that was clicked to the chosen state
	document.getElementById(cell).className = baseClass + "-chosen";
	
	if (first4 == "http"){
		
		//Only append the expanded table row id's if the page is within the intranet.huntington.com domain
		if (linkPrefix == "http://wwwdev" || linkPrefix == "http://intran"){  //If the url appears to go to a static page on intranet.huntington.com (Dev or Prod)...
			//Go to the new page and highlight the menu item that was clicked on and expand all appropriate menus.
			window.location = document.getElementById(linkID).href + "?selected=" + selectedMenuItem + collectExpanded();
		}else{  //If the url appears to go outside of this site...
			//Go to the new page.
			window.location = document.getElementById(linkID).href;
		}
		
	}else{ 
		window.location = document.getElementById(linkID).href + "?selected=" + collectExpanded();
	}*/
	
}
//--------------------------------------------------------------------
//Limit the input in a textarea to the maxlength of the textarea so the user can see what will be input
function ismaxlength(obj) {
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}
//--------------------------------------------------------------------
//Collect the submenus that are expanded when going from page to page and return them
function collectExpanded() {
	var menuRows = document.getElementById("leftMenu").getElementsByTagName("tr");
	var URLappend = "";
	
	for (var i = 0; i < menuRows.length; i++){  //Loop through all the rows in the menu
	
		if (menuRows[i].className == "submenu" && menuRows[i].style.display == "inline")  //If the rows contains a submenu and the submenu has been displayed...
			URLappend += menuRows[i].id + ",";  //Add the id of the submenu row to the string
	}
	
	URLappend = URLappend.slice(0, (URLappend.length - 1));  //Remove the comma after the last element in the string

	if (URLappend.length > 0){
		return "&expanded=" + URLappend;  //Return the string
	}else{
		return "";
	}
	
}
//--------------------------------------------------------------------
//When the page loads, expand the submenus that were passed through the URL
function expandMenus() {

	//Resize the body so that it takes up AT LEAST the full window height (only works when window is maximized)
    //document.all.contentbody.height = (document.body.parentNode.clientHeight - 127 - 75);  // Available Content Area - Top Tabs and Search Boxes - Footer

	var paramStr = window.location.search.substr(1);	//Takes everything after the ? in the parameter list
	var paramStrArray = paramStr.split('&');  //Gathers a collection of all parameter names and their values from the URL
	var menuRows = document.getElementById("leftMenu").getElementsByTagName("tr");

	//Loop through all the parameter name/value pairs
	for (var i = 0; i < paramStrArray.length; i++){
		var params = paramStrArray[i].split('=');
	
		//If the parameter name is "selected"
		if (params[0] == "selected"){
			
			selectedMenuItem = params[1];  //Set the selectedMenuItem variable to the value of the parameter
			
			var selBaseClass = document.getElementById(selectedMenuItem).className.slice(0,1); 
			document.getElementById(selectedMenuItem).className = selBaseClass + "-chosen";  //Put the selected cell to the chosen state
			
		}
		
		//If the parameter name is "expanded"
		if (params[0] == "expanded"){
			
			var paramArray = params[1].split(',');  //Split on the comma to gather all the submenus
			
			for (var j = 0; j < paramArray.length; j ++){  //For each of the submenu name/value pairs gathered...
				
				for (var k = 0; k < menuRows.length; k++){
					
					if (menuRows[k].id == paramArray[j] && menuRows[k].className == "submenu"){  //Loop through all the rows in the menu to find the one that matches this submenu
						cellsExpanded = menuRows[k-2].cells;  //Find the table cell that called this particular submenu
						//var expBaseClass = cellsExpanded[0].className.slice(0,1);
						//cellsExpanded[0].className = expBaseClass + "-chosen";  //Change that cell to the "chosen" state
						var cellsExpandedImage = cellsExpanded[0].id + "I";
						getImage(cellsExpandedImage, "true");  //Point the arrow of that cell downward
					}
				
				}
				
				document.getElementById(paramArray[j]).style.display = "inline";  //Expand the submenu
			}
			
		}
	
	}
	
}
//--------------------------------------------------------------------
//Highlights the cell when scrolled over
function menuMouseOver(menuID) {
	//alert(menuID);
	var baseClass = document.getElementById(menuID).className.slice(0,1);
	
		if (document.getElementById(menuID).className != (baseClass + "-chosen")){
			document.getElementById(menuID).className = (baseClass + "-hover");
		}

}
//--------------------------------------------------------------------
//Un-highlights the cell when scrolled off
function menuMouseOut(menuID) {
	var baseClass = document.getElementById(menuID).className.slice(0,1);

		if (document.getElementById(menuID).className != (baseClass + "-chosen")){
			document.getElementById(menuID).className = baseClass;
		}

}
/******************************* END: JAVASCRIPT FOR LEFT MENU *******************************/

//--------------------------------------------------------------------
//Loads the selected page from the select box
function loadSelectedPage(url) {
	
	if (url != "")
		window.location = url;
}

//-->