var preloadFlag = false;   // assume older browser and that image cannot preload
var lockedImage = "";      // need to hold an image open
var openMenu = "";         // name of open sub-menu (if any)
var openQuestion = "";     // open question number (if any)

var now = new Date();
var theYear = now.getFullYear();


function newImage(arg) {   // function to create a new image and cache it
   if (document.images) {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
   }
}

function changeImages() {
   if (document.images && (preloadFlag == true)) {
      for (var i=0; i<changeImages.arguments.length; i+=2) {
         document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
      }
   }
}

function pagePrep() { // preload images is called via the onLoad properity in the page <body>
   if (document.images) {
      preloadFlag = true;
   }
}

function changeImages() {  // the rollover code for the top of page toolbar.
   if (document.images && (preloadFlag == true) ) { // && (changeImages.arguments[0] != lockedImage)) {
      for (var i=0; i<changeImages.arguments.length; i+=2) {
         document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
      }
   }
}

function switchDisplay(objectID) {              // changes the "display" style of the object from
   obj = document.getElementById(objectID);     // visible (block) to invisible (none) or vise-versa
   if(obj.style.display == "none" || obj.style.display == "") {
      if( openMenu != "" ) {
         openObj =  document.getElementById( openMenu );
         openObj.style.display = "none";
      }
      obj.style.display = "block";
      openMenu = objectID;
   } else {
      obj.style.display = "none";
      openMenu = "";
   }
}

function openWin(val) {
   var winFeatures = 'width=465,height=340,scrollbars=yes,toolbar=yes';
   win = open(val,'WIN',winFeatures);
   if (parseInt(navigator.appVersion) == 2 && (navigator.appVersion.indexOf('Mac') != -1)) {win = open(val,'WIN',winFeatures)}
   if (!(self.opener)) {win.opener = top.self;}
}

function showQuestion( ID ) {
   if( openQuestion == "" ) {
      document.getElementById( "qa" + ID ).style.background = "#fff";
      document.getElementById(  "a" + ID ).style.display = "block";
      openQuestion = ID;
      return;
   }

   if( openQuestion == ID ) {
      if( document.getElementById( "a" + ID ).style.display == "block" ) {
         document.getElementById( "a" + ID ).style.display = "none";
         document.getElementById( "qa" + ID ).style.background = "#ffc";
         openQustion = "";
      } else {
         document.getElementById( "a" + ID ).style.display = "block";
         document.getElementById( "qa" + ID ).style.background = "#fff";
         openQustion = ID;
      }
      return;
   }

   document.getElementById( "qa" + openQuestion ).style.background = "#ffc";
   document.getElementById( "a" + openQuestion ).style.display = "none";

   document.getElementById( "a" + ID ).style.display = "block";
   document.getElementById( "qa" + ID ).style.background = "#fff";

   openQuestion = ID;

}

//
// client-side cookie function.
// one user-value per cookie UNLESS you concatenate the desired values
// in to one string and store that string.
//

function getCookie(name){     // retrieves a cooke from a user's machine
  var cname = name + "=";     // if cookie not located, it returns a "null" value.
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return null;
}

function setCookie(name, value, expires, path, domain, secure) {     // sets a cookie on the user's machine
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +  // if exipres == null, coookie will expire at end of session
  ((path == null) ? "" : "; path=" + path) +                         // if path == null, cookie will only be accessbile to the directory the creating file was housed in
  ((domain == null) ? "" : "; domain=" + domain) +                   // if domain == null, cookie will only be accessbile to the server the creating file was hosted on.
  ((secure == null) ? "" : "; secure");                              // if secure == null, cookie could be hacked...cookies ARE NOT secure. just leave this one  blank.
}

function delCookie (name,path,domain) {      // deletes named cookie from user's machine
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +        // if path == null, cookie MUST be deleted by the page/directory that created it
    ((domain == null) ? "" : "; domain=" + domain) +  // if domain == null, cookie MUST be deleted by the directory/server that created it.
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

