function trim(s) {
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmpty(formName, fieldName) {
    var error = 0;
    if(eval("formName."+fieldName+".value.length == 0 || trim(formName."+fieldName+".value).length == 0")) {
        eval("formName."+fieldName+".style.border = '1px solid red'");
		eval("document.getElementById(fieldName+'Label').style.color='red'");
        error = 1;
    } else {
        eval("formName."+fieldName+".style.border = '1px solid black'");
		eval("document.getElementById(fieldName+'Label').style.color='black'");
    }
    return error;   
}
function validateEmail(formName, fieldName) {
    var error = 0;
    var theField = eval("formName."+fieldName+".value");
    var atPos=theField.indexOf("@");
	var dotPos=theField.lastIndexOf(".");
	var whiteSpace=theField.indexOf(" ");
    var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/
    if(theField == "" || atPos<1 || dotPos-atPos<2 || whiteSpace>-1 || eval("formName."+fieldName+".value.match(illegalChars)")) {
        eval("formName."+fieldName+".style.border = '1px solid red'");
		eval("document.getElementById(fieldName+'Label').style.color='red'");
        error = 1;
    } else {
        eval("formName."+fieldName+".style.border = '1px solid black'");
		eval("document.getElementById(fieldName+'Label').style.color='black'");
    }
    return error;
}
function checkForm(theForm) {
	var test1=validateEmpty(theForm, "contactName");
	var test2=validateEmpty(theForm, "contactEmail");
	var test3=validateEmail(theForm, "contactEmail");
	var test4=validateEmpty(theForm, "contactText");
	if( test1 || test2 || test3 || test4) {
		return false;
	} else {
		return true;
	}
}
