// Poll Comment Form Required Fields
function checkPollCommentForm(form) {

	var okToGo = true;
	
	if(document.getElementById('name').value == "") {
		showNamediv();
		okToGo = false;
	}
	else{
		hideNamediv();
	}
	
	if(document.getElementById('email').value == "") {
		showEmaildiv();
		okToGo = false;
	}
	else{
		hideEmaildiv();
	}
	if(document.getElementById('comment').value == "") {
		showCommentdiv();
		okToGo = false;
	}
	else{
		hideCommentdiv();
	}

	if(okToGo) {
		if (typeof insertComment != "undefined") {
			return insertComment(form);
		}else{
			return postForm(form, false);
		};
	}
	
	return okToGo;
}

function hideNamediv() {
	document.getElementById('errorMessageName').style.visibility= 'hidden';
}
function showNamediv() { 
	document.getElementById('errorMessageName').style.visibility= 'visible';
}
function hideEmaildiv() {
	document.getElementById('errorMessageEmail').style.visibility= 'hidden';
}
function showEmaildiv() { 
	document.getElementById('errorMessageEmail').style.visibility= 'visible';
}
function hideCommentdiv() {
	document.getElementById('errorMessageComment').style.visibility= 'hidden';
}
function showCommentdiv() { 
	document.getElementById('errorMessageComment').style.visibility= 'visible';
}


// Poll Vote Form Required Fields
function checkPollVoteForm() {
	// set var radio_choice to false
	var radio_choice = false;

	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0;  counter < voteForm.poll_answer.length; counter++) {
	// If a radio button has been selected it will return true
	// (If not it will return false)
	if (voteForm.poll_answer[counter].checked)
		radio_choice = true; 
	}

	if (!radio_choice) {
		showVotediv();
		okToGo = false;
	}
	else {
		hideVotediv();
		okToGo = true;
	}
	
	if(okToGo) {
		return submit(form);
	}
	
	return okToGo;
}

function hideVotediv() {
	document.getElementById('errorMessageVote').style.visibility= 'hidden';
}
function showVotediv() { 
	document.getElementById('errorMessageVote').style.visibility= 'visible';
}


// Word Count in textarea
function WordCount (oTextArea, oCountLabelBox, nCount) {
	var sText = oTextArea.value;
	var nWordCount = 0;

	for (var nIter = 0; nIter < sText.length; nIter++) {
			if (sText.charAt(nIter) == "\\n" || sText.charAt(nIter) == " " || sText.charAt(nIter) == "\\r") {
				 nWordCount++;
				 if (nWordCount > nCount-1) {
						oTextArea.value = sText.substring(0,nIter);
						alert("Word count limit is " + nCount);
						break;
				 }
			}
	}
	if(nWordCount <= nCount-1)
	{
		oCountLabelBox.value = nWordCount + 1;								
		document.getElementById('errorcount').style.visibility = 'hidden';
	}
	else
	{
		oCountLabelBlock.value = nWordCount;
		document.getElementById('errorcount').style.visibility = 'visible'; 
	}
}

