function send_xmlhttprequest(obsluha, method, url, content, headers) {
	var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));

	if (!xmlhttp)
		return false;

	xmlhttp.open(method, url);

	if (obsluha != null)
		xmlhttp.onreadystatechange = function() {
			obsluha(xmlhttp);
		};

	if (headers) {
		for (var key in headers)
			xmlhttp.setRequestHeader(key, headers[key]);
	}

	xmlhttp.send(content);
	return true;
}

function open_popup(dokument, sirka, vyska, scrollbars) {
	so = screen.width;
	vo = screen.height;
	zleva = ((so - sirka) / 2) - 13;
	shora = 120;
	popup_win = window.open(dokument,"popup_okno","width="+sirka+",height="+vyska+",left="+zleva+",top="+shora+",location=0,resizable=1,scrollbars="+scrollbars+",status=0,toolbar=0");
	popup_win.focus();
}

function Show(id, show) {
  if (show)
    document.getElementById(id).style.visibility='visible';
  else
    document.getElementById(id).style.visibility='hidden';
}


function open_hide(id) {
	obj = document.getElementById(id);

	if (obj) {
		if (obj.style.display == '' || obj.style.display == 'block')
			obj.style.display = 'none';
		else
			obj.style.display = 'block';
	}

	return false;
}

function WallyMaker (_id, _cl) {
	var f = document.getElementById(_id);
	if (f == null) {
		alert('WallyMaker error: bad id ' + _id);
		return;
	}

	function GetByTag (_t, _e) {
		if (_e != undefined)
			return _e.getElementsByTagName(_t);
		else
			return document.getElementsByTagName(_t);
	}

	function GetByClass (_c, _e) {
		var e = GetByTag("*", _e);
		var e2 = new Array();
		
		var i = 0;
		for (i = 0; i < e.length; i++)
			if (e[i].className == _c)
				e2.push(e[i]);
		
		return e2;
	}
	
	// skupina (fieldset s inputama a selectama)
	function Group(_e, _g) {
		this.el = _e;
		this.groups = _g;  // reference na pole skupin
		this.selects = GetByTag("select", this.el);
		this.inputs = GetByTag("input", this.el);
		this.numActives = 0;  // pocet aktivnich prvku (zaskrtnuty, vybrany)
		var i = 0;

		// nastaveni selectu
		for (i = 0; i < this.selects.length; i++) {
			this.selects[i].ref = this;  // reference na this
			this.selects[i].act = false;  // je aktivni? (value neni 0)
			if (this.selects[i].value != 0)
				this.numActives++;
			
			this.selects[i].onchange = function () {
				if (this.value != 0) {
					if (!this.act) {
						this.act = true;
						this.ref.numActives++;
					}
				} else {
					this.act = false;
					this.ref.numActives--;
				}
				
				if (this.ref.numActives == 0)
					this.ref.DOthers(false);
				else
					this.ref.DOthers(true);
			}
		}
		
		// nastaveni checkboxu
		for (i = 0; i < this.inputs.length; i++) {
			this.inputs[i].ref = this;
			if (this.inputs[i].type == "checkbox")
				if (this.inputs[i].checked)
					this.numActives++;
					
				this.inputs[i].onclick = function () {
					if (this.checked)
						this.ref.numActives++;
					else
						this.ref.numActives--;
					
					if (this.ref.numActives == 0)
						this.ref.DOthers(false);
					else
						this.ref.DOthers(true);
				}
		}
		
		// disable
		this.D = function(_de) {
			for (i = 0; i < this.selects.length; i++)
				this.selects[i].disabled = _de;
			for (i = 0; i < this.inputs.length; i++)
				this.inputs[i].disabled = _de;
		}
		
		this.Disable = function () {
			this.D(true);
		}
		
		this.Enable = function () {
			this.D(false);
		}
		
		// disable ostatni skupiny
		this.DOthers = function (_de) {
			for (i = 0; i < this.groups.length; i++)
				if (this.groups[i] != this) {
					if (_de)
						this.groups[i].Disable();
					else
						this.groups[i].Enable();
				}
		}
	}

	var fi = GetByClass(_cl, f), i = 0, groups = new Array();
	for (i = 0; i < fi.length; i++)
		groups.push(new Group(fi[i], groups));

	// 
	for (i = 0; i < groups.length; i++)
		if (groups[i].numActives > 0) {
			groups[i].DOthers(true);
			break;
		}
}