function PopupWindow()
{

    

}

PopupWindow.prototype = {

    popupName: 'PopupGenericWindow',
    popupBlockName: 'PopupGenericWindowBlock',
    popupTitle: '',
    popupWidth: 100,
    popupHeight: 100,
    popupPathContent: '',
    popupPathImages: '/JSFiles/Plugins/PopupWindow/Images/',

    setPopupTitle: function(popupTitle)
    {
        this.popupTitle = popupTitle;
    },

    setPopupWidth: function(popupWidth)
    {
        this.popupWidth = popupWidth;
    },

    setPopupHeight: function(popupHeight)
    {
        this.popupHeight = popupHeight;
    },

    setPopupPathContent: function(popupPathContent)
    {
        this.popupPathContent = popupPathContent;
    },

    scrollY:function()
	{

        /*var ie5 = document.all&&document.getElementById;
		var ns6 = document.getElementById&&!document.all;

        return (ns6) ? window.pageYOffset : document.body.scrollTop;
        */

        var scrollX, scrollY;

        if (document.all)
        {
            if (!document.documentElement.scrollLeft)
                scrollX = document.body.scrollLeft;
            else
                scrollX = document.documentElement.scrollLeft;

            if (!document.documentElement.scrollTop)
                scrollY = document.body.scrollTop;
            else
                scrollY = document.documentElement.scrollTop;
        }
        else
        {
            scrollX = window.pageXOffset;
            scrollY = window.pageYOffset;
        }

        return scrollY;

	},

    iecompattest:function()
	{
		return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	},

    adjustPosition: function()
	{

        var ie5 = document.all&&document.getElementById;
		var ns6 = document.getElementById&&!document.all;
        
		var winBrowserWidth = ns6? window.innerWidth-20 : this.iecompattest().clientWidth;
		var winBrowserHeight = ns6? window.innerHeight-20 :this.iecompattest().clientHeight;
        
		var winX = Math.ceil((winBrowserWidth - this.popupWidth) / 2);
		var winY = Math.ceil((winBrowserHeight - this.popupHeight) / 2);

		document.getElementById(this.popupName).style.left = winX + 'px';
		document.getElementById(this.popupName).style.top = (this.scrollY() + winY) + 'px';

        document.getElementById(this.popupBlockName).style.width = document.body.scrollWidth;
		document.getElementById(this.popupBlockName).style.height = document.body.scrollHeight;
                
	},

    generate: function()
    {

        var popupWindow = '';
        var buttonCloseSize = 48;
        var titleHeight = 38;
        
        popupWindow += '<div id="PopupGenericWindow" sytle="width:' + this.popupWidth + 'px; height:' + this.popupHeight + 'px;">';
        popupWindow += '<table width="' + this.popupWidth + '" border="0" cellspacing="0" cellpadding="0">';
        popupWindow += '<tr>';
        popupWindow += '<td width="' + (this.popupWidth - buttonCloseSize) + '" class="PopupWindowTitle">' + this.popupTitle + '</td>';
        popupWindow += '<td width="28" class="PopupWindowTitle">';
        popupWindow += '<a href="javascript:;" onclick="closePopupWindow(\'' + this.popupName +'\',\'' + this.popupBlockName +'\');"><img src="' + this.popupPathImages + 'CloseButton.gif" width="28" height="27" border="0" /></a>';
        popupWindow += '</td>';
        popupWindow += '</tr>';
        popupWindow += '<tr>';
        popupWindow += '<td colspan="2" height="' + (this.popupHeight - titleHeight) + '" class="PopupWindowContent">';
        popupWindow += '<iframe name="FloatingLayerContent" allowtransparency="false" id="FloatingLayerContent" src="' + this.popupPathContent + '" width="100%" height="100%" style="width:100%; height:100%;" frameborder="no"></iframe>';
        popupWindow += '</td>';
        popupWindow += '</tr>';
        popupWindow += '</table>';
        popupWindow += '</div>';
        popupWindow += '<div id="PopupGenericWindowBlock"></div>';

        
        document.body.innerHTML = document.body.innerHTML + popupWindow;
        
    },

    changeVisibility: function(visible)
    {

        if (visible)
        {

            document.getElementById(this.popupName).style.display = 'inline';
            document.getElementById(this.popupBlockName).style.display = 'inline';

        }
        else
        {

            document.getElementById(this.popupName).style.display = 'none';
            document.getElementById(this.popupBlockName).style.display = 'none';

        }

    },

    open: function()
    {

        var p1 = document.getElementById(this.popupName);
        var p2 = document.getElementById(this.popupBlockName);

        if (p1) document.body.removeChild(p1);

        if (p2) document.body.removeChild(p2);
        
        // gera o html
        this.generate();

        // centraliza a popup
        this.adjustPosition();

        // mostra a popup
        this.changeVisibility(true);

    }

}

function closePopupWindow(pName,pBlockName)
{

    var p1 = document.getElementById(pName);
    var p2 = document.getElementById(pBlockName);

    document.body.removeChild(p1);
    document.body.removeChild(p2);

}