function addFavourite(url, pagetitle)
{
  if(navigator.appName.indexOf('Microsoft')>=0)
  {
	window.external.AddFavorite(location.protocol + "//" +location.host, document.title);
  }
}


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.type.value == "")
  {
    alertmessage += '   - Type of Query\n';
  }
  else
  {
    if(document.EnquiryForm.type.value=="NO")
    {
      alert("Breakdown Cover UK does not supply products or services.\nIf you wish to talk about products or services we suggest you\ncontact the supplier of your product or service directly.");
      return false;
	}
  }

  if(document.EnquiryForm.name.value == "")
  {
    alertmessage += '   - Your Name\n';
  }
  
  if(document.EnquiryForm.email.value=="")
  {
    alertmessage += '   - Your Email\n';
  }
  
  if(document.EnquiryForm.query.value == "")
  {
    alertmessage += '   - Your Enquiry\n';
  }

  if(document.EnquiryForm.email.value!="")
  {
    alertmessage+= checkEmail(document.EnquiryForm.email.value);
  }
  
  if(alertmessage == "")
  {
     document.EnquiryForm.submit();
  }
  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;
  }
}