function addQuestion()
{
	var ni = document.getElementById('CMSQuestions');
	
	// Increment the total question count
	var numi = document.getElementById("questionCount");
	var questionCount = (document.getElementById("questionCount").value -1)+ 2;
	numi.value = questionCount;
	
	var str = '<div id="CMSQuestion'+questionCount+'">';
	str += '<p class="question">Question #'+questionCount+'</p>';
	str += '<input class=\"order\" name="order[]" type="text" value="'+questionCount+'">';
	str += '<input class=\"question\" name="question[]" type="text" value="Question">';
	// Current question number
	str += '<input name="questionID[]" type="hidden" value="-1">';
	str += '<a href="javascript:" onclick="removeQuestion(\''+questionCount+'\');" class="removeQuestion">X</a><br />';

	str += '<div id="CMSAnswers'+questionCount+'">';
	// Add all the new answer text boxes
	for(var i = 1; i < 5; i++)
	{
		str += '<div id="CMSQuestion'+questionCount+'Answer'+i+'">';
		str += '<input class="order" name="answerOrder'+questionCount+'[]" type="text" value="'+i+'">';
		str += '<input class="answer" name="answer'+questionCount+'[]" type="text" value="Answer '+i+'">';
		str += '<input class="value" name="value'+questionCount+'[]" type="text" value="0">';
		str += '<a href="javascript:" onclick="removeAnswer(\''+questionCount+'\', \''+i+'\')" class="removeAnswer">X</a>';
		str += '<input name="answerID'+questionCount+'[]" type="hidden" value="-1"><br />';
		str += '</div>';
	}
	
	str += '</div>';
	str += '<input type="hidden" id="answerCount'+questionCount+'" name="answerCount'+questionCount+'" value="4">';
	str += '<a href="javascript:" class="addAnswer" onclick="addAnswer(\''+questionCount+'\');">+</a><br /><br />';
	str += '</div>';
	
	ni.innerHTML += str;
}

function addAnswer(questionCount)
{
	var ni = document.getElementById("CMSAnswers"+questionCount);

	// Increment the total answer count
	var numi = document.getElementById("answerCount"+questionCount);
	var answerCount = (document.getElementById("answerCount"+questionCount).value -1)+ 2;
	numi.value = answerCount;

	// Add a new answer row
	var str = '<div id="CMSQuestion'+questionCount+'Answer'+answerCount+'">';
	str += '<input class="order" name="answerOrder'+questionCount+'[]" type="text" value="'+answerCount+'">';
	str += '<input class="answer" name="answer'+questionCount+'[]" type="text" value="Answer '+answerCount+'">';
	str += '<input class="value" name="value'+questionCount+'[]" type="text" value="0">';
	str += '<a href="javascript:" onclick="removeAnswer(\''+questionCount+'\', \''+answerCount+'\')" class="removeAnswer">X</a>';
	str += '<input name="answerID'+questionCount+'[]" type="hidden" value="-1"><br />';
	str += '</div>';

	ni.innerHTML += str;
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

function removeQuestion(question)
{
	var d = document.getElementById('CMSQuestions');
	var olddiv = document.getElementById('CMSQuestion'+question);
	d.removeChild(olddiv);
  
  	// Reduce the total question count
  	var numi = document.getElementById("questionCount");
  	var questionCount = (document.getElementById("questionCount").value -1);
	numi.value = questionCount;
	
	// Save the fact that a removal has been made
	var numi = document.getElementById("removedElement");
	numi.value = "Yes";
}

function removeAnswer(question, answer)
{
	var d = document.getElementById('CMSAnswers'+question);
	var olddiv = document.getElementById('CMSQuestion'+question+'Answer'+answer);
	d.removeChild(olddiv);
  
  	// Reduce the total answer count
  	var numi = document.getElementById('answerCount'+question);
  	var answerCount = (document.getElementById('answerCount'+question).value -1);
	numi.value = answerCount;
	
	// Save the fact that a removal has been made
	var numi = document.getElementById("removedElement");
	numi.value = "Yes";
}

/////////////////////////////////////////////
/////////////////////////////////////////////

// Make sure all questions are answered
function canSubmit_Quiz(form)
{
	var count = document.getElementById("questionCount").value;
	var canSubmit = true;
	
	// Verify all questions
	for(var i = 1; i < count; i++)
	{
		var elem = document.getElementsByName("answer"+i);
		var found = false;
	
		// Verify at least one option has been selected per question
		for(var j = 0; j < elem.length; j++)
		{			
			if(elem[j].checked == true)
				found = true;
		}
		
		if(found == false)
			canSubmit = false;
	}
	
	// Will allow or reject submition
	if(canSubmit == false)
	{
		alert("All quiz questions must be answered before we can see if you're a Christian Hipster.");
		return false;
	}
	else
		return true;
	
	/* Run through each group of buttons
	for(var i = 0; i < count; i++)
	{
		var buttonCount = form.answer[i].length;
		var answer = "";
		
		// Run through each button
		for(var j = 0; j < buttonCount; j++)
		{
			if(form.answer[i][j].checked == false)
			{
				alert("FALSE");
				answer = "Y";
			}
		}
		
		if(answer == "Y")
			return false;
	}
	*/
	return true;
}
