function checkEmail(mail)
{
  var email = mail;
  invalidChars = " /:,;?()"
  incorrect ='';
  var errormessage="";

  for (i=0; i<invalidChars.length; i++) 
  {
    badChar = invalidChars.charAt(i)

    if (email.indexOf(badChar,0) > -1) 
    {
      incorrect += '   - Invalid Email Address\n';
      break;
    }
  }
  atPos = email.indexOf("@",1)

  if (atPos == -1)
  {
    incorrect += '   - Invalid Email Address\n';
  }

  if (email.indexOf("@",atPos+1) > -1)
  {
    incorrect += '   - Invalid Email Address\n';
  }
  periodPos = email.indexOf(".",atPos)

  if (periodPos == -1)
  {
    incorrect += '   - Invalid Email Address\n';
  }

  if (periodPos+3 > email.length)
  {
    incorrect += '   - Invalid Email Address\n';
  }           

  if (incorrect != '')
  {
    errormessage += '   - Invalid Email Address\n';
  }
 return errormessage;
}

function CheckEnquiryForm()
{
  alertmessage = "";

  if(document.EnquiryForm.name.value == "")
  {
    alertmessage += '   - Name\n';
  }
  
  if(document.EnquiryForm.enquiry.value == "")
  {
    alertmessage += '   - Enquiry\n';
  }

  if(document.EnquiryForm.mail.value=="")
  {
    alertmessage += '   - Email\n';
  }

  if(document.EnquiryForm.mail.value!="")
  {
    alertmessage+= checkEmail(document.EnquiryForm.mail.value);
  }

  if(alertmessage == "")
  {
    return true;
  }
  else
  {
    TopMessage = "You have not entered the following form elements correctly: \n\n";
    BottomMessage = "\nPlease correct these fields to continue";
    alertmessage = TopMessage + alertmessage + BottomMessage;

    alert(alertmessage);
    return false;
  }
}

function CheckDetailForm()
{
  alert("f");
  alertmessage = "";

  if(document.DetailForm.name.value == "")
  {
    alertmessage += '   - Name\n';
  }
  
 // if(document.DetailForm.comments.value == "")
 // {
 //   alertmessage += '   - Enquiry\n';
 // }

  if(document.DetailForm.email.value=="")
  {
    alertmessage += '   - Email\n';
  }

  if(document.DetailForm.email.value!="")
  {
    alertmessage+= checkEmail(document.DetailForm.email.value);
  }

  if(alertmessage == "")
  {
    return true;
  }
  else
  {
    TopMessage = "You have not entered the following form elements correctly: \n\n";
    BottomMessage = "\nPlease correct these fields to continue";
    alertmessage = TopMessage + alertmessage + BottomMessage;

    alert(alertmessage);
    return false;
  }
}
