function trim(strVal) {
  if (strVal == null) return strVal;
  return strVal.replace(/^\s+|\s+$/g,"");
}

function checkTalkbackForm() {

    var formErrors = "These empty fields prevented your submission.  Please supply:\r\n";
    var failFields = 0;
    var docRef = document.talkbackform;

    if (trim(docRef.TITLE.value) == "") {
        formErrors += "* A title\n";
        failFields = 1;
    }
    if (trim(docRef.COMMENTS.value) == "") {
        formErrors += "* A comment\n";
        failFields = 1;
    }
    if (trim(docRef.FULLNAME.value) == "") {
        formErrors += "* A fullname\n";
        failFields = 1;
    }
    if (trim(docRef.EMAIL.value) == "") {
        formErrors += "* An e-mail address!\n";
        failFields = 1;
    }
    else {       
       //ATTR_RE= /^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-.]?[0-9a-zA-Z])*[.][a-zA-Z]{2,3}$/gi;
       ATTR_RE = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

     if (!ATTR_RE.test(docRef.EMAIL.value)) {
          formErrors += "* A valid e-mail address!!\n";
          failFields = 1;   
     }
    }
    if ((docRef.SCODE) && (trim(docRef.SCODE.value) == "") ) {
        formErrors += "* The security code\n";
        failFields = 1;
    }		

    if (failFields == 1) {
        alert(formErrors);
        return false;
    } else {
        return true;
    }
}

function cancelForm() {
  var url = "[?=$returl?]";
  location.href = url;
}