function Verifica_folha()
{

	f = document.getElementsByTagName("link");
	//alert(f[0].disable);
	if (window.event)
	{
		//f.href="ConsultaProtocolos_ie.css"
		f[0].disabled=false;
		f[1].disabled=true;
	
	}
	else if (!document.all)
	{
		//f.href="ConsultaProtocolos_fx.css"
		f[0].disabled=true;
		f[1].disabled=false;
	}


}
function foco()
{
	document.forms[0].num1.focus();
	
}



function StartLoad (v)
{
	campo  = v;
      //verifica se o browser tem suporte a ajax
  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
        // ajax1 = new ActiveXObject("Microsoft.XMLHTTP");		 
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
          //  ajax1 = new ActiveXObject("Msxml2.XMLHTTP");			
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            //   ajax1 = new XMLHttpRequest();			   
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
			  // ajax1 = null;
            }
         }
      }
	  

	  if (ajax)
        {
			
			if (campo == "Locais")
			{
				vDiv = document.getElementById("lista_Locais");
				vDiv.innerHTML = "";				
				vLocais = document.getElementById("Locais");
				vText = vLocais;
				var valor = vLocais.value;

			}
			if (campo == "Locais2")
			{
				vDiv = document.getElementById("lista_Locais2");
				vDiv.innerHTML = "";				
				vLocais2 = document.getElementById("Locais2");
				vText = vLocais2;
				var valor = vLocais2.value;
			}
			if (campo == "Locais3")
			{
				vDiv = document.getElementById("lista_Locais3");
				vDiv.innerHTML = "";				
				vLocais3 = document.getElementById("Locais3");
				vText = vLocais3;
				var valor = vLocais3.value;
			}

			if (campo == "Palavra_Chave")
			{
				vDiv = document.getElementById("lista_Palavra_Chave");
				vDiv.innerHTML = "";				
				vPalavra_Chave = document.getElementById("Palavra_Chave");
				vText = vPalavra_Chave;
				var valor = vPalavra_Chave.value;
			}

		
		if (valor.length > 1) 
			{
				if (campo != "Palavra_Chave")
				{
						ajax.open("get","Locais.asp?str="+valor,true);					
					}
					else
					{
						ajax.open("get","Palavra_Chave.asp?str="+valor,true);											
						}
					

				ajax.setRequestHeader("Content-Type","aplication/x-www-form-urlencode");
				//ajax1.setRequestHeader("Content-Type","aplication/x-www-form-urlencode");		
						
			   ajax.onreadystatechange = function CarregaXML()
				 {
					  if(ajax.readyState == 4 ) 
					{
					   if(ajax.responseXML)
						{
							  processXML(ajax.responseXML);
						  }
						  
					   else
						{
						   //caso não seja um arquivo XML emite a mensagem abaixo
						  vText.value = "--Não Carregado!--";
					   }
					}
				 
				 }
	
				ajax.send(null);                			
			}
			else if (valor.length == 0 )
			{
				 vDiv.style.display = "none";
			 }
		}
}

//
function processXML(obj)
{
   // pega a tag setor
   var dataArray = obj.getElementsByTagName("item");
   
    descricao = new Array();
    codigo = new Array();

   //total de elementos contidos na tag func;
  if (dataArray.length > 0)
   {
		   vDiv.style.display = "block";
		   vDiv.innerHTML = "";
      //passa o arquivo XML para extrair os dados;
      for (var i=0; i < dataArray.length; i++)
      {
      //conteudo dos campos no arquivo XML;
	//alert(dataArray[i].childNodes.item(0).text);
			   codigo[i] = dataArray[i].childNodes.item(0).text;
			  if (!codigo[i])
			  	 codigo[i] = dataArray[i].getElementsByTagName("codigo")[0].firstChild.nodeValue;

			     descricao[i] = dataArray[i].childNodes.item(1).text;
  			  if (!descricao[i])
			     descricao[i] = dataArray[i].getElementsByTagName("descricao")[0].firstChild.nodeValue;	 


			  var a = document.createElement("a");
					
			  a.setAttribute("href","javascript:PreencheCampo("+i+",'"+campo+"')");
			 // a.setAttribute("onclick","javascript:alert('teste');");
			  a.onclick = function(){
				
										vDiv.style.display = "none";
									   
										}
					
			if (campo == "Locais")
			{
			  a.innerHTML = codigo[i];
			}
			if (campo == "Locais2")
			{
			 	 a.innerHTML = codigo[i];
				
				}
			if (campo == "Locais3")
			{
			  	a.innerHTML = codigo[i];
				
				}		
			if (campo == "Palavra_Chave")
			{
				  a.innerHTML = descricao[i];
				}		
				
		  vDiv.appendChild(a);
      }
      
    }

}

function Maiuscula(cmp)
{
	cmp.value = cmp.value.toUpperCase();
	
	}
function PreencheCampo(vlr,cmp)
{
	if (cmp == "Locais")
	{
		document.getElementById("Locais").value = codigo[vlr];
		document.getElementById("Cod_Locais").value = codigo[vlr];
	}
	if (cmp == "Locais2")
	{
		document.getElementById("Locais2").value = codigo[vlr];
		document.getElementById("Cod_Locais2").value = codigo[vlr];
		
		}
	if (cmp == "Locais3")
	{
		document.getElementById("Locais3").value = codigo[vlr];
		document.getElementById("Cod_Locais3").value = codigo[vlr];
		
		}		
	if (cmp == "Palavra_Chave")
	{
		document.getElementById("Palavra_Chave").value = descricao[vlr];
		}		
		
}

function EscondeDiv(campo)
{

	if (campo == "Locais")
	{
		document.getElementById("lista_Locais2").style.display = "none";		
		document.getElementById("lista_Locais3").style.display = "none";		
		document.getElementById("lista_Palavra_Chave").style.display = "none";		
	}
	if (campo == "Locais2")
	{
		document.getElementById("lista_Locais").style.display = "none";
		document.getElementById("lista_Locais3").style.display = "none";
		document.getElementById("lista_Palavra_Chave").style.display = "none";				
		}
	if (campo == "Locais3")
	{
		document.getElementById("lista_Locais").style.display = "none";
		document.getElementById("lista_Locais2").style.display = "none";		
		document.getElementById("lista_Palavra_Chave").style.display = "none";		
		}			
	if (campo == "Palavra_Chave")
	{
		document.getElementById("lista_Locais").style.display = "none";
		document.getElementById("lista_Locais2").style.display = "none";		
		document.getElementById("lista_Locais3").style.display = "none";		
		}			
		
	
}
function EscondeDivTotal()
{
	
	document.getElementById("lista_Locais").style.display = "none";	
	document.getElementById("lista_Locais2").style.display = "none";		
	document.getElementById("lista_Locais3").style.display = "none";		
	document.getElementById("lista_Palavra_Chave").style.display = "none";		

	
	}

 
function valida(form)
{
N1 = document.form1.num1.value;
N2 = document.form1.num2.value;
N3 = document.form1.num3.value;


if (N1 == "" || N2=="" || N3=="")
{ // verifica se o campo nome está vazio
	alert("O n° do protocolo deve ser preenchido!"); // mensagem exibida se o campo não for preenchido
	document.form1.num1.focus(); // coloque esse linha no script fazendo referência ao formulário e ao campo com foco //
	return false;
}
}
function valida1()
{
vOrgao = document.getElementById("or_doc1");
vNome = document.getElementById("nomeint");
vTipoInt = document.getElementById("Tipo_Interessado");
vMatricula = document.getElementById("matricula");
vLocais  = document.getElementById("Locais");
vLocais2 = document.getElementById("Locais2");
vAssunto = document.getElementById("Assunto");
vPalavra_chave = document.getElementById("Palavra_Chave");
vNumdoc = document.getElementById("numdoc");
vAno = document.getElementById("Ano");
vLocais3 = document.getElementById("Locais3");
vDiaInicial = document.getElementById("diaInicial");
vMesInicial = document.getElementById("mesInicial");
vAnoInicial = document.getElementById("anoInicial");
vDataInicial = vDiaInicial.value + vMesInicial.value + vAnoInicial.value;
vDiaFinal = document.getElementById("diaFinal");
vMesFinal = document.getElementById("mesFinal");
vAnoFinal = document.getElementById("anoFinal");
vDataFinal = vDiaFinal.value + vMesFinal.value + vAnoFinal.value;
vTipoDoc = document.getElementById("Tipo_Doc");
vMunicipio = document.getElementById("municipio");
vEstado = document.getElementById("estado");

	if (vOrgao.value =="")
	{
		alert('Orgão não escolhido!');
		vOrgao.focus();
		return false;
	}
		else if ((vPalavra_chave.value != "") && (vAssunto.value == ""))
		{
			alert('Escolha o Assunto!');
			vAssunto.focus();
			return false;
			}
				else if ((vNumdoc.value != "")&&(vAno.value == ""))
				{
					alert('Digite o ano!');
					vAno.focus();
					return false;							
					}
					else if ((vNumdoc.value == "")&&(vAno.value != ""))
					{
						alert('Digite o número do documento!');
						vNumdoc.focus();
						return false;							
						}
						
						else if ((vNumdoc.value != "") && (vAno.value !="") && (vLocais3.value == ""))
						{
							alert('Escolha o setor de origem!');
							vLocais3.focus();
							return false;								
							}
								else if ((vAno.value <1979) && (vAno.value != ""))
								{
									alert ('Digite um ano igual ou maior que 1979!');
									vAno.value = "";
									vAno.focus();
									return false;
									}
									/*else if ((vDataInicial != "" ) && (vDataFinal == ""))
									{
										alert('Digite a data final!');
										vDiaFinal.focus();
										return false;								
										}
										else if ((vDataInicial == "" ) && (vDataFinal != ""))
										{
											alert('Digite a data Inicial!');
											vDiaInicial.focus();
											return false;								
											}*/
											else if (!validar_data(vDiaInicial.value, vMesInicial.value, vAnoInicial.value) && (vDataInicial != ""))
											{
												alert('data de início inválida!');
												vDiaInicial.value = "";
												vMesInicial.value = "";
												vAnoInicial.value = "";
												vDiaInicial.focus();
												return false;							
												}
												else if(!validar_data(vDiaFinal.value, vMesFinal.value, vAnoFinal.value) && (vDataFinal != ""))
												{
													alert('data de fim inválida!');
													vDiaFinal.value = "";
													vMesFinal.value = "";
													vAnoFinal.value = "";
													vDiaFinal.focus();
													return false;							
													}
													else if ((vAnoInicial.value != vAnoFinal.value) && vDataFinal != "")
													{
														alert ('Os anos iniciais e finais devem ser iguais');
														vAnoInicial.focus();
														return false;																			
														}
														else if((vMunicipio.value!="") && (vEstado.value == ""))
														{
															alert('Escolha o Estado!');
															vEstado.focus();
															return false;
															}
															else if((vMunicipio.value=="") && (vEstado.value!= ""))
															{
																alert('Escolha o Município');
																vMunicipio.focus();
																return false;
																}
																else if ((vNome.value == "") && (vTipoInt.value == "") && (vMatricula.value == "") && (vAssunto.value == "") && (vLocais.value == "") && (vLocais2.value == "") && (vDataInicial == "") && (vTipoDoc.value == "" ) && (vLocais3.value=="") && (vMunicipio.value=="") && (vEstado.value=="") )
																{
																	alert ('Preencha pelo menos um dos seguintes campos: Assunto, Remetente, Destinatário ,a Data Inicial e Final, a Sigla do Setor, ou o Municipio e Estado!');
																	return false;
																	}

										
return true;
}
function Valida2()
{
vOrgao = document.getElementById("or_doc2");
vNome = document.getElementById("nomeint");
vTipoInt = document.getElementById("Tipo_Interessado");
vMatricula = document.getElementById("matricula");
	
	if (vOrgao.value =="")
	{
		alert('Orgão não escolhido!');
		vOrgao.focus();
		return false;
	}
	else if (vNome.value == "" && vTipoInt.value == "" && vMatricula.value == "")
	{
		alert('Preencha ao menos mais uma opção!');
		vNome.focus();
		return false;
		}
	else if (vNome.value != "" && vTipoInt.value != "" && vMatricula.value == "")
	{
		alert('Escolha o órgão e somente mais uma opção!');
		vNome.value ="";
		vTipoInt.value = "";
		vNome.focus();
		return false;
		}	
	else if (vNome.value != "" && vTipoInt.value == "" && vMatricula.value != "")
	{
		alert('Escolha o órgão e somente mais uma opção!');
		vNome.value ="";
		vMatricula.value = "";
		vNome.focus();
		return false;
		}			
	else if (vNome.value == "" && vTipoInt.value != "" && vMatricula.value != "")
	{
		alert('Escolha o órgão e somente mais uma opção!');
		vTipoInt.value = "";
		vMatricula.value = "";
		vNome.focus();
		return false;
		}			

	
	}

function Validar_Num(e)
{
// Esta função bloqueia a digitação de teclas diferentes das numéricas e do backspace.
// A função keyCode retorna o número ASCII correspondente da tecla pressionada
// quando o navegador é o Internet Explorer
// A função which retorna o número ASCII correspondente da tecla pressionada
// quando o navegador é o Netscape ou o Firefox
  if (window.event) // Internet Explorer
   var tecla = e.keyCode; 
  else if (e.which)  // Netscape ou Firefox
       var tecla = e.which;
// número zero = 48
// número nove = 57
// tecla backspace
if ((tecla < 48 || tecla > 57) && (tecla != 8) && (tecla !=44))
  return false;
else 
   return true;
} 

function validar_data(dia, mes, ano)
{
	if(isNaN(dia))
		return false;
	if(isNaN(mes))
		return false;
	if(isNaN(ano))
		return false;
	if(dia < 1 || dia > 31 || mes < 1 || mes > 12 || ano < 1800 || ano > 2999)
		return false;	
	if((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11))
		dia_max = 30;
	else if(mes == 2)
	{
		if(ano % 400 == 0 || (ano % 4 == 0 && ano % 100 != 0))
			dia_max = 29;
		else
			dia_max = 28;	
	}
	else
		dia_max = 31;
	if(dia > dia_max)
		return false;
	return true;
}

function MudaFoco(campo,prox_campo,xData)
{
	if (campo.value.length == 2 && (xData == "dia" || xData == "mes"))
	{
		prox_campo.focus()
		
		}
	if (campo.value.length == 4 && (xData == "ano"))
	{
		prox_campo.focus()
		
		}
	
}

/*String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, ”);
}

String.prototype.ltrim = function() {
return this.replace(/^\s+/, ”);
}

String.prototype.rtrim = function() {
return this.replace(/\s+$/, ”);
}*/
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function ValidaForm()
{
	
 tab = document.form1.tabela;
 param = document.form1.parametro;
 vparam = Trim(document.form1.parametro.value); 
 
	if (tab.value==0)
	{
		alert('Selecione uma tabela para consulta');
		tab.focus();
		return false;
	}
	/*else if (((tab.value==4) || (tab.value==5) || (tab.value==6)) && (vparam==""))
	/{
		alert('Digite um parâmetro para a consulta');
		param.focus;
		return false;
	}*/
	else
	{
		return true;
	}
	

}


