SokAuto = function(id, idc)
{
	this.fnCustomFormatter = function(oResultItem, sQuery) {
			var sText = oResultItem[0];
			var sArtnr = oResultItem[1];
			
			return sText;
	};

	this.id = id;
	
	var myServer = "sokauto.php";
	var mySchema = ["records", "Rslt", "Artikelnr"];
	this.myDataSource = new YAHOO.widget.DS_XHR(myServer, mySchema);
	this.myDataSource.scriptQueryAppend = "";

	this.myAutoComp = new YAHOO.widget.AutoComplete(id, idc, this.myDataSource);
	this.myAutoComp.forceSelection = false;
	this.myAutoComp.typeAhead = false;
	this.myAutoComp.autoHighlight = false;
	this.myAutoComp.maxResultsDisplayed = 20;
	this.myAutoComp.formatResult = this.fnCustomFormatter;
	
	var oThis = this;
	this.myAutoComp.textboxFocusEvent.subscribe(function(){
		var sInputValue = YAHOO.util.Dom.get(oThis.id).value; 
		if (sInputValue.length === 0)
			{
				setTimeout(function(){oThis.myAutoComp.sendQuery(sInputValue);},0);
			}
	});
	this.myAutoComp.itemSelectEvent.subscribe(function(oSelf, elItem, oData) {
		var txt = elItem[2][0];
		var artnr = elItem[2][1];
		window.location.href = "visaenprodukt.php?artnr=" + encodeURIComponent(artnr);
	});
}

function kopplaSokrutor()
{
	new SokAuto("venstersok", "venstersokcontainer");
	var ed = $("venstersok");
	var xy = YAHOO.util.Dom.getXY(ed);
	var y = xy[1] + ed.offsetHeight;
	if (YAHOO.env.ua.ie) y -= 3;
	var div = $("venstersokcontainer");
	div.style.top = y + "px";
	div.style.width = "130px";
}

YAHOO.util.Event.onDOMReady(function() {
	if ($("venstersok") != null) kopplaSokrutor();
});