/************************************************************/
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jay Rumsey | http://www.nova.edu/~rumsey/ */

// Used to show or hide fields related to joint nominators. 
function ShowRegJoint(op) {
  document.getElementById('Yes').style.display='none';
  document.getElementById('No').style.display='none';

  if (op == 1) {
    document.getElementById('Yes').style.display='block';
  }
  if (op == 2) {
    document.getElementById('No').style.display='block';
  }
}

// Used to show or hide fields related to individual versus organizational nominees. 
function ShowReg(op) {
  document.getElementById('Individual').style.display='none';
  document.getElementById('Organization').style.display='none';

  if (op == 1) {
    document.getElementById('Individual').style.display='block';
  }
  if (op == 2) {
    document.getElementById('Organization').style.display='block';
  }
}

// Used to count the words during form completion
function CountWordsLeft(myForm, field, count, no_words, field_id) {
	var text=field.value + " ";
	if(no_words>0) {
        var iwhitespace = /^[^A-Za-z0-9]+/gi; // remove initial whitespace
        var left_trimmedStr = text.replace(iwhitespace, "");
        var na = rExp = /[^A-Za-z0-9]+/gi; // non alphanumeric characters
        var cleanedStr = left_trimmedStr.replace(na, " ");
        var splitString = cleanedStr.split(" "); 
        var word_count = splitString.length -1;
        count.value=no_words-word_count;		
		if (count.value<0) {
			alert ("You have exceeded the maximum number of words for \n" + field_id);
			if (field_id == 'the synopsis.') {
				document.NominationForm.Synopsis.focus();
			} else if (field_id == '1. In your own words, describe the how the individual, corporation, foundation or group has helped your charity advance their mission.') {
				document.NominationForm.Mission.focus();
			} else if (field_id == '2. What has the nominee done to enable positive change in your organization?') {
				document.NominationForm.WhyNominate.focus();
      		} else if (field_id == '3. How did your nominee get involved with your organization?') {
				document.NominationForm.TimeInvolved.focus();
			} else if (field_id == '4. What other community activities is your nominee involved with?') {
				document.NominationForm.CommunityInvolved.focus();
			} else if (field_id == '5. Additional Comments.') {
				document.NominationForm.AdditionalComments.focus();
			}
		}
    }
}

// Used to validate the phone number during form completion
function validatePhoneNumber(phone, field_id) {
	if (phone.value.search(/\d{3}\-\d{3}\-\d{4}/) == -1 ) {
		alert("Please enter a value for " + field_id + " with the format xxx-xxx-xxxx. Example: 780-555-5555.");
   	}
}

// Used to validate the postal code during form completion
function validatePostalCode(postalCode, field_id) {
	postalCode.value=postalCode.value.toUpperCase();
	if (postalCode.value.search(/^\s*[a-ceghj-npr-tvxy]\d[a-z](\s)\d[a-z]\d\s*$/i) == -1 ) {
		alert("Please enter a value for " + field_id + " with the format xxx xxx. Example: T6G 2H7");
		postalCode.value = 'xxx xxx'; 
   	}
}

// Used to validate categories during form completion
function validateCategory(category) {	
  	if (category.selectedIndex==0) {
		alert("Please select a value for the 'Nomination Category' field.");
    }
}

// Used to validate joint nominations during form completion
function validateJoint(joint) {	
  	if (joint.selectedIndex==0) {
		alert("Please select a value for the 'Joint Nomination' field.");
    }
}

// Used to validate required text fields during form completion
function validateRequiredText(name) {	
	if (name.value=="") {
		alert ("Please enter a value for the " + name.id + " field.");
	}
}

// Used to validate the entire form before it is JointNominationted
function validateBeforeJointNomination2(theform) {
	var missingFields = false;
	var strFieldsNominator = ""; 
	var strFieldsNominee = ""; 
	var strFieldsCount = ""; 
	
	// NOMINATOR Section
	if (theform.NameofOrganization_Nominator.value=="") {
		missingFields = true;
		strFieldsNominator += "Please enter a value for the 'Name of Organization Nominating' field. \n";
	}
	if (theform.FirstNameofContact_Nominator.value=="") {
		missingFields = true;
		strFieldsNominator += "Please enter a value for the 'First Name of Contact' field. \n";
	}
	if (theform.LastNameofContact_Nominator.value=="") {
		missingFields = true;
		strFieldsNominator += "Please enter a value for the 'Last Name of Contact' field. \n"; 
	}
	if (theform.TitleofContact_Nominator.value=="") {
		missingFields = true;
		strFieldsNominator += "Please enter a value for the 'Title of Contact' field. \n";
	}
	if (theform.PhoneNumber_Nominator.value.search(/\d{3}\-\d{3}\-\d{4}/) == -1) { 
		missingFields = true;
		strFieldsNominator += "Please enter a value for the 'Phone Number' field with the format xxx-xxx-xxxx. Example: 780-555-5555. \n";
	}
	if (theform.email.value=="") {
		missingFields = true;
		strFieldsNominator += "Please enter a value for the 'Email Address' field. \n"; 
	}
	if (theform.StreetAddress_Nominator.value=="") {
		missingFields = true;
		strFieldsNominator += "Please enter a value for the 'Street Address' field. \n";
	}
	if (theform.City_Nominator.value=="") {
		missingFields = true;
		strFieldsNominator += "Please enter a value for the 'City' field. \n" 
	}
	theform.PostalCode_Nominator.value=theform.PostalCode_Nominator.value.toUpperCase();
	if (theform.PostalCode_Nominator.value.search(/^\s*[a-ceghj-npr-tvxy]\d[a-z](\s)\d[a-z]\d\s*$/i) == -1 ) {
		theform.PostalCode_Nominator.value = 'xxx xxx'; 
		missingFields = true;		
		strFieldsNominator +=  "Please enter a value for the 'Postal Code' field with the format xxx xxx. Example: T6G 2H7 \n";
	}
	
	// Joint NOMINATOR Section 
	if (theform.JointNomination.selectedIndex == 0) {
		missingFields = true;	
		strFieldsNominee +=  "Please enter a value for the 'Is this a joint nomination?' field. \n";
	}
	
	// Joint NOMINATOR Section
	if (theform.JointNomination.selectedIndex == 1) {
		if (theform.NameofOrganization_JointNomination.value=="") {
			missingFields = true;
			strFieldsNominator += "Please enter a value for the 'Name of Organization Nominating - Joint' field. \n";
		}
		if (theform.FirstNameofContact_JointNomination.value=="") {
			missingFields = true;
			strFieldsNominator += "Please enter a value for the 'First Name of Contact - Joint' field. \n";
		}
		if (theform.LastNameofContact_JointNomination.value=="") {
			missingFields = true;
			strFieldsNominator += "Please enter a value for the 'Last Name of Contact - Joint' field. \n"; 
		}
		if (theform.TitleofContact_JointNomination.value=="") {
			missingFields = true;
			strFieldsNominator += "Please enter a value for the 'Title of Contact - Joint' field. \n";
		}
		if (theform.PhoneNumber_JointNomination.value.search(/\d{3}\-\d{3}\-\d{4}/) == -1) { 
			missingFields = true;
			strFieldsNominator += "Please enter a value for the 'Phone Number - Joint' field with the format xxx-xxx-xxxx. Example: 780-555-5555. \n";
		}
		if (theform.EmailAddress_JointNomination.value=="") {
			missingFields = true;
			strFieldsNominator += "Please enter a value for the 'Email Address - Joint' field. \n"; 
		}
		if (theform.StreetAddress_JointNomination.value=="") {
			missingFields = true;
			strFieldsNominator += "Please enter a value for the 'Street Address - Joint' field. \n";
		}
		if (theform.City_JointNomination.value=="") {
			missingFields = true;
			strFieldsNominator += "Please enter a value for the 'City - Joint' field. \n" 
		}
		theform.PostalCode_JointNomination.value=theform.PostalCode_Nominator.value.toUpperCase();
		if (theform.PostalCode_JointNomination.value.search(/^\s*[a-ceghj-npr-tvxy]\d[a-z](\s)\d[a-z]\d\s*$/i) == -1 ) {
			theform.PostalCode_JointNomination.value = 'xxx xxx'; 
			missingFields = true;		
			strFieldsNominator +=  "Please enter a value for the 'Postal Code - Joint' field with the format xxx xxx. Example: T6G 2H7 \n";
		}	
	}
	
	if (theform.JointNomination.selectedIndex == 2) {	
		// Do nothing
	} 
	
	// NOMINEE Section 
	if (theform.IndividualOrOrganization.selectedIndex == 0) {
		missingFields = true;	
		strFieldsNominee +=  "Please enter a value for the 'Are you nominating an individual or an organization?' field. \n";
	}
	if (theform.IndividualOrOrganization.selectedIndex == 1) {
		if (theform.FirstName_Nominee.value=="") {
			missingFields = true;	
			strFieldsNominee +=  "Please enter a value for the 'First Name of Nominee' field. \n";
		}
		if (theform.LastName_Nominee.value=="") {
			missingFields = true;	
			strFieldsNominee +=  "Please enter a value for the 'Last Name of Nominee' field. \n";
		}
		if (theform.SelectOneNominationCategory_Individual.selectedIndex==0) { 
			missingFields = true;	
			strFieldsNominee +=  "Please select a value for the 'Select One Nomination Category (Individual)' field. \n";
		}
	} // end Individual 
	if (theform.IndividualOrOrganization.selectedIndex == 2) {
		if (theform.NomineeOrganization_Nominee.value=="") {
			missingFields = true;	
			strFieldsNominee +=  "Please enter a value for the 'Nominee Organization' field. \n";
		}
		if (theform.SelectOneNominationCategory_Organization.selectedIndex==0) { 
			missingFields = true;	
			strFieldsNominee +=  "Please select a value for the 'Select One Nomination Category (Organization)' field. \n";
		}
	} // end Organization 
	if (theform.PhoneNumber_Nominee.value.search(/\d{3}\-\d{3}\-\d{4}/) == -1) { 
		missingFields = true;
		strFieldsNominee += "Please enter a value for the 'Phone Number' field with the format xxx-xxx-xxxx. Example: 780-555-5555. \n"; 
	}
	if (theform.EmailAddress_Nominee.value=="") {
		missingFields = true;
		strFieldsNominee += "Please enter a value for the 'Email Address' field. \n"; 
	}
	if (theform.StreetAddress_Nominee.value=="") {
		missingFields = true;
		strFieldsNominee += "Please enter a value for the 'Street Address' field. \n"; 
	}
	if (theform.City_Nominee.value=="") {
		missingFields = true;
		strFieldsNominee += "Please enter a value for the 'City' field. \n"; 
	}
	theform.PostalCode_Nominee.value=theform.PostalCode_Nominee.value.toUpperCase();
	if (theform.PostalCode_Nominee.value.search(/^\s*[a-ceghj-npr-tvxy]\d[a-z](\s)\d[a-z]\d\s*$/i) == -1 ) {
		theform.PostalCode_Nominee.value = 'xxx xxx'; 
		missingFields = true;		
		strFieldsNominee +=  "Please enter a value for the 'Postal Code' field with the format xxx xxx. Example: T6G 2H7 \n";
	}
	if (theform.countSynopsis.value < 0) {
		missingFields = true;
		strFieldsCount += "Please use less than 75 words for the 'Synopsis' field. \n"; 
	}
	if (theform.countSynopsis.value == 75) {
		missingFields = true;
		strFieldsCount += "Please enter a value for the 'Synopsis' field. \n"; 
	}
	if (theform.countMission.value < 0) {
		missingFields = true;
		strFieldsCount += "Please use less than 250 words for the '1. In your own words, describe how the individual, corporation, foundation or group has helped your charity advance their mission' field. \n"; 
	}
	if (theform.countMission.value == 250) {
		missingFields = true;
		strFieldsCount += "Please enter a value for the '1. In your own words, describe how the individual, corporation, foundation or group has helped your charity advance their mission' field. \n"; 
	}
	if (theform.countWhyNominate.value < 0) {
		missingFields = true;
		strFieldsCount += "Please use less than 450 words for the '2. What has the nominee done to enable positive change in your organization?' field. \n"; 
	}
	if (theform.countWhyNominate.value == 450) {
		missingFields = true;
		strFieldsCount += "Please enter a value for the '2. What has the nominee done to enable positive change in your organization?' field. \n"; 
	}
	if (theform.countTimeInvolved.value < 0) {
		missingFields = true;
		strFieldsCount += "Please use less than 200 words for the '3. How did your nominee get involved with your organization?' field. \n"; 
	}
	if (theform.countTimeInvolved.value == 200) {
		missingFields = true;
		strFieldsCount += "Please enter a value for the '3. How did your nominee get involved with your organization?' field. \n"; 
	}
	if (theform.countCommunityInvolved.value < 0) {
		missingFields = true;
		strFieldsCount += "Please use less than 250 words for the '4. What other community activities is your nominee involved with?' field. \n"; 
	}
	if (theform.countCommunityInvolved.value == 250) {
		missingFields = true;
		strFieldsCount += "Please enter a value for the '4. What other community activities is your nominee involved with?' field. \n"; 
	}
	if (theform.countAdditionalComments.value < 0) {
		missingFields = true;
		strFieldsCount += "Please use less than 250 words for the '5. Additional Comments' field. \n"; 
	}
		
	// JointNomination the form
	if (missingFields == true) {
		var strFields = "";
		
		if (strFieldsNominator != "") {
			strFields += "Nominator Information \n\n" + strFieldsNominator + "\n";
		}
		if (strFieldsNominee != "") {
			strFields += "Nominee Information \n\n" + strFieldsNominee + "\n";
		}
		if (strFieldsCount != "") {
			strFields += "Long Answer Questions \n\n" + strFieldsCount;
		}
		alert(strFields); 
		
		return false; 
	} else { // OR NOT
		return true;
	}
}

// For previewing the form 
function fieldIncomplete(field, popup) {
	if (field=='xxx-xxx-xxxx' || field=='xxx xxx' || field=='Select one...' || field.length==0 || field.selectedIndex==0) {
		popup.document.write("<font color='red'>Please complete this required information.</font>");
	} else {
		popup.document.write(field);
	}
}

function fieldIncompleteIndividual(field, popup) {
	if (field=='0' || field=='Select one...' || field.length==0 || field.selectedIndex==0) {
		popup.document.write("<font color='red'>Please complete this required information.</font>");
	} else if (field=='1') {
		popup.document.write("Individual");
	} else if (field =='2') {
		popup.document.write("Organization");
	}
}

function fieldIncompleteJoint(field, popup) {
	if (field=='0' || field=='Select one...' || field.length==0 || field.selectedIndex==0) {
		popup.document.write("<font color='red'>Please complete this required information.</font>");
	} else if (field=='1') {
		popup.document.write("Yes");
	} else if (field =='2') {
		popup.document.write("No");
	}
}

function previewForm() { 
	popup = window.open('','popup','toolbar=no,menubar=no,width=500,scrollbars=yes,resizable=yes'); 
	popup.document.open(); 
	popup.document.write("<html><head><link href=\"AFPnn4.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>"); 
	popup.document.write("<font size='2' face='Arial, Helvetica, sans-serif'>"); 
	popup.document.write("<a href='javascript:window.close()'>Close Window</a> | "); 
	popup.document.write("<a href='javascript:window.print()'>Print This Page</a>"); 
	popup.document.write("<p><img src='/images/PDbanner.gif'><p><b>NOMINATION FORM</b></p>" ); 
	
// Nominator
	popup.document.write("<p><b>Nominator Information</b></p>" ); 
	popup.document.write("<p>Name of Organization Nominating <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.NameofOrganization_Nominator.value, popup); 	
	popup.document.write("<p>First Name of Contact <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.FirstNameofContact_Nominator.value, popup); 	
	popup.document.write("<p>Last Name of Contact <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.LastNameofContact_Nominator.value, popup); 	 
	popup.document.write("<p>Title of Contact <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.TitleofContact_Nominator.value, popup); 	
	popup.document.write("<p>Phone Number <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.PhoneNumber_Nominator.value, popup); 	
	popup.document.write("<p>Email Address <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.EmailAddress_Nominator.value, popup); 	
	popup.document.write("<p>Street Address <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.StreetAddress_Nominator.value, popup); 	
	popup.document.write("<p>City <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.City_Nominator.value, popup); 	 
	popup.document.write("<p>Postal Code <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.PostalCode_Nominator.value, popup); 	
	
// Joint Nominator
	popup.document.write("<p>Is this a joint nomination? <font color='red'>*</font></p>" );
	fieldIncompleteJoint(document.NominationForm.JointNomination.value, popup); 
	if (document.NominationForm.JointNomination.selectedIndex == 1) { 
		popup.document.write("<p><b> Joint Nominator Information</b></p>" ); 
		popup.document.write("<p>Name of Organization Nominating - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.NameofOrganization_JointNomination.value, popup); 	
		popup.document.write("<p>First Name of Contact - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.FirstNameofContact_JointNomination.value, popup); 	
		popup.document.write("<p>Last Name of Contact - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.LastNameofContact_JointNomination.value, popup); 	 
		popup.document.write("<p>Title of Contact - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.TitleofContact_JointNomination.value, popup); 	
		popup.document.write("<p>Phone Number - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.PhoneNumber_JointNomination.value, popup); 	
		popup.document.write("<p>Email Address - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.EmailAddress_JointNomination.value, popup); 	
		popup.document.write("<p>Street Address - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.StreetAddress_JointNomination.value, popup); 	
		popup.document.write("<p>City - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.City_JointNomination.value, popup); 	 
		popup.document.write("<p>Postal Code - Joint <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.PostalCode_JointNomination.value, popup); 	
	}
	if (document.NominationForm.JointNomination.selectedIndex == 2) {
			popup.document.write("<p>This is not a joint nomination.</p>" ); 
	}

// Nominee
	popup.document.write("<p><b>Nominee Information</b></p>" ); 
	popup.document.write("<p>Are you nominating an individual or an organization? <font color='red'>*</font></p>" );
	fieldIncompleteIndividual(document.NominationForm.IndividualOrOrganization.value, popup); 
	if (document.NominationForm.IndividualOrOrganization.selectedIndex == 1) { 
		popup.document.write("<p>First Name of Nominee <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.FirstNameofNominee_Nominee.value, popup); 	
		popup.document.write("<p>Last Name of Nominee <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.LastNameofNominee_Nominee.value, popup); 
		popup.document.write("<p>Select One Nomination Category (Individual) <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.SelectOneNominationCategory_Individual.options[document.NominationForm.SelectOneNominationCategory_Individual.selectedIndex].text, popup);	
	} 
	if (document.NominationForm.IndividualOrOrganization.selectedIndex == 2) {
		popup.document.write("<p>Name of Nominee Organization<font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.NomineeOrganization_Nominee.value, popup); 	
		popup.document.write("<p>Select One Nomination Category (Organization) <font color='red'>*</font></p>" ); 
		fieldIncomplete(document.NominationForm.SelectOneNominationCategory_Organization.options[document.NominationForm.SelectOneNominationCategory_Organization.selectedIndex].text, popup);
	}
	popup.document.write("<p>First Name of Contact (if different)</p>" ); 
	popup.document.write(document.NominationForm.FirstNameofContact_Nominee.value);
	popup.document.write("<p>Last Name of Contact (if different)</p>" ); 
	popup.document.write(document.NominationForm.LastNameofContact_Nominee.value);	
	popup.document.write("<p>Phone Number <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.PhoneNumber_Nominee.value, popup); 	
	popup.document.write("<p>Email Address <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.EmailAddress_Nominee.value, popup); 	
	popup.document.write("<p>Street Address <font color='red'>*</font></p>" );
	fieldIncomplete(document.NominationForm.StreetAddress_Nominee.value, popup); 	
	popup.document.write("<p>City <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.City_Nominee.value, popup); 	
	popup.document.write("<p>Postal Code <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.PostalCode_Nominee.value, popup); 

// Nomination
	popup.document.write("<p>Long Answer Questions</p>" ); 
	popup.document.write("<p>Please summarize the achievements of the nominee. This will be used for promotional purposes. Be sure to be clear and consise. Max. 75 words <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.Synopsis.value, popup);
	popup.document.write("<p>1. In your own words, describe how the individual, corporation, foundation or group has helped your charity advance their mission. Max. 250 words <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.Mission.value, popup);
	popup.document.write("<p>2. What has the nominee done to enable positive change in your organization? (Describe the impact the nominee has had, what specific achievements were accomplished through the nominee’s involvement and where applicable please include information on financial support and support the nominee may receive from your organization or professional staff.) Max. 450 words <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.WhyNominate.value, popup);
	popup.document.write("<p>3. How did the nominee get involved with your organization? Max. 200 words <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.TimeInvolved.value, popup);
	popup.document.write("<p>4. What other community activities is your nominee involved with? (Please include involvement at local, national and international levels.) Max. 250 words <font color='red'>*</font></p>" ); 
	fieldIncomplete(document.NominationForm.CommunityInvolved.value, popup);
	popup.document.write("<p>5. Additional Comments Max. 250 words (optional)</p>" ); 
	popup.document.write(document.NominationForm.AdditionalComments.value); 
	popup.document.write("<p><a href='javascript:window.close()'>Close Window</a> | "); 
	popup.document.write("<a href='javascript:window.print()'>Print This Page</a></p></font></body></html>"); 
	popup.document.close(); 
} 