function navHelper() {
	var navLIs = $$('#navMain > li');
	var browserURL = document.URL.toLowerCase();
	
	if (browserURL.include('/corporate.aspx') || browserURL.include('/corporate/')){
		navLIs[0].removeClassName('active');
		navLIs[1].addClassName('active');
	}
	
}


//First and Last LI Selector
//Note: Prototype Driven
function liFirstLast() {
	var firstLIs =	$$('ul > li:first-child');
	var lastLIs = $$('ul > li:last-child');
	
	firstLIs.each(function(liFirst) {
		liFirst.addClassName('first');
		});
		
	lastLIs.each(function(liLast) {
		liLast.addClassName('last');
	});
}

//Zebra Striping Tabular Data
function stripe() {
  var evens = $$('table.stripe tr:nth-child(odd)');
    if(evens) {
      evens.each(function(tr) {
        tr.addClassName('oddRow');
      });
    }
}

//Header Helper
//Creates various hover classes for the header controls
function headerHelper() {
	var hoverLists = $$('#quicklinkOB, #quicklinkSignUp, #quicklinkDemo');
	
	hoverLists.each(function(hoverList){
		hoverList.observe('mouseenter', function(event){
			hoverList.addClassName('hover');
		});
		hoverList.observe('mouseleave', function(event){
			hoverList.removeClassName('hover');
		});
	});
}

//Unordered List Drop Down Menu 'Please Select...' Insertor, just add UL's ID into dropdownList Array
function dropdownInsert() {
	var dropdownList = $$('#quicklinkOB, #quicklinkSignUp, #quicklinkDemo');
	
	dropdownList.each(function(dropdownInsertion){
		dropdownInsertion.insert({top:"<li>Please Select One...</li>"} );
	});
}

//Input Clear
//Clears text inputs on a page on focus
//Note: Prototype driven
function inputClear() {
	var textInputs = $$('input[type="text"]');
	
	textInputs.each(function(textInput){
		textInput.initialValue = textInput.value;
		textInput.observe('focus', function(event) {
			if(textInput.value == textInput.initialValue){
				textInput.clear();
			}
		});
		textInput.observe('blur', function(event){
			if(textInput.value.blank() == true) {
				textInput.value = textInput.initialValue;
			}
		});
	});
}
/*


// Search Box Focus 
function inputFocus () {

	var input = document.getElementById ('header_0_txtSearch');
	input.focus ();
	// ...but if someone wishes to go back in their history, let them!
	document.onkeydown = function (e) {
	if (!e) {
	var e = window.event;
	}
	if (e.keyCode === 8 && !input.value) {
	history.back();
	}
	};
	};
*/

// Cookie Functions
// Set the cookie 
function setCookie(name,value,days) { 
	if (days) { 
		var date = new Date(); 
		date.setTime(date.getTime()+(days*24*60*60*1000)); 
		var expires = ";expires="+date.toGMTString(); 
	} else { 
		expires = ""; 
	} 
	document.cookie = name+"="+value+expires+";"; 
}

// Read the cookie 
function readCookie(name) { 
	var needle = name + "="; 
	var cookieArray = document.cookie.split(';'); 
	for(var i=0;i < cookieArray.length;i++) { 
		var pair = cookieArray[i]; 
		while (pair.charAt(0)==' ') { 
			pair = pair.substring(1, pair.length); 
		} 
		if (pair.indexOf(needle) == 0) { 
			return pair.substring(needle.length, pair.length); 
		} 
	} 
	return null; 
}


//make sure one checkbox has been checked
function checkAtLeastOne(source, args)
{
    args.IsValid=false;
   var arr = $('form1').getElements(); 
   arr.each(function(item) {
        if(item.type == "checkbox") {
            if(item.checked) {
                args.IsValid = true;
            }
        }
   });
}
//make sure one textbox has been filled
function popAtLeastOne(source, args)
{   
    var inputs = $$('#locationFieldset input[type="text"]'); 
    
    args.IsValid = false;
    inputs.each(function(input) {
            if(!input.value.blank()) {
                    args.IsValid = true;
                }
    });
}

function homeBankingMenu() {
	var oddLIs = $$('#navBankingContainer ul li:nth-child(odd)');
	
	oddLIs.each(function(oddLI){
		oddLI.addClassName('odd');
	});
	
	var evenLIs = $$('#navBankingContainer ul li:nth-child(even)');
	
	evenLIs.each(function(evenLI){
		evenLI.addClassName('even');
	});	
	
	var listSiblings = $$('#navBankingContainer ul li li, #navBankingContainer ul li:last-child');
	
	listSiblings.each(function(listSibling){
		listSibling.removeClassName('even');
		listSibling.removeClassName('odd');
	});
	
	var firstLIsAs = $$('#navBankingContainer > ul > li > a');
	
	firstLIsAs.each(function(liFirst, index) {
		var textCopy = liFirst.innerHTML;
		liFirst.innerHTML = "";
		liFirst.insert("<strong>"+textCopy+"</strong>");
	});
	
	var homeBankingTabs = $$('#navBankingContainer h2');
	var homeBankingSections = $$('#navBankingContainer > ul');
	
	var currentPage = location.href;
	
	if(currentPage.include('/privatebanking/')){
		var currentSection = 2;
		var lastSection = 2;
	}
	else {
		var currentSection = 0;
		var lastSection = 0;
	}
	
	homeBankingTabs[currentSection].addClassName('active');
	homeBankingSections[currentSection].addClassName('active');
	
	homeBankingTabs.each(function(homeBankingTab, index) {
		homeBankingTab.observe('click', function(event){
			lastSection = currentSection;
			currentSection = index;
			homeBankingTabs[lastSection].removeClassName('active');
			homeBankingSections[lastSection].removeClassName('active');
			homeBankingTabs[currentSection].addClassName('active');
			homeBankingSections[currentSection].addClassName('active');
			
			event.stop();
		});
	});
	
}

//Replacement for Window Onload - Loads before images, cross-browser
document.observe("dom:loaded", function() {
	//dynamicShadow('/images/global/shadow.png', 'page-container', 16, 0);
	dropdownInsert();
	liFirstLast(); // Adds classes 'first' and 'last' to respective LIs
	inputClear();
	//inputFocus ();
	headerHelper();
	navHelper();
	stripe();
	if(document.getElementById("page-container").className == "pgHome clearthis"){
		homeBankingMenu();
	}
});