Event.observe(window,"load",init);function init(){$("zipSearchForm").focusFirstElement()}function doSearch(){var A=$("txt_zipcode").getValue();var D=$("txt_city").getValue();var B=$("txt_state").getValue();var C=/^\d{5}$/;if(C.test(A)){$("txt_city").clear();$("txt_state").clear();getLocations(A)}else{if(A.length>0){alert("Please enter a valid 5 digit zipcode...")}else{if(D.length==0&&B.length==0){alert("Please enter a city, city and state, or a zipcode...")}else{if(D.length==0&&B.length>0){alert("Please enter a city...")}else{getZipFromYahoo(D,B)}}}}return false}function getZipFromYahoo(C,B){var A="proxy.php?url=http://local.yahooapis.com/MapsService/V1/geocode&params=appid-location_search,city-"+C+",state-"+B+",zip-00000&isXML=true";new Ajax.Request(A,{method:"get",onCreate:showLoading,onComplete:function(F){var I=F.responseXML.documentElement;var L=I.getElementsByTagName("Result");var H=new Array();$("loading").style.display="none";$("multipleCities").style.display="none";if(L[0].childNodes.length==0){showError();return }if(L.length==1&&L[0].getAttribute("precision")=="zip"){try{$("txt_zipcode").value=I.getElementsByTagName("Zip")[0].firstChild.nodeValue;$("txt_city").value=I.getElementsByTagName("City")[0].firstChild.nodeValue;$("txt_state").value=I.getElementsByTagName("State")[0].firstChild.nodeValue;getLocations(I.getElementsByTagName("Zip")[0].firstChild.nodeValue)}catch(E){showError();return }}else{if(L.length>1){$("multipleCities").update();try{for(var G=0;G<L.length;G++){var J=I.getElementsByTagName("City")[G].firstChild.nodeValue;var K=new RegExp(C,"i");if(K.test(J)){H.push({city:J,state:I.getElementsByTagName("State")[G].firstChild.nodeValue,zip:I.getElementsByTagName("Zip")[G].firstChild.nodeValue})}}}catch(E){showError();return }if(H.length>0){var M=new Template("<div><a href=\"javascript:void(0)\" onclick=\"onCitySelect('#{city}', '#{state}', #{zip})\">#{city}, #{state} #{zip}</a></div>");var D=new String();D+="<p>"+H.length+(H.length==1?" city":" cities")+" found.  Please select one below:</p>";H.each(function(N){D+=M.evaluate(N)});$("multipleCities").update(D);$("multipleCities").style.display="block"}else{showError()}}else{showError()}}}})}function onCitySelect(C,B,A){$("txt_city").value=C;$("txt_state").value=B;$("txt_zipcode").value=A;$("multipleCities").update();$("multipleCities").style.display="none";getLocations(A)}function getLocations(B){var A="proxy.php?url=http://scanbox.pharmacy.com/cgi-bin/locationsByZipcode.pl&params=zip-"+B+"&isXML=true";new Ajax.Request(A,{method:"get",onCreate:showLoading,onComplete:displayResults})}function displayResults(E){$("loading").style.display="none";$("multipleCities").style.display="none";var H=E.responseXML.documentElement;if(!H.hasChildNodes()){showError();return }var J=H.getElementsByTagName("search");var B=H.getElementsByTagName("location");var C=new Array();var G=new Array();for(var F=0;F<J.length;F++){C.push({county:H.getElementsByTagName("county")[F].firstChild.nodeValue,zipcode:H.getElementsByTagName("zipcode")[F].firstChild.nodeValue,city:H.getElementsByTagName("city")[F].firstChild.nodeValue,state:H.getElementsByTagName("state")[F].firstChild.nodeValue})}for(var F=0;F<B.length;F++){G.push({number:H.getElementsByTagName("number")[F].firstChild.nodeValue,name:H.getElementsByTagName("name")[F].firstChild.nodeValue,htmlName:encodeURIComponent(H.getElementsByTagName("name")[F].firstChild.nodeValue.replace(/\'/g,"")),address:H.getElementsByTagName("address")[F].firstChild.nodeValue,htmlAddress:encodeURIComponent(H.getElementsByTagName("address")[F].firstChild.nodeValue),city:H.getElementsByTagName("city")[F+1].firstChild.nodeValue,htmlCity:encodeURIComponent(H.getElementsByTagName("city")[F+1].firstChild.nodeValue),state:H.getElementsByTagName("state")[F+1].firstChild.nodeValue,zipcode:H.getElementsByTagName("zipcode")[F+1].firstChild.nodeValue,phone:(H.getElementsByTagName("phone")[F].firstChild.nodeValue).replace(/\./g,"-"),distance:H.getElementsByTagName("distance")[F].firstChild.nodeValue})}var I=new Template('<div class="zipInfo">    <p>Locations near:  <span>#{city}, #{state} #{zipcode} (#{county} County)</span></p></div>');var D=new Template('<div id="loc-#{number}" class="locationInfo">    <p><span class="name">#{number} - #{name}</span><span class="distance">(#{distance} miles)</span></p>    <p>#{address}</p>    <p>#{city}, #{state} #{zipcode}</p>    <p>        <span class="options">            <a class="map" href="proxy.php?url=http://65.208.108.14:9080/zipsearch/map.jsp&params=number-#{number},name-#{htmlName},address-#{htmlAddress},city-#{htmlCity},state-#{state},zipcode-#{zipcode}" target="mapWindow" onclick="return openMap(this)">View Map</a>            <a class="contact" href="javascript:void(0)" onclick="toggleContactForm(#{number}, true)">Contact Location</a>        </span>        #{phone}    </p></div>');var A=I.evaluate(C[0]);G.each(function(K){A+=D.evaluate(K)});$("searchResults").update(A)}function toggleContactForm(E,B){if(B){if($("contactForm")!=null){return }}var A=$$(".locationInfo");var F;for(var D=0;D<A.length;D++){if(A[D].id!=("loc-"+E)){B?A[D].hide():A[D].show()}else{F=A[D]}}if(B){var C="proxy.php?url=http://65.208.108.14:9080/zipsearch/contact.jsp&params=number-"+E;new Ajax.Updater(F,C,{method:"get",insertion:"after",onCreate:function(){$("loading").style.display="inline"},onComplete:function(G){$("loading").style.display="none";new Rotech.InputMask("txt_pphone","999-999-9999")}})}else{$("contactForm").remove()}}function submitContactForm(E){var C=$("txt_pname").value;var B=$("txt_pemail").value;var A=$("txt_pphone").value;var G=/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;var D=/^[2-9]\d{2}-\d{3}-\d{4}$/;if(C.length==0||C==""){alert("Please enter your name...")}else{if(B.length==0&&A.length==0){alert("Please enter a valid email and/or phone number...")}else{if(B.length>0&&!G.test(B)){alert("Please enter a valid email address (e.g. john.smith@company.com)...")}else{if(A.length>0&&!D.test(A)){alert("Please enter a valid phone number...")}else{A=A.gsub("-","");var F=$("contactForm").serialize();F=F.replace(/\&pphone=\d{3}-\d{3}-\d{4}/,"&pphone-"+A);F=F.replace(/=/g,"-");F=F.replace(/&/g,",");$("contactForm").action="proxy.php?url=http://65.208.108.14:9080/zipsearch/contact.jsp&params="+F;$("contactForm").request({onComplete:function(H){$("contactForm").remove();Element.insert($("loc-"+E),{after:H.responseText})}})}}}}return false}function openMap(B){var A=window.open(B.href,B.target,"width=620,height=620,toolbar=no,location=no,resizable=no,status=no,menubar=yes,scrollbars=no,titlebar=yes");A.focus();return false}function resetSearch(){$("zipSearchForm").reset();$("searchResults").update();$("loading").style.display="none";$("multipleCities").style.display="none"}function showLoading(){$("searchResults").update();$("loading").style.display="inline"}function showError(){$("searchResults").update('<p class="error">No locations found. Please try again...</p>')}