function Ibuy(id,grpid,qryid,ctype)
{
	//req = xmlreq();
	
		var req;
		if (window.XMLHttpRequest)
 		 	{// code for IE7+, Firefox, Chrome, Opera, Safari
 				  req=new XMLHttpRequest();
 			 }
		else
 			 {// code for IE6, IE5
		   		  req=new ActiveXObject("Microsoft.XMLHTTP");
  		 	}
	
		
	if(req)
	{
		req.onreadystatechange = function ()
		{
			if (req.readyState == 4) 
			{
				var res = req.responseXML.getElementsByTagName("basket")[0].childNodes[0].nodeValue;
				var t_qty_new = req.responseXML.getElementsByTagName("t_qty_new")[0].childNodes[0].nodeValue;
				var t_prc_new = req.responseXML.getElementsByTagName("t_price_new")[0].childNodes[0].nodeValue;
				var total_price = req.responseXML.getElementsByTagName("total_price")[0].childNodes[0].nodeValue;
				var total_qty = req.responseXML.getElementsByTagName("total_qty")[0].childNodes[0].nodeValue;
				
			
				
				if (document.getElementById)
				{
					
					my_id = 'ibuy' + id;
				
					
					if(res == 'none')
					{
						document.getElementById(my_id).innerHTML = 'In the cart - <a style="cursor:pointer;" onclick=remove_this(\"'+ id + '\",\"' + grpid + '\",\"' + qryid +'\") >remove</a>';
					}
					
					if(t_qty_new!='none')
					{
						document.getElementById('qty_new').innerHTML = t_qty_new;
					}
					
					if(t_prc_new!='none')
					{
						document.getElementById('price_new').innerHTML = "$ " + t_prc_new;
					}
					
					if(total_price!='none')
					{
						document.getElementById('total_price').innerHTML = "$ " + total_price ;
					}
					
					if(total_qty!='none')
					{
						document.getElementById('total_qty').innerHTML = total_qty ;
					}
				}
			}
		}
		if (ctype == undefined) { ctype = 'stamp'; }
		req.open("GET","/includes/ibuy.php?id=" + id + "&grpid=" + grpid + "&qryid=" + qryid + "&ctype=" + ctype);
		req.send(null);
		
		return false;
	}
	else
	{
		return false;
	}
}
//joseph start added
function remove_this(id, grpid, qryid)
{
	var xmlhttp;
		if (window.XMLHttpRequest)
 		 	{// code for IE7+, Firefox, Chrome, Opera, Safari
 				  xmlhttp=new XMLHttpRequest();
 			 }
		else
 			 {// code for IE6, IE5
		   		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		 	}
	
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
   				 {
   				 	
   				 	
   		 			var res = xmlhttp.responseXML.getElementsByTagName("basket")[0].childNodes[0].nodeValue;
					var t_qty_new = xmlhttp.responseXML.getElementsByTagName("t_qty_new")[0].childNodes[0].nodeValue;
					var t_prc_new = xmlhttp.responseXML.getElementsByTagName("t_price_new")[0].childNodes[0].nodeValue;
					var total_price = xmlhttp.responseXML.getElementsByTagName("total_price")[0].childNodes[0].nodeValue;
					var total_qty = xmlhttp.responseXML.getElementsByTagName("total_qty")[0].childNodes[0].nodeValue;
				
			
				
				
				if (document.getElementById)
				{
					
					my_id = 'ibuy' + id;
					
					if(res == 'none')
					{
						document.getElementById(my_id).innerHTML = '<a style="cursor:pointer" onclick=Ibuy(\"'+ id + '\",\"' + grpid + '\",\"' + qryid +'\")>I Buy</a>';
					}
					else
						document.getElementById(my_id).innerHTML =  res;
					
					if(t_qty_new!='none')
					{
						document.getElementById('qty_new').innerHTML = t_qty_new;
					}
					
					if(t_prc_new!='none')
					{
						document.getElementById('price_new').innerHTML = "$ " + t_prc_new;
					}
					
					if(total_price!='none')
					{
						document.getElementById('total_price').innerHTML = "$ " + total_price ;
					}
					
					if(total_qty!='none')
					{
						document.getElementById('total_qty').innerHTML = total_qty ;
					}
				}
   		 	 }
 	 	}

	xmlhttp.open("GET","/includes/iremove.php?id=" + id + "&ctype=stamp",true);
	xmlhttp.send();
}	
//joseph end added
function detail_Ibuy(id,grpid,qryid,no)
{
	var txt = '';
	Ibuy(id,grpid,qryid,no);
	return false;
}
function Want(sgno,cid,usr,ctype)
{
	req = xmlreq();
	
	if(req)
	{
		if (ctype == undefined) { ctype = 'both'; }
		req.open("GET","/includes/addwantlist.php?sgno=" + sgno + "&country=" + cid + "&userid=" + usr + "&condition=" + ctype);
		req.send(null);
		wid = 'want' + sgno + cid;
		document.getElementById(wid).innerHTML = "In the Wantlist";				
		
		return false;
	}
	else 
	{
		return false;
	}
}
