var xmlHttp, addlink

function rewrite(id) {
	var targ = document.getElementById(id)
	targ.innerHTML = targ.innerHTML
}

function addToCart(id, caller) {

	caller.style.display = 'none'
	addlink	= document.createElement('DIV')
	caller.parentNode.insertBefore(addlink,caller.nextSibling)
	addlink.innerHTML = '<img src="/images/loading.gif" alt="Adding to cart" style="float:none" />'
	var url = '/addtocart.php?id=' + id
	xmlHttp=GetXmlHttp()
	xmlHttp.onreadystatechange=addToCartDone 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)	
}

function addToCartDone() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		var num = xmlHttp.responseText
		addlink.innerHTML = '<img src="/images/tick.png" alt="Added to cart" style="float:left" />Added to cart<br/><a href="/cart">View Cart</a>'
	}
}

function GetXmlHttp() {
  var xmlhttp = false;
  if (window.XMLHttpRequest)
  {
    xmlhttp = new XMLHttpRequest()
  }
  else if (window.ActiveXObject)// code for IE

  {
    try
    {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
    } catch (e) {
      try
      {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
      } catch (E) {
        xmlhttp=false
      }
    }
  }
  return xmlhttp;
}


function showMenu(object){
	object.nextSibling.style.display="block";
	object.style.backgroundImage =  'url(/assets/minus.gif)';
	object.onclick = new Function("hideMenu(this)");
	
}

function hideMenu(object){
	object.nextSibling.style.display="none";
	object.style.backgroundImage =  'url(/assets/plus.gif)';
	object.onclick = new Function("showMenu(this)");
}