﻿/* 
    Page Resize Code 
    
    
    Include this code somewjere in you .aspx file and ensure that you have the outer <div>
    with an ID that is e.g. in this example it is "TopFrame".   Change the line TopFrameID = "TopFrame";
    in the ResizePageElements() function as required.
    
    The code works out the height of this element and uses this to center it vertically.
        
*/

function ResizePageElements() {
    //Set the height to sit in thye centre of the browser window vertically
    var TopFrameID;
    var TopFrame;
    var VerticalSpace;

    TopFrameID = "TopFrame";
    VerticalSpace = GetWindowHeight() - GetElementHeight(TopFrameID);
    if (VerticalSpace > 0)
        NewTop = VerticalSpace / 2 - 10;
    else
        NewTop = 0;
    TopFrame = document.getElementById(TopFrameID);
    TopFrame.style.top = NewTop + "px";
}


function GetWindowHeight() {
    if (document.documentElement.clientHeight > 0)
        return document.documentElement.clientHeight;
    return document.body.clientHeight;
}

function GetWindowWidth() {
    GetWindowSize();
    return myWidth;
    if (document.window.innerWidth > 0)
        return document.window.innerWidth;
    if (document.documentElement.clientWidth > 0)
        return document.documentElement.clientWidth;
    return document.body.clientWidth;
}

var myWidth = 0, myHeight = 0;

function GetWindowSize() {
    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;
    }
    //window.alert( 'Width = ' + myWidth );
    //window.alert( 'Height = ' + myHeight );
}


function GetElementHeight(Elem) {

    if (document.getElementById) {
        var elem = document.getElementById(Elem);
    }
    else if (document.all) {
        var elem = document.all[Elem];
    }

    xPos = elem.offsetHeight;
    return xPos;
}

function GetElementWidth(Elem) {

    if (document.getElementById) {
        var elem = document.getElementById(Elem);
    }
    else if (document.all) {
        var elem = document.all[Elem];
    }

    yPos = elem.offsetWidth;
    return yPos;
}

function GetElementTop(Elem) {

    if (document.getElementById) {
        var elem = document.getElementById(Elem);
    }
    else if (document.all) {
        var elem = document.all[Elem];
    }
    yPos = elem.offsetTop;
    tempEl = elem.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

//Hook up to page events when the frame is loaded	

window.onload = ResizePageElements;
window.onresize = ResizePageElements;
