var bolMozilla	= !(document.all);
//var objAjax		= "null";
var objData		= new Date();
var bolErroAjax = false;


function click(e) {
	strEndereco = window.location.href;
	intComeco = strEndereco.indexOf("//",0)+2;
	intFim = strEndereco.indexOf("/", intComeco) - intComeco;
	if(typeof(event)=="object"){
		if(event.button==2 || event.button==3){
			if(strEndereco.substr(intComeco,intFim) == "www.gboex.com.br") {
				alert('Propriedade GBOEX.\nAcesso não permitido.');
			}
		}
	}
}
document.onmousedown=click;

function SetHelp(txt) { help.innerText = txt ; }

function main(campofoco) { 
	var i;
	if (campofoco == '') 
		return false;
	if(document.form)
	{
		// verifica se existe mais de um formulário definidos com mesmo nome
		if(document.forms.length > 1)
			// se existir, percorre os elementos de todos os formulários com nome form
		   	for (i = 0; i < document.form.length; i++)
		  		for (j = 0; j < document.form1[i].elements.length; j++)
				{
				   	if (campofoco == document.form1[i].elements[j].name)
						document.form1[i].elements[campofoco].focus();  
				}
		else if (document.forms.length == 1)
			   	for (i = 0; i < document.form.elements.length; i++)
				{
				   	if (campofoco == document.form1[i].name)
						document.form1[campofoco].focus();  
				}
	}
}

function Apaga(){
	if(document.form)
	{
		// verifica se existe mais de um formulário definidos com mesmo nome
		if(document.forms.length > 1)
			// se existir, percorre os elementos de todos os formulários com nome form
		   	for (i = 0; i < document.form.length; i++)
		  		for (j = 0; j < document.form1[i].elements.length; j++)
				{
					var element = document.form1[i].elements[j];
					if(element.nodeName == "INPUT" && element.type == "text")
	  				    element.value="";  
				}	
			// só existe um formulário cujos elementos são zerados
		else if (document.forms.length == 1)
			   	for (i = 0; i < document.form.elements.length; i++)
				{
					var element = document.form1[i];
					if(element.nodeName == "INPUT" && element.type == "text")
	  				    element.value="";  
				}	
	}
}


var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage()
{
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function FormataDado(campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form1[campo].value;
	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 = tam - 1 ; }
			
	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form1[campo].value = vr ;}
		if ( tam > pos && tam <= tammax ){
			document.form1[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
}

function FormataValor(campo,tammax,teclapres) {
	
	if(typeof(campo)=="undefined" && typeof(tammax)=="undefined" && typeof(teclapres)=="undefined"){
		formataValor();
	} else {
		objcampo = (typeof(campo)=="object")?campo:document.form1[campo];
    
		vr=objcampo.value;
		var tecla = teclapres.keyCode;
		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 = tam - 1 ; }
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= 2 ){ 
				objcampo.value = vr ; }
			if ( (tam > 2) && (tam <= 5) ){
				objcampo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 6) && (tam <= 8) ){
				objcampo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 9) && (tam <= 11) ){
				objcampo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 12) && (tam <= 14) ){
				objcampo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 15) && (tam <= 17) ){
				objcampo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
		}
	}
	
}


function FormataFator(campo,tammax,teclapres) {
    var tecla = teclapres.keyCode;
    vr = document.form1[campo].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 = tam - 1 ; }

    if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
        if ( tam <= 7 ){
             document.form1[campo].value = vr ; }
         if ( (tam > 7) && (tam <= 11) ){
             document.form1[campo].value = vr.substr( 0, tam - 7 ) + ',' + vr.substr( tam - 7, tam ) ; }
    }
}

function SaltaCampo (campo,prox,tammax,teclapres){

	var tecla = teclapres.keyCode;	
	vr = document.form1[campo].value;
	if( tecla == 109 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.form1[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	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 (tecla != 0 && tecla != 9 && tecla != 16 )
			if ( tam == tammax )	
				document.form1[prox].focus() ;	}
}


function FormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form1[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form1[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form1[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}


function FormataMesAno(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form1[Campo].value;
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2  && tam < 7 )
			document.form1[Campo].value = vr.substr( 0, 2  ) + '/' + vr.substr( 2, 4 ); }
}


function FormataMesAno2(src,e) {
	mask = '##/####';
	if(window.event) {
	  _TXT = e.keyCode; } 
	else 
	  if(e.which) { 
	    _TXT = e.which; }
	  if(_TXT > 47 && _TXT < 58) { 
	    var i = src.value.length; 
	    var saida = mask.substring(0,1); 
	    var texto = mask.substring(i)
	    if (texto.substring(0,1) != saida) { 
	       src.value += texto.substring(0,1); } 
	    return true; }
	  else {
	    if (_TXT != 8) { 
	       return false; } 
	    else { 
	       return true; }
	}
}

function FormataMesAno3(NomeCampo,teclapres) {
	var tecla = teclapres.keyCode;
	var Campo = document.getElementById(NomeCampo);
    
    // Verifica se existe o campo
	if(Campo != null)
	{
	    vr = Campo.value;
	    vr = vr.replace( "/", "" );
	    tam = vr.length + 1;

	    if ( tecla != 9 && tecla != 8 )
	    {
		    if ( tam > 2  && tam < 7 )
			    document.getElementById(NomeCampo).value = vr.substr( 0, 2  ) + '/' + vr.substr( 2, 4 ); 
	    }
	}
}

function FormataMascara(src,mask,e) {
    if(window.event) {
      _TXT = e.keyCode;
	} else {
      	if(e.which) {
        	_TXT = e.which;
		}
	}
	if((_TXT > 47 && _TXT < 58) || (_TXT >= 96 && _TXT <= 105)) {
		var i = src.value.length;
		var saida = mask.substring(0,1);
		var texto = mask.substring(i)
		if (texto.substring(0,1) != saida) {
			src.value += texto.substring(0,1); }
		return true;
	} else {
		if (_TXT != 8){
			return false;
		} else {
		   return true;
		}
	}
}



function FormataCEP(src,e) {
	mask = '#####-###';
	if(window.event) {
	  _TXT = e.keyCode; } 
	else 
	  if(e.which) { 
	    _TXT = e.which; }
	  if(_TXT > 47 && _TXT < 58) { 
	    var i = src.value.length; 
	    var saida = mask.substring(0,1); 
	    var texto = mask.substring(i)
	    if (texto.substring(0,1) != saida) { 
	       src.value += texto.substring(0,1); } 
	    return true; }
	  else {
	    if (_TXT != 8) { 
	       return false; } 
	    else { 
	       return true; }
	}
}



function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}

function FormataCPF(Campo, teclapres){
	
	var tecla = teclapres.keyCode;	
	var vr = new String(Campo.value);	

	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8){		
		if (tam > 3 && tam < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		}
}


function MFValidate(formField, aBool, prompt)
{
    if (aBool == false)
    {
        formField.focus();
        formField.select();
        alert(prompt);
        formField.focus();
    }
    return aBool;
}


function Vazio(pStrText){
	var len = pStrText.length;
	var pos;
	var vStrnewtext = "";

	for (pos=0; pos<len; pos++){
		if (pStrText.substring(pos, (pos+1)) != " "){
			vStrnewtext = vStrnewtext + pStrText.substring(pos, (pos+1));
		}
	}

	if (vStrnewtext.length > 0)
		return false;
	else
		return true;
}


function isCPFCNPJ(campo,pType){
   if( Vazio( campo ) ){return false;}

   var campo_filtrado = "", valor_1 = " ", valor_2 = " ", ch = "";
   var valido = false;
        
   for (i = 0; i < campo.length; i++){
      ch = campo.substring(i, i + 1);
      if (ch >= "0" && ch <= "9"){
         campo_filtrado = campo_filtrado.toString() + ch.toString()
         valor_1 = valor_2;
         valor_2 = ch;
      }
      if ((valor_1 != " ") && (!valido)) valido = !(valor_1 == valor_2);
   }
   if (!valido) campo_filtrado = "12345678912";

   if (campo_filtrado.length < 11){
      for (i = 1; i <= (11 - campo_filtrado.length); i++){campo_filtrado = "0" + campo_filtrado;}
   }

	if(pType <= 1){
		if ( ( campo_filtrado.substring(9,11) == checkCPF( campo_filtrado.substring(0,9) ) ) && 
                     ( campo_filtrado.substring(11,12)=="") ){return true;}
	}

	if((pType == 2) || (pType == 0)){
		if (campo_filtrado.length >= 14){
			if ( campo_filtrado.substring(12,14) == checkCNPJ( campo_filtrado.substring(0,12) ) ){ return true;}
		}
	}
	
	return false;
}

function checkCNPJ(vCNPJ){
   var mControle = "";
   var aTabCNPJ = new Array(5,4,3,2,9,8,7,6,5,4,3,2);
   for (i = 1 ; i <= 2 ; i++){
      mSoma = 0;
      for (j = 0 ; j < vCNPJ.length ; j++)
         mSoma = mSoma + (vCNPJ.substring(j,j+1) * aTabCNPJ[j]);
      if (i == 2 ) mSoma = mSoma + ( 2 * mDigito );
      mDigito = ( mSoma * 10 ) % 11;
      if (mDigito == 10 ) mDigito = 0;
      mControle1 = mControle ;
      mControle = mDigito;
      aTabCNPJ = new Array(6,5,4,3,2,9,8,7,6,5,4,3);
   }
   return( (mControle1 * 10) + mControle );
}

function checkCPF(vCPF){
   var mControle = ""
   var mContIni = 2, mContFim = 10, mDigito = 0;
   for (j = 1 ; j <= 2 ; j++){
      mSoma = 0;
      for (i = mContIni ; i <= mContFim ; i++)
         mSoma = mSoma + (vCPF.substring((i-j-1),(i-j)) * (mContFim + 1 + j - i));
      if (j == 2 ) mSoma = mSoma + ( 2 * mDigito );
      mDigito = ( mSoma * 10 ) % 11;
      if (mDigito == 10) mDigito = 0;
      mControle1 = mControle;
      mControle = mDigito;
      mContIni = 3;
      mContFim = 11;
   }
   return( (mControle1 * 10) + mControle );
}



function confirmaexclusao()
{ if (confirm('O registro será excluído.\nConfirma?'))
     {LPost(window,document.form1);
     }
}


function confirmaalteracao()
{ if (confirm('O registro será alterado.\nConfirma?'))
     {LPost(window,document.form1);
     }
}

function confirmainclusao()
{ if (confirm('O registro será incluído.\nConfirma?'))
     {LPost(window,document.form1);
     }
}


function confirmaprocessamento()
{ if (confirm('Confirma o processamento solicitado?'))
     {LPost(window,document.form1);
     }
}

//###########################################################################
// Função ...............	Funções de confirmação padrão                   #
//																			#
// Autor ................	Juliano   										#
// Criação ..............	23/06/2010										#
// Alteração ............	23/06/2010										#
//																			#
// Descrição ...........	Funções para chamada de janelas de confirmação, #
//							retornando true ou false;                       #
// Obs .................	Funções criadas em substituição a funções ja    #
//							existentes, evitando o uso da função LPOST.     #
//###########################################################################

function confirmarExclusao()
{ if (confirm('O registro será excluído.\nConfirma?'))
     {
       return true;
     }
     else
     {
       return false;
     }
}


function confirmarAlteracao()
{ if (confirm('O registro será alterado.\nConfirma?'))
     {
       return true;
     }
     else
     {
       return false;
     }
}

function confirmarInclusao()
{ if (confirm('O registro será incluído.\nConfirma?'))
     {
       return true;
     }
     else
     {
       return false;
     }
}


function confirmarProcessamento()
{ if (confirm('Confirma o processamento solicitado?'))
     {
       return true;
     }
     else
     {
       return false;
     }
}

//###########################################################################
// Função ...............	abrePopup										#
// Parametros ...........	strPagina	: Caminho da pagina a ser aberta	#
//								strJanela	: Nome da Janela				#
//								strOpcao	: Opções relativas a janela		#
//																			#
// Autor ................	Centeno   										#
// Criação ..............	10/05/2006										#
// Alteração ............	10/05/2006										#
//																			#
// Descrição ...........	Função que abre uma janela pop-up e já coloca o	#
//							foco na mesma									#
//###########################################################################
function abrePopup(strPagina, strJanela, strOpcao){
	//objJanela = window.open(strPagina, strJanela, strOpcao);
	//objJanela.focus();
	var strTemp = "";
	var strLeft = "";
	var strTop = "";
	if(strOpcao.indexOf("width=") >= 0 && strOpcao.indexOf("left=") == -1){
		strTemp = strOpcao.substr(strOpcao.indexOf("width=")+6);
		intCont = (strTemp.indexOf("px")==-1)?strTemp.indexOf(","):strTemp.indexOf("px");
		strLeft = ", left="+ ((screen.width/2) - (strTemp.substr(0, intCont)/2))
	}
	if(strOpcao.indexOf("height=") >= 0 && strOpcao.indexOf("top=") == -1){
		strTemp = strOpcao.substr(strOpcao.indexOf("height=")+7);
		intCont = (strTemp.indexOf("px")==-1)?strTemp.indexOf(","):strTemp.indexOf("px");
		strTop = ", top="+ ((screen.height/2) - (strTemp.substr(0, intCont)/2));
	}
	eval("obj_"+ strJanela +" = window.open('"+ strPagina +"','"+ strJanela +"','"+ strOpcao + strLeft + strTop+"');");
	var objJanela = eval("obj_"+ strJanela);
	objJanela.focus();
}


//###########################################################################
// Função ...............	abreModal										#
// Parametros ...........	strPagina	: Caminho da pagina a ser aberta	#
//							strOpcao	: Opções relativas a janela			#
//																			#
// Autor ................	Centeno   										#
// Criação ..............	10/05/2006										#
// Alteração ............	31/10/2007										#
//																			#
// Descrição ............	Função que abre uma janela pop-up, coloca o		#
//							foco na mesma e trunca a janela principal		#
//																			#
// Valores para a variavel strOpcao											#
//		help: 			no | yes											#
//		status: 			no | yes										#
//		scroll:			no | yes											#
//		dialogWidth:	numero de pixels (ex: 180px)						#
//		dialogHeight:	numero de pixels (ex: 180px)						#
//																			#
//###########################################################################
function abreModal(){
	//objJanela = showModalDialog(strPagina, strJanela, strOpcao);
	//eval("obj_"+ strJanela +" = showModalDialog('"+ strPagina +"','"+ strJanela +"','"+ strOpcao +"');");
	
	strPagina = arguments[0];
	strOpcao = (arguments.length==2)?arguments[1]:arguments[2];;
	
	if(!bolMozilla) {
		strOpcao=strOpcao.replace(/=/g,':');
		strOpcao=strOpcao.replace(/,/g,';');
		strOpcao=strOpcao.replace("dialogWidth", "width");
		strOpcao=strOpcao.replace("dialogHeight", "height");
		strOpcao=strOpcao.replace("width", "dialogWidth");
		strOpcao=strOpcao.replace("height", "dialogHeight");
		//alert(strOpcao);
		showModalDialog(strPagina, self, strOpcao +";Center:yes;");
	} else
		window.open(strPagina, strJanela, strOpcao+",resizable=no,modal=yes");
}
if(typeof(window.dialogArguments)=="object"){
	opener = window.dialogArguments;
}


//###########################################################################
// Função ...............	formataMoeda									#
// Parametros ...........	intValorTemp	: Valor que sera formatado		#
//																			#
// Autor ................	Centeno   										#
// Criação ..............	21/06/2006										#
// Alteração ............	21/06/2006										#
//																			#
// Descrição ............	Função formata um valor em formato de moeda		#
//###########################################################################
function formataMoeda(intValorTemp){
	intValor = intValorTemp +'';
	
	strValor = "";
	for (i=0; i < intValor.length; i++) {
		strTemp = ("0123456789").indexOf(intValor.substring(i, i+1));
		if (strTemp>=0) {
			strValor += strTemp;
		}
	}
	intValor = strValor;
	
	intLen = intValor.length;

	if ( intLen <= 2 ){ 
		strValor = intValor;
	}
	if (intLen > 2 && intLen <= 5){
		strValor = intValor.substr(0, intLen-2) +","+ intValor.substr(intLen-2, intLen);
	}
	if (intLen >= 6 && intLen <= 8){
		strValor = intValor.substr(0, intLen-5) +"."+ intValor.substr(intLen-5, 3) +","+ intValor.substr(intLen-2, intLen);
	}
	if (intLen >= 9 && intLen <= 11){
		strValor = intValor.substr(0, intLen-8) +"."+ intValor.substr(intLen-8, 3) +"."+ intValor.substr(intLen-5, 3) +","+ intValor.substr(intLen-2, intLen);
	}
	if (intLen >= 12 && intLen <= 14){
		strValor = intValor.substr(0, intLen-11) +"."+ intValor.substr(intLen-11, 3) +"."+ intValor.substr(intLen-8, 3) +"."+ intValor.substr(intLen-5, 3) +","+ intValor.substr(intLen-2, intLen);
	}
	if (intValorTemp < 0) {
		strValor = '-' + strValor;
	}
	return strValor;
}

//###########################################################################
// Função ...............	retornaNum										#
// Parametros ...........	objEvent : Evento q dispara a função (opcional)	#
//																			#
// Autor ................	Centeno   										#
// Criação ..............	27/06/2006										#
// Alteração ............	10/07/2006										#
//																			#
// Descrição ............	Função retorna somente numeros					#
//###########################################################################
function retornaNum(objEvent){
	objEvent = (!objEvent)?event:objEvent;
	var objTecla = (bolMozilla)?objEvent.keycode:objEvent.keyCode;
	return ((objTecla!=9 && objTecla!=8 && (objTecla>=48 && objTecla<=57)) || objTecla==13 );
}


//###########################################################################
// Função ...............	AlterarTeclaEnter								#
// Parametros ...........	TeclaPres	: Tecla pressionada					#
//																			#
// Autor ................	Juliano/Raoni									#
// Criação ..............	28/06/2006										#
// Alteração ............	10/07/2006										#
//																			#
// Descrição ............	Função para alterar valor do enter para tab		#

//###########################################################################
function AlteraTeclaEnter(teclapres) {
	if (teclapres.keyCode==13){
		teclapres.keyCode=9; 
		return teclapres.keyCode;
	}
}



//###########################################################################
// Função ...............	replaceCaracteres								#
// Parametros ...........	strPalavra	: String a ser pesquisada			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	14/08/2006										#
// Alteração ............	14/08/2006										#
//																			#
// Descrição ............	Substitui os caracteres inválidos de uma string	#
//###########################################################################
function replaceCaracteres(strPalavra){
	strInvalidos = "áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ'´`";
	strValidos = "aaaaeeiooouucAAAAEEIOOOUUC";
	strRetorno = "";
	for (var i = 0; i < strPalavra.length; i++) {
		intPosicao = strInvalidos.indexOf(strPalavra.charAt(i));
		if (intPosicao != -1) {
			strRetorno += strValidos.charAt(intPosicao);
		} else {
			strRetorno += strPalavra.charAt(i);
		}
	}
	return strRetorno;
}


//###########################################################################
// Função ...............	criaObjHttp										#
// Parametros ...........	strUrl	: Mensagem que deve aparecer 			#
//							strUrl	: Mensagem que deve aparecer 			#
//							strUrl	: Mensagem que deve aparecer 			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	11/08/2006										#
// Alteração ............	11/08/2006										#
//																			#
// Descrição ............	Cria objeto de requisição XmlHttp				#
//###########################################################################
function criaObjHttp(strUrl, strMetodo, strModo){
	try{
    	ObjHttp = new XMLHttpRequest();
	}catch(ee){
    	try{
		       ObjHttp = new ActiveXObject("Msxml2.XMLHTTP");
    	}catch(e){
			try{
				ObjHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				ObjHttp = false;
				alert("Erro:\n"+E);
			}
		}
	}

	strMetodo = (typeof(strMetodo)!="undefined")?strMetodo:"POST";
	strModo = (typeof(strModo)!="undefined")?strModo:true;

	if(ObjHttp){
		try{
			ObjHttp.open(strMetodo, strUrl, strModo);
		}catch(ee){
			alert(ee.message +"\n"+ strMetodo +" - "+ strUrl +" - "+ strModo);
		}
//		if (ObjHttp.overrideMimeType) {
//			ObjHttp.overrideMimeType('text/xml');
//		}
		//ObjHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded, charset: iso-8859-1");
		ObjHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ObjHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		ObjHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		ObjHttp.setRequestHeader("Pragma", "no-cache");
		//ObjHttp.setRequestHeader("Content-Type","text/xml, charset: iso-8859-1"); 
        ObjHttp.setRequestHeader("encoding","ISO-8859-1"); 
	}
	return ObjHttp;
}


//###########################################################################
// Função ...............	validaData										#
// Parametros ...........	strData	: Data no formato dd/mm/yyyy 			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	14/08/2006										#
// Alteração ............	14/08/2006										#
//																			#
// Descrição ............	Verifica se é uma data válida					#
//###########################################################################
function validaData(strData) {
	intDia = strData.split("/")[0];
	intMes = strData.split("/")[1];
	intAno = strData.split("/")[2];
	if(parseInt(intDia, 10)>0 && parseInt(intMes, 10)>0 && parseInt(intAno, 10)>999){
		if ((intDia < 01)||(intDia < 01 || intDia > 30) && (  intMes == 04 || intMes == 06 || intMes == 09 || intMes == 11 ) || intDia > 31) {
			return false;
		} else if (intMes < 01 || intMes > 12 ) {
			return false;
		} else if (intMes == 2 && ( intDia < 01 || intDia > 29 || ( intDia > 28 && (parseInt(intAno / 4) != intAno / 4)))) {
			return false;
		} else{
			return true;
		}
	} else {
		return false;
	}
}


//###########################################################################
// Função ...............	corrigePng										#
//																			#
// Autor ................	Centeno											#
// Criação ..............	16/08/2006										#
// Alteração ............	16/08/2006										#
//																			#
// Descrição ............	Corrige o problema de transp do PNG no IE		#
//###########################################################################
function corrigePng(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (document.body.filters)){
		for(var i=0; i<document.images.length; i++){
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}    
}



//###############################################################################################
// Função ...............	MenuAlternaAplic			    									#
// Parametros ...........	strTextoMenu	: Textos que deve aparecer no menu. 				#
//					  	devem ser separados por vírgula					#
//				strLinkMenu			: Enredeços de hyperlink que o menu deve adicionar	#
//				strLinkMenuTp (opcional)	: vazio= abre destino na mesma tela, "P" = abre Popup	#
//				strLinkMenuTpPopup (opcional)	: qdo Popup passa os parametros da tela	Popup (largura, altura, etc.) #
//																								#
// Autor ................	Juliano																#
// Criação ..............	22/09/2006															#
// Alteração ............	09/02/2010															#
//																								#
//###############################################################################################
function criaMenu(strTextoMenu,strLinkMenu,strLinkMenuTp,strLinkMenuTpPopup,strLayer){

	var TempTextoMenu = new Array();
	TempTextoMenu = strTextoMenu.split(',');

	var TempLinkMenu = new Array();
	TempLinkMenu = strLinkMenu.split(',');

	strLinkMenuTp = (!strLinkMenuTp)?"":strLinkMenuTp;
	var TempLinkMenuTp = new Array();
	TempLinkMenuTp = strLinkMenuTp.split(',');

	strLinkMenuTpPopup = (!strLinkMenuTpPopup)?"":strLinkMenuTpPopup;
	var TempLinkMenuTpPopup = new Array();
	TempLinkMenuTpPopup = strLinkMenuTpPopup.split(',');

	strLayer = (!strLayer)?"Layer1":strLayer;
	subcriaMenu = [];
	textmenu = [];
	textmenu[0] = TempTextoMenu;
	textmenu[1] = TempLinkMenu;
	textmenu[2] = TempLinkMenuTp;
	textmenu[3] = TempLinkMenuTpPopup;
	if(document.getElementById){
		criaMenu = document.getElementById(strLayer);
		lonk = document.getElementById("criaMenu");
		//criaMenu.setAttribute("position","absolute")
		function over(){ this.style.backgroundColor = '#B2B4BF'; }
		function out(){ this.style.backgroundColor = '#F2F3ED'; }
		function show(){ this.style.visibility='visible'; }
		function hide(){ this.style.visibility='hidden'; }
		for (i=0; i<textmenu[0].length; i++){
			if (textmenu[2][i] == "P")
			{
				if (textmenu[3][i] == "" || !textmenu[3][i]) 
				{
					textmenu[3][i] = "toolbar=no,left=0,top=0,width=760,height=560,scrollbars=yes";
				}
				
				tempTextoPopup = "<a class=A4 onclick='abrePopup(";
				tempTextoPopup += '"' + textmenu[1][i] + '"';
				tempTextoPopup += ',';
				tempTextoPopup += '"PopupCriaMenu"';
				tempTextoPopup += ',';
				tempTextoPopup += '"' + textmenu[3][i] + '"';
				tempTextoPopup += ");'";
				tempTextoPopup += " href='#'>" + textmenu[0][i] + "</a>";
				textmenu[0][i] = tempTextoPopup;
			}
			else
			{
				textmenu[0][i] = "<a class=A4 href='"+textmenu[1][i]+"' >" + textmenu[0][i] + "</a>";
			}

			subcriaMenu[i] = document.createElement("DIV");
			subcriaMenu[i].setAttribute("className", "specialcriaMenu");
			subcriaMenu[i].innerHTML = textmenu[0][i];
			subcriaMenu[i].style.padding = "5px";
			subcriaMenu[i].onmouseover = over;
			subcriaMenu[i].onmouseout = out;
			criaMenu.appendChild(subcriaMenu[i]);
		}
		criaMenu.style.top = (parseInt(lonk.style.top)+parseInt(lonk.style.height));
		criaMenu.onmouseover = show;
		criaMenu.onmouseout = hide;
	}

}


//###########################################################################
// Função ...............	pulaCampo										#
// Parametros ...........	intMaxLen	: Tamanho de caracteres do campo	#
//							intSalto	: Numero de campo a saltar			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	22/08/2006										#
// Alteração ............	22/08/2006										#
//																			#
// Descrição ............	Salta o foco para o campo indicado				#
// Observação 1 .........	Quando o campo é do tipo select, o parametro	#
//							intMaxLen passar a valer como intSalto			#
// Observação 2 .........	Nos campos text usar este função no onkeyup, e	#
//							nos campos select usar no onchange				#
//###########################################################################
function pulaCampo(intMaxLen, intSalto){
	objCampo 	= event.srcElement;
	intTecla	= (bolMozilla)?event.keycode:event.keyCode;
	intSalto	= (!intSalto)?1:intSalto;
	intMaxLen	= (!intMaxLen)?((objCampo.maxLength>2000000000)?1:objCampo.maxLength):intMaxLen;
	objSalto	= document.getElementById(intSalto);
	intLen		= objCampo.value.length;
	
	// ----------------------------------------------------------------------
	// Criar um array com as teclas que não pulam campos e extensão do objeto 
	// Raoni Madeira - Data: 16/04/2010
	// ----------------------------------------------------------------------
		
	var arrTeclas = [
	                     0,
	                     8,  //Backspace
	                     9,  //Tab
	                     13, //Enter
	                     16, //Shif TAB
	                     17, 
	                     35, //Home
	                     36, //End
	                     37, //Esquerda
	                     38, //Cima
	                     39, //Direita
	                     40, //Baixo
	                     46  //Delete
	                 ];
	
	// Criar um extension method do objeto Array
	Array.prototype.has = function(search) {
	    for (var i=0; i < this.length; i++) {
	        if (this[i] == search) {
		        return true;
	        }
	    }
	}
	
	// ----------------------------------------------------------------------
	// Verifica se existe máscara Mask Edit do ajax
	// Renan Rosa da Silva - Data: 08/03/2010
	// ----------------------------------------------------------------------
	var value = "";
	
	try{
	    value = objCampo.options[objCampo.selectedIndex].value;
	}
	catch(error){
        value = objCampo.value;    
	}
	
	// Verifica se contém a máscara no value do objeto. Se sim não pula campo.
	if (value.indexOf('_') > -1){
	    return;
	}	
	
	// ----------------------------------------------------------------------
	
	if(objCampo.type.substr(0,6)=="select"){
		intSalto = (!intMaxLen)?1:intMaxLen;
		objSalto	= document.getElementById(intSalto);
		if(!objSalto){
			for(intCont=0; intCont < objCampo.form.elements.length; intCont++){
				if(objCampo.form.elements[intCont].name==objCampo.name){				    
                    for(intCont; intCont < objCampo.form.elements.length; intCont++){
	                    if (objCampo.form.elements[intCont+intSalto].disabled 	                       
	                        || objCampo.form.elements[intCont + intSalto].readOnly == true
	                            || objCampo.form.elements[intCont+intSalto].type.substr(0,7)=="hidden")
	                                
	                    {
	                        continue;
	                    }
	                    else
	                    {
					        objCampo.form.elements[intCont+intSalto].focus();
    				        if(objCampo.form.elements[intCont+intSalto].type.substr(0,5)=="text"){
	    				        objCampo.form.elements[intCont+intSalto].select();
		    		        }
    						return;
		    		    }
				    }
					alert("Erro: Impossível colocar o cursor no campo solicitado, pois o mesmo está desabilitado.");
                    return;
				}
			}
		} else {
            if (objSalto.disabled || objSalto.type.substr(0,7)=="hidden" || objSalto.readOnly == true)
            {
			    alert("Erro: Impossível colocar o cursor no campo solicitado, pois o mesmo está desabilitado.");
            }
            else
            {
		        objSalto.focus();	
		    }
		}
		return;
	}	
	
	if(!arrTeclas.has(intTecla)){
	    if(intLen >= intMaxLen){		
		    if(!objSalto){			    
			    for(intCont=0; intCont < objCampo.form.elements.length; intCont++){
				    if(objCampo.form.elements[intCont].name==objCampo.name){					    
                        for(intCont; intCont < objCampo.form.elements.length; intCont++){
	                        if (objCampo.form.elements[intCont + intSalto].disabled 
	                            || objCampo.form.elements[intCont + intSalto].readOnly == true		                        
	                                || objCampo.form.elements[intCont + intSalto].type.substr(0,7)=="hidden")
	                        {
	                            continue;
	                        }
	                        else
	                        {
					            objCampo.form.elements[intCont+intSalto].focus();
    				            if(objCampo.form.elements[intCont+intSalto].type.substr(0,5)=="text"){
	    				            objCampo.form.elements[intCont+intSalto].select();
		    		            }
    						    return;
		    		        }
				        }
					    alert("Erro: Impossível colocar o cursor no campo solicitado, pois o mesmo está desabilitado.");
                        return;
				    }
			    }
		    } else {
                if (objSalto.disabled || objSalto.type.substr(0,7)=="hidden" || objSalto.readOnly == true)
                {
				    alert("Erro: Impossível colocar o cursor no campo solicitado, pois o mesmo está desabilitado.");
                }
                else
                {
			        objSalto.focus();	
			    }
		    }
	    }	
	}	
}

//###########################################################################
// Função ...............	subtraiData										#
// Parametros ...........	strData	: Data no formato DD/MM/YYYY			#
//							intDias	: Numero de dias						#
//							bolSubtracao : Boolean q diz se subtrai ou soma	#
//							os dias informados no paramentro intDia			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	18/10/2006										#
// Alteração ............	18/10/2006										#
//																			#
// Descrição ............	Subtrai ou soma x dias de uma determinada data	#
//###########################################################################
function subtraiData(strData, intDias, bolSubtracao){
	bolSubtracao = (typeof(bolSubtracao)=="undefined")?true:bolSubtracao;
	arrData = strData.split("/");
	objData = new Date(arrData[2], arrData[1]-1, arrData[0]);
	if (bolSubtracao==true){
		objDiferenca = new Date(objData.getTime() - (intDias * 1000 * 60 * 60 * 24));
	} else {
		objDiferenca = new Date(objData.getTime() + (intDias * 1000 * 60 * 60 * 24));
	}
	strData = (objDiferenca.getDate()<10)?"0"+objDiferenca.getDate():objDiferenca.getDate();
	strData += "/";
	strData += ((objDiferenca.getMonth()+1)<10)?"0"+(objDiferenca.getMonth()+1):(objDiferenca.getMonth()+1);
	strData += "/";
	strData += (objDiferenca.getYear()<10)?"0"+objDiferenca.getYear():objDiferenca.getYear();
	//alert(objDiferenca.getDate() +'/'+ (objDiferenca.getMonth()+1) +'/'+ objDiferenca.getYear());
	return strData;
}

//###########################################################################
// Função ...............	AnoMesDia										#
// Parametros ...........	strData	: Data no formato DD/MM/YYYY			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	21/11/2006										#
// Alteração ............	21/11/2006										#
//																			#
// Descrição ............	Transforma a data em YYYY-MM-DD					#
//###########################################################################
function AnoMesDia(strData){
	arrData = strData.split("/");
	return arrData[2] +"-"+ arrData[1] +"-"+ arrData[0];
}


//###########################################################################
// Função ...............	DiaMesAno										#
// Parametros ...........	strData	: Data no formato YYYY-MM-DD			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	28/11/2007										#
// Alteração ............	28/11/2007										#
//																			#
// Descrição ............	Transforma a data em DD/MM/YYYY					#
//###########################################################################
function DiaMesAno(strData){
	arrData = strData.split("-");
	if(arrData.length == 3){
		return arrData[2] +"/"+ arrData[1] +"/"+ arrData[0];
	} else
		return strData;
}


//###########################################################################
// Função ...............	dateDif											#
// Parametros ...........	strData1 : Data no formato DD/MM/YYYY			#
//							strData2 : Data no formato DD/MM/YYYY			#
//							strTipo  : Tipo do retorno(Dia, Mes, Ano, null)	#
//																			#
// Autor ................	Centeno											#
// Criação ..............	21/11/2006										#
// Alteração ............	21/11/2006										#
//																			#
// Descrição ............	Retorna a diferença entre duas datas			#
//###########################################################################
function dateDif(strData1, strData2, strTipo){
	strTipo = (typeof(strTipo)=="undefined")?"":strTipo;
	arrData1 = strData1.split("/");
	objData1 = new Date(arrData1[2], arrData1[1], arrData1[0]);
	arrData2 = strData2.split("/");
	objData2 = new Date(arrData2[2], arrData2[1], arrData2[0]);
	intDif = objData1.getTime() - objData2.getTime();
	switch(strTipo){
		case "d":
			intDif = intDif / 1000 / 60 / 60 / 24;
			break;
		case "m":
			intDif = intDif / 1000 / 60 / 60 / 24 / 30.2;
			break;			
		case "y":
			intDif = intDif / 1000 / 60 / 60 / 24 / 365;
			break;
	}
	return intDif;
}


//###########################################################################
// Função ...............	getValorRadio									#
// Parametros ...........	objRadio : Objeto do typo RadioButton			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	02/01/2007										#
// Alteração ............	02/01/2007										#
//																			#
// Descrição ............	O valor da opção selecionada no RadioButton		#
//###########################################################################
function getValorRadio(objRadio){
	for (i=0;i<objRadio.length;i++){
       if (objRadio[i].checked)
          break;
    }
    return objRadio[i].value;
}


//###########################################################################
// Função ...............	formataData										#
// Parametros ...........													#
//																			#
// Autor ................	Centeno											#
// Criação ..............	13/04/2007										#
// Alteração ............	13/04/2007										#
//																			#
// Descrição ............	Devolve o valor formatado para o campo			#
//###########################################################################
function formataData(){
	objCampo 	= event.srcElement;
	intTecla	= (bolMozilla)?event.keycode:event.keyCode;
	strValor 	= objCampo.value.replace("/", "");
	strValor 	= strValor.replace("/", "");
	intLen		= strValor.length + 1;
	if (intTecla != 8 && intTecla != 9  &&  intTecla != 16){
		if (intLen>2 && intLen<5)
			objCampo.value = strValor.substr( 0, intLen - 2  ) + '/' + strValor.substr( intLen - 2, intLen );
		if (intLen>=5 && intLen<=10)
			objCampo.value = strValor.substr( 0, 2 ) + '/' + strValor.substr( 2, 2 ) + '/' + strValor.substr( 4, 4 );
	}	
}





//###########################################################################
// Função ...............	ajustaCarregando								#
// Parametros ...........	bolResize : Indica o redimencionamento da pag.	#
//							intIndex : Numero do z-index da div				#
//																			#
// Autor ................	Centeno											#
// Criação ..............	13/04/2007										#
// Alteração ............	13/04/2007										#
//																			#
// Descrição ............	Ajusta as propriedades da layer carregando		#
//###########################################################################
function ajustaCarregando(bolResize, intIndex){
	bolResize	= (typeof(bolResize)=="undefined")?false: bolResize;
	intIndex	= (typeof(intIndex)=="undefined")?1: intIndex;
	objDiv		= document.getElementById("divCarregando");
	objFrm		= document.getElementById("iframeCarregando");
	
	var intLargura = (document.body.clientWidth > 20)?document.body.clientWidth-20:0;
	
	if (document.getElementById("imgCarregando")){
		objImg	= document.getElementById("imgCarregando");	// Centeno | 05.03.2008
		objImg.style.height	  = getPageSize()[1]+"px"; 	// Centeno | 05.03.2008
		objImg.style.width    = intLargura +"px";			// Centeno | 05.03.2008
	}
	

	if(!bolResize){
		objDiv.style.display = "none";
	}

	objDiv.style.position	= "absolute";
	objDiv.style.left		= "0px";
	objDiv.style.top		= "0px";
	objDiv.style.right		= "0px";
	objDiv.style.zIndex		= "100";
	objDiv.style.width		= "98%";
	objDiv.style.height		= "98%";

	objDiv.style.height		= getPageSize()[1]+"px"; 	// Centeno | 05.03.2008
	objDiv.style.width      = intLargura +"px";			// Centeno | 05.03.2008

	//objImg.src			= "/GBOEX/images/carregando.png";
	//objImg.style.height	= document.body.clientHeight+"px";
	//objImg.style.height	= getPageSize()[1]+"px"; 	// Centeno | 05.03.2008
	//objImg.style.width    = intLargura +"px";			// Centeno | 05.03.2008
	//objImg.style.width    = (document.body.clientWidth-20)+"px";
	
//	alert(objImg +" - "+ objImg.style.height +" - "+ objImg.style.width);

	/*
	objFrm.scrolling		= "no";
	objFrm.frameborder		= "0";
	objFrm.style.position	= "absolute";
	objFrm.style.left		= "0px";
	objFrm.style.top		= "0px";
	objFrm.style.display	= "none";
	*/
}

//###########################################################################
// Função ...............	mostraCarregando								#
// Parametros ...........	bolMostra : Indica se tem ocultar ou mostrar	#
//							strForm : Formulario onde estão os campos		#
//																			#
// Autor ................	Centeno											#
// Criação ..............	13/04/2007										#
// Alteração ............	13/04/2007										#
//																			#
// Descrição ............	Mostra e oculta a função carregando				#
//###########################################################################
function mostraCarregando(bolMostra, strForm){
	bolMostra 	= (typeof(bolMostra)=="undefined")?true:bolMostra;
	strForm 	= (typeof(strForm)=="undefined")?"form1":strForm;
	objDiv		= document.getElementById("divCarregando");
	objForm 	= eval("document."+strForm);
	//objFrm		= document.getElementById("iframeCarregando");
	if(bolMostra){
		objDiv.style.display	= "block";
		//objFrm.style.width		= objDiv.offsetWidth;
		//objFrm.style.height		= objDiv.offsetHeight;
		//objFrm.style.top		= objDiv.style.top;
		//objFrm.style.left		= objDiv.style.left;
		//objFrm.style.zIndex		= objDiv.style.zIndex + 1;
		//objFrm.style.display	= "block";
	} else {
		objDiv.style.display 	= "none";
		//objFrm.style.display 	= "none";
	}
	for(intCont=0; intCont<objForm.elements.length; intCont++){	    
		if(objForm.elements[intCont].type.substr(0,6)=="select"){
			//objForm.elements[intCont].style.display = (bolMostra)?"none":"inline";
		}
	}
}
function Aguarde(bolMostra, strForm){
	bolMostra 	= (typeof(bolMostra)=="undefined")?true: bolMostra;
	if(bolMostra){
    	//document.getElementById("divCarregando").style.display = "inline";
	    document.getElementById("divImgCarregando").style.display = "inline";
	} else {
	    //document.getElementById("divCarregando").style.display = "inline";
	    document.getElementById("divImgCarregando").style.display = "none";
	}
    mostraCarregando(bolMostra, strForm);
}




//###########################################################################
// Função ...............	formataValor									#
// Parametros ...........													#
//																			#
// Autor ................	Centeno											#
// Criação ..............	13/04/2007										#
// Alteração ............	13/04/2007										#
//																			#
// Descrição ............	Formata um valor do tipo moeda					#
//###########################################################################
function formataValorCenteno(){
	objCampo 	= event.srcElement;
	intValor = objCampo.value +'';
	
	strValor = "";
	for (i=0; i < intValor.length; i++) {
		strTemp = ("0123456789").indexOf(intValor.substring(i, i+1));
		if (strTemp>=0) {
			strValor += strTemp;
		}
	}
	intValor = strValor;
	intLen = intValor.length;

	intTecla	= (bolMozilla)?event.keycode:event.keyCode;
	
	//if (intTecla == 8 ){
		//intLen = intLen - 1 ;
	//}
	
	if ( intTecla != 8 && intTecla != 9){	
			if ( intLen <= 2 ){ 
				strValor = intValor;
			}
			if (intLen > 2 && intLen <= 5){
				strValor = intValor.substr(0, intLen-2) +","+ intValor.substr(intLen-2, intLen);
			}
			if (intLen >= 6 && intLen <= 8){
				strValor = intValor.substr(0, intLen-5) +"."+ intValor.substr(intLen-5, 3) +","+ intValor.substr(intLen-2, intLen);
			}
			if (intLen >= 9 && intLen <= 11){
				strValor = intValor.substr(0, intLen-8) +"."+ intValor.substr(intLen-8, 3) +"."+ intValor.substr(intLen-5, 3) +","+ intValor.substr(intLen-2, intLen);
			}
			if (intLen >= 12 && intLen <= 14){
				strValor = intValor.substr(0, intLen-11) +"."+ intValor.substr(intLen-11, 3) +"."+ intValor.substr(intLen-8, 3) +"."+ intValor.substr(intLen-5, 3) +","+ intValor.substr(intLen-2, intLen);
			}
		event.srcElement.value = strValor;
	}
}





//###########################################################################
// Função ...............	formataValor									#
// Parametros ...........													#
//																			#
// Autor ................	Juliano											#
// Criação ..............	28/04/2008										#
// Alteração ............	28/04/2008										#
//																			#
// Descrição ............	Formata um valor do tipo moeda					#
//###########################################################################
function formataValor() {
		objcampo 	= event.srcElement;

		vr=objcampo.value;
		tecla	= (bolMozilla)?event.keycode:event.keyCode;

		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 ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= 2 ){ 
				objcampo.value = vr ; }
			if ( (tam > 2) && (tam <= 5) ){
				objcampo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 6) && (tam <= 8) ){
				objcampo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 9) && (tam <= 11) ){
				objcampo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 12) && (tam <= 14) ){
				objcampo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 15) && (tam <= 17) ){
				objcampo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
		}
	
}





//###########################################################################
// Função ...............	getAjax											#
// Parametros ...........	strUrl : Url a ser chamada via AJAX				#
//							objReferencia : Campo ou função para retorno	#
//							objFuncaoPos : Função a ser chamada após exec	#
//																			#
// Autor ................	Centeno											#
// Criação ..............	15/08/2007										#
// Alteração ............	15/08/2007										#
//																			#
// Descrição ............	Realiza chamada a aplicaçãoes por meio do AJAX	#
//###########################################################################
function getAjax(strUrl, objReferencia, objFuncaoPos, strModo) {
	var objFuncaoPos = (typeof(objFuncaoPos)!="undefined")?objFuncaoPos:"";
	var strModo = (typeof(strModo)!="undefined")?strModo:false;
    var objAjax = criaObjHttp(strUrl, "get", strModo);
	//alert('1 ' + typeof(objAjax));
	//Centeno();
	objAjax.onreadystatechange = function do_readyStateChange(to) {
        if (objAjax.readyState == 4){
			var txtResposta = objAjax.responseText;
			if(txtResposta.indexOf("#")>=0){ // Procura por erros, se houver "#" é pq tem erro
				bolErroAjax = true;
				if(txtResposta.length==3){ // Verifica se NÂO existe mensagem de erro
					alert("Erro ao executar operação.")
				} else { // Se existe, mostra mensagem de erro
					alert(txtResposta.substr(1));
				}
			} else { // Não encontrou erro
				bolErroAjax = false;
				if (typeof(objReferencia) == "function"){ // Verifica se é função e chama a mesma
					objReferencia(txtResposta);
				} else { // Cai aqui caso não seja função
					switch (document.getElementById(objReferencia).type){// Verifica o tipo de campo
						case "text":
							document.getElementById(objReferencia).value = txtResposta;
							break;
						case "select-one" : // Select (Combo)
							var arrResposta = txtResposta.split("|");
							for (i=0; i<arrResposta.length-1; i++){
								var arrColunas = arrResposta[i].split(";");
								var objOption = document.createElement("option");
								objOption.value = arrColunas[0];
								objOption.text = arrColunas[1];
								document.getElementById(objReferencia).options.add(objOption);
							}
							break;
						default:
							document.getElementById(objReferencia).innerHTML = txtResposta;
							break;
					}
				}
			}
			if(objFuncaoPos!=""){ // Verifica se precisa chamar função apos execução
				objFuncaoPos();
			}
        }
    }
    objAjax.send();
}

//###########################################################################
// Função ...............	formataFator									#
// Parametros ...........	intInteiros : Numero de casas inteiras			#
//																			#
// Autor ................	Centeno											#
// Criação ..............	03/10/2007										#
// Alteração ............	03/10/2007										#
//																			#
// Descrição ............	Formata um fator								#
//###########################################################################
function formataFator(intInteiros, bolInverter){
	objCampo 	= event.srcElement;
	intValor 	= objCampo.value +'';
	intInteiros	= (typeof(intInteiros)!="undefined")?intInteiros:1;
	bolInverter	= (typeof(bolInverter)!="undefined")?bolInverter:false;
	
	strValor = "";
	for (i=0; i < intValor.length; i++) {
		strTemp = ("0123456789").indexOf(intValor.substring(i, i+1));
		if (strTemp>=0) {
			strValor += strTemp;
		}
	}
	intValor = strValor;
	intLen = intValor.length;

	intTecla	= (bolMozilla)?event.keycode:event.keyCode;
	
	if ( intTecla != 8 && intTecla != 9){
		if(!bolInverter){
			if (intLen > intInteiros){
				strValor = intValor.substr(0, intInteiros) +","+ intValor.substr(intInteiros, intLen);
			}
		} else{
			// Tem que terminar
		}
		event.srcElement.value = strValor;
	}
}










String.prototype.trim = function(){
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
	}

//////
function criaFrame(){
	var objFrameTeste = document.createElement("iframe");
	objFrameTeste.setAttribute("name", "objFrameTeste");
	objFrameTeste.setAttribute("id", "objFrameTeste");
	objFrameTeste.style.display = "none";
	document.body.appendChild(objFrameTeste);
}
//window.onload = criaFrame;

function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	//    console.log(self.innerWidth);
	//    console.log(document.documentElement.clientWidth);
	
	if (self.innerHeight) {    // all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	
	//    console.log("xScroll " + xScroll)
	//    console.log("windowWidth " + windowWidth)
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	//    console.log("pageWidth " + pageWidth)
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}


//###########################################################################
// Função ...............	chamaGBHelp				    #
// #
//					   de Help			    #
// Autor ................	Juliano					    #
// Criação ..............	14/08/2008				    #
// Alteração ............	14/08/2008				    #
//									    #
// Descrição ............	Chama o Sistema de Help GBHelp Num tópico   #
//                              específico ou no conteúdo (TOC)             #
// Obs. ................	O tópico desejado pode ser informado por    #
//                              intermedio do parametro de entrada ou por   #
//                              pelo value de um campo hidden com id=hMapID #
//###########################################################################
function chamaGBHelp(intMapID){
	var strChamaHelp = "/GBdotNet/GGINT/GGINT050.aspx";
	var campoMapID;
	var varFrameHeader;

	if (parseInt(intMapID) == 0 || typeof(intMapID) == "undefined" )
		intMapID = verificaMapID();

	if (parseInt(intMapID) != 0 && typeof(intMapID) != "undefined" )
	{
		//mostraCarregando();
		strChamaHelp = strChamaHelp + "?mapid=" + intMapID;

		varDataDiv = document.getElementById("dataDivGBHelp");
		if(varDataDiv == null || varDataDiv == "null")
		{
			var sHTML="";
			sHTML+="<div id=dataDivGBHelp style=\"visibility:hidden\">";
			sHTML+="<iframe name=iframeGBHelp id=iframeGBHelp style=\"visibility:hidden;width:0;height:0\"></iframe>";
			sHTML+="</div>";
			document.body.insertAdjacentHTML("beforeEnd",sHTML);
		}
	
		var oDivConGBHelp=document.getElementById("dataDivGBHelp");
		if(oDivConGBHelp)
		{
			document.getElementById("iframeGBHelp").src = strChamaHelp;
		}
	}
	else
		alert("Novo sistema de Ajuda em construção para esta aplicação.\nUtilize o botão Ajuda disponível na parte inferior da tela.");
}

//###########################################################################
// Função ...............	verificaMapID				    #
// Autor ................	Juliano					    #
// Criação ..............	14/08/2008				    #
// Alteração ............	14/08/2008				    #
//									    #
// Descrição ............	Verifica se campo hidden hMapID existe.         #
// Obs. ................	Retorna True ou False                           #
//###########################################################################
function verificaMapID(){
	var campoMapID;
	var varFrameHeader;
	var intMapID;
	intMapID = 0;
	campoMapID = document.getElementById("hMapID");
	if (campoMapID == null || campoMapID == "null")
	{
		varFrameMainIframe = parent.frames['main'].frames['iframe'];
		if (varFrameMainIframe != undefined && varFrameMainIframe != "undefined")
		{
			campoMapID = varFrameMainIframe.document.getElementById("hMapID");
			if (campoMapID != null && campoMapID != "null")
				intMapID = campoMapID.value;
		}
	}
	else
		intMapID = campoMapID.value;
	return intMapID;
}


//######################################################################################################################
//Função .............. 	gbhelp_mostra_conteudo								       #
//Parametros........... 	oculta_mostra  : ID da DIV que deverá ser ocultada e mostrada. 			       #
//														       #
//														       #
//Autor................		Rodrigo Vicentini								       #
//Criação..............		12/02/2009									       #
//Alteração............		12/02/2009									       #										#
//														       #
//Descrição............		Função a ser chamada quando for necessário ocultar e depois mostrar conteúdo do GBHelp.#
//######################################################################################################################

function gbhelp_mostra_conteudo(id)
    {
       var mostra = document.getElementById(id);
       if (mostra.style.display == 'block')
           mostra.style.display = 'none';
       else
           mostra.style.display = 'block';
    }


//###########################################################################
// Função ...............	criaIframeFinalPagina       				    #
// Autor ................	Juliano					                        #
// Criação ..............	07/05/2010                                      #
// Alteração ............	                                                #
//									                                        #
// Descrição ............	Cria um iFrame no final da página corrente      #
//###########################################################################
function criaIframeFinalPagina(strIframeID, strIframeConteudoInicial, strParentID, strLargura, strAltura){
	var varFrameHeader;
    strDivName = "dataDiv_" + strIframeID;
    varDataDiv = document.getElementById(strDivName);
    strLargura	= (typeof(strLargura)!="undefined")?strLargura:'100%';
    strLargura	= (typeof(strLargura)!="undefined")?strLargura:'200px';
        
	if(varDataDiv == null || varDataDiv == "null")
	{
		var strHTML="";
		strHTML+="<CENTER><div id='" + strDivName + "' align='center'>";
		strHTML+="<iframe name='" + strIframeID 
		strHTML+="' id='" + strIframeID 
		strHTML+="' style='width:" + strLargura + ";height:" + strAltura
		strHTML+="' frameBorder=0></iframe></div></CENTER>";
		objPai = document.getElementById(strParentID);
		if (objPai)
		{
    		objPai.insertAdjacentHTML("beforeEnd",strHTML);
		}
		else
		{
		    document.body.insertAdjacentHTML("beforeEnd",strHTML);
		}
	}

    if (typeof(strIframeConteudoInicial)!="undefined")
    {
	    var oDataDiv=document.getElementById(strDivName);
	    if(oDataDiv)
	    {
		    document.getElementById(strIframeID).src = strIframeConteudoInicial;
	    }
	}
}



//###########################################################################
// Função ...............	converteMoedaToUS				                #
// Autor ................	Raoni					                        #
// Criação ..............	29/04/2009				                        #
// Alteração ............	29/04/2009                  				    #
// Descrição ............	Converte um valor para o padrão americano       #
// Parametros........... 	Valor a ser convertido                          # 
// Obs. ................	Retorna o valor no padrão americando            #
//###########################################################################

function converteMoedaToUS(valor){                
            
    var y = valor.split(".").length;    
    var i = 0;        
        
    while(i < (y - 1)){
       var valor = valor.replace(".", "");
       i++;
    }        
       
    valor = valor.replace(",", ".");
    return valor;
}

//###########################################################################
// Função ...............	GbCalendarioDataHoje			                #
// Autor ................	Juliano					                        #
// Criação ..............	16/03/2010				                        #
// Alteração ............	                              				    #
// Descrição ............	Mostra a data corrente no GBCalendario          #
// Parametros........... 	objetos internos do GbCalendario                # 
//###########################################################################

function GbCalendarioDataHoje(sender,args)
{
    if(sender._textbox.get_element().value == "")
    {
        var todayDate = new Date();
        sender._selectedDate = todayDate;
    }
}

//###########################################################################
// Função ...............	GBCalendarioModificaParaMesAno	                #
// Autor ................	Juliano					                        #
// Obs.: ................   Retirado de http://forums.asp.net/t/1349086.aspx#
// Criação ..............	22/03/2010				                        #
// Alteração ............	                              				    #
// Descrição ............	Altera calendário do AjaxCalendarExtender para  #
//                          mostrar apenas Mês/Ano                          #
// Parametros........... 	BehaviorID do Calendário que se deseja alterar  # 
//###########################################################################

function GBCalendarioModificaParaMesAno(cal) {
    //we need to modify the original delegate of the month cell.
    cal._cell$delegates = {
    mouseover: Function.createDelegate(cal, cal._cell_onmouseover),
    mouseout: Function.createDelegate(cal, cal._cell_onmouseout),

    click: Function.createDelegate(cal, function(e) {
        /// <summary> 
        /// Handles the click event of a cell
        /// </summary>
        /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>

        e.stopPropagation();
        e.preventDefault();

        if (!cal._enabled) return;

        var target = e.target;
        var visibleDate = cal._getEffectiveVisibleDate();
        Sys.UI.DomElement.removeCssClass(target.parentNode, "ajax__calendar_hover");
        switch (target.mode) {
            case "prev":
            case "next":
                cal._switchMonth(target.date);
                break;
            case "title":
                switch (cal._mode) {
                    case "days": cal._switchMode("months"); break;
                    case "months": cal._switchMode("years"); break;
                }
                break;
            case "month":
                //if the mode is month, then stop switching to day mode.
                if (target.month == visibleDate.getMonth()) {
                    //this._switchMode("days");
                } else {
                    cal._visibleDate = target.date;
                    //this._switchMode("days");
                }
                cal.set_selectedDate(target.date);
                cal._switchMonth(target.date);
                cal._blur.post(true);
                cal.raiseDateSelectionChanged();
                break;
            case "year":
                if (target.date.getFullYear() == visibleDate.getFullYear()) {
                    cal._switchMode("months");
                } else {
                    cal._visibleDate = target.date;
                    cal._switchMode("months");
                }
                break;

            case "today":
                cal.set_selectedDate(target.date);
                cal._switchMonth(target.date);
                cal._blur.post(true);
                cal.raiseDateSelectionChanged();
                break;
        }

    })
    }
}


//###########################################################################
// Função ...............	GBCalendarioMesAnoShown     	                #
// Autor ................	Juliano					                        #
// Obs.: ................   Retirado de http://forums.asp.net/t/1349086.aspx#
// Criação ..............	22/03/2010				                        #
// Alteração ............	                              				    #
// Descrição ............	Altera o modo do calendário para Mês/Ano        #
// Parametros........... 	objetos internos do GbCalendario                #
//###########################################################################

function GBCalendarioMesAnoShown(sender, args) {
    //set the default mode to month
    sender._switchMode("months", true);
    changeCellHandlers(sender);
}


//###########################################################################
// Função ...............	changeCellHandlers           	                #
// Autor ................	Juliano					                        #
// Obs.: ................   Retirado de http://forums.asp.net/t/1349086.aspx#
// Criação ..............	22/03/2010				                        #
// Alteração ............	                              				    #
// Descrição ............	Ajusta os "handlers" de cada mês do Calendário  #
// Parametros........... 	objetos internos do GbCalendario                # 
//###########################################################################
function changeCellHandlers(cal) {
    if (cal._monthsBody) {
        //remove the old handler of each month body.
        for (var i = 0; i < cal._monthsBody.rows.length; i++) {
            var row = cal._monthsBody.rows[i];
            for (var j = 0; j < row.cells.length; j++) {
                $common.removeHandlers(row.cells[j].firstChild, cal._cell$delegates);
            }
        }
        //add the new handler of each month body.
        for (var i = 0; i < cal._monthsBody.rows.length; i++) {
            var row = cal._monthsBody.rows[i];
            for (var j = 0; j < row.cells.length; j++) {
                $addHandlers(row.cells[j].firstChild, cal._cell$delegates);
            }
        }
    }
}

//###########################################################################
// Função ...............	ajustaEnterOnChange     						#
//																			#
// Autor ................	Juliano											#
// Criação ..............	12/04/2010										#
//																			#
// Descrição ............	Força o salto de campo quando for pressionada a	#
//                          tecla <ENTER>. Função criada para usar em       #
//                          campos que utilizam o MaskedEdit Extender, mas  #
//                          pode ser utilizada em outras circunstâncias.    #
//###########################################################################
function ajustaEnterOnChange() {
    if (event.keyCode == 13) {
        var objTabPrincipal = document.getElementById("tabPrincipal");
        // Verifica se a tabela com id tabPrincipal existe no documento HTML.
        // Se existe, colocar o foco nela. Senão, coloca o foco na Tag pai
        if (objTabPrincipal)
        {
            objTabPrincipal.focus();
        }
        else
        {
            event.srcElement.parentNode.focus();
        }
    }
}

//###########################################################################
// Função ...............	Prototype Array      							#
//																			#
// Autor ................	Raoni       									#
// Criação ..............	15/04/2010										#
//																			#
// Descrição ............	Criar um extension method do objeto Array       #
//###########################################################################	
	Array.prototype.has = function(search) {
	    for (var i=0; i < this.length; i++) {
	        if (this[i] == search) {
		        return true;
	        }
	    }
	}

//###########################################################################
// Função ...............	isMaxLength          							#
//																			#
// Autor ................	Raoni       									#
// Criação ..............	15/04/2010										#
//																			#
// Descrição ............	Limitar a quantidade caracteres em um TextBox   # 
//                          do tipo Multiline                               #
//###########################################################################	
function isMaxLength(){
    
    var objCampo = (!bolMozilla) ? event.srcElement : event.target;   

    var intLength = objCampo.getAttribute ? parseInt(objCampo.getAttribute("maxLength")) : ""
    
    if (objCampo.getAttribute && objCampo.value.length > intLength){
        objCampo.value = objCampo.value.substring(0, intLength)
    }
}

//##############################################################################

