var currentli;
//-------------------------- Routing Number Validation --------------------------function currentNav() {

	if (!document.getElementById('nav')) {
	  Set_Cookie('curMenu','null','','','','');
		return true;
	}
	Set_Cookie('curMenu', 'null', '', '', '', '');
	document.getElementById('nav').getElementsByTagName('UL')[0].id = 'navul';
	
	var baseString = window.location+'';
	var startPos = baseString.indexOf('?');
		if (startPos == -1) {
		return false;
		}
	var endPos = baseString.length;
	var qv = unescape(baseString.substring(startPos+1,endPos));
	
  var word=qv.split("&");
	if (currentli = document.getElementById(qv)) 
	{
			currentli.className='selected';
		// Set the cookie
		Set_Cookie('curMenu',currentli.id,'','','','');
		//Set_Cookie('curMenuName',currentli.parent.id,'','','','');
	}
	else if (word.length > 1)
	{
	  setMenuFromLink(word);
	}
	else if (getMenuForIdOnly(qv)==true)
	{
		currentli = document.getElementById(currentli);
	  currentli.className='selected';
		// Set the cookie
		Set_Cookie('curMenu',currentli.id,'','','','');
	}
	else if (Get_Cookie('curMenu') != null) 
	{
	  //Get the cookie and select that menu
	  qv = Get_Cookie('curMenu');
	  currentli = document.getElementById(qv);
	  if ((currentli == "null") || (currentli == null))
	  {
		Set_Cookie('curMenu','null','','','','');
		return;
	  }
	  currentli.className='selected';
		// Set the cookie
		Set_Cookie('curMenu',currentli.id,'','','','');
	}

	if ((currentli == "null") || (currentli == null))
	{
	  Set_Cookie('curMenu','null','','','','');
	  return;
	  // redirect to home page
	  //window.location = "/main.aspx";
	}
  
   // Set the MLC name for HBX - End
	var recurse = currentli.parentNode;
	while (recurse != null) {
		if(recurse.nodeName == 'LI') {
			recurse.className = 'selected';
		}
		recurse = recurse.parentNode;
	}
}

function popUpWindow(URL,windowName,width,height) {
	var w = screen.availWidth;
	var h = screen.availHeight;
	var leftPos = Math.round((w-width)/2);
	var topPos = Math.round((h-height)/2);
	var defaults = "scrollbars=auto,resizable=yes,";
	var centerOnScreen = "top="+topPos+",left="+leftPos+",width="+width+",height="+height+",scrollbars=1";
	// safari seems to need the trailer comma
	var options = "'" + defaults + centerOnScreen + ",'";
	window.name = "popup";
	var msgWindow = window.open(URL,windowName,options);
	msgWindow.creator=self;
	msgWindow.focus();
}

function popUpPrintWindow(URL,windowName,width,height) {
	var w = screen.availWidth;
	var h = screen.availHeight;
	var leftPos = Math.round((w-width)/2);
	var topPos = Math.round((h-height)/2);
	var defaults = "scrollbars=auto,resizable=yes,";
	var centerOnScreen = "top="+topPos+",left="+leftPos+",width="+width+",height="+height+",scrollbars=1,menubar=yes";
	// safari seems to need the trailer comma
	var options = "'" + defaults + centerOnScreen + ",'";
	window.name = "popup";
	var msgWindow = window.open(URL,windowName,options);
	msgWindow.creator=self;
	msgWindow.focus();
}

function popup(id)
{
  var str;
  str=  window.location.href;
  str1 =window.location.pathname; 
  popUpWindow(str.substring(0,str.indexOf(str1)+1)+ 'popup.aspx?id=' + id,"PopUp",800,400);
}

function popUpExternUrl(URL) {
	var msgWindow = window.open(URL);
	msgWindow.creator=self;
	msgWindow.focus();
}

function setup() {
	currentNav();
}//fn

function Set_Cookie(name,value,expires,path,domain,secure) { 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
} 

function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function setMenuFromLink(word)
{
  for(var i=0; i<word.length;i++)
  { var menuWord = word[i].split("=");
    if (menuWord.length > 1) 
    { if ((menuWord[0] == "menu") || (menuWord[0] == "MENU"))
      { qv = qv + "|" + menuWord[1]; }
      if ((menuWord[0] == "id") || (menuWord[0] == "ID"))
      { qv = word[i]; }
    }
  }
  currentli = document.getElementById(qv);
  if (currentli != null)
  { currentli.className='selected';
    // Set the cookie
    Set_Cookie('curMenu',currentli.id,'','','','');
  }
  else 
  { currentli = Get_Cookie('curMenu'); }
}

function getMenuForIdOnly(qv)
{
  var menuID;
	var listItems = document.getElementById('nav').getElementsByTagName('li');
  for(var i=0;i<listItems.length;i++)
  { menuID = (listItems[i].id).split("|");
    if (qv == menuID[0])  
    { currentli = listItems[i].id; return true; }
  }
}
function clearMenu()
{
	  Set_Cookie('curMenu','null','','','','');
		return true;
}
window.onload = setup;

function escapeHTML (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}

function IsNumeric(value){
 	if (isNaN(value))
 		return false;
 	else
 		return true;		
}

// For Search
function searchresults(e)
{
var keycode = e.keyCode;
    if (!IsEmpty(document.getElementById("txtSearch")))
    {  
        if (keycode == 13)
           window.location.href="search.aspx?txtSearch=" + document.getElementById("txtSearch").value; 
    }
    return true;
}

function postpages()
{
  if (!IsEmpty(document.getElementById("txtSearch")))    
      window.location.href="search.aspx?txtSearch=" + document.getElementById("txtSearch").value;
}

function IsEmpty(aTextField)
{
		  returnValue = false;
   		if ((aTextField.value.length==0) || (aTextField.value==null)) 
   			returnValue = true;
   		else 
   			returnValue = isWhitespace(aTextField.value);
   		 return returnValue;
}

function isWhitespace (s)
{
    var i;
    var whitespace = " \t\n\r";
    for (i = 0; i < s.length; i++)
    {
       var c = s.charAt(i);
	     if (whitespace.indexOf(c) == -1) return false;
     }
     return true;
}