var currentPollOption = 0;
var pollHasFocus = false;

function addOption(value) {		
	var pi = document.getElementById("pollOptions");

	if (currentPollOption == 0) {
		pi.innerHTML = "";
	}
	currentPollOption++;
	ip = document.createElement("INPUT");
	ip.type = "hidden";
	ip.name = "pollOption[]";
	ip.value = document.forms['post-form'].optionValue.value;
			
	ipd = document.createElement("DIV");
	ipd.id = "option" + currentPollOption;
	ipd.innerHTML = "<a href=\"#\" onclick=\"removeOption(" + currentPollOption + ")\">[-]<" + "/a> " + ip.value;
	ipd.appendChild(ip);
	pi.appendChild(ipd);
	
	document.forms['post-form'].optionValue.value = "";
}

function disableEnterKey(e) {
	var key;

	 if(window.event) {
		 key = window.event.keyCode;     //IE
	 } else {
		key = e.which;     //firefox
	 }

	if(key == 13) {
	  return false;
	} else {
	  return true;
	}
}

function removeOption(id) {
	var pi = document.getElementById("pollOptions");
	opt = document.getElementById("option" + id);
	pi.removeChild(opt);
	currentPollOption--;
	if (currentPollOption == 0) {
		pi.innerHTML = "None";
	}
}

selectPostMood = function(mood) {
	if (mood) {
		icn = $("#icn" + mood);
		$("#oPostMood").val(mood);
		icn.css('opacity', 1.0);
		if (activeMood != mood && activeMood != "") {
			$("#icn" + activeMood).style('opacity', '0.5');
		}
		activeMood = mood;
	}
}

checkPost = function() {
	if (!$("#oPostMood").val()) {
		alert("Please choose whether this is a Comment, a Question, an Agreement or Disagreement.");
		return false;
	}
	if (pollHasFocus) {
		return false;
	} else {
		return true;
	}
	
}

$(function() { selectPostMood(activeMood); });
