// what to do when page loads?

window.onload = MJPloadPage;

function MJPloadPage() {
  externalLinks();
}

/*
These two functions will work on the majority of
recent browsers which all have their different
access methods.
*/

function getRef(id) {
 if (document.getElementById) return document.getElementById(id);
 if (document.all) return document.all[id];
 if (document.layers) return document.layers[id];
}

function getSty(id) {
 if (getRef(id).style) return getRef(id).style;
 return getRef(id);
}

/*
Makes all links with rel=external open in a new window
for XHTML 1+ Strict compliance.
*/

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

// TOGGLE MENU CODE

function toggleMenu() {
  if (getSty('MenuBar').display != 'none') {
    getSty('MenuBar').display = 'none';
    getSty('MainBit').position = 'static';
  }
  else {
    getSty('MenuBar').display = 'block';
    getSty('MainBit').position = 'absolute';
  }
  return false;
}

// COOKIE FUNCTIONS

function getCookie(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 setCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" +escape(value) +
    ( (expires) ? ";expires=" + expires.toGMTString() : "") +
    ( (path) ? ";path=" + path : "") + 
    ( (domain) ? ";domain=" + domain : "") +
    ( (secure) ? ";secure" : "");
}

function delCookie(name,path,domain) {
  if (getCookie(name)) document.cookie = name + "=" +
    ( (path) ? ";path=" + path : "") +
    ( (domain) ? ";domain=" + domain : "") +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}