/*************************************
 *
 * @Author: Danielle Danielsson
 * 
 * @Date:   27 January 2005
 *
 ************************************/


/**
 * Validates Volunteers Application Form Fields
 */
function AppForm_Validation(thisForm){

 	if (thisForm.FirstName.value == ""){ 	
		alert("Please enter your First Name.");
		thisForm.FirstName.focus();
		return(false);
	}
 	else if (thisForm.FirstName.value != "" && thisForm.FirstName.value.length > "20") {
		alert("Your FIRST NAME exceeds 20 characters. It can't be THAT long!");
		thisForm.FirstName.focus();
		return(false);
	}
 	if (thisForm.LastName.value == ""){ 	
		alert("Please enter your Last Name.");
		thisForm.LastName.focus();
		return(false);
	}
 	else if (thisForm.LastName.value != "" && thisForm.LastName.value.length > "20") {
		alert("Your LAST NAME exceeds 20 characters. It can't be THAT long!");
		thisForm.LastName.focus();
		return(false);
	}
   	if (thisForm.Street.value == ""){ 	
		alert("Please enter your Street Name.");
		thisForm.Street.focus();
		return(false);
	}
 	else if (thisForm.Street.value != "" && thisForm.Street.value.length > "40") {
		alert("Your STREET NAME exceeds 40 characters. It can't be THAT long!");
		thisForm.Street.focus();
		return(false);
	}
   	if (thisForm.Suburb.value == ""){ 	
		alert("Please enter your Suburb.");
		thisForm.Suburb.focus();
		return(false);
	}
 	else if (thisForm.Suburb.value != "" && thisForm.Suburb.value.length > "20") {
		alert("Your SUBURB NAME exceeds 20 characters. It can't be THAT long!");
		thisForm.Suburb.focus();
		return(false);
	}
	else if (thisForm.PostCode.value == ""){ 	
		alert("Please enter your POST CODE.");
		thisForm.PostCode.focus();
		return(false);
   } 
   	else if (thisForm.Phone.value == ""){ 	
		alert("Please enter your PHONE NUMBER.");
		thisForm.Phone.focus();
		return(false);
   } 	
   	else if (thisForm.Phone.value != "" && thisForm.Phone.value.length > "20") {
		alert("Your PHONE NUMBER exceeds 20 characters. It can't be THAT long!");
		thisForm.Phone.focus();
		return(false);
	}
   	else if (thisForm.Mobile.value == ""){ 	
		alert("Please enter your MOBILE PHONE NUMBER.");
		thisForm.Mobile.focus();
		return(false);
   } 	
 	else if (thisForm.Mobile.value != "" && thisForm.Mobile.value.length > "20") {
		alert("Your MOBILE NUMBER exceeds 20 characters. It can't be THAT long!");
		thisForm.Mobile.focus();
		return(false);
	}
  
	else if (thisForm.Email.value == ""){ 	
		alert("Please enter your EMAIL address.");
		thisForm.Email.focus();
		return(false);
	}
	else if (thisForm.Email.value != "" && thisForm.Email.value.length > "50") {
		alert("Your EMAIL address exceeds 60 characters. Are you sure it is that long?.");
		thisForm.Email.focus();
		return(false);
	}
	else if (thisForm.VolunteeringBecause.value == ""){ 	
		alert("Please let us know why you want to volunteer.");
		thisForm.VolunteeringBecause.focus();
		return(false);
	}
	else if (thisForm.VolunteeringBecause.value != "" && thisForm.VolunteeringBecause.value.length > "1000") {
		alert("Your Reason For Volunteering exceeds 1000 characters. Please keep don't exceed 1000 characters.");
		thisForm.VolunteeringBecause.focus();
		return(false);
	}
	else if (thisForm.Experience.value == ""){ 	
		alert("Please fill in your Experience.");
		thisForm.Experience.focus();
		return(false);
	}

	else if (thisForm.Experience.value != "" && thisForm.Experience.value.length > "10000") {
		alert("Your Experience description exceeds 1000 characters. Please keep don't exceed 10000 characters.");
		thisForm.Experience.focus();
		return(false);
	}
	else if (!thisForm.EAS[0].checked && !thisForm.EAS[1].checked){ 	
		alert("Please select an option for Evening Advice Sessions");
		thisForm.EAS[0].focus();
		return(false);
	}

	else if (!thisForm.GeneralLawAdvisor[0].checked && !thisForm.GeneralLawAdvisor[1].checked){ 	
		alert("Please select an option to indicate your Qualifications");
		thisForm.GeneralLawAdvisor[0].focus();
		return(false);
	}
	else if (!thisForm.MigrationAdvisor[0].checked && !thisForm.MigrationAdvisor[1].checked){ 	
		alert("Please select an option to indicate your Qualifications");
		thisForm.MigrationAdvisor[0].focus();
		return(false);
	}
	else if (thisForm.EAS_Availability.value == ""){ 	
		alert("Please let us know of your availability.");
		thisForm.EAS_Availability.focus();
		return(false);
	}
	else if (!thisForm.DayVolunteer[0].checked && !thisForm.DayVolunteer[1].checked){ 	
		alert("Please select one of the Day Volunteer options");
		thisForm.DayVolunteer[0].focus();
		return(false);
	}
	else if (thisForm.DayAvailability.value == ""){ 	
		alert("Please let us know of your availability.");
		thisForm.DayAvailability.focus();
	return(false);
	}


	//Check that gpa results are of correct datatype 
   //verifyDigits(thisForm.h_phone.value,thisForm);
	//verifyDigits(thisForm.result_first_yr.value,thisForm);
	//verifyDigits(thisForm.result_second_yr.value, thisForm);
	//verifyDigits(thisForm.result_third_yr.value, thisForm);




	//if all fields are filled in, check that dates is in valid format
	
	//verifyDateFormat(thisForm.start_date1.value);
	//verifyDateFormat(thisForm.end_date1.value);
	//verifyDateFormat(thisForm.start_date2.value);
	//verifyDateFormat(thisForm.end_date2.value);



}


/*
* Verifies date entered uses correct format (xx/xx/xxxx), where x is
* any digit (0 - 9).
*/

function verifyDateFormat(data)
{
	regExDate = /\d\d\/\d\d\/\d\d\d\d/;
	var input = new String(data);

	if(!(regExDate.test(input)))
	{
		alert("Error, invalid date format!\nMust use mm/dd/yyyy format.");
	   	return(false);
	}
	else
	{
		verifyDateValue(data);
	}
}


/*
* Checks that the date values are valid.
*/
function verifyDateValue(data)
{
	var errors = false;
	var errorString = "";
	var currentYear = 1999;
	var input = new String(data);

	// if month begins with '0', Javascript thinks this is an octal. (?)
	// these selection statements get around this
	if(input.substring(0, 1) == 0)
	{
		var month = parseInt(input.substring(1, 2));
	}

	else
	{
		var month = parseInt(input.substring(0, 2));
	}

	// if day begins with '0', Javascript thinks this is an octal. (?)
	// these selection statements get around this
	if(input.substring(3, 4) == 0)
	{
		var day = parseInt(input.substring(4, 5));
	}

	else
	{
		var day = parseInt(input.substring(3, 5));
	}

	var year = parseInt(input.substring(6, 10));

	if((month > 12) || (month < 1))
	{
		errorString = errorString + "\nMonth " + month + " is invalid. (use 01-12 inclusive)";
		errors = true;
	}

	if(isNaN(month))
	{
		errorString = errorString + "\nMonth " + month + " is not a number";
		errors = true;
	}

	if((day > 31) || (day < 1))
	{
		errorString = errorString + "\nDate " + day + " is invalid (use 01-31 inclusive)";
		errors = true;
	}

   	if(errors)
	{
			alert("It is important that the DATE is entered correctly. \nYou entered: " + month + "/" + day + "/" + year + "\n" + errorString);
		
	}
}





