function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function validate(theForm){
	// see if we're going to the index page for submission instead of the second page of the form
	// check which radio button has been selected for email authorized
	isEmailAuthorized = getCheckedValue(theForm.email_authorized);
	
	finalAction = "/clients/emarketing/index.cfm?" + theForm.indexQueryString.value;
	
	// DO NOT show step 2 at all if they selected "no" to email specials
	/* - doing this after the captcha verification now 11/9/06 Cindi V
	if(isEmailAuthorized == "0"){
		// no custom fields and not signing up for email... just submit the form
		document.forms[0].action = finalAction;	
	}
	*/
	
	if(theForm.whichView.value != 'editclient' || (theForm.whichView.value == 'editclient' && isEmailAuthorized == 1)){
	
		if(theForm.first_name.value == ''){
			alert("Please enter your first name.");
			theForm.first_name.focus();
			return false;				
		}
		if(theForm.last_name.value == ''){
			alert("Please enter your last name.");
			theForm.last_name.focus();
			return false;				
		}
		
		
		if(isEmailAuthorized == 1){
			// need an email address at least 
			if(theForm.email.value == ''){
				alert("Please enter your email address in order to receive exclusive vacation offers by email.");
				theForm.email.focus();
				return false;
			}
		} else {
			// check for EITHER email address of mailing address
			if(theForm.email.value == '' && theForm.address.value == ''){
				alert("Please enter either your email address or mailing address");
				theForm.email.focus();
				return false;
			}
			// check for complete address entry if they chose to enter their address instead of their email
			if(theForm.address.value != ''){
				if(theForm.city.value == ''){
					alert("Please enter a city name.");
					theForm.city.focus();
					return false;
				}
				if(theForm.zip.value == ''){
					alert("Please enter your zip code.");
					theForm.zip.focus();
					return false;
				}
				if(theForm.country.selectedIndex == 0){
					alert("Please select a country.");
					theForm.country.focus();
					return false;
				}
			}
		}
		// if they have entered an email address, make sure it's valid and matches the confirm email field
		if(theForm.email.value != ''){
			// check for matching email addresses
			if((typeof theForm.verify_email != "undefined") && theForm.email.value != theForm.verify_email.value){
				alert("The email addresses that you have entered do not match. Please check you entries and try again.");
				theForm.email.focus();
				return false;
			}
			// check for a valid email address
			if(echeck(theForm.email.value) == false){
				theForm.email.focus();
				return false;
			}
		}
		
		// always require state field to be selected 5/27/08 Cindi V
		if(theForm.state.selectedIndex == 0){
			alert("Please select a state.");
			theForm.state.focus();
			return false;
		}
		
	}
	
	// validate CAPTCHA entry
	/*if(theForm.captchaText.value == ''){
		alert("Please enter the verification code.");
		theForm.captchaText.focus();
		return false;
	}*/
	
	return true;
}
