function doReleaseSubmit() {
var frm = document.getElementById('frmregister');
var mrs;
var email = frm.DataEmailSender.value != '';
var pwd1 = frm.DataPassword.value != '';
var pwd2 = frm.DataPasswordConfirm.value != '';
var nameLval = LTrim(frm.DataNameLast.value);
var nameFval = LTrim(frm.DataNameFirst.value);
var nameL = nameLval != '';
var nameF = nameFval != '';
var country = frm.DataCountryName.value != '';
  //Prevent leading and tailing spaces in last and first name
  if (frm.DataNameLast.value != nameLval) {
    frm.DataNameLast.value = nameLval;
  }
  if (frm.DataNameFirst.value != nameFval) {
    frm.DataNameFirst.value = nameFval;
  }
  //Reset validation error display
  if (!formReturnOrFormFirst) { //Reset the email-in-use if not run automaically on page entry
    document.getElementById('DataProcessErrorEmailInUse').style.display = 'none';
    document.getElementById('DataProcessErrorUnspecified').style.display = 'none';
  }
  document.getElementById('DataProcessErrorPassword').style.display = 'none';
  document.getElementById('DataProcessErrorPasswordLength').style.display = 'none';
  document.getElementById('DataProcessErrorEmailFormat').style.display = 'none';
  if (frm.sex_ms != null) { //The third title option is optional (you know what I mean)
    mrs = (frm.sex_mr.checked || frm.sex_mrs.checked || frm.sex_ms.checked);
  }
  else {
    mrs = (frm.sex_mr.checked || frm.sex_mrs.checked);
  }
  if (email && pwd1 && pwd2 && mrs && nameL && nameF && country) {
    frm.formsubmit.disabled = false;
  }
  else {
    frm.formsubmit.disabled = true;
  }
}

/* IDs for error message paragraphs
"DataProcessErrorEmailInUse"      Email/loginID in use
"DataProcessErrorEmailFormat"     Wrong email format (according to isEmail function)
"DataProcessErrorPassword"        Password and confirmation not equal
"DataProcessErrorPasswordLength"  Password to short oor to long
*/

function doValidate() {
var submit = true;
var frm = document.getElementById('frmregister');
var emailerr = isEmail(frm.DataEmailSender.value);
var pwderr = isPwdOK(frm.DataPassword.value, frm.DataPasswordConfirm.value);
  //Clean up any leading and tailing spaces in the mane and first name
  frm.DataNameLast.value = Trim(frm.DataNameLast.value);
  frm.DataNameFirst.value = Trim(frm.DataNameFirst.value);
  //Check email
  if (emailerr != '') {
    //alert('Email address "' + document.frm.DataEmailSender.value + '":\n' + emailerr);
    document.getElementById('DataProcessErrorEmailFormat').style.display = '';
    submit = false;
  }
  //Check password
  if (pwderr != '' && submit) {
    //alert(pwderr);
    if (pwderr.indexOf('confirmation') != -1) { //If we find text as to different password and confirmation
      document.getElementById('DataProcessErrorPassword').style.display = '';
    }
    else { //any illegal characters or length
      document.getElementById('DataProcessErrorPasswordLength').style.display = '';
    }
    submit = false;
  }
  if(submit) {
    frm.DataNameLast.value = Trim(frm.DataNameLast.value); //No tailing spaces
    frm.DataNameFirst.value = Trim(frm.DataNameFirst.value); //Do.
    frm.submit();
  }
  else {
    //reset message for email in use
    document.getElementById('DataProcessErrorEmailInUse').style.display = 'none';
    document.getElementById('DataProcessErrorUnspecified').style.display = 'none';
  }
}


function isEmail(eadr) {
//var cIllegalChars = '()<>,;:\/"[] ' //Below 128, notably not ' (single quotation mark), but double qoutation mark
var cIllegalChars =  ' /|\&$#%*`",:;()<>[]{}'; //Below 128, notably not ' (single quotation mark), but double qoutation mark
var blank, arr, nam, dom, i
  for (i = 0; i < cIllegalChars.length; i++) {
    if (eadr.indexOf(cIllegalChars.charAt(i)) != -1) {
      blank = '';
      if (cIllegalChars.charAt(i) == ' ') { //Help identify the space character
        blank = '(space) ';
      }
      return 'Illegal character "' + cIllegalChars.charAt(i) + '" ' + blank + 'at pos. ' + (eadr.indexOf(cIllegalChars.charAt(i)) + 1);
    }
  }
  for (i = 0; i < eadr.length; i++) { //Check for characters above 127
    if (eadr.charCodeAt(i) > 127) {
      return 'Illegal character "' + eadr.charAt(i) + '" at pos. ' + (i + 1);
    }
  }
  arr = eadr.split('@');
  if (arr.length != 2) { //We want exactly one "@"
    return 'Illegal format: Missing or to many "@"';
  }
  if (arr[0].length == 0) {
    return 'Illegal format: Missing name';
  }
  nam = arr[0].split('.');
  for (i = 0; i < nam.length; i++) {
    if (nam[i] == '') { //We want no "ab..cd", "ab." or ".cd" in the name
      return 'Illegal format: Invalid use of "." in name';
    }
  }
  dom = arr[1].split('.');
  if (dom.length < 2) { //We want at least one "." in the domain
    return 'Illegal format: Missing "." in domain name';
  }
  for (i = 0; i < dom.length; i++) {
    if (dom[i] == '') { //We want no "xx..yy", "xx." or ".xx" in the domain
      return 'Illegal format: Invalid use of "." in domain name';
    }
  }
  if (dom[dom.length - 1].length < 2) { //We want at least two characters in domain main id
    return 'Illegal format: ';
  }
  return '';
}

function isPwdOK (pwd1, pwd2) {
var minlen = 4, maxlen = 30;
var len, awr;
  len = pwd1.length
  if (pwd1.indexOf(' ') != -1) {
    return 'Password may not contain spaces';
  }
  if (pwd1.indexOf('"') != -1) {
    return 'Password may not contain double quotationmarks';
  }
  if (len < minlen || maxlen < len) {
    return 'Password must be between ' + minlen + ' and ' + maxlen + ' characters long';
  }
  if (pwd1 != pwd2) {
    return 'Password and confirmation are different';
  }
  return '';
}


function clearField(fld) {
  fld.value = '';
  doReleaseSubmit();
}