// qm_count.js 7/22/2010 (c) Copyright by Carl Gorringe <carl at gotalift.com>. Created for 511.org. DO NOT REDISTRIBUTE.

var QM_baseURL = "http://rideshare.511.org/quickmatch/";
var QM_baseEngine = "http://rideshare.511.org/quickmatch/cgi-bin/qm_count.pl";

var QM_from_ready,QM_to_ready,QM_cgi_flat,QM_cgi_flon,QM_cgi_tlat,QM_cgi_tlon,QM_cgi_f,QM_cgi_t,QM_cgi_a,QM_cgi_z,QM_cgi_ref,QM_fillF,QM_fillT,QM_fillC,QM_timer;var QM_err1="Geocoding Error (unknown)";var QM_err2="Please inform the webmaster that the Google API Key is improperly set.";var QM_err3="Please enter a city or zipcode in both the Start and End fields.";var QM_err4="<br/><br/>Server timed out.<br/>Try searching again.";var QM_err5="<br/><br/>Search failed.<br/>Try searching again.";function QM_$(A){return document.getElementById(A)}function QM_eURI(A){return encodeURIComponent(A)}String.prototype.rtrim=function(){return this.replace(/\s\s*$/,"")};function QM_getGeocode(D,C){var A="http://maps.google.com/maps/geo?q="+QM_eURI(D)+"&gl=us&sensor=false&output=json&key="+QM_gkey+"&callback="+QM_eURI(C);var B=document.createElement("script");B.type="text/javascript";B.src=A;document.body.appendChild(B)}function QM_updateFrom(B){if(!B){alert(QM_err1)}else{if(B.Status.code==610){alert(QM_err2)}else{if(B.Status.code!=200){alert(QM_err3+" (code "+B.Status.code+")")}else{var A=B.Placemark[0];document.QM_frm.f.value=A.address;document.QM_frm.flat.value=A.Point.coordinates[1];document.QM_frm.flon.value=A.Point.coordinates[0];QM_from_ready=true}}}}function QM_updateTo(B){if(!B){alert(QM_err1)}else{if(B.Status.code==610){alert(QM_err2)}else{if(B.Status.code!=200){alert(QM_err3+" (code "+B.Status.code+")")}else{var A=B.Placemark[0];document.QM_frm.t.value=A.address;document.QM_frm.tlat.value=A.Point.coordinates[1];document.QM_frm.tlon.value=A.Point.coordinates[0];QM_to_ready=true}}}}function QM_lookupFrom(){var A=document.QM_frm.f.value;document.QM_frm.flat.value="";document.QM_frm.flon.value="";if((A.rtrim()!="")&&A!=QM_fillF){A+=", CA, US";QM_getGeocode(A,"QM_updateFrom")}}function QM_lookupTo(){var A=document.QM_frm.t.value;document.QM_frm.tlat.value="";document.QM_frm.tlon.value="";if((A.rtrim()!="")&&A!=QM_fillT){A+=", CA, US";QM_getGeocode(A,"QM_updateTo")}}function QM_submitEvenLater(){document.QM_frm.submit()}function QM_submitLater(){if(!QM_from_ready||!QM_to_ready){setTimeout("QM_submitEvenLater()",1000)}else{document.QM_frm.submit()}}function QM_submitForm(){if(document.QM_frm.flat.value==""){QM_from_ready=false;QM_lookupFrom()}if(document.QM_frm.tlat.value==""){QM_to_ready=false;QM_lookupTo()}if(!QM_from_ready||!QM_to_ready){setTimeout("QM_submitLater()",750);return false}return true}function QM_doSubmit(){var C="QM_doResults";if((document.QM_frm.flat.value=="")||(document.QM_frm.tlat.value=="")){alert(QM_err3);return }QM_cgi_flat=parseFloat(document.QM_frm.flat.value);QM_cgi_flon=parseFloat(document.QM_frm.flon.value);QM_cgi_tlat=parseFloat(document.QM_frm.tlat.value);QM_cgi_tlon=parseFloat(document.QM_frm.tlon.value);QM_cgi_a=parseInt(document.QM_frm.a.value);QM_cgi_z=parseInt(document.QM_frm.z.value);QM_cgi_ref=document.QM_frm.ref.value;QM_$("QM_panel1").style.display="none";QM_$("QM_panel2").style.display="";QM_$("QM_resultsText").style.display="none";QM_$("QM_resultsNum").innerHTML="?";QM_$("QM_errorText").innerHTML="";var A=QM_baseEngine+"?flat="+QM_eURI(QM_cgi_flat)+"&flon="+QM_eURI(QM_cgi_flon)+"&tlat="+QM_eURI(QM_cgi_tlat)+"&tlon="+QM_eURI(QM_cgi_tlon)+"&ref="+QM_eURI(QM_cgi_ref)+"&callback="+QM_eURI(C);if(QM_cgi_a>0){A+="&a="+QM_eURI(QM_cgi_a)}if(QM_cgi_z>0){A+="&z="+QM_eURI(QM_cgi_z)}QM_timer=setTimeout(function(){QM_$("QM_resultsText").style.display="none";QM_$("QM_resultsNum").innerHTML="?";QM_$("QM_errorText").innerHTML=QM_err4;QM_$("QM_panel2").style.display="none";QM_$("QM_panel3").style.display=""},10000);var B=document.createElement("script");B.type="text/javascript";B.src=A;document.body.appendChild(B)}function QM_doResults(A){QM_$("QM_panel2").style.display="none";QM_$("QM_panel3").style.display="";if(QM_timer){clearTimeout(QM_timer)}if(A&&A.total){var B=parseInt(A.total);QM_$("QM_resultsText").style.display="";QM_$("QM_resultsNum").innerHTML=B;QM_$("QM_errorText").innerHTML=""}else{QM_$("QM_resultsText").style.display="none";QM_$("QM_resultsNum").innerHTML="?";QM_$("QM_errorText").innerHTML=QM_err5}}function QM_resetForm(){QM_$("QM_panel2").style.display="none";QM_$("QM_panel3").style.display="none";QM_$("QM_panel1").style.display="";QM_$("QM_f").style.color=QM_fillC;QM_$("QM_t").style.color=QM_fillC;document.QM_frm.f.value=QM_fillF;document.QM_frm.t.value=QM_fillT;document.QM_frm.flat.value="";document.QM_frm.flon.value="";document.QM_frm.tlat.value="";document.QM_frm.tlon.value=""}if(typeof XMLHttpRequest=="undefined"){XMLHttpRequest=function(){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(A){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(A){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(A){}try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(A){}}}document.QM_frm.f.onchange=QM_lookupFrom;document.QM_frm.t.onchange=QM_lookupTo;document.QM_frm.onsubmit=QM_submitForm;QM_fillF=document.QM_frm.f.value;QM_fillT=document.QM_frm.t.value;QM_fillC=QM_$("QM_f").style.color;QM_resetForm();
