console.log("mpl_loaded"); //ga('create', 'UA-741540-2', 'auto', {'name': 'stores'}); //ga('create', 'UA-741540-11', 'auto', {'name': 'dashboard'}); if (jQuery("body.nextRegister").length){ setLimitCookie("previous_balance", "", -1); console.log("mpl_ cleared balance"); } var limit_days = 30; // originally checked balance for a set number of days var d = new Date(); limit_days = d.getDate(); // customer service advised that balances reset on the 1st /* defaults - also see cust type settings below */ var free_shipping_min = 90; var shipping_cusa = 6.95; var shipping_akhi = 21.95; var nextVeterinarian_limit = 1000; var nextClinicStaff_limit = 200; var nextStudent_limit = 2000; var nextFaculty_limit = 2000; if (jQuery('[class*="xemail_clarion@value.net"]').length || jQuery('[class*="courtney.dugan@bluepearlvet.com"]').length || jQuery('[class*="jlc77@cornell.edu"]').length){ nextClinicStaff_limit = 2000; } if (location.hostname.indexOf("ez") == -1){ /* vets consumer store limits */ var nextVeterinarian_limit = 1000; var nextClinicStaff_limit = 130; var nextStudent_limit = 200; var nextFaculty_limit = 200; } const formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 2 }); Date.prototype.monthDays= function(){ var d= new Date(this.getFullYear(), this.getMonth()+1, 0); return d.getDate(); } /* cust type settings */ if (jQuery("body.nextClinicStaff").length || jQuery("body.nextClinicStaffNMX").length){ jQuery("body").attr("monthly_limit", nextClinicStaff_limit); jQuery("body").attr("balance_days", limit_days); jQuery("body").attr("remaining_days", d.monthDays()-limit_days); free_shipping_min = 90; shipping_cusa = 6.95; shipping_akhi = 21.95; } jQuery("body[monthly_limit]").attr("over_monthly_limit",0); // if (jQuery("body.nextStudent").length){ jQuery("body").attr("monthly_limit", nextStudent_limit); } // if (jQuery("body.nextFaculty").length){ jQuery("body").attr("monthly_limit", nextFaculty_limit); } //CheckPreviousBalance(); jQuery(document).ready(function(){ RelocateCheckoutButton(); CheckPreviousBalance(); }); // window.setTimeout(function(){ // CheckPreviousBalance(); // }, 1000); function CheckPreviousBalance(){ if (!jQuery("body[monthly_limit]").length){ console.log("mpl_ no monthly purchase limit"); return; } if (getLimitCookie("previous_balance") == ""){ console.log("mpl_ no previous balance cookie"); if (!jQuery(".purchase_limit_data").length){ console.log("mpl_ .purchase_limit_data not found"); jQuery("body").prepend(''); } jQuery(".purchase_limit_data").load("account.aspx .nextOrderList", function(){ CalcMonthlyPurchases(); }); } else { console.log("mpl_ found previous balance cookie: "+getLimitCookie("previous_balance")); jQuery("body").attr("previous_balance",getLimitCookie("previous_balance")); PollOverLimit(); } } function SendBalance(){ var store_name = location.hostname.replace("www.vet-ez-order.com","vet").replace("store.nexternal.com","consumer"); var customer = masterServerVars.CustomerID; if (jQuery("#ctl00_cphFooter_mcfFooter_maiAccountInfo_pnlAccountInfo").length){ customer = jQuery("#ctl00_cphFooter_mcfFooter_maiAccountInfo_pnlAccountInfo").text().replace("Not","").replace("? Click here | My Account","").trim(); } if (jQuery("#pnlTempWelcome").length){ customer = jQuery("#pnlTempWelcome b").text().trim(); } if (jQuery("#ctl00_cphFooter_mcfFooter_maiAccountInfo_pnlAccountInfo b").length){ customer = jQuery("#ctl00_cphFooter_mcfFooter_maiAccountInfo_pnlAccountInfo b").text().trim(); } customer = customer + " / " + getLimitCookie("reg-pg-login-attempt").replace("@","_") //ga('dashboard.send', 'event', 'CSP Balance', "$"+jQuery("body").attr("previous_balance")+" / "+store_name+"."+customer); } function CalcMonthlyPurchases(){ var previous_balance = 0; if (!jQuery(".purchase_limit_data .nextAlternateOrderRow, .purchase_limit_data .nextOrderRow").length){ console.log("mpl_ no previous balance"); setLimitCookie("previous_balance", previous_balance, 0); jQuery("body").attr("previous_balance",previous_balance); PollOverLimit(); return; } console.log("mpl_ parsing previous balance data"); //jQuery(".purchase_limit_data .nextAlternateOrderRow, .purchase_limit_data .nextOrderRow") jQuery(".purchase_limit_data .nextAlternateOrderRow,.purchase_limit_data .nextOrderRow").each(function(index){ console.log("parsing row "+(index+1)); var tst_date = "1/2/2006"; // try "1/2/2006" var tst_alt_date = "12/2/2020"; var purchase_date = jQuery(this).find("td:first").next().text().trim(); if (purchase_date == tst_date){ purchase_date = tst_alt_date; //free_shipping_min = 30; console.log("mpl_ using alternate test date of "+purchase_date); } else { console.log("mpl_ using actual date of "+purchase_date); } if (GetDateOffset(purchase_date) < limit_days){ var amount = (jQuery(this).find("td:last").text().replace("$","").trim()*1); console.log("mpl_gross: "+amount); // subtract shipping from order history if (amount-shipping_cusa < free_shipping_min){ amount = amount-shipping_cusa; // does not account for alaska/hi if (amount <= 0){ amount = 0.00; } } console.log("mpl_net: "+amount); previous_balance = (previous_balance+amount); console.log("mpl_balance: "+previous_balance+"\n-----------------------"); } if (index == jQuery(".purchase_limit_data .nextAlternateOrderRow,.purchase_limit_data .nextOrderRow").length-1){ previous_balance = formatter.format(previous_balance).replace("$",""); console.log("mpl_ previous balance is $"+previous_balance); setLimitCookie("previous_balance", previous_balance, 1); jQuery("body").attr("previous_balance", previous_balance); console.log("mpl_ set previous balance session cookie"); //window.setTimeout(function(){ SendBalance(); //},1000); PollOverLimit(); } }); } function setLimitCookie(cname, cvalue, exdays){ var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires="+d.toUTCString(); if (exdays == 0){ expires = "expires=0"; } document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getLimitCookie(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 ""; } function RelocateCheckoutButton(){ console.log("mpl_ checking button position"); if (!jQuery('.nextCheckOutButtonBottomWrapper #ctl00_mctMobileCart_mnbCheckout_aButton').length){ jQuery('#ctl00_mctMobileCart_mnbCheckout_aButton').wrap('
'); console.log("mpl_ changed button position A"); } if (!jQuery('.nextCheckOutButtonBottomWrapper .nextCheckOutButton.nextCheckOutButtonBottom').length){ var store = "vet"; if (location.hostname.indexOf("nexternal") > -1){ store = "consumer"; } jQuery('.nextCheckOutButton.nextCheckOutButtonBottom').wrap('
'); jQuery(".nextCheckOutButtonBottomWrapper").insertAfter("#aCartCalculator"); jQuery(".nextCheckOutButtonBottomWrapper").addClass(store+"_store"); console.log("mpl_ changed button position B"); } } function PollOverLimit(){ if (!jQuery("body[monthly_limit]").length){ jQuery("body[monthly_limit]").removeAttr("over_monthly_limit"); console.log("mpl_ error setting monthly purchase limit"); return; } //jQuery("body").attr("previous_balance", 0); //jQuery("body").attr("avail_balance", (jQuery("body").attr("monthly_limit")*1)-(jQuery("body").attr("previous_balance")*1)); if (getLimitCookie("previous_balance") == ""){ console.log("mpl_ could not get previous balance"); return; } if (!jQuery("body[polling_purchase_limit]").length){ jQuery("body").attr("polling_purchase_limit", 0); UpdateInCartLimit(); window.setInterval(function(){ UpdateInCartLimit(); //jQuery("body").data("polling_purchase_limit",(jQuery("body").data("polling_purchase_limit")*1)+1)); //jQuery("body").attr("polling_purchase_limit", ((jQuery("body").attr("polling_purchase_limit")*1)+1)); }, 1000); } else { console.log("mpl_ already polling"); } } var g_cart_total = 0; function UpdateInCartLimit(){ console.log("mpl_ checking cart"); if (jQuery(".ui-mobile-viewport").length){ var cart_total = jQuery(".nextCartTotalAmount:contains('$'):last").text().replace("$",""); } else { var cart_total = jQuery("#upCartData b:contains('$'):last").text().replace("$",""); } if (jQuery('#spnShipping').length){ jQuery("body").attr("shipping_total", jQuery('#spnShipping').text().replace("$","")); } else { jQuery("body").attr("shipping_total", jQuery('#ctl00_ctl00_ctl00_cphMain_ctl00_ctrShoppingCart_tdShippingPrice').text().replace("$","")); } cart_total = (cart_total.replace(",","")*1)-(jQuery("body").attr("shipping_total")*1); if (g_cart_total != cart_total){ g_cart_total = cart_total; jQuery("body").removeAttr("over_monthly_limit"); jQuery("body").attr("cart_total", cart_total); jQuery("body").attr("month_total", (cart_total*1) + (getLimitCookie("previous_balance").replace(",","")*1)); jQuery("body").attr("avail_balance", (jQuery("body").attr("monthly_limit")*1)-(jQuery("body").attr("previous_balance")*1)); var purchase_limit_details = "Cart: "+formatter.format(cart_total)+"|Balance: "+formatter.format(getLimitCookie("previous_balance").replace(",",""))+"|Available: "+formatter.format(((jQuery("body").attr("monthly_limit")*1)-(getLimitCookie("previous_balance").replace(",","")*1)))+"|Limit: "+formatter.format(jQuery("body").attr("monthly_limit")); if ((jQuery("body").attr("month_total")*1) > (jQuery("body").attr("monthly_limit")*1)){ jQuery(".nextCheckOutButtonBottomWrapper.vet_store").appendTo(".nextCartBottomButtons"); var over_limit = formatter.format((jQuery("body").attr("monthly_limit")*1)-(jQuery("body").attr("month_total")*1)); jQuery("body").attr("over_monthly_limit", over_limit); jQuery("#over_monthly_limit_msg_style").remove(); //if (!jQuery('#over_monthly_limit_msg[over_limit="'+over_limit+'"]').length){ RelocateCheckoutButton(); var cart_msg = 'Your cart exceeds your monthly purchase limit by '+over_limit.replace("-","")+'.'; jQuery("body").append(''); var purchase_limit_details = "Cart: $"+cart_total+"|Balance: $"+getLimitCookie("previous_balance").replace(",","")+"|Available: $"+((jQuery("body").attr("monthly_limit")*1)-(getLimitCookie("previous_balance").replace(",","")*1))+"|Limit: $"+jQuery("body").attr("monthly_limit"); var store_name = location.hostname.replace("www.vet-ez-order.com","vet").replace("store.nexternal.com","consumer"); var customer = masterServerVars.CustomerID; if (jQuery("#ctl00_cphFooter_mcfFooter_maiAccountInfo_pnlAccountInfo").length){ customer = jQuery("#ctl00_cphFooter_mcfFooter_maiAccountInfo_pnlAccountInfo").text().replace("Not","").replace("? Click here | My Account","").trim(); } if (jQuery("#pnlTempWelcome").length){ customer = jQuery("#pnlTempWelcome b").text().trim(); } if (jQuery("#ctl00_cphFooter_mcfFooter_maiAccountInfo_pnlAccountInfo b").length){ customer = jQuery("#ctl00_cphFooter_mcfFooter_maiAccountInfo_pnlAccountInfo b").text().trim(); } console.log(store_name+"."+customer+" "+purchase_limit_details); //ga('stores.send', 'event', 'CSP Members', 'Over $'+jQuery("body").attr("monthly_limit")+'/mo limit', store_name+"."+customer+" ("+purchase_limit_details+")"); //ga('dashboard.send', 'event', 'CSP Cart Blocked', store_name+"."+customer+" / "+purchase_limit_details, over_limit.replace("$","")); //} } else { //ga('dashboard.send', 'event', 'CSP Cart Unblocked', store_name+"."+customer+" / "+purchase_limit_details, cart_total); jQuery("#over_monthly_limit_msg_style").remove(); } } } function ReduceCart(){ jQuery('[onclick*="showEdit"]:last').click(); jQuery('[onblur*="editQuantityBlur"]:last').val(jQuery('[onblur*="editQuantityBlur"]:last').val()-1); jQuery('[onblur*="editQuantityBlur"]:last').attr("onclick", jQuery('[onblur*="editQuantityBlur"]:last').attr("onblur")); jQuery('[onblur*="editQuantityBlur"]:last').click(); setTimeout(function(){ if (jQuery('[over_monthly_limit]').length){ ReduceCart(); } },1700); } function GetDateOffset(order_date){ var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! var yyyy = today.getFullYear(); today = mm + '/' + dd + '/' + yyyy; //today = "08/24/2015"; var date1 = new Date(order_date); var date2 = new Date(today); var diffDays = parseInt((date2 - date1) / (1000 * 60 * 60 * 24), 10); return diffDays; }