1 /* Portions based on [email protected] */ 2 3// DntFnctnVer = '1.10'; 4 5var BillingAddressReq; 6var BillingCityReq; 7var BillingStateReq; 8var BillingZipReq; 9var BillingCountryReq; 10var BillingPhoneReq; 11var skipCC; 12 13function validator(form) { 14if (!validatePaymentOption(form)) return false; 15 document.orderInfo['submitBtn'].disabled=true; 16 document.orderInfo['submitBtn'].value='Submitting...'; 17return true; 18} 19 20// for popup window use 21function openWindow(url) { 22 wndHandle = window.open(url,'500x350','toolbar=yes,status=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,directories=yes,width=500,height=350') 23 wndHandle.focus(); 24} 25 26// basic error checking for field value 27function validateField(fieldID,fieldLabel,fieldType) { 28 var valid = true; 29// console.log(fieldID); 30 var errorMsg = 'The following errors occurred :\n\n'; 31 if(fieldType == 'checkbox' && document.orderInfo.chkAgree.checked == false){ 32 var fieldLength = 0; 33 }else{ 34 var fieldLength = document.getElementById(fieldID).value.length; 35 } 36 if (fieldLength == 0) { 37 errorMsg += "The "+ fieldLabel +" is a required field.\n"; 38 valid = false; 39 } 40 if (!valid) { 41 document.getElementById(fieldID).focus(); 42 alert (errorMsg); 43 } 44 return valid; 45} 46 47 48// basic error checking 49function validateCardNumber() { 50 var valid = true; 51 var errorMsg = 'The following errors occurred :\n\n'; 52 var CardNum = new Number(document.orderInfo.cardnum.value.length); 53 54 if (CardNum < 13 | CardNum > 20) { 55 errorMsg += "The credit card number must be 13 to 20 digits depending on the card type.\n"; 56 valid = false; 57 } 58 if (!valid) { 59 document.orderInfo.cardnum.focus(); 60 alert (errorMsg); 61 } 62 return valid; 63} 64 65// basic error checking 66function validateCardCode() { 67 var valid = true; 68 var errorMsg = 'The following errors occurred :\n\n'; 69 var CardCode = new Number(document.orderInfo.CardCode.value.length); 70 71 if (CardCode < 3 | CardCode > 4) { 72 errorMsg += "The verification code is either 3 or 4 digits.\n"; 73 valid = false; 74 } 75 76 if (!valid) { 77 document.orderInfo.CardCode.focus(); 78 alert (errorMsg); 79 } 80 return valid; 81} 82 83// basic error checking for ABA Routing Number 84function validateRoutingNumber() { 85 var valid = true; 86 var errorMsg = 'The following errors occurred :\n\n'; 87 var ABARoutingNumber = new Number(document.orderInfo.chkRouting.value.length); 88 89 if (ABARoutingNumber == 0) { 90 errorMsg += "The Routing Number cannot be blank.\n"; 91 valid = false; 92 } else if (ABARoutingNumber != 9) { 93 errorMsg += "The Routing Number must be 9 digits.\n"; 94 valid = false; 95 } 96 if (!valid) { 97 document.orderInfo.chkRouting.focus(); 98 alert (errorMsg); 99 } 100 return valid; 101} 102 103// basic error checking for Bank name 104function validateBankName() { 105 var valid = true; 106 var errorMsg = 'The following errors occurred :\n\n'; 107 var bankName = document.orderInfo.BankName.value.length; 108 109 if (bankName == 0) { 110 errorMsg += "The bank name cannot be blank.\n"; 111 valid = false; 112 } 113 if (!valid) { 114 document.orderInfo.BankName.focus(); 115 alert (errorMsg); 116 } 117 return valid; 118} 119 120// basic error checking for account number 121function validateAccountNumber() { 122 var valid = true; 123 var errorMsg = 'The following errors occurred :\n\n'; 124 var bankName = document.orderInfo.chkAccount.value.length; 125 126 if (bankName == 0) { 127 errorMsg += "The account number cannot be blank.\n"; 128 valid = false; 129 } 130 if (!valid) { 131 document.orderInfo.chkAccount.focus(); 132 alert (errorMsg); 133 } 134 return valid; 135} 136 137// basic error checking for account name 138function validateAccountName() { 139 var valid = true; 140 var errorMsg = 'The following errors occurred :\n\n'; 141 var bankName = document.orderInfo.AccountName.value.length; 142 143 if (bankName == 0) { 144 errorMsg += "The account name cannot be blank.\n"; 145 valid = false; 146 } 147 if (!valid) { 148 document.orderInfo.AccountName.focus(); 149 alert (errorMsg); 150 } 151 return valid; 152} 153 154// basic error checking for email address 155function validateEmailAddress() { 156 var valid = true; 157 var errorMsg = 'The following errors occurred :\n\n'; 158 var emailAddress = document.orderInfo.PayPalEmailAddress.value.length; 159 160 if (emailAddress == 0) { 161 errorMsg += "The paypal email address cannot be blank.\n"; 162 valid = false;
163 } 164 if (!valid) { 165 document.orderInfo.PayPalEmailAddress.focus(); 166 alert (errorMsg); 167 } 168 return valid; 169} 170 171// When the user wants to use the ECheck payment option, the credit 172// card fields are cleared... 173function clearCardFields() 174{ 175 176 if ( 177 ( 178 (document.orderInfo.UsingECheck != null) && 179 (document.orderInfo.UsingECheck.checked == true) 180 ) 181 || 182 ( 183 (document.orderInfo.UsingPayPal != null) && 184 (document.orderInfo.UsingPayPal.checked == true) 185 ) 186 ) 187 { 188 document.orderInfo.cardnum.value = ""; 189 document.orderInfo.ExpMonth.selectedIndex = 0; 190 document.orderInfo.ExpYear.selectedIndex = 0; 191 document.orderInfo.CardCode.value = ""; 192 } 193 194} 195 196// When the user wants does not use the ECheck payment option, the ECheck 197// fields are cleared... 198function clearECheckFields() 199{ 200 if (document.orderInfo.UsingECheck.checked == false) 201 { 202 document.orderInfo.ABARoutingNumber.value = ""; 203 document.orderInfo.BankName.value = ""; 204 document.orderInfo.AccountNumber.value = ""; 205 document.orderInfo.AccountType.selectedIndex = 0; 206 document.orderInfo.AccountName.value = ""; 207 208 document.orderInfo.TaxID_SSN.value = ""; 209 document.orderInfo.LicenseNum.value = ""; 210 document.orderInfo.LicenseState.value = ""; 211 document.orderInfo.LicenseDOB.value = ""; 212 213 } 214} 215 216// This function enables the ECheck section fields. By default the 217// ECheck section fields are disabled. 218function enableECheckFields() 219{ 220 if (document.orderInfo.UsingECheck.checked == true) 221 { 222 document.orderInfo.ABARoutingNumber.disabled = false; 223 document.orderInfo.BankName.disabled = false; 224 document.orderInfo.AccountNumber.disabled = false; 225 document.orderInfo.AccountType.disabled = false; 226 document.orderInfo.AccountName.disabled = false; 227 228 document.orderInfo.OrganizationType.disabled = false; 229 document.orderInfo.Tax_ID.disabled = false; 230 document.orderInfo.DriverLicense.disabled = false; 231 document.orderInfo.TaxID_SSN.disabled = false; 232 } 233} 234 235// This function disables the License section fields when Tax_ID/SSN 236//Radio button is checked. By default the TAX_ID/SSN fields are enabled. 237function disableLicenseFields() 238{ 239 if (document.orderInfo.UsingECheck.checked == true) { 240 if(document.orderInfo.DriverLicense.checked == false) 241 { 242 document.orderInfo.TaxID_SSN.disabled = false; 243 document.orderInfo.LicenseNum.disabled = true; 244 document.orderInfo.LicenseState.disabled = true; 245 document.orderInfo.LicenseDOB.disabled = true; 246 247 document.orderInfo.LicenseNum.value = ""; 248 document.orderInfo.LicenseState.value = ""; 249 document.orderInfo.LicenseDOB.value = ""; 250 } 251 } 252} 253 254// This function enables the License section fields when Driver's License Details 255//Radio button is checked. By default the License section fields are disabled. 256function enableLicenseFields() 257{ 258 if (document.orderInfo.UsingECheck.checked == true) { 259 if (document.orderInfo.DriverLicense.checked == true) 260 { 261 document.orderInfo.TaxID_SSN.disabled = true; 262 document.orderInfo.LicenseNum.disabled = false; 263 document.orderInfo.LicenseState.disabled = false; 264 document.orderInfo.LicenseDOB.disabled = false; 265 266 document.orderInfo.TaxID_SSN.value = ""; 267 } 268 } 269} 270 271// When the user wants does not use the PayPal payment option, the PayPal 272// fields are cleared... 273function clearPayPalFields() 274{ 275 if (document.orderInfo.UsingPayPal.checked == false) 276 { 277 document.orderInfo.PayPalEmailAddress.value = ""; 278 279 document.orderInfo.PayPalEmailAddress.disabled = true; 280 281 document.orderInfo.action = "process_payment.php"; 282 } 283} 284 285// This function enables the PayPal section fields. By default the 286// PayPal section fields are disabled. 287function enablePayPalFields() 288{ 289 if (document.orderInfo.UsingPayPal.checked == true) 290 { 291 document.orderInfo.PayPalEmailAddress.disabled = false; 292 293 document.orderInfo.action = "process_payment_paypal.php"; 294 295 } 296} 297 298// Shipping information is the same as billing information 299function CopyBillingInfo() 300{ 301 if (document.orderInfo.same_as_billing.checked == false) 302 { 303 document.orderInfo.same_as_billing.value = "0"; 304 document.orderInfo.ShipAddress.value = ""; 305 document.orderInfo.ShipCity.value = ""; 306 document.orderInfo.ShipState.selectedIndex = 0; 307 document.orderInfo.ShipZip.value = ""; 308 document.orderInfo.ShipCountry.selectedIndex = 0; 309 } else { 310 document.orderInfo.same_as_billing.value = "1"; 311 document.orderInfo.ShipAddress.value = document.orderInfo.BillAddress.value; 312 document.orderInfo.ShipCity.value = document.orderInfo.BillCity.value; 313 document.orderInfo.ShipState.selectedIndex = document.orderInfo.BillState.selectedIndex; 314 document.orderInfo.ShipZip.value = document.orderInfo.BillZip.value; 315 document.orderInfo.ShipCountry.selectedIndex = document.orderInfo.BillCountry.selectedIndex; 316 } 317} 318 319// Format Total 320function formatorderAmount(orderAmount) 321{ 322 orderAmount = orderAmount.toString().replace(/\$|\,/g,''); 323 if(isNaN(orderAmount)) orderAmount = "0"; 324 sign = (orderAmount == (orderAmount = Math.abs(orderAmount))); 325 orderAmount = Math.floor(orderAmount*100+0.50000000001); 326 cents = orderAmount%100; 327 orderAmount = Math.floor(orderAmount/100).toString(); 328 if (cents < 10) cents = "0" + cents; 329 for (var i = 0; i < Math.floor((orderAmount.length-(1+i))/3); i++) 330 orderAmount = orderAmount.substring(0,orderAmount.length-(4*i+3))+','+ 331 orderAmount.substring(orderAmount.length-(4*i+3)); 332 return (((sign)?'':'-') + orderAmount + '.' + cents); 333} 334 335 336/*************************************************************************\ 337 validatePaymentOption(form) 338 function that delegates the validation to the the appropriate 339 function based on the payment option selected 340 341\*************************************************************************/ 342function validatePaymentOption(form) { 343 344 if (form.UsingECheck != null) { 345 if (form.UsingECheck.checked == true) { 346 return CheckECheck(form); 347 } 348 } 349 350 if (form.UsingPayPal != null) { 351 if(form.UsingPayPal.checked == true) { 352 return CheckPayPal(form); 353 } 354 } 355 356 return CheckCardNumber(form); 357} 358 359/*************************************************************************\ 360 CheckPayPal(form) 361 362\*************************************************************************/ 363function CheckPayPal(form) { 364 var validEmailAddress = false;
365 366 validEmailAddress = validateEmailAddress(); 367 if (!validEmailAddress) 368 { 369 return false; 370 } 371 372 return true; 373} 374 375/*************************************************************************\ 376 CheckECheck(form) 377 378\*************************************************************************/ 379function CheckECheck(form) { 380 var validABARoutingNumber = false; 381 var validBankName = false; 382 var validAccountNumber = false; 383 var validAccountName = false; 384 385 validABARoutingNumber = validateRoutingNumber(); 386 if (!validABARoutingNumber) { 387 return false; 388 } 389 390 validBankName = validateBankName(); 391 if (!validBankName) { 392 return false; 393 } 394 395 validAccountNumber = validateAccountNumber(); 396 if (!validAccountNumber) { 397 return false; 398 } 399 400 validAccountName = validateAccountName(); 401 if (!validAccountName) { 402 return false; 403 } 404 405 return true; 406 407} 408 409/*************************************************************************\ 410 CheckCardNumber(form) 411 function called when users click the "check" button. 412 413\*************************************************************************/ 414function CheckCardNumber(form) { 415 var validCardNumber = false; 416 var validCardCode = false;
417 418 419 var validFields = false; 420 validFields = validateRequiredFields(); 421 if(!validFields) { 422 return false; 423 } 424 425 426/* if(form.chargenow != null) { 427 if(form.chargenow[0].checked == 0) { 428 return true; 429 } 430 } 431*/ 432 433// if chargenow is 0 skip the rest of the function 434if((document.orderInfo.chargenow.length && document.orderInfo.chargenow[0].type =='radio') || document.orderInfo.chargenow.type =='radio'){ 435 for (var i=0; i < document.orderInfo.chargenow.length; i++) { 436 if (document.orderInfo.chargenow[i].checked) { 437 var chargenow = document.orderInfo.chargenow[i].value; 438 } 439 if(chargenow != null) { 440 if(chargenow == 0){ 441 return true; 442 } 443 } 444 } 445// }else{ //if(document.orderInfo.chargenow.type =='text') { 446// if(document.orderInfo.chargenow.value == 0){ 447// return true; 448// } 449 } 450 451 if (typeof form.chargeType !== "undefined" && form.chargeType.value == 'Check:Sale') { 452 // SKIP CC Check & Check for Check Fields 453 if (!validateRoutingNumber()) return false; 454 if (!validateField('chkAccount','Account Number','')) return false; 455 if (!validateField('chkType','Account Type','')) return false; 456 if (!validateField('chkAgree','Authorization Checkbox','checkbox')) return false; 457 return true; 458 } 459 460 if (skipCC == 1 || gateway == "stripe") { 461 return true; // SKIP CC Check 462 } 463 464 validCardNumber = validateCardNumber(); 465 if (!validCardNumber) { 466 return false; 467 } 468 469 validCardCode = validateCardCode(); 470 if (!validCardCode) { 471 return false; 472 } 473 474 var tmpyear; 475 if (form.cardnum.value.length == 0) { 476 alert("The following errors occurred :\n\nPlease enter a Card Number."); 477 form.cardnum.focus(); 478 //return; 479 return false; 480 } 481 if (form.ExpYear.value.length == 0) { 482 alert("The following errors occurred :\n\nPlease enter the Expiration Year."); 483 form.ExpYear.focus(); 484 //return; 485 return false; 486 } 487 if (form.ExpYear.value > 96) 488 tmpyear = "19" + form.ExpYear.value; 489 else if (form.ExpYear.value < 81) 490 tmpyear = "20" + form.ExpYear.value; 491 else { 492 alert("The following errors occurred :\n\nThe Expiration Year is not valid."); 493 return false; 494 } 495 496 tmpmonth = form.ExpMonth.options[form.ExpMonth.selectedIndex].value; 497 // The following line doesn't work in IE3, you need to change it 498 // to something like "(new CardType())...". 499 // if (!CardType().isExpiryDate(tmpyear, tmpmonth)) { 500 if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) { 501 alert("The following errors occurred :\n\nThis card has already expired."); 502 //return; 503 form.ExpYear.focus(); 504 return false; 505 } 506 card = form.CardType.options[form.CardType.selectedIndex].value; 507 if(!card){ 508 alert("Invalid Card Type."); 509 form.CardType.focus(); 510 return false; 511 } 512 card_ = eval(card + ".getCardType()"); 513 514 var retval = eval(card + ".checkCardNumber(\"" + form.cardnum.value + "\", " + tmpyear + ", " + tmpmonth + ");"); 515 516 cardname = ""; 517 518 if (retval) 519 return true; 520 else { 521 // The cardnumber has the valid luhn checksum, but we want to know which 522 // cardtype it belongs to. 523 for (var n = 0; n < Cards.size; n++) { 524 if (Cards[n].checkCardNumber(form.cardnum.value, tmpyear, tmpmonth)) { 525 cardname = Cards[n].getCardType(); 526 break; 527 } 528 } 529 if (cardname.length > 0) { 530 alert("The following errors occurred :\n\nThis looks like a " + cardname + " number, not a " + card_ + " number."); 531 form.CardType.focus(); 532 } 533 else { 534 alert("The following errors occurred :\n\nThis card number is not valid. Please recheck your card number. Do not use any dashes or spaces."); 535 form.cardnum.focus(); 536 } 537 538 } 539 return false; 540} 541 542/*************************************************************************\ 543 Object CardType([String cardtype, String rules, String len, int year, int month]) 544 cardtype : type of card, eg: MasterCard, Visa, etc. 545 rules : rules of the cardnumber, eg: "4", "6011", "34,37". 546 len : valid length of cardnumber, eg: "16,19", "13,16". 547 year : year of expiry date. 548 month : month of expiry date. 549 eg: 550 var VisaCard = new CardType("Visa", "4", "16");
551 var AmExCard = new CardType("AmEx", "34,37", "15"); 552 553\*************************************************************************/ 554function CardType() { 555 var n; 556 var argv = CardType.arguments; 557 var argc = CardType.arguments.length; 558 559 this.objname = "object CardType"; 560 561 var tmpcardtype = (argc > 0) ? argv[0] : "CardObject"; 562 var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9"; 563 var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19"; 564 565 this.setCardNumber = setCardNumber; // set CardNumber method. 566 this.setCardType = setCardType; // setCardType method. 567 this.setLen = setLen; // setLen method. 568 this.setRules = setRules; // setRules method. 569 this.setExpiryDate = setExpiryDate; // setExpiryDate method. 570 571 this.setCardType(tmpcardtype); 572 this.setLen(tmplen); 573 this.setRules(tmprules); 574 if (argc > 4) 575 this.setExpiryDate(argv[3], argv[4]); 576 577 this.checkCardNumber = checkCardNumber; // checkCardNumber method. 578 this.getExpiryDate = getExpiryDate; // getExpiryDate method. 579 this.getCardType = getCardType; // getCardType method. 580 this.isCardNumber = isCardNumber; // isCardNumber method. 581 this.isExpiryDate = isExpiryDate; // isExpiryDate method. 582 this.luhnCheck = luhnCheck;// luhnCheck method. 583 return this; 584} 585 586// Updated version to check cardType and update the value 587// based on https://stackoverflow.com/questions/72768/ 588function checkCardType(number) 589{ 590 var curCardType; 591 // visa 592 var re = new RegExp("^4"); 593 if (number.match(re) != null) 594 curCardType = "VISA"; 595 596 // Mastercard 597 // Updated for Mastercard 2017 BINs expansion 598 if (/^(5[1-5][0-9]{14}|2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12}))$/.test(number)) 599 curCardType = "MASTERCARD"; 600 601 // AMEX 602 re = new RegExp("^3[47]"); 603 if (number.match(re) != null) 604 curCardType = "AMERICANEXPRESS"; 605 606 // Discover 607 re = new RegExp("^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)"); 608 if (number.match(re) != null) 609 curCardType = "DISCOVER"; 610 611 // Diners 612 re = new RegExp("^36"); 613 if (number.match(re) != null) 614 curCardType = "Diners"; 615 616 // Diners - Carte Blanche 617 re = new RegExp("^30[0-5]"); 618 if (number.match(re) != null) 619 curCardType = "Diners - Carte Blanche"; 620 621 // JCB 622 re = new RegExp("^35(2[89]|[3-8][0-9])"); 623 if (number.match(re) != null) 624 curCardType = "JCB"; 625 626 // Visa Electron 627 re = new RegExp("^(4026|417500|4508|4844|491(3|7))"); 628 if (number.match(re) != null) 629 curCardType = "Visa Electron"; 630 631 var CardType = document.getElementById('CardType'); 632 633 var opts = CardType.options; 634 for (var opt, j = 0; opt = opts[j]; j++) { 635 if (opt.value == curCardType) { 636 CardType.selectedIndex = j; 637 break; 638 } 639 } 640 // console.log(curCardType + number) 641} 642 643/*************************************************************************\ 644 boolean checkCardNumber([String cardnumber, int year, int month]) 645 return true if cardnumber pass the luhncheck and the expiry date is 646 valid, else return false. 647 648\*************************************************************************/ 649function checkCardNumber() { 650 651 var argv = checkCardNumber.arguments; 652 var argc = checkCardNumber.arguments.length; 653 var cardnumber = (argc > 0) ? argv[0] : this.cardnumber; 654 var year = (argc > 1) ? argv[1] : this.year; 655 var month = (argc > 2) ? argv[2] : this.month; 656 657 this.setCardNumber(cardnumber); 658 this.setExpiryDate(year, month); 659 660 if (!this.isCardNumber()) 661 return false; 662 if (!this.isExpiryDate()) 663 return false; 664 665 return true; 666} 667 668/*********************************************************************** 669**\ 670 String getCardType() 671 return the cardtype. 672 673\*********************************************************************** 674**/ 675function getCardType() { 676 return this.cardtype; 677} 678 679/*************************************************************************\ 680 String getExpiryDate() 681 return the expiry date. 682 683\*************************************************************************/ 684function getExpiryDate() { 685 return this.month + "/" + this.year; 686} 687 688/*************************************************************************\ 689 boolean isCardNumber([String cardnumber]) 690 return true if cardnumber pass the 691 luhncheck and the rules, else return false. 692 693\*************************************************************************/ 694function isCardNumber() { 695 var argv = isCardNumber.arguments; 696 var argc = isCardNumber.arguments.length; 697 var cardnumber = (argc > 0) ? argv[0] : this.cardnumber; 698 699 if (!this.luhnCheck()) 700 return false;
701 702 for (var n = 0; n < this.len.size; n++) 703 if (cardnumber.toString().length == this.len[n]) { 704 for (var m = 0; m < this.rules.size; m++) 705 { 706 var headdigit = cardnumber.substring(0, this.rules[m].toString().length); 707 if (headdigit == this.rules[m]) 708 return true; 709 } 710 return false; 711 } 712 return false; 713} 714 715 716/*************************************************************************\ 717 boolean isExpiryDate([int year, int month]) 718 return true if the date is a valid expiry date, 719 else return false. 720 721\*************************************************************************/ 722function isExpiryDate() { 723 724 var argv = isExpiryDate.arguments; 725 var argc = isExpiryDate.arguments.length; 726 727 year = argc > 0 ? argv[0] : this.year; 728 month = argc > 1 ? argv[1] : this.month; 729 730 if (!isNum(year+"")) 731 return false; 732 if (!isNum(month+"")) 733 return false; 734 today = new Date(); 735 expiry = new Date(year, month); 736 if (today.getTime() > expiry.getTime()) 737 return false; 738 else 739 return true; 740} 741 742 743/*************************************************************************\ 744 boolean isNum(String argvalue) 745 return true if argvalue contains only numeric characters, 746 else return false. 747 748\*************************************************************************/ 749function isNum(argvalue) { 750 argvalue = argvalue.toString(); 751 752 if (argvalue.length == 0) 753 return false; 754 755 for (var n = 0; n < argvalue.length; n++) 756 if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9") 757 return false; 758 759 return true; 760} 761 762 763/*************************************************************************\ 764 boolean luhnCheck([String CardNumber]) 765 return true if CardNumber pass the luhn check else return false. 766 Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl 767 768\*************************************************************************/ 769function luhnCheck() { 770 var argv = luhnCheck.arguments; 771 var argc = luhnCheck.arguments.length; 772 773 var CardNumber = argc > 0 ? argv[0] : this.cardnumber; 774 775 if (! isNum(CardNumber)) { 776 return false; 777 } 778 779 var no_digit = CardNumber.length; 780 var oddoeven = no_digit & 1; 781 var sum = 0; 782 783 for (var count = 0; count < no_digit; count++) { 784 var digit = parseInt(CardNumber.charAt(count)); 785 if (!((count & 1) ^ oddoeven)) { 786 digit *= 2; 787 if (digit > 9) 788 digit -= 9; 789 } 790 sum += digit; 791 } 792 if (sum % 10 == 0) 793 return true; 794 else 795 return false; 796} 797 798 799/*************************************************************************\ 800 ArrayObject makeArray(int size) 801 return the array object in the size 802specified. 803 804\*************************************************************************/ 805function makeArray(size) { 806 this.size = size; 807 return this; 808} 809 810 811/*************************************************************************\ 812 CardType setCardNumber(cardnumber) 813 return the CardType object. 814 815\*************************************************************************/ 816function setCardNumber(cardnumber) { 817 this.cardnumber = cardnumber; 818 return this; 819} 820 821 822/*************************************************************************\ 823 CardType setCardType(cardtype) 824 return the CardType object. 825 826\*************************************************************************/ 827function setCardType(cardtype) { 828 this.cardtype = cardtype; 829 return this; 830} 831 832 833/*************************************************************************\ 834 CardType setExpiryDate(year, month) 835 return the CardType object. 836 837\*************************************************************************/ 838function setExpiryDate(year, month) {
839 this.year = year; 840 this.month = month; 841 return this; 842} 843 844 845/*************************************************************************\ 846 CardType setLen(len) 847 return the CardType object. 848 849\*************************************************************************/ 850function setLen(len) { 851 // Create the len array. 852 if (len.length == 0 || len == null) 853 len = "13,14,15,16,19"; 854 855 var tmplen = len; 856 n = 1; 857 while (tmplen.indexOf(",") != -1) { 858 tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length); 859 n++; 860 } 861 this.len = new makeArray(n); 862 n = 0; 863 while (len.indexOf(",") != -1) { 864 var tmpstr = len.substring(0, len.indexOf(",")); 865 this.len[n] = tmpstr; 866 len = len.substring(len.indexOf(",") + 1, len.length); 867 n++; 868 } 869 this.len[n] = len; 870 return this; 871} 872 873 874/*************************************************************************\ 875 CardType setRules() 876 return the CardType object. 877 878\*************************************************************************/ 879function setRules(rules) { 880 // Create the rules array. 881 if (rules.length == 0 || rules == null) 882 rules = "0,1,2,3,4,5,6,7,8,9"; 883 884 var tmprules = rules; 885 n = 1; 886 while (tmprules.indexOf(",") != -1) { 887 tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length); 888 n++; 889 } 890 this.rules = new makeArray(n); 891 n = 0; 892 while (rules.indexOf(",") != -1) { 893 var tmpstr = rules.substring(0, rules.indexOf(",")); 894 this.rules[n] = tmpstr; 895 rules = rules.substring(rules.indexOf(",") + 1, rules.length); 896 n++; 897 } 898 this.rules[n] = rules; 899 return this; 900} 901// End --> 902 903 904 905/*************************************************************************\ 906 isThereCC() 907 return CCinfo in and user doesn't click use credit card. 908 909\*************************************************************************/ 910function isThereCC(cclen) { 911 if (cclen != 0) 912 { 913 alert("Please Clear Card Number or click Pay with Credit Card Button."); 914 return false; 915 } 916} 917 918/*************************************************************************\ 919 checkName() 920 return True or False based on the name value. 921 922\*************************************************************************/ 923 924 function checkRegex(object_value, regex) { 925 return regex.test(object_value); 926} 927 928function CheckPhoneNumber(TheNumber) { 929 var valid = 1 930 var GoodChars = "0123456789()-+. " 931 var i = 0 932if (TheNumber=="") { 933return false; 934 } 935for (i =0; i <= TheNumber.length -1; i++) { 936if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) { 937return false; 938} 939 } 940return true; 941} 942 943 944function validateRequiredFields() { 945 var isValid = true; 946 var errorMsg = 'Please Fill the Following Required Fields\n'; 947 // check if Amount is Empty 948 var OrderTotalLength = document.orderInfo.OrderTotal.value.length; 949 var OrderTotal = document.orderInfo.OrderTotal.value; 950 if(OrderTotalLength == 0 || (OrderTotal == 0 && ZeroTotalCheck==1)) 951 { 952 errorMsg += ' Dollar Amount\n'; 953 isValid = false; 954 } 955 // check if FirstName is Empty 956 var firstName = document.orderInfo.FirstName.value.length; 957 if(firstName == 0) 958 { 959 errorMsg += ' First Name\n'; 960 isValid = false; 961 } 962 // check if LastName is Empty 963 var lastName = document.orderInfo.LastName.value.length; 964 if(lastName == 0) 965 { 966 errorMsg += ' Last Name\n'; 967 isValid = false; 968 } 969 // check if CompanyName is Empty 970 var isCompNameReq = document.orderInfo.CompanyName.id; 971 if( isCompNameReq == "CompanyNameReq") 972 { 973 var companyName = document.orderInfo.CompanyName.value.length; 974 if(companyName == 0) 975 { 976 errorMsg += ' Company Name\n'; 977 isValid = false; 978 } 979 } 980 // check if PhoneNumber is Empty 981 var phoneNum = document.orderInfo.Phone.value.length; 982 if(phoneNum == 0 && BillingPhoneReq != 0) 983 { 984 errorMsg += ' Phone Number\n'; 985 isValid = false; 986 } 987 988 if ((phoneNum != 0) && (!CheckPhoneNumber(document.orderInfo.Phone.value))) 989 { 990 errorMsg += ' A Valid Phone Number\n'; 991 isValid = false;
992 } 993 994 995 // check if EmailAddress is Empty 996 var eMail = document.orderInfo.EmailAddress.value.length; 997 if(eMail == 0) 998 { 999 errorMsg += ' Email Address\n'; 1000 isValid = false; 1001 } 1002 if ((eMail != 0) && (!checkRegex(document.orderInfo.EmailAddress.value.trim(), /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/))) 1003 { 1004 errorMsg += ' a VALID e-mail address\n'; 1005 isValid = false; 1006 } 1007 1008 // check if Billing Address is Empty 1009 var address = document.orderInfo.BillAddress.value.length; 1010 if(address == 0 && BillingAddressReq != 0) 1011 { 1012 errorMsg += ' Billing Address\n'; 1013 isValid = false; 1014 } 1015 // check if Billing City is Empty 1016 var bCity = document.orderInfo.BillCity.value.length; 1017 if(bCity == 0 && BillingCityReq != 0) 1018 { 1019 errorMsg += ' Billing City\n'; 1020 isValid = false; 1021 } 1022 // check if Billing State is Empty 1023 var bState = document.orderInfo.BillState.value.length; 1024 if(bState == 0 && BillingStateReq != 0) 1025 { 1026 errorMsg += ' Billing State\n'; 1027 isValid = false; 1028 } 1029 // check if Billing ZipCode is Empty 1030 var bZip = document.orderInfo.BillZip.value.length; 1031 if(bZip == 0 && BillingZipReq != 0) 1032 { 1033 errorMsg += ' Billing ZipCode\n'; 1034 isValid = false; 1035 } 1036 1037 // check if Billing Country is Empty 1038 var bCountry = document.orderInfo.BillCountry.value.length;
1039 if(bCountry == 0 && BillingCountryReq != 0) 1040 { 1041 errorMsg += ' Billing Country\n'; 1042 isValid = false; 1043 } 1044 if(!isValid) 1045 { 1046 alert(errorMsg); 1047 } 1048 return isValid; 1049} 1050 1051// Moved from dnt_main 6/29/18 1052function updateTotals(){ 1053 1054 var total = 0; 1055 var price = 0; 1056 var y = 0; 1057 var product; 1058 var freequantity = 0; 1059 var freetotal = 0; 1060 var freetotals = new Object; 1061 1062 for (var x = 0; x < totaltickets; x ++) { 1063 if (document.orderInfo.elements[y].type == 'checkbox'){ 1064 if (document.orderInfo.elements[y].checked == 1){ 1065 quantity = parseInt(document.orderInfo.elements[y].value); 1066 if (isNaN(quantity)) { quantity = 0; } 1067 }else{ 1068 quantity = 0; 1069 } 1070 }else{ 1071 // quantity = parseInt(document.orderInfo.elements[y].value); 1072 var CurQty = document.orderInfo.elements[y].value; 1073 var FrmtQty = CurQty.replace(/,/g,''); 1074 document.orderInfo.debug.value = document.orderInfo.debug.value + ' ' + FrmtQty; 1075 quantity = parseFloat(FrmtQty); 1076 1077 if (isNaN(quantity)) { quantity = 0; } 1078 } 1079 product = document.orderInfo.elements[y+3].value; 1080 //alert((x + 1) + ' gives ' + product); 1081 freequantity = parseFloat(document.orderInfo.elements[y+4].value); 1082 if (product != null && !(isNaN(freequantity))){ 1083 freequantity *= quantity; 1084 //alert (freequantity); 1085 //alert(freequantity - (freequantity % 1)); 1086 freequantity = freequantity - (freequantity % 1); 1087 if (freetotals[product] != null){ 1088 freequantity += freetotals[product]; 1089 } 1090 freetotals[product] = freequantity; 1091 } 1092 1093 var CurPrice = document.orderInfo.elements[y+2].value 1094 var FrmtPrice = CurPrice.replace(/,/g,''); 1095 price = parseFloat(FrmtPrice); 1096 if (isNaN(price)) { price = 0; } 1097 document.orderInfo.elements[y+1].value = formatorderAmount(price * quantity); 1098 //y = y + 3; 1099 y = y + 5; 1100 total += price * quantity; 1101 } 1102 1103 1104 y = 0; 1105 for (var x = 0; x < totaltickets; x ++) { 1106 if (document.orderInfo.elements[y].type == 'checkbox'){ 1107 if (document.orderInfo.elements[y].checked == 1){ 1108 quantity = parseInt(document.orderInfo.elements[y].value); 1109 if (isNaN(quantity)) { quantity = 0; } 1110 }else{ 1111 quantity = 0 1112 if (isNaN(quantity)) { quantity = 0; } 1113 } 1114 }else{ 1115 quantity = parseInt(document.orderInfo.elements[y].value); 1116 if (isNaN(quantity)) { quantity = 0; } 1117 } 1118 product = document.orderInfo.elements[y].name; 1119 //alert(y); 1120 //alert(product); 1121 if (product != null){ 1122 freequantity = freetotals[product]; 1123 if (!(isNaN(freequantity))){ 1124 if (freequantity > quantity){ 1125 freequantity = quantity; 1126 } 1127 price = parseFloat(document.orderInfo.elements[y+2].value); 1128 freetotal += (price * freequantity); 1129 } 1130 //alert('from ' + y); 1131 y = y + 5; 1132 //alert('up to ' + y); 1133 } 1134 } 1135 //document.orderInfo.OrderTotal.value = formatorderAmount(total); 1136 document.orderInfo.OrderTotal.value = formatorderAmount(total - freetotal); 1137 } 1138 1139 var Cards = new makeArray(5); 1140 Cards[0] = new CardType("MASTERCARD", "51,52,53,54,55", "16"); 1141 var MASTERCARD = Cards[0]; 1142 Cards[1] = new CardType("VISA", "4", "13,16"); 1143 var VISA = Cards[1]; 1144 Cards[2] = new CardType("AMERICAN EXPRESS", "34,37", "15"); 1145 var AMERICANEXPRESS = Cards[2]; 1146 Cards[3] = new CardType("DISCOVER", "6011", "16"); 1147 var DISCOVER = Cards[3]; 1148 Cards[4] = new CardType("DINER'S CLUB", "30,36,38", "14"); 1149 var DINERSCLUB = Cards[4]; 1150 1151 var LuhnCheckSum = Cards[7] = new CardType(); 1152 1153function CheckMinimum(){ 1154 var curOrderTotalClean = document.orderInfo.OrderTotal.value.replace(/\,/g,''); 1155 var curOrderTotal = document.orderInfo.OrderTotal.value; 1156 var message = ''; 1157 if ((Number(curOrderTotalClean) < Number(CheckMinimumAmount)) || isNaN(curOrderTotalClean)) 1158 message += '- A minimum amount of $'+CheckMinimumAmount+' is required\n'; 1159 if (curOrderTotal.substring(curOrderTotal.length-3,curOrderTotal.length-2) == ",") 1160 message += '- The amount is not in a correct format. Please use the format 0.00 \n'; 1161 if (message !=''){ 1162 alert('Warning:\n'+message); 1163 document.orderInfo.OrderTotal.value = ''; 1164 return false; 1165 } 1166 else 1167 return true; 1168}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.