function checkTcnrForm(theForm) {
    var why = "";
    why += isEmpty(theForm.title.value,"News Title area has not been filled in.\n");
    why += isEmpty(theForm.agent.value,"News Agent has not been filled in.\n");
    why += isEmpty(theForm.s_story.value,"News short story has not been filled in.\n");
    why += isEmpty(theForm.f_story.value,"News full story has not been filled in.\n");
    if ((theForm.display_full.checked == false) && (theForm.url.value.length == 0))  {
       why += "Please enter News URL or select Display Full checkbox!\n";
    }

    why += checkSubTitle(theForm.sub_title1.value, theForm.sub_url1.value, theForm.sub_agent1.value, theForm.sub_story1.value, 1);
    why += checkSubTitle(theForm.sub_title2.value, theForm.sub_url2.value, theForm.sub_agent2.value, theForm.sub_story2.value, 2);
    why += checkSubTitle(theForm.sub_title3.value, theForm.sub_url3.value, theForm.sub_agent3.value, theForm.sub_story3.value, 3);
    why += checkSubTitle(theForm.sub_title4.value, theForm.sub_url4.value, theForm.sub_agent4.value, theForm.sub_story4.value, 4);
    why += checkSubTitle(theForm.sub_title5.value, theForm.sub_url5.value, theForm.sub_agent5.value, theForm.sub_story5.value, 5);

    var wc = countIt(theForm.s_story.value);

    if (why != "") {
       alert("The following form field(s) were incomplete or incorrect:\n\n" + why);
       return false;
    } else if (wc == false) {
       return false;
    } else {
       return true;
    }
    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){

   var error = "";
   strng=strng.split(" ")
   var words = 0;
   words = strng.length;
   if (words > 130) {
      error = "You have entered "+words+" words in the short story!\n Please reduce the number of maximum words to 130!!!\n";
      alert(error);
      return false;
   } else if (words > 120) {
      error = "You have entered "+words+" words in the short story!\n You are advised to limit the number of maximum words to 120!!!\n Would you still like to continue with the story now?";
      var ret_val = confirm(error);
      if (ret_val == true){
         return true;
      } else {
         return false;
      }    
   } else {
      return true;
   }
}

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

function checkSubTitle(s_title,s_url,s_agent,sf_story,i) {
  var error = "";
  if (s_title.length != 0) {
     if ((s_url.length == 0) || (s_agent.length == 0) || (sf_story.length == 0)) {
        error += "Sub news item "+i+" has a title value, you must enter URL, Agent and Full Story.\n";
     }
  } else if (s_url.length != 0) {
     if ((s_title.length == 0) || (s_agent.length == 0) || (sf_story.length == 0)) {
        error += "Sub news item "+i+" has a url value, you must enter Title, Agent and Full Story.\n";
     }
  } else if (s_agent.length != 0) {
     if ((s_title.length == 0) || (s_url.length == 0) || (sf_story.length == 0)) {
        error += "Sub news item "+i+" has an Agent value, you must enter Title, URL and Full Story.\n";
     }
  } else if (sf_story.length != 0) {
     if ((s_title.length == 0) || (s_url.length == 0) || (s_agent.length == 0)) {
        error += "Sub news item "+i+" has a Full Story value, you must enter Title, URL and an Agent.\n";
     }
  } else  {
     return error;
  }
return error;
}


