var formHasFocus = false;

function checkEmail(strEmail)
{
 if (strEmail.length >= 5 && strEmail.indexOf('@') != -1 && strEmail.indexOf('.') != -1)
 {
  var atpos = strEmail.indexOf('@')
  var dotpos = strEmail.indexOf('.', atpos)
  var user = strEmail.substring(0, atpos)
  var domname = strEmail.substring(atpos + 1, dotpos)
  var domlast = strEmail.substring(dotpos + 1)
  if (user.length > 0 && domname.length > 0 && domlast.length > 0)
  {
   return true;
  }
  else
  {
   return false;
  }
 }
 else
 {
  return false;
 }
}

function controlGotFocus()
{
 formHasFocus = true;
}

function controlLostFocus()
{
 formHasFocus = false;
}

function loadContactUsCode()
{
 var objContactForm = document.getElementById('contactusform');
 if (objContactForm.fcode.value == '')
 {
  objContactForm.fcode.focus();
 }
}

function loadContactUs()
{
 if (!formHasFocus) document.getElementById('contactusform').fname.focus();
}

function checkContact()
{
 var objContactForm = document.getElementById('contactusform');
 if (objContactForm.fname.value == '')
 {
  alert('You must write down a name!');
  objContactForm.fname.focus();
  return false;
 }
 else
 {
  if (!checkEmail(objContactForm.femail.value))
  {
   alert('The e-mail address must be valid!');
   objContactForm.femail.focus();
   return false;
  }
  else
  {
   if (objContactForm.fmessage.value == '')
   {
    alert('You must write down a message!');
    objContactForm.fmessage.focus();
    return false;
   }
   else
   {
    if (objContactForm.fcode.value.length != 4)
    {
     alert('The verifiaction code must have a length of four characters!');
     objContactForm.fcode.focus();
     return false;
    }
    else
    {
     return true;
    }
   }
  }
 }
}
