function checkClassifiedForm(theForm) {
    var why = "";
    why += isEmpty(theForm.title.value,"Classified Title area has not been filled in.\n");
    why += checkDropdown(theForm.category.selectedIndex,"Classified Category has not been selected.\n");
    why += isEmpty(theForm.details.value,"Classified details have not been filled in.\n");

    why += countIt(theForm.details.value,"The details cannot exceed 300 words.");
    why += isEmpty(theForm.contactname.value,"Contact Name have not been filled in.\n");
    why += checkEmail(theForm.contactemail.value);


    if (why != "") {
       alert("The following form field(s) were incomplete or incorrect:\n\n" + why);
       return false;
    } else {
       return true;
       //theForm.submit()
    }
//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 checkPhone (strng,err) {
var error = "";
if (strng == "") {
   error = err;
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}

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


// valid selector from dropdown list

function checkDropdown(choice,err) {
var error = "";
    if (choice == 0) {
    error = err;
    }    
return error;
} 

function countIt(strng,err){

var error = "";
strng=strng.split(" ")
var words = 0;
words = strng.length;
if (words > 300) {
    err += " You have entered "+words+" now!";
    error = err;
    }    
return error;
// document.wordcount.wordcount3.value=formcontent.length
}
