function checkMemberRegForm(theForm) {
    var why = ""; 
    why += isEmpty(theForm.fname.value,"Please fill in your first name.\n");
    why += isEmpty(theForm.lname.value,"Please fill in your last name.\n");
    why += checkEmail(theForm.email.value);
    why += isEmpty(theForm.uname.value,"Please fill in your user name.\n");
    why += checkPassWd(theForm.pass.value,theForm.pass2.value);
    why += isEmpty(theForm.country.value,"Please fill in your country.\n");
    //var wc = countIt(theForm.comments.value);
 
    if (why != "") {
       alert(why);
       return false;
    }
    return true;
}

function checkArticleForm(theForm) {
    var why = ""; 
    why += isEmpty(theForm.title.value,"Please fill in your title.\n");
    why += isEmpty(theForm.cat_id1.value,"Please select Category 1.\n");
    why += isEmpty(theForm.story.value,"Please fill in your story.\n");
    //var wc = countIt(theForm.story.value);
 
    if (why != "") {
       alert(why);
       return false;
    }
    return true;
}

function checkCommentForm(theForm) {
    var why = ""; 
    why += isEmpty(theForm.name.value,"Please fill in your name.\n");
    //why += checkEmail(theForm.email.value);
    //why += isEmpty(theForm.country.value,"Please fill in your country.\n");
    why += isEmpty(theForm.comments.value,"Please fill in your comments.\n");
    //var wc = countIt(theForm.comments.value);
 
    if (why != "") {
       alert(why);
       return false;
    }
    return true;
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;
}

function checkPassWd (strng, pass2) {
var error="";
if (strng == "") {
   error = "Please enter a valid password.\n";
} else if (pass2 == "") {
   error = "Please enter a valid password.\n";
} else if (strng != pass2) {
   error = "Passwords do not match!\n";
} else if (strng.length < 6 || strng.length > 16) {
   error = "Password should be between 6 and 16 chars!\n";
} else if (pass2.length < 6 || pass2.length > 16) {
   error = "Password should be between 6 and 16 chars!\n";
}
return error;
}

function isEmpty(strng,err) {
var error = "";
  if (strng.length == 0) {
     error = err;
  }
return error;
}

function countIt(strng){

   var error = "";
   strng=strng.split(" ")
   var words = 0;
   words = strng.length;
   if (words > 250) {
      error = "You have entered "+words+" words in the short story!\n Please reduce the number of maximum words to 250!!!\n";
      alert(error);
      return false;
   } else {
      return true;
   }
}
