$(document).ready(function(){if(typeof String.prototype.trim!=="function"){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")
}
}if(!($.blockUI==undefined)){$.blockUI.defaults.css={};
$.blockUI.defaults.overlayCSS={}
}$(".navMenu > li").hoverIntent({over:function(){$(this).addClass("sfhover")
},out:function(){$(this).removeClass("sfhover")
},sensitivity:12,interval:75});
$(".navMenu > li > ul > li").hoverIntent({over:function(){$(this).addClass("sfhover")
},out:function(){$(this).removeClass("sfhover")
},sensitivity:12,interval:75});
$(".newWindow").click(function(){openWindow(this.href);
return false
});
$(".autoSubmit").bind("change",function(){$(this).parents("form").submit()
});
$("a.submitForm").bind("click",function(){if(this.target==null){$(this).parents("form").submit()
}else{$(this.target).click()
}return false
});
$(".orderItemChkBox").click(function(){$.blockUI({message:"Updating your cart..."});
$(this).next().trigger("click")
});
$(".initFocus").focus();
$(".tab").click(function(){$(".tab").addClass("inactive").removeClass("active");
$(this).addClass("active").removeClass("inactive");
$(this).find("a").get(0).blur();
$(".tabContent").each(function(){$(this).hide()
});
$("#"+this.id+"Content").show()
});
var countdown={init:function(){countdown.remaining=countdown.max-$(countdown.obj).val().length;
if(countdown.remaining<0){$(countdown.obj).val($(countdown.obj).val().substring(0,countdown.max))
}$(countdown.obj).next().find(".remaining").html(countdown.remaining)
},max:null,remaining:null,obj:null};
$(".countdown").each(function(){$(this).focus(function(){var c=$(this).attr("class");
countdown.max=parseInt(c.match(/limit_[0-9]{1,}_/)[0].match(/[0-9]{1,}/)[0]);
countdown.obj=this;
iCount=setInterval(countdown.init,1000)
}).blur(function(){countdown.init();
clearInterval(iCount)
})
});
$("textarea :not(.countdown)").bind("keyup blur",function(){var maxLength=$(this).attr("maxlength");
if(maxLength!=null){currentLength=this.value.length;
remainingCharacters=(maxLength-currentLength);
if(currentLength>=maxLength){this.value=this.value.substr(0,maxLength)
}}});
maxLength=60;
function checkTextLength(textField){currentLength=textField.value.length;
remainingCharacters=(maxLength-currentLength);
if(currentLength>=maxLength){textField.value=textField.value.substr(0,maxLength)
}}$(".itemQty").submitFromEnter("input#addToCartButton");
$(".sellableItems td input:text").click(function(){$(this).select()
});
$(".defaultToZero").blur(function(){if($(this).val().trim()==""){$(this).val(0)
}});
var pastingText=false;
var pressedKeys=[];
var PC_CTRL_KEY=17;
var KEY_V=86;
$(".numericOnly").keyup(function(e){var keyCode=e.which;
pressedKeys[keyCode]=false;
if(pastingText){this.value=$(this).val().replace(/\D/g,"");
pressedKeys=[];
pastingText=false
}});
$(".numericOnly").keydown(function(e){var keyCode=e.which;
pressedKeys[keyCode]=true;
if(keyCode==KEY_V&&(pressedKeys[PC_CTRL_KEY]||pressedKeys[91]||pressedKeys[93]||pressedKeys[224])){pastingText=true;
return true
}if(keyCode==8||keyCode==9||keyCode==13||(keyCode>=48&&keyCode<=57)||(keyCode>=96&&keyCode<=105)){return true
}return false
});
$("#addToCartButton").click(function(){var params=$(this.form).serializeArray();
params.push({name:"ajax",value:true},{name:this.name,value:this.value});
$("#addToCartButton").hide();
$("#addToCartProcessing").show();
$.post(this.form.action,params,function(data){if(validateResponse(data)){$("#addToCartModalContentContainer").html(data);
$("#totalQuantity").html($("#newTotalQuantity").html());
$("#addToCartModal").jqmShow();
$("#theTitle").html($("#newModalTitle").html());
resetQuantityInputs();
$(".giftRegistryCheckbox").each(function(){$(this).attr("checked",false)
});
$(".registryIdInput").each(function(){$(this).val("")
});
$("#addToCartButton").show();
$("#addToCartProcessing").hide()
}});
$("#orderId").val(null);
return false
});
ajaxGetHandler(ajaxGetHandler);
$(".quantityInput").submitFromEnter("input#updateQuantity");
$("#updateQuantity").bind("click",function(){$.blockUI({message:"Updating your cart..."})
});
$("#registerFromCheckoutButton").click(function(){$.get("/checkout/register/registerAnonymous.htm",null,function(data){if(validateResponse(data)){$("#checkoutRegistrationModalContainer").html(data);
$("#checkoutRegistrationModal").jqmShow()
}});
return false
});
$("input[name='isStorePickup']").click(function(){if($(this).val()=="true"){$("#hiddenMethodInput").val("pickup");
$("#changeMethod").submit()
}else{$("#hiddenMethodInput").attr("disabled","disabled");
$("#changeMethod").submit()
}});
$("input[name='shipMethod']").click(function(){$.blockUI({message:"Updating your cart..."});
$("#hiddenMethodInput").val($(this).val());
$("#changeMethod").submit()
});
$(".tab").click(function(){if(this.id=="singleTab"){$(".currentTab").val("1");
$(".shipEntireOrderCheckbox").removeAttr("disabled");
$(".defaultShipEntireOrderCheckbox").attr("checked","checked");
$(".shipEntireOrder").removeClass("disabled")
}if(this.id=="multipleTab"){$(".currentTab").val("2");
$(".shipEntireOrderCheckbox").attr("disabled",true).removeAttr("checked");
$(".defaultShipEntireOrderCheckbox").removeAttr("checked");
$(".shipEntireOrder").addClass("disabled")
}});
$(".tab").filter(".active").click();
$(".methodsContainer input:radio").click(function(){displayDeliveryInstructions(this)
});
$(".methodsContainer input:radio:checked").each(function(){$(this).click()
});
$(".methodsContainer select.daySelect").bind("change blur keyup",function(){var selectedKey=$("option:selected",$(this))[0].value;
var fgId=$(this).attr("fgId");
var options=fgTimeSlots[fgId][selectedKey];
var timeSelect=$(".timeSelect-"+fgId);
timeSelect.empty();
if(options!=null){for(var i=0;
i<options.length;
i++){timeSelect.append($("<option>",{value:options[i].key}).text(options[i].value))
}}});
$(".addNewNumber").click(function(){if($(this).parent().parent().find(".addingNewPhone").val()=="true"){$(this).parent().parent().find(".addingNewPhone").val("false")
}else{$(this).parent().parent().find(".addingNewPhone").val("true")
}$(this).parent().parent().children(".existingPhoneSelect").find("select option:first").attr("selected","selected").parent("select");
$(this).parent().parent().children(".newPhoneInput").toggle();
$(this).parent().parent().children(".existingPhoneSelect").toggle();
return false
});
$(".preventDoubleSubmit").preventDoubleSubmit();
$(".hover-menu").hoverIntent({sensitivity:1,interval:50,over:function(){$(".hover-items",this).fadeIn(200)
},timeout:1000,out:function(){$(".hover-items",this).fadeOut(200)
}});
$(".wishlist .addToCartLink").one("click",function(){this.href=this.href+"&quantity="+$(this).closest("tr.item").find(".quantityInput").val()
})
});
$.fn.preventDoubleSubmit=function(){$(this).submit(function(){if(this.beenSubmitted){return false
}else{this.beenSubmitted=true
}})
};
$.fn.submitFromEnter=function(targetSelector){$(this).keypress(function(e){if(e.keyCode==13){$(targetSelector).click();
return false
}})
};
function displayDeliveryInstructions(clickedElem){var parentContainer=$(clickedElem).parents(".methodsContainer");
if($(clickedElem).val()=="delivery"){$(".dayTimeContainer",parentContainer).show();
$(".dayTimeContainer textarea, .dayTimeContainer select").removeAttr("disabled")
}else{$(".dayTimeContainer",parentContainer).hide();
$(".dayTimeContainer textarea, .dayTimeContainer select").attr("disabled",true)
}}function openWindow(winUrl,w,h){var winAttr="resizable=true,toolbar=yes,location=yes,scrollbars=yes";
if(w>0&&h>0){winAttr+=",width="+w+",height="+h
}window.open(winUrl,"text",winAttr)
}function positionModal(h){h.w.css("top",$(window).scrollTop()+10).prependTo("body>.bodyContent").show()
}function removeModal(h){h.w.hide();
if(h.o){h.o.remove()
}if(typeof(jwplayer)!="undefined"&&jwplayer()!=undefined){if(jwplayer().getState()=="PLAYING"){jwplayer().stop()
}}}function ajaxGetHandler(callback){$("a.ajaxGet").click(function(){$(this.target).load(this.href);
return false
})
}function printCart(){_gaq.push(["_trackPageview","/links/shoppingcart/print"]);
self.print()
}function validateResponse(data){var ajaxErrorRedirect=$("#ajaxErrorRedirect",$(data));
if(ajaxErrorRedirect.length>0){window.location=ajaxErrorRedirect.text();
return false
}return true
}function resetQuantityInputs(){var inputs=$(".sellableItems input.itemQty, .sellableItems input.accessoryQty");
var itemInputs=$(".sellableItems input.itemQty");
if(itemInputs.length==1){inputs.val("0");
itemInputs.val("1")
}else{inputs.val("0")
}$(".giftWrapCheckbox").removeAttr("checked")
}function resetTimeslots(){$(".methodsContainer select.daySelect option[selected]").removeAttr("selected");
$(".methodsContainer select.daySelect :first-child").attr("selected","selected");
$(".methodsContainer .timeOptions select").attr("disabled","disabled");
$(".methodsContainer .timeOptions").each(function(){$("select:first",this).removeAttr("disabled").show()
});
$(".methodsContainer .timeOptions select option").removeAttr("selected");
$(".methodsContainer .timeOptions select :first-child").attr("selected","selected")
}function addItemToWishList(pWishListId){if(pWishListId==null){$("#wishListSubmitButton").click();
return false
}$("#orderId").val(pWishListId);
$("#addToCartButton").click();
return false
}function addItemToRegistry(pRegistryId){$("#addToCartButton").hide();
$("#addToCartProcessing").show();
$.ajax({type:"POST",url:"/giftregistry/addToGiftRegistry.htm",data:$("form#addToCart").serialize()+"&giftRegistryId="+pRegistryId,cache:false,success:function(data,textStatus,jqXHR){if(validateResponse(data)){$("#addToCartModalContentContainer").html(data);
$("#totalQuantity").html($("#newTotalQuantity").html());
$("#addToCartModal").jqmShow();
$("#theTitle").html($("#newModalTitle").html());
resetQuantityInputs();
$("#addToCartButton").show();
$("#addToCartProcessing").hide()
}}});
return false
}function addCSpaceItemToRegistry(pRegistryId){$("#addToCartButton").hide();
$("#addToCartProcessing").show();
$.ajax({type:"POST",url:"/giftregistry/addCSpaceToGiftRegistry.htm",data:$("form#addToCart").serialize()+"&giftRegistryId="+pRegistryId,cache:false,success:function(data,textStatus,jqXHR){if(validateResponse(data)){$("#addToCartModalContentContainer").html(data);
$("#totalQuantity").html($("#newTotalQuantity").html());
$("#addToCartModal").jqmShow();
$("#theTitle").html($("#newModalTitle").html());
resetQuantityInputs();
$("#addToCartButton").show();
$("#addToCartProcessing").hide()
}}});
return false
};
