var lastCdInsertedNoticia =  null;
var minAbaAddNoticia      = -1;

function pegaIDAbaConsultaNoticia(){
	if(minAbaAddNoticia==-1){
		var nrNewTabId = adicionarTab('maintab','Carregando...',loadingDIV.innerHTML,'');
		minAbaAddNoticia = nrNewTabId;
	}
	else{
		var nrNewTabId = minAbaAddNoticia;
	}
	return nrNewTabId
}

function abreRegistroNoticia(cd){
	if (currentObjColor != '')
		currentObjColor.style.backgroundColor = originalObjColor;
	var nrNewTabId = pegaIDAbaConsultaNoticia()
	mostraLoadingTab();
	abreRegistroAba('/sclient/noticias/carregaalteracaonoticia.php?cdNoticia='+cd+'&tabId='+nrNewTabId);
}

function abreUltimoRegistroInserido(){
	var nrNewTabId = pegaIDAbaConsultaNoticia()
	mostraLoadingTab();
	abreRegistroAba('/sclient/noticias/carregaalteracaonoticia.php?cdNoticia='+lastCdInsertedNoticia+'&tabId='+nrNewTabId);
}

function ajustaMensagensNoticias(){
	var lenDivs = document.getElementsByTagName("div").length;
	for(x=0;x<lenDivs;x++){
		if(document.getElementsByTagName("div")[x].className=='mensagemSucessoRodapeFormularios' ||
		   document.getElementsByTagName("div")[x].className=='mensagemErroRodapeFormularios' )
			document.getElementsByTagName("div")[x].style.display = 'none';
	}
	escondeLoadingTab();
}


function deleteItemNoticia(e, cd){
	if (e.keyCode ==  46){
		if(confirm('Você tem certeza que deseja excluir o registro selecionado?')){
			mostraLoadingTab();
			frmOperacao.location = '/sclient/noticias/noticiasoperacao.php?cd_delete='+cd;
		}
	}
}

/* Validação dos Formularios de INSERIR e ALTERAR */
function checkFormNoticia(obj,dsRTE){
	if(obj.ds_titulo_noticia.value==''){
		alert('Por favor, informe o TÍTULO!');
		try{obj.ds_titulo_noticia.select();}
		catch(APPLICATION){}
		return false;
	}
	if(obj.dt_noticia.value==''){
		alert('Por favor, informe a DATA!');
		try{obj.dt_noticia.select();}
		catch(APPLICATION){}
		return false;
	}
	if(obj.cd_idioma.value=='-1'){
		alert('Por favor, informe o IDIOMA!');
		try{obj.dt_noticia.select();}
		catch(APPLICATION){}
		return false;
	}
	rteFormHandler(dsRTE);
	mostraLoadingTab();
	return true;
}

function checkFormNoticiaSite(obj,dsRTE){
	rteFormHandler(dsRTE);
	mostraLoadingTab();
	return true;
}


function mostraMensagemSucesso(){
	var lenDivs = document.getElementsByTagName("div").length;
	for(x=0;x<lenDivs;x++){
		if(document.getElementsByTagName("div")[x].className=='mensagemSucessoRodapeFormularios')
			document.getElementsByTagName("div")[x].style.display = 'block';
	}
}

function limpaFormInserirNoticia(idTab,cdReg){
	var objAux       = document.getElementById("tcontent"+idTab);
	objAux.innerHTML = objAux.rel;
	escondeLoadingTab();
	objAux = document.getElementById("formInserirNoticia");
	objAux.ds_titulo_noticia.focus();
	objAux.ds_titulo_noticia.select();
	startRTE('txRich01','');
	lastCdInsertedNoticia = cdReg;
}

