// JavaScript Document
window.onload = function(){
  mostraMsg();
}

function mostraMsg(){
  ocultaMsg();
  var overlay = document.createElement("div")
  overlay.id = "overlay";
  overlay.onclick = function(){ocultaMsg();}
  try{
	var msg =  document.getElementById("msg");
  }catch(e){}
  if(msg){
	msg.className = "aviso_garantia";
  }
  document.body.appendChild(overlay);
  posicionaMsg();
}

function ocultaMsg(){
  try{
	var msg = document.getElementById("msg");
	var overlay = document.getElementById("overlay");
  }catch(e){}
  if(msg){
	msg.className = "aviso_garantia oculto";
  }
  if(overlay){
	document.body.removeChild(overlay);	
  }
  window.onresize = null;
  window.onscroll = null;
}

function posicionaMsg(){
	window.onresize = function(){posicionaMsg();};
	window.onscroll = function(){posicionaMsg();};
	var obj = document.getElementById("msg");
	var ScrollTop;
	if (window.pageYOffset){
	  ScrollTop = window.pageYOffset;
	}
	else{
	  ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	var tamJanela = getTamanhoJanela();
	obj.style.left = ((tamJanela[0] - obj.offsetWidth)/2)+"px";
	obj.style.top = (((tamJanela[1] - obj.offsetHeight)/2)+ScrollTop)+"px";
	try{
	  document.getElementById("overlay").style.height = getTamanhoPagina()[1]+"px";
	}catch(e){}
}

function getTamanhoJanela(){
  var myWidth = 0, myHeight = 0;
  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;
  }
  return [myWidth,myHeight];
}

function getTamanhoPagina(){
  var altura = 0; largura = 0;
  var tjan = getTamanhoJanela()
  if (window.innerHeight && window.scrollMaxY) {// Firefox
	altura = window.innerHeight + window.scrollMaxY;
	largura = window.innerWidth + window.scrollMaxX;
	if(altura <= 0) altura = window.innerHeight;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 
	altura = document.body.scrollHeight;  
	largura = document.body.scrollWidth; 
	if(largura<tjan[0])largura = tjan[0];
	if(altura<tjan[1])altura = tjan[1];
  } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari    
	altura = document.body.offsetHeight;    
	largura = document.body.offsetWidth;
	if(largura<tjan[0])largura = tjan[0];
	if(altura<tjan[1])altura = tjan[1];
  }   
  return [largura,altura];
} 
