function validateNum(input) { var num = input.value; var character = ''; var match = false; for (var i = 0; i < num.length; i++) { character = num.substr(i, 1); match = /[0-9]/.test(character); if (!match) { input.value = num.substr(0, num.length - 1); alert('This field can only contain numeric values'); return false; } } return true; } function validateCheckout(form, paymentExceptions) { // Validate step 2 err = "The following error[s] occurred:\n\n"; if (form.userFullName) { if (form.userFullName.value == "") { err += "You must enter a billing name.\n"; } } if (form.userBillingAddress1) { if (form.userBillingAddress1.value == "") { err += "You must enter a billing address.\n"; } } if (form.userBillingCity) { if (form.userBillingCity.value == "") { err += "You must enter a billing city.\n"; } } if (form.userBillingCountry) { var countryCode = form.userBillingCountry.value; var count = statesArray.length; var needsState = false; for (i = 0; i < count; i++) { if (statesArray[i] == countryCode) { needsState = true; } } if (form.userBillingStateOrProvince.value == "" || (form.userBillingStateOrProvince.value == "noselection" && form.userBillingCountry.value == "noselection")) { err += "You must select a valid billing state/province or country.\n"; } else if (needsState && form.userBillingStateOrProvince.value == "noselection") { err += "You must select a valid billing state/province or country.\n"; } if (((form.userBillingCountry.options[form.userBillingCountry.selectedIndex].text).split("*")).length > 1 && form.userBillingZipCode.value == "") { err += "You must enter a billing zip code.\n"; } } if (form.userDayPhone) { if (form.userDayPhone.value == "") { err += "You must enter a phone number.\n"; } } if (form.userDiscipline) { if (form.userDiscipline.value == "") { err += "You must select a discipline.\n"; } } if (form.payment_method) { // paymentExceptions is a string of payment types // with no need to validate. if (form.payment_method.value == "noselection" || form.payment_method.value == "") { err += "You must select a payment method.\n"; } else { if (paymentExceptions.search(form.payment_method.value) < 0) { err += CheckCardNumber(form); if (form.cc_owner.value == "") { err += "You must enter a credit card holder.\n"; } if (form.orderCVV2code) { if (form.orderCVV2code.value == "") { err += "You must enter a CVV2 security code.\n"; } } } else if (form.orderPurchaseOrderNumber) { //Purchase Order is required for net30 if (form.orderPurchaseOrderNumber.value == "") { //err += "You must enter a purchase order number for Net30 accounts.\n"; } } } } if (form.shippingFullName) { if (form.shippingFullName.value == "") { err += "You must enter a shipping name.\n"; } } if (form.shippingAddress1) { if (form.shippingAddress1.value == "") { err += "You must enter a shipping address.\n"; } } if (form.shippingCity) { if (form.shippingCity.value == "") { err += "You must enter a shipping city.\n"; } } if (form.shippingCountry) { var countryCode = form.shippingCountry.value; var count = statesArray.length; var needsState = false; for (i = 0; i < count; i++) { if (statesArray[i] == countryCode) { needsState = true; } } if (form.shippingStateOrProvince.value == "" || (form.shippingStateOrProvince.value == "noselection" && form.shippingCountry.value == "noselection")) { err += "You must select a valid shipping state/province or country.\n"; } else if (needsState && form.shippingStateOrProvince.value == "noselection") { err += "You must select a valid shipping state/province or country.\n"; } if (((form.shippingCountry.options[form.shippingCountry.selectedIndex].text).split("*")).length > 1 && form.shippingZipCode.value == "") { err += "You must enter a shipping zip code.\n"; } } /* if(document.getElementById("residentialY") && document.getElementById("residentialN")){ if(!document.getElementById("residentialY").checked && !document.getElementById("residentialN").checked){ err += "You must select whether your shipping address is residental or not.\n"; } } */ if (form.taxExempt) { if (form.taxExempt[0].checked && form.fedTaxIdNumber.value == "" && form.shippingStateOrProvince.value == "MI") { err += "Please enter your Federal Tax ID Number."; } } if (document.getElementById('profLisence_select')) { var profSelect = document.getElementById('profLisence_select'); var profSelectVal = profSelect.options[profSelect.selectedIndex].value; if (profSelectVal == "") { err += "Please select if you have a professional license. Please select Yes or No for the question \"Do you have a professional license number?\".\n\n"; } if (profSelectVal == "yes" && form.professional_license.value == "") { err += "Please input a professional lisence number.\n"; } } if (document.getElementById('asha_select')) { var ashaSelect = document.getElementById('asha_select'); var ashaSelectVal = ashaSelect.options[ashaSelect.selectedIndex].value; if (ashaSelectVal == "") { err += "Please select if you have want to use AHSA credit. Please select Yes or No for the question \"Are you taking this course for ASHA credit?\".\n\n"; } if (ashaSelectVal == "yes" && form.ASHA.value == "") { err += "Please input your ASHA number.\n"; } } // Check email address if (form.checkOutType && form.userEmail) { //if (form.checkOutType.value != "fast_checkout") { //validate email if not fast checkout if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3,4})+$/.test(form.userEmail.value)) { } else { err += "You must enter a email address.\n"; } //} } if (err != "The following error[s] occurred:\n\n") { alert(String(err)); return false; } else { return true; } } /*/ *************************************** * Begin Validate credit card *************************************** /*/ // Setup card types var Cards = new makeArray(8); Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16"); var Mastercard = Cards[0]; Cards[1] = new CardType("Visa", "4", "13,16"); var Visa = Cards[1]; Cards[2] = new CardType("Amex", "34,37", "15"); var AMEX = Cards[2]; Cards[3] = new CardType("DinersClubCard", "30,36,38", "14"); var DinersClubCard = Cards[3]; Cards[4] = new CardType("Discover", "6011", "16"); var Discover = Cards[4]; Cards[5] = new CardType("enRouteCard", "2014,2149", "15"); var enRouteCard = Cards[5]; Cards[6] = new CardType("JCBCard", "3088,3096,3112,3158,3337,3528", "16"); var JCBCard = Cards[6]; var LuhnCheckSum = Cards[7] = new CardType(); /*************************************************************************\ CheckCardNumber(form) function called when users click the "check" button. \*************************************************************************/ function CheckCardNumber(form) { var tmpyear; if (form.cc_number.value.length == 0) { err = "You must enter a Card Number.\n"; form.cc_number.focus(); return err; } if (form.cc_expiration_year.value.length == 0) { err = "Please enter the Expiration Year.\n"; form.cc_expiration_year.focus(); return err; } if (form.cc_expiration_year.value.length != 4) { if (form.cc_expiration_year.value > 96) tmpyear = "19" + form.cc_expiration_year.value; else if (form.cc_expiration_year.value < 21) tmpyear = "20" + form.cc_expiration_year.value; else { err = "The Expiration Year is not valid.\n"; return err; } } else { tmpyear = form.cc_expiration_year.value; } tmpmonth = form.cc_expiration_month.options[form.cc_expiration_month.selectedIndex].value; // The following line doesn't work in IE3, you need to change it // to something like "(new CardType())...". // if (!CardType().isExpiryDate(tmpyear, tmpmonth)) { if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) { err = "This card has already expired.\n"; return err; } card = form.payment_method.value; var retval = eval(card + ".checkCardNumber(\"" + form.cc_number.value + "\", " + tmpyear + ", " + tmpmonth + ");"); cardname = ""; if (retval) // comment this out if used on an order form return ""; else { // The cardnumber has the valid luhn checksum, but we want to know which // cardtype it belongs to. for (var n = 0; n < Cards.size; n++) { if (Cards[n].checkCardNumber(form.cc_number.value, tmpyear, tmpmonth)) { cardname = Cards[n].getCardType(); break; } } if (cardname.length > 0) { err = "This looks like a " + cardname + " number, not a " + card + " number.\n"; return err; } else { err = "This card number is not valid.\n"; return err; } } } /*************************************************************************\ Object CardType([String cardtype, String rules, String len, int year, int month]) cardtype : type of card, eg: MasterCard, Visa, etc. rules : rules of the cardnumber, eg: "4", "6011", "34,37". len : valid length of cardnumber, eg: "16,19", "13,16". year : year of expiry date. month : month of expiry date. eg: var VisaCard = new CardType("Visa", "4", "16"); var AmExCard = new CardType("AmEx", "34,37", "15"); \*************************************************************************/ function CardType() { var n; var argv = CardType.arguments; var argc = CardType.arguments.length; this.objname = "object CardType"; var tmpcardtype = (argc > 0) ? argv[0] : "CardObject"; var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9"; var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19"; this.setCardNumber = setCardNumber; // set CardNumber method. this.setCardType = setCardType; // setCardType method. this.setLen = setLen; // setLen method. this.setRules = setRules; // setRules method. this.setExpiryDate = setExpiryDate; // setExpiryDate method. this.setCardType(tmpcardtype); this.setLen(tmplen); this.setRules(tmprules); if (argc > 4) this.setExpiryDate(argv[3], argv[4]); this.checkCardNumber = checkCardNumber; // checkCardNumber method. this.getExpiryDate = getExpiryDate; // getExpiryDate method. this.getCardType = getCardType; // getCardType method. this.isCardNumber = isCardNumber; // isCardNumber method. this.isExpiryDate = isExpiryDate; // isExpiryDate method. this.luhnCheck = luhnCheck;// luhnCheck method. return this; } /*************************************************************************\ boolean checkCardNumber([String cardnumber, int year, int month]) return true if cardnumber pass the luhncheck and the expiry date is valid, else return false. \*************************************************************************/ function checkCardNumber() { var argv = checkCardNumber.arguments; var argc = checkCardNumber.arguments.length; var cardnumber = (argc > 0) ? argv[0] : this.cardnumber; var year = (argc > 1) ? argv[1] : this.year; var month = (argc > 2) ? argv[2] : this.month; this.setCardNumber(cardnumber); this.setExpiryDate(year, month); if (!this.isCardNumber()) return false; if (!this.isExpiryDate()) return false; return true; } /*************************************************************************\ String getCardType() return the cardtype. \*************************************************************************/ function getCardType() { return this.cardtype; } /*************************************************************************\ String getExpiryDate() return the expiry date. \*************************************************************************/ function getExpiryDate() { return this.month + "/" + this.year; } /*************************************************************************\ boolean isCardNumber([String cardnumber]) return true if cardnumber pass the luhncheck and the rules, else return false. \*************************************************************************/ function isCardNumber() { var argv = isCardNumber.arguments; var argc = isCardNumber.arguments.length; var cardnumber = (argc > 0) ? argv[0] : this.cardnumber; if (!this.luhnCheck()) return false; for (var n = 0; n < this.len.size; n++) if (cardnumber.toString().length == this.len[n]) { for (var m = 0; m < this.rules.size; m++) { var headdigit = cardnumber.substring(0, this.rules[m].toString().length); if (headdigit == this.rules[m]) return true; } return false; } return false; } /*************************************************************************\ boolean isExpiryDate([int year, int month]) return true if the date is a valid expiry date, else return false. \*************************************************************************/ function isExpiryDate() { var argv = isExpiryDate.arguments; var argc = isExpiryDate.arguments.length; year = argc > 0 ? argv[0] : this.year; month = argc > 1 ? argv[1] : this.month; if (!isNum(year + "")) return false; if (!isNum(month + "")) return false; today = new Date(); expiry = new Date(year, month); if (today.getTime() > expiry.getTime()) return false; else return true; } /*************************************************************************\ boolean isNum(String argvalue) return true if argvalue contains only numeric characters, else return false. \*************************************************************************/ function isNum(argvalue) { argvalue = argvalue.toString(); if (argvalue.length == 0) return false; for (var n = 0; n < argvalue.length; n++) if (argvalue.substring(n, n + 1) < "0" || argvalue.substring(n, n + 1) > "9") return false; return true; } /*************************************************************************\ boolean luhnCheck([String CardNumber]) return true if CardNumber pass the luhn check else return false. Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl \*************************************************************************/ function luhnCheck() { var argv = luhnCheck.arguments; var argc = luhnCheck.arguments.length; var CardNumber = argc > 0 ? argv[0] : this.cardnumber; if (!isNum(CardNumber)) { return false; } var no_digit = CardNumber.length; var oddoeven = no_digit & 1; var sum = 0; for (var count = 0; count < no_digit; count++) { var digit = parseInt(CardNumber.charAt(count)); if (!((count & 1) ^ oddoeven)) { digit *= 2; if (digit > 9) digit -= 9; } sum += digit; } if (sum % 10 == 0) return true; else return false; } /*************************************************************************\ ArrayObject makeArray(int size) return the array object in the size specified. \*************************************************************************/ function makeArray(size) { this.size = size; return this; } /*************************************************************************\ CardType setCardNumber(cardnumber) return the CardType object. \*************************************************************************/ function setCardNumber(cardnumber) { this.cardnumber = cardnumber; return this; } /*************************************************************************\ CardType setCardType(cardtype) return the CardType object. \*************************************************************************/ function setCardType(cardtype) { this.cardtype = cardtype; return this; } /*************************************************************************\ CardType setExpiryDate(year, month) return the CardType object. \*************************************************************************/ function setExpiryDate(year, month) { this.year = year; this.month = month; return this; } /*************************************************************************\ CardType setLen(len) return the CardType object. \*************************************************************************/ function setLen(len) { // Create the len array. if (len.length == 0 || len == null) len = "13,14,15,16,19"; var tmplen = len; n = 1; while (tmplen.indexOf(",") != -1) { tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length); n++; } this.len = new makeArray(n); n = 0; while (len.indexOf(",") != -1) { var tmpstr = len.substring(0, len.indexOf(",")); this.len[n] = tmpstr; len = len.substring(len.indexOf(",") + 1, len.length); n++; } this.len[n] = len; return this; } /*************************************************************************\ CardType setRules() return the CardType object. \*************************************************************************/ function setRules(rules) { // Create the rules array. if (rules.length == 0 || rules == null) rules = "0,1,2,3,4,5,6,7,8,9"; var tmprules = rules; n = 1; while (tmprules.indexOf(",") != -1) { tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length); n++; } this.rules = new makeArray(n); n = 0; while (rules.indexOf(",") != -1) { var tmpstr = rules.substring(0, rules.indexOf(",")); this.rules[n] = tmpstr; rules = rules.substring(rules.indexOf(",") + 1, rules.length); n++; } this.rules[n] = rules; return this; } // End -->// JavaScript Document /* ############## END ################# */ /* ############ checkPass ############ # This function checks that pass # # and confirm pass match # # throw an error alert box # ################################### */ function validateForm() { // Get elements in form err = ""; c = document.newCustomer.elements.length; for (i = 0; i < c; i++) { // loop through them to see if any are blank // If one is blank set err if (document.newCustomer.elements[i].value == "" && document.newCustomer.elements[i].name != "userBillingAddress2") { err = err + "All fields for new customers must be filled out.\n"; break; // No need to continue loop error found } } // Check email address if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.newCustomer.userEmail.value)) { } else { err = err + "You used an invalid email address.\n"; } // Check pass/confirm pass values if (document.newCustomer.userPassword.value != document.newCustomer.confirmPassword.value) { err = err + "Password and Confirm Password do not match. Please try again.\n"; document.getElementById("userPassword").value = ""; document.getElementById("userPassword").focus(); document.getElementById("confirmPassword").value = "" } if (err != "") { alert(String(err)); } else { document.newCustomer.submit(); } } /* ############## END ################# */ /* ########### setShipping ########### # This function sets the shipping # # address to the same as the # # billing address (checked) # # or clears it in the checkout # # form (unchecked) # ################################### */ function setShipping(prevUser) { // check to see if sameShipping is checked var checked = document.getElementById("sameShipping").checked; if (checked) { if (prevUser) { document.getElementById("prevShippingAddresses").selectedIndex = 0; document.getElementById("remove_address").style.visibility = "hidden"; } if ($("#shippingFirstName").length) { $("#shippingFirstName").val(document.getElementById("userFirstName").value); $("#shippingLastName").val(document.getElementById("userLastName").value); } else if (document.getElementById("shippingFullName")) { document.getElementById("shippingFullName").value = (document.getElementById("userFullName")) ? document.getElementById("userFullName").value : document.getElementById("userFirstName").value + " " + document.getElementById("userLastName").value; } else { document.getElementById("shippingShipTo").value = (document.getElementById("userFullName")) ? document.getElementById("userFullName").value : document.getElementById("userFirstName").value + " " + document.getElementById("userLastName").value; } if (document.getElementById("registrantFirst")) { document.getElementById("registrantFirst").value = document.getElementById("userFirstName").value; } if (document.getElementById("registrantLast")) { document.getElementById("registrantLast").value = document.getElementById("userLastName").value; } document.getElementById("shippingCompanyName").value = document.getElementById("userCompanyName").value; document.getElementById("shippingAddress1").value = document.getElementById("userBillingAddress1").value; document.getElementById("shippingAddress2").value = document.getElementById("userBillingAddress2").value; document.getElementById("shippingCity").value = document.getElementById("userBillingCity").value; document.getElementById("shippingStateOrProvince").value = document.getElementById("userBillingStateOrProvince").value document.getElementById("shippingZipCode").value = document.getElementById("userBillingZipCode").value; if (document.getElementById("shippingHomePhone")) { document.getElementById("shippingHomePhone").value = document.getElementById("userDayPhone").value; } document.getElementById("shippingCountry").value = document.getElementById('userBillingCountry').value; //document.getElementById('shipping_country_text').firstChild.nodeValue = document.getElementById('country_text').firstChild.nodeValue; if (document.getElementById("shippingCompanyName").value == "") { if (document.getElementById("residentialY")) { document.getElementById("residentialY").checked = true; } } else { if (document.getElementById("residentialN")) { document.getElementById("residentialN").checked = true; } } if (document.getElementById("checkOutType").value != "fast_checkout") { if (document.getElementById("Home")) document.getElementById("Home").checked = false; if (document.getElementById("Work")) document.getElementById("Work").checked = false; if (document.getElementById("Other")) document.getElementById("Other").checked = false; if (document.getElementById("Other2")) document.getElementById("Other2").style.visibility = "hidden"; if (document.getElementById("Other2")) document.getElementById("Other2").value = ""; } disabled = true; } else { if ($("#shippingFirstName").length) { $("#shippingFirstName").val(''); $("#shippingLastName").val(''); } else if (document.getElementById("shippingFullName")) { document.getElementById("shippingFullName").value = ""; } else { document.getElementById("shippingShipTo").value = ""; } document.getElementById("shippingCompanyName").value = ""; document.getElementById("shippingAddress1").value = ""; document.getElementById("shippingAddress2").value = ""; document.getElementById("shippingCity").value = ""; document.getElementById("shippingStateOrProvince").selectedIndex = 0; document.getElementById("shippingZipCode").value = ""; if (document.getElementById("shippingHomePhone")) { document.getElementById("shippingHomePhone").value = ""; } document.getElementById("residentialY").checked = false; document.getElementById("residentialN").checked = false; document.getElementById("shippingCountry").value = ""; //document.getElementById('shipping_country_text').firstChild.nodeValue= "N/A"; disabled = false; if (prevUser) { previousAdderess(); } } // Enable or disable shipping Options //setCountry('userBillingStateOrProvince', 'userBillingCountry', 'userBillingStateOrProvince'); } /* ############## END ################# */ /* ########### setCountry ########### # This function sets the country # # based on either the billing # # or shipping state/province # ################################### */ var statesArray = Array('US',Array('Alabama','Alaska','Arizona','Arkansas','Armed Forces Americas','Armed Forces Europe / Africa / Southwest Asia / Middle East','Armed Forces Pacific / Southeast Asia','California','Colorado','Connecticut','Delaware','District of Columbia','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','West Virginia','Wisconsin','Wyoming'),'NZ',Array('Auckland','Bay Of Plenty','Canterbury','Chatham Islands','Gisborne','Hawkes Bay','Manawatu-Wanganui','Marlborough','Nelson','Northland','Otago','Southland','Taranaki','Tasman','Waikato','Wellington','West Coast'),'CA',Array('Alberta','British Columbia','Manitoba','New Brunswick','Newfoundland and Labrador','Northwest Territories','Nova Scotia','Nunavut','Ontario','Prince Edward Island','Quebec','Saskatchewan','Yukon'),'AU',Array('Australia Capital Territory','Jervis Bay Territory','New South Wales','Northern Territory','Queensland','South Australia','Tasmania','Victoria','Western Australia')); function setCountry(loc, country, calledBy) { if (calledBy == loc) { //called by state menu sel = document.getElementById(loc).selectedIndex; // value of selected item selValue = document.getElementById(loc).options[sel].text; y = statesArray.length for (x = 1; x < y; x++) { b = statesArray[x].length for (a = 0; a < b; a++) { if (selValue == statesArray[x][a]) { var currentCountry = statesArray[x - 1]; break; } }//end for if (currentCountry) { break; }//end if x++; }//end for if (document.getElementById(loc).options[sel].value != "noselection" && document.getElementById(loc).options[sel].value != "" && currentCountry != "" && currentCountry != undefined) { document.getElementById(country).value = currentCountry; } } else if (calledBy == country) { ///called by country curCountryCode = document.getElementById(country).value; switch (curCountryCode) { case "US": document.getElementById(loc).selectedIndex = 3; break; case "CA": document.getElementById(loc).selectedIndex = 59; break; case "AU": document.getElementById(loc).selectedIndex = 74; break; case "NZ": document.getElementById(loc).selectedIndex = 83; break; default: document.getElementById(loc).selectedIndex = 1; } } } //function setCountry /* ############## END ################# */ /* ########## rushShipping ########### # This function adds or subtracts # # the rush shipping fee # ################################### */ function rushShipping() { ship = document.getElementById('shipping').value shipStart = ship.substring(0, ship.length - 3); shipEnd = ship.substring(ship.length - 3, ship.length); total = document.getElementById('total').value totalStart = total.substring(0, total.length - 3); totalEnd = total.substring(total.length - 3, total.length); if (document.getElementById('shippingRush').value == "Yes") { shipStart = Number(Number(shipStart) + 5); totalStart = Number(Number(totalStart) + 5); document.getElementById('shippingRush_text').firstChild.nodeValue = ' 5.00'; } else { shipStart = Number(Number(shipStart) - 5); totalStart = Number(Number(totalStart) - 5); document.getElementById('shippingRush_text').firstChild.nodeValue = ' 0.00'; } document.getElementById('shipping').value = shipStart + shipEnd; //document.getElementById('shipping_text').firstChild.nodeValue = document.getElementById('shipping').value; document.getElementById('total').value = totalStart + totalEnd; document.getElementById('total_text').firstChild.nodeValue = document.getElementById('total').value; } /* ############## END ################# */ function calcShipping(selection) { //return true; // Max discount var discount = "0.00"; var paymentMethod = ""; var giftCertificate = ""; var nonTaxable = "0" // Default cost var totalCost = "0"; // Get currently selected shipping cost var shipCost = $(".shipping-rates:checked").val().split("~")[1]; var serviceFee = 0.00; if ($("#serviceFee").length) { serviceFee = Number($("#serviceFee").val()); } if (document.getElementById('tax')) { var taxCost = Math.round(((Number(serviceFee + Number(totalCost) + Number(shipCost) - Number(nonTaxable)) - Number(Number(discount) + Number(giftCertificate))) *.06) * 100) / 100; //document.getElementById('tax').value } else { var taxCost = 0.00; } //document.getElementById('total').value = Number(totalCost)+Number(shipCost)+Number(taxCost); if (document.getElementById('discountText')) { if (Number(discount) > (Number(totalCost) + Number(shipCost) + Number(taxCost))) { var remaining = Number(discount) - (Number(totalCost) + Number(shipCost) + Number(taxCost)); } else { var remaining = 0; } if (Number(discount) > Number(totalCost) + Number(shipCost) + Number(taxCost)) discount = Number(totalCost) + Number(shipCost) + Number(taxCost); document.getElementById('discountText').innerHTML = formatCurrency(Number(discount)); document.getElementById('discount').value = document.getElementById('discountText').innerHTML; document.getElementById('remaining').innerHTML = formatCurrency(remaining); if ((Number(totalCost) + Number(shipCost) + Number(taxCost)) - Number(discount) > 0 && (paymentMethod == "Prepaid" || (paymentMethod == "Gift Certificate" && giftCertificate != ""))) { if (document.getElementById('processText')) { document.getElementById('processText').innerHTML = "Please adjust your cart total to be less than or equal to your giftcard amount or choose a second payment method by clicking here."; document.getElementById('processText').style.color = "#FF0000"; } if (document.getElementById('process')) document.getElementById('process').disabled = true; } else { if (document.getElementById('processText')) { document.getElementById('processText').innerHTML = ""; document.getElementById('processText').style.color = "#000000"; } if (document.getElementById('process')) document.getElementById('process').disabled = false; } } if (document.getElementById('taxText')) { document.getElementById('taxText').innerHTML = formatCurrency(taxCost); document.getElementById('tax').value = taxCost; } document.getElementById('total').value = (serviceFee + Number(totalCost) + Number(shipCost) + Number(taxCost)) - Number(discount); document.getElementById('total_text').innerHTML = formatCurrency(serviceFee + (Number(totalCost) + Number(shipCost) + Number(taxCost)) - Number(discount)); } function formatCurrency(num) { num = num.toString().replace(/\$|\,/g, ''); if (isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num * 100 + 0.50000000001); cents = num % 100; num = Math.floor(num / 100).toString(); if (cents < 10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3)); return (((sign) ? '' : '-') + num + '.' + cents); } /* ######### prevAddresses ########## # This function gets the prevous # # shipping addresses used for the # # user account # ################################### */ // Function for previous addresses // Function for previous addresses function previousAdderess() { // get the selected value sel = document.getElementById("prevShippingAddresses").selectedIndex; //alert(sel); if (sel != 0) { // Selection is a previous address // Make "remove" visible document.getElementById("remove_address").style.visibility = "visible"; var mystring = ""; var prevArr = mystring.split("~"); var c = prevArr.length; for (a = 0; a < c; a++) { var selArr = prevArr[a].split("|"); if (selArr[0] == document.getElementById("prevShippingAddresses").options[sel].value) { break; } } console.log(selArr); //document.getElementById("shippingFullName").value = disabled; if (document.getElementById("shippingFullName")) { document.getElementById("shippingFullName").value = selArr[3]; } document.getElementById("shippingCompanyName").value = selArr[4]; document.getElementById("shippingAddress1").value = selArr[5]; document.getElementById("shippingAddress2").value = selArr[6]; document.getElementById("shippingCity").value = selArr[7]; // Work around to select state needed for Mac browsers c = document.getElementById("shippingStateOrProvince").length for (i = 0; i < c; i++) { if (document.getElementById("shippingStateOrProvince").options[i].value == selArr[8]) { document.getElementById("shippingStateOrProvince").selectedIndex = i; break; } } document.getElementById("shippingZipCode").value = selArr[9]; if (document.getElementById("shippingHomePhone")) { document.getElementById("shippingHomePhone").value = selArr[11]; } if (selArr[12] == "Work" || selArr[12] == "Home") { document.getElementById(selArr[12]).checked = true; document.getElementById("Other2").style.visibility = "hidden"; } else { document.getElementById("Other").checked = true; document.getElementById("Other2").style.visibility = "visible"; document.getElementById("Other2").value = selArr[12]; } if (document.getElementById("shippingCompanyName").value == "") { document.getElementById("residentialY").checked = true; } else { document.getElementById("residentialN").checked = true; } setCountry('shippingStateOrProvince', 'shippingCountry', 'shippingStateOrProvince'); } else { document.getElementById("remove_address").style.visibility = "hidden"; document.getElementById("shippingFullName").value = ""; document.getElementById("shippingCompanyName").value = ""; document.getElementById("shippingAddress1").value = ""; document.getElementById("shippingAddress2").value = ""; document.getElementById("shippingCity").value = ""; document.getElementById("shippingStateOrProvince").selectedIndex = 0; document.getElementById("shippingCountry").selectedIndex = 0; document.getElementById("shippingZipCode").value = ""; if (document.getElementById("shippingHomePhone")) { document.getElementById("shippingHomePhone").value = ""; } if (document.getElementById("Home")) document.getElementById("Home").checked = false; if (document.getElementById("Work")) document.getElementById("Work").checked = false; if (document.getElementById("Other")) document.getElementById("Other").checked = false; if (document.getElementById("Other2")) document.getElementById("Other2").value = ""; if (document.getElementById("Other2")) document.getElementById("Other2").style.visibility = "hidden"; if (document.getElementById("residentialY")) document.getElementById("residentialY").checked = false; if (document.getElementById("residentialN")) document.getElementById("residentialN").checked = false; } } /* ############## END ################# */ /* ######### remove_address ########## # This function gets called when # # remove is clicked next to the # # prev address drop down. # # Used to delete any previously # # used shipping addresses # #################################### */ function remove_address() { sel = document.getElementById("prevShippingAddresses").selectedIndex; selText = document.getElementById("prevShippingAddresses").options[sel].text; var confirm_delete = confirm("Are you sure you want to delete\n" + selText + "\nfrom your saved address list?"); if (confirm_delete) { //document.getElementById("checkOutType").value = "remove_prev_address"; var shippingId = document.getElementById("prevShippingAddresses").value; document.getElementById("removeIt").style.visibility = "visible"; document.getElementById("removeIt").src = "https://www.snapsource.com/store/includes/cart/checkout_remove_address.php?shippingId=" + shippingId; document.getElementById("prevShippingAddresses").remove(sel); previousAdderess(); } } /* ############## END ################# */ /*/ * Caps lock bubble error /*/ var timerRunning = false; // set ertimer to false var myTimer = null; // set myTimer to null function checkCapsLock(e, layer, referer) { var myKeyCode = 0; // initialize key code list var myShiftKey = false; // initialize shift key var // Internet Explorer 4+ if (document.all) { myKeyCode = e.keyCode; myShiftKey = e.shiftKey; // Netscape 4 } else if (document.layers) { myKeyCode = e.which; myShiftKey = ( myKeyCode == 16 ) ? true : false; // Netscape 6 } else if (document.getElementById) { myKeyCode = e.which; myShiftKey = e.shiftKey; }// if // Clear timer if it's still // running when this function // is called again. if (timerRunning) { clearTimeout(myTimer); }//if // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on if (( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey) { putErrorBubbleMsg("Your Caps Lock key is currently set to on. Remember your password is case sensitive. If you have a problem logging in, please turn your Caps Lock key off."); document.getElementById(layer).style.display = 'inline'; document.getElementById(layer).style.top = findPosY(document.getElementById(referer.id), layer, document.getElementById(layer).clientHeight + 2) + "px"; document.getElementById(layer).style.left = findPosX(document.getElementById(referer.id), layer, document.getElementById(layer).clientWidth * .75) + "px"; // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on } else if (( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey) { putErrorBubbleMsg("Your Caps Lock key is currently set to on. Remember your passwordis case sensitive. If you have aproblem logging in please turn your Caps Lock key off."); document.getElementById(layer).style.display = 'inline'; document.getElementById(layer).style.top = findPosY(document.getElementById(referer.id), layer, document.getElementById(layer).clientHeight + 2) + "px"; document.getElementById(layer).style.left = findPosX(document.getElementById(referer.id), layer, document.getElementById(layer).clientWidth * .75) + "px"; } else { document.getElementById(layer).style.display = 'none'; } // hides bubble after 5 seconds myTimer = setTimeout("hideBubble('" + layer + "')", 5000); timerRunning = true; } /*/ *************************************** * Begin Net 30 (credit acount) * Verification *************************************** /*/ function setTableDisplay(items, displayValue, type) { if (!type) { type = 'table-row'; } displayType = (displayValue) ? (navigator.appName == "Netscape") ? type : 'inline' : 'none'; itemArray = items.split(","); for (i = 0; i < itemArray.length; i++) { document.getElementById(itemArray[i]).style.display = displayType; } //end for }