﻿// JScript File

function closeWindow(id)
{
    var popupStyle = document.getElementById(id).style;
    popupStyle.display = "none";
    
    var parent = document.getElementById("imgPopupInner");
    var elementVar = document.getElementById("fullImage");
    
    if (elementVar != null)
    parent.removeChild(elementVar);
}
function openImage(popupId, imageUrl, width, height, text)
{
    closeWindow(popupId);
    var imgObj = document.createElement('img');
    
    imgObj.setAttribute('id', 'fullImage');
    imgObj.setAttribute('alt', 'Full image');
    imgObj.setAttribute('src', imageUrl);
    
    var popup = document.getElementById(popupId);
    popup.style.width = width + "px";
    popup.style.padding = "10px";
    var closeBtn = document.getElementById('imgCloseBtn');
    closeBtn.style.top = ( -1 * (height - 10)) + "px";
    
    popup.style.margin = "0px auto";

    closeBtn.parentNode.insertBefore(imgObj, closeBtn);

    if (text != null)
    {
        var imgText = document.getElementById("popupText");
        if (imgText == null)
        {
            imgText = document.createElement('span');
            imgText.setAttribute('id', 'popupText');
        }
        
        imgText.className = "popupText";
        imgText.innerHTML = text;
        closeBtn.parentNode.appendChild(imgText); 
    }
    
    SetToScroll('imgPopup');
    openWindow(popupId);
}
function SetToScroll(id)
{
    var popupStyle = document.getElementById(id).style;
    popupStyle.position = "absolute";
    popupStyle.top = (document.documentElement.scrollTop + 20) + "px";
    popupStyle.left = "0px";
    popupStyle.margin = "0px auto";
}
function openAndScroll(id)
{
    openWindow(id);
    SetToScroll(id);
    return false;
}
function openWindow(id)
{
    var popupStyle = document.getElementById(id).style;
    
    if (popupStyle.display == "block")
        popupStyle.display = "none";
    else
        popupStyle.display = "block";
}
