
function FrontPage_Form1_Validator(theForm)
{

if (theForm.txtFname.value == "")
  {
    alert("Please enter your First Name");
    theForm.txtFname.focus();
    return (false);
  }

if (theForm.txtLname.value == "")
  {
    alert("Please enter your Last Name.");
    theForm.txtLname.focus();
    return (false);
  }
  
if (theForm.txtUname.value == "")
  {
    alert("Please choose a username.");
    theForm.txtUname.focus();
    return (false);
  }
    
if (theForm.txtPwd.value == "")
  {
    alert("Please choose a password.");
    theForm.txtPwd.focus();
    return (false);
  }
  
if (theForm.txtRePwd.value == "")
  {
    alert("Please re-enter password.");
    theForm.txtRePwd.focus();
    return (false);
  }

if (theForm.txtPno1.value == "")
  {
    alert("Please enter a phone number or simply enter 0.");
    theForm.txtPno1.focus();
    return (false);
  }

var checkOK = "0123456789-. ";
  var checkStr = theForm.txtPno1.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == " " && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != " ")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the phone number field.");
    theForm.txtPno1.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid phone number in the Phone Number Field or Simply enter 0.");
    theForm.txtPno1.focus();
    return (false);
  }
  
if (theForm.txtPno2.value == "")
  {
    alert("Please enter a value for the Alternate Phone Number or simply enter 0.");
    theForm.txtPno2.focus();
    return (false);
  }

var checkOK = "0123456789-. ";
  var checkStr = theForm.txtPno2.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == " " && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != " ")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the Alternate Phone Number Fields.");
    theForm.txtPno2.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid figure as Alternate Phone Number.");
    theForm.txtPno2.focus();
    return (false);
  }
  
if (theForm.txtemail.value == "")
  {
    alert("Please enter a valid email address.");
    theForm.txtemail.focus();
    return (false);
  }
  
{  
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=theForm.txtemail.value.match(emailPat);

if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username part of email address contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name part of email address contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The username part of email address doesn't seem to be valid.");
return false;
}

/* 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) {
alert("Destination IP address part of email address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name part of email address does not seem to be valid.");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The email address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This email address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}


if (theForm.txtreemail.value == "")
  {
    alert("Please re-enter email address.");
    theForm.txtreemail.focus();
    return (false);
  }

if (theForm.txtPwd.value != theForm.txtRePwd.value)
  {
    alert("Password and Password Confirmation are not the same!");
    theForm.txtPwd.focus();
    return (false);
  }

if (theForm.chkAccept.checked == false)
  {
    alert("You have to agree with the Terms and Conditions to proceed with the registration!");
    theForm.chkAccept.focus();
    return (false);
  }
  
if (theForm.txtemail.value != theForm.txtreemail.value)
  {
    alert("Email and Email Confirmation are not the same!");
    theForm.txtemail.focus();
    return (false);
  }

}
