/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var xmlhttp

function showPage(page, message){
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="show_page.php";
  url=url+"?page="+page;
  url=url+"&message="+message;
  url=url+"&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChanged1;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function showMenuCate(cateId){
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="pages/menu/menu.php";
  url=url+"?cateId="+cateId;
  url=url+"&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChangeSubmenu;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function addToBasket(productID, price_type, customerId){
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="functions/addProduct.php";
  url=url+"?productID="+productID;
  url=url+"&price_type="+price_type;
  url=url+"&customerId="+customerId;
  url=url+"&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChangeBasket;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function addOfferToBasket(offerId, prodStr, customerId){
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="functions/addOfferProduct.php";
  url=url+"?offerId="+offerId;
  url=url+"&prodStr="+prodStr;
  url=url+"&customerId="+customerId;
  url=url+"&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChangeBasket;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function show_basket(){
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="views/show_basket.php";
  url=url+"?sid="+Math.random();
  xmlhttp.onreadystatechange=stateChangeBasket;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function openPayment(basketId, customerId){
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="paymentgateway/index.php";
  url=url+"?basketId="+basketId;
  url=url+"&customerId="+customerId;
  url=url+"&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChanged1;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function stateChanged1(){
  if (xmlhttp.readyState==4){
    document.getElementById("navi_page").innerHTML=xmlhttp.responseText;
  }
}

function stateChangeBasket(){
  if (xmlhttp.readyState==4){
    document.getElementById("basket-content").innerHTML=xmlhttp.responseText;
  }
}

function stateChangeSubmenu(){
  if (xmlhttp.readyState==4){
    document.getElementById("submenu").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject(){
  if (window.XMLHttpRequest){
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject){
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}

