var searchLabelVisible=true;var locationLabelVisible=true;$(function(){$(".location-name").load("/location.php");$("#price-quotes-from-sellers").pricequotesfromsellers();$("#why-chug").show();$("#price-quotes-from-sellers").hide();$("#price-quotes-from-sellers-info").hide();$.chug.user.initUserPanel();initChangeEmail();$("#search").keypress(function(){if(searchLabelVisible){$(".for-search").hide();searchLabelVisible=false}});$("#newlocation").keydown(function(a){if(locationLabelVisible){$(".for-zip").hide();locationLabelVisible=false}if(a.which==13){if(validateIndexForm($(this).closest("form")[0])){$(this).closest("form").submit()}return false}});$("#search").focus()});var lastSearchTerm="";function validateIndexForm(a){var c=a.s.value;var b="";if(a.newlocation){b=a.newlocation.value}if(c.length==0&&b.length==0){return false}if(c.length==0&&b.length>0){a.action="/index.php"}if(c.length>0&&b.length==0){a.action="/results.php"}if(c.length>0&&b.length>0){a.action="/results.php"}return true}function checkSearchTerm(a){if(lastSearchTerm==a){return}lastSearchTerm=a}var _ajax=null;function getPricesCalendar(a){if(_ajax){_ajax.abort()}_ajax=$.ajax({url:"/index.php?action=betterprices&s="+a+"&dma="+dma,dataType:"html",contentType:"application/x-www-form-urlencoded",success:function(b){$("#widgets").html(b);$("#price-quotes-from-sellers").pricequotesfromsellers()}})}function initChangeEmail(){$(".user-panel #user-panel-change-email").click(function(){var a=$("#change-email-dialog");a.dialog({type:"fixed",x:"center",y:24,destroyOnClose:false});a.dialog("open");a.verticalclip();$.chug.user.getAccount(function(b){$(".text_field",a).val(b.email)});$("form",a).submit(function(c){c.preventDefault();var b=$(".text_field",a).val();if(b&&b!=""){$.chug.user.setEmail(b)}a.dialog("close");return false});return false})};
