

	function switchCountry(objStatesId,objCountriesId)
	{

		var ObjDropDown = document.getElementById(objStatesId)
		var index  = ObjDropDown.selectedIndex
		var selValue = ObjDropDown.options[index].value

		if(selValue.indexOf("-") != -1)
		{
			var arr = selValue.split("-");
			var countryId = arr[1];
			var objCountryDropDown = document.getElementById(objCountriesId);
			if (objCountryDropDown.options[objCountryDropDown.selectedIndex].value != countryId)
			{
				
					for(var i=0; i<objCountryDropDown.length; i++)
					{
						if (objCountryDropDown[i].value == countryId)
						{
							objCountryDropDown.selectedIndex = i;
							break;
						}
					}
			}
		}
	}

	
	function isValidNumber(ccTypeId,ccnumId,cFlag)
	{

		var objCctype = document.getElementById(ccTypeId);
		var objCcnum = document.getElementById(ccnumId);

		if( objCctype == null || objCcnum == null){ return false; }
		
		var index = objCctype.selectedIndex
		
		var ccType = objCctype.options[index].value
		var ccnum = objCcnum.value;


		// if the call is made before the credit card number is entered
		// don't raise the alert
		if(cFlag == 1)
		{	if(ccnum == "") 
			return false;
		}

		if ( isValidCreditCard(ccType,ccnum) )
		{
			//alert("valid number");
			return true;
		}
		else
		{

			alert("Number entered is invalid or Type of card card selected is correct.");
			//objCcnum.value=""
			return false;
		}


	}

	function isValidCreditCard(ccType, ccnum)
	{

		/*
		var objCctype = document.getElementsByName(objName);
		var objCcnum = document.getElementById(ccnumId);
		ccType = getCheckedValue(objCctype);
		ccnum = objCcnum.value;
		*/


		if(ccnum.trim == "") return false;
		var re;
		var re13;

		if (ccType == "visa") {
		// Visa: length 16, prefix 4, dashes optional.
			re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
			
			// Visa: length 13, prefix 4, dashes optional.
			re13 = /^4\d{4}-?\d{4}-?\d{4}$/;
			
		} else if (ccType == "mc") {
		// Mastercard: length 16, prefix 51-55, dashes optional.
		re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
		} else if (ccType == "disc") {
		// Discover: length 16, prefix 6011, dashes optional.
		re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
		} else if (ccType == "amex") {
		// American Express: length 15, prefix 34 or 37.
		re = /^3[4,7]\d{13}$/;
		} else if (ccType == "diners") {
		// Diners: length 14, prefix 30, 36, or 38.
		re = /^3[0,6,8]\d{12}$/;
		}


		// validate format for visa 13 digits
		if(ccType == "visa" && ccnum.length < 16 )
		{
		//alert(ccnum.length);
		if (!re13.test(ccnum)) return false;

		}
		else
		{
		// validate format for 16 digit cards
		if (!re.test(ccnum)) return false;
		}

		// Remove all dashes for the checksum checks to eliminate negative numbers
		ccnum = ccnum.split("-").join("");

		// 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;
   
	}
	

