﻿var overlayW = false;

function getElById(e) {
    e = document.getElementById(e);
    return e;
}

function positionOverlayWindow() {
    navigatorX = document.body.clientWidth;
    navigatorY = document.body.clientHeight;
    scrollTop = document.body.scrollTop;

    if (browser == "Opera") {
        navigatorX = document.documentElement.clientWidth;
        navigatorY = document.documentElement.clientHeight;
        scrollTop = document.documentElement.scrollTop;
    }

    overlay.style.width = navigatorX + "px";
    overlay.style.height = navigatorY + "px";
    overlayWindow.style.top = (navigatorY - overlayWindow.clientHeight) / 2 + scrollTop + "px";
    overlayWindow.style.left = (navigatorX - overlayWindow.clientWidth) / 2 + "px";

    overlayW = true;
}


function detectBrowser() {
    navAgent = navigator.userAgent;

    if (navAgent.indexOf("MSIE") > 0) {
        browser = "IE";
    }

    if (navAgent.indexOf("Opera") > 0) {
        browser = "Opera";
    }

    if (navAgent.indexOf("Firefox") > 0) {
        browser = "Firefox";
    }

    return browser;
}

function OverlayWindow(url) {

    invisibleSelectBox(1);

    if (getElById("overlay") == null) {

        overlay = document.createElement("div");
        overlay.setAttribute("id", "overlay");
        //overlay.setAttribute("onclick","closeOverlayWindow();");
        document.body.appendChild(overlay);

        overlayWindow = document.createElement("div");
        overlayWindow.setAttribute("id", "overlay-window");
        overlayWindow.innerHTML = "<div class=\"clearfix\" id=\"overlay-top\"><a class=\"close\" href=\"javascript:closeOverlayWindow();\">Kapat</a></div>";
        overlayWindow.innerHTML += "<iframe id=\"overlayFrame\" src=\"" + url + "\" frameborder=\"0\" scrolling=\"no\"></iframe>";
        document.body.appendChild(overlayWindow);

        detectBrowser();
        positionOverlayWindow();
    }

}

function closeOverlayWindow() {
    invisibleSelectBox(0);

    document.body.removeChild(overlayWindow);
    document.body.removeChild(overlay);

    overlayW = false;
}

function invisibleSelectBox(argument) {

    // invisible select box in #content2
    if (getElById("content2") != null) {
        var content2 = getElById("content2");
        var selectBoxCollection = content2.getElementsByTagName("select");

        if (argument == 1) {
            for (var i = 0; i < selectBoxCollection.length; i++) {
                selectBoxCollection[i].style.visibility = "hidden";
            }
        }

        // visible select box in #content2
        else {
            for (var i = 0; i < selectBoxCollection.length; i++) {
                selectBoxCollection[i].style.visibility = "visible";
            }
        }
    }
}

window.onresize = function() {
    if (getElById("overlay") != null) {
        positionOverlayWindow();
    }
};
