<!-- logic_save_load_searchcriteria.js

//Cookie limits: 
//300 total cookies 
//4 kilobytes per cookie, where the name and the OPAQUE_STRING combine to form the 4 kilobyte limit. 
//20 cookies per server or domain. (note that completely specified hosts and domains are treated as separate entities and have a 20 cookie limitation for each, not combined) 
//So to use more than 20 cookies values, you must use keys.


//---------------------------------------------------------
//fnSaveFormElements
//in: oForm [object] form of elements
//update: element [object] form element cookie value, cookie check state
//Prereq: Requires logic_cookiekey.js for setSHPCookieKey
//        Client must set ignoresave tag to "true" to ignore the field, but could be any value because this
//        simply checks for the existence of the flag by checking for undefined.  If undefined, then we save the field.
//        NS3 does not support private tags like ignoresave, and thus won't support save/load for ignored fields.

function fnSaveFormElements(oForm, iDays) {
 var i,j,oEl,iLength,oChildEl,cookieName;
 cookieName="searchcriteria";
//Doesn't work, I'm assuming because for new cookie, one doesn't initially exist because of not using ASP, just html on linux. Error handling suppression on page will prevent cookie get/save errors anyway if cookies are turned off.
// if(document.cookie) {
  for(i=0;i<oForm.elements.length;i++) {
  if(oForm.elements[i].type) {
   if(oForm.elements[i].type.toLowerCase()=="checkbox" && oForm.elements[i].ignoresave==undefined) {
     //Writes 'true' or 'false' to cookie
     setSHPCookieKey(cookieName,oForm.elements[i].name.toLowerCase(),oForm.elements[i].checked,"/",iDays);  
   } 
   else if(oForm.elements[i].type.toLowerCase()=="radio") {
     //This will go through for each radio button in group, so for 3, will go through 3 times, but we only save, or load the one checked.
     oEl=oForm.elements[i];
     iLength=oForm[oEl.name].length;
     if (iLength==undefined) {
                              //Single radio button
       if(oForm.elements[i].checked && oForm.elements[i].ignoresave==undefined)
          setSHPCookieKey(cookieName,oForm.elements[i].name.toLowerCase(),oForm.elements[i].checked,"/",iDays);  
     }
     else
                              //Group Collection of Radio buttons
     for(j=0;j<iLength;j++) {
       //Get the actual child at index j
       oChildEl=oForm[oEl.name][j];
       if (oChildEl.checked) {
           //Turn off child so that we don't write multiple times, because the parent loop will hit this code for each child radio.
           oChildEl.checked=false;
           //Now write the elements name (the group collection name), but with the index of the radio that is checked.
           setSHPCookieKey(cookieName,oForm.elements[i].name.toLowerCase(),j,"/",iDays); 
       }
     }
    
   } 
   else if(oForm.elements[i].type.toLowerCase()=="select-one" && oForm.elements[i].ignoresave==undefined) {
     setSHPCookieKey(cookieName,oForm.elements[i].name.toLowerCase(),oForm.elements[i].selectedIndex,"/",iDays);
   } 
   else if(oForm.elements[i].type.toLowerCase()=="text" && oForm.elements[i].ignoresave==undefined) {
     setSHPCookieKey(cookieName,oForm.elements[i].name.toLowerCase(),oForm.elements[i].value,"/",iDays);  
   }
  }
 }
// }
}


//---------------------------------------------------------
//fnLoadFormElements
//in: oForm [object] form of elements
//update: element [object] form element value, check state
//Prereq: Requires logic_cookiekeys.js for getSHPCookieKey
//        Client must set ignoresave tag to "true" to ignore the field, but could be any value because this
//        simply checks for the existence of the flag by checking for undefined.  If undefined, then we save the field.
//        NS3 does not support private tags like ignoresave, and thus won't support save/load for ignored fields.
function fnLoadFormElements(oForm) {
 var sValue, i, iLength, cookieName;
 //try..catch logic is not supported by Netscape 4, only 6+
 cookieName="searchcriteria";
//Doesn't work, I'm assuming because for new cookie, one doesn't initially exist because of not using ASP, just html on linux. Error handling suppression on page will prevent cookie get/save errors anyway if cookies are turned off.
// if(document.cookie) {
  //The getSHPcookie may return null, so check for null values with if(value)
  for(i=0;i<oForm.elements.length;i++) {
  if(oForm.elements[i].type) {
   //Just checking for .ignoresave (not caring for the tag value) won't work, javascript will only evaluate for existence if the tag exists by returning true, rather than undefined.
   //which is the opposite of what we want, we want to ignore the items with the ignoresave tag.
   if(oForm.elements[i].type.toLowerCase()=="checkbox" && oForm.elements[i].ignoresave==undefined) {
    sValue=getSHPCookieKey(cookieName,oForm.elements[i].name.toLowerCase());
    //Note: Can't assign .checked to string value of 'false', otherwise, this is considered a string, non-empty, or not false.
    //So use the conditional ternary operator to set a true boolean based on the string value.
    if(sValue)
       oForm.elements[i].checked=(sValue.toLowerCase()=="true")?true:false;
   }
   else if(oForm.elements[i].type.toLowerCase()=="radio") {
    sValue=getSHPCookieKey(cookieName,oForm.elements[i].name.toLowerCase());
    //Note: Can't assign .checked to string value of 'false', otherwise, this is considered a string, non-empty, or not false.
    //So use the conditional ternary operator to set a true boolean based on the string value.
    if (sValue && sValue > '' && oForm.elements[i].ignoresave==undefined) {  //For group collection of radios, all tags must have ignoresave tag for the group to be ignored.
      iLength=oForm[oForm.elements[i].name].length;
      if (iLength==undefined)           //Single radio
         oForm.elements[i].checked=true;
      else {                            //Group collection of radio buttons
        oForm[oForm.elements[i].name][sValue].checked=true; 
      }
    }
   }
   else if(oForm.elements[i].type.toLowerCase()=="select-one" && oForm.elements[i].ignoresave==undefined) {
     sValue=getSHPCookieKey(cookieName,oForm.elements[i].name.toLowerCase());
     //Note: Setting the selectedIndex to a string value of '2' still works for NS, and IE. Also, setting it to a too large a value, simply clears the list to blank, just like setting to -1.
     if (sValue && sValue > '')
         oForm.elements[i].selectedIndex=sValue;
   }
   else if(oForm.elements[i].type.toLowerCase()=="text" && oForm.elements[i].ignoresave==undefined) {

     oEl=oForm.elements[i];
     sValue=getSHPCookieKey(cookieName,oEl.name.toLowerCase());
     //Only overwrite if sValue is not the same as defaultValue on element.  This will allow for setting
     //a default value, then not clearing it out with spaces.  However, if the user does clear out some
     //fields with an empty string then we'll accept it if there isn't a defaultValue.

     if(oEl.defaultValue && oEl.defaultValue>'') {
        //Don't overwrite value with spaces if defaultValue exists
        if(sValue && sValue > '' && sValue!=undefined) oEl.value=sValue;
     }
     else { 
        if(sValue && sValue!=undefined) oEl.value=sValue;
     }
   }
  }
  }
// }
}

// end of ignore -->
