function add_to_cart(product,amount,button)
{
var b=document.getElementById(button);
b.value="Working...";
	
var num=document.getElementById(amount).value;
var ajaxConn = new XHConn();
	
ajaxConn.connect("/?p=ajax&action=add_to_cart", "POST", "amount="+num+"&product="+product,addedToCart,product);
}

function addedToCart(XML,custom)
{
var b=document.getElementById("add"+custom);
	
if(XML.responseText=="0")
	{
	document.getElementById("amount"+custom).value="1";
	b.value="Add to Cart";
	}
else
	b.value="Update Cart";
}

function shipping()
{
	document.location.href="/?p=shipping";
}

function show_gst()
{
var l=document.getElementById("ship_to_country");
//if(l.selectedIndex!=-1 && l.options[l.selectedIndex].value=="CAN")
	document.getElementById("cart").submit();
}

function togglemt(id,id2,start_image,start_text,other_image,other_text)
{
var e=document.getElementById(id);
var e2=document.getElementById(id2);
if(e2.value==start_text)
	{
	e.src=other_image;
	e2.value=other_text;
	}
else
	{
	e.src=start_image;
	e2.value=start_text;
	}
}

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone, fnCustom)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();
    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp,fnCustom);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

