document.write("<style>div.fora{background: #000000; width: 100%; left: 0; top: 0; position: absolute; z-index: 40000; filter: alpha(opacity=40); -moz-opacity: 0.4; opacity: 0.4; }</style>");

function habilitaSelects()
{
    /************************************************
	No Internet Explorer versão 6.0, o box das mensagens de erro
	e sucesso, não consegue ficar sobrepostas aos objetos html do 
	tipo "select". Com isso, temos que "escondê-los" durante a execução
	e ao fechar a janela, iremos voltar com eles para a página.
	*************************************************/
    var IE = document.all; 
	var navVers = navigator.appVersion;
	var oIPTC = document.getElementById('box_iptc');
    if (IE && navVers.indexOf('MSIE 6.0') != -1) {
	    if (oIPTC) {
            var oCat = document.getElementById('box_iptc.categoria');
			oCat.style.visibility = 'visible';
			var oSub = document.getElementById('box_iptc.subcategoria');
			oSub.style.visibility = 'visible';
			var oCal = document.getElementById('box_iptc.catalogo');
			oCal.style.visibility = 'visible';
			var oCal = document.getElementById('box_iptc.sempermissao');
			oCal.style.visibility = 'visible';
			var oCal = document.getElementById('box_iptc.compermissao');
			oCal.style.visibility = 'visible';
		} else {
	        var selects = document.getElementsByTagName('select');
		    for (var i=0; i<selects.length; i++)
		    {
		        selects[i].style.visibility = 'visible';
		    }
		}
	}  
}

function desabilitaSelects()
{
    var IE = document.all; 
	var navVers = navigator.appVersion;
	
    if (IE && navVers.indexOf('MSIE 6.0') != -1) {
	    var selects = document.getElementsByTagName('select');
		for (var i=0; i<selects.length; i++)
		{
  	        selects[i].style.visibility = 'hidden';
		}
	}  
}

function addEvent(whichObject,eventType,functionName,suffix)
{
	if (!suffix)
		suffix = '';

	if (whichObject.attachEvent)
	{
		whichObject['e'+eventType+functionName+suffix] = functionName;
		whichObject[eventType+functionName+suffix] = function(){whichObject['e'+eventType+functionName+suffix]( window.event );}
		whichObject.attachEvent('on'+eventType, whichObject[eventType+functionName+suffix]);
	}
	else
		whichObject.addEventListener(eventType, functionName, false);
}

function resizeDiv()
{
	var tam_pag = tamPage();

	if (document.getElementById('div_fora') != null)
	{
		document.getElementById('div_fora').style.height = ((tam_pag.y - 10) + 'px');
		document.getElementById('div_fora').style.width  = ((tam_pag.x - 20) + 'px');
	}

	if (document.getElementById('div_msg') != null)
	{
		var top  = ((tam_pag.h - 90 - 26) / 2);
		var left = ((tam_pag.w - 300 - 40) / 2);

		document.getElementById('div_msg').style.top  = (top < 0) ? "0px" : top + "px";
		document.getElementById('div_msg').style.left = (left < 0) ? "0px" : left + "px";
	}
}

function hideBox()
{
	if (document.getElementById('div_fora') != null)
		document.body.removeChild(document.getElementById('div_fora'));
		
	if (document.getElementById('div_msg') != null)
		document.body.removeChild(document.getElementById('div_msg'));
    
	/******** 
	mostrar novamente os selects na página
	*********/
	habilitaSelects();
	    
	addEvent(window, 'scroll', function(e){ void(0) });
	addEvent(window, 'resize', function(e){ void(0) });		
}

function showBox(msg, tipo, callback, sem_fechar)
{   	
    window.scrollTo(0, 0); 
	if(!callback) callback = hideBox;

    var img = '../static/img/confirma01.gif';
	var cls = 'box box_ok';

	if (tipo == 'erro')
	{
		img = '../static/img/confirma02.gif';
		cls = 'box box_erro';
	}
	else if (tipo == 'alert')
	{
		img = '../static/img/confirma04.gif';
		cls = 'box box_inform';
	}
	else if (tipo == 'help')
	{
		img = '../static/img/confirma03.gif';
		cls = 'box box_inform';
	}
	
	/******************************************
	ESCONDE OS SELECTS DA PÁGINA
	******************************************/
	desabilitaSelects();

	var tam_pag = tamPage();
    
	var div0     = document.createElement('div');
	var div_fora = document.createElement('div');

	div_fora.className    = 'fora';
	div_fora.id           = 'div_fora';
	div_fora.style.height = (tam_pag.y + 'px');

	var top  = ((tam_pag.h - 90 - 26) / 2);
	var left = ((tam_pag.x - 300 - 40) / 2);

	div0.className    = cls;
	div0.id           = 'div_msg';
	div0.style.zIndex = '50000';
	//div0.style.position = 'fixed';

	var div0_1     = document.createElement('div');
	var div0_1_img = document.createElement('img');

	div0_1.className = 'box_esq';
	div0_1_img.src   = img;

	div0_1.appendChild(div0_1_img);

	var div0_2    = document.createElement('div');
	var div0_2_ul = document.createElement('ul');
	var div0_2_li = document.createElement('li');

	div0_2.className = 'box_dir';

	div0_2.appendChild(div0_2_ul);
	div0_2_ul.appendChild(div0_2_li);
	div0_2_li.innerHTML = msg;
	
	var div0_3 = document.createElement('div');

	if (!sem_fechar)
	{
		var div0_3_a = document.createElement('a');

		div0_3.className      = 'fechar';
		div0_3.align          = 'right';
		div0_3_a.style.cursor = 'pointer';

        div0_3_a.setAttribute('id', 'teste')
		div0_3_a.onmousedown = callback;		
		div0_3_a.onclick = callback;						 
        div0_3_a.innerHTML = "FECHAR [x]";
		div0_3.appendChild(div0_3_a);			
	}

	div0.style.top     = (top < 0) ? "0px" : top + "px";
	div0.style.left    = (left < 0) ? "0px" : left + "px";
	div0.style.display = "block";

	div0.appendChild(div0_1);
	div0.appendChild(div0_2);
	div0.appendChild(div0_3);

	document.body.appendChild(div_fora);
	document.body.appendChild(div0);

	addEvent(window, 'scroll', function(e){ resizeDiv() });
	addEvent(window, 'resize', function(e){ resizeDiv() });   
}

function tamPage()
{
	var x, y, w, h, xScrool;

	if (window.innerHeight && window.scrollMaxY)
	{
		x = window.innerWidth + window.scrollMaxX;
		y = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}
	else
	{
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}

	if (self.innerHeight)
	{
		w = self.innerWidth;
		h = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}

	if (self.pageYOffset)
		xScrool = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		xScrool = document.documentElement.scrollTop;
	else if (document.body)
		xScrool = document.body.scrollTop;

	if (y < h)
		y = h;

	if (x < w)
		x = w;

	return { x:x, y:y, w:w, h:h, xScrool:xScrool };
}
