String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
}
function sleep(millis)
{
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while(curDate-date < millis);
} 
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else 
    {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else 
        {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}

	return windowHeight;
}
function setFooter() {
 
    var SetContentDivs = true;
    var minusBorderHeight = 0;
    /* this must be equal to 4 * border px for content-middle */
    var BorderOffsetShow = 32;

	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {

            /* grab elements which make up the height of the document */
			var headerHeight = document.getElementById('header-div').offsetHeight;
			var contentHeight = document.getElementById('content-middle').offsetHeight;
			var LEFTcontentHeight = document.getElementById('content-left').offsetHeight;
			var RIGHTcontentHeight = document.getElementById('content-right').offsetHeight;

            /* if we already matched up the heights in a previous call */
            /* THIS STOPS IE7 GETTING STUCK IN AN INFINATE LOOP DUE TO RESIZE CALLS */
            if((contentHeight + BorderOffsetShow) == LEFTcontentHeight && RIGHTcontentHeight == LEFTcontentHeight) {
                SetContentDivs = false;
            }

            if(SetContentDivs) {

                /* work out which of the three content elements has expanded the most */
			    if((LEFTcontentHeight > RIGHTcontentHeight) && LEFTcontentHeight > contentHeight) {
			        contentHeight = LEFTcontentHeight;
			    } else if (RIGHTcontentHeight > contentHeight) {
			        contentHeight = RIGHTcontentHeight;
			    }

                /* grab all content-div elements */
                var contentElementMid = document.getElementById('content-middle');
                var contentElementLeft = document.getElementById('content-left');
                var contentElementRight = document.getElementById('content-right');
            }

            /* grab the overall container element */
			var containerElement = document.getElementById('container');

            /* grab the footer element and get it's height */
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;

            /* calculate total page height */
            var pageHeight = (contentHeight + headerHeight + footerHeight);
            
			if (windowHeight - pageHeight >= 0) {

                /* set footer position */
				footerElement.style.position = 'absolute';
				footerElement.style.top = (windowHeight - footerHeight) + 'px';
				footerElement.style.left = '0px';
                
                if(containerElement.offsetHeight < contentHeight) {
                    /* set container height */
                    containerElement.style.height = (windowHeight - containerElement.style.top) + 'px';
                }

			}
			else {

				footerElement.style.position = 'absolute';
				footerElement.style.left = '0px';

                /* set footer position */
				footerElement.style.top = (contentHeight + headerHeight) + 'px';
                
                if(containerElement.offsetHeight < contentHeight) {
                    /* set container height */
                    containerElement.style.height = (pageHeight - containerElement.style.top) + 'px';
                }
			}


            if(SetContentDivs) {
                /* expand all columns to longest length column */
                contentElementMid.style.height = (contentHeight - BorderOffsetShow) + 'px';
                contentElementLeft.style.height = contentHeight + 'px';
                contentElementRight.style.height = contentHeight  + 'px';
            }

            /* turn footer visibility on */
            footerElement.style.visibility = 'visible';

            //if(confirm('resized?') != true) {
            if(false) {
                return false;
            }
		}
	}
}

window.onload = function() {
    setFooter();
}

window.onresize = function() {
	setFooter();
}
