//Checks if user put a user name and if that name is not swear.
function checkName()
{
  var firstName = getCookie('firstName');
  if (firstName == null)
  {
    firstName = poll.firstNameBox.value;
  }
  
  if (firstName == "")
  {
    alert ("Please enter your name!");
    return false;
  }
  else
  {
    if ((firstName != null) && containsSwearWords(firstName))
	{
	  alert ("Please do not use swear words!");
      return false;
	}
	else
	{
      //if it doesn't start with letter, or has 3 or more spaces , or doesn't have vowels, or has some special character, or has three or more same successive letters or four or more same successive numbers or has less than 3 characers.
	  if (!firstName.match(/^[a-z]/i) || firstName.match(/\s{3,}/) || !firstName.match(/[a,e,i,o,u,y]/i) || firstName.match(/[@,~,`,#,$,%,\^,&,\*,\(,\),-,_,=,+,\[,\{,\},\],\|,\\,;,:,",\,,<,>,\/,\?]/) || firstName.match(/(a{3,})|(b{3,})|(c{3,})|(d{3,})|(e{3,})|(f{3,})|(g{3,})|(h{3,})|(i{3,})|(j{3,})|(k{3,})|(l{3,})|(m{3,})|(n{3,})|(o{3,})|(p{3,})|(q{3,})|(r{3,})|(s{3,})|(t{3,})|(u{3,})|(v{3,})|(w{3,})|(x{3,})|(y{3,})|(z{3,})|(0{4,})|(1{4,})|(2{4,})|(3{4,})|(4{4,})|(5{4,})|(6{4,})|(7{4,})|(8{4,})|(9{4,})|(\.{2,})|(!{2,})|('{3,})/i) || (firstName.length < 3))
	  {
	    alert ("Please enter a valid name!");
        return false;
	  }
	  else
	  {
	    return true;
	  }
	}
  }
}

function checkAnswer()
{
	var radioSelected = false;
	//Loop through the options of the option list and and checks is something is chosen.
    for (var option = 0;  option < poll.vote.length;  option++)
    {
      if (poll.vote[option].checked)
	  {
        radioSelected = true;
	  }
    }
    if (!radioSelected)
    {
      alert ("Please choose something to vote!");
      return (false);
    }
  return (true);
}

function checkInput()
{
  //If user suplied name
  if (checkName() && checkAnswer())
  {
	 setCookie('firstName',poll.firstNameBox.value,365);
	 return true;
  }
  else
  {
    return false;
  }
}
