/*---- Init Javascript ------*/ var dealerCode = '270c16c500d02cccc6c75a4f27347a43'; var vin = 'SALWR2FE7HA166898'; var currencyFormat = function (num, decimals) { var numString = num.toString().replace(/,/g, ''); return "$" + parseFloat(numString).toFixed(decimals).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); }; var populate = function (results) { if (results.lease_payment) { updateVal('ds_lease_payment', currencyFormat(results.lease_payment)); updateVal('ds_lease_das', currencyFormat(results.lease_das)); updateVal('ds_lease_down', currencyFormat(results.lease_down)); updateVal('ds_lease_down_text', results.lease_down_text); updateVal('ds_lease_down_or_das', currencyFormat(results.lease_down_or_das)); updateModal('ds_lease_link', results.lease_frameurl, results.vin); } if (results.finance_lowapr) { updateVal('ds_finance_lowapr', (results.finance_lowapr)); updateVal('ds_finance_lowapr_max_term', (results.finance_lowapr_max_term)); updateModal('ds_finance_lowapr_link', results.finance_lowapr_frameurl, results.vin); } else { jQuery(".ds_vin_" + results.vin).find(".dsp-banner-footer").hide(); } if (results.finance_payment) { updateVal('ds_finance_payment', currencyFormat(results.finance_payment)); updateVal('ds_finance_das', currencyFormat(results.finance_das)); updateVal('ds_finance_down', currencyFormat(results.finance_down)); updateVal('ds_finance_down_text', results.finance_down_text); updateVal('ds_finance_down_or_das', currencyFormat(results.finance_down_or_das)); updateModal('ds_finance_link', results.finance_frameurl, results.vin); } }; var updateVal = function (key, value) { var match = jQuery('.' + key).html(value); match.removeClass(key); }; var updateModal = function (key, frame_url, vin) { var tag = jQuery("a." + key); var newClass = key + vin; tag.removeClass(key).addClass(newClass).attr('href', frame_url); jQuery("a." + newClass).fancybox({ 'transitionIn': 'none', 'transitionOut': 'none', 'type': 'iframe', 'href': frame_url }); }; var GetURLParameter = function (sParam) { var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); if (sParameterName[0] == sParam) { return sParameterName[1]; } } }; var setSigninCookie = function () { if (document.cookie.search('vrp-form=visited') < 0) { jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.4/js.cookie.min.js", function (data, textStatus, jqxhr) { Cookies.set('vrp-form', 'visited', { expires: 7, path: '' }); }); } }; var requireSigninIfDesired = function (results, signed_in, dealerCode, vin) { var sign_in_required = parseInt(results.sign_in_required); if (sign_in_required && !signed_in) { /* * checks to see if sign in is required and then signs the user in if sign_in_user is set. * */ var sign_in_user = GetURLParameter('sign_in_user'); if (sign_in_user) { setSigninCookie(); signed_in = true; } else if (!results.payment_is_a_special || !results.show_specials_without_signing_in) { /* * if sign in required and the user is not signed in, add code to alert the user to sign in instead of payments * */ var sign_in_url = ('https://www.dealerscience.com/iframe.php?target=signin' + '&dealerCode=' + dealerCode + '&vin=' + vin + '&reloadtopframe=' + encodeURIComponent(window.top.location.href.replace(window.top.location.hash, ""))); var lease_sign_in_url = (sign_in_url + '&monthly=' + results.lease_payment + '&down=' + results.lease_down_or_das + '&url=' + encodeURIComponent(results.lease_url)); var finance_sign_in_url = (sign_in_url + '&monthly=' + results.finance_payment + '&down=' + results.finance_down_or_das + '&url=' + encodeURIComponent(results.finance_url)); results.finance_payment = null; results.lease_payment = null; results.finance_lowapr = null; jQuery('.das').html(""); jQuery('.payment').html("

Sign in to
View Payments

"); updateModal('ds_lease_link', lease_sign_in_url, results.vin); updateModal('ds_finance_link', finance_sign_in_url, results.vin); } } return results; }; var populateVDP = function (lease_details_template, finance_details_template, signed_in) { var apiurl = 'https://www.dealerscience.com/webservices/script/?v=0.2&key=FJA12D159&details&category=script&paymenttype=2&dealerCode=' + dealerCode + '&vin=' + vin; jQuery.getJSON(apiurl, function (results) { var appendLocation = jQuery(".mainPriceContainer"); if (jQuery(".finance-container,.dealerScienced").length == 0) { jQuery(".mainPriceContainer").each(function () { var thisBlock = this; jQuery("
").appendTo(this); }); } if (jQuery(".finance-container,.dealerScienced").length == 0) { jQuery(".custom-pricing-container>.discounts-box").each(function () { appendLocation = this; jQuery("
").appendTo(this); }); } if (jQuery(".finance-container,.dealerScienced").length == 0) { jQuery("#ctabox-pricing.ctabox-row").first().each(function () { appendLocation = this; jQuery("
").appendTo(this); }); } if (jQuery(".finance-container:not(.dealerScienced)").length) { jQuery(".finance-container:not(.dealerScienced)").addClass('dealerScienced').attr('id', 'finance-container').removeClass('finance-container').html(finance_details_template); jQuery("#finance-container").clone().attr('id', 'lease-container').insertBefore(jQuery("#finance-container")); jQuery("#lease-container").html(lease_details_template); if (!results.show_lease) { jQuery("#lease-container").hide(); } if (!results.show_finance) { jQuery("#finance-container").hide(); } jQuery("#lease-container").parents('.dealerScienced').addClass('ds_vin_' + vin.toUpperCase()); var resultsAfterSignin = requireSigninIfDesired(results, signed_in, dealerCode, vin); populate(resultsAfterSignin); } }); }; jQuery(document).ready(function () { var apiurl = 'https://www.dealerscience.com/webservices/ds/jstemplate/?v=0.2&key=FJA12D159&dealerCode=' + dealerCode + '&category=script&subcategory[]=details_lease&subcategory[]=details_finance&subcategory[]=lease_finance_header'; jQuery.getJSON(apiurl, function (results) { var lease_details_template = results['details_lease']; var finance_details_template = results['details_finance']; var header_template = results['lease_finance_header']; var signed_in = (document.cookie.search('vrp-form=visited') >= 0 ? true : false); populateVDP(lease_details_template, finance_details_template, signed_in); /* VDP */ if (jQuery(".maincardetails").length > 0) { populateVDP(lease_details_template, finance_details_template, signed_in); } jQuery(header_template).appendTo("head"); }); });