function $(id){
	return document.getElementById(id);	
}

function removerPopup(){
	document.getElementById('popup').style.display = 'none';
}

function removerBanner(){
	$('bannerHora').innerHTML = '';
	$('bannerHora').style.display = 'none';
}

function linkImagem(valor){ location.href = valor; } /***** LINK PARA IMAGENS (IE6) *****/
/***** ADICIONAR FAVORITOS *****/
function addFav(){
	var url = "http://www.voesol.com.br";
    var title = "SOL Linhas Aéreas";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}
function abrirJanela(url,nome,parametros){ window.open(url,nome,parametros); } /**** ABRIR POPUP *****/
function trocarEstilo(campo, estilo){ document.getElementById(campo).className = estilo; } /***** TROCAR ESTILO DE UM CAMPO *****/
function trocarImagem(campo, img){ document.getElementById(campo).src = raiz+"/img/admin/"+img; } /***** TROCAR IMAGEM *****/

/***** ESCONDER E MOSTRAR MENUS *****/
function showMenu(id){
	var e = $(id);
	if(e.style.display == ''){
		e.style.display = 'none';
	}else{
		e.style.display = '';
	}
}

/***** VALIDAR TITULO DA NEWS ESCOLHIDA NO CADASTRO DE CONTEÚDO *****/
function verificarTituloNews(valor, valor2){
	if (valor != 0){
		document.getElementById('divAuxData').style.display = '';
		document.getElementById('divAuxTitulo').style.display = '';
		document.getElementById('divAuxData2').style.display = '';
		document.getElementById('divAuxTitulo2').style.display = '';
		document.getElementById('conteudo[data_cadastro]').setAttribute('obrigatorio','true');
		document.getElementById('conteudo[titulo_news]').setAttribute('obrigatorio','true');
			
		if (valor == "N"){
			var data = new Date()
			var dia = data.getDate();
			var mes = data.getMonth()+1;
			var ano = data.getFullYear();
			
			if (dia < 10) dia = '0'+dia;
			if (mes < 10) mes = '0'+mes;
			
			var auxData = dia+'/'+mes+'/'+ano; 
			document.getElementById('conteudo[data_cadastro]').value = auxData;
			document.getElementById('conteudo[titulo_news]').value = '';
		} else {
			var campoSelect = document.getElementById('conteudo[id_news_titulo]');
			var data = document.getElementById('conteudo[id_news_titulo]').options[campoSelect.selectedIndex].getAttribute('data');
			var titulo = document.getElementById('conteudo[id_news_titulo]').options[campoSelect.selectedIndex].getAttribute('titulo');
			document.getElementById('conteudo[data_cadastro]').value = data;
			document.getElementById('conteudo[titulo_news]').value = titulo;
		}
	} else {
		document.getElementById('divAuxData').style.display = 'none';
		document.getElementById('divAuxTitulo').style.display = 'none';
		document.getElementById('divAuxData2').style.display = 'none';
		document.getElementById('divAuxTitulo2').style.display = 'none';
		document.getElementById('conteudo[data_cadastro]').setAttribute('obrigatorio','');
		document.getElementById('conteudo[titulo_news]').setAttribute('obrigatorio','');
	}
}


/***** CARREGA LISTA DE CONTEÚDOS DA NEWSLETTER *****/
function conteudoNewsletter(valor){
	if (valor != 0){
		document.getElementById('linhaTitulo').style.display = '';
		conteudoAjax(raiz+'/admin/newsletter/list_gerenciar.php?id='+valor, 'divList');
	} else {
		document.getElementById('linhaTitulo').style.display = 'none';
		document.getElementById('divList').innerHTML = '';
	}
}


/***** ABRIR POPUP COM VISUALIZADOR DE NEWS *****/
function auxNews(valor, action){
	if (document.getElementById('news[senha]')){
		document.getElementById('vis[senha]').value = document.getElementById('news[senha]').value;	
	}
	document.getElementById('vis[id_news_titulo]').value = valor;
	document.getElementById('formAuxNews').action = action;
	document.getElementById('formAuxNews').submit();
}


/***** ABRIR POPUP COM RELATÓRIO DETALHADO DE ACESSOS *****/
function auxAcesso(valor, valor2, valor3, action){
	document.getElementById('rel[data_de]').value = valor;
	document.getElementById('rel[data_ate]').value = valor2;
	document.getElementById('rel[id_acesso]').value = valor3;
	document.getElementById('formAuxAcessos').action = action;
	document.getElementById('formAuxAcessos').submit();
}

/***** ABRIR POPUP COM RELATÓRIO DETALHADO DE ACESSOS *****/
function auxRelatorioSao(valor, action){
	document.getElementById('rel[id_atendimento]').value = valor;
	document.getElementById('formAuxSao').action = action;
	document.getElementById('formAuxSao').submit();
}

/**** ADICIONAR ITEM NO COMBOBOX *****/
function addCombo(combo, value, texto){
	var novo = document.createElement("option");
	novo.value = value;
	novo.text = url_decode(texto);
	combo.options.add(novo);
}

// url_decode version 1.0  
function url_decode(str) {  
	var n, strCode, strDecode = "";  

	for (n = 0; n < str.length; n++) {  
		if (str.charAt(n) == "%") {  
			strCode = str.charAt(n + 1) + str.charAt(n + 2);  
			strDecode += String.fromCharCode(parseInt(strCode, 16));  
			n += 2;  
		} else {  
			strDecode += str.charAt(n);  
		}  
	}  

	return strDecode;  
}


/***** ORGANIZAR CORES DA LISTAGEM APÓS ORDENAÇAO *****/
function corLinhas(tabela){
	var tamanho = document.getElementById(tabela).rows.length;
	var cor = '#E5E5E5';
	
	for(i=1; i<tamanho; i++){
		if (cor == '#E5E5E5'){
			cor = '';
		} else {
			cor = '#E5E5E5';
		}
		document.getElementById(tabela).rows[i].bgColor = cor;
	}
}

/***** LIMPAR FORM *****/
function limparFormulario(formulario){
	for (var i=0;i<document.getElementById(formulario).length;i++){
   	   
	    tipoInput = document.forms[formulario].elements[i].type.toUpperCase();
		nomeCampo = document.forms[formulario].elements[i].id;
		
		if(tipoInput == "FILE"){ document.forms[formulario].elements[i].value = '';	}
		if(tipoInput == "HIDDEN" && nomeCampo != 'arquivo_lista' && nomeCampo != 'id_admin_subsubmenu'){ document.forms[formulario].elements[i].value = ''; }		
		if(tipoInput  == "RADIO" || tipoInput == "CHECKBOX"){ document.forms[formulario].elements[i].checked = false; }
		if (tipoInput == "TEXT" || tipoInput == "TEXTAREA" || tipoInput == "PASSWORD"){ document.forms[formulario].elements[i].value = ''; }
		if (tipoInput == "SELECT-ONE"){ document.forms[formulario].elements[i].selectedIndex = 0; }
		
    }
}

/***** APARECER E DESAPARECE TOOLTIP (LISTAGENS COM FOTO) *****/
function tooltip(nomeDiv, acao){
	if (acao == 'on'){
		document.getElementById(nomeDiv).style.display = '';	
	} else if (acao == 'off'){
		document.getElementById(nomeDiv).style.display = 'none';	
	}
}


/***** ENVIAR FORMULARIO COM ENTER *****/
function enterLogar(e){
	if(e.keyCode == 13){
		submitFormAdm('msgStatus', 'formLogin', 'verificaLogin', 'btLogin', 'escuro');
	}
}

/**** ENVIAR LINK PARA AMIGO *****/
function enviarAmigo(url){
	$('formAmigo').url.value = url;
	$('formAmigo').submit();
}
