// $Id
// vi:ts=2 sw=2 expandtab

function callAjax(url, responseFunc)
{
  var xmlHttp;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch (e) {
    // Internet Explorer
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {
        //alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange = function() {
    /*
     * 0 : The request is not initialized
     * 1 : The request has been setup
     * 2 : The request has been sent
     * 3 : The request is in process
     * 4 : The request is complete
     */
    if (xmlHttp.readyState == 4) {
      // Request is complete
      responseFunc(xmlHttp.responseXML, xmlHttp.responseText);
    }
  }
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}

function update_cart_display(xml, text)
{
  var sc = document.getElementById('shopping_cart');
  if (null == sc) return;

  var cart_total = parseFloat(text);
  if (!isNaN(cart_total) && cart_total > 0) {
    sc.innerHTML = '<a href="/cart.cgi">Shopping Cart: &#163; '
      + cart_total + '</a>';
  }
  else if (text != '') {
    sc.innerHTML = text;
  }
}

function show_cart_total()
{
  callAjax('/cart.cgi?get_cart_info_html=1', update_cart_display);
}

