// JavaScript document

function overlay() 
{
	el = document.getElementById("overlay");
	el.style.display = (el.style.display == "block") ? "none" : "block";
	
	var top = (screen.availHeight / 2) - 350;
	
	document.getElementById('headerModal').style.marginTop = top+'px';
}

function mostraModal(idObj) 
{
	el = document.getElementById(idObj);
	el.style.display = (el.style.display == "block") ? "none" : "block";
	
	var top = (screen.availHeight / 2) - 350;
	
	document.getElementById(idObj+'HeaderModal').style.marginTop = top+'px';
}

/**
 * MODAL v1.0
 * Usado para criar "janelas" do tipo modal com tags "div"
 *
 * @author Gildonei Mendes A. Junior <junior@sitecomarte.com.br>
 * @version 1.0
 * @creation 200-06-04
 * @copyright SITE com ARTE
 * @license OpenSource
 * http://www.sitecomarte.com.br/
 *
 * Este código é livre para todos apenas deixe o comentário,
 * caso faça alguma melhoria, favor reportar a melhoria por e-mail
 */

// Cria um modal na tela
var __URL__ = '/';
function showModal(idObj, titulo, msg, largura, altura)
{
	var largura = (largura < 300 || largura === undefined) ? '300px' : largura+'px';
	var altura	= (altura < 200 || altura === undefined) ? '200px' : altura+'px';

	// Obtém o objeto "body"
	var corpo = document.getElementsByTagName('body')[0];
	
	// Cria o modal principal
	var modal = document.createElement('div');
	modal.setAttribute('name', idObj);
	modal.setAttribute('id', idObj);
	//modal.setAttribute('class','modal');
	modal.style.position 	= 'absolute';
	modal.style.left		= '0px';
	modal.style.top			= '0px';
	modal.style.width		= '100%';
	modal.style.height		= '100%';
	modal.style.textAlign	= 'center';
	modal.style.zIndex		= '1000';
	modal.style.background	= 'url('+__URL__+'imgLayout/background-trans.png) repeat';
	

	// Cria o cabeçalho do modal
	var header = document.createElement('div');
	header.setAttribute('name', 'divTitle'+idObj);
	header.setAttribute('id', 'divTitle'+idObj);
	header.style.margin		= 'auto';
	header.style.marginTop	= altura;
	header.style.width		= largura;
	header.style.height		= '17px';
	header.style.borderTop	= '1px solid #999';
	header.style.borderLeft	= '1px solid #999';
	header.style.borderRight= '1px solid #999';
	header.style.background	= '#FFF';
	header.style.padding	= '5px';
	header.style.textAlign	= 'left';
	header.style.padding	= '5px';
	header.style.background	= 'url('+__URL__+'imgLayout/bgHeaderForm.jpg) repeat';
	
	// Texto do título do modal
	var txtTitulo = document.createElement('h4');
//	txtTitulo.style.width	= '200px';
	txtTitulo.innerHTML		= titulo;
	
	// Div para o título modal
	var divTitle = document.createElement('div');
	divTitle.setAttribute('id','txtTitle'+idObj);
	divTitle.setAttribute('name','txtTitle'+idObj);
	divTitle.style.float = 'left';
	divTitle.style.width = '180px';
	if(navigator.appName == 'Netscape')
		divTitle.setAttribute('style','float:left;width:180px;');
	
	// Div para o linl de fechar o modal
	var divClose = document.createElement('div');
	divClose.setAttribute('id','divClose'+idObj);
	divClose.style.float = 'right';
	divClose.style.width = '15px';
	divClose.style.position= 'absolute';
	if(navigator.appName == 'Netscape')
		divClose.setAttribute('style','float:right;width:15px;height:15px;');
	
	// Link para fechar o modal
	var linkClose = document.createElement('a');
	linkClose.setAttribute('id','linkClose'+idObj);
	linkClose.setAttribute('href',"javascript:closeModal('"+idObj+"');");
	linkClose.setAttribute('style','float:right;margin:0px;padding:0px;');
	linkClose.style.float = 'right';
	
	// Imagem do botão de fechar
	var imgClose = document.createElement('img');
	imgClose.setAttribute('src',__URL__+'imgLayout/close.gif');
	imgClose.setAttribute('alt','Fechar');
	imgClose.setAttribute('title','Fechar');
	imgClose.setAttribute('width','15');
	imgClose.setAttribute('height','15');
	imgClose.setAttribute('style','float:right;');
	imgClose.style.border = '0px';
	imgClose.style.float  = 'right';
	
	
	// Conteúdo do modal
	var conteudo = document.createElement('div');
	conteudo.setAttribute('name', idObj+'Corpo');
	conteudo.setAttribute('id', idObj+'Corpo');
	conteudo.innerHTML			= msg;
	conteudo.style.width		= largura;
	conteudo.style.margin		= 'auto';
	conteudo.style.fontFamily	= 'Tahoma, Verdana, Arial';
	conteudo.style.fontSize		= '11px';
	conteudo.style.borderLeft	= '1px solid #999';
	conteudo.style.borderRight	= '1px solid #999';
	conteudo.style.textAlign	= 'left';
	conteudo.style.padding		= '5px';
	conteudo.style.background	= '#FFF';
	
	// Rodapé do modal
	var footer = document.createElement('div');
	footer.setAttribute('name', idObj+'Footer');
	footer.setAttribute('id', idObj+'Footer');
	footer.style.width			= largura;
	footer.style.padding		= '5px';
	footer.style.margin			= 'auto';
	footer.style.borderBottom	= '1px solid #999';
	footer.style.borderLeft		= '1px solid #999';
	footer.style.borderRight	= '1px solid #999';
	footer.style.background		= '#FFF';
	footer.style.fontSize		= '4px';
	
	// Cria os elementos
	divClose.appendChild(linkClose);
	linkClose.appendChild(imgClose);
	
	divTitle.appendChild(txtTitulo);
	//if(navigator.appName != 'Netscape')
	//{
	//	divTitle.appendChild(divClose);
	//}
	//else
	header.appendChild(divTitle);
	header.appendChild(divClose);
	
	modal.appendChild(header);
	modal.appendChild(conteudo);
	modal.appendChild(footer);

	corpo.appendChild(modal);

	// Adiciona a função de onclick para o link de fechar	
	//document.getElementById('linkClose'+idObj).onclick = "closeModal('"+idObj+"');"
}

// Remove o modal da tela
function closeModal(idObj)
{
	var obj = document.getElementById(idObj);

	if(obj != null)
	{
		var parent = obj.parentNode;
		parent.removeChild(obj);
	}		
}
