
// FORM VALIDATION FUNCTIONS
// Copyright © 2005 Richard de Nys. All rights reserved.
//______________________________________________________


function checkEmail(e) {
	// Machinas for DXM v0.8
	var errors = '';
	// var e = document.getElementById(fieldID).value;
	e = e.replace(/^\s+/,'').replace(/\s+$/,'');
	if (e != "") {
		var amp=e.indexOf('@');
		var dot=e.indexOf('.');
		var illegals=/[\(\)\<\>\,\;\:\\\"\[\]\ ]/;
		var tld=/^.+@.+\..{2,}$/;
		if (amp<1) errors+='An @ is missing.\n'; // An @ is missing from the email address.
		if (dot<1) errors+='A . (dot) is missing.\n'; // A . is missing from the email address.
		if (amp==(e.length-1) || dot==(e.length-1) || !(tld.test(e))) errors+='The address is not complete.\n'; // The email address is not complete.
		if (e.match(illegals)) errors+='The address contains illegal characters.'; // The email address contains illegal characters.
	}
	if (!errors) {
		return "";
	} else {
		errors = 'Please check the email address:\n'+errors; // Please check the email address:
		return errors;
	}
}

function checkForm(formName) {
	var errors = '';
	var f = document.forms[formName];
	if (formName == 'contact') {
		var fields = new Array("email");
	}

	for (var x=0; x < fields.length; x++) {
		if (eval("f."+fields[x]+".value") == "") {
			errors+='Please complete all fields marked with a *.\n';
			break;
		}
	}
	if (typeof(f.email) != "undefined") errors += checkEmail(f.email.value);

	if (!errors) {
		document.returnValue = true;
	} else {
		alert(errors);
		document.returnValue = false;
	}
}
