// isSelected
	function isSelected (strValue) {
		if (strValue == "")
			return false;
		else
			return true;
	}

function isEmpty (strValue) {
	return (! strValue.replace (/^(\s*)/, "", strValue));
}

function isValidEmail (emailStr) {

	var emailPat=/^(.+)@(.+)$/; // general email format
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; // don't allow these special characters  ( ) < > @ , ; : \ " . [ ]
	var validChars="\[^\\s" + specialChars + "\]"; // what constitudes valid characters (actually what does not)
	var quotedUser="(\"[^\"]*\")"; // user can be quoted, eg. "jiminy cricket"@disney.com
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; // IP address instead of host, eg joe@[123.234.345.1]
	var atom=validChars + '+'; // atoms are a series of non-special characters
	var word="(" + atom + "|" + quotedUser + ")"; // represents one word in the typical username
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); // describes the structure of the user
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); // describes the structure of a normal domain name (non-IP)

	// Break up user@domain into different pieces that are easy to analyze.
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		return false; // alert("Email address seems incorrect (check @ and .'s)");
	}

	var user=matchArray[1];
	var domain=matchArray[2];

	// See if "user" is valid
	if (user.match(userPat)==null) {
		return false; // alert("The username doesn't seem to be valid.");
	}

	// if the e-mail address is at an IP address (as opposed to a symbolic
	// host name) make sure the IP address is valid.
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return false; // alert("Destination email IP address is invalid!");
			}
		}
		return true; // no need to checkfurther - code below is for non-IP domain names
	}

	// Domain is symbolic name, not an IP
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
	    return false; // alert("The domain name doesn't seem to be valid.");
	}

	// Now we need to break up the domain to get a count of how many atoms
	// it consists of.
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>3) {
		return false; // alert("The address must end in a three-letter domain, or two letter country.");
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
		return false; // alert("This address is missing a hostname!");
	}

	// If we've gotten this far, everything's valid!
	return true;
}

// branchSearchCheckComplete
	function branchSearchCheckComplete(formObj) {
		var alert_message = "";

		if (!isSelected(formObj.ctyID.value)) {
			alert_message = alert_message + "   Country\n";
		}

		if (!isSelected(formObj.staID.value)) {
			alert_message = alert_message + "   State\n";
		}

		if (!isSelected(formObj.areID.value)) {
			alert_message = alert_message + "   Area of State\n";
		}

		if (alert_message) {
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else {
			return true;
		}
	}


// checkContactDetailsComplete
	function checkContactDetailsComplete(formObj) {
		var alert_message = "";
		if (isEmpty(formObj.contactName.value)) {
			alert_message = alert_message + "   Name\n";
		}

		if (isEmpty(formObj.contactAddress.value)) {
			alert_message = alert_message + "   Address\n";
		}

		if (isEmpty(formObj.contactTown.value)) {
			alert_message = alert_message + "   Town\n";
		}

		if (isEmpty(formObj.contactPhone.value)) {
			alert_message = alert_message + "   Phone\n";
		}

		if (isEmpty(formObj.contactEmail.value)) {
			alert_message = alert_message + "   Email\n";
		} else {
			if (!isValidEmail(formObj.contactEmail.value)) {
				alert_message = alert_message + "   Valid Email\n";
			}
		}

		if (alert_message) {
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else {
			return true;
		}
	}
