var global={};function on_ready(){prepare_login();prepare_search();prepare_train();prepare_form_mailing()}
function prepare_login(){if($("#box_login_body").length){var a=$('<input class="input_form input_login" type="text" value="password" />');a.hide();$("#box_login_body").append(a);$(document.activeElement).addClass("i_have_focus");$("#box_login_body").children(".input_form:nth(1)").hasClass("i_have_focus")||($("#box_login_body").children(".input_form:nth(1)").hide(),$("#box_login_body").children(".input_form:nth(2)").show());$(".i_have_focus").removeClass("i_have_focus");$("#box_login_body").children(".input_form:nth(0)").focus(function(){$(this).val()===
"e-mail address"&&$(this).val("")});$("#box_login_body").children(".input_form:nth(2)").focus(function(){$(this).val()==="password"&&($("#box_login_body").children(".input_form:nth(2)").hide(),$("#box_login_body").children(".input_form:nth(1)").show().focus())});$("#box_login_body").children(".input_form:nth(0)").blur(function(){$(this).val().length||$(this).val("e-mail address")});$("#box_login_body").children(".input_form:nth(1)").blur(function(){$(this).val().length||($("#box_login_body").children(".input_form:nth(1)").hide(),
$("#box_login_body").children(".input_form:nth(2)").show())})}}
function prepare_search(){$("#form_search").length&&($("#form_search").find(".input_form").focus(function(){$(this).val()==="search the catalogue"&&$(this).val("");$("#box_search_matches").show()}),$("#form_search").children(".input_form").blur(function(){$(this).val().length||$(this).val("search the catalogue");$("#box_search_matches").data("hover")||$("#box_search_matches").hide()}),$.ajax({url:"/xml/products.xml",success:function(a,d){if(d==="success")global.product_xml=a,$("#form_search").children(".input_form").attr("autocomplete",
"off")}}),$("#form_search").children(".input_form").keyup(function(){$(".box_search_match").remove();if(typeof global.product_xml==="object"){var a=$(this).val();if(a.length>1&&$(this).val()!=="search the catalogue"){var d=RegExp("\\b("+a+")","i"),b=0;$(global.product_xml).find("product=>name").each(function(){var a=$(this).text();if(a.match(d)){var f=$('<div class="box_search_match"> </div>');f.hover(function(){$("#box_search_matches").data("hover",1)},function(){$("#box_search_matches").data("hover",
0)});a.length>25&&(a=a.substr(0,25)+"...");a=a.replace(d,'<span style="color:#333">$1</span>');f.html(a);f.data("url","/catalogue/"+$(this).parent().children("parent").text()+"/"+$(this).parent().children("url").text()+"/");$(f).click(function(){window.location=$(this).data("url")});$("#box_search_matches").length||$("#form_search").append('<div id="box_search_matches"> </div>');$("#box_search_matches").children(".box_search_match").length<2?$("#box_search_matches").append(f):b+=1}});b&&(a=$('<div class="box_search_match box_search_match_more"> </div>'),
a.hover(function(){$("#box_search_matches").data("hover",1)},function(){$("#box_search_matches").data("hover",0)}),a.click(function(){$("#form_search").submit()}),a.text("and "+b+" more match"),b>1&&a.text(a.text()+"es"),$("#box_search_matches").append(a));$(".box_search_match:last").css("border-bottom-width","2px")}}}))}
function prepare_train(){$.flash.hasVersion(8)&&$.ajax({url:"/do/anim-seen/",success:function(a){$(a).filter(":first").attr("seen")!=="1"&&$.ajax({url:"/img/global/train.swf",success:function(){load_train()}})}})}function load_train(){$("#train").length&&($("#train").css("background-image","none"),$("#train").flash({swf:"/img/global/train.swf",width:340,height:190,hasVersion:8,menu:false,scale:"noborder",wmode:"transparent"}),$.ajax({url:"/do/anim-seen/",type:"POST",data:"done=1"}))}
function prepare_cart(){$("#form_product_options").unbind("submit").bind("submit",function(){return take_cart()}).children(".form_add_pram").removeClass("form_add_pram_busy form_add_pram_disabled").val("add to shopping pram");update_stock();$("#form_product_options").data("submitted")&&($("#form_product_options").data("submitted",0),$(".box_form_option").each(function(){var a=$(this).children(":input");a.attr("type")==="text"?a.val(""):a.attr("type")==="select-one"?a.children(":first").attr("selected",
"selected"):a.attr("type")==="checkbox"&&a.attr("checked","")}))}function prepare_stock(){$(".box_form_option").each(function(){if(!$(this).children("select").length)return 1;$(this).children("select").bind("change",function(){update_stock()})})}
function take_cart(){var a={silent:1};$("#form_product_options").children(".text_form_fail").remove();var d=[];$(".box_form_option").each(function(){e=$(this).children(":input");for(var b in personalisations_verify){var f=$(e).attr("name").match(/^personalisations\[(.+)\]$/),f=f?f[1]:$(e).attr("name");b===f&&(!e.val().length&&!parseInt(personalisations_verify[b].optional)||e.val().length>parseInt(personalisations_verify[b].max_length))&&d.push(b)}e.attr("type")==="checkbox"?a[e.attr("name")]=e.is(":checked"):
a[e.attr("name")]=e.val()});if(d.length){var b=$('<div class="text_form_fail text_form_fail_list"> </div>'),g="The following are missing/too long:",f;for(f in d)g+=' <br /> <span class="text_form_fail_on"> &nbsp;&nbsp;&nbsp;&nbsp;'+d[f].replace(/_/g," ")+" </span>";$(b).html(g);$("#form_product_options").children(".form_add_pram").before(b);return false}$("#form_product_options").children("input").each(function(){if($(this).attr("type")==="submit")return 1;a[$(this).attr("name")]=$(this).val()});
if(!($.browser.msie&&parseInt($.browser.version)<=8))return add_to_cart(a),false}
function add_to_cart(a){typeof a==="object"&&($("#form_product_options").data("submitted",1),$("#form_product_options").unbind("submit").bind("submit",function(){return false}).children(".form_add_pram").addClass("form_add_pram_busy"),$.ajax({data:a,type:"POST",url:"/do/add-to-pram/",success:function(a,b){if(b!=="success")$("#form_product_options").children(".form_add_pram").before('<div class="text_form_fail"> Failed to add to pram.<br />Please try again. </div>'),prepare_cart();else if($(a).filter(":first").attr("type")!==
"ok"){if($(a).find("reasons").children("reason").length){var g=$('<div class="text_form_fail text_form_fail_list"> The following are missing/too long: </div>');$(a).find("reasons").children("reason").each(function(){g.append('<br /><span class="text_form_fail_on">&nbsp;&nbsp;&nbsp;&nbsp;'+$(this).text()+"</span>")});$("#form_product_options").children(".form_add_pram").before(g)}else $("#form_product_options").children(".form_add_pram").before('<div class="text_form_fail"> Failed to add to pram.<br />Please try again. </div>');
prepare_cart()}else{prepare_cart();var f=$(a).find("quantity").text();if(typeof f==="string"){var h="items";parseInt(f)===1&&(h="item");var i=$("#box_pram_total_holder").children(".text_pram_total:nth(1)"),j=$('<div class="text_pram_total"> </div>').text(f).css("margin-top","-20px");$("#box_pram_total_holder").prepend(j);$("#text_pram_items_label").text(h+" in your pram");$("html,body").animate({scrollTop:0},300,function(){i.animate({"margin-top":"20px"},200,function(){$(this).remove()});j.animate({"margin-top":"0"},
200)})}f=$(a).find("price").text();typeof f==="string"&&(f=new Number(f),$(".box_pram_body:nth(0)").children(".text_pram_details:nth(2)").text("\u00a3"+f.toFixed(2)))}},error:function(){$("#form_product_options").children(".form_add_pram").before('<div class="text_form_fail"> Failed to add to pram.<br />Please try again. </div>');prepare_cart()}}))}
function update_stock(){if(typeof stock_levels.global==="number")stock_levels.global===0&&$("#form_product_options").unbind("submit").bind("submit",function(){return false}).children(".form_add_pram").addClass("form_add_pram_disabled").val("sorry, out of stock");else{var a=[];$(".box_form_option").each(function(){if($(this).children("select").length){var d=$(this).children("select").attr("name"),b=d.match(/^personalisations\[(.+)\]$/);b[1].length&&(d=b[1]);stock_skips[d]&&a.push($(this).children("select").val())}});
a=a.join("|");typeof stock_levels[a]==="number"&&(stock_levels[a]===0?$("#form_product_options").unbind("submit").bind("submit",function(){return false}).children(".form_add_pram").addClass("form_add_pram_disabled").val("sorry, out of stock"):$("#form_product_options").unbind("submit").bind("submit",function(){return take_cart()}).children(".form_add_pram").removeClass("form_add_pram_busy form_add_pram_disabled").val("add to shopping pram"))}}
function prepare_review(){$("#form_review").length&&($("#form_review").unbind("submit").bind("submit",function(){return take_review()}).children(".input_submit_review").removeClass("input_submit_review_busy").val("submit review"),$("#form_review").children(":input[name=review_text]").removeAttr("disabled"))}
function take_review(){var a={silent:1};$("#form_review").children(".text_review_fail").remove();a.review_text=$("#form_review").children(":input[name=review_text]").val();if(a.review_text.length<1)return $("#form_review").prepend('<div class="text_review_fail"> Please type your review before submitting it. </div>'),false;$("#form_review").children("input").each(function(){$(this).attr("type")==="hidden"&&(a[$(this).attr("name")]=$(this).val())});add_review(a);return false}
function add_review(a){typeof a==="object"&&($("#form_review").unbind("submit").bind("submit",function(){return false}).children(".input_submit_review").addClass("input_submit_review_busy").val("submitting review..."),$("#form_review").children(":input[name=review_text]").attr("disabled","disabled"),$.ajax({data:a,type:"POST",url:"/do/add-review/",success:function(a,b){if(b!=="success")$("#form_review").prepend('<div class="text_review_fail"> Failed to add review. Please try again. </div>'),prepare_review();
else{var g=$(a).filter(":first").attr("type");g==="authorise"?($("#form_review").prepend('<div class="text_review_fail"> Your session has expired and you will need to login again to save a review.<br />Please click <a href="/your/login/">here</a> to login.<br />Make sure to save your review first as you will be navigated away from this page. </div>'),prepare_review()):g!=="ok"?($("#form_review").prepend('<div class="text_review_fail"> Failed to add review. Please try again. </div>'),prepare_review()):
($("#form_review").prepend('<div class="text_review_fail"> Thank you. Your review has been saved, pending review. </div>'),$("#form_review").children(".input_submit_review").val("review submitted"))}},error:function(){$("#form_review").prepend('<div class="text_review_fail"> Failed to add review. Please try again. </div>');prepare_review()}}))}
function prepare_remove(a){$.browser.msie&&parseInt($.browser.version)<=8||($(".form_pram_remove").unbind("submit").bind("submit",function(a){return take_remove(a.target)}),$(".input_remove_pram").removeClass("form_remove_pram_busy").val("remove item"),a&&$(a).parent().remove())}
function take_remove(a){var d={silent:1};$(".text_form_fail").remove();$(a).children("input").each(function(){if($(this).attr("type")==="submit")return 1;d[$(this).attr("name")]=$(this).val()});remove_from_cart(a,d);return false}
function remove_from_cart(a,d){typeof d==="object"&&($(a).unbind("submit").bind("submit",function(){return false}).children(".input_remove_pram").addClass("form_remove_pram_busy").val("removing..."),$.ajax({data:d,type:"POST",url:"/do/remove-from-pram/",success:function(d,g){if(g!=="success")$(a).children(".form_remove_pram").before('<div class="text_form_fail"> Failed to remove from pram.<br />Please try again. </div>'),prepare_remove();else if($(d).filter(":first").attr("type")!=="ok")$(a).children(".input_remove_pram").parent().prepend('<div class="text_form_fail"> Failed to remove from pram. Please try again. </div>'),
prepare_remove();else{prepare_remove(a);var f=$(d).find("quantity").text();if(typeof f==="string"){var h="items";parseInt(f)===1&&(h="item");$(".box_pram_body:nth(0)").children(".text_pram_details:nth(1)").text(f+" "+h+" in your pram")}h=$(d).find("price").text();typeof h==="string"&&(h=new Number(h),$(".box_pram_body:nth(0)").children(".text_pram_details:nth(2)").text("\u00a3"+h.toFixed(2)),$(".box_pram_item:last").children(".text_pram_price").text("\u00a3"+h.toFixed(2)));parseInt(f)===0&&($("#box_pram_items").children().remove(),
$("#box_pram_items").append(empty_div))}},error:function(){$(a).children(".form_remove_pram").before('<div class="text_form_fail"> Failed to remove from pram.<br />Please try again. </div>');prepare_remove()}}))}function prepare_register(){$("#box_register").submit(function(){return take_register()})}
function take_register(a){typeof a!=="string"&&(a="#box_register");$(a).find("input").css("border-color","#B0D5EC");$(a).find(".box_error_message").remove();var d=[],b,g,f,h;$(a).find("input").each(function(){var a=$(this).attr("name");a==="email"&&(!$(this).val().match(/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i)||$(this).val().length>255)?d.push({input:a,error:"Please provide a valid e-mail address"}):a==="password"&&($(this).val().length<3||$(this).val().length>30)?d.push({input:a,error:"Please create a password between 3 and 30 characters"}):
a==="surname"&&($(this).val().length<2||$(this).val.length>255)?d.push({input:a,error:"Please provide your surname"}):a==="first_name"&&($(this).val().length<2||$(this).val.length>255)?d.push({input:a,error:"Please provide your first name"}):a==="address_1"&&($(this).val().length<1||$(this).val.length>255)?d.push({input:a,error:"Please provide the first line of your address"}):a==="postcode"&&!$(this).val().match(/^[a-z0-9\s\-]{3,255}$/i)?d.push({input:a,error:"Please provide a valid postcode"}):
a==="accept_terms"&&!$(this).is(":checked")&&d.push({input:a,error:"You must accept the terms and conditions"});a==="email"?b=$(this).val():a==="email_confirm"?g=$(this).val():a==="password"?f=$(this).val():a==="password_confirm"&&(h=$(this).val())});b!==g&&d.push({input:"email_confirm",error:"Please check your e-mail addresses match"});f!==h&&d.push({input:"password_confirm",error:"Please check your passwords match"});if(d.length){for(c in d){var i=$('<div class="box_error_message"> </div>').text(d[c].error);
$(a).find('input[name="'+d[c].input+'"]').css("border-color","#FFC1AD").parents(".box_form_field").append(i)}return false}return true}
function prepare_contact_form(){$("form.box_company_detail").length&&$("form.box_company_detail").submit(function(){$(".text_form_error").remove();$(".input_error").removeClass("input_error");var a=[];$("form.box_company_detail").children(".box_form_contact_items:nth(0) > .input_contact").val().length<2&&a.push({n:0,message:"Please provide your name"});$("form.box_company_detail").children(".box_form_contact_items:nth(1) > .input_contact").val().length<2&&$("form.box_company_detail").children(".box_form_contact_items:nth(2) > .input_contact").val().length<
2?a.push({n:1,message:"Please provided either an e-mail address"},{n:2,message:"or phone number"}):$("form.box_company_detail").children(".box_form_contact_items:nth(1) > .input_contact").val().length&&!$("form.box_company_detail").children(".box_form_contact_items:nth(1) > .input_contact").val().match(/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i)&&a.push({n:1,message:"Please check your e-mail address is valid"});$("form.box_company_detail").children(".box_form_contact_items:nth(4) > .textarea_contact").val().length<
5&&a.push({n:4,message:"Please include your message for us"});for(var d=0;d<a.length;d++){var b=$('<div class="text_form_error"> </div>');b.text(a[d].message);$(".box_form_\tcontact_items:nth("+a[d].n+")").append(b).children(".input_contact,.textarea_contact").addClass("input_error")}if(a.length)return false})}
function prepare_checkout(){prepare_postage();prepare_discount();prepare_address_details();$("#checkbox_returning_customer").change(function(){var a=$(this).parent().siblings(".box_form_field").children("input[name=heard_from]");$(this).is(":checked")?a.data("val",$(a).val()).val("Returning customer").attr("disabled","disabled"):a.val($(a).data("val")).removeAttr("disabled")})}
function prepare_postage(){$(":input[name=delivery_method]").length&&$(":input[name=delivery_method]").change(function(){var a=postage[$(this).val()];update_price(a)})}
function prepare_discount(){if(!($.browser.msie&&parseInt($.browser.version)<=8)&&$(":input[name=discount_code][type=text]").length){var a=$('<div class="input_submit_discount"> Apply Discount </div>');$(":input[name=discount_code]").before(a);$("form[name=checkout]").submit(function(a){if($(a.originalEvent.explicitOriginalTarget).attr("name")==="discount_code")return false});a.click(function(){if(!$(this).data("busy")){var a=$(":input[name=discount_code]").val();$(this).siblings(".box_checkout_error").remove();
a.match("^[a-zA-Z0-9]{2,20}$")?($(".input_submit_discount").addClass("input_submit_discount_busy").text("Checking Code").data("busy",1),take_discount(a)):$(this).before('<div class="box_checkout_error"> This discount code is invalid </div>')}});$(":input[name=discount_code]").keyup(function(a){a.keyCode===13&&!$(this).siblings(".input_submit_discount").data("busy")&&(a=$(":input[name=discount_code]").val(),$(this).siblings(".box_checkout_error").remove(),a.match("^[a-zA-Z0-9]{2,20}$")?($(".input_submit_discount").addClass("input_submit_discount_busy").text("Checking Code").data("busy",
1),take_discount(a)):$(".input_submit_discount").before('<div class="box_checkout_error"> This discount code is invalid </div>'))})}}
function prepare_address_details(){$("form[name=checkout_address_details]").submit(function(){$(":input[name=heard_from]").css("border-color","#CCC").parents(".box_form_field").children(".box_error_message").remove();if($(":input[name=address_type]").length){if($(":input[name=heard_from]").val().length<2){var a=$('<div class="box_error_message"> </div>').text("Please let us know");$(":input[name=heard_from]").css("border-color","#FFC1AD").parents(".box_form_field").append(a);return false}if($(":input[name=address_type]:checked").val()===
"existing")return 1}a=take_register(".box_pram_item:nth(1)");if($(":input[name=heard_from]").val().length<2)return a=$('<div class="box_error_message"> </div>').text("Please let us know"),$(":input[name=heard_from]").css("border-color","#FFC1AD").parents(".box_form_field").append(a),false;if(!a)return false})}
function take_discount(a){$.ajax({data:{code:a},type:"POST",url:"/do/check-discount-code/",success:function(a,b){b!=="success"&&$(".input_submit_discount").removeClass("input_submit_discount_busy").text("Apply Discount").data("busy",0).before('<div class="box_checkout_error"> Failed to validate discount code </div>');var g=$(a).filter(":first").attr("type");if(g!=="ok")g==="invalid"?$(".input_submit_discount").removeClass("input_submit_discount_busy").text("Apply Discount").data("busy",0).before('<div class="box_checkout_error"> This discount code is invalid </div>'):
$(".input_submit_discount").removeClass("input_submit_discount_busy").text("Apply Discount").data("busy",0).before('<div class="box_checkout_error"> Failed to validate discount code </div>');else{var g=$(a).find("value").attr("type"),f=parseFloat($(a).find("value").text());String(f).match("(d{1,10}.00)")&&(f=f.substr(0,-3),f=parseFloat(f));$(".input_submit_discount").data({type:g,val:f});g=postage[$(":input[name=delivery_method]:checked").val()];update_price(g,1)}},error:function(){$(".input_submit_discount").removeClass("input_submit_discount_busy").text("Apply Discount").data("busy",
0).before('<div class="box_checkout_error"> Failed to validate discount code </div>')}})}
function update_price(a){var d=$(".input_submit_discount").data("type"),b=$(".input_submit_discount").data("val"),g=a+prices.subtotal;typeof b==="number"&&(d==="fixed"?g-=b:g=prices.subtotal-prices.subtotal/100*b+a,$(".box_pram_item:last").children(".text_pram_price_label").each(function(){$(this).text().match("Discount")&&($(this).prev(".text_pram_price").remove(),$(this).remove())}),d==="fixed"?(b>prices.subtotal+a&&(b=prices.subtotal+a),b="-\u00a3"+b.toFixed(2)):b="-"+b+"%",b=$('<div class="text_pram_price"> '+
b+" </div> "),d==="perc"?$(".box_pram_item:last").children(".text_pram_price_label:first").after('<div class="text_pram_price_label"> Discount: </div>').after(b):$(".box_pram_item:last").children(".text_pram_price:last").before(b).before('<div class="text_pram_price_label"> Discount: </div>'),$(".input_submit_discount").removeClass("input_submit_discount_busy").text("Apply Discount").data("busy",0));var f=0;$(".text_pram_price_label").each(function(){if($(this).text().match("Delivery"))return false;
f+=1});$(".box_pram_item:last").children(".text_pram_price:nth("+f+")").text("\u00a3"+a.toFixed(2));g<0&&(g=0);$(".box_pram_item:last").children(".text_pram_price:last").text("\u00a3"+g.toFixed(2))}
function prepare_your_form(){$("form.box_your:nth(0)").length&&$("form.box_your:nth(0)").submit(function(){$(".text_your_error").remove();var a=$(this).children(".box_your_form_section:nth(0)").children(":input[name=password]").val(),d=$(this).children(".box_your_form_section:nth(1)").children(":input[name=password_confirm]").val();if(a.length<3||a.length>30)return $(this).children(".box_your_form_section:nth(0)").append('<span class="text_your_error"> Please enter a password between 3 and 30 characters </span>'),
false;if(a!==d)return $(this).children(".box_your_form_section:nth(1)").append('<span class="text_your_error"> Please check your passwords match </span>'),false})}
function prepare_form_mailing(){$("#form_mailing").unbind("submit").bind("submit",function(){var a={silent:1},d=0;$(".box_mailing").each(function(){var b=$(this).children(":input");b.removeClass("input_mailing_error");a[b.attr("name")]=b.val();if(b.attr("name")==="name"&&(b.val().length<2||b.val().length>255))b.addClass("input_mailing_error"),d=1;if(b.attr("name")==="email"&&(!b.val().match(/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i)||b.val().length>255))b.addClass("input_mailing_error"),d=1});if(d)return false;
$("#form_mailing").unbind("submit").bind("submit",function(){return false}).children("input[type=submit]").addClass("input_mailing_submit_busy");$.ajax({data:a,type:"POST",url:"/do/mailing-join/",success:function(a){$(a).filter(":first").attr("type")!=="ok"?($("#form_mailing").children(".box_mailing").remove(),$("#form_mailing").children("input[type=submit]").remove(),$("#form_mailing").append('<div class="box_mailing"> <span class="label_mailing"> An error occurred. Please try again later. </span> </div>')):
($("#form_mailing").children(".box_mailing").remove(),$("#form_mailing").children("input[type=submit]").remove(),$("#form_mailing").append('<div class="box_mailing"> <span class="label_mailing"> Thank you. You have now been added to our mailing list. </span> </div>'))},error:function(){$("#form_mailing").children(".box_mailing").remove();$("#form_mailing").children("input[type=submit]").remove();$("#form_mailing").append('<div class="box_mailing"> <span class="label_mailing"> An error occurred. Please try again later. </span> </div>')}});
return false})};

