/*
  Dental Morelli Ltda.
  Tecnologia da Informação - TI
  
  Data                 Programador                     SATI   Comentários
  25/01/2006		   Paulo S. Aguiar				   34072  Acrescentar as funções setPointer e Mostrar_Ocultar_DIV 
  23/02/2006           Paulo S. Aguiar				   35712  Acrescentar a função openAjax().	
  15/11/2006		   Paulo S. Aguiar				   41208  Ajuste na função F_ProcessaAJAX_CFC para receber mais um param. 	
  17/11/2006           Fernando Francisco de Oliveira  41326  Alteração para retornar a string de HTML nas funções de AJAX
  26/12/2006		   Paulo S. Aguiar				   42001  Acrescentar a função F_ProcessaAJAX_WDDX	
  11/05/2007           Fernando F.Oliveira             45551  Colocado encodeURI na função ajax
  16/12/2009		   Paulo S. Aguiar				   63620  Ajuste na função validar_campo	  	
[-------------------------------------------------------------------------------------------------------------] 
*/


var marked_row = new Array;

emptyString = /^\s*$/

/* ############################################################################################################### */
function SoNumeros(e)
{
	if ( window.event ) { // IE
		if ( window.event.keyCode < 48 || window.event.keyCode > 57 ) {
		   window.event.keyCode = 0;
		}
	}
	else 
	if ( e.which ) { // NETSCAPE
		if ( e.which < 48 || e.which > 57 ) {
			return false;
		}
	}
}
	
/* ############################################################################################################### */
function Nome_OnBlur( form ) {
		 if ( form.Apelido.value.length == 0 ) {
			var nome = form.Nome.value;
			
			if ( nome.indexOf( ' ' ) == -1 ) {
			   form.Apelido.value = nome;
			} 
			else
			{
			   form.Apelido.value = nome.substr( 0, nome.indexOf( ' ' ) );
			}
		 }
}


/* ############################################################################################################### */
function validar_campo(campo) {
	
	if ( campo ){
		if ( ( campo.type == 'text' ) || ( campo.type == 'password' ) ) {
			if ( campo.title ) 
				titulo = campo.title
			else
				titulo = campo.name;
				
			if ( emptyString.test(campo.value) ) {
				alert( 'O campo ' + titulo + ' deve ser preenchido!' );
				campo.focus();
				return false;
			}
		}
	}
	return true;
}


/* ############################################################################################################### */
//Verifica se string é numérica
function isNum(str)
{
      var VBlnIsNum;
      VIntTam = str.length;
      VBlnIsNum = true;

      if (VIntTam == 0) {
         return false;
      }
      else
      {
         for (i=0; i < VIntTam; i++) {
            if (str.substring(i,i+1) < '0' || str.substring(i,i+1) > '9') {
               VBlnIsNum = false;
            }
         }
         return VBlnIsNum;
      }
}


/* ############################################################################################################### */
//Função de validação de CPF
function isCPF(st) {
    if (st == "")
       return (false);
    
    l = st.length;

    //aleterado para se usuário não digitar os zeros na frente do CPF, completar sozinho
    if ((l == 9) || (l == 8))
    {
      for (i = l ; i < 10; i++) {
          st = '0' + st
      }
    }
    l = st.length;
    st2 = "";
for (i = 0; i < l; i++) {
  caracter = st.substring(i,i+1);
  if ((caracter >= '0') && (caracter <= '9'));
     st2 = st2 + caracter;
}
if ((st2.length > 11) || (st2.length < 10))
   return (false);
if (st2.length==10)
   st2 = '0' + st2;
digito1 = st2.substring(9,10);
digito2 = st2.substring(10,11);
digito1 = parseInt(digito1,10);
digito2 = parseInt(digito2,10);
sum = 0; mul = 10;
for (i = 0; i < 9 ; i++) {
    digit = st2.substring(i,i+1);
    tproduct = parseInt(digit ,10) * mul;
    sum += tproduct;
    mul--;
}
dig1 = ( sum % 11 );
if ( dig1==0 || dig1==1 )
   dig1=0;
else
  dig1 = 11 - dig1;
if (dig1!=digito1)
  return (false);
sum = 0;
mul = 11;
for (i = 0; i < 10 ; i++) {
    digit = st2.substring(i,i+1);
    tproduct = parseInt(digit ,10)*mul;
    sum += tproduct;
    mul--;
}
dig2 = (sum % 11);
if ( dig2==0 || dig2==1 )
  dig2=0;
else
  dig2 = 11 - dig2;
if (dig2 != digito2)
  return (false);
return (true);
}

/* ############################################################################################################### */
/**********************************************************************
Arquivo de funções em Java Script para validação de campos

Desenvolvedor	: Leandro Silva Ferreira
E-mail			: leandro@i9web.com.br


Qualquer dúvida, sugestão ou melhoramento dos scripts, por favor
me envie um e-mail.

/**********************************************************************/ 

/**********************************************************************
Função de formatação de valores numéricos na digitação

Objetivos :
	- Inclusão automática de . e ,

Parametros :
	objeto		-> Nome do campo de formulário (Usar this)
	teclapres	-> Tecla pressionada (Usar event)
	tammax		-> Tamanho máximo de caracteres
	decimais	-> Nº de casas decimais

Exemplo:
	OnKeyDown     FormataValor(this,event,17,0);


/**********************************************************************/ 
function FormataValor(objeto,teclapres,tammax,decimais) 
{

	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;

	if ((tecla == 8) && (tamanhoObjeto == tammax))
	{
		tamanhoObjeto = tamanhoObjeto - 1 ;
	}



if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
	{

		vr	= objeto.value;
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( ",", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		tam	= vr.length;
		
		if (tam < tammax && tecla != 8)
		{
			tam = vr.length + 1 ;
		}

		if ((tecla == 8) && (tam > 1))
		{
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
		}
	
		//Cálculo para casas decimais setadas por parametro
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if (decimais > 0)
			{
				if ( (tam <= decimais) )
				{ 
					objeto.value = ("0," + vr) ;
				}
				if( (tam == (decimais + 1)) && (tecla == 8))
				{
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
				{
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				{
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
				}
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			}
			else if(decimais == 0)
			{
				if ( tam <= 3 )
				{ 
			 		objeto.value = vr ;
				}
				if ( (tam >= 4) && (tam <= 6) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 7) && (tam <= 9) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 10) && (tam <= 12) )
				{
			 		if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 13) && (tam <= 15) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
				}			
			}
		}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}

/* ############################################################################################################### */
/********************************************************************** 
Função de formatação de campos tipo texto durante a digitação

Objetivos :
	- Mudar tudo para maiúsculo
	- Não aceitar acentos nem Ç

Parâmetros :
	objeto		-> Nome do campo de formulário (Usar this)

Exemplo : 
	OnKeyPress    FormataTexto(this);
/**********************************************************************/
function FormataTexto(objeto, maximo)
{
	var valor = objeto.value;	
	var LetrasArray = new Array();

	LetrasArray[1] = new Array();
	LetrasArray[2] = new Array();
	
	//Primeira Coluna : Letras Acentuadas e Símbolos
	LetrasArray[1][ 1]= chr(225); //'á';
	LetrasArray[1][ 2]= chr(227); //'ã';
	LetrasArray[1][ 3]= chr(224); //'à';
	LetrasArray[1][ 4]= chr(226); //'â';
	LetrasArray[1][ 5]= chr(228); //'ä';
	LetrasArray[1][ 6]= chr(233); //'é';
	LetrasArray[1][ 7]= chr(232); //'è';
	LetrasArray[1][ 8]= chr(234); //'ê';
	LetrasArray[1][ 9]= chr(235); //'ë';
	LetrasArray[1][10]= chr(237); //'í';
	LetrasArray[1][11]= chr(236); //'ì';
	LetrasArray[1][12]= chr(238); //'î';
	LetrasArray[1][13]= chr(239); //'ï';
	LetrasArray[1][14]= chr(243); //'ó';
	LetrasArray[1][15]= chr(245); //'õ';
	LetrasArray[1][16]= chr(242); //'ò';
	LetrasArray[1][17]= chr(244); //'ô';
	LetrasArray[1][18]= chr(246); //'ö';
	LetrasArray[1][19]= chr(250); //'ú';
	LetrasArray[1][20]= chr(249); //'u';
	LetrasArray[1][21]= chr(251); //'u';
	LetrasArray[1][22]= chr(252); //'u';
	LetrasArray[1][23]= chr(231); //'ç';
	LetrasArray[1][24]= chr(193); //'Á';
	LetrasArray[1][25]= chr(195); //'Ã';
	LetrasArray[1][26]= chr(192); //'À';
	LetrasArray[1][27]= chr(194); //'Â';
	LetrasArray[1][28]= chr(196); //'Ä';
	LetrasArray[1][29]= chr(201); //'É';
	LetrasArray[1][30]= chr(200); //'È';
	LetrasArray[1][31]= chr(202); //'Ê';
	LetrasArray[1][32]= chr(203); //'Ë';
	LetrasArray[1][33]= chr(205); //'Í';
	LetrasArray[1][34]= chr(204); //'Ì';
	LetrasArray[1][35]= chr(206); //'Î';
	LetrasArray[1][36]= chr(207); //'Ï';
	LetrasArray[1][37]= chr(211); //'Ó';
	LetrasArray[1][38]= chr(213); //'Õ';
	LetrasArray[1][39]= chr(210); //'Ò';
	LetrasArray[1][40]= chr(212); //'Ô';
	LetrasArray[1][41]= chr(214); //'Ö';
	LetrasArray[1][42]= chr(218); //'Ú';
	LetrasArray[1][43]= chr(217); //'Ù';
	LetrasArray[1][44]= chr(219); //'Û';
	LetrasArray[1][45]= chr(220); //'Ü';
	LetrasArray[1][46]= chr(199); //'Ç';
	LetrasArray[1][47]= chr(209); //'Ñ';
	LetrasArray[1][48]= chr(241); //'ñ';
	LetrasArray[1][49]= chr(126); //'~';
	LetrasArray[1][50]= chr( 94); //'^';
	LetrasArray[1][51]= chr(180); //'´';
	LetrasArray[1][52]= chr( 96); //'`';
	
	//Segunda Coluna : Letras Equivalentes sem acentos
	LetrasArray[2][ 1]='a';
	LetrasArray[2][ 2]='a';
	LetrasArray[2][ 3]='a';
	LetrasArray[2][ 4]='a';
	LetrasArray[2][ 5]='a';
	LetrasArray[2][ 6]='e';
	LetrasArray[2][ 7]='e';
	LetrasArray[2][ 8]='e';
	LetrasArray[2][ 9]='e';
	LetrasArray[2][10]='i';
	LetrasArray[2][11]='i';
	LetrasArray[2][12]='i';
	LetrasArray[2][13]='i';
	LetrasArray[2][14]='o';
	LetrasArray[2][15]='o';
	LetrasArray[2][16]='o';
	LetrasArray[2][17]='o';
	LetrasArray[2][18]='o';
	LetrasArray[2][19]='u';
	LetrasArray[2][20]='u';
	LetrasArray[2][21]='u';
	LetrasArray[2][22]='u';
	LetrasArray[2][23]='c';
	LetrasArray[2][24]='A';
	LetrasArray[2][25]='A';
	LetrasArray[2][26]='A';
	LetrasArray[2][27]='A';
	LetrasArray[2][28]='A';
	LetrasArray[2][29]='E';
	LetrasArray[2][30]='E';
	LetrasArray[2][31]='E';
	LetrasArray[2][32]='E';
	LetrasArray[2][33]='I';
	LetrasArray[2][34]='I';
	LetrasArray[2][35]='I';
	LetrasArray[2][36]='I';
	LetrasArray[2][37]='O';
	LetrasArray[2][38]='O';
	LetrasArray[2][39]='O';
	LetrasArray[2][40]='O';
	LetrasArray[2][41]='O';
	LetrasArray[2][42]='U';
	LetrasArray[2][43]='U';
	LetrasArray[2][44]='U';
	LetrasArray[2][45]='U';
	LetrasArray[2][46]='C';
	LetrasArray[2][47]='N';
	LetrasArray[2][48]='n';
	LetrasArray[2][49]='';
	LetrasArray[2][50]='';
	LetrasArray[2][51]='';
	LetrasArray[2][52]='';

	temp = "" + valor + (String.fromCharCode(window.event.keyCode));
    
    if ( temp.length > maximo ) {
        window.event.keyCode=0;
    }
    else
    {

	for (i=1; i<=52 ; i++ )
	{
		while (temp.indexOf((LetrasArray[1][i]))>-1)
			{
				pos= temp.indexOf((LetrasArray[1][i]));
				temp = "" + (temp.substring(0, pos) + (LetrasArray[2][i]) + temp.substring((pos + (LetrasArray[1][i].length)), temp.length));
			}
	}
	if((window.event.keyCode) != 13)
		{
            if (maximo != null) {
                temp = temp.substring(temp,1,maximo);
            }
			objeto.value = (temp.toUpperCase());
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
    
    }

}

/* ############################################################################################################### */
/********************************************************************** 
Função de validação de campos do tipo Data

Objetivos :
	- Aceitar somente datas do tipo : dd/mm/aaaa

Parâmetros :
	objeto		-> Nome do campo de formulário (Usar this)

Exemplo : 
	OnChange    ValidaData(this);
/**********************************************************************/ 
function ValidaData(objeto) 
{

	var DataString	= objeto.value;
	var DataArray	= DataString.split("/");  
	var Flag=true; 

	if (DataArray.length != 3) 
		Flag=false; 
	else 
		{
			if (DataArray.length==3) 
			{
				var dia = DataArray[0], mes = DataArray[1], ano = DataArray[2]; 

				if (((Flag) && (ano<1000) || ano.length>4)) 
					Flag=false; 
				
				if (Flag) 
				{ 
					verifica_mes = new Date(mes+"/"+dia+"/"+ano); 
					if (verifica_mes.getMonth() != (mes - 1)) 
						Flag=false; 
				} 
			} 
			else 
				Flag=false; 
		} 
return Flag;
} 

/* ############################################################################################################### */
/********************************************************************** 
Função de formatação de campos do tipo Data

Objetivos :
	- Mascarar a entrada de dados no formato : dd/mm/aaaa

Parâmetros :
	objeto		-> Nome do campo de formulário (Usar this)
	teclapress	-> Tecla pressionada (Usar event)

Exemplo : 
	OnKeyDown    FormataData(this,event);

Requirido :
	Função ValidaData
/**********************************************************************/ 
function FormataData(objeto,teclapress)
{
	if ( window.event ) { // IE		
		var tecla = teclapress.keyCode;
	
		if(((window.event.keyCode == 13) || (window.event.keyCode == 9))&&objeto.value != "")
		{
			if(!(ValidaData(objeto)))
				{
					window.event.cancelBubble = true;
					window.event.returnValue = false;
					window.alert("Data Inválida");
					objeto.value = "";
					objeto.focus();
				}
		}
	
		if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )&& objeto.value.length < (10))
		{
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			tam = vr.length;
	
			if (tam < 8)
				{
					if (tecla != 8) {tam = vr.length + 1 ;}
				}
			else
				{
					window.event.cancelBubble = true;
					window.event.returnValue = false;
				}
			
			if ((tecla == 8) && (tam > 1))
				{
					tam = tam - 1 ;
					objeto.value = vr.substr(0,tam);
					window.event.cancelBubble = true;
					window.event.returnValue = false;
				}
					if ( tam <= 4 && tecla != 8){ 
						objeto.value = vr ; }
	
					if ( (tam >= 4) && (tam <= 6) ){
						objeto.value = vr.substr(0, tam - 4) + '/' + vr.substr( tam - 4, 4 ); }
	
					if ( (tam >= 6) && (tam <= 8) ){
						objeto.value = vr.substr(0, tam - 6 ) + '/' + vr.substr( tam - 6, 2 ) + '/' + vr.substr( tam - 4, 4 ); }
	
					if ((tam == (8)) && tecla != 8)
						{
							if(tecla >=96 && tecla <=105)
								{
									tecla = tecla - 48;
								}
	
							objeto.value = objeto.value + (String.fromCharCode(tecla));
							window.event.cancelBubble = true;
							window.event.returnValue = false;
	
							if (!(ValidaData(objeto)))
								{
									window.alert("Data Inválida");
									objeto.value = "";
									objeto.focus();
								}
						}
		}
		else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
			{
				event.returnValue = false;
			}
	}
	else 
	if ( teclapress.which ) { // NETSCAPE
		var tecla = teclapress.keyCode;
	
		if(((teclapress.which.keyCode == 13) || (teclapress.which.keyCode == 9))&&objeto.value != "")
		{
			if(!(ValidaData(objeto)))
				{
					teclapress.which.cancelBubble = true;
					teclapress.which.returnValue = false;
					window.alert("Data Inválida");
					objeto.value = "";
					objeto.focus();
				}
		}
	
		if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )&& objeto.value.length < (10))
		{
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			tam = vr.length;
	
			if (tam < 8)
				{
					if (tecla != 8) {tam = vr.length + 1 ;}
				}
			else
				{
					teclapress.which.cancelBubble = true;
					teclapress.which.returnValue = false;
				}
			
			if ((tecla == 8) && (tam > 1))
				{
					tam = tam - 1 ;
					objeto.value = vr.substr(0,tam);
					teclapress.which.cancelBubble = true;
					teclapress.which.returnValue = false;
				}
					if ( tam <= 4 && tecla != 8){ 
						objeto.value = vr ; }
	
					if ( (tam >= 4) && (tam <= 6) ){
						objeto.value = vr.substr(0, tam - 4) + '/' + vr.substr( tam - 4, 4 ); }
	
					if ( (tam >= 6) && (tam <= 8) ){
						objeto.value = vr.substr(0, tam - 6 ) + '/' + vr.substr( tam - 6, 2 ) + '/' + vr.substr( tam - 4, 4 ); }
	
					if ((tam == (8)) && tecla != 8)
						{
							if(tecla >=96 && tecla <=105)
								{
									tecla = tecla - 48;
								}
	
							objeto.value = objeto.value + (String.fromCharCode(tecla));
							teclapress.which.cancelBubble = true;
							teclapress.which.returnValue = false;
	
							if (!(ValidaData(objeto)))
								{
									window.alert("Data Inválida");
									objeto.value = "";
									objeto.focus();
								}
						}
		}
		else if((teclapress.which.keyCode != 8) && (teclapress.which.keyCode != 9) && (teclapress.which.keyCode != 13) && (teclapress.which.keyCode != 35) && (teclapress.which.keyCode != 36) && (teclapress.which.keyCode != 46))
			{
				teclapress.which.returnValue = false;
			}				
	}		
}

/* ############################################################################################################### */
/********************************************************************** 
Função de validação de campos do tipo Data Hora

Objetivos :
	- Aceitar somente datas do tipo : dd/mm/aaaa hh:mm:ss

Parâmetros :
	objeto		-> Nome do campo de formulário (Usar this)

Exemplo : 
	OnChange    ValidaDataHora(this);
/**********************************************************************/ 
function ValidaDataHora(objeto) 
{        
	var DataHoraString	= objeto.value;
	var Flag			= true;
	
	if(DataHoraString != "" &&((DataHoraString.indexOf("/")!= -1) && (DataHoraString.indexOf(" ")!= -1) && (DataHoraString.indexOf(":")!= -1)))
	{
//		dd/mm/aaaa hh:mm:ss
		var DataArray	= DataHoraString.split("/");  
//		DataArray[0]	= dd;
//		DataArray[1]	= mm;	
//		DataArray[2]	= aaaa hh:mm:ss	;

		var AuxArray	= DataArray[2].split(" ");
//		AuxArray[0]		= aaaa;
//		AuxArray[1]		= hh:mm:ss;
	
		DataArray[2]	= AuxArray[0];
	
		var HoraArray	= AuxArray[1].split(":");
//		HoraArray[0]	= hh;
//		HoraArray[1]	= mm;
//		HoraArray[2]	= ss;

		if(HoraArray[2] >= 0){Flag = true;} 
	}
	else {Flag= false;}

if(Flag)
	{
		//Valida a data
		if (DataArray.length != 3) 
			Flag=false; 
		else 
			{
				if (DataArray.length==3) 
				{
					var dia = DataArray[0], mes = DataArray[1], ano = DataArray[2]; 
	
					if (((Flag) && (ano<1000) || ano.length>4)) 
						Flag=false; 
					
					if (Flag) 
					{ 
						verifica_mes = new Date(mes+"/"+dia+"/"+ano); 
						if (verifica_mes.getMonth() != (mes - 1)) 
							Flag=false; 
					} 
				} 
				else 
					Flag=false; 
			} 
	
		//Valida a hora
		if (HoraArray.length != 3) 
			Flag=false; 
		else 
			{
				if (HoraArray.length==3) 
				{
					var hora = HoraArray[0], min = HoraArray[1], seg = HoraArray[2]; 
					
					if(!((hora>=0 && hora <=23) && (min>=0 && min<=59) && (seg>=0 && seg<=59)))
						Flag=false;
				} 
				else 
					Flag=false; 
			} 
	}		
return Flag;
} 

/* ############################################################################################################### */
/********************************************************************** 
Função de formatação de campos do tipo Data Hora

Objetivos :
	- Mascarar a entrada de dados no formato : dd/mm/aaaa hh:mm:ss

Parâmetros :
	objeto		-> Nome do campo de formulário (Usar this)
	teclapress	-> Tecla pressionada (Usar event)

Exemplo : 
	OnKeyPress    FormataDataHora(this);

Requirido :
	Função ValidaDataHora(objeto);
/**********************************************************************/ 
function FormataDataHora(objeto,teclapress)
{
	var tecla = teclapress.keyCode;

	if(((window.event.keyCode == 13) || (window.event.keyCode == 9))&&objeto.value != "")
	{
		if(!(ValidaDataHora(objeto)))
			{
				window.event.cancelBubble = true;
				window.event.returnValue = false;
				alert("Data Hora Inválida");
				objeto.value = "";
				objeto.focus();
			}
	}

	if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )&& objeto.value.length <= (19))
    {
		vr = objeto.value;
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( " ", "" );
		vr = vr.replace( ":", "" );
		vr = vr.replace( ":", "" );
		tam = vr.length;

		if (tam < 14)
			{
				if (tecla != 8) {tam = vr.length + 1 ;}
			}
		else
			{
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
		
		if ((tecla == 8) && (tam > 1))
			{
				tam = tam - 1 ;
				objeto.value = vr.substr(0,tam);
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
				if ( tam <= 2 && tecla != 8){ 
			 		objeto.value = vr ; }

				if ( (tam >= 2) && (tam <= 4) ){
			 		objeto.value = vr.substr(0, tam - 2) + ':' + vr.substr( tam - 2, 2 ); }

				if ( (tam >= 4) && (tam <= 6) ){
					objeto.value = vr.substr(0, tam - 4 ) + ':' + vr.substr( tam - 4, 2 ) + ':' + vr.substr( tam - 2, 2 ); }

				if ( (tam >= 6) && (tam <= 10) ){
					objeto.value = vr.substr(0, tam - 6 ) + ' ' + vr.substr( tam - 6, 2 ) + ':' + vr.substr( tam - 4, 2 ) + ':' + vr.substr( tam - 2, 2 ); }


				if ( (tam >= 10) && (tam <= 12) ){
					objeto.value = vr.substr(0, tam - 10 ) + '/' + vr.substr( tam - 10, 4 ) + ' ' + vr.substr( tam - 6, 2 ) + ':' + vr.substr( tam - 4, 2 ) + ':' + vr.substr( tam - 2, 2 ) ;}			

				if ( (tam >= 12) && (tam <= 14) ){
					objeto.value = vr.substr(0, tam - 12 ) + '/' + vr.substr( tam - 12, 2 ) + '/' + vr.substr( tam - 10, 4 ) + ' ' + vr.substr( tam - 6, 2 ) + ':' + vr.substr( tam - 4, 2 ) + ':' + vr.substr( tam - 2, 2 ) ;}			

				if ((tam == (14)) && tecla != 8)
					{
						if (!(ValidaDataHora(objeto)))
							{
								if(tecla >=96 && tecla <=105){tecla = tecla - 48;}
								objeto.value = objeto.value + (String.fromCharCode(tecla));
								window.event.cancelBubble = true;
								window.event.returnValue = false;
								alert("Data Hora Inválida");
								objeto.value = "";
								objeto.focus();
							}
					}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			event.returnValue = false;
		}
}

/* ############################################################################################################### */
function Mostrar_Ocultar_DIV(NomeDiv) {
	oDivMudar = document.getElementById(NomeDiv);
			
	if ( oDivMudar ) {	
			if ( oDivMudar.className == 'SecaoHidden' ) {
				oDivMudar.className = 'SecaoVisivel';
				}
			else {
				oDivMudar.className = 'SecaoHidden';				
			}
		}
	}

/* ############################################################################################################### */
function SetVisible( oDiv, visivel ) {

	oDivMudar = document.getElementById(oDiv);
			
	if ( oDivMudar ) {	
		if ( visivel ) 
			oDivMudar.style.visibility = 'visible'
		else
			oDivMudar.style.visibility = 'hidden';
	}
}

/* ############################################################################################################### */
function SetHTML( oDiv, HTML ) {

	oDivMudar = document.getElementById(oDiv);
			
	if ( oDivMudar ) {	
		oDivMudar.innerHTML = HTML;
	}
}

/* ############################################################################################################### */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function



/* ############################################################################################################### */
// Função para iniciarmos o Ajax no browser do cliente.
function openAjax() {
	var ajax;
	
	try{
		ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers decentes, como: Firefox, Safari, dentre outros.
	}
	catch(ee){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
		}
		catch(e){
			try{
				ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
			}
			catch(E){
				ajax = false;
			}
		}
	}
	return ajax;
}

/* ############################################################################################################### */
// Função para buscar dados com Ajax.
function F_BuscaHTML_AJAX( URLGet, id_oResultado, Nao_Aguardar_Retorno_Dados, NaoUsarCache ) {
	var retorno = '';
	if(document.getElementById) {
		var oExibeResultado = MM_findObj( id_oResultado );
		
		if (!oExibeResultado){
			window.alert("Não possível encontrar o objeto para receber o retorno do AJAX!");
			return;
		}
		
		if ( URLGet.trim() == "" ){
			window.alert("É necessário passar a URL para busca dos dados pelo AJAX!");
			return;				
		}
		
		if ( NaoUsarCache == undefined || NaoUsarCache ) {			
			var Hora = noCache();
		}
		else		
			var Hora = '';
			
		var ajax = openAjax(); 
		
		ajax.open("GET", URLGet + Hora, Nao_Aguardar_Retorno_Dados ); 
		
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) { 
				if(ajax.status == 200) {
					var resultado = ajax.responseText; 
					resultado = resultado.replace('<META NAME="ColdFusionMXEdition" CONTENT="ColdFusion DevNet Edition - Not for Production Use.">', " ");
					resultado = unescape(resultado); 
				
					oExibeResultado.innerHTML = resultado.trim();
					
					retorno = resultado.trim();
				}
				else{
					oExibeResultado.innerHTML = ajax.responseText; //"N&atilde;o h&aacute; resultados com termo pesquisado!";
					retorno = oExibeResultado.innerHTML;
				} 
			}
		}
		ajax.send(null); 
	} 
	
	return (retorno);
}	


/* ############################################################################################################### */
// Função para buscar dados com Ajax.
function F_BuscaDadosAJAX( operacao, Parametros, id_oCampoPesquisa, id_oResultado, Nao_Aguardar_Retorno_Dados, NaoUsarCache ) {
	var retorno = '';
	if(document.getElementById) {
		var oCampoPesquisa  = MM_findObj( id_oCampoPesquisa );
		
		var Termo           = "";
		
		if (oCampoPesquisa){
			Termo = oCampoPesquisa.value;
		}
		
		retorno = F_ProcessaAJAX_CFC( operacao, encodeURI( Parametros + Termo), id_oResultado, Nao_Aguardar_Retorno_Dados, NaoUsarCache );
	} 
	return (retorno);
}	

/* ############################################################################################################### */
// Função para buscar dados com Ajax.
function F_ProcessaAJAX_CFC( operacao, parametros, id_oresultado, Nao_Aguardar_Retorno_Dados, NaoUsarCache, URLRaizSite ) {
	var retorno = '';
	if (!URLRaizSite){
		URLRaizSite = "";
	}
	retorno = F_BuscaHTML_AJAX( URLRaizSite + 'Includes/Processar_Ajax.cfm?Objeto=' + operacao + '&' + parametros,
					   id_oresultado, Nao_Aguardar_Retorno_Dados, NaoUsarCache );
	return (retorno);
}


/* ############################################################################################################### */
// Função para buscar dados com Ajax e WDDX.
function F_ProcessaAJAX_WDDX(operacao, parametros, Nao_Aguardar_Retorno_Dados, NaoUsarCache, URLRaizSite) {
	//esta função retorna informações javascript gerados por cfwddx
	
	if (!Nao_Aguardar_Retorno_Dados) {
		Nao_Aguardar_Retorno_Dados = false;
	}
	
	if (!URLRaizSite){
		URLRaizSite = "";
	}	
	
	var resultado = "";	
	var url		  = URLRaizSite + 'Includes/Processar_Ajax.cfm?Objeto=' + operacao + '&' + encodeURI(parametros) + noCache();	
	
	try{
		var req    = openAjax(); 		
		
		req.onreadystatechange = function(){
			switch(req.readyState){
				case 1: break;
				case 2: break;
				case 3: break;
				case 4:
					if ( req.status == 200 ){
						try{
							resultado = req.responseText; 
							resultado = resultado.replace('<META NAME="ColdFusionMXEdition" CONTENT="ColdFusion DevNet Edition - Not for Production Use.">', " ");
							resultado = unescape(resultado); 
						}catch(e){ 
							window.alert('Parsing Error: O valor retornado não pode ser avaliado(httpAjax).')
						}
					}else{ 
						window.alert("Ocorreu um problema no retorno dos dados(httpAjax):\n" + req.statusText);
					}
					break;
			}
		}
		req.open( "GET" , url, Nao_Aguardar_Retorno_Dados );				
		req.send(null);
	}catch(e){
		window.alert('Erro montar a requisição(AJAX).');
	}
	return eval(resultado.trim());
}

/* ############################################################################################################### */
function noCache(){
	var thetime=new Date();

	var nhours=thetime.getHours();
	var nmins=thetime.getMinutes();
	var nsecn=thetime.getSeconds();
	
	var Hora = '&AjaxHora=' + nhours+"-"+nmins+"-"+nsecn;
	
	return Hora;
}
							
/* ############################################################################################################### */
/**
 * Adiciona método trim() à classe String.
 * Elimina brancos no início e fim da String.
 */
String.prototype.trim = function(){
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
} //String.trim
