//Checks if the user filled in the create quiz page corretly.
function checkTextAreas(elementName,element2Name)
{
  //Declare array containing question text areas.
  var questions = new Array ();
  //Declare array containing answer option text areas.
  var answerOptions = new Array ();
  
  //Assign question and answer option text areas into two arrays.
  for (var questionNo=0; questionNo < 20; questionNo++)
  {
	questions[questionNo] = document.getElementById(elementName+"["+questionNo+"]");
	answerOptions[questionNo] = new Array ();
	
	for (var answerOptionNo=0; answerOptionNo < 5; answerOptionNo++)
	{
	  answerOptions[questionNo][answerOptionNo] = document.getElementById(element2Name+"["+questionNo+"]["+answerOptionNo+"]");
	}
  }
   
  //Loop through the first 5 question text areas.
  for (var question=0; question < 5; question++)
  {
    //If they are empty alert the user.
	if (questions[question].value == "")
	{
      alert ("The quiz cannot have less than 5 questions. Please fill in question No "+(question+1)+". ");
      return false;
	}
  }
   
  //Loop through all the question text areas.
  for (var question=0; question < 20; question++)
  {
    //If they are not empty,
	if (questions[question].value != "")
	{
	  //check if they contain any swear words,
	  if (containsSwearWords(questions[question].value))
	  {
        alert ("Question No "+(question+1)+" contains swear words!");
        return false;
	  }
	  //if they don't start with letter or digit, or don't have at least 3 words 2 of which contain at least 1 vowel each, or have some special character, or have three or more same successive letters or 5 or more same successive numbers or 2-3 or more same successive special characters, or have less than 10 characers.
	  if (!questions[question].value.match(/^[a-z,0-9]/i) || !questions[question].value.match(/[a,e,i,o,u,y].*\s.*[a,e,i,o,u,y].*\s.*/i) || questions[question].value.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{5,})|(1{5,})|(2{5,})|(3{5,})|(4{5,})|(5{5,})|(6{5,})|(7{5,})|(8{5,})|(9{5,})|(\s{2,})|(\.{3,})|(\?{2,})|(;{2,})|(:{2,})|(&{2,})|(\*{2,})|(#{2,})|(@{2,})|(%{2,})|(\({3,})|(\){3,})|(\-{3,})|(={2,})|(\+{2,})|(\${2,})|(\[{2,})|(\]{2,})|(\{{2,})|(\}{2,})|(\\{2,})|(\/{2,})|(\,{2,})|(<{3,})|(>{3,})|(_{2,})|("{2,})|('{3,})|(!{3,})|(~{2,})|(`{2,})|(\^{2,})|(\|{2,})/i) || (questions[question].value.length < 10))
	  {
        alert ("Question No "+(question+1)+" does not appear to be valid.");
        return false;
	  }
	  
	  //Loop through the first two answer options (for questions that are not empty)
	  for (var answerOption=0; answerOption < 2; answerOption++)
	  {
	    //If they are empty alert the user.
		if (answerOptions[question][answerOption].value == "")
		{
		  alert ("You will need to have at least 2 answers for each question. Please fill in answer No"+(answerOption+1)+" for question No "+(question+1)+". ");
		  return false;
		}
	  }
	  
	  //Loop through all answer options (for questions that are not empty)
	  for (var answerOption=0; answerOption < 5; answerOption++)
	  {
	    //If they are not empty,
		if (answerOptions[question][answerOption].value != "")
		{
		  //check if they contain any swear words,
		  if (containsSwearWords(answerOptions[question][answerOption].value))
		  {
		    alert ("Answer No"+(answerOption+1)+" for question No "+(question+1)+" contains swear words!");
		    return false;
		  }
		  //if they don't start with letter or digit, or have some special character, or have three or more same successive letters or 5 or more same successive numbers or 2-3 or more same successive special characters.
		  if (!answerOptions[question][answerOption].value.match(/^[a-z,0-9]/i) || answerOptions[question][answerOption].value.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{5,})|(1{5,})|(2{5,})|(3{5,})|(4{5,})|(5{5,})|(6{5,})|(7{5,})|(8{5,})|(9{5,})|(\s{2,})|(\.{3,})|(\?{2,})|(;{2,})|(:{2,})|(&{2,})|(\*{2,})|(#{2,})|(@{2,})|(%{2,})|(\({3,})|(\){3,})|(\-{3,})|(={2,})|(\+{2,})|(\${2,})|(\[{2,})|(\]{2,})|(\{{2,})|(\}{2,})|(\\{2,})|(\/{2,})|(\,{2,})|(<{3,})|(>{3,})|(_{2,})|("{2,})|('{3,})|(!{3,})|(~{2,})|(`{2,})|(\^{2,})|(\|{2,})/i))
		  {
		    alert ("Answer No"+(answerOption+1)+" for question No "+(question+1)+"  does not appear to be valid. ");
		    return false;
		  }
		}
	  }
	}
  }
  return true;
}
