function add_discount_to_page(discount_code,disc){let discount_id=disc[1];let discount_amount=disc[2];let discount_type_id=disc[0];let discount_display_text=disc[3];let html='';discount_type_id=(typeof discount_type_id=='string')?parseInt(discount_type_id):discount_type_id;switch(discount_type_id){case 1:case 3:case 4:case 6:case 7:case 8:$('#totals div:first').before(html);break;case 2:case 5:$('#totals span.amtdue').before(html);break;}} function build_country_options_html(countries){let html='';if(countries.length){for(let property in countries){if(countries.hasOwnProperty(property)){html+='';} return html;} function build_shipping_options_html(shipping){let html='';if(shipping.length){for(let property in shipping){if(shipping.hasOwnProperty(property)){html+='';} return html;} function build_state_options_html(states){let html='';if(states.length){for(let property in states){if(states.hasOwnProperty(property)){html+='';} return html;} function checkout_next_step() {let billing_first_name=$('#billing_first_name').val();let billing_last_name=$('#billing_last_name').val();let billing_company_name=$('#billing_company_name').val();let billing_address_1=$('#billing_address_1').val();let billing_address_2=$('#billing_address_2').val();let billing_city=$('#billing_city').val();let billing_country_id=$('#checkout_billing_country option:selected').val();let billing_state_id=$('#checkout_billing_state option:selected').val();let billing_zip=$('#billing_zip').val();let shipping_first_name=$('#shipping_first_name').val();let shipping_last_name=$('#shipping_last_name').val();let shipping_company_name=$('#shipping_company_name').val();let shipping_address_1=$('#shipping_address_1').val();let shipping_address_2=$('#shipping_address_2').val();let shipping_city=$('#shipping_city').val();let shipping_country_id=$('#checkout_shipping_country option:selected').val();let shipping_state_id=$('#checkout_shipping_state option:selected').val();let shipping_zip=$('#shipping_zip').val();let shipping_notes=$('#shipping_notes').val();let url='https://www.lightology.com/index.php?module=cart_billing';let data='&billing_first_name='+encodeURIComponent(billing_first_name)+'&billing_last_name='+encodeURIComponent(billing_last_name)+'&billing_company_name='+encodeURIComponent(billing_company_name)+'&billing_address_1='+encodeURIComponent(billing_address_1)+'&billing_address_2='+encodeURIComponent(billing_address_2)+'&billing_city='+encodeURIComponent(billing_city)+'&billing_country_id='+billing_country_id+'&billing_state_id='+billing_state_id+'&billing_zip='+encodeURIComponent(billing_zip)+'&shipping_first_name='+encodeURIComponent(shipping_first_name)+'&shipping_last_name='+encodeURIComponent(shipping_last_name)+'&shipping_company_name='+encodeURIComponent(shipping_company_name)+'&shipping_address_1='+encodeURIComponent(shipping_address_1)+'&shipping_address_2='+encodeURIComponent(shipping_address_2)+'&shipping_city='+encodeURIComponent(shipping_city)+'&shipping_country_id='+shipping_country_id+'&shipping_state_id='+shipping_state_id+'&shipping_zip='+encodeURIComponent(shipping_zip)+'&shipping_notes='+encodeURIComponent(shipping_notes);$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){window.location=data.location;}}});} function detect_async_support() {let supported=true;try{eval('async () => {}');}catch(e){if(e instanceof SyntaxError){supported=false;}else{throw e;}} return supported;} function display_submit_order_spinner(){var spinner=$('  '+''+'  Processing payment... Please do not refresh the page'+'');$('#submit_order').replaceWith(spinner);$('.red_txt').html('');} function highlight_checkout_input_errors(data){$('.billing_edit, .shipping_edit, .cc_edit').removeClass('error');if(data.hasOwnProperty('input_errors')){for(let property in data.input_errors){if(data.input_errors.hasOwnProperty(property)){$('#'+property).addClass('error');}}}} function remove_displayed_discounts(codes){for(let i=0;i0){$('.cart_wrapper').removeClass('empty').addClass('full');}else{$('.cart_wrapper').removeClass('full').addClass('empty');}} function update_cart_page(data){let html,property;let ship_service_id,ship_service_default,ship_service_name,ship_service_cost;$('#amt_discounted_subtotal').html(data.discounted_subtotal);$('#amt_tax_rate').html(data.tax_rate);$('#amt_tax').html(data.tax);$('#amt_shipping').html(data.shipping);$('#amt_total').html(data.total);$('#amt_payable_total').html(data.payable_total);let disc=data.discount;if(disc){for(property in disc){if(disc.hasOwnProperty(property)){$('#discount_display_text_'+disc[property][1]).html(disc[property][3]);$('#discount_amount_'+disc[property][1]).html(disc[property][2]);$('#status_msg_'+disc[property][1]).fadeIn();}}} let $cart_shipping_option=$('#cart_shipping_option');if(data.ship.length){$cart_shipping_option.find('option').remove();html='';for(property in data.ship){if(data.ship.hasOwnProperty(property)){ship_service_id=data.ship[property][0];ship_service_name=data.ship[property][1];ship_service_cost=data.ship[property][2];ship_service_default=data.ship[property][3];html+='';}} $cart_shipping_option.append(html).prop('disabled',false);}else{html='';$cart_shipping_option.append(html).prop('disabled',true);}} function apply_discount(){let discount_code,url,data;let status_class,status_code,disc,property;discount_code=$('#cart_promo').val();if(!discount_code.length){return;} url='https://www.lightology.com/index.php?module=dispatcher';data='action=apply_discount&discount_code='+discount_code;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){status_class='';status_code=(typeof data.status_code=='string')?parseInt(data.status_code):data.status_code;switch(status_code){case 1:status_class='green_txt';$('#cart_promo_apply').fadeOut(200);$('#cart_promo').val('').blur();break;case 0:case-1:status_class='red_txt';break;} remove_displayed_discounts(data.removed_codes);$('#status_msg').html(''+data.status_msg+'').removeClass().addClass(status_class);disc=data.discount;if(disc.length>0){for(property in disc){if(disc.hasOwnProperty(property)){if(!$('#status_msg_'+disc[property][1]).length){add_discount_to_page(discount_code,disc[property]);break;}}}} update_cart_page(data);setTimeout(function(){$('#status_msg span').fadeOut();},2000);}}});} function handle_add_accessory_to_cart_click(prod_id) {let url='https://www.lightology.com/index.php?module=dispatcher';let qty=parseInt($('#acc_qty_'+prod_id).val(),10);let data='action=add_accessory_to_cart&prod_id='+prod_id+'&quantity='+qty;$('#add_acc_to_cart_'+prod_id).after('').hide();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){let cartCnt=parseInt(data.cart_count,10);$('.cart_count').html(cartCnt);update_cart_image(cartCnt);$('#add_acc_to_cart_'+prod_id+' + span').addClass('green_txt').css('font-size','9px').html('added').fadeOut(800).delay(800,function(){$('#add_acc_to_cart_'+prod_id).show();});}}});} function handle_address_select_item_click($this){let url='https://www.lightology.com/index.php?module=dispatcher';let addr_id=$this.attr('id').replace('address_select_item_id_','');let address_type=$('#address_type').text();let data='action=get_address_for_checkout&addr_id='+addr_id+'&addr_type_name='+address_type.toLowerCase();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){$('.ui-dialog').remove();if(data){let prefix=address_type.toLowerCase()+'_';let type_to=address_type.toLowerCase().slice(0,4);$('input#'+prefix+'first_name').val(data.address.first_name);$('input#'+prefix+'last_name').val(data.address.last_name);$('input#'+prefix+'company_name').val(data.address.company_name);$('input#'+prefix+'address_1').val(data.address.address_1);$('input#'+prefix+'address_2').val(data.address.address_2);$('input#'+prefix+'city').val(data.address.city);$('input#'+prefix+'zip').val(data.address.zip);$('#checkout_'+prefix+'country').val(data.address.country_id);$('.error').removeClass('error');let $checkout_state=$('#checkout_'+prefix+'state');let $checkout_to_state=$('#checkout_'+type_to+'_to_state');$checkout_state.find('option').remove();if(data.states.length){$checkout_to_state.show();$checkout_state.append(build_state_options_html(data.states));}else{$checkout_to_state.hide();} if(type_to=='ship'){let $checkout_shipping_option=$('#checkout_shipping_option');$checkout_shipping_option.find('option').remove();$checkout_shipping_option.append(build_shipping_options_html(data.shipping));$checkout_shipping_option.prop('disabled',(data.shipping.length<1));let $shipping_restriction_div=$('#shipping_restriction_div');if(data.shipping.length<1){$shipping_restriction_div.show();}else{$shipping_restriction_div.hide();}} if(type_to=='bill'){let bill_country_id=parseInt(data.address.country_id,10);let shipping_countries=[41,185,239,248];if(shipping_countries.indexOf(bill_country_id)>=0){$('#checkout_ship_to_bill').prop('disabled',false);}else{$('#checkout_ship_to_bill').prop('disabled',true);}}}},error:function(){}});} function handle_cart_promo_keyup(key){if(key===37||key===39||key===35||key===36||(key>=96&&key<=105)||(key>=48&&key<=57)||(key>=65&&key<=90)||key===8||key===46||key===9||key===116||key===16||key===17||key===45) {if($('#cart_promo').val().length){$('#cart_promo_apply').show();}else{$('#cart_promo_apply').hide();}}else{if(key===13){apply_discount();}}} function handle_cart_cc_number_key(event){const keys=[48,49,50,51,52,53,54,55,56,57];let key=event.which;let $cc_number=$('#cc_number') if(keys.includes(key)){let amex_edges=[4,11];let visa_edges=[4,9,14];let cc_number=$cc_number.val();let length=cc_number.length;let edges=visa_edges;let max_length=19;if(length>0&&cc_number[0]==='3'){edges=amex_edges;max_length=17;} if(length===max_length){event.preventDefault();} else if(edges.includes(length)){$cc_number.val(cc_number+' ');}} else{event.preventDefault();}} function handle_cart_shipping_country_change(){let url='https://www.lightology.com/index.php?module=dispatcher';let ship_country_id=parseInt($('#cart_shipping_country').val(),10);let data='action=cart_shipping_country_change&ship_country_id='+ship_country_id;$('#cart_shipping_zip').val('');$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){let $cart_ship_to_state=$('#cart_ship_to_state');let $cart_shipping_state=$('#cart_shipping_state');let $cart_shipping_option=$('#cart_shipping_option');let $shipping_restriction_div=$('#shipping_restriction_div');$('#tax_state').html(data.tax_state);$('#amt_tax_rate').html(data.amt_tax_rate);$('#amt_tax').html(data.amt_tax);$('#amt_shipping').html(data.amt_shipping);$('#amt_total').html(data.amt_total);$('#amt_payable_total').html(data.amt_payable_total);$('.amtdue').html(data.amount_due_label);$cart_shipping_state.find('option').remove();$cart_shipping_option.find('option').remove();if(data.shipping_states.length){$cart_ship_to_state.show();$cart_shipping_state.append(build_state_options_html(data.shipping_states));if(data.state_zip_tax_enabled){$('#cart_ship_to_zip').show();}else{$('#cart_ship_to_zip').hide();}}else{$cart_ship_to_state.hide();} $cart_shipping_option.append(build_shipping_options_html(data.shipping));$cart_shipping_option.prop('disabled',(data.shipping.length<1));if(data.shipping.length<1){$shipping_restriction_div.show();}else{$shipping_restriction_div.hide();}}}});} function handle_cart_shipping_option_change(){let url='https://www.lightology.com/index.php?module=dispatcher';let ship_service_id=parseInt($('#cart_shipping_option').val(),10);let data='action=cart_shipping_option_change&ship_service_id='+ship_service_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#amt_shipping').html(data.amt_shipping);$('#amt_total').html(data.amt_total);$('#amt_payable_total').html(data.amt_payable_total);$('#cart_shipping_title').html(data.shipping_title);$('#cart_shipping_option_title').html(data.shipping_option_title);}}});} function handle_cart_shipping_state_change(){let url='https://www.lightology.com/index.php?module=dispatcher';let ship_state_id=parseInt($('#cart_shipping_state').val(),10);let data='action=cart_shipping_state_change&ship_state_id='+ship_state_id;$('#cart_shipping_zip').val('');$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#tax_state').html(data.tax_state);$('#amt_tax_rate').html(data.amt_tax_rate);$('#amt_tax').html(data.amt_tax);$('#amt_shipping').html(data.amt_shipping);$('#amt_total').html(data.amt_total);$('#amt_payable_total').html(data.amt_payable_total);$('.amtdue').html(data.amount_due_label);let $cart_shipping_option=$('#cart_shipping_option');$cart_shipping_option.find('option').remove();$cart_shipping_option.append(build_shipping_options_html(data.shipping));$cart_shipping_option.prop('disabled',(data.shipping.length<1));if(data.state_zip_tax_enabled){$('#cart_ship_to_zip').show();}else{$('#cart_ship_to_zip').hide();}}}});} function handle_cart_shipping_zip_change(){let url='https://www.lightology.com/index.php?module=dispatcher';let shipping_zip=$('#cart_shipping_zip').val();let data='action=cart_shipping_zip_change&shipping_zip='+shipping_zip;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#tax_state').html(data.tax_state);$('#amt_tax_rate').html(data.amt_tax_rate);$('#amt_tax').html(data.amt_tax);$('#amt_shipping').html(data.amt_shipping);$('#amt_total').html(data.amt_total);$('#amt_payable_total').html(data.amt_payable_total);$('.amtdue').html(data.amount_due_label);}}});} function handle_checkout_billing_country_change(){let url='https://www.lightology.com/index.php?module=dispatcher';let bill_country_id=parseInt($('#checkout_billing_country').val(),10);let data='action=checkout_billing_country_change&bill_country_id='+bill_country_id;let shipping_countries=[41,185,239,248];if(shipping_countries.indexOf(bill_country_id)>=0){$('#checkout_ship_to_bill').prop('disabled',false);}else{$('#checkout_ship_to_bill').prop('disabled',true);} $.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#billing_zip').prop('value',data.billing_zip);if(data.hasOwnProperty('shipping_zip')){$('#shipping_zip').prop('value',data.shipping_zip);} let $checkout_billing_state=$('#checkout_billing_state');$checkout_billing_state.find('option').remove();if(data.billing_states.length){$('#checkout_bill_to_state').show();$checkout_billing_state.append(build_state_options_html(data.billing_states));}else{$('#checkout_bill_to_state').hide();} if(data.shipping_countries){let $checkout_shipping_country=$('#checkout_shipping_country');$checkout_shipping_country.find('option').remove();$checkout_shipping_country.append(build_country_options_html(data.shipping_countries));if(data.billing_states.length){$('#checkout_ship_to_state').show();$('#checkout_shipping_state').append(build_state_options_html(data.billing_states));}else{$('#checkout_ship_to_state').hide();}} if(data.shipping){let $checkout_shipping_option=$('#checkout_shipping_option');$checkout_shipping_option.find('option').remove();let html=build_shipping_options_html(data.shipping);$checkout_shipping_option.append(html);}}}});} function handle_checkout_billing_state_change(){let url='https://www.lightology.com/index.php?module=dispatcher';let bill_state_id=parseInt($('#checkout_billing_state').val(),10);let data='action=checkout_billing_state_change&bill_state_id='+bill_state_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#billing_zip').prop('value',data.billing_zip);if(data.hasOwnProperty('shipping_zip')){$('#shipping_zip').prop('value',data.shipping_zip);} if(data.shipping_states){let $checkout_shipping_state=$('#checkout_shipping_state');$checkout_shipping_state.find('option').remove();$checkout_shipping_state.append(build_state_options_html(data.shipping_states));} if(data.shipping){let $checkout_shipping_option=$('#checkout_shipping_option');$checkout_shipping_option.find('option').remove();let html=build_shipping_options_html(data.shipping);$checkout_shipping_option.append(html);}}}});} function handle_checkout_next_step() {$('#checkout_error_message').html('');$('#ship_to_bill_error_message').html('');let cc_number=$('#cc_number').val();cc_number=cc_number.replace(/ /g,'');let url='https://www.lightology.com/index.php?module=dispatcher';let billing_first_name=$('#billing_first_name').val();let billing_last_name=$('#billing_last_name').val();let billing_company_name=$('#billing_company_name').val();let billing_address_1=$('#billing_address_1').val();let billing_address_2=$('#billing_address_2').val();let billing_city=$('#billing_city').val();let billing_zip=$('#billing_zip').val();let shipping_first_name=$('#shipping_first_name').val();let shipping_last_name=$('#shipping_last_name').val();let shipping_company_name=$('#shipping_company_name').val();let shipping_address_1=$('#shipping_address_1').val();let shipping_address_2=$('#shipping_address_2').val();let shipping_city=$('#shipping_city').val();let shipping_zip=$('#shipping_zip').val();let shipping_notes=$('#shipping_notes').val();let data='action=validate_checkout_input'+'&billing_first_name='+encodeURIComponent(billing_first_name)+'&billing_last_name='+encodeURIComponent(billing_last_name)+'&billing_company_name='+encodeURIComponent(billing_company_name)+'&billing_address_1='+encodeURIComponent(billing_address_1)+'&billing_address_2='+encodeURIComponent(billing_address_2)+'&billing_city='+encodeURIComponent(billing_city)+'&billing_country='+$('#checkout_billing_country option:selected').val()+'&billing_state='+$('#checkout_billing_state option:selected').val()+'&billing_zip='+encodeURIComponent(billing_zip)+'&shipping_first_name='+encodeURIComponent(shipping_first_name)+'&shipping_last_name='+encodeURIComponent(shipping_last_name)+'&shipping_company_name='+encodeURIComponent(shipping_company_name)+'&shipping_address_1='+encodeURIComponent(shipping_address_1)+'&shipping_address_2='+encodeURIComponent(shipping_address_2)+'&shipping_city='+encodeURIComponent(shipping_city)+'&shipping_country='+$('#checkout_shipping_country option:selected').val()+'&shipping_state='+$('#checkout_shipping_state option:selected').val()+'&shipping_zip='+encodeURIComponent(shipping_zip)+'&cc_number='+cc_number+'&cc_month='+$('#cc_month').val()+'&cc_year='+$('#cc_year').val()+'&cc_cvv='+$('#cc_cvv').val()+'&shipping_notes='+encodeURIComponent(shipping_notes);$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){if(data.hasOwnProperty('input_errors')){highlight_checkout_input_errors(data);$('#checkout_error_message').html('Please correct the fields highlighted in red');} else{if(async_supported){checkout_next_step_verify_addresses();}else{checkout_next_step();}}}}});} function handle_checkout_ship_to_bill_change($this){$('#ship_to_bill_error_message').html('');$('.billing_edit').removeClass('error');let url='https://www.lightology.com/index.php?module=dispatcher';let ship_to_bill=($this.prop('checked'))?1:0;let billing_first_name=$('#billing_first_name').val();let billing_last_name=$('#billing_last_name').val();let billing_company_name=$('#billing_company_name').val();let billing_address_1=$('#billing_address_1').val();let billing_address_2=$('#billing_address_2').val();let billing_city=$('#billing_city').val();let billing_country_id=$('#checkout_billing_country option:selected').val();let billing_state_id=$('#checkout_billing_state option:selected').val();let billing_zip=$('#billing_zip').val();let data='action=checkout_ship_to_bill_change&ship_to_bill='+ship_to_bill+'&billing_first_name='+encodeURIComponent(billing_first_name)+'&billing_last_name='+encodeURIComponent(billing_last_name)+'&billing_company_name='+encodeURIComponent(billing_company_name)+'&billing_country_id='+billing_country_id+'&billing_state_id='+billing_state_id+'&billing_address_1='+encodeURIComponent(billing_address_1)+'&billing_address_2='+encodeURIComponent(billing_address_2)+'&billing_city='+encodeURIComponent(billing_city)+'&billing_zip='+encodeURIComponent(billing_zip);$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){if(data.hasOwnProperty('input_errors')){highlight_checkout_input_errors(data);$('#checkout_ship_to_bill').prop('checked',false);$('#ship_to_bill_error_message').html('Please correct the billing fields highlighted in red');}else{$('#shipping_first_name').prop('value',data.address.first_name);$('#shipping_last_name').prop('value',data.address.last_name);$('#shipping_company_name').prop('value',data.address.company_name);$('#shipping_address_1').prop('value',data.address.address_1);$('#shipping_address_2').prop('value',data.address.address_2);$('#shipping_city').prop('value',data.address.city);$('#shipping_zip').prop('value',data.address.zip);let $checkout_shipping_country=$('#checkout_shipping_country');$checkout_shipping_country.find('option').remove();let html=build_country_options_html(data.shipping_countries);$checkout_shipping_country.append(html);if(data.shipping_states.length){let $checkout_shipping_state=$('#checkout_shipping_state');$('#checkout_ship_to_state').show();$checkout_shipping_state.find('option').remove();html=build_state_options_html(data.shipping_states);$checkout_shipping_state.append(html);}else{$('#checkout_ship_to_state').hide();} let $checkout_shipping_option=$('#checkout_shipping_option');$checkout_shipping_option.find('option').remove();html=build_shipping_options_html(data.shipping);$checkout_shipping_option.append(html);$('.checkout_disable').prop('disabled',(ship_to_bill===1));if(ship_to_bill>0){$('#select_another_shipping_address_div').hide();}else{$('#select_another_shipping_address_div').show();} $checkout_shipping_option.prop('disabled',(data.shipping.length<1));let $shipping_restriction_div=$('#shipping_restriction_div');if(data.shipping.length<1){$shipping_restriction_div.show();}else{$shipping_restriction_div.hide();}}}}});} function handle_checkout_shipping_state_change() {let url='https://www.lightology.com/index.php?module=dispatcher';let ship_state_id=parseInt($('#checkout_shipping_state').val(),10);let data='action=checkout_shipping_state_change&ship_state_id='+ship_state_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#shipping_zip').prop('value',data.shipping_zip);let $checkout_shipping_option=$('#checkout_shipping_option');$checkout_shipping_option.find('option').remove();$checkout_shipping_option.append(build_shipping_options_html(data.shipping));$checkout_shipping_option.prop('disabled',(data.shipping.length<1));}}});} function handle_checkout_shipping_country_change() {let url='https://www.lightology.com/index.php?module=dispatcher';let ship_country_id=parseInt($('#checkout_shipping_country').val(),10);let data='action=checkout_shipping_country_change&ship_country_id='+ship_country_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#shipping_zip').prop('value',data.shipping_zip);let $checkout_shipping_state=$('#checkout_shipping_state');let $checkout_ship_to_state=$('#checkout_ship_to_state');$checkout_shipping_state.find('option').remove();if(data.shipping_states.length){$checkout_ship_to_state.show();$checkout_shipping_state.append(build_state_options_html(data.shipping_states));}else{$checkout_ship_to_state.hide();} let $checkout_shipping_option=$('#checkout_shipping_option');$checkout_shipping_option.find('option').remove();$checkout_shipping_option.append(build_shipping_options_html(data.shipping));$checkout_shipping_option.prop('disabled',(data.shipping.length<1));let $shipping_restriction_div=$('#shipping_restriction_div');if(data.shipping.length<1){$shipping_restriction_div.show();}else{$shipping_restriction_div.hide();}}}});} function handle_checkout_shipping_option_change(){let url='https://www.lightology.com/index.php?module=dispatcher';let ship_service_id=parseInt($('#checkout_shipping_option').val(),10);let data='action=checkout_shipping_option_change&ship_service_id='+ship_service_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#shipping_first_name').prop('value',data.address.first_name);$('#shipping_last_name').prop('value',data.address.last_name);$('#shipping_company_name').prop('value',data.address.company_name);$('#shipping_address_1').prop('value',data.address.address_1);$('#shipping_address_2').prop('value',data.address.address_2);$('#shipping_city').prop('value',data.address.city);$('#shipping_zip').prop('value',data.address.zip);if(ship_service_id==5||ship_service_id==6){$('.checkout_disable').prop('disabled',true);$('#checkout_ship_to_bill').prop('disabled',true);}else{$('#checkout_ship_to_bill').prop('disabled',false);if(!data.ship_to_bill){$('.checkout_disable').prop('disabled',false);}} $('#checkout_shipping_option_title').html(data.shipping_option_title+' *');}}});} function handle_save_customer_address_click(prefix) {let url='https://www.lightology.com/index.php?module=dispatcher';let first_name=$('#'+prefix+'first_name').val();let last_name=$('#'+prefix+'last_name').val();let company_name=$('#'+prefix+'company_name').val();let address_1=$('#'+prefix+'address_1').val();let address_2=$('#'+prefix+'address_2').val();let city=$('#'+prefix+'city').val();let zip=$('#'+prefix+'zip').val();let country_id=$('#checkout_'+prefix+'country option:selected').val();let state_id=$('#checkout_'+prefix+'state option:selected').val();if(typeof state_id==='undefined'){state_id=0;} $('.error').removeClass('error');let data='action=validate_address&'+prefix+'first_name='+encodeURIComponent(first_name)+'&'+prefix+'last_name='+encodeURIComponent(last_name)+'&'+prefix+'company_name='+encodeURIComponent(company_name)+'&'+prefix+'address_1='+encodeURIComponent(address_1)+'&'+prefix+'address_2='+encodeURIComponent(address_2)+'&'+prefix+'city='+encodeURIComponent(city)+'&'+prefix+'zip='+encodeURIComponent(zip)+'&'+prefix+'country_id='+country_id+'&'+prefix+'state_id='+state_id+'&prefix='+prefix;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){let code=(typeof data.code=='string')?parseInt(data.code):data.code;switch(code){case 0:if(data.fields.length){for(let property in data.fields){if(data.fields.hasOwnProperty(property)){$('#'+data.fields[property]).addClass('error');}}} break;case 1:let output=data.output;let cust_id=$('#cart_cust_id').text();let data2='action=build_save_customer_address_dialog'+'&addr_type=0'+'&addr_parent_type=0'+'&addr_parent_id='+cust_id+'&first_name='+encodeURIComponent(output[prefix+'first_name'])+'&last_name='+encodeURIComponent(output[prefix+'last_name'])+'&company_name='+encodeURIComponent(output[prefix+'company_name'])+'&address_1='+encodeURIComponent(output[prefix+'address_1'])+'&address_2='+encodeURIComponent(output[prefix+'address_2'])+'&city='+encodeURIComponent(output[prefix+'city'])+'&zip='+encodeURIComponent(output[prefix+'zip'])+'&country_id='+country_id+'&state_id='+state_id+'&prefix='+prefix;$.ajax({type:'POST',url:url,data:data2,dataType:'json',success:function(data2){if(data2.dialog){let buttons=[{text:'Save',click:function(){save_address(prefix,create_customer_address,$(this));}},{text:'Cancel',click:function(){$(this).dialog('close');}}];$('body').append(data2.dialog);$('#save_address_dialog').dialog({title:data2.title,height:'auto',width:'auto',modal:true,show:{effect:'fade',duration:800},close:function(){$(this).remove();},buttons:buttons});}},error:function(){}});break;}},error:function(){}});} function handle_select_another_address_click(address_type) {let url='https://www.lightology.com/index.php?module=dispatcher';let cust_id=$('#cart_cust_id').text();let data='action=build_select_address_dialog&cust_id='+cust_id+'&address_type='+address_type;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data.dialog){$('body').append(data.dialog);$('#select_address_dialog').dialog({title:data.title,height:'auto',width:'auto',modal:true,show:{effect:'fade',duration:800},close:function(){$(this).remove();}});}},error:function(){}});} function remove_discount($this){let discId,url,data;discId=$this.data().discountId;url='https://www.lightology.com/index.php?module=dispatcher';data='action=remove_discount&discount_id='+discId;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#status_msg_'+discId).fadeOut();update_cart_page(data);}}});} function remove_order_line($this) {let prod_id=$this.data('prodId');let prod_sku=$this.data('prodSku');let prod_name=$this.data('prodName');let category_name=$this.data('categoryName');let quantity=parseInt($('#order_line_quantity_'+prod_id).val(),10);let vendor=$this.data('vendName');$this.text('removing...');if(typeof gtag!=='undefined'){let user_id=$('#ga_user_id').text();generate_ga_config_clause(user_id);gtag('event','remove_from_cart',{'send_to':['UA-1647398-1','G-10MBQY35VG'],'items':[{'id':prod_sku,'name':prod_name,'brand':vendor,'category':category_name,'quantity':quantity}]});} let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=remove_order_line&prod_id='+prod_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){let itemCount=parseInt(data.item_count,10);$('div#prod_row_'+prod_id).remove();if(typeof itemCount==='number'){$('.cart_count').html(itemCount);update_cart_image(itemCount);remove_displayed_discounts(data.removed_codes);update_cart_page(data);} if(!itemCount){$('div.products').append('There are no items in your shopping cart.');$('#amt_discounted_subtotal, #amt_tax_rate, #amt_tax, #amt_shipping, #amt_total, #amt_payable_total').html('0.00');$('.go-btn').html('');if(typeof data.discount!=='undefined'){$('#discount_amount_1, #discount_amount_1').html('0.00');$('#status_msg_1, #status_msg_2').hide();} let $confirm_form=$('form#confirm_form');let $add_cart_to_wishlist_wrapper=$('.add_cart_to_wishlist_wrapper');if($confirm_form.length){$confirm_form.remove();} if($add_cart_to_wishlist_wrapper.length){$add_cart_to_wishlist_wrapper.remove();}} $('.mini-row-container').html(data.minicart);let item_count=(data.item_count)?data.item_count:'';$('.minicart .count').html(item_count);}}});} function update_order_line_quantity($this){let prod_id,quantity,url,data;prod_id=$this.data('prodId');quantity=parseInt($('#order_line_quantity_'+prod_id).val(),10);if(Number.isNaN(quantity)||quantity<1){window.location.reload();}else{url='https://www.lightology.com/index.php?module=dispatcher';data='action=update_order_line_quantity&id='+prod_id+'&quantity='+quantity;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){$('#order_line_quantity_'+prod_id).val(data.quantity);$('#line_total_'+prod_id).html(data.line_total);remove_displayed_discounts(data.removed_codes);update_cart_page(data);$('.mini-row-container').html(data.minicart);}}});}} let async_supported=false;function cart_events_router(){$('body').on('click','.add_acc_to_cart',function(e){e.preventDefault();let prodId=$(this).data().prodId;handle_add_accessory_to_cart_click(prodId);}).on('click','#add_more_com_plus',function(){$('.add_more_com').toggle();}).on('click','.address_select_item',function(){handle_address_select_item_click($(this));}).on('keyup','#cart_promo',function(event){let key=event.which;handle_cart_promo_keyup(key);}).on('click','.cart_prod_remove',function(event){event.preventDefault();remove_order_line($(this));}).on('click','#cart_promo_apply',function(event){event.preventDefault();apply_discount();}).on('change','#cart_shipping_country',function(){handle_cart_shipping_country_change();}).on('change','#cart_shipping_option',function(){handle_cart_shipping_option_change();}).on('change','#cart_shipping_state',function(){handle_cart_shipping_state_change();}).on('change','#cart_shipping_zip',function(){handle_cart_shipping_zip_change();}).on('keypress','#cc_number',function(event){handle_cart_cc_number_key(event);}).on('change','#checkout_billing_country',function(){handle_checkout_billing_country_change();}).on('change','#checkout_billing_state',function(){handle_checkout_billing_state_change();}).on('click','#checkout_next_step',function(){handle_checkout_next_step();}).on('click','#checkout_ship_to_bill',function(){handle_checkout_ship_to_bill_change($(this));}).on('change','#checkout_shipping_country',function(){handle_checkout_shipping_country_change();}).on('change','#checkout_shipping_option',function(){handle_checkout_shipping_option_change();}).on('change','#checkout_shipping_state',function(){handle_checkout_shipping_state_change();}).on('submit','#confirm_form',function(){display_submit_order_spinner();}).on('change','.order_line_quantity',function(event){event.preventDefault();update_order_line_quantity($(this));}).on('click','.remove_discount',function(event){event.preventDefault();remove_discount($(this));}).on('keydown','#save_address_form',function(event){let key=event.which;if(key==13){event.preventDefault();return false;}}).on('click','#save_this_billing_address',function(){handle_save_customer_address_click('billing_');}).on('click','#save_this_shipping_address',function(){handle_save_customer_address_click('shipping_');}).on('click','#select_another_billing_address',function(){handle_select_another_address_click('Billing');}).on('click','#select_another_shipping_address',function(){handle_select_another_address_click('Shipping');}).on('submit','form[name="shipping_estimator_form"]',function(event){event.preventDefault();})} $(function(){async_supported=detect_async_support();$('#cart_promo').val('');cart_events_router();});;const MODAL_ACCOUNT_SETTINGS=10;const MODAL_ADD_ADDRESS=20;const MODAL_ADD_PROJECT_OPTION=150;const MODAL_ADD_PROJECT_ROOM=30;const MODAL_CHANGE_PASSWORD=40;const MODAL_CONFIRMATION=50;const MODAL_COPY_PROJECT=60;const MODAL_EDIT_ADDRESS=80;const MODAL_EDIT_NON_STOCK_ITEM=140;const MODAL_EDIT_PROJECT=90;const MODAL_EDIT_TRADE_REQUEST=160;const MODAL_EMAIL_PROJECT=100;const MODAL_RENAME_PROJECT_ROOM=110;const MODAL_TAX_EXEMPTION=120;const MODAL_XFER_PROJECT_ITEMS=130;const TOOL_NONE=0;const TOOL_ADD_CUSTOMER=10;const TOOL_EDIT_CUSTOMER=20;const TOOL_CART_ACTIVITY=25;const TOOL_FIND_CUSTOMER=30;const TOOL_FIND_PRODUCT=40;const TOOL_FIND_PROJECT=45;const TOOL_FIND_WISHLIST=50;const TOOL_RESOURCES=60;const TOOL_SALES_TAX_RATE=70;const TOOL_VIEW_CART=75;const TOOL_VIRTUAL_INVENTORY=80;const SEND_PROJECT_EMAIL=1;const PREVIEW_PROJECT_EMAIL=2;var spinner_img=$('');var ajax_call_in_progress=false;var ajax_call_button_text='Working...';var ajax_call_error_text='System Error';var tool_add_customer_height=0;var tool_cart_activity_height=0;var tool_edit_customer_height=0;var tool_find_customer_height=0;var tool_find_product_height=0;var tool_find_project_height=0;var tool_find_wishlist_height=0;var tool_sales_tax_rate_height=0;var selected_tool=TOOL_NONE;var modal_email_project_height=0;var modal_email_project_height_adder1=0;var modal_email_project_height_adder2=0;var modal_email_project_height_adder3=0;var modal_xfer_project_items_height=300;let selected_project_files=[];let selected_project_items=[];function create_customer_address(address_changed,addr_validated,addr_residential,address_1,address_2,city,zip,state_id,country_id,extra_values) {let url='https://www.lightology.com/index.php?module=dispatcher';let prefix=extra_values['prefix'];let data='action=create_customer_address'+'&user_type='+extra_values['user_type']+'&addr_type='+extra_values['addr_type']+'&addr_parent_type='+extra_values['addr_parent_type']+'&addr_parent_id='+extra_values['addr_parent_id']+'&label='+encodeURIComponent(extra_values[prefix+'label'])+'&first_name='+encodeURIComponent(extra_values[prefix+'first_name'])+'&last_name='+encodeURIComponent(extra_values[prefix+'last_name'])+'&company_name='+encodeURIComponent(extra_values[prefix+'company_name'])+'&address_1='+encodeURIComponent(address_1)+'&address_2='+encodeURIComponent(address_2)+'&city='+encodeURIComponent(city)+'&zip='+zip+'&state_id='+state_id+'&country_id='+country_id+'&addr_validated='+addr_validated+'&addr_residential='+addr_residential+'&prefix='+prefix;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data&&data.html){if(extra_values.hasOwnProperty('user_type')){if(extra_values['user_type']==='user'){$('#addresses_panel .panel-wrap').html(data.html);}else if(extra_values['user_type']==='cust'){$('#edit_customer_address_book').html(data.html);}}else{$('.address_list').append(data.html);}}},error:function(){}});} function create_customer(address_changed,addr_validated,addr_residential,address_1,address_2,city,zip,state_id,country_id,extra_values) {let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=create_customer'+'&cust_account_type='+extra_values['cust_account_type']+'&cust_first_name='+encodeURIComponent(extra_values['cust_first_name'])+'&cust_last_name='+encodeURIComponent(extra_values['cust_last_name'])+'&price_code='+extra_values['price_code']+'&cust_company_name='+encodeURIComponent(extra_values['cust_company_name'])+'&occupation='+extra_values['occupation']+'&cust_address_1='+encodeURIComponent(address_1)+'&cust_address_2='+encodeURIComponent(address_2)+'&cust_city='+encodeURIComponent(city)+'&cust_state_id='+state_id+'&cust_zip='+zip+'&cust_country_id='+country_id+'&addr_validated='+addr_validated+'&addr_residential='+addr_residential+'&cust_phone='+extra_values['cust_phone']+'&cust_phone_mobile='+extra_values['cust_phone_mobile']+'&cust_phone_other='+extra_values['cust_phone_other']+'&cust_phone_fax='+extra_values['cust_phone_fax']+'&cust_email='+encodeURIComponent(extra_values['cust_email'])+'&sales_rep_id='+extra_values['sales_rep_id']+'&cust_contact_ok='+extra_values['cust_contact_ok']+'&send_email='+extra_values['send_email']+'&include_100_off='+extra_values['include_100_off']+'&order_catalogs='+extra_values['order_catalogs']+'&catalogs='+extra_values['catalogs'].join('|');if(address_changed){$('#cust_address_1').val(address_1);$('#cust_city').val(city);$('#cust_zip').val(zip);} $.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){if(data.hasOwnProperty('message')){$('.message').html(data.message);} if(data.hasOwnProperty('code')&&data.code>0){if(typeof gtag!=='undefined'){let user_name=$('#ga_user_name').text();gtag('event','new_account',{'event_category':'new_account_rep','event_label':user_name});}}}},error:function(){}});} function save_address(prefix,save_callback,$this) {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let $button=$('#submit_'+prefix+'address');let button_text=$button.text();$button.text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let form_data=$('#'+prefix+'address_form').serialize();let data='action=validate_address&'+form_data;if(!$this){$('#'+prefix+'address_form *').removeClass('err_bg');} $.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#submit_'+prefix+'address').text(button_text);let code=(typeof data.code=='string')?parseInt(data.code):data.code;switch(code){case 0:if(!$this){let modal_type=MODAL_ADD_ADDRESS;if(prefix==='edit_'){modal_type=MODAL_EDIT_ADDRESS;} set_modal_height(modal_type,data.fields.length);if(data.fields.length){for(let property in data.fields){if(data.fields.hasOwnProperty(property)){$('#'+data.fields[property]).addClass('err_bg');}}} $('#'+prefix+'address_form .message').html(data.message);} break;case 1:let extra_values=data.output;extra_values['prefix']=prefix;extra_values['token']=$('#token').val();extra_values['addr_id']=$('#addr_id').val();extra_values['addr_type']=$('#addr_type').val();extra_values['addr_parent_type']=$('#addr_parent_type').val();extra_values['addr_parent_id']=$('#addr_parent_id').val();extra_values['user_type']=$('#user_type').val();let address_1=extra_values[prefix+'address_1'];let address_2=extra_values[prefix+'address_2'];let city=extra_values[prefix+'city'];let country_id=extra_values[prefix+'country_id'];let state_id=extra_values[prefix+'state_id'];let zip=extra_values[prefix+'zip'];if(typeof state_id==='undefined'){state_id=0;} setTimeout(function(){if($this){$this.dialog('close').remove();}else{$('#'+prefix+'address_form .message').html('');$('#'+prefix+'address_modal').modal('hide');}},1500);if(async_supported){lookup_save_domestic_address('Address Selection',address_1,address_2,city,zip,state_id,country_id,extra_values,save_callback);}else{save_callback(false,0,0,address_1,address_2,city,zip,state_id,country_id,extra_values);} break;}},error:function(){ajax_call_in_progress=false;$('#submit_add_address').text(ajax_call_error_text);}});} function save_new_password($this){var url='https://www.lightology.com/index.php?module=dispatcher';var data='action=save_user_new_password';data+='&'+$('#change_password_form').serialize();$('.ui-dialog-buttonset').append(spinner_img.attr('id','spinner_change_password_form').css('margin-left','10px'));$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){$('#spinner_change_password_form').remove();$('#change_password_form .message').html(data.message);if(data.code==1){setTimeout(function(){$('#change_password_form .message').html('');$this.dialog('close').remove();},3000);}},error:function(){}});} function set_modal_height(modal,extra_lines) {let width=$(window).width() let line_height=20;let height=0;switch(modal){case MODAL_ACCOUNT_SETTINGS:let adjustment=0;let user_account_type=$('input[name="user_account_type"]:checked').val();if(user_account_type=='2'){adjustment=100;} if(width>=1367){height=340+adjustment+extra_lines*line_height;}else if(width>=480){height=560+adjustment+extra_lines*line_height;}else{height=600+adjustment+extra_lines*line_height;} $('#account_settings_inquiry').height(height);break;case MODAL_ADD_ADDRESS:if(width>=1367){height=540+extra_lines*line_height;}else{height=720+extra_lines*line_height;} $('#add_address_inquiry').height(height);break;case MODAL_EDIT_NON_STOCK_ITEM:if(width>=1367){height=780+extra_lines*line_height;}else{height=1040+extra_lines*line_height;} $('#add_non_stock_item_inquiry').height(height);break;case MODAL_ADD_PROJECT_OPTION:if(width>=450){height=140+extra_lines*line_height;}else{height=160+extra_lines*line_height;} $('#add_project_option_inquiry').height(height);break;case MODAL_ADD_PROJECT_ROOM:if(width>=450){height=140+extra_lines*line_height;}else{height=160+extra_lines*line_height;} $('#add_project_room_inquiry').height(height);break;case MODAL_CHANGE_PASSWORD:if(width>=450){height=260+extra_lines*line_height;}else{height=260+extra_lines*30;} $('#change_password_inquiry').height(height);break;case MODAL_CONFIRMATION:if(width>=450){height=130;}else{height=160;} $('#confirmation_inquiry').height(height);break;case MODAL_COPY_PROJECT:if(width>=450){height=140;}else{height=160;} $('#copy_project_inquiry').height(height);break;case MODAL_EDIT_ADDRESS:if(width>=1367){height=540+extra_lines*line_height;}else{height=720+extra_lines*line_height;} $('#edit_address_inquiry').height(height);break;case MODAL_EDIT_PROJECT:if(width>=450){height=540+extra_lines*line_height;}else{height=680+extra_lines*line_height;} if($('#owner_id_fieldset').length){height+=120;} $('#edit_project_inquiry').height(height);break;case MODAL_EDIT_TRADE_REQUEST:if(width>=450){height=1170+extra_lines*line_height;}else{height=1190+extra_lines*line_height;} $('#edit_trade_request_modal_content').height(height);break;case MODAL_EMAIL_PROJECT:if(extra_lines==0){if(width>1366){modal_email_project_height=520;}else if(width>=480){modal_email_project_height=610;}else{modal_email_project_height=690;} height=modal_email_project_height+ modal_email_project_height_adder1+ modal_email_project_height_adder2+ modal_email_project_height_adder3;}else{height=modal_email_project_height+ modal_email_project_height_adder1+ modal_email_project_height_adder2+ modal_email_project_height_adder3+ extra_lines*line_height;} $('#email_project_inquiry').height(height);break;case MODAL_RENAME_PROJECT_ROOM:if(width>=450){height=140;}else{height=160;} $('#rename_project_room_inquiry').height(height);break;case MODAL_TAX_EXEMPTION:if(width>=480){height=160;}else if(width>=424){height=180;}else if(width>=332){height=200;}else{height=220;} $('#tax_exemption_inquiry').height(height);break;case MODAL_XFER_PROJECT_ITEMS:if(width>=450){height=modal_xfer_project_items_height+extra_lines*line_height;}else{height=modal_xfer_project_items_height+20+extra_lines*line_height;} $('#xfer_project_items_inquiry').height(height);break;}} function set_tool_height(tool,extra_lines) {selected_tool=tool;let width=$(window).width() let line_height=20;let height=0;switch(tool){case TOOL_ADD_CUSTOMER:if(extra_lines===0){if(width>=1367){tool_add_customer_height=1040;}else if(width>=877){tool_add_customer_height=1380;}else if(width>=769){tool_add_customer_height=1460;}else if(width>=612){tool_add_customer_height=1660;}else if(width>=364){tool_add_customer_height=1720;}else{tool_add_customer_height=1800;} height=tool_add_customer_height;}else{height=tool_add_customer_height+extra_lines*line_height;} break;case TOOL_CART_ACTIVITY:if(extra_lines===0){if(width>=769){tool_cart_activity_height=280;}else{tool_cart_activity_height=320;} height=tool_cart_activity_height;}else{height=tool_cart_activity_height+extra_lines*line_height;} break;case TOOL_EDIT_CUSTOMER:if(extra_lines===0){if(width>=1367){tool_edit_customer_height=1020;}else if(width>=769){tool_edit_customer_height=1420;}else{tool_edit_customer_height=1840;} height=tool_edit_customer_height;}else{height=tool_edit_customer_height+extra_lines*line_height;} break;case TOOL_FIND_CUSTOMER:if(extra_lines===0){if(width>=1350){tool_find_customer_height=430;}else if(width>=769){tool_find_customer_height=580;}else{tool_find_customer_height=570;} height=tool_find_customer_height;}else{height=tool_find_customer_height+extra_lines*line_height;} break;case TOOL_FIND_PRODUCT:if(extra_lines===0){if(width>=769){tool_find_product_height=330;}else{tool_find_product_height=370;} height=tool_find_product_height;}else{height=tool_find_product_height+extra_lines*line_height;} break;case TOOL_FIND_PROJECT:if(extra_lines===0){if(width>=769){tool_find_project_height=300;}else{tool_find_project_height=340;} height=tool_find_project_height;}else{height=tool_find_project_height+extra_lines*line_height;} break;case TOOL_FIND_WISHLIST:if(extra_lines===0){if(width>=769){tool_find_wishlist_height=260;}else{tool_find_wishlist_height=300;} height=tool_find_wishlist_height;}else{height=tool_find_wishlist_height+extra_lines*line_height;} break;case TOOL_RESOURCES:if(width>=1326){height=3160;}else{height=3600;} break;case TOOL_SALES_TAX_RATE:if(extra_lines===0){if(width>=769){tool_sales_tax_rate_height=520;}else{tool_sales_tax_rate_height=640;} height=tool_sales_tax_rate_height;}else{height=tool_sales_tax_rate_height+extra_lines*line_height;} break;case TOOL_VIRTUAL_INVENTORY:if(width>=769){height=400;}else{height=540;} break;case TOOL_VIEW_CART:if(width>=769){height=260+extra_lines*line_height;}else{height=380+extra_lines*line_height;} break;} $('#static-display-form').height(height);$('#form-single-tools').height(height);} function show_dialog(content) {$('#quickview_box').append(content);$('#quickview_box').dialog({height:'auto',width:'auto',modal:true,show:{effect:'fade',duration:800},close:function(){$('#quickview_box').remove();$('body').append('
');}});} function update_customer_address(address_changed,addr_validated,addr_residential,address_1,address_2,city,zip,state_id,country_id,extra_values) {let prefix=extra_values['prefix'];let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=update_customer_address'+'&addr_id='+extra_values['addr_id']+'&user_type='+extra_values['user_type']+'&addr_type='+extra_values['addr_type']+'&addr_parent_id='+extra_values['addr_parent_id']+'&addr_parent_type='+extra_values['addr_parent_type']+'&label='+encodeURIComponent(extra_values[prefix+'label'])+'&first_name='+encodeURIComponent(extra_values[prefix+'first_name'])+'&last_name='+encodeURIComponent(extra_values[prefix+'last_name'])+'&company_name='+encodeURIComponent(extra_values[prefix+'company_name'])+'&address_1='+encodeURIComponent(address_1)+'&address_2='+encodeURIComponent(address_2)+'&city='+encodeURIComponent(city)+'&zip='+zip+'&state_id='+state_id+'&country_id='+country_id+'&addr_validated='+addr_validated+'&addr_residential='+addr_residential+'&prefix='+prefix;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data&&data.html){if(extra_values['user_type']=='user'){$('#addresses_panel .panel-wrap').html(data.html);}else if(extra_values['user_type']=='cust'){$('#edit_customer_address_book').html(data.html);}}},error:function(){}});} function update_customer(output) {let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=update_customer'+'&cust_nxt_id='+output['cust_nxt_id']+'&cust_account_type='+output['cust_account_type']+'&cust_email='+encodeURIComponent(output['cust_email'])+'&cust_first_name='+encodeURIComponent(output['cust_first_name'])+'&cust_last_name='+encodeURIComponent(output['cust_last_name'])+'&cust_company_name='+encodeURIComponent(output['cust_company_name'])+'&cust_phone='+output['cust_phone']+'&cust_phone_mobile='+output['cust_phone_mobile']+'&cust_phone_other='+output['cust_phone_other']+'&cust_phone_fax='+output['cust_phone_fax']+'&sales_rep_id='+output['sales_rep_id']+'&sales_rep_change_reason='+encodeURIComponent(output['sales_rep_change_reason'])+'&price_code='+output['price_code']+'&occupation='+output['occupation']+'&cust_contact_ok='+output['cust_contact_ok']+'&send_email='+output['send_email']+'&include_100_off='+output['include_100_off'];$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data&&data.message){$('.cust-submit-button-div').append(data.message);$('.message').html(data.message);}},error:function(){}});} function handle_account_signin_click() {let url='https://www.lightology.com/index.php?module=dispatcher';let form_data=$('#account_signin_form').serialize();let data='action=account_signin&'+form_data;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){switch(data.code){case 0:window.location=data.redirect;break;case 1:let html='
'+'

Your account has items in carts on one or more other devices. '+'Would you like to include these items in your cart?

'+'
'+''+'
'+''+''+''+''+'
'+'
'+'
';show_dialog(html);break;case 2:$('#account_signin_form > .red_txt').html(data.message);break;}}},error:function(){}});} function handle_account_tab_click($this) {let tab_id=$this.attr('id');if(tab_id.indexOf('_button')>0){tab_id=tab_id.replace('_button','');} let panel=tab_id.split('_')[0];if(panel==='tools'){window.location='https://www.lightology.com/index.php?module=admin';return;} if(panel==='projects'){window.location='https://www.lightology.com/index.php?module=pm_home';return;} if(ajax_call_in_progress){return;} ajax_call_in_progress=true;$('.account-tabs li').removeClass('active');$('.account-panel').removeClass('active');$('#active_tool_content').html('');$('#'+tab_id).parent().addClass('active');$('#'+panel+'_panel').addClass('active');let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=set_user_active_tab&active_tab='+panel;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(){ajax_call_in_progress=false;},error:function(){ajax_call_in_progress=false;}});} function handle_add_address_click($this) {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;if($('#add_address_modal').length){$('#add_address_modal').remove();} if($('#edit_address_modal').length){$('#edit_address_modal').remove();} let url='https://www.lightology.com/index.php?module=dispatcher';let user_type=$this.data('userType');let cust_id=$this.attr('id').replace('cust_id_','');let data='action=build_add_customer_address_dialog&addr_type=0&addr_parent_type=0&addr_parent_id='+cust_id+'&user_type='+user_type;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){ajax_call_in_progress=false;if($('#account-layout').length){$('#account-layout').append(data);}else if($('.admin_tools').length){$('.admin_tools').append(data);} $('#add_address_modal').modal();set_modal_height(MODAL_ADD_ADDRESS,0);}},error:function(){ajax_call_in_progress=false;$('#add_address').text(ajax_call_error_text);}});} function handle_address_country_change() {let url='https://www.lightology.com/index.php?module=dispatcher';let country_id=parseInt($('#address_country_id').val(),10);let data='action=address_country_change&country_id='+country_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){let $address_state_div=$('#address_state_div');let $address_state_id=$('#address_state_id');$address_state_id.find('option').remove();if(data.length){$address_state_div.show();$address_state_id.append(data);}else{$address_state_div.hide();}},error:function(){}});} function handle_address_default_click($this,$type) {let checked=$this.is(':checked');if(!checked){$this.prop('checked',true);} else{let url='https://www.lightology.com/index.php?module=dispatcher';let user_type=$this.data('userType');let addr_type_bit=($type==='bill')?'1':'2';let addr_id=$this.attr('id').replace($type+'_id_','');let data='action=set_customer_addr_type_bit&addr_id='+addr_id+'&addr_type_bit='+addr_type_bit+'&exclusive=1&user_type='+user_type;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){if(data.html){if(user_type=='user'){$('#addresses_panel .panel-wrap').html(data.html);}else if(user_type=='cust'){$('#edit_customer_address_book').html(data.html);}}else if(!data.set){window.location.reload();}}},error:function(){}});}} function handle_back_to_dashboard_click() {$('.account-panel').removeClass('active');$('#dashboard_panel').addClass('active');let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=set_user_active_tab&active_tab=dashboard';$.ajax({type:'POST',url:url,data:data,dataType:'json'});} function handle_change_password_redesign_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#change_password_redesign').text();$('#change_password_redesign').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=build_change_password_dialog_redesign';$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#change_password_redesign').text(button_text);if(data){if($('#change_password_modal').length){$('#change_password_modal').replaceWith(data);} else{$('#account-layout').append(data);} $('#change_password_modal').modal();set_modal_height(MODAL_CHANGE_PASSWORD,0);if(typeof acsbJS!=='undefined'){acsbJS.restart();}}},error:function(){ajax_call_in_progress=false;$('#change_password_redesign').text(ajax_call_error_text);}});} function handle_create_customer_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;const fields={catalogs:{multiselect_checkbox:true},cust_account_type:{checkbox:true},cust_address_1:{},cust_address_2:{},cust_city:{},cust_company_name:{},cust_contact_ok:{checkbox:true},cust_country_id:{select_dropdown:true},cust_email:{},cust_first_name:{},cust_last_name:{},cust_phone:{},cust_phone_fax:{},cust_phone_mobile:{},cust_phone_other:{},cust_state_id:{select_dropdown:true},cust_zip:{},include_100_off:{checkbox:true},occupation:{select_dropdown:true},order_catalogs:{checkbox:true},price_code:{select_dropdown:true},sales_rep_id:{select_dropdown:true},send_email:{checkbox:true}};let $message=$('.message');$message.html('');let $create_customer=$('#create_customer');let button_text=$create_customer.text();$create_customer.text(ajax_call_button_text);$('#add_new_customer_form *').removeClass('err_bg');let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=validate_create_customer';for(let field in fields){if(fields[field].hasOwnProperty('multiselect_checkbox')){let values=[];$.each($('input[name="'+field+'"]:checked'),function(){values.push($(this).val());});data+='&'+field+'='+values.join('|');}else if(fields[field].hasOwnProperty('checkbox')){data+='&'+field+'='+$('input[name="'+field+'"]:checked').val();}else if(fields[field].hasOwnProperty('select_dropdown')){data+='&'+field+'='+$('select[name="'+field+'"] option:selected').val();}else{data+='&'+field+'='+encodeURIComponent($('input[name="'+field+'"]').val());}} $.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$create_customer.text(button_text);if(data.hasOwnProperty('code')){let code=(typeof data.code=='string')?parseInt(data.code):data.code;switch(code){case 0:if(data.hasOwnProperty('message')){$message.html(data.message);} if(data.hasOwnProperty('fields')&&data.fields.length>0){set_tool_height(TOOL_ADD_CUSTOMER,data.fields.length);for(let property in data.fields){if(data.fields.hasOwnProperty(property)){$('#'+data.fields[property]).addClass('err_bg');}}} break;case 1:let extra_values=data.output;extra_values['token']=$('#token').val();let address_1=extra_values['cust_address_1'];let address_2=extra_values['cust_address_2'];let city=extra_values['cust_city'];let country_id=extra_values['cust_country_id'];let state_id=extra_values['cust_state_id'];let zip=extra_values['cust_zip'];if(typeof state_id==='undefined'){state_id=0;} if(async_supported){lookup_save_domestic_address('Customer Address Selection',address_1,address_2,city,zip,state_id,country_id,extra_values,create_customer);}else{create_customer(false,0,0,address_1,address_2,city,zip,state_id,country_id,extra_values);} break;}}},error:function(){ajax_call_in_progress=false;$create_customer.text(ajax_call_error_text);}});} function handle_cust_account_type_change($this) {let height=$('#static-display-form').height();if($this.val()=='2'){$('#company_name_div, #cust_phone_fax_div').show();height+=60;if($('#create_customer').is(':visible')){tool_add_customer_height+=60;}}else{$('#company_name_div, #cust_phone_fax_div').hide();height-=60;if($('#create_customer').is(':visible')){tool_add_customer_height-=60;}} $('#static-display-form').height(height);$('#form-single-tools').height(height);} function handle_cust_country_change() {var url='https://www.lightology.com/index.php?module=dispatcher';var country_id=parseInt($('#cust_country_id').val(),10);var data='action=cust_country_change&country_id='+country_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){var $cust_state=$('#cust_state');var $cust_state_id=$('#cust_state_id');$cust_state_id.find('option').remove();if(data.states.length){$cust_state.show();$cust_state_id.append(data.states);}else{$cust_state.hide();}}},error:function(){}});} function handle_cust_order_catalogs_change() {let $static_display_form=$('#static-display-form');let height=$static_display_form.height();let order_catalogs=$('input[name="order_catalogs"]:checked').val();if(order_catalogs>0){$('#order_catalogs_container').show();tool_add_customer_height+=420;height+=420;}else{$('#order_catalogs_container').hide();tool_add_customer_height-=420;height-=420;} $static_display_form.height(height);$('#form-single-tools').height(height);} function handle_cust_send_email_change() {let height=$('#static-display-form').height();let price_level=parseInt($('#price_code').val(),10);let send_email=$('input[name="send_email"]:checked').val();if([6,7].includes(price_level)&&send_email>0){if(!$('.include-50').is(':visible')){$('.include-50').show();height+=60;if($('#create_customer').is(':visible')){tool_add_customer_height+=60;}}}else if($('.include-50').is(':visible')){$('.include-50').hide();height-=60;if($('#create_customer').is(':visible')){tool_add_customer_height-=60;}} $('#static-display-form').height(height);$('#form-single-tools').height(height);} function handle_delete_customer_address_click($this) {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let cust_id=$this.data('custId');let user_type=$this.data('userType');let url='https://www.lightology.com/index.php?module=dispatcher';let addr_id=$this.attr('id').replace('addr_id_','');let data='action=delete_customer_address&addr_id='+addr_id+'&cust_id='+cust_id+'&user_type='+user_type;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;if(data&&data.html){if(user_type=='user'){$('#addresses_panel .panel-wrap').html(data.html);}else if(user_type=='cust'){$('#edit_customer_address_book').html(data.html);}}},error:function(){ajax_call_in_progress=false;}});} function handle_edit_account_settings_redesign_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#edit_account_settings_redesign').text();$('#edit_account_settings_redesign').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=build_account_settings_dialog_redesign';$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#edit_account_settings_redesign').text(button_text);if(data){if($('#account_settings_modal').length){$('#account_settings_modal').replaceWith(data);}else{$('#account-layout').append(data);} $('#account_settings_modal').modal();set_modal_height(MODAL_ACCOUNT_SETTINGS,0);if(typeof acsbJS!=='undefined'){acsbJS.restart();}}},error:function(){ajax_call_in_progress=false;$('#edit_account_settings_redesign').text(ajax_call_error_text);}});} function handle_edit_address_click($this) {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;if($('#add_address_modal').length){$('#add_address_modal').remove();} if($('#edit_address_modal').length){$('#edit_address_modal').remove();} let url='https://www.lightology.com/index.php?module=dispatcher';let user_type=$this.data('userType');let addr_id=$this.attr('id').replace('addr_id_','');let data='action=build_edit_address_dialog&addr_id='+addr_id+'&user_type='+user_type;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;if(data){if($('#account-layout').length){$('#account-layout').append(data);}else if($('.admin_tools').length){$('.admin_tools').append(data);} $('#edit_address_modal').modal();set_modal_height(MODAL_EDIT_ADDRESS,0);}},error:function(){ajax_call_in_progress=false;}});} function handle_edit_customer_country_change() {let url='https://www.lightology.com/index.php?module=dispatcher';let country_id=parseInt($('#edit_customer_country_id').val(),10);let data='action=address_country_change&country_id='+country_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){let $edit_customer_state_div=$('#edit_customer_state_div');let $edit_customer_state_id=$('#edit_customer_state_id');$edit_customer_state_id.find('option').remove();if(data.length){$edit_customer_state_div.show();$edit_customer_state_id.append(data);}else{$edit_customer_state_div.hide();$edit_customer_state_id.html('');}},error:function(){}});} function handle_find_customer_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let $find_customer=$('#find_customer');let button_text=$find_customer.text();$find_customer.text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let form_data=$('#find_customer_form').serialize();let data='action=find_matching_customers&'+form_data;$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$find_customer.text(button_text);$('#active_tool_content').append(data);},error:function(){ajax_call_in_progress=false;$find_customer.text(ajax_call_error_text);}});} function handle_find_customer_reset_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#find_customer_reset').text();$('#find_customer_reset').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=find_customer_reset';$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#find_customer_reset').text(button_text);$('#active_tool_content').html(data);set_tool_height(TOOL_FIND_CUSTOMER,0);},error:function(){ajax_call_in_progress=false;$('#find_customer_reset').text(ajax_call_error_text);}});} function handle_find_product_redesign_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#find_product_redesign').text();$('#find_product_redesign').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let form_data=$('#find_product_form').serialize();let data='action=find_matching_products&'+form_data;$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#find_product_redesign').text(button_text);$('#active_tool_content').append(data);},error:function(){ajax_call_in_progress=false;$('#find_product_redesign').text(ajax_call_error_text);}});} function handle_find_product_reset_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#find_product_reset').text();$('#find_product_reset').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=find_product_reset';$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#find_product_reset').text(button_text);$('#active_tool_content').html(data);set_tool_height(TOOL_FIND_PRODUCT,0);},error:function(){ajax_call_in_progress=false;$('#find_product_reset').text(ajax_call_error_text);}});} function handle_find_virtual_inventory_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#find_virtual_inventory').text();$('#find_virtual_inventory').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let form_data=$('#virtual_inventory_form').serialize();let data='action=find_virtual_inventory&'+form_data;$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#find_virtual_inventory').text(button_text);$('#active_tool_content').append(data);},error:function(){ajax_call_in_progress=false;$('#find_virtual_inventory').text(ajax_call_error_text);}});} function handle_find_virtual_inventory_reset_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#find_virtual_inventory_reset').text();$('#find_virtual_inventory_reset').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=find_virtual_inventory_reset';$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#find_virtual_inventory_reset').text(button_text);$('#active_tool_content').html(data);set_tool_height(TOOL_VIRTUAL_INVENTORY,0);},error:function(){ajax_call_in_progress=false;$('#find_virtual_inventory_reset').text(ajax_call_error_text);}});} function handle_find_wishlist_redesign_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#find_wishlist_redesign').text();$('#find_wishlist_redesign').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let form_data=$('#find_wishlist_form').serialize();let data='action=find_matching_wishlists&redesign=1&'+form_data;$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#find_wishlist_redesign').text(button_text);$('#active_tool_content').append(data);},error:function(){ajax_call_in_progress=false;$('#find_wishlist_redesign').text(ajax_call_error_text);}});} function handle_find_wishlist_reset_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#find_wishlist_reset').text();$('#find_wishlist_reset').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=find_wishlist_reset';$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#find_wishlist_reset').text(button_text);$('#active_tool_content').html(data);set_tool_height(TOOL_FIND_WISHLIST,0);},error:function(){ajax_call_in_progress=false;$('#find_wishlist_reset').text(ajax_call_error_text);}});} function handle_get_zip_sales_tax_rate_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#get_zip_sales_tax_rate').text();$('#get_zip_sales_tax_rate').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let zip=$('#sales_tax_zip').val();let data='action=get_zip_sales_tax_data&zip='+zip;$('#zip_sales_tax_data').html('');$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#get_zip_sales_tax_rate').text(button_text);$('#zip_sales_tax_data').html(data);let extra_lines=3;if(data.indexOf('tax rate data for zip code')>0){extra_lines=17;} set_tool_height(TOOL_SALES_TAX_RATE,extra_lines);},error:function(){ajax_call_in_progress=false;$('#get_zip_sales_tax_rate').text(ajax_call_error_text);}});} function handle_include_other_db_carts() {var url='https://www.lightology.com/index.php?module=dispatcher';var data='action=include_other_db_carts';$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){window.location=$('input[name="redirect"]').val();},error:function(){window.location=$('input[name="redirect"]').val();}});} function handle_load_database_cart_click() {if($('#load_database_cart').is(':checked')){$('#user_cart_id_div').show();}else{$('#user_cart_id_div').hide();}} function handle_project_select_type_change($this) {switch($this.val()){case'1':$('#new_project_room_fieldset').hide();modal_xfer_project_items_height=300;break;case'2':$('#new_project_room_fieldset').show();modal_xfer_project_items_height=360;break;} set_modal_height(MODAL_XFER_PROJECT_ITEMS,0);} function handle_reason_select_change(element) {var prod_id=element.id.substring(14);var reason=$('#'+element.id).val();if(reason=='C'){$('#restocking_fee_'+prod_id).show();}else{$('#restocking_fee_'+prod_id).hide();}} function handle_resend_order_email_button_click($this) {var url='https://www.lightology.com/index.php?module=dispatcher';var form_data=$('#resend_order_email_form').serialize();var data='action=resend_order_email&'+form_data;$('#results').html('');var spinner=$('    Sending...');var $td=$this.closest('td');var $button=$this.detach();$td.prepend(spinner);$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){$td.find('span').replaceWith($button);$('#results').html(data);}});} function handle_reset_find_project_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#reset_find_project').text();$('#reset_find_project').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=reset_find_project';$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#reset_find_project').text(button_text);$('#active_tool_content').html(data);set_tool_height(TOOL_FIND_PROJECT,0);},error:function(){ajax_call_in_progress=false;$('#reset_find_project').text(ajax_call_error_text);}});} function handle_sales_tax_state_change() {let url='https://www.lightology.com/index.php?module=dispatcher';let state_id=parseInt($('#sales_tax_state').val(),10);let data='action=sales_tax_state_change&state_id='+state_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){if(data.sales_tax_rate){$('#state_sales_tax_rate').val(data.sales_tax_rate);}else{$('#state_sales_tax_rate').val('System Error');}}},error:function(){$('#state_sales_tax_rate').val('System Error');}});} function handle_spec_sheet_show_sku_click($this) {let prod_id=$this.attr('id').replace('show_sku_','');let $link=$('a#spec_sheet_link_'+prod_id);let href=$link.attr('href');if($this.prop('checked')){$link.attr('href',href+'&show_sku=1');}else{$link.attr('href',href.replace(/&show_sku=[0-9]+/g,''));}} function handle_start_customer_emulation_click(element) {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let cust_id=0;let cart_id=0;let wishlist_id=0;let element_id=element.id let return_module='';if(typeof element_id==='string'&&element_id.indexOf('db_cart_')===0){cart_id=parseInt(element_id.substring(8));} else if(typeof element_id==='string'&&element_id.indexOf('wishlist_id_')===0){wishlist_id=parseInt(element_id.substring(12));return_module='admin_find_cust';} else if(typeof element_id==='string'&&element_id.indexOf('matching_wishlist_id_')===0){wishlist_id=parseInt(element_id.substring(21));cust_id=$(element).data('custId');return_module='admin_find_wish';} let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=start_customer_emulation&cust_id='+cust_id+'&cart_id='+cart_id;if(return_module.length>0){data=data+'&return_module='+return_module;} $.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {ajax_call_in_progress=false;if(data){if(data.code==1){if(wishlist_id>0){window.location='https://www.lightology.com/index.php?module=wishlist&wishlist_id='+wishlist_id;}else{window.location='https://www.lightology.com/index.php?module=cust';}}}},error:function(){ajax_call_in_progress=false;}});} function handle_submit_account_settings_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#submit_account_settings').text();$('#submit_account_settings').text(ajax_call_button_text);$('#account_settings_form *').removeClass('err_bg');let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=save_user_account_settings_redesign';data+='&'+$('#account_settings_form').serialize();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#submit_account_settings').text(button_text);$('#account_settings_form .message').html(data.message);let code=(typeof data.code=='string')?parseInt(data.code):data.code;switch(code){case 0:if(data.fields.length){set_modal_height(MODAL_ACCOUNT_SETTINGS,data.fields.length);for(let property in data.fields){if(data.fields.hasOwnProperty(property)){$('#'+data.fields[property]).addClass('err_bg');}}} break;case 1:$('#user_account_settings').replaceWith(data.html);setTimeout(function(){$('#account_settings_form .message').html('');$('#account_settings_modal').modal('hide');},1500);break;}},error:function(){ajax_call_in_progress=false;$('#submit_account_settings').text(ajax_call_error_text);}});} function handle_submit_change_password_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#submit_change_password').text();$('#submit_change_password').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=save_user_new_password';data+='&'+$('#change_password_form').serialize();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#submit_change_password').text(button_text);$('#change_password_form .message').html(data.message);set_modal_height(MODAL_CHANGE_PASSWORD,2) if(data.code==1){setTimeout(function(){$('#change_password_form .message').html('');$('#change_password_modal').modal('hide');},3000);}},error:function(){ajax_call_in_progress=false;$('#submit_change_password').text(ajax_call_error_text);}});} function handle_submit_find_project_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#submit_find_project').text();$('#submit_find_project').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let form_data=$('#find_project_form').serialize();let profile_page='';if($('.profile_page').length){profile_page='&profile_page';} let data='action=find_matching_projects&'+form_data+profile_page;$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#submit_find_project').text(button_text);if(data){if(data.html){$('#active_tool_content').append(data.html);} if(data.profile){$('.profile_page').replaceWith(data.profile);}}},error:function(){ajax_call_in_progress=false;$('#submit_find_project').text(ajax_call_error_text);}});} function handle_tax_exemption_click() {if($('#tax_exemption_modal').length){$('#tax_exemption_modal').modal();} else{if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#tax_exemption_dialog').text();$('#tax_exemption_dialog').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=build_tax_exemption_dialog';$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){ajax_call_in_progress=false;$('#tax_exemption_dialog').text(button_text);$('#account-layout').append(data);$('#tax_exemption_modal').modal();set_modal_height(MODAL_TAX_EXEMPTION,0);}},error:function(){ajax_call_in_progress=false;$('#tax_exemption_dialog').text(ajax_call_error_text);}});}} function handle_tool_window_resize() {if(selected_tool!==TOOL_NONE){set_tool_height(selected_tool,0);}} function handle_update_customer_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;const fields={catalogs:{multiselect_checkbox:true},cust_account_type:{checkbox:true},cust_company_name:{},cust_contact_ok:{checkbox:true},cust_email:{},cust_first_name:{},cust_last_name:{},cust_nxt_id:{},cust_phone:{},cust_phone_fax:{},cust_phone_mobile:{},cust_phone_other:{},include_100_off:{checkbox:true},occupation:{select_dropdown:true},order_catalogs:{checkbox:true},price_code:{select_dropdown:true},sales_rep_change_reason:{textarea:true},sales_rep_id:{select_dropdown:true},send_email:{checkbox:true}};$('.message').html('');let $update_customer=$('#update_customer');let button_text=$update_customer.text();$update_customer.text(ajax_call_button_text);$('#edit_customer_form *').removeClass('err_bg');let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=update_customer';for(let field in fields){if(fields[field].hasOwnProperty('multiselect_checkbox')){let values=[];$.each($('input[name="'+field+'"]:checked'),function(){values.push($(this).val());});data+='&'+field+'='+values.join('|');}else if(fields[field].hasOwnProperty('checkbox')){data+='&'+field+'='+$('input[name="'+field+'"]:checked').val();}else if(fields[field].hasOwnProperty('select_dropdown')){data+='&'+field+'='+$('select[name="'+field+'"] option:selected').val();}else if(fields[field].hasOwnProperty('textarea')){data+='&'+field+'='+encodeURIComponent($('textarea[name="'+field+'"]').val());}else{data+='&'+field+'='+encodeURIComponent($('input[name="'+field+'"]').val());}} $.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$update_customer.text(button_text);if(data.hasOwnProperty('message')){$('.message').html(data.message);} if(data.hasOwnProperty('code')){let code=(typeof data.code=='string')?parseInt(data.code):data.code;if(code<1&&data.hasOwnProperty('fields')){if(data.fields.length>0){set_modal_height(TOOL_EDIT_CUSTOMER,data.fields.length);for(let property in data.fields){if(data.fields.hasOwnProperty(property)){$('#'+data.fields[property]).addClass('err_bg');}}}}}},error:function(){ajax_call_in_progress=false;$('#update_customer').text(ajax_call_error_text);}});} function handle_update_salesrep_click() {var url='https://www.lightology.com/index.php?module=dispatcher';var salesrep_id=parseInt($('#sales_rep_id').val(),10);var data='action=update_salesrep&salesrep_id='+salesrep_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){window.location.reload();},error:function(){}});} function handle_user_account_type_change($this) {let height=$('#account_settings_inquiry').height();if($this.val()=='2'){$('#company_name_div, #company_website_div, #company_occupation_div').show();height+=100;}else{$('#company_name_div, #company_website_div, #company_occupation_div').hide();height-=100;} $('#account_settings_inquiry').height(height);} function handle_user_country_change() {let url='https://www.lightology.com/index.php?module=dispatcher';let country_id=parseInt($('#user_country_id').val(),10);let data='action=address_country_change&country_id='+country_id;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){let $user_state=$('#user_state');let $user_state_id=$('#user_state_id');$user_state_id.find('option').remove();if(data.length){$user_state.show();$user_state_id.append(data);}else{$user_state.hide();}},error:function(){}});} function handle_user_has_salesrep_click() {if($('#user_has_salesrep').is(':checked')){$('#user_salesrep_id').show();}else{$('#user_salesrep_id').hide();}} function handle_view_cart_activity_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let $view_cart_activity=$('#view_cart_activity');let button_text=$view_cart_activity.text();$view_cart_activity.text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let cart_activity_arg=$('#cart_activity_arg').val();let data='action=view_cart_activity&cart_activity_arg='+cart_activity_arg;$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$view_cart_activity.text(button_text);$('#active_tool_content').append(data);},error:function(){ajax_call_in_progress=false;$('#view_cart_activity').text(ajax_call_error_text);}});} function handle_view_cart_button_click() {if(ajax_call_in_progress){return;} ajax_call_in_progress=true;let button_text=$('#view_cart').text();$('#view_cart').text(ajax_call_button_text);let url='https://www.lightology.com/index.php?module=dispatcher';let form_data=$('#view_cart_form').serialize();let data='action=view_cart&'+form_data;$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){ajax_call_in_progress=false;$('#view_cart').text(button_text);$('#active_tool_content').append(data);},error:function(){ajax_call_in_progress=false;$('#view_cart').text(ajax_call_error_text);}});} function handle_view_order_details_click($this) {let url='https://www.lightology.com/index.php?module=dispatcher';let cust_type=$this.data('custType');let nxtrend_order_id=$this.data('nxtrendOrderId');let data='action=build_order_details_html&nxtrend_order_id='+nxtrend_order_id+'&cust_type='+cust_type;if($this.hasClass('expanded')){$('#order_details_'+nxtrend_order_id).remove();$this.find('.expand_button').html('');$this.removeClass('expanded');} else{$this.find('.expand_button').html('');$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){$this.find('.expand_button').html('');if(data.code===1){$this.closest('div').after(data.html);}}});$this.addClass('expanded');}} function handle_virtual_inventory_page_click($this) {let url='https://www.lightology.com/index.php?module=dispatcher';let page=$this.attr('id').replace('page_','');let form_data=$('#virtual_inventory_form').serialize();let data='action=find_virtual_inventory&'+form_data+'&page='+page;$('#tool_results').remove();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){$('#active_tool_content').append(data);}});} $(function(){$(window).on('scroll',function(){let scrollTop=$(window).scrollTop();if(scrollTop>50){$('.project_files_action_bar').stop().css("padding","12px 20px 15px");$('.project_action_bar').stop().css("padding","12px 20px 15px");$('.scroll-fx').stop().css("height","25px");} else{$('.project_files_action_bar').stop().css("padding","50px 20px");$('.project_action_bar').stop().css("padding","50px 20px");$('.scroll-fx').stop().css("height","50px");}});$('body').on('click','#account_logout_link',function(event){event.preventDefault();handle_logout_link_click($(this));}).on('click','#account_signin',function(event){event.preventDefault();handle_account_signin_click();}).on('click','.account-tabs li a, .account_tab_button',function(){handle_account_tab_click($(this));}).on('click','.add-address',function(){handle_add_address_click($(this));}).on('click','.address_bill',function(){handle_address_default_click($(this),'bill');}).on('change','#address_country_id',function(){handle_address_country_change();}).on('change','#edit_customer_country_id',function(){handle_edit_customer_country_change();}).on('click','.address_ship',function(){handle_address_default_click($(this),'ship');}).on('click','#back_to_dashboard',function(){handle_back_to_dashboard_click()}).on('click','#cancel_account_settings',function(event){event.preventDefault();$('#account_settings_modal').modal('hide');}).on('click','#cancel_add_address',function(event){event.preventDefault();$('#add_address_modal').modal('hide');}).on('click','#cancel_add_non_stock_item',function(event){event.preventDefault();$('#edit_non_stock_item_modal').modal('hide');}).on('click','#cancel_add_project_option',function(event){event.preventDefault();$('#add_project_option_modal').modal('hide');}).on('click','#cancel_add_project_room',function(event){event.preventDefault();$('#add_project_room_modal').modal('hide');}).on('click','#cancel_change_password',function(event){event.preventDefault();$('#change_password_modal').modal('hide');}).on('click','#cancel_copy_project',function(event){event.preventDefault();$('#copy_project_modal').modal('hide');}).on('click','#cancel_edit_address',function(event){event.preventDefault();$('#edit_address_modal').modal('hide');}).on('click','#cancel_edit_project',function(event){event.preventDefault();$('#edit_project_modal').modal('hide');}).on('click','#cancel_edit_trade_request',function(event){event.preventDefault();$('#edit_trade_request_modal').modal('hide');}).on('click','#cancel_remove_project',function(event){event.preventDefault();$('#confirmation_modal').modal('hide');}).on('click','#cancel_remove_project_item',function(event){event.preventDefault();$('#confirmation_modal').modal('hide');}).on('click','#cancel_remove_project_room',function(event){event.preventDefault();$('#confirmation_modal').modal('hide');}).on('click','#cancel_rename_project_room',function(event){event.preventDefault();$('#rename_project_room_modal').modal('hide');}).on('click','#cancel_tax_exemption',function(event){event.preventDefault();$('#tax_exemption_modal').modal('hide');}).on('click','#cancel_update_non_stock_item',function(event){event.preventDefault();$('#edit_non_stock_item_modal').modal('hide');}).on('click','#cancel_xfer_project_items',function(event){event.preventDefault();$('#xfer_project_items_modal').modal('hide');}).on('click','#change_password_redesign',function(){handle_change_password_redesign_click();}).on('click','#create_account_show_password > input',function(){var field_type=$('#user_password').attr('type');if(field_type==='password'){$('#user_password, #user_password_confirm').attr('type','text');}else{$('#user_password, #user_password_confirm').attr('type','password');}}).on('click','#create_customer',function(event){event.preventDefault();handle_create_customer_button_click();}).on('change','input[type=radio][name=cust_account_type]',function(){handle_cust_account_type_change($(this));}).on('change','#cust_country_id',function(){handle_cust_country_change();}).on('click','#cust_got_consultant',function(){if($(this).prop('checked')){$('#cust_slsrep').prop('disabled',false);}else{$('#cust_slsrep').prop('disabled',true);}}).on('click','#cust_talk_consultant',function(){if($(this).prop('checked')){$('#cust_contact_info').prop('disabled',false);}else{$('#cust_contact_info').prop('disabled',true);}}).on('click','.delete_customer_address',function(){handle_delete_customer_address_click($(this));}).on('click','#edit_account_settings_redesign',function(){handle_edit_account_settings_redesign_click();}).on('click','.edit_address_redesign',function(){handle_edit_address_click($(this));}).on('click','#find_customer',function(event){event.preventDefault();handle_find_customer_button_click();}).on('keypress','#find_customer_form',function(event){let key=event.which;if(key==13){event.preventDefault();handle_find_customer_button_click();}}).on('click','#find_customer_reset',function(event){event.preventDefault();handle_find_customer_reset_button_click();}).on('keypress','#find_product_form',function(event){let key=event.which;if(key==13){event.preventDefault();handle_find_product_redesign_button_click();}}).on('click','#find_product_redesign',function(event){event.preventDefault();handle_find_product_redesign_button_click();}).on('click','#find_product_reset',function(event){event.preventDefault();handle_find_product_reset_button_click();}).on('keypress','#find_project_form',function(event){let key=event.which;if(key==13){event.preventDefault();handle_submit_find_project_click();}}).on('click','#find_virtual_inventory',function(event){event.preventDefault();handle_find_virtual_inventory_button_click();}).on('click','#find_virtual_inventory_reset',function(event){event.preventDefault();handle_find_virtual_inventory_reset_button_click();}).on('keypress','#find_wishlist_form',function(event){let key=event.which;if(key==13){event.preventDefault();handle_find_wishlist_redesign_button_click();}}).on('click','#find_wishlist_redesign',function(event){event.preventDefault();handle_find_wishlist_redesign_button_click();}).on('click','#find_wishlist_reset',function(event){event.preventDefault();handle_find_wishlist_reset_button_click();}).on('click','#get_zip_sales_tax_rate',function(){handle_get_zip_sales_tax_rate_click();}).on('click','input[name="include_carts_no"]',function(event){event.preventDefault();window.location=$('input[name="redirect"]').val();}).on('click','input[name="include_carts_yes"]',function(event){event.preventDefault();handle_include_other_db_carts();}).on('change','#load_database_cart',function(){handle_load_database_cart_click();}).on('change','#price_code',function(){handle_cust_send_email_change();}).on('click','#project_owner_find',function(event){event.preventDefault();handle_project_owner_name_change();}).on('click','#project_owner_reset',function(event){event.preventDefault();window.location='https://www.lightology.com/index.php?module=pm_home';}).on('change','input[type=radio][name=project_select]',function(){handle_project_select_type_change($(this));}).on('change','.reason_select',function(){handle_reason_select_change(this);}).on('click','#resend_order_email',function(event){event.preventDefault();handle_resend_order_email_button_click($(this));}).on('click','#reset_find_project',function(event){event.preventDefault();handle_reset_find_project_button_click();}).on('change','#sales_rep_id',function(){if($('#edit_customer_form').length){$('#sales_rep_change_reason_div').show();let height=$('#static-display-form').height();height+=160;$('#static-display-form').height(height);$('#form-single-tools').height(height);}}).on('change','#sales_tax_state',function(){handle_sales_tax_state_change();}).on('change','input[name="order_catalogs"]',function(){handle_cust_order_catalogs_change();}).on('change','input[name="send_email"]',function(){handle_cust_send_email_change();}).on('click','.spec_sheet_show_sku',function(){handle_spec_sheet_show_sku_click($(this));}).on('click','#start_customer_emulation, .emulate_customer_cart, '+'.account_wishlist_name, .matching_wishlist_name',function(event) {event.preventDefault();handle_start_customer_emulation_click(this);}).on('click','#submit_account_settings',function(event){event.preventDefault();handle_submit_account_settings_click();}).on('click','#submit_add_address',function(event){event.preventDefault();save_address('add_',create_customer_address,null);}).on('click','#submit_change_password',function(event){event.preventDefault();handle_submit_change_password_click();}).on('click','#submit_edit_address',function(event){event.preventDefault();save_address('edit_',update_customer_address,null);}).on('click','#submit_find_project',function(event){event.preventDefault();handle_submit_find_project_click();}).on('click','#submit_tax_exemption',function(){$('#tax_exemption_modal').modal('hide');}).on('click','#tax_exemption_dialog',function(){handle_tax_exemption_click();}).on('click','#update_customer',function(event){event.preventDefault();handle_update_customer_button_click();}).on('click','#update_salesrep',function(){handle_update_salesrep_click();}).on('change','input[type=radio][name=user_account_type]',function(){handle_user_account_type_change($(this));}).on('change','#user_country_id',function(){handle_user_country_change();}).on('change','#user_has_salesrep',function(){handle_user_has_salesrep_click();}).on('click','#view_cart',function(event){event.preventDefault();handle_view_cart_button_click();}).on('click','#view_cart_activity',function(event){event.preventDefault();handle_view_cart_activity_button_click();}).on('keypress','#view_cart_form',function(event){let key=event.which;if(key==13){event.preventDefault();handle_view_cart_button_click();}}).on('click','.view_order_details',function(){handle_view_order_details_click($(this));}).on('keypress','#virtual_inventory_form',function(event){let key=event.which;if(key==13){event.preventDefault();handle_find_virtual_inventory_button_click();}}).on('click','.virtual_inventory_page',function(event){event.preventDefault();handle_virtual_inventory_page_click($(this));}).on('keypress','#xfer_items_project_name',function(){$('input[name="project_select"]:eq(1)').prop('checked',true);$('#new_project_room_fieldset').show();modal_xfer_project_items_height=360;set_modal_height(MODAL_XFER_PROJECT_ITEMS,0);}).on('keypress','#zip_sales_tax_rate_form',function(event){let key=event.which;if(key==13){event.preventDefault();handle_get_zip_sales_tax_rate_click();}})});$(document).ready(function(){if($(".registration_failed").length>0){$(".show-top")[0].scrollIntoView();if(window.matchMedia("only screen and (max-width: 920px)").matches){$("document").ready(function(){$(".set-top-mob").css("margin-top","140px");});} if(window.matchMedia("only screen and (min-width: 1320px)").matches){$("document").ready(function(){$(".set-top-mob").css("margin-top","60px");});}}});;const SEND_WISHLIST_EMAIL=1;const PREVIEW_WISHLIST_EMAIL=2;let saved_button;var spinner=$('spinner');let selected_item=0;let selected_items=[];let move_buttons_enabled=true;if(!String.prototype.trim){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}} function get_available_selected_item_prod_ids() {let prod_ids=[];for(let idx=0;idx');}});} function handle_add_all_items_to_cart_click(){let prod_ids=[];let quantities=[];$('.item_quantity').each(function(){quantities.push($(this).val());prod_ids.push($(this).data('prodId'));});let data='&prod_id='+prod_ids.join('|')+'&quantity='+quantities.join('|');window.location='https://www.lightology.com/index.php?module=dispatcher&action=add_items_to_cart_show_cart'+data;} function handle_add_selected_items_to_cart_click() {let prod_ids=get_available_selected_item_prod_ids();let quantities=get_available_selected_item_quantities();if(quantities.length>0){let data='&prod_id='+prod_ids.join('|')+'&quantity='+quantities.join('|');window.location='https://www.lightology.com/index.php?module=dispatcher&action=add_items_to_cart_show_cart'+data;}} function handle_add_to_wishlist_click() {let url='https://www.lightology.com/index.php?module=dispatcher';let quantity=1;let $quantity=$('#quantity');if($quantity.length){quantity=parseInt($quantity.val(),10);} let prod_id=parseInt($('#display_prod_id').val(),10);let data='action=add_item_to_wishlist&prod_id='+prod_id+'&quantity='+quantity;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){switch(data.code){case 1:let $add_to_wishlist_button=$('.add_to_wishlist');let elem=$add_to_wishlist_button.clone();let div=$add_to_wishlist_button.closest('div');$add_to_wishlist_button.replaceWith($('Added to wishlist'));$('span',div).fadeOut(1500,function(){$(this).replaceWith(elem);let $required_items=$('#required_items');if($required_items.length){$('html, body').animate({scrollTop:$required_items.offset().top},1000);}});$('.wishlist_count').html(data.count.toString());$('li.wishlist').addClass('active');break;case 2:show_wishlist_dialog(data.content);$('input[name="wishlist_select"]:eq(0)').prop('checked',true);if(typeof acsbJS!=='undefined'){acsbJS.restart();} break;}}},error:function(){}});} function handle_add_to_wishlist_submit($this) {let url='https://www.lightology.com/index.php?module=dispatcher';let quantity=1;let $quantity=$('#quantity');if($quantity.length){quantity=parseInt($quantity.val(),10);} let prod_id=parseInt($('#display_prod_id').val(),10);let data='action=add_item_to_wishlist&prod_id='+prod_id+'&quantity='+quantity;let html_success='

';let html_failure='

';let html_message;let message_timeout=4000;data+='&'+$this.serialize();let button=$this.find('button[name="add_to_wishlist_submit"]');let div=button.closest('div');saved_button=button.detach();div.prepend(spinner.css('float','right'));$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {div.find('img').replaceWith(saved_button);$('.ui-dialog-titlebar').hide(0);if(data){if(data.code==1){html_message=html_success+'Added to Wishlist

';message_timeout=2000;$('.wishlist_count').html(data.count.toString());$('li.wishlist').addClass('active');}else{html_message=html_failure+data.content+'';message_timeout=4000;} $('#wishlist_quickview_box').html(html_message);$('#wishlist_quickview_box').dialog({position:{my:'center',at:'center',of:window}});} setTimeout(function(){$('#wishlist_quickview_box').dialog('close');},message_timeout);},error:function(){html_message=html_failure+'A system error has occurred - changes may not have been saved'+'';$('#wishlist_quickview_box').html(html_message);$('#wishlist_quickview_box').dialog({position:{my:'center',at:'center',of:window}});setTimeout(function(){$('#wishlist_quickview_box').dialog('close');},4000);}});} function handle_add_wishlist_item_to_cart_click($this){let prod_id=$this.data('prodId');let $quantity=$('#quantity_'+prod_id);let quantity=parseInt($quantity.val(),10);let data='action=add_wishlist_item_to_cart&prod_id='+prod_id+'&quantity='+quantity;let url='https://www.lightology.com/index.php?module=dispatcher';$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {if(data){if(data.hasOwnProperty('code')&&data.code>0){$this.text('Added to Cart');$this.css("background-color","#33af06");if(data.hasOwnProperty('items')&&typeof gtag!=='undefined'){let user_id=$('#ga_user_id').text();generate_ga_config_clause(user_id);gtag('event','add_to_cart',{'send_to':['UA-1647398-1','G-10MBQY35VG'],'items':data.items});} if(data.hasOwnProperty('count')){$('.minicart .count').show().html(data.count);}}}},error:function(){}});} function handle_create_wishlist_submit() {let url='https://www.lightology.com/index.php?module=dispatcher';let wishlist_name=encodeURIComponent($('input[name="create_wishlist_name"]:first').val());let data='action=create_wishlist&wishlist_name='+wishlist_name;$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {if(data){switch(data.code){case 0:$('#create_new_wishlist_error').html(data.content);break;case 1:window.location='https://www.lightology.com/index.php?module=wishlist&wishlist_id='+data.wishlist_id;break;}}}});} function handle_delete_wishlist_submit() {let url='https://www.lightology.com/index.php?module=dispatcher';let wishlist_id=parseInt($('span#wishlist_id').text(),10);let data='action=delete_wishlist&wishlist_id='+wishlist_id;if(wishlist_id>0){$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {if(data){switch(data.code){case 0:$('.message').html(data.content);break;case 1:window.location='https://www.lightology.com/index.php?module=wishlist';break;}}}});}} function handle_email_wishlist_click() {$('#full_name').val('');$('#email_address').val('');$('#email_message').val('');$('#email_dialog_message').html('');$('#wl_preview_email_section').empty();let $modal_content=$('.modal-content');$('#static-display-email').height(580);$modal_content.height(620);$modal_content.width(600);$('#emailModal').modal('show');} function handle_email_wishlist_pricing_change($this) {let html=null;$('#wl_preview_email_section').empty();switch($this.val()){case'3':html='
'+'WARNING: You are emailing this wishlist with Trade pricing!
';$('#wl_email_price_warning').html(html);$('#wl_email_markup_input').remove();break;case'4':html='
'+''+'

% markup (from '+$this.data('mkup-lo')+'% to '+$this.data('mkup-hi')+'%)*

'+'
';$this.after(html);html='

*Prices will not go higher than retail price, so maximum markup may vary.

';$('#wl_email_price_warning').html(html);break;default:$('#wl_email_price_warning').html('');$('#wl_email_markup_input').remove();break;}} function handle_email_wishlist_request(request_type) {let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=process_email_wishlist_request&request_type='+request_type;let $email_dialog_message=$('#email_dialog_message');$email_dialog_message.html('');data+='&'+$('#form-email-wishlist').serialize();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {if(data){let $modal_content=$('.modal-content');let $static_display_email=$('#static-display-email');switch(data.code){case 0:$static_display_email.height(650);$modal_content.height(690);$modal_content.width(600);$email_dialog_message.html(data.message);break;case 1:$email_dialog_message.html('');if(request_type===PREVIEW_WISHLIST_EMAIL){let item_count=data.item_count;let modal_content_height=1360+item_count*420;let static_display_email_height=1220+item_count*420;$static_display_email.height(static_display_email_height);$modal_content.height(modal_content_height);$modal_content.width(700);$('#wl_preview_email_section').html(data.html);} else if(request_type===SEND_WISHLIST_EMAIL){$('#wl_preview_email_section').html('');$static_display_email.height(680);$modal_content.height(750);$modal_content.width(600);$('#email_dialog_message').html(data.html);setTimeout(function(){$('#emailModal').modal('hide');},2500);} break;}}},error:function(){$('#email_dialog_message').html('Unable to send email - please try again later');}});} function handle_item_quantity_focusout($this){let quantity=$this.val();if(quantity.length>0){quantity=parseInt(quantity,10);if(quantity<1){$this.val('1');}}else{$this.val('1');}} function handle_item_quantity_dec_click($this){let prod_id=$this.data('prodId');let $quantity=$('#quantity_'+prod_id);let quantity=parseInt($quantity.val(),10);if(quantity>1){$quantity.val(quantity-1);}} function handle_item_quantity_inc_click($this){let prod_id=$this.data('prodId');let $quantity=$('#quantity_'+prod_id);let quantity=parseInt($quantity.val(),10);if(quantity<999){$quantity.val(quantity+1);}} function handle_item_quantity_key(event){let key=event.which;if((key<48||key>57)&&key!=8&&key!=9&&key!=35&&key!=36&&key!=46) {event.preventDefault();}} function handle_move_to_button_click($this){if(move_buttons_enabled){let prod_id=$this.data('prodId');selected_item=prod_id;$('#moveModal').modal('show');}} function handle_move_to_submit(){let wishlist_id=$('#move_to_wishlist option:selected').val();let data='';if(wishlist_id<1){$('#move_to_wishlist_error').text('Please select a list');}else{let mode=$('input[name="wishlist_move_mode"]:checked').val();if(selected_item>0){selected_items=[];selected_items.push(selected_item);selected_item=0;} if(selected_items.length>0){let url='https://www.lightology.com/index.php?module=dispatcher';let prod_ids=get_available_selected_item_prod_ids();let quantities=get_available_selected_item_quantities();if(mode==='cut'){let from_wishlist_id=parseInt($('span#wishlist_id').text(),10);data='action=move_to_wishlist&from_wishlist_id='+from_wishlist_id+'&to_wishlist_id='+ wishlist_id+'&prod_id='+prod_ids.join('|')+'&quantity='+quantities.join('|');}else{data='action=copy_to_wishlist&wishlist_id='+wishlist_id+'&prod_id='+prod_ids.join('|')+'&quantity='+quantities.join('|');} $.ajax({type:'POST',url:url,data:data,dataType:'json',success:function() {window.location='https://www.lightology.com/index.php?module=wishlist&wishlist_id='+wishlist_id;},error:function(){window.location='https://www.lightology.com/index.php?module=wishlist&wishlist_id='+wishlist_id;}});}}} function handle_print_wishlist_click() {let url='https://www.lightology.com/index.php?module=dispatcher';let wishlist_id=parseInt($('span#wishlist_id').text(),10);let data='action=build_print_wishlist_html&wishlist_id='+wishlist_id;if(wishlist_id>0){$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {if(data){let printer=window.open('','');printer.document.write(data);printer.document.close();printer.print();printer.close();}}});}} function handle_remove_selected_items_click() {if(selected_items.length<1){return;} $('#removeSelectedModal').modal('show');} function handle_remove_selected_items_submit() {let wishlist_id=parseInt($('span#wishlist_id').text(),10);let prod_ids=selected_items.join(':');let data='&wishlist_id='+wishlist_id+'&prod_ids='+encodeURIComponent(prod_ids);window.location='https://www.lightology.com/index.php?module=dispatcher&action=remove_items_from_wishlist'+data;} function handle_rename_wishlist_submit() {let url='https://www.lightology.com/index.php?module=dispatcher';let wishlist_id=parseInt($('span#wishlist_id').text(),10);let wishlist_name=encodeURIComponent($('input[name="rename_wishlist_name"]:first').val());let data='action=rename_wishlist&wishlist_id='+wishlist_id+'&wishlist_name='+wishlist_name;if(wishlist_id>0){$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {if(data){switch(data.code){case 0:$('#rename_wishlist_error').html(data.content);break;case 1:window.location='https://www.lightology.com/index.php?module=wishlist&wishlist_id='+wishlist_id;break;}}}});}} function handle_save_cart_to_wishlist_click() {let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=save_cart_to_wishlist';$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data){switch(data.code){case 1:$('.wishlist_count').html(data.count.toString());$('li.wishlist').addClass('active');show_wishlist_dialog(data.content);break;case 2:show_wishlist_dialog(data.content);$('input[name="wishlist_select"]:eq(0)').prop('checked',true);break;}}}});} function handle_save_cart_to_wishlist_submit($this) {let url='https://www.lightology.com/index.php?module=dispatcher';let data='action=save_cart_to_wishlist';data+='&'+$this.serialize();$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data){if(data.code==1){$('.wishlist_count').html(data.count.toString());$('li.wishlist').addClass('active');$('#wishlist_dialog_error_message').html('');$('#wishlist_dialog_success_message').html(data.content);}else{$('#wishlist_dialog_success_message').html('');$('#wishlist_dialog_error_message').html(data.content);}},error:function(){$('#wishlist_dialog_success_message').html('');$('#wishlist_dialog_error_message').html('A system error has occurred - changes may not have been saved');}});} function handle_select_action_cancel_click() {$('.select_wishlist_item').each(function(){$(this).prop('checked',false);handle_select_wishlist_item_click($(this));});selected_items=[];$('.action-bar').removeClass('active');move_buttons_enabled=true;} function handle_select_all_items_click() {if($('#select_all_items').is(':checked')){selected_items=[];$('.select_wishlist_item').each(function(){$(this).prop('checked',true);handle_select_wishlist_item_click($(this));});}else{$('.select_wishlist_item').each(function(){$(this).prop('checked',false);handle_select_wishlist_item_click($(this));});selected_items=[];}} function handle_select_wishlist_item_click($this) {let prod_id=parseInt($this.data().prodId,10);let item_offset=selected_items.indexOf(prod_id);if(item_offset>-1){selected_items.splice(item_offset,1);}else{selected_items.push(prod_id);} console.log(selected_items.join(' '));if(selected_items.length>0){$('.action-bar').addClass('active');move_buttons_enabled=false;}else{$('.action-bar').removeClass('active');move_buttons_enabled=true;} let all=$('.select_wishlist_item').length;let checked=$('.select_wishlist_item:checked').length;if(checked===all){$('#select_all_items').prop('checked',true);}else{$('#select_all_items').prop('checked',false);}} function update_wishlist_item_notes($this) {let url='https://www.lightology.com/index.php?module=dispatcher';let prod_id=parseInt($this.data().prodId,10);let wishlist_id=parseInt($this.data().wishlistId,10);let type=$('#type_'+prod_id).val();let room=$('#room_'+prod_id).val();let note=$('#note_'+prod_id).val();let data='action=update_wishlist_item_notes&wishlist_id='+wishlist_id+'&prod_id='+prod_id+'&type='+encodeURIComponent(type)+'&room='+encodeURIComponent(room)+'¬e='+ encodeURIComponent(note);let button=$this;let div=$this.closest('div');button.replaceWith('Saving…');$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function() {div.find('span').replaceWith('Saved');div.find('span').fadeOut(1000,function(){$(this).replaceWith(button);});let room_note='';if(room.length>0){room_note=room;if(note.length>0){room_note=room_note+' / '+note;}} else if(note.length>0){room_note=note;} room_note=' Notes: '+room_note;$('#wishlist_room_note_'+prod_id).text(room_note);}});} function update_wishlist_item_quantity($this) {let url='https://www.lightology.com/index.php?module=dispatcher';let prod_id=parseInt($this.data().prodId,10);let wishlist_id=parseInt($this.data().wishlistId,10);let quantity=parseInt($('#quantity_'+prod_id).val(),10);let data='action=update_wishlist_item_quantity&wishlist_id='+wishlist_id+'&prod_id='+prod_id+'&quantity='+quantity;let $div=$this.closest('div.update_wishlist_item_quantity_div');let a=$div.find('a');a.replaceWith('Updating…');$.ajax({type:'POST',url:url,data:data,dataType:'json',success:function(data) {$div.find('span').replaceWith(data.message);$div.find('span').fadeOut(1000,function(){$(this).replaceWith(a);});if(data.subtotal){$('#price_subtotal_'+prod_id).html(data.subtotal);} if(data.total){$('#wishlist_total').html(data.total);}}});} $(document).ready(function(){$(window).on('scroll',function(){let scrollTop=$(window).scrollTop();if(scrollTop>50){$('.action-bar').stop().css("padding","12px 20px 15px");$('.scroll-fx').stop().css("height","25px");} else{$('.action-bar').stop().css("padding","50px 20px");$('.scroll-fx').stop().css("height","50px");}});if(matchMedia('only screen and (max-width: 820px)').matches){$(".wishlist-collapse").hide();} $('body').on('click','#add_selected_items_to_cart',function(event){event.preventDefault();handle_add_selected_items_to_cart_click();}).on('click','#add_to_wishlist, #add_to_wishlist_new',function(event){event.preventDefault();handle_add_to_wishlist_click();}).on('submit','form[name="add_to_wishlist"]',function(event){event.preventDefault();handle_add_to_wishlist_submit($(this));}).on('click','.atc-btn',function(event){event.preventDefault();handle_add_wishlist_item_to_cart_click($(this));}).on('click','#atc-total',function(event){event.preventDefault();handle_add_all_items_to_cart_click();}).on('click','.collapse-list',function(){$(this).next('.wishlist-collapse').slideToggle('fast');$(this).toggleClass('list-open');$(this).find('i').toggleClass('fa fa-plus fa fa-minus');}).on('keypress','input[name="create_wishlist_name"]',function(event){let key=event.which;if(key==13){event.preventDefault();handle_create_wishlist_submit();}}).on('click','#submit-new-inquiry',function(event){event.preventDefault();handle_create_wishlist_submit();}).on('click','#submit-remove-list',function(event){event.preventDefault();handle_delete_wishlist_submit();}).on('click','.dropbtn',function(){$(this).next(".dropdown-content").slideToggle("fast");$(this).text($(this).text()=='Show Options and Notes'?'Hide Options and Notes x':'Show Options and Notes');}).on('click','#email_wishlist',function(event){event.preventDefault();handle_email_wishlist_click();}).on('focusout','.item_quantity',function(event){event.preventDefault();handle_item_quantity_focusout($(this));}).on('keydown','.item_quantity',function(event){handle_item_quantity_key(event);}).on('click','.item_quantity_dec',function(){handle_item_quantity_dec_click($(this));}).on('click','.item_quantity_inc',function(){handle_item_quantity_inc_click($(this));}).on('click','.modal-header .close',function(){$('#wishlist_quickview_box').empty();$('#wishlist_quickview_box').removeAttr("style")}).on('click','.move-btn',function(event){event.preventDefault();handle_move_to_button_click($(this));}).on('click','#submit-move-list',function(event){event.preventDefault();handle_move_to_submit();}).on('click','#move_selected_items',function(event){event.preventDefault();$('#moveModal').modal('show');}).on('click','#print_wishlist',function(event){event.preventDefault();handle_print_wishlist_click();}).on('click','#remove_selected_items',function(){handle_remove_selected_items_click();}).on('click','#submit-remove-selected',function(event){event.preventDefault();handle_remove_selected_items_submit();}).on('click','#rename_wishlist_submit',function(event){event.preventDefault();handle_rename_wishlist_submit();}).on('click','#save_cart_to_wishlist',function(event){event.preventDefault();handle_save_cart_to_wishlist_click();}).on('submit','form[name="save_cart_to_wishlist"]',function(event){event.preventDefault();handle_save_cart_to_wishlist_submit($(this));}).on('click','#search_wishlist',function(){let wishlist_id=$('#search_wishlist_id').val();window.location.href=('https://www.lightology.com/index.php?module=wishlist&wishlist_id='+wishlist_id);}).on('keypress','#search_wishlist_id',function(event){let key=event.which;if(key==13){event.preventDefault();let wishlist_id=$('#search_wishlist_id').val();window.location.href=('https://www.lightology.com/index.php?module=wishlist&wishlist_id='+wishlist_id);}}).on('click','#select_action_cancel',function(event){event.preventDefault();handle_select_action_cancel_click();}).on('click','#select_all_items',function(){handle_select_all_items_click();}).on('click','.select_wishlist_item',function(){handle_select_wishlist_item_click($(this));}).on('click','#studio-designer',function(event){event.preventDefault();function BasicLoader(){}BasicLoader.currentSiteUrl='https://studiowebware.secure.force.com/';BasicLoader.pageToLoad=BasicLoader.currentSiteUrl+'/apex/SDCaptureLoader';BasicLoader.TIMEOUT=10000;BasicLoader.INTERVAL=100;BasicLoader.CURRENT_TIMEOUT=0;BasicLoader.validated=false;BasicLoader.onComplete=function(){console.log('BasicLoader.completed');};BasicLoader.wait=function(){try{if(BasicLoader.CURRENT_TIMEOUT>=BasicLoader.TIMEOUT){alert('Timeout elapsed!');} else if(BasicLoader.validated){BasicLoader.onComplete();}else{BasicLoader.CURRENT_TIMEOUT+=BasicLoader.INTERVAL;window.setTimeout('BasicLoader.wait();',BasicLoader.INTERVAL);}}catch(e){console.error('BasicLoader.wait() exception: ',e);}};BasicLoader.addScriptElement=function(){let iFrame=document.createElement('iframe');iFrame.src=BasicLoader.pageToLoad;iFrame.id='basicLoader';iFrame.name='basicLoader';iFrame.frameBorder=1;iFrame.style.display='none';document.getElementsByTagName('body')[0].appendChild(iFrame);};BasicLoader.load=function(){let basicLoaderIFrame=document.getElementById('basicLoader');if(basicLoaderIFrame){if(Loader)Loader.load();return;}window.addEventListener('message',BasicLoader.receiveMessage,false);BasicLoader.addScriptElement();BasicLoader.wait();};BasicLoader.receiveMessage=function(e){if(e.origin&&e.origin==BasicLoader.currentSiteUrl){window.removeEventListener('message',BasicLoader.receiveMessage,false);if(e.data&&e.data.executable&&typeof e.data.executable=='string'){let script=document.createElement('script');script.type='text/javascript';script.innerHTML=e.data.executable;document.getElementsByTagName('head')[0].appendChild(script);BasicLoader.validated=true;}else{console.error(['BasicLoader.receiveMessage',e]);BasicLoader.validated=false;}}};BasicLoader.load();}).on('click','#submit-email-list',function(event){event.preventDefault();handle_email_wishlist_request(SEND_WISHLIST_EMAIL);}).on('click','#submit-preview-list',function(event){event.preventDefault();handle_email_wishlist_request(PREVIEW_WISHLIST_EMAIL);}).on('click','.update_wishlist_item_notes',function(event){event.preventDefault();update_wishlist_item_notes($(this));}).on('click','.update_wishlist_item_quantity',function(event){event.preventDefault();update_wishlist_item_quantity($(this));}).on('change','select[name="wishlist_email_pricing"]',function(){handle_email_wishlist_pricing_change($(this));}).on('click','.wishlist_prod_sku',function(event){event.preventDefault();let temp=$('');$('body').append(temp);temp.val($(this).text()).select();document.execCommand('copy');temp.remove();});});