if (typeof tcp === 'undefined') { tcp = {}; } if (typeof tcp.cart === 'undefined') { tcp.cart = {}; } tcp.cart.signFee = parseFloat(2.99); tcp.cart.rushFee = parseFloat(3.99); tcp.cart.domain = window.location.host; //TCP Global: tcp.cart.ssUrl = "https://forms.na1.netsuite.com/app/site/hosting/scriptlet.nl?script=382&deploy=1&compid=3732272&h=a0404b18eac88ce5598f&callback=?"; //Ramsey: //tcp.cart.ssUrl = "https://forms.na1.netsuite.com/app/site/hosting/scriptlet.nl?script=179&deploy=1&compid=TSTDRV1019787&h=5eec2ddae03cbd37e614&callback=?"; tcp.cart.shipIns = 'F'; tcp.cart.signRqd = 'F'; tcp.cart.rush = 'F'; jQuery(document).ready(function(){ tcp.cart.nlShopperId = tcp.cart.getCookie("NLShopperId"); // If cart is empty, don't add checkboxes and abandon ship var serviceItemField = ''; console.log(serviceItemField); var lineItemCount = null; if (serviceItemField != null && serviceItemField != '') { lineItemCount = parseInt(serviceItemField); if(lineItemCount < 1) { //Make jsonp ajax call to SL to delete the cart record var params = "&nlShopperId=" + tcp.cart.nlShopperId + "&deleteRecord=T"; var url = tcp.cart.ssUrl + params; jQuery.getJSON(url, function(data) { console.log(data); }); return; } } tcp.cart.addCheckboxes(); tcp.cart.insFeeChart = tcp.cart.genInsuranceFeeChart(); tcp.cart.setInsuranceFeeCost(); jQuery("#shipInsCheck").live('change', tcp.cart.updateShipInsurance); jQuery("#signatureReqCheck").live('change', tcp.cart.updateSignFee); jQuery("#rushCheck").live('change', tcp.cart.updateRushFee); //Make jsonp ajax call to SL to get the NLShopperId //along with service options selected var params = "&nlShopperId=" + tcp.cart.nlShopperId + "&getRecord=T"; var url = tcp.cart.ssUrl + params; jQuery.getJSON(url, function(data) { console.log(data); if(data != null && data != "") { data = JSON.parse(data); if(data.recordExists) { tcp.cart.shipIns = data.shipIns; tcp.cart.signRqd = data.signRqd; tcp.cart.rush = data.rush; } } tcp.cart.updateServices(); }); }); tcp.cart.addCheckboxes = function(){ var trCount = jQuery("#carttable > tbody").children("tr").length; var insertBeforeRow = trCount - 1; var tableId = "#carttable"; var serviceTbl = jQuery("" + "" + "" + "" + "" + "
" + "" + "

" + //"
" + "
" + "
" + "" + "" + //"" + "" + "" + "
" + "" + "" + "" + //"" + "" + "" + "
" + "" + " "); if (window.location.host == "checkout.na1.netsuite.com") { insertBeforeRow = jQuery("#submitordertable > tbody").children("tr").length; tableId = "#submitordertable"; trCount = jQuery("#submitordertable > tbody").children("tr").length; serviceTbl = jQuery("" + "" + "" + "" + "" + "
" + "

" + //"
" + "
" + "
" + ""); serviceTbl.insertAfter(tableId + " > tbody > tr:nth-child(" + trCount + ")"); var feeRows = jQuery(//"" + //"Shipping Insurance" + //"" + //"" + "" + "Acceptance Signature Required" + "$2.99" + "" + "" + "Rush Processing" + "$3.99" + ""); feeRows.insertAfter("#ordersummary_itemtotal"); } else { serviceTbl.insertBefore(tableId + " > tbody > tr:nth-child(" + insertBeforeRow + ")"); } } tcp.cart.updateServices = function(){ if(tcp.cart.shipIns == 'T') { tcp.cart.shipInsIsChecked = true; jQuery("#ordersummary_shipInsAmt").text("$" + tcp.cart.insFee); jQuery("#ordersummary_shipInsurance").css('display', ''); if(!jQuery("#shipInsCheck").is(":checked")) { jQuery("#shipInsCheck").attr("checked", true).change(); } } else { tcp.cart.shipInsIsChecked = false; jQuery("#ordersummary_shipInsurance").css('display', 'none'); } if(tcp.cart.signRqd == 'T') { tcp.cart.signIsChecked = true; jQuery("#ordersummary_signRqd").css('display', ''); if(!jQuery("#signatureReqCheck").is(":checked")) { jQuery("#signatureReqCheck").attr("checked", true).change(); } } else { tcp.cart.signIsChecked = false; jQuery("#ordersummary_signRqd").css('display', 'none'); } if(tcp.cart.rush == 'T') { tcp.cart.rushIsChecked = true; jQuery("#ordersummary_rush").css('display', ''); if(!jQuery("#rushCheck").is(":checked")) { jQuery("#rushCheck").attr("checked", true).change(); } } else { tcp.cart.rushIsChecked = false; jQuery("#ordersummary_rush").css('display', 'none'); } tcp.cart.updateTotal(); } tcp.cart.updateShipInsurance = function(){ var trCount = jQuery("#feeLabelTbl > tbody").children("tr").length; if(jQuery("#shipInsCheck").is(":checked")) { tcp.cart.shipIns = 'T'; tcp.cart.shipInsIsChecked = true; tcp.cart.insFee = tcp.cart.getInsuranceFeeAmt(); jQuery("#shipInsLabel").css('display', ''); jQuery("#shipInsTxt").text("$" + tcp.cart.insFee); jQuery("#shipInsTxtRow").css('display', ''); // Review & Submit page: jQuery("#ordersummary_shipInsAmt").text("$" + tcp.cart.insFee); jQuery("#ordersummary_shipInsurance").css('display', ''); tcp.cart.loadScript('/site/update-services/tcp.cart.setShipInsTrue.html', tcp.cart.setShipInsTrueCB); } else { tcp.cart.shipIns = 'F'; tcp.cart.shipInsIsChecked = false; jQuery("#shipInsLabel").css('display', 'none'); jQuery("#shipInsTxt").text(""); jQuery("#shipInsTxtRow").css('display', 'none'); // Review & Submit page: jQuery("#ordersummary_shipInsurance").css('display', 'none'); tcp.cart.loadScript('/site/update-services/tcp.cart.setShipInsFalse.html', tcp.cart.setShipInsFalseCB); } //Make jsonp ajax call to SL to post the NLShopperId //along with service options selected var params = "&nlShopperId=" + tcp.cart.nlShopperId + "&shipIns=" + tcp.cart.shipIns; var url = tcp.cart.ssUrl + params; jQuery.getJSON(url, function(data) { console.log(data); tcp.cart.updateServices(); }); tcp.cart.updateTotal(); } tcp.cart.updateSignFee = function(){ if(jQuery("#signatureReqCheck").is(":checked")) { tcp.cart.signRqd = 'T'; tcp.cart.signIsChecked = true; jQuery("#signLabel").css('display', ''); jQuery("#signTxtRow").css('display', ''); // Review & Submit page: jQuery("#ordersummary_signRqd").css('display', ''); tcp.cart.loadScript('/site/update-services/tcp.cart.setSignRqdTrue.html', tcp.cart.setShipInsTrueCB); } else { tcp.cart.signRqd = 'F'; tcp.cart.signIsChecked = false; jQuery("#signLabel").css('display', 'none'); jQuery("#signTxtRow").css('display', 'none'); // Review & Submit page: jQuery("#ordersummary_signRqd").css('display', 'none'); tcp.cart.loadScript('/site/update-services/tcp.cart.setSignRqdFalse.html', tcp.cart.setShipInsFalseCB); } //Make ajax call to SL to save the NLShopperId //along with service options selected var params = "&callback=postSLData" + "&nlShopperId=" + tcp.cart.nlShopperId + "&signRqd=" + tcp.cart.signRqd; var url = tcp.cart.ssUrl + params; jQuery.getJSON(url, function(data) { console.log(data); tcp.cart.updateServices(); }); tcp.cart.updateTotal(); } tcp.cart.updateRushFee = function(){ if(jQuery("#rushCheck").is(":checked")) { tcp.cart.rush = 'T'; tcp.cart.rushIsChecked = true; jQuery("#rushLabel").css('display', ''); jQuery("#rushTxtRow").css('display', ''); // Review & Submit page: jQuery("#ordersummary_rush").css('display', ''); tcp.cart.loadScript('/site/update-services/tcp.cart.setRushTrue.html', tcp.cart.setShipInsTrueCB); } else { tcp.cart.rush = 'F'; tcp.cart.rushIsChecked = false; jQuery("#rushLabel").css('display', 'none'); jQuery("#rushTxtRow").css('display', 'none'); // Review & Submit page: jQuery("#ordersummary_rush").css('display', 'none'); tcp.cart.loadScript('/site/update-services/tcp.cart.setRushFalse.html', tcp.cart.setShipInsFalseCB); } //Make ajax call to SL to save the NLShopperId //along with service options selected var params = "&callback=postSLData" + "&nlShopperId=" + tcp.cart.nlShopperId + "&rush=" + tcp.cart.rush; var url = tcp.cart.ssUrl + params; jQuery.getJSON(url, function(data) { console.log(data); tcp.cart.updateServices(); }); tcp.cart.updateTotal(); } tcp.cart.updateTotal = function() { tcp.cart.insFee = parseFloat(tcp.cart.getInsuranceFeeAmt()); var total = parseFloat(''); if(total != null && total != '') { if(tcp.cart.shipInsIsChecked) { total += tcp.cart.insFee; } if(tcp.cart.signIsChecked) { total += tcp.cart.signFee; } if(tcp.cart.rushIsChecked) { total += tcp.cart.rushFee; } // **********Update the 'Total'*********** jQuery("#carttable > tbody > tr:last-child > td:nth-child(3)").html("$" + total.toFixed(2) + ""); // Update the mini cart too: //TCP Global: jQuery("div.mct.rollover_mct > div.total > span:last-child").text("$" + total.toFixed(2)); jQuery("#ordersummary_total > td:last-child").html("$" + total.toFixed(2) + ""); //Ramsey: /* jQuery("#mcart_total span:nth-child(2)").text("$" + total.toFixed(2)); jQuery("div.cart_checkout").contents().filter(function() { return this.nodeType === 3; }).wrap( "" ).end(); jQuery("div.cart_checkout > span:nth-child(4)").text("total $" + total.toFixed(2)); jQuery("#ordersummary_total > td:last-child").html("$" + total.toFixed(2) + ""); */ // ***********End update total************** } } tcp.cart.genInsuranceFeeChart = function() { var insFeeChart = new Array(); var topRangeStart = 50.00; var topRangeEnd = 2550.00; var incr = 100.00; var finalTopRange = 999999.00; var fee = 1.50; var feeIncr = 1.00; var finalFeeIncr = 4.00; for(var i = topRangeStart; i <= topRangeEnd; i += incr) { var insFee = new Object(); insFee.rangeMax = i; insFee.fee = fee; insFeeChart.push(insFee); fee += feeIncr; } var maxInsFee = new Object(); maxInsFee.rangeMax = finalTopRange; maxInsFee.fee = fee + finalFeeIncr; insFeeChart.push(maxInsFee); return insFeeChart; } tcp.cart.getInsuranceFeeAmt = function() { var amount = ''; //var amount = parseFloat(''); //var amount = parseFloat(''); var insFee = 0; for (var i = 0; i < tcp.cart.insFeeChart.length; i++) { if (amount <= tcp.cart.insFeeChart[i]['rangeMax']) { insFee = tcp.cart.insFeeChart[i]['fee']; break; } } return insFee.toFixed(2); } tcp.cart.setInsuranceFeeCost = function() { var insFee = tcp.cart.getInsuranceFeeAmt(); jQuery("#shipInsText").html("Shipping Insurance - Additional Cost: $" + insFee + "Why Purchase Insurance?"); } tcp.cart.setCookie = function(cname, cvalue, domain) { document.cookie = cname + "=" + cvalue + "; domain=" + domain + "; path=/"; } tcp.cart.getCookie = function(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) ==' ') c = c.substring(1); if (c.indexOf(name) == 0) return c.substring(name.length, c.length); } return ""; } tcp.cart.loadScript = function(url, callback) { // Adding the script tag to the head as suggested before var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; // Then bind the event to the callback function. // There are several events for cross browser compatibility. script.onreadystatechange = callback; script.onload = callback; // Fire the loading head.appendChild(script); } tcp.cart.setShipInsTrueCB = function() { console.log('Dynamic script loaded. Set shipIns true.'); } tcp.cart.setShipInsFalseCB = function() { console.log('Dynamic script loaded. Set shipIns false.'); }