//<!--
// This function will validate a form
function validateForm(theform)
{
  pass = 1; //assume everything is ok
  msg = "Please solve the following errors before continuing your registration process\n\n";

  //make sure required fields are not empty
  if (isEmpty(theform.sitetalk_reg_firstname.value))
  {
    msg = msg + "- Please enter a valid NAME (2-24 characters)\n";
    pass = 0;
  }
  
    if (isEmpty(theform.sitetalk_reg_lastname.value))
  {
    msg = msg + "- Please enter a valid SURNAME (2-24 characters)\n";
    pass = 0;
  }
  
    if (isEmpty(theform.sitetalk_reg_town.value))
  {
    msg = msg + "- Please enter the name of the TOWN where you live\n";
    pass = 0;
  }
    if (isEmpty(theform.sitetalk_reg_username.value))
  {
    msg = msg + "- Invalid USERNAME. Please try again (4-20 characters)\n";
    pass = 0;
  }
    if (isEmpty(theform.sitetalk_reg_password.value))
  {
    msg = msg + "- Invalid format for the PASSWORD. Please try again\n";
    pass = 0;
  }
  
   //validate the email address
  if (!(isEmail(theform.sitetalk_reg_email.value)))
  {
    msg = msg + "- E-MAIL ADDRESS you provided looks incorrect\n";
    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);
}

//-->
