function ValidateData() {


//Submission variable
var CanSubmit = false;

//Check there is something entered into the word list
CanSubmit = ForceEntry("WordList", "Please enter words into the word list.");
if (!CanSubmit) return;
	
//Get the word count
var count = GetWordCount();
var min_count = CalculateMinimumWords();

//If there aren't enough words, warn the user
if (count<min_count)
{
	alert("You must enter at least " + min_count + "words.");
	return;
}

//Check there are no more than 35 words - if there are more than 35,
//POST the information rather tha using GET

	//Grab the word list text
	var wordList = document.getElementById("WordList").value;
	//If it is longer than 200 characters
	if (wordList.length > 200)
	{
		document.LayoutBingo.method = "post";		
		document.LayoutBingo.VarsPosted.value = "true";
	}
	
	
//If fields have been entered correctly, submit the form
document.LayoutBingo.submit();

} //end function

function CalculateMinimumWords() {
	
	//Calculate the minimum number of required cards
	var cardCount = parseInt(document.getElementById("CardCount").value);
	var entryCount = parseInt(document.getElementById("EntryCount").value);
	
	//Return value for the competition being close
	if (document.getElementById("Competition close").checked)
		return Math.ceil(entryCount + (cardCount * 1.5));
		
	//Random or very close are the same
	return cardCount + (entryCount - 1);
}

function GetWordCount() {
	//Grab the word list text
	var wordList = document.getElementById("WordList").value;
	//Split the word list into individual words
	var count=0;
	
	//Trim the word list - if it is completely empty, don't bother counting
	var trimmedList = wordList.replace(/^\s+|\s+$/g, '') ;	
	if (trimmedList != "")
	{
		var words = wordList.split(/\s/);
		//Go through words and count (ignoring any empty indexes)
		for (var i=0; i<words.length; i++) {
			//Get the next word
			var word = words[i];
			//Trim it
			var trimmed = word.replace(/^\s+|\s+$/g, '') ;	
			//If non-zero, bump word counter
			if (trimmed!="")
			 count++;		
		} //endfor
	} //endif
	
	return count;
}

function PrintWordCount() {
	
	//Get the word count
	var count = GetWordCount();		
	//Calculate the minimum numbers of words
	var minWords = CalculateMinimumWords();	
	
	//Output the word count
	if (count<minWords)
	{
		var short = minWords-count;
		document.getElementById("WordCount").innerHTML = 
		  "Words entered so far: "+count+"  <b>(you need at least "+short+" more)</b>";
		  return;
    }
    
	document.getElementById("WordCount").innerHTML = 
	  "Words entered so far: "+count;
}


