﻿// JScript File
var _useOverwin = true;
var FuncJSLabels = null;
var _scrollSize = null;
var _warning;
var _hideProgressEnabled = true;
var _prefix = "ctl00_ContentPlace_";

function _wwwOnLoad() {
    try {
        _setContent();
        lexTitles(); //tartalmat csak akkor tölt be, ha a_f_lex-en tartózkodik a felhasználó (máskor nem kell cím)
        initCharTable();
    }
    catch (ex) {
    }
}

//Kezdőlap top ikonjaihoz a szükséges osztályok hozzáadása/elvétele (ahol szükséges)
function initTopIcons(aktMenuP) {
    if (/a_f_lex.aspx/.test(window.location.pathname) || aktMenuP == "aLogin") {
        jQuery(".divCharTable").removeClass("inaktiv");
    } else {
        jQuery(".divCharTable").addClass("inaktiv");
    }
    if (/a_f_lex.aspx/.test(window.location.pathname)) {
        jQuery(".divSearchSettings").removeClass("inaktiv");
    } else {
        jQuery(".divSearchSettings").addClass("inaktiv");
    }
}

function OpenURL(URL) {
    if (!FuncJSLabels) { GetFuncJSLabels("OpenURL('" + URL + "')"); return; }
    window.status = FuncJSLabels.OnConnect;

    if (URL === "" || URL === null || URL.length <= 8) {
        window.status = FuncJSLabels.EnterValidURL;
    }
    else {
        var location = URL;
        document.location.href = URL;
        window.status = FuncJSLabels.ConnectedTo.replace("[URL]", URL);
    }
}

function GetFuncJSLabelsComplete(res, x, evalfunc) {
    if (res) {
        FuncJSLabels = Sys.Serialization.JSON.deserialize(res);
    }
    if (evalfunc) { eval(evalfunc); }
}

function GetFuncJSLabels(evalfunc) {
    Sys.Net.ServiceMethod.invoke("~/services/s_s_info.asmx", "GetLabelArr", "",
        { tLabel: ["OnConnect", "EnterValidURL", "ConnectedTo"] },
        GetFuncJSLabelsComplete, GetFuncJSLabelsComplete, GetFuncJSLabelsComplete, null, evalfunc);

}

function replaceStr(src, find, to) {
    var retV = src;
    var spos = -1;
    while ((spos = retV.indexOf(find)) >= 0) {
        retV = retV.substring(0, spos) + to + retV.substring(spos + find.length);
    }
    return retV;
}

function getScrollbarSize() {
    if (!_scrollSize) {
        if (document.body) {
            var scr = null;
            var inn = null;

            // Outer scrolling div
            scr = document.createElement('div');
            scr.style.position = 'absolute';
            scr.style.top = '0px';
            scr.style.left = '0px';
            scr.style.width = '100px';
            scr.style.height = 'auto';
            // Start with no scrollbar
            scr.style.overflow = 'scroll';
            scr.id = "getscrollsize";
            scr.className = "overwin";
            scr.style.zIndex = 20000;

            // Inner content div
            inn = document.createElement('div');
            inn.style.width = '100%';
            inn.style.height = '200px';
            inn.className = "overwincontent";

            // Put the inner div in the scrolling div
            scr.appendChild(inn);
            // Append the scrolling div to the doc

            document.body.appendChild(scr);
            inn.innerHTML = "Get scrollbars sizes<BR/>Width:<BR/>-out:" + scr.offsetWidth + "<BR/>-in:" + inn.offsetWidth + "<BR/>";
            _scrollSize = scr.offsetHeight - inn.offsetHeight + 2;
            // Remove the scrolling div from the doc
            document.body.removeChild(document.body.lastChild);

        } else {
            _scrollSize = 22;
        }
    }
    return _scrollSize;
}

function setlang(lang) {
    var d = new Date();
    writePersistentCookie("Preferences=Lang", lang, "days", 30, true);
//    document.cookie = "Lang=;expires=" + d.toGMTString();
//    document.cookie = "Lang=" + lang; 
    window.location.reload();
}

//inicialiáló tartalom betöltése és színezés
function _setContent() {
    try {
        var aktMenuPointID;
        var lLocation = location.pathname + location.search;
        var lScrollTop = getCookieValue("ScrollTop");
        lLocation = lLocation.replace("/0/www/", "");
        lLocation = lLocation.replace("/1/www/", "");
        lLocation = lLocation.replace("/art/www/", "");
        lLocation = lLocation.replace("/ART/www/", "");
        lLocation = lLocation.split("&")[0];
        //Oldalbetöltéskor URL-től függően az alábbiak történnek:
        if (decodeURLParams("categoryid") != "") {
            switch (decodeURLParams("categoryid")) {
                case "1": jQuery("#aMainPage a").addClass("clickedRed"); break;
                case "2": jQuery("#aBrochures a").addClass("clickedRed"); break;
                case "3": jQuery("#aJob a").addClass("clickedRed"); break;
                case "4": jQuery("#aContact a").addClass("clickedRed"); break;
                case "5": jQuery("#aPartners a").addClass("clickedRed"); break;
                case "6": jQuery("#aAboutUs a").addClass("clickedRed"); break;
                case "7": jQuery("#aRecomendations a").addClass("clickedRed"); break;
                case "10": jQuery("#aAttention a").addClass("clickedRed"); break;
                case "16": jQuery("#aMTA a").addClass("clickedRed"); break;
                case "100": jQuery("#aIssueToSee a").addClass("clickedRed"); break;
                case "19":
                case "20": jQuery("#aHelpInfo a").addClass("clickedRed"); break;
                case "101": jQuery("#aHelpInfo a").addClass("clickedRed");
                    //segítő információkhoz tartozó almenü megjelenítése
                    var pos = jQuery("#aHelpInfo").offset();
                    jQuery("#subHelpInfo").css({ "display": "", "position": "absolute", "left": (pos.left - 2) + "px", "top": (pos.top + 33) + "px" });
                    myCurvyDivs(true, "#curvedMenu7", "#curvedMenu8");
                    break;
                case "102": jQuery("#aEvents a").addClass("clickedRed"); break;
                case "103": jQuery("#aPress a").addClass("clickedRed"); break;
                case "105": jQuery("#aLexDatas a").addClass("clickedRed");
                    var jqImg = jQuery(".SubMenuArrow");
                    for (var i = 0; i < jqImg.length; i++) {
                        jqImg[i].src = jqImg[i].src.replace("Act", "Ina");
                    }
                    //lexikális adatokhoz tartozó almenü megjelenítése
                    var pos = jQuery("#aLexDatas").offset();
                    jQuery("#subLexDatas").css({ "display": "", "position": "absolute", "left": (pos.left - 2) + "px", "top": (pos.top + 33) + "px" });
                    myCurvyDivs(true, "#curvedMenu1", "#curvedMenu2");
                    break;
            }
        }else if(/a_f_lex.aspx/.test(location.pathname)) {
            jQuery("#aLexDatas a").addClass("clickedRed");
        }else if(/DEFAULT.ASPX/.test(location.search.toUpperCase())){
            jQuery("#aLogin a").addClass("clickedRed");
        } else if (/music.aspx/.test(location.pathname)) {
            jQuery("#aMusic a").addClass("clickedRed");
        } else if (/order.aspx/.test(location.pathname)) {
            jQuery("#aBrochures a").addClass("clickedRed");
        }else{
            jQuery("#aMainPage a").addClass("clickedRed");
        }

        aktMenuPointID = jQuery(".clickedRed").parent().attr("id") == "" ? jQuery(".clickedRed").parent().parent().attr("id") : jQuery(".clickedRed").parent().attr("id");
        initTopIcons(aktMenuPointID); //navigációs (top) ikonok beállítása

        //ha a jobboldali almenüre kattintottunk, akkor be kell állítani a pozíciót (főleg nyelvváltásnál lenne elcsúszás enélkül)
        if (/submenu/.test(jQuery("#" + aktMenuPointID).attr("className"))) {
            setSubmenu(jQuery(".clickedRed").parent().attr("id"));
        }

        if (0 in jQuery("#ie9div")) {
            var lAttentionImage = jQuery('<span>&nbsp;&nbsp;&nbsp;</span><img class="hand" src="images/important_lex3.gif" alt="x"/>');
            lAttentionImage.mouseover(function() {
                overlib('<div class="browserattention">' + getLabels("lblBrowserAttention", true) + '</div>', FGCOLOR, 'white', TEXTFONTCLASS, 'oltxt', AUTOSTATUS, FULLHTML, 1);
            });
            lAttentionImage.mouseout(function() { nd(); });
            jQuery("#recommendedBrowsers").append(lAttentionImage);
        }
    }
    catch (ex) { }
}

//menüpontokra kattintás kezelése
function _refreshContent(aktMenuPoint) {
    try {
        var lPrefix = './'; //WWW-s ágon ez a prefix kell
        if (!/www/.test(window.location.pathname)) {
            lPrefix = './www/'; //sima ágon ez a prefix kell
        }

        switch (aktMenuPoint) {
            case "aMainPage": window.location = lPrefix + "content.aspx?categoryid=1"; break;
            case "aIssueToSee": window.location = lPrefix + "content.aspx?categoryid=100"; break;
            case "aHelpInfo": window.location = lPrefix + "content.aspx?categoryid=101"; break;
            case "aEvents": window.location = lPrefix + "content.aspx?categoryid=102"; break;
            case "aPress": window.location = lPrefix + "content.aspx?categoryid=103"; break;
            case "aLogin": window.location = /www/.test(window.location.pathname) ? '../Default.aspx' : './Default.aspx'; break;
            case "aContact": window.location = lPrefix + "content.aspx?categoryid=4"; break;
            case "aAboutUs": window.location = lPrefix + "content.aspx?categoryid=6"; break;
            case "aBrochures": window.location = lPrefix + "content.aspx?categoryid=2"; break;
            case "aRecomendations": window.location = lPrefix + "content.aspx?categoryid=7"; break;
            case "aAttention": window.location = lPrefix + "content.aspx?categoryid=10"; break;
            case "aMusic": window.location = lPrefix + "music.aspx"; break;
            case "aJob": window.location = lPrefix + "content.aspx?categoryid=3"; break;
            case "aPartners": window.location = lPrefix + "content.aspx?categoryid=5"; break;
            case "aMTA": window.location = lPrefix + "content.aspx?categoryid=16"; break;
            case "aLexDatas":
                if (!/a_f_lex.aspx/.test(window.location.pathname)) {
                    window.location = lPrefix + "content.aspx?categoryid=105";
                } else {
                    var jqImg = jQuery(".SubMenuArrow");
                    for (var i = 0; i < jqImg.length; i++) {
                        jqImg[i].src = jqImg[i].src.replace("Act", "Ina");
                    }
                    //lexikális adatokhoz tartozó almenü megjelenítése
                    var pos = jQuery("#aLexDatas").offset();
                    jQuery("#subLexDatas").css({ "display": "", "position": "absolute", "left": (pos.left - 2) + "px", "top": (pos.top + 33) + "px" });
                    myCurvyDivs(true, "#curvedMenu1", "#curvedMenu2");
                }
                break;
            case "aSubPersons":
                jQuery(".subLex").hide(); //eggyel mélyebb szint eltüntetése
                var jQThis = jQuery("#aSubPersons");
                var pos = jQThis.offset();
                jQuery("#subPersons").css({ "display": "inline", "position": "absolute", "left": (pos.left + jQThis.width() + 14) + "px", "top": (pos.top - 7) + "px" });
                var jqImg = jQuery(".SubMenuArrow");
                for (var i = 0; i < jqImg.length; i++) {
                    jqImg[i].src = jqImg[i].src.replace("Act", "Ina");
                }
                if (0 in jqImg) {
                    var lImg = jqImg[0];
                    lImg.src = lImg.src.replace("Ina", "Act");
                }
                myCurvyDivs(true, "#curvedMenu3", "#curvedMenu4");
                break;
            case "aSubEvents":
                jQuery(".subLex").hide(); //eggyel mélyebb szint eltüntetése
                var jQThis = jQuery("#aSubEvents");
                var pos = jQThis.offset();
                jQuery("#subEvents").css({ "display": "inline", "position": "absolute", "left": (pos.left + jQThis.width() + 14) + "px", "top": (pos.top - 7) + "px" });
                var jqImg = jQuery(".SubMenuArrow");
                for (var i = 0; i < jqImg.length; i++) {
                    jqImg[i].src = jqImg[i].src.replace("Act", "Ina");
                }
                if (1 in jqImg) {
                    var lImg = jqImg[1];
                    lImg.src = lImg.src.replace("Ina", "Act");
                }
                myCurvyDivs(true, "#curvedMenu5", "#curvedMenu6");
                break;
            case "aLanguage":
                if (jQuery("#languageList").css("display") == "none") {
                    jQuery(".subLex").hide();
                    jQuery(".subLexDatas").hide();
                    var pos = jQuery("#tdLanguage").offset();
                    jQuery("#languageList").css({ "left": (pos.left - 80) + "px", "top": (pos.top + 33) + "px" });
                    jQuery("#languageList").show();
                    myCurvyDivs(false, "#curvedMenuLang1", "#curvedMenuLang2");
                } else {
                    jQuery("#languageList").hide();
                } break;
            case "aSubABC":
                window.location = 'a_f_lex.aspx?SearchType=0';
                /*if (!/a_f_lex.aspx/.test(window.location.pathname)) {
                    window.location = 'a_f_lex.aspx?SearchType=0';
                } else {
                    _hideContent();
                    jQuery(".SearchByABC").show();
                    lexTitles(0);
                    jQuery(".SearchByText").css({ "display": "none" });
                    jQuery(".SearchByCode").css({ "display": "none" });
                    jQuery(".EventSearchByInstName").css({ "display": "none" });
                    jQuery.art.hideLexMenu();
                    jQuery(".ChoosenPerson").text("");
                    jQuery("#DataLister").css({ "display": "none" });
                    jQuery(".SearchABC a").css({ "color": "#ffffff" });
                }*/
                break;
            case "aSubText":
                window.location = 'a_f_lex.aspx?SearchType=1';
                /*if (!/a_f_lex.aspx/.test(window.location.pathname)) {
                    window.location = 'a_f_lex.aspx?SearchType=1';
                } else {
                    _hideContent();
                    jQuery(".SearchByText").css({ "display": "block" });
                    jQuery(".searchNames").focus();
                    lexTitles(1);
                    jQuery(".SearchByABC").css({ "display": "none" });
                    jQuery(".SearchByCode").css({ "display": "none" });
                    jQuery(".EventSearchByInstName").css({ "display": "none" });
                    jQuery.art.hideLexMenu();
                    var x = jQuery(".searchNames");
                    if (0 in x) {
                        jQuery(".searchNames")[0].innerText = "";
                    }
                    jQuery(".ChoosenPerson").text("");
                }*/
                break;
            case "aSubCode":
                window.location = 'a_f_lex.aspx?SearchType=2';
                /*if (!/a_f_lex.aspx/.test(window.location.pathname)) {
                    window.location = 'a_f_lex.aspx?SearchType=2';
                } else {
                    _hideContent();
                    jQuery(".SearchByCode").css({ "display": "block" });
                    jQuery(".searchCode").focus();
                    lexTitles(2);
                    jQuery(".SearchByABC").css({ "display": "none" });
                    jQuery(".SearchByText").css({ "display": "none" });
                    jQuery(".EventSearchByInstName").css({ "display": "none" });
                    jQuery.art.hideLexMenu();
                    var x = jQuery(".searchCode");
                    if (0 in x) {
                        jQuery(".searchCode")[0].innerText = "";
                    }
                    jQuery(".ChoosenPerson").text("");
                    jQuery("#DataLister").css({ "display": "none" });
                }*/
                break;
            case "aSubEvntByInst":
                window.location = 'a_f_lex.aspx?SearchType=3';
                /*if (!/a_f_lex.aspx/.test(window.location.pathname)) {
                    window.location = 'a_f_lex.aspx?SearchType=3';
                } else {
                    _hideContent();
                    jQuery(".EventSearchByInstName").css({ "display": "block" });
                    jQuery(".SearchEventByInst").focus();
                    lexTitles(3);
                    jQuery(".SearchByABC").css({ "display": "none" });
                    jQuery(".SearchByText").css({ "display": "none" });
                    jQuery(".SearchByCode").css({ "display": "none" });
                    jQuery.art.hideLexMenu();
                    var x = jQuery(".SearchEventByInst");
                    if (0 in x) {
                        jQuery(".SearchEventByInst")[0].innerText = "";
                    }
                    jQuery(".ChoosenPerson").text("");
                }*/
                break;
            case "aSubLibraryHelp": window.location = lPrefix + "content.aspx?categoryid=19"; break;
            case "aSubDatabaseHelp": window.location = lPrefix + "content.aspx?categoryid=20"; break;
        }
    }
    catch (ex) { }
}

//Submenüpontok pozíciójának állítása - mert a kattintott menüpontnak teljes egészében kell látszania, így ha szükséges, arrébb kell görgetni az oldalsó menüt
function setSubmenu(aktMenuPointID) {
    //Oldalsó menühöz - ha nem látszik teljesen a kattintott menüpont, akkor arrébb ugrik a helyes pozícióba
    var ltop = jQuery.art.settingsBase._divScroll[0].style.top;
    var lpos = parseInt(ltop, 10); //scrollDiv pozíciója
    var submenuTblRows = jQuery("#tblMenu td"); //táblázat oszlopainak (de mivel soronként egy oszlop van -> sorainak) beolvasása
    var topIndex = 0; //kattintott meüpont pozíciója
    var i = 0;
    //őt megelőzők magasságának összeadása
    while (submenuTblRows[i].id != this.id && i < submenuTblRows.length - 1) {
        topIndex -= submenuTblRows[i].offsetHeight;
        i++;
    }
    if (topIndex > lpos) { //ha felfelé lóg ki
        jQuery.art.settingsBase._divScroll.css({ top: (topIndex) + "px" });
        document.cookie = "ScrollTop=" + jQuery.art.settingsBase._divScroll[0].style.top; //beállítjuk cookie-ként is
    }
    topIndex -= submenuTblRows[i].offsetHeight - 2; //akt menüpont magasságát is hozzávesszük 
    if (topIndex < (lpos - 156)) { //ha lefelé lóg ki
        jQuery.art.settingsBase._divScroll.css({ top: (lpos - 8 + (topIndex - lpos + 168)) + "px" });
        document.cookie = "ScrollTop=" + jQuery.art.settingsBase._divScroll[0].style.top;  //beállítjuk cookie-ként is
    }
}

function _zoomImage(tImage) {
    overwin("<img src=\"images\\" + tImage + "\">", 'ABOVE', 'LEFT', 'HELP');
}

function loadPage(lPage) {
    window.location = "../" + lPage;
}

function _setContentPage() {
    try {
        if (/lex/.test(location)) {
            window.location = './content.aspx';
        }
    }
    catch (ex) {
    }
}

function _hideContent() {
    try {
        jQuery(".cont").hide();
        jQuery(".cont_lex").show();
        jQuery("#container").css({ "height": "100%" });
        jQuery("html").css({ "height": "100%" });
        jQuery("#personDetails").hide();
        jQuery("#personAlphabet").hide();
        jQuery(".BackToList").hide();
        jQuery("#DataLister").text("");
        jQuery(".lebeg").remove();
        jQuery(".lebeg2").remove();
        //topmenu ikonok feltételesen aktívvá, illetve inkaktivvá tétele (ha nem frissül az oldal - frissítéskor: initTopIcons)
        jQuery(".divSearchSettings").removeClass("inaktiv");
        jQuery(".divCharTable").removeClass("inaktiv");
    }
    catch (ex) {
    }
}

//Lexikális menüpontokhoz tartozó címek kiírása az oldal fejlécére
function lexTitles(type) {
    var lTitle = "";
    var lSearh = window.location.search;
    if (type != null) {
        switch (type) { //a_f_lex.aspx-en menüpont váltás történik
            case 0: lTitle = getLabels("mnuPersonsAlphabet"); break;
            case 1: lTitle = getLabels("mnuPersonsText"); break;
            case 2: lTitle = getLabels("mnuPersonsCode"); break;
            case 3: lTitle = getLabels("mnuEventsText"); break;
            case 4: lTitle = getLabels("mnuLibraryHelp"); break;
        }
    } else { //ez a rész oldalbetöltés esetén hajtódik végre
        if (/SearchType=0/.test(lSearh)) { lTitle = getLabels("mnuPersonsAlphabet"); }
        else if (/SearchType=1/.test(lSearh)) { lTitle = getLabels("mnuPersonsText"); jQuery(".searchNames").focus(); }
        else if (/SearchType=2/.test(lSearh)) { lTitle = getLabels("mnuPersonsCode"); jQuery(".searchCode").focus(); }
        else if (/SearchType=3/.test(lSearh)) { lTitle = getLabels("mnuEventsText"); jQuery(".SearchEventByInst").focus(); }
        //else { lTitle = jQuery("#aSubABC")[0].innerText; }
    }
    if (lTitle != "") {
        jQuery("#lexTitles").remove();
        jQuery("#head").append("<div id='lexTitles' style='position:relative; color:black; font-weight: bold; width:395px; height:20px; font-size:11px; background-image: url(images/lex_titles2b.png); left:592px; bottom: 87px; padding-top:3px; text-align:center;'>" + lTitle + "</div>");
    }
}

function removeLexTitles() {
    jQuery("#lexTitles").remove();
}

function getLabels(lblCode, htmlNeeded) {
    var labelsByClass = jQuery(".divTexts ." + lblCode);
    
    if (0 in labelsByClass) {
        if (htmlNeeded) {
            return labelsByClass.html();
        } else {
            return labelsByClass.text();
        }
    }
    else {
        return lblCode;
    }
}

//...................................................................................
//Lex-es webservice adatok hívása (mindegyiknek van www-s és györkérbeli megfelelője)
//...................................................................................

function _onRecordInfoCompleteLex(result, response, context) {
    var opt, eSrc, lCaption, lhtml, levent;
    try {
        _hideProgress();
        eSrc = context[0];
        opt = context[1];
        levent = context[2];
        lCaption = result.Caption;
        lhtml = result.InfoHtml.replace(/\[NAME\]/g, opt.text).replace(/\[ID\]/g, opt.id);
        //TODO: A panel címét az s_s_lex_info.cs-beli RecordInfo()-nak kellene visszaadnia...
        //jQueryMsgBox(getLabels("lblRInfoPLex"), lhtml.replace("width: 750px", ""), "rInfoPanel", 800, "recordPopUp");
        jQueryMsgBox(getLabels("lblRInfoPLex"), lhtml.replace("width: 750px", ""), "rInfoPanel", 100 + (gPanelZ++), "recordPopUp");

        var Link = jQuery(".recordPopUp .fixedHeader th a");
        for (var i = 0; i < Link.length; i++) {
            Link[i].onmousemove = null;
        }
    }
    catch (ex) {
        var a = 0;
    }
}

function _getRecordInfoLex(options, tElement) {
    var levent, ltext;
    try {
        _showProgress(jQuery.art.progressText);
        levent = { clientX: event.clientX, clientY: event.clientY };
        Sys.Net.ServiceMethod.invoke("services/s_s_lex_info.asmx", "RecordInfoLex", "",
                                      { ID: options.id, tInfoType: options.infoType },
                                      _onRecordInfoCompleteLex, null, null, null,
                                      [tElement, options, levent]);
    }
    catch (ex) {
    }
}

function _getKiadvRecordInfo(id) {
    try {
        return;
    }
    catch (ex) { }
}

function _getRecordInfoKLex(options, tElement) {
    var levent;
    try {
        _showProgress(jQuery.art.progressText);
        levent = { clientX: event.clientX, clientY: event.clientY };
        Sys.Net.ServiceMethod.invoke("services/s_s_lex_info.asmx", "RecordInfoLex", "",
                                      { ID: options.id, tInfoType: options.infoType },
                                      _onRecordInfoCompleteKLex, null, null, null,
                                      [tElement, options, levent]);
    }
    catch (ex) {
        var a = 0;
    }
}

function _onRecordInfoCompleteKLex(result, response, context) {
    var opt, eSrc, lCaption, lhtml, levent;
    try {
        _hideProgress();
        eSrc = context[0];
        opt = context[1];
        levent = context[2];
        lCaption = result.Caption;
        lhtml = result.InfoHtml.replace(/\[NAME\]/g, opt.text).replace(/\[ID\]/g, opt.fullID);
        //TODO: A panel címét az s_s_lex_info.cs-beli RecordInfo()-nak kellene visszaadnia...
        //jQueryMsgBox(getLabels("lblRInfoKLex"), lhtml.replace("width: 750px", ""), "rInfoPanel", 800, "recordPopUp");
        jQueryMsgBox(getLabels("lblRInfoKLex"), lhtml.replace("width: 750px", ""), "rInfoPanel", 100 + (gPanelZ++), "recordPopUp");
    }
    catch (ex) {
    }
}

//===============================================================================
// EGYÉNI FORMÁZÁS MEGADÁSA:
// 
// inline style-ként csak a szerkezethez kellő attribútumok vanak megadva,
// színek (és egyebek) megadása extracss paraméterrel az alábbiaknak megfelelően:
//
// css fájlba:  
//
// .extracss .jQueryMsgBoxHeadTop { background-color:#87a5be; text-align:right; }
// .extracss .jQueryMsgBoxHeadBottom { background-color:#d8e3e9; color:#3d607e; }
// .extracss { background-color:#10324d; }
// 
// ahol extracss = jQueryMsgBox hívásakor átadott extracss paraméter
//===============================================================================

function jQueryMsgBox(title, content, msgBoxID, zindex, extracss, titleInHeadTop) {
    var maxWidth, maxHeight, fadingDiv, head, result;
    var jqMsgBox;
    try {
        head = "<div id='" + msgBoxID + "Head' class='jQueryMsgBoxHead'>";
        if (titleInHeadTop) {
            head += "<div id='" + msgBoxID + "HeadTop' class='jQueryMsgBoxHeadTop' style='width:100%; height:20px;'><span style='float: left; padding-left: 8px; padding-top: 1px;'>" + title + "</span>";
        }
        else {
            head += "<div id='" + msgBoxID + "HeadTop' class='jQueryMsgBoxHeadTop' style='width:100%; height:20px;'>";
        }
        head += "<div id='" + msgBoxID + "Exit' class='jQueryMsgBoxExit' style='float:right; position:relative; padding-right:5px; font-size:16px; cursor:pointer;' >X</div>";
        head += "</div>";
        if (titleInHeadTop) {
            //head += "<div id='" + msgBoxID + "HeadBottom' class='jQueryMsgBoxHeadBottom' style='width:100%; font-size:20px; text-align:center; clear:both;'></div>"
        }
        else {
            head += "<div id='" + msgBoxID + "HeadBottom' class='jQueryMsgBoxHeadBottom' style='width:100%; font-size:20px; text-align:center; clear:both;'>" + title + "</div>";
        }
        head += "</div>";
        result = "<div id='" + msgBoxID + "' class='jQueryMsgBox' style='padding:10px;'>" + head + content + "</div>";

        maxWidth = jQuery(window).width();
        maxHeight = jQuery(window).height();
        //fadingDiv = "<div id='fade" + msgBoxID + "' class='jQueryMsgBoxFadingDiv' style='z-index:" + zindex + "; width:" + maxWidth + "px; height:" + maxHeight + "px;'></div>";
        var fadingdivtop = ((0 in jQuery(".sidemenu")) ? jQuery(".sidemenu").position().top + jQuery(".sidemenu").height() + 2 : 0);
        var fadingdivheight = maxHeight - fadingdivtop;
        fadingDiv = "<div id='fade" + msgBoxID + "' class='jQueryMsgBoxFadingDiv' style='z-index:" + zindex + "; width:" + maxWidth + "px; height:" + fadingdivheight + "px; top: " + fadingdivtop + "px;'></div>";
        jQuery("body").append(fadingDiv);
        jQuery("body").append(result);
        jqMsgBox = jQuery("#" + msgBoxID);
        jqMsgBox.css({ "z-index": (zindex + 10), "position": "absolute", "top": (maxHeight - jqMsgBox.height()) / 2 + "px", "left": (maxWidth - 820) / 2 + "px", "width": "800px" });
        if (extracss != "") {
            jqMsgBox.addClass(extracss);
        }
        jqMsgBox.children().children().children("#" + msgBoxID + "Exit").click(function() {
            jQueryMsgBoxExit(this);
            nd();
        });
        jqMsgBox.children().children().children("#" + msgBoxID + "Exit").mouseover(function() {
            overlib(getLabels("lblClose"), WIDTH, 70, FGCOLOR, '#a9bed2', TEXTFONTCLASS, 'oltxt', AUTOSTATUS);
        });
        jqMsgBox.children().children().children("#" + msgBoxID + "Exit").mouseout(function() {
            nd();
        });
        changeFontSize(0);
    } catch (ex) {
    }
}

function jQueryMsgBoxExit(tMsgBoxCloseDiv) {
    var lId;
    try {
        lId = tMsgBoxCloseDiv.id.split("Exit");
        jQuery("#" + lId[0]).remove();
        jQuery("#fade" + lId[0]).remove();
    }
    catch (ex) {
    }
}

//súgóinformációk megjelenítése a lex-es panelekhez
function _getHelpInfoLex(labels, panelcount) {
    var columns, maxWidth, maxHeight, texts;
    var result = "";
    var arrowhelp = "";
    try {
        arrowhelp = "<table style='width:100%;'><tbody><tr><td class='td0' style='border-bottom: #d20019 1px solid !important;'>&uarr;&nbsp;&darr;</td><td class='td1' style='border-bottom: #d20019 1px solid !important;'>:</td><td class='td2' style='border-bottom: #d20019 1px solid !important;'>" + getLabels("lblSortArrowHelp", true) + "</td></tr></tbody></table>";
        arrowhelp += '<div style="height: 10px;">&nbsp;</div>';
        
        columns = labels.columns.split("|");
        texts = labels.texts.split("|");
        for (var i = 0; i < columns.length; i++) {
            if (/images/.test(columns[i]) && /./.test(columns[i])) {
                result += "<tr><td class='td0'><img src='" + columns[i] + "'/></td><td class='td1'>:</td><td class='td2'>" + texts[i] + "</td></tr>";
            } else {
                result += "<tr><td class='td0'>" + columns[i] + "</td><td class='td1'>:</td><td class='td2'>" + texts[i] + "</td></tr>";
            }
        }
        result = (panelcount > 1 ? arrowhelp : "") + "<table style='width:100%;'><tbody>" + result + "</tbody></table>";

        jQueryMsgBox(getLabels("lblHelpInfo"), result, "helpInfoPanel", 900, "hlpInfoPanelLex");
    }
    catch (ex) {
        var a = "";
    }
}

//Plusz információs ablak lexikális adatokhoz
function infoBox(tWidth, tHeight, tID, tData, tInfo, tBetu) {
    _popUp = true;

    var win = null;
    var w = tWidth;
    var h = tHeight;
    var lBetu = (tBetu) ? tBetu : 0;
    var theUrl = "a_e_personinfo_lex.aspx?id=" + tID + "&betu=" + lBetu + "&table=" + tData;
    var lToolbar = ((location.pathname.indexOf("/1/") > -1) || (location.hostname == "localhost")) ? 'toolbar=yes,' : 'toolbar=no,';

    if (tInfo != "") {
        if (tInfo.charAt(0) != "&")
            theUrl = theUrl + "&" + tInfo;
        else
            theUrl = theUrl + tInfo;
    }
    var myname = "InfoBox";
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var settings = 'height=' + h + ',';
    settings += 'width=' + w + ',';
    settings += 'top=' + wint + ',';
    settings += 'left=' + winl + ',';
    settings += 'resizable=yes,';
    settings += lToolbar;
    settings += 'scrollbars=yes';
    win = window.open(theUrl, myname, settings);
    win.focus();
}

//..........................................................................
//Megadott URL paraméter kiolvasása
//..........................................................................

function decodeURLParams(tParamName) {
    var lParams = location.search;
    var lParam;
    var lPos;

    lParams = lParams.substring(1, lParams.length);
    lPos = lParams.search(tParamName + "=");

    if (lPos < 0) return "";

    lParams = lParams.substring(lPos, lParams.length);
    lPos = lParams.search("&");

    if (lPos < 0) {
        lPos = lParams.length;
    }

    lParams = lParams.substring(0, lPos);
    lParam = lParams.replace(tParamName + "=", "");

    return lParam;
}

//..........................................................................
//Megrendelés elküldése
//..........................................................................

function _sendOrder() {
    var divOrder = $("divOrder");
    var txtName = $("txtName");
    var txtPostalCode = $("txtPostalCode");
    var txtCity = $("txtCity");
    var txtStreet = $("txtStreet");
    var txtHouseNumber = $("txtHouseNumber");
    var btnOrder = $("btnOrder");
    var lblOrderError = $("lblOrderError").value;

    if (txtName.value == "" || txtPostalCode.value == "" || txtStreet.value == "" || txtHouseNumber.value == "") {
        alert(lblOrderError);
        return;
    }

    btnOrder.style.display = "none";

    Sys.Net.ServiceMethod.invoke("services/s_s_order.asmx", "SendOrder", "", { tOrderForm: divOrder.innerHTML, tEmail: "art@artchivum.com" }, _onSendOrderMethodComplete, null, null, null, [this, null]);
}

function _onSendOrderMethodComplete(result, response, context) {
    var divOrderOK = $("divOrderOK");

    if (result) {
        var divOrder = $("divOrder");

        divOrder.style.display = "none";
    }
    else {
        var lblSmtpErr = $("lblSmtpError").value;
        divOrderOK.children[0].innerHTML = lblSmtpErr;
    }
    divOrderOK.style.display = "";
}

//..........................................................................
//Cookie lekérdezése név alapján
//..........................................................................

function getCookie(cookieName) {
    var exp = new RegExp(escape(cookieName) + "=([^;]+)");
    if (exp.test(document.cookie + ";")) {
        exp.exec(document.cookie + ";");
        return unescape(RegExp.$1);
    }
    else {
        return "";
    }
}

//..........................................................................
//Cookie írása
//..........................................................................

function writeCookie(cookieName, cookieValue, cookieExperied, cookieDomain, textraPath) {
    if (testCookie()) {
        var exdate = new Date();
        var experied = (!cookieExperied) ? 0 : cookieExperied;
        exdate.setDate(exdate.getDate() + experied);
        var exdateStr = (!cookieExperied) ? "" : ";expires=" + exdate.toGMTString();
        var lextrapath = (textraPath) ? textraPath : "";
        var domain = (!cookieDomain) ? "" : ";domain=" + cookieDomain;

        document.cookie = escape(cookieName) + "=" + escape(cookieValue) + exdateStr + "; path=/" + lextrapath + domain;
    }
}

function writeCookieNoEsc(cookieName, cookieValue, cookieExperied, cookieDomain, textraPath) {
    if (testCookie()) {
        var exdate = new Date();
        var experied = (!cookieExperied) ? 0 : cookieExperied;
        exdate.setDate(exdate.getDate() + experied);
        var exdateStr = (!cookieExperied) ? "" : ";expires=" + exdate.toGMTString();
        var lextrapath = (textraPath) ? textraPath : "";
        var domain = (!cookieDomain) ? "" : ";domain=" + cookieDomain;

        document.cookie = cookieName + "=" + cookieValue + exdateStr + "; path=/" + lextrapath + domain;
        return true;
    }
    else return false;
}

function testCookie() {
    document.cookie = "testSessionCookie=Enabled";
    if (getCookie("testSessionCookie") == "Enabled") {
        return true;
    }
    else {
        return false;
    }
}

function PopUpWindow(tUrl) {

    _popUp = true;

    var win = null;
    var w = 850;
    var h = 600;
    var theUrl = tUrl;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var settings = 'height=' + h + ',';
    settings += 'width=' + w + ',';
    settings += 'top=' + wint + ',';
    settings += 'left=' + winl + ',';
    settings += 'resizable=no,';
    settings += 'toolbar=no,';
    settings += 'titlebar=no,';
    settings += 'scrollbars=yes';
    win = window.open(theUrl, "", settings);
    win.focus();
}

function _infoMsgBlink(lID, lBlinkVal) {
    var lElement = $(lID);
    if (lElement != undefined) {
        if (lBlinkVal) {
            lBlinkVal = false;
            lElement.style.visibility = "visible";
        }
        else {
            lBlinkVal = true;
            lElement.style.visibility = "hidden";
        }
    }
}

function _showLoading(e) {
    var divLoading = $("loadingDiv");

    if (divLoading) {
        _hideProgressEnabled = false;
        divLoading.style.display = "";
    }
    _showProgress();
}


function _hideLoading() {
    var divLoading = $("loadingDiv");

    if (divLoading) {
        _hideProgressEnabled = true;
        divLoading.style.display = "none";
    }
    _hideProgress();
}

//..........................................................................
//Folyamatjelző megmutatása
//..........................................................................

function _showProgress(tString) {
    var divProgress = $("progressDiv");
    var lTextInsert;
    var lblInProgress;
    var parent;

    if (!tString && _warning) {
        return;
    }

    if (divProgress) {
        divProgress.style.display = "";

        lblInProgress = $("lblInProgress");

        if (lblInProgress != null) {
            lblInProgress = lblInProgress.value;
        }

        if (lblInProgress == null) {
            if (divProgress.innerHTML || divProgress.innerHTML === "") { lblInProgress = divProgress.innerHTML; }
            else {
                parent = window.opener;
                lblInProgress = parent.$("lblInProgress").value;
            }
        }

        if (divProgress.children[0] != null) {
            lTextInsert = divProgress.children[0];
        }
        else {
            lTextInsert = divProgress;
        }

        if (tString != null) {
            lTextInsert.innerHTML = tString;
        }
        else {
            lTextInsert.innerHTML = lblInProgress;
        }
    }
    else {
        lblInProgress = $("lblInProgress");

        if (lblInProgress != null) {
            lblInProgress = lblInProgress.value;
        }

        if (lblInProgress == null) {
            parent = window.opener;
            lblInProgress = (parent) ? parent.$("lblInProgress").value : "";
        }
        divProgress = document.createElement("div");
        divProgress.id = "progressDiv";
        divProgress.className = "loading";
        if (tString != null) {
            divProgress.innerHTML = tString;
        }
        else {
            divProgress.innerHTML = lblInProgress;
        }
        document.body.appendChild(divProgress);
    }
}

//..........................................................................
//Folyamatjelző elrejtése
//..........................................................................

function _hideProgress() {
    var divProgress = $("progressDiv");

    if (_hideProgressEnabled && divProgress) {
        divProgress.style.display = "none";
    }
}

//..........................................................................
//Kicsi folyamatjelző megmutatása
//..........................................................................

function _showProgressLittle(tIndex) {
    _showProgress();
}

//lekerekítések
function myCurvyDivs(permanent, divTopID, divBottomID) {
    try {
        jqTop = jQuery(divTopID);
        jqBottom = jQuery(divBottomID);
        if (permanent) {
            if (0 in jqTop) {
                if (!/cornered/.test(jQuery(divTopID).attr("className"))) { //ha már van "cornered" class, akkor ez már kerekített
                    if (jqTop.width() == 0) { //az eredetileg display:none-os diveknél nem minde IE verzió alatt kap szélességet, ekkor be kell állítani
                        jqTop.css({ "width": jqTop.next().attr("clientWidth") + "px" });
                    }
                    curvyCorners({ tl: { radius: 5 }, tr: { radius: 5 }, bl: { radius: 0 }, br: { radius: 0 }, antiAlias: true }, divTopID);
                    jQuery(divTopID).addClass("cornered");
                }
            }
            if (0 in jqBottom) {
                if (!/cornered/.test(jQuery(divBottomID).attr("className"))) { //ha már van "cornered" class, akkor ez már kerekített
                    if (jqBottom.width() == 0) { //az eredetileg display:none-os diveknél nem minde IE verzió alatt kap szélességet, ekkor be kell állítani
                        jqBottom.css({ "width": jqBottom.prev().attr("clientWidth") + "px" });
                    }
                    curvyCorners({ tl: { radius: 0 }, tr: { radius: 0 }, bl: { radius: 5 }, br: { radius: 5 }, antiAlias: true }, divBottomID);
                    jQuery(divBottomID).addClass("cornered");
                }
            }
        } else {
            if (0 in jqTop) {
                if (jqTop.width() == 0) {
                    jqTop.css({ "width": jQuery(divTopID).next().attr("clientWidth") + "px" });
                }
                curvyCorners({ tl: { radius: 5 }, tr: { radius: 5 }, bl: { radius: 0 }, br: { radius: 0 }, antiAlias: true }, divTopID);
            }
            if (0 in jqBottom) {
                if (jqBottom.width() == 0) {
                    jqBottom.css({ "width": jQuery(divBottomID).prev().attr("clientWidth") + "px" });
                }
                curvyCorners({ tl: { radius: 0 }, tr: { radius: 0 }, bl: { radius: 5 }, br: { radius: 5 }, antiAlias: true }, divBottomID);
            }
        }
    } catch (ex) {
    }
}

//..........................................................................
//Header pozicionálása görgetett listák esetén
//..........................................................................

function SetHeaderE(e) {
    try {
        var lDiv = Function.getEventTarget(e);
        setHeaderPos(lDiv.getElementsByTagName("TH"), lDiv);
    }
    catch (ex) {
    }
}
function setHeaderPos(tCells, tDiv) {
    jQuery.each(tCells, function() {
        //this.style.top = (tDiv.scrollTop - 2) + "px";
        this.style.top = (tDiv.scrollTop - 4) + "px";
    });
}

function _tblSortStruct(lMsg, lColor, e, f) {
    var eSrc, lTrArr;
    try {
        if (tblSort) {
            if (e.type == "click") {
                var jQeTrgt = jQuery(Function.getEventTarget(e));
                var panelid = jQeTrgt.parents().parents().parents().parents().parents().parents()[0].className.replace("loaded", "").replace("Content", "");
                var htr = jQuery("#SortingEnded").attr("hoverstoregenerate");
                if (htr == undefined) {
                    htr = "";
                }
                jQuery("#SortingEnded").attr("hoverstoregenerate", htr + panelid + "|!|mod" + "|!!!|");
                hoversToRegenerate[hoversToRegenerate.length] = panelid + "|!|mod";

                tblSort.showMSG(lMsg, lColor, e);

                var divArr0 = jQuery(".div" + panelid)[1];
                if (jQeTrgt.attr("clickedfrom") == "lebeg2") {
                    jQuery("#dinamicContent").scrollTop(divArr0.offsetTop - jQuery(divArr0.previousSibling).height() - jQuery(divArr0.previousSibling.previousSibling).height());
                }
                jQeTrgt.attr("clickedfrom", "");
            }
            else {
                tblSort.showMSG(lMsg, lColor, e);
            }
        }
    }
    catch (ex) {
    }
}

function PopUpInfoHlp(e, tHelp, tCaption, tOverlib, tText, tCssClass, tOWCSS) {
    var lHeight, lVerticalAlign, eSrc;
    try {
        lVerticalAlign = ((jQuery.art.settingsBase.preDivHeight * 0.7) > e.clientY) ? 'BELOW' : 'ABOVE';
    }
    catch (ex) {
        lVerticalAlign = 'BELOW';
    }
    eSrc = Function.getEventTarget(e);

    if (!lVerticalAlign)
        lVerticalAlign = 'BELOW';
    if (lVerticalAlign == 'ABOVE' && !tCaption)
        lVerticalAlign = 'BELOW';
    var lPopUpOff;
    var lCaption = tCaption;
    var lCssClass = (tCssClass) ? " " + tCssClass : "";
    var lowCSSparam = (tOWCSS) ? "OWCLASS" : "";
    var lowCSS = (tOWCSS) ? tOWCSS : "";
    lPopUpOff = getCookieValue("PopUpOff");
    var popup = $("ctl00_popup");
    if (popup != null) {
        if (_getPopUpOff()) {
            return;
        }
    }
    if (tText == null) {
        tText = eSrc.innerText;
    }
    var tInfoHtml = tHelp; //"<p>" + tHelp + "</p>";

    while (tText.indexOf("[BR]") > -1) {
        tText = tText.replace("[BR]", "<br />");
    }
    while (tText.indexOf("[DIV]") > -1) {
        tText = tText.replace("[DIV]", "<div class=\"txt\">");
    }
    while (tText.indexOf("[!DIV]") > -1) {
        tText = tText.replace("[!DIV]", "</div>");
    }
    //ha a fejléc kép, és van megadva nagyobb kép
    if (tText.indexOf(" srcLarge=") > -1) {
        var srcIndex = tText.indexOf(" srcLarge=") + 10;
        var imgLarge = tText.substr(srcIndex);

        tInfoHtml = tInfoHtml.replace('[IMG]', '"[FIELD]"');
        if (tInfoHtml.indexOf('"[FIELD]"') < 0) {
            tInfoHtml += '"[FIELD]"';
        }

        tText = (lCaption == "") ? "&quot;" + tText.substr(0, srcIndex - 10) + "&quot;" : tText.substr(0, srcIndex - 10);
        tInfoHtml = '<div class=\"body1' + lCssClass + '\">' + tInfoHtml.replace('"[FIELD]"', "<br /><div class=\"img\"><img src=\"" + imgLarge + "\"/><br />" + tText + "</div>") + '</div>';
        lCaption = (lCaption == "") ? tText : lCaption;
    }
    //ha tartalmazza a [FIELD] szöveget a tHelp, akkor csere
    if (tInfoHtml.indexOf("[FIELD]") > -1) {
        tInfoHtml = tInfoHtml.replace("[FIELD]", tText);
    }
    lCaption = (!lCaption) ? '' : lCaption;
    overwin(tInfoHtml, 'CAPTION', lCaption, 'WIDTH', 200, lVerticalAlign, 'LEFT', 'HELP', lowCSSparam, lowCSS);
}

function _focusItem(e) {
    //this bemeneti értékkel aktuális/előző focused sor beállítás
    //event nem alkalmas az onclick TR elemének meghatározására

    var lThead, txtFocusedRow, lPos, lstPrev, lst, i, joinedCount = 0, setFocus = true;

    try {
        lThead = e.parentNode.parentNode.children[0];
        txtFocusedRow = lThead.children[1].children[0].children[0];  //THEAD 2.SOR INPUT-ja

        lPos = e.sectionRowIndex;   // e.parentNode.children -jei közül

        if (e.className.indexOf("listitemfocusp1") < 0) {
            //előző poz.szerinti sor alapállapot
            //     tömb a listitemfocusp1 sorokból
            lstPrev = j$.art.getElementsByClass(e.parentNode, 'listitemfocusp1', 'tr');
            for (i = 0; i < lstPrev.length; i++) {
                lstPrev[i].className = lstPrev[i].className.replace("listitemfocusp1", "listitemoutp1");
            }

            //     beállítás
            lst = e.parentNode.children;
            for (i = lPos; i < lst.length; i++) {
                //következő parent vagy nem parent/joined sorig kiemelet formázás
                if ((lPos == i) || (lst[i].className.indexOf("joinedrow") > -1)) {
                    lst[i].className = lst[i].className.replace("listitemoutp1", "listitemfocusp1");
                }
                else {
                    break;
                }
            }

            //ha a kiválasztott joined, akkor az előtte lévő sorok parent-ig kiemelve
            if (lst[lPos].className.indexOf("joinedrow") > -1) {
                for (i = lPos - 1; i > 0; i--) {
                    if ((lst[i].className.indexOf("parentrow") > -1) || (lst[i].className.indexOf("joinedrow") > -1)) {
                        lst[i].classNamelst = [i].className.replace("listitemoutp1", "listitemfocusp1");
                    }
                    else {
                        break;
                    }
                }
            }
        }
    }
    catch (ex) {
    }
}

var hoversToRegenerate = new Array();
