var xmldoc = false;

function getOfferResponse()
{
	var message = xmldoc.getElementsByTagName("message").item(0).firstChild.nodeValue;
	
	var goto_shopping_cart=confirm(message+" Proceed to shopping cart?");

  if (goto_shopping_cart)
   window.location="shopping_chart.php";
}

function add_offer_to_cart(product_id)
{
  var requested_quantity = 1*document.getElementById('quantity'+product_id).value;
  var available_quantity = 1*document.getElementById('number_in_stock'+product_id).value;
  
  if (document.getElementById('product_package_option'+product_id) != null)
   {
    product_package_option_id = 1*document.getElementById('product_package_option'+product_id).value;
   } else {
    product_package_option_id = -1;
   }
  
  
  if (requested_quantity > available_quantity)
   {
    alert("Only "+available_quantity+" items left in stock!");
    return false;
   } else {
    var strURL	= "cart_funcs.php";
    var query	= "action=add&product_id="+product_id+"&quantity="+document.getElementById('quantity'+product_id).value+"&product_package_option_id="+product_package_option_id;
    
      if (document.implementation && document.implementation.createDocument)
    {	// Firefox, Mozilla, Netscape
      xmldoc = document.implementation.createDocument("","doc",null);
      xmldoc.load(strURL+"?"+query);
      xmldoc.onload = getOfferResponse;

    } else if (window.ActiveXObject) {	// IE
          xmldoc = new ActiveXObject("Microsoft.XMLDOM");
      xmldoc.async = false;
      xmldoc.load(strURL+"?"+query);
      getOfferResponse();
      }   
   }
  
  

}
