﻿var arrMnu = new Array();
var timeout;
var browserVersion = navigator.appVersion.toLowerCase();


function getElement(id){
    var e = document.all ? document.all[id] : document.getElementById(id);
    return e;
}

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}


//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
//
function addLoadEvent(func){	

	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

//
// addResizeEvent()
// Adds event to window.resize without overwriting currently assigned onresize functions.
//
function addResizeEvent(func){	
	var oldonresize = window.onresize;
	if (typeof window.onresize != 'function'){
    	window.onresize = func;
	} else {
		window.onresize = function(){
		    oldonresize();
		    func();
		}
	}

}

//
// getPageScroll()
// Returns array with x,y page scroll values.
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



function addBookmark(title,url){
    if (window.sidebar) window.sidebar.addPanel(title, url, "");
    else
        if(document.all) window.external.AddFavorite(url, title);
        else
            if(window.opera && window.print) return true;
}

function resizeLayout(){

    var arrayPageSize = getPageSize();
    
   
    var tudo = getElement('tudo');
    var conteudo = getElement('conteudo');
    var lateralEsq = getElement('menu');
    if (typeof conteudo != 'undefined'){
        var util = conteudo.offsetTop+conteudo.offsetHeight;        
        if (lateralEsq != null){
          
            if(conteudo.offsetTop+conteudo.offsetHeight < lateralEsq.offsetTop+lateralEsq.offsetHeight){
                util = lateralEsq.offsetTop+lateralEsq.offsetHeight;
               
            }
        }
       
        //alert("util: " + util + "; pagesize: " + arrayPageSize[3]);
        if (util > arrayPageSize[3]) 
        
        {tudo.style.height = util + 'px';
        }
        else 
        {tudo.style.height = arrayPageSize[3] + 'px'; 
        }
         
           
    }
}

addLoadEvent(resizeLayout);
addResizeEvent(resizeLayout);


