/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e2) {
      xmlHttp = false;
    }
  }
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

var mouseX;
var mouseY;

function getCoord( event ) {
   mouseX = event.pageX;
   mouseY = event.pageY;
}

if( document.all ) { 
 } else if( document.getElementById ) {
  document.captureEvents( Event.MOUSEMOVE );
  document.onmousemove = getCoord;
}



/*Put Item into basket*/
var c_product_price;
var c_product_quantity;
var c_product_tprice;
var c_product_name;
var c_section_name;
var c_product_id_remove;

function PutItemIntoCart(id, price, product_pack, product_name, section_name, quantity){
  if(quantity.search('[0-9]+') == -1) quantity = 1;
  if(!quantity) quantity = 1;
  if(!price) price = 0;  
  if(!product_name) product_name = '';
  if(!section_name) section_name = '';

  c_product_id = id;
  c_product_quantity = quantity;
  c_product_price = price;
  c_product_name = product_name;
  c_section_name = section_name;
  c_product_id_remove = null;

  price = quantity * price;
  c_product_tprice = price;


  // Build the URL to connect to
  if(product_pack)
	var url = "/p_inventory/d_cart.php?action=putItem&id="+id+'&price='+price+'&product_pack='+product_pack+"&name="+product_name+"&section_name="+section_name+"&quantity="+quantity;
  else
	var url = "/p_inventory/d_cart.php?action=putItem&id="+id+'&price='+price+"&name="+product_name+"&section_name="+section_name+"&quantity="+quantity;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updateCart;
  xmlHttp.send(null);
}

/*Remove Item From basket*/
function RemoveItemFromCart(id){
  // Build the URL to connect to
  var url = "/p_inventory/d_cart.php?action=removeItem&id="+id;
  c_product_id = null;
  c_product_id_remove = id;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updateCart;
  xmlHttp.send(null);
}


function updateCart() {
  if (xmlHttp.readyState == 4) {
      var response = xmlHttp.responseText;
	  if(response == '0') {alert('This product already in cart.');return;}
 	  response = response.split("=");
 	  try{
    	  document.getElementById("cartStat_count").innerHTML = response[0] + ' it.';
	      document.getElementById("cartStat_price").innerHTML = '$' + response[1];
	  }catch (e) {}
  }
}
