function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}

function check_submit(what) {
	mandats = new Array();
	j = 0;
	retval = false;
	for(i = 0; i<what.elements.length; i++) {
		if(what.elements[i].className == 'mandat'
			|| what.elements[i].className == 'error') {
			if(trim(what.elements[i].value) != '') {
				retval = true;
			}
			mandats[j] = i;
			j++;
		}
	};
	if(!retval) {
		for(i=0; i<mandats.length; i++) {
			what.elements[mandats[i]].className = 'error';
		};
		alert(TEXT_MANDAT_ERROR);
	};
	what.elements[mandats[0]].focus();
	return retval;
}

function setup() {
	MM_preloadImages('/obrazky/vlajka-anglicka.gif','/obrazky/vlajka-nemecka.gif','/obrazky/vlajka-polska.gif');
	if(typeof(window.document.flash) != 'undefined') {
		window.document.flash.SetVariable('jazyk', lang);
		//window.document.mapa.style.display = 'block';
	};
	if(typeof(window.document.flashmapa) != 'undefined') {
		window.document.flashmapa.SetVariable('jazyk', lang);
		//window.document.flashmapa.style.display = 'block';
	};
}

function row(what, action) {
	if(action == 'on') {
		what.originalClass = what.className;
		what.className = 'vypis-aktivni';
	} else {
		what.className = what.originalClass;
	};
}
function razeni(what) {
	document.getElementById('frm_sort').value = what;
	document.getElementById('frmrazeni').submit();
	return false;
}
function oblasti(what) {
	//alert(names[what][0]);
	if(typeof(document.oblasti) == ('undefined')) {
		document.oblasti = new Array();
	};
	if(typeof(document.oblasti[what]) == ('undefined')) {
		document.oblasti[what] = false;
	};
	document.oblasti[what] = ! document.oblasti[what];
	loblasti = new Array();
	list = new Array();
	for(key in names) {
		if(document.oblasti[key]) {
			loblasti.push(key);
			list.push(names[key][0]);
		};
	};
	document.getElementById('frm_oblasti').value = loblasti.join('|');
	document.getElementById('frm_toblasti').value = list.join(', ');
}
function changeAction(what) {
	if(document.getElementById('frm_oblasti').value != '') {
		what.action = what.action + '/oblast/' + document.getElementById('frm_oblasti').value + '/';
	} else {
		what.action = what.action + '/';
	};
	return true;
}
function fill(where, what) {
	// Do formulářového pole s ID "where" vloží hodnotu what
	document.getElementById(where).value = what;
	return false;
}
function prepni(what) {
	co = document.getElementById(what);
	if(co.style.display != 'none') {
		co.style.display = 'none';
	} else {
		co.style.display = 'block';
	};
}
function switchTA2() {
	ta1 = document.getElementById('novrow1');
	ta2 = document.getElementById('novrow2');
	current = ta1.style.display;
	if(current=='none') {
		ta1.style.display = '';
		ta2.style.display = '';
	} else {
		ta1.style.display = 'none';
		ta2.style.display = 'none';
	}
};

function GoFirst() {
	if(document.forms.length>0) document.forms[0].elements[0].focus();
};

function CallCalendar(a,b) {
	var tmp;
	//tmp = document.forms[a].elements[b];
	tmp = document.getElementById(b);
	w=window.open('/calendar.php?date='+tmp.value+'&a='+a+'&b='+b,'calendar','width=280,height=250');
}

function displayImage(file, w, h) {
	nw = w+20;
	nh = h+20;
	file = '/imager.php?file='+file;
	param = 'width=' + nw + ',height=' + nh;
	w=window.open(file,'imager',param);
}

function switchChecks(frm) {
	if(!frm.action) frm.action = 'off';
	for(i=0; i<frm.form.length; i++) {
		if(frm.form.elements[i].type == 'checkbox') {
			if(frm.action == 'off')
				frm.form.elements[i].checked = false;
			else
				frm.form.elements[i].checked = true;
		};
	};
	frm.value = frm.action == 'off' ? 'Zaškrtnout vše' : 'Odškrtnout vše';
	frm.action = frm.action == 'off' ? 'on' : 'off';
}

function addToForum() {
	if(navigator.appVersion.indexOf("MSIE") == -1) {
  	protocol = document.getElementById("forumadd").protocol + "//";
  	host = document.getElementById("forumadd").host;
  	path = document.getElementById("forumadd").pathname;
  	srch = document.getElementById("forumadd").search;
  	kam = protocol + host + path + srch;
		window.location = kam;
	} else {
		document.getElementById("forumadd").click();
	}
	return false;
}
