function toggleLayer(whichLayer, onOff)
{
	if(onOff) {
		var style1 = document.getElementById(whichLayer).style;
		style1.display = "none";
	} else {
		var style1 = document.getElementById(whichLayer).style;
		style1.display = "block";
	}
}

function submitform(formName) {
	alert("asdf " + formName);
	document.form_1.submit();
}

function ReplaceChars(text) {
	cleanString = "";
	for (i=0; i < text.length; i++) {
		myChar = text.charAt(i);
		if (myChar == "{" || myChar == "}" || myChar == "<" || myChar == ">" || myChar == "[" || myChar == "]" || myChar == "-" || myChar == '"') {
			cleanString = cleanString + "";
		} else {
			cleanString = cleanString + myChar;
		}
	}
	return cleanString;
}
function limitText(commentBox,maxChars) {
	var result = true;
	if (commentBox.value.length >= maxChars) {
		result = false;
 		}
	if (window.event) {
		window.event.returnValue = result;
		return result;
	}	
}
function filterNonNumeric(field) {
	var result = new String();
	var numbers = "0123456789";
	var chars = field.value.split("");  //create array
	for (i = 0; i < chars.length; i++) {
		if (numbers.indexOf(chars[i]) != -1) {
			result += chars[i];
		}
	}
	return result;
}
function filterNonNumericString(str) {
	var result = new String();
	var numbers = "0123456789";
	var chars = str.split("");  //create array
	for (i = 0; i < chars.length; i++) {
		if (numbers.indexOf(chars[i]) != -1) {
			result += chars[i];
		}
	}
	return result;
}
function filterNonAlpha(field) {
	var result = new String();
	var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var chars = field.value.split("");  //create array
	for (i = 0; i < chars.length; i++) {
		if (letters.indexOf(chars[i]) != -1) {
			result += chars[i];
		}
	}
	return result;
}
function isEmailWellFormed(email) {
	
	invalidChars=" <>[]{}/:,';!";
	
	
	for (i=0; i<invalidChars.length; i++) {
		if (email.indexOf((invalidChars.charAt(i)),0)>-1) {
			return("The following characters are not allowed in an e-mail address:'" + invalidChars + "'");
		}
	}

	
	atPos=email.indexOf("@",0);
	if ((atPos<=0) || (email.indexOf("@",atPos+1)>-1)) {
		return("A valid e-mail address has the form: username@domain");
	}

	
	
	domainParts = (email.substring(atPos+1,email.length)).split(".");
	domainPartsCount = domainParts.length;
	
	
	if (domainPartsCount<2) {
		return("The domain must contain at least one period");
	}

	
	for (i=0;i<domainPartsCount;i++) {
		if (domainParts[i].length==0) {
			return("Periods in the domain are not placed properly");
		}
	}

	
	if (domainParts[domainPartsCount-1].length<2) {
		return("The final portion of the domain must be at least two characters long");
	}

	
	return ("");
}

function validate_alpha_field(field_name, error_string) {
	if (filterNonAlpha(document.form[field_name]) == '') {
		alert('Please enter ' + error_string + '.');
		document.form[field_name].focus();
		return false;
	} else {
		document.form[field_name].value = ReplaceChars(document.form[field_name].value);
		return true;
	}
}

function validate_text_field(field_name, error_string) {
	if (filterNonAlpha(document.form[field_name]) == '') {
		alert('Please enter ' + error_string + '.');
		document.form[field_name].select();
		document.form[field_name].focus();
		return false;
	} else {
		document.form[field_name].value = ReplaceChars(document.form[field_name].value);
		return true;
	}
}

function validate_mixed_field(field_name, error_string) {
	if (filterNonAlpha(document.form[field_name]) == '' || filterNonNumeric(document.form[field_name]) == '') {
		alert('Please enter ' + error_string + '.');
		document.form[field_name].focus();
		return false;
	} else {
		document.form[field_name].value = ReplaceChars(document.form[field_name].value);
		return true;
	}
}

function validate_numeric_field(field_name, error_string, length, concat_num) {
	if (concat_num) {
		concat_num = filterNonNumericString(concat_num);
	}
	if (filterNonNumeric(document.form[field_name]) == '') {
		alert('Please enter ' + error_string + '.');
		document.form[field_name].focus();
		return false;
	} else {
		if (length) {
			if (concat_num) {
				field_length = concat_num.length;
				if (field_length != length) {
					alert(error_string + ' does not contain the correct length of characters.');
					document.form[field_name].focus();
					return false;
				} else {
					document.form[field_name].value = ReplaceChars(document.form[field_name].value);
					return true;
				}
			} else {
				if (document.form[field_name].value.length != length) {
					alert(error_string + ' does not contain the correct length of characters.');
					document.form[field_name].focus();
					return false;
				} else {
					document.form[field_name].value = ReplaceChars(document.form[field_name].value);
					return true;
				}
			}
		}
	}
}
function select_defined(field_name, error_string) {
	if (document.form[field_name].value == '') {
		alert('Please enter ' + error_string + '.');
		document.form[field_name].focus();
		return false;
	} else {
		return true;
	}
}
