addLoadEvent("loadRadioGroups");
	
function loadRadioGroups(){
	var el = new Array();
	
	var form = document.getElementById("__fbform");
		
	el = getRadioGroups(form);
	for(var i = 0; i < el.length; i++){
		
		var o = new RadioGroup(el[i]);
		_controls.add(o);
		
	}
	
}

function getRadioGroups(el){
	var arr = new Array();
	var tmpArr;
	var nodes = el.childNodes;
	for(var i = 0; i < nodes.length; i++){
		if(nodes[i].tagName && nodes[i].tagName.toLowerCase() == "radiogroup")
			arr[arr.length] = nodes[i];
		else{
			tmpArr = getRadioGroups(nodes[i]);
			if(tmpArr)
				for(var j = 0; j < tmpArr.length; j++)
					arr[arr.length] = tmpArr[j];
		}
	}
	
	return arr;
}

function RadioGroup_ValidateRequired(id){
	var rg = _controls.getControlById(id);
	for(var i = 0; i <= rg.list.split(";").length; i++){
		if(document.getElementById(id + "_" + i)) {
			if(document.getElementById(id + "_" + i).checked)
				return true;
		}
	}
			
	return false;
}

function RadioGroup(el){
	this.type = "slider";
	this.max = 0;
	this.min = 0;
	this.width = 0;
	this.id = "";
	this.el = null;
	this.name = "";
	this.style = "";
	this.list = null;
	this.specifyOther = "false";
	
	this.oldMouseX = 0;
	
	this.load(el);
	this.render();
}

RadioGroup.prototype.load = function(el){
	this.el = el;
	this.cols = el.attributes["cols"].value;
	this.sort = el.attributes["sort"].value;
	this.list = el.attributes["list"].value;
	this.specifyOther = el.attributes["specifyother"].value;
	this.id = el.attributes["id"].value;
	this.name = el.attributes["name"].value;
	this.style = el.attributes["labelstyle"].value;
}

RadioGroup.prototype.render = function(){

	var thisHTML = "<table>";
	var allOptions = this.list.split(";");
	var rowCount = 0;
	var val = "";
	
	var container = document.createElement("span");
	this.el.parentNode.insertBefore(container, this.el);
	
	if(this.specifyOther == "true")
		allOptions[allOptions.length] = "Other";
	
	for(var i = 0; i < allOptions.length; null){
		thisHTML += "<tr>";
		for(var j = 0; j < this.cols; j++){
			if(i >= allOptions.length)
				break;
				
			label = allOptions[i];
			val = allOptions[i];
			
			if(label.toLowerCase() == "other" && this.specifyOther == "true") label += " (Please Specify)<br /><input type=\"text\" name=\"" + this.name + "\"/>";
			
			if(i == allOptions.length-1)
				thisHTML += "<td colspan=\"" + (this.cols-j).toString() + "\" valign=\"top\">";
			else
				thisHTML += "<td valign=\"top\">";
			
			thisHTML += "<input type=\"radio\" id=\"" + this.id + "_" + i + "\" name=\"" + this.name + "\" value=\"" + val + "\" />&nbsp;<span class=\"" + this.style + "\">" + label + "</span>";
			i++;
			//alert(this.style);
			thisHTML += "</td>";
		}
		thisHTML += "</tr>";
	}
	thisHTML += "</table>";
	
	container.innerHTML = thisHTML;
	this.el.parentNode.removeChild(this.el);
}