/*
*	Tomáš Králík Copyright © 2010 
*/

function radioSet(id, value, params) {
	
	var thisId = id;
	
	this.onchange = function () {};
	
	var params = new Tparams(params);
	
	
	if (params.params['checkedClass']) {
		this.radioYesClass = params.params['checkedClass'];
	} else {
		this.radioYesClass = 'radioYes';
	}
	
	if (params.params['uncheckedClass']) {
		this.radioNoClass = params.params['uncheckedClass'];
	} else {
		this.radioNoClass = 'radioNo';
	}
	
	if (params.params['value']) {
		this.group = document.getElementById(params.params['value']);
	} else {
		this.group = document.getElementById(thisId + '.value');
	}
	
	
	this.group.value = '';
	this.value = value;
	
	
	this.radios = new Array();
	
	
	this.add = function (id, params) {
		
		var params = new Tparams(params);
		
		var optionDiv = document.createElement('div');
		optionDiv.className = 'radio';
		appendNode(optionDiv);
		
		
		var onclick = thisId + '.check(\'' + id + '\'); return false;';
		var nodeId = thisId + '.' + id;
		
		var radio = '<span class="' + this.radioNoClass + '" id="' + nodeId + '" onclick="' + onclick + '" onmousedown="return false;" >&nbsp;</span>';
		
		
		if (params.params['title']) {
			var title = '<span style="float:left;cursor:pointer;" onclick="' + onclick + '" onmousedown="return false;">' + params.params['title'] + '</span>';
		} else {
			var title = '';
		}
		
		
		optionDiv.innerHTML = radio + title;
		
		this.radios.push(id);
		
		// value set
		if (this.value == id) {
			this.check(id);
		}
		
		
	}
	
	
	this.check = function (id) {
		
		var radio = document.getElementById(thisId + '.' + id);
		
		for (var x in this.radios) {
			
			if (this.radios[x] == id) {
				document.getElementById(thisId + '.' + this.radios[x]).className = this.radioYesClass;
				this.value = id;
			} else {
				document.getElementById(thisId + '.' + this.radios[x]).className = this.radioNoClass;
			}
			
		}
		
		this.onchange();
		
	}
		
}

