var unansweredBG = "#eeeeee";
var unansweredBorder = "#ffffff";
var answeredTopBG = "#8cc63e";
var answeredBottomBG = "#fafffa";
var answeredBorder = "#005500";

// Question Class
function Question(id, content, answers)
{	
	this.id = id;
	this.content = content;
	this.answers = answers;
	
	this.drawQuestion = drawQuestion;
	this.setAnswered = setAnswered;
	
	function drawQuestion(parentID)
	{
		var questionContent = "";
		var newContainer;
		
		var thisID = parentID+1;
		var nextID = thisID+1;
		
		newContainer = document.getElementById("c"+(thisID));

		questionContent += "<div style=\"background-color: "+unansweredBG+"; width: 600px; padding: 5px;\" id=\"q"+this.id+"\">"+this.content+"</div>";
		questionContent += "<div style=\"border: 1px solid "+unansweredBG+"; width: 600px; padding: 5px;\" id=\"a"+this.id+"\">";
		
		for(var i in this.answers) 
		{
			var a = this.answers[i];
			var msgClass = "";
			
			if(a.msg=="")
			{
				msgClass = "hiddenMessage";
			}
			else
			{
				msgClass = "displayMessage";
			}
			
			if(a.nextQuestion=="end")
			{
				questionContent += " <input style=\"border: 0px;\" type=\"radio\" id=\"r"+this.id+"_"+i+"\" name=\""+this.id+"\" onclick=\"setAnswered('"+this.id+"'); document.getElementById('msg"+this.id+"').className='"+msgClass+"';document.getElementById('msg"+this.id+"').innerHTML='"+a.msg+"';document.getElementById('c"+(nextID)+"').innerHTML='';\" /> <label for=\"r"+this.id+"_"+i+"\" style=\"cursor:hand; cursor: pointer;\">"+a.content+"</label>   ";
			}
			else
			{
				questionContent += " <input style=\"border: 0px;\" type=\"radio\" id=\"r"+this.id+"_"+i+"\" name=\""+this.id+"\" onclick=\"setAnswered('"+this.id+"'); document.getElementById('msg"+this.id+"').className='"+msgClass+"';document.getElementById('msg"+this.id+"').innerHTML='"+a.msg+"';document.getElementById('c"+(nextID)+"').innerHTML='';"+a.nextQuestion+".drawQuestion("+thisID+");\" /> <label for=\"r"+this.id+"_"+i+"\" style=\"cursor:hand; cursor: pointer;\">"+a.content+"</label>   ";
			}
		}
		questionContent += "<br/></div><div style=\"display: none;\" id=\"arrow"+this.id+"\"><img src=../../policies_and_initiatives/shw/images/table_green_arrow2.gif /></div>\n<br/><div id=\"msg"+this.id+"\"></div>\n<br/><div id=\"c"+(nextID)+"\"></div>";
		
		newContainer.innerHTML = questionContent;
	}
}

// Answer Class
function Answer(content, nextQuestion, msg)
{
	this.content = content;
	this.nextQuestion = nextQuestion;
	this.msg = msg;
}

function setAnswered(questionID)
{
	var questionDiv = document.getElementById('q'+questionID);
	var answerDiv = document.getElementById('a'+questionID);
	var arrowDiv = document.getElementById('arrow'+questionID)
	
	questionDiv.style.borderWidth = "1px";
	questionDiv.style.borderStyle = "solid";
	questionDiv.style.borderColor = answeredBorder;
	questionDiv.style.backgroundColor = answeredTopBG;
	questionDiv.style.borderBottomWidth = "0px";
	answerDiv.style.borderColor = answeredBorder;
	answerDiv.style.backgroundColor = answeredBottomBG;
	answerDiv.style.borderBottomWidth = "0px";
	answerDiv.style.borderTopWidth = "0px";
	
	arrowDiv.style.display = "block";
}
