function CountWordsLeft(myForm, field, count, no_words) {
    var text=document.getElementById('longtext').value;
    if(no_words>0)
    {
        var iwhitespace = /^[^A-Za-z0-9]+/gi; // remove initial whitespace
        var left_trimmedStr = text.replace(iwhitespace, "");
        var na = rExp = /[^A-Za-z0-9]+/gi; // non alphanumeric characters
        var cleanedStr = left_trimmedStr.replace(na, " ");
        var splitString = cleanedStr.split(" "); 
        var word_count = splitString.length -1;
        count.value=no_words-word_count;
        if(word_count > 100)
        alert ("You have reached the maximum amount of words allowed. Please revise your text to be less than or equal to 100 words as specified in the rules of the contest.");
    }
    
}

function formValidator(){
	
	var nominee = document.getElementById('nominee');
	var longtext = document.getElementById('longtext');

	if(isEmpty(nominee, "Please enter your nominee for this contest")){
			
		return false;
	}
	
	if(isEmpty(longtext, "Please tell us why your nominee should win this contest")){
			return false;
		}
	
	return true;
	
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}




