<!--

var buttonClicked = false;
//this is used so the user can only submit the form once


function sendForm(){
  if(!buttonClicked){
  //this function submits the form (the clue's in the name)
    if(!checkBlanks()){
      return false;
    } else {
       buttonClicked = true;
       //this bit puts the form into edit mode (see php script)
      document.form.submit();
    }
  }
  else {
      alert("Please only click the button once.");
  }
}

function removeSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}

function checkBlanks(){
//check if any fields are empty
var thisOK = true;

  var errors = new Array();

  if (removeSpaces(document.form.username.value)==""){
    errors.push('nameError');
    thisOK = false;

  }
  if (removeSpaces(document.form.useremail.value)==""){
    errors.push('emailError');
    thisOK = false;
  } else if (!checkEmail(document.form.useremail.value)){
    errors.push('emailError');
    thisOK = false;
  }

  if (removeSpaces(document.form.comments.value)==""){
    errors.push('commentsError');
    thisOK = false;
  }

  if(!thisOK){
      showErrors(errors);
  }


  return thisOK;

}


function checkEmail(theString){
//checks that the email address contains an 'at' and a 'dot'
if ((theString.indexOf("@") == -1) || (theString.indexOf(".") == -1)){
    return false;
  } else {
    return true;
  }
}


function showErrors(errors){

//hide any existing errors
var errorArray = new Array('nameError','emailError','commentsError');
for(i=0;i<3;i++){
	var thisObj = eval("document.getElementById('" + errorArray[i] + "').style");
	thisObj.visibility = "hidden";
	thisObj.display = "none";
}
var thisObj = eval("document.getElementById('genericError').style");
thisObj.visibility = "hidden";
thisObj.display = "none";



//show new errors specified by array 'errors'
for(i=0;i<errors.length;i++){
 var thisObj = eval("document.getElementById('" + errors[i] + "').style");
 thisObj.visibility = "visible";
 thisObj.display = "block";
}

var thisObj = eval("document.getElementById('genericError').style");
thisObj.visibility = "visible";
thisObj.display = "block";

}

//-->