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();
}

function showCartForm() {
Obj=document.getElementById('cart_form');	
Obj.style.display = 'block';
}

function SubBox(id) {
 subid="sub_"+id;
 imgid="img1_"+id;
 upd_v="TreeElement_"+id;
 
 contextMenuObj=document.getElementById(subid);
 contextMenuImg=document.getElementById(imgid);

 if (contextMenuObj.style.display == 'block') {
 contextMenuObj.style.display = 'none';
 contextMenuImg.src='http://www.ajax-spb.ru/images/icons/plus.gif'; 
 serverUpdateSession(upd_v,0);
 }
 else {
 contextMenuObj.style.display = 'block';
 contextMenuImg.src='http://www.ajax-spb.ru/images/icons/minus.gif';
 serverUpdateSession(upd_v,1); 
 }
 
 return true;
}


function serverUpdateSession(variable,value) {
  var url = "http://www.ajax-spb.ru/updateSession.php?var=" + variable + "&value=" + value;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);
}

function serverAddToCart(product_id,product_qty) {
  var url = "http://www.ajax-spb.ru/updateShoppingCart.php?action=add_to_cart&product_id=" + product_id + "&product_qty=" + product_qty;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = shoppingCartTotalUpdate;
  xmlHttp.send(null);
}
function updateCartItemQty(product_id,product_qty) {
  var url = "http://www.ajax-spb.ru/updateShoppingCart.php?action=update_cart_item_qty&product_id=" + product_id + "&product_qty=" + product_qty;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = shoppingCartTableUpdate;
  xmlHttp.send(null);
}
function serverDeleteFromCart(product_id) {
  var url = "http://www.ajax-spb.ru/updateShoppingCart.php?action=delete_from_cart&product_id=" + product_id;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = shoppingCartTableUpdate;
  xmlHttp.send(null);
}

function updatePage() {
 
}

function shoppingCartTotalUpdate() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
Obj=document.getElementById('shoppingCartTotal');
Obj.innerHTML=response;
 }
}

function shoppingCartTableUpdate() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
Obj=document.getElementById('table_with_cart_items');
Obj.innerHTML=response;
 }
}