
/**
 * da .focus() elementu s ID=current
 */
function setCursor(current) {
	var elm = document.getElementById(current);
	if (elm) {
		elm.focus();
	}
}


/**
 * schova nebo zobrazi element s ID current
 * @param string current ID html elementu
 * @param bool show ma se element skryt nebo zobrazit
 */
function setDisplay(current, show) {
	var elm = document.getElementById(current);
	if (elm) {
		var tag = elm.tagName.toLowerCase();

		if (!show) {
			elm.style.display = 'none';

		} else if (tag == 'table') {
			elm.style.display = 'table';

		} else if (tag == 'img') {
			elm.style.display = 'inline';

		} else {
			elm.style.display = 'block';
		}
	}
}


/**
 * skupiny inputu
 * @param string current ID html elementu pro aktivovani
 * @param array source pole vsech ID pro nastaveni hodnoty disabled
 * @return void
 */
function setEnable(current, source) {
	var elm;

	for (var i in source) {
		elm = document.getElementById(source[i]);
		if (elm) {
			elm.disabled = (current != source[i]);
		}
	}
}


/**
 * zmeni hodnotu input hidden na hodnotu action
 * @param string
 */
function changeAction(action, form) {
	var elm = document.getElementById('cfgAction');
	if (elm) {
		elm.value = action;
		if (typeof(form) != 'undefined') elm.form.action = form;
	}
}


/**
 *
 * @param string msg hodnota zpravy funkce alert()
 * @return bool (false)
 */
function setFalse(htmlObj, msg) {
	if (htmlObj != null) {
		htmlObj.focus();

		if (typeof(htmlObj.style) != 'undefined') {
			htmlObj.className = 'WARNING';
		}
	}

	if (msg.toString != '') alert(msg);

	return false;
}


/**
 *
 * @return bool
 */
function checkLogin() {
	var auth = document.getElementById('auth');
	if (!auth || typeof(auth.value) == 'undefined') {
		return false;

	} else if (auth.value.indexOf('@') == -1 || auth.value.indexOf('.') == -1) {
		return setFalse(auth, 'Email pro přihlášení do systému nebyl správně zadán.');
	}
	auth.className = 'INPUT';

	var pass = document.getElementById('pass');
	if (!pass || typeof(pass.value) == 'undefined') {
		return false;

	} else if (pass.value.replace(/\s/g, '') == '') {
		return setFalse(pass, 'Heslo pro přihlášení do systému bylo chybně zadáno.');
	}
	pass.className = 'INPUT';

	return true;
}

