var pageType = "starting";
var depth = "";
var imageLocation;

var lockedImage = "";      // var of the left toolbar image/menu that is "open"
var preloadFlag = false;   // assume older browser and that image cannot preload

function newImage(arg) {   // function to create a new image and cache it
   if (document.images) {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
   }
}



function pagePrep() {
   
   imageLocation = depth + "images/";

   if (document.images) {
      
      preloadFlag = true;

      var openMenu = getCookie( 'menu' ); // if the user is returning to the site in the same
      
   }
  

}

function changeImages() {
   if ( 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 == "") {
      obj.style.display = "block";
   } else {
      obj.style.display = "none";
   }
}


//
// 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";
  }
}

//
// popup coding if needed
//

function newwin( file, winname ) {
   newwindow = window.open( file, winname, 'toolbar=1,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width=450,height=400,left=50,top=50');
   newwindow.focus();
}
