var root_path=location.protocol+"//"+location.host;var ajax_path=root_path+"/_ajax/";var t;function showCart(){if($("#js_cartinfo").length>0){$.ajax({url:ajax_path+"showcart/",cache:false,success:function(a){$("#js_cartinfo").html(a);}});$.ajax({url:ajax_path+"showcart/footer/true",cache:false,success:function(a){$("#js_cartinfo_footer").html(a);}});}}function addCart(c,a,b){if(!c||!a){return false;}if(b){setWait();}else{showNotice("wait");}$.post(ajax_path+"addcart/"+(b?"cartview/true":null),{id:c,amount:a},function(e){if(e=="error"){showNotice("error",true);}else{if(b){clearWait();$("#js_ajax_cart").html(e);}else{showNotice("success",true);showCart();}}});}function changeCart(b,a){if(!b||!a||a<=0){return false;}setWait();$.post(ajax_path+"changecart/",{id:b,amount:a},function(c){if(c=="error"){showNotice("changeerror",true);}else{$("#js_helper").val("wait");clearWait();$("#js_ajax_cart").html(c);setTimeout(function(){$("#product_"+b).focus().val($("#product_"+b).val());$("#js_helper").val(" ");$("input.js_cart_amount_input").bind("keypress",function(f){allowed=(f.which!=8&&f.which!=0&&f.which!=44&&f.which!=46&&(f.which<48||f.which>57))?false:true;if(allowed){if(checkAmount($(this).val(),$(this).hasClass("js_kg"))){$("#"+this.id+"_lastvalue").val($(this).val());}else{$("#"+this.id+"_lastvalue").val("1");}return true;}else{return false;}});},500);}});}function removeCart(a){if(!a){return false;}setWait();$.post(ajax_path+"removecart/",{id:a},function(b){if(b=="error"){showNotice("error",true);}else{clearWait();$("#js_ajax_cart").html(b);}});}function chooseSelver(b,c,a){$(".calendar_cont").fadeOut("fast");if($("#js_selver").val()){$.post(ajax_path+"chooseselver/",{id:$("#js_selver").val()},function(e){if(e=="selvererror"){showNotice("selvererror",true);}else{d=new Date(b,c,a);calendar(d,e);$(".calendar_cont").fadeIn("fast");}});}}function chooseTime(){if($("#js_deliverytime").val()){$.post(ajax_path+"choosedeliverytime/",{time:$("#js_deliverytime").val()},function(a){if(a=="error"){showNotice("timeerror",true);}});}}function calendar(a,b){$("#js_datepick").dpSetStartDate(a.addDays(b).asString());selected=$("#js_datepick").dpGetSelected();if(typeof(selected.length)!="undefined"&&selected.length>0&&selected[0]<a){setDeliverDate(0);}}function initCalendar(b,a){$("#js_datepick").datePicker({createButton:false}).bind("click",function(){$(this).dpDisplay();this.blur();return false;}).bind("dateSelected",function(f,c,g){setDeliverDate(c);});$("#js_datepick").dpSetOffset(-50,80);if(b){$("#js_datepick").dpSetSelected(b);}if(a){$("#js_datepick").dpSetStartDate(a);}}function setDeliverDate(a){if(typeof(a)!="object"){$("#js_deliver_date").html(" ");}else{$.post(ajax_path+"setdeliverdate/",{date:a.getDate()+"."+(a.getMonth()+1)+"."+a.getFullYear()},function(b){if(b=="dateerror"){showNotice("error",true);}else{$("#js_deliver_date").html(b);}});}}function postContactInfo(){var a={};$("#js_contact_data").find("input[type='text'], textarea").filter(":enabled").each(function(){a[this.name]=this.value;});$.post(ajax_path+"postcontactinfo/",a,function(b){if(typeof(b)=="object"){success=true;$.each(b.status,function(e,c){if(c=="ok"){$("#js_input_"+e).removeClass("error");$("#js_error_"+e).addClass("hidden");}else{success=false;$("#js_input_"+e).addClass("error");$("#js_error_"+e).removeClass("hidden");}});if(success){document.location.href=document.location.href.replace(2,3);}}},"json");}function confirmOrder(){$.ajax({url:ajax_path+"confirmorder/",cache:false,success:function(a){if(a=="ok"){document.location.href=document.location.href.replace(3,4);}else{showNotice("confirmerror",true);}}});}function setWait(){$(".bucket_cont a").css("cursor","wait");}function clearWait(){$(".bucket_cont a").css("cursor","default");}function showNotice(a,b){$("#js_cart_notice_text").html($("#js_cart_notice_"+a).html());if(a.match(/error/)){$("#js_cart_notice_text").removeClass("info");$("#js_cart_notice_text").addClass("info_error");}else{$("#js_cart_notice_text").removeClass("info_error");$("#js_cart_notice_text").addClass("info");}if($.browser.msie&&parseInt($.browser.version)<7){$("#js_cart_notice").css("top",$(window).scrollTop()+parseInt($(window).height()/2)+"px");$("#js_cart_notice").show();}else{$("#js_cart_notice").center().show();}if(b){t=setTimeout(function(){$("#js_cart_notice").fadeOut("fast");clearTimeout(t);},1000);}}function closeNotice(){clearTimeout(t);$("#js_cart_notice").fadeOut("fast");}function productMark(b,a){$.post(ajax_path+"productmark/",{id:b,mark:a},function(c){if(c=="error"){showNotice("markerror",true);}else{$("#js_stars_"+b).html(c);showNotice("marksuccess",true);}});}function checkAmountCart(b,a){if(checkAmount($(b).val(),a,b)){newval=$(b).val().replace(/\,/,".");if(newval!=$("#"+b.id+"_firstvalue").val()){changeCart(b.id.replace(/product_/,""),newval);}}}function checkAmount(b,a,c){if(!a&&typeof(b)=="object"&&($(b).hasClass("js_kg"))){a=true;}inputval=(typeof(b)=="object")?$(b).val():b;inputlength=inputval.length;if(!inputlength){return false;}else{if(!a&&inputval.charAt(0)=="0"){if(typeof(b)=="object"){$(b).val($("#"+b.id+"_lastvalue").val());}else{if(c){$(c).val($("#"+c.id+"_firstvalue").val());}}}else{comma=0;commaplace=0;for(i=0;i<inputlength;i++){if(inputval.charAt(i)=="."||inputval.charAt(i)==","){comma++;commaplace=i;if(i==(inputlength-1)){if(comma>1||!a){if(typeof(b)=="object"){$(b).val($("#"+b.id+"_lastvalue").val());}else{if(c){$(c).val($("#"+c.id+"_firstvalue").val());}}return false;}return false;}if(comma>1||i==0||commaplace==0){if(typeof(b)=="object"){$(b).val($("#"+b.id+"_lastvalue").val());}else{if(c){$(c).val($("#"+c.id+"_firstvalue").val());}}return false;}if(!a){if(typeof(b)=="object"){$(b).val($("#"+b.id+"_lastvalue").val());}else{if(c){$(c).val($("#"+c.id+"_firstvalue").val());}}return false;}}if(commaplace>0&&(i-commaplace)>1){if(typeof(b)=="object"){$(b).val($("#"+b.id+"_lastvalue").val());}else{if(c){$(c).val($("#"+c.id+"_firstvalue").val());}}return false;}}}}return true;}function backtofirst(){var a={};$("#js_contact_data").find("input[type='text'], textarea").filter(":enabled").each(function(){a[this.name]=this.value;});$.post(ajax_path+"backtofirst/",a,function(b){document.location.href=document.location.href.replace(2,1);});}$(function(){$(".ingredientsWrap a").mouseover(function(){$(this).next(".ingredientsPopup").show("fast");return false;});$(".ingredientsWrap a").mouseout(function(){$(this).next(".ingredientsPopup").hide("fast");return false;});$("input.js_cart_amount_input").bind("keypress",function(a){allowed=(a.which!=8&&a.which!=0&&a.which!=44&&a.which!=46&&(a.which<48||a.which>57))?false:true;if(allowed){if(checkAmount($(this).val(),$(this).hasClass("js_kg"))){$("#"+this.id+"_lastvalue").val($(this).val());}else{$("#"+this.id+"_lastvalue").val("1");}return true;}else{return false;}});$(".productmark").hover(function(){nr=this.id.charAt(this.id.length-1);i=0;$(this).parent().children().each(function(){i++;if(i<=nr){$(this).attr("src",root_path+"/gfx/star_active.png");}});},function(){$(this).parent().children().each(function(){if($(this).hasClass("half")){$(this).attr("src",root_path+"/gfx/star_half.png");}else{if($(this).hasClass("empty")){$(this).attr("src",root_path+"/gfx/star_empty.png");}else{$(this).attr("src",root_path+"/gfx/star_complete.png");}}});});$(document).keydown(function(a){if((a.which)==8&&$("#js_helper").val()=="wait"){return false;}});});
