function checkCommentForm(theForm) {
    var why = ""; 
    why += isEmpty(theForm.name.value,"Please fill in your name.\n");
    why += isEmpty(theForm.country.value,"Please fill in your country.\n");
    why += isEmpty(theForm.comment.value,"Please fill in your comments.\n");
    why += checkEmail(theForm.email.value);
    var wc = countIt(theForm.comment.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 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;
   }
}


