
var httpRequest;
var product_number = "nothin";

var cookieContent = "not_enabled"; /* value is compared in perl script */
var timeMarker = "not_enabled";/* not_enabled value compared in perl */
 
 //if(navigator.javaEnabled){window.document.CUBBYHOLE.storeItemNumber("abc123");)
 
 //startHttpRequest();
 
   var d = new Date();
  var e = d.getTime()
  var es = e.toString();
 
 
 
 
 
function startHttpRequest(product_number) // loaded with body tag -- onLoad=makeRequest()
{
//if (window.XMLHttpRequest) 
//{
  try
  {
  httpRequest = new XMLHttpRequest();
  }
  catch(e)
  {
   try 
   {
    httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
   } 
     catch (e) 
     {
       try 
	   {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
       } 
       catch (e) 
	   {
	     if (!httpRequest) 
         {
         alert('Giving up :Cannot create an XMLHTTP instance');
         return false;
         }
	   }
     }
   }
   if (httpRequest.overrideMimeType){httpRequest.overrideMimeType('text/xml');}
  //}
processOrder(product_number);
}//end makeRequest




function processOrder(product_number)
{
var MSmatch = "okay";
var navType = navigator.userAgent;
if(navType.match(/\bMSIE/)){MSmatch = "boing";}


if(navigator.cookieEnabled == 1)
{
var cookieL;
cookieL = document.cookie;
 
  if(!cookieL)
  {
//  var d = new Date();
//  var e = d.getTime()
//  var es = e.toString();
  document.cookie = "CART ACTIVATED=" + es;
  timeMarker = es;
  }
     
  if(cookieL)
  {
  cookieContent = document.cookie.split("=");
  timeMarker = cookieContent[1];
  }

}// end cookie enabled


if((navigator.javaEnabled()) &&(MSmatch != "boing"))
{
//var es = "";
 // var d = new Date();
 // var e = d.getTime()
//  es = e.toString();

  //var readCubbyHoleData = new java.lang.String();
  var readCubbyHoleData;
  
  readCubbyHoleData = window.document.CUBBYHOLE.getItemNumber();
    
   if(readCubbyHoleData == "not_enabled")
   {
   window.document.CUBBYHOLE.storeItemNumber(es);
   timeMarker = es;
   }
   
   if(readCubbyHoleData != "not_enabled"){timeMarker = readCubbyHoleData;}
   
  
  }// end using Java enabled


var urlToCall = "";
var responseTextStr = "";


httpRequest.onreadystatechange = function()	
{
  if (httpRequest.readyState == 4) 
  {
    if (httpRequest.status == 200) 
	 {
      
	  
	 	 responseTextStr = httpRequest.responseText;
	
	
	/* THIS IS THE ELEMENT THAT GETS DISPLAYED */
	
	 document.getElementById('PRODUCT_BUTTON_DIV').innerHTML = responseTextStr;
	 
	 /* The responseTextStr is the data returned from the Perl script */
	 
     }
   }
	 
}



/*   ============ After the function's been declared the url for processing is called ==========  */
/*  ============= Note the empty rather than null has been sent in the send function ========= */


/*  -------------This is the code that displays the login block -------- */
/*  -------------This is the code that displays the login block -------- */
/*  -------------                       loginBlock.pl                               -------- */
/*  -------------This is the code that displays the login block -------- */
/*  -------------This is the code that displays the login block -------- */


urlToCall = "http://www.OrderFormCity.com/cgi-bin/ajax/shoppingCart/process.pl?PRODUCT_NUMBER=" + product_number  + "&TIME_MARKER=" + timeMarker;

httpRequest.open('GET', urlToCall, true);
httpRequest.send('');
		
	


}















/* *****************************************
How it works
   The product button on the product web page calls the processOrder(var abc) function.
The variable 'var abc' is passed to the function from the call which is then passed to the itemProcess(abc) function.   In the itemProcess() function the script checks for a cookie.  If no cookie has been set a time variable is set up and the cookie is created with this time variable as its value.  If the web browser doesn't accept cookies then the cubby hole java applet function, getItemNumber() is called.  It returns a variable.  The default variable = "not_enabled".  If this default variable hasn't been changed and still equals "not_enabled" then it is assigned a new value, the time variable which has been converted to a string.  The storeItemNumbers(time) is called to set the time in the JavaCubbyHole class.
     Next the timeMarker and product_number variables are sent to the Perl script.  The
Perl script is called using the JavaScript httpRequest() method.  I'm using the GET method
here and the tmeMarker and product_number varialbes are attached to the url as environment
variables (i.e. ?TIME_MARKER=timeMarker&PRODUCT_NUMBER=product_number).
    At this point we're working with three files, the product web page, the JavaScript
itemProcessing.js and the Perl script, process.pl.
    

The cookie and applet only store the file name.    
	
	Will need to write templates that will generate the web pages that will utilize this shopping cart script.
	
Note:  To date, script for boolean verification of cookies is very reliable.  
****************************************** */
