// KOMPATIBILITA

var Br = new BrCheck()

function BrCheck() {
    this.VER = navigator.appVersion;
    this.AGENT = navigator.userAgent.replace(/[\/]/g, ' ');
    this.DOM = document.getElementById ? true : false;

    this.OP5 = this.AGENT.indexOf("Opera 5") > -1 ? true : false;
    this.OP6 = this.AGENT.indexOf("Opera 6") > -1 ? true : false;
    this.OP7 = this.AGENT.indexOf("Opera 7") > -1 ? true : false;
    this.OP8 = this.AGENT.indexOf("Opera 8") > -1 ? true : false;
    this.OP = (this.OP5 || this.OP6 || this.OP7 || this.OP8);

    this.IE4 = (document.all && !this.DOM && !this.OP) ? true : false;
    this.IE5 = (this.VER.indexOf("MSIE 5") > -1 && this.DOM && !this.OP) ? true : false;
    this.IE6 = (this.VER.indexOf("MSIE 6") > -1 && this.DOM && !this.OP) ? true : false;
    this.IE7 = (this.VER.indexOf("MSIE 7") > -1 && this.DOM && !this.OP) ? true : false;
    this.IE8 = (this.VER.indexOf("MSIE 8") > -1 && this.DOM && !this.OP) ? true : false;
    this.IE = (this.IE4 || this.IE5 || this.IE6 || this.IE7 || this.IE8);

    this.NS4 = (document.layers && !this.DOM) ? true : false;
    this.NS7 = (this.DOM && parseInt(this.VER) >= 5 && this.AGENT.lastIndexOf('Netscape') < this.AGENT.lastIndexOf('7')) ? true : false;
    this.NS6 = (this.DOM && parseInt(this.VER) >= 5 && !this.NS7) ? true : false;
    this.NS = (this.NS4 || this.NS6 || this.NS7);

    return this;
}

function initModelKeySearch() {
    document.onkeyup = function (e) {
        if (e == undefined) e = window.event;

        var src = (e.target) ? e.target : e.srcElement;

        if (src.tagName.toLowerCase() != "input" && src.tagName.toLowerCase() != "textarea" && getE("modelColumn")) {
            window.clearTimeout(tmrClearModelExps);

            var keynum = 0;
            if (window.event) keynum = e.keyCode
            else if (e.which) keynum = e.which

            gsTempModelExps += String.fromCharCode(keynum).toLowerCase() + "";

            var node = null;
            for (var i = 0; i < getE("modelColumn").childNodes.length; i++) {
                node = getE("modelColumn").childNodes[i];

                if (node.title != undefined) {
                    if (node.title.substring(0, gsTempModelExps.length) == gsTempModelExps) {
                        scrollToModelRow(parseInt(node.id.substring(8, node.id.length)));
                        tmrClearModelExps = window.setTimeout(clearTempModelExps, 1000);
                        return;
                    }
                }
            }

            tmrClearModelExps = window.setTimeout(clearTempModelExps, 1000);
        }
    }
}

var gsTempModelExps = "";
var tmrClearModelExps = null;

function hideMiscDialogBox() {
    if (getE('miscDialogOK')) getE('miscDialogOK').style.display = 'none';
    return false;
}

function clearTempModelExps() {
    gsTempModelExps = "";
}

function SetElementAttribute(el, attr, val) {
    if (Br.IE && attr == "class") {
        el.className = val;
    }
    else if (attr == "onkeypress") {
        el.onkeypress = val;
    }
    else if (attr == "onclick") {
        el.onclick = val;
    }
    else if (attr == "onmousemove") {
        el.onmousemove = val;
    }
    else if (attr == "onmouseout") {
        el.onmouseout = val;
    }
    else if (Br.IE && attr == "maxlength") {
        el.maxLength = val;
    }
    else if (Br.IE && attr == "colspan") {
        el.colSpan = val;
    }
    else if (Br.IE && attr == "cellspacing") {
        el.cellSpacing = val;
    }
    else {
        el.setAttribute(attr, val);
    }
}

function CreateElement(sElName, aElAttributes, aChilds) {
    var el = document.createElement(sElName);
    for (attr in aElAttributes) {
        SetElementAttribute(el, attr, aElAttributes[attr]);
    }
    if (typeof aChilds == "Array") {
        for (var i = 0; i < aChilds.length; i++)
            el.appendChild(aChilds[i]);
    }
    return el;
}


// rebuildAndSortParams();
// 
//     function rebuildAndSortParams(sParams)
//     {
//       sParams = 'technické informaceŃHT.0551Đtechnické informaceŃWith ignition distributor cap 2.7494PHTĐtechnické informaceŃRotor 3.7573/21RSĐ';
//       
//       var aParams = sParams.split('Đ');
//       aParams.sort();
//       var sCurParam = "";
// 			var sRetval = "";
// 
//       for (var i = 0; i < aParams.length; i++) {
//         if (aParams[i].length > 0) {
//         	var aParam = aParams[i].split('Ń');
// 
// 					if (sCurParam != aParam[0]) {
// 						sRetval += aParam[0];
// 						sCurParam = aParam[0];
// 					}
// 
// 					sRetval += 'Ń' + aParam[1] + 'Đ';
//         }
//       }
// 
// 			return sRetval;
//     }

String.prototype.trim = function () { return this.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, ''); }
function getE(objectID) { return document.getElementById(objectID); }
function getF(formName) { return document.forms[formName]; }
function getTN(sValue) { if (sValue == '' || sValue == ' ') { return document.createTextNode('\u00a0'); } return document.createTextNode(sValue); }
function getCE(sElement) { return document.createElement(sElement); }
function RemoveCh(Node) { if (Node == null) return false; while (Node.childNodes.length > 0) { Node.removeChild(Node.childNodes[0]); } }
function GetSRC(e) { return (window.event) ? window.event.srcElement : e.target; }
function setE(id, attr, value) { var el = getE(id); if (el != null) { el[attr] = value; } }

function addRowToFastOrder(sentence) {

    fastOrderLastID += 1;

    var temp = "<table class='foRow' id='foRow" + fastOrderLastID + "' cellpadding='0' cellspacing='0'>" +
							"<tr>" +
							"<td class='foPLU'><input onkeypress='fastOrderKeyPress(event, \"FO_Plu\", " + fastOrderLastID + ");' id='FO_Plu" + fastOrderLastID + "' class='input_text' type='text' name='FO_Plu' maxlength='13' value='' /></td>" +
							"<td class='foCount'><input onkeypress='fastOrderKeyPress(event, \"FO_Plu\", " + fastOrderLastID + ");' id='FO_Count" + fastOrderLastID + "' class='input_text' type='text' name='FO_Count' value='1' /></td>" +
							"<td class='foOption'><img style='cursor: pointer;' onclick='getE(\"foRow" + fastOrderLastID + "\").parentNode.removeChild(getE(\"foRow" + fastOrderLastID + "\"));' src='/img/bt-clear.gif' alt='" + sentence + "' title='" + sentence + "' />" +
							"<td class='foNote'>&nbsp;</td>" +
							"</tr>" +
							"</table>"

    getE("foAdd").innerHTML += temp;
}

var lastKeyNum;
function fastOrderKeyPress(e, what, id) {
    if (window.event) {
        lastKeyNum = window.event.keyCode;
    }
    else if (e.which) {
        lastKeyNum = e.which;
    }

    if (lastKeyNum == 13) {
        if (what == "FO_Plu") {
            getE("FO_Count" + id).focus();
        }
        else {
            getE("FO_Plu" + getFastOrderNextID(id)).focus();
        }
    }
}

function getFastOrderNextID(id) {

    for (var i = ++id; i <= fastOrderLastID; i++) {
        if (getE("FO_Plu" + i)) {
            return i;
        }
    }

    addRowToFastOrder("");
    return fastOrderLastID;
}

function showMiscDialogOK(title, content, btns) {

    var oDialog = getE("miscDialogOK");
    var oTitle = getE("miscDialogOKTitle");
    var oContent = getE("miscDialogOKContent");
    var oButtons = getE("miscDialogOKButtons");

    if (!oDialog || !oTitle || !oContent || !oButtons) return;

    if (title.length != "") oTitle.innerHTML = title;
    if (btns != undefined) oButtons.innerHTML = btns;

    oContent.innerHTML = content;
    oDialog.style.display = "block";

}

function showMiscDialog(title, content, btns) {

    var oDialog = getE("miscDialog");
    var oTitle = getE("miscDialogTitle");
    var oContent = getE("miscDialogContent");
    var oButtons = getE("miscDialogButtons");

    if (!oDialog || !oTitle || !oContent || !oButtons) return;

    if (title.length != "") oTitle.innerHTML = title;
    if (btns != undefined) oButtons.innerHTML = btns;

    oContent.innerHTML = content;
    oDialog.style.display = "block";

}

function hideMiscDialog() {
    if (getE('miscDialog')) getE('miscDialog').style.display = 'none';
    return false;
}

function onFoPluKeyUp(id, e) {



}

var tmrMisc = null;

function selectedTabChanged(nIndex, kTypCode) {
    if (!getE("tab" + nIndex)) {
        LoadProductDetail(-1, kTypCode, nIndex);
    }
    else {
        for (var i = 0; i < 10; i++) {
            var tab = getE("tab" + i);
            if (tab) {
                var fold = getE("tabFold" + i);
                tab.style.display = (nIndex == i) ? "block" : "none";
                fold.className = (nIndex == i) ? "foEx foSel" : "foEx";
            }
        }
    }

    return false;
}

function selectedTabChangedInclPage(nIndex, kTypCode, nDirection, sRecord) {
    LoadProductDetailInclPage(-1, kTypCode, nIndex, nDirection, sRecord);
    return false;
}

/*------------------------------------------------------------------------------
* Naplni description v seznamu produktu a zobrazi
*/
function fillDescBubble(nIndex, obj) {
    var el = getE("descBubble");
    var elInp = getE("description_" + nIndex);
    if (el && elInp) {
        el.innerHTML = elInp.value;

        var y = getPosY(obj, getE("column2"));
        el.style.left = "50px";
        el.style.top = (y + 15) + "px";

        showDescBubble();
    }
}

/*------------------------------------------------------------------------------
* Zobrazi description v seznamu produktu
*/
function showDescBubble() {
    window.clearTimeout(tmrMisc);

    var el = getE("descBubble");
    if (el) el.style.display = "block";
}

/*------------------------------------------------------------------------------
* Zobrazi box s textem
*/
function showDescBubbleText(sText, xPos, yPos) {

    var el = getE("descBubble");
    if (el) {
        el.innerHTML = sText;

        el.style.left = (xPos) + "px";
        el.style.top = yPos + "px";

        showDescBubble();
    }

}

/*------------------------------------------------------------------------------
* Skryje description v seznamu produktu
*/
function hideDescBubble() {
    tmrMisc = window.setTimeout(function () { if (getE('descBubble')) getE('descBubble').style.display = 'none'; }, 100);
}

/*------------------------------------------------------------------------------
* Naplni poznamku v kosiku
*/
function fillDescBubbleOrder(obj, sText) {
    var el = getE("descBubble");
    if (el) {
        el.innerHTML = sText;

        var y = getPosY(obj, getE("column2"));
        var x = getPosX(obj, getE("column2"));
        el.style.left = (x + 15) + "px";
        el.style.top = (y + 15) + "px";

        showDescBubble();
    }
}

// *************************************************************************************************

var tmrDocumentsSubmenu = null;
function showDocumentsSubmenu() {
    window.clearTimeout(tmrDocumentsSubmenu);
    if (getE("uiExSubmenu")) {
        getE("uiExSubmenu").style.display = "block";
    }
}

function hideDocumentsSubmenu() {
    tmrDocumentsSubmenu = window.setTimeout(function () { getE("uiExSubmenu").style.display = "none"; }, 300)
}

var aOpenedLists = new Array(0, 0, 0, 0, 1, 1);
function openCloseList(nListID) {

    var oList = getE("userList" + nListID);
    var oListHeader = getE("userListHeader" + nListID);

    if (aOpenedLists[nListID - 1] == 1) {
        if (oList != null) oList.style.display = "none";
        if (oListHeader != null) oListHeader.className = oListHeader.className.replace("opened", "");

        aOpenedLists[nListID - 1] = 0;
    }
    else {
        if (oList != null) oList.style.display = "";
        if (oListHeader != null) oListHeader.className = oListHeader.className + " opened";

        aOpenedLists[nListID - 1] = 1;
    }

    //alert(aOpenedLists);

    saveOpenedLists();
}

function openCloseGroup(nGroupID) {

    var oGroup = getE("uclGroup" + nGroupID);
    var oGroupHeader = getE("uclGroupHeader" + nGroupID);

    var oLastGroup = getE("uclGroup" + aOpenedLists[3]);
    var oLastGroupHeader = getE("uclGroupHeader" + aOpenedLists[3]);

    if (oGroup == oLastGroup) {
        if (oGroup != null) oGroup.style.display = "none";
        if (oGroupHeader != null) oGroupHeader.className = "closed";

        aOpenedLists[3] = 0;
    }
    else {
        if (oLastGroup != null) oLastGroup.style.display = "none";
        if (oLastGroupHeader != null) oLastGroupHeader.className = "closed";

        if (oGroup != null) oGroup.style.display = "";
        if (oGroupHeader != null) oGroupHeader.className = "opened";

        aOpenedLists[3] = nGroupID;
    }

    saveOpenedLists();
}

function loadOpenedLists() {
    sOpenedLists = extractCookies("openedLists");

    if (sOpenedLists != "") {
        var aTemp = sOpenedLists.split("|");
        for (var i = 0; i < 6; i++) {
            if (aTemp[i] != null) aOpenedLists[i] = aTemp[i];
        }
    }
}

function saveOpenedLists() {

    sOpenedLists = "";
    for (var i = 0; i < 6; i++) {
        sOpenedLists += ((sOpenedLists == "") ? "" : "|") + aOpenedLists[i];
    }

    insertCookies("openedLists", sOpenedLists);
}

function extractCookies(sName) {
    var aCookieList = document.cookie.split(";");
    var aCookieArray = new Array();
    var aTemp = "#"
    for (var i = 0; i < aCookieList.length; i++) {
        if (aCookieList[i].indexOf(sName) > -1) {
            if (aCookieList[i].indexOf("=") > -1) { aTemp = aCookieList[i].split("="); }
        }
    }

    if (aTemp != "#") {
        return unescape(aTemp[1]);
    }
    else {
        return "";
    }
}

function insertCookies(sName, sData) {
    var dVyprs = new Date();
    dVyprs.setDate(dVyprs.getDate() - 365);
    document.cookie = sName + "=" + sData + "; expires=" + dVyprs.toGMTString() + "; path=\/;";
    dVyprs.setDate(365 + 365 + dVyprs.getDate());
    document.cookie = sName + "=" + sData + "; expires=" + dVyprs.toGMTString() + "; path=\/;";
}

function showCalendarEx(oid, x, y, gli) {
    var cal = document.getElementById('divcal');
    var calframe = document.getElementById('diviframcal');
    var tbox = document.getElementById(oid);
    var ssrc = '/Includes/Calendar_INC.asp?el=' + oid + '&selDate=' + tbox.value + "&gli=" + gli;
    cal.style.position = "absolute";
    if (y == 0)
        cal.style.top = (getPosY(tbox) + 18) + 'px';
    else
        cal.style.top = y + "px";
    if (x == 0)
        cal.style.left = (getPosX(tbox)) + 'px';
    else
        cal.style.left = x + "px";
    calframe.src = ssrc;
    cal.style.display = 'block';
}


function getPosX(obj, objTo) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent || obj.offsetParent == objTo)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function getPosY(obj, objTo) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent || obj.offsetParent == objTo)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function SelectHide(sStyle) {
    SelectHideEx(sStyle, document);
    for (var i = 0; i < window.frames.length; i++) {
        SelectHideEx(sStyle, window.frames[i].document);
    }
}

function SelectHideEx(sStyle, odocument) {
    var o;
    o = odocument.getElementsByTagName("select");
    if (o != null) {
        if (o.tagName == 'SELECT') {
            if (SelectExcept(o)) o.style.visibility = sStyle;
        } else {
            for (var i = 0; i < o.length; i++) {
                if (SelectExcept(o[i])) o[i].style.visibility = sStyle;
            }
        }
    }
}

function SelectExcept(o) {
    return !((o.id == "AMenu1") || (o.id == "TabMenu1") || (o.id == "TabMenu5") || (o.id == "TabMenu6") || (o.id == "CellMenu1") || (o.id == "CellMenu2") || (o.id == "ImgMenu1"));
}

function controlNumber(e, allowComma) {

    var keynum
    var keychar
    var numcheck

    if (allowComma == undefined) allowComma = false;

    if (window.event) {
        keynum = e.keyCode
    }
    else if (e.which) {
        keynum = e.which
    }
    return ((keynum >= 48) && (keynum <= 57)) || keynum == 8 || keynum == 13 || (Br.NS && e.charCode == 0) || (allowComma && (keynum == 44 || keynum == 46))
}

function selDetailTab(tab, max) {
    for (var i = 1; i <= max; i++) {
        el = document.getElementById('foEx' + i);
        elI = document.getElementById('fo' + i);

        if (el && elI) {
            if (tab == i && el.className == "foEx") {
                el.className = "foEx foSel";
                elI.style.display = '';
            } else if (tab != i && el.className == "foEx foSel") {
                el.className = "foEx"
                elI.style.display = 'none';
            }
        }
    }
}
function trim(str) { return str.replace(/^\s*|\s*$/g, ""); }

function scrollToModelRow(nRowNr) {

    var c = getE("modelColumn");
    var r = getE("modelRow" + nRowNr);

    if (c && r) {
        var height = 0;
        for (var i = 0; i < nRowNr; i++) {
            if (getE("modelRow" + i)) height += getE("modelRow" + i).offsetHeight;
        }
        c.scrollTop = height;
        if (c.offsetHeight >= c.scrollHeight)
            if (getE("modelSelected")) getE("modelSelected").style.paddingRight = "3px";
    }
}

function scrollToMotorRow(nRowNr) {

    var c = getE("motorColumn");
    var r = getE("motorRow" + nRowNr);

    if (c && r) {
        var height = 0;
        for (var i = 0; i < nRowNr; i++) {
            if (getE("motorRow" + i)) height += getE("motorRow" + i).offsetHeight;
        }
        c.scrollTop = height;
        if (c.offsetHeight >= c.scrollHeight)
            if (getE("motorSelected")) getE("motorSelected").style.paddingRight = "3px";
    }
}

function getNewHttpObject() {
    var objType = false;
    try {
        objType = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e) {
        try {
            objType = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (e) {
            objType = new XMLHttpRequest();
        }
    }

    return objType;
}

var aOpenedCats = new Array(0, 0, 0, 0, 0, 0);
function closeCats(nLevel) {
    for (var i = 5; i >= nLevel; i--) {
        if (getE("catList" + aOpenedCats[i])) getE("catList" + aOpenedCats[i]).style.display = "none";
        if (getE("catImage" + aOpenedCats[i])) getE("catImage" + aOpenedCats[i]).src = "/img/tree-plus.gif";
        aOpenedCats[i] = 0;
    }
}

function catClicked(nCat, nSort, sLasts, nIco, nUni, nLevel, sKTyp) {

    var eItem = getE("cat" + nCat);
    var eList = getE("catList" + nCat);
    var eImage = getE("catImage" + nCat);

    if (eList) {
        //
        // Je nacteno, jen otvirame/zavirame
        //
        if (eList.style.display == "none") {
            closeCats(nLevel);
            eList.style.display = "block";
            if (eImage) eImage.src = "/img/tree-minus.gif";
            aOpenedCats[nLevel] = nCat;
        }
    }
    else if (eItem) {
        //
        // Neni nacteno, nacitame
        //
        closeCats(nLevel);

        var theHttpRequest = getNewHttpObject();
        theHttpRequest.onreadystatechange = function () { processAJAX(); };
        theHttpRequest.open("get", "/includes/ajax_Sortiment.asp?a=getCatChilds&cat=" + nCat + "&sort=" + nSort + "&lasts=" + sLasts + "&ico=" + nIco + "&uni=" + nUni + "&sktyp=" + sKTyp);
        theHttpRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
        theHttpRequest.send(null);
    }

    function processAJAX() {
        if (theHttpRequest.readyState == 4) {
            eItem.innerHTML += theHttpRequest.responseText;
            if (getE("catImage" + nCat)) getE("catImage" + nCat).src = "/img/tree-minus.gif";
            aOpenedCats[nLevel] = nCat;
        }
    }
}

function catDetailClicked(nCat, nSort, sLasts, nIco, nUni, nLevel, sKTyp) {

    var eItem = getE("cat" + nCat);
    var eList = getE("catList" + nCat);
    //var eImage = getE("catImage" + nCat);
    $('.FPL').removeClass('act');
    eItem.className = "FPL act";
    if (eList) {
        //
        // Je nacteno, jen otvirame/zavirame
        //
        if (eList.style.display == "none") {
            closeCats(nLevel);
            eList.style.display = "block";
            //if (eImage) eImage.src = "/img/tree-minus.gif";
            aOpenedCats[nLevel] = nCat;
        }
    }
    else if (eItem) {
        //
        // Neni nacteno, nacitame
        //
        closeCats(nLevel);

        var theHttpRequest = getNewHttpObject();
        theHttpRequest.onreadystatechange = function () { processAJAX(); };
        theHttpRequest.open("get", "/includes/ajax_Sortiment.asp?a=getDetailCatChilds&cat=" + nCat + "&sort=" + nSort + "&lasts=" + sLasts + "&ico=" + nIco + "&uni=" + nUni + "&sktyp=" + sKTyp);
        theHttpRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
        theHttpRequest.send(null);
    }

    function processAJAX() {
        if (theHttpRequest.readyState == 4) {
            //eItem.innerHTML += theHttpRequest.responseText;
            $("#cat" + nCat).after(theHttpRequest.responseText);
            //if (getE("catImage" + nCat)) getE("catImage" + nCat).src = "/img/tree-minus.gif";
            aOpenedCats[nLevel] = nCat;
        }
    }
}

function EmailControl(sEmail) {
    var regEx = new RegExp("^[_a-zA-Z0-9\.\-]+@(([_a-zA-Z0-9\-]{1,}\.){1,})+\.[a-zA-Z]{2,}$");

    regEx.ignoreCase = true;

    return regEx.test(sEmail);
}

function Bookmark(url, title) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else if (document.all) {
        window.external.AddFavorite(url, title);
    }
    else {
        return true;
    }
}

var fadeInOut;
function fadeInObject(objID, speed, opacity) { // fce necha plynule zobrazit libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
    window.clearTimeout(fadeInOut);
    var obj = getE(objID);
    if (!(opacity > 0)) opacity = 0;
    if (!(speed > 0)) speed = 5;
    opacity += speed;
    if (Br.IE) {
        obj.style.filter = 'alpha(Opacity=' + opacity + ')';
        if (opacity < 100) { fade = setTimeout("fadeInObject('" + objID + "'," + speed + "," + opacity + ");", 0) } else { obj.style.filter = '' }
    } else if (Br.NS) {
        obj.style.MozOpacity = opacity / 100;
        if (opacity < 100) { fade = setTimeout("fadeInObject('" + objID + "'," + speed + "," + opacity + ");", 0) } else { obj.style.MozOpacity = 1; }
    }
    if (obj.style.display != 'block') obj.style.display = 'block';
}
function fadeOutObject(objID, speed, opacity) { // fce necha plynule zmiznout libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
    window.clearTimeout(fadeInOut);
    var obj = getE(objID);
    if (Br.OP) { obj.style.display = 'none'; return; }
    if (!(opacity > 0)) opacity = 100;
    if (!(speed > 0)) speed = 5;
    opacity -= speed;
    if (Br.IE) {
        obj.style.filter = 'alpha(Opacity=' + opacity + ')';
        if (opacity > 0) { fade = setTimeout("fadeOutObject('" + objID + "'," + speed + "," + opacity + ");", 0) } else { obj.style.display = 'none'; obj.style.filter = ''; }
    } else if (Br.NS) {
        obj.style.MozOpacity = opacity / 100;
        if (opacity > 0) { fade = setTimeout("fadeOutObject('" + objID + "'," + speed + "," + opacity + ");", 0) } else { obj.style.display = 'none'; obj.style.MozOpacity = 1; }
    }
}

// function checkStoreCount(code, storeCount) {
// 
// 	var count = parseInt(getE("count_1_" + code).value);
// 	var el = getE("dorequest_1_" + code);
// 
// 	if (count > storeCount) {
// 		if (confirm("Objednáváte více, než je na skladě.\n\nChcete skutečně objednat i nedostupné množství?")) el.value = 1;
// 	}
// }
// 
// // status, args nechany z duvodu kompatibility
// function showMyModalDialog(url,title,sizeX,sizeY,status,args,top) //top znaci jak daleko od vrchu okna
//                                                                   // default je 50px (ve stylech)
// {
//    var wo = document;
//    var frameID = '';
//    if(window!=window.top){
//       wo = window.top.document;
//       frameID = window.self.name;
//    }
//    
//    if(getE('modalIframe')){return;}
//    //if(Br.IE){SelectHide('hidden');}
//     
//    if(Br.IE6)
//    {
//    		var clona = wo.createElement('iframe');
// 	    clona.id='clona';
// 	    clona.src = '/administration/clonaIE6.htm';
//    		wo.body.appendChild(clona);
//    }
//    else
//    {
//    		var div=wo.createElement('div');
// 	    div.id='clona';
//    		wo.body.appendChild(div);
//    }
//    
//     
//    var clona=wo.createElement('div');
//    clona.id='clona1'; // margin nelze pouzit, bug v IE
// 
//    url += ((url.indexOf("?")>-1)?"&":"?") +"title="+ title+"&frameID="+ frameID;
//    
//    clona.innerHTML="<iframe name='modalIframe' id='modalIframe' width='"+sizeX+"' height='"+sizeY+"' frameborder='0' scrolling='auto' src='"+ url +"'></iframe>";
//     
//    wo.body.appendChild(clona);
//    if(top!==undefined){
//       wo.getElementById('modalIframe').style.top=top;
//    }
// }
//  
// 
// function prmtest(id, value) {
// params_1.newValueReturn(id, value); }
// function CloseMyModalDialog(){
// 
// 	if(window.top.document.getElementById('clona1') && window.top.document.getElementById('clona'))
// 	{ 
//     window.top.document.body.removeChild(getE('clona1'));
//     window.top.document.body.removeChild(getE('clona'));
//     //if(Br.IE){SelectHide('visible');}
//     }
// }
// 
// 
// 
// function SetDSP(nDSP, sURL) {
// 	var vyprs=new Date();
// 	vyprs.setDate(vyprs.getDate() + 14);
// 
// 	if (nDSP==1) 
// 	{
// 		document.cookie="DSP=1; expires="+vyprs.toGMTString()+";path=\/;";
// 	} 
// 	else 
// 	{
// 		document.cookie="DSP=0; expires="+vyprs.toGMTString()+";path=\/;";
// 	}
// 	if (getE('RedirOnListCagChange')!=null) window.location.href=sURL;
// }
// 
// 
// 
// // ###   FCE PRO DIALOG ZADANI VOLITELNYCH PARAMETRU   ###
// var gsFormSuffix, gsFormIndex;
// 
// function BuyOrSetVariableParams(sFormSuffix,sFormIndex) {
// 	var sSelects, nWindowHeight;
// 	gsFormIndex = sFormIndex;
// 	gsFormSuffix = sFormSuffix;
// 
// 	sSelects = getE("DivForPars" + sFormSuffix + sFormIndex).innerHTML;
// 	// ve skeletu musí být ve fci GetFormattedParams "ParamItem" psáno CASE-SENSITIVE !!!
// 	if (sSelects == "") {
// 		getF("BuyForm" + sFormSuffix + sFormIndex).submit();
// 	} else {
// 		// 22 je výška selectu - definováno raději i podle stylu!
// 		// nWindowHeight = 86 + 22 * (sSelects.split("ParamItem").length);
// 		getE('DivForParams').innerHTML = getE("DivForPars" + sFormSuffix + sFormIndex).innerHTML;
// 		getE('ParamCaption').innerHTML = getE("BuyForm" + sFormSuffix + sFormIndex).NameItem.value;
// 		getE('ParamTbl').style.top =  window.event.srcElement.offsetTop + 20;
// 		getE('ParamTbl').style.left =  window.event.srcElement.offsetLeft - 60;
// 		getE('ParamTbl').style.display = 'inline';
// 	}
// }
// 
// 
// 
// 
// 
// // SELECT on/off
// 
// 
// // ###   FCE PRO PriceList ###
// 
// function SHModalDlgPricelist()
// {
// 	var strReturn = showModalDialog("/Includes/EmailPricelist.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=320px;dialogHeight=124px;");
//     if (strReturn == "") return;
// 	document.location.href = "/EmailPricelist.asp?EmailPricelist=" + strReturn;
// }
// 
// // ##########
// 
// 
// 
// function InsertCookies(strName,strData){
// 	var vyprs=new Date();
// 	vyprs.setDate(vyprs.getDate() - 365);
// 	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+"; path=\/;";
// 	vyprs.setDate(365 + 365 + vyprs.getDate());
// 	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+"; path=\/;";
// }
// 
// 
// /***************************************************************************/
// /***************************************************************************/
// 	
// function ExtractCookies_simple(strName){
// 	var cookieList=document.cookie.split("; ");
// 	var cookieArray = new Array();
// 	var name = "#"
// 	for (var i=0; i < cookieList.length; i++){
// 		if(cookieList[i].indexOf(strName+'=')==0){
// 			return cookieList[i].substr(cookieList[i].search('=')+1);
// 		}
// 	}
// 	return "";
// }
// 
// /***************************************************************************/
// /***************************************************************************/
// 
// function FormatNumber(text){
// 	var mezi = BarterComma(text);
// 	mezi = ''+Math.round(parseFloat(mezi) * 100);
// 	var desetiny = mezi.substring(mezi.length-2, mezi.length);
// 	var cele = mezi.substring(0,mezi.length-2);
// 	if (parseFloat(mezi) < 1){
// 	        var mezi = "0."+desetiny;
// 	}else{
// 	        var mezi = cele+"."+desetiny;
// 	}
// 	return mezi;
// }
// function FormatFloat(nNumber,nDecimal){
// 	var sNumber = BarterComma(nNumber);
// 	sNumber = ''+Math.round(parseFloat(sNumber) * Math.pow(10,nDecimal));
// 	var sDedimal = sNumber.substring(sNumber.length-nDecimal, sNumber.length);
// 	var nInt = sNumber.substring(0,sNumber.length-nDecimal);
// 	if (parseFloat(sNumber) < 1){
// 	        var sNumber = "0."+sDedimal;
// 	}else{
// 	        var sNumber = nInt+"."+sDedimal;
// 	}
// 	return sNumber;
// }
// 
// function FormatCurrency(nNumber,nDecimal){
// 	var sCurrency, iInsertSpace;
// 	sCurrency = FormatFloat(nNumber, nDecimal).replace('.',',');
// 	iInsertSpace = sCurrency.indexOf(',') - 3;
// 	while (iInsertSpace>0) {
// 		sCurrency = sCurrency.substring(0,iInsertSpace) + ' ' + sCurrency.substring(iInsertSpace,sCurrency.length);
// 		iInsertSpace -= 3;
// 	}
// 	if (nDecimal==0) sCurrency = sCurrency.substring(0,sCurrency.indexOf(","));
// 	return sCurrency;
// }
// 
// function FUCJS(nNumber, nDecimal, bCurrSymbol) {
// 	var sCurrency;
// 	nDecimal = (nDecimal > 0) ? nDecimal : gbCurrencyDigitsAfterDecimalSeparator;
// 	if (parseFloat(nNumber))
// 		sCurrency = FormatCurrency(nNumber, nDecimal);
// 	else
// 		sCurrency = "0";
// 	sCurrency = sCurrency.replace(" ", gbCurrencyThousandSeparator);
// 	sCurrency = sCurrency.replace(",", gbCurrencyDecimalSeparator);
// 	
// 	if (nDecimal == 0) sCurrency = sCurrency + gbCurrencySuffixNotDecimal;
// 	
// 	if (bCurrSymbol) {
// 		if (gbCurrencyBeforeAmount)
// 			sCurrency = "<small>" + gbCurrencyName + "</small>&nbsp;" + sCurrency;
// 		else
// 			sCurrency = sCurrency + "&nbsp;<small>" + gbCurrencyName + "</small>";
// 	}
// 	return sCurrency;
// }
// 
// function BarterComma(text){
// 	var mezi = ''+text;
// 	if (mezi.indexOf(',') != -1){
// 		mezi = mezi.split(",");
// 		mezi = mezi[0]+"."+mezi[1];
// 	}else{
// 		mezi = text;
// 	}
// 	return parseFloat(mezi);
// }
// 
function controlMaxNumber(value, nMax, obj) {
    if (value > nMax && value >= 1) {
        alert("Číslo stránky musí být v rozmezí od 1 - " + nMax);
        return false;
    } else {
        if (obj.action.indexOf('pg-0') != -1) obj.action = obj.action.replace(/pg-0/, 'pg-' + value)
        else if (obj.action.indexOf('PgID=0') != -1) obj.action = obj.action.replace(/PgID=0/, 'PgID=' + value)
        return true;
    }
}

// 
// function ControlFloat(){
// 	if (!Br.IE) return;
// 	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode !=46) && (event.keyCode !=44)) event.returnValue = false;
// }
// 
// 
// function ControlPhone() {
// 	if (!Br.IE) return;
//     if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32)  && (event.keyCode!=40) && (event.keyCode!=41) && (event.keyCode!=43))
// 		event.returnValue = false;
// }
// function ControlPSC() {
// 	if (!Br.IE) return;
//     if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32) && (event.keyCode != 45))
// 		event.returnValue = false;
// }
// 
// function ShowSearchMenu(x){
//     if (x == 1){
//         getE('Searchtable').style.display='';
//     }else{
//         getE('Searchtable').style.display='none';
//     }
// }
// 
// function ValidateAccount(sAccount) {
// 	var u1,u2,t1,t2,i;
// 	var vahy = new Array("1","2","4","8","5","10","9","7","3","6")
// 	u1 = sAccount.substring(0,sAccount.length - 10);
// 	u2 = sAccount.substring(sAccount.length - 10,12);
// 	t1 = 0;t2 = 0;
// 	for(i=u1.length ;i>0;i--) {
// 		t1 += u1.charAt(i - 1)*vahy[10 - i];
// 	}	  
// 	for(i=u2.length ;i>0;i--) {
// 		t2 += u2.charAt(i - 1)*vahy[10 - i];
// 	}
// 	if (((t2%11) == 0)&&((t1%11 == 0))) {
// 		return true;
// 	} else {
// 		return false;
// 	}
// }
// 
// // ##### PriceList BEEND #######################################################
// function PutCategoriesIdNameToSelect(saCatIdName, nIndex, bStart) {
// 	var arrData, arrSubData, saCatID, el;
// 	arrData = saCatIdName.split("*");
// 	saCatID = "";
// 	for (var i=0; i<arrData.length-1; i++) {
// 	    arrSubData = arrData[i].split("/")
// 		el = document.createElement("OPTION")
// 	    el.value = arrSubData[0];
// 	    el.text = arrSubData[1];
// 		saCatID += arrSubData[0] + "$"
// 		if (bStart==true) {
// 			if (i==0) {
// 				el.text='-Všechny kategorie-';
// 				document.PL['Categ'+nIndex].options.add(el);
// 			}
// 		} else
// 		    document.PL['Categ'+nIndex].options.add(el);
// 	}
// 		
// 	document.PL['CatID' + nIndex].value = saCatID.substr(0,saCatID.length - 1);
// 	if (saCatIdName == "") {
// 		document.PL['Categ'+nIndex].style.display = "none";
// 		getE("ChooseCateg"+nIndex).style.display  = "inline";
// 	} else {
// 		document.PL['Categ'+nIndex].style.display = "inline";
// 		getE("ChooseCateg"+nIndex).style.display  = "none";
// 	}
// }
// 
// function GetCategoriesIdNameForSelect(nTree,bAlsoDisabled,nIndex,nUserType) {
// 	var saCatID,nProID,sProNM;
// 	var r;
// 	
// 	nProID = document.PL['ProdID'+nIndex].value;
// 	
// 	sProNM = document.PL['ProdID'+nIndex].options[document.PL['ProdID'+nIndex].selectedIndex].innerHTML
// 	saCatID = document.PL['CatID' + nIndex].value;
// 	if(Br.IE){
// 		var strReturn = showModalDialog("/Includes/PriceListSelectCatsOfProd.asp?TREE="+nTree+"&ProID="+nProID+"&DIS="+bAlsoDisabled+"&CatIDs="+saCatID+"&ADM="+nUserType+"&ProNM="+sProNM,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=470px;dialogHeight=450px");
// 		if (typeof(strReturn) == 'undefined') return;
// 		with(getE("Categ"+nIndex)){
// 			r = options.length;
// 	       		for (var i=0; i<r; i++) {
// 	               		options.remove(options.length-1);
// 	       		}
// 		}
// 		PutCategoriesIdNameToSelect(strReturn, nIndex, false);
// 	}else{
// 		window.open("/Includes/PriceListSelectCatsOfProd.asp?TREE="+nTree+"&ProID="+nProID+"&DIS="+bAlsoDisabled+"&CatIDs="+saCatID+"&ADM="+nUserType+"&ProNM="+sProNM+"&nIndex="+nIndex,"okno","toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=470,height=450,left=0,top=0");
// 	}
// 	
// }
// function ClearCategories(nIndex) {
// 
// 	while(document.PL['Categ'+nIndex].length>0) {
// 		document.PL['Categ'+nIndex].options[0] = null;	
// 		}
// 	
// 	document.PL['CatID' + nIndex].value = "";
// 	document.PL['Categ'+nIndex].style.display = "none";
// 	getE("ChooseCateg"+nIndex).style.display  = "inline";
// }
// 
// // ##### PriceList END #####
// 
// function ShowImage(sImgPath, GLI) {
// 		window.open('/ShowImage.asp?IMG=' + sImgPath + '&gli=' + GLI, "Foto","scrollbars=0,status=0,toolbar=0,location=0,directories=0,height=100,width=100,resizable=1");
// }
// 
// function ShowHide(element) {
// 	var e = getE( element );
// 	if (e.style.display=="none") {
// 		if (!Br.OP) SelectHide('hidden');
// 		e.style.display = "" }
// 	else {
// 		if (!Br.OP) SelectHide('visible');
// 		e.style.display = "none" };
// //	if (!Br.IE) this.blur(); //aby nam nezustaval v mozile oznacen klikaci text
// }
// 
// function styleChange(elementId,classNameStr) {	var e = getE( elementId );	e.className = classNameStr;}
// 
// function hideAvaibilityDialog() {
// 	var e = getE( "avaibilitybox" );
// 	e.style.display = "none";
// //	var e = getE( "avaibilitybox" );
// //	e.style.display = "none";
// }
// 
// 
// 
// 
// /* positions */
// 
// function topScroll() {
// 	if (window.innerHeight) {
// 		  return ( window.pageYOffset )
// 	} else if (document.documentElement && document.documentElement.scrollTop) {
// 		return ( document.documentElement.scrollTop )
// 	} else if (document.body) {
// 		  return ( document.body.scrollTop )
// 	}
// }
// 
// // specialitky
// 
// var fadeInOut;
// function fadeInObject ( objID, speed, opacity ) { // fce necha plynule zobrazit libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
// 	window.clearTimeout(fadeInOut);
// 	var obj = getE(objID);
// 	if (!(opacity>0)) opacity = 0;
// 	if (!(speed>0)) speed = 25;
// 	opacity+=speed;
// 	if (Br.IE) {
// 		obj.style.filter = 'alpha(Opacity='+opacity+')';
// 		if (opacity<100) { fade=setTimeout("fadeInObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.filter='' }
// 	} else if (Br.NS) {
// 		obj.style.MozOpacity = opacity/100;
// 		if (opacity<100) { fade=setTimeout("fadeInObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.MozOpacity=1; }
// 	}
// 	if (obj.style.display=='none') obj.style.display='block';
// }
// function fadeOutObject ( objID, speed, opacity ) { // fce necha plynule zmiznout libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
// 	window.clearTimeout(fadeInOut);
// 	var obj = getE(objID);
// 	if (!(opacity>0)) opacity = 100;
// 	if (!(speed>0)) speed = 5;
// 	opacity-=speed;
// 	if (Br.IE) {
// 		obj.style.filter = 'alpha(Opacity='+opacity+')';
// 		if (opacity>0) { fade=setTimeout("fadeOutObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.display='none'; obj.style.filter=''; }
// 	} else if (Br.NS) {
// 		obj.style.MozOpacity = opacity/100;
// 		if (opacity>0) { fade=setTimeout("fadeOutObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.display='none'; obj.style.MozOpacity=1; }
// 	}
// 	if (obj.style.display=='block') obj.style.display='none';
// }
// 
// 
// // AvaibilityBox - Avaibility Dialog
// function showAvaibilityDialog( code, posX, posY ) {
// 	var e = getE( "avaibilitybox" );
// 	e.style.display = "";
// 	getE('sCode2').innerHTML = code;
// 	getE('sInfo').innerHTML = "Zjišťuje se...";
// 	getE('avaibilityFrame').src = "/Avaibility.asp?sCode=" + code ;
// }
// function hideAvaibilityDialog() {
// 	var e = getE( "avaibilitybox" );
// 	e.style.display = "none";
// //	var e = getE( "avaibilitybox" );
// //	e.style.display = "none";
// }
// 
// // ShopInfoBox
// 
// function showShopInfoDialog() {
// 	clearTimeout;
// 	if (!Br.OP) SelectHide('hidden');
// 	var e = getE( "shopinfobox" );
// 	fadeInObject ( "shopinfobox", 0 );
// 	e.style.position = "absolute";
// 	e.style.top = topScroll() + 200+'px';
// 	e.style.left = (document.body.clientWidth/2 - 100)+'px';
// 	setTimeout("hideShopInfoboxDialog();", 20000);
// }
// 
// function hideShopInfoboxDialog() {
// 	var e = getE( "shopinfobox" );
// 	fadeOutObject ( "shopinfobox", 10 );
// 	clearTimeout;
// 	if (!Br.OP) SelectHide('visible');
// }
// 
// function showShopConfirmDialog() {
// 	clearTimeout;
// 	
// 	hideShopInfoboxDialog();
// 	if (Br.IE) {
// 		if (getE('sortingSelector')) getE('sortingSelector').style.visibility='hidden';
// 		if (getE('producerSelector')) getE('producerSelector').style.visibility='hidden';
// 	}
// 	var e = getE( "shopconfirmbox" );
// 	
// 	e.style.position = "absolute";
// 	e.style.top = topScroll() + 300+'px';
// 	e.style.left = (document.body.clientWidth/2 - 210)+'px';
// 	fadeInObject ( "shopconfirmbox", 0 );
// 	if (getE('boxformcount')) getE('boxformcount').focus();
// }
// 
// function hideShopConfirmDialog() {
// 	if (getE('itemsOnPageSelect')) { getE('itemsOnPageSelect').style.visibility='visible'; }
// 	if (getE('sortingSelector')) getE('sortingSelector').style.visibility='visible';
// 	if (getE('producerSelector')) getE('producerSelector').style.visibility='visible';
// 	var e = getE( "shopconfirmbox" );
// 	fadeOutObject ( "shopconfirmbox", 10 );
// }
// 
// function GetBuy(frm,sAction,sTarget) {
//     getE( "shopinfobox").style.display='none';
// 	frm.action = sAction;
// 	frm.target = sTarget;
// 	frm.elements.AUO.value = '';
// 	frm.submit();
// }
// 
// function GetBuyDetail(frm,sAction,sTarget, idPNC) {
// 
//     if (getE('ParamItemdetail'))     getE('ParamItemdetail').value = idPNC;
//     if (getE('countdetail'))         getE('countdetail').value     = getE('Count_' + idPNC).value;
//     getE( "shopinfobox").style.display='none';
// 	frm.action = sAction;
// 	frm.target = sTarget;
// 	frm.elements.AUO.value = 'ok';
// 	frm.submit();
// }
// 
// 
// /* hover images in commodity list */
// var bHoverName = 0, bHoverImage = 0, nLastImageId = 0; // jestli mame mys nad nazvem a obrazkem
// function hideHoverImage( hoverWhat, idImage ) {
// 	if (hoverWhat==1) bHoverName = 0;
// 	if (hoverWhat==2) bHoverImage = 0;
// 	setTimeout("if (bHoverName==0 & bHoverImage==0) getE('hover_"+idImage+"').style.display='none';", 500); //getE('hover_'+idImage).style.display='none';
// }
// 
// function showHoverImage( hoverWhat, idImage ) {
// 	clearTimeout;
// 	if (idImage!=nLastImageId) { 
// 		bHoverName = 0; 
// 		bHoverImage = 0; 
// 		if (getE('hover_'+nLastImageId)) getE('hover_'+nLastImageId).style.display='none';
// 	}
// 	if (hoverWhat==1) bHoverName = 1;
// 	if (hoverWhat==2) bHoverImage = 1;
// 	nLastImageId = idImage;
// 	getE('hover_'+idImage).style.display='block';
// }
// 
// function checkCount( myCount, minCount, sUnit, onlyMultiplied ) {
// 	myCount = parseInt(myCount.replace(",","."));
// 	minCount = parseInt(minCount.replace(",","."));
// 	if ( myCount == 0 ) return true;
// 	
// 	if ( myCount < minCount ) {
// 		alert('Toto zboží lze objednat v minimálním počtu '+minCount+' '+sUnit+'.'); return false;
// 	}
// 	if ( (onlyMultiplied==1) && ( (myCount*10) % (minCount*10) != 0) ) {
// 		alert('Toto zboží lze zakoupit pouze v násobcích '+minCount+' '+sUnit+'.'); return false;
// 	}
// 	return true;
// }
// 
// function GoToPage(nPage, sParam) {  document.location.href = '?pgID=' + nPage + sParam;}
// 
// function ShowCalendar(oid)
//  {
//   var cal = document.getElementById('divcal');
//   var calframe = document.getElementById('diviframcal');
//   var tbox = document.getElementById(oid);
//   var ssrc = '/Includes/Calendar_INC.asp?el=' + oid + '&selDate=' + tbox.value;
//   
//   cal.style.top = tbox.offsetTop + tbox.offsetHeight;
//   cal.style.left = tbox.offsetLeft;
//   
//   calframe.src = ssrc;
//   cal.style.display = 'block';
//  }
//  
// function Bookmark(url,title){
// 	if (window.sidebar){
// 		window.sidebar.addPanel(title, url,"");
// 	}
// 	else if( document.all){
// 		window.external.AddFavorite(url, title);
// 	}
// 	else{
// 		return true;
// 	}
// }
//  
// 
// function changeProducers(divId)
// {
//     for (var i=1;i<=5;i++)
//     {
//         getE("prod"+i).className="foldEx";
//         getE("prodList"+i).style.display="none";
//     }
//     getE("prod"+divId).className="foldEx selFo";
//     getE("prodList"+divId).style.display="block";
// }
// 
// function showHideDodAdr(bShow)
// {
//     if (bShow==1)
//     {
//         getE("dodAdr0").style.display = "block";
//         getE("dodAdr1").style.display = "block";
//         getE("dodAdr2").style.display = "block";
//     }
//     else
//     {
//         getE("dodAdr0").style.display = "none";
//         getE("dodAdr1").style.display = "none";
//         getE("dodAdr2").style.display = "none";
//     }
// }
// 
// function addBookmark() 
// {
//     var sTitle, sUrl;
//   
//     sTitle = document.title;
//     sUrl  = document.location.href 
//     
//     if (window.sidebar) 
//     { 
//             window.sidebar.addPanel(sTitle, sUrl,""); 
//     } 
//     else if ( document.all ) 
//     {
//             window.external.AddFavorite( sUrl, sTitle);
//     } 
//     else if ( window.opera && window.print ) 
//     {
//             return true;
//     }
// }
// 
// function ShowImageDetail(sImgPath,sID) {
// 		getE(sID).src = sImgPath;
// 
// }
// 
// function extractNumber(obj, decimalPlaces, allowNegative)
// {
// 	var temp = obj.value;
// 	
// 	// avoid changing things if already formatted correctly
// 	var reg0Str = '[0-9]*';
// 	if (decimalPlaces > 0) {
// 		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
// 	} else if (decimalPlaces < 0) {
// 		reg0Str += '\\.?[0-9]*';
// 	}
// 	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
// 	reg0Str = reg0Str + '$';
// 	var reg0 = new RegExp(reg0Str);
// 	if (reg0.test(temp)) return true;
// 
// 	// first replace all non numbers
// 	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
// 	var reg1 = new RegExp(reg1Str, 'g');
// 	temp = temp.replace(reg1, '');
// 
// 	if (allowNegative) {
// 		// replace extra negative
// 		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
// 		var reg2 = /-/g;
// 		temp = temp.replace(reg2, '');
// 		if (hasNegative) temp = '-' + temp;
// 	}
// 	
// 	if (decimalPlaces != 0) {
// 		var reg3 = /\./g;
// 		var reg3Array = reg3.exec(temp);
// 		if (reg3Array != null) {
// 			// keep only first occurrence of .
// 			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
// 			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
// 			reg3Right = reg3Right.replace(reg3, '');
// 			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
// 			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
// 		}
// 	}
// 	
// 	obj.value = temp;
// }
// 
// function blockNonNumbers(obj, e, allowDecimal, allowNegative)
// {
// 	var key;
// 	var isCtrl = false;
// 	var keychar;
// 	var reg;
// 		
// 	if(window.event) {
// 		key = e.keyCode;
// 		isCtrl = window.event.ctrlKey
// 	}
// 	else if(e.which) {
// 		key = e.which;
// 		isCtrl = e.ctrlKey;
// 	}
// 	
// 	if (isNaN(key)) return true;
// 	
// 	keychar = String.fromCharCode(key);
// 	
// 	// check for backspace or delete, or if Ctrl was pressed
// 	if (key == 8 || isCtrl)
// 	{
// 		return true;
// 	}
// 
// 	reg = /\d/;
// 	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
// 	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
// 	
// 	return isFirstN || isFirstD || reg.test(keychar);
// }
// 
// 
// 
// function ControlDecimalNumber(e){
// 	var keynum;
// 	
// 	if(window.event){
// 		keynum = window.event.keyCode;
// 	}
// 	else if(e.which){
// 		keynum = e.which;
// 	}
// 	if((GetSRC(e).value.indexOf(',')>-1 || GetSRC(e).value.indexOf('.')>-1 )&&(keynum == 44 || keynum == 46)){return false;}
// 	//alert(keynum);
// 	//                                                                                      carka           tecka
// 	return (((keynum >= 48) && (keynum <= 57)) || (keynum == 8 || keynum == 13) || (keynum == 44 || keynum == 46) || keynum === undefined);
// }
// function EmailControl(sEmail){
// 	var regEx  = new RegExp("^[_a-zA-Z0-9\.\-]+@(([_a-zA-Z0-9\-]{1,}\.){1,})+\.[a-zA-Z]{2,}$"); 
// 	
// 	regEx.ignoreCase = true;
// 		
// 	if (regEx.test(sEmail) == false)	{
// 		alert('Nesprávný formát e-mailu');
// 		return false;
// 	}
// 	return true;
// }
// 
// function chckFrmAssistent()
// {
//     if (!EmailControl(getE('email').value)) {return false;}
//     if (getE('question').value==''){alert('Není vyplněn text dotazu.'); return false;}
//     return true;
//     
// }
// function showPrmImage(idc, idp)
// {
//     window.open("/showParamImages.asp?DPG="+idc+"&ipar="+idp,"Images","toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=520,height=500,left=0,top=0");
// }
//

function validateICO(ico) {

    var icoSpace = String(ico).indexOf(' ');
    // Odstraním případné mezery
    while (icoSpace != -1) {
        ico = ico.replace(' ', '')
        icoSpace = ico.indexOf(' ');
    }

    var icoLength = String(ico).length;
    // Větší než 8 míst, chyba
    if (icoLength > 8) {
        alert('Zadané IČ nevyhovělo kontrole integrity. Proveďte kontrolu zadání.');
        return false;
    }

    //Pokud je ico menší než 8 čísel, doplní se nulami
    if (icoLength < 8) {
        ico = '00000000' + ico;
        ico = String(ico).substring(ico.length - 8, ico.length);
    }


    // Zapamatuji si poslední číslo IČA
    var cIco = String(ico).substring(icoLength - 1, icoLength);
    // Vezmu jen prvních sedm
    ico = String(ico).substring(0, 7);


    var icoArray = ico.split("");
    var icoSum = 0;
    // První až sedmou číslici vynásobíme čísly 8, 7, 6, 5, 4, 3, 2 a součiny sečtu
    for (var i = 0; i < 7; i++) {
        icoSum += parseInt(icoArray[i]) * (8 - parseInt(i));
    }

    // Spočítám zbytek po dělení jedenácti: zbytek = soucet % 11
    var icoSolve = icoSum % 11;
    // Kontrolní číslo
    var c = 0;
    // Pro něj musí platit: * je-li zbytek 0 nebo 10, pak c = 1; * je-li zbytek 1, pak c = 0; * v ostatních případech je c = 11 - zbytek
    if (icoSolve == 0 | icoSolve == 10) { c = 1; }
    else if (icoSolve == 1) { c = 0; }
    else { c = 11 - icoSolve; }

    // Aby bylo IČo správné, musí se kontrolní číslo rovnat poslednímu číslu IČA
    if (cIco != c) {
        alert('Zadané IČ nevyhovělo kontrole integrity. Proveďte kontrolu zadání.');
        return false;
    } else {
        return true;
    }

}


function topScroll() {
    if (window.innerHeight) {
        return (window.pageYOffset)
    } else if (document.documentElement && document.documentElement.scrollTop) {
        return (document.documentElement.scrollTop)
    } else if (document.body) {
        return (document.body.scrollTop)
    }
}


// Změny pro Bannery
function ControlAndAddBanner() {
    if (getE('hoverBannerPrepare')) {
        getE('hoverBanner').innerHTML = getE('hoverBannerPrepare').innerHTML
        getE('hoverBanner').style.top = topScroll() + 160 + 'px';
        getE('hoverBanner').style.left = (document.body.clientWidth / 2 - 300) + 'px';
        getE('hoverBanner').style.display = 'block';
        var time = (getE('timeForBanner')) ? getE('timeForBanner').value : 5;
        if (time != "0") { setTimeout("CloseTechBanner()", parseInt(time) * 1000); }
    }
}

function CloseTechBanner() {
    getE('hoverBanner').style.display = 'none';
    getE('hoverBanner').innerHTML = '';
    //  getE('hoverBannerPrepare').innerHTML = '';
}


$(function () {
    $('.tb1sEx').mouseover(showToolTip);
    $('.tb2sEx').mouseover(showToolTip);
    $('.tb3sEx').mouseover(showToolTip);

    $('.test1').mouseleave(hideToolTip);

    function showToolTip() {

        // pozice aktualniho tlacitka
        var position = $(this).position();

        var left = 0;
        var top = 0;
        var toolTipW = 155;
        // id ToolTip okna
        var id = "#" + $(this).attr('id') + "info";
        // vyska tlacitka
        var buttonHeight = 37;

        // sirka dokumentu
        //var dWidth = 757;
        var dWidth = $(document).width() - 202;
        dWidth = dWidth - ((dWidth - 757) / 2 - toolTipW / 2);

        if ((position.left + 180 + toolTipW) > dWidth) {
            left = position.left - 75;
        } else {
            left = position.left + 100;
        }

        // vyska dokumentu
        var headerHeight = 238; // vyska header (nebo 310..)
        var footerHeight = 221; // vyska footer

        // vyska okna prohlizece - obsahove casti
        //var dHeight = $(document).height() - footerHeight;
        var dHeight = $(window).height();

        // komplet vyska pozice tlacitka + vyska tooltipu
        var absBtnHeightWtoolTip = position.top + headerHeight - buttonHeight + $(id).height();
        var absBtnHeight = position.top + headerHeight - buttonHeight;

        //alert(windowHeight + ' ' + dHeight + ' ' + (position.top) + ' ' + $(id).height() + ' ' + (position.top + headerHeight - buttonHeight + $(id).height() ));

        //if ((position.top + buttonHeight + $(id).height()) > dHeight && (position.top + 221 > $(id).height())) {
        if (absBtnHeightWtoolTip > dHeight && (absBtnHeight - $(id).height()) > 0) {
            top = position.top - $(id).height() + 15;
        } else {
            top = position.top + buttonHeight;
        }

        $(id).css('position', 'absolute');
        $(id).css('z-index', '100');
        $(id).css('left', left);
        $(id).css('top', top);

        $(id).show();
    }

    function hideToolTip() {
        var id = "#cat" + $(this).attr('id') + "info";
        $(id).hide();
    }

});

function showModelImage(idHref) {
/*
    // pozice aktualniho tlacitka
    var position = $('#' + idHref).position();

    // sirka dokumentu
    //var dWidth = 757;
    var dWidth = $(document).width() - 202;
    dWidth = dWidth - ((dWidth-757) / 2);

    // vyska dokumentu
    var dHeight = $(document).height() - 221; // 310 = vyska header + footer + prvky mimo div s tlacitky; 221 - vyska bez footer

    var left = 0;
    var top = 0;
    var toolTipW = 155;
    // id ToolTip okna
    var id = '#model' + idHref;

    if ((position.left + 180 + toolTipW) > dWidth) {
    left = position.left - 75;
    } else {
    left = position.left + 100;
    }

    //if ((position.top + 32 + $(id).height()) > dHeight && (position.top + 221 > $(id).height())) {
    top = position.top - $(id).height() + 5;
    //} else {
    //top = position.top + 32;
    //}

    $(id).css('position', 'absolute');
    $(id).css('z-index', '100');
    $(id).css('left', left);
    $(id).css('top', top);

    $(id).show();
*/

    $('#sidecarimage').attr('src', idHref);
    $('#sidecarimage').show();
}

function showInfoDialog(t) {
    //var t = 'Vážený zákazníku, přecházíte na starý design našeho e-shopu, který bude v provozu už JEN do 29.února 2013.Věříme, že po chvíli používání se Vám zalíbí nová verze, tak jako u 96% všech uživatelů našeho e-shopu, kteří již na starý design nepřecházejí.';

    $('#modalCustWinTitle').text('Informace');
    $('#modalCustWinContent').text(t);
    $('#overlayCust').show();
    $('#modalCustWin').show();

    setTimeout(function () {
        olddesignsubmit();
    }, 3000);
}

function olddesignsubmit() {

    $('#modalWin').hide();
    $('#overlayCust').hide;
    $('#theForm').submit();
}
