/******************************************************************************************************************
 * Arquivo criado em:		2003-01-11
 * Arquivo atualizado em:	2011-03-24
 * Autor:					Francisco L. de Matos
 * Descricao:				Arquivo de funções comuns
 ******************************************************************************************************************/

/* Ajax/Goodies */

	// 01 - Carregar pagina - carregar_pagina_goodie
	/*
		Atributos:  1º DIV alvo da requisicao assincrona (Ex.: '#obj_form')
					2º pagina de resposta (Ex.: 'obj_form.php?comando=700')
		Uso com: 	chamadas normais de funções
		Exemplo: 	carregar_pagina_goodie('#obj_form','obj_form.php?comando=700')
		Descricao: 	Esta função utiliza o plugin Goodies/Ajax para realizar chamadas assincronas.
	*/
	function carregar_pagina_goodie() {
		// 1. vamos receber os parâmetros
		var divForm = '', strPagina = '', figType = 0;
		var temp, temp2, time;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {divForm   = arguments[i];}
			if (i == 1) {strPagina = arguments[i];}
			if (i == 2) {figType   = arguments[i];}
		}
		// 2. Redirecionamento
		if (divForm != '' && strPagina != '') {
			// 2.1. Tratamento de strings das DIVs
			divForm = divForm.replace('#','');
			strPagina = strPagina.replace('#','');
			// 2.2. Tratamento da inclusão do force refresh
			temp = strPagina.substr(strPagina.length-4,4);
			temp2 = strPagina.substr(strPagina.length-1,1);
			time = '&tempo='+new Date().getTime();
			if (temp == '.php' || temp == '.asp' || temp == '.aspx' || temp == '.htm' || temp == 'html' || temp2 == '/') {
				strPagina += '?temp=1'+time;
			}else {
				strPagina += time;
			}
			// 2.3. Carregamento Ajax
			ajax_loadContent(figType,divForm,strPagina);
		} else {
			return false;
		}
	}

/* Formularios */

	// 01 - //
	function validar_campo() {
		// 1. vamos receber os parâmetros
		var campo = '', tipo_dado = '', opcional = '';
		var retorno = true;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo = arguments[i];}
			if (i == 1) {tipo_dado = arguments[i];}
			if (i == 2) {opcional = arguments[i];}
		}
		// 2. comandos
		switch (tipo_dado) {
			case 'string':
				if (opcional == '') {opcional = 1;}
				if (!checar_tamanho(trim(campo.value),opcional,campo.maxLength)) {retorno = false;} break;
			case 'email':
				if (!is_email(trim(campo.value))) {retorno = false;} break;
			case 'data':
				if (!is_data(campo.value)) {retorno = false;} break;
		}
		// 3. retorno
		return retorno;
	}
	// 02 - Ativar (habilitar) elementos do formulario - ativar_form
	/*
		Atributos:  1º formulario (Ex.: document.form_empresa)
					2º tipo de botao - opcional
		Uso com: 	chamadas normais de funções
		Exemplo: 	ativar_form(document.form_empresa,1)
		Descricao: 	Esta função ativa elementos desativados de um formulario.
	*/
	function ativar_form(){
		// 1. vamos receber os parâmetros
		var form = '', campo = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {form  = arguments[i];}
			if (i == 1) {campo = arguments[i];}
		}
		// 2. vamos reativar os campos do formulario
		if (typeof form == 'object') {
			if (typeof campo == 'string') {
				form[campo].disabled = false; form[campo].value = campo;
			}
		} else {
			if (typeof form == 'string' && typeof campo == 'string') {
				document.forms[form].elements[campo].disabled = false;
				document.forms[form].elements[campo].value = campo;
			}
		}
	}
	// 03 - Habilitar e desabilitar botões - hab_bot
	/*
		Atributos:  1º nome do campo
					2º novo valor do campo
		Uso com: 	links e botões
		Exemplo: 	hab_bot('Salvar',1); hab_bot('Limpar',1);
		Descricao: 	Esta função foi especialmente desenvolvida para des/habilitar botoes de um formulario
	*/
	function hab_bot() {
		// 1. vamos receber os parâmetros
		var campo = '', opcoes = 0, form = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo  = arguments[i];}
			if (i == 1) {opcoes = arguments[i];}
			if (i == 2) {form   = arguments[i];}
		}
		// 2. vamos setar os cookies
		if (typeof form == 'object') {
			if (form[campo].disabled == true) {form[campo].disabled = false;}
			else {form[campo].disabled = true;}
			if (opcoes == 1){form[campo].value = 'Aguarde ...';}
		} else if (typeof form == 'string') {
			if (document.forms[form].elements[campo].disabled == true) {document.forms[form].elements[campo].disabled = false;} 
			else {document.forms[form].elements[campo].disabled = true;}
			if (opcoes == 1){document.forms[form].elements[campo].value = 'Aguarde ...';}
		} else {
			if (document.getElementById(campo).disabled == true) {document.getElementById(campo).disabled = false;} 
			else {document.getElementById(campo).disabled = true;}
			if (opcoes == 1){document.getElementById(campo).value = 'Aguarde ...';}
		}
	}
	// 04 - Bloquear teclas especiais - block_key
	/*
		Atributos:  1º codigo da tecla
		Uso com: 	links e botões
		Exemplo: 	if(block_key(e.which)){foco_vizinho(this,this.maxLength,this.form);
		Descricao: 	Esta funcao foi desenvolvida para bloquear eventos especiais de teclado, ou seja,
					as teclas abaixo não são levadas em consideração para comandos especificos
	*/
	function block_key() {
		// 1. vamos receber os parâmetros
		var evento = null; var tecla = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {evento = arguments[i];}
		}
		// 2. Tratamento do evento
		if(typeof(evento) != 'object') {
			tecla = evento;
		}else {
			if(document.all) { // Internet Explorer
				tecla = evento.keyCode;
			} else { // Nestcape, Firefox
				var tecla = evento.which	? evento.which    :
						    evento.keyCode	? evento.keyCode  :
							evento.charCode	? evento.charCode : void 0;
			}
		}
		// 3. Vamos retornar os valores
		if (tecla == '') {return false;}
		if (tecla == 8)  {return false;}
		if (tecla == 13) {return false;}
		if (tecla == 35) {return false;}
		if (tecla == 36) {return false;}
		if (tecla == 37) {return false;}
		if (tecla == 39) {return false;}
		if (tecla == 46) {return false;}
		return true;
	}
	// 05 - Levar foco para o campo vizinho - foco_vizinho
	/*
		Atributos:  1º campo (Ex.: this)
					2º tamanho máximo
					3º formulário (Ex.: this.form) É usado para identificar campos que são repetidos na página, 
					   porém em formulários diferntes
					4º evento (Ex.: event)
		Uso com: 	onKeyDown, onKeyPress (geralmente)
		Exemplo: 	onKeyUp="foco_vizinho(this, this.maxLength);"
		Descricao: 	Esta função passa o foco para o próximo campo. Ela é utilizada exclusivamente em formularios.
	*/
	function foco_vizinho() {
		// 1. variaveis iniciais
		var campo = '', tammax = '', kC = '', form = null, passarfoco = 0, totalC = 0;
		// 2. vamos receber os parâmetros
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo  = arguments[i];}	// campo
			if (i == 1) {tammax = arguments[i];}	// tamanho máximo
			if (i == 2) {form   = arguments[i];}	// formulário (this.form, document.form_cadatro, etc, ...)
			if (i == 3) {kC     = arguments[i];}	// event
		}
		// 3. Tratamento de erros
		var temp_ = localizar_formulario_campo(campo,form);
		vI = temp_[0]; vJ = temp_[1];
		if (vI == -1 || vJ == -1) {return true;}
		if (tammax == '') {
			if (document.forms[vI].elements[vJ].maxLength) {
				tammax = document.forms[vI].elements[vJ].maxLength;
			} else {
				tammax = 9999999999;
			}
		}
		// 4. Vamos tratar o evento
		if (arguments.length == 4) {kC = arguments[3].keyCode;} else {kC = 0;}
		// 5. Vamos validar o foco
		if (!((kC == 9) || (kC == 16)))                               {passarfoco++;}
		if (document.forms[vI].elements[vJ].value.length == tammax)   {passarfoco++;}
		if (document.forms[vI].elements[vJ].value.indexOf("_") == -1) {passarfoco++;}
		// 6. Iniciar foco
		if (passarfoco == 3) {
			// 6.1. vamos retornar o foco para o próximo campo
			if (vI != -1 && vJ != -1) {
				// a. proximo campo
				vJ++;
				// b. vamos verificar se o proximo campo esta desabilitado ou oculto
				while (document.forms[vI].elements[vJ].disabled == true || document.forms[vI].elements[vJ].type == 'hidden') {
					vJ++; totalC++; if (totalC == 10) {break;}
				}
				// c. vamos verificar se o proximo campo existe, para ai sim aplicarmos o foco
				if (document.forms[vI].elements[vJ]) {
					document.forms[vI].elements[vJ].focus();
				}
			}
		}
	}
	// 06 - Reiniciar campos de um formulario - reset_form
	/*
		Atributos:  1º form (Ex.: form_teste)
		Uso com: 	onKeyDown, onKeyPress (geralmente)
		Exemplo: 	onKeyUp="foco_vizinho(this, this.maxLength);"
		Descricao: 	Esta função passa o foco para o próximo campo. Ela é utilizada exclusivamente em formularios.
	*/
	function reset_form() {
		// 1. vamos receber os parâmetros
		var form = null;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {form = arguments[i];}		// campo
		}
		// 2. vamos descobrir o ID do formulário e o ID do campo para recuperarmos o valor
		var i = 0, j = 0, vI = -1, vJ = -1;
		if (form) {
			// 2.1. Achar o form
			var temp_ = localizar_formulario_campo('',form);
			vI = temp_[0]; vJ = temp_[1];
			// 2.2. Achar o campo
			if (vI != -1) {
				for (j = 0; j < document.forms[vI].elements.length; j++) {
					// 2.2.1. limpar campos
					if (document.forms[vI].elements[j].type == 'select-one') {
						document.forms[vI].elements[j].value = document.forms[vI].elements[j].options[0].value;
					}
					else if (document.forms[vI].elements[j].type == 'text' || document.forms[vI].elements[j].type == 'textarea' || document.forms[vI].elements[j].type == 'password' || document.forms[vI].elements[j].type == 'file') {
						document.forms[vI].elements[j].value = '';
					}
					else if (document.forms[vI].elements[j].type == 'select-multiple') {
						document.forms[vI].elements[j].selected = '';    document.forms[vI].elements[j].value = '';
						document.forms[vI].elements[j].selected = null;  document.forms[vI].elements[j].value = null;
						document.forms[vI].elements[j].selected = false; document.forms[vI].elements[j].value = false;
					}
					else if (document.forms[vI].elements[j].type == 'radio' || document.forms[vI].elements[j].type == 'checkbox') {
						document.forms[vI].elements[j].checked = false;
					}
					// 2.2.2. reiniciar spans/divs de apoio dos campos
					if (document.getElementById('span_qtd_'+document.forms[vI].elements[j].name)) {
						document.getElementById('span_qtd_'+document.forms[vI].elements[j].name).innerHTML = '';
					}
					if (document.getElementById('span_see_'+document.forms[vI].elements[j].name)) {
						document.getElementById('span_see_'+document.forms[vI].elements[j].name).style.display = 'none';
					}
				}
			}
		}
	}
	// 07 - Verificar/validar se duas strings de dois campos de formularios são iguais - validar_confirmacao
	/*
		Atributos:  1º campo 1 (trata-se do primeiro campo que será comparado com o segundo)
					2º campo 2 (trata-se do segundo campo que será comparado com o primeiro)
		Uso com: 	campos, preferencialmente onBlur
		Exemplo: 	onBlur="validar_confirmacao(document.form_usuario.Senha, this)"
		Descricao: 	Esta função é utilizada para identificar inconsistências em campos de senha e confirmação da senha.
	*/
	function validar_confirmacao(){
		// a) vamos receber os parâmetros
		var c1 = '', c2 = '', form = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {c1 = arguments[i];}
			if (i == 1) {c2 = arguments[i];}
			if (i == 2) {form = arguments[i];}
		}
		// b) vamos iniciar o tratamento
		if (c1 == '') {alert("ERRO <function>: A funcao 'validar_confirmacao' foi acionada incorretamente!"); return false;}
		if (c2 == '') {alert("ERRO <function>: A funcao 'validar_confirmacao' foi acionada incorretamente!"); return false;}
		// c) CAMPO 1 - vamos descobrir o ID do formulário e o ID do campo para recuperarmos o valor
		var i = 0, j = 0, vI = -1, vJ = -1;
		if (form) {
			// 1. Achar o form
			for (i = 0; i < document.forms.length; i++) {
				if (form.name == document.forms[i].name){vI = i;}
				if (vI != -1){break;}
			}
			// 2. Achar o campo
			for (j=0; j < document.forms[vI].elements.length; j++) {
				if (document.forms[vI].elements[j].name == c1.name) {
					vJ = j;
					break;
				}
			}
		} else {
			// 3. Achar form e campo
			for (i = 0; i < document.forms.length; i++) {
				for (j=0; j < document.forms[i].elements.length; j++) {
					if (document.forms[i].elements[j].name == c1.name) {vI = i; vJ = j; break;}
				}
				if (vI != -1 && vJ != -1){break;}
			}
		}
		// d) CAMPO 2 - vamos descobrir o ID do formulário e o ID do campo para recuperarmos o valor
		var i2 = 0, j2 = 0, vI2 = -1, vJ2 = -1;
		if (form) {
			// 1. Achar o form
			for (i2 = 0; i2 < document.forms.length; i2++) {
				if (form.name == document.forms[i2].name){vI2 = i2;}
				if (vI2 != -1){break;}
			}
			// 2. Achar o campo
			for (j2=0; j2 < document.forms[vI2].elements.length; j2++) {
				if (document.forms[vI2].elements[j2].name == c2.name) {
					vJ2 = j2;
					break;
				}
			}
		} else {
			// 3. Achar form e campo
			for (i2 = 0; i2 < document.forms.length; i2++) {
				for (j2=0; j2 < document.forms[i2].elements.length; j2++) {
					if (document.forms[i2].elements[j2].name == c2.name) {vI2 = i2; vJ2 = j2; break;}
				}
				if (vI2 != -1 && vJ2 != -1){break;}
			}
		}
		// e) Atribuições dos valores
		var v1 = document.forms[vI].elements[vJ].value;
		var v2 = document.forms[vI2].elements[vJ2].value;
		// f) Comparação
		if (v1 != "" && v2 != "") {
			if (v1 != v2){
				alert("ERRO: A confirmação da senha não confere!");
				document.forms[vI].elements[vJ].value = "";
				document.forms[vI2].elements[vJ2].value = "";
				document.forms[vI].elements[vJ].focus();
			}
		}
	}
	// 08 - Verificar/validar força da senha - verificar_forca_senha
	/*
		Atributos:  1º campo (trata-se do campo que será testado)
					2º formulário (Ex.: this.form. É usado para identificar campos que são repetidos na página, porém em formulários diferentes)
					3º div - opcional - (trata-se da div que receberá o resultado)
		Uso com: 	campos, preferencialmente onKeyUp
		Exemplo: 	onkeyup="javascript: verificar_forca_senha(this);"
		Descricao: 	Esta função é utilizada para fragilidades de senha.
	*/
	function verificar_forca_senha(){
		// a) vamos receber os parâmetros
		var campo = '', form = '', div = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo = arguments[i];}
			if (i == 1) {form  = arguments[i];}
			if (i == 2) {div   = arguments[i];}
		}
		// b) erro
		if (campo == '') {alert("ERRO <function>: A funcao 'verificar_forca_senha' foi acionada incorretamente!"); return false;}
		// c) atribuições
		if (div == '') {div = document.getElementById('forca_senha');} else {div = document.getElementById(div);}
		var contemNumeros = /[0-9]/; 
		var contemLetras = /[a-z]/i; 
		var contemEspecial = /[@#$%&*]/; //var contemEspecial = /[@#$%&amp;*]/; 
		var contagem = 0;
		// d) vamos descobrir o ID do formulário e o ID do campo para recuperarmos o valor
		var temp_ = localizar_formulario_campo(campo,form);
		vI = temp_[0]; vJ = temp_[1];
		// e) validacao
		if (vI != -1 && vJ != -1) {
			var valor = document.forms[vI].elements[vJ].value;
			if (valor.length > 0) {
				xx = '';
				if (contemNumeros.test(valor)) {contagem++; xx = xx+"n";}
				if (contemLetras.test(valor)) {contagem++; xx = xx+"l";}
				if (contemEspecial.test(valor)) {contagem++; xx = xx+"e";}
				if (valor.length > 9) {contagem++; xx = xx+"9";}
				if (valor.length > 19) {contagem++; xx = xx+"19";}
				switch(contagem) { 
					case 1: {
						//div.style.background = "#FC9";
						div.style.color = "#F00";
						div.innerHTML = "Senha fraca!";
					} break; 
					case 2: {
						//div.style.background =" #FF9";
						div.style.color = "#800";
						div.innerHTML = "Senha relevante!";
					} break; 
					case 3: {
						//div.style.background = "#6C9";
						div.style.color = "#080";
						div.innerHTML = "Senha forte!";
					} break; 
					case 4: {
						//div.style.background = "#006600";
						div.style.color = "#777";
						div.innerHTML = "Senha fortíssima!";
					} break; 
					case 5: {
						//div.style.background = "#000";
						div.style.color = "#000";
						div.innerHTML = "Senha extremamente forte!";
					} break; 
					default: {
						//div.style.background = "#AAA";
						div.innerHTML = "ERRO <function>: A funcao 'verificar_forca_senha' foi acionada incorretamente!"; 
					}
				} 
			} else {
				//div.style.background = "#AAA";
				div.innerHTML = "Força da senha, aguardando ..."; 
			}
		}
	} 
	// 09 - Excluir aspas e apostrofes de um campo - EA
	/*
		Atributos:  1º campo (trata-se do campo inteiro. Ex.: this)
					2º formulário - opcional - (Ex.: this.form. É usado para identificar campos que são repetidos na página, porém em formulários diferentes)
		Uso com: 	campos de formulários
		Exemplo: 	onblur="EA(this,this.form)"
		Descricao: 	Esta função é utilizada para retirar caracteres de injeção SQL como aspas simples e duplas.
	*/
	function EA(){
		// a) Coleta de parâmetros
		var campo = "", form = "", texto = "";
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo = arguments[i];}
			if (i == 1) {form = arguments[i];}
		}
		// b) tratamento de parametros padroes
		if (campo == "") {alert("ERRO <function>: A funcao 'EA' foi acionada incorretamente!"); return false;}
		// c) vamos descobrir o ID do formulário e o ID do campo para recuperarmos o valor
		var i = 0, j = 0, vI = -1, vJ = -1;
		if (form) {
			// 1. Achar o form
			for (i = 0; i < document.forms.length; i++) {
				if (form.name == document.forms[i].name){vI = i;}
				if (vI != -1){break;}
			}
			// 2. Achar o campo
			for (j=0; j < document.forms[vI].elements.length; j++) {
				if (document.forms[vI].elements[j].name == campo.name) {
					vJ = j;
					break;
				}
			}
		} else {
			// 3. Achar form e campo
			for (i = 0; i < document.forms.length; i++) {
				for (j=0; j < document.forms[i].elements.length; j++) {
					if (document.forms[i].elements[j].name == campo.name) {vI = i; vJ = j; break;}
				}
				if (vI != -1 && vJ != -1){break;}
			}
		}
		var texto = document.forms[vI].elements[vJ].value;
		// d) validação e retorno
		if (texto != "") {
			document.forms[vI].elements[vJ].value = limpar_aspas(texto);
		}
	}
	
/* Apoio a funcoes de interacao com formularios */

	// 01 - Localizar ID de um FORM e um CAMPO - localizar_formulario_campo
	/*
		Atributos:  1º campo (Ex.: this, this.name, 'nome_campo')
					2º formulário (Ex.: this.form) É usado para identificar campos que são repetidos na página, porém em formulários diferentes
		Uso com: 	funcoes JS de validacao e interacao em geral
		Exemplo: 	var temp_ = localizar_formulario_campo(this,this.form)
		Descricao: 	Esta função é utilizada para identificar o ID de um formulario e o ID de um determinado campo
					retornando um array com os indices DOM dos elementos FORM e CAMPO (nesta sequencia)
	*/
	function localizar_formulario_campo() {
		// 1. Variaveis iniciais
		var campo = '', form = '', temp = '', temp2 = '';
		var i = 0, j = 0, vI = -1, vJ = -1;
		// 2. Coleta de parametros
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo = arguments[i];}
			if (i == 1) {form  = arguments[i];}
		}
		// 3. Tratamento de variaveis
		if (typeof campo == 'string') {campo = campo.replace('#','');}
		if (typeof form  == 'string') {form  = form.replace('#','');}
		/*
		if (typeof campo == 'object') {
			if (typeof campo[0] == 'string') {temp = campo[0];}
			if (typeof campo[1] == 'string') {temp2 = campo[1];}
			campo = temp;
			form  = temp2;
		}
		*/
		// 3. Comandos
		// 3.1. achar o indice do formulario e o indice do campo
		if (form && campo) {
			// a. Achar o form
			for (i = 0; i < document.forms.length; i++) {
				if (typeof form == 'object') {
					if (form.name == document.forms[i].name){vI = i;}
				} else if (typeof form == 'string') {
					if (document.getElementById(form)) {
						if (document.forms[form].name == document.forms[i].name){vI = i;}
					}
				} else {vI = -1;}
				if (vI != -1){break;}
			}
			// b. Achar o campo
			if (vI != -1 && campo != '') {
				for (j = 0; j < document.forms[vI].elements.length; j++) {
					if (typeof campo == 'object') {
						if (document.forms[vI].elements[j].name == campo.name){
							vJ = j; break;
						}
					} else if (typeof campo == 'string') {
						if (document.getElementById(campo)) {
							if (document.forms[vI].elements[j].name == campo){
								vJ = j; break;
							}
						}
					} else {vJ = -1;}
				}
			}
		} 
		// 3.2. achar apenas o indice do formulario
		else if (form && !campo) {
			// a. Achar o form
			for (i = 0; i < document.forms.length; i++) {
				if (typeof form == 'object') {
					if (form.name == document.forms[i].name){vI = i;}
				} else if (typeof form == 'string') {
					if (document.getElementById(form)) {
						if (document.forms[form].name == document.forms[i].name){vI = i;}
					}
				} else {vI = -1;}
				if (vI != -1){break;}
			}
		}
		// 3.3. achar o indice do formulario e de um campo a partir do campo
		else if (!form && campo) {
			// a. Achar form e campo
			for (i = 0; i < document.forms.length; i++) {
				for (j = 0; j < document.forms[i].elements.length; j++) {
					if (typeof campo == 'object') {
						if (document.forms[i].elements[j].name == campo.name){
							vI = i; vJ = j; break;
						}
					} else if (typeof campo == 'string') {
						if (document.getElementById(campo)) {
							if (document.forms[i].elements[j].name == campo){
								vI = i; vJ = j; break;
							}
						}
					} else {vI = -1; vJ = -1;}
				}
				if (vI != -1 && vJ != -1){break;}
			}
		}
		// 4. Retorno
		temp = Array(vI,vJ);
		return temp;
	}

/* Strings.Validacoes em texto e campos */

	// 01 - Validar domínio a partir de uma string - is_dominio
	/*
		Atributos:  1º domínio (Ex.: http://www.empresa.com.br, ...)
		Uso com: 	funções em gerais
		Exemplo: 	boolean = is_dominio('http://www.empresa.com.br');
		Descricao: 	Esta função é utilizada exclusivamente para validar conteúdos de dominio de variáveis string.
	*/
	function is_dominio(){
		// 1. Coleta de parâmetros
		var dm = ""; var ce = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {dm = arguments[i];}
		}
		// 2. Tratamentos/críticas
		// 2.1. ERRO: conteudo nulo
		if (dm == "") {return false;}
		// 2.2. ERRO: conteudo pequeno
		if (dm.length < 14) {return false;}
		// 2.3. ERRO: verifica o divisor de protocolo
		var dominio_ = dm.split('://');
		if (dominio_.length < 2) {return false;}
		// 2.4. ERRO: verifica o comprimento do protocolo e do domínio
		var prot = "", dominio = "";
		prot = dominio_[0].toLowerCase(); dominio = dominio_[1];
		if (prot != 'http') {return false;}
		// 2.5. ERRO: verifica o ponto
		var d_ = dominio.split('.');
		if (d_.length < 2) {return false;}
		// 2.6. NOTA: se o script chegou até aqui então tá tudo certo
		return true;
	}
	// 02 - Validar domínio a partir de um campo - validar_dominio
	/*
		Atributos:  1º campo (Ex.: this)
					2º formulário (Ex.: this.form. É usado para identificar campos que são repetidos na página, porém em formulários diferentes)
		Uso com: 	onBlur (geralmente)
		Exemplo: 	onBlur="validar_dominio(this,this.form)"
		Descricao: 	Esta função é utilizada para validação de strings de dominios em campos de formulario.
	*/
	function validar_dominio(){
		// 1. Coleta de parâmetros
		var campo = "", form = "";
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo = arguments[i];}
			if (i == 1) {form = arguments[i];}
		}
		// 2. vamos descobrir o ID do formulário e o ID do campo para recuperarmos o valor
		var temp_ = localizar_formulario_campo(campo,form);
		vI = temp_[0]; vJ = temp_[1];
		if (vI == -1 || vJ == -1) {return false;}
		// 3. validação e mensagem de erro
		var dm = document.forms[vI].elements[vJ].value;
		if (dm != "") {
			if (!is_dominio(dm)) {
				// 1. Resposta
				alert(dm+"\n\r\n\r ERRO: URL inválida!");
				//document.forms[vI].elements[vJ].value = "";
				window.setTimeout("document.forms["+vI+"].elements["+vJ+"].focus()",20);
				//window.setTimeout("document.forms["+vI+"].elements["+vJ+"].select()",20);
			}
		}
	}

	// 03 - Validar nome a partir de uma string - is_nome
	/*
		Atributos:  1º nome (Ex.: Roberto Lopes Gonçalves, ...)
		Uso com: 	funções em gerais
		Exemplo: 	boolean = is_nome('Roberto Lopes Gonçalves');
		Descricao: 	Esta função é utilizada exclusivamente para validar nomes próprios.
	*/
	function is_nome(){
		// 1. Coleta de parâmetros
		var nm = ""; var ce = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {nm = arguments[i];}
		}
		// 2. Tratamentos/críticas
		// 2.1. ERRO: conteudo nulo
		if (nm == "") {return false;}
		// 2.2. ERRO: conteudo pequeno
		if (nm.length < 2) {return false;}
		// 2.3. ERRO: verifica ausencia de caracteres
		var nome_ = nm.split('');
		if (nome_.length < 1) {return false;}
		// 2.4. ERRO: verifica caracteres indesejaveis
		var c_ = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","w","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","X","W","Y","Z","ç","Ç","à","À","á","Á","ã","Ã","â","Â","è","È","é","É","ê","Ê","ì","Ì","í","Í","ò","Ò","ó","Ó","ô","Ô","õ","Õ","ù","Ù","ú","Ú","û","Û","."," ");
		n = 0; achou = 0;
		while (n < nome_.length) {
			for(i=0; i<c_.length; i++) {if (nome_[n] == c_[i]) {achou++;}}
			n++;
		}
		if (nome_.length != achou) {return false;}
		// 3. Se a função chegar até aqui é porque o evento não é número
		return true;
	}
	// 04 - Validar nome a partir de um campo - validar_nome
	/*
		Atributos:  1º campo (Ex.: this)
					2º formulário (Ex.: this.form. É usado para identificar campos que são repetidos na página, porém em formulários diferentes)
		Uso com: 	onBlur (geralmente)
		Exemplo: 	onBlur="validar_nome(this,this.form)"
		Descricao: 	Esta função é utilizada para validação de nomes próprios em campos de formulario.
	*/
	function validar_nome(){
		// 1. Coleta de parametros
		var campo = '', form = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo = arguments[i];}
			if (i == 1) {form = arguments[i];}
		}
		// 2. Tratamento de erros
		var temp_ = localizar_formulario_campo(campo,form);
		vI = temp_[0]; vJ = temp_[1];
		if (vI == -1 || vJ == -1) {return false;}
		// 3. Comandos
		var nm = document.forms[vI].elements[vJ].value;
		// d) validação e mensagem de erro
		if (nm != "") {
			if (!is_nome(nm)) {
				// 2. Resposta
				alert(nm+"\n\r\n\r ERRO: O nome não pode possuir caracteres especiais e números!");
				//document.forms[vI].elements[vJ].value = "";
				window.setTimeout("document.forms["+vI+"].elements["+vJ+"].focus()",20);
				//window.setTimeout("document.forms["+vI+"].elements["+vJ+"].select()",20);
			}
		}
	}

	// 05 - Validar login a partir de uma string - is_login
	/*
		Atributos:  1º nome (Ex.: cris123_saude, ...)
		Uso com: 	funções em gerais
		Exemplo: 	boolean = is_login('cris123_saude');
		Descricao: 	Esta função é utilizada exclusivamente para validar logins de sistema.
	*/
	function is_login(){
		// 1. Coleta de parâmetros
		var nm = ""; var ce = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {nm = arguments[i];}
		}
		// 2. Tratamentos/críticas
		// 2.1. ERRO: conteudo nulo
		if (nm == "") {return false;}
		// 2.2. ERRO: conteudo pequeno
		if (nm.length < 2) {return false;}
		// 2.3. ERRO: verifica ausencia de caracteres
		var nome_ = nm.split('');
		if (nome_.length < 1) {return false;}
		// 2.4. ERRO: verifica caracteres indesejaveis
		var c_ = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","w","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","X","W","Y","Z","1","2","3","4","5","6","7","8","9","0",".","-","_");
		n = 0; achou = 0;
		while (n < nome_.length) {
			for(i=0; i<c_.length; i++) {if (nome_[n] == c_[i]) {achou++;}}
			n++;
		}
		if (nome_.length != achou) {return false;}
		// 3. Se a função chegar até aqui é porque o evento não é número
		return true;
	}

	// 06 - Validar numero a partir de uma string- is_numero
	/*
		Atributos:  1º nome (Ex.: cris123_saude, ...)
		Uso com: 	funções em gerais
		Exemplo: 	boolean = is_numero('cris123_saude'); ---> false
		Descricao: 	Esta função é utilizada exclusivamente para caracteres numericos de ums string.
	*/
	function is_numero(){
		// 1. Coleta de parâmetros
		var nm = '', ce = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {nm = ''+arguments[i]+'';}
		}
		// 2. Tratamentos/críticas
		// 2.1. ERRO: conteudo nulo
		if (nm === '') {return false;}
		// 2.2. ERRO: conteudo pequeno
		if (nm.length < 1) {return false;}
		// 2.3. ERRO: verifica ausencia de caracteres
		var numero_ = nm.split('');
		if (numero_.length < 1) {return false;}
		// 2.4. ERRO: verifica caracteres indesejaveis
		var c_ = new Array('1','2','3','4','5','6','7','8','9','0');
		n = 0; achou = 0;
		for (i=0; i < numero_.length; i++) {
			for(j=0; j<c_.length; j++) {if (numero_[i] == c_[j]) {achou++;}}
		}
		if (numero_.length != achou) {return false;}
		// 3. Se a função chegar até aqui é porque o evento não é número
		return true;
	}

	// 07 - Validar dia a partir de uma string - is_dia
	/*
		Atributos:  1º dia (Ex.: 01, 31, 32, ...)
		Uso com: 	funções em gerais
		Exemplo: 	boolean = is_dia('01'); ---> true
		Descricao: 	Esta função é utilizada exclusivamente para validar nomes próprios.
	*/
	function is_dia(){
		// 1. Coleta de parâmetros
		var input = ''; var ce = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {input = arguments[i];}
		}
		// 2. Tratamentos/críticas
		// 2.1. ERRO: conteudo nulo
		if (input == '') {return false;}
		// 2.2. ERRO: conteudo pequeno
		if (input.length < 1) {return false;}
		// 2.3. ERRO: verifica ausencia de caracteres
		var temp_ = input.split('');
		if (temp_.length < 1) {return false;}
		// 2.4. ERRO: verifica caracteres indesejaveis
		var c_ = new Array('1','2','3','4','5','6','7','8','9','0');
		n = 0; achou = 0;
		while (n < temp_.length) {
			for(i=0; i<c_.length; i++) {if (temp_[n] == c_[i]) {achou++;}}
			n++;
		}
		if (temp_.length != achou) {return false;}
		// 3. Se a função chegar até aqui é porque o evento não é número
		if (parseFloat(input) < 1 || parseFloat(input) > 31) {return false;}
		return true;
	}
	// 08 - Validar dia a partir de um campo- validar_dia
	/*
		Atributos:  1º campo (Ex.: this)
					2º formulário (Ex.: this.form. É usado para identificar campos que são repetidos na página, porém em formulários diferentes)
		Uso com: 	onBlur (geralmente)
		Exemplo: 	onBlur="validar_nome(this,this.form)"
		Descricao: 	Esta função é utilizada para validação de nomes próprios em campos de formulario.
	*/
	function validar_dia(){
		// 1. Coleta de parametros
		var campo = "", form = "";
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo = arguments[i];}
			if (i == 1) {form = arguments[i];}
		}
		// 2. Tratamento de parametros padroes
		var temp_ = localizar_formulario_campo(campo,form);
		vI = temp_[0]; vJ = temp_[1];
		if (vI == -1 || vJ == -1) {return false;}
		// 3. Validacao e mensagem de erro
		var input = document.forms[vI].elements[vJ].value;
		if (input != '') {
			if (!is_dia(input)) {
				// 2. Resposta
				alert(input+"\n\r\n\r ERRO: Dia inválido!");
				//document.forms[vI].elements[vJ].value = "";
				window.setTimeout('document.forms['+vI+'].elements['+vJ+'].focus()',20);
				//window.setTimeout("document.forms["+vI+"].elements["+vJ+"].select()",20);
			}
		}
	}

	// 09 - Validar sigla de um pais - is_pais
	/*
		Atributos:  1º string do pais (Ex.: br)
		Uso com: 	chamada normal de funcoes
		Exemplo: 	var eh_pais = is_pais('br');
		Descricao: 	Esta função é utilizada para validação de abreviacoes/siglas de paises utilizadas em
					dominios e ...
	*/
	function is_pais() {
		// 1. Coleta de parâmetros
		var pais = '', achou = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {pais = arguments[i];}
		}
		// 2. Tratamentos/críticas
		if (pais == '') {return false;}
		// 3. Comandos
		pais = pais.toLowerCase();
		var pais_ = new Array('ac','ad','ae','af','ag','ai','al','am','an','ao','aq','ar','as',
							  'at','au','aw','ax','az','ba','bb','bd','be','bf','bg','bh','bi',
							  'bj','bm','bn','bo','br','bs','bt','bv','bw','by','bz','ca','cc',
							  'cd','cf','cg','ch','ci','ck','cl','cm','cn','co','cr','cu','cv',
							  'cx','cy','cz','de','dj','dk','dm','do','dz','ec','ee','eg','eh',
							  'er','es','et','eu','fi','fj','fk','fm','fo','fr','ga','gb','gd',
							  'ge','gf','gg','gh','gi','gl','gm','gn','gp','gq','gr','gs','gt',
							  'gu','gw','gy','hk','hm','hn','hr','ht','hu','id','ie','il','im',
							  'in','io','iq','ir','is','it','je','jm','jo','jp','ke','kg','kh',
							  'ki','km','kn','kp','kr','kw','ky','kz','la','lb','lc','li','lk',
							  'lr','ls','lt','lu','lv','ly','ma','mc','md','me','mg','mh','mk',
							  'ml','mm','mn','mo','mp','mq','mr','ms','mt','mu','mv','mw','mx',
							  'my','mz','na','nc','ne','nf','ng','ni','nl','no','np','nr','nu',
							  'nz','om','pa','pe','pf','pg','ph','pk','pl','pm','pn','pr','ps',
							  'pt','pw','py','qa','re','ro','rs','ru','rw','sa','sb','sc','sd',
							  'se','sg','sh','si','sj','sk','sl','sm','sn','so','sr','st','su',
							  'sv','sy','sz','tc','td','tf','tg','th','tj','tk','tl','tm','tn',
							  'to','tp','tr','tt','tv','tw','tz','ua','ug','uk','um','us','uy',
							  'uz','va','vc','ve','vg','vi','vn','vu','wf','ws','ye','yt','yu',
							  'za','zm','zw');
		for (i = 0; i < pais_.length; i++) {
			if (pais == pais_[i]) {
				achou = 1;
			}
		}
		if (achou == 1) {return true;} else {return false;}
	}

	// 10 - Validar sigla/extensao de um dominio - is_extensao
	/*
		Atributos:  1º string da extensao (Ex.: br)
		Uso com: 	chamada normal de funcoes
		Exemplo: 	var eh_ext = is_extensao('br');
		Descricao: 	Esta função é utilizada para validação de extensoes de dominio 
	*/
	function is_extensao() {
		// 1. Coleta de parâmetros
		var ext = '', achou = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {ext = arguments[i];}
		}
		// 2. Tratamentos/críticas
		if (ext == '') {return false;}
		// 3. Comandos
		ext = ext.toLowerCase();
		var ext_ = new Array('com','net','info','agr','am','art','b','coop','edu','esp','etc',
							 'far','fm','g12','gov','imb','ind','inf','jus','mil','org','psi',
							 'radio','rec','srv','tmp','tur','tv','adm','adv','arq','ato','bio',
							 'bmd','can','cim','cng','cnt','ecn','eng','eti','fnd','fot','fst',
							 'ggf','jor','lel','mat','med','mus','not','ntr','odo','ppg','pro',
							 'psc','qsl','slg','trd','taxi','teo','vet','zlg','nom','blog','flog',
							 'vlog','wiki','cc','in','us','mobi','eu','ws');
		for (i = 0; i < ext_.length; i++) {
			if (ext == ext_[i]) {
				achou = 1;
			}
		}
		if (achou == 1) {return true;} else {return false;}
	}

/* String.Formatacoes em textos e formularios */
	
	// 01 - Esta função completa valores com caracteres indicados - completar_caracteres
	/*
		Atributos:  1º texto (trata-se do texto que será incrementado)
					2º tamanho (trata-se do tamanho final da string)
					3º caracter (trata-se do caracter que será usado para completar)
					4º inverso (0 para completar da esquerda para direita e 1 para completar ao contrário)
		Uso com: 	chamadas normais de funções
		Exemplo: 	$temp = completar_caracteres(20,5,0,0) ---> 00020
		Descricao: 	Esta função é utilizada completar caracteres em uma string. O objetivo desta função nasceu
					da necessidade em facilicar a criação de layouts de arquivos TXT para cargas automáticas em BDs.
					A funcao nativa do PHP 'str_pad' fornece o mesmo resultado (vide manual)
	*/
	function completar_caracteres() {
		// 1. Coleta de argumentos
		var str = ''; var tam = ''; var car = ''; var inv = 0;
		totalArg = arguments.length; ce = 0;
		for (i = 0; i < totalArg; i++) {
			if (i == 0) {str = arguments[i];}
			if (i == 1) {tam = arguments[i];}
			if (i == 2) {car = arguments[i];}
			if (i == 3) {inv = arguments[i];}
		}
		// 2. Tratamento de erros
		if (str == ''){ce++;}
		if (tam == ''){ce++;}
		if (car == ''){ce++;}
		// 3. Comandos
		if (ce == 0) {
			var STR = str; var n = STR.length;
			if (n < tam) {
				while (n < tam) {
					if (inv == 0) {STR = car+STR;} // caracteres antes  (esquerda)
					if (inv == 1) {STR = STR+car;} // caracteres depois (direita)
					n++;
				}
			}
			return STR;
		} else {
			return str;
		}
	}
	
	// 02 - Aplicar máscara ALFA-NUMÉRICA em uma variavel - mascara
	/*
		Atributos:  1º valor (string que será mascarada)
					2º mascara (formato da mascara)
					3º direcao (0 para comecar da esquerda, 1 para comecar da direita)
		Uso com: 	chamadas normais de funções
		Exemplo: 	CodAgencia = mascara('485', '99999-9', 1) | Resp.: 48-5
		Descricao: 	Esta função é utilizada mascarar uma string.
	*/
	function mascara() {
		// 1. declaracao das variáveis
		var ce = 0, sValue = '', sMask = '', sDir = 0;
		var i, n, nCount, sValue, fldLen, mskLen,bolMask, sCod, ntecla;
		carac = new Array("!","@","#","$","%","&","*","(",")","+",
						  "=","/","\\","|","?","'","\"","{","}","[","]",
						  "ª","º",":",",",";","§","°","<",">",".","´",
						  "`","~","^");
		// 2. coleta de atributos
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {var sValue = arguments[i];}
			if (i == 1) {var sMask = arguments[i];}
			if (i == 2) {var sDir = arguments[i];}
		}
		// 3. Tratamento de erros
		//if (sValue == "") {ce++;}
		if (sMask == '') {ce++;}
		if (ce != 0) {alert('ERRO [function:mascara]: A função foi chamada incorretamente!'); return false;}
		// 4. Limpeza de todos os caracteres de formatação que já estiverem no campo
		sValue = limpar_string(sValue)
		// 5. Esquerda para direita
		if (sDir == 0) {
			// 5.1. Start de variáveis
			fldLen = sValue.length; mskLen = sMask.length;
			i = 0; nCount = 0; sCod = ""; mskLen = fldLen;
			// 5.2. Aplicação da máscara
			while (i <= mskLen) {
				bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == ",") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
				bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
				if (bolMask) {
					sCod += sMask.charAt(i);
					mskLen++; 
				} else {
					sCod += sValue.charAt(nCount);
					nCount++;
				}
				i++;
			}
		}
		// 6. Direita para esquerda
		if (sDir == 1) {
			// 6.1. Start de variáveis
			fldLen = sValue.length; mskLen = sMask.length;
			i = mskLen; 
			nCount = fldLen; 
			sCod = "";
			mskLen = fldLen;
			// 6.2. Aplicação da máscara
			while (i >= 0) {
				bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == ",") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
				bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
				if (bolMask) {
					if (nCount >= 0) {
						sCod = sMask.charAt(i)+sCod;
						mskLen--; 
					}
				} else {
					sCod = sValue.charAt(nCount)+sCod;
					nCount--;
				}
				i--;
			}
		}
		// 7. Retornar o valor final
		return sCod;
	}
	
	// 03 - Aplicar máscara ALFA-NUMÉRICA em campos - aplicar_mascara
	/*
		Atributos:  1º campo (Ex.: this, document.form1.Cnpj, etc, ...)
					2º formulario (Ex.: this.form, document.form1, etc, ...)
					3º evento do teclado (Ex.: event)
					4º mascara (formato da mascara)
					5º numerico ou nao (0 permite caracteres alfa-numericos, 1 permite apenas numeros)
					6º direcao (0 para comecar da esquerda, 1 para comecar da direita)
		Uso com: 	onKeyPress
		Exemplo: 	return aplicar_mascara(this, this.form, event, '99999-999')
		Descricao: 	Esta função é utilizada exclusivamente em campos para aplicação de máscara em tempo real.
	*/
	function aplicar_mascara() {
		// 1. coleta de parâmetros
		var campo = '', form = '', evento = null, mask = '', numerico = 1, direcao = 0, strValue = '', retornar = 0, comp = '';
		var i, tecla;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {campo = arguments[i];}
			if (i == 1) {form = arguments[i];}
			if (i == 2) {evento = arguments[i];}
			if (i == 3) {mask = arguments[i];}
			if (i == 4) {numerico = arguments[i];}
			if (i == 5) {direcao = arguments[i];}
			
		}
		// 2. tratamento de parametros padroes
		if (campo == '') {alert("ERRO <function>: A funcao 'aplicar_mascara' foi acionada incorretamente!"); return false;}
		if (mask  == '') {alert("ERRO <function>: A funcao 'aplicar_mascara' foi acionada incorretamente!"); return false;}
		// 3. vamos descobrir o ID do formulário e o ID do campo para recuperarmos o valor/conteudo
		var i = 0, j = 0, vI = -1, vJ = -1;
		if (typeof(form) == 'object') {
			// 3.1. Achar o form
			for (i = 0; i < document.forms.length; i++) {
				if (form.name == document.forms[i].name){vI = i;}
				if (vI != -1){break;}
			}
			// 3.2. Achar o campo
			for (j=0; j < document.forms[vI].elements.length; j++) {
				if (document.forms[vI].elements[j].name == campo.name) {
					vJ = j;
					break;
				}
			}
		} else {
			// 3.3. Achar form e campo
			for (i = 0; i < document.forms.length; i++) {
				for (j=0; j < document.forms[i].elements.length; j++) {
					if (document.forms[i].elements[j].name == campo.name) {vI = i; vJ = j; break;}
				}
				if (vI != -1 && vJ != -1){break;}
			}
		}
		// 4. tratamento do evento
		if(typeof(evento) != 'object') {
			tecla = evento;
		}else {
			if(document.all) { // Internet Explorer
				tecla = evento.keyCode;
			} else { // Nestcape, Firefox
				var tecla = evento.which	? evento.which    :
							   evento.keyCode	? evento.keyCode  :
							   evento.charCode	? evento.charCode : void 0;
			}
		}
		// 5. Tratamento de evento da tecla
		// 3.1. Habilitar teclas <UNDEFINED>, <DEL>, <TAB>, <ENTER>, <ESC>, <BACKSPACE> e <???>
		if (tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 16 || tecla == 27 || tecla == 46) {
			retornar = 3;
		} else {
		//if (tecla != 8) { // backspace
			if (numerico == 1) { // apenas números...
				if ((tecla > 47) && (tecla < 58)) { // números de 0 a 9
					retornar = 1;
					comp = String.fromCharCode(tecla);
				}
			} else { // qualquer caracter...
				retornar = 2;
				comp = String.fromCharCode(tecla);
			}
		//} else {
		//	retornar = 3;
		}
		// 6. Valor do campo
		if (retornar > 0 && retornar < 3) {
			// 6.1. Atribuir valor ao campo
			//objForm[strField].value = mascara(objForm[strField].value+comp,mask,sDir);
			document.forms[vI].elements[vJ].value = mascara(document.forms[vI].elements[vJ].value+comp,mask,direcao);
		}
		// 7. Retornar evento
		if(document.all) {evento.returnValue = false;return false;} else {return false;}
	}

/* String.Bloqueio de caracteres em campos */

	// 01 - Verificar se o caracter digitado é numero - apenas_numero
	/*
		Atributos:  1º evento (Ex.: event)
		Uso com: 	campos
		Exemplo: 	onkeypress="return apenas_numero(event)"
		Descricao: 	Esta função é utilizada exclusivamente para validar conteúdos de campos, ou seja, permitir
					a digitação apenas de números.
	*/
	function apenas_numero(){
		// 1. Coleta de parâmetros
		var evento = 0, tecla = '', array = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {evento = arguments[i];}
			if (i == 1) {array  = arguments[i];}
		}
		// 2. Tratamento do evento
		if(typeof(evento) != 'object') {
			tecla = evento;
		} else {
			if(document.all) { // Internet Explorer
				tecla = evento.keyCode;
			} else { // Nestcape, Firefox
				var tecla = evento.which    ? evento.which    :
						    evento.keyCode  ? evento.keyCode  :
							evento.charCode ? evento.charCode : void 0;
			}
		}
		// 3.1. Habilitar teclas <UNDEFINED>, <DEL>, <TAB>, <ENTER>, <ESC>, <BACKSPACE> e <???>
		if (tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 16 || tecla == 27 || tecla == 46) {
			if(document.all) {evento.returnValue = true; return true;} else {return true;}
		}
		// 3. Tratamento de teclas
		// 3. Tratamento usando array
		if (array == 1) {
			var achou = 0;
			var c_ = new Array('1','2','3','4','5','6','7','8','9','0');
			var c = String.fromCharCode(tecla)
			for (i = 0; i < c_.length; i++) {if (c == c_[i]) {achou = 1;}}
			if (achou == 1) {
				if(document.all) {evento.returnValue = true; return true;} else {return true;}
			}
		} else {
			// 3.2. Habilitar números de 0 a 9
			if ((tecla >= 48) && (tecla <= 57)){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
		}
		// 4. Se a funcao chegar ate aqui eh porque o evento nao eh valido
		if(document.all) {evento.returnValue = false; return false;} else {return false;}
	}
	// 02 - Verificar se o caracter digitado NÃO é numero - apenas_texto
	/*
		Atributos:  1º evento (Ex.: event)
					2º array - opcional - (permite a escolha do algorítimo que será utilizado)
		Uso com: 	campos
		Exemplo: 	onkeypress="return apenas_texto(event,1)"
		Descricao: 	Esta função é utilizada exclusivamente para validar conteúdos de campos, ou seja, permitir
					a digitação apenas de textos.
	*/
	function apenas_texto(){
		// 1. Coleta de parâmetros
		var evento = 0, achou = 0, array = 1;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {evento = arguments[i];}
			if (i == 1) {array  = arguments[i];}
		}
		// 2. Tratamento do evento
		if(typeof(evento) != 'object') {
			tecla = evento;
		}else {
			if(document.all) { // Internet Explorer
				tecla = evento.keyCode;
			} else { // Nestcape, Firefox
				var tecla = evento.which    ? evento.which    :
						    evento.keyCode  ? evento.keyCode  :
							evento.charCode ? evento.charCode : void 0;
			}
		}
		// 3. Tratamento de teclas especiais
		// 2.2. Habilitar teclas <UNDEFINED>, <DEL>, <TAB>, <ENTER>, <ESC>, <BACKSPACE> e <???>
		if (tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 16 || tecla == 27 || tecla == 46) {
			if(document.all) {evento.returnValue = true; return true;} else {return true;}
		}
		// 4. Tratamento de teclas
		// 4.1. Tratamento usando array
		if (array == 1) {
			var achou = 0;
			var c_ = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','w','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','W','Y','Z','ç','Ç','à','À','á','Á','ã','Ã','â','Â','è','È','é','É','ê','Ê','ì','Ì','í','Í','ò','Ò','ó','Ó','ô','Ô','õ','Õ','ù','Ù','ú','Ú','û','Û');
			var c = String.fromCharCode(tecla)
			for(i=0; i<c_.length; i++) {if (c.indexOf(c_[i],0) != -1) {achou = 1;}}
			if (achou != 0) {return true;}
		// 4.2. Tratamento usando ASCII
		} else {
			// 3.2. Habilitar teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
			//if ((tecla >= 35)  &&  (tecla <= 40)){return false;}
			if ((tecla >= 35)  &&  (tecla <= 40)){return true;}
			// 3.3. Habilitar letras maiúsculas e minúsculas
			else if (((tecla >= 65)  &&  (tecla <= 90)) || ((tecla >= 97)  &&  (tecla <= 122))){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.4. Habilitar A com acentuação
			else if ((tecla >= 192)  &&  (tecla <= 197)){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.5. Habilitar Ç, E e I com acentuação
			else if ((tecla >= 199)  &&  (tecla <= 207)){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.6. Habilitar Ñ e O com acentuação
			else if ((tecla >= 209)  &&  (tecla <= 214)){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.7. Habilitar U com acentuação
			else if (tecla == 217 || tecla == 221){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.8. Habilitar a(minusculo) com acentuação
			else if (tecla == 224 || tecla == 228){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.9. Habilitar ç, e(minusculo) e i(minusculo) com acentuação
			else if (tecla == 231 || tecla == 239){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.10. Habilitar ñ e o(minusculo com acentuação
			else if (tecla == 241 || tecla == 246){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.11. Habilitar u com acentuação
			else if (tecla == 249 || tecla == 252){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
		}
		// 5. Se a funcao chegar ate aqui eh porque o evento nao eh valido
		if(document.all) {evento.returnValue = false; return false;} else {return false;}
	}
	// 03 - Verificar se o caracter digitado pertence aos padrões de um nome - apenas_nome
	/*
		Atributos:  1º evento (Ex.: event)
		Uso com: 	campos
		Exemplo: 	onkeypress="return apenas_nome(event)"
		Descricao: 	Esta função é utilizada exclusivamente para validar conteúdos de campos, ou seja, permitir
					a digitação apenas de caracteres característicos de nomes próprios.
	*/
	function apenas_nome(){
		// 1. Coleta de parâmetros
		var evento = 0, achou = 0, tecla = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {evento = arguments[i];}
		}
		// 2. Tratamento do evento
		// 2.1. Captura do evento
		if(typeof(evento) != 'object') {
			tecla = evento;
		}else {
			if(document.all) { // Internet Explorer
				tecla = evento.keyCode;
			} else { // Nestcape, Firefox
				var tecla = evento.which    ? evento.which    :
						    evento.keyCode  ? evento.keyCode  :
							evento.charCode ? evento.charCode : void 0;
			}
		}
		// 2.2. Habilitar teclas <UNDEFINED>, <DEL>, <TAB>, <ENTER>, <ESC>, <BACKSPACE> e <???>
		if (tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 16 || tecla == 27 || tecla == 46) {
			if(document.all) {
				evento.returnValue = true; return true;
			} else {
				return true;
			}
		}
		// 3. Tratamento
		var achou = 0;
		var c_ = new Array('a','b','c','d','e','f','g','h','i','j','k',
						   'l','m','n','o','p','q','r','s','t','u','v',
						   'x','y','w','z','A','B','C','D','E','F','G',
						   'H','I','J','K','L','M','N','O','P','Q','R',
						   'S','T','U','V','X','W','Y','Z','ç','Ç','à',
						   'À','á','Á','ã','Ã','â','Â','è','È','é','É',
						   'ê','Ê','ì','Ì','í','Í','ò','Ò','ó','Ó','ô',
						   'Ô','õ','Õ','ù','Ù','ú','Ú','û','Û','.',' ');
		var c = String.fromCharCode(tecla);
		//for(i=0; i<c_.length; i++) {if (c.indexOf(c_[i],0) != -1) {achou = 1;}}
		for(i = 0; i < c_.length; i++) {if (c == c_[i]) {achou = 1; /*alert(c +' - '+ c_[i]);*/}}
		if (achou == 1) {
			if(document.all) {
				evento.returnValue = true; return true;
			} else {
				return true;
			}
		}
		// 4. Se a funcao chegar ate aqui eh porque o evento nao eh valido
		if(document.all) {evento.returnValue = false; return false;} else {return false;}
	}
	// 04 - Verificar se o caracter digitado pertence aos padrões de um login - apenas_login
	/*
		Atributos:  1º evento (Ex.: event)
		Uso com: 	campos
		Exemplo: 	onkeypress="return apenas_nome(event)"
		Descricao: 	Esta função é utilizada exclusivamente para validar conteúdos de campos, ou seja, permitir
					a digitação apenas de caracteres característicos de nomes próprios.
	*/
	function apenas_login(){
		// 1. Coleta de parâmetros
		var evento = 0, achou = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {evento = arguments[i];}
		}
		// 2. Tratamento do evento
		// 2.1. Captura do evento
		if(typeof(evento) != 'object') {
			tecla = evento;
		}else {
			if(document.all) { // Internet Explorer
				tecla = evento.keyCode;
			} else { // Nestcape, Firefox
				var tecla = evento.which    ? evento.which    :
						    evento.keyCode  ? evento.keyCode  :
							evento.charCode ? evento.charCode : void 0;
			}
		}
		// 2.2. Habilitar teclas <UNDEFINED>, <DEL>, <TAB>, <ENTER>, <ESC>, <BACKSPACE> e <???>
		if (tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 16 || tecla == 27 || tecla == 46) {
			if(document.all) {evento.returnValue = true; return true;} else {return true;}
		}
		// 3. Tratamento
		var achou = 0;
		var c_ = new Array("a","b","c","d","e","f","g","h","i","j","k","l",
						   "m","n","o","p","q","r","s","t","u","v","x","y",
						   "w","z","A","B","C","D","E","F","G","H","I","J",
						   "K","L","M","N","O","P","Q","R","S","T","U","V",
						   "X","W","Y","Z","1","2","3","4","5","6","7","8",
						   "9","0",".","-","_");
		var c = String.fromCharCode(tecla)
		for(i=0; i<c_.length; i++) {if (c == c_[i]) {achou = 1;}}
		if (achou == 1) {
			if(document.all) {evento.returnValue = true; return true;} else {return true;}
		}
		// 4. Se a funcao chegar ate aqui eh porque o evento nao eh valido
		if(document.all) {evento.returnValue = false; return false;} else {return false;}
	}
	// 05 - Verificar se o caracter digitado pertence aos padrões do domínio - apenas_dominio
	/*
		Atributos:  1º evento (Ex.: event)
					2º array - opcional - (permite a escolha do algorítimo que será utilizado)
		Uso com: 	campos
		Exemplo: 	onkeypress="return apenas_dominio(event,1)"
		Descricao: 	Esta função é utilizada exclusivamente para validar conteúdos de campos, ou seja, permitir
					a digitação apenas de caracteres característicos de e-mail.
	*/
	function apenas_dominio(){
		// 1. Coleta de parâmetros
		var evento = 0, achou = 0, array = 1;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {evento = arguments[i];}
			if (i == 1) {array = arguments[i];}
		}
		// 2. Tratamento do evento
		// 2.1. Captura do evento
		if(typeof(evento) != 'object') {
			tecla = evento;
		}else {
			if(document.all) { // Internet Explorer
				tecla = evento.keyCode;
			} else { // Nestcape, Firefox
				var tecla = evento.which    ? evento.which    :
						    evento.keyCode  ? evento.keyCode  :
							evento.charCode ? evento.charCode : void 0;
			}
		}
		// 2.2. Habilitar teclas <UNDEFINED>, <DEL>, <TAB>, <ENTER>, <ESC>, <BACKSPACE> e <???>
		if (tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 16 || tecla == 27 || tecla == 46) {
			if(document.all) {evento.returnValue = true; return true;} else {return true;}
		}
		// 3. Tratamento usando array
		if (array == 1) {
			var achou = 0;
			var c_ = new Array('a','b','c','d','e','f','g','h','i','j','k','l',
							   'm','n','o','p','q','r','s','t','u','v','x','y',
							   'w','z',':','/','.','_','-','1','2','3','4','5',
							   '6','7','8','9','0');
			var c = String.fromCharCode(tecla);
			for(i=0; i<c_.length; i++) {if (c == c_[i]) {achou = 1;}}
			if (achou == 1) {
				if(document.all) {evento.returnValue = true; return true;} else {return true;}
			}
		} else {
			// 3.2. Habilitar numeros
			if ((tecla >= 48)  &&  (tecla <= 57)){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.3. Habilitar letras minúsculas
			else if ((tecla >= 97)  &&  (tecla <= 122)){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
			// 3.4. Habilitar @ _ - . ------------------ PRECISA ARRUMAR para : / . _ -
			else if (tecla == 64 || tecla == 95 || tecla == 45 || tecla == 46){if(document.all) {evento.returnValue = true; return true;} else {return true;}}
		}
		// 4. Se a funcao chegar ate aqui eh porque o evento nao eh valido
		if(document.all) {evento.returnValue = false; return false;} else {return false;}
	}
	// 06 - Verificar se o caracter digitado pertence aos padrões de um token - apenas_token
	/*
		Atributos:  1º evento (Ex.: event)
		Uso com: 	campos
		Exemplo: 	onkeypress="return apenas_nome(event)"
		Descricao: 	Esta função é utilizada exclusivamente para validar conteúdos de campos, ou seja, permitir
					a digitação apenas de caracteres característicos de nomes próprios.
	*/
	function apenas_token(){
		// 1. Coleta de parâmetros
		var evento = 0, achou = 0, tecla = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {evento = arguments[i];}
		}
		// 2. Tratamento do evento
		// 2.1. Captura do evento
		if(typeof(evento) != 'object') {
			tecla = evento;
		}else {
			if(document.all) { // Internet Explorer
				tecla = evento.keyCode;
			} else { // Nestcape, Firefox
				var tecla = evento.which    ? evento.which    :
						    evento.keyCode  ? evento.keyCode  :
							evento.charCode ? evento.charCode : void 0;
			}
		}
		// 2.2. Habilitar teclas <UNDEFINED>, <DEL>, <TAB>, <ENTER>, <ESC>, <BACKSPACE> e <???>
		if (tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 16 || tecla == 27 || tecla == 46) {
			if(document.all) {
				evento.returnValue = true; return true;
			} else {
				return true;
			}
		}
		// 3. Tratamento
		var achou = 0;
		var c_ = new Array('a','b','c','d','e','f','g','h','i','j','k','l',
						   'm','n','o','p','q','r','s','t','u','v','x','y',
						   'w','z','0','1','2','3','4','5','6','7','8','9');
		var c = String.fromCharCode(tecla);
		//for(i=0; i<c_.length; i++) {if (c.indexOf(c_[i],0) != -1) {achou = 1;}}
		for(i=0; i<c_.length; i++) {if (c == c_[i]) {achou = 1; /*alert(c +' - '+ c_[i]);*/}}
		if (achou == 1) {
			if(document.all) {
				evento.returnValue = true; return true;
			} else {
				return true;
			}
		}
		// 4. Se a funcao chegar ate aqui eh porque o evento nao eh valido
		if(document.all) {evento.returnValue = false; return false;} else {return false;}
	}

/* Diversos */
	
	// 01 - Link falso - lf
	/*
		Atributos:  nenhum
		Uso com: 	chamadas normais de eventos e links
		Exemplo: 	onClick="javascript:lf()"
		Descricao: 	Esta função é utilizada apenas para simular um comando.
	*/
	function lf(){/*Não faz nada*/}
	// 02 - Aumentar tamanho do texto - zoom
	/*
		Atributos:  1º tipo (+ (mais) para aumentar e - (menos) para diminuir)
					2º div (Nome da div que receberá o novo atributo)
		Uso com: 	chamadas normais de funções
		Exemplo: 	onclick="javascript:zoom('-','<?= $div;?>');"
		Descricao: 	Esta função é utilizada para interação com o usuário, permitindo o 'zoom' dos textos do site.
	*/
	function zoom() { 
		// a) vamos receber os parâmetros
		var tipo = "", div = "";
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {tipo = arguments[i];}
			if (i == 1) {div = arguments[i];}
		}
		// b) vamos iniciar o tratamento
		var sizeAtual = document.getElementById(div).style.fontSize; 
		sizeAtual = sizeAtual.substring(0, sizeAtual.indexOf('p'));
		if (tipo == "-") {
			if (sizeAtual > 10) {
				document.getElementById(div).style.fontSize = (parseInt(sizeAtual)-1)+'px';
			}
		} else if (tipo == "+") {
			if (sizeAtual < 16) {
				document.getElementById(div).style.fontSize = (parseInt(sizeAtual)+1)+'px';
			}
		} 
	}

/* Number.Tratamento de numeros */

	// 01 - Gerar numero aleatorio - roundNumber
	/*
		Atributos:  1º ???
		Uso com: 	chamadas normais para variaveis
		Exemplo: 	var x = roundNumber(123);
		Descricao: 	Esta função é utilizada apenas para gerar um numero aleatorio
	*/
	function roundNumber(rnum) {
	   return Math.round(rnum * Math.pow(10,2)) / Math.pow(10,2);
	}
	// 02 - Converter numeros float em moeda - float2moeda
	/*
		Atributos:  1º Numero que sera convertido para o formato moeda
		Uso com: 	chamadas normais para variaveis
		Exemplo: 	var x = float2moeda(123.25); ---> 123,25
		Descricao: 	Esta funcao eh utilizada para converter numeros float em moeda (americano para brasileiro)
	*/
	function float2moeda() {
		// a) vamos receber os parâmetros
		var num = null;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {num = arguments[i];}
		}
		// b) tratamentos
		x = 0;
		if (num < 0) {
			num = Math.abs(num);
			x = 1;
		}
		if (isNaN(num)) {num = '0';}
		cents = Math.floor((num * 100 + 0.5) % 100);
		num = Math.floor((num * 100 + 0.5) / 100).toString();
		if (cents < 10) {cents = '0' + cents;}
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
			num = num.substring(0,num.length-(4 * i + 3)) + '.' + num.substring(num.length-(4 * i + 3));
		}
		ret = num + ',' + cents;
		if (x == 1) {ret = ' - ' + ret;}
		return ret;
	}
	// 03 - Converter numeros moeda em float - moeda2float
	/*
		Atributos:  1º Numero que sera convertido para o formato float
		Uso com: 	chamadas normais para variaveis
		Exemplo: 	var x = float2moeda(123,25); ---> 123.25
		Descricao: 	Esta funcao eh utilizada para converter numeros moeda em float (brasileiro para americano)
	*/
	function moeda2float(moeda){
		moeda = moeda.replace('.','');
		moeda = moeda.replace(',','.');
		return parseFloat(moeda);
	}

/* Number.DVs */

	// 01 - Este é um round personalizado (gerar numero aleatorio) - roundP
	function roundP(num){
		var num = ""+num+"";
		var cd = num.indexOf(".");
		if (cd == "") {
			cd = num.indexOf(",");
			if (cd == "") {
				return num;
			} else {
				num = num.substring(0,cd);
				return num;
			}
		} else {
			num = num.substring(0,cd);
			return num;
		}
	}
	// 02 - Calcular DV dos protocolos - DV (verificar)
	function DV(numx){
		var cDV = (numx - (9 * (roundP(numx/9))));
		var nDV = numx+""+cDV;
		return nDV;
	}
	// 03 - Esta função testa o DV dos protocolos - tDV (verificar)
	function tDV(prot) {
		var prot = ""+prot+"";
		if (prot.length > 8) {return false;}
		var nDV = prot.substr(0,7);
		var cDVp = prot.substr(7,1);
		var cDVc = (nDV - (9 * (roundP(nDV/9))));
		if (cDVp == cDVc){
			return true;
		} else {
			return false;
		}
	}

/* Stings.Pagina */

	// 01 - Esta função captura dados da string da url da pagina - dados_pagina
	/*
		Atributos:  1º string (trata-se do tipo de dado que sera retornado)
		Uso com: 	variáveis
		Exemplo: 	url = dados_pagina('url')
		Descricao: 	Esta função é utilizada retornar strings contendo informações da url do site.
	*/
	function dados_pagina() {
		// 1. Coleta de parametros
		var type = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {type = arguments[i];}
		}
		// 2. Tratamento de erros
		if (type == '') {return '';}
		// 3. Comandos
		var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
		var url = location.href.substring(dir.length,location.href.length+1);
		// 4. Retorno
		if (type == 'dir') {
			return dir;
		} else if (type == 'url') {
			return url;
		}
		return '';
	}

/* Stings.Tratamento de strings */
	
	// 01 - Esta função limpa string de caracteres indesejados - limpar_string
	/*
		Atributos:  1º string (trata-se do texto que será limpo)
		Uso com: 	variáveis
		Exemplo: 	texto_limpo = limpar_string("texto: 9879-8798") ---> "texto98798798"
		Descricao: 	Esta função é utilizada exclusivamente retirar caracteres especiais de strings.
	*/
	function limpar_string(){
		// a) Coleta de parâmetros
		var st = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {st = arguments[i];}
		}
		// b) tratamento de parametros padroes
		if (st == '') {alert("ERRO <function>: A funcao 'limpar_string' foi acionada incorretamente!"); return false;}
		// c) limpeza
		for (i = 0; i < 10; i++){
			st = st.toString().replace( ":", "" );
			st = st.toString().replace( "-", "" );
			st = st.toString().replace( ".", "" );
			st = st.toString().replace( ",", "" );
			st = st.toString().replace( "/", "" );
			st = st.toString().replace( "(", "" );
			st = st.toString().replace( ")", "" );
			st = st.toString().replace( " ", "" );
			st = st.toString().replace( "*", "" );
			st = st.toString().replace( "+", "" );
			st = st.toString().replace( "!", "" );
			st = st.toString().replace( "@", "" );
			st = st.toString().replace( "$", "" );
			st = st.toString().replace( "%", "" );
			st = st.toString().replace( "&", "" );
			st = st.toString().replace( "=", "" );
			st = st.toString().replace( "[", "" );
			st = st.toString().replace( "]", "" );
			st = st.toString().replace( "?", "" );
			st = st.toString().replace( "}", "" );
			st = st.toString().replace( "{", "" );
		}
		return st;
	}
	// 02 - Esta função limpa string de aspas - limpar_aspas
	/*
		Atributos:  1º string (trata-se do texto que será limpo)
		Uso com: 	variáveis
		Exemplo: 	texto_limpo = limpar_aspas("Olá Mr. 'President'")
		Descricao: 	Esta função é utilizada para retirar caracteres de injeção SQL como aspas simples e duplas de variáveis.
	*/
	function limpar_aspas(){
		// a) Coleta de parâmetros
		var st = '', tp = 0;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {st = arguments[i];}
			if (i == 1) {tp = arguments[i];}
		}
		// b) tratamento de parametros padroes
		if (st == '') {return st;}
		//if (st == '') {alert("ERRO <function>: A funcao 'limpar_aspas' foi acionada incorretamente!"); return false;}
		// c) limpeza
		for (i = 0; i < 40; i++){
			if (tp == 0 || tp == 2) {st = st.toString().replace( '"', "" );}
			if (tp == 1 || tp == 2) {st = st.toString().replace( "'", "" );}
		}
		//alert(st+' - '+tp);
		return st;
	}
	// 03 - trim completo - trim
	/*
		Atributos:  1º string (trata-se do texto que será limpo)
		Uso com: 	variáveis
		Exemplo: 	texto_limpo = trim(" texto ") ----> "texto"
		Descricao: 	Esta função é utilizada para retirar caracteres de espaço no início e fim de uma string.
	*/
	function trim() {
		// a) Coleta de parâmetros
		var st = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {st = arguments[i];}
		}
		// b) limpeza
		return st.replace(/^\s+|\s+$/g,"");
	}
	// 04 - left trim - ltrim
	/*
		Atributos:  1º string (trata-se do texto que será limpo)
		Uso com: 	variáveis
		Exemplo: 	texto_limpo = ltrim(" texto") ----> "texto"
		Descricao: 	Esta função é utilizada para retirar caracteres de espaço no início de uma string.
	*/
	function ltrim() {
		// a) Coleta de parâmetros
		var st = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {st = arguments[i];}
		}
		// b) limpeza
		return st.replace(/^\s+/,"");
	}
	// 05 - right trim - rtrim
	/*
		Atributos:  1º string (trata-se do texto que será limpo)
		Uso com: 	variáveis
		Exemplo: 	texto_limpo = rtrim("texto ") ----> "texto"
		Descricao: 	Esta função é utilizada para retirar caracteres de espaço no fim de uma string.
	*/
	function rtrim() {
		// a) Coleta de parâmetros
		var st = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {st = arguments[i];}
		}
		// b) limpeza
		return st.replace(/\s+$/,"");
	}
	// 07 - UTF8 (Decodificar) - utf8_decode
	function utf8_decode(str_data) {
		var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
		str_data += '';
		while ( i < str_data.length ) {
			c1 = str_data.charCodeAt(i);
			if (c1 < 128) {
				tmp_arr[ac++] = String.fromCharCode(c1);
				i++;
			} else if ((c1 > 191) && (c1 < 224)) {
				c2 = str_data.charCodeAt(i+1);
				tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = str_data.charCodeAt(i+1);
				c3 = str_data.charCodeAt(i+2);
				tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return tmp_arr.join('');
	}
	// 08 - UTF8 (Codificar) - utf8_encode
	function utf8_encode (string) {
		string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
		var utftext = "";
		var start, end;
		var stringl = 0;
		start = end = 0;
		stringl = string.length;
		for (var n = 0; n < stringl; n++) {
			var c1 = string.charCodeAt(n);
			var enc = null;
	 
			if (c1 < 128) {
				end++;
			} else if((c1 > 127) && (c1 < 2048)) {
				enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
			} else {
				enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
			}
			if (enc != null) {
				if (end > start) {
					utftext += string.substring(start, end);
				}
				utftext += enc;
				start = end = n+1;
			}
		}
	 
		if (end > start) {utftext += string.substring(start, string.length);}
	 
		return utftext;
	}
	// 09 - Checa a quantidade mínima e máxima de caracteres de um campo/variável - checar_tamanho
	/*
		Atributos:  1º texto (trata-se do texto que será validado)
					2º mini (comprimento mínimo da string)
					3º maxi (comprimento máximo da string)
		Uso com: 	variáveis
		Exemplo: 	boolean = checar_tamanho("79011-150",3,9) ---> verdadeiro
		Descricao: 	Esta função é utilizada checar se uma variável obedece aos critérios de comprimento mínimo e
					máximo de uma string. Ela ajuda a não exceder caracteres no BD.
	*/
	function checar_tamanho() {
		// a) Coleta de parâmetros
		var texto = '', mini = 0, maxi = 255;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {texto = arguments[i];}
			if (i == 1) {mini = arguments[i];}
			if (i == 2) {maxi = arguments[i];}
		}
		// b) tratamento de parametros padroes
		//if (texto == "") {alert("ERRO <function>: A funcao 'checar_tamanho' foi acionada incorretamente!"); return false;}
		if (mini == '') {alert("ERRO <function>: A funcao 'checar_tamanho' foi acionada incorretamente!"); return false;}
		if (maxi == '') {alert("ERRO <function>: A funcao 'checar_tamanho' foi acionada incorretamente!"); return false;}
		// c) validação
		if (texto.length > maxi || texto.length < mini) {
			return false;
		} else {
			return true;
		}
	}
	// 10 - Checa o conteúdo de um campo/variável avaliando por ER - checar_regex
	/*
		Atributos:  1º texto (texto que será validado)
					2º regexp (expressão regular que será utilizada para a validação)
		Uso com: 	variáveis strings
		Exemplo: 	boolean = checar_regex(campo.value,/^([0-9a-zA-Z])+$/)
		Descricao: 	Esta função é utilizada em conjunto com uma ER para validar uma string.
	*/
	function checar_regex() {
		// a) coleta de parâmetros
		var texto = '', regexp = '';
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {texto = arguments[i];}
			if (i == 1) {regexp = arguments[i];}
		}
		// b) tratamento de parametros padroes
		if (texto == "") {alert("ERRO <function>: A funcao 'checar_regex' foi acionada incorretamente!"); return false;}
		if (regexp == "") {alert("ERRO <function>: A funcao 'checar_regex' foi acionada incorretamente!"); return false;}
		// c) validação
		if (!(regexp.test(texto))) {
			return false;
		} else {
			return true;
		}
	}

/* TESTES */

	function unicode() {
		// 1. vamos receber os parâmetros
		var texto = ''; var com_array = 1;
		for (i = 0; i < arguments.length; i++) {
			if (i == 0) {texto = arguments[i];}
			if (i == 1) {com_array = arguments[i];}
		}
		// 2. Troca de caracteres com array
		if (com_array == 1) {
			var car_ = Array('á','à','â','ã','ä','Á','À','Â','Ã','Ä','é','è','ê','ê',
							 'É','È','Ê','Ë','í','ì','î','ï','Í','Ì','Î','Ï','ó','ò',
							 'ô','õ','ö','Ó','Ò','Ô','Õ','Ö','ú','ù','û','ü','Ú','Ù',
							 'Û','ç','Ç','ñ','Ñ','&','\'');
			var uni_ = Array('\u00e1','\u00e0','\u00e2','\u00e3','\u00e4','\u00c1',
							 '\u00c0','\u00c2','\u00c3','\u00c4','\u00e9','\u00e8',
							 '\u00ea','\u00ea','\u00c9','\u00c8','\u00ca','\u00cb',
							 '\u00ed','\u00ec','\u00ee','\u00ef','\u00cd','\u00cc',
							 '\u00ce','\u00cf','\u00f3','\u00f2','\u00f4','\u00f5',
							 '\u00f6','\u00d3','\u00d2','\u00d4','\u00d5','\u00d6',
							 '\u00fa','\u00f9','\u00fb','\u00fc','\u00da','\u00d9',
							 '\u00db','\u00e7','\u00c7','\u00f1','\u00d1','\u0026',
							 '\u0027');
			var texto_ = texto.split('');
			var temp = '';
			var i = 0;
			for (i=0;i<texto_.length;i++){
				for (j=0;j<car_.length;j++){
					if (texto_[i] == car_[j]) {
						texto.toString().replace(car_[j],uni_[j]);
						//alert(car_[j]+' - '+uni_[j]);
					}
				}
				temp = temp + texto_[i];
			}
			return texto;
		}
		/*
		var hex_ = Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
		var temp = ''; var totalHex = 0;
		var temp_ = Array();
		for (i=0;i<hex_.length;i++){
			for (j=0;j<hex_.length;j++){
				//temp += hex_[i]+""+hex_[j]+"<Br>";
				temp_[totalHex] = '\\u00'+hex_[i]+hex_[j];
				totalHex++;
			}
		}
		var n = 0;
		while (n < totalHex){
			temp += temp_[n]+" \n";
			n++;
		}
		return temp;
		*/
		//palavra = 'ù';
		//alert(palavra.charCodeAt(0)+' - '+temp_[120].toString()+' \u0078');
		//var x = '\u006F';
		//var y = String.fromCharCode(63)
		//alert(temp);
		//xx = 'http://hamstersoup.com/javascript/regexp_character_class_tester.html';
	}

