/* cookieHandler.js */

// set the index value for the disclaimer page in the map application introductions
var serverName = 'maps';
var mapIntroCTagLoc = 'mapintro';
var disclaimerNoCheckIndex_js = 4;
var mapApplicationLoc = window.location.href;
var mapApplicationLocArray = mapApplicationLoc.split("/");
//alert(mapApplicationLocArray[mapApplicationLocArray.length-2]);
var applicationAcronym_js = mapApplicationLocArray[mapApplicationLocArray.length-2];
//alert('unadjusted: ' + applicationAcronym_js);

/*
if (applicationAcronym_js == mapIntroCTagLoc) {
   applicationAcronym_js = applicationAcronym_ct;
//alert('adjusted: ' + applicationAcronym_js);
}
*/

if (applicationAcronym_js == 'MapYourFarm') {
   applicationAcronym_js = 'mapyourfarm';
//alert('adjusted: ' + applicationAcronym_js);
}

// function to value of boolean cookie
function checkBooleanCookie(cookieName) {
   var flagCookieValue = 0;
   var flagCookieExists = 0;
   var cookieValue = getCookie(cookieName);
   //alert('getCookie called');

   if (!cookieValue) {
      flagCookieValue = 0;
      flagCookieExits = 0;
      //alert('boolean cookie does not exist');
   }
   else if (cookieValue == 1) {
      flagCookieValue = cookieValue;
      flagCookieExits = 1;
      //alert('boolean cookie value is: ' + cookieValue);
   }
   else if (cookieValue == 0) {
      flagCookieValue = cookieValue;
      flagCookieExits = 1;
      //alert('boolean cookie value is: ' + cookieValue);
   }
   else {
      //alert('boolean cookie has value other than expected: ' + cookieValue);
   }
   /*
   // create an instance of the Date object
   var now = new Date();
   // fix the bug in Navigator 2.0, Macintosh
   fixDate(now);

   now.setTime(now.getTime());
   */

   return flagCookieValue;
}

// function to determine if a map should be made based on value of boolean cookie
function mapButton(cookieName, theMenuItemID, theURL, theTitle, showMenuBar, showToolBar, showLocationBar, showDirectoriesBar, showStatusBar, allowResize, useScrollbars, deltaWidth, deltaHeight) {

  //alert('theMenuItemID ' + theMenuItemID);
  var tmp1 = checkBooleanCookie(cookieName);
  var tmp2 = 0;
  var tmp3 = 0;
  //alert('cookieName ' + cookieName + ' cookie value tmp1 ' + tmp1);
  if (tmp1 == 1) {
    //document.location.href = "index.cfm?MenuItemID=" + disclaimerNoCheckIndex_js;
    document.location.href = "index.cfm?MenuItemID=" + theMenuItemID;
    tmp2 = setCookie(cookieName, tmp1, '', '/');
    tmp3 = openNewWindow(theURL, theTitle, showMenuBar, showToolBar, showLocationBar, showDirectoriesBar, showStatusBar, allowResize, useScrollbars, deltaWidth, deltaHeight);
  }
  else {
    // load the disclaimer (that doesn't check if cookie has been set)
    document.location.href = "index.cfm?MenuItemID="+ disclaimerNoCheckIndex_js;
  }
}

// function to "make a map"
function makeAMap(cookieName, theMenuItemID, theURL, theTitle, showMenuBar, showToolBar, showLocationBar, showDirectoriesBar, showStatusBar, allowResize, useScrollbars, deltaWidth, deltaHeight) {

   //alert('makeAMap ' + cookieName);
   //alert('makeAMap: theMenuItemID ' + theMenuItemID);
   var tmp1 = setCookie(cookieName, 1, '', '/');
   var tmp2 = 0;

   tmp2 = openNewWindow(theURL, theTitle, showMenuBar, showToolBar, showLocationBar, showDirectoriesBar, showStatusBar, allowResize, useScrollbars, deltaWidth, deltaHeight);
}

// function to reset boolean cookie to 0 ("don't make a map")
function dontMakeAMap(cookieName) {
   //alert('dontMakeAMap ' + cookieName);
   var tmp1 = setCookie(cookieName, 0, '', '/');
   // return to introductory page
   document.location.href = "index.cfm";
}
