	function checkCardType()
	{
		var cc_type;
		var frm1 =document.frmadd;
		if((cc_type=getCardType(frm1.CreditCardNumber.value))==false)
		{
			//lblcc_type.innerText="";
			alert("Please enter a valid card number.")
			frm1.CreditCardNumber.focus();
			return false;
		}
		if (checkCard(cc_type,frm1.CreditCardNumber.value)==false)
		{
			frm1.CreditCardNumber.focus()
			return false
		}
		
		//lblcc_type.innerText=cc_type;
		document.frm1.card_type.value=cc_type;
		return false;
	}
	/*******************************************
	*cadit card validation                      *
	***********************************************/
	function checkcc_numberWithMod10(cc_number) {
		var i;
		var cc = new Array(16);
		var checksum = 0;
		var validcc;
	
		// assign each digit of the card number to a space in the array
		for (i = 0; i < cc_number.length; i++) {
			cc[i] = Math.floor(cc_number.substring(i, i+1));
		}
	
		// walk through every other digit doing our magic
		// if the card number is sixteen digits then start at the
		// first digit (position 0), otherwise start from the
		// second (position 1)
		for (i = (cc_number.length % 2); i < cc_number.length; i+=2) {
			var a = cc[i] * 2;
			if (a >= 10) {
				var aStr = a.toString();
				var b = aStr.substring(0,1);
				var c = aStr.substring(1,2);
				cc[i] = Math.floor(b) + Math.floor(c);
			} else {
				cc[i] = a;
			}
		}
	
		// add up all of the digits in the array
		for (i = 0; i < cc_number.length; i++) {
			checksum += Math.floor(cc[i]);
		}
	
		// if the checksum is evenly divisble by 10
		// then this is a valid card number
		validcc = ((checksum % 10) == 0);
	
		return validcc;
	}
	
	function cleancc_number(cc_number) {
		var i;
		var ch;
		var newCard = "";
	
		// walk through the string character by character to build
		// a new string with numbers only
		i = 0;
		while (i < cc_number.length) {
			// get the current character
			ch = cc_number.substring(i, i+1);
			if ((ch >= "0") && (ch <= "9")) {
				// if the current character is a digit then add it
				// to the numbers-only string we're building
				newCard += ch;
			} else {
				// not a digit, so check if its a dash or a space
				if ((ch != " ") && (ch != "-")) {
					// not a dash or a space so fail
					alert("The card number contains invalid characters.");
					return "";
				}
			}
			i++;
		}
	
		// we got here if we didn't fail, so return what we built
		return newCard;
	}
	
	function getCardType(cc_number)
	{
		var validCard;
		var cardStart;
		var cc_type;
		// clean up any spaces or dashes in the card number
		validCard = cleancc_number(cc_number);
		cardStart = validCard.substring(0,1);
		switch(cardStart)
		{
			case "4" : cc_type ="VISA"; break;
			case "6" : cc_type ="DI"; break;
			case "5" : cc_type ="MC"; break;
			case "3" : cc_type ="AX"; break;
			default  : cc_type =false;
		}	
		return cc_type;											
	
	}
	function checkCard(cc_type, cc_number) {
		var validCard;
		var cardLength;
		var cardLengthOK;
		var cardStart;
		var cardStartOK;
	
		// check if the card type is valid
		if ((cc_type != "VISA") && (cc_type != "MC") && (cc_type != "AX") && (cc_type != "DI") && (cc_type != "Diners") && (cc_type != "JCB")) {
			alert('Please select a card type.' + cc_type);
			return false;
		}
	
		// clean up any spaces or dashes in the card number
		validCard = cleancc_number(cc_number);
		if (validCard != "") {
			// check the first digit to see if it matches the card type
			cardStart = validCard.substring(0,1);
			cardStartOK = ( ((cc_type == "VISA") && (cardStart == "4")) ||
					((cc_type == "DI") && (cardStart == "6")) ||
					((cc_type == "MC") && (cardStart == "5")) ||
					((cc_type == "AX") && (cardStart == "3")) ||
					((cc_type == "Diners") && (cardStart == "3"))	)
			if (!(cardStartOK)) {
				// card number's first digit doesn't match card type
				alert("Please make sure the card number you've entered matched the card type you selected.");
				return false;
			}
	
			// the card number is good now, so check to make sure
			// it's a the right length
			cardLength = validCard.length;
			cardLengthOK = ( ((cc_type == "VISA") && ((cardLength == 13) || (cardLength == 16))) ||
					 ((cc_type == "MC") && (cardLength == 16)) ||
					 ((cc_type == "DI") && (cardLength == 16)) ||
					 ((cc_type == "AX") && (cardLength == 15)) )
			if (!(cardLengthOK)) {
				// not the right length
				alert("Please make sure you've entered all of the digits on your card.");
				return false;
			}
	
			// card number seems OK so do the Mod10
			if (checkcc_numberWithMod10(validCard)) {
				return true;
			} else {
				alert("Please make sure you've entered your card number correctly.");
				return false;
			}
		} else {
			return false;
		}
	}
