var counter = 0;

function pollSubmit(field) {
	var c = $('pollform').comment;
	
	killText(c);
	
	return true;
}

function addOption(node) {
	var options = $('options');
	
	var option = document.createElement("div");
	option.className = "option";

	var optionInput = document.createElement("input");
	optionInput.type = "text";
	optionInput.name = "options[new" + counter + "][option]";
	
	var cbox = document.createElement("input");
	cbox.type = "checkbox";
	cbox.name = "options[new" + counter + "][text]";
	cbox.value = "y";
	
	var span = document.createElement("span");
	span.className = "small";
	span.innerHTML = "text";
	span.setAttribute("title","Include a text field associated with this question");
	
	option.appendChild(optionInput);
	option.appendChild(cbox);
	option.appendChild(span);

	options.appendChild(option);
	
	counter++;
	
	makeSortables();
}

function makeSortables() {
	Sortable.destroy('options');
	Sortable.create('options', {tag:"div",only:'option'});
}

function killText(node) {
	if (node.value == node.defaultValue) {
		node.value = "";
		node.style.color = "#000000";
	}
}

function restoreText(node) {
	if (node.value == "") {
		node.value = node.defaultValue;
		node.style.color = "#999999";
	}
}

function checkForm(node) {
	var pnode = node;
	
	while (pnode.nodeName != "FORM") {
		pnode = pnode.parentNode;
	}
	
	return false;
}