var locID = "";
var language = 0;
var pid = 0;

window.addOnload = function(fn) {
	if (!window.OnloadCache) window.OnloadCache = [];
	var ol = window.OnloadCache;
	ol[ol.length] = fn;
}

window.onload = function() {
	var ol = window.OnloadCache;
	if (ol)
		for (var x = 0; x < ol.length; x++)
			this.action = ol[x]();
}

function showWeatherDetails ( input, selection ) {
 if (selection.getAttribute("locid")!=undefined) {
   locID=selection.getAttribute("locid");
   }
  new Ajax.Request("index.php",
				          {  method: 'post',
  						  	 asynchronous:true, 
					   	     postBody: "id="+pid+"&type=445&no_cache=1&tx_weatherfinder_pi1[a]=queryWeather&L="+language+"&tx_weatherfinder_pi1[value]="+locID,
							 onSuccess: function (t) { $("weather-results").innerHTML=t.responseText; },
							 onFailure: function (t) { }
	  					   }
  )
}

function init () { 
  new Ajax.Autocompleter("weather-search-input", 
                         "weather-choices",
						 "index.php?id="+pid+"&type=445&no_cache=1&tx_weatherfinder_pi1[a]=queryLocation&L="+language,
                         {paramName: "tx_weatherfinder_pi1[value]", 
                          minChars: 2, 
						  frequency: 0.8,
                          afterUpdateElement: showWeatherDetails,
                          indicator: "weather-busy-indicator"});
  pid = $("weather-pid").value;
  language = $("weather-lang-id").value;
  $("weather-search-input").focus();
}

window.addOnload(init);