function confirm(ccNo,ccType)
{
   errorStrings = new Array(
      "Check sum passed",                                             //0
      "Invalid card number",                                          //1
      "Invalid card number",                                          //2
      "Invalid card number",                                          //3
      "Invalid card number",                                          //4
      "Invalid card number",                                          //5
      "Invalid card number",                                          //6
      "Invalid card number",                                          //7
      "Invalid card number",                                          //8
      "Invalid card number",                                          //9
      "Credit card number must be at least 13 digits ",               //10
      "Invalid Master Card number",                                   //11
      "Invalid Visa number",                                          //12
      "Invalid American Express Card number",                         //13
      "Invalid Discover Card number",                                 //14
      "Invalid Diner's Club/Carte Blanche number",                    //15
      "Invalid enRoute Card number",                                  //16
      "Invalid JCB Card number",                                      //17
      "Insert return value 18 message here",                          //18
      "Insert return value 19 message here",                          //19
      "Insert return value 20 message here",                          //20
      "Master Card number must be 16 digits",                         //21
      "Visa Card number must be 13 or 16 digits",                     //22
      "American Express Card number must be 15 digits",               //23
      "Discover Card number must be 16 digits",                       //24
      "Diner's Club/Carte Blanche number must be 14 digits",          //25
      "enRoute Card number must be 15 digits",                        //26
      "JCB Card number begining with 3 must be 16 digits",            //27
      "JCB Card number begining with 2131 or 1800 must be 15 digits") //28

   if((reason = verify_cc(ccNo,ccType)) == 0){
      return true;
   }else{
      alert(errorStrings[reason]);
      return false;
   }
}
function verify_cc(inNumber, type) {                     // returns 0 if valid, positive error code if invalid.
   var total = 1*0;
   var tmp = 1*0;

   var number = "";
   // strip the card number string to only numbers...
   for(i = 0; i < inNumber.length; i++){
      if(inNumber.charAt(i) >= "0" && inNumber.charAt(i) <= "9"){
         number = number + inNumber.charAt(i);
      }
   }
   if(number.length < 13) return 10;               // too short for any card
   

   // collect prefix characters for comparison
   var first = "" + number.charAt(0);
   var second = "" + number.charAt(1);
   var third = "" + number.charAt(2);
   var firstTwo = first + second;
   var firstFour = firstTwo + third + number.charAt(3);

   if(type == "MC"){                               // MASTERCARD
      if(first != "5" || second < "1" || second > "5")
         return 11;
      if(number.length != 16)
         return 21;
   }else if(type == "VISA"){                       // VISA
      if(first != "4")
         return 12;
      if(number.length != 13 && number.length != 16)
         return 22;
   }else if(type == "AMEX"){                       // AMERICAN EXPRESS
      if(first != "3" || (second != "4" && second != "7"))
         return 13;
      if(number.length != 15)
         return 23;
   }else if(type == "DISC"){                       // DISCOVER
      if(firstFour != "6011")
         return 14;
      if(number.length != 16)
         return 24;
   }else if(type == "DCCB"){                       // DINERS CLUB/CARTE BLANCHE
      if(firstTwo != "36" && firstTwo != "38" && (firstTwo != "30" || (third < "0" || third > "5"))){
         return 15;
      }
      if(number.length != 14)
         return 25;
   }else if(type == "enRoute"){                    // enROUTE
      if(firstFour != "2014" && firstFour != "2149")
         return 16;
      if(number.length != 15)
         return 26;
      return 0;                                    // no check sum calculation for enRoute
   }
   else if(type == "JCB")                          // JCB
   {
      if(firstFour != "2131" && firstFour != "1800" && (first != "3") )
         return 17;
      if(number.length != 16 && first =="3")
         return 27;
      if(number.length != 15 && first != "3")
         return 28;
   }
   // do the check sum -- LUHN Formula (MOD 10)
   for(loc = number.length - 2; loc >= 0; loc -= 2){
      total += 1 * number.charAt(loc +1);          // collect odd digits from right
      tmp = number.charAt(loc) * 2;                // double even digits from right
      if(tmp > 9) total += 1;                      // if doubled digits are > 9 add individual digit values
      total += tmp%10;
   }
   if(number.length % 2 > 0)
      total += 1 * number.charAt(0);
   return (total % 10);
}

