﻿// JScript File
var strId = null;
function MoveToCenter(o_id)
{
    if (o_id==null)
    {
        if (strId==null)
        {
            return;
        }
        o_id = strId;
    }
    else
    {
        strId = o_id;
    }

    var oTag=document.getElementById(o_id);
    if(oTag==null)return;

    var iframeV = $get(o_id.replace("PanelPopupShow", "ExcelUpload"));
    var _scrollTop = 0;
    var _scrollLeft = 0;
    var _objWidth = 800;
    var _objHeight = 600;
    var _childWidth = Math.max(Math.max(iframeV.contentWindow.document.body.scrollWidth, iframeV.contentWindow.document.body.clientWidth), parseInt(iframeV.width));
    var _childHeight = Math.max(Math.max(iframeV.contentWindow.document.body.scrollHeight, iframeV.contentWindow.document.body.clientHeight), parseInt(iframeV.height));
    if (typeof(window.pageYOffset)!= 'undefined')
    {
        _scrollTop = parseInt(window.pageYOffset);
        _scrollLeft = parseInt(window.pageXOffset);
    }
    else if (typeof(document.compatMode) != 'undefined' && document.compatMode != 'BackCompat')
    {
        _scrollTop = parseInt(document.documentElement.scrollTop);
        _scrollLeft = parseInt(document.documentElement.scrollLeft);
        _objWidth = Math.min(document.documentElement.clientWidth, document.documentElement.offsetWidth);
        _objHeight = Math.min(document.documentElement.clientHeight, document.documentElement.offsetHeight);
    }
    else if (typeof(document.body) != 'undefined')
    {
        _scrollTop = parseInt(document.body.scrollTop);
        _scrollLeft = parseInt(document.body.scrollLeft);
        _objWidth = Math.min(document.body.scrollWidth, document.documentElement.offsetWidth);
        _objHeight = Math.min(document.body.scrollHeight, document.documentElement.offsetHeight);
    }

    _objWidth = Math.min(_childWidth, _objWidth);


    if (4 / 3 > _objWidth / _objHeight) _objHeight = parseInt(3 * _objWidth / 4);
    _scrollLeft = (document.documentElement.clientWidth - _objWidth) /2 + _scrollLeft + 5;

    setTagPositionWidthHeight(o_id, _scrollLeft, _scrollTop, _objWidth, _objHeight);
   // setTagPositionWidthHeight(o_id, -1, -1, _objWidth, _objHeight);

}

function setTagPositionWidthHeight(o_id,  left, top, width, height)
{
    var popShow = $get(o_id);
    var popHead = $get(o_id.replace("PanelPopupShow", "PanelPopupHead"));
    var popBody = $get(o_id.replace("PanelPopupShow", "PanelPopupBody"));
    var iframeV = $get(o_id.replace("PanelPopupShow", "ExcelUpload"));

    popShow.style.position = 'absolute';
    if (left >= 0 && top >= 0)
    {
        popShow.style.left = left + 'px';
        popShow.style.top = top + 'px';
    }
    else
    {
        popShow.style.left = (screen.availWidth - width) /2  - window.screenLeft + 'px';
        popShow.style.top = (screen.availHeight -  height) /2  - window.screenTop + 'px';
    }

    popShow.style.width = width + "px";
    popHead.style.width = width + "px";
    iframeV.width = width - 3 + "px";

    popBody.style.height = height + "px";
    iframeV.style.height = height - 5 + "px";

    // iframeV.contentWindow.document.body.style.margin = "0px";
    // iframeV.contentWindow.document.body.style.padding = "0px";
    // popHead.innerText = popShow.style.width;
}

window.onresize = MoveToCenter;