﻿// JScript File

function windowOpen(url, name, width, height, resizable)
{
	var win = window.open(url, name, "width="+width + ", height="+height+",resizable="+ (resizable ? "yes" : "no"));
	win.focus();
	return win;
}

function windowOpenCentre(url, name, width, height)
{
	return windowOpenCentre(url, name, width, height, false);
}

function windowOpenCentre(url, name, width, height, resizable)
{
	var left = (window.screen.width-width)/2;
	var top = (window.screen.height-height)/2;
	
	var win = window.open(url, name, "width="+width + ", height="+height+",left="+left+",top="+top+", resizable="+ (resizable ? "yes" : "no"));
	win.focus();
	return win;
}

function windowOpenCascade(url, name, width, height)
{
    var minShow = 80; // v % minimalni cast okna, ktera musi byt videt
    var x = (top.screenLeft || top.screenX) + 20;
    var y = (top.screenTop || top.screenY) + 10;

    if ((screen.width - x) < (width / 100 * minShow) || (screen.height - 50 - y) < (height / 100 * minShow))
    {
        x = 20;
        y = 10;
    }
    var win = window.open(url, name, "resizable=yes,width=" + width + ", height=" + height + ",left=" + x + ",top=" + y);
    win.focus();
    return win;
}


function windowOpenMaxHeight(url, name, width) {
    var left = (window.screen.width - width) / 2;
    var height = screen.availHeight-30;
    var win = window.open(url, name, "width=" + width + ",top=0, screenY = 0, left=" + left + ", height=" + height + ", resizable=yes");
    win.focus();
    return win;
}

function windowOpenModal(url, name, width, height)
{
    windowOpenModal(url, name, width, height, false);
}

function windowOpenModal(url, name, width, height, resizable)
{
    window.showModalDialog(url, name, "scroll:no; status:no; help:no; dialogWidth=" + width + "px; dialogHeight=" + height + "px; resizable=" + (resizable ? "yes" : "no"));
}

function windowOpenModalCentre(url, name, width, height)
{
    windowOpenModalCentre(url, name, width, height, false)
}

function windowOpenModalCentre(url, name, width, height, resizable)
{
    window.showModalDialog(url, name, "scroll:no; status:no; help:no; center:yes; dialogWidth=" + width + "px; dialogHeight=" + height + "px; resizable=" + (resizable ? "yes" : "no"));
}

function windowReload()
{
	window.location.href = window.location.href;
}


function clearComboSelection(controlId)
{
	var combo = wcGetComboById(controlId);
	if (combo){
		combo.ClearSelection();
		combo.ClearSelectedValueItem();
		combo.NeedClearList = true;
		combo.IsDirty = true;
		combo.UpdateState();
	}
	return true; 
}

 function setSelected(controlId, text, val) 
 { 
	var combo = wcGetComboById(controlId);
	combo.TextObj.value = text;
	combo.Text = text; 
	combo.Value = val; 
	combo.UpdateState(); 

	return true;
}

//Obnoví okno případně okna na pozadí i v případě, že je volána z rámce.
function parentsRefresh() {
	try {
		top.location.href = top.location.href;
	}
	catch (err) { }
	try {
		top.opener.top.opener.refreshGrid();
	}
	catch (err) {
	    try {
    		top.opener.top.opener.location.href = top.opener.top.opener.location.href;
	    }
	    catch (err) { }
	}
	try {
	    top.opener.refreshGrid();
	}
	catch (err) {
	    try {
	        top.opener.location.href = top.opener.location.href;
	    }
	    catch (err) { }
	}
}

// Testuje, zda hodnota zadana v prvku (napr. textbox), je numericka.
// Vklada se do vlastnosti OnClientClick tlacitka pro ulozeni hodnot
// Parametry: ID prvku, chybova hlaska pri zadani nenumericke hodnoty
// pr. pouziti: OnClientClick="return isNumeric('txtN','Hodnota N musí být číslo.');"
function isNumeric(elementId, message) {
    var str = document.getElementById(elementId).value;
    var re = /^[0-9]+$/;  // regularni vyraz pro ciselnou hodnotu

    if (!str.match(re)) {
        alert(message);
        return false;
    }

    return true;
}


//provede nacteni formularu po padu session a znovuprihlaseni
function reloadAfterLogin()
{
    if (opener && opener.top)
    {
        opener.location = opener.location; // refresh okna, kde se o session prislo
        if (opener.top.frames.length > 0)
        {
            // refresh ramcu - hlavni okno aplikace
            var len = opener.top.frames.length
            var fr = opener.top.frames;
            for (var i = 0; i < len; i++)
            {
                if (opener == fr[i])
                    continue;

                // nerefreshuji se iframy (taby)
                // stranka, ktera se zobrazuje pri padu, nema strukturu,
                // tedy neobsahuje title
                if (!fr[i].document.title) 
                    fr[i].location = fr[i].location;
            }
        }
    }
}

// Zobrazi potvrzovaci dialog
// msg - text dialogu
// width, heigth - rozmery dialogoveho okna
// title - titulek okna
// okText, cancelText - texty na tlacitkach dialogu
// Pokud prohlizec nepodporuje modalni okna, je zobrazen stadnartni javascriptovy
// confirm, ktery vyuziva pouze prvni parametr - msg
// Dialog vraci 'ok', pokud bylo stisknuto tlacitko potrvzujici danou akci, jinak cokoliv jineho (resi i zavreni krizkem)
function ETSConfirm(msg, width, height, okText, cancelText, title) {
    if (window.showModalDialog && window.navigator.userAgent.toLowerCase().indexOf('chrome') == -1) {

        if (!width)
            width = 300;
        if (!height)
            height = 100;

        var params = new Object();
        if (msg)
            params.Message = msg;
        if (title)
            params.Title = title;
        if (okText)
            params.BtnOKText = okText;
        if (cancelText)
            params.BtnCancelText = cancelText;

        return window.showModalDialog(appRootPathPrefix + 'Confirm.htm', params, 'dialogWidth=' + width + 'px; dialogHeight=' + height + 'px; center=yes; status=no; dialogTitle=pokustitulek');
    }
    else {
        msg = msg.replace("<br />", "\n").replace("<br/>", "\n").replace("<BR />", "\n").replace("<BR/>", "\n");
        if (confirm(msg))
            return 'ok';
        else return;
    }
}

String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

