﻿
var oMyElement; //Script-level variable to hold reference to object as it's moved within the DOM tree

function CTDetailsLinks_closePopup(oElementID)
{
//    alert(oElementID);
//    var oElement = document.getElementById(oElementID);
//    alert(oElement.style.display);
//    oElement.style.display = "none";
    //    alert(oElement.style.display);

    oMyElement.style.display = "none";
    objDiv = document.getElementById("CTPopupBackground");
    objDiv.style.display = "none";
    //document.body.style.overflow = "visible";
    return false;
}

function CTDetailsLinks_showPopup(oElement, sElementName)
{
    try {

        //document.body.style.overflow = "hidden";
        oMyElement = oElement;
        
        var elDisplay = getStyle(oElement, 'display');
        //alert(elDisplay);

        if (elDisplay == 'block') return;
        
        var winWidth = window.innerWidth;
        if (winWidth==undefined)
        {
            winWidth = document.body.clientWidth; //+16;
        } else {
            var sbWidth =getScrollerWidth();
            //alert(sbWidth);
            winWidth = winWidth - sbWidth;
        }
        var winHeight = window.innerHeight;
        if (winHeight==undefined)
        {
            winHeight = document.documentElement.clientHeight;
        }
        var scroll_top = window.pageYOffset;
        if (scroll_top==undefined)
        {
            scroll_top = document.documentElement.scrollTop;
        }

        objDiv = document.getElementById("CTPopupBackground");
        if (objDiv == undefined) {
            objDiv = document.createElement('div');
            objDiv.id = 'CTPopupBackground';
            document.body.appendChild(objDiv);
        }
        objDiv.style.display = "block";

        objModalWindow = document.getElementById("modal-window");
        if (objModalWindow == undefined) {
            objModalWindow = document.createElement('div');
            objModalWindow.id = 'modal-window';
            document.body.appendChild(objModalWindow);
        }
        objModalWindow.style.display = "block"; 

        var arrayPageSize = getPageSize();
        //objDiv.style.height = arrayPageSize[1] + "px";

        //Set inner box position
        var elWidth = getStyle(oElement, 'width').replace('px', '')
        var elHeight = getStyle(oElement, 'height').replace('px', '')

        //oElement.style.left = (winWidth - elWidth) / 2 + "px";
        oElement.style.display = "block";
        oElement.style.position = "fixed";
        oElement.style.top = "50%";
        oElement.style.left = "50%";
        oElement.style.marginTop = "-" + elHeight / 2 + "px";
        oElement.style.marginLeft = "-" + elWidth / 2 + "px";
        
        //document.body.appendChild(oElement);
        objModalWindow.appendChild(oElement);
        document.getElementById('Form').appendChild(objModalWindow);


        //IE6 does not support "fixed" positioning, so handle differently
        var isIE6 = isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1; ///msie|MSIE 6/.test(navigator.userAgent);
        if (isIE6) {
            //oElement.style.position = "absolute";
            //oElement.style.top = scroll_top + (winHeight - elHeight) / 2 + "px";
            //oElement.style.marginTop = (0 - parseInt(oElement.offsetHeight / 2)) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + "px";
            //alert(oElement.style.marginTop);
            if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
                jQuery("body", "html").css({ height: "100%", width: "100%" });
            }
        } else {
        }
    }
    catch(e)
    {
        alert(e);
        //alert(sElementName + " has not been configured");
    }
    return false
}

function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;
    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';
    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';
    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);
    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;
    // Remove the scrolling div from the doc
    document.body.removeChild(
    document.body.lastChild);
    // Pixel width of the scroller
    return (wNoScroll - wScroll);
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}

function getStyle(el, style) {
    if (!document.getElementById) return;

    var value = el.style[style];

    if (!value)
        if (document.defaultView)
        value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);

    else if (el.currentStyle)
        value = el.currentStyle[style];

    return value;
}