var viewportwidth;
var viewportheight;
var debug = false;
var debugBrowserVersion = false;

 function getViewportWidthHeight() {
     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
     if (typeof window.innerWidth != 'undefined') {
         viewportwidth = window.innerWidth;
         viewportheight = window.innerHeight
     }
     // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
     else if (typeof document.documentElement != 'undefined' &&
              typeof document.documentElement.clientWidth != 'undefined' && 
              document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth;
        viewportheight = document.documentElement.clientHeight
     }
     // older versions of IE
     else {
         viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
         viewportheight = document.getElementsByTagName('body')[0].clientHeight
     }
 }

 function getBrowser() {
     return navigator.appName;
 }
 
 function getBrowserVersion(){
     return (parseInt(navigator.appVersion));
 }

 function isIE5() {
     return ie5;
 }
 function isIE6() {
     return ie6;
 }
 function isIE7() {
     //var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
     //return ie7;
     return ie7;
 }
 function isIE8() {
     return ie8;
 }
   

 function recalcPageContentHeight(){
	 if (document.getElementById) {  
           //Get Heights of objects inside page_content
           //-------------------------------------------------------
            //actual height of an object on the browser's window
            var Menu_Container_height = getElementByIdHeight('Menu_Container');
            if (debug == true) { alert('Menu_Container_height = ' + Menu_Container_height); }

			var Container_height = getElementByIdHeight('DescriptionContainer');
            if (debug == true) { alert('Container_height = ' + Container_height); }
            
            var separator_height = getElementByIdHeight('separator');
            if (debug == true) { alert('separator_height = ' + separator_height); }
            //-------------------------------------------------------

            //-------------------------------------------------------
            var new_page_content_height = (Menu_Container_height + Container_height + separator_height);
            //-------------------------------------------------------
            
            //Set new heights of page_content div
			//-------------------------------------------------------
			  var intExtraHeight  = 30;
              new_page_content_height = new_page_content_height + intExtraHeight;
              
			  if (getElementByIdHeight('page_content') != new_page_content_height){
				  setElementByIdHeight('page_content', new_page_content_height  + 'px');	//when setting style height of a div tag resize event ocueres			
			  }			
            //-------------------------------------------------------            
        }
 }

 
 function setMainContainerHeight() {
    recalcPageContentHeight();
	
    getViewportWidthHeight();
	if (viewportheight > 0) {
        if (document.getElementById) {
           
           //Get Heights of objects
           //-------------------------------------------------------
            //actual height of an object on the browser's window
            var header_height = getElementByIdHeight('site_header_main');
            if (debug == true) { alert('header_height = ' + header_height); }

			var page_content_height = getElementByIdHeight('page_content');
            if (debug == true) { alert('page_content_height = ' + page_content_height); }
            
            var footer_height = getElementByIdHeight('page_footer');
            if (debug == true) { alert('footer_height = ' + footer_height); }
            //-------------------------------------------------------

            //-------------------------------------------------------
            var site_content_height = (header_height + page_content_height + footer_height)
            //-------------------------------------------------------


            //Get index, Adjustion for different browsers
            //-------------------------------------------------------
            var intExtraHeight = -2;
            //Set For all old IE browsers
            //IE5-6
            if ((getBrowser() == "Microsoft Internet Explorer") && ((isIE5() == true) || (isIE6() == true))) {
                intExtraHeight = -2;
                if (debugBrowserVersion == true) {
                    alert('IE5-6 used. isIE5() = ' + isIE5() + '. isIE6() = ' + isIE6() + '');
                    alert('version = ' + getBrowserVersion());
                }
            }
            //IE7
            if ((getBrowser() == "Microsoft Internet Explorer") && (isIE7() == true)) {
                intExtraHeight = 0;
                if (debugBrowserVersion == true) {
                    alert('IE7 used. isIE7=true.');
                    alert('version = ' + getBrowserVersion());
                }
            }             
            //If client uses IE8
            if ((getBrowser() == "Microsoft Internet Explorer") && (isIE8() == true)) {//(getBrowserVersion()>=8)) {
                intExtraHeight = -20;
                if (debugBrowserVersion == true) {
                    alert('IE8 used.');
                    alert('version = ' + getBrowserVersion());
                }
            }
            //'Google Chrome' browser & 'Netscape Navigator' & Safari
            //For these browsers Broser is 'Netscape' Vesion is '5'
            if (getBrowser() == "Netscape") {
                intExtraHeight = -20;
                if (debugBrowserVersion == true) {
                    alert(getBrowser() + '. Version = ' + getBrowserVersion());
                }                
            }
            if (getBrowser() == "Opera") {
                intExtraHeight = -20;
                if (debugBrowserVersion == true) {
                    alert(getBrowser() + '. Version = ' + getBrowserVersion());
                }                 
            }
			
            if (debug == true) { alert('Browser intExtraHeight = ' + intExtraHeight) }
            //-------------------------------------------------------
            
            //Set new heights of page_content div
			//-------------------------------------------------------
            var NewHeight = 0; //for page_content
            if (site_content_height < viewportheight) {
                if (debug == true) {
                    alert('site_content_height < viewportheight --> TRUE');
                }
                NewHeight = page_content_height + (viewportheight - site_content_height) + intExtraHeight;

                //Value NewHeight will make splitter till the footer and NewHeight 
                //will be greter than NewSplitterHeight 
                //if RadPanelbar was expanded and now got collapsed
                //we need to adjust heights of wrappers also
                if (getElementByIdHeight('page_content') != NewHeight){
				  setElementByIdHeight('page_content', NewHeight  + 'px');	//when setting style height of a div tag resize event ocueres			
				}
            }
            else {
                if (debug == true) {
                    alert('site_content_height < viewportheight --> FALSE');
                }
            }
            //-------------------------------------------------------            
            
            if (debug == true) { alert('END') }
        }
    }
}



function setElementByIdWidth(ElementById, NewWidth) {
    if (document.getElementById) {
        var objElementById = document.getElementById(ElementById);
        objElementById.style.width = NewWidth;
    }
}
function setElementByIdHeight(ElementById, NewHeight) {
    if (document.getElementById) {
        var objElementById = document.getElementById(ElementById);
        objElementById.style.height = NewHeight;
    }
}

function getElementById(ElementById) {
    if (document.getElementById) {
        return document.getElementById(ElementById);
    }
} 
function getElementByIdWidth(ElementById) {
    if (document.getElementById) {
        var objElementById = document.getElementById(ElementById);
        return objElementById.offsetWidth;
    }
} 
function getElementByIdHeight(ElementById) {
    if (document.getElementById) {
        var objElementById = document.getElementById(ElementById);
        return objElementById.offsetHeight;
    }
}
function pause(millis) {
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while (curDate - date < millis);
} 