<!--


function viewCookie()
{
 alert(document.cookie);
}


// GET COOKIE FUNCTION

function getCookie(name){
   var cname = name + "=";
   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;
}



// SET EXPIRATION DATE OF COOKIE TO 7 DAYS AHEAD

var expiration = new Date();
expiration.setTime(expiration.getTime() + 604800000);

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}


// CHECK FOR ID ALREADY IN COOKIE

function checkDup(form,idValueArray,value){

   var valueLength = idValueArray.length
   var x = 0;

   while (x < valueLength){

      if (idValueArray[x] == value){
//         alert("You have already selected this item.");
         return false;
         }
      x++;
    }
      return true;
}


// THIS WILL WRITE THE INFO TO A COOKIE

function addID(form)
{
   var arrayLength;
   var idValueArray = new Array;
   var cookieValue = '';

      // check for existing cookie and get existing values

   if(getCookie('cart')){
         cookieValue = getCookie('cart');
//alert(cookieValue);
         idValueArray = cookieValue.split('/');
//alert(idValueArray);
//alert(form.id.value);
//alert(document.cartStatus.cartCount.value);
      }

         if (checkDup(form,idValueArray,form.id.value)){
            idValueArray[idValueArray.length] = form.id.value;
            }

   // join the IDs into a string then add to any existing values

   cookieValue = idValueArray.join('/');
   setCookie("cart",cookieValue,expiration,"/",null,null);

   //update the count in the cart if it exists
   if(idValueArray.length>0)
document.cartStatus.cartCount.value = idValueArray.length;

}


// THIS WILL FIND THEN DELETE ID

function deleteID(form)
{
   var arrayLength;
   var idValueArray = new Array;
   var cookieValue = '';

      // check for existing cookie and get existing values

   if(getCookie('cart'))
      {
         cookieValue = getCookie('cart');
         //alert(cookieValue);
         idValueArray = cookieValue.split('/');
         //alert(idValueArray);
         //alert(form.id.value);
         //alert(document.cartStatus.cartCount.value);
      }

    var valueLength = idValueArray.length
    var x = 0;

    while (x < valueLength)
      {

      if (idValueArray[x] == form.id.value)
        {
	  //  alert(idValueArray);
 	  idValueArray.splice(x,1);
	  //  alert(idValueArray);
	  // alert(x);
        }
      x++ 
      }


   // join the IDs into a string then add to any existing values

  if(valueLength>=0)
    { 
     cookieValue = idValueArray.join('/');
    }


   setCookie("cart",cookieValue,expiration,"/",null,null);

   //update the count in the cart if it exists
   if(idValueArray.length>=0)
 document.cartStatus.cartCount.value = idValueArray.length;

}


// RUN A CANNED QUERY TO GET RECORDS SELECTED

function getRecords(cookieName){
   var searchString = getCookie(cookieName);
//alert(searchString);
   // These variables need to be updated for every tb
   // each string variable contains the name\value pair required by webPub
   // They must be URL encoded.

   var textbase = "Lib";
   var idField = "id";
//   var bu = "http%3A%2F%2Fsupport%2Einmagic%2Ecom%2Fdemos%2Fconsult%2Fbookbag%2Ehtm";
//   var bu = "http%3A%2F%2FTRINITY%2FCNIS%2FLIBDEMO%2FSEARCHLIBRARY%2Ehtm";
   var bu = "http%3A%2F%2Fcrewnoble.com%2FLIBDEMO%2FLIBRARY%2Ehtm";
   var recordsPerPage = "";
   var reportForm = "WebCartToEmail";
   var displayForm = "WebFull";
   var rl = "0";
   var dl = "0";
   var np = "3";

   var CannedQuery = '/dbtw-wpd/exec/dbtwpub.dll?';
   CannedQuery += 'TN=' + textbase;
   CannedQuery += '&QF0='+ idField;
   CannedQuery += '&QI0=' + searchString;
   CannedQuery += '&BU=' + bu;
   CannedQuery += '&MR=' + recordsPerPage;
   CannedQuery += '&RF=' + reportForm;
   CannedQuery += '&RL=' + rl;
   CannedQuery += '&DF=' + displayForm;
   CannedQuery += '&DL=' + rl;
   CannedQuery += '&NP=' + np;
   CannedQuery += '&AC=QBE_QUERY';
   //alert(CannedQuery);
   window.location.href = CannedQuery;
}

function delCookie(name) 
{
document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
} 


// USE THIS FOR TESTING

function setCookieCart()
{
 the_Cart = "73/69"
// the_cookie = "cart=" + escape(the_Cart)  + "; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/"; 
 varcookie = "cart=" + escape(the_Cart) + ";path=/"; 
document.cookie = varcookie
//alert(document.cookie);
self.location.reload();
}

// USE THIS FOR CHECKING ALL CHECKBOXES (Each checkbox is in a different form; one for each record.)

function checkall()
{
 varCountCheckboxes = 0
   for(k=2; k<document.forms.length; k++)
    
    {
      if (document.forms[k].elements[0].type.substring(0,8) == "checkbox")
        {
          varCountCheckboxes += 1
          document.forms[k].elements[0].checked = true;
          addID(document.forms[k])
        }
    }
       //  alert(varCountCheckboxes)
}



// USE THIS FOR UN-CHECKING ALL CHECKBOXES (Each checkbox is in a different form; one for each record.)

function uncheckall()
{
 varCountCheckboxes = 0
   for(k=2; k<document.forms.length; k++)
    
    {
      if (document.forms[k].elements[0].type.substring(0,8) == "checkbox")
        {
          varCountCheckboxes += 1
	 if (document.forms[k].elements[0].checked == true) // Added 11-06-2009 KKN
	   {
            document.forms[k].elements[0].checked = false;
            deleteID(document.forms[k])
	   }
        }
    }
       //  alert(varCountCheckboxes)
}


// USE THIS FOR CHECKING ALL CHECKBOXES when WebCartToEmail (reviewing items in cart) form loads

function SendEmailCheckall()
{
    for (var i=0; i < document.FormName.elements.length; i++)
     {
       if (!document.FormName.elements[i].checked)document.FormName.elements[i].checked=true
     }
}


// USE THIS FOR UNCHECKING ALL CHECKBOXES when WebCartToEmail (reviewing items in cart) form loads


function SendEmailUncheckall()
{
    for (var i=0; i < document.FormName.elements.length; i++)
     {
       if (document.FormName.elements[i].checked)document.FormName.elements[i].checked=false
     }
}




// USE THIS FOR EMPTYING THE CART COOKIE

function setCookieCartEmpty()
{
 the_Cart = ""
// the_cookie = "cart=" + escape(the_Cart)  + "; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/"; 
 varcookie = "cart=" + escape(the_Cart) + ";path=/"; 
document.cookie = varcookie
//alert(document.cookie);
//self.location.reload();
document.cartStatus.cartCount.value =""
uncheckall();
}


//-->


