// Surveys

function AnswerClick(who) {
	// This function is invoked when user selects an option. The AJAX call should be made from here
	var groupName = who.name.replace("rbGroup","");
	var selectedValue = who.value;
	
	// Disable the controls of this option group
	// Remove the onClick functionality
	var allButtons = document.getElementsByName(who.name);
	for (var i=0;i<allButtons.length;i++) {
		allButtons[i].disabled = true;
		allButtons[i].onclick = doNothing;
	}
	
	_surveysIndex.Vote(document.getElementById("hdnUState").value, groupName,selectedValue,FillInfo_Callback);
}

function ForumIndexAnswerClick(who) {
	// This function is invoked when user selects an option. The AJAX call should be made from here
	var groupName = who.name.replace("rbGroup","");
	var selectedValue = who.value;
	
	// Disable the controls of this option group
	// Remove the onClick functionality
	var allButtons = document.getElementsByName(who.name);
	for (var i=0;i<allButtons.length;i++) {
		allButtons[i].disabled = true;
		allButtons[i].onclick = doNothing;
	}
	
	_forumsIndex.Vote(document.getElementById("hdnUState").value, groupName,selectedValue,FillInfo_Callback);
}

function FillInfo_Callback(response) {
	
	var resStr = response.value;
	
	if (resStr == null || resStr == "") {
		// An error occured
	} else {
		var blocks = resStr.split("~#~");
		var qid = blocks[0];
		// Show the results table
		document.getElementById("res"+qid).style.display = (window.navigator.appName.toLowerCase().indexOf("explorer")>-1)?"block":"table";
		// Fill the data
		for (var i=1;i<blocks.length;i++) {
			document.getElementById("res"+qid+"item"+i+"_lbl").innerHTML = blocks[i];
			document.getElementById("res"+qid+"item"+i+"_slider").style.width = blocks[i];
		}
	}
}

function doNothing() {
	return false;
}

function ToggleItem(who) {
	var tgt = document.getElementById(who.getAttribute("myitem"));
	who.parentNode.className = (who.parentNode.className.indexOf("Selected")>-1)?who.parentNode.className.replace(" Selected",""):(who.parentNode.className + " Selected");
	tgt.className = (tgt.className.indexOf("Collapsed")>-1)?tgt.className.replace("Collapsed","Open"):tgt.className.replace("Open","Collapsed");
}

