function gw_prepareForm(mod_id){if(!document.getElementById){return;}
if(!document.getElementById("WeatherForm"+mod_id)){return;}
document.getElementById("WeatherForm"+mod_id).onsubmit=function(){return gw_submitform(mod_id,0);};}
function gw_submitform(mod_id,go){var form=document.getElementById("WeatherForm"+mod_id)
var data="";for(var i=0;i<form.elements.length;i++){if(go!=1&&form.elements[i].name=='gw_a'&&form.elements[i].value==''){return false;}
data+=form.elements[i].name;data+="=";if(form.elements[i].name=='gw_a'&&go==1){data+=escape(eval('default_location'+mod_id));go=0;}else{data+=escape(form.elements[i].value);}
data+="&";}
data+="process=1";var unit=document.getElementById('temp_unit'+mod_id).value;if(unit=='US')data+="&toF=1";else if(unit=='SI')data+="&toC=1";return!gw_sendData(mod_id,data);}
function gw_toF(mod_id){var a=document.getElementById('str_gw_a_org'+mod_id).value;document.getElementById('temp_unit'+mod_id).value='US';gw_sendData(mod_id,'process=1&toF=1&gw_a='+escape(a));}
function gw_toC(mod_id){var a=document.getElementById('str_gw_a_org'+mod_id).value;document.getElementById('temp_unit'+mod_id).value='SI';gw_sendData(mod_id,'process=1&toC=1&gw_a='+escape(a));}
function gw_sendData(mod_id,data){var request=gw_getHTTPObject();if(request){gw_displayLoading(mod_id,document.getElementById("gw_loading"+mod_id));request.onreadystatechange=function(){gw_parseResponse(request,mod_id);};url=eval('gw_lib_url'+mod_id)+"?"+data
+"&label_city="+escape(eval('label_city'+mod_id))
+"&popup_city="+escape(eval('popup_city'+mod_id))
+"&popup_deg_F="+escape(eval('popup_deg_F'+mod_id))
+"&popup_deg_C="+escape(eval('popup_deg_C'+mod_id))
+"&size_city="+eval('size_city'+mod_id)
+"&hide_input="+eval('hide_input'+mod_id)
+"&hide_humidity="+eval('hide_humidity'+mod_id)
+"&hide_wind="+eval('hide_wind'+mod_id)
+"&hide_forecast="+eval('hide_forecast'+mod_id)
+"&lang="+eval('lang'+mod_id)
+"&request_interval="+eval('request_interval'+mod_id)
+"&mod_id="+mod_id
+"&googleweather_unit="+eval('googleweather_unit'+mod_id)
+"&use_curl="+eval('googleweather_use_curl'+mod_id)
+"&default_location="+escape(eval('default_location'+mod_id));request.open("GET",url,true);request.send(null);return true;}else{return false;}}
function gw_parseResponse(request,mod_id){if(request.readyState==4){if(request.status==200||request.status==304){var container=document.getElementById("googleWeather_container"+mod_id);container.innerHTML=request.responseText;var myRegExp=/No such city/;var str=request.responseText;var matchPos1=str.search(myRegExp);var a=document.getElementById('str_gw_a'+mod_id);var set_focus=eval('focus_on_city'+mod_id);if(set_focus==1){if(a.type!='hidden'){if(matchPos1==-1){a.value='';a.focus();}else{a.focus();a.select();}}}
gw_prepareForm(mod_id);}}}
function gw_getHTTPObject(){var xhr=false;if(window.XMLHttpRequest){xhr=new XMLHttpRequest();}else if(window.ActiveXObject){try{xhr=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xhr=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){xhr=false;}}}
return xhr;}
function gw_displayLoading(mod_id,element){if(element==null)return;var image=document.createElement("img");image.setAttribute("src",eval('gw_progress_gif'+mod_id));image.setAttribute("alt","Loading...");element.appendChild(image);}
