﻿function openPopup(id, url, filename) {

    var windowWidth = pageWidth();
    var windowHeight = pageHeight();

    //    if (parseInt(navigator.appVersion) > 3) {
    //        if (navigator.appName == "Netscape") {
    //            windowWidth = window.innerWidth;
    //            windowHeight = window.innerHeight;
    //        }
    //        if (navigator.appName.indexOf("Microsoft") != -1) {
    //            windowWidth = document.body.offsetWidth;
    //            windowHeight = document.body.offsetHeight;
    //        }
    //    }



    var popupwidth = $('#popup' + id).width();
    var left = (windowWidth - popupwidth) / 2;

    var popupheight = $('#popup' + id).height();
    var top = (windowHeight - popupheight) / 2;
    if (top < 20) top = 20;
    $('#popup' + id).show();
    $('#popup' + id).css("left", left);
    $('#popup' + id).css("top", top);
    var timeticks = new Date().getTime();
    var html = $('#popup' + id).html();
    if (html != null) {
        //haal oude iframe eruit
        var posIFrame = html.indexOf("<IFRAME");
        if (posIFrame > 0) {
            html = html.substring(0, posIFrame);
        }
        //vervang tags
        html = html.replace('{fileurl}', url);
        html = html.replace('{filename}', filename);
        //iframe terugplaatsen in popup
        $('#popup' + id).html(html + '<iframe src="' + url + '?' + timeticks + '" scrolling="auto" width="100%" height="100%"/>');
        var backColor = $('#hiddenPopupShadowColor' + id).val();
        var opacity = $('#hiddenPopupShadowOpacity' + id).val();
        $('#modalBackground').show();
        $('#modalBackground').css('background-color', backColor);
        $('#modalBackground').css('filter', 'Alpha(Opacity=' + opacity + ')');
        $('#modalBackground').css('moz-opacity', '0.' + opacity);
        $('#modalBackground').css('opacity', '0.' + opacity);
        $('#closePopup' + id).click(function() {
            $('#popup' + id).hide();
            $('#modalBackground').hide();
        });
    }
}

function pageWidth() {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pageHeight() {
    return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
}

function posLeft() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function posTop() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function posRight() {
    return posLeft() + pageWidth();
}

function posBottom() {
    return posTop() + pageHeight();
}
    
    