/* 
 * Search Ajax Javascript
 *
 */
YAHOO.example.RemoteCustomRequest = function() {
	var oDS = new YAHOO.util.XHRDataSource("/api/address-lookup.asp");
	oDS.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
	oDS.responseSchema = { resultsList: "ResultSet.Results", fields: ["location", "id", "cid"] };
	var oAC = new YAHOO.widget.AutoComplete("sl_main", "sl_complete", oDS);
	oAC.queryDelay = 0.1;
	oAC.forceSelection = true; 
	oAC.typeAhead = false; 
	var mySearchPlace = YAHOO.util.Dom.get("slp");
	var mySearchCode = YAHOO.util.Dom.get("slc");
	var myHandler = function(sType, aArgs) {
		var myAC = aArgs[0]; // reference back to the AC instance 
		var elLI = aArgs[1]; // reference to the selected LI element 
		var oData = aArgs[2]; // object literal of selected item's result data
		// update hidden form field with the selected item's ID
		if (oData[1] != 0) {
			mySearchPlace.value = oData[1];
		}
		if (oData[2] != 0) {
			mySearchCode.value = oData[2];
		}		
	};
	oAC.itemSelectEvent.subscribe(myHandler);
	return { oDS: oDS, oAC: oAC };
} ();

function fncExpand(strElement) {
	document.getElementById('searchadvimg').src = (document.getElementById(strElement).style.display != 'block')? '/images/icons/minus.gif' : '/images/icons/plus.gif'	
	document.getElementById(strElement).style.display = (document.getElementById(strElement).style.display != 'block')? 'block' : 'none';	
	document.getElementById('d').value = (document.getElementById('d').value != 1)? '1' : '0';	
	return true;
}		

function fncSubmit(theForm) {
	if (theForm.sl_main.value == '' && theForm.ci.value == '' & theForm.gi.value == '') {
		alert('You must enter a location or postcode!');
		theForm.sl_main.focus();
		return false;
	}
	return true;
}

