 function checkEmail(fld)
 {
  inputValue = fld.value;
  var ri = /^[\w\-\.]+@[\w\-\.]+\.[\w]{2,}$/;
  return (!ri.test(inputValue))
 }

 function CheckForm (theForm)
 {
  var errmsg = "The following error(s) occured while trying to process the form:\n";
  errmsg += "__________________________________________________\n\n";
  var badmail = " is not valid e-mail address.\n";
  var passed = true;
   if (theForm.txtname.value.length == 0) 
   { 
    passed = false;
    errmsg += "You need to enter your Name.\n";
   }
   if (theForm.txtemail.value.length == 0)
   { 
    passed = false;
    errmsg += "You need to enter your E-mail address.\n";
   }
   else
   {
	if (checkEmail(theForm.email))
	{
	 passed = false;
	 errmsg += theForm.txtemail.value + badmail
	}
   }
   if (theForm.txtmessage.value.length == 0 || theForm.txtmessage.value == "Type your message here...") 
   { 
    passed = false;
    errmsg += "You need to enter your Message.\n";
   }		   
		
   if (passed == false) {alert (errmsg) }
   return(passed); 
 }
 
 function CheckState (control, evnt)
 {
	 if (evnt == 0)
	 {
	 	if (control.value == "Type your message here...")
		 {
			 control.innerHTML = "";
		 }
	 }
	 if (evnt == 1)
	 {
	 	if (control.value == "")
		 {
			 control.innerHTML = "Type your message here...";
		 }		 
	 }
 }
 