//Hillsborough County JS File
//Included via head.html

function checkForm(oForm, arrFormFields){
	/*****************************************
	 * checkForm(form object, array of Form Fields that are required)
	 * checkForm() is used to insure that all text fields within a form
	 * have been filled in. To use, call the function from the opening
	 * form tag in the onSubmit method:
	 * 		<form method="post" onSubmit="return checkForm(this, createArray('field1','field2',fieldx'))">
	 * the first argument is a reference to the current form object, obtained by passing this. The second
	 * argument is an array of fields you want checked. This function loops through this array and verifies
	 * that each field has a value entered into it. If it does not, it generates an alert message containing
	 * all of the fields that were missing, and moves focus to the first field it found that was not filled in.
	 *****************************************/
	sErrorList = "We're sorry, the following required fields were not filled out:\n";
	isValid = true;
	reSeperator = /_/g; //regex for the seperator in the fields
	oFocusField = null; //field to focus on if there are missing fields.
	
	for(i=0;i<arrFormFields.length;i++){
		oField = eval("oForm."+arrFormFields[i]);
		if(trim(oField.value).length == 0){
			sErrorList += arrFormFields[i].replace(reSeperator, " ")+"\n";
			isValid = false;
			if(oFocusField == null){
				oFocusField = oField;
			}
		}
	}
	
	if(isValid){
		return true;
	}else{
		alert(sErrorList);
		oFocusField.focus();
		return false;
	}
}

function checkPasswords(oForm){
	if(trim(oForm.Password.value) != "" && oForm.Password.value == oForm.Password_Confirm.value){
		return true;
	}else{
		alert("We're sorry, the passwords you entered did not match");
		return false;
	}
}

function confirmSubmit(){
	theMessage = "By submitting this form you agree to the terms outlined in the legal notice available by clicking on \"Legal Information\" at the bottom of the page. This includes, but is not limited to, agreeing that any and all information submitted by this form or via email becomes a public record to the extent provided by law; public records are subject to being reviewed by any person desiring to review such records.\nTo continue and submit this form click Ok.\nTo cancel and not send the information click Cancel.";

	if(confirm(theMessage)){
		return true;
	}else{
		alert("Your submission has been cancelled");
		return false;
	}
}

function createArray(){
	//this is used to create an array of objects
	return arguments;
}

// Function to 'activate' images.
function imgOn(imgName) {
        if (document.images) {
            document[imgName].src = eval(imgName + "on.src");
        }
}
// Function to 'deactivate' images.
function imgOff(imgName) {
        if (document.images) {
            document[imgName].src = eval(imgName + "off.src");
        }
}

function trim(sText){
	//remove leading spaces
	while(sText.substring(0,1) == ' '){
		sText = sText.substring(1,sText.length);
	}
	//remove trailing spaces
	while(sText.substring(sText.length-1,sText.length) == ' '){
		sText = sText.substring(0,sText.length-1);
	}
	
	return sText;
}