function update_qty(id, qty,mysel_id)
{	if(id!='')
	{
		document.getElementById('div_qty_'+id).style.display = "none";
		document.getElementById('div_qty_proc_'+id).style.display = "block";
		http = createRequestObject();
	  var url='/select.php?update='+id+'&qty='+qty+'&mysel_id='+mysel_id;

	  //http.onreadystatechange = handleResponse; // FF 1.0 and 1.5 do not call it if open(,,false) used
	  http.open("GET", url, false);
	  http.send(null);
	  handleUpdateQtyResponse();
	}
}

function handleUpdateQtyResponse()
{
	if(http.readyState == 4 && http.status == 200)
	{		var xmldoc = http.responseXML;
		var coll = xmldoc.getElementsByTagName('update');
		if(coll.length)
		{
			var id = coll[0].childNodes[0].nodeValue;
			coll = xmldoc.getElementsByTagName('qty')[0].childNodes;
      var qty = coll.length>0 ? coll[0].nodeValue : '';
			coll = xmldoc.getElementsByTagName('subtotal')[0].childNodes;
      var subtotal = coll.length>0 ? coll[0].nodeValue : '';
			coll = xmldoc.getElementsByTagName('total')[0].childNodes;
      var total = coll.length>0 ? coll[0].nodeValue : '';
			coll = xmldoc.getElementsByTagName('msg')[0].childNodes;
      var msg = coll.length>0 ? coll[0].nodeValue : '';

			document.getElementById('qty_'+id).value = qty;
			document.getElementById('subtotal_'+id).innerHTML = subtotal;
			document.getElementById('total').innerHTML = total;

			document.getElementById('div_qty_proc_'+id).style.display = "none";
			document.getElementById('div_qty_'+id).style.display = "block";
			if(msg!='')
				alert(msg);
		}
		else
			alert('Error occured! Please refresh page');
		delete http;
	}
}

function deselect_article(id,mysel_id)
{
	if(id!='')
	{
		document.getElementById('del_btn_'+id).innerHTML = "Removing...";
		http = createRequestObject();
	  var url='/select.php?del='+id+'&mysel_id='+mysel_id;

	  //http.onreadystatechange = handleResponse; // FF 1.0 and 1.5 do not call it if open(,,false) used
	  http.open("GET", url, false);
	  http.send(null);
	  handleDeselectResponse();
	}
}

function handleDeselectResponse()
{
	if(http.readyState == 4 && http.status == 200)
	{
		var xmldoc = http.responseXML;
		var coll = xmldoc.getElementsByTagName('del');
		if(coll.length)
		{
			var id = coll[0].childNodes[0].nodeValue;
			coll = xmldoc.getElementsByTagName('total')[0].childNodes;
      var total = coll.length>0 ? coll[0].nodeValue : '';

			var tr = document.getElementById('tr_'+id);
			tr.parentNode.deleteRow(tr.rowIndex);
			document.getElementById('total').innerHTML = total;
		}
		else
			alert('Error occured! Please refresh page');
		delete http;
	}
}

var http = false;

function createRequestObject()
{
   var req;
   if(window.XMLHttpRequest)
   {
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   }
   else if(window.ActiveXObject)
   {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   }
   else
   {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }
   return req;
}


