var PollObjects = new Array();

function InitPoll(header_obj)
{
	var PollObjectsIndex = PollObjects.length;
	PollObjects[PollObjectsIndex] = new PollObject(document.getElementById(header_obj).parentNode, PollObjectsIndex);	
}

function PollObject(container_node, index)
{
	this.index = index;
	this.rootNode = container_node;
	this.inputList = this.rootNode.getElementsByTagName("input");
	this.radioList = new Array();
	this.checkList = new Array();
	this.dataList;
	this.submitButton;
	
	for(i=0;i<this.inputList.length;i++)
	{
		switch(this.inputList[i].type)
		{
			case "radio":
				this.radioList[this.radioList.length] = this.inputList[i];
				break;
			case "checkbox":
				this.checkList[this.checkList.length] = this.inputList[i];
				break;
			case "image":
				this.submitButton = this.inputList[i];
				break;
		}
	}
	
	this.dataList = (this.isRadioList()) ? this.radioList : this.checkList;
	for(d=0;d<this.dataList.length;d++)
	{
		eval("this.dataList[d].onclick = function(){PollObjects[" + this.index + "].checkActiveState();}");
	}
	
	this.inactiveButton = new Image();
	this.inactiveButton.src = this.submitButton.src.replace("Active.sflb","Inactive.sflb");
	
	this.activeButton = new Image();
	this.activeButton.src = this.submitButton.src;
	
	this.checkActiveState();
	
}

PollObject.prototype.checkActiveState = function()
{
	var isChecked = false;
	for(i=0;i<this.dataList.length;i++)
	{
		if(this.dataList[i].checked == true){isChecked=true;}
	}
	(isChecked) ? this.setActive() : this.setInactive();
}

PollObject.prototype.setActive = function()
{
	this.submitButton.src = this.activeButton.src;
	this.submitButton.disabled = false;
	this.submitButton.style.cursor = "pointer";
}

PollObject.prototype.setInactive = function()
{
	this.submitButton.src = this.inactiveButton.src;
	this.submitButton.disabled = true;
	this.submitButton.style.cursor = "default";
}

PollObject.prototype.isRadioList = function()
{
	var toReturn = false;
	if(this.radioList.length == 0 && this.checkList.length > 0)
	{
		toReturn = false;
	}
	else if(this.radioList.length > 0 && this.checkList.length == 0)
	{
		toReturn = true;	
	}
	else
	{
		throw "This is neither a radio nor checkbox list poll.";
	}
	return toReturn;
}