function addOnload(fn) {
	var nowOnload = window.onload;
	window.onload = function() {
		fn();
		if(nowOnload != null && typeof(nowOnload) == 'function') nowOnload();
	}
}

function addOnresize(fn) {
	var nowOnresize = window.onresize;
	window.onresize = function() {
		fn();
		if(nowOnresize != null && typeof(nowOnresize) == 'function') nowOnresize();
	}
}

function popLayerAlert(parameter){

	document.getElementById('alertArea').style.visibility='hidden';

	var	obj2 = document.getElementById('bgGeralAlpha');
	var	obj3 = document.getElementById('bgGeralAlphaSob');

	var chk1 = document.body.scrollHeight;
	var chk2 = document.body.offsetHeight;
	var chk3 = document.getElementById('container').offsetHeight;

	var chkw1 = document.body.scrollWidth;
	var chkw2 = document.body.offsetWidth;
	var chkw3 = document.getElementById('container').offsetWidth;

	if(chk3 > chk1 || chk3 > chk2){
		y = document.getElementById('container').offsetHeight;
	}else{
		if (chk1 > chk2){
			y = document.body.scrollHeight;
		}else{
			y = document.body.offsetHeight;
		}
	}


	if(chkw3 > chkw1 || chkw3 > chkw2){
		x = document.getElementById('container').offsetWidth;
	}else{
		if (chk1 > chk2){
			x = document.body.scrollWidth;
		}else{
			x = document.body.offsetWidth;
		}
	}

	altura = y - 4;

	document.getElementById('alertArea').style.display='block';
	document.getElementById('popLayer').style.display='block';

	setTimeout(function(){
		var chkpop = document.getElementById('popLayer').offsetHeight;

		posicao = chkpop / 2;

		obj2.style.height = altura+"px";
		obj3.style.height = altura+"px";

		obj2.style.width = x+"px";
		obj3.style.width = x+"px";

		//document.getElementById('popLayer').style.marginTop=-posicao+'px';
		document.getElementById('alertArea').style.visibility='visible';

		return false;
	},100);

}

function chkbgpoplayer(){

	var chk1 = document.body.scrollHeight;
	var chk2 = document.body.offsetHeight;
	var chk3 = document.getElementById('container').offsetHeight;

	var chkw1 = document.body.scrollWidth;
	var chkw2 = document.body.offsetWidth;
	var chkw3 = document.getElementById('container').offsetWidth;

	if(chk3 > chk1 || chk3 > chk2){
		y = document.getElementById('container').offsetHeight;
	}else{
		if (chk1 > chk2){
			y = document.body.scrollHeight;
		}else{
			y = document.body.offsetHeight;
		}
	}

	if(chkw3 > chkw1 || chkw3 > chkw2){
		x = document.getElementById('container').offsetWidth;
	}else{
		if (chk1 > chk2){
			x = document.body.scrollWidth;
		}else{
			x = document.body.offsetWidth;
		}
	}

	if (y > document.getElementById('bgGeralAlpha').offsetHeight){
		document.getElementById('bgGeralAlpha').style.height=y+'px';
	}

	if (x > document.getElementById('bgGeralAlpha').offsetWidth){
		document.getElementById('bgGeralAlpha').style.width=x+'px';
	}

}

addOnresize(chkbgpoplayer);

function chkscroll(){
//	alert("teste");
	posicao = getInnerSize()[1]/2+getScrollXY()[1]-15;
	if(document.getElementById('popLayer'))
	document.getElementById('popLayer').style.top=posicao+'px';
	if(document.getElementById('popLayerDica'))
	document.getElementById('popLayerDica').style.top=posicao+'px';
}

function closePopLayer(parameter){
	document.getElementById('alertArea').style.display='none';

	if(document.getElementById('popLayerSucesso'))
		document.getElementById('popLayerSucesso').style.display='none';

}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

  return [ scrOfX, scrOfY ];

}

function getInnerSize(){
	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];
}

window.onscroll = chkscroll;
