	
	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 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 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;
		}
