//
function initHotelZoek(e) {
	var hd;
	hd = xGetElementById("destination"); // Hotel destination

	if (hd != null) {
		this.hdData = new function() {
			var rsXML = {
					resultNode: "item", 
					fields: [
						{ key: 'naam' },
						{ key: 'gebied' },
						{ key: 'url' }
					],
					metaNode: "resultset"
				};

			var rsJS = {
					fields: ["naam","gebied","url"]};

			var rsText = {
						recordDelim: "\n",
						fieldDelim: "\t"
					};

			// first build a datasource
			var hdServer = "/ajax/hdsearch2.php";
			var hdDataSource = new YAHOO.util.XHRDataSource(hdServer);
			hdDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
			hdDataSource.responseSchema = rsXML;

			/*
			hdDataSource.doBeforeParseData = function(oRequest, oFullResponse, oCallback) {
str = inspect(oFullResponse);//.responseXML);
			alert(str);
				return oFullResponse;
			}
			*/

			//this.autoComplete = new YAHOO.widget.AutoComplete("destination", "destinationList", hdDataSource);
			this.autoComplete = new YAHOO.widget.AutoComplete("destination", "hotelAC", hdDataSource);
			this.autoComplete.resultTypeList = false;
			this.autoComplete.prehighlightClassName = "yui-ac-prehighlight";
			this.autoComplete.typeAhead = false;
			this.autoComplete.maxResultsDisplayed = 10;
			this.autoComplete.useShadow = true;
			this.autoComplete.allowBrowserAutocomplete = false;

			// format Results
			this.autoComplete.formatResult = function(oResultItem, sQuery, sResultMatch) {
				var naam = oResultItem.naam;
				var gebied = oResultItem.gebied;
				var url = oResultItem.url;
				var attribute1 = oResultItem[0];
				var attribute2 = oResultItem[1];
	
				/* parse text
				var aMarkup = [
					attribute1,
					"<span>",
					attribute2,
					"</span>"];

				return (aMarkup.join(""));
				*/
				var aMarkup = [
					"<a style='margin:0;font-weight:bolder;' href='",
					url,
					"'>",
					naam,
					"</a>",
					"<span>",
					gebied,
					"</span>"];

				return (aMarkup.join(""));
			}
		}
	}

	initStdInput(['dq','dqw'],['what','where']);
	initStdSubmit('dagjeuitzoeken',['dq','dqw'],['what','where']);
}

YAHOO.util.Event.addListener(window, 'load', initHotelZoek);
