function strip(num)
	{ // this function removes spaces and illegal characters
	num = "" + num;
	if (!num)
	return "";
	var result = "";
	for (i=0; i<num.length; i++){
	character = num.charAt(i);
	if ("0123456789".indexOf(character) != -1)
	result += character;
	}
	return result;
	}

function CheckCreditCardNumber(f)
{
var cno = strip(f.CreditCardNumber.value);
// get the card number and send it to function strip
// to remove any illegal characters

var msg='The credit card number you entered could not be\n '
+ 'validated. Please check the number and try again.'

//-------------- Check Visa -----------------------\\ 
if (f.CreditCard.value == "Visa")
	{
	if (((cno.length == 13) || (cno.length == 16)) && (cno.substring(0,1) == 4))
		return true
	else
		{
		alert(msg); 
		f.CreditCardNumber.focus();
		return false;
		}
	}


//-------------- Check Mastercard -----------------------\\ 
if (f.CreditCard.value == "Mastercard")
	{
	var firstdig=cno.substring(0,1);
	var seconddig=cno.substring(1,2);
	if (((cno.length == 16) || (cno.length == 19)) && 
		(firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
		return true;
	else
		{
		alert(msg); 
		f.CreditCardNumber.focus();
		return false;
		}
	}


//-------------- Check Diners -----------------------\\
if (f.CreditCard.value == "Diners")
	{ 
	firstdig = cno.substring(0,1);
	seconddig = cno.substring(1,2);
	if (((cno.length == 14) || (cno.length == 17)) && 
		(firstdig == 3) && ((seconddig == 0) ||
		(seconddig == 6) || (seconddig == 8)))
		return true;
	else
		{
		alert(msg); 
		f.CreditCardNumber.focus();
		return false;
		}
	}


//-------------- Check Amex -----------------------\\
if (f.CreditCard.value == "American Express")
	{
	firstdig = cno.substring(0,1);
	seconddig = cno.substring(1,2);
	if (((cno.length == 15) || (cno.length == 18)) && 
		(firstdig == 3) && ((seconddig == 4) || (seconddig == 7))) 
		return true;
	else
		{
		alert(msg); 
		f.CreditCardNumber.focus();
		return false;
		}
	}


//-------------- Check Switch -----------------------\\
if (f.CreditCard.value == "Switch")
	{
	firstdigs = cno.substring(0,6);
	if (((cno.length == 16) &&
		((firstdigs.indexOf('5641') != -1) ||
		(firstdigs.indexOf('6331') != -1) || 
		(firstdigs.indexOf('675964') != -1) ||
		(firstdigs.indexOf('675963') != -1) || 
		(firstdigs.indexOf('4905') != -1))) ||
		((cno.length == 18) && ((firstdigs.indexOf('67594') != -1) ||
		(firstdigs.indexOf('4903') != -1) || 
		(firstdigs.indexOf('4911') != -1))) ||
		((cno.length == 19) && ((firstdigs.indexOf('6333') != -1) ||
		(firstdigs.indexOf('675960') != -1) || 
		(firstdigs.indexOf('67595') != -1) ||
		(firstdigs.indexOf('67590') != -1) || 
		(firstdigs.indexOf('4936') != -1))))
		return true;
	else
		{
		alert(msg); 
		f.CreditCardNumber.focus();
		return false;
		}
	}

return false;
}


