function messagebox () {
   element = document.getElementById("theform");
   if (element.topic.value == 'Did not receive lost password email' ) {
	    element.message.value = 'Please re-send the email to me.';
   } else {
	    element.message.value = '';
   }
}
function test_length(limitField) {
   if (limitField.value.length > 2000) {
      alert('You have reached the 2000 character limit.');   
      limitField.value = limitField.value.substring(0, 2000);
   }
}
function newImage () {
	 document.getElementById('new_captcha').value = 1;
   document.getElementById('theform').submit();
}
function validateForm() {
   element = document.getElementById("theform");
   if(trim(element.email.value)==""){
      alert("Please enter your email address.");
      element.email.focus();
      return false;
   }
   if(! CheckEmail (element.email.value) ) {
      alert("Invalid email address.");
      element.email.focus();
      return false;
   }
   if(trim(element.fname.value)==""){
      alert("Please enter your name.");
      element.fname.focus();
      return false;
   }
   if (element.topic.selectedIndex == 0 ) {
      alert ( "You must select a topic." );
      return false;
   }
   if(trim(element.message.value)==""){
      alert("Please enter a message.");
      element.message.focus();
      return false;
   }
   if(trim(element.security_code.value)==""){
      alert("Please enter the security code displayed.");
      element.security_code.focus();
      return false;
   }
   document.getElementById('submitButton').disabled=true;
   return true;
}
function CheckEmail(field) {
 	 var i = 1;
	 var sLength = field.length;

	 while (( i < sLength) && (field.charAt(i) != "@")) {
		  i++;
	 }
	 if ((i >= sLength) || field.charAt(i) != "@"){
		  return false;
	 } else {
		  i += 2;
	 }
	 while ((i < sLength) && (field.charAt(i) != ".")) {
		  i++;
	 }
	 if ((i >= sLength - 1) || (field.charAt(i) != ".")) {
		  return false;
	 } else {
		  return true;
	 }
}
function trim(stringToTrim) {
	 return stringToTrim.replace(/^\s+|\s+$/g,"");
}
