function is_valid_email(email) { // Regular expression pattern for email validation var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Test the email against the pattern return emailPattern.test(email); } var delay = (function(){ var timer = window.my_awesome_autocomplete_box_timeoutId; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); }; })(); function validateEmail(email) { if( /(.+)@(.+){2,}\.(.+){2,}/.test(email) ){ return true; } else { return false; } } function choose_shade_option(thisvalue) { var bits=thisvalue.split(","); // $accessory_counter.'\',\''.$bits[0].'\',\''.$color.'\',\''.number_format($item_price_array[$bits[0]],2,'.',',').'">'.$color.' var classname = bits[0]; var item_id = bits[1]; var size = bits[2]; var option_price = bits[3]; $('#'+classname+'_price').html(option_price); $('#'+classname+'_item_id').html(item_id); $('#'+classname+'_item_size').html(size); } function choose_multisize_option(item_id) { var item_name = $('#'+item_id+'_item_name').html(); var item_price = $('#'+item_id+'_item_price').html(); $('.buysqu').css("color","#000000"); $('.buysqu').css("background-color","#ffffff"); $('.buysqu').css("border-color","#cccccc"); $('#fromprice').css("display","none"); $('#price').html(item_price); $('#chosen_id').html(item_id); $('#'+item_id+'_button').css("color","#ffffff"); $('#'+item_id+'_button').css("background-color","#f15a01"); $('#'+item_id+'_button').css("border-color","#f15a01"); } function choose_multisize_add() { var item_id = $('#chosen_id').html(); var item_name = $('#'+item_id+'_item_name').html(); var item_price = $('#'+item_id+'_item_price').html(); $('#added_accessory_cart_contents').html(item_name); $('#added_accessory_cart').fadeIn(400); //add to cart $.ajax({url: "/ajax_store/add_cart/i"+item_id+"/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); //set callback to make disappear myVar = setTimeout(hide_accessory_cart, 4000); } function add_shade_to_cart(classname) { var item_id = $('#'+classname+'_item_id').html(); var item_name = $('#'+classname+'_item_size').html(); console.log("adding the item"); $('#add_cart_'+classname).css("color","#fff"); $('#add_cart_'+classname).css("background-color","#4caf50"); $('#add_cart_'+classname).css("border-color","#4caf50"); $('#added_accessory_cart_contents').html(item_name); $('#added_accessory_cart').fadeIn(400); console.log("/ajax_store/add_cart/i"+item_id+"/"); //add to cart $.ajax({url: "/ajax_store/add_cart/i"+item_id+"/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); //set callback to make disappear myVar = setTimeout(hide_accessory_cart, 4000); } function acc_multi_choose_item(inventory_item_id,price,name) { $('.acc_price_total').html('$'+price); $('#1_item_id').html(inventory_item_id); $('#1_item_id_name').html(name); $('#afterpay_product_id').html('i'+inventory_item_id); } function escalade_option(classname,item_id,override_color,option_price) { $('.escalade_acc_'+classname).css("display","none"); $('#escalade_accessory_'+classname+"_"+item_id).css("display","block"); //since we are changing the size, make the "add to cart" button the default colours $('#add_cart_'+classname).css("color","#f15a01"); $('#add_cart_'+classname).css("background-color","#fff"); $('#add_cart_'+classname).css("border-color","#f15a01"); //register the chosen option $('#'+classname+'_item_id').html(item_id); if ( $('#opt-'+classname+'-'+item_id+'-tick').length )//tick element exists { //hide tick options from all in sequence $('.opt-'+classname).html(""); //dont change colours, just show a tick icon $('#opt-'+classname+"-"+item_id+'-tick').html('check'); } else { //change colours if(override_color != '') { var color=override_color; } else { var color='f15a01'; } //make all divs in that sequance standard orange and white $('.opt-'+classname).css("color","#f15a01"); $('.opt-'+classname).css("background-color","#fff"); $('.opt-'+classname).css("border-color","#f15a01"); //select the chosen option as grey/white $('.opt-'+classname+'-'+item_id).css("color","#fff"); $('.opt-'+classname+'-'+item_id).css("background-color","#"+color); $('.opt-'+classname+'-'+item_id).css("border-color","#"+color); } //fade current image out and new image in $('#opt-'+classname).fadeOut(300, function() { $('#opt-'+classname).attr("src",'/img/items/'+item_id+'-web.jpg'); if(option_price!=''){$('#price'+classname).html('$'+option_price);} }); $('#opt-'+classname).delay(300).fadeIn(400); } function escalade_change_tramp_landing(size_id,make_id,promo,trailer) { $('.escalade_make_'+make_id).css("display","none"); $('#escalade_size_'+size_id).css("display","block"); var country=$('#web_country_code').html(); var no_skirt; if(size_id == '31' || size_id == '32' || size_id == '33' ) { no_skirt='_no_skirt'; } else { no_skirt=''; } //fade out current image $('#tramp_thumb_'+make_id).fadeOut(300, function() { //change the image source if(promo=='1')//shade promo { $('#tramp_thumb_'+make_id).attr('src','/img/sizes/'+size_id+'-web_shade'+no_skirt+'.jpg'); } else if(promo=='3')//tent { $('#tramp_thumb_'+make_id).attr('src','/img/sizes/'+size_id+'-web_tent'+no_skirt+'.jpg'); } else if(promo=='2')//bball promo { $('#tramp_thumb_'+make_id).attr('src','/img/sizes/'+size_id+'-web-hoop'+no_skirt+'.jpg'); } else { $('#tramp_thumb_'+make_id).attr('src','/img/sizes/'+size_id+'-web'+no_skirt+'.jpg'); } }); //fade in image $('#tramp_thumb_'+make_id).fadeIn(300); //var height = $('#size_height_'+size_id).html(); var diameter = $('#size_diameter_'+size_id).html(); //change price //$('#height_'+make_id).html(height); $('#diameter_'+make_id).html(diameter); $('#diameter_'+make_id+'_2').html(diameter); } function change_tramp_landing(size_id,make_id,promo,trailer) { //change image var country=$('#web_country_code').html(); //fade out current image $('#tramp_thumb_'+make_id).fadeOut(300, function() { //change the image source if(promo=='1')//shade promo { $('#tramp_thumb_'+make_id).attr('src','/img/sizes/'+size_id+'-web_shade.jpg?1=9'); } else if(promo=='3')//tent { $('#tramp_thumb_'+make_id).attr('src','/img/sizes/'+size_id+'-web_tent.jpg?1=9'); } else if(promo=='2')//bball promo { $('#tramp_thumb_'+make_id).attr('src','/img/sizes/'+size_id+'-web-hoop.jpg?1=9'); } else { $('#tramp_thumb_'+make_id).attr('src','/img/sizes/'+size_id+'-web.jpg?1=9'); } }); //fade in image $('#tramp_thumb_'+make_id).fadeIn(300); var zipmoney_devide_weeks = $('#size_pricezip_'+size_id).html(); var price = $('#size_price_'+size_id).html(); var wasprice = $('#size_was_price_'+size_id).html(); wasprice = wasprice.replace(",", ""); price = price.replace(",", ""); wasprice = parseFloat(wasprice); wasprice=wasprice*1; price = parseFloat(price); price=price*1; //change price if(country=='au') // show zipmoney for Australia { var zipmodal; var weeklyprice = price + 25; // add a $25 establishment fee weeklyprice = weeklyprice +102; // add $102 monthly fees over 17 months weeklyprice = weeklyprice / 73; weeklyprice=Math.ceil(weeklyprice); // round up to nearest dollar if(price > 1000) { //var weeklyprice = price/12; //weeklyprice = weeklyprice/4.33; //weeklyprice=Math.round(weeklyprice * 100) / 100; zipmodal='Pay with Zip or $'+weeklyprice+' / week* interest FREE'; } else { zipmodal='Pay with Zip or $'+weeklyprice+' / week* interest FREE'; } var was_price_text; if(wasprice > price) { was_price_text='

Was $'+wasprice+'

'; } else { was_price_text=''; } $('#tramp_price_'+make_id).html('

$'+price+'

'+was_price_text); $('#tramp_zip_under_'+make_id).html('

'+zipmodal+'

'); } else // for any other country - show zipmoney breakdown { $('#tramp_price_'+make_id).html('

$'+price+'

'); $('#tramp_zip_under_'+make_id).html(''); } var saving = wasprice - price; saving = Math.ceil(saving * 100)/100; if(saving > 0) { $('#was_price_strike_'+make_id).html('Was $'+wasprice+''); $('#save_price_strike_'+make_id).html('Save $'+saving+trailer); } else { $('#was_price_strike_'+make_id).html(''); trailer = trailer.substring(2); $('#save_price_strike_'+make_id).html(trailer); // Free Shade Cover! } if( $('#out_ofstockitems_'+size_id).length ) // is this SIZE an out of stock item? { $('#add_cart_btn_'+make_id).css("display","none"); $('#low_stock_msg_'+make_id).css("display","block"); } else { $('#add_cart_btn_'+make_id).css("display","block"); $('#low_stock_msg_'+make_id).css("display","none"); } //var height = $('#size_height_'+size_id).html(); var diameter = $('#size_diameter_'+size_id).html(); //change price //$('#height_'+make_id).html(height); $('#diameter_'+make_id).html(diameter); $('#diameter_'+make_id+'_2').html(diameter); } function add_playset_install_cart(item_id,item_name) { //hide modals $('#install_type_modal').css('display','none'); $('.lean-overlay').css('display','none'); $('#added_accessory_cart_contents').html(item_name); $('#added_accessory_cart').fadeIn(400); //add to cart $.ajax({url: "/ajax_store/add_cart/i"+item_id+"/", async: false, success: function(result){ }}); //set callback to make disappear myVar = setTimeout(hide_accessory_cart, 4000); } function closesms() { $('#blackout').css("display","none"); $('#smsquest').css("display","none"); } function hide_sms_error() { $('#sorrysms').css("display","none"); //hide error message } function validate_sms_code() { //smscode value var code = $('#smscode').val(); var coderesult; if(code.length !=6) //check 6 digits long { $('#sorrysms').css("display","block"); //show error message } else { $.ajax({url: "/ajax_store/validate_sms_code/"+code+"/", async: false, success: function(result){ coderesult = result; }}); if(coderesult == 'validated') // the same { $('#smsvalidated').val('1'); // and hide button to resubmit page $('#yessms').css("display","block"); //show success message $('#sorrysms').css("display","none"); //show error message $('#alternativesms').css("display","none"); //show error message // submit form document.getElementById("complete").submit(); } else // not the same { //return error message $('#sorrysms').css("display","block"); //show error message } } } function toggleterms() { if( document.getElementById('termsshipping').style.display == 'none' ) { $('#termsshipping').css("display","block"); } else { $('#termsshipping').css("display","none"); } } function save_address_line(address, postcode) { $('#contact_address_2').val(address); $('#contact_zip_suburb').val(postcode); $('#address_alert').html(''); saveorder('0'); } function saveorder(checkaddress) { console.log('saveorder()'); //since user has gone back to editing the address, hide these buttons $('.inside_australia').css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#continue_button').css("display","none"); $('#contact_alert').html(""); //create 1.5 second delay, so this function is not being hit over and over agin delay(function(){ var save_suburb_id = $('#save_suburb_id').val(); if(checkaddress=='1' && save_suburb_id > 0) // if any suburb id selected { //check address is valid check_address(); } var enough_details=false; //get data entered into client feilds var contact_name = $('#contact_name').val(); var contact_lastname = $('#contact_lastname').val(); var contact_email = $('#contact_email').val(); var contact_phone_mobile = $('#contact_phone_mobile').val(); var contact_acode_home = $('#contact_acode_home').val(); var contact_phone_home = $('#contact_phone_home').val(); var contact_postcode = $('#contact_zip_suburb').val(); var contact_address_1 = $('#contact_address_1').val(); var contact_address_2 = $('#contact_address_2').val(); //is the address a PO box ? var contact_address_lowercase = contact_address_2.toLowerCase(); contact_address_lowercase = ' '+contact_address_lowercase+' '; var po_one = contact_address_lowercase.indexOf('po box'); var po_two = contact_address_lowercase.indexOf("pobox"); var po_three = contact_address_lowercase.indexOf("p.o."); var po_three = contact_address_lowercase.indexOf("p.o box"); var locked_bag = contact_address_lowercase.indexOf('locked bag'); var private_bag = contact_address_lowercase.indexOf('private bag'); var pacel_locker = contact_address_lowercase.indexOf('parcel locker'); var pacel_collect = contact_address_lowercase.indexOf('parcel collect'); //console.log('contact_address_lowercase = '+contact_address_lowercase); //console.log('po_one = '+po_one+' po_two = '+po_two); var hide_rest_of_form_po_box=false; if(po_one > 0 || po_two > 0 || po_three > 0 || locked_bag > 0 || private_bag > 0 || pacel_locker > 0 || pacel_collect > 0) { hide_rest_of_form_po_box=true; $('#po_box_error').css("display","block"); } else { $('#po_box_error').css("display","none"); } var combinedphones = contact_phone_mobile + contact_phone_home; var combinedaddresses = contact_address_1 + contact_address_2; //if we have the necessary details, ensure that the shipping options are shown if(save_suburb_id == '' || contact_postcode.length < 4 || contact_email.length < 9 || combinedphones.length < 8 || contact_name.length < 2 || contact_lastname.length < 2 || combinedaddresses.length < 7) { //alert(save_suburb_id + ' | ' + contact_email+ ' | ' + combinedphones + ' | ' + contact_name+ ' | ' + contact_lastname+ ' | ' + combinedaddresses);; console.log('insufficient information. hide #delivery_methods'); $('.inside_australia').css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $('#delivery_methods').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); if(save_suburb_id > 0) { if(contact_email.length < 9) { $('#contact_alert').html('
report_problem Please complete your email address above to continue.
'); } else if(combinedphones.length < 8) { $('#contact_alert').html('
report_problem Please complete your phone or mobile above to continue.
'); } else if( contact_name.length < 2 || contact_lastname.length < 2) { $('#contact_alert').html('
report_problem Please complete your name and surname above to continue.
'); } else if( combinedaddresses.length < 7) { $('#contact_alert').html('
report_problem Please complete your shipping address above to continue.
'); } } } else { console.log('sufficient information. show #delivery_methods'); if(hide_rest_of_form_po_box==true) // PO box used as address { console.log('hide_rest_of_form_po_box == true'); $('.inside_australia').css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $('#delivery_methods').css("display","none"); } else { $('.inside_australia').css("display","block"); $('#delivery_methods').css("display","block"); adopt_pickup_method_2020(); // new 2020 template } } //check that either a valid email or sufficiently long phone number or mobile has been entered if( contact_name.length < 2) // no first name { //console.log('no first name'); enough_details=false; } else { if(validateEmail(contact_email)) { //console.log('email is valid'); enough_details=true; } else if (contact_phone_home.length > 7) { //console.log('has phone number'); enough_details=true; } else if (contact_phone_mobile.length > 9) { //console.log('has mobile number'); enough_details=true; } } //if enough details to save if(enough_details==true) { //console.log('enough details to continue'); //strip non digits contact_phone_home = contact_phone_home.replace(/\D/g,''); contact_acode_home = contact_acode_home.replace(/\D/g,''); contact_phone_mobile = contact_phone_mobile.replace(/\D/g,''); var mobile_first_three = contact_phone_mobile.substr(0, 3); var mobile_first_two = contact_phone_mobile.substr(0, 2); if(mobile_first_three == '+61') { contact_phone_mobile='0'+contact_phone_mobile.substr(3); } else if(mobile_first_two == '61') { contact_phone_mobile='0'+contact_phone_mobile.substr(2); } var home_first_three = contact_phone_home.substr(0, 3); var home_first_two = contact_phone_home.substr(0, 2); if(home_first_three == '+61') { contact_phone_home = contact_phone_home.substr(3); } else if(home_first_two == '61') { contact_phone_home = contact_phone_home.substr(2); } if(contact_phone_mobile=='') { contact_phone_mobile='0'; } if(contact_phone_home=='') { contact_phone_home='0'; } if(contact_address_1=='') { contact_address_1='0'; } if(contact_address_2=='') { contact_address_2='0'; } if(save_suburb_id=='') { save_suburb_id='0'; } if(save_suburb_id=='0') { var international_suburb = $('#internation_suburb').val(); var internation_country = $('#internation_country').val(); //take international country and suburb contact_address_2 = contact_address_2 + ' ' + international_suburb; } if(contact_postcode=='') { contact_postcode='0'; } if(contact_email=='') { contact_email='none'; } if(contact_name=='') { contact_name='none'; } if(contact_lastname=='') { contact_lastname='none'; } check_show_delivery(hide_rest_of_form_po_box); $.ajax({url: "/ajax_store/saveorder/"+encodeURIComponent(contact_name)+"|||"+encodeURIComponent(contact_lastname)+"|||"+encodeURIComponent(contact_email)+"/"+encodeURIComponent(contact_phone_mobile)+"|||"+encodeURIComponent(contact_acode_home+''+contact_phone_home)+"/"+encodeURIComponent(contact_address_1)+"|||"+encodeURIComponent(contact_address_2)+"/"+save_suburb_id+"-"+internation_country+'-'+contact_postcode+'/', async: false, success: function(result){ //$("#shs_label").html(result); // alert('result = '+result); }}); } }, 1100); } function saveorderusa(checkaddress) { var verified_usa_zip = false; console.log('saveorderusa called'); //since user has gone back to editing the address, hide these buttons $('.cannot_deliver').css("display","none"); $('.inside_australia').css("display","none"); //$("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $('#lead_origin_header').css("display","none"); $('#lead_origin_options').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#continue_button').css("display","none"); $('#contact_alert').html(""); //create 1.5 second delay, so this function is not being hit over and over agin delay(function(){ //var save_suburb_id = $('#save_suburb_id').val(); if(checkaddress=='1' && save_suburb_id > 0) // if any suburb id selected { //check address is valid check_address(); } //get data entered into client feilds var contact_name = $('#contact_name').val(); contact_name = contact_name.trim(); var contact_lastname = $('#contact_lastname').val(); contact_lastname = contact_lastname.trim(); var contact_email = $('#contact_email').val(); contact_email = contact_email.trim(); var contact_phone_mobile = $('#contact_phone_mobile').val(); contact_phone_mobile = contact_phone_mobile.trim(); //strip non digits //contact_phone_home = contact_phone_home.replace(/\D/g,''); //contact_acode_home = contact_acode_home.replace(/\D/g,''); contact_phone_mobile = contact_phone_mobile.replace(/\D/g,''); //var contact_acode_home = $('#contact_acode_home').val(); //var contact_phone_home = $('#contact_phone_home').val(); var contact_zip = $('#zip-input').val(); var contact_city = $('#city-input').val(); var contact_state = $('#state-input').val(); var contact_country = $('#country-input').val(); var contact_address_1 = $('#contact_address_1').val(); var contact_address_2 = $('#contact_address_2').val(); var call_me; call_me='no'; // default if($('#call_me').is(':checked')) //chose to wait for all order { call_me='yes'; } //is the address a PO box ? var contact_address_lowercase = contact_address_2.toLowerCase(); contact_address_lowercase = ' '+contact_address_lowercase+' '; var po_one = contact_address_lowercase.indexOf('po box'); var po_two = contact_address_lowercase.indexOf("pobox"); var po_three = contact_address_lowercase.indexOf("p.o."); var po_three = contact_address_lowercase.indexOf("p.o box"); var locked_bag = contact_address_lowercase.indexOf('locked bag'); var private_bag = contact_address_lowercase.indexOf('private bag'); var pacel_locker = contact_address_lowercase.indexOf('parcel locker'); var pacel_collect = contact_address_lowercase.indexOf('parcel collect'); //console.log('contact_address_lowercase = '+contact_address_lowercase); //console.log('po_one = '+po_one+' po_two = '+po_two); var hide_rest_of_form_po_box=false; if(po_one > 0 || po_two > 0 || po_three > 0 || locked_bag > 0 || private_bag > 0 || pacel_locker > 0 || pacel_collect > 0) { hide_rest_of_form_po_box=true; $('#po_box_error').css("display","block"); } else { $('#po_box_error').css("display","none"); } var combinedaddresses = contact_address_1 + contact_address_2; //if we have the necessary details, ensure that the shipping options are shown if(contact_zip.length < 4 || contact_email.length < 7 || contact_phone_mobile.length < 6 || contact_name.length < 2 || contact_lastname.length < 2 || combinedaddresses.length < 7) { //alert(save_suburb_id + ' | ' + contact_email+ ' | ' + combinedphones + ' | ' + contact_name+ ' | ' + contact_lastname+ ' | ' + combinedaddresses);; console.log('insufficient information. hide #delivery_methods'); $('.inside_australia').css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $('#delivery_methods').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); if(contact_zip > 0) { if(contact_email.length < 9) { $('#contact_alert').html('
report_problem Please complete your email address above to continue.
'); } else if(contact_phone_mobile.length < 6) { $('#contact_alert').html('
report_problem Please complete your phone or mobile above to continue.
'); } else if( contact_name.length < 2 || contact_lastname.length < 2) { $('#contact_alert').html('
report_problem Please complete your name and surname above to continue.
'); } else if( combinedaddresses.length < 7) { $('#contact_alert').html('
report_problem Please complete your shipping address above to continue.
'); } } } else { console.log('sufficient information. show #delivery_methods'); if(hide_rest_of_form_po_box==true) // PO box used as address { //console.log('hide_rest_of_form_po_box == true'); //$('.inside_australia').css("display","none"); //$("#next_button").css("display","block"); //$("#next_button_submit").css("display","none"); //$('#delivery_methods').css("display","none"); } else { //$('.inside_australia').css("display","block"); //$('#delivery_methods').css("display","block"); //adopt_pickup_method_2020(); // new 2020 template } } //////////////now, saving the order ////////////////// //check that either a valid email or sufficiently long phone number or mobile has been entered if( contact_name.length > 1 && contact_email.length > 6 && contact_phone_mobile.length > 5) { console.log('enough details to continue'); if(contact_address_1=='') { contact_address_1='0'; } if(contact_address_2=='') { contact_address_2='0'; } if(contact_email=='') { contact_email='none'; } if(contact_name=='') { contact_name='none'; } if(contact_lastname=='') { contact_lastname='none'; } //alert("/ajax_store/saveorder/"+encodeURIComponent(contact_name)+"/"+encodeURIComponent(contact_lastname)+"/"+encodeURIComponent(contact_email)+"/"+encodeURIComponent(contact_phone_mobile)+"/"+encodeURIComponent(contact_acode_home+''+contact_phone_home)+"/"+encodeURIComponent(contact_address_1)+"/"+encodeURIComponent(contact_address_2)+"/"+save_suburb_id+"-"+internation_country+'-'+contact_postcode+'/'); //alert('sending: '+save_suburb_id+' '+contact_postcode); //check_show_delivery(hide_rest_of_form_po_box); var aj_url="/ajax_store/saveorderusa/"+encodeURIComponent(contact_name)+"|||"+encodeURIComponent(contact_lastname)+"|||"+encodeURIComponent(contact_email)+"/"+encodeURIComponent(contact_phone_mobile)+"/"+encodeURIComponent(contact_address_1)+"|||"+encodeURIComponent(contact_address_2)+"/"+contact_zip+"-"+encodeURIComponent(contact_city)+"-"+encodeURIComponent(contact_state)+"-"+encodeURIComponent(contact_country)+"-"+call_me+"/"; console.log(aj_url); $.ajax({url: aj_url, async: false, success: function(result){ //$("#shs_label").html(result); //alert('result = '+result); console.log(result); // //var contact_city = $('#city-input').val(); //var contact_state = $('#state-input').val(); //var contact_country = $('#country-input').val(); if (contact_city !== '' && contact_state !== '' && contact_country !== '' && combinedaddresses.length > 5) { if(result[1]['usa_tax_amount']>0) { $('#taxes-amount').html('$'+result[1]['usa_tax_amount']); $('#taxes-holder').css('display', 'block'); } else { $('#taxes-amount').html('N/A'); } if(result[1]['usa_shipping_amount']>0) { $('#shipping-amount').html('$'+result[1]['usa_shipping_amount']); } else { $('#shipping-amount').html('FREE'); } if(result[1]['usa_final_order_amount']>0) { $('#total-selector').html(result[1]['usa_final_order_amount']); } if(result[1]['freighter']!=='') { $('#freighter-holder').html(result[1]['freighter']); } if (contact_state === "AK" || contact_state === "AS" || contact_state === "HI" || contact_state === "PR" || contact_state === "TT" || contact_state === "VI" || contact_state === "MP") { console.log("State input is not allowed: "+contact_state); console.log('hide inside australia'); $('.cannot_deliver').css("display","block"); } else { $('.inside_australia').css("display","block"); $('#delivery_methods').css("display","block"); $('#address_holder').css("display","table"); $('#zip_holder').css("display","table"); $('#city_holder').css("display","table"); $('#state_holder').css("display","table"); $('#country_holder').css("display","table"); $('#lead_origin_header').css("display","block"); $('#lead_origin_options').css("display","block"); $('.mob_summary_box-1').css("display","block"); $('.mob_summary_box-2').css("display","block"); $('#zip-msg-box').css("display","none"); } } }}); //console.log("/ajax_store/saveorderusa/"+encodeURIComponent(contact_name)+"|||"+encodeURIComponent(contact_lastname)+"|||"+encodeURIComponent(contact_email)+"/"+encodeURIComponent(contact_phone_mobile)+"|||"+encodeURIComponent(contact_acode_home+''+contact_phone_home)+"/"+encodeURIComponent(contact_address_1)+"|||"+encodeURIComponent(contact_address_2)+"/"+contact_zip+"/"); } else { console.log('not enough details'); } var autocompleteLoader = document.getElementById("autocomplete_loader"); if (autocompleteLoader) { autocompleteLoader.style.display = "none"; } }, 1100); } function saveorderCA(checkaddress) { var verified_usa_zip = false; console.log('saveorderCA called'); //since user has gone back to editing the address, hide these buttons $('.cannot_deliver').css("display","none"); $('.inside_australia').css("display","none"); //$("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $('#lead_origin_header').css("display","none"); $('#lead_origin_options').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#continue_button').css("display","none"); $('#contact_alert').html(""); //create 300ms second delay, so this function is not being hit over and over agin delay(function(){ //get data entered into client feilds var contact_name = $('#contact_name').val(); contact_name = contact_name.trim(); var contact_lastname = $('#contact_lastname').val(); contact_lastname = contact_lastname.trim(); var contact_email = $('#contact_email').val(); contact_email = contact_email.trim(); var contact_phone_mobile = $('#contact_phone_mobile').val(); contact_phone_mobile = contact_phone_mobile.trim(); contact_phone_mobile = contact_phone_mobile.replace(/\D/g,''); var contact_zip = $('#zip-input').val(); var contact_city = $('#city-input').val(); var contact_state = $('#state-input').val(); var contact_country = $('#country-input').val(); var contact_address_1 = $('#contact_address_1').val(); var contact_address_2 = $('#contact_address_2').val(); var call_me; call_me='no'; // default if($('#call_me').is(':checked')) //chose to wait for all order { call_me='yes'; } //is the address a PO box ? var contact_address_lowercase = contact_address_2.toLowerCase(); contact_address_lowercase = ' '+contact_address_lowercase+' '; var po_one = contact_address_lowercase.indexOf('po box'); var po_two = contact_address_lowercase.indexOf("pobox"); var po_three = contact_address_lowercase.indexOf("p.o."); var po_three = contact_address_lowercase.indexOf("p.o box"); var locked_bag = contact_address_lowercase.indexOf('locked bag'); var private_bag = contact_address_lowercase.indexOf('private bag'); var pacel_locker = contact_address_lowercase.indexOf('parcel locker'); var pacel_collect = contact_address_lowercase.indexOf('parcel collect'); var hide_rest_of_form_po_box=false; if(po_one > 0 || po_two > 0 || po_three > 0 || locked_bag > 0 || private_bag > 0 || pacel_locker > 0 || pacel_collect > 0) { hide_rest_of_form_po_box=true; $('#po_box_error').css("display","block"); } else { $('#po_box_error').css("display","none"); } var combinedaddresses = contact_address_1 + contact_address_2; //if we have the necessary details, ensure that the shipping options are shown if(contact_zip.length < 4 || contact_email.length < 7 || contact_phone_mobile.length < 6 || contact_name.length < 2 || contact_lastname.length < 2 || combinedaddresses.length < 7) { console.log('insufficient information. hide #delivery_methods'); $('.inside_australia').css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $('#delivery_methods').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); if(contact_email.length < 9) { $('#contact_alert').html('
report_problem Please complete your email address above to continue.
'); } else if(contact_phone_mobile.length < 6) { $('#contact_alert').html('
report_problem Please complete your phone or mobile above to continue.
'); } else if( contact_name.length < 2 || contact_lastname.length < 2) { $('#contact_alert').html('
report_problem Please complete your name and surname above to continue.
'); } else if( combinedaddresses.length < 7) { $('#contact_alert').html('
report_problem Please complete your shipping address above to continue.
'); } else { //alert('no zip code'); $('#contact_alert').html('
report_problem Please complete your shipping address above to continue.
'); } } else { console.log('sufficient information. show #delivery_methods'); } //////////////now, saving the order ////////////////// //check that either a valid email or sufficiently long phone number or mobile has been entered if( contact_name.length > 1 && contact_email.length > 6 && contact_phone_mobile.length > 5) { //console.log('enough details to continue'); $('#parent_shipping_container').css("display","block"); //alert('show address input'); if(contact_address_1=='') { contact_address_1='0'; } if(contact_address_2=='') { contact_address_2='0'; } if(contact_email=='') { contact_email='none'; } if(contact_name=='') { contact_name='none'; } if(contact_lastname=='') { contact_lastname='none'; } //alert("/ajax_store/saveorder/"+encodeURIComponent(contact_name)+"/"+encodeURIComponent(contact_lastname)+"/"+encodeURIComponent(contact_email)+"/"+encodeURIComponent(contact_phone_mobile)+"/"+encodeURIComponent(contact_acode_home+''+contact_phone_home)+"/"+encodeURIComponent(contact_address_1)+"/"+encodeURIComponent(contact_address_2)+"/"+save_suburb_id+"-"+internation_country+'-'+contact_postcode+'/'); //alert('sending: '+save_suburb_id+' '+contact_postcode); //check_show_delivery(hide_rest_of_form_po_box); var aj_url="/ajax_store/saveorderca/"+encodeURIComponent(contact_name)+"|||"+encodeURIComponent(contact_lastname)+"|||"+encodeURIComponent(contact_email)+"/"+encodeURIComponent(contact_phone_mobile)+"/"+encodeURIComponent(contact_address_1)+"|||"+encodeURIComponent(contact_address_2)+"/"+contact_zip+"<=>"+encodeURIComponent(contact_city)+"<=>"+encodeURIComponent(contact_state)+"<=>"+encodeURIComponent(contact_country)+"<=>"+call_me+"/"; console.log(aj_url); $.ajax({url: aj_url, async: false, success: function(result){ if (contact_city !== '' && contact_state !== '' && contact_country !== '' && combinedaddresses.length > 5) { if(result[1]['ca_tax_amount']>0) { $('#taxes-amount').html('$'+result[1]['ca_tax_amount']); $('#taxes-holder').css('display', 'block'); } else { $('#taxes-amount').html('N/A'); } if(result[1]['ca_shipping_amount']>0) { $('#shipping-amount').html('$'+result[1]['ca_shipping_amount']); } else { $('#shipping-amount').html('FREE'); } if(result[1]['ca_final_order_amount']>0) { $('#total-selector').html(result[1]['ca_final_order_amount']); } if(result[1]['freighter']!=='') { $('#freighter-holder').html(result[1]['freighter']); } if (contact_state === "AK" || contact_state === "AS" || contact_state === "HI" || contact_state === "PR" || contact_state === "TT" || contact_state === "VI" || contact_state === "MP") { console.log("State input is not allowed: "+contact_state); console.log('hide inside australia'); $('.cannot_deliver').css("display","block"); } else { $('.inside_australia').css("display","block"); $('#delivery_methods').css("display","block"); $('#address_holder').css("display","table"); $('#zip_holder').css("display","table"); $('#city_holder').css("display","table"); $('#state_holder').css("display","table"); $('#country_holder').css("display","table"); $('#lead_origin_header').css("display","block"); $('#lead_origin_options').css("display","block"); $('.mob_summary_box-1').css("display","block"); $('.mob_summary_box-2').css("display","block"); $('#zip-msg-box').css("display","none"); } } }}); } else { //$('#contact_alert').html('
report_problem Please enter a valid name, email address and phone number above to continue.
'); } }, 300); } function verify_email_address() { var contact_email = $('#contact_email').val(); var n = contact_email.length; //$.ajax({url: "/ajax_store/check_address/"+encodeURIComponent(contact_address_2)+"/"+suburb_id+"/"+encodeURIComponent(contact_address_1)+"/", async: false, success: function(result){ if(n < 1) { // do nothing } else if(n > 6) { $.ajax({url: "/ajax_store/verify_email_address_exists/"+encodeURIComponent(contact_email)+"/", async: true, success: function(result){ $("#address_alert").html(result); }}); } else { $("#address_alert").html('
report_problem Your email address does not exist. Please double check it.
'); } } function verify_email_address_with_delay() { //there has already been a 1 second delay before this function is called time_delay(function() { var contact_email = $('#contact_email').val(); var n = contact_email.length; //$.ajax({url: "/ajax_store/check_address/"+encodeURIComponent(contact_address_2)+"/"+suburb_id+"/"+encodeURIComponent(contact_address_1)+"/", async: false, success: function(result){ if(n < 1) { // do nothing } else if(n > 6) { $.ajax({url: "/ajax_store/verify_email_address_exists/"+encodeURIComponent(contact_email)+"/", async: true, success: function(result){ $("#address_alert").html(result); }}); } else { $("#address_alert").html('
report_problem Your email address does not exist. Please double check it.
'); } }, 1800); } function check_show_delivery(hide_rest_of_form_po_box) { //since user has gone back to editing their basic details $('.inside_australia').css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#continue_button').css("display","none"); //create 1.5 second delay, so this function is not being hit over and over agin delay(function(){ var save_suburb_id = $('#save_suburb_id').val(); //get data entered into client feilds var contact_name = $('#contact_name').val(); var contact_lastname = $('#contact_lastname').val(); var contact_email = $('#contact_email').val(); var contact_phone_mobile = $('#contact_phone_mobile').val(); var contact_acode_home = $('#contact_acode_home').val(); var contact_phone_home = $('#contact_phone_home').val(); var contact_address_1 = $('#contact_address_1').val(); var contact_address_2 = $('#contact_address_2').val(); var email_test = is_valid_email(contact_email); var combinedphones = contact_phone_mobile + contact_acode_home + contact_phone_home; var combinedaddresses = contact_address_1 + contact_address_2; //if we have the necessary details, ensure that the shipping options are shown if(save_suburb_id == '' || contact_email.length < 9 || combinedphones.length < 8 || contact_name.length < 2 || contact_lastname.length < 2 || combinedaddresses.length < 7 || email_test == false) { //alert(save_suburb_id + ' | ' + contact_email+ ' | ' + combinedphones + ' | ' + contact_name+ ' | ' + contact_lastname+ ' | ' + combinedaddresses);; $('.inside_australia').css("display","none"); $('#delivery_methods').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); if(contact_email.length < 9) { $('#contact_alert').html('
report_problem Please complete your email address above to continue.
'); } else if(combinedphones.length < 8) { $('#contact_alert').html('
report_problem Please complete your phone or mobile above to continue.
'); } else if( contact_name.length < 2 || contact_lastname.length < 2) { $('#contact_alert').html('
report_problem Please complete your name and surname above to continue.
'); } else if( combinedaddresses.length < 7) { $('#contact_alert').html('
report_problem Please complete your shipping address above to continue.
'); } } else { if(hide_rest_of_form_po_box == true) { //issue - PO box used in address } else { $('.inside_australia').css("display","block"); $('#delivery_methods').css("display","block"); } $('#contact_alert').html(""); adopt_pickup_method_2020(); // new 2020 template } if(contact_email.length > 8 ) { verify_email_address_with_delay(); } //saveorderusa("0"); }, 1100); } function check_address() { $("#address_alert").html(' '); var suburb_id = $('#save_suburb_id').val(); if(suburb_id > 0) // only validate if suburb id within australia { var contact_address_1 = $('#contact_address_1').val(); var contact_address_2 = $('#contact_address_2').val(); var email_address = $('#contact_email').val(); if(contact_address_1.length < 1) { contact_address_1='missing'; } if(contact_address_2.length < 3) { contact_address_2='missing'; } //$.ajax({url: "/ajax_store/check_address/"+encodeURIComponent(contact_address_2)+"/"+suburb_id+"/"+encodeURIComponent(contact_address_1)+"/", async: false, success: function(result){ $.ajax({url: "/ajax_store/check_address/"+encodeURIComponent(contact_address_2)+"/"+suburb_id+"/"+encodeURIComponent(email_address)+"/", async: false, success: function(result){ $("#address_alert").html(result); }}); } //saveorder('0'); } function check_promo_code_new() { var value = $('#promo_input').val(); value=value.trim(); value = value.substr(0, 50); var n = value.length; if(n > 2) // only do if 5 or more characters { //alert(value); $.ajax({url: "/ajax_store/check_promotional_code/"+encodeURIComponent(value)+"/", async: false, success: function(result){ $("#promo").val(value); $("#promo_result").html(result); $("#promocodemodal-new").openModal(); }}); } } /* old pre-2020 function */ function check_promo(value) { delay(function() //delay of 1 second { value = value.substr(0, 50); var n = value.length; if(n > 3) // only do if 5 or more characters { //alert(value); $.ajax({url: "/ajax_store/check_promotional_code/"+encodeURIComponent(value)+"/", async: false, success: function(result){ $("#promo_result").html(result); }}); } }, 1000); } function change_suburb_order(suburb_id,suburb_name,postcode) { $('#contact_zip_suburb').val(postcode); save_suburb_order(suburb_id,suburb_name); } function blur_element(element_id) { $(element_id).blur(); } function save_suburb_order_nz(suburb_id,suburb_name) { //$('#contact_zip_suburb').blur(); // un focus suburb field $("#outside_australia_onscreen").css("display","none"); $('#delivery_methods').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#contact_zip_suburb').val(suburb_name); $('#address_alert').html('
timelapse Checking email and address...
'); $('#shs_label').html('done Suburb Chosen:
'+suburb_name); //$('#shs_label').css( "background-color", "#d8ffdb" ); $('#save_suburb_id').val(suburb_id); var contact_address_1 = $('#contact_address_1').val(); var contact_address_2 = $('#contact_address_2').val(); if(contact_address_2 == '' && contact_address_1 != '') // the fields are around the wrong way { $('#contact_address_1').val(contact_address_2); $('#contact_address_2').val(contact_address_1); } if(suburb_id > 0) // within australia or NZ { //hide international shipping address $('#international_address').css("display","none"); //check address is valid saveorder('1'); //if(suburb_id > 0) // within australia //{ //hide delivery options if( $('#delivery_method').val() == 'delivery') // only check this if the delivery option is selected. otherwise it is premature to check this { //calculate delivery fee $.ajax({url: "/ajax_store/check_stock_levels/"+suburb_id+"/", async: true, success: function(result){ $("#stock_control_feedback").html(result); //show delivery options // $('#delivery_methods').css("display","block"); }}); } //} scroll_to_anchor('subscribenews'); } else // international { $('#address_alert').html(''); //show international shipping address $('#international_address').css("display","block"); //dont check validity of address saveorder('0'); //show international modal //calculate delivery fee $.ajax({url: "/ajax_store/get_order_id/", async: false, success: function(result){ $("#int_order_id").html(result); $("#int_order_id_onscreen").html(result); $('#outside_australia_modal').openModal(); $("#outside_australia_onscreen").css("display","block"); $("#delivery_methods").css("display","none"); }}); } } function save_suburb_order(suburb_id,suburb_name) { console.log('save_suburb_order('+suburb_id+' , '+suburb_name+' )'); $("#outside_australia_onscreen").css("display","none"); $('#delivery_methods').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#address_alert').html('Checking email and address...'); $('#shs_label').html('Suburb: '+suburb_name); //$('#shs_label').css( "background-color", "#d8ffdb" ); $('#save_suburb_id').val(suburb_id); $('#shs_label').css('padding','8px'); var contact_address_1 = $('#contact_address_1').val(); var contact_address_2 = $('#contact_address_2').val(); if(contact_address_2 == '' && contact_address_1 != '') // the fields are around the wrong way { $('#contact_address_1').val(contact_address_2); $('#contact_address_2').val(contact_address_1); } if(suburb_id > 0) // within australia { console.log('within australia'); //hide international shipping address $('#international_address').css("display","none"); //check address is valid saveorder('1'); //if(suburb_id > 0) // within australia //{ //hide delivery options if( $('#delivery_method').val() == 'delivery') // only check this if the delivery option is selected. otherwise it is premature to check this { //calculate delivery fee $.ajax({url: "/ajax_store/check_stock_levels/"+suburb_id+"/", async: true, success: function(result){ $("#stock_control_feedback").html(result); //show delivery options console.log('result = '+result); if(result=='brisbane') // ex brisbane { $('#perth_pickup_col').css("display","none"); $('#perth_pickup_col_na').css("display","block"); } else { $('#perth_pickup_col').css("display","block"); $('#perth_pickup_col_na').css("display","none"); } // $('#delivery_methods').css("display","block"); }}); } //} scroll_to_anchor('subscribenews'); } else // international { console.log('international'); $('#address_alert').html(''); //show international shipping address $('#international_address').css("display","block"); //dont check validity of address saveorder('0'); //show international modal //calculate delivery fee $.ajax({url: "/ajax_store/get_order_id/", async: false, success: function(result){ $("#int_order_id").html(result); $("#int_order_id_onscreen").html(result); $('#outside_australia_modal').openModal(); $("#outside_australia_onscreen").css("display","block"); $('.inside_australia').css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); console.log('hide #delivery_methods'); $("#delivery_methods").css("display","none"); }}); } } function reset_address_2020() { $('#fake_state_holder').html(''); $('#contact_zip_suburb').val(''); $('#suburb_searcher').css("display","table"); $('#fake_state_holder').css("display","none"); $(".inside_australia").css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $("#contact_zip_suburb").focus(); } function save_suburb_order_2020(suburb_id,suburb_name) { console.log('save_suburb_order('+suburb_id+' , '+suburb_name+' )'); $("#outside_australia_onscreen").css("display","none"); $('#delivery_methods').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#address_alert').html('
timelapse Checking email and address...
'); $('#shs_label').html(''); $('#fake_state_holder').html('
edit CHANGE
Suburb

'+suburb_name+'
'); $('#suburb_searcher').css("display","none"); $('#fake_state_holder').css("display","block"); //temporary message to states var foundin = suburb_name.indexOf(" VIC "); if(foundin < 2) { foundin = suburb_name.indexOf(" NSW "); } if(foundin > 1)//this order is for NSW or VIC { $('#delay_delivery').css("display","block"); } else { $('#delay_delivery').css("display","none"); } //$('#shs_label').css( "background-color", "#d8ffdb" ); $('#save_suburb_id').val(suburb_id); var contact_address_1 = $('#contact_address_1').val(); var contact_address_2 = $('#contact_address_2').val(); if(contact_address_2 == '' && contact_address_1 != '') // the fields are around the wrong way { $('#contact_address_1').val(contact_address_2); $('#contact_address_2').val(contact_address_1); } if(suburb_id > 0) // within australia { console.log('within australia'); //hide international shipping address $('#international_address').css("display","none"); $(".inside_australia").css("display","block"); adopt_pickup_method_2020(); // new 2020 template //$('#delivery_method').val('delivery'); //check address is valid saveorder('1'); //if(suburb_id > 0) // within australia //{ //hide delivery options if( $('#delivery_method').val() == 'delivery') // only check this if the delivery option is selected. otherwise it is premature to check this { //choose_delivery_fast('delivery'); //calculate delivery fee $.ajax({url: "/ajax_store/check_stock_levels/"+suburb_id+"/", async: true, success: function(result){ $("#stock_control_feedback").html(result); //show delivery options console.log('result = '+result); if(result=='brisbane') // ex brisbane { $('#perth_pickup_col').css("display","none"); $('#perth_pickup_col_na').css("display","block"); } else { $('#perth_pickup_col').css("display","block"); $('#perth_pickup_col_na').css("display","none"); } // $('#delivery_methods').css("display","block"); }}); } $.ajax({url: "/ajax_store/get_order_id/", async: true, success: function(result){ $("#saved_ord_id").val(result); }}); //} //scroll_to_anchor('subscribenews'); } else // international { console.log('international'); $('#address_alert').html(''); //show international shipping address $('#international_address').css("display","block"); //dont check validity of address saveorder('0'); //show international modal //calculate delivery fee $.ajax({url: "/ajax_store/get_order_id/", async: false, success: function(result){ $("#int_order_id").html(result); $("#int_order_id_onscreen").html(result); //$('#outside_australia_modal').openModal(); $(".inside_australia").css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); $("#outside_australia_onscreen").css("display","block"); $('.inside_australia').css("display","none"); $("#next_button").css("display","block"); $("#next_button_submit").css("display","none"); console.log('hide #delivery_methods'); $("#delivery_methods").css("display","none"); }}); } } function save_suburb_order_usa() { $("#outside_australia_onscreen").css("display","none"); $('#delivery_methods').css("display","none"); $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#international_address').css("display","none"); $(".inside_australia").css("display","block"); //adopt_pickup_method_2020(); // new 2020 template //$('#delivery_method').val('delivery'); //check address is valid //saveorder('1'); } function proceed_stock_option(option, days) { $('#deliverytermsandconditions').css("display","none"); $('#continue_button').css("display","none"); //hide continue button if(option == '1')// wait for all order { days=days*1; //set minimum days can book for set_pickdate_field('#shipping_date',days); $('#days_to_delivery').val(days); //create date from this day var someDate = new Date(); someDate.setDate(someDate.getDate() + days); var dd = someDate.getDate(); var mm = someDate.getMonth() + 1; var y = someDate.getFullYear(); $('#shipping_date').val(dd + '/'+ mm + '/'+ y); $('#earliestdate_bolded').html(dd + '/'+ mm + '/'+ y); //$('#earliestdate').html(); $('#choose_split_delivery_dates').css("display","none"); $('#choose_single_delivery_date').css("display","block"); //confirm freight and delivery fee $.ajax({url: "/ajax_store/confirm_freighter/", async: false, success: function(result){ $("#confirm_freighter").html(result); $('#confirm_freighter').css("display","block"); }}); } else if(option == '2')// split the order { $('#choose_single_delivery_date').css("display","none"); //show splitting options var suburb_id = $('#save_suburb_id').val(); $.ajax({url: "/ajax_store/show_splitting_options/"+suburb_id+"/", async: false, success: function(result){ $('#choose_split_delivery_dates').css("display","block"); var pieces = result.split('|||'); // pieces[0] message 1 // pieces[1] days 1 // pieces[2] message 2 // pieces[3] days 2 // pieces[4] total cost $("#split_delivery_message_1").html(pieces[0]); $("#split_days_to_delivery_1").val(pieces[1]); var days=pieces[1]*1; days++; // alert(' days = '+days); $('#split_shipping_date_1').val(''); //set minimum days can book for set_pickdate_field('#split_shipping_date_1',days); $("#split_delivery_message_2").html(pieces[2]); $("#split_days_to_delivery_2").val(pieces[3]); days=pieces[3]*1; days++; $('#split_shipping_date_2').val(''); set_pickdate_field('#split_shipping_date_2',days); $("#split_delivery_message_price").html(pieces[4]); }}); } else // order needs to come from 2 seperate warehouses { $('#choose_single_delivery_date').css("display","none"); //show splitting options var suburb_id = $('#save_suburb_id').val(); $.ajax({url: "/ajax_store/show_splitting_warehouse_options/"+suburb_id+"/", async: false, success: function(result){ $('#choose_split_delivery_dates').css("display","block"); var pieces = result.split('|||'); // pieces[0] message 1 // pieces[1] days 1 // pieces[2] message 2 // pieces[3] days 2 // pieces[4] total cost $("#split_delivery_message_1").html(pieces[0]); $("#split_days_to_delivery_1").val(pieces[1]); var days=pieces[1]*1; days++; $('#split_shipping_date_1').val(''); //set minimum days can book for set_pickdate_field('#split_shipping_date_1',days); $("#split_delivery_message_2").html(pieces[2]); $("#split_days_to_delivery_2").val(pieces[3]); days=pieces[3]*1; days++; $('#split_shipping_date_2').val(''); set_pickdate_field('#split_shipping_date_2',days); $("#split_delivery_message_price").html(pieces[4]); }}); } //scroll down a bit scroll_to_anchor('changeorder'); } function clearance_size_option_new(classname,size_id,name,option_price,was_price) { //since we are changing the size, make the "add to cart" button the default colours $('#add_cart_'+classname).css("color","#f15a01"); $('#add_cart_'+classname).css("background-color","#fff"); $('#add_cart_'+classname).css("border-color","#f15a01"); //register the chosen size $('#chosen-size-'+classname).html(size_id); $('#size_name_'+classname).html(name); //change colours var color='f15a01'; //make all divs in that sequance standard orange and white $('.opt-'+classname).css("color","#f15a01"); $('.opt-'+classname).css("background-color","#fff"); $('.opt-'+classname).css("border-color","#f15a01"); //select the chosen option as grey/white $('.opt-'+classname+'-'+size_id).css("color","#fff"); $('.opt-'+classname+'-'+size_id).css("background-color","#"+color); $('.opt-'+classname+'-'+size_id).css("border-color","#"+color); //fade current image out and new image in $('#opt-'+classname).fadeOut(300, function() { $('#opt-'+classname).attr("src",'/img/sizes/'+size_id+'-web.jpg'); if(option_price!=''){$('#price'+classname).html('$'+option_price);} if(was_price!=''){$('#wasprice'+classname).html('$'+was_price);} }); $('#opt-'+classname).delay(300).fadeIn(400); } function cartadded_model_size(make_id) { var free_items =''; var model_make_name = $('#model_make_name_'+make_id).html(); var chosen_size= $('#chosen-size-'+make_id).html(); var name = $('#size_name_'+chosen_size).html(); $('#size_added_name').html(name); if( $('#free_items_'+chosen_size).length) { free_items = $('#free_items_'+chosen_size).html(); $('#free_item').html(free_items); } else { $('#free_item').html(''); } ////check free items //does the free item include a shade cover? free_items = free_items.toLowerCase(); var n = free_items.indexOf("shade"); if(n > 0) { //show an "already included message $('.acc_shade-cover').html('
doneFREE - Already added
'); } var bballincluded = free_items.indexOf("basket"); if(bballincluded > 0) { //show an "already included message $('.acc_basketball-set').html('
doneFREE - Already added
'); } $('#added_accessory_cart_contents').html(name+' '+model_make_name); $('#added_accessory_cart').fadeIn(400); //$('#cartadded').css("left",'inherit'); //$('#cartadded').css("right",0); //Materialize.showStaggeredList('#cartadded'); $.ajax({url: "/ajax_store/add_cart/s"+chosen_size+"/", async: true, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); myVar = setTimeout(hide_accessory_cart, 3000); } function cartadded_accessory(make_id) { var free_items =''; var chosen_size= $('#chosen-item-'+make_id).html(); var name = $('#size_name_'+make_id).html(); $('#size_added_name').html(name); //alert('make_id = ' + make_id+ ' chosen_size = ' + chosen_size + ' name = ' + name ); /* if( $('#free_items_'+chosen_size).length) { free_items = $('#free_items_'+chosen_size).html(); $('#free_item').html(free_items); } else { $('#free_item').html(''); } */ $('#free_item').html(''); /* ////check free items //does the free item include a shade cover? free_items = free_items.toLowerCase(); var n = free_items.indexOf("shade"); if(n > 0) { //show an "already included message $('.acc_shade-cover').html('
doneFREE - Already added
'); } var bballincluded = free_items.indexOf("basket"); if(bballincluded > 0) { //show an "already included message $('.acc_basketball-set').html('
doneFREE - Already added
'); } */ //$('#cartadded').css("left",'inherit'); //$('#cartadded').css("right",0); //Materialize.showStaggeredList('#cartadded'); $('#added_accessory_cart_contents').html(name); $('#added_accessory_cart').fadeIn(400); $.ajax({url: "/ajax_store/add_cart/i"+chosen_size+"/", async: true, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); //set callback to make disappear myVar = setTimeout(hide_accessory_cart, 3000); } function clearance_accessory_option(classname,item_id,name,option_price,was_price) { //since we are changing the size, make the "add to cart" button the default colours $('#add_cart_'+classname).css("color","#f15a01"); $('#add_cart_'+classname).css("background-color","#fff"); $('#add_cart_'+classname).css("border-color","#f15a01"); //register the chosen size $('#chosen-item-'+classname).html(item_id); //alert('#size_name_'+classname+ ' = '+name); $('#size_name_'+classname).html(name); //change colours var color='f15a01'; //make all divs in that sequance standard orange and white $('.opt-'+classname).css("color","#f15a01"); $('.opt-'+classname).css("background-color","#fff"); $('.opt-'+classname).css("border-color","#f15a01"); //select the chosen option as grey/white $('.opt-'+classname+'-'+item_id).css("color","#fff"); $('.opt-'+classname+'-'+item_id).css("background-color","#"+color); $('.opt-'+classname+'-'+item_id).css("border-color","#"+color); //fade current image out and new image in //alert(' faceout #acc-opt-'+classname); $('#acc-opt-'+classname).fadeOut(300, function() { $('#acc-opt-'+classname).attr("src",'/img/items/'+item_id+'-web.jpg'); if(option_price!=''){$('#price'+classname).html('$'+option_price);} if(was_price!=''){$('#wasprice'+classname).html('$'+was_price);} }); $('#acc-opt-'+classname).delay(300).fadeIn(400); } function clearance_size_option(classname,size_id,name,option_price) { //since we are changing the size, make the "add to cart" button the default colours $('#add_cart_'+classname).css("color","#f15a01"); $('#add_cart_'+classname).css("background-color","#fff"); $('#add_cart_'+classname).css("border-color","#f15a01"); //register the chosen size $('#chosen-size-'+classname).html(size_id); $('#size_name_'+classname).html(name); //change colours var color='f15a01'; //make all divs in that sequance standard orange and white $('.opt-'+classname).css("color","#f15a01"); $('.opt-'+classname).css("background-color","#fff"); $('.opt-'+classname).css("border-color","#f15a01"); //select the chosen option as grey/white $('.opt-'+classname+'-'+size_id).css("color","#fff"); $('.opt-'+classname+'-'+size_id).css("background-color","#"+color); $('.opt-'+classname+'-'+size_id).css("border-color","#"+color); //fade current image out and new image in $('#opt-'+classname).fadeOut(300, function() { $('#opt-'+classname).attr("src",'/img/sizes/'+size_id+'-web.jpg'); if(option_price!=''){$('#price'+classname).html('$'+option_price);} }); $('#opt-'+classname).delay(300).fadeIn(400); } //item_option('1','6','','1999.99'); function item_option(classname,item_id,override_color,option_price) { //since we are changing the size, make the "add to cart" button the default colours $('#add_cart_'+classname).css("color","#f15a01"); $('#add_cart_'+classname).css("background-color","#fff"); $('#add_cart_'+classname).css("border-color","#f15a01"); //register the chosen option $('#'+classname+'_item_id').html(item_id); if ( $('#opt-'+classname+'-'+item_id+'-tick').length )//tick element exists { //hide tick options from all in sequence $('.opt-'+classname).html(""); //dont change colours, just show a tick icon $('#opt-'+classname+"-"+item_id+'-tick').html('check'); } else { //change colours if(override_color != '') { var color=override_color; } else { var color='f15a01'; } //make all divs in that sequance standard orange and white $('.opt-'+classname).css("color","#f15a01"); $('.opt-'+classname).css("background-color","#fff"); $('.opt-'+classname).css("border-color","#f15a01"); //select the chosen option as grey/white $('.opt-'+classname+'-'+item_id).css("color","#fff"); $('.opt-'+classname+'-'+item_id).css("background-color","#"+color); $('.opt-'+classname+'-'+item_id).css("border-color","#"+color); } //fade current image out and new image in $('#opt-'+classname).fadeOut(300, function() { $('#opt-'+classname).attr("src",'/img/items/'+item_id+'-web.jpg'); if(option_price!=''){$('#price'+classname).html('$'+option_price);} }); $('#opt-'+classname).delay(300).fadeIn(400); } function lookup_map(warehouse) { var postcode = $('#contact_zip_suburb').val(); postcode = postcode.trim(); var mapkey = 'AIzaSyDWe_BJQTPHZVwBdS8KtcJ_BtspLGa0wTE'; var suburb = $('#shs_label').html(); suburb = suburb.replace("Suburb:
", ""); // remove this for NZ suburb = suburb.replace("Suburb:", ""); suburb = suburb.replace("(town)", ""); if(warehouse == 'Auckland') { //if the suburb contains , only take the latter part (which is the township, not the suburb) because the suburb/town combinations for the freighter are different to that of google maps /* var n = suburb.includes(","); if(n == true) { var res = suburb.split(","); suburb=res[1]; //alert('suburb = '+suburb); } */ var postcode = $('#contact_nz_postcode').val(); } else { var postcode = $('#contact_zip_suburb').val(); } postcode = postcode.trim(); //suburb = suburb.replace(",", ""); suburb = suburb.trim(); if(suburb == '(Outside Australia)') // outside australia { //alert( '(Outside Australia)'); var from = $("#internation_country option:selected").text(); } else { var from = suburb+' '+postcode+' '+$("#internation_country option:selected").text(); //alert( suburb+' '+postcode ); } if(warehouse == 'Auckland') { //if the suburb contains , only take the latter part (which is the township, not the suburb) because the suburb/town combinations for the freighter are different to that of google maps $('#aucklandmap').css("display","block"); $('#brisbanemap').css("display","none"); $('#perthmap').css("display","none"); var weblink = 'https://maps.google.com.au/maps?hl=en&saddr=%20%20'+encodeURIComponent(from)+'&daddr=42+Ororke+Rd,+Penrose,+Auckland+1061,+New+Zealand'; var mapimg = 'https://maps.googleapis.com/maps/api/staticmap?key='+mapkey+'&scale=2&size=448x250&markers=color:blue|label:B|%20%20'+encodeURIComponent(from)+'&markers=color:green|label:A|%20%20Penrose%20Auckland%201061%20New%20Zealand&sensor=false&format=jpg-baseline'; } else if(warehouse == 'Brisbane') { $('#aucklandmap').css("display","none"); $('#pickup_map').css("display","block"); $('#brisbanemap').css("display","block"); $('#perthmap').css("display","none"); var weblink = 'https://maps.google.com.au/maps?hl=en&saddr=%20%20'+encodeURIComponent(from)+'&daddr=Vuly+Trampolines,+95+Ingleston+Road,+Wakerley+QLD+4154'; var mapimg = 'https://maps.googleapis.com/maps/api/staticmap?key='+mapkey+'&scale=2&size=448x250&markers=color:blue|label:B|%20%20'+encodeURIComponent(from)+'&markers=color:green|label:A|%20%20Wakerley%20QLD%204154&sensor=false&format=jpg-baseline'; } else { $('#aucklandmap').css("display","none"); $('#brisbanemap').css("display","none"); $('#perthmap').css("display","block"); var weblink = 'https://maps.google.com.au/maps?hl=en&saddr=%20%20'+encodeURIComponent(from)+'&daddr=Mainfreight+International+Pty+Ltd,+2,+Hugh+Edwards+Drive,+Perth+Airport+WA+6105'; var mapimg = 'https://maps.googleapis.com/maps/api/staticmap?key='+mapkey+'&scale=2&size=448x250&markers=color:blue|label:B|%20%20'+encodeURIComponent(from)+'&markers=color:green|label:A|Mainfreight+International+Pty+Ltd,+2+Hugh+Edwards+Drive,+Perth+Airport+WA+6105'; } $("#js-map-directions_1").attr("href", weblink); $("#js-map-directions").attr("href", weblink); $("#js-map-image").attr("src", mapimg); $('#pickup_map').css("display","block"); //alert("sending data ... /ajax_store/check_pickup/"+warehouse+"/"); //get pickup availability information $.ajax({url: "/ajax_store/check_pickup/"+warehouse+"/", async: false, success: function(result) { //alert("result = "+result); $("#pickup_alert").html(result); if( result.indexOf('not stocked at our') >= 0) { // this is the error message saying that items are not stocked. don't show continue button $('#continue_button').css("display","none"); if(warehouse == 'Perth') { $('#pickup_map').css("display","none"); $('#perthmap').css("display","none"); } } else { $('#continue_button').css("display","block"); } }}); scroll_to_anchor('whichlocation'); } function continue_shopping() { scroll_to_anchor('accessoryslider'); hide_cart(); } function show_billing_address(show) { if(show == '1') { $('#billing_contact').css("display","block"); } else { $('#billing_contact').css("display","none"); } } function check_zipmoney() { $('#zip_congrats').css("display","none"); $('#zip_rejected').css("display","none"); var yob = $('#zip_yob').val(); var approved = false; // Return today's date and time var currentTime = new Date() var year = currentTime.getFullYear() year=year*1; yob=yob*1; var difference = year - yob; var selectedoption = $('#zip_employment').val(); if(selectedoption == '9' || selectedoption == '8' || selectedoption == '1' || selectedoption == '2' || selectedoption == '11' || selectedoption == '3') { approved = true; } if(difference > 18 && approved == true) // accepted { $('#zip_congrats').css("display","block"); $('#rest-of-form').css("display","block"); } else // desclined { $('#zip_rejected').css("display","block"); $('#rest-of-form').css("display","none"); } } function show_payment(div,smssec) { var value; //make all buttons in that sequance standard orange text and white bg $('.payoptbtn').css("color","#f15a01"); $('.payoptbtn').css("background-color","#fffff"); $('.paym_lnk').css("background-color","#ffffff"); //select the chosen option as orange bg /white text $('#payopt-'+div).css("color","#fff"); $('#payopt-'+div).css("background-color","#f15a01"); switch(div) { case "credit": value = "Credit Card"; break; case "afterpay": value = "Afterpay"; break; case "finance": value = "Finance"; break; case "cash": value = "Cash"; break; default: value = "Direct Deposit "; } $('#payment_type').val(value); $('#zip_congrats').css("display","none"); $('#zip_rejected').css("display","none"); $('#rest-of-form').css("display","none"); $('#payment-method-afterpay').css("display","none"); $('#payment-method-credit').css("display","none"); $('#payment-method-cash').css("display","none"); $('#payment-method-deposit').css("display","none"); $('#payment-method-finance').css("display","none"); $('#payment-method-'+div).css("display","block"); $('#smssec').val(smssec); scroll_to_anchor('howpay'); if( div == 'finance') { // show rest of form $('#rest-of-form').css("display","block"); } else if(div == 'credit' ) { //dont show rest of form } else { $('#rest-of-form').css("display","block"); } } function blur_suburb_2020() { $('#contact_zip_suburb').blur(); // un focus suburb field } function search_order_suburbs_2020(post_code) { //since user has gone back to the suburb choice, hide delivery options and continue button $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#deliverytermsandconditions').css("display","none"); $('#continue_button').css("display","none"); post_code = post_code.trim() var length = post_code.length; if(length > 2) { delay(function() { //reset the address warning alert $('#address_alert').html(" "); //$('#shs_label').css( "background-color", "#fff" ); $('#shs_label').html(''); $.ajax({url: "/ajax_store/search_order_suburbs_2020/"+encodeURIComponent(post_code)+"/", async: true, success: function(result){ $("#shs_label").html(result); // }}); }, 500); } } function search_order_suburbs_usa() { console.log('tripped'); //since user has gone back to the suburb choice, hide delivery options and continue button $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#deliverytermsandconditions').css("display","none"); $('#continue_button').css("display","none"); $('#inside_australia').css("display","none"); $('#city_holder').css("display","none"); $('#state_holder').css("display","none"); $('#country_holder').css("display","none"); $('#lead_origin_header').css("display","none"); $('#lead_origin_options').css("display","none"); $('.mob_summary_box-1').css("display","none"); $('.mob_summary_box-2').css("display","none"); $('#zip-msg-box').css("display","block"); $('#city-input').val(''); $('#state-input').val(''); $('#country-input').val(''); saveorderusa("0"); } function search_order_suburbs(post_code) { //since user has gone back to the suburb choice, hide delivery options and continue button $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#deliverytermsandconditions').css("display","none"); $('#continue_button').css("display","none"); post_code = post_code.trim() var length = post_code.length; if(length > 3) { //reset the address warning alert $('#address_alert').html(" "); //$('#shs_label').css( "background-color", "#fff" ); $('#shs_label').html(''); $.ajax({url: "/ajax_store/search_order_suburbs/"+post_code+"/", async: false, success: function(result){ $("#shs_label").html(result); $('#contact_zip_suburb').blur(); // un focus suburb field }}); } else if(length > 1) { //reset the address warning alert $('#address_alert').html(" "); $("#shs_label").html('Click on your suburb:
Outside Australia
'); } } function search_order_suburbs_nz(suburb) { delay(function() { //since user has gone back to the suburb choice, hide delivery options and continue button $('#delivery_div').css("display","none"); $('#pickup_div').css("display","none"); $('#deliverytermsandconditions').css("display","none"); $('#continue_button').css("display","none"); suburb = suburb.trim() var length = suburb.length; if(length > 2) { //reset the address warning alert $('#address_alert').html(" "); //$('#shs_label').css( "background-color", "#fff" ); $('#shs_label').html(''); $.ajax({url: "/ajax_store/search_order_suburbs_nz/"+encodeURIComponent(suburb)+"/", async: false, success: function(result){ $("#shs_label").html(result); //$('#contact_zip_suburb').blur(); // un focus suburb field }}); } else if(length > 1) { //reset the address warning alert $('#address_alert').html(" "); $("#shs_label").html('Click on your suburb:
Outside New Zealand
'); } }, 100); } function changed_bold_date() { var changed_date=$('#shipping_date').val(); $('#earliestdate_bolded').html(changed_date); // warehouse storage charging var end_date=''; //if warehouse charging is turned on if($('#charging_for_storage').html() == '1') { //check if chosen date is more than 14 days after todays date, or after the earliest dispatch date (whatever is latter) //check if stock option exists on page if ( $('#stock_option_1').length )//stock options exist on page - some stock must be out of stock { if($('#stock_option_1').is(':checked')) //chose to wait for all order { //get earliest selectable date of #shipping_date start_date = $('#shipping_date_min_date').html(); //compare with chosen date end_date = $('#earliestdate_bolded').html(); // 23 December, 2016 } else // chose to split into 2 deliveries { //start_date = $('#split_shipping_date_1').html(); //end_date = $('#earliestdate_bolded').html(); // 23 December, 2016 //start_date = $('#split_shipping_date_2').html(); //end_date = $('#earliestdate_bolded').html(); // 23 December, 2016 } } else // no stock options - all items must be in stock { //get earliest selectable date of #shipping_date start_date = $('#shipping_date_min_date').html(); //compare with chosen date end_date = $('#earliestdate_bolded').html(); // 23 December, 2016 } //alert("/ajax_store/compare_holding_dates/"+encodeURIComponent(start_date)+"/"+encodeURIComponent(end_date)+"/"); $.ajax({url: "/ajax_store/compare_holding_dates/"+encodeURIComponent(start_date)+"/"+encodeURIComponent(end_date)+"/", async: false, success: function(result){ //alert(result); $('#charging_storage').html(result); }}); } } function set_pickdate_field(field_id,days) //sets the minimum selectable date for a datepicker field { var count=1; var hourcount = days * 24; var day_window; var datcurrentDate = new Date(new Date().getTime() + hourcount * 60 * 60 * 1000); var datday = datcurrentDate.getDate(); var datmonth = datcurrentDate.getMonth(); var datyear = datcurrentDate.getFullYear(); /* 9 // insert this code on page to test what the page would do if you were in this month. 9 = October (js does one month ahead) if( $('#sheldyn_test_month').length) // if element exists on page for testing purposes { //override month for testing purposes datmonth = $('#sheldyn_test_month').html(); datmonth = datmonth * 1; alert('new datmonth = '+datmonth); } */ /* Rationale: During our non-peak times of the year, allow customers to book in delivery within 2 months of their purchase date. This seems reasonable and allows for more customer convenience than a 3 week period. It allows customers to organise birthdays and special events well in advance, not just a few weeks in advance. To help spreadh the warehouse burden : during October, it drop the window to a 4 week window. In November and December, it can drop to a 2 week window. If we don't drop the window during these months, customers will inevitably choose to have the order delivered in the week leading up to xmas and our warehouse will have to work 24 hours a day. */ //the month is 1 less (eg 1 = feb, 2 = march ...) switch(datmonth) { case 7: // during august day_window = 31;//4week window break; case 8: // during september day_window = 14;//4week window break; case 9: // during oct day_window = 14;// 2 week window break; case 10: // during nov day_window = 14; // 2 week window break; case 11: // during dec day_window = 60;// 2 month window to allow next year delivery break; default: // all other months day_window = 60;//4week window break; } var endhourcount = 24 * day_window; endhourcount=endhourcount+ hourcount; var datendDate = new Date(new Date().getTime() + endhourcount * 60 * 60 * 1000); var endday = datendDate.getDate(); var endmonth = datendDate.getMonth(); var endyear = datendDate.getFullYear(); //alert('month = '+datmonth+' | window = '+week_window+ ' | endhourcount = '+endhourcount+ ' | end date: '+endday+'/'+endmonth+'/'+endyear ); /* if( $('#sheldyn_test_month').length) // if element exists on page { alert(datyear+'/'+datmonth+'/'+datday+' ... '+endyear+'/'+endmonth+'/'+endday); } */ $(field_id).pickadate({selectYears: 2, min:new Date(datyear, datmonth, datday, 10, 30), max:new Date(endyear, endmonth, endday, 10, 30), disable:[1,7,[2017,11,25],[2017,11,26],[2018,0,1],[2018,11,25],[2018,11,26],[2019,0,1]]}); datmonth++; $(field_id+'_min_date').html(datyear+'-'+datmonth+'-'+datday); } function set_datepick_field(field_id,days) //sets the minimum selectable date for a datepicker field but with no future limits or weekend limits { var count=1; var hourcount = days * 24; var day_window; var datcurrentDate = new Date(new Date().getTime() + hourcount * 60 * 60 * 1000); var datday = datcurrentDate.getDate(); var datmonth = datcurrentDate.getMonth(); var datyear = datcurrentDate.getFullYear(); /* Rationale: During our non-peak times of the year, allow customers to book in delivery within 2 months of their purchase date. This seems reasonable and allows for more customer convenience than a 3 week period. It allows customers to organise birthdays and special events well in advance, not just a few weeks in advance. To help spreadh the warehouse burden : during October, it drop the window to a 4 week window. In November and December, it can drop to a 2 week window. If we don't drop the window during these months, customers will inevitably choose to have the order delivered in the week leading up to xmas and our warehouse will have to work 24 hours a day. */ //the month is 1 less (eg 1 = feb, 2 = march ...) switch(datmonth) { case 7: // during august day_window = 31;//4week window break; case 8: // during september day_window = 14;//4week window break; case 9: // during oct day_window = 14;// 2 week window break; case 10: // during nov day_window = 14; // 2 week window break; case 11: // during dec day_window = 60;// 2 month window to allow next year delivery break; default: // all other months day_window = 60;//4week window break; } var endhourcount = 24 * day_window; endhourcount=endhourcount+ hourcount; var datendDate = new Date(new Date().getTime() + endhourcount * 60 * 60 * 1000); var endday = datendDate.getDate(); var endmonth = datendDate.getMonth(); var endyear = datendDate.getFullYear(); $(field_id).pickadate({selectYears: 2, min:new Date(datyear, datmonth, datday, 10, 30), disable:[[2019,11,25],[2019,11,26],[2020,0,1]]}); datmonth++; $(field_id+'_min_date').html(datyear+'-'+datmonth+'-'+datday); } function adopt_pickup_method_2020() { var method = $("#delivery_method").val(); var suburb_id = $("#save_suburb_id").val(); if(suburb_id == '0') { $(".inside_australia").css('display','none'); $("#next_button").css('display','block'); $("#next_button_submit").css('display','none'); } else { if(method == 'delivery') { $("#next_button").css('display','block'); $("#next_button_submit").css('display','none'); choose_delivery_fast('delivery'); // recalculate shipping } else // pickup { $("#delivery_method").val('pickup'); $("#next_button").css('display','none'); $("#next_button_submit").css('display','block'); $('#shipping_rh_line').css("display","none"); var total_price = $('#cart_total_price_on_page_load').html(); console.log('11. #cart_total_price = $'+total_price); $('#cart_total_price').html('$'+total_price); } } } function choose_delivery_fast(method) { //hide these sections, forcing the user to choose their warehouse again $('#aucklandmap').css("display","none"); $('#brisbanemap').css("display","none"); $('#perthmap').css("display","none"); $('#pickup_alert').html(""); $('#pickup_map').css("display","none"); $('.indicator').css("display","inline"); //slider animation if(method == 'delivery') { fadedelivery('#delivery','1'); } else { fadedelivery('#pickup','2'); } //reset pickup location to blank $('#pickup_location').val(""); $('#delivery_method').val(method); //scroll_to_anchor('deliveryclicker'); if(method=='pickup') { $('#delivery_div').css("display","none"); $('#pickup_div').css("display","block"); $('#continue_button').css("display","none"); // temporary covid 19 measure var afterpay_original = $("#afterpay_on_page_load").html(); $('#afterpay_4_payments').html(afterpay_original); adopt_pickup_method_2020(); // new 2020 template } else // delivery { $('#pickup_div').css("display","none"); var suburb_id = $('#save_suburb_id').val(); $.ajax({url: "/ajax_store/fast_checkout_prep/"+suburb_id+"/", async: false, success: function(result){ $("#confirm_freighter").html(result); $('#confirm_freighter').css("display","block"); $('#delivery_div').css("display","block"); $('#continue_button').css("display","block"); // hide continue to payment button // new 2020 template $("#next_button").css('display','none'); $("#next_button_submit").css('display','block'); var shipping_price = 0; if ($('#ship_price').length > 0) { shipping_price=$("#ship_price").html(); shipping_price=shipping_price*1; } //console.log('shipping_price = '+shipping_price); if(shipping_price > 0) { var final_shipping_price = (Math.round(shipping_price * 100) / 100).toFixed(2); $('#shipping_value').html('$'+final_shipping_price); } else { $('#shipping_value').html('FREE'); } $('#shipping_rh_line').css("display","block"); var total_price = $('#cart_total_price_on_page_load').html(); total_price = total_price*1; console.log('total_price = '+total_price+" + "+shipping_price); total_price = total_price + shipping_price; //console.log(total_price+' = '+total_price+' + '+shipping_price); var final_total_price = (Math.round(total_price * 100) / 100).toFixed(2); console.log('22. #cart_total_price = $'+final_total_price); $('#cart_total_price').html('$'+final_total_price); var afterpay_original; if(shipping_price > 0) { afterpay_original = total_price / 4; afterpay_original = (Math.round(afterpay_original * 100) / 100).toFixed(2); } else { afterpay_original = $("#afterpay_on_page_load").html(); } $('#afterpay_4_payments').html(afterpay_original); //lookup_map('Brisbane'); }}); } } function choose_delivery(method) { //hide these sections, forcing the user to choose their warehouse again $('#aucklandmap').css("display","none"); $('#brisbanemap').css("display","none"); $('#perthmap').css("display","none"); $('#pickup_alert').html(""); $('#pickup_map').css("display","none"); $('.indicator').css("display","inline"); //slider animation if(method == 'delivery') { fadedelivery('#delivery','1'); } else { fadedelivery('#pickup','2'); } $("#earliestdate").html(''); // set to blank $('#choose_split_delivery_dates').css("display","none"); $('#choose_single_delivery_date').css("display","none"); $('#deliverytermsandconditions').css("display","none"); $('#continue_button').css("display","none"); // hide continue to payment button //reset pickup location to blank $('#pickup_location').val(""); //uncheck atl options $('#confirm_freighter_split').css("display","none"); $("#split_atl_yes").attr("checked", false); $("#split_atl_no").attr("checked", false); if(method=='pickup') { delivery_method='pickup'; $('#delivery_div').css("display","none"); $('#pickup_div').css("display","block"); } else // delivery { delivery_method='delivery'; $('#delivery_div').css("display","block"); $('#pickup_div').css("display","none"); $('#deliverytermsandconditions').css("display","none"); } $('#delivery_method').val(delivery_method); //scroll_to_anchor('deliveryclicker'); if(method!='pickup') { var suburb_id = $('#save_suburb_id').val(); $.ajax({url: "/ajax_store/check_stock_levels/"+suburb_id+"/", async: false, success: function(result){ //if everything is in stock, then chose single delivery date, and enforce minimum date selection if(result.length < 10) //return the days until arrival { var days = result * 1; //create date from this day var someDate = new Date(); someDate.setDate(someDate.getDate() + days); var dd = someDate.getDate(); var mm = someDate.getMonth() + 1; var y = someDate.getFullYear(); $('#shipping_date').val(dd + '/'+ mm + '/'+ y); set_pickdate_field('#shipping_date',days); $("#days_to_delivery").val(days); $('#choose_single_delivery_date').css("display","block"); $("#stock_control_feedback").html(''); //temporary xmas messages if(dd < 24 && mm == 12) { $("#stock_control_feedback").html('
done Your order will arrive before xmas
'); } else if(mm == 12) { $("#stock_control_feedback").html('
info_outline Your order may not arrive before xmas.
Please call us to confirm - 1300667514
'); } $("#earliestdate").html('The earliest that your order can be delivered is '+dd + '/'+ mm + '/'+ y+'. '); $("#earliestdate_bolded").html(dd + '/'+ mm + '/'+ y); //show freighter information $.ajax({url: "/ajax_store/confirm_freighter/", async: false, success: function(result){ $("#confirm_freighter").html(result); $("#confirm_freighter_split").html(''); $('#confirm_freighter').css("display","block"); }}); } else // some items are out of stock - return feedback with options for when to receive order { $('#choose_single_delivery_date').css("display","none"); $("#stock_control_feedback").html(result); } }}); } } function agreetotermscheck() { if($('#agreetoterms:checkbox:checked').length > 0) // { $('#continuerow').css("display","inline"); } else { $('#continuerow').css("display","none"); } } function showfreightsplit() { //get dates of 2 split orders var firstdate = $("#split_shipping_date_1").val(); // show storage fee message ////////////////////////////////////////////////////////// //get earliest selectable date of #shipping_date var start_date = $('#split_shipping_date_1_min_date').html(); //compare with chosen date var end_date = $('#split_shipping_date_1').val(); // 23 December, 2016 /* // storage fees - no longer applies $.ajax({url: "/ajax_store/compare_holding_dates/"+encodeURIComponent(start_date)+"/"+encodeURIComponent(end_date)+"/", async: false, success: function(result){ $('#charging_storage_split').html(result); }}); */ ////////////////////////////////////////////////////////// var seconddate = $("#split_shipping_date_2").val(); //only proceed if both dates are selected if(firstdate!='' && seconddate!='') { $('#confirm_freighter_split').css("display","block"); } } function delivery_asap() { var adddays = $("#days_to_delivery").val(); adddays=adddays*1; //create date from this day var someDate = new Date(); someDate.setDate(someDate.getDate() + adddays); var dd = someDate.getDate(); var mm = someDate.getMonth() + 1; var y = someDate.getFullYear(); $('#shipping_date').val(dd + '/'+ mm + '/'+ y); $('#continue_button').css("display","none"); $('#deliverytermsandconditions').css("display","none"); check_order_splitting(); } function check_order_splitting() { //create 1 second delay, so this function is not being hit over and over agin //delay(function(){ $.ajax({url: "/ajax_store/check_order_splitting/", async: false, success: function(result){ $("#order_splitting_info").html(result); $('#continue_button').css("display","none"); }}); //}, 1000); } function restart_order() { $.ajax({url: "/ajax_store/restart/", async: false, success: function(result){ //$("div").html(result); }}); } function choose_atl(choice) { if(choice == 'yes') { $('#atlyes').attr("src",'/img/icons/tick-circle.jpg'); $('#atlno').attr("src",'/img/icons/no-circle.jpg'); $('#atl').val('yes'); $('#split_atl_yes_notes').css("display","block"); $('#split_atl_no_notes').css("display","none"); } else { $('#atlyes').attr("src",'/img/icons/no-circle.jpg'); $('#atlno').attr("src",'/img/icons/tick-circle.jpg'); $('#atl').val('no'); $('#split_atl_yes_notes').css("display","none"); $('#split_atl_no_notes').css("display","block"); } //show the continue button $('#continue_button').css("display","block"); $('#deliverytermsandconditions').css("display","block"); scroll_to_anchor('givepermission'); } function split_atl_toggle(answer) { $('#split_atl_yes_notes').css("display","none"); $('#split_atl_no_notes').css("display","none"); if(answer=='yes') { $('#split_atl_yes_notes').css("display","block"); } else // no { $('#split_atl_no_notes').css("display","block"); } //show the continue button $('#continue_button').css("display","block"); $('#deliverytermsandconditions').css("display","block"); } function atl_toggle(answer) { $('#atl_yes_notes').css("display","none"); $('#atl_no_notes').css("display","none"); if(answer=='yes') { $('#atl_yes_notes').css("display","block"); } else // no { $('#atl_no_notes').css("display","block"); } //show the continue button $('#continue_button').css("display","block"); $('#deliverytermsandconditions').css("display","block"); } function fill_orange_spare(classname,unique_id,item_name) { var item_id = $('#'+classname+'_item_id').html(); $('#add_cart_'+unique_id+'_'+classname).css("color","#fff"); $('#add_cart_'+unique_id+'_'+classname).css("background-color","#4caf50"); $('#add_cart_'+unique_id+'_'+classname).css("border-color","#4caf50"); // $('#added_accessory_cart_contents').html(item_name); // old // $('#added_accessory_cart').fadeIn(400); // old $('.new_added_freebies').css("display","none"); $('#new_added_item_name').html(item_name); $('#new_added_item_img').attr('src','/img/items/'+item_id+'.png'); $('#addedtocartmodal-new').fadeIn(400); // make icon larger $("#top_cart_icon").animate({ fontSize: "40px" }, 600, function() { }); $("#cart_on_mobile").animate({ fontSize: "2.3rem" }, 600, function() { }); //add to cart $.ajax({url: "/ajax_store/add_cart/i"+item_id+"/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); //set callback to make disappear // myVar = setTimeout(hide_accessory_cart, 3000); // old //set callback to make disappear myVar = setTimeout(hide_added_cart_new, 4000); } function temporary_add_swingset(current_promo) { var accessory = $('#swing_set_accessory').val(); $('#add_cart_swing_set').css("color","#fff"); $('#add_cart_swing_set').css("background-color","#4caf50"); $('#add_cart_swing_set').css("border-color","#4caf50"); if(accessory=='bballset') { var description ='Medium Swing Set and Basketball Set'; } else if(accessory=='shade') { var description ='Medium Swing Set and Shade Cover'; } else { var description ='Medium Swing Set'; } $('#added_accessory_cart_contents').html(description); $('#added_accessory_cart').fadeIn(400); //remove swing set $.ajax({url: "/ajax_store/remove_cart/s40/", async: false, success: function(result){ }}); //remove shade cover $.ajax({url: "/ajax_store/remove_cart/i1110/", async: false, success: function(result){ }}); //remove bball set $.ajax({url: "/ajax_store/remove_cart/i1112/", async: false, success: function(result){ }}); //add to cart $.ajax({url: "/ajax_store/add_cart/s40/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); //set callback to make disappear myVar = setTimeout(hide_accessory_cart, 3000); if(accessory=='bballset') { //add to cart $.ajax({url: "/ajax_store/add_cart/i1112/", async: false, success: function(result){ }}); } else if(accessory=='shade') { //add to cart $.ajax({url: "/ajax_store/add_cart/i1110/", async: false, success: function(result){ }}); } } function buyingsize_accessory_sizes(item_id, make_id, price,size) { price = price.replace(",", ""); price = price * 1; $('#selected_accessory_size').val(item_id); $('.opt-size-'+make_id).css("color","#f15a01"); $('.opt-size-'+make_id).css("background-color","#fff"); //select the chosen option as grey/white $('.opt-'+item_id).css("color","#fff"); $('.opt-'+item_id).css("background-color","#f15a01"); $('#make_'+make_id+'_show_price').html(price); $('#make_'+make_id+'_item_size').html(size); $('#make_'+make_id+'_item_id').html(item_id); $('#afterpay_product_id').html('i'+item_id); } function buyingsize_accessory_sizes_tent(item_id, make_id, price,size,variant) { console.log(item_id) console.log(make_id) console.log(price) console.log(size) console.log(variant) price = price.replace(",", ""); price = price * 1; $('#selected_accessory_size').val(item_id); $('.opt-size-'+make_id+'-'+variant).css("color","#f15a01"); $('.opt-size-'+make_id+'-'+variant).css("background-color","#fff"); //select the chosen option as grey/white $('.opt-'+item_id).css("color","#fff"); $('.opt-'+item_id).css("background-color","#f15a01"); $('#make_'+make_id+'_show_price_'+variant).html(price); $('#make_'+make_id+'_item_size_'+variant).html(size); $('#make_'+make_id+'_item_id_'+variant).html(item_id); $('#afterpay_product_id').html('i'+item_id); } function add_accessory_cart(make_id) { var price = $('#make_'+make_id+'_show_price').html(); var size = $('#make_'+make_id+'_item_size').html(); var item_id = $('#make_'+make_id+'_item_id').html(); var accessory_cart_name = $('#accessory_cart_name').html(); //$('#added_accessory_cart_contents').html(size+' '+accessory_cart_name); // old //$('#added_accessory_cart').fadeIn(400); // old $('.new_added_freebies').css("display","none"); $('#new_added_item_name').html(size+' '+accessory_cart_name); $('#new_added_item_img').attr('src','/img/items/'+item_id+'-web.jpg'); $('#addedtocartmodal-new').fadeIn(400); // make icon larger $("#top_cart_icon").animate({ fontSize: "40px" }, 600, function() { }); $("#cart_on_mobile").animate({ fontSize: "2.3rem" }, 600, function() { }); //add to cart $.ajax({url: "/ajax_store/add_cart/i"+item_id+"/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); //redirect to cart window.location.href = '/cart'; //set callback to make disappear myVar = setTimeout(hide_added_cart_new, 4000); } function add_accessory_cart_tent(make_id,variant) { var price = $('#make_'+make_id+'_show_price_'+variant).html(); var size = $('#make_'+make_id+'_item_size_'+variant).html(); var item_id = $('#make_'+make_id+'_item_id_'+variant).html(); var accessory_cart_name = $('#accessory_cart_name').html(); //$('#added_accessory_cart_contents').html(size+' '+accessory_cart_name); // old //$('#added_accessory_cart').fadeIn(400); // old $('.new_added_freebies').css("display","none"); $('#new_added_item_name').html(size+' '+accessory_cart_name); $('#new_added_item_img').attr('src','/img/items/'+item_id+'-web.jpg'); $('#addedtocartmodal-new').fadeIn(400); // make icon larger $("#top_cart_icon").animate({ fontSize: "40px" }, 600, function() { }); $("#cart_on_mobile").animate({ fontSize: "2.3rem" }, 600, function() { }); //add to cart $.ajax({url: "/ajax_store/add_cart/i"+item_id+"/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); //redirect to cart window.location.href = '/cart'; //set callback to make disappear myVar = setTimeout(hide_added_cart_new, 4000); } function buy_accessory_page(classname) { var item_id = $('#'+classname+'_item_id').html(); var item_name = $('#'+classname+'_item_id_name').html(); //console.log("adding the item"); //$('#add_cart_'+classname).css("color","#fff"); //$('#add_cart_'+classname).css("background-color","#4caf50"); //$('#add_cart_'+classname).css("border-color","#4caf50"); //$('#added_accessory_cart_contents').html(item_name); // old //$('#added_accessory_cart').fadeIn(400); // old $('.new_added_freebies').css("display","none"); $('#new_added_item_name').html(item_name); $('#new_added_item_img').attr('src','/img/items/'+item_id+'-web.jpg'); $('#addedtocartmodal-new').fadeIn(400); // make icon larger $("#top_cart_icon").animate({ fontSize: "40px" }, 600, function() { }); $("#cart_on_mobile").animate({ fontSize: "2.3rem" }, 600, function() { }); //add to cart $.ajax({url: "/ajax_store/add_cart/i"+item_id+"/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); window.location.href="/cart" }}); //set callback to make disappear myVar = setTimeout(hide_added_cart_new, 4000); log_id = 'i'+item_id; log_add_to_cart(log_id); } function fill_orange_one(classname,item_name, show_accessory_popup) { var item_id = $('#'+classname+'_item_id').html(); if( $('#add_cart_'+classname).css("background-color")=="rgb(76, 175, 80)") // already added - remove it { console.log("already added - remove it"); $('#add_cart_'+classname).css("color","#f15a01"); $('#add_cart_'+classname).css("background-color","#fff"); $('#add_cart_'+classname).css("border-color","#f15a01"); //add to cart $.ajax({url: "/ajax_store/remove_cart/i"+item_id+"/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); } else // adding the item { console.log("adding the item"); $('#add_cart_'+classname).css("color","#fff"); $('#add_cart_'+classname).css("background-color","#4caf50"); $('#add_cart_'+classname).css("border-color","#4caf50"); if(show_accessory_popup === undefined) { $('#added_accessory_cart_contents').html(item_name); $('#added_accessory_cart').fadeIn(400); } console.log("/ajax_store/add_cart/i"+item_id+"/"); //add to cart $.ajax({url: "/ajax_store/add_cart/i"+item_id+"/", async: false, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); //set callback to make disappear if(show_accessory_popup === undefined) { myVar = setTimeout(hide_accessory_cart, 4000); } } } function hide_accessory_cart() { $('#added_accessory_cart').fadeOut(1000); } function tramp_cartadded(make_id) { var free_items =''; if(make_id == '11') // ultra { $('#we_also_free_hoop').css("display","block"); //$('#we_also_free_hoop').css("display","none"); } else { $('#we_also_free_hoop').css("display","block"); } var chosen_size= $('#make_select_'+make_id).val(); var name = $('#size_name_'+chosen_size).html(); $('#size_added_name').html(name); if( $('#free_items_'+chosen_size).length) // element exists on page { free_items = $('#free_items_'+chosen_size).html(); $('#free_item').html(free_items); } else { $('#free_item').html(''); } var price = $('#size_price_'+chosen_size).html(); var zipprice = $('#size_pricezip_'+chosen_size).html(); $('#added_c_price').html(price); $('#added_c_zipprice').html(zipprice); ////check free items //does the free item include a shade cover? free_items = free_items.toLowerCase(); var n = free_items.indexOf("shade"); var extra_image=''; if(n > 0) { //show an "already included message extra_image='_shade'; $('.acc_shade-cover').html('
doneFREE - Already added
'); } var bballincluded = free_items.indexOf("ball"); if(bballincluded > 0) { //show an "already included message extra_image='-hoop'; $('.acc_basketball-set').html('
doneFREE - Already added
'); } $('#addedcart_img').attr("src",'/img/sizes/'+chosen_size+'-web'+extra_image+'.jpg'); //show modal $('#addedtocartmodal').openModal(); $.ajax({url: "/ajax_store/add_cart/s"+chosen_size+"/", async: true, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); } function cartadded(make_id) { var free_items =''; var chosen_size= $('#chosen-size-'+make_id).html(); var name = $('#size_name_'+chosen_size).html(); $('#size_added_name').html(name); if( $('#free_items_'+chosen_size).length) { free_items = $('#free_items_'+chosen_size).html(); $('#free_item').html(free_items); } else { $('#free_item').html(''); } ////check free items //does the free item include a shade cover? free_items = free_items.toLowerCase(); var n = free_items.indexOf("shade"); if(n > 0) { //show an "already included message $('.acc_shade-cover').html('
doneFREE - Already added
'); } var bballincluded = free_items.indexOf("basket"); if(bballincluded > 0) { //show an "already included message $('.acc_basketball-set').html('
doneFREE - Already added
'); } $('#cartadded').css("left",'inherit'); $('#cartadded').css("right",0); Materialize.showStaggeredList('#cartadded'); $.ajax({url: "/ajax_store/add_cart/s"+chosen_size+"/", async: true, success: function(result){ $('#cartqty').css("display","block"); $('#cartqtymobile').css("display","block"); $('#cartqty_contents').html(result); }}); } function hide_cart() { $('#cartadded').css("right",'inherit'); $('#cartadded').css("left",-1000); } function get_nz_shipping_estimate() { //get post code var location=$('#postcode_cart').val(); var dfx_zone_id=$('#postcode_hidden_cart').val(); //ajax price calculator $.ajax({url: "/ajax_store/get_nz_shipping_estimate/"+dfx_zone_id+"/", async: true, success: function(result) { //alert(result); var bits = result.split("|"); $("#shipping_estimate_results").html('Your shipping estimate to '+location+' is $'+bits[0]+'*

*'+bits[1]+''); }}); } function get_shipping_estimate() { //get post code var location=$('#postcode_cart').val(); var dfx_zone_id=$('#postcode_hidden_cart').val(); //ajax price calculator //alert("/ajax_store/get_shipping_estimate/"+dfx_zone_id+"/"); $.ajax({url: "/ajax_store/get_shipping_estimate/"+dfx_zone_id+"/", async: true, success: function(result) { //alert(result); //alert(result); var bits = result.split("|"); $("#shipping_estimate_results").html('Your shipping estimate to '+location+' is $'+bits[0]+'*

*'+bits[1]+''); }}); } function choosing_free_acc_size(countup) { $('#free_acc_size').val(countup); } function add_free_bike(bike_id) { //add to cart $.ajax({url: "/ajax_store/add_free_bike/"+bike_id+"/", async: false, success: function(result){ // result location.reload(); }}); } function add_cart_above_free_extra(item_id) { var main_size_counter = $('#free_acc_size').val(); //add to cart $.ajax({url: "/ajax_store/add_free_extra/"+item_id+"/"+main_size_counter+"/", async: false, success: function(result){ // result location.reload(); }}); } function add_cart_above(id,name,line_count) { if( $('#add_cart_'+id).css("background-color")=="rgb(76, 175, 80)") // already added - remove it { /* //make orange/white again $('#add_cart_'+id).css("color","#f15a01"); $('#add_cart_'+id).css("background-color","#fff"); $('#add_cart_'+id).css("border-color","#f15a01"); //$('.add_cart_below_'+id).css("display","none"); $('#qty_'+line_count).val(line_count); // reset value to 1 cart_summary_remove(line_count); // remote line from cart */ } else { $('#box_addon_'+line_count).css("display","none"); // hide accessory box $('.add_cart_below_'+id).css("display","block"); fill_orange_one(id,name,'no'); //cart_summary_adjust_qty('9999999','0'); // a fake number just to return price location.reload(); //window.location.href = "/cart?recommended=yes"; } } function cart_summary_adjust_qty(line_count) { delay(function(){ var new_qty = $("#qty_"+line_count).val(); new_qty = new_qty*1; if(new_qty < 1) // weve incremented it down to 0 { cart_summary_remove(line_count); } else { $.ajax({url: "/ajax_store/cart_summary_adjust_qty/"+line_count+"/"+new_qty+"/", async: true, success: function(result) { console.log("result = "+result); // alert(result);// 2708.98|52|11 or 3580.98|69|12 //var pieces = result.split("|"); //$("#cart_total_price").html('$'+pieces[0]); //$("#cart_total_price_mobile").html('$'+pieces[0]); //$("#zip_tot_mobile").html(''); //$("#zip_tot_desktop").html(''); //$('#itmincart').html(pieces[2]); //$('#cartqty_contents').html(pieces[2]); //refresh the page location.reload(); }}); } }, 200); } function cart_summary_remove(line_count) { $('#remove_row_'+line_count).css("display","none"); $.ajax({url: "/ajax_store/cart_summary_remove/"+line_count+"/", async: false, success: function(result) { //alert(result); var pieces = result.split("|"); console.log('33. #cart_total_price = $'+pieces[0]); $("#cart_total_price").html('$'+pieces[0]); $("#cart_total_price_mobile").html('$'+pieces[0]); $("#zip_tot_mobile").html(''); $("#zip_tot_desktop").html(''); $('#itmincart').html(pieces[2]); $('#cartqty_contents').html(pieces[2]); //refresh the page location.reload(); }}); } function remove_sponsorships() { // mark sponsorships as not added $('#i834').val('0'); $('#i832').val('0'); $('#i833').val('0'); $('#i484').val('0'); $.ajax({url: "/ajax_store/remove_sponsorships/", async: false, success: function(result){ $("#cart_contents").html(result); }}); } function check_sms_sec() { var valid=false; //check terms of trade have been ticked if($('#agreetoterms:checkbox:checked').length > 0) // okay { var smsvalidated = $('#smsvalidated').val(); var smssec = $('#smssec').val(); if(smssec == '1' && smsvalidated == '1' || smssec != '1') { //allow submission valid=true; return valid; } else { //stop form submission process return valid; } } else { return valid; alert('Please complete this form by accepting our terms and conditions.'); } } function submit_address_form() { $("#submit_okay").val('1'); $("#store_checkout_form").submit(); } function validate_submit_address_form() { console.log('validate_submit_address_form()'); var valid = true; var error; var n; var address = $("#contact_address_2").val(); address=address.trim(); n = address.length; if(n < 4) { error = 'Please enter your shipping address.'; valid = false; } var name = $("#contact_name").val(); name=name.trim(); n = name.length; if(name < 2) { error = 'Please enter your full name.'; valid = false; } var last = $("#contact_lastname").val(); last=last.trim(); n = last.length; if(last < 4) { error = 'Please enter your full name.'; valid = false; } var phone = $("#contact_phone_mobile").val(); phone=phone.trim(); n = phone.length; if(n < 8) { error = 'Please enter your mobile or phone number.'; valid = false; } var email = $("#contact_email").val(); email=email.trim(); n = email.length; if(n < 6) { error = 'Please enter your email address.'; valid = false; } else { var atpos = email.indexOf("@"); var dotpos = email.lastIndexOf("."); if (atpos<1 || dotpos=email.length) { valid = false; error = 'Please check your email address. It does not look correct.'; } } var ad_select = $("#ad_select").val(); ad_select = ad_select.trim(); if(ad_select == '') { $("#ad_select").css('border','5px solid #f36f21'); $("#ad_select").css('border-left','5px solid #f36f21'); error = 'Please choose how you heard about us.'; valid = false; } var zip = $("#save_suburb_id").val(); zip=zip * 1; if(zip < 1) { error = 'Please select your suburb / post code.'; valid = false; } if(valid == false) { alert(error); } else { var okay = $("#submit_okay").val(); if(okay == '0') // was the submit button pressed (instead of enter) { valid = false; } } return valid; } function validate_submit_address_form_usa() { console.log('validate_submit_address_form()'); var valid = true; var error; var n; var address = $("#contact_address_2").val(); address=address.trim(); n = address.length; if(n < 4) { error = 'Please enter your shipping address.'; valid = false; } var name = $("#contact_name").val(); name=name.trim(); n = name.length; if(name < 2) { error = 'Please enter your full name.'; valid = false; } var last = $("#contact_lastname").val(); last=last.trim(); n = last.length; if(last < 4) { error = 'Please enter your full name.'; valid = false; } var phone = $("#contact_phone_mobile").val(); phone=phone.trim(); n = phone.length; if(n < 8) { error = 'Please enter your mobile or phone number.'; valid = false; } var email = $("#contact_email").val(); email=email.trim(); n = email.length; if(n < 6) { error = 'Please enter your email address.'; valid = false; } else { var atpos = email.indexOf("@"); var dotpos = email.lastIndexOf("."); if (atpos<1 || dotpos=email.length) { valid = false; error = 'Please check your email address. It does not look correct.'; } } var ad_select = $("#ad_select").val(); ad_select = ad_select.trim(); if(ad_select == '') { $("#ad_select").css('border','5px solid #f36f21'); $("#ad_select").css('border-left','5px solid #f36f21'); error = 'Please choose how you heard about us.'; valid = false; } var zip = $("#zip-input").val(); zip=zip * 1; if(zip < 1) { error = 'Please select your zip code.'; valid = false; } if(valid == false) { alert(error); } else { var okay = $("#submit_okay").val(); if(okay == '0') // was the submit button pressed (instead of enter) { valid = false; } } return valid; } function hideconfirm() { var smssec = $('#smssec').val(); if(smssec == '1') { //launch sms entry screen $('#blackout').css("display","block"); $('#smsquest').css("display","block"); //ajax_store sms sending request $.ajax({url: "/ajax_store/smssec/", async: true, success: function(result){ //alert(result); }}); } else // sms security not needed - submit form { $('#confirmorderpayment').css("display","none"); $('#gobackbutton').css("display","none"); $('#processingplease').css("display","inline"); document.getElementById("complete").submit(); } } function submit_fast_pay() { var pressed = $('#conf_pressed').val(); if(pressed == '1') { //ok to proceed document.getElementById("complete").submit(); } } function conf_pressed() { $('#conf_pressed').val("1"); $('#confirmorderpayment').css("display","none"); $('#gobackbutton').css("display","none"); $('#processingplease').css("display","inline"); document.getElementById("complete").submit(); } function hidealert(itemid) { $("#alert_"+itemid).html(''); } function validate_cc(current_value, next) { //auto tabbing if(current_value !='' && next !='') { //current.value.length==current.getAttribute("maxlength")) if(current_value.length == 4) { document.getElementById(next).focus(); } } var valid = false; var amex ='no'; var currentTime = new Date() // returns the month (from 0 to 11) var current_month = currentTime.getMonth() + 1; var current_year = currentTime.getFullYear() //reset error to blank $('#credit_card_error').html(''); var cc_number_1 = $('#cc_number_1').val(); var cc_number_2 = $('#cc_number_2').val(); var cc_number_3 = $('#cc_number_3').val(); var cc_number_4 = $('#cc_number_4').val(); var ccv = $('#ccv').val(); var cc_expiry_month = $('#cc_expiry_month').val(); var cc_expiry_year = $('#cc_expiry_year').val(); cc_expiry_year = "20" + cc_expiry_year; //var cc_sec_code = document.getElementById('cc_sec_code').value; var firstletters = cc_number_1.substring(0,2); if(firstletters == '34' || firstletters == '37') { amex ='yes'; } cc_expiry_year = cc_expiry_year * 1; cc_expiry_month = cc_expiry_month * 1; ///////////////////////////////////////////////////////////////////////// // has enough of the card been filled in to identify the card type if ( cc_number_1.length == 4 && cc_number_2.length ==4) // has the full card been filled out ? { var last_card_validted = $('#lastcardvalidted').html(); var this_card_validated = cc_number_1+''+cc_number_2; if ( this_card_validated != last_card_validted) // has the full card been filled out ? { //alert('card numbers : '+this_card_validated); $('#lastcardvalidted').html(this_card_validated); $.ajax({url: "/ajax_public/get_cc_surcharge/"+amex+"/"+this_card_validated+"/", async: true, success: function(result){ //alert(result); result = decodeURIComponent(result); if(result == 'unknown') // set back to default { $('#card_surcharge_percentage_type').val('unknown card|1.9'); $('#card_type_surcharge').html('Unknown'); $('#card_surcharge_percentage').html('1.9'); var fee = 1.9; } else // VISA Credit Card|1.38 { var res = result.split("|"); var fee = res[1]*1; $('#card_surcharge_percentage_type').val(result); $('#card_type_surcharge').html(res[0]); $('#card_surcharge_percentage').html(res[1]); } }}); } } ///////////////////////////////////////////////////////////////////////// $('#credit_card_error').css('display','none'); $('#credit_card_error').html(''); //validate credit card and expiry date if (cc_number_1.length < 4 || cc_number_2.length < 4 || cc_number_3.length < 4 ) // last one can be 3 in length for AMEX { //credit card number not long enough //valid = false; } else if ( cc_number_3.length < 4 && amex != 'yes' || cc_number_3.length < 3 && amex == 'yes') { //credit card number not long enough //valid = false; } else if (ccv.length < 3 && amex == 'no' ) { //credit card number not long enough //valid = false; } else if (cc_expiry_year < 1 || cc_expiry_month < 1) // month or year has been left unchosen { //credit card number not long enough //valid = false; } else if(cc_expiry_year < current_year ) { //credit card has expired //valid = false; } else if(cc_expiry_year == current_year && cc_expiry_month < current_month) { //credit card has expired //valid = false; } else // validate credit card { //credit card has expired if (ccv.length < 4 && amex == 'yes' ) { //valid = false; if (ccv.length > 2 ) { $('#credit_card_error').css('display','block'); $('#credit_card_error').html('The CCV on AMEX cards is 4 digits long'); } } else { var card_type = validate_cc_number(cc_number_1+cc_number_2+cc_number_3+cc_number_4, cc_expiry_year, cc_expiry_month); if(card_type != '') { valid = true; } } } if (valid == false) { if( cc_number_4.length < 4 || cc_expiry_year < 2000 || cc_expiry_month < 1 || ccv.length < 3) // if cc details are incomplete, don't show error messages, as this will confuse user. so just show nothing { //show nothing $('#rest-of-form').css("display","none"); } else // if details are in full, but incorrect, show error message { //alert( 'cc_number_4 length = '+cc_number_4.length + ' cc_expiry_year = ' + cc_expiry_year + ' cc_expiry_month = ' + cc_expiry_month ); $('#credit_card_error').html('
The above credit card is either incorrect or has expired!
'); $('#rest-of-form').css("display","none"); } } else // corect details { //show nothing, but display rest of the form below $('#rest-of-form').css("display","block"); } } function validate_cc_number(cc_number, expiry_year, expiry_month) { var valid = true; var card_type = ''; if(expiry_month.length < 2) { expiry_month = "0"+expiry_month; } var Cards = new makeArray(3); Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16"); var MasterCard = Cards[0]; Cards[1] = new CardType("Visa", "4", "13,16"); var Visa = Cards[1]; Cards[2] = new CardType("AMEX", "34,37", "15"); var AMEX = Cards[2]; /*Cards[3] = new CardType("DinersClubCard", "30,36,38", "14"); var DinersClubCard = Cards[3]; Cards[4] = new CardType("DiscoverCard", "6011", "16"); var DiscoverCard = Cards[4]; Cards[5] = new CardType("enRouteCard", "2014,2149", "15"); var enRouteCard = Cards[5]; Cards[6] = new CardType("JCBCard", "3088,3096,3112,3158,3337,3528", "16"); var JCBCard = Cards[6]; var LuhnCheckSum = Cards[7] = new CardType();*/ for (var n = 0; n < Cards.size; n++) { if (Cards[n].checkCardNumber(cc_number, expiry_year, expiry_month)) { card_type = Cards[n].getCardType(); break; } } return card_type; } /*************************************************************************\ Object CardType([String cardtype, String rules, String len, int year, int month]) cardtype : type of card, eg: MasterCard, Visa, etc. rules : rules of the cardnumber, eg: "4", "6011", "34,37". len : valid length of cardnumber, eg: "16,19", "13,16". year : year of expiry date. month : month of expiry date. eg: var Visa = new CardType("Visa", "4", "16"); var AMEX = new CardType("AmEx", "34,37", "15"); \*************************************************************************/ function CardType() { var n; var argv = CardType.arguments; var argc = CardType.arguments.length; this.objname = "object CardType"; var tmpcardtype = (argc > 0) ? argv[0] : "CardObject"; var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9"; var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19"; this.setCardNumber = setCardNumber; // set CardNumber method. this.setCardType = setCardType; // setCardType method. this.setLen = setLen; // setLen method. this.setRules = setRules; // setRules method. this.setExpiryDate = setExpiryDate; // setExpiryDate method. this.setCardType(tmpcardtype); this.setLen(tmplen); this.setRules(tmprules); if (argc > 4) this.setExpiryDate(argv[3], argv[4]); this.checkCardNumber = checkCardNumber; // checkCardNumber method. this.getExpiryDate = getExpiryDate; // getExpiryDate method. this.getCardType = getCardType; // getCardType method. this.isCardNumber = isCardNumber; // isCardNumber method. this.isExpiryDate = isExpiryDate; // isExpiryDate method. this.luhnCheck = luhnCheck;// luhnCheck method. return this; } /*************************************************************************\ boolean checkCardNumber([String cardnumber, int year, int month]) return true if cardnumber pass the luhncheck and the expiry date is valid, else return false. \*************************************************************************/ function checkCardNumber() { var argv = checkCardNumber.arguments; var argc = checkCardNumber.arguments.length; var cardnumber = (argc > 0) ? argv[0] : this.cardnumber; var year = (argc > 1) ? argv[1] : this.year; var month = (argc > 2) ? argv[2] : this.month; this.setCardNumber(cardnumber); this.setExpiryDate(year, month); if (!this.isCardNumber()) return false; if (!this.isExpiryDate()) return false; return true; } /*************************************************************************\ String getCardType() return the cardtype. \*************************************************************************/ function getCardType() { return this.cardtype; } /*************************************************************************\ String getExpiryDate() return the expiry date. \*************************************************************************/ function getExpiryDate() { return this.month + "/" + this.year; } /*************************************************************************\ boolean isCardNumber([String cardnumber]) return true if cardnumber pass the luhncheck and the rules, else return false. \*************************************************************************/ function isCardNumber() { var argv = isCardNumber.arguments; var argc = isCardNumber.arguments.length; var cardnumber = (argc > 0) ? argv[0] : this.cardnumber; if (!this.luhnCheck()) return false; for (var n = 0; n < this.len.size; n++) if (cardnumber.toString().length == this.len[n]) { for (var m = 0; m < this.rules.size; m++) { var headdigit = cardnumber.substring(0, this.rules[m].toString().length); if (headdigit == this.rules[m]) return true; } return false; } return false; } /*************************************************************************\ boolean isExpiryDate([int year, int month]) return true if the date is a valid expiry date, else return false. \*************************************************************************/ function isExpiryDate() { var argv = isExpiryDate.arguments; var argc = isExpiryDate.arguments.length; year = argc > 0 ? argv[0] : this.year; month = argc > 1 ? argv[1] : this.month; if (!isNum(year+"")) return false; if (!isNum(month+"")) return false; today = new Date(); expiry = new Date(year, month); if (today.getTime() > expiry.getTime()) return false; else return true; } /*************************************************************************\ boolean isNum(String argvalue) return true if argvalue contains only numeric characters, else return false. \*************************************************************************/ function isNum(argvalue) { argvalue = argvalue.toString(); if (argvalue.length == 0) return false; for (var n = 0; n < argvalue.length; n++) if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9") return false; return true; } /*************************************************************************\ boolean luhnCheck([String CardNumber]) return true if CardNumber pass the luhn check else return false. Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl \*************************************************************************/ function luhnCheck() { var argv = luhnCheck.arguments; var argc = luhnCheck.arguments.length; var CardNumber = argc > 0 ? argv[0] : this.cardnumber; if (! isNum(CardNumber)) { return false; } var no_digit = CardNumber.length; var oddoeven = no_digit & 1; var sum = 0; for (var count = 0; count < no_digit; count++) { var digit = parseInt(CardNumber.charAt(count)); if (!((count & 1) ^ oddoeven)) { digit *= 2; if (digit > 9) digit -= 9; } sum += digit; } if (sum % 10 == 0) return true; else return false; } /*************************************************************************\ ArrayObject makeArray(int size) return the array object in the size specified. \*************************************************************************/ function makeArray(size) { this.size = size; return this; } /*************************************************************************\ CardType setCardNumber(cardnumber) return the CardType object. \*************************************************************************/ function setCardNumber(cardnumber) { this.cardnumber = cardnumber; return this; } /*************************************************************************\ CardType setCardType(cardtype) return the CardType object. \*************************************************************************/ function setCardType(cardtype) { this.cardtype = cardtype; return this; } /*************************************************************************\ CardType setExpiryDate(year, month) return the CardType object. \*************************************************************************/ function setExpiryDate(year, month) { this.year = year; this.month = month; return this; } /*************************************************************************\ CardType setLen(len) return the CardType object. \*************************************************************************/ function setLen(len) { // Create the len array. if (len.length == 0 || len == null) len = "13,14,15,16,19"; var tmplen = len; n = 1; while (tmplen.indexOf(",") != -1) { tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length); n++; } this.len = new makeArray(n); n = 0; while (len.indexOf(",") != -1) { var tmpstr = len.substring(0, len.indexOf(",")); this.len[n] = tmpstr; len = len.substring(len.indexOf(",") + 1, len.length); n++; } this.len[n] = len; return this; } /*************************************************************************\ CardType setRules() return the CardType object. \*************************************************************************/ function setRules(rules) { // Create the rules array. if (rules.length == 0 || rules == null) rules = "0,1,2,3,4,5,6,7,8,9"; var tmprules = rules; n = 1; while (tmprules.indexOf(",") != -1) { tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length); n++; } this.rules = new makeArray(n); n = 0; while (rules.indexOf(",") != -1) { var tmpstr = rules.substring(0, rules.indexOf(",")); this.rules[n] = tmpstr; rules = rules.substring(rules.indexOf(",") + 1, rules.length); n++; } this.rules[n] = rules; return this; } // End -->