function validate_billing_request(cc_type, cc_number, cc_expiry_date_month,cc_expiry_date_year)
{
	
	cc_expiry_month = cc_expiry_date_month;

	cc_expiry_year = cc_expiry_date_year;

	

	if(cc_type.value=="")

	{

		alert("Please specify 'Credit Card Type'");

		cc_type.focus();

		return false;

	}
	
	if(cc_number.value=="")

	{

		alert("Please enter 'Credit Card Number'");

		cc_number.focus();

		return false;

	}
	
	if(!isValidCC(cc_type.value, cc_number.value))

	{

		alert("Please enter valid 'Credit Card Number'");

		cc_number.select();

		return false;

	}
//alert(cc_expiry_month.value);
	if(cc_expiry_month.value=="")

	{

		alert("Please specify 'Expiration Month'");

		cc_expiry_date_month.focus();

		return false;

	}

	if(cc_expiry_year.value=="")

	{

		alert("Please specify 'Expiration Year'");

		cc_expiry_year.focus();

		return false;

	}

	if(!isFutureDate(cc_expiry_year.value, cc_expiry_month.value))

	{

		alert("Please specify valid 'Expiration Date'");

		cc_expiry_date_month.focus();

		return false;

	}



	return true;

}



function isValidCC(type, ccnum) 

{

	if (type == "Visa" || type == "visa") 

	{

		// Visa: length 16, prefix 4, dashes optional.

		var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;

	}

	else if (type == "MasterCard" || type == "masterCard") 

	{

		// Mastercard: length 16, prefix 51-55, dashes optional.

		var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;

	} 

	else if (type == "Jcb" || type == "jcb") 

	{

		// Mastercard: length 16, prefix 51-55, dashes optional.

		var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;

	} 

	else if (type == "Visaelectron" || type == "visaelectron") 

	{

		// Mastercard: length 16, prefix 51-55, dashes optional.

		var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;

	} 

	else if (type == "Switch" || type == "switch") 

	{

		// Mastercard: length 16, prefix 51-55, dashes optional.

		var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;

	} 

	else if (type == "solo" || type == "solo") 

		{

			// Mastercard: length 16, prefix 51-55, dashes optional.

			var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;

		} 


	else if (type == "Discover" || type == "discover") 

	{

		// Discover: length 16, prefix 6011, dashes optional.

		var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;

	}

	else if (type == "Amex" || type == "amex" ) 

	{

		// American Express: length 15, prefix 34 or 37.

		var re = /^3[4,7]\d{13}$/;

	}

	else if (type == "Diners" || type == "diners") 

	{

		// Diners: length 14, prefix 30, 36, or 38.

		var re = /^3[0,6,8]\d{12}$/;

	}

	else



	{

		if(ccnum.length<16)

		{

			//alert("Please enter valid 'Credit Card Number'");

			//ccnum.select();

			return false;

		}

	}



	if (re.test(ccnum)) 

		return true;

	else

		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 isCharsInBag (s, bag)
{
    var i;
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.
 
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return false;
    }
    return true;
}
function is_NaN(s)
{
	if (isCharsInBag (s, "0123456789") == false)
    {
        return true;
    }
    return false;
}
function isFutureDate(year, month) 

{

	if (is_NaN(year+""))

		return false;

	if (is_NaN(month+""))

		return false;

	today = new Date();

	expiry = new Date(year, month);

	if (today.getTime() > expiry.getTime())

		return false;

	else

		return true;

}



function validateAllCards(cc_type, cc_number, cc_expiry_date)

{

	var len=cc_type.length;

	for(var i=0;i<len;i++){

		return validate_billing_request(cc_type[i], cc_number[i], cc_expiry_date[i]);

	}



//	return false;	



}