function err (field, msg) {
	alert(msg);
	field.focus();
	return (false);
}

function FormValidate() {
	var form = document.rentersForm;

	if (!isValidNumericField(form.zipcode, 5, "Zip Code")){
        return (false);
	}

	if (form.email.value && !isValidEmail(form.email)) {
		return err(form.email, "Please re-enter your Email Address.\n Note: the Email Address you entered is not valid.");
	}
}


function isEmptyField(fieldName, errorText) {

	if (fieldName.value == "" )
		return !(err(fieldName, "Please enter " + errorText + "."));
			
	return (false);
}

function isOnlyDigits(numberStr) {

	var validChars = "0123456789";
	
	for (var i=0; i<numberStr.length; i++) {
		if (validChars.indexOf(numberStr.charAt(i)) == "-1")
			return (false);
	}
	
	return (true);
}

function isValidNumericField(field, fieldSize, errorText) {

	if (field.value == "" )
		alert("Please enter your " + errorText + ".");
	else if (!isOnlyDigits(field.value))
  		alert("Please re-enter " + errorText + " information. \nNote: Only numbers are accepted.");
	else if (field.value.length < fieldSize)
  		alert("Please re-enter " + errorText + " information. \n The information you entered  is incomplete.");
	else
		return (true);
	
	field.focus();
	return (false);
}


function isValidEmail(hInput) {
	// Interim fix to allow leading/trailing spaces.
	// TODO: Use client-side validation functions from /js/forms.js instead
	var strEmail = hInput.value;
	if (/^\s/.test(strEmail)) { strEmail = strEmail.replace(/^\s{1,}/, ""); }
	if (/\s$/.test(strEmail)) { strEmail = strEmail.replace(/\s{1,}$/, ""); }
	hInput.value = strEmail;
	if (strEmail.length < 5) { return false; }
	if (!/(^[A-z0-9\.\-_]*)@([A-z0-9\.\-_]+)\.([A-z]{2,4})$/.test(strEmail)) { return false; }
	return true;
}


function addElement(list, text_in, value_in) {

	var o = list.options;
	var nIdx;
	if (o.length < 0) //IE for Mac 4.5 sets length to -1 if list is empty
		nIdx = 0;
	else
		nIdx = o.length;

	o[nIdx] = new Option(text_in, value_in);
}