function busca()//interno
{
	var tipo=document.getElementById("tipo").value;
	escondeItensIndex();
	
	if(tipo!="Todos"){ //se o tipo for diferente de "todos" ele mostrara apenas o itens de pesquisa referentes aquele tipo
		mostraItens(tipo);
	}
	buscaAll(1, 1,getObj("registros").value);
	//limpa("interna");
		
}

function buscaAll(pagina,menor, maior)//interno
{
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=buscaPublicacao";
	this.ajax.params += "&tipo=" + getObj("tipo").value;
	this.ajax.params += "&ano=" + getObj("ano").value;
	
	this.ajax.params += "&titulo=" + getObj("titulo").value;
	this.ajax.params += "&autor=" + getObj("autor").value;
	this.ajax.params += "&edicao=" + getObj("edicao").value;
	/*if(document.forms["form"]["edicao"]!=null){	
		var indice=document.forms["form"]["edicao"].selectedIndex;
		
		if(document.forms["form"]["edicao"].options[indice].text!="Todos"){
			
			this.ajax.params += "&edicao=" + document.forms["form"]["edicao"].options[indice].text;
			
		}
	}*/
	this.ajax.params += "&registros=" + getObj("registros").value;

			this.ajax.params += "&pagina=" + pagina;
			this.ajax.params += "&maior=" + maior;
			this.ajax.params += "&menor=" + menor;
	
	this.ajax.func = function()
	{		
		if(this.readyState==4 && this.status == 200)
		{
			getObj("loading").style.display = "none";
			
			//objeto HTML que recebe o resultado em HTML				
			getObj("resultado").innerHTML = this.responseText;
		}	
	}
	this.ajax.url = "actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
}

function mudaTipo()//interno, de acordo com o tipo selecionado ele ira limpar os campos selecionados e fazer uma nova busca 
{
	limpa();
	busca();
}

function checkAll(ini)//interno
{
	var faz = true;
	check = getObj("chkall").checked;
	var i= ini;
	while(faz)
	{
		obj = getObj("chk"+i++);
		if(obj != null) 
			obj.checked = check;
		else
			faz = false;	
	}
}

function opcao(ini)//interno
{
		 if (getObj('acao').value == 'E')	excluir("E", ini); 
	else if	(getObj('acao').value == 'J')	location="novo.php?tipo=1";
	else if	(getObj('acao').value == 'A')	location="novo.php?tipo=2";
	else if	(getObj('acao').value == 'L')	location="novo.php?tipo=3";
	else if	(getObj('acao').value == 'I')	visualizarSelecionados(ini);
	else if	(getObj('acao').value == 'P')	publicar("P",ini);
	else if	(getObj('acao').value == 'D')	despublicar("D",ini);
}

function excluir(op, ini)//interno
{
	ids = getIdsSelecionado(ini, op);
	if(ids != "")
	{
		if(confirm("Deseja realmente EXCLUIR essa(s) Publicação(ões)?"))
		{
			var url = "actionBuscaPublicacao.php";
			var parametro = "func=excluir&ids="+ids;
			var func = function()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status == 200)
				{
					document.getElementById("loading").style.display = "none";
					if(this.responseText=="OK"){
						busca();
						alert("Excluido com sucesso!");
					}
				}
			}
			Send(url,parametro,document.getElementById("loading"),func);
		}
	}
	else{
		alert("Marque pelo menos um registro para efetuar a EXCLUSÃO!");
		getObj("acao").options[0].selected=true;	
	}
	
}

function getIdsSelecionado(ini, op)//interno
{
	var faz = true;
	var i= ini;
	var ids = "";

	while(faz)
	{
		obj = getObj("chk"+i);
		objH = getObj("h"+i++);

		if(obj != null) 
		{
			if(obj.checked)
			{
				if(objH.value != op)
				{
					if (op == "E")
					{
						ids += obj.value += " ";	
					}
					else if(op=="I"){
						ids += obj.value += " ";
					}else if(op=="P"){
						ids += obj.value += " ";
					}else if(op=="D"){
						ids += obj.value += " ";
					}
									
				}
			}
		}
		else
			faz = false;
	}
	return ids;
	
}

function visualizarSelecionados(ini)//de acordos com os ids selecionados ele ira verificar a visualização
{
	ids = getIdsSelecionado(ini,"I");
	if(ids != "")
	{
		var url = "actionBuscaPublicacao.php";
		var parametro = "func=visualizarSelecionados&ids="+ids;
		var func = function(){
			if(xmlHttp.readyState==4 && xmlHttp.status == 200)
			{
				document.getElementById("loading").style.display = "none";
				document.getElementById("resultado").innerHTML = this.responseText;
				document.getElementById("buscaT").style.display="none";
				document.getElementById("thelanguage").style.display="none";
				getObj("voltar").style.display="none";
				getObj("voltar2").style.display="block";
				
			}
		}
		Send(url,parametro,document.getElementById("loading"),func);
		
	}
	else{
		alert("Marque pelo menos um registro para efetuar poder visualizar!");
		getObj("acao").options[0].selected=true;	
	}
	
}

function escondeItensIndex()//interno
{
	getObj("labelTitulo").style.display="none";
	getObj("titulo").style.display="none";
	getObj("labelEdicao").style.display="none";
	getObj("edicao").style.display="none";
	getObj("labelTexto").style.display="none";
	getObj("texto").style.display="none";
	getObj("labelAutor").style.display="none";
	getObj("autor").style.display="none";
	getObj("labelAno").style.display="block";
	getObj("ano").style.display="block";
	document.getElementById("voltar2").style.display="none";
	document.getElementById("voltar").style.display="block";
	document.getElementById("buscaT").style.display="block";
	document.getElementById("thelanguage").style.display="block";
}

function limpa()//interno
{
	getObj("edicao").value="";
	getObj("titulo").value="";
	getObj("texto").value="";
	getObj("autor").value="";

	
}

function mostraItens(op)//interno
{
	if(op=="J"){
		getObj("labelTitulo").style.display="none";
		getObj("titulo").style.display="none";
		getObj("labelEdicao").style.display="block";
		getObj("edicao").style.display="block";
		getObj("labelAno").style.display="block";
		getObj("ano").style.display="block";
		//getObj("labelTexto").style.display="block";
		//getObj("texto").style.display="block";
		//getObj("labelTexto").innerHTML="Conte&uacute;do:";
		getObj("labelAutor").style.display="none";
		getObj("autor").style.display="none";
	}else if(op=="A"){
		getObj("labelTitulo").style.display="block";
		getObj("titulo").style.display="block";
		getObj("labelEdicao").style.display="none";
		getObj("edicao").style.display="none";
		getObj("labelAno").style.display="block";
		getObj("ano").style.display="block";
		//getObj("labelTexto").style.display="block";
		//getObj("texto").style.display="block";
		//getObj("labelTexto").innerHTML="Conte&uacute;do";
		getObj("labelAutor").style.display="none";
		getObj("autor").style.display="none";
	}else if(op=="L"){
		getObj("labelTitulo").style.display="block";
		getObj("titulo").style.display="block";
		getObj("labelEdicao").style.display="none";
		getObj("edicao").style.display="none";
		getObj("labelAno").style.display="none";
		getObj("ano").style.display="none";
		//getObj("labelTexto").style.display="block";
		//getObj("texto").style.display="block";
		//getObj("labelTexto").innerHTML="Sin&oacute;pse";
		getObj("labelAutor").style.display="block";
		getObj("autor").style.display="block";
	}
}

function escondeNovo(tipo,id)//interno, esconderá os campos desnecessários de uma nova publicacao, ou de uma
//edição de publicacao , de acordo com o tipo fornecido.
{
	if(tipo=="1"){
		getObj("labelTitulo").style.display="none";
		getObj("titulo").style.display="none";
		getObj("labelEdicao").style.display="block";
		getObj("edicao").style.display="block";
		getObj("labelDE").style.display="block";
		getObj("labelA").style.display="block";
		getObj("mesO").style.display="block";
		getObj("mesD").style.display="block";
		getObj("labelPdf").style.display="block";
		getObj("pdf").style.display="block";
		getObj("labelAutoria").style.display="none";
		getObj("autoria").style.display="none";
		getObj("labelAutor").style.display="none";
		getObj("autor").style.display="none";
		getObj("labelTexto").innerHTML="Destaques:";
		getObj("labelCapa").innerHTML="Capa:";
		getObj("ano").style.display="block";
		getObj("labelAno").style.display="block";
		if(id==2){
			getObj("labelAtualizaCapa").innerHTML="Atualizar Capa";
			getObj("labelAtualizaPdf").style.display="block";
			}
	}else if(tipo=="2"){
		getObj("labelTitulo").style.display="block";
		getObj("titulo").style.display="block";
		getObj("labelEdicao").style.display="none";
		getObj("edicao").style.display="none";
		getObj("labelDE").style.display="none";
		getObj("labelA").style.display="none";
		getObj("mesO").style.display="none";
		getObj("mesD").style.display="none";
		getObj("labelPdf").style.display="none";
		getObj("pdf").style.display="none";
		getObj("labelAutoria").style.display="none";
		getObj("autoria").style.display="none";
		getObj("labelAutor").style.display="block";
		getObj("autor").style.display="block";
		getObj("labelAutor").innerHTML="Autor(es)/Fonte:";
		getObj("labelTexto").innerHTML="Conteúdo:";
		getObj("labelCapa").innerHTML="Foto:";
		getObj("ano").style.display="block";
		getObj("labelAno").style.display="block";		
		if(id==2){
			getObj("labelAtualizaCapa").innerHTML="Atualizar Foto";
			getObj("labelAtualizaPdf").style.display="none";
		}
	}else if(tipo=="3"){
		getObj("labelTitulo").style.display="block";
		getObj("titulo").style.display="block";
		getObj("labelEdicao").style.display="none";
		getObj("edicao").style.display="none";
		getObj("labelDE").style.display="none";
		getObj("labelA").style.display="none";
		getObj("mesO").style.display="none";
		getObj("mesD").style.display="none";
		getObj("labelPdf").style.display="block";
		getObj("pdf").style.display="block";
		getObj("labelAutor").style.display="none";
		getObj("autor").style.display="none";
		getObj("labelAutor").innerHTML="Autor:";
		getObj("labelAutoria").style.display="block";
		getObj("autoria").style.display="block";
		getObj("labelTexto").innerHTML="Sin&oacute;pse:";
		getObj("labelCapa").innerHTML="Capa:";
		getObj("ano").style.display="none";
		getObj("labelAno").style.display="none";
		if(id==2){
			getObj("labelAtualizaCapa").innerHTML="Atualizar Capa";
			getObj("labelAtualizaPdf").style.display="none";
		}
	}

}

function alterna(objSelect)//interno, irá alternar os valores da publicacao de um novo jornal, de forma a não deixar 
//dois meses se repetirem no select que contém os meses
{
	var index=document.forms["formEdicao"][objSelect].selectedIndex;
	var opcao=document.forms["formEdicao"][objSelect].options[index].text;
	var select_alvo;
	var default_option;
	
	if(objSelect=="mesO"){
		getObj("mesOrigem").value=opcao;
		select_alvo = document.forms["formEdicao"]["mesD"];
		default_option=select_alvo.options[select_alvo.selectedIndex].text;
    }
	else{
		getObj("mesDestino").value=opcao;
		select_alvo = document.forms["formEdicao"]["mesO"];
		default_option=select_alvo.options[select_alvo.selectedIndex].text;
	}
	
	
	if(opcao!="------------------------"){
		var lista=new Array("------------------------","Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
		select_alvo.options.length = 0;
		var j=0;
       	for (i = 0; i <lista.length; i++) {
		  if((lista[i]!=opcao)){
           	var nome_opcao = lista[i];
           	select_alvo.options[j] = new Option(nome_opcao);
			j++;
			}
    	}
		
		select_alvo.options[0].selected=true;
		
		
		for(i = 0;i < lista.length-1;i++){
			if(select_alvo.options[i].text==default_option){
				select_alvo.options[i].selected=true;
			}
		}
		var indice=select_alvo.selectedIndex;
		
		//alert(opcao+","+default_option+","+select_alvo.options[indice].text);
	}else{
		var lista=new Array("------------------------","Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
		select_alvo.options.length = 0;
		for (i = 0; i <lista.length; i++) {
		  var nome_opcao = lista[i];
          select_alvo.options[i] = new Option(nome_opcao);
			
    	}
		select_alvo.options[0].selected=true;
		for(i = 0;i < lista.length-1;i++){
			if(select_alvo.options[i].text==default_option){
				select_alvo.options[i].selected=true;
			}
		}
		/*for(i = 0;i < lista.length-1;i++){
			if(select_alvo.options[i].text==default_option){
				select_alvo.options[i].selected=true;
			}
		}*/
	}
}

function verifica(form,action,div,img,erro)//interno, ele fará a validação dos campos, se tudo ocorrer tudo bem já fará a 
// inserção 
{
	var permite=false;
	var texto=CKEDITOR.instances.Texto.getData();
	if((getObj("tipo").value=='1')||(getObj("tipo").value=='J')){
		var RegExp=/^[0-9]+$/;
		if(getObj("ano").value==""){
			alert('Falta preencher campo "Ano"!');
		}else if(getObj("edicao").value==""){
			alert('Falta preencher campo "Edição"!');
		}else if(!RegExp.test(getObj("edicao").value)){
			alert('Edição em formato inválido (digite apenas números)!');
		}else if((getObj("mesO").value=="------------------------")||(getObj("mesD").value=="------------------------")){
			alert('Falta preencher o bimestre corretamente!');
		}else if(texto==""){
				alert('Texto Vazio!');
		}else if((document.getElementById("capa").value=="")&&(getObj("tipo").value=='1')){
			alert('Capa Vazia!');
		}else if((document.getElementById("pdf").value=="")&&(getObj("tipo").value=='1')){
			alert('Pdf Vazio!');
		}else permite=true;	
	}
	else if((getObj("tipo").value=='2')||(getObj("tipo").value=='A')){
		if(getObj("titulo").value==""){
			alert('Falta preencher o campo "Título"!');
		}/*else if(getObj("autor").value==""){
			alert('Falta preencher o campo "Autor(es)"!');
		}*/else if(texto==""){
			alert('Conteúdo vazio!');
		}else if((getObj("capa").value=="")&&(getObj("tipo").value=='1')){
			alert('Foto Vazia!');
		}else permite=true;
	}
 	else if((getObj("tipo").value=='3')||(getObj("tipo").value=='L')){
		if(getObj("titulo").value==""){
			alert('Falta preencher o campo "Título"!');
		}else if(getObj("autoria").value=="----"){
			alert('Especifique de quem é a autoria!(CFM ou CRM)');
		}else if(texto==""){
			alert('Conteúdo da sinópse vazio!');
		}else if((getObj("capa").value=="")&&(getObj("tipo").value=='1')){
			alert('Capa Vazia!');
		}else permite=true;
	}
	if(permite){
		if(confirm("Você deseja Publicar?"))
			getObj("publicacao").value=1;
		else
			getObj("publicacao").value=0;
		/*alert(getObj("edicao").value)
		alert(getObj("ano").value)
		alert(getObj("mesOrigem").value)
		alert(getObj("mesDestino").value)
 		*/micoxUpload(form,action,div,img,erro);
		
		if((getObj("tipo").value=='1')||(getObj("tipo").value=='2')||(getObj("tipo").value=='3'))
			limpaNovo();
		//else
			//mudaImagem();
		
	}
}

function limpaNovo()//interno, efetuará a limpeza dos campos apos a adição de uma nova publicacao
{
	getObj("edicao").value="";
	CKEDITOR.instances.Texto.setData("");
	getObj("titulo").value="";
	getObj("autor").value="";
	getObj("ano").value="";
	getObj("capa").value="";
	getObj("pdf").value="";
	data=new Date();
	getObj("ano").value=data.getFullYear();
	getObj("mesO").value="------------------------";
	getObj("mesD").value="------------------------";
	alterna("mesO");
	alterna("mesD");
	
}

function pegaCampo(titulo,ano)//interno
{
	
	if(getObj("tipo").value=="J"){
		var texto=titulo;
		//alert(texto2[0]);
		var aux;
		var aux2;
		
		var texto2=texto.split(/[E][d][i][ç][ã][o][\s][n][º][\d]+[\s][d][e][\s]+/);
		
		if(texto2[0]=="")
			texto2=texto2[1].split(/[\s][a][\s]/);
		else
			texto2=texto2[0].split(/[\s][a][\s]/);
		aux=texto2[0];
		
		getObj("mesOrigem").value=texto2[0];
		getObj("mesDestino").value=texto2[1];
		getObj("ano").value=ano;
		
		texto2=texto.split(/[E][d][i][ç][ã][o][\s]+[n][º]/);
		
		if(texto2[0]=="")
			texto2=texto2[1].split(/[\s]+/);
		else
			texto2=texto2[0].split(/[\s]+/);
		
		getObj("edicao").value=texto2[0];
		var select_alvo = document.forms["formEdicao"]["mesO"];
		for(i=0;i<select_alvo.options.length;i++){
			if(select_alvo.options[i].text==document.getElementById("mesOrigem").value){
				//alert(document.getElementById("mesOrigem").value)
				select_alvo.options[i].selected=true;
			}
		}
		select_alvo = document.forms["formEdicao"]["mesD"];
		for(i=0;i<select_alvo.options.length;i++){
			if(select_alvo.options[i].text==document.getElementById("mesDestino").value){
				select_alvo.options[i].selected=true;
				//alert(document.getElementById("mesDestino").value)
			}
		}
		//getObj("mesDestino").value=getObj("mesD").value;
		}
	else if(getObj("tipo").value=="L"){
		getObj("autoria").value=getObj("Hautoria").value;
		//alert(getObj("Hautoria").value);
	}
	
}

/*function baixaPdfs()//interno
{
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=baixaPdfs";
	this.ajax.func = function()
	{		
		if(this.readyState==4 && this.status == 200)
		{
			
			getObj("loading").style.display = "none";
			alert(this.responseText);
			downloadPdf();
		}
	}
	this.ajax.url = "../../../intranet/gerenciador_de_publicacoes/actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
}*/

/*function getCapas()//interno
{
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=getCapas";
	this.ajax.func = function()
	{		
		if(this.readyState==4 && this.status == 200)
		{
			
			getObj("loading").style.display = "none";
			alert(this.responseText);
			
		}
	}
	this.ajax.url = "../../../intranet/gerenciador_de_publicacoes/actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
}
*/
/*function downloadPdf()//interno
{
	location="pdf_jornais/Jornais.zip";
}*/

/*function visualizar(id)//interno
{
	
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=visualizar";
	this.ajax.params += "&id=" + id;
	
	this.ajax.func = function()
	{		
		
		if(this.readyState==4 && this.status == 200)
		{
			document.getElementById("loading").style.display = "none";
			document.getElementById("resultado").innerHTML = this.responseText;
			document.getElementById("buscaT").style.display="none";
			document.getElementById("thelanguage").style.display="none";
			getObj("voltar").style.display="none";
			getObj("voltar2").style.display="block";
			
		}
	}
	this.ajax.url = "actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
	
}*/

function buscaExterna()//externo
{
	buscaExternaAll(1, 1,getObj("registros").value);
	
}

function buscaExternaAll(pagina,menor, maior)//externo
{
	
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=getPublicacoes";
	this.ajax.params += "&tipo=" + getObj("tipo").value;
	if(getObj("ano")!=null)
		this.ajax.params += "&ano=" + getObj("ano").value;
	else 
		this.ajax.params += "&ano=Todos";
	
	if(getObj("autor")!=null){
		if(getObj("autor").value!='Todos')
			this.ajax.params += "&autor=" + getObj("autor").value;
	}
	if(document.forms["form"]["edicao"]!=null){	
		var indice=document.forms["form"]["edicao"].selectedIndex;
		if(document.forms["form"]["edicao"].options[indice].text!="Todos")
			this.ajax.params += "&edicao=" + document.forms["form"]["edicao"].options[indice].text;
	}
	if(document.forms["form"]["titulo"]!=null){
		if(getObj("tipo").value!='A'){	
			var indice=document.forms["form"]["titulo"].selectedIndex;
			if(document.forms["form"]["titulo"].options[indice].text!="Todos")
				this.ajax.params += "&titulo=" + document.forms["form"]["titulo"].options[indice].text;
				
		}else{
			this.ajax.params += "&titulo=" + document.forms["form"]["titulo"].value;
		}
		
	}
	this.ajax.params += "&registros=" + getObj("registros").value;
	
			this.ajax.params += "&pagina=" + pagina;
			this.ajax.params += "&maior=" + maior;
			this.ajax.params += "&menor=" + menor;
	
	this.ajax.func = function()
	{		
		if(this.readyState==4 && this.status == 200)
		{
			//getObj("loading").style.display = "none";
			//alert(this.responseText);
			//objeto HTML que recebe o resultado em HTML				
			getObj("resultado").innerHTML = this.responseText;
		}
	}
	this.ajax.url = "../../../intranet/gerenciador_de_publicacoes/actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
}

/*function pegaRecente(ids)//externo
{
	if(ids!=""){
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=getTabelaRecente";
	this.ajax.params += "&ids=" + ids;
	
	this.ajax.func = function()
	{		
		
		if(this.readyState==4 && this.status == 200)
		{
			getObj("loading").style.display = "none";
			
			//objeto HTML que recebe o resultado em HTML				
			getObj("resultado").innerHTML = this.responseText;
		}
	}
	this.ajax.url = "../../../intranet/gerenciador_de_publicacoes/actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
	}
}
*/

/*function atualizaIndex()
{
	
	if(getObj("tipo").value=="J"){
		buscaEdicoes(false,"interno");
	}
	else{
		document.forms["form"]["edicao"].options[0].selected=true;
		busca();
	}
}
*/
function atualiza(titulo,ano)//externo
{
	getObj("ano").value=ano;
	buscaEdicoes(false,titulo);		
	
}



function atualizaLivros(autor)//externo
{
	getObj("autor").value=autor;
	buscaTituloLivros(false);
	
}

function atualizaOutros(titulo)
{
	getObj("titulo").value=titulo;
	buscaTituloOutros(false);
}

function buscaEdicoes(ini,value)//externo
{
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=getEdicoes";
	this.ajax.params += "&ano=" + getObj("ano").value;
	
	this.ajax.func = function()
	{		
		if(this.readyState==4 && this.status == 200)
		{
			
			//getObj("loading").style.display = "none";
			
			var lista =this.responseText.split(/[?]/);
			
			var select_alvo = document.forms["form"]["edicao"];
			
			select_alvo.options.length = 0;
			
			for (i = 0; i <lista.length; i++) {
				var nome_opcao = lista[i];
           		select_alvo.options[i] = new Option(nome_opcao);
   			}
			
			if(ini){
				buscaExterna();
				
			}
			else if(value=="interno"){
				busca();
				/*if(getObj("edicao").value!="Todos")
					select_alvo.options[1].selected=true;
				else*/
					select_alvo.options[0].selected=true;
				
			}
			else
				select_alvo.options[1].selected=true;
		}
	}
	this.ajax.url = "../../../intranet/gerenciador_de_publicacoes/actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
}

function buscaTituloLivros(ini)//externo
{
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=getTitulos";
	if(getObj("autor").value!="Todos")
		this.ajax.params+="&autor="+getObj("autor").value;
	
	this.ajax.func = function()
	{		
		if(this.readyState==4 && this.status == 200)
		{
			
			getObj("loading").style.display = "none";
			
			var lista =this.responseText.split(/[?]/);
			
			var select_alvo = document.forms["form"]["titulo"];
			
			select_alvo.options.length = 0;
			
			for (i = 0; i <lista.length; i++) {
				var nome_opcao = lista[i];
           		select_alvo.options[i] = new Option(nome_opcao);
   			}
			
			if(ini)
				buscaExterna();
			else
				select_alvo.options[1].selected=true;
				
		}
	}
	this.ajax.url = "../../../intranet/gerenciador_de_publicacoes/actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
}

function buscaTituloOutros(ini)//externo
{
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=getOutros";
	this.ajax.params+="&ano="+getObj("ano").value;
	
	this.ajax.func = function()
	{		
		if(this.readyState==4 && this.status == 200)
		{
			
			getObj("loading").style.display = "none";
			
			var lista =this.responseText.split(/[?]/);
			
			var select_alvo = document.forms["form"]["titulo"];
			
			select_alvo.options.length = 0;
			
			for (i = 0; i <lista.length; i++) {
				var nome_opcao = lista[i];
           		select_alvo.options[i] = new Option(nome_opcao);
   			}
			
			if(ini)
				buscaExterna();
			else
				select_alvo.options[1].selected=true;
				
		}
	}
	this.ajax.url = "../../../intranet/gerenciador_de_publicacoes/actionBuscaPublicacao.php";
	this.ajax.Send(getObj("loading"));
}

function pegaCapaJornalRecente()//externo
{
	
	this.ajax = new objAjaxNew();
	this.ajax.params = "func=pegaCapaJornalRecente";
	this.ajax.func = function()
	{		
		
		if(this.readyState==4 && this.status == 200)
		{
			//objeto HTML que recebe o resultado em HTML				
			getObj("CapaJornal").innerHTML = this.responseText;
		}
	}
	this.ajax.url = "intranet/gerenciador_de_publicacoes/actionBuscaPublicacao.php";
	this.ajax.Send(getObj(null));
	
}

function publicar(op,ini){
	ids = getIdsSelecionado(ini, op);
	if(ids != "")
	{
		if(confirm("Deseja realmente PUBLICAR esse(s) Registro(s)?"))
		{
			var url = "actionBuscaPublicacao.php";
			var parametro = "func=publicar&ids="+ids;
			var func = function()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status == 200)
				{
					document.getElementById("loading").style.display = "none";
					if(this.responseText=="OK"){
						busca();
						alert("Publicado com sucesso!");
					}
				}
			}
			Send(url,parametro,document.getElementById("loading"),func);
		}
	}
	else{
		alert("Marque pelo menos um registro para efetuar a PUBLICACAO!");
		getObj("acao").options[0].selected=true;	
	}
	
}

function despublicar(op,ini){
	ids = getIdsSelecionado(ini, op);
	if(ids != "")
	{
		if(confirm("Deseja realmente retira a publicacao(oes) desse(s) Registro(s)?"))
		{
			var url = "actionBuscaPublicacao.php";
			var parametro = "func=despublicar&ids="+ids;
			var func = function()
			{
				
				if(xmlHttp.readyState==4 && xmlHttp.status == 200)
				{
					document.getElementById("loading").style.display = "none";
					if(this.responseText=="OK"){
						busca();
						alert("publicacao retirada com sucesso!");
					}
				}
			}
			Send(url,parametro,document.getElementById("loading"),func);
		}
	}
	else{
		alert("Marque pelo menos um registro para RETIRAR A PUBLICACAO!");
		getObj("acao").options[0].selected=true;	
	}
	
}

