/* Javascript functions for use throughout Bigcommerce Classic White Shop template */ $(function(){ // this is here just incase the HTMLHead code fails $('html').addClass('javascript'); }); // Fetch the value of a cookie function get_cookie(name) { name = name += "="; var cookie_start = document.cookie.indexOf(name); if(cookie_start > -1) { cookie_start = cookie_start+name.length; cookie_end = document.cookie.indexOf(';', cookie_start); if(cookie_end == -1) { cookie_end = document.cookie.length; } return unescape(document.cookie.substring(cookie_start, cookie_end)); } } // Set a cookie function set_cookie(name, value, expires) { if(!expires) { expires = "; expires=Wed, 1 Jan 2020 00:00:00 GMT;" } else { expire = new Date(); expire.setTime(expire.getTime()+(expires*1000)); expires = "; expires="+expire.toGMTString(); } document.cookie = name+"="+escape(value)+expires; } /* Javascript functions for the products page */ var num_products_to_compare = 0; var product_option_value = ""; var CurrentProdTab = ""; function showProductImage(filename, product_id, currentImage) { var l = (screen.availWidth/2)-350; var t = (screen.availHeight/2)-300; var variationAdd = ''; if(ShowVariationThumb) { variationAdd = '&image_rule_id=' + encodeURIComponent(ShowVariationThumb); CurrentProdThumbImage = null; } UrlAddOn = ''; if(currentImage) { UrlAddOn = "¤t_image="+currentImage; } else if(CurrentProdThumbImage) { UrlAddOn = "¤t_image="+CurrentProdThumbImage; } var imgPopup = window.open(filename + "?product_id="+product_id+variationAdd+UrlAddOn, "imagePop", "toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=700,height=600,top="+t+",left="+l); imgPopup.focus(); } function CheckQuantityLimits (form) { var qty = parseInt($('#qty_').val(), 10); if (!qty) { // If text fields are being used for 'quantity' we need to get this value instead: qty = parseInt($('#text_qty_').val(), 10); } if (qty < productMinQty) { alert(lang.ProductMinQtyError); return false; } if (qty > productMaxQty) { alert(lang.ProductMaxQtyError); return false; } return true; } function CheckProductConfigurableFields(form) { var requiredFields = $('.FieldRequired'); var valid = true; requiredFields.each(function() { var namePart = this.name.replace(/^.*\[/, ''); var fieldId = namePart.replace(/\].*$/, ''); if(this.type=='checkbox' ) { if(!this.checked) { valid = false; alert(lang.EnterRequiredField); this.focus(); return false; } } else if(this.value == '') { if(this.type != 'file' || (this.type == 'file' && document.getElementById('CurrentProductFile_'+fieldId).value == '')) { valid = false; alert(lang.EnterRequiredField); this.focus(); return false; } } }); var fileFields = $(form).find("input[name^='ProductField']:file"); fileFields.each(function() { if(this.value != '') { var namePart = this.name.replace(/^.*\[/, ''); var fieldId = namePart.replace(/\].*$/, ''); var fileTypes = document.getElementById('ProductFileType_'+fieldId).value; fileTypes = ','+fileTypes.replace(' ', '').toLowerCase()+',' var ext = this.value.replace(/^.*\./, '').toLowerCase(); if(fileTypes.indexOf(','+ext+',') == -1) { alert(lang.InvalidFileTypeJS); this.focus(); this.select(); valid = false; } } }); return valid; } function check_add_to_cart(form, required) { var valid = true; var qtyInputs = $(form).find('input.qtyInput'); qtyInputs.each(function() { if(isNaN($(this).val()) || $(this).val() <= 0) { alert(lang.InvalidQuantity); this.focus(); this.select(); valid = false; return false; } }); if(valid == false) { return false; } if(!CheckProductConfigurableFields(form)) { return false; } // validate the attributes var attributesValidated = $('#productDetailsAddToCartForm') .validate() .form(); if (!attributesValidated) { return false; } if (!CheckQuantityLimits(form)) { return false; } if(required && !$(form).find('.CartVariationId').val()) { alert(lang.OptionMessage); var select = $(form).find('select').get(0); if(select) { select.focus(); } var radio = $(form).find('input[type=radio]').get(0); if(radio) { radio.focus(); } return false; } if (!CheckEventDate()) { return false; } // if we're using the fastcart, pop that up now if (config.FastCart) { return fastCartAction(); } return true; } function compareProducts(compare_path) { var pids = ""; if($('form').find('input[name=compare_product_ids]:checked').size() >= 2) { var cpids = document.getElementsByName('compare_product_ids'); for(i = 0; i < cpids.length; i++) { if(cpids[i].checked) pids = pids + cpids[i].value + "/"; } pids = pids.replace(/\/$/, ""); document.location.href = compare_path + pids; return false; } alert(lang.CompareSelectMessage); return false; } function product_comparison_box_changed(state) { // Increment num_products_to_compare - needs to be > 0 to submit the product comparison form if(state) num_products_to_compare++; else if (num_products_to_compare != 0) num_products_to_compare--; } function remove_product_from_comparison(id) { if(num_compare_items > 2) { for(i = 1; i < 11; i++) { document.getElementById("compare_"+i+"_"+id).style.display = "none"; } num_compare_items--; } else { alert(lang.CompareTwoProducts); } } (function($){ $.fn.captchaPlaceholder = function () { $(this).each(function(){ var $$ = $(this); if (!$$.parent().is(':visible')) { // don't do anything if this placeholder isn't visible return; } var img = $$.find('.captchaImage'); if (img.length) { // don't do anything if an image is already in the dom return; } var rand = Math.round(500 + Math.random() * 7500); img = $(''); $$.append(img); }); return this; }; })(jQuery); function show_product_review_form() { document.getElementById("rating_box").style.display = ""; if(typeof(HideProductTabs) != 'undefined' && HideProductTabs == 0) { CurrentProdTab = 'ProductReviews_Tab'; } else { document.location.href = "#write_review"; } $('.captchaPlaceholder').captchaPlaceholder(); } function jump_to_product_reviews() { if(typeof(HideProductTabs) != 'undefined' && HideProductTabs == 0) { CurrentProdTab = 'ProductReviews_Tab'; } else { document.location.href = "#reviews"; } } function g(id) { return document.getElementById(id); } function check_product_review_form() { var revrating = g("revrating"); var revtitle = g("revtitle"); var revtext = g("revtext"); var revfromname = g("revfromname"); var captcha = g("captcha"); if(revrating.selectedIndex == 0) { alert(lang.ReviewNoRating); revrating.focus(); return false; } if(revtitle.value == "") { alert(lang.ReviewNoTitle); revtitle.focus(); return false; } if(revtext.value == "") { alert(lang.ReviewNoText); revtext.focus(); return false; } if(captcha.value == "" && HideReviewCaptcha != "none") { alert(lang.ReviewNoCaptcha); captcha.focus(); return false; } return true; } function check_small_search_form() { var search_query = g("search_query"); if(search_query.value == "") { alert(lang.EmptySmallSearch); search_query.focus(); return false; } return true; } function setCurrency(currencyId) { var gotoURL = location.href; if (location.search !== '') { if (gotoURL.search(/[&|\?]setCurrencyId=[0-9]+/) > -1) gotoURL = gotoURL.replace(/([&|\?]setCurrencyId=)[0-9]+/, '$1' + currencyId); else gotoURL = gotoURL + '&setCurrencyId=' + currencyId; } else gotoURL = gotoURL + '?setCurrencyId=' + currencyId; location.href = gotoURL; } // Dummy sel_panel function for when design mode isn't enabled function sel_panel(id) {} function inline_add_to_cart(filename, product_id, quantity, returnTo) { if(typeof(quantity) == 'undefined') { var quantity = '1'; } var html = '