function dexalert2(data, title, w, h, id) {
    if (typeof h == 'undefined')
        h = 450;
    ipopuphtml(data, title, w, h, id);
}

/** popup.js **/

var gZIndex = 1;

function fadeIn(obj, start, stop, step, speed) {
    obj.style.opacity = start / 100;
    obj.style.filter = "alpha(opacity=" + start + ")";
    obj.style.display = "block";
    var id = window.setInterval(
	function() {
	    op = parseFloat(obj.style.opacity) + step / 100;
	    op = Math.round(op * 100) / 100;
	    obj.style.opacity = op;
	    obj.style.filter = "alpha(opacity=" + (op * 100) + ")";
	    //document.title = document.title + ' ' + obj.style.opacity;
	    if (obj.style.opacity >= stop / 100) window.clearInterval(id);
	}
	, speed)
}


function windowClose(id) {
    var win = document.getElementById("popupMask" + id);
    //win.style.display = "none";
    win.parentNode.removeChild(win);
    win = document.getElementById("popupDialog" + id);
    //win.style.display = "none";
    win.parentNode.removeChild(win);

    document.body.parentNode.className = '';
}

function escapehtml(s) {
    return s.replace(/['"&<>]/g, function(c) {
        if (c == "'")
            return '&apos;';
        if (c == '"')
            return '&quot;';
        if (c == '&')
            return '&amp;'
        if (c == '<')
            return '&lt;'
        if (c == '>')
            return '&gt;';
    });
}

function ipopup(url, title, w, h) {
    var id = Math.random();
    return ipopupraw("<iframe src='" + escapehtml(url) + "' scrolling=\"no\" frameborder=\"0\" width=\"100%\" height=\"100%\" id=\"iframe" + id + "\"></iframe>", title, w, h, id);
}



function ipopuphtml(data, title, w, h) {
    var id = Math.random();
    //return ipopupraw('<div style="height: 100%; background-color: white; overflow-y: scroll;"><div style="padding: 7px;">' + data + '</div></div>', title, w, h);
    return ipopupraw('<div class="dexalerth"><a href="javascript:;" onclick="windowClose(\'' + id + '\');" style="float:right;margin-top: 8px; margin-right: 8px;"><img src="res/pics/x2.gif" border="0"/></a>' + title + '</div><div class="dexalertc" style="overflow-y: scroll;height: ' + (h - 63) + 'px">' + data + '</div>', title, w, h, id);
}

function ipopupraw(data, title, w, h, id) {
    if (!id)
        id = Math.random();
    //mask
    var mask = document.createElement('div');

    mask.id = 'popupMask' + id;
    mask.className = 'popupMask';

    pBody = document.body;

    var fullHeight = getViewportHeight();
    var fullWidth = getViewportWidth();

    // Determine what's bigger, scrollHeight or fullHeight / width
    if (fullHeight > pBody.scrollHeight) {
        popHeight = fullHeight;
    } else {
        popHeight = pBody.scrollHeight
    }

    mask.style.height = popHeight + "px";
    mask.style.width = pBody.scrollWidth + "px";

    mask.style.opacity = "0.40"; // firefox miatt
    mask.style.filter = "alpha(opacity=40)"; // ie miatt

    mask.style.backgroundColor = "Black";
    mask.style.position = "absolute";
    mask.style.zIndex = gZIndex++;
    mask.style.top = "0px";
    mask.style.left = "0px";
    mask.style.display = "block";

    pBody.appendChild(mask);

    var popup = document.createElement('div');
    popup.id = "popupDialog" + id;

    var pBody = document.body;

    if (typeof w == 'undefined')
    //w = getViewportWidth()-150;
        w = 950;
    if (typeof h == 'undefined')
        h = getViewportHeight() - 150;

    var left = Math.round(getViewportWidth() / 2 - w / 2);
    var top = Math.round(getViewportHeight() / 2 - h / 2);
    if (left < 0)
        left = 0;
    if (top < 0)
        top = 0;
    if (typeof (window.pageYOffset) != 'undefined')
        top += window.pageYOffset
    else
        top += document.documentElement.scrollTop;

    //alert(getViewportWidth() + ', ' + getViewportHeight() + '\r\n' + w + ', ' + h + '\r\n' + left + ', ' + top);

    popup.style.position = "absolute";
    popup.style.zIndex = gZIndex++;
    popup.style.top = "0px";
    popup.style.left = "0px";
    /////popup.style.display = "none";
    //popup.style.opacity = "1.0";

    popup.style.top = top + "px";
    popup.style.left = left + "px";

    popup.style.width = w + "px";
    popup.style.height = h + "px";

    //'<a href=javascript:windowClose(' + id + ')>Bezárás</a>' +

    popup.innerHTML =
    '<div class="boxp1"></div><div class="boxp2" style="height: ' + (h - 10) + 'px;">'
    //+ '<span style="position: absolute;"><a style="position: relative; top: 20px; left: 850px;" href=javascript:windowClose(' + id + ')>Bezárás</a></span>'
        + data + '</div><div class="boxp3"></div>';

    pBody.appendChild(popup);

    //opacity(mask, 0, 40, 5000);
    //fadeIn(mask, 0, 40, 2);
    //resizeUp(popup, 100, 400, 20);

    //fadeIn(popup, 0, 100, 30, 20);
    //fadeIn(mask, 0, 40, 11, 20);

    document.body.parentNode.className = 'stop_scroll';

    return id;
}

function getViewportHeight() {
    if (window.innerHeight != window.undefined) return window.innerHeight;
    if (document.compatMode == 'CSS1Compat') return document.documentElement.clientHeight;
    if (document.body) return document.body.clientHeight;
    return window.undefined;
}
function getViewportWidth() {
    if (window.innerWidth != window.undefined) return window.innerWidth;
    if (document.compatMode == 'CSS1Compat') return document.documentElement.clientWidth;
    if (document.body) return document.body.clientWidth;
    return window.undefined;
}

function returnpopup(retval) {
    var wo = window.parent;
    if (wo && wo.popupcallback) {
        var ret = retval.replace("\"", "\\\"").replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r")
        wo.setTimeout('window.popupcallback("' + ret + '");', 10);
        //wo.focus();
    }
    //window.close();
    exitpopup();
}

////

var str_ai_ci_re = /[áéíóöőúüű]/g;
var str_ai_ci_map = {'á':'a', 'é':'e', 'í':'i', 'ó':'o', 'ö':'o', 'ő':'o', 'ú':'u', 'ü':'u', 'ű':'u'};
function str_ai_ci(s) { // accent insensitive, case insensitive
    return (new String(s)).toLowerCase().replace(str_ai_ci_re, function(m) { return str_ai_ci_map[m]; });
}

function updatescenelist(order) {
    try {
        var cont = $('scenelistcontainer');
        cont.innerHTML = '';
        var otable = document.createElement('table');
        otable.className = 'list';
        otable.cellSpacing = 0;
        otable.cellPadding = 0;
        cont.appendChild(otable);
        var ocol = document.createElement('col');
        otable.appendChild(ocol);
        ocol = document.createElement('col');
        ocol.width = '90';
        ocol.style.width = '90px';
        otable.appendChild(ocol);

        var otbody = document.createElement('tbody');
        otable.appendChild(otbody);

        var cmpfunc = [
            function(a, b) { if (a.rank != b.rank) return a.rank - b.rank; if (a.lastevent == b.lastevent) { return str_ai_ci(a.title).localeCompare(str_ai_ci(b.title)); } if (a.lastevent < b.lastevent) return 1; else return -1; },
            function(a, b) { if (a.rank != b.rank) return a.rank - b.rank; return str_ai_ci(a.title).localeCompare(str_ai_ci(b.title)); }
        ];
        scenes.sort(cmpfunc[order]);

        for (var i = 0; i < scenes.length; i++) {
            var scene = scenes[i];

            var otr = document.createElement('tr');
            otbody.appendChild(otr);

            var otd1 = document.createElement('td');
            otd1.className = 'lptree_0';
            otr.appendChild(otd1);
            var oa = document.createElement('a');
            oa.href = scene.url;
            oa.className = scene.classname;
            oa.appendChild(document.createTextNode(scene.title));
            otd1.appendChild(oa);
            var ofrag = document.createElement('span');
            ofrag.innerHTML = scene.titleextra;
            otd1.appendChild(ofrag);

            var oediv = document.createElement('div');
            oediv.className = 'lp_events';
            oediv.innerHTML = scene.events;
            otd1.appendChild(oediv);

            var otd2 = document.createElement('td');
            otd2.innerHTML = '&#160;';
            otd2.width = '90';
            otr.appendChild(otd2);

        }

    } catch (e) { alert(e); }
}