localWebsiteOnload = function() { // Just a placeholder. This will be redefined in localwebsite.js
}
/**
 * Main menu navigation event hook
 */
var menuOneActiveNode;var activeNode;var menuTimeout;
initMainMenu = function() {
  if (document.getElementById) {
    var navRoot = document.getElementById("main_menu"); // Get main list ul
    //Regex for selecting active menu one
    if (typeof primaryMenu!="undefined")
      var reMenuOne = new RegExp("^" + primaryMenu, "i");

    // Loop over main list items
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName.toLowerCase() == 'li') {
        //find active menu
        if (menuOneActiveNode == null && (typeof primaryMenu!="undefined") && node.firstChild.innerHTML.match(reMenuOne )) {
	      menuOneActiveNode = node;
          //mark the node as being active
          addClassName(node, "nav_on");
	      selectMenuTwo(node);
        }
		
        //Apply onmouseover and onmouseout event handlers to each main list item
        node.onmouseover = function() {
          if (menuTimeout) window.clearTimeout(menuTimeout);
          //different node than the activeNode
          if (activeNode && this != activeNode) {
        	removeClassName(activeNode, "mouse_over");
          	//make appearance of currently selected node
            if (activeNode == menuOneActiveNode) {
	        	removeClassName(activeNode, "nav_on");
            }
          }
          activeNode = this;
          addClassName(activeNode, "mouse_over");
        }
        node.onmouseout = function() {
          if (menuTimeout) window.clearTimeout(menuTimeout);
          menuTimeout = window.setTimeout("if(activeNode){removeClassName(activeNode,'mouse_over');};if(menuOneActiveNode){activeNode=menuOneActiveNode;addClassName(menuOneActiveNode,'nav_on');}", 750);
        }
      }
    }
  }
}
/**
 * Marks second level node as active
 */
selectMenuTwo = function(menuOneNode) {

  //Regex for selecting active menu two
  if (typeof secondaryMenu!="undefined" && menuOneNode.getElementsByTagName("UL").length == 1)
    var reMenuTwo = new RegExp("^" + secondaryMenu, "i");
  else
    return;

  menuTwoList = menuOneNode.getElementsByTagName("UL")[0];
  if (menuTwoList!="undefined") {
    for (j=0; j<menuTwoList.childNodes.length; j++) {
      menuTwoNode = menuTwoList.childNodes[j];
      if (menuTwoNode.nodeName == "LI") {
        if (menuTwoNode.firstChild.innerHTML.match(reMenuTwo )) {
          //mark the node as being active
          addClassName(menuTwoNode, "nav_on");
          break;
        }
      }
    }
  }
}
addClassName = function(element, cls) {
	if (!element.className) element.className="";
	if (element.className.indexOf(cls) == -1)
		element.className += " " + cls;
}
removeClassName = function(element, cls) {
	var rep=element.className.indexOf(" "+cls) == -1 ? cls:" "+cls;
    element.className=element.className.replace(rep,"");
}

/**
 * On change event for the select box
 */
goToURL = function(selectBox) {
    if (selectBox.options[selectBox.selectedIndex].value != "") {
        window.location.href = selectBox.options[selectBox.selectedIndex].value;
    }
}
/**
 * Cookie functions:
 * In order to improve our service, we use cookies to
 * calculate the number of unique users.
 */
var SESSION_COOKIE = "sessionID";
var USER_COOKIE = "usrID";
var OLD_USER_COOKIE = "userID";
var LOGGED_IN_COOKIE = "show_logout";
initCookies = function() {
  var sessionCookie = getCookie(SESSION_COOKIE);
  var oldUserCookie = getCookie(OLD_USER_COOKIE);
  //if (oldUserCookie !== null) delCookie(OLD_USER_COOKIE);
  var userCookie = getCookie(USER_COOKIE);
  //just touch the permanent cookie if exists
  if (userCookie !== null) {
    if (sessionCookie === null)
      setUserCookie(userCookie);
  }
  else {
    setUserCookie(oldUserCookie);
  }
  //unique cookie for this session
  if (sessionCookie === null)
    setCookie(SESSION_COOKIE, getUniqueID());
  //if logged in cookie is present, make the logout link visible
  if (getCookie(LOGGED_IN_COOKIE) !== null) {
    if (document.getElementById) {
	    var logoutLink = document.getElementById("logout_link");
	    if (logoutLink)
	    	logoutLink.style.display = "inline";
  	}
  }
}
setUserCookie = function(cookieValue) {
  var today = new Date();
  var dAdd = new Date(today.getTime() + (365 * 86400000));
  var host = getHost();
  var domain;
  if (host && host.indexOf(".") != -1){
    var hostArr = host.split(".");
    if (hostArr.length > 1){
      domain = "." + hostArr[hostArr.length-2] + "." + hostArr[hostArr.length-1]; 
    }
  }
  setCookie(USER_COOKIE, (cookieValue !== null ? cookieValue : getUniqueID()), dAdd, "/", domain, false);
}
getHost = function() {
  var host = (typeof window.all != 'undefined' && typeof window.opera == 'undefined') ?
    window.location.hostname : window.location.host;
  if (!host) host = document.location.hostname;
  return !host?null:host;
}
getUniqueID = function() {
  var id = (new Date()).getTime();
  id += Math.random().toString().replace(/\./,"");
  return id;
}
getCookie = function(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));
}
setCookie = function(name, value, expires, path, domain, secure){
//	( (path) ? ";path=" + path : "") +
  document.cookie = name + "=" + escape(value) +
	( (expires) ? ";expires=" + expires.toGMTString() : "") +
	";path=/" +
	( (domain) ? ";domain=" + domain : "") +
	( (secure) ? ";secure" : "");
}
delCookie = function(name){
    document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
/**
 * Makes the target attributes for xhtml1.1 strict documents.
 * Give anchors with attribute rel="externalLink" a target attribute of "_blank" 
 */
externalLink = function() {
  if (document.getElementsByTagName) {
    var i, a;
    a = document.getElementsByTagName('a');
    for (i in a) {
      if (a[i].rel == 'externalLink')
        a[i].target = '_blank';
  }
 }
}
/**
 * Returns element matching its id
 * If element doesn't exist null is returned.
 */
getElementWithID = function(elementID) {
	if (document.getElementById)
		return document.getElementById(elementID);
}
/**
 * Submits quick search form found on the top of each page
 */
submitQuickSearch = function() {
	var quickSearchForm = getElementWithID("frmSearch");
	if (quickSearchForm)
		quickSearchForm.submit();
}
/**
 * This is convenience method used on i.e. Consolidated banking statistics page
 * Returns the selected value of select box if exist,
 * otherwise returns "" (empty string)
 */
getSelectBoxValue = function(boxID) {
	var selectBox = getElementWithID(boxID);
	if (selectBox)
	{
		if (selectBox.selectedIndex != -1)
			return selectBox.options[selectBox.selectedIndex].value;
		else
			return "";
	}
	else {
		return "";
	}
}
/**
 * This function has to be hooked to body onload event
 */
mainOnLoad = function() {
  initCookies();
  initMainMenu();
  localWebsiteOnload();
  //minimize flickering CSS background images in IE6
  try {
  	document.execCommand("BackgroundImageCache", false, true);
  } catch(err) {}
}