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 CheckNewsForm()
{
  alertmessage = "";

  if(document.NewsForm.name.value == "")
  {
    alertmessage += '   - Name\n';
  }

  if(document.NewsForm.mail.value=="")
  {
    alertmessage += '   - Email\n';
  }

  if(document.NewsForm.mail.value!="")
  {
    alertmessage+= checkEmail(document.NewsForm.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 addFavourite()
{
  if(navigator.appName.indexOf('Microsoft')>=0)
  {
	window.external.AddFavorite("http://www.mobile-phones.gb.net/", "Mobile Phones");
  }
}

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 UpdateChecks(which) {
if     (which == 'all')    { AllIsChecked();  }
else if(which == 'open')  { BoxesCheck();    }
}

function AllIsChecked() {
if(document.PhoneFinderForm.open_any.checked == false) { BoxesCheck(); }
else {
	document.PhoneFinderForm.standard.checked = false;
	document.PhoneFinderForm.flip.checked = false;
	document.PhoneFinderForm.slide.checked = false;
	document.PhoneFinderForm.rotate.checked = false;
	}
}

function BoxesCheck() {
document.PhoneFinderForm.open_any.checked = false;
}


function UpdateFeats(which) {
if     (which == 'all')    { AllFeatures();  }
else if(which == 'feat')  { FeaturesCheck();    }
}

function AllFeatures() {
if(document.PhoneFinderForm.feat_any.checked == false) { BoxesCheck(); }
else {
	document.PhoneFinderForm.video.checked = false;
	document.PhoneFinderForm.bluetooth.checked = false;
	document.PhoneFinderForm.mp3.checked = false;
	document.PhoneFinderForm.ringtones.checked = false;
	document.PhoneFinderForm.mms.checked = false;
	document.PhoneFinderForm.java.checked = false;
	document.PhoneFinderForm.radio.checked = false;
	document.PhoneFinderForm.gprs.checked = false;
	document.PhoneFinderForm.email.checked = false;
	document.PhoneFinderForm.internet.checked = false;
	document.PhoneFinderForm.threeg.checked = false;
	document.PhoneFinderForm.flash.checked = false;
	document.PhoneFinderForm.pcsync.checked = false;
	document.PhoneFinderForm.smartphone.checked = false;
	document.PhoneFinderForm.wifi.checked = false;
	}
}

function FeaturesCheck() {
document.PhoneFinderForm.feat_any.checked = false;
}

function toggle_visibility(id, name)
{
  var e = document.getElementById(id);
  var f = document.getElementById(name);
  if(e.style.display == 'none')
  {
     e.style.display = 'block';
	 f.innerHTML = 'Hide';
  }
  else
  {
    e.style.display = 'none';
	f.innerHTML = 'Show';
  }
}
