﻿/***************** 
* Consts
*****************/
var MIN_HEIGHT = 682;

//Opens a new browser windows to print the current page.
function printPage(printUrl) {
    window.open(printUrl, "_blank","status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes,location=no");
}

/*
* Moves and expands the text field on the text pages.
* Instead of a fixed height the height is set to auto and the hidden div with the extra 
* text is made visible.
*/
function changeToBigTextfield(pageType) {
    if (document.getElementById) {

        var bodyHeight = MIN_HEIGHT;
        var pageWrapperObj = document.getElementById("PageWrapper");
        if (pageWrapperObj != null) {
            pageWrapperObj.style.height = 'auto';


            var contentObj = document.getElementById("Content");
            if (contentObj != null) {
                contentObj.style.top = 0 + 'px';
                contentObj.style.height = 'auto';
            }

            var contentTextWrapperObj = document.getElementById("ContentTextWrapper");
            if (contentTextWrapperObj != null) {
                contentTextWrapperObj.style.height = 'auto';
            }

            var additionalBodyTextObj = document.getElementById("AdditionalBodyText");
            if (additionalBodyTextObj != null) {
                additionalBodyTextObj.style.display = "block";
            }

            bodyHeight = Math.floor(pageWrapperObj.offsetHeight);
            if (bodyHeight < MIN_HEIGHT) {
                /*We do not want a page height smaller than MIN_HEIGHT so we reset the pageWrapper element to a fixed height.
                * We the set the text field to fit the page size.
                */
                pageWrapperObj.style.height = MIN_HEIGHT + 'px';
                setContentToPageSize(pageType, contentObj);
            }
            
            //We must hide the 'Read more' link
            var contentReadMoreObj = document.getElementById("ContentReadMore");
            if (contentReadMoreObj != null) {
                contentReadMoreObj.style.display = "none";
            }
            
            //We must make the toolbar with the CLOSE and PRINT buttons visible.
            var toolbarObj = document.getElementById("Toolbar");
            if (toolbarObj != null) {
                toolbarObj.style.display = "block";
            }
            
            //The footer should follow the the text field.
            var footerObj = document.getElementById("Footer");
            if (footerObj != null) {
                footerObj.style.position = "static";
            }

            //Now we must resize the flash element if the page has grown higher than MIN_HEIGHT
            var flashMenuContentObj = document.getElementById("FlashMenuContent");
            if (flashMenuContentObj != null) {
                var bodyHeight = Math.floor(pageWrapperObj.offsetHeight);
                if (bodyHeight > MIN_HEIGHT) {
                    if (document.all) {
                        //IE 8 does not redraw the flags just by resizing the flash object, so we trigger a redraw by first hiding the element.
                        flashMenuContentObj.style.display = "none";
                    }
                    flashMenuContentObj.style.height = bodyHeight + 'px';
                    if (document.all) {
                        flashMenuContentObj.style.display = "block";
                    }
                }
            }
        }
    }
}

/*
* When the text fit within the standard page size we set the size of the text field
* so it just fits the page.
*/
function setContentToPageSize(pageType, contentObj) {
    var contentTop = 10;
    var contentLeft;
    var contentWidth;
    var contentHeight = 662;
    switch (pageType) {
        case 1:
            {
                contentLeft = 150;
                contentWidth = 525;
                break;
            }
        case 2:
            {
                contentLeft = 0;
                contentWidth = 675;
                break;
            }
        case 3:
            {
                contentLeft = 225;
                contentWidth = 450;
                break;
            }
        default:
            {
                contentLeft = 225;
                contentWidth = 450;
                break;
            }
    }
    contentObj.style.left = contentLeft + 'px';
    contentObj.style.top = contentTop + 'px';
    contentObj.style.width = contentWidth + 'px';
    contentObj.style.height = contentHeight + 'px';
}

/* *************************************************************
* When the use clicks the CLOSE button we must restore the text field and the the other related
* elements.
*/
function changeToSmallTextfield(pageType) {
    if (document.getElementById) {

        var contentTop;
        var contentLeft;
        var contentWidth;
        var contentHeight;

        var contentTextWrapperTop = 0; ;
        var contentTextWrapperLeft = 0;
        var contentTextWrapperWidth;
        var contentTextWrapperHeight;
        switch (pageType) {
            case 1:
                {
                    contentLeft = 150;
                    contentTop = 150;
                    contentWidth = 525;
                    contentHeight = 450;

                    contentTextWrapperHeight = 420;
                    break;
                }
            case 2:
                {
                    contentLeft = 0;
                    contentTop = 300;
                    contentWidth = 675;
                    contentHeight = 300;

                    contentTextWrapperHeight = 270;
                    break;
                }
            case 3:
                {
                    contentLeft = 225;
                    contentTop = 150;
                    contentWidth = 450;
                    contentHeight = 450;

                    contentTextWrapperHeight = 420;
                }
            default:
                {
                    contentLeft = 225;
                    contentTop = 150;
                    contentWidth = 450;
                    contentHeight = 450;

                    contentTextWrapperHeight = 420;
                    break;
                }
        }


        var pageWrapperObj = document.getElementById("PageWrapper");
        if (pageWrapperObj != null) {
            pageWrapperObj.style.height = MIN_HEIGHT + 'px';
        }

        var contentObj = document.getElementById("Content");
        if (contentObj != null) {
            contentObj.style.left = contentLeft + 'px';
            contentObj.style.top = contentTop + 'px';
            contentObj.style.width = contentWidth + 'px';
            contentObj.style.height = contentHeight + 'px';
        }

        var contentTextWrapperObj = document.getElementById("ContentTextWrapper");
        if (contentTextWrapperObj != null) {
            contentTextWrapperObj.style.height = contentTextWrapperHeight + 'px';
        }

        var additionalBodyTextObj = document.getElementById("AdditionalBodyText");
        if (additionalBodyTextObj != null) {
            additionalBodyTextObj.style.display = "none";
        }

        var contentReadMoreObj = document.getElementById("ContentReadMore");
        if (contentReadMoreObj != null) {
            contentReadMoreObj.style.display = "block";
        }
        var toolbarObj = document.getElementById("Toolbar");
        if (toolbarObj != null) {
            toolbarObj.style.display = "none";
        }

        var footerObj = document.getElementById("Footer");
        if (footerObj != null) {
            footerObj.style.position = "absolute";
            footerObj.style.marginBottom = 0 + 'px';
        }

        var flashMenuContentObj = document.getElementById("FlashMenuContent");
        if (flashMenuContentObj != null) {
            if (document.all) {
                flashMenuContentObj.style.display = "none";
            }
            flashMenuContentObj.style.height = '100%';
            if (document.all) {
                flashMenuContentObj.style.display = "block";
            }
        }
    }
}

