﻿//blokování klávesy ENTER
function checkKey(e)
{
    /// <summary>
    ///     xxxxx
    /// </summary>
    /// <param name="xxxxx" type="xxxxx">xxxxx</param>
    if (!e) e = window.event;
    var code; var targ;
    if (e.keyCode) code = e.keyCode
    else if (e.which) code = e.which;
    if (e.target) targ = e.target
    else if (e.srcElement) targ = e.srcElement;
	if (code == 13 && !(targ.tagName.toLowerCase() == "textarea"))
		return false;
	return true;
}
function pohonPocitadla(vstup, zobrazovac, max)
{
    /// <summary>
    ///     xxxxx
    /// </summary>
    /// <param name="xxxxx" type="xxxxx">xxxxx</param>
	var vystupniElement = document.getElementById(zobrazovac);
	var vstupniElement = document.getElementById(vstup);
	if (!vstupniElement || !vystupniElement) return;
	var pocet = max - vstupniElement.value.length;
	var jednotka = " znaků";

	if (pocet == 1 || pocet == -1)
		jednotka = " znak";
	if (pocet > 1 && pocet < 5)
		jednotka = " znaky";
	if (pocet < -1 && pocet > -5)
		jednotka = " znaky";
	vystupniElement.innerHTML = pocet + jednotka;
}
function clickButton(e, buttonid)
{
    /// <summary>
    ///     xxxxx
    /// </summary>
    /// <param name="xxxxx" type="xxxxx">xxxxx</param>
	var bt = document.getElementById(buttonid);
	if (typeof bt == 'object') {
		if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
			if (event.keyCode == 13) {
				bt.click();
				return false;
			}
		}
		else if (e.keyCode == 13) {
			bt.click();
			return false;
		}
	}
}

function getIEVersion(elementId)
{
    /// <summary>
    ///     Zobrazí v daném prvku verzi IE jako string
    /// </summary>
    /// <param name="elementId" type="string">ID prvku, v kterém se má výstup zobrazit</param>
    var output = document.getElementById(elementId);
    if (!output) return;
    if (output.value) return;

    var tridentVersion = -1;
    var ua = navigator.userAgent;
    var reIE8 = new RegExp('Trident\/([0-9]{1,}[\.0-9]{0,})');
    if (reIE8.exec(ua) != null)
    {
        tridentVersion = parseFloat(RegExp.$1);
    }
    if (tridentVersion != -1)
    {
        var bitStr = '';
        var ieStr = '';        
        if (navigator.cpuClass.indexOf('x64') != -1)
            bitStr = ' (64-bit)';
        if (tridentVersion == 4)
            ieStr = 'IE8';            
        if (tridentVersion == 5)
            ieStr = 'IE9'
        output.innerHTML = ieStr + bitStr;
    }
}
function divDisplaySwitch(elementId)
{
    /// <summary>
    ///     Vypne/Zapne zobrazení prvku na stránce (CSS display)
    /// </summary>
    /// <param name="elementId" type="string">ID přepínaného prvku</param>
    var div = document.getElementById(elementId);
    if (div.style.display == 'none')
        div.style.display = 'block';
    else
        div.style.display = 'none';
}
function currentYear()
{
    /// <summary>
    ///     Vrací současný kalendářní rok
    /// </summary>    
    var date = new Date();
    document.write(date.getFullYear());
}
function recountElementSize(elementId, wShorten, hShorten)
{
    /// <summary>
    ///     Změní velikost prvku dle okna prohlížeče, v kterém je umístěný
    /// </summary>
    /// <param name="elementId" type="string">ID prvku u něhož měníme velikost</param>
    /// <param name="wShorten" type="Number" integer="true">o kolik má být šířka prvku menší než šířka okna</param>
    /// <param name="hShorten" type="Number" integer="true">o kolik má být výška prvku menší než výška okna</param>
    // based on http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

    var element = document.getElementById(elementId);
    if (element)
    {
        var height = 0, width = 0;
        var minHeight = 200, minWidth = 200;
        if (typeof(window.innerHeight) == 'number')
        {
            //Non-IE
            width = window.innerWidth;
            height = window.innerHeight;
        }
        else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
        {
            //IE 6+ in 'standards compliant mode'
            width = document.documentElement.clientWidth;	                
            height = document.documentElement.clientHeight;
        }
        else if (document.body && (document.body.clientWidth || document.body.clientHeight))
        {
            //IE 4 compatible
            width = document.body.clientWidth;	                
            height = document.body.clientHeight;
        }
        if (width < minWidth || height < minHeight)
            return;
        if (wShorten != 0)
            element.style.width = (width - wShorten) + 'px';
        if (hShorten != 0)
            element.style.height = (height - hShorten) + 'px';
    }
}
function winClose() {
    window.close();
}
