var xmlCatalogInfo;
var xmlAddToBoxInfo;

function GetXmlHttpObject() {
   var xmlHttp = null;
   try { // Firefox, Opera 8.0+, Safari
     xmlHttp = new XMLHttpRequest();
   }
   catch (e) { //Internet Explorer
      try {
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}

function loadCatalog(catalogSearch) { 
   xmlCatalogInfo = GetXmlHttpObject();
   if (xmlCatalogInfo == null) {
      alert ("Your browser does not support HTTP Request");
      return;
   }
   var url = "/load-catalog.php?q=" + catalogSearch + "&r=" + Math.random()*1234567;
   xmlCatalogInfo.onreadystatechange = loadCatalogResponse;
   xmlCatalogInfo.open("GET", url, true);
   xmlCatalogInfo.send(null);
}

function loadCatalogResponse() { 
   if (xmlCatalogInfo.readyState == 4 || xmlCatalogInfo.readyState == "complete") { 
     document.getElementById("catalogdiv").innerHTML = xmlCatalogInfo.responseText;
     fb.anchors.length = 0;
     fb.tagAnchors(document);
   } 
}

function addToBox(itemNo) { 
   xmlAddToBoxInfo = GetXmlHttpObject();
   if (xmlAddToBoxInfo == null) {
      alert ("Browser does not support HTTP Request");
      return;
   }
   var url = "/add-to-box.php?itemNo=" + itemNo + "&r="+Math.random()*1234567;
   xmlAddToBoxInfo.onreadystatechange = addToBoxResponse;
   xmlAddToBoxInfo.open("GET", url, true);
   xmlAddToBoxInfo.send(null);
}

function addToBoxResponse() { 
   if (xmlAddToBoxInfo.readyState == 4 || xmlAddToBoxInfo.readyState == "complete") { 
      var xmlDoc = xmlAddToBoxInfo.responseXML;
      var boxCount = xmlDoc.getElementsByTagName("boxcount")[0].childNodes[0].nodeValue;
      var itemNo = xmlDoc.getElementsByTagName("itemno")[0].childNodes[0].nodeValue;
      var productName = xmlDoc.getElementsByTagName("productname")[0].childNodes[0].nodeValue;
      var pictureFile = xmlDoc.getElementsByTagName("picturefile")[0].childNodes[0].nodeValue;
      document.getElementById("boxCount").innerHTML = "(" + boxCount + " Items)";
      fbHTML = "<div style=\"width:300px;height:150px;background:black;color:white\">" +
	    "<p style='font-size:13px;margin-bottom:1em'><img src='thumbnail.php?image=" + 
		pictureFile + "&h=148' style='border:1px solid white;margin-right:20px' align='left'>" +
		productName + " has been added to your shipping box.<p style='font-size:13px'>" +
		"You may change quantities for this item and E-Mail your order by clicking " +
		"<a style='color:white;font-weight:bold' href='order.html'>View Shipping Box</a> in the menu.</div>";
      fb.start({html:fbHTML, rev:'width:300 height:150 scrolling:no theme:black innerBorder:0'});
      fb.anchors.length = 0;
      fb.tagAnchors(document);
   } 
}
