/*
Limite de 5 alerts abertos

Parâmetros obrigatórios (Senão forem definidos o divAlert monstrará uma mensagem padrão de erro)
conteudo = texto ou HTML

Opicionais
tipo = atenção, erro, aviso ou ""
width = valor numérico ou "". Se for vazio terá 292px como padrão.
height = valor numérico ou "". Se for vazio terá 107px como padrão.
top = valor numérico em relação ao topo do documento ou top | middle | center | bottom. Assumirá middle se não for declarado.
left = valor numérico em relação à esquerda do documento ou left | center | right. Assumirá center se não for declarado.
autoFechar = recurso que dá a opção do usuário marcar se quer ou não fechar a janela automaticamente. Valores true ou false. Se autoFechar for true mas segundos não forem predefinidos, o valor padrão será 6.
segundos = define o tempo que ficará aberto. Se autoFechar for true dependerá do usuário clicar no checkbox para fehcar. Se autoFechar for false mas houver valor maior que 6 segundos, a janela fechará automaticamente sem intervanção do usuário.
btFechar = true ou false para mostrar ou não o botão fechar. Se não houver valor para segundos, o botão fechar irá aparecer.
*/
ie = (document.all)? true:false;
function divAlertChecarVazio(obj){
	if(obj == "" || obj == null){
		return true;
	}else{
		return false;
	}
}
var divAlertSegundo;
var tempDivAlertBoo;
function divAlert(conteudo,tipo,width,height,top,left,autoFechar,segundos,btFechar){
	if(document.getElementsByTagName("body").length >= 1 && document.getElementsByTagName("html").length >= 1){
		var strPathDivAlert = "javascript/bibliotecas/divAlert/";
		var id = "divAlert_ID";
		var divAlertZindex = 10000;
		if(!document.getElementById(id)){
			tempDivAlertBoo = true;
			var margem = 10;
			var objHTML = document.getElementsByTagName("html")[0];
			var objBody = document.getElementsByTagName("body")[0];
			var objDiv = document.createElement("div");
			objDiv.setAttribute("id",id);
			var numScrollTop = objHTML.scrollTop;
			var numScrollLeft = objHTML.scrollLeft;
			var numMaxHeight = objHTML.clientHeight;
			var numMaxWidth = objHTML.clientWidth;
			if(divAlertChecarVazio(conteudo)){
				conteudo = "O parâmetro <b>conteudo</b> deve ser preenchido.";
				autoFechar =  false;
				segundos = 6000;
			}
			if(!parseInt(width) || divAlertChecarVazio(width)){
				width = 292;
			}
			if(!parseInt(height) || divAlertChecarVazio(height)){
				height = 107;
			}
			if(top.toLowerCase() == "top"){
				top = margem + numScrollTop;
			}else if(top.toLowerCase() == "bottom"){
				top = numMaxHeight - (margem + height) + numScrollTop;
			}else{
				top = parseInt(((numMaxHeight - height)/2) + numScrollTop);
			}
			if(left.toLowerCase() == "left"){
				left = margem + numScrollLeft;
			}else if(left.toLowerCase() == "right"){
				left = numMaxWidth - (margem + width) + numScrollLeft;
			}else{
				left = parseInt(((numMaxWidth - width)/2) + numScrollLeft);
			}
			var objCantos = '<div class="divAlert_canto_RT"><img src="'+strPathDivAlert+'imagens/canto_RT.gif" /></div>'+
			'<div class="divAlert_canto_LT"><img src="'+strPathDivAlert+'imagens/canto_LT.gif" /></div>'+
			'<div class="divAlert_canto_RB"><img src="'+strPathDivAlert+'imagens/canto_RB.gif" /></div>'+
			'<div class="divAlert_canto_LB"><img src="'+strPathDivAlert+'imagens/canto_LB.gif" /></div>';
			var recursosAdicionais = "";
			if(!parseInt(segundos) || divAlertChecarVazio(segundos) || btFechar){
				recursosAdicionais = '<div class="divAlert_btFechar"><img src="'+strPathDivAlert+'imagens/bt_fechar.gif" onclick=fecharDivAlert("'+id+'",false); /></div>';
				segundos = 6000;
			}
			divAlertSegundo = segundos;
			var objIco;
			if(tipo.toLowerCase() == "atenção" || tipo.toLowerCase() == "atencao"){
				objIco = '<img src="'+strPathDivAlert+'imagens/ico_atencao.png" />';
			}else if(tipo.toLowerCase() == "aviso"){
				objIco = '<img src="'+strPathDivAlert+'imagens/ico_aviso.png" />';
			}else if(tipo.toLowerCase() == "erro"){
				objIco = '<img src="'+strPathDivAlert+'imagens/ico_erro.png" />';
			}
			if(tipo.toLowerCase() == "atenção" || tipo.toLowerCase() == "atencao" || tipo.toLowerCase() == "aviso" || tipo.toLowerCase() == "erro"){
				conteudo = '<table cellspacing="0" cellspadding="0"><tr><td width="35" valign="top" style="padding-right:6px;">'+objIco+'</td><td valign="top">'+conteudo+'</td></tr></table>';
			}
			if(autoFechar == true){
				recursosAdicionais = recursosAdicionais + '<div class="divAlert_autoFechar" style="width:'+(width-12)+'px;"><div class="floatLeft"><input id="checkbox_'+id+'" type="checkbox" class="borderNone" onclick="segundosDivAlert('+"'"+id+"'"+',true);" /></div> <div class="fontePequena floatLeft">Fechar automaticamente após <span id="escreveSegundo_'+id+'" class="fontePequena">'+parseInt(segundos/1000)+'</span> segundos</div></div>';
				conteudo = '<div id="conteudo_'+id+'" class="divAlert_conteudo" style="width:'+(width-20)+'px; height:'+(height-46)+'px;">'+conteudo+'</div>';
			}else{
				conteudo = '<div id="conteudo_'+id+'" class="divAlert_conteudo" style="width:'+(width-20)+'px; height:'+(height-20)+'px;">'+conteudo+'</div>';
			}
			var objIframe = '<iframe id="iframe_'+id+'" class="divAlert_iframe" style="width:'+(width+2)+'px; height:'+(height+2)+'px; top:'+top+'px; left:'+left+'px; z-index:'+divAlertZindex+';"></iframe>';
			var objHTML = '<div id="div_'+id+'" class="divAlert_principal" style="width:'+width+'px; height:'+height+'px; top:'+top+'px; left:'+left+'px; z-index:'+divAlertZindex+';">'+ conteudo + objCantos + recursosAdicionais +'</div>';
			objDiv.innerHTML = objIframe + objHTML;
			objBody.appendChild(objDiv);
			if(document.getElementById("checkbox_"+id) && document.getElementById("checkbox_"+id).checked == true){
				//window.setTimeout('fecharDivAlert("'+id+'",true);',segundos);
			}else if(autoFechar == false){
				//window.setTimeout('fecharDivAlert("'+id+'",false);',segundos);
			}
		}
	}
}
var tempDivAlertSegundo;
function segundosDivAlert(){
	var objEscreverSegundo = document.getElementById("escreveSegundo_divAlert_ID");
	if(tempDivAlertBoo){
		tempDivAlertSegundo = divAlertSegundo + 1000;
		tempDivAlertBoo = false;
	}
	if(tempDivAlertSegundo > 1000){
		tempDivAlertSegundo = tempDivAlertSegundo - 1000;
		objEscreverSegundo.innerHTML = parseInt(tempDivAlertSegundo/1000);
		window.setTimeout("segundosDivAlert();",1000);
	}else if(tempDivAlertSegundo <= 1000){
		fecharDivAlert("divAlert_ID",true);
		window.clearTimeout();
	}
}
function fecharDivAlert(id,auto){
	if(document.getElementById("checkbox_"+id) && auto == true && document.getElementById("checkbox_"+id).checked == true){
		document.getElementsByTagName("body")[0].removeChild(document.getElementById(id));
	}else if(auto == false && document.getElementById(id)){
		document.getElementsByTagName("body")[0].removeChild(document.getElementById(id));
	}
}
var numStyle = document.styleSheets.length;
if(!ie){
	for(var x = 0; x < numStyle; x++){
		var numCSSRules = document.styleSheets[x].cssRules.length;
		for(var y = 0; y < numCSSRules; y++){
			if(document.styleSheets[x].cssRules[y].styleSheet){
				var numImportCssRules = document.styleSheets[x].cssRules[y].styleSheet.cssRules.length;
				for(var z = 0; z < numImportCssRules; z++){
					var strSelector = document.styleSheets[x].cssRules[y].styleSheet.cssRules[z].selectorText;
					if(strSelector == ".divAlert_canto_RT" || strSelector == ".divAlert_canto_LT"){
						document.styleSheets[x].cssRules[y].styleSheet.cssRules[z].style.top = "-8px";
					}else if(strSelector == ".divAlert_canto_RB" || strSelector == ".divAlert_canto_LB"){
						document.styleSheets[x].cssRules[y].styleSheet.cssRules[z].style.bottom = "-3px";
					}
				}
			}
		}
	}
}
/*
Desenvolvido por Darlesson
www.darlesson.com.br
*/