﻿var tempo;
var minW;
var minH;

function fit(largura, altura)
{
	
	minW = largura;
	minH = altura;
	
	addWindowEvent( 'onresize', self, onResizeDiv );
	onResizeDiv();
	
}

function addWindowEvent( eventName, scope, func )
{
	var oldEvent = window[ eventName ];
	if (typeof window[ eventName ] != 'function') window[ eventName ] = function(){ func.call( scope ); };
	else
	{
		window[ eventName ] = function()
		{ 
			if( oldEvent ) oldEvent();
			func.call( scope );
		}
	}
	
}

function getWinSize()
{
	var winH, winW;
	if (parseInt(navigator.appVersion)>3) {
		if ( document.body.offsetWidth ){ // Gecko / WebKit
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		} else if ( document.body.offsetWidth ){ // MS
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	return { height: winH, width: winW };
}

function onResizeDiv()
{
	var winSize = getWinSize();
	var w = winSize.width < minW? minW+"px" : "100%";
	var h = winSize.height < minH? minH+"px" : "100%";
	/*
	 for IE on PC, turn off the disabled scrollbar 
	 on the right when there's no content to scroll
	*/
	if( document.all )
	{
		if ( (document.body.scroll = ( w!="100%" || h!="100%" )? "auto" : "no") == "auto")
		{
			
			document.body.style.overflow = "auto";
			
		}
	}
	
	document.getElementById( "site" ).style.width = w;
	document.getElementById( "site" ).style.height = h;
	
}


function popUp(pagina)
{
	
	window.open (pagina, "janela","menubar=0,resizable=0,width=700,height=580, scrollbars=1");

}


function setFocus(){
	
	var fla = self.document.getElementById("site");
	
	if(fla) fla.focus();
	else {
		
		tempo = setInterval( function(){
			
			clearInterval( tempo );
			load();
			
		}, 500 );
		
	}
	
}


function load()
{
	setFocus();
	onResizeDiv();
	
}

window.onload = load;