function setcookie(d,a,c){var b="";c&&(b=new Date,b.setTime(b.getTime()+864E5*c),b="; expires="+b.toUTCString());document.cookie=d+"="+a+b+"; path=/"}function deletecookie(d){document.cookie=d+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"}function getcookie(d){d+="=";for(var a=document.cookie.split(";"),c=0;c<a.length;c++){for(var b=a[c];" "==b.charAt(0);)b=b.substring(1);if(-1!=b.indexOf(d))return b.substring(d.length,b.length)}return""}
function liftcurtain(){$(document).unbind("keydown");$(".d-popupCurtain, .p-popup").remove();$("body").removeClass("j-noScroll")}function dropcurtain(d){liftcurtain();$(document).on("keydown",function(a){27==a.keyCode&&liftcurtain()});$(document.body).prepend('<div class="d-popupCurtain"></div><div class="loadingWrap p-popup d-popupWrap '+d+'"><img src="/images/loading.gif" alt="loading"></div>')}
function loadpopup(d,a,c,b){c=void 0===c?null:c;b=void 0===b?null:b;dropcurtain(d);"undefined"==typeof b&&(b="");$.get(a,c,function(b){$(".p-popup").html(b).removeClass("loadingWrap");$(document).scrollTop();$(".p-popup").css("top","0px")}).done(b)}
function showerrors(d,a){a=a||"";$(".d-inError").addClass("j-hidden");if("object"!=typeof d)return!1;for(var c in d)if(d.hasOwnProperty(c)){var b=d[c];0<a.length?$(a).find("[data-for="+b+"]").removeClass("j-hidden"):$("[data-for="+c+"]").html(b).removeClass("j-show")}}
$(function(){var d=null;$(document).on("click",".j-changelocation",function(a){a={};a.l=$(this).data("id");$.getJSON("/update-location",a,function(c){if(c.status)location.reload();else return alert("Something went wrong with the location update!"),!1})});$(document).on("keyup",".j-typeahead",function(a){var c={a:"typeahead"};c.q=$(this).val();clearTimeout(d);d=setTimeout(function(){$.getJSON("/search",c,function(b){$(".searchResult").removeClass("j-hidden");$(".searchResult").html(b.content)})},500)});
$(document).on("click",".j-owlCode",function(a){a.preventDefault();var c=$(this).closest("form");a=c.serializeArray();$.getJSON("/general-process?a=owlcompetition",a,function(b){var a=c.find(".d-error[data-for=code]");a.addClass("j-hidden");0==b.status?a.removeClass("j-hidden").html(b.data):(c.hide(),$(".owlForm").show())})});$(document).on("click",".j-owlForm",function(a){a.preventDefault();var c=$(this).closest("form");a=c.serializeArray();$.getJSON("/general-process?a=owlform",a,function(b){c.find(".d-success").addClass("j-hidden");
0==b.status?showerrors(b,c):(c.find(".d-inError").addClass("j-hidden"),c.find(".d-success").removeClass("j-hidden"))})});$(document).on("click",".j-signupsubmit",function(a){a.preventDefault();var c=$(this).closest("form");a=c.serializeArray();$.getJSON("/general-process?a=signup",a,function(b){var a=c.find(".d-inError[data-for=e]"),d=c.find(".d-success[data-for=e]");a.addClass("j-hidden");d.addClass("j-hidden");0==b.status?a.removeClass("j-hidden").html(b.data):d.removeClass("j-hidden").html(b.data)})});
""!==getcookie("firstvisit")||"/city-update-confirmation"==window.location.pathname&&"/email-preference-update"==window.location.pathname||(setcookie("firstvisit",1,2592E6),setTimeout(function(){loadpopup("welcome","/welcome-popup")},5E3));$(document).on("click",".d-popupClose, .d-popupCurtain, .d-popupClose",function(a){a.preventDefault();liftcurtain()})});