if (/msie/i.test (navigator.userAgent)) //only override IE
{
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id)
	{
		var elem = document.nativeGetElementById(id);
		if(elem)
		{
			//make sure that it is a valid match on id
			if(elem.attributes['id'].value == id)
			{
				return elem;
			}
			else
			{
				//otherwise find the correct element
				for(var i=1;i<document.all[id].length;i++)
				{
					if(document.all[id][i].attributes['id'].value == id)
					{
						return document.all[id][i];
					}
				}
			}
		}
		return null;
	};
}

var el="";
var char_count=0;
var fullStr="";
var initial_whitespace_rExp="";
var left_trimmedStr="";
var non_alphanumerics_rExp="";
var cleanedStr="";
var splitString="";
var word_count=0;
var wordOrWords="";
var charOrChars="";
var foundMatches="";
var semratio="";


function formValidate(comments){

	if((document.getElementById('firstName').value.length==0)&&
	(document.getElementById('lastName').value.length==0)&&
	(document.getElementById('strAddress').value.length==0)&&
	(document.getElementById('phoneNumber').value.length==0)&&
	(document.getElementById('emailAddress').value.length==0)&&
	(document.getElementById('comments').value=="Type comments here.")){
		alert("It appears you have not entered anything in your form.\r\nPlease review the form and let me know if you want to be contacted\r\n and if so, how do I reach you. \r\n\r\nThank you. \r\n\r\nAlan Brubaker");
		return false;
	}

	if(document.getElementById('phoneNumber').value.length>0){

	var stripped = document.getElementById('phoneNumber').value.replace(/[\(\)\.\-\ ]/g, '');

		if (isNaN(parseInt(stripped))) {
			 alert("The phone number contains illegal characters.\r\nPlease correct your phone number if you wish to provide it to us.");
			 document.getElementById('phoneNumber').value="";
			 document.getElementById('phoneNumber').focus();
			 return false;
	        }

       }

	if(document.getElementById('emailAddress').value.length>0 && document.getElementById('emailAddress').value.lastIndexOf('@')==-1){
		alert('Your email address does not appear to be valid.\r\nPlease check to make sure it is correct.');
		document.getElementById('emailAddress').value="";
		document.getElementById('emailAddress').focus();
		return false;
	}
	
	var prohibStr="";
        var prohibChars=new Array('\<a','href','\</a\>','[url','[/url]','[link','[/link','https','http','ftp','smtp','pop3','nntp','imap','irc','\#','\%','\^','\{','\}','com\?','\<','\>');
	
	for(p in prohibChars){
		//alert(prohibChars[p]);
		if(document.getElementById('comments').value.lastIndexOf(prohibChars[p])!=-1){
		prohibStr+='\r\n'+prohibChars[p]+'\r\n';
	
		}
	}
	
	if(prohibStr.length>0){	
	alert('Your Comments contain restricted or disallowed character(s): '+prohibStr+'\r\n\r\nPlease review your comments and remove them to continue.');
	return false;
	}
	
	validContent(comments);
		
	if(semratio<0.4){
	alert("Following our review of your comments, it does not appear to be in English or make sense in English.\n\r\As a precaution this message has not been sent. \n\r\n\rPlease review your comments.");
	return false;
	}

alert(semratio);
return true;
}


function validContent(){


	el=document.getElementById('comments');
	char_count=el.value.length;          // very crude measure
	fullStr=el.value+" "; // add space delimiter to end of text
	initial_whitespace_rExp= /^[^A-Za-z0-9]+/gi; //use for complex whitespace
	left_trimmedStr=fullStr.replace(initial_whitespace_rExp, " ");
	non_alphanumerics_rExp=/[^A-Za-z0-9]+/gi;   // and for delimiters
	cleanedStr=left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	splitString=cleanedStr.split(" ");
	word_count=splitString.length -1;

	var reqdWords=new Array("the","of","to","and","a","in","is","it","you","that","he","was","for","on","are","with","as","I","his","they","be","at","one","have","this","from","or","had","by","hot","but","some","what","there","we","can","out","other","were","all","your","when","up","use","word","how","said","an","each","she","which","do","their","time","if","will","way","about","many","then","them","would","write","like","so","these","her","long","make","thing","see","him","two","has","look","more","day","could","go","come","did","my","sound","no","most","number","who","over","know","water","than","call","first","people","may","down","side","been","now","find","any","new","work","part","take","get","place","made","live","where","after","back","little","only","round","man","year","came","show","every","good","me","give","our","under","open","seem","together","next","white","children","begin","got","walk","example","ease","paper","often","always","music","those","both","mark","book","letter","until","mile","river","car","feet","care","second","group","carry","took","rain","eat","room","friend","began","idea","fish","mountain","north","once","base","hear","horse","cut","sure","watch","color","face","wood","main","enough","plain","girl","usual","young","ready","above","ever","red","list","though","feel","talk","bird","soon","body","dog","family","direct","pose","leave","song","measure","state","product","black","short","numeral","class","wind","question","happen","complete","ship","area","half","rock","order","fire","south","problem","piece","told","knew","pass","farm","top","whole","king","size","heard","best","hour","better","true","during","hundred","am","remember","step","early","hold","west","ground","interest","reach","fast","five","sing","listen","six","table","travel","less","morning","name","very","through","just","form","much","great","think","say","help","low","line","before","turn","cause","same","mean","differ","move","right","boy","old","too","does","tell","sentence","set","three","want","air","well","also","play","small","end","put","home","read","hand","port","large","spell","add","even","land","here","must","big","high","such","follow","act","why","ask","men","change","went","light","kind","off","need","house","picture","try","us","again","animal","point","mother","world","near","build","self","earth","father","head","stand","own","page","should","country","found","answer","school","grow","study","still","learn","plant","cover","food","sun","four","thought","let","keep","eye","never","last","door","between","city","tree","cross","since","hard","start","might","story","saw","far","sea","draw","left","late","run","while","press","close","night","real","life","few","stop","ten","simple","several","vowel","toward","war","lay","against","pattern","slow","center","love","person","money","serve","appear","road","map","science","rule","govern","pull","cold","notice","voice","fall","power","town","fine","certain","fly","unit","lead","cry","dark","machine","note","wait","plan","figure","star","box","noun","field","rest","correct","able","pound","done","beauty","drive","stood","contain","front","teach","week","final","gave","green","oh","quick","develop","sleep","warm","free","minute","strong","special","mind","behind","clear","tail","produce","fact","street","inch","lot","nothing","course","stay","wheel","full","force","blue","object","decide","surface","deep","moon","island","foot","yet","busy","test","record","boat","common","gold","possible","plane","age","dry","wonder","laugh","thousand","ago","ran","check","game","shape","yes","hot","miss","brought","heat","snow","bed","bring","sit","perhaps","fill","east","weight","language","among");

	for(n in splitString){
		for(x in reqdWords){
			if(reqdWords[x]==splitString[n]){
			foundMatches+=reqdWords[x]+" ";

			}
		}
	}
	//foundMatches=foundMatches.split(" ");
	foundMatches.length=foundMatches.length-1;
	semratio=foundMatches.length/word_count;

return semratio;
}
