

function isValidCreditCard(type, ccnum) 
{
   // akash: do a case insensitive match..
   type = type.toLowerCase();

   if (type == "visa") 
   {
      // Visa: length 16, prefix 4, dashes optional.
      var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   } 
   else if (type == "mastercard") 
   {
      // MasterCard: length 16, prefix 51-55, dashes optional.
      var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
      //alert("here");
   } 
   else if (type == "discover") 
   {
      // Discover: length 16, prefix 6011, dashes optional.
      var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
   } 
   else if (type == "american express" || type == "amex") 
   {
      // American Express: length 15, prefix 34 or 37.
      var re = /^3[4,7]\d{13}$/;
   } 
   else if (type == "diners club") 
   {
      // Diners: length 14, prefix 30, 36, or 38.
      var re = /^3[0,6,8]\d{12}$/;
   } 
   else if (type == "carte blanche") 
   {
      // Carte Blanche: Same as Diners Club.
      var re = /^3[0,6,8]\d{12}$/;
   } 
   else if (type == "jcb") 
   {
      // JCB: length 16, prefix 3, dashes optional.
      var re = /^3\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   } 
   else
   {
      // other cards, just do mod 10 check
	  var re = null;
   }
   
   // other cards, just skip this check
   if (re != null)
   {
	 if (!re.test(ccnum)) return false;
   }
   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.
   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
      checksum += parseInt(ccnum.charAt(i-1));
   }
   // Analyze odd digits in even length strings or even digits in odd length strings.
   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }
   if ((checksum % 10) == 0) return true; else return false;
}
/*  ================================================================
    FUNCTION:  isCreditCard(st)
 
    INPUT:     st - a string representing a credit card number

    RETURNS:  true, if the credit card number passes the Luhn Mod-10
		    test.
	      false, otherwise
    ================================================================ */
 

<!--
function isCreditCard(source, arguments) {
  // Encoding only works on cards with less than 19 digits
  st = arguments.Value;
  if (st.length > 19)
    arguments.IsValid = false;

  sum = 0; mul = 1; l = st.length;
  var othernumber = ""
  
  for (i = 0; i < l-1; i++) {
	digit = st.substring(i,i+1);
    othernumber = othernumber + digit
  }
  
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
// Uncomment the following line to help create credit card numbers
// 1. Create a dummy number with a 0 as the last digit
// 2. Examine the sum written out
// 3. Replace the last digit with the difference between the sum and
//    the next multiple of 10.

//  document.writeln("<BR>Sum      = ",sum,"<BR>");
  
  lastdigit = 10 - (sum % 10);
  othernumber = othernumber + "" + lastdigit
  //othernumber = left(othernumber,l-1)
  //othernumber.substring(l-1,l) = 0;

	if (lastdigit != "10") {
	  document.f1.anothernumber.value = othernumber;
	}

  //alert("Sum      = " + sum + ":" + othernumber.substring(l-1,l));

  if ((sum % 10) == 0)
    arguments.IsValid = true;
  else
    arguments.IsValid = false;

} // END FUNCTION isCreditCard()

function AutoTabForward(oFromTextBox,nTriggerLen,oToTextBox)
{
	if (oFromTextBox.value.length >= nTriggerLen)
	{
		//alert(oFromTextBox.value.length);
		oToTextBox.focus();
	}
	
}
function PasswordLengthValid(source, arguments) 
{
	var sPassword = arguments.Value;
	
	if (sPassword.length >= 6)
		arguments.IsValid = true;
	else
		arguments.IsValid = false;
}
function Phone3NumLengthValid(source, arguments) 
{
	var sValue = arguments.Value;
	
	if (sValue.length >= 3)
		if (isNumber(sValue))
			arguments.IsValid = true;
		else
			arguments.IsValid = false;
	else
		arguments.IsValid = false;
}
function Phone4NumLengthValid(source, arguments) 
{
	var sValue = arguments.Value;
	
	if (sValue.length >= 4)
		if (isNumber(sValue))
			arguments.IsValid = true;
		else
			arguments.IsValid = false;
	else
		arguments.IsValid = false;
}
function isNumber(nValue){

	nValue = jsTrim(nValue)
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(nValue))
	{
		testresult=true
	}
	else
	{
		testresult=false
	}
	return (testresult)
}
function jsTrim(strInput)
{
	var strResult;
	var objRegex = new RegExp("(^\\s+)|(\\s+$)");
	strResult = strInput.replace(objRegex, "");
	return(strResult);
}

function VerifyDate(nMonth, nDay, nYear)
{
	var sDate = nMonth + "/" + nDay + "/" + nYear;
	
	var dDate = new Date(sDate);
	var nMonth2 = dDate.getMonth() + 1;
	
	if (nMonth2 == nMonth)
		return true;
	else
		return false;
}


-->
