	/*
	+ - - - - - - - - - - - - - - - - - - - - - - - - +
	Michel 11/07/2008: FUNÇÕES << JavaScript >> GLOBAIS
	+ - - - - - - - - - - - - - - - - - - - - - - - - +
	
	function desabilita_cor(campo)
	
	function verifica_numero( campo )
	function verifica_num_chars( campo, chrs )
	function IsNumeric(sText)
	function IsNumericChars(sText, chrs)
	
	function checa_email(campo)
	function verifica_data(data)
	function verifica_mmaaaa(data)
	function mascara_data(data)
	
	//Mascara
	function Mascara(formato, objeto)
	function Formatar(campo,e)
	function FormatarHora(campo,e)
	function validaTecla(campo, event)
	
	function isNum( caractere )
	
	// Formata direto no componente:
	function Formata_CNPJ_CPF( el )
	function FormataCNPJ( el )
	function FormataCPF( el )
	function FormataIE( el )
	
	// Formata o String:
	function FormataStrCNPJ( el )
	function FormataStrCPF( el )
	function FormataStrIE( el )
	function FormatRG( el )
	function FormatCPF( el )
	
	function ValidarCPF(Objcpf)
	function checacpf(cpf)
	
	function ValidarRG( el )
	
	function sonumero(e,event)
	
	function adicionar_val_list(campo_orig, campo_dest)
	function limpar_val_list(campo)
	
	function fullwin()
	function fullwin_ajuda(val)
	
	function obter_resolucao_tela()
	
	function textCounter(field, countfield, maxlimit)
	
	*/
	
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	// RESOLUÇÃO DE VÍDEO
	var tela_largura = 800, tela_altura = 600;
	obter_resolucao_tela();
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	function desabilita_cor(campo) {
		campo.className='campos_formulario';
	}
	
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	// TIPOS DE VALIDAÇÃO:
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	function verifica_numero( campo ) {
		var sText = campo.value;
		var ValidChars;
		ValidChars = "0123456789";
		var IsNumber = true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++) { 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) { IsNumber = false; }
		}
		return IsNumber;
	}
	
	function verifica_num_chars( campo, chrs ) {
		var sText = campo.value;
		var ValidChars;
		ValidChars = "0123456789" + chrs;
		var IsNumber = true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++) { 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) { IsNumber = false; }
		}
		return IsNumber;
	}
	
	function IsNumeric(sText) {
		var ValidChars;
		ValidChars = "0123456789";
		var IsNumber = true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++) { 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) { IsNumber = false; }
		}
		return IsNumber;
	}
	
	function IsNumericChars(sText, chrs) {
		var ValidChars;
		ValidChars = "0123456789" + chrs;
		var IsNumber = true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++) { 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) { IsNumber = false; }
		}
		return IsNumber;
	}
	
	function checa_email(campo) {
		var valor = campo.value;
		var email = valor.match(/(\w+)@(.+)\.(\w+)$/);
		if (email == null) {
		  return false;
		} else {
			return true;
		}
	}

	function verifica_data(data) { 
		if (data.value != "") {
		dia = (data.value.substring(0,2));
		mes = (data.value.substring(3,5)); 
		ano = (data.value.substring(6,10)); 
		situacao = ""; 
		if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
		situacao = "falsa"; 
		} 
		if (mes < 01 || mes > 12 ) { 
		situacao = "falsa"; 
		}
		if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
		situacao = "falsa"; 
		} 
		if (situacao == "falsa") { 
			// data.focus(); // data.select();
			return false;  // alert("Data inválida!"); 
		}
		} 
	}
	function verifica_data_mmaaaa(data) { 
		if (data.value != "") {
		dia = 01;
		mes = (data.value.substring(0,2)); 
		ano = (data.value.substring(3,7)); 
		situacao = ""; 
		if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
		situacao = "falsa"; 
		} 
		if (mes < 01 || mes > 12 ) { 
		situacao = "falsa"; 
		}
		if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
		situacao = "falsa"; 
		} 
		if (situacao == "falsa") { 
			// data.focus(); // data.select();
			return false;  // alert("Data inválida!"); 
		}
		} 
	}
	function mascara_data(data){ 
		var mydata = ''; 
		mydata = mydata + data; 
		if (mydata.length == 2){ 
		mydata = mydata + '/'; 
		} 
		if (mydata.length == 5){ 
		mydata = mydata + '/'; 
		} 
		return mydata; 
	} 
	
	
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	
	//function Mascara(formato, keypress, objeto){
	function Mascara(formato, objeto) {
		
		// desabilita_cor(objeto); // Web Integrada
		campo = eval (objeto);
		
		// CEP
		if (formato=='CEP') {
			separador = '-'; 
			conjunto1 = 5;
			if (campo.value.length == conjunto1) {
				campo.value = campo.value + separador;
			}
		}
		
		// PLACA
		if (formato=='PLACA') {
			separador = '-'; 
			conjunto1 = 3;
			if (campo.value.length == conjunto1) {
				campo.value = campo.value + separador;
			}
		}
		
		// DATA
		if (formato=='DATA') {
			separador = '/'; 
			conjunto1 = 2;
			conjunto2 = 5;
			if (campo.value.length == conjunto1) {
				campo.value = campo.value + separador;
			}
			if (campo.value.length == conjunto2) {
				campo.value = campo.value + separador;
			}
		}
		
		// DATA (mm/aaaa)
		if (formato=='MMAAAA') {
			separador = '/'; 
			conjunto1 = 2;
			if (campo.value.length == conjunto1) {
				campo.value = campo.value + separador;
			}
		}
		
		// TELEFONE
		if (formato=='TELEFONE'){
			separador = '-'; 
			conjunto1 = 4;
			if (campo.value.length == conjunto1) {
				campo.value = campo.value + separador;
			}
		}
		
		// HORA
		if (formato=='HORA'){
			separador = ':'; 
			conjunto1 = 2;
			if (campo.value.length == conjunto1) {
				campo.value = campo.value + separador;
			}
		}
		
		// CBO (9999.99)
		if (formato=='CBO') {
			separador = '.'; 
			conjunto1 = 4;
			if (campo.value.length == conjunto1) {
				campo.value = campo.value + separador;
			}
		}
		
	}
	
	function Formatar(campo,e) {
		var cod="";
		if(document.all) {cod=event.keyCode;} else {cod=e.which;}
		if(cod == 08) return;
		if (cod < 48 || cod > 57)
		{
		if (cod < 45 || cod > 57) alert("Digite somente Caracteres Numéricos!");
		cod=0;
		campo.focus(); return false;
		}
		tam=campo.value.length; 
		if(tam > 9) return false; 
		var caract = String.fromCharCode(cod); 
		if(tam == 2 || tam == 5) {campo.value+="/"+caract; return false;} 
		campo.value+=caract; return false; 
	}
	
	document.onKeyPress=Formatar;
	
	function FormatarHora(campo,e) {
		var cod="";
		if(document.all) {cod=event.keyCode;} else {cod=e.which;}
		if(cod == 08) return;
		if (cod < 48 || cod > 57)
		{
		if (cod < 45 || cod > 57) alert("Digite somente Caracteres Numéricos!");
		cod=0;
		campo.focus(); return false;
		}
		tam=campo.value.length; 
		if(tam > 4) return false; 
		var caract = String.fromCharCode(cod); 
		if(tam == 2) {campo.value+=":"+caract; return false;} 
		campo.value+=caract; return false; 
	}
	
	document.onKeyPress=FormatarHora;
	
	
	//=============================================================================
	
	
	function validaTecla(campo, event) { 
		var BACKSPACE= 8; 
		var key; 
		var tecla; 
		  
		CheckTAB=true; 
		  
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode; 
		  
		key = String.fromCharCode( tecla); 
		//alert( 'key: ' + tecla + ' -> campo: ' + campo.value); 
		  
		if ( tecla == 13 ) return false; 
		  
		if ( tecla == BACKSPACE ) return true; 
		  
		return ( isNum(key)); 
	} 
	
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	function isNum( caractere ) { 
		var strValidos = "0123456789";
		if ( strValidos.indexOf( caractere ) == -1 ) {
			return false; 
		} else {
			return true;
		}
	} 
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	// Formata direto no componente:
	
	function Formata_CNPJ_CPF( el ) {
		vr = el.value; 
		tam = vr.length; 
		if ( tam <= 11 )
			FormataCPF( el );
		else
			FormataCNPJ( el );
	}
	
	function FormataCNPJ( el ) { 
		vr = el.value; 
		tam = vr.length; 
		  
		if ( vr.indexOf(".") == -1 ) { 
			if ( ( tam < 13 || tam > 15 ) && tam != 0 ) {
				alert( "Quantidade de dígitos inválida para o CNPJ." );
				return false ;
			}
			else if ( tam == 13 ) 
					el.value = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 3 ) + '.' + vr.substr( 4, 3 ) + '/' + vr.substr( 7, 4 ) + '-' + vr.substr( 11, 2 ) ; 
			else if ( tam == 14 ) 
					el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
			else if ( tam == 15 ) 
					el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '/' + vr.substr( 9, 4 ) + '-' + vr.substr( 13, 2 ) ; 
		} 
		  
		return true; 
	} 
	
	function FormataCNPJ2( el ) { 
		vr = el.value; 
		tam = vr.length; 
		  
		if ( vr.indexOf(".") == -1 ) { 
			if ( ( tam < 13 || tam > 15 )  ) {
				//alert( "Quantidade de dígitos inválida para o CNPJ." );
				el.value = vr;
				return true ;
			}
			else if ( tam == 13 ) 
					el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
			else if ( tam == 14 ) 
					el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
			else if ( tam == 15 ) 
					el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '/' + vr.substr( 9, 4 ) + '-' + vr.substr( 13, 2 ) ; 
		} 
		  
		return true; 
	} 
	
	function FormataCPF( el ) { 
		vr = el.value; 
		tam = vr.length; 
		  
		if ( vr.indexOf(".") == -1 ) { 
			if ( ( tam < 9 || tam > 11 ) && tam != 0 ) {
				//alert( "Quantidade de dígitos inválida para o CPF." );
				return false ;
			}
			else if ( tam == 9 ) 
					el.value = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 3 ) + '.' + vr.substr( 4, 3 ) + '-' + vr.substr( 7, 2 ) ; 
			else if ( tam == 10 ) 
					el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '-' + vr.substr( 8, 2 ) ; 
			else if ( tam == 11 ) 
					el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 ) ; 
		} 
		  
		return true; 
	} 
	
	function FormataIE( el ) { 
		vr = el.value; 
		tam = vr.length; 
		  
		if ( vr.indexOf(".") == -1 ) { 
			if ( ( tam < 10 || tam > 12 ) && tam != 0 ) {
				alert( "Quantidade de dígitos inválida para o IE." );
				return false ;
			}
			else if ( tam == 10 ) 
					el.value = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 3 ) + '.' + vr.substr( 4, 3 ) + '.' + vr.substr( 7, 3 ) ; 
			else if ( tam == 11 ) 
					el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '.' + vr.substr( 8, 3 ) ; 
			else if ( tam == 12 ) 
					el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '.' + vr.substr( 9, 3 ) ; 
		} 
		  
		return true; 
	} 
	
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	// Formata o String:
	
	function FormataStrCNPJ( el ) { 
		vr = el; 
		tam = vr.length; 
		  
		if ( vr.indexOf(".") == -1 ) { 
			if ( ( tam < 13 || tam > 15 ) && tam != 0 ) {
				alert( "Quantidade de dígitos inválida para o CNPJ." );
				return "" ;
			}
			else if ( tam == 13 ) 
					el = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 3 ) + '.' + vr.substr( 4, 3 ) + '/' + vr.substr( 7, 4 ) + '-' + vr.substr( 11, 2 ) ; 
			else if ( tam == 14 ) 
					el = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
			else if ( tam == 15 ) 
					el = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '/' + vr.substr( 9, 4 ) + '-' + vr.substr( 13, 2 ) ; 
		} 
		  
		return el; 
	} 
	
	function FormataStrCPF( el ) { 
		vr = el; 
		tam = vr.length; 
		  
		if ( vr.indexOf(".") == -1 ) { 
			if ( ( tam < 9 || tam > 11 ) && tam != 0 ) {
				alert( "Quantidade de dígitos inválida para o CPF." );
				return "" ;
			}
			else if ( tam == 9 ) 
					el = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 3 ) + '.' + vr.substr( 4, 3 ) + '-' + vr.substr( 7, 2 ) ; 
			else if ( tam == 10 ) 
					el = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '-' + vr.substr( 8, 2 ) ; 
			else if ( tam == 11 ) 
					el = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 ) ; 
		} 
		  
		return el; 
	} 
	
	function FormataStrIE( el ) { 
		vr = el; 
		tam = vr.length; 
		  
		if ( vr.indexOf(".") == -1 ) { 
			if ( ( tam < 10 || tam > 12 ) && tam != 0 ) {
				alert( "Quantidade de dígitos inválida para o IE." );
				return "" ;
			}
			else if ( tam == 10 ) 
					el = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 3 ) + '.' + vr.substr( 4, 3 ) + '.' + vr.substr( 7, 3 ) ; 
			else if ( tam == 11 ) 
					el = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '.' + vr.substr( 8, 3 ) ; 
			else if ( tam == 12 ) 
					el = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '.' + vr.substr( 9, 3 ) ; 
		} 
		  
		return el; 
	} 
	
	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	function FormatRG( el ) { 
		vr = el.value; 
		tam = vr.length; 
		if (tam == 2)  el.value = vr.substr(0, 2) + '.';
		if (tam == 6)  el.value = vr.substr(0, 6) + '.';
		if (tam == 10)  el.value = vr.substr(0, 10) + '-';
		if (tam > 11) return false;
		// desabilita_cor(el); // Web Integrada
		return el.value; 
	} 
	
	function FormatCPF( el ) { 
		vr = el.value; 
		tam = vr.length; 
		if (tam == 3)  el.value = vr.substr(0, 3) + '.';
		if (tam == 7)  el.value = vr.substr(0, 7) + '.';
		if (tam == 11)  el.value = vr.substr(0, 11) + '-';
		if (tam > 13) return false;
		// desabilita_cor(el); // Web Integrada
		return el.value; 
	} 

	//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	function ValidarCPF(Objcpf) {
		var cpf = Objcpf.value;
		exp = /\.|\-/g;
		cpf = cpf.toString().replace( exp, '' );
		if (checacpf(cpf)) {
			return true;
		} else {
			return false;
		}
	}
	function checacpf(cpf) {
		if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
		return false;
		soma = 0;
		for (i=0; i < 9; i ++)
		soma += parseInt(cpf.charAt(i)) * (10 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
		resto = 0;
		if (resto != parseInt(cpf.charAt(9)))
		return false;
		soma = 0;
		for (i = 0; i < 10; i ++)
		soma += parseInt(cpf.charAt(i)) * (11 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
		resto = 0;
		if (resto != parseInt(cpf.charAt(10)))
		return false;
		// alert('CPF correto.');
		return true;
	}
	
	function ValidarRG( el ) {
		
		var numero; var num; var expr; var resto; var total = 0;
		
		num = el.value;  expr = /\.|\-/g;
		num = num.toString().replace( expr, '' );
		
		letra_x = "x";
		letra_X = "X";
		if ( num.indexOf(letra_x) >= 0 || num.indexOf(letra_X) >= 0 ) {
			
			num = num.toString().replace( "x", '' );
			num = num.toString().replace( "X", '' );
			if (IsNumeric(num)) {
				return true;
			} else {
				return false;
			}
			
		} else {
		
			numero = num.split("");
			tamanho = numero.length;
			vetor = new Array(tamanho);
			
			if (tamanho>=1) { vetor[0] = parseInt(numero[0]) * 2; }
			if (tamanho>=2) { vetor[1] = parseInt(numero[1]) * 3; }
			if (tamanho>=3) { vetor[2] = parseInt(numero[2]) * 4; }
			if (tamanho>=4) { vetor[3] = parseInt(numero[3]) * 5; }
			if (tamanho>=5) { vetor[4] = parseInt(numero[4]) * 6; }
			if (tamanho>=6) { vetor[5] = parseInt(numero[5]) * 7; }
			if (tamanho>=7) { vetor[6] = parseInt(numero[6]) * 8; }
			if (tamanho>=8) { vetor[7] = parseInt(numero[7]) * 9; }
			if (tamanho>=9) { vetor[8] = parseInt(numero[8]) * 100; }
			if (tamanho>=1) { total += vetor[0]; }
			if (tamanho>=2) { total += vetor[1]; }
			if (tamanho>=3) { total += vetor[2]; }
			if (tamanho>=4) { total += vetor[3]; }
			if (tamanho>=5) { total += vetor[4]; }
			if (tamanho>=6) { total += vetor[5]; }
			if (tamanho>=7) { total += vetor[6]; }
			if (tamanho>=8) { total += vetor[7]; }
			if (tamanho>=9) { total += vetor[8]; }
			resto = total % 11;
			
			if (resto != 0) { return false; } else { return true; }
			
		}
	}

	function sonumero(e,event) {
		var tecla = event.keyCode?event.keyCode:(event.which?event.which:event.charCode);
		if ( tecla == 9 || tecla > 95 && tecla < 106 || tecla > 47 && tecla < 58 || tecla == 8 || tecla == 18 || tecla == 46 || tecla > 36 && tecla < 41 ) {
			return true;
		} else {
			// alert("tecla: " + tecla);
			return false;
		}
	}
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	function adicionar_val_list(campo_orig, campo_dest) {
		if ( campo_orig.value + ", " != campo_dest.value ) {
			campo_dest.value = campo_dest.value + campo_orig.value + ", ";
		}
	}
	function limpar_val_list(campo) {
		campo.value = "";
	}
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	// Full Screen Window Opener Script- 
	function fullwin() {
		window.open("ajuda/index.html","","fullscreen,scrollbars")
	}
	function fullwin_ajuda(val) {
		window.open("ajuda/index.asp?s_url=" + val,"","fullscreen,scrollbars")
	}
	
function obter_resolucao_tela() {
	if (self.screen) {
		tela_largura = screen.width;
		tela_altura = screen.height;
	}
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}

function retira_acentos(palavra) {
	com_acento = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ';
	sem_acento = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC';
	nova='';
	for(i=0;i<palavra.length;i++) {
		if (com_acento.search(palavra.substr(i,1))>=0) {
		nova+=sem_acento.substr(com_acento.search(palavra.substr(i,1)),1);
		}
		else {
			nova+=palavra.substr(i,1);
		}
	}
	return nova;
}

