function submitForm(currentForm) {
  //function to run checks on form before submission
  //first check that key fields are completed
  if (checkComplete(currentForm)) {
     //then check with the user their details are correct
     if (confirmDetails(currentForm)) {
        //if all ok, then form can be submitted
        //set up timer to run the thanks function
        //and then return true so the form will be submitted
        setTimeout('thanks()',5000);
        return true; }}
     //in any other case set return to false so form won't submit
     return false;}

function checkComplete(currentForm) {
  //function to check the form is complete
  //create a variable for composing a message
  message = " and then select submit to send this form.";

  //check the visitor has entered their name
  if (currentForm.Name.value==""){
     alert("Please enter your NAME" + message);
     currentForm.Name.focus();
     return false; }

 //check the visitor has entered their street
  if (currentForm.Street.value==""){
     alert("Please enter your STREET" + message);
     currentForm.Street.focus();
     return false; }

 //check the visitor has entered their town
  if (currentForm.Town.value==""){
     alert("Please enter your City" + message);
     currentForm.Town.focus();
     return false; }

 //check the visitor has entered their post code
  if (currentForm.Post_Code.value==""){
     alert("Please enter your Post/Zip Code" + message);
     currentForm.Post_Code.focus();
     return false; }

 //check the visitor has entered their Country
  if (currentForm.Country.value==""){
     alert("Please enter your Country" + message);
     currentForm.Country.focus();
     return false; }

 //check the visitor has entered their Email Address
  if (currentForm.Email.value==""){
     alert("Please enter your E-mail Address" + message);
     currentForm.Email.focus();
     return false;}

//check the visitor has entered a valid Email Address
  if (currentForm.Email.value.indexOf ('@', 0) == -1) {
     alert("Please enter a VALID E-mail address");
     currentForm.Email.focus();
     return (false);}

  //if all is ok, then submission can continue
     return true;}

function confirmDetails(currentForm) {
  //confirm with the visitor that the details are correct
  //create a variable for composing the message
  newLine = "\n"
  confirmMessage = "Please check your entries:" + newLine;
  //step though form elements one at a time
  for (i =0; i < currentForm.elements.length - 2; i++) {
     //if the element is anything other than an unselected radio button
     if (!(currentForm.elements[i].type == "radio")||
        currentForm.elements[i].checked) {
        //if the element is a checkbox
        if (currentForm.elements[i].type == "checkbox") {
           //and if the checkbox is checked
           if (currentForm.elements[i].checked)
           //add a heading and the element name to the message
           confirmMessage += "Interest: " + currentForm.elements[i].name + newLine; }
        //if the element is a selection list add the element name and the
        //text of the currently selected option
        else if(currentForm.elements[i].type == "select-one") {
           confirmMessage += currentForm.elements[i].name + ": " + currentForm.elements[i][currentForm.elements[i].selectedIndex].text + newLine;

        //otherwise add the element's name and value to the message string
        } else { confirmMessage += currentForm.elements[i].name + ": " + currentForm.elements[i].value + newLine; }}}

  //display the message to the user to check details
  confirmMessage += "\nAre these details correct?";
  //return true to calling function if submission should continue
  if (confirm(confirmMessage)) {
      return true;}
  //return false to calling function if submission should not continue
  return false; }

function thanks() {
  //display a thank you page
  location.href="thanks.html"; }


