
//----------------------------------------------------------------------------------------------------------
// Valida o Campo de Preenchimento da frm, não permite alguns valores como: AND, OR, NEAR e etc.
//----------------------------------------------------------------------------------------------------------
function fnTrataCaracteres(strFrase) {
   var i;
   var strAux;
   var strPalavra;   
   var exclusivo = "'and', 'or', 'xor', 'not', 'for', 'goto', 'as', 'where', 'if'";
  
   //Tira o caracter espaço do final da string
   if ((strFrase.charAt(strFrase.length - 1)) == " ")
	strFrase = strFrase.substring(0, (strFrase.length - 1));
	
   strPalavra = strFrase.toLowerCase()
   strPalavra = strPalavra.split(" ");
   i = 0;
   
   strAux = "";
   
   if (exclusivo.indexOf(strPalavra[i]) != -1){
		strAux = strPalavra[i];		
	}
	else{
		if (!fnCaracteresInvalidos(strPalavra[i]))
			return false;
	
		for (i=1; i < strPalavra.length; i++) {
			strAux = "";
			      
			if (exclusivo.indexOf(strPalavra[i]) != -1){
				strAux = strPalavra[i];
			}
			
			if (!fnCaracteresInvalidos(strPalavra[i]))
				return false;
		}
	}
   
   if (strAux != ""){
			alert("\nParâmetro '" + strAux + "' Inválido para Pesquisa");
			return false;
	} 
	      
   return true;
}

function fnCaracteresInvalidos(strPalavra) {
	var i;
	var invalidos = "@!?.,;:'#%$~`^&*()-+=/|\<>";
	
	for (i=0; i < strPalavra.length; i++) {	   
		if (invalidos.indexOf(strPalavra.charAt(i)) != -1){
			alert("\nCaracter '" + strPalavra.charAt(i) + "' Inválido para Pesquisa");
			return false;			
		}
   } 
   	
	return true;
}


function ValidaBusca(objForm) 
{  		
		var strValor = "";
		strValor = objForm.SearchString.value.length;		
		// chamar funcao passando o valor do campo
		if(objForm.SearchString.value.toUpperCase().substr(0, 4) == "AND " || objForm.SearchString.value.toUpperCase().substr(0, 3) == "OR " || objForm.SearchString.value.toUpperCase().substr(0, 5) == "NEAR " || objForm.SearchString.value.toUpperCase().substr(0, 4) == "NOT ")
		{	alert("Texto de Pesquisa Incorreto.");
			objForm.SearchString.focus();
			return false;
		}	
		if(objForm.SearchString.value.toUpperCase().substr(strValor - 4, 4) == " AND" || objForm.SearchString.value.toUpperCase().substr(strValor - 3, 3) == " OR" || objForm.SearchString.value.toUpperCase().substr(strValor - 5, 5) == " NEAR" || objForm.SearchString.value.toUpperCase().substr(strValor - 4, 4) == " NOT")
		{	alert("Texto de Pesquisa Incorreto.");
			objForm.SearchString.focus();
			return false;
		}	
		if(objForm.SearchString.value == "")
		{	alert("Preenchimento Obrigatório para Pesquisa.");
			objForm.SearchString.focus();
			return false;
		}	
		if(!fnTrataCaracteres(objForm.SearchString.value)){
					objForm.SearchString.focus();
					return false;}			
		 else 
		{
                objForm.submit();
        }
		return true;
}

//==================================


function ValidaVisita(Form) 
{
	if (form.NOME.value == "")
	{
		alert("Digite seu Nome !");
		form.NOME.focus();
		return false;
	}
	if (form.TEL.value == "")
	{
 		alert("Digite seu Telefone !");
		form.TEL.focus();
		return false;
	}
	
    if (form.ENDERECO.value == "")
	{
 		alert("Digite seu Endereço !");
		form.ENDERECO.focus();
		return false;
	}
    	
      if (form.LOCAL.value == "")
	{
 		alert("Digite o Local da Visita !");
		form.LOCAL.focus();
		return false;
	}	
	 if (form.NoVISITANTES.value=="" ) 
	  	{
            alert ("Digite o Número de Visitantes !") ;
		    form.NoVISITANTES.focus();
            return false;
         }
         
      if (form.NIVEL.value=="" ) 
	  	{
            alert ("Digite o Nível de Escolaridade !") ;
		    form.NIVEL.focus();
            return false;
         }
         
        if (form.DATAS.value=="" ) 
	  	{
            alert ("Digite a Data da Visita !") ;
		    form.DATAS.focus();
            return false;
         }
}		



//==================================


function fnTrataCaracteresNew(strFrase) {
   var i;
   var strAux;
   var strPalavra;   
   var exclusivo = "'and', 'or', 'xor', 'not', 'for', 'goto', 'as', 'where', 'if'";
  
   //Tira o caracter espaço do final da string
   if ((strFrase.charAt(strFrase.length - 1)) == " ")
	strFrase = strFrase.substring(0, (strFrase.length - 1));
	
   strPalavra = strFrase.toLowerCase()
   strPalavra = strPalavra.split(" ");
   i = 0;
   
   strAux = "";
   
   if (exclusivo.indexOf(strPalavra[i]) != -1){
		strAux = strPalavra[i];		
	}
	else{
		if (!fnCaracteresInvalidosNew(strPalavra[i]))
			return false;
	
		for (i=1; i < strPalavra.length; i++) {
			strAux = "";
			      
			if (exclusivo.indexOf(strPalavra[i]) != -1){
				strAux = strPalavra[i];
			}
			
			if (!fnCaracteresInvalidosNew(strPalavra[i]))
				return false;
		}
	}
   
   if (strAux != ""){
			alert("\nParâmetro '" + strAux + "' Inválido para Pesquisa");
			return false;
	} 
	      
   return true;
}

function fnCaracteresInvalidosNew(strPalavra) {
	var i;
	var invalidos = "@!?.,;:'#%$~`^&*()-+=/|\<>";
	
	for (i=0; i < strPalavra.length; i++) {	   
		if (invalidos.indexOf(strPalavra.charAt(i)) != -1){
			alert("\nCaracter '" + strPalavra.charAt(i) + "' Inválido para Pesquisa");
			return false;			
		}
   } 
   	
	return true;
}


function ValidaBuscaNew(objForm) 
{  		
		var strValor = "";
		strValor = objForm.SearchString.value.length;		
		// chamar funcao passando o valor do campo
		if(objForm.SearchString.value.toUpperCase().substr(0, 4) == "AND " || objForm.SearchString.value.toUpperCase().substr(0, 3) == "OR " || objForm.SearchString.value.toUpperCase().substr(0, 5) == "NEAR " || objForm.SearchString.value.toUpperCase().substr(0, 4) == "NOT ")
		{	alert("Texto de Pesquisa Incorreto.");
			objForm.SearchString.focus();
			return false;
		}	
		if(objForm.SearchString.value.toUpperCase().substr(strValor - 4, 4) == " AND" || objForm.SearchString.value.toUpperCase().substr(strValor - 3, 3) == " OR" || objForm.SearchString.value.toUpperCase().substr(strValor - 5, 5) == " NEAR" || objForm.SearchString.value.toUpperCase().substr(strValor - 4, 4) == " NOT")
		{	alert("Texto de Pesquisa Incorreto.");
			objForm.SearchString.focus();
			return false;
		}	
		if(objForm.SearchString.value == "")
		{	alert("Preenchimento Obrigatório para Pesquisa.");
			objForm.SearchString.focus();
			return false;
		}	
		if(!fnTrataCaracteresNew(objForm.SearchString.value)){
					objForm.SearchString.focus();
					return false;}			
		 else 
		{
                objForm.submit();
        }
		return true;
}

// -->

