function checkUniChoice()

{

	var uni_choices = document.getElementById("university");

	var choices_value = uni_choices.options[uni_choices.selectedIndex].value;



	if(choices_value == "OtherUni")

	{

		var other_uni = document.getElementById("other_university");

		other_uni.disabled=false;

	}

	else

	{

		var other_uni = document.getElementById("other_university");

		other_uni.disabled=true;

	}

	

}



function validateFields()

{

	validateNoOfChoices();

	togglePollType(document.getElementById("poll_type"));

}



function validateNoOfChoices(){

	var choice_table = document.getElementById("choice_table");

	var poll_type = document.getElementById("poll_type");

	if(choice_table.rows.length < 3)

	{

		poll_type.options[1].disabled = true;

		poll_type.options[0].selected = true;

	}

	else

	{

		poll_type.options[1].disabled = false;

	}

	//var poll_type = obj.options[obj.selectedIndex].value;

	//var max_choice = document.getElementById("max_choice");

}



function togglePollType(obj)

{

	var poll_type = obj.options[obj.selectedIndex].value;

	var max_choice = document.getElementById("max_choice");

	var min_choice = document.getElementById("min_choice");

	if(poll_type=="S")

	{

		max_choice.selectedIndex = 0;

		max_choice.disabled = true;

		min_choice.selectedIndex = 0;

		min_choice.disabled = true;

	}

	else

	{

		max_choice.disabled = false;

		if(max_choice.selectedIndex==0)

			max_choice.selectedIndex = 1;

		min_choice.disabled = false;

	}

		

}

function addChoice()

{

	var course_list = document.getElementById('course');

	

	var uls = course_list.getElementsByTagName("UL");

	for(var i = uls.length-1 ;uls.length>0 && i < uls.length ; i++){

		//alert(uls[i].lastChild);

		//alert(uls[i].lastChild.className);

		if(uls[i].lastChild.nodeName=="LI")

			var item = uls[i].lastChild;

	}

	

	

	var new_ul = document.createElement("ul");

	var new_li = document.createElement("li");

	var new_input = document.createElement("input");

	

	var s= document.createElement("SPAN");

	var t= '\u00A0'; // &nbsp;

	s.className = "bullet";

	s.appendChild(document.createTextNode(t));

	new_li.insertBefore(s,new_li.firstChild);

	//var img= document.createElement("span");

	//img.className="sptree";

	//img.innerHTML="&nbsp;";

	//new_li.insertBefore(img,new_li.firstChild);

	

	new_li.className = "liBulletLast";

	new_input.name = "module[]";

	new_input.style.width="250px";

	//new_input.maxLength="300";

	

	

	

	//var new_cell2 = new_row.insertCell(1);

	var new_link = document.createElement("a");

	new_link.innerHTML = "remove";

	new_link.href = "javascript:void(0)";

	new_link.onclick = function(){removeChoice(this)};

	

	new_ul.appendChild(new_li);

	new_li.appendChild(document.createTextNode('Module:'));

	new_li.appendChild(new_input);

	new_li.firstChild.style.background="url(/images/Lbullet.png) center left no-repeat";

	//new_li.style.background="url(/images/Lbullet.png) center left no-repeat";

	new_li.firstChild.style.fontSize="14pt"; 

	course_list.appendChild(new_ul);

	//alert(item.innerHTML);

	//item.firstChild.style.border="1px solid black";

	//item.firstChild.style.height="100px";

	item.firstChild.style.background="url(/images/Tbullet.png) center left no-repeat";

	//item.style.background="url(/images/Tbullet.png) center left no-repeat";

	//new_li.style.height="50px";

	//new_ul.style.height="50px";

	item.className="liBullet";	

	item.firstChild.style.fontSize="14pt"; 

	//alert(course_list.nextSibling.nextSibling);

	//alert(item.firstChild.style.background);

	

	//new_cell2.appendChild(document.createTextNode('['));

	//new_cell2.appendChild(new_link);

	//new_cell2.appendChild(document.createTextNode(']'));

	

	//var new_option = document.createElement("option");

	//new_option.text = document.getElementById("min_choice").length+1;

	//new_option.value = document.getElementById("min_choice").length+1;

	//document.getElementById("min_choice").add(new_option,null);

	

	//var new_option = document.createElement("option");

	//new_option.text = document.getElementById("max_choice").length+1;

	//new_option.value = document.getElementById("max_choice").length+1;

	//document.getElementById("max_choice").add(new_option,null);

	//validateFields();

}



function removeChoice(obj)

{

	if(obj.parentNode!=null && obj.parentNode.parentNode !=null)

	{

		if(obj.parentNode.parentNode.tagName=="TR"){

			var index = obj.parentNode.parentNode.rowIndex;

			var choice_table = document.getElementById('choice_table');

			if(choice_table.rows.length == 2)

				alert("Minimum 2 choices!");

			else{

				choice_table.deleteRow(index);

				document.getElementById("max_choice").remove(document.getElementById("max_choice").length-1);

				document.getElementById("min_choice").remove(document.getElementById("min_choice").length-1);

				validateFields();

			}

		}

	}

}
