//WordCount function
function countWords(text)
		{
		var arrWords = text.split(/\s+/);
		if(arrWords[0] == /\s+/ || arrWords[0] == "")
			return(0);
		else
			return(arrWords.length);
		}
//end wordcount


function validate_apps_form(){

	var stringFName = document.apps_form.txt_fname.value;
	var stringLName = document.apps_form.txt_lname.value;
	/*var stringTitle = document.apps_form.txt_title.value;*/
	/*var stringCompany = document.apps_form.txt_company.value;*/
	var stringAddress = document.apps_form.txt_address.value;
	var stringCity = document.apps_form.txt_city.value;
	var objectState = document.apps_form.txt_state;
	var stringStateValue = objectState.options[objectState.selectedIndex].value;
	var stringZip = document.apps_form.txt_zip.value;
	/*var objectCountry = document.apps_form.country;*/
	/*var stringCountryValue = objectCountry.options[objectCountry.selectedIndex].value;*/
	var stringPhone = document.apps_form.txt_phone.value;
	var stringDOB = document.apps_form.txt_dob.value;
	var stringEmail = document.apps_form.txt_email.value;

	var stringAppName = document.apps_form.txt_appName.value;
	var stringPlatform = document.apps_form.txt_platform.value;
	var stringLink = document.apps_form.txt_appLink.value;

	var stringDescription = document.apps_form.txt_description.value;
	var descripWordCount = countWords(stringDescription);

	var stringAdvancement = document.apps_form.txt_advancement.value;
	var advancementWordCount = countWords(stringAdvancement);
		
	if (stringFName.length == 0) {
		alert ("Please enter a first name.");
		apps_form.txt_fname.focus();
		return false;
	}

	if (stringLName.length == 0) {
		alert ("Please enter a last name.");
		apps_form.txt_lname.focus();
		return false;
	}
	
/*
	if (stringTitle.length == 0) {
		alert ("Please enter a title.");
		apps_form.txt_title.focus();
		return false;
	}
	
	if (stringCompany.length == 0) {
		alert ("Please enter a company.");
		apps_form.txt_company.focus();
		return false;
	}
*/
	
	if (stringAddress.length == 0) {
		alert ("Please enter a street address.");
		apps_form.txt_address.focus();
		return false;
	} 
	
	if (stringCity.length == 0) {
		alert ("Please enter a city.");
		apps_form.txt_city.focus();
		return false;
	} 

/*	
	if (stringCountryValue == "unselected") {
		alert ("Please select the speaker's Country.");
		document.apps_form.country.focus();
		return false;
	}
	
	if (stringCountryValue == "United States" && stringStateValue == "unselected") {
		alert ("You indicated the speaker's address is within the United States but have not selected a State. Please select a State.");
		document.apps_form.state.focus();
		return false;
	}

	if (stringCountryValue == "United States" && stringZip.length == 0) {
		alert ("You indicated the speaker's address is within the United States but have not entered the Zip Code. Please enter the Zip Code.");
		apps_form.zip.focus();
		return false;
	}
*/

	if (stringStateValue == "unselected") {
		alert ("Please select a U.S. state.");
		document.apps_form.txt_state.focus();
		return false;
	}
		
	if (stringZip.length == 0) {
		alert ("Please enter a zip code.");
		apps_form.txt_zip.focus();
		return false;
	}
	
	if (stringPhone.length == 0) {
		alert ("Please enter a phone number.");
		apps_form.txt_phone.focus();
		return false;
	}
	
	if (stringEmail.length == 0) {
		alert ("Please enter an e-mail address.");
		apps_form.txt_email.focus();
		return false;
		
		} else { 

			if ( (apps_form.txt_email.value.indexOf("@") < 1) || (apps_form.txt_email.value.indexOf(".") < 3) ) {
					alert("The e-mail format appears to be in error. Please confirm the e-mail address you entered is valid.");
					apps_form.txt_email.focus();
					return false;
				}
		}
	
	if (stringAppName.length == 0) {
		alert ("Please enter the application's name/title.");
		apps_form.txt_appName.focus();
		return false;
	}

	if (stringPlatform.length == 0) {
		alert ("Please describe the application's platform.");
		apps_form.txt_platform.focus();
		return false;
	}
	
	if (stringLink.length == 0) {
		alert ("Please include a link to the application.");
		apps_form.txt_appLink.focus();
		return false;
	}
	
	if (stringDescription.length == 0) {
		alert ("Please enter a description of the application.");
		apps_form.txt_description.focus();
		return false;
	}
	
	if (descripWordCount > 105) {
		alert ("Please limit the description to 100 words.");
		return false;
	}
	
	if (stringAdvancement.length == 0) {
		alert ("Please describe how the application advances the Innovation Movement.");
		apps_form.txt_advancement.focus();
		return false;
	}
	
	if (advancementWordCount > 105) {
		alert ("Please limit your answer to 100 words.");
		return false;
	}

	return true;
}
