// JavaScript code for DB/Text InfoCart
//  Copyright © 2001, Inmagic, Inc., Woburn, MA, USA. All rights reserved.

   // 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 = "Popline";
   var idField = "DocNo";
   var bu = "http%3A%2F%2ccp-apps2%2Epopweb%2Fbasic%2Ehtml";
   var recordsPerPage = "50";
   var reportForm = "starterCart";
   var displayForm = "LongRecordDisplay";
   var rl = "0";
   var dl = "0";
   var np = "0";
   
   
      //sets the domain the cookie can be used in
      //null means just the default domain
      var domain = null;
      
      
// Heinle's function for retrieving a cookie. INFOCART

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;
}

// An adaptation of Dorcht's function for setting a cookie.
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");
}

// An adaptation of Dorcht's function for deleting a cookie.
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


//set expiration date 30 days ahead
var expiration = new Date();
expiration.setTime(expiration.getTime() + 1000 * 60 * 60 * 24 * 30);

//set this cookie
function setPassword(form){
	var password = form.ID.value;
	setCookie('inmusers', password, expiration, null, domain, null);
	}
	
//get this cookie
function getPassword(){	
	if (getCookie('inmusers') != null){ 	
		document.qbe_form.ID.value = getCookie('inmusers');
	}
}
//delete this cookie
function clearPassword(form){
	document.qbe_form.ID.value = "";
	delCookie('inmusers', null, domain);
}

// Clear all the boxes on the form except the password
function clearForm (form) {
   var formLength = form.elements.length;
   
   //walk through all the elements of the form
   for(i=0;i<formLength;i++){

      //if it is a text element then clear it. wont work for textarea
      if (form.elements[i].type == 'text') {
         form.elements[i].value = '';
      }
   }
}



// run a canned query to get the record selected
function getRecords(cookieName){
   var searchString = getCookie(cookieName);
   

   var CannedQuery = '/ics-wpd/exec/icswppro.dll?';
   CannedQuery += 'TN=' + textbase;
   CannedQuery += '&QF0='+ idField;
   CannedQuery += '&QI0=' + escape(searchString);
   CannedQuery += '&BU=' + escape(document.location);
   CannedQuery += '&MR=' + recordsPerPage;
   CannedQuery += '&RF=' + reportForm;
   CannedQuery += '&RL=' + rl;
   CannedQuery += '&DF=' + displayForm;
   CannedQuery += '&DL=' + dl;
   CannedQuery += '&NP=' + np;
   CannedQuery += '&AC=QBE_QUERY';
   //alert(CannedQuery);
   window.location.href = CannedQuery;
}

