function _gel(id)
{
	return document.getElementById(id);
}

function XHConn()
{
	var xmlhttp;
	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)
	{
		if (!xmlhttp) return 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) {
				fnDone(xmlhttp); }};
			xmlhttp.send(sVars);
		}
		catch(z) { return false; }
		return true;
	};
	return this;
}

var buff = null;
var timer = null;
function rpcProduct(frmobj)
{
    if(frmobj){
		var productid = frmobj.ProductID.value;
		var propertyid = frmobj.PropertyID.value;
		var quantity = frmobj.Quantity.value;
		var price = frmobj.Price.value;
	}
/*
	if(buff == str){ return; }
	buff = str;
 	if(str.length < 3){
		_gel("resultat").style.display = "none";
		return;
	}
*/
/*	
	if(timer != null){
		clearTimeout(timer);
		timer = null;
	}
	timer = setTimeout("doSearch(\""+str+"\")",500);
*/
	addProduct(productid,propertyid,quantity,price);
}
function addProduct(productid,propertyid,quantity,price)
{
	var myConn = new XHConn();
	var strQueryString = "";
	if (!myConn) {
		alert('Fel');
	} else {
		var fnWhenDone = function (oXML) { showresults(oXML.responseText); };	 
		if(productid && propertyid && quantity && price)
			strQueryString = "ProductID="+productid+"&PropertyID="+propertyid+"&Quantity="+quantity+"&Price="+price;
		myConn.connect("modules/basket/basket.content.php", "POST", strQueryString, fnWhenDone);
	}
}
function showresults(resultat)
{	
	res = _gel("resultat");
	bgcolor = "";
	
	if(resultat.length < 2){
		_gel("resultat").style.display = "none";
		return;
	}
	res.innerHTML = "";
	_gel("resultat").style.display = "block";
	resultat = resultat.split("|");

/*
	res.innerHTML = "<div><table cellpadding='2' cellspacing='0' width='100%' border='1'>";
	for(x=0;x<resultat.length;x++){
		arr = resultat[x].split(";");
		
		if(x % 2)
			bgcolor="";
		else
			bgcolor="#fafafa";

//		res.innerHTML += "<div style='border-bottom:1px solid #ccc;padding:2px;cursor:pointer; font-size: 9px;' onmouseover='this.style.background=\"#ff9\";' onmouseout='this.style.background= \"none\";'><div style='width:30px;'>"+arr[0]+" st</div><div style='width:120px;'>"+arr[1]+"</div><div style='width:30px;'>"+arr[2]+"</div></div>";
		res.innerHTML += "<tr bgcolor='"+bgcolor+"'><td class='smalltext' valign='top'><nobr>"+arr[0]+" st</nobr></td><td class='smalltext' width='100%'>"+arr[1]+"</td><td class='smalltext' valign='top' align='right'><nobr>"+arr[2]+" kr</nobr></td></tr>";
	}
	res.innerHTML += "</table></div>";
*/

	res.innerHTML = resultat;
}
