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").value = mood;
		Element.setOpacity(icn, 1);
		if (activeMood != mood && activeMood != "") {
			icna = $("icn" + activeMood);
			Element.setOpacity(icna, 0.5);

		}
		activeMood = mood;
	}
}

checkPost = function() {
	if (document.forms['post-form'].cName.value == "") {
		alert("You must specify a title for this post");
		return false;
	}
	
	if (pollHasFocus) {
		return false;
	} else {
		return true;
	}
}

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