	
	    function BackClicked(){
		    var oForm = document.forms[0];			
		    var elmtBackClicked = oForm.elements("hidBackClicked")	
		    elmtBackClicked.value="1";		
	    }
	
	/* All Visa card account numbers begin with a 4, all MasterCard accounts begin with a 5,
	   all Discover card accounts begin with a 6, and all American Express cards begin with a 3.
	   In addition, credit cards have a fixed number of digits: Amex accounts all contain 
	   15 digits, and Visa, MasterCard, and Discover card accounts all contain 16 digits. */
	   
	// This function requires elements name to match element names in function 	
		var _FormSubmittedCount = 0;	   
		
		function ValidateCreditCardForm() {

			if (_FormSubmittedCount == 1)
				{
				alert('Please stand by...\n Your request is being processed.');
				return false;   
				}
			else
				{
			 	_FormSubmittedCount +=1;
				}	
		
			var oForm = document.forms[0];			
			var elmtBackClicked = oForm.elements["hidBackClicked"];
			
			//don't validate if the back button is clicked
			if (elmtBackClicked.value=="1")
				{
				elmtBackClicked.value="0";
				return true;
				}

				var ctrlPrefix = "ctl00$mainContent$PlayerRegistration$";
			var elmtCreditCardNumber = oForm.elements[ctrlPrefix + "CreditCardNumber"];
			
					
			// if this element is on the form 
			if (elmtCreditCardNumber != null)
				{			
					var elmtCreditCardType = oForm.elements[ctrlPrefix + "CreditCardTypeID"];
					var elmtCreditCardName = oForm.elements[ctrlPrefix + "CreditCardName"];
					var elmtCreditCardExpMonth = oForm.elements[ctrlPrefix + "CreditCardExpMonth"];
					var elmtCreditCardExpYear = oForm.elements[ctrlPrefix + "CreditCardExpYear"];
					var elmtCreditCardZip = oForm.elements[ctrlPrefix + "CreditCardZip"];
					
					var elmttxteNewsLetterEmail = oForm.elements[ctrlPrefix + "txteNewsLetterEmail"];
					var elmtchkboxUSTANewsletter = oForm.elements[ctrlPrefix + "chkboxUSTANewsletter"];
					var elmtchkboxActiveTennis = oForm.elements[ctrlPrefix + "chkboxActiveTennis"];
					var elmtchkboxLocalEvents = oForm.elements[ctrlPrefix + "chkboxLocalEvents"];
					
					var iCreditCardTypeID = elmtCreditCardType.options[elmtCreditCardType.selectedIndex].value;
					var sCCIsNumeric = IsNumeric(elmtCreditCardNumber.value);
					if (elmtCreditCardName.value.length == 0) {
						alert('Please enter the Name on your Credit Card');
						elmtCreditCardName.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if (iCreditCardTypeID == '') {
						alert('Please select your Credit Card Type');
						elmtCreditCardType.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if (elmtCreditCardNumber.value.length == 0) {
						alert('Please enter your Credit Card Number');
						elmtCreditCardNumber.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if (sCCIsNumeric == 'no' || elmtCreditCardNumber.value.length == 0 || 
								(iCreditCardTypeID == 3 && elmtCreditCardNumber.value.length != 15) || 
								(iCreditCardTypeID != 3 && elmtCreditCardNumber.value.length != 16) || 
								(iCreditCardTypeID == 1 && elmtCreditCardNumber.value.substr(0, 1) != '4') || 		
								(iCreditCardTypeID == 3 && elmtCreditCardNumber.value.substr(0, 1) != '3') || 
								(iCreditCardTypeID == 4 && elmtCreditCardNumber.value.substr(0, 1) != '5')) {
									alert('Invalid Credit Card number. Please make sure the Credit Card number entered is valid.');
									elmtCreditCardNumber.select();
									_FormSubmittedCount = 0;
									return false;
					} else if (elmtCreditCardExpMonth.options[elmtCreditCardExpMonth.selectedIndex].value == '' || elmtCreditCardExpYear.options[elmtCreditCardExpYear.selectedIndex].value == '') {
						alert('Please select Credit Card Expiration Month / Year.');
						if (elmtCreditCardExpMonth.options[elmtCreditCardExpMonth.selectedIndex].value == '') {
							elmtCreditCardExpMonth.focus();
						} else {
							elmtCreditCardExpYear.focus();
						}
						_FormSubmittedCount = 0;
						return false;
					} else if (elmtCreditCardZip.value.length == 0) {
						alert('Please enter your Zip Code');
						elmtCreditCardZip.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if ((!elmtchkboxUSTANewsletter.checked && !elmtchkboxActiveTennis.checked && !elmtchkboxLocalEvents.checked) && 
						((elmttxteNewsLetterEmail.value != 'enter your e-mail here') && (elmttxteNewsLetterEmail.value.replace(/^\s+|\s+$/g,"") != ''))) {
						alert('Please select the newsletter(s)');						
						_FormSubmittedCount = 0;
						return false;
					} else if ((elmtchkboxUSTANewsletter.checked || elmtchkboxActiveTennis.checked || elmtchkboxLocalEvents.checked) && 
						((elmttxteNewsLetterEmail.value == 'enter your e-mail here') || (elmttxteNewsLetterEmail.value.replace(/^\s+|\s+$/g,"") == ''))) {
						 alert('Please enter your e-mail to sign up for the newsletter(s)');
						 elmttxteNewsLetterEmail.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if ((elmtchkboxUSTANewsletter.checked || elmtchkboxActiveTennis.checked || elmtchkboxLocalEvents.checked)) {
						var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
						  if (emailfilter.test(elmttxteNewsLetterEmail.value) == false) {
						    alert('Please enter a valid email address');
						    _FormSubmittedCount = 0;
						    return false;
						  }					
					} else {						
						return true;
					}					
					return true;
				}
		} 
		
		function ValidateCreditCardFormOrderShirtForm() {
			
			if (_FormSubmittedCount == 1)
				{
				alert('Please stand by...\n Your request is being processed.');
				return false;   
				}
			else
				{
			 	_FormSubmittedCount +=1;
				}	
		
			var oForm = document.forms[0];			
			var elmtBackClicked = oForm.elements["hidBackClicked"];
			
			//don't validate if the back button is clicked
			if (elmtBackClicked.value=="1")
			{
				elmtBackClicked.value="0";
				return true;
			}

			var ctrlPrefix = "ctl00$mainContent$OrderShirts$";
			var elmtCreditCardNumber = oForm.elements[ctrlPrefix + "CreditCardNumber"];
			
			// if this element is on the form 
			if (elmtCreditCardNumber != null)
				{			
					var elmtCreditCardType = oForm.elements[ctrlPrefix + "CreditCardTypeID"];
					var elmtCreditCardName = oForm.elements[ctrlPrefix + "CreditCardName"];
					var elmtCreditCardExpMonth = oForm.elements[ctrlPrefix + "CreditCardExpMonth"];
					var elmtCreditCardExpYear = oForm.elements[ctrlPrefix + "CreditCardExpYear"];
					var elmtCreditCardZip = oForm.elements[ctrlPrefix + "CreditCardZip"];
					
					var elmttxteNewsLetterEmail = oForm.elements[ctrlPrefix + "txteNewsLetterEmail"];
					var elmtchkboxUSTANewsletter = oForm.elements[ctrlPrefix + "chkboxUSTANewsletter"];
					var elmtchkboxActiveTennis = oForm.elements[ctrlPrefix + "chkboxActiveTennis"];
					var elmtchkboxLocalEvents = oForm.elements[ctrlPrefix + "chkboxLocalEvents"];
					
					var iCreditCardTypeID = elmtCreditCardType.options[elmtCreditCardType.selectedIndex].value;
					var sCCIsNumeric = IsNumeric(elmtCreditCardNumber.value);
					if (elmtCreditCardName.value.length == 0) {
						alert('Please enter the name on your credit card');
						elmtCreditCardName.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if (iCreditCardTypeID == '') {
						alert('Please select your credit card type');
						elmtCreditCardType.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if (elmtCreditCardNumber.value.length == 0) {
						alert('Please enter your credit card number');
						elmtCreditCardNumber.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if (sCCIsNumeric == 'no' || elmtCreditCardNumber.value.length == 0 || 
								(iCreditCardTypeID == 3 && elmtCreditCardNumber.value.length != 15) || 
								(iCreditCardTypeID != 3 && elmtCreditCardNumber.value.length != 16) || 
								(iCreditCardTypeID == 1 && elmtCreditCardNumber.value.substr(0, 1) != '4') || 		
								(iCreditCardTypeID == 3 && elmtCreditCardNumber.value.substr(0, 1) != '3') || 
								(iCreditCardTypeID == 4 && elmtCreditCardNumber.value.substr(0, 1) != '5')) {
									alert('Invalid Credit Card number. Please make sure the Credit Card number entered is valid.');
									elmtCreditCardNumber.select();
									_FormSubmittedCount = 0;
									return false;
					} else if (elmtCreditCardExpMonth.options[elmtCreditCardExpMonth.selectedIndex].value == '' || elmtCreditCardExpYear.options[elmtCreditCardExpYear.selectedIndex].value == '') {
						alert('Please select your expiration month / year.');
						if (elmtCreditCardExpMonth.options[elmtCreditCardExpMonth.selectedIndex].value == '') {
							elmtCreditCardExpMonth.focus();
						} else {
							elmtCreditCardExpYear.focus();
						}
						_FormSubmittedCount = 0;
						return false;
					} else if (elmtCreditCardZip.value.length == 0) {
						alert('Please enter your zip code');
						elmtCreditCardZip.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if ((!elmtchkboxUSTANewsletter.checked && !elmtchkboxActiveTennis.checked && !elmtchkboxLocalEvents.checked) && 
						((elmttxteNewsLetterEmail.value != 'enter your e-mail here') && (elmttxteNewsLetterEmail.value.replace(/^\s+|\s+$/g,"") != ''))) {
						alert('Please select the newsletter(s)');						
						_FormSubmittedCount = 0;
						return false;
					} else if ((elmtchkboxUSTANewsletter.checked || elmtchkboxActiveTennis.checked || elmtchkboxLocalEvents.checked) && 
						((elmttxteNewsLetterEmail.value == 'enter your e-mail here') || (elmttxteNewsLetterEmail.value.replace(/^\s+|\s+$/g,"") == ''))) {
						alert('Please enter your e-mail');
						elmttxteNewsLetterEmail.focus();
						_FormSubmittedCount = 0;
						return false;
					} else if ((elmtchkboxUSTANewsletter.checked || elmtchkboxActiveTennis.checked || elmtchkboxLocalEvents.checked)) {
						var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
						  if (emailfilter.test(elmttxteNewsLetterEmail.value) == false) {
						    alert('Please enter a valid email address');
						    _FormSubmittedCount = 0;
						    return false;
						  }					
					} else {						
						return true;
					}					
					return true;
				}
		} 
		
		
		function IsNumeric(sValue) {
			var sValidChars = '0123456789';
			var sIsNumeric = 'yes';		
			for (var i = 0; i < sValue.length; i++) {				
				if (sValidChars.indexOf(sValue.substring(i, i + 1)) == -1) {
					sIsNumeric = 'no';
					break;
				}
			}		
			return sIsNumeric;
        }
		
		function pay() {
		    var oForm = document.forms[0];
		    var ctrlPrefix = "ctl00$mainContent$PlayerRegistration$";
		    if (oForm.elements[ctrlPrefix + "cmdSubmit"] != null) {
		        oForm.elements[ctrlPrefix + "cmdSubmit"].disabled = true;

		        if (ValidateCreditCardForm()) {
		            //construct the object instance and put the cc info in it.
		            var accountInfo = new AMS.AccountInfo();
		            accountInfo.setCCType(oForm.elements[ctrlPrefix + "CreditCardTypeID"].value);
		            accountInfo.setCCNumber(oForm.elements[ctrlPrefix + "CreditCardNumber"].value);
		            accountInfo.setCCExpMonth(oForm.elements[ctrlPrefix + "CreditCardExpMonth"].value);
		            accountInfo.setCCExpYear(oForm.elements[ctrlPrefix + "CreditCardExpYear"].value);
		            accountInfo.setCCCardholder(oForm.elements[ctrlPrefix + "CreditCardName"].value);
		            accountInfo.setCCZip(oForm.elements[ctrlPrefix + "CreditCardZip"].value);
		            accountInfo.setModulus(oForm.elements[ctrlPrefix + "hdnModulus"].value);
		            accountInfo.setExponent(oForm.elements[ctrlPrefix + "hdnExponent"].value);

		            //alert(document.getElementById("#<%=hdnModulus.ClientID %>"].value));
		            //alert(document.getElementById("#<%=hdnExponent.ClientID %>"));

		            //invoke the getCipher function to retrieve the cipher text
		            try {
		                var cipherText = AMS.getCipher(accountInfo);
		                //alert(cipherText);
		                if (cipherText) {
		                    //if get valid cipher text, go ahead with followings
		                    //save the cipher text in the hidden filed "cipherText"
		                    oForm.elements[ctrlPrefix + "hdnCipherText"].value = cipherText;
		                    ClearCCFields();
		                    oForm.elements[ctrlPrefix + "cmdSubmit"].disabled = false;
		                    return true;
		                } else {
		                    oForm.elements[ctrlPrefix + "cmdSubmit"].disabled = false;
		                    //Note: Use customized error handling and logging here.
		                    alert("Get cipher text error. Try again.");
		                    reloadForm();
		                    return false;
		                }
		            } catch (exception) {
		                if (exception == "InvalidToken") {
		                    //Note: Use customized error handling and logging here.
		                    alert('Error: the token is invalid. Try again.');
		                }
		                if (exception == "AccountInfoMessageTooLong") {
		                    //Note: Use customized error handling and logging here.
		                    alert('Error: The input account information message is too long. Try again.');
		                }
		                oForm.elements[ctrlPrefix + "cmdSubmit"].disabled = false;
		                reloadForm();
		                return false;
		            }
		        }
		        else {
		            if (oForm.elements[ctrlPrefix + "cmdSubmit"] != null) {
		                oForm.elements[ctrlPrefix + "cmdSubmit"].disabled = false;
		            };
		            return false;
		        };
		    };
		};

		function reloadForm() {
		    //reload the form to retry
		    window.location.reload();
		    var oForm = document.forms[0];
		    var ctrlPrefix = "ctl00$mainContent$PlayerRegistration$";
		    oForm.elements[ctrlPrefix + "cmdSubmit"].disabled = false;
		}

		function ClearCCFields() {
		    try {
		        var oForm = document.forms[0];
		        var ctrlPrefix = "ctl00$mainContent$PlayerRegistration$";
		        //Integration Note: make sure the sensitive data fields not be sent to server side
		        oForm.elements[ctrlPrefix + "CreditCardTypeID"].value = "";
		        oForm.elements[ctrlPrefix + "CreditCardNumber"].value = "";
		        oForm.elements[ctrlPrefix + "CreditCardExpMonth"].value = "";
		        oForm.elements[ctrlPrefix + "CreditCardExpYear"].value = "";
		        oForm.elements[ctrlPrefix + "CreditCardZip"].value = "";
		    } catch (ex) { };
		}
