﻿function toggle(div_id) {
    var el = document.getElementById(div_id);
    if (el.style.display == 'none') el.style.display = 'block';
    else el.style.display = 'none';
}
function overlay_size(popUpDivVar,divHeight) {
    if (typeof window.innerWidth != 'undefined') {
        viewportheight = window.innerHeight;
    }
    else {
        viewportheight = document.documentElement.clientHeight;
    }
    if ((viewportheight > document.body.scrollHeight) && (viewportheight > document.body.clientHeight)) {
        overlay_height = viewportheight;
    }
    else {
        if (document.body.clientHeight > document.body.scrollHeight) {
            overlay_height = document.body.clientHeight;
        }
        else {
            overlay_height = document.body.scrollHeight;
        }
    }
    var overlay = document.getElementById('overlay');
    overlay.style.height = overlay_height + 'px';
    var ScrollTop = document.body.scrollTop;
    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
    var popUpDiv = document.getElementById(popUpDivVar);
    popUpDiv_height = viewportheight / 2 - divHeight/2;
    popUpDiv.style.top = ScrollTop + popUpDiv_height + 'px';
}
function window_pos(popUpDivVar,divWidth) {
    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerHeight;
    }
    else {
        viewportwidth = document.documentElement.clientHeight;
    }
    if ((viewportwidth > document.body.scrollWidth) && (viewportwidth > document.body.clientWidth)) {
        window_width = viewportwidth;
    }
    else {
        if (document.body.clientWidth > document.body.scrollWidth) {
            window_width = document.body.clientWidth;
        }
        else {
            window_width = document.body.scrollWidth;
        }
    }
    var popUpDiv = document.getElementById(popUpDivVar);
    window_width = window_width / 2 - divWidth/2;
    popUpDiv.style.left = window_width + 'px';
}
function popup(windowname,divWidth,divHeight) {
    overlay_size(windowname,divHeight);
    window_pos(windowname,divWidth);
    toggle('overlay');
    toggle(windowname);
}
function clearPopup(windowname) {
    document.getElementById('overlay').style.display = 'none';
    document.getElementById(windowname).style.display = 'none';
}
function trim(str) {
    str = str.replace(/^\s+/, '');
    for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    return str;
}
