function isCanadaOrUSpostal(postal) { if (postal.match(/^\d{5}$/)) return 'US'; else if (postal.toUpperCase().match(/^[A-Z]{1}\d{1}[A-Z]{1}[ -\.]{0,1}\d{1}[A-Z]{1}\d{1}$/)) return 'CA'; else return false; } window.addEvent('domready', function(){ if($('breakfastLocatorForm') != null) { $('breakfastLocatorForm').addEvent('submit', function(e){ new Event(e).stop(); // variables setup var url = ''; var zip = $('zipCode').value; var addr = ''; var city = ''; var st = ''; var radius = 5; var country = isCanadaOrUSpostal(zip); // test zip validation if (!zip || zip == '' || isCanadaOrUSpostal(zip) == false) { $('errorInZip').innerHTML = 'Please enter a valid zip'; $('errorInZip').setStyle('display', 'block'); return; } else { $('errorInZip').innerHTML = ''; $('errorInZip').setStyle('display', 'none'); } // setup URL url += 'advantagecallback.jsp'; url += '?transaction=search'; url += '&pWidth=400'; url += '&iconID=31'; url += '&proxIconId=400'; url += '&ambiguities=0'; url += '&postalCode=' + zip; url += '&radius=' + radius; url += '&address=' + addr; url += '&city=' + city; url += '&state=' + st; url += '&country=' + country; return open(url, "a", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=830,height=700"); }); } });