/*
The isEmpty and isWhitespace functions were taken straight from Netscape's JavaScript development site, http://developer
.netscape.com.
*/


// whitespace characters
var whitespace = " \t\n\r";

/****************************************************************/
function leftpad(theItem, thePad, minSize) {
	newItem = new String(theItem);
	while (newItem.length < minSize) {
		newItem = thePad + newItem;
	}
	return newItem;
}

/****************************************************************/
function isEmpty(s) {
// Check whether string s is empty.
	return ((s == null) || (s.length == 0))
}

/****************************************************************/
function isWhitespace(s) {
	var i;

// Is s empty?
	if (isEmpty(s))
		return true;

// Search through string's characters one by one
// until we find a non-whitespace character.
// When we do, return false; if we don't, return true.

	for (i = 0; i < s.length; i++)
	{
// Check that current character isn't whitespace.
	var c = s.charAt(i);
	if (whitespace.indexOf(c) == -1)
		return false;
	}

// All characters are whitespace.
	return true;
}

/****************************************************************/
function ForceEntry(val, str) {
	var strInput = new String(val.value);

	if (isWhitespace(strInput)) {
		alert(str);
		return false;
	}
	else
		return true;
}

/****************************************************************/
function ValidateCommonData() {
USA="USA";
CANADA="CANADA";
	if (document.webform.State.selectedIndex == 0) {
		if ((document.webform.Country.value != USA) && (document.webform.Country.value != CANADA))
			document.webform.State.selectedIndex=1;
	}
	if (isEmpty(document.webform.Street_Address.value)) {
		alert("Please enter your Street Address.");
		document.webform.Street_Address.focus();
		return false;
	}

//	if ((isEmpty(document.webform.City.value)) || (document.webform.State.selectedIndex == 0) || (isEmpty(document.webform.Zip_Code.value)) || (document.webform.Country.selectedIndex == 0)) {

	if (isEmpty(document.webform.City.value)) {
		alert("Please enter your City.");
		document.webform.City.focus();
		return false;
	}
	if (document.webform.State.selectedIndex == 0) {
		alert("Please enter your State/Province.");
		document.webform.State.focus();
		return false;
	}
	if (isEmpty(document.webform.Zip_Code.value)) {
		alert("Please enter your Zip Code.");
		document.webform.Zip_Code.focus();
		return false;
	}
/*
	if (document.webform.Country.selectedIndex == 0) {
		alert("Please enter your Country.");
		document.webform.Country.focus();
		return false;
	}
*/
	return true;

}

/****************************************************************/
function ValidateMembershipData() {

USA="USA";
CANADA="CANADA";

	if ((document.webform.MemberType[0].checked == false) && (document.webform.MemberType[1].checked == false) && (document.webform.MemberType[2].checked == false)) {
		alert("Please indicate the type of membership you are interested in: join, renew, rejoin");
		document.webform.MemberType[0].focus();
		return false;
	}
	else {
		update_dues();
/*
		amtdue=0;
		if ((document.webform.Country.value == USA) || (document.webform.Country.value == CANADA))
			amtdue+=parseFloat(document.webform.membership_usa_canada.value);
		else
			amtdue+=parseFloat(document.webform.membership_other_countries.value);
		document.webform.amtdue.value=amtdue;
*/
	}
	if ((document.webform.PaymentMethod[0].checked == false) && (document.webform.PaymentMethod[1].checked == false)) {
		alert("Please indicate your payment method: mail a check or pay online");
		document.webform.PaymentMethod[0].focus();
		return false;
	}
	if ((document.webform.DirectoryListing[0].checked == false) && (document.webform.DirectoryListing[1].checked == false) && (document.webform.DirectoryListing[2].checked == false) && (document.webform.DirectoryListing[3].checked == false) && (document.webform.DirectoryListing[4].checked == false)) {
		alert("Please indicate the type of directory listing you want");
		document.webform.DirectoryListing[0].focus();
		return false;
	}
	if ((document.webform.WhoAmI[0].checked == false) && (document.webform.WhoAmI[1].checked == false) && (document.webform.WhoAmI[2].checked == false) && (document.webform.WhoAmI[3].checked == false) && (document.webform.WhoAmI[4].checked == false) && (document.webform.WhoAmI[5].checked == false) && (document.webform.WhoAmI[6].checked == false) && (document.webform.WhoAmI[7].checked == false) && (document.webform.WhoAmI[8].checked == false) && (document.webform.WhoAmI[9].checked == false)) {
		alert("Please tell us about yourself (mark all that apply)");
		document.webform.WhoAmI[0].focus();
		return false;
	}
	return true;

}

/****************************************************************/
function update_dues() {

USA="USA";
CANADA="CANADA";

	amtdue=0;
	if ((document.webform.Country.value == USA) || (document.webform.Country.value == CANADA))
		amtdue+=parseFloat(document.webform.membership_usa_canada.value);
	else
		amtdue+=parseFloat(document.webform.membership_other_countries.value);
	document.webform.amtdue.value=amtdue;
	return true;

}

/****************************************************************/
function ValidateJoinData() {

//<input type=hidden name="required" value="realname,email,Phone_Number,Country,Street_Address,City,State,Zip_Code">

	if (isEmpty(document.webform.realname.value)) {
		alert("Please enter your Name.");
		document.webform.realname.focus();
		return false;
	}
	if (isEmpty(document.webform.email.value)) {
		alert("Please enter your Email Address.");
		document.webform.email.focus();
		return false;
	}
	else {
		email=document.webform.email.value;
		if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
			alert("Invalid email address: '" + email + "'");
			document.webform.email.focus();
			return false;
		}
        }
	if (!ValidateCommonData())
		return false;
	if (isEmpty(document.webform.Phone_Number.value)) {
		alert("Please enter your Phone Number.");
		document.webform.Phone_Number.focus();
		return false;
	}
	if (!ValidateMembershipData())
		return false;

}

/****************************************************************/
function storm_update_amtdue() {

	amtdue=0;
	stormdvd=0;
	stormvhs=0;

	if (document.webform.StormDvdNum.value == "")
		document.webform.StormDvdNum.value=0;
	if (document.webform.StormVhsNum.value == "")
		document.webform.StormVhsNum.value=0;
	stormdvd=parseFloat(document.webform.StormDvdNum.value) * parseFloat(document.webform.StormDvdPrice.value);
	document.webform.StormDvdTot.value=stormdvd;
	amtdue+=stormdvd;

	stormvhs=parseFloat(document.webform.StormVhsNum.value) * parseFloat(document.webform.StormVhsPrice.value);
	document.webform.StormVhsTot.value=stormvhs;
	amtdue+=stormvhs;

	document.webform.amtdue.value=amtdue;
	document.webform.orderamt.value=amtdue;
	return true;

}
/****************************************************************/
function medal_update_amtdue() {

	amtdue=0;
	medal=0;

	medal=parseFloat(document.webform.MedalNum.value) * parseFloat(document.webform.MedalPrice.value);
	document.webform.MedalTot.value=medal;
	amtdue+=medal;

	document.webform.amtdue.value=amtdue;
	document.webform.orderamt.value=amtdue;
	return true;

}

/****************************************************************/
function ValidateOrderStormData() {

//<input type=hidden name="required" value="realname,email,Phone_Number,Country,Street_Address,City,State,Zip_Code">

	if (isEmpty(document.webform.realname.value)) {
		alert("Please enter your Name.");
		document.webform.realname.focus();
		return false;
	}
	if (isEmpty(document.webform.email.value)) {
		alert("Please enter your Email Address.");
		document.webform.email.focus();
		return false;
	}
	else {
		email=document.webform.email.value;
		if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
			alert("Invalid email address: '" + email + "'");
			document.webform.email.focus();
			return false;
		}
        }
	if (!ValidateCommonData())
		return false;
	if (isEmpty(document.webform.Phone_Number.value)) {
		alert("Please enter your Phone Number.");
		document.webform.Phone_Number.focus();
		return false;
	}
	if (isEmpty(document.webform.StormDvdNum.value))
		document.webform.StormDvdNum.value=0;
	if (isEmpty(document.webform.StormVhsNum.value))
		document.webform.StormVhsNum.value=0;
	if ((document.webform.StormDvdNum.value == 0) && (document.webform.StormVhsNum.value == 0)) {
		alert("Please enter the number of items you wish to order.");
		document.webform.StormDvdNum.focus();
		return false;
	}
	storm_update_amtdue();
	if ((document.webform.PaymentMethod[0].checked == false) && (document.webform.PaymentMethod[1].checked == false)) {
		alert("Please indicate your payment method: mail a check or pay online");
		document.webform.PaymentMethod[0].focus();
		return false;
	}
}

/****************************************************************/
function ValidateOrderMedalData() {

//<input type=hidden name="required" value="realname,email,Phone_Number,Country,Street_Address,City,State,Zip_Code">

	if (isEmpty(document.webform.realname.value)) {
		alert("Please enter your Name.");
		document.webform.realname.focus();
		return false;
	}
	if (isEmpty(document.webform.email.value)) {
		alert("Please enter your Email Address.");
		document.webform.email.focus();
		return false;
	}
	else {
		email=document.webform.email.value;
		if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
			alert("Invalid email address: '" + email + "'");
			document.webform.email.focus();
			return false;
		}
        }
	if (!ValidateCommonData())
		return false;
	if (isEmpty(document.webform.Phone_Number.value)) {
		alert("Please enter your Phone Number.");
		document.webform.Phone_Number.focus();
		return false;
	}
	if (isEmpty(document.webform.AwardYear.value)) {
		alert("Please enter the year of your award.");
		document.webform.AwardYear.focus();
		return false;
	}
	if (isEmpty(document.webform.AwardCategory.value)) {
		alert("Please enter the category of your award.");
		document.webform.AwardCategory.focus();
		return false;
	}
	if (isEmpty(document.webform.AgencyDepartment.value)) {
		alert("Please enter the name of your agency/department.");
		document.webform.AgencyDepartment.focus();
		return false;
	}

	if (isEmpty(document.webform.MedalNum.value))
		document.webform.MedalNum.value=0;
	if (document.webform.MedalNum.value == 0) {
		alert("Please enter the number of items you wish to order.");
		document.webform.MedalNum.focus();
		return false;
	}
	medal_update_amtdue();
	if ((document.webform.PaymentMethod[0].checked == false) && (document.webform.PaymentMethod[1].checked == false)) {
		alert("Please indicate your payment method: mail a check or pay online");
		document.webform.PaymentMethod[0].focus();
		return false;
	}
}


/****************************************************************/
function ValidateAwardData() {

//<input type=hidden name="required" value="nomination_year,category,nominee_type,duty_type,start_date,end_date,incident_name,nominee_name,nominee_title,nominee_unit,nominee_address,nominee_city,nominee_zipcode,nominee_state,nominee_country,nominee_phonehome,nominee_phonework,nominee_phonecell,nominee_email,nominee_srt,incident_summary,rescuer_training,environmental_conditions,attachment,realname,email,nominator_title,nominator_signature,nominator_date,nominator_unit,nominator_address,nominator_city,nominator_state,nominator_country,nominator_zipcode,nominator_phonework,nominator_phonecell,nominee_name[],nominee_title[],nominee_unit[],nominee_address[],nominee_city[],nominee_zipcode[],nominee_state[],nominee_country[],nominee_phonehome[],nominee_phonework[],nominee_phonecell[],nominee_email[],nominee_srt[]">

	if (isEmpty(document.webform.nomination_year.value)) {
		alert("Please enter the nomination year.");
		document.webform.nomination_year.focus();
		return false;
	}
	if ((document.webform.category[0].checked == false) && (document.webform.category[1].checked == false) && (document.webform.category[2].checked == false) && (document.webform.category[3].checked == false) && (document.webform.category[4].checked == false)) {
		alert("Please indicate the category of your award.");
		document.webform.category[0].focus();
		return false;
	}
	if ((document.webform.nominee_type[0].checked == false) && (document.webform.nominee_type[1].checked == false) && (document.webform.nominee_type[2].checked == false) && (document.webform.nominee_type[3].checked == false)) {
		alert("Please indicate the type of nominee.");
		document.webform.nominee_type[0].focus();
		return false;
	}
	if ((document.webform.duty_type[0].checked == false) && (document.webform.duty_type[1].checked == false) && (document.webform.duty_type[2].checked == false) && (document.webform.duty_type[3].checked == false) && (document.webform.duty_type[4].checked == false)) {
		alert("Please indicate the type of duty.");
		document.webform.duty_type[0].focus();
		return false;
	}
	if (isEmpty(document.webform.start_date.value)) {
		alert("Please enter the start date/time for this incident.");
		document.webform.start_date.focus();
		return false;
	}
	if (isEmpty(document.webform.end_date.value)) {
		alert("Please enter the end date/time for this incident.");
		document.webform.end_date.focus();
		return false;
	}
	if (isEmpty(document.webform.incident_name.value)) {
		alert("Please enter the name of this incident.");
		document.webform.incident_name.focus();
		return false;
	}
	if ((isEmpty(document.webform.nominee_name.value)) || (isEmpty(document.webform.nominee_title.value)) || (isEmpty(document.webform.nominee_unit.value)) || (isEmpty(document.webform.nominee_address.value)) || (isEmpty(document.webform.nominee_city.value)) || (isEmpty(document.webform.nominee_zipcode.value)) || (isEmpty(document.webform.nominee_state.value)) || (isEmpty(document.webform.nominee_country.value)) || (isEmpty(document.webform.nominee_phonehome.value)) || (isEmpty(document.webform.nominee_phonework.value)) || (isEmpty(document.webform.nominee_phonecell.value)) || (isEmpty(document.webform.nominee_email.value)) || (isEmpty(document.webform.nominee_srt.value))) {
		alert("Please enter complete information about this nominee.");
		if (isEmpty(document.webform.nominee_name.value))
			document.webform.nominee_name.focus();
		else if (isEmpty(document.webform.nominee_title.value))
			document.webform.nominee_title.focus();
		else if (isEmpty(document.webform.nominee_unit.value))
			document.webform.nominee_unit.focus();
		else if (isEmpty(document.webform.nominee_address.value))
			document.webform.nominee_address.focus();
		else if (isEmpty(document.webform.nominee_city.value))
			document.webform.nominee_city.focus();
		else if (isEmpty(document.webform.nominee_zipcode.value))
			document.webform.nominee_zipcode.focus();
		else if (isEmpty(document.webform.nominee_state.value))
			document.webform.nominee_state.focus();
		else if (isEmpty(document.webform.nominee_country.value))
			document.webform.nominee_country.focus();
		else if (isEmpty(document.webform.nominee_phonehome.value))
			document.webform.nominee_phonehome.focus();
		else if (isEmpty(document.webform.nominee_phonework.value))
			document.webform.nominee_phonework.focus();
		else if (isEmpty(document.webform.nominee_phonecell.value))
			document.webform.nominee_phonecell.focus();
		else if (isEmpty(document.webform.nominee_email.value))
			document.webform.nominee_email.focus();
		else
			document.webform.nominee_srt.focus();
		return false;
	}
	email=document.webform.nominee_email.value;
	if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
		alert("Invalid email address: '" + email + "'");
		document.webform.nominee_email.focus();
		return false;
	}
	if (isEmpty(document.webform.incident_summary.value)) {
		alert("Please enter your summary of the incident.");
		document.webform.incident_summary.focus();
		return false;
	}
	if (isEmpty(document.webform.rescuer_training.value)) {
		alert("Please describe all training, qualifications, certifications, capabilities and skills of the rescuer(s)/team(s).");
		document.webform.rescuer_training.focus();
		return false;
	}
	if (isEmpty(document.webform.environmental_conditions.value)) {
		alert("Please describe the environmental conditions present at the time of the incident.");
		document.webform.environmental_conditions.focus();
		return false;
	}
	if ((document.webform.attachment[0].checked == false) && (document.webform.attachment[1].checked == false) && (document.webform.attachment[2].checked == false) && (document.webform.attachment[3].checked == false) && (document.webform.attachment[4].checked == false) && (document.webform.attachment[5].checked == false) && (document.webform.attachment[6].checked == false) && (document.webform.attachment[7].checked == false) && (document.webform.attachment[8].checked == false) && (document.webform.attachment[9].checked == false) && (document.webform.attachment[10].checked == false) && (document.webform.attachment[11].checked == false) && (document.webform.attachment[12].checked == false) && (document.webform.attachment[13].checked == false) && (document.webform.attachment[14].checked == false)) {
		alert("Please indicate the type(s) of attachment you will submit.");
		document.webform.attachment[0].focus();
		return false;
	}
	if ((isEmpty(document.webform.realname.value)) || (isEmpty(document.webform.nominator_title.value)) || (isEmpty(document.webform.nominator_signature.value)) || (isEmpty(document.webform.nominator_date.value)) || (isEmpty(document.webform.nominator_unit.value)) || (isEmpty(document.webform.nominator_address.value)) || (isEmpty(document.webform.nominator_city.value)) || (isEmpty(document.webform.nominator_state.value)) || (isEmpty(document.webform.nominator_country.value)) || (isEmpty(document.webform.nominator_zipcode.value)) || (isEmpty(document.webform.nominator_phonework.value)) || (isEmpty(document.webform.nominator_phonecell.value))) {
		alert("Please enter complete information about yourself.");
		if (isEmpty(document.webform.realname.value))
			document.webform.realname.focus();
		else if (isEmpty(document.webform.email.value))
			document.webform.email.focus();
		else if (isEmpty(document.webform.nominator_title.value))
			document.webform.nominator_title.focus();
		else if (isEmpty(document.webform.nominator_signature.value))
			document.webform.nominator_signature.focus();
		else if (isEmpty(document.webform.nominator_date.value))
			document.webform.nominator_date.focus();
		else if (isEmpty(document.webform.nominator_unit.value))
			document.webform.nominator_unit.focus();
		else if (isEmpty(document.webform.nominator_address.value))
			document.webform.nominator_address.focus();
		else if (isEmpty(document.webform.nominator_city.value))
			document.webform.nominator_city.focus();
		else if (isEmpty(document.webform.nominator_state.value))
			document.webform.nominator_state.focus();
		else if (isEmpty(document.webform.nominator_country.value))
			document.webform.nominator_country.focus();
		else if (isEmpty(document.webform.nominator_zipcode.value))
			document.webform.nominator_zipcode.focus();
		else if (isEmpty(document.webform.nominator_phonework.value))
			document.webform.nominator_phonework.focus();
		else if (isEmpty(document.webform.nominator_phonecell.value))
			document.webform.nominator_phonecell.focus();
		else
			document.webform.nominee_srt.focus();
		return false;
	}
	email=document.webform.email.value;
	if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
		alert("Invalid email address: '" + email + "'");
		document.webform.email.focus();
		return false;
	}
/*
	if ((document.webform.nominee_type[0].checked == false) && (isEmpty(document.webform.nominee_name[].value) || isEmpty(document.webform.nominee_title[].value) || isEmpty(document.webform.nominee_unit[].value) || isEmpty(document.webform.nominee_address[].value) || isEmpty(document.webform.nominee_city[].value) || isEmpty(document.webform.nominee_zipcode[].value) || isEmpty(document.webform.nominee_state[].value) || isEmpty(document.webform.nominee_country[].value) || isEmpty(document.webform.nominee_phonehome[].value) || isEmpty(document.webform.nominee_phonework[].value) || isEmpty(document.webform.nominee_phonecell[].value) || isEmpty(document.webform.nominee_email[].value) || isEmpty(document.webform.nominee_srt[].value))) {
		alert("Please enter complete information about this nominee.");
		document.webform.nominee_name[].focus();
		return false;
	}
*/
}



