﻿// JavaScript Document

function validate(formobj){	

var alertMsg = "Please complete the following:\n";
	var l_Msg = alertMsg.length;
 	alertMsg += checkEmail(formobj.From.value);
	alertMsg += CountTextField(formobj.Subject.value,"Subject");
	alertMsg += CountTextField(formobj.Body.value,"Message");

	
	//email
function checkEmail(strng){
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

 if (strng == "") {
 		alertMsg = " - Enter your e-mail address\n";
    }
	
  else if  (!(emailFilter.test(strng))) {
		alertMsg =  " - Your email address appears to be incorrect\n";
  }
 
	else if (strng.match(illegalChars)) {
   alertMsg =  " - Your email address  contains illegal characters\n";
	 }
else  {
   alertMsg =  "";
	 }	
return alertMsg;
}//end Email
	
//Count any text field
	
	function CountTextField(strng,Xmsg){
	
	var countMe = strng;
        var escapedStr = encodeURI(countMe)
        if (escapedStr.indexOf("%") != -1) {
            var count = escapedStr.split("%").length - 1
            if (count == 0) count++  //perverse case; can't happen with real UTF-8
            var tmp = escapedStr.length - (count * 3)
            count = count + tmp
        } else {
            count = escapedStr.length
        }
        if (count ==0){
		  alertMsg = " -  Enter your "+Xmsg+"\n";
	   }
	   
	   else if (count >200){
		  alertMsg = " - You entered more than 200 characters in "+Xmsg+"\n";
	   }
	  else  {
   alertMsg =  "";
	 }	
	
	return alertMsg;
	}//end count note


	if (alertMsg.length == l_Msg){
		return true;
	}else{
	alert(alertMsg);
			//document.write(alertMsg);
	return false;
	}
}
// 