//////////////////////////
//Credit Card Functions//
////////////////////////
function isCC (CCNum,CCType) //is Credit Card Number Function for Dropdown Lists
{
	var cardNumber= CCNum;
	var cctype=	CCType.substring(0,1)
//	var cctype=ucase(left(trim(CCType),1));
	var doesMatch = true;
if ((cctype == "V") && (!isV(cardNumber)))
		doesMatch = false;
if ((cctype == "M") && (!isMC(cardNumber)))
		doesMatch = false;
if ((cctype == "A") && (!isAmex(cardNumber)))
		doesMatch = false;
if ((cctype == "D") && (!isD(cardNumber)))
		doesMatch = false;
if (!doesMatch){
//alert('Invalid Credit Card');
return false;
}
else {return true;}
}

//Visa
function isV(cc)
{
  if (((cc.length == 16) || (cc.length == 13)) &&
      (cc.substring(0,1) == 4))
    return isCreditCard(cc);
  return false;
}
//Master Card
function isMC(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == 5) &&
      ((seconddig >= 1) && (seconddig <= 5)))
    return isCreditCard(cc);
  return false;

}
//AMEX
function isAmex(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == 3) &&
      ((seconddig == 4) || (seconddig == 7)))
    return isCreditCard(cc);
  return false;

}
//Discover
function isD(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;
 }
 //
 function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  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>");
//  alert("Sum      = " + sum);

  if ((sum % 10) == 0){return (true);}
  else{return (false);}

} // END FUNCTION isCreditCard()

function CheckExp(EYear,EMonth){
var date=new Date();
var Nowyear=date.getYear();
var Nowmonth=date.getMonth()+1;
if ((EMonth <= Nowmonth) && (EYear <=Nowyear))
{
//alert('Expiration date has to be in the future');
return false;
}
return true;
}