function checkAllValidChars(objValue,valid_chars) {
var tmp_flag = false;
  // if check each char in objValue to see if it is in the valid_chars string
  for (var i = 0; i<= objValue.length; i++) {
   if ((valid_chars.indexOf(objValue.charAt(i))) == -1) {  // did not find char in valid string
     return false;
   }
 }
  return true; 
}

function emptyField(textStr) {
 if(textStr.length == 0) return true;
  for (var i=0; i<textStr.length; ++i) {
    var ch = textStr.charAt(i);
    if(ch != ' ' && ch != '	') return false;
  }
  return true;
}

function checkStandardText(objLabel,objValue) {
 if (emptyField(objValue))
   return ("\n" + objLabel + " cannot be blank \n");
 else
   return ("");
}

function checkLastName(objValue,objLabel) {
var valid_chars = "abcdefghijklmnopqrstuvwxyz";
valid_chars += valid_chars.toUpperCase();
valid_chars += ". -'"
if (checkAllValidChars(objValue,valid_chars) && !(emptyField(objValue)))
  return ("");
else
  return ("\n" + objLabel + "  cannot be blank and must contain letters, periods, dashes, and apostrophes only. \n");
}  // end checkLastName function

function checkAllValidNums(objValue,valid_charss) {
var tmp_flag = false;
var j = 0;
  // if check each char in objValue to see if it is in the valid_chars string
  for (var i = 0; i<= objValue.length; i++) {
   if ((valid_charss.indexOf(objValue.charAt(i))) != -1) {  // did find char in valid string
        j++;
   }
  }
  --j;
  if (j == 10) {  
      return true; 
  }else{
      return false;
  }
}

function checkPhone(objValue,objLabel) {
valid_charss = "0123456789";
valid_chars = "0123456789";
valid_chars += "-";
valid_chars += ")";
valid_chars += "(";
valid_chars += " ";
pattern = /\W?\d{3}\W?\W?\d{3}\W?\d{4}/
result = objValue.match(pattern)
result1 = checkAllValidNums(objValue,valid_charss)
if (checkAllValidChars(objValue,valid_chars) && !(emptyField(objValue)) && result && result1 )
  return ("");
else
  return ("\n" + objLabel + " cannot be blank and Please use the format as in the example. \n");
}  // end checkPhone function
function checkEmailAddr(objValue,ObjLabel) {
  if (emptyField(objValue))  {
     return ("\n" + ObjLabel + " cannot be blank \n");
  } else {
     // check to see if valid entry -(modified code from Travelocity.com)
     var indexofAtsign  = objValue.indexOf('@');   // -1 returned fi not found
     var indexofPeriod  = objValue.indexOf('.',indexofAtsign);
     var indexofSpace  = objValue.indexOf(' ');
     if (indexofSpace >= 0 || indexofAtsign <= 0 || indexofPeriod == -1 || indexofPeriod <= indexofAtsign + 1) {
       if (indexofSpace >= 0) { 
         return ("\n" + ObjLabel + " is not valid format.  Please check for spaces. \n");
       } else { 
         return ("\n" + ObjLabel + " is not valid format. \n");
       } 
     } else {
     return ("");
     } 
  }
} // end checkEmailAddr function
function CommunicationsNews(formObj) {
// first validate required fields
var alert_text = "You have entered incomplete or invalid information.  Please use the list below to correct \n " 
var start_text = alert_text;
var alert_text1 = checkLastName(formObj.FirstName.value,"First Name");
var alert_text2 = checkLastName(formObj.LastName.value,"Last Name")
var alert_text3 = checkPhone(formObj.Phone.value,"Office Telephone");
var alert_text4 = checkEmailAddr(formObj.Email.value,"Email")
var alert_text5 = "\nWhat\'s is the News? cannot be blank \n"
var alert_text6 = "\nWhen did it happen? cannot be blank \n"
var alert_text7 = "\nWhere did it happen? cannot be blank \n"
var alert_text8 = "\nWhy is it important?  cannot be blank \n"
var alert_text9 = "\nAdditional Details? cannot be blank \n"

if (alert_text1 == ""){
    if (alert_text2 == ""){
		if (alert_text3 == ""){
			if (alert_text4 == ""){
				if (formObj.WhatIsTheNews.value.length > 0){
				    if (formObj.WhenDidItHappen.value.length > 0){
				    	if (formObj.WhereDidItHappen.value.length > 0){
				    		if (formObj.WhyImportant.value.length > 0){
				    			if (formObj.AdditionalDetails.value.length > 0){				    					    
				                    alert_text += "";
				                }else{
	   			                    alert_text += alert_text9;
	   			                }
	   			            }else{
   			                    alert_text += alert_text8;
   			                }
	   			        }else{
	   			            alert_text += alert_text7;	   			                   
	   			        }
				    }else{
	   			        alert_text += alert_text6;	 
				    }
				}else{
			        alert_text += alert_text5;							
				}
			}else{
			    alert_text += alert_text4;				
			}
		}else{
			alert_text += alert_text3;	
		}
	}else{
		alert_text += alert_text2;	
    }
}else{
	alert_text += alert_text1;	
}

if (alert_text != start_text) {
window.alert(alert_text)
return false;
} else {
  return true;
}
}
