function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
return false;
   }
}
return true;
}

function validateRMI(theForm) { // for RMI form
	// Set variables and get info
	var isError = false; // for any type of error
	var formError = false; // for a missing form field error
	var emailError = false; // for an invalid email address error
	var errorMessage = "";
	var emailMessage = "";
	var firstname = theForm.firstname.value;
	var lastname = theForm.lastname.value;
	var email = theForm.email.value;
	var address1 = theForm.address1.value;
	var city = theForm.city.value;
	var state = theForm.state.selectedIndex;
	var postalcode = theForm.postalcode.value;
	var birth_month = theForm.birth_month.selectedIndex;
	var birth_day = theForm.birth_day.selectedIndex;
	var birth_year = theForm.birth_year.selectedIndex;
	//var gender = theForm.gender.value;
	
	if ( ( theForm.gender[0].checked == false ) && ( theForm.gender[1].checked == false ) ) {
		isError = true;
		formError = true;
		errorMessage = "You must select a gender.\r\n";
	}
		
	if(firstname == "") {
		isError = true;
		formError = true;
		errorMessage = errorMessage + "You must enter your first name.\r\n";
	}
	if(lastname == "") {
		isError = true;
		formError = true;
		errorMessage = errorMessage + "You must enter your last name.\r\n";
	}
		if(address1 == "") {
		isError = true;
		formError = true;
		errorMessage = errorMessage + "You must enter an address.\r\n";
	}
	
	if(city == "") {
		isError = true;
		formError = true;
		errorMessage = errorMessage + "You must enter a city.\r\n";
	}
	if(state == 0) {
		isError = true;
		formError = true;
		errorMessage = errorMessage + "You must choose a state.\r\n";
	}
	
	if(postalcode == "" || postalcode.length < 5 || validateZIP(postalcode) == false ) {
		isError = true;
		formError = true;
		errorMessage = errorMessage + "You must enter a zip code.\r\n";
	}
	
	//if((birth_month == 0) || (birth_day == 0) || (birth_year == 0)) {
//		isError = true;
//		formError = true;
//		errorMessage = errorMessage + "You must select a date of birth.\r\n";
//	}
	if (email == "") {
		isError = true;
		formError = true;
		errorMessage = errorMessage + "You must enter your email address.\r\n";
	} else {
		
		if (email.lastIndexOf(".") == -1 || (email.lastIndexOf(".")+1==email.length)  ||  email.indexOf("@") == -1  ||  email.indexOf("@") > email.lastIndexOf(".")) {
			
			isError = true;
			emailError = true;
			emailMessage = "Invalid E-mail Address (valid = name@domain.extension)";
			
		}
	}
	
	if(firstname==""){
	document.getElementById("firstname").focus();
	}
	else if(lastname==""){
		document.getElementById("lastname").focus();	
	}
	else if(address1 == ""){
		document.getElementById("address1").focus();
	}
	else if(city == ""){
		document.getElementById("city").focus();
	}
	else if(state == ""){
		document.getElementById("state").focus();
	}
	else if(postalcode == ""){
		document.getElementById("postalcode").focus();
	}
	else if(validateZIP(postalcode) == false){
		document.getElementById("postalcode").focus();
	}
	else if(birth_month == 0){
		document.getElementById("birth_month").focus();
	}
	else if(birth_day == 0){
		document.getElementById("birth_day").focus();
	}
	else if(birth_year == 0){
		document.getElementById("birth_year").focus();
	}
	else if(email == ""){
		document.getElementById("email").focus();
	}
	else if (email.lastIndexOf(".") == -1 || (email.lastIndexOf(".")+1==email.length)  ||  email.indexOf("@") == -1  ||  email.indexOf("@") > email.lastIndexOf(".")){
		document.getElementById("email").focus();
	}
	
	if (isError) {
		if (formError && emailError)
			alert("" + errorMessage + "\r\n\r\n" + emailMessage);
		else if (formError)
			alert("" + errorMessage);
		else
			alert(emailMessage);
		return false;
	}
	
	return true;
}

function validateGoalRMI() {
	var errMessage = "";
	if(!globalIsQuestionAnswered('taking_zetia')) {
		errMessage += "Are you currently taking ZETIA or intend to start taking ZETIA?\r\n";
		}
	return errMessage;
	}

