// ========== Navbar common scripts  ============================= 
// Menu Variables
var mm = 'm1'; // 
var timeOn;
var startTime;
var hide_this; // Used to define whether to hide form elements below pull down menus.

function show_menu(mx) {
	clearTimeout(timeOn);
	var exp = "menuOn('" + mx + "')";
  	startTime = setTimeout(exp, 300); // 200ms delay before firing menubars
}

function menuOn(mx) {
	if (document.getElementById) {
		if (mx != mm) document.getElementById([mm]).style.visibility = "hidden";
		mm = mx;
		if (document.forms[0]) {  // This hides form elements in the page
			for (var j=0; j < document.forms.length; j++) {  // iterate through form elements
				hide_this = document.forms[j];
				if (hide_this.className!="lh_form") {   // unless I flagged this form as lh and ok, hide the elements
		 			for (var i=0; i < hide_this.elements.length; i++) {
		 				if (hide_this.elements[i].nodeName == 'SELECT') hide_this.elements[i].style.visibility="hidden"; // Only hide select elements... the ones that overlap in IE
					}
				}
			}
		}
		document.getElementById([mm]).style.visibility = "visible";
	}
}

function hide_menu(mx) {
	clearTimeout(startTime);
  	timeOn = setTimeout("menuOut()", 200);
}

function do_lang_change(pg) {
	var switcherFrame = document.createElement('iframe');
	switcherFrame.setAttribute("src",pg);
	switcherFrame.setAttribute("width", "0");
	switcherFrame.setAttribute("height", "0");
	switcherFrame.setAttribute("border", "0");
	switcherFrame.setAttribute("frameborder", "0");
	document.body.appendChild(switcherFrame);
}

function menuOut() {
	if (document.getElementById) document.getElementById([mm]).style.visibility = "hidden";	
	if (document.forms[0]) {  // This reshows form elements in the page
		for (var j=0; j < document.forms.length; j++) {  // iterate through form elements
			hide_this = document.forms[j];
			for (var i=0; i < hide_this.elements.length; i++) {
				hide_this.elements[i].style.visibility="visible";
			}
		}
	}
}
// ========== End Menu Scripts ==============================

// ========== Login Tracking JS func ================================
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function decodeUTF8(utftext) {
  var string = "";
  var i = 0;
  var c = c1 = c2 = 0;
  while (i < utftext.length) {
    c = utftext.charCodeAt(i);
    if (c < 128){
      string += String.fromCharCode(c);
      i++;
    }
    else if ((c > 191) && (c < 224)) {
      c2 = utftext.charCodeAt(i+1);
      string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
      i += 2;
    }
    else {
      c2 = utftext.charCodeAt(i+1);
      c3 = utftext.charCodeAt(i+2);
      string+=String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
      i += 3;
      }
  }
  return string;
}


