var toll=toll || {};

toll.RadioGroup=function(radioName, clickCallback){
	this.radios=document.getElementsByName(radioName);
	
	var that=this;
	if(clickCallback){
		for(var i=0; i<this.radios.length; i++) {
			var radio=this.radios[i];
			radio.onclick=function(){
				clickCallback.call(that);
			}
		}
	}
	
	this.setEnabled=function(enabled){
		for(var i=0; i<this.radios.length; i++) {
			var radio=this.radios[i];
			radio.disabled=enabled==false;
		}
	}
	this.setCheckedValue=function(value){
		for(var i=0; i<this.radios.length; i++) {
			var radio=this.radios[i];
			if(radio.value==value){
				radio.checked=true;
				break;
			}
		}
	 }
	 this.getCheckedValue=function(){
		for(var i=0; i<this.radios.length; i++) {
			var radio=this.radios[i];
			if(radio.checked){
				return radio.value;
			}
		}
	 }
};

toll.SelectControl=function(selectElement, callback){
	//Use like constructor but omit 'new' as in: var s=toll.SelectControl(arg1,arg2)
	var obj={
		setEnabled:function(enabled){
			selectElement.disabled = !enabled;
		},
		
		getSelectedValue:function(){
			return selectElement.options[selectElement.selectedIndex].value;
		},
		getSelectedText:function(){
			return selectElement.options[selectElement.selectedIndex].text;
		},
		setSelectionToFirstOption:function(){
			selectElement.options[0].selected = true;
		},
		setSelectedOption:function(optionValue){
			var opt;
			for(var i=0;i<selectElement.options.length;i++){
				opt=selectElement.options[i];
				if(opt.value==optionValue){
					opt.selected=true;
					break;
				}
			}
		}
	}
	selectElement.onchange=function(){callback.apply(obj)};
	return obj;
}






