//esconde e mostra as divs
function toggleBox(szDivId, iState){ //1-visible 0-hidden
	if(document.layers){	//NN4+
		if(document.layers[szDivId].visibility){
		}
		else{
		document.layers[szDivId].visibility = iState ? "show" : "hide";
		}
		
		if(document.layers[szDivId].display){
		}
		else{
			document.layers[szDivId].display = iState ? "block" : "none";
		}
	}
	else if(document.getElementById){	//gecko(NN6) + IE5+
		var obj = document.getElementById(szDivId);
		//Para o parâmetro VISIBILITY
		if (obj.style.visibility == "visible"){
			obj.style.display = iState ? "block" : "none";
			obj.style.visibility = iState ?	"visible" : "hidden";
		}else{
		obj.style.visibility = iState ?	"visible" : "hidden";
		obj.style.display = iState ? "block" : "none";
		}
		
	}
	else if (document.all){	//IE 4
		document.all[szDivId].style.visibility = iState ? "visible" : "hidden";
		document.all[szDivId].style.display = iState ? "block" : "none";
	}
}

function controlBox(rdButtons){
	var i;

	botao = rdButtons;
	//alert(rdButtons);
	for (i=0; i<botao.length; i++)
	{
		if(botao[i].checked)
		{
			switch(botao[i].value)
			{
				case "PP":
					toggleBox('box_param', 1);
					escreve_param('text_docum', 'Parecer Pr&eacute;vio');
					escreve_param('text_dono', 'Prefeito');
					escreve_param('text_dados', 'o N&uacute;mero do Parecer Pr&eacute;vio');
					document.form_decisoes.rd_param[1].value = "NA";
					document.form_decisoes.rd_param[2].value = "NM";
				break;
				
				case "AV":
					toggleBox('box_param', 1);
					escreve_param('text_docum', 'Ac&oacute;rd&atilde;o');
					escreve_param('text_dados', 'o N&uacute;mero do Ac&oacute;rd&atilde;o');
					escreve_param('text_dono', 'Gestor');
					document.form_decisoes.rd_param[1].value = "NA";
					document.form_decisoes.rd_param[2].value = "NM";
				break;
				
				case "NP":
					toggleBox('box_dados', 1);
					toggleBox('box_geral', 0);
					toggleBox('box_pesquisar', 1);
					escreve_param('text_dados', 'o N&uacute;mero do Processo');
					escreve_param('input', '<input type="text" name="param_pesquisa" id="param_pesquisa" onkeyup="formAjax_in.formata( this.id )" onkeypress="formAjax_in.formata( this.id )" class="classNormal ,classRequerido ,campoIndexar ,requerido ,Por favor - Preencha o campo! , , ,processo ,processo" />');
				break;
				
				case "NA":
					toggleBox('box_dados', 1);
					toggleBox('box_geral', 0);
					toggleBox('box_pesquisar', 1);
					if(document.form_decisoes.rd_tp_busca[0].checked)
					{
						escreve_param('text_dados', 'o N&uacute;mero do Parecer Pr&eacute;vio');
					}
					else
					{
						escreve_param('text_dados', 'o N&uacute;mero do Ac&oacute;rd&atilde;o');
					}
					escreve_param('input', '<input type="text" name="param_pesquisa" id="param_pesquisa"  onkeyup="formAjax_in.formata( this.id )" onkeypress="formAjax_in.formata( this.id )" class="classNormal ,classRequerido ,campoIndexar ,requerido ,Por favor - Preencha o campo! , , ,processo ,processo" />');
				break;
				
				case "NM":
					toggleBox('box_dados', 1);
					toggleBox('box_geral', 0);
					toggleBox('box_pesquisar', 1);
					if(document.form_decisoes.rd_tp_busca[0].checked)
					{
						escreve_param('text_dados', 'o Nome do Prefeito');
					}
					else
					{
						escreve_param('text_dados', 'o Nome do Gestor');
					}
					escreve_param('input', '<input type="text" name="param_pesquisa" id="param_pesquisa" size="50" />');
				break;
				
				case "NC":
					toggleBox('box_dados', 0);
					toggleBox('box_geral', 1);
					toggleBox('box_pesquisar', 1);
					
				break;
				
			}

		}
	}
}

function validaDecisoes()
{//
	btTipo = document.form_decisoes.rd_tp_busca;
	btParam = document.form_decisoes.rd_param;
	formDados = document.form_decisoes.param_pesquisa;
	
	mc1 = -1 //caso não seja marcado nenhuma opção
	mc2 = -1
	//Verificando o "Tipo de busca"
	for(i=0; i<btTipo.length; i++)
	{
		if(btTipo[i].checked)
		{
			mc1 = i;
		}
	}
	
	//Verificando o "Parâmetros de busca"
	for(i=0; i<btParam.length; i++)
	{
		if(btParam[i].checked)
		{
			mc2 = i;
		}
	}
		//Se não marcou o "Tipo de busca"
		if(mc1==-1)
		{
			alert("Selecione uma opção para validar sua pesquisa !!!");
			return false;
		}
		
		//Se não marcou o "Parâmetros de busca"
		if(mc2==-1)
		{
			alert("Selecione uma opção para validar sua pesquisa !!!");
			return false;
		}

		//Se não digitou os dados da busca
		if(formDados.value=="")
		{
			alert("digite o valor no campo para validar sua pesquisa!!!");
			formDados.focus();
			return false;
		}
	return true;
}

// Abrir Pop-Up centralizada
function abreCentro(pagina,largura,altura) {

//pega a resolução do visitante
w = screen.width;
h = screen.height;

//divide a resolução por 2, obtendo o centro do monitor
meio_w = w/2;
meio_h = h/2;

//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
altura2 = altura/2;
largura2 = largura/2;
meio1 = meio_h-altura2;
meio2 = meio_w-largura2;

//abre a nova janela, já com a sua devida posição
window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+', scrollbars = yes');
}



/** Funções de controle de tela de cadastro do Push
*	Autor: Marcio Mota
*	Data: 03 de Agosto de 2007
*	www.tcm.ce.gov.br
*/

/**
* Desabilita o Enter
*/
function pressenter(addValue, addElement, e){
x = window.event;
   if(navigator.appName=='Microsoft Internet Explorer'){
	   
      var y=x.keyCode;
      
	  if(y == 13){
		  add_proc(addValue, addElement);
		  return false;
      } 
   }

   if(navigator.appName=='Netscape'){
      var y = e.keyCode;
	 
      if(y == 13){
         add_proc(addValue, addElement);
		 return false; 
      }
   }
}
	



/**
*	Função que adiciona os processos a lista (select mutiple)
*/
function add_proc(addValue, addElement){
	
	nmProc = document.getElementById(addValue); //valor passado
	selAdd = document.getElementById(addElement); //campo onde será inserido
	hidden = document.getElementById("procs"); // campo hidden
	
	
	if (selAdd.length == 0){
		
		hidden.value = ""; // limpando os valores do campo hidden
		
		//criando e inserindo como filho um novo objeto Option
		var newOpt = new Option(nmProc.value, nmProc.value);
		selAdd.options[0] =newOpt;
		addhidden(nmProc);
	}else{
		
		//verificando se o numero do processo já foi adicionado
		for(m=0; m<selAdd.length; m++){
			vai = true;
			if (nmProc.value == selAdd.options[m].value){
				alert("Este processo já foi adicionado a sua lista!!!");
				vai = false;
				break;
			}
		}
		
		//se não houver nenhuma opção selecionada
		if (vai == true){
			selAdd.selectedIndex = -1;
			addhidden(nmProc);
			if (selAdd.selectedIndex == -1){
				var selText = new Array(); //pega os textos
    			var selValues = new Array(); //pega os values
    			var selIsSel = new Array();
    			var newCount = -1;
    			var newSelected = -1;
    			var i;
				for(i=0; i<selAdd.length; i++){
					newCount++;
					if (newCount == selAdd.selectedIndex+1) {
						selText[newCount] = nmProc.value;
						selValues[newCount] = nmProc.value;
						selIsSel[newCount] = false;
						newCount++;
						newSelected = newCount;
					}
					selText[newCount] = selAdd.options[i].text;
      				selValues[newCount] = selAdd.options[i].value;
      				selIsSel[newCount] = selAdd.options[i].selected;
				}
				
				for(i=0; i<=newCount; i++)
    			{
      				var newOpt = new Option(selText[i], selValues[i]);
      				selAdd.options[i] = newOpt;
      				selAdd.options[i].selected = selIsSel[i];
    			}
			
			}
		}
	}
	nmProc.value = "" //limpa o campo onde digita o processo
}

/**
*	Função que remove os processos a lista (select mutiple)
*/
function rm_proc(rmElemen)
{
	theSel = document.getElementById(rmElemen);
  var selIndex = theSel.selectedIndex;
   
  if (selIndex != -1) {
    for(i=theSel.length-1; i>=0; i--)
    {
      if(theSel.options[i].selected)
      {
        rmhidden(theSel.options[i].value);
		theSel.options[i] = null;
      }
    }
    if (theSel.length > 0) {
      theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
	  theSel.selectedIndex = -1
	  
    }
  }else{
  	alert("Selecione os processos que deseja excluir!!!");
  }
}

function addhidden(proc){
	
	sel = document.getElementById("list_proc");
	hidden = document.getElementById("procs");
	
	if(sel.length == 0){
		hidden.value = "";
	}
	
	if(hidden.value == ""){
		
		addvalue = proc.value;
	}else{
	addvalue = hidden.value + "," + proc.value;
	}
	hidden.value = addvalue;

}

function rmhidden(proc){
	
	hidden = document.getElementById("procs");
	
	if(hidden.value.match(proc+",") == null){
		rmvalue = hidden.value.replace(","+proc,"");	
	}else{
		rmvalue = hidden.value.replace(proc+",","");	
	}
	
	
	
	//rmvalue = hidden.value.replace(","+proc,"");

	hidden.value = rmvalue;

}

function validaPush()
{
	nmCadastro = document.form_push.nm_pessoa;
	emailCadastro = document.form_push.email;
	Processos = document.form_push.procs;


	if(nmCadastro.value=="")
		{
			alert("digite seu nome no campo para validar sua pesquisa!!!");
			nmCadastro.focus();
			return false;
		}
	if(emailCadastro.value=="")
		{
			alert("digite seu email no campo para validar sua pesquisa!!!");
			emailCadastro.focus();
			return false;
		}
	if(Processos.value=="")
		{
			alert("Adicione no mínimo um processo para acompanhamento!!!");
			Processos.focus();
			return false;
		}
}



function bloq_data(acao){
	
	if(acao == 0){
		
	document.form_sap.dt_agend.disabled = true;
	document.form_sap.tp_turno.disabled = true;
	
	}
	if(acao == 1){
	document.form_sap.dt_agend.disabled = false;
	document.form_sap.tp_turno.disabled = false;
	}
}