/* BEGIN - AJAX */
function akceZobrazeni(odkaz, typ, kamZobrazit, query_string)
{
    var url = odkaz + ((query_string != 0) ? "&" + query_string : "");

    if (!url) {
        document.getElementById(kamZobrazit).innerHTML = "";
    } else {
        if (window.ActiveXObject) {
            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange = function () { processRequest(kamZobrazit, url); } ;
        httpRequest.send(null);
    }
    if (typ == "odkaz") {
        return false;
    }
}
function processRequest(kamZobrazit, url)
{
    var mistoZobrazeni = document.getElementById(kamZobrazit);
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            mistoZobrazeni.innerHTML = httpRequest.responseText;
        } else {
            alert("Chyba pri nacitani stanky "+ httpRequest.status +": "+ httpRequest.statusText + " ("+ url +")");
        }
    } else {
        mistoZobrazeni.innerHTML = "<span style='color:red;'>Nahrávám....</span>";
    }
}
/* END - AJAX */

/*
31.5.2005
Ales Dostal
Funkce pro kontrolu formulare
*/
function kontrolaFormulare(frm)
{
    for (i=1; i < arguments.length; i++) {
        if (frm[arguments[i]].value == '') {
            frm[arguments[i]].focus();
            alert('Vyplňte všechny povinné položky.');
            return false;
        }
    }
    return true;
}
/*
31.5.2005
Ales Dostal
Funkce pro pouziti cisla do formulare z vyhledavani zamestnancu
*/
function pouzijCislo(cislo, prijmeni, jmeno, policko)
{
    f = window.opener.document.forms.vloz_zamestnance;
    if(!f) {
        return false;
    } else {
        window.opener.document.forms['vloz_zamestnance'][policko].value = cislo + ' (' + prijmeni + ' ' + jmeno + ')';
        alert("Číslo zaměstnance bylo použito do formuláře.");
        window.close();
        return true;
    }
}

/*
2.6.2005
Ales Dostal
Funkce pro pouziti datumu do fomulare
*/
function pouzijDatum(datum_zadani, policko)
{
    f = window.opener.document.forms.vloz_zamestnance;
    if(!f) {
        return false;
    } else {
        window.opener.document.forms['vloz_zamestnance'][policko].value = datum_zadani;
        alert("Datum bylo použito do formuláře.");
        window.close();
        return true;
    }
}

/* START HORNI MENU */
/*
7.6.2005
Ales Dostal
funkce pro horni menu
*/
var currentMenu = null;
if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    //if (window.opera) return; // I'm too tired
    actuator.onmouseover = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
            this.showMenu();
        }
    }

    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        } else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        /* 12.6.2005 Ales Dostal funkce pro zobrazeni-skryti select menu, aby v IE v menu neprosvitalo */
        if ((navigator.appName == "Microsoft Internet Explorer") & parseInt(navigator.appVersion) >=4 ) {
            if (!document.getElementsByTagName) return;
            var sels = document.getElementsByTagName('select');
            for (var i = 0; i < sels.length; i++) {
                var sel = sels[ i ];
                if (currentMenu == null) {
                    sel.style.visibility = 'visible';
                } else {
                    sel.style.visibility = 'hidden';
                }
            }
        }
        return false;
    }

    actuator.showMenu = function() {
        menu.style.left = this.offsetLeft + "px";
        menu.style.top = this.offsetTop + this.offsetHeight + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}
/* END HORNI MENU */

//Highlight form element- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

var highlightcolor="#e8fd5e"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e)
{
    eventobj=ns6? e.target : event.srcElement
    if (previous!='') {
        if (checkel(previous)) {
            previous.style.backgroundColor=''
        }
        previous=eventobj
        if (checkel(eventobj)) {
            eventobj.style.backgroundColor=highlightcolor
        }
    } else {
        if (checkel(eventobj)) {
            eventobj.style.backgroundColor=highlightcolor
        }
        previous=eventobj
    }
}


/*
23.6.2005
Ales Dostal
funkce pro kontrolu zadanych dat ve formulari
*/
var focus_changing = false;
var dont_check = false;

// Focus into field f, display message s and return false
function focus_alert(s, f) {
	f.focus();
	alert(s);
	return false;
}

// Check fields in the form
// s is warning message, f is pointer to <form>, next arguments are names of mandatory fields
// example of use: <form onSubmit="return form_correct('Fill-in all marked fields!', this, 'name', 'password');">
function form_correct(s, f) {
	// correctness of each field
	for (i=0; i < f.elements.length; i++) {
		if (f.elements[i].onblur != undefined && !f.elements[i].onblur()) {
			return false;
		}
	}

	// non-emptiness of selected fields
	for (i=2; i < arguments.length; i++) {
		if (f[arguments[i]].value == '') {
			return focus_alert(s, f[arguments[i]]);
		}
	}
	return true;
}

// Check if field matches ereg
// example of use: <input onBlur="return ereg_correct('Enter a date!', this, /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/);">
function ereg_correct(s, f, regexp) {
	if (f.value == '' || regexp.test(f.value)) {
		return true;
	}
	if (!focus_changing) {
		focus_changing = true;
		focus_alert(s, f);
		focus_changing = false;
	}
	return false;
}

// Check if there is a number in the field
// s is warning message, f is input field, boolean negative allows negative values, d1 is number of digits before decimal point, optional d2 is maximum count of digits after decimal point (empty - none, d1 - unlimited)
// example of use: <input onBlur="return number_correct('Enter a possitive number!', this, false, 5);">
function number_correct(s, f, negative, d1, d2) {
	f.value = f.value.replace(',', '.');
	return ereg_correct(s, f, new RegExp('^'+ (negative ? '-?' : '') +'[0-9]{0,'+ (d1 ? d1 : '') +'}'+ (d2 ? '([.][0-9]{1,'+ d2 +'})?' : '') +'$'));
}

// Check if there is an e-mail in the field, simplified!
// example of use: <input onBlur="return email_correct('Enter an e-mail!', this);">
function email_correct(s, f) {
	return ereg_correct(s, f, /^[^ @]+@[^ @]+\.[^ @]+$/);
}

// Check if there is a URL in the field, simplified!
// example of use: <input onBlur="return email_correct('Enter a URL!', this);">
function url_correct(s, f) {
	return ereg_correct(s, f, /^https?:\/\/[^ \/]+\.[^ ]+/);
}
/*
konec kontroly zadanych dat ve formulari
*/

/*
15.8.2005
Ales Dostal
funkce pro zvyrazneni radku tabulky po najeti mysi
*/
function barvaSel (id, typ)
{
    var radek = document.getElementById(id).style;
    var barva = "orange";
    if (typ == 'vyber') {
        if (radek.backgroundColor != barva) {
            radek.backgroundColor = "#CCCCFF";
        }
    } else if(typ == 'out') {
        if (radek.backgroundColor != barva) {
            radek.backgroundColor = "";
        }
    } else {
        if (radek.backgroundColor == barva) {
            radek.backgroundColor = "";
        } else {
            radek.backgroundColor = barva;
        }
    }
}

function akceZobrazeni2(odkaz, typ, kamZobrazit, query_string)
{
    var url = odkaz + ((query_string != 0) ? "?" + query_string : "");

    if (!url) {
        document.getElementById(kamZobrazit).innerHTML = "";
    } else {
        if (window.ActiveXObject) {
            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange = function () { processRequest(kamZobrazit, url); } ;
        httpRequest.send(null);
    }
    if (typ == "odkaz") {
        return false;
    }
}
function rozbalStrom (rodic, uroven, administrator, cist, stazeni, mazat, vkladat)
{
	var radek = document.getElementById(rodic).style;
	var gets = 'administrator=' + administrator + '&cist=' + cist + '&stazeni=' + stazeni + '&mazat=' + mazat + '&vkladat=' + vkladat;
	// var gets = 'administrator=' + administrator;
	if (radek.display == "none") {
		radek.display = "block";
		document.getElementById('img_' + rodic).src = "img/ikony/07.gif";
		akceZobrazeni2('./', '', rodic, 'page=157&modul=strom&uroven=' + uroven + '&rodic=' + rodic + '&' + gets);
	} else {
		radek.display = "none";
		document.getElementById('img_' + rodic).src = "img/ikony/06.gif";
	}
	return false;
}

function legendaShow(idf)
{
	var tableIn = document.getElementById(idf).style;

	if (tableIn.display == "none") {
		tableIn.display = "block";
	} else {
		tableIn.display = "none";
	}
}

