//<!--
// This function will validate a form

function alphanumeric(alphane)
{
        var numaric = alphane;
        for(var j=0; j<numaric.length; j++)
                {
                  var alphaa = numaric.charAt(j);
                  var hh = alphaa.charCodeAt(0);
                  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
                  {
                  }
                else        {
                         return false;
                  }
                }
 return true;
}


function validateForm(theform)
{
  pass = 1; //assume everything is ok
  msg = "The following problems where found in trying to submit this form:\n\n";

  //make sure required fields are not empty
  if (isEmpty(theform.login.value))
  {
    msg = msg + "- Login cannot be empty\n";
    pass = 0;
  }

  if (!alphanumeric(theform.login.value))
  {
    msg = msg + "- Login  must be alphanumeric value\n";
    pass = 0;
  }

  if (isEmpty(theform.fname.value))
  {
    msg = msg + "- Fullname cannot be empty\n";
    pass = 0;
  }

  if (isEmpty(theform.introducer.value))
  {
    msg = msg + "- Introducer ID cannot be empty\n";
    pass = 0;
  }


  if (isEmpty(theform.phone.value))
  {
    msg = msg + "- Phone Number cannot be empty\n";
    pass = 0;
  }

  if (isEmpty(theform.security_code.value))
  {
    msg = msg + "- Validation Code cannot be empty\n";
    pass = 0;
  }

  //validate the email address
  if (!(isEmail(theform.email.value)))
  {
    msg = msg + "- Please enter a valid email address\n";
    pass = 0;
  }

  //Username and Password
  if (isEmpty(theform.passwd_1.value))
  {
    msg = msg + "- Password cannot be empty\n";
    pass = 0;
  }

    //validate the password
  if (theform.passwd_1.value != theform.passwd_2.value)
  {
    msg = msg + "- You did not enter the same password. Please re-enter your passwords.";
    pass = 0;
  }

  if (pass == 1)
  {
    return true;
  }
  else
  {
    alert(msg);
    return false;
  }
}

// validators ------------------------------------------------------------------

function isEmpty (s) {
        var p = /\S+/;
        return !p.test(s);
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isAlphaNum(string) {
    if (string.search(/^[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isNum(string) {
    if (string.search(/^[0-9]+$/) != -1)
        return false;
    else
        return true;
}

function isExecutable (s) {
        var p = /\.(bat|com|dll|exe|vbs)$/i;
        return p.test(s);
}

function isImage (s) {
        var p = /\.(gif|jpg)$/i;
        return p.test(s);
}

function isUrl (s) {
        var p = /^(http|https|ftp):\/\/\S+\.[^\.\s]{2,4}(\/\S*)?$/i;
        return p.test(s);
}

//-->
