// 
// Copyright (c) 2001, ThoughtByDesign. All rights reserved.
// 
// This computer program is protected by copyright law and international treaties.
// Unauthorized reproduction or distribution of this program, or any portion of it,
// may result in severe civil and criminal penalties, and will be prosecuted to the
// maximum extent possible under the law.
// 
// Class: NA (validation utilities)
// 
// Author: Rob Allen
// Last Modified: November 27, 2001
// 
//


function ValidateAmount(amount, fieldName) {
	var rawAmount = amount.replace(/[$]/g,"");
	rawAmount = rawAmount.replace(/[,]/,"");
	
	if (isNaN(parseFloat(rawAmount)) == true) {
		alert("Enter a valid amount (e.g., 55,000.00).");
		return false;
	} // if
	return true;
} // ValidateAmount()


function ValidateNumber(value, name, min, max) {
	var intValue = parseInt(value);
	if (isNaN(intValue) == true || intValue < min || intValue > max) {
		alert("The "+name+" field must be a number between "+min+" and "+max+"." );
		return false;
	} // if
	return true;
} // ValidateNumber()


function ValidatePhone(phone, fieldName) {
	if (ValidateRequired(phone,fieldName) == false) {
		return false;
	} // if
	return true;
} // ValidatePhone()


function ValidateZip(zip, fieldName) {
	if (ValidateRequired(zip,fieldName) == false) {
		return false;
	} // if
	
	var zipText = zip.replace(/\s/g,"");
	var lengthOk = zipText.length == 5 || zipText.length == 9;
	if (isNaN(parseInt(zip)) == true || lengthOk == false) {
		alert("Enter a valid zip code, e.g., 00288.");
		return false;
	} // if
	return true;
} // ValidateZip()


function ValidateEmail(email) {
	if (email.indexOf("@") == -1) {
		alert("Enter a valid email address.");
		return false;
	} // if
	if (email.indexOf(".") == -1) {
		alert("Enter a valid email address.");
		return false;
	} // if
	return true;
} // ValidateEmail()


function ValidateRequired(value, fieldName) {
	if (value == null) {
		alert("You must enter a value in the "+fieldName+" field.");
		return false;
	} // if
	var strippedValue = value.replace(/\s/g,"");
	if (strippedValue == "") {
		alert("The "+fieldName+" field may not be blank.");
		return false;
	} // if
	return true;
} // ValidateRequired()


function ValidateLength(value, maxLength, fieldName) {
	if (value == null) {
		return true;
	} // if
	if (value.length > maxLength) {
		alert("The "+fieldName+" field may not be longer than "+maxLength+" characters.");
		return false;
	} // if
	return true;
} // ValidateLength()