
function checkForm()
{
   // the variables below are assigned to each
   // form input 
   var gname, gemail, gurl, gmessage;

   with(window.document.guestform)
   {
      gname    = txtName;
      gemail   = txtEmail;
      gurl     = txtUrl;
      gmessage = mtxMessage;
   }

   // if name is empty alert the visitor
   if(trim(gname.value) == '')
   {
      alert('Please enter your name');
      gname.focus();
      return false;
   }
   // alert the visitor if email is empty or 
   // if the format is not correct 
   else if(trim(gemail.value) != '' && !isEmail(trim(gemail.value)))
   {
      alert('Please enter a valid email address or leave it blank');
      gemail.focus();
      return false;
   }
   // alert the visitor if message is empty
   else if(trim(gmessage.value) == '')
   {
      alert('Please enter your message');
      gmessage.focus();
      return false;
   }
   else
   {
      // when all input are correct 
      // return true so the form will submit 
      return true;
   }
}

/*
Strip whitespace from the beginning and end of a string
*/ 

function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}

function isEmail(str)
{
	var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	return regex.test(str);
} 

//----------------------TOGGLING--------------------------//

function toggleElementDisplay(id) {
	var style2;
	if (document.getElementById) {
		// this is the way the standards work
		style2 = document.getElementById(id).style;
	}
	else if (document.all) {
		// this is the way old msie versions work
		style2 = document.all[id].style;
	}
	else if (document.layers) {
		// this is the way nn4 works
		style2 = document.layers[id].style;
	}
	var hidden = ((style2.display=="none") || (style2.display==""));
	style2.display = hidden ? "block":"none"; 
	return hidden;
}