// JavaScript for Popup Window

		var _overlayWidth = 900;
        var _overlayHeight = 620;
        var _expandWidthStep = 45;
        var _expandHeightStep = 30;
        var _expandStepSpeed = 5;
        
        var _windowWidth = 0;
        var _windowHeight = 0;
        var _scrollWidth = 0;
        var _scrollHeight = 0;
        var _opening = 0;

        function loadOverlayPanel(overlayPanelId, sectionId, overlayWidth, overlayHeight) {
            if (_opening == 0) {
                var targetWidth = _overlayWidth;
                var targetHeight = _overlayHeight;
                
                _opening = 1;

                var divs = document.getElementsByTagName("DIV");
                var divIndex = 0; var currentDiv = null;
                for (divIndex = 0; divIndex < divs.length; divIndex++) {
                    currentDiv = divs[divIndex];
                    if (currentDiv.attributes["overlay"] != null && currentDiv.attributes["overlay"].value == "true") {
                        if (currentDiv.id != overlayPanelId) {
                            hidePanel(currentDiv, 1);
                            hidePanel(firstChild(currentDiv));
                        }
                    }
                }

                if (overlayWidth != undefined && overlayWidth != null) {
                    targetWidth = parseInt(overlayWidth);
                }
                if (overlayHeight != undefined && overlayHeight != null) {
                    targetHeight = parseInt(overlayHeight);
                }

                var panel = document.getElementById(overlayPanelId);
                showPanel(panel);
                
                calculateSize();
                getScrollXY();
                centerInScreen(panel);

                expandOverlayPanel(overlayPanelId, sectionId, targetWidth, targetHeight);
            }
        }

        function expandOverlayPanel(overlayPanelId,sectionId,targetWidth,targetHeight) {
            var panel = document.getElementById(overlayPanelId);
            var width = parseInt(panel.style.width.replace("px", ""));
            var height = parseInt(panel.style.height.replace("px", ""));
            var newWidth, newHeight;

            if (width < targetWidth) {
                newWidth = (width + ((width + _expandWidthStep) >= targetWidth ? targetWidth - width : _expandWidthStep));
                panel.style.width = newWidth + "px";
            }
            if (height < targetHeight) {
                newHeight = (height + ((height + _expandHeightStep) >= targetHeight ? targetHeight - height : _expandHeightStep));
                panel.style.height = newHeight + "px";
            }
            centerInScreen(panel);

            if (newWidth < targetWidth || newHeight < targetHeight) {
                window.setTimeout("expandOverlayPanel('" + overlayPanelId + "','" + sectionId + "'," + targetWidth + "," + targetHeight + ")", _expandStepSpeed);
            }
            else {
                panel = firstChild(document.getElementById(overlayPanelId));
                showPanel(panel);
                openSection(sectionId);
                _opening = 0;
            }
        }

        function centerInScreen(panel) {
            width = parseInt(panel.style.width.replace("px", ""));
            height = parseInt(panel.style.height.replace("px", ""));
            //the next two lines control the location of the popup in the window
			panel.style.left = ((((_windowWidth > width ? _windowWidth - width : 0)) / 1.9) + _scrollWidth) -20 + "px";
            panel.style.top = ((((_windowHeight > height ? _windowHeight - height : 0)) / 1.8) + _scrollHeight) -20 + "px";            
        }

        function openSection(sectionId) {
            var divs = document.getElementsByTagName("DIV");
            var divIndex = 0; var currentDiv = null;
            for (divIndex = 0; divIndex < divs.length; divIndex++) {
                currentDiv = divs[divIndex];
                if (currentDiv.attributes["section"] != null && currentDiv.attributes["section"].value == "true") {
                    if (currentDiv.id == sectionId) {
                        showPanel(currentDiv);
                    }
                    else {
                        hidePanel(currentDiv);
                    }
                }
            }
        }

        function hideOverlayPanel(overlayPanelId, stopElementId) {
            hidePanel(firstChild(document.getElementById(overlayPanelId)));
            hidePanel(document.getElementById(overlayPanelId), 1);

            if (stopElementId != undefined && stopElementId != null) {
                var element = document.getElementById(stopElementId);
                document.getElementById(stopElementId).parentNode.replaceChild(element, document.getElementById(stopElementId));
            }
        }

        function hidePanel(panelId, includeSize) {
            var panel = (typeof panelId == "string" ? document.getElementById(panelId) : panelId);
            panel.style.visibility = "hidden";
            panel.style.display = "none";
            if (includeSize != undefined && includeSize != null && includeSize == 1) {
                panel.style.width = "0px";
                panel.style.height = "0px";
            }
        }

        function showPanel(panelId) {
            var panel = (typeof panelId == "string" ? document.getElementById(panelId) : panelId);
            panel.style.visibility = "visible";
            panel.style.display = "block";
        }

        function firstChild(panel) {
            return panel.getElementsByTagName("DIV")[0];
        }

        function calculateSize() {
            var myWidth = 0, myHeight = 0;
            if (typeof (window.innerWidth) == 'number') {
                //Non-IE
                myWidth = window.innerWidth;
                myHeight = window.innerHeight;
            } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                //IE 6+ in 'standards compliant mode'
                myWidth = document.documentElement.clientWidth;
                myHeight = document.documentElement.clientHeight;
            } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
            
            _windowWidth = myWidth;
            _windowHeight = myHeight;
        }

        function getScrollXY() {
            var scrOfX = 0, scrOfY = 0;
            if (typeof (window.pageYOffset) == 'number') {
                //Netscape compliant
                scrOfY = window.pageYOffset;
                scrOfX = window.pageXOffset;
            } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
                //DOM compliant
                scrOfY = document.body.scrollTop;
                scrOfX = document.body.scrollLeft;
            } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
                //IE6 standards compliant mode
                scrOfY = document.documentElement.scrollTop;
                scrOfX = document.documentElement.scrollLeft;
            }

            _scrollWidth = scrOfX;
            _scrollHeight = scrOfY;
        }
