/*
	Predefinições
	-------------
*/
var array_estado = new Array();
array_estado[0] = "AL";
array_estado[1] = "AC";
array_estado[2] = "AM";
array_estado[3] = "AP";
array_estado[4] = "BA";
array_estado[5] = "CE";
array_estado[6] = "DF";
array_estado[7] = "ES";
array_estado[8] = "GO";
array_estado[9] = "MT";
array_estado[10] = "MA";
array_estado[11] = "MS";
array_estado[12] = "MG";
array_estado[13] = "PA";
array_estado[14] = "PI";
array_estado[15] = "PE";
array_estado[16] = "PR";
array_estado[17] = "PB";
array_estado[18] = "RJ";
array_estado[19] = "RR";
array_estado[20] = "RO";
array_estado[21] = "RN";
array_estado[22] = "RS";
array_estado[23] = "SC";
array_estado[24] = "SP";
array_estado[25] = "SE";
array_estado[26] = "TO";

var array_mes = new Array();
array_mes[0] = "Janeiro";
array_mes[1] = "Fevereiro";
array_mes[2] = "Março";
array_mes[3] = "Abril";
array_mes[4] = "Maio";
array_mes[5] = "Junho";
array_mes[6] = "Julho";
array_mes[7] = "Agosto";
array_mes[8] = "Setembro";
array_mes[9] = "Outubro";
array_mes[10] = "Novembro";
array_mes[11] = "Dezembro";

var array_mes_curto = new Array();
array_mes_curto[0] = "Jan";
array_mes_curto[1] = "Fev";
array_mes_curto[2] = "Mar";
array_mes_curto[3] = "Abr";
array_mes_curto[4] = "Mai";
array_mes_curto[5] = "Jun";
array_mes_curto[6] = "Jul";
array_mes_curto[7] = "Ago";
array_mes_curto[8] = "Set";
array_mes_curto[9] = "Out";
array_mes_curto[10] = "Nov";
array_mes_curto[11] = "Dez";

/*
	Lista de funções
	----------------
*/


// Testa os diferentes tipos de browsers.
var browser = null;
if (window.navigator.userAgent.toLowerCase().indexOf("msie") != -1)
{
	browser = 'ie';
}
else if (window.navigator.userAgent.toLowerCase().indexOf("firefox") != -1)
{
	browser = 'firefox';
}
else if (window.navigator.userAgent.toLowerCase().indexOf("chrome") != -1)
{
	browser = 'chrome';
}
else if (window.navigator.userAgent.toLowerCase().indexOf("opera") != -1)
{
	browser = 'opera';
}
else if (window.navigator.userAgent.toLowerCase().indexOf("safari") != -1)
{
	browser = 'safari';
}
else if (window.navigator.userAgent.toLowerCase().indexOf("netscape") != -1)
{
	browser = 'netscape';
}

// Hacks específicos para cada tipo de browser.
switch (browser)
{
	case "ie":
	case "chrome":
	case "opera":
	case "safari":
	case "netscape":
	{
		break;
	}
	case "firefox":
	{
		HTMLElement.prototype.__defineGetter__("innerText", function()
		{
			return(this.textContent);
		});
		HTMLElement.prototype.__defineSetter__("innerText", function(texto)
		{
			this.textContent = texto;
		});
		break;
	}
}

Array.prototype.count = function(parametro)
{
	var ocorrencias = 0;
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == parametro)
		{
			ocorrencias++;
		}
	}
	return(ocorrencias);
}

Array.prototype.exists = function(parametro)
{
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == parametro)
		{
			return(true);
		}
	}
	return(false);
}

Array.prototype.index = function(parametro)
{
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == parametro)
		{
			return(i);
		}
	}
	return(-1);
}

Number.prototype.chr = function() {
	var objeto = this;
	return(String.fromCharCode(objeto));
}

Number.prototype.int = function() {
	var objeto = this;
	if (isNaN(parseInt(objeto, 10)))
	{
		return(null);
	}
	return(parseInt(objeto, 10));
}

Number.prototype.round = function(casas_decimais) {
	if (casas_decimais == null)
	{
		casas_decimais = 0;
	}
	var fator = Math.pow(10, casas_decimais);
	return(Math.round(this * fator) / fator);
}

String.prototype.asc = function() {
	var objeto = this;
	return(objeto.charCodeAt(0));
}

String.prototype.bool = function() {
	var objeto = this;
	if ((objeto.toLowerCase() == "true") || (objeto == "1"))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

String.prototype.int = function() {
	var objeto = this;
	if (isNaN(parseInt(objeto, 10)))
	{
		return(null);
	}
	return(parseInt(objeto, 10));
}

String.prototype.left = function(parametro) {
	var objeto = this;
	objeto = objeto.substr(0, parametro);
	return(objeto);
}

String.prototype.right = function(parametro) {
	var objeto = this;
	objeto = objeto.substr(objeto.length - parametro);
	return(objeto);
}

String.prototype.repeat = function(n) {
	return(new Array(n + 1).join(this));
}

String.prototype.trim = function() {
	var objeto = this;
	objeto = objeto.replace(/^\s*(.*)/, "$1");
	objeto = objeto.replace(/(.*?)\s*$/, "$1");
	return(objeto);
}

function adiciona_barra_invertida_aspas(parametro)
{
	parametro = parametro.toString();
	parametro = parametro.replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
	return(parametro);
}

function adiciona_opcao_combobox(objeto, valor, texto, titulo, posicao)
{
	if (posicao == null)
	{
		posicao = elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length");
	}
	switch (browser)
	{
		case "ie":
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		{
			var elemento = document.createElement("OPTION");
			elemento_html_altera_atributo(elemento, "value", valor);
			elemento_html_altera_atributo(elemento, "text", texto);
			if (titulo != null)
			{
				elemento_html_altera_atributo(elemento, "title", titulo);
			}
			objeto.add(elemento, posicao);
			break;
		}
		case "firefox":
		{
			elemento_html_atributo(objeto, "options")[posicao] = new Option(texto, valor);
			if (titulo != null)
			{
				elemento_html_altera_atributo(elemento_html_atributo(objeto, "options")[posicao], "title", titulo);
			}
			break;
		}
	}
}	

function adiciona_opcao_combobox_avancado()
{
	var array_parametros = arguments;
	var objeto = array_parametros[0];
	var posicao = array_parametros[1];
	if (posicao == null)
	{
		posicao = elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length");
	}
	switch (browser)
	{
		case "ie":
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		{
			var elemento = document.createElement("OPTION");
			break;
		}
		case "firefox":
		{
			var elemento = new Option();
			break;
		}
	}
	for (var i = 2; i < array_parametros.length; i += 2)
	{
		if ((i + 1) < array_parametros.length)
		{
			var atributo = array_parametros[i];
			var valor = array_parametros[i + 1];
			elemento_html_altera_atributo(elemento, atributo, valor);
		}
	}
	switch (browser)
	{
		case "ie":
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		{
			objeto.add(elemento, posicao);
			break;
		}
		case "firefox":
		{
			elemento_html_atributo(objeto, "options")[posicao] = elemento;
			break;
		}
	}
}	

function ajax_http_request()
{
	var http_request;
	try
	{
		http_request = new XMLHttpRequest(); // Mozilla, Safari, ...
	}
	catch (e)
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP"); // IE
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP"); // IE
			}
			catch (e)
			{
				http_request = false;
			}
		}
	}
	return(http_request);
}

function __atributo(atributo)
{
	switch (browser)
	{
		case "ie":
		{
			switch (atributo)
			{
				case "style":
				{
					atributo = "cssText";
					break;
				}
				case "textContent":
				{
					atributo = "innerText";
					break;
				}
			}
			break;
		}
		case "chrome":
		{
			switch (atributo)
			{
				case "className":
				{
					atributo = "class";
					break;
				}
			}
			break;
		}
		case "opera":
		{
			switch (atributo)
			{
				case "className":
				{
					atributo = "class";
					break;
				}
			}
			break;
		}
		case "safari":
		{
			switch (atributo)
			{
				case "className":
				{
					atributo = "class";
					break;
				}
			}
			break;
		}
		case "netscape":
		{
			switch (atributo)
			{
				case "className":
				{
					atributo = "class";
					break;
				}
			}
			break;
		}
		case "firefox":
		{
			switch (atributo)
			{
				case "className":
				{
					atributo = "class";
					break;
				}
				case "innerText":
				{
					atributo = "textContent";
					break;
				}
			}
			break;
		}
	}
	return(atributo);
}

function base64_decode(parametro)
{
	parametro = parametro.toString();
	var caracteres = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var retorno = "";
	var caractere1, caractere2, caractere3;
	var encode1, encode2, encode3, encode4;
	var i = 0;
	// Remove todos os caracteres que não são A-Z, a-z, 0-9, +, /, ou =.
	parametro = parametro.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	do
	{
		encode1 = caracteres.indexOf(parametro.charAt(i++));
		encode2 = caracteres.indexOf(parametro.charAt(i++));
		encode3 = caracteres.indexOf(parametro.charAt(i++));
		encode4 = caracteres.indexOf(parametro.charAt(i++));
		caractere1 = (encode1 << 2) | (encode2 >> 4);
		caractere2 = ((encode2 & 15) << 4) | (encode3 >> 2);
		caractere3 = ((encode3 & 3) << 6) | encode4;
		retorno = retorno + String.fromCharCode(caractere1);
		if (encode3 != 64)
		{
			retorno = retorno + String.fromCharCode(caractere2);
		}
		if (encode4 != 64)
		{
			retorno = retorno + String.fromCharCode(caractere3);
		}
	} while (i < parametro.length);
	return(retorno);
}

function base64_encode(parametro)
{
	parametro = parametro.toString();
	var caracteres = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var retorno = "";
	var caractere1, caractere2, caractere3;
	var encode1, encode2, encode3, encode4;
	var i = 0;
	do
	{
		caractere1 = parametro.charCodeAt(i++);
		caractere2 = parametro.charCodeAt(i++);
		caractere3 = parametro.charCodeAt(i++);
		encode1 = caractere1 >> 2;
		encode2 = ((caractere1 & 3) << 4) | (caractere2 >> 4);
		encode3 = ((caractere2 & 15) << 2) | (caractere3 >> 6);
		encode4 = caractere3 & 63;
		if (isNaN(caractere2))
		{
			encode3 = encode4 = 64;
		}
		else if (isNaN(caractere3))
		{
			encode4 = 64;
		}
		retorno = retorno + caracteres.charAt(encode1) + caracteres.charAt(encode2) + caracteres.charAt(encode3) + caracteres.charAt(encode4);
	}
	while (i < parametro.length);
	return(retorno);
}

function copia_objeto(objeto, nivel)
{
	var novo_objeto;
	if (nivel == undefined)
	{
		nivel = 0;
	}
	if (objeto == null)
	{
		novo_objeto = null;
	}
	else if ((typeof(objeto) == "object") && (objeto.length != undefined))
	{
		// Array
		novo_objeto = new Array;
		for (var i = 0; i < objeto.length; ++i)
		{
			novo_objeto[novo_objeto.length] = copia_objeto(objeto[i], nivel + 1);
		}
	}
	else if (typeof(objeto) == "object")
	{
		// Object
		novo_objeto = new Object();
		for (var i in objeto)
		{
			novo_objeto[i] = copia_objeto(objeto[i], nivel + 1);
		}
	}
	else
	{
		// Plain
		novo_objeto = objeto;
	}
	return novo_objeto;
}

function elemento_atributo(objeto, atributo)
{
	atributo = __atributo(atributo);
	switch (browser)
	{
		case "ie":
		{
			if (atributo == "length")
			{
				return(objeto.length);
			}
			else
			{
				return(objeto.getAttribute(atributo));
			}
			break;
		}
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		case "firefox":
		{
			if ((objeto.hasAttribute) && (objeto.hasAttribute(atributo)) && (atributo != "value"))
			{
				return(objeto.attributes[atributo].value);
			}
			else
			{
				return(eval("objeto." + atributo));
			}
			break;
		}
	}
}

function elemento_altera_atributo(objeto, atributo, valor)
{
	atributo = __atributo(atributo);
	switch (browser)
	{
		case "ie":
		{
			if (atributo == "length")
			{
				objeto.length = valor;
			}
			else
			{
				objeto.setAttribute(atributo, valor);
			}
			break;
		}
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		case "firefox":
		{
			if (atributo == "class")
			{
				objeto.setAttribute(atributo, valor);
			}
			else
			{
				eval("objeto." + atributo + " = valor");
			}
			break;
		}
	}
}

function elemento_html_atributo(objeto, atributo)
{
	return(elemento_atributo(objeto, atributo));
}

function elemento_html_altera_atributo(objeto, atributo, valor)
{
	elemento_altera_atributo(objeto, atributo, valor);
}

function elemento_centraliza(objeto)
{
	objeto.style.position = "absolute";
	objeto.style.top = "50%";
	objeto.style.left = "50%";
	objeto.style.marginTop = (objeto.clientHeight / 2) * -1;
	objeto.style.marginLeft = (objeto.clientWidth / 2) * -1;
}

function elemento_html_altura(objeto)
{
	return(elemento_html_posicao(objeto)).height;
}

function elemento_html_carrega_valor(objeto, valor, separador, separador2, opcao)
{
	if (valor == null)
	{
		return;
	}
	var tag, tipo, id;
	if (objeto.tagName == null)
	{
		tag = objeto[0].tagName;
		tipo = objeto[0].type;
		id = objeto[0].id;
	}
	else
	{
		tag = objeto.tagName;
		tipo = objeto.type;
	}
	if (tag != null)
	{
		tag = tag.toUpperCase();
	}
	if (tipo != null)
	{
		tipo = tipo.toUpperCase();
	}
	if (separador == null)
	{
		separador = "\x01";
	}
	if (separador2 == null)
	{
		separador2 = "\x02";
	}
	var array_valor, array_valor2;
	if (((tag == "INPUT") && ((tipo == "TEXT") || (tipo == "PASSWORD") || (tipo == "HIDDEN"))) || (tag == "TEXTAREA"))
	{
		if (id == null)
		{
			elemento_html_altera_atributo(objeto, "value", valor);
		}
		else
		{
			array_valor = valor.split(separador);
			for (var i = 0; i < array_valor.length; i++)
			{
				elemento_html_altera_atributo(objeto[i], "value", array_valor[i]);
			}
		}
	}
	else
	{
		if (valor.length == 0)
		{
			return;
		}
	}
	if (tag == "SELECT")
	{
		if (id == null)
		{
			if (!objeto.multiple)
			{
				for (var i = 0; i < elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length"); i++)
				{
					if (elemento_html_atributo(elemento_html_atributo(objeto, "options")[i], "value") == valor)
					{
						elemento_html_altera_atributo(objeto, "selectedIndex", i);
						elemento_html_altera_atributo(objeto, "title", elemento_html_atributo(elemento_html_atributo(objeto, "options")[i], "title"));
						break;
					}
				}
			}
			else
			{
				array_valor = valor.split(separador);
				for (var i = 0; i < array_valor.length; i++)
				{
					out2:
					for (var j = 0; j < elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length"); j++)
					{
						if (elemento_html_atributo(elemento_html_atributo(objeto, "options")[j], "value") == array_valor[i])
						{
							elemento_html_altera_atributo(elemento_html_atributo(objeto, "options")[j], "selected", true);
							break out2;
						}
					}
				}
			}
		}
		else
		{
			if (!objeto[0].multiple)
			{
				array_valor = valor.split(separador);
				for (var i = 0; i < array_valor.length; i++)
				{
					out1:
					for (var j = 0; j < elemento_html_atributo(elemento_html_atributo(objeto[i], "options"), "length"); j++)
					{
						if (elemento_html_atributo(elemento_html_atributo(objeto[i], "options")[j], "value") == array_valor[i])
						{
							elemento_html_altera_atributo(objeto[i], "selectedIndex", j);
							elemento_html_altera_atributo(objeto[i], "title", elemento_html_atributo(elemento_html_atributo(objeto[i], "options")[j], "title"));
							break out1;
						}
					}
				}
			}
			else
			{
				array_valor = valor.split(separador2);
				for (var h = 0; h < array_valor.length; h++)
				{
					array_valor2 = array_valor[h].split(separador);
					for (var i = 0; i < array_valor2.length; i++)
					{
						out3:
						for (var j = 0; j < elemento_html_atributo(elemento_html_atributo(objeto[h], "options"), "length"); j++)
						{
							if (elemento_html_atributo(elemento_html_atributo(objeto[h], "options")[j], "value") == array_valor2[i])
							{
								elemento_html_altera_atributo(elemento_html_atributo(elemento_html_atributo(objeto[h], "options")[j], "selected", true));
								break out3;
							}
						}
					}
				}
			}
		}
	}
	if ((tag == "INPUT") && ((tipo == "RADIO") || (tipo == "CHECKBOX")))
	{
		if (id == null)
		{
			if (elemento_html_atributo(objeto, "value") == valor)
			{
				elemento_html_altera_atributo(objeto, "checked", true);
				if (tipo == "RADIO")
				{
					// Esta linha é necessária, pois no IE, o OPTION dinâmico perde seu valor ao movermos as linhas da tabela para cima ou para baixo.
					elemento_html_altera_atributo(objeto, "defaultChecked", true);
				}
			}
		}
		else
		{
			array_valor = valor.split(separador);
			if (opcao == null) // valores diferentes para cada radio button ou checkbox.
			{
				for (var i = 0; i < array_valor.length; i++)
				{
					out4:
					for (var j = 0; j < elemento_html_atributo(objeto, "length"); j++)
					{
						if (elemento_html_atributo(objeto[j], "value") == array_valor[i])
						{
							elemento_html_altera_atributo(objeto[j], "checked", true);
							if (tipo == "RADIO")
							{
								// Esta linha é necessária, pois no IE, o OPTION dinâmico perde seu valor ao movermos as linhas da tabela para cima ou para baixo.
								elemento_html_altera_atributo(objeto[j], "defaultChecked", false);
							}
							break out4;
						}
					}
				}
			}
			else // valores iguais para cada radio button ou checkbox.
			{
				for (var i = 0; i < array_valor.length; i++)
				{
					if (elemento_html_atributo(objeto[i], "value") == array_valor[i])
					{
						elemento_html_altera_atributo(objeto[i], "checked", true);
					}
				}
			}
		}
	}
}

function elemento_html_estilo(objeto, atributo)
{
	var estilo = "";
	if ((document.defaultView) && (document.defaultView.getComputedStyle))
	{
		estilo = document.defaultView.getComputedStyle(objeto, null).getPropertyValue(atributo);
	}
	else if (objeto.currentStyle)
	{
		atributo = atributo.replace(/-(\w)/g, function(ocorrencia, parametro) { return parametro.toUpperCase(); });
		estilo = objeto.currentStyle[atributo];
	}
	return(estilo);
}

function elemento_html_id(objeto, id)
{
	return(document.getElementById(id));
}

function elemento_html_foco(objeto, seleciona)
{
	var tag, tipo, id;
	if (objeto.tagName == null)
	{
		tag = objeto[0].tagName;
		tipo = objeto[0].type;
		id = objeto[0].id;
	}
	else
	{
		tag = objeto.tagName;
		tipo = objeto.type;
	}
	if (tag != null)
	{
		tag = tag.toUpperCase();
	}
	if (tipo != null)
	{
		tipo = tipo.toUpperCase();
	}
	if (id == null)
	{
		objeto.focus();
		if (seleciona != null)
		{
			elemento_html_seleciona(objeto);
		}
	}
	else
	{
		objeto[0].focus();
		if (seleciona != null)
		{
			elemento_html_seleciona(objeto[0]);
		}
	}
}

function elemento_html_indice(objeto)
{
	if (objeto.tagName == null)
	{
		var id = objeto[0].id;
		var nome = objeto[0].name;
	}
	else
	{
		var id = objeto.id;
		var nome = objeto.name;
	}
	if (nome == null)
	{
		var array_objeto = get_elements_by_id(id);
	}
	else
	{
		var array_objeto = document.getElementsByName(nome);
	}
	for (var i = 0; i < array_objeto.length; i++)
	{
		if (array_objeto[i] == objeto)
		{
			return(i);
		}
	}
	return(null);
}

function elemento_html_largura(objeto)
{
	return(elemento_html_posicao(objeto)).width;
}

function elemento_html_nome(objeto, nome)
{
	return(document.getElementsByName(nome));
}

function elemento_html_onkeydown_tecla_enter(e, objeto, alvo)
{
	var e = e || window.event;
	var codigo_tecla = e.keyCode || e.which;
	if (codigo_tecla == 13)
	{
		switch (browser)
		{
			case "ie":
			case "chrome":
			case "opera":
			case "safari":
			case "netscape":
			{
				e.returnValue = false;
				e.cancelBubble = true;
				break;
			}
			case "firefox":
			{
				e.preventDefault();
				e.stopPropagation();
				break;
			}
		}
		if (typeof(alvo) == "function")
		{
			alvo();
		}
		else if (typeof(alvo) == "string")
		{
			eval(alvo);
		}
		else if (typeof(alvo) == "object")
		{
			elemento_html_foco(alvo, true);
		}
	}
}

function elemento_html_onkeypress_filtra_tecla(e, objeto, er)
{
	var e = e || window.event;
	var codigo_tecla = e.keyCode || e.which;
	switch (browser)
	{
		case "ie":
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		{
			var caractere = String.fromCharCode(codigo_tecla);
			break;
		}
		case "firefox":
		{
			var codigo_caractere = e.charCode;
			if (codigo_caractere == 0)
			{
				return;
			}
			var caractere = String.fromCharCode(codigo_caractere);
			break;
		}
	}
	if (typeof(er) == "string")
	{
		er = new RegExp(er);
	}
	if (!er.test(caractere))
	{
		switch (browser)
		{
			case "ie":
			case "chrome":
			case "opera":
			case "safari":
			case "netscape":
			{
				e.returnValue = false;
				e.cancelBubble = true;
				break;
			}
			case "firefox":
			{
				e.preventDefault();
				e.stopPropagation();
				break;
			}
		}
	}
}

function elemento_html_onkeypress_caixa_alta(e, objeto)
{
	var e = e || window.event;
	var codigo_tecla = e.keyCode || e.which;
	var caractere = String.fromCharCode(codigo_tecla);
	switch (browser)
	{
		case "ie":
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		{
			e.returnValue = false;
			e.cancelBubble = true;
			var selecao = document.selection.createRange();
			var selecao2 = selecao.duplicate();
			if (objeto.tagName == "TEXTAREA")
			{
				selecao2.moveToElementText(objeto);
			}
			else
			{
				selecao2.expand('textedit');
			}
			selecao2.setEndPoint('EndToEnd', selecao);
			posicao_cursor = selecao2.text.length;
			elemento_html_altera_atributo(objeto, "value", (elemento_html_atributo(objeto, "value").substr(0, posicao_cursor) + caractere.toUpperCase() + elemento_html_atributo(objeto, "value").substr(posicao_cursor)));
			var selecao = objeto.createTextRange();
			selecao.collapse(true);
			selecao.moveEnd('character', posicao_cursor + 1);
			selecao.moveStart('character', posicao_cursor + 1);
			selecao.select();
			break;
		}
		case "firefox":
		{
			e.preventDefault();
			e.stopPropagation();
			var posicao_cursor = objeto.selectionStart;
			elemento_html_altera_atributo(objeto, "value", (elemento_html_atributo(objeto, "value").substr(0, posicao_cursor) + caractere.toUpperCase() + elemento_html_atributo(objeto, "value").substr(posicao_cursor)));
			objeto.setSelectionRange(posicao_cursor + 1, posicao_cursor + 1);
			break;
		}
	}
}

function elemento_html_posicao(elemento)
{
	var coordenadas = {
		left: 0,
		top: 0,
		width: elemento.offsetWidth,
		height: elemento.offsetHeight,
		bottom: 0
	};
	while (elemento)
	{
		coordenadas.left += ((elemento.offsetLeft == null) ? 0 : elemento.offsetLeft);
		coordenadas.top += ((elemento.offsetTop == null) ? 0 : elemento.offsetTop);
		elemento = elemento.parentNode;
	}
	coordenadas.bottom = coordenadas.top + coordenadas.height;
	return(coordenadas);
}

function elemento_html_posicao_x(objeto)
{
	return(elemento_html_posicao(objeto)).left;
}

function elemento_html_posicao_y(objeto, origem)
{
	return(elemento_html_posicao(objeto)).top;
}

function elemento_html_seleciona(objeto)
{
	var tag, tipo, id;
	if (objeto.tagName == null)
	{
		tag = objeto[0].tagName;
		tipo = objeto[0].type;
		id = objeto[0].id;
	}
	else
	{
		tag = objeto.tagName;
		tipo = objeto.type;
	}
	if (tag != null)
	{
		tag = tag.toUpperCase();
	}
	if (tipo != null)
	{
		tipo = tipo.toUpperCase();
	}
	if (((tag == "INPUT") && ((tipo == "TEXT") || (tipo == "PASSWORD"))) || (tag == "TEXTAREA"))
	{
		switch (browser)
		{
			case "ie":
			case "opera":
			case "safari":
			case "netscape":
			{
				var selecao = objeto.createTextRange();
				selecao.collapse(true);
				selecao.moveEnd('character', elemento_html_valor(objeto).length);
				selecao.moveStart('character', 0);
				selecao.select();
				break;
			}
			case "firefox":
			case "chrome":
			{
				objeto.setSelectionRange(0, elemento_html_valor(objeto).length);
				break;
			}
		}
	}
}

function elemento_html_tag(objeto, tag)
{
	return(document.getElementsByTagName(tag));
}

function elemento_html_tamanho(objeto, nome, comparacao, tamanho)
{
	var parametro = elemento_html_valor(objeto);
	switch (comparacao)
	{
		case "=":
		case "==":
		{
			if (parametro.length == tamanho)
			{
				alert("O campo '" + nome + "' não pode ter " + tamanho + " caracteres.");
				elemento_html_foco(objeto, true);
				return(true);
			}
			break;
		}
		case "!=":
		case "<>":
		{
			if (parametro.length != tamanho)
			{
				alert("O campo '" + nome + "' deve ter exatamente " + tamanho + " caracteres.");
				elemento_html_foco(objeto, true);
				return(true);
			}
			break;
		}
		case "<":
		{
			if (parametro.length < tamanho)
			{
				alert("O campo '" + nome + "' deve ter no mínimo " + tamanho + " caracteres.");
				elemento_html_foco(objeto, true);
				return(true);
			}
			break;
		}
		case "<=":
		{
			if (parametro.length <= tamanho)
			{
				alert("O campo '" + nome + "' deve ter no mínimo " + (tamanho + 1) + " caracteres.");
				elemento_html_foco(objeto, true);
				return(true);
			}
			break;
		}
		case ">":
		{
			if (parametro.length > tamanho)
			{
				alert("O campo '" + nome + "' deve ter no máximo " + tamanho + " caracteres.");
				elemento_html_foco(objeto, true);
				return(true);
			}
			break;
		}
		case ">=":
		{
			if (parametro.length >= tamanho)
			{
				alert("O campo '" + nome + "' deve ter no máximo " + (tamanho - 1) + " caracteres.");
				elemento_html_foco(objeto, true);
				return(true);
			}
			break;
		}
	}
	return(false);
}

function elemento_html_valida(objeto, nome, condicao)
{
	if (!condicao)
	{
		if (nome != null)
		{
			elemento_html_foco(objeto, true);
			alert("O campo '" + nome + "' não é válido.");
		}
	}
	return(condicao);
}

function elemento_html_valor(objeto, atributo, separador, separador2)
{
	var tag, tipo, id;
	if (objeto.tagName == null)
	{
		tag = objeto[0].tagName;
		tipo = objeto[0].type;
		id = objeto[0].id;
	}
	else
	{
		tag = objeto.tagName;
		tipo = objeto.type;
	}
	if (tag != null)
	{
		tag = tag.toUpperCase();
	}
	if (tipo != null)
	{
		tipo = tipo.toUpperCase();
	}
	if (atributo == null)
	{
		atributo = "value";
	}
	if (separador == null)
	{
		separador = "\x01";
	}
	if (separador2 == null)
	{
		separador2 = "\x02";
	}
	var array_valor, array_valor2, valor;
	if (((tag == "INPUT") && ((tipo == "TEXT") || (tipo == "PASSWORD") || (tipo == "FILE") || (tipo == "HIDDEN"))) || (tag == "TEXTAREA"))
	{
		if (id == null)
		{
			valor = elemento_html_atributo(objeto, atributo);
		}
		else
		{
			array_valor = new Array();
			for (var i = 0; i < elemento_html_atributo(objeto, "length"); i++)
			{
				array_valor.push(elemento_html_atributo(objeto[i], atributo));
			}
			valor = array_valor.join(separador);
		}
	}
	if (tag == "SELECT")
	{
		if (id == null)
		{
			if (!objeto.multiple)
			{
				if (elemento_html_atributo(objeto, "selectedIndex") >= 0)
				{
					valor = elemento_html_atributo(elemento_html_atributo(objeto, "options")[elemento_html_atributo(objeto, "selectedIndex")], atributo);
				}
			}
			else
			{
				array_valor = new Array();
				for (var i = 0; i < elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length"); i++)
				{
					if (elemento_html_atributo(elemento_html_atributo(objeto, "options")[i], "selected"))
					{
						array_valor.push(elemento_html_atributo(elemento_html_atributo(objeto, "options")[i], atributo));
					}
				}
				valor = array_valor.join(separador);
			}
		}
		else
		{
			if (!objeto[0].multiple)
			{
				array_valor = new Array();
				for (var i = 0; i < get_elements_by_id(id).length; i++)
				{
					if (elemento_html_atributo(objeto[i], "selectedIndex") < 0)
					{
						array_valor.push(null);
					}
					else
					{
						array_valor.push(elemento_html_atributo(elemento_html_atributo(objeto, "options")[i], atributo));
					}
				}
				valor = array_valor.join(separador);
			}
			else
			{
				array_valor = new Array();
				for (var i = 0; i < get_elements_by_id(id).length; i++)
				{
					array_valor2 = new Array();
					for (var j = 0; j < elemento_html_atributo(elemento_html_atributo(objeto[i], "options"), "length"); j++)
					{
						if (elemento_html_atributo(elemento_html_atributo(objeto[i], "options")[j], "selected"))
						{
							array_valor2.push(elemento_html_atributo(elemento_html_atributo(objeto[i], "options")[j], atributo));
						}
					}
					array_valor.push(array_valor2.join(separador2));
				}
				valor = array_valor.join(separador);
			}
		}
	}
	if ((tag == "INPUT") && ((tipo == "RADIO") || (tipo == "CHECKBOX")))
	{
		if (id == null)
		{
			if (elemento_html_atributo(objeto, "checked"))
			{
				valor = elemento_html_atributo(objeto, atributo);
			}
		}
		else
		{
			array_valor = new Array();
			for (var i = 0; i < elemento_html_atributo(objeto, "length"); i++)
			{
				if (elemento_html_atributo(objeto[i], "checked"))
				{
					array_valor.push(elemento_html_atributo(objeto[i], atributo));
				}
			}
			valor = array_valor.join(separador);
		}
	}
	return(valor);
}

function elemento_html_vazio(objeto, nome)
{
	var tag, tipo, id;
	if (objeto.tagName == null)
	{
		tag = objeto[0].tagName;
		tipo = objeto[0].type;
		id = objeto[0].id;
	}
	else
	{
		tag = objeto.tagName;
		tipo = objeto.type;
	}
	if (tag != null)
	{
		tag = tag.toUpperCase();
	}
	if (tipo != null)
	{
		tipo = tipo.toUpperCase();
	}
	var vazio = false;
	if (((tag == "INPUT") && ((tipo == "TEXT") || (tipo == "PASSWORD") || (tipo == "FILE") || (tipo == "HIDDEN"))) || (tag == "TEXTAREA"))
	{
		if (id == null)
		{
			if (elemento_html_atributo(objeto, "value").toString().trim() == "")
			{
				vazio = true;
			}
		}
		else
		{
			var marcado = false;
			for (var i = 0; i < objeto.length; i++)
			{
				if (elemento_html_atributo(objeto[i], "value").toString().trim() != "")
				{
					marcado = true;
					break;
				}
			}
			if (!marcado)
			{
				vazio = true;
			}
		}
	}
	if (tag == "SELECT")
	{
		if (id == null)
		{
			if (!objeto.multiple)
			{
				if (elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length") == 0)
				{
					vazio = true;
				}
				else if (elemento_html_atributo(elemento_html_atributo(objeto, "options")[0], "value") == "")
				{
					if (elemento_html_atributo(objeto, "selectedIndex") == 0)
					{
						vazio = true;
					}
				}
				else
				{
					if (elemento_html_atributo(objeto, "selectedIndex") < 0)
					{
						vazio = true;
					}
				}
			}
			else
			{
				var marcado = false;
				for (var i = 0; i < elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length"); i++)
				{
					if (elemento_html_atributo(elemento_html_atributo(objeto, "options")[i], "selected"))
					{
						marcado = true;
						break;
					}
				}
				if (!marcado)
				{
					vazio = true;
				}
			}
		}
		else
		{
			if (!objeto[0].multiple)
			{
				var marcado = false;
				for (var i = 0; i < get_elements_by_id(id).length; i++)
				{
					if (elemento_html_atributo(elemento_html_atributo(objeto[i], "options"), "length") > 0)
					{
						if (elemento_html_atributo(elemento_html_atributo(objeto[i], "options")[0], "value") == "")
						{
							if (elemento_html_atributo(objeto[i], "selectedIndex") > 0)
							{
								marcado = true;
								break;
							}
						}
						else
						{
							if (elemento_html_atributo(objeto[i], "selectedIndex") >= 0)
							{
								marcado = true;
								break;
							}
						}
					}
				}
				if (!marcado)
				{
					vazio = true;
				}
			}
			else
			{
				var marcado = false;
				for (var i = 0; i < get_elements_by_id(id).length; i++)
				{
					for (var j = 0; j < elemento_html_atributo(elemento_html_atributo(objeto[i], "options"), "length"); j++)
					{
						if (elemento_html_atributo(elemento_html_atributo(objeto[i], "options")[j], "selected"))
						{
							marcado = true;
							break;
						}
					}
				}
				if (!marcado)
				{
					vazio = true;
				}
			}
		}
	}
	if ((tag == "INPUT") && ((tipo == "RADIO") || (tipo == "CHECKBOX")))
	{
		if (id == null)
		{
			if (!elemento_html_atributo(objeto, "checked"))
			{
				vazio = true;
			}
		}
		else
		{
			var marcado = false;
			for (var i = 0; i < objeto.length; i++)
			{
				if (elemento_html_atributo(objeto[i], "checked"))
				{
					marcado = true;
					break;
				}
			}
			if (!marcado)
			{
				vazio = true;
			}
		}
	}
	if (vazio)
	{
		if (nome != null)
		{
			elemento_html_foco(objeto, true);
			alert("O campo '" + nome + "' é obrigatório.");
		}
	}
	return(vazio);
}

function elemento_html_zera_valor(objeto)
{
	var tag, tipo, id;
	if (objeto.tagName == null)
	{
		tag = objeto[0].tagName;
		tipo = objeto[0].type;
		id = objeto[0].id;
	}
	else
	{
		tag = objeto.tagName;
		tipo = objeto.type;
	}
	if (tag != null)
	{
		tag = tag.toUpperCase();
	}
	if (tipo != null)
	{
		tipo = tipo.toUpperCase();
	}
	if (((tag == "INPUT") && ((tipo == "TEXT") || (tipo == "PASSWORD") || (tipo == "HIDDEN"))) || (tag == "TEXTAREA"))
	{
		if (id == null)
		{
			elemento_html_altera_atributo(objeto, "value", "");
		}
		else
		{
			for (var i = 0; i < objeto.length; i++)
			{
				elemento_html_altera_atributo(objeto[i], "value", "");
			}
		}
	}
	if (tag == "SELECT")
	{
		if (id == null)
		{
			if (!objeto.multiple)
			{
				if ((elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length") > 0) && (elemento_html_atributo(elemento_html_atributo(objeto, "options")[0], "text") == "") && (elemento_html_atributo(elemento_html_atributo(objeto, "options")[0], "value") == ""))
				{
					elemento_html_altera_atributo(objeto, "selectedIndex", 0);
				}
				else
				{
					elemento_html_altera_atributo(objeto, "selectedIndex", -1);
				}
			}
			else
			{
				for (var i = 0; i < elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length"); i++)
				{
					elemento_html_altera_atributo(elemento_html_atributo(objeto, "options")[i], "selected", false);
				}
			}
		}
		else
		{
			if (!objeto[0].multiple)
			{
				for (var i = 0; i < get_elements_by_id(id).length; i++)
				{
					if ((elemento_html_atributo(elemento_html_atributo(objeto[i], "options"), "length") > 0) && (elemento_html_atributo(elemento_html_atributo(objeto[i], "options")[0], "text") == "") && (elemento_html_atributo(elemento_html_atributo(objeto[i], "options")[0], "value") == ""))
					{
						elemento_html_altera_atributo(objeto[i], "selectedIndex", 0);
					}
					else
					{
						elemento_html_altera_atributo(objeto[i], "selectedIndex", -1);
					}
				}
			}
			else
			{
				for (var i = 0; i < get_elements_by_id(id).length; i++)
				{
					for (var j = 0; j < elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length"); j++)
					{
						elemento_html_altera_atributo(elemento_html_atributo(objeto[i], "options")[j], "selected", false);
					}
				}
			}
		}
	}
	if ((tag == "INPUT") && ((tipo == "RADIO") || (tipo == "CHECKBOX")))
	{
		if (id == null)
		{
			elemento_html_altera_atributo(objeto, "checked", false);
			if (tipo == "RADIO")
			{
				// Esta linha é necessária, pois no IE, o OPTION dinâmico perde seu valor ao movermos as linhas da tabela para cima ou para baixo.
				elemento_html_altera_atributo(objeto, "defaultChecked", false);
			}
		}
		else
		{
			for (var i = 0; i < elemento_html_atributo(objeto, "length"); i++)
			{
				elemento_html_altera_atributo(objeto[i], "checked", false);
				if (tipo == "RADIO")
				{
					// Esta linha é necessária, pois no IE, o OPTION dinâmico perde seu valor ao movermos as linhas da tabela para cima ou para baixo.
					elemento_html_altera_atributo(objeto[i], "defaultChecked", false);
				}
			}
		}
	}
}

function elemento_xml_atributo(elemento, atributo)
{
	return(xml_decode(elemento.getAttribute(atributo)));
}

function elemento_xml_valor(elemento)
{
	if ((elemento.hasChildNodes()) && (elemento.childNodes.length == 1))
	{
		return(xml_decode(elemento.firstChild.nodeValue));
	}
	else
	{
		return(xml_decode(""));
	}
}

function php_escape_aspas_simples(parametro)
{
	if (parametro == null)
	{
		return(parametro);
	}
	parametro = parametro.toString();
	return(parametro.replace(/'/g, "\\'"));
}

function php_escape_aspas_duplas(parametro)
{
	if (parametro == null)
	{
		return(parametro);
	}
	parametro = parametro.toString();
	return(parametro.replace(/"/g, "\\\""));
}

function formata_nome_arquivo(parametro)
{
	parametro = parametro.toString();
	var er = /[^0-9a-zA-Z_]/g;
	parametro = parametro.replace(er, "_");
	var er = /_{2,}/;
	while (parametro.indexOf("__") != -1)
	{
		parametro = parametro.replace(er, "_");
	}
	parametro = parametro.toLowerCase();
	return(parametro);
}

function formata_nome_pasta(parametro)
{
	parametro = parametro.toString();
	var er = /[^0-9a-zA-Z_]/g;
	parametro = parametro.replace(er, "_");
	var er = /_{2,}/;
	while (parametro.indexOf("__") != -1)
	{
		parametro = parametro.replace(er, "_");
	}
	parametro = parametro.toLowerCase();
	return(parametro);
}

function formulario_onsubmit(e, objeto)
{
	var e = e || window.event;
	switch (browser)
	{
		case "ie":
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		{
			e.returnValue = false;
			e.cancelBubble = true;
			break;
		}
		case "firefox":
		{
			e.preventDefault();
			e.stopPropagation();
			break;
		}
	}
}

function get_bounding_client_rect(elemento)
{
	var coordenadas = {
		left: 0,
		top: 0,
		width: elemento.offsetWidth,
		height: elemento.offsetHeight,
		bottom: 0
	};
	while (elemento)
	{
		coordenadas.left += ((elemento.offsetLeft == null) ? 0 : elemento.offsetLeft);
		coordenadas.top += ((elemento.offsetTop == null) ? 0 : elemento.offsetTop);
		elemento = elemento.offsetParent; // O menu funciona dessa forma, mas esta não é a maneira correta de determinar a posição absoluta do elemento na tela.
//		elemento = elemento.parentNode;
	}
	coordenadas.bottom = coordenadas.top + coordenadas.height;
	return(coordenadas);
}

function get_elements_by_id(parametro)
{
	// Esta função pode apresentar problemas de lentidão em sites com muitos elementos HTML.
	parametro = parametro.toString();
	var array_elementos = new Array();
	var objeto = document.getElementById(parametro);
	if (objeto != null)
	{
		var tag, nome;
		if (objeto.tagName == null)
		{
			tag = objeto[0].tagName;
			nome = objeto[0].name;
		}
		else
		{
			tag = objeto.tagName;
			nome = objeto.name;
		}
		if (tag != null)
		{
			tag = tag.toUpperCase();
		}
		if (((tag == "INPUT") || (tag == "SELECT") || (tag == "TEXTAREA")) && (nome.length > 0))
		{
			var array_elementos = document.getElementsByName(parametro);
		}
		else
		{
			var elementos = document.getElementsByTagName(tag);
			var array_elementos = new Array();
			for (var i = 0; i < elementos.length; i++)
			{
				if ((elementos[i].id != null) && (elementos[i].id == parametro))
				{
					array_elementos.push(elementos[i]);
				}
			}
		}
	}
	return(array_elementos);
}

function html_decode(parametro)
{
	parametro = parametro.toString();
	/* Solução elegante, porém, incompleta.
	var elemento = document.createElement("textarea");
	elemento.innerHTML = parametro.replace(/</g, "&lt;").replace(/>/g, "&gt;");
	parametro = elemento.value;
	elemento = null;
	parametro = parametro.replace(/"/g, "&quot;");
	return(parametro);
	*/

	// Solução por "força bruta".
	var valores = new Array("&amp;", "&nbsp;", "&iexcl;", "&cent;", "&pound;", "&curren;", "&yen;", "&brvbar;", "&sect;", "&uml;", "&copy;", "&ordf;", "&laquo;", "&not;", "&shy;", "&reg;", "&macr;", "&deg;", "&plusmn;", "&sup2;", "&sup3;", "&acute;", "&micro;", "&para;", "&middot;", "&cedil;", "&sup1;", "&ordm;", "&raquo;", "&frac14;", "&frac12;", "&frac34;", "&iquest;", "&Agrave;", "&Aacute;", "&Acirc;", "&Atilde;", "&Auml;", "&Aring;", "&AElig;", "&Ccedil;", "&Egrave;", "&Eacute;", "&Ecirc;", "&Euml;", "&Igrave;", "&Iacute;", "&Icirc;", "&Iuml;", "&ETH;", "&Ntilde;", "&Ograve;", "&Oacute;", "&Ocirc;", "&Otilde;", "&Ouml;", "&times;", "&Oslash;", "&Ugrave;", "&Uacute;", "&Ucirc;", "&Uuml;", "&Yacute;", "&THORN;", "&szlig;", "&agrave;", "&aacute;", "&acirc;", "&atilde;", "&auml;", "&aring;", "&aelig;", "&ccedil;", "&egrave;", "&eacute;", "&ecirc;", "&euml;", "&igrave;", "&iacute;", "&icirc;", "&iuml;", "&eth;", "&ntilde;", "&ograve;", "&oacute;", "&ocirc;", "&otilde;", "&ouml;", "&divide;", "&oslash;", "&ugrave;", "&uacute;", "&ucirc;", "&uuml;", "&yacute;", "&thorn;", "&yuml;", "&quot;", "&lt;", "&gt;", "");
	var caracteres = new Array("&", " ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "­", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "\"", "<", ">", "");
	for (var i = 0; i < valores.length; i++)
	{
		if (valores[i] != "&nbsp;")
		{
			var er = new RegExp(valores[i], "g");
			parametro = parametro.replace(er, caracteres[i]);
		}
	}
	return(parametro);
}

function html_encode(parametro)
{
	parametro = parametro.toString();
	/* Solução elegante, porém, incompleta.
	var elemento = document.createElement("div");
	elemento.innerText = parametro;
	parametro = elemento.innerHTML;
	elemento = null;
	return(parametro);
	*/

	// Solução por "força bruta".
	var caracteres = new Array("&", " ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "­", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "\"", "<", ">", "");
	var valores = new Array("&amp;", "&nbsp;", "&iexcl;", "&cent;", "&pound;", "&curren;", "&yen;", "&brvbar;", "&sect;", "&uml;", "&copy;", "&ordf;", "&laquo;", "&not;", "&shy;", "&reg;", "&macr;", "&deg;", "&plusmn;", "&sup2;", "&sup3;", "&acute;", "&micro;", "&para;", "&middot;", "&cedil;", "&sup1;", "&ordm;", "&raquo;", "&frac14;", "&frac12;", "&frac34;", "&iquest;", "&Agrave;", "&Aacute;", "&Acirc;", "&Atilde;", "&Auml;", "&Aring;", "&AElig;", "&Ccedil;", "&Egrave;", "&Eacute;", "&Ecirc;", "&Euml;", "&Igrave;", "&Iacute;", "&Icirc;", "&Iuml;", "&ETH;", "&Ntilde;", "&Ograve;", "&Oacute;", "&Ocirc;", "&Otilde;", "&Ouml;", "&times;", "&Oslash;", "&Ugrave;", "&Uacute;", "&Ucirc;", "&Uuml;", "&Yacute;", "&THORN;", "&szlig;", "&agrave;", "&aacute;", "&acirc;", "&atilde;", "&auml;", "&aring;", "&aelig;", "&ccedil;", "&egrave;", "&eacute;", "&ecirc;", "&euml;", "&igrave;", "&iacute;", "&icirc;", "&iuml;", "&eth;", "&ntilde;", "&ograve;", "&oacute;", "&ocirc;", "&otilde;", "&ouml;", "&divide;", "&oslash;", "&ugrave;", "&uacute;", "&ucirc;", "&uuml;", "&yacute;", "&thorn;", "&yuml;", "&quot;", "&lt;", "&gt;", "");
	for (var i = 0; i < caracteres.length; i++)
	{
		if (caracteres[i] != " ")
		{
			var er = new RegExp(caracteres[i], "g");
			parametro = parametro.replace(er, valores[i]);
		}
	}
	return(parametro);
}

function preenche_combobox_lista_valores(elemento, lista_valores, separador)
{
	if (separador == null)
	{
		separador = "\x01";
	}
	adiciona_opcao_combobox(elemento, "", "");
	var valor, texto;
	var array_valor = lista_valores.split(separador);
	for (var i = 0; i < array_valor.length; i += 2)
	{
		valor = array_valor[i].trim();
		if (((valor.substr(0, 1) == "'") && (valor.substr(valor.length - 1, 1) == "'")) || ((valor.substr(0, 1) == "\"") && (valor.substr(valor.length - 1, 1) == "\"")))
		{
			valor = valor.substr(1, valor.length - 2);
		}
		texto = array_valor[i + 1].trim();
		if (((texto.substr(0, 1) == "'") && (texto.substr(texto.length - 1, 1) == "'")) || ((texto.substr(0, 1) == "\"") && (texto.substr(texto.length - 1, 1) == "\"")))
		{
			texto = texto.substr(1, texto.length - 2);
		}
		adiciona_opcao_combobox(elemento, valor, texto);
	}
}

function remove_barra_invertida_aspas(parametro)
{
	parametro = parametro.toString();
	parametro = parametro.replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
	return(parametro);
}

function tabela_exclui_linha(elemento)
{
	while ((elemento.parentNode) && (elemento.nodeName.toLowerCase() != "tr"))
	{
		elemento = elemento.parentNode;
	}
	var posicao = elemento.rowIndex; // A tabela possui uma linha de cabeçalho.
	while ((elemento.parentNode) && (elemento.nodeName.toLowerCase() != "table"))
	{
		elemento = elemento.parentNode;
	}
	elemento.deleteRow(posicao);
}

function tabela_move_linha(elemento, deslocamento, linhas_cabecalho, linhas_rodape)
{
	if (deslocamento == 0)
	{
		return;
	}
	while ((elemento.parentNode) && (elemento.nodeName.toLowerCase() != "tr"))
	{
		elemento = elemento.parentNode;
	}
	var elemento_pai = elemento.parentNode;
	var i = elemento.rowIndex;
	if (deslocamento < 0)
	{
		while (deslocamento < 0)
		{
			i--;
			if (i < linhas_cabecalho)
			{
				i = elemento_pai.rows.length - (linhas_rodape + 1);
			}
			deslocamento++;
		}
	}
	else if (deslocamento > 0)
	{
		while (deslocamento > 0)
		{
			i++;
			if (i == (elemento_pai.rows.length - linhas_rodape))
			{
				i = linhas_cabecalho;
			}
			deslocamento--;
		}
	}
	elemento_pai.removeChild(elemento);
	var linha = elemento_pai.insertRow(i);
	elemento_pai.replaceChild(elemento, linha);
}

function url_decode(parametro)
{
	parametro = parametro.toString();
	parametro = parametro.replace(/\+/g, " ");
	parametro = unescape(parametro);
	return(parametro);
}

function url_encode(parametro)
{
	parametro = parametro.toString();
	parametro = parametro.replace(/\+/g, "%2B");
	parametro = escape(parametro);
	return(parametro);
}

function xml_ajax_combobox(url, parametros, metodo, modo, objeto, valor_padrao, funcao)
{
	if ((xml_ajax_combobox.depurar != null) && (xml_ajax_combobox.depurar))
	{
		window.open(url + ((parametros == null) ? "" : "?" + parametros));
	}
	var primeiro_elemento_vazio = false;
	if (elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length") > 0)
	{
		if (elemento_html_atributo(elemento_html_atributo(objeto, "options")[0], "value") == "")
		{
			primeiro_elemento_vazio = true;
			var primeiro_elemento = elemento_html_atributo(objeto, "options")[0];
		}
		elemento_html_altera_atributo(elemento_html_atributo(objeto, "options"), "length", 0);
	}
	var elemento = document.createElement("OPTION");
	elemento_html_altera_atributo(elemento, "value", "Carregando...");
	elemento_html_altera_atributo(elemento, "text", "Carregando...");
	elemento_html_atributo(objeto, "options").add(elemento);
	var http_request = ajax_http_request();
	if (http_request)
	{
		metodo = metodo.toUpperCase();
		switch (metodo)
		{
			case "GET":
			{
				http_request.open("GET", url + ((parametros == null) ? "" : "?" + parametros), modo);
				break;
			}
			case "POST":
			{
				http_request.open("POST", url, modo);
				break;
			}
			default:
			{
				return;
			}
		}
		if (modo)
		{
			http_request.onreadystatechange = function()
			{
				if (http_request.readyState == 4)
				{
					if (http_request.status == 200)
					{
						var objeto_xml = http_request.responseXML;
						if (xml_converte_texto(objeto_xml) != "")
						{
							elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length") = 0;
							if (primeiro_elemento_vazio)
							{
								elemento_html_atributo(objeto, "options").add(primeiro_elemento);
							}
							xml_carrega_elemento_html(objeto_xml, objeto, valor_padrao);
							if (funcao != null)
							{
								if (typeof(funcao) == "function")
								{
									funcao();
								}
								else if (typeof(funcao) == "string")
								{
									eval(funcao);
								}
							}
						}
					}
				}
			}
		}
		if (metodo == "GET")
		{
			http_request.send(null);
		}
		else if (metodo == "POST")
		{
			http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http_request.setRequestHeader("Content-length", parametros.length);
			http_request.setRequestHeader("Connection", "close");
			http_request.send(parametros);
		}
		if (!modo)
		{
			var objeto_xml = http_request.responseXML;
			if (xml_converte_texto(objeto_xml) != "")
			{
				elemento_html_altera_atributo(elemento_html_atributo(objeto, "options"), "length", 0);
				if (primeiro_elemento_vazio)
				{
					elemento_html_atributo(objeto, "options").add(primeiro_elemento);
				}
				xml_carrega_elemento_html(objeto_xml, objeto, valor_padrao);
				if (funcao != null)
				{
					if (typeof(funcao) == "function")
					{
						funcao();
					}
					else if (typeof(funcao) == "string")
					{
						eval(funcao);
					}
				}
			}
		}
	}
}

function xml_ajax_execute(url, parametros, metodo, modo, funcao)
{
	if ((xml_ajax_execute.depurar != null) && (xml_ajax_execute.depurar))
	{
		window.open(url + ((parametros == null) ? "" : "?" + parametros));
	}
	var http_request = ajax_http_request();
	if (http_request)
	{
		metodo = metodo.toUpperCase();
		switch (metodo)
		{
			case "GET":
			{
				http_request.open("GET", url + ((parametros == null) ? "" : "?" + parametros), modo);
				break;
			}
			case "POST":
			{
				http_request.open("POST", url, modo);
				break;
			}
			default:
			{
				return;
			}
		}
		if (modo)
		{
			// O evento "onreadystatechange" só funciona no modo Assíncrono no Firefox.
			http_request.onreadystatechange = function()
			{
				if (http_request.readyState == 4)
				{
					if (http_request.status == 200)
					{
						var objeto_xml = http_request.responseXML;
						var txt = http_request.responseText;
						if (typeof(funcao) == "function")
						{
							funcao(objeto_xml, txt);
						}
						else if (typeof(funcao) == "string")
						{
							eval(funcao);
						}
					}
				}
			}
		}
		if (metodo == "GET")
		{
			http_request.send(null);
		}
		else if (metodo == "POST")
		{
			http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http_request.setRequestHeader("Content-length", parametros.length);
			http_request.setRequestHeader("Connection", "close");
			http_request.send(parametros);
		}
		if (!modo)
		{
			var objeto_xml = http_request.responseXML;
			var txt = http_request.responseText;
			funcao(objeto_xml, txt);
		}
	}
}

function xml_carrega_elemento_html(objeto_xml, objeto, valor_padrao, separador)
{
	if (objeto_xml == null)
	{
		return;
	}
	if (separador == null)
	{
		separador = ",";
	}
	var tag, tipo, id;
	if (objeto.tagName == null)
	{
		tag = objeto[0].tagName;
		tipo = objeto[0].type;
		id = objeto[0].id;
	}
	else
	{
		tag = objeto.tagName;
		tipo = objeto.type;
	}
	if (tag != null)
	{
		tag = tag.toUpperCase();
	}
	if (tipo != null)
	{
		tipo = tipo.toUpperCase();
	}
	if (tag == "SELECT")
	{
		var primeiro_elemento_vazio = false;
		if (elemento_html_atributo(elemento_html_atributo(objeto, "options"), "length") > 0)
		{
			if (elemento_html_atributo(elemento_html_atributo(objeto, "options")[0], "value") == "")
			{
				elemento_html_altera_atributo(elemento_html_atributo(objeto, "options"), "length", 1);
			}
			else
			{
				elemento_html_altera_atributo(elemento_html_atributo(objeto, "options"), "length", 0);
			}
		}
		var root = objeto_xml.getElementsByTagName("root");
		if (root.length > 0)
		{
			root = root[0];
		}
		else
		{
			root = objeto_xml;
		}
		if (root.hasChildNodes())
		{
			if (root.firstChild.attributes.length == 0)
			{
				var rows = root.firstChild.getElementsByTagName("row");
			}
			else
			{
				var rows = root.getElementsByTagName("row");
			}
			if (id == null)
			{
				for (var i = 0; i < rows.length; i++)
				{
					var elemento = document.createElement("OPTION");
					if (rows[i].attributes.length == 0)
					{
						break;
					}
					else if (rows[i].attributes.length == 1)
					{
						elemento_html_altera_atributo(elemento, "text", xml_decode(rows[i].getAttribute(rows[i].attributes[0].name)));
					}
					else
					{
						elemento_html_altera_atributo(elemento, "text", xml_decode(rows[i].getAttribute(rows[i].attributes[1].name)));
					}
					elemento_html_altera_atributo(elemento, "value", xml_decode(rows[i].getAttribute(rows[i].attributes[0].name)));
					if (rows[i].attributes.length > 2)
					{
						elemento_html_altera_atributo(elemento, "title", xml_decode(rows[i].getAttribute(rows[i].attributes[2].name)));
					}
					else
					{
						elemento_html_altera_atributo(elemento, "title", "");
					}
					if (rows[i].attributes.length > 3)
					{
						for (var j = 3; j < rows[i].attributes.length; j++)
						{
							elemento_html_altera_atributo(elemento, "x_" + rows[i].attributes[j].name, xml_decode(rows[i].attributes[j].value));
						}
					}
					elemento_html_atributo(objeto, "options").add(elemento);
				}
				if (valor_padrao != null)
				{
					elemento_html_carrega_valor(objeto, valor_padrao);
				}
			}
			else
			{
				var array_valor_padrao = valor_padrao.split(separador);
				for (var k = 0; k < get_elements_by_id(id).length; k++)
				{
					for (var i = 0; i < rows.length; i++)
					{
						var elemento = document.createElement("OPTION");
	
						if (rows[i].attributes.length == 0)
						{
							break;
						}
						else if (rows[i].attributes.length == 1)
						{
							elemento_html_altera_atributo(elemento, "text", xml_decode(rows[i].getAttribute(rows[i].attributes[0].name)));
						}
						else
						{
							elemento_html_altera_atributo(elemento, "text", xml_decode(rows[i].getAttribute(rows[i].attributes[1].name)));
						}
						elemento_html_altera_atributo(elemento, "value", xml_decode(rows[i].getAttribute(rows[i].attributes[0].name)));
						if (rows[i].attributes.length > 2)
						{
							elemento_html_altera_atributo(elemento, "title", xml_decode(rows[i].getAttribute(rows[i].attributes[2].name)));
						}
						if (rows[i].attributes.length > 3)
						{
							for (var j = 3; j < rows[i].attributes.length; j++)
							{
								elemento_html_altera_atributo(elemento, "x_" + rows[i].attributes[j].name, xml_decode(rows[i].attributes[j].value));
							}
						}
						elemento_html_atributo(objeto[k], "options").add(elemento);
					}
					if (array_valor_padrao[k] != null)
					{
						elemento_html_carrega_valor(objeto[k], array_valor_padrao[k]);
					}
				}
			}
		}
	}
}

function xml_converte_objeto(xml)
{
	switch (browser)
	{
		case "ie":
		{
			var objeto_xml = new ActiveXObject("Microsoft.XMLDOM");
			objeto_xml.async = "false";
			objeto_xml.loadXML(xml);
			break;
		}
		case "firefox":
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		{
			var parser = new DOMParser();
			var objeto_xml = parser.parseFromString(xml, "text/xml");
			break;
		}
	}
	return(objeto_xml);
}

function xml_converte_texto(objeto_xml)
{
	switch (browser)
	{
		case "ie":
		{
			return(objeto_xml.xml);
			break;
		}
		case "firefox":
		case "chrome":
		case "opera":
		case "safari":
		case "netscape":
		{
			return((new XMLSerializer()).serializeToString(objeto_xml));
			break;
		}
	}
}

function xml_decode(parametro)
{
	if (parametro == null)
	{
		return("");
	}
	parametro = parametro.toString();
	parametro = url_decode(parametro);
	return(parametro);
}

function xml_encode(parametro)
{
	if (parametro == null)
	{
		return("");
	}
	parametro = parametro.toString();
	parametro = url_encode(parametro);
	return(parametro);
}

function xml_adiciona_atributo(objeto, atributo, posicao, valor_padrao)
{
	if (typeof(objeto) == "string")
	{
		objeto = xml_converte_objeto(objeto);
	}
	var root = objeto;
	while (root.parentNode != null)
	{
		root = root.parentNode;
	}
	var nos = objeto.childNodes;
	for (var i = 0; i < nos.length; i++)
	{
		if (nos[i].attributes.getNamedItem(atributo) == null)
		{
			var no = root.createAttribute("atributo");
			if (valor_padrao != null)
			{
				no.nodeValue = valor_padrao;
			}
			nos[i].setAttributeNode(no);
			if ((posicao + 1) < nos[i].attributes.length)
			{
				for (var j = nos[i].attributes.length - 2; j >= posicao; j--)
				{
					var no = nos[i].getAttributeNode(nos[i].attributes[j].nodeName).cloneNode(true);
					nos[i].removeAttributeNode(nos[i].getAttributeNode(nos[i].attributes[j].nodeName));
					j--;
					nos[i].setAttributeNode(no);
				}
			}
		}
	}
}

function xml_remove_atributo(objeto, atributo)
{
	if (typeof(objeto) == "string")
	{
		objeto = xml_converte_objeto(objeto);
	}
	var nos = objeto.childNodes;
	for (var i = 0; i < nos.length; i++)
	{
		if (nos[i].attributes.getNamedItem(atributo) != null)
		{
			nos[i].removeAttributeNode(nos[i].getAttributeNode(atributo));
		}
	}
}

function valida_cnpj(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	parametro = parametro.replace(/\.-\//g, "");
	if (parametro.length != 14)
	{
		return(false);
	}
	if (!valida_inteiro(parametro))
	{
		return(false);
	}
	var sequencia, soma, resto;
	if ((parametro == "00000000000000") || (parametro == "11111111111111") || (parametro == "22222222222222") || (parametro == "33333333333333") || (parametro == "44444444444444") || (parametro == "55555555555555") || (parametro == "66666666666666") || (parametro == "77777777777777") || (parametro == "88888888888888") || (parametro == "99999999999999"))
	{
		return(false);
	}
	sequencia = "543298765432";
	soma = 0;
	for (var i = 0; i < sequencia.length; i++)
	{
		soma += parseInt(parametro.charAt(i), 10) * (sequencia.charAt(i));
	}
	resto = (soma % 11);
	if ((resto == 0) || (resto == 1))
	{
		resto = 0;
	}
	else
	{
		resto = (11 - resto);
	}
	if (resto != parseInt(parametro.charAt(12), 10))
	{
		return(false);
	}
	sequencia = "654329876543";
	soma = 0;
	for (var i = 0; i < sequencia.length; i++)
	{
		soma += parseInt(parametro.charAt(i), 10) * (sequencia.charAt(i));
	}
	soma += (resto * 2);
	resto = (soma % 11);
	if ((resto == 0) || (resto == 1))
	{
		resto = 0;
	}
	else
	{
		resto = (11 - resto);
	}
	if (resto != parseInt(parametro.charAt(13), 10))
	{
		return(false);
	}
	return(true);
}

function valida_cpf(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	parametro = parametro.replace(/\.-/g, "");
	if (parametro.length != 11)
	{
		return(false);
	}
	var soma, digito;
	if ((parametro == "00000000000") || (parametro == "11111111111") || (parametro == "22222222222") || (parametro == "33333333333") || (parametro == "44444444444") || (parametro == "55555555555") || (parametro == "66666666666") || (parametro == "77777777777") || (parametro == "88888888888") || (parametro == "99999999999"))
	{
		return(false);
	}
	soma = 0;
	for (var i = 0; i < 9; i++)
	{
		soma += parseInt(parametro.charAt(i), 10) * (10 - i);
	}
	digito = soma - (Math.floor(soma / 11) * 11);
	if ((digito == 0) || (digito == 1))
	{
		digito = 0;
	}
	else
	{
		digito = 11 - digito;
	}
	if (digito != parseInt(parametro.charAt(9), 10))
	{
		return(false);
	}
	soma = digito * 2;
	for (var i = 0; i < 9; i++)
	{
		soma += parseInt(parametro.charAt(i), 10) * (11 - i);
	}
	digito = soma - (Math.floor(soma / 11) * 11);
	if ((digito == 0) || (digito == 1))
	{
		digito = 0;
	}
	else
	{
		digito = 11 - digito;
	}
	if (digito != parseInt(parametro.charAt(10), 10))
	{
		return(false);
	}
	return(true);
}

function valida_data(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-3][0-9]\/[0-1][0-9]\/[0-9]{4}$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	var array_data, dia, mes, ano, ano_bissexto;
	array_data = parametro.split("/");
	if (array_data == null)
	{
		return(false);
	}
	dia = array_data[0].int();
	mes = array_data[1].int();
	ano = array_data[2].int();
	if ((mes < 1) || (mes > 12))
	{
		return(false);
	}
	if ((dia < 1) || (dia > 31))
	{
		return(false);
	}
	if (((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) && (dia == 31))
	{
		return(false);
	}
	if (mes == 2)
	{
		ano_bissexto = (((ano % 4) == 0) && (((ano % 100) != 0) || ((ano % 400) == 0)));
		if ((dia > 29) || ((dia == 29) && !ano_bissexto))
		{
			return(false);
		}
	}
	return(true);
}

function valida_data_curta(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-3][0-9]\/[0-1][0-9]\/[0-9]{2}$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	var array_data, dia, mes, ano, ano_bissexto;
	array_data = parametro.split("/");
	if (array_data == null)
	{
		return(false);
	}
	dia = array_data[0].int();
	mes = array_data[1].int();
	ano = ("19" + array_data[2]).int();
	if ((mes < 1) || (mes > 12))
	{
		return(false);
	}
	if ((dia < 1) || (dia > 31))
	{
		return(false);
	}
	if (((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) && (dia == 31))
	{
		return(false);
	}
	if (mes == 2)
	{
		ano_bissexto = (((ano % 4) == 0) && (((ano % 100) != 0) || ((ano % 400) == 0)));
		if ((dia > 29) || ((dia == 29) && !ano_bissexto))
		{
			return(false);
		}
	}
	return(true);
}

function valida_data_hora(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-3][0-9]\/[0-1][0-9]\/[0-9]{4} [0-2][0-9]:[0-5][0-9](:[0-5][0-9])?$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	var data = parametro.substr(0, 10);
	var hora = parametro.substr(11);
	var retorno = valida_data(data, obrigatorio);
	if (retorno)
	{
		var retorno = valida_hora(hora, obrigatorio);
	}
	return(retorno);
}

function valida_dia(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-9]{2}$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	if ((parametro.int() < 1) || (parametro.int() > 31))
	{
		return(false);
	}
	return(true);
}

function valida_email(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,3}$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	return(true);
}

function valida_er(er, parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var retorno = er.test(parametro);
	return(retorno);
}

function valida_estado(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[a-zA-Z]{2}$/;
	if (er.test(parametro) == false)
	{
		return(false);
	}
	var retorno = false;
	for (var i = 0; i < array_estado.length; i++)
	{
		if (parametro.toUpperCase() == array_estado[i])
		{
			retorno = true;
			break;
		}
	}
	return(retorno);
}

function valida_hora(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-2][0-9]:[0-5][0-9](:[0-5][0-9])?$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	if (parseInt(parametro.substr(0, 2), 10) > 23)
	{
		return(false);
	}
	return(true);
}

function valida_inteiro(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-9]+$/;
	return(er.test(parametro));
}

function valida_mes(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-9]{2}$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	if ((parametro.int() < 1) || (parametro.int() > 12))
	{
		return(false);
	}
	return(true);
}

function valida_mes_ano(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-9]{6}$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	if ((parametro.substr(0, 2).int() < 1) || (parametro.substr(0, 2).int() > 12))
	{
		return(false);
	}
	return(true);
}

function valida_moeda(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^((-?[0-9]+(,[0-9]+)?)|(-?[0-9]{1,3}(\.[0-9]{3})*)(,[0-9]+)?)$/;
	return(er.test(parametro));
}

function valida_moeda_eua(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^((-?[0-9]+(\.[0-9]+)?)|(-?[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]+)?)$/;
	return(er.test(parametro));
}

function valida_moeda_eua_inteiro(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^-?[0-9]+(\.[0-9]+)?$/;
	return(er.test(parametro));
}

function valida_moeda_inteiro(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^-?[0-9]+(,[0-9]+)?$/;
	return(er.test(parametro));
}

function valida_nome_arquivo(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-9a-zA-Z_]+$/;
	return(er.test(parametro));
}

function valida_nome_pasta(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-9a-zA-Z_]+$/;
	return(er.test(parametro));
}

function valida_numero(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^((-?[0-9]+)|(-?[0-9]{1,3}(\.[0-9]{3})*))$/;
	return(er.test(parametro));
}

function valida_numero_decimal(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^((-?[0-9]+(,[0-9]+)?)|(-?[0-9]{1,3}(\.[0-9]{3})*)(,[0-9]+)?)$/;
	return(er.test(parametro));
}

function valida_numero_decimal_eua(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^((-?[0-9]+(\.[0-9]+)?)|(-?[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]+)?)$/;
	return(er.test(parametro));
}

function valida_numero_decimal_eua_inteiro(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^-?[0-9]+(\.[0-9]+)?$/;
	return(er.test(parametro));
}

function valida_numero_decimal_inteiro(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^-?[0-9]+(,[0-9]+)?$/;
	return(er.test(parametro));
}

function valida_numero_eua(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^((-?[0-9]+)|(-?[0-9]{1,3}(,[0-9]{3})*))$/;
	return(er.test(parametro));
}

function valida_numero_eua_inteiro(parametro, obrigatorio)
{
	return(valida_inteiro(parametro, obrigatorio));
}

function valida_numero_inteiro(parametro, obrigatorio)
{
	return(valida_inteiro(parametro, obrigatorio));
}

function valida_periodo_data(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-3][0-9]\/[0-1][0-9]\/[0-9]{4} a [0-3][0-9]\/[0-1][0-9]\/[0-9]{4}$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	var data_inicio = parametro.substr(0, 10);
	var data_fim = parametro.substr(11);
	var retorno = valida_data(data_inicio, obrigatorio);
	if (retorno)
	{
		var retorno = valida_data(data_fim, obrigatorio);
	}
	return(retorno);
}

function valida_periodo_hora(parametro, obrigatorio)
{
	if (parametro == null)
	{
		parametro = "";
	}
	else
	{
		parametro = parametro.toString();
	}
	if (obrigatorio == null)
	{
		obrigatorio = true;
	}
	if ((obrigatorio == false) && (parametro.length == 0))
	{
		return(true);
	}
	var er = /^[0-2][0-9]:[0-5][0-9](:[0-5][0-9])? a [0-2][0-9]:[0-5][0-9](:[0-5][0-9])?$/;
	if (!er.test(parametro))
	{
		return(false);
	}
	var hora_inicio = parametro.substr(0, parametro.indexOf(" "));
	var hora_fim = parametro.substr(parametro.indexOf(" a ") + 3);
	var retorno = valida_hora(hora_inicio, obrigatorio);
	if (retorno)
	{
		var retorno = valida_hora(hora_fim, obrigatorio);
	}
	return(retorno);
}

function valida(formato, objeto, obrigatorio)
{
	formato = formato.int();
	if (typeof(objeto) == "object")
	{
		var parametro = elemento_html_valor(objeto);
	}
	else
	{
		var parametro = objeto;
	}
	switch (formato)
	{
		case 1: // Texto.
		{
			var retorno = true;
			return(retorno);
			break;
		}
		case 2: // CPF (somente números).
		{
			var retorno = valida_cpf(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 3: // CPF (com pontuação).
		{
			var er = /^[0-9]{3}\.[0-9]{3}\.[0-9]{3}-[0-9]{2}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			if (retorno)
			{
				var retorno = valida_cpf(parametro, obrigatorio);
			}
			return(retorno);
			break;
		}
		case 4: // CNPJ (somente números).
		{
			var retorno = valida_cnpj(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 5: // CNPJ (com pontuação).
		{
			var er = /^[0-9]{2}\.[0-9]{3}\.[0-9]{3}\/[0-9]{4}-[0-9]{2}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			if (retorno)
			{
				var retorno = valida_cnpj(parametro, obrigatorio);
			}
			return(retorno);
			break;
		}
		case 6: // CPF/CNPJ (somente números).
		{
			var retorno = valida_cpf(parametro, obrigatorio);
			if (!retorno)
			{
				var retorno = valida_cnpj(parametro, obrigatorio);
			}
			return(retorno);
			break;
		}
		case 7: // CPF/CNPJ (com pontuação).
		{
			var er = /^[0-9]{3}\.[0-9]{3}\.[0-9]{3}-[0-9]{2}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			if (retorno)
			{
				var retorno = valida_cpf(parametro, obrigatorio);
			}
			else
			{
				var er = /^[0-9]{2}\.[0-9]{3}\.[0-9]{3}\/[0-9]{4}-[0-9]{2}$/;
				var retorno = valida_er(er, parametro, obrigatorio);
				if (retorno)
				{
					var retorno = valida_cnpj(parametro, obrigatorio);
				}
			}
			return(retorno);
			break;
		}
		case 8: // DDD (somente números).
		{
			var er = /^[0-9]{2}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 9: // DDD+Telefone (somente números).
		{
			var er = /^[0-9]{9,10}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 10: // DDD+Telefone (com pontuação).
		{
			var er = /^(\(?[0-9]{2}\)? )?[0-9]{3,4}-?[0-9]{4}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 11: // Telefone (somente números).
		{
			var er = /^[0-9]{7,8}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 12: // Telefone (com pontuação).
		{
			var er = /^[0-9]{3,4}-?[0-9]{4}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 13: // Ramal.
		{
			var retorno = true;
			return(retorno);
			break;
		}
		case 14: // CEP (somente números).
		{
			var er = /^[0-9]{8}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 15: // CEP (com pontuação).
		{
			var er = /^[0-9]{5}-[0-9]{3}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 16: // Estado.
		{
			var retorno = valida_estado(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 17: // Sexo (M/F).
		{
			var er = /^M|F$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 18: // Dia (DD).
		{
			var retorno = valida_dia(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 19: // Mês (MM).
		{
			var retorno = valida_mes(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 20: // Ano (AAAA).
		{
			var er = /^[0-9]{4}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 21: // Ano (AA).
		{
			var er = /^[0-9]{2}$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 22: // Mês+Ano (MMAAAA).
		{
			var retorno = valida_mes_ano(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 23: // E-Mail.
		{
			var retorno = valida_email(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 24: // URL (Home page).
		{
			var retorno = true;
			return(retorno);
			break;
		}
		case 25: // Arquivo (nome do arquivo).
		{
			var retorno = valida_nome_arquivo(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 26: // Imagem (nome do arquivo).
		{
			var retorno = valida_nome_arquivo(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 27: // DD/MM/YYYY.
		{
			var retorno = valida_data(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 28: // DD/MM/YY.
		{
			var retorno = valida_data_curta(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 29: // HH:MM:SS.
		{
			var retorno = valida_hora(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 30: // HH:MM.
		{
			var retorno = valida_hora(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 31: // DD/MM/YYYY HH:MM:SS.
		{
			var retorno = valida_data_hora(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 32: // DD/MM/YYYY HH:MM.
		{
			var retorno = valida_data_hora(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 33: // DD/MM/YYYY a DD/MM/YYYY.
		{
			var retorno = valida_periodo_data(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 34: // HH:MM:SS a HH:MM:SS.
		{
			var retorno = valida_periodo_hora(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 35: // Número inteiro.
		{
			var retorno = valida_numero_inteiro(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 36: // Número decimal (sem pontuação).
		{
			var retorno = valida_numero_decimal_inteiro(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 37: // Número decimal (com pontuação).
		{
			var retorno = valida_numero_decimal(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 38: // Número decimal EUA (sem pontuação).
		{
			var retorno = valida_numero_decimal_eua_inteiro(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 39: // Moeda (com pontuação).
		{
			var retorno = valida_moeda(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 40: // Moeda EUA (sem pontuação).
		{
			var retorno = valida_moeda_eua_inteiro(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 41: // Booleano (1/0).
		{
			var er = /^[0-1]$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 42: // Booleano (1/Null).
		{
			var er = /^[1]$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 43: // Booleano (S/N).
		{
			var er = /^[snSN]$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 44: // Booleano (Y/N).
		{
			var er = /^[ynYN]$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 45: // Booleano Ativo/Inativo.
		{
			var er = /^[aiAI]$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 46: // Booleano Sim/Não.
		{
			var er = /^[snSN]$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 47: // Booleano Yes/No.
		{
			var er = /^[ynYN]$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 48: // Sexo (H/M).
		{
			var er = /^[hmHM]$/;
			var retorno = valida_er(er, parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 49: // Moeda (sem pontuação).
		{
			var retorno = valida_moeda_inteiro(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 50: // Número (com pontuação).
		{
			var retorno = valida_numero(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 51: // Número (sem pontuação).
		{
			var retorno = valida_numero_inteiro(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 52: // Moeda EUA (com pontuação).
		{
			var retorno = valida_moeda_eua(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 53: // Número decimal EUA (com pontuação).
		{
			var retorno = valida_numero_decimal_eua(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 54: // Número EUA (sem pontuação).
		{
			var retorno = valida_numero_eua_inteiro(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 55: // Número EUA (com pontuação).
		{
			var retorno = valida_numero_eua(parametro, obrigatorio);
			return(retorno);
			break;
		}
		case 56: // Dia (D).
		{
			var retorno = valida_dia(parametro, obrigatorio);
			if (retorno)
			{
				if (parametro != null)
				{
					if (parametro.substr(0, 1) == "0")
					{
						var retorno = false
					}
				}
			}
			return(retorno);
			break;
		}
		case 57: // Mês (M).
		{
			var retorno = valida_mes(parametro, obrigatorio);
			if (retorno)
			{
				if (parametro != null)
				{
					if (parametro.substr(0, 1) == "0")
					{
						var retorno = false
					}
				}
			}
			return(retorno);
			break;
		}
	}
}

function filtra_tecla(formato)
{
	formato = formato.int();
	parametro = ".*";
	switch (formato)
	{
		case 1: // Texto.
		{
			return(parametro);
			break;
		}
		case 2: // CPF (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 3: // CPF (com pontuação).
		{
			parametro = "[0-9.-]";
			return(parametro);
			break;
		}
		case 4: // CNPJ (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 5: // CNPJ (com pontuação).
		{
			parametro = "[0-9./-]";
			return(parametro);
			break;
		}
		case 6: // CPF/CNPJ (somente números).
		{
			parametro = "[0-9./-]";
			return(parametro);
			break;
		}
		case 7: // CPF/CNPJ (com pontuação).
		{
			parametro = "[0-9./-]";
			return(parametro);
			break;
		}
		case 8: // DDD (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 9: // DDD+Telefone (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 10: // DDD+Telefone (com pontuação).
		{
			parametro = "[0-9() -]";
			return(parametro);
			break;
		}
		case 11: // Telefone (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 12: // Telefone (com pontuação).
		{
			parametro = "[0-9-]";
			return(parametro);
			break;
		}
		case 13: // Ramal.
		{
			return(parametro);
			break;
		}
		case 14: // CEP (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 15: // CEP (com pontuação).
		{
			parametro = "[0-9-]";
			return(parametro);
			break;
		}
		case 16: // Estado.
		{
			parametro = "[a-zA-Z]";
			return(parametro);
			break;
		}
		case 17: // Sexo (M/F).
		{
			parametro = "[MF]";
			return(parametro);
			break;
		}
		case 18: // Dia (DD).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 19: // Mês (MM).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 20: // Ano (AAAA).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 21: // Ano (AA).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 22: // Mês+Ano (MMAAAA).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 23: // E-Mail.
		{
			parametro = "[0-9a-zA-Z_-@]";
			return(parametro);
			break;
		}
		case 24: // URL (Home page).
		{
			return(parametro);
			break;
		}
		case 25: // Arquivo (nome do arquivo).
		{
			parametro = "[0-9a-zA-Z_]";
			return(parametro);
			break;
		}
		case 26: // Imagem (nome do arquivo).
		{
			parametro = "[0-9a-zA-Z_]";
			return(parametro);
			break;
		}
		case 27: // DD/MM/YYYY.
		{
			parametro = "[0-9/]";
			return(parametro);
			break;
		}
		case 28: // DD/MM/YY.
		{
			parametro = "[0-9/]";
			return(parametro);
			break;
		}
		case 29: // HH:MM:SS.
		{
			parametro = "[0-9]:";
			return(parametro);
			break;
		}
		case 30: // HH:MM.
		{
			parametro = "[0-9:]";
			return(parametro);
			break;
		}
		case 31: // DD/MM/YYYY HH:MM:SS.
		{
			parametro = "[0-9/ :]";
			return(parametro);
			break;
		}
		case 32: // DD/MM/YYYY HH:MM.
		{
			parametro = "[0-9/ :]";
			return(parametro);
			break;
		}
		case 33: // DD/MM/YYYY a DD/MM/YYYY.
		{
			parametro = "[0-9/ ]";
			return(parametro);
			break;
		}
		case 34: // HH:MM:SS a HH:MM:SS.
		{
			parametro = "[0-9: ]";
			return(parametro);
			break;
		}
		case 35: // Número inteiro.
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 36: // Número decimal (sem pontuação).
		{
			parametro = "[0-9,]";
			return(parametro);
			break;
		}
		case 37: // Número decimal (com pontuação).
		{
			parametro = "[0-9.,]";
			return(parametro);
			break;
		}
		case 38: // Número decimal EUA (sem pontuação).
		{
			parametro = "[0-9.]";
			return(parametro);
			break;
		}
		case 39: // Moeda (com pontuação).
		{
			parametro = "[0-9.,]";
			return(parametro);
			break;
		}
		case 40: // Moeda EUA (sem pontuação).
		{
			parametro = "[0-9.]";
			return(parametro);
			break;
		}
		case 41: // Booleano (1/0).
		{
			parametro = "[0-1]";
			return(parametro);
			break;
		}
		case 42: // Booleano (1/Null).
		{
			parametro = "[1]";
			return(parametro);
			break;
		}
		case 43: // Booleano (S/N).
		{
			parametro = "[snSN]";
			return(parametro);
			break;
		}
		case 44: // Booleano (Y/N).
		{
			parametro = "[ynYN]";
			return(parametro);
			break;
		}
		case 45: // Booleano Ativo/Inativo.
		{
			parametro = "[aiAI]";
			return(parametro);
			break;
		}
		case 46: // Booleano Sim/Não.
		{
			parametro = "[snSN]";
			return(parametro);
			break;
		}
		case 47: // Booleano Yes/No.
		{
			parametro = "[ynYN]";
			return(parametro);
			break;
		}
		case 48: // Sexo (H/M).
		{
			parametro = "[hmHM]";
			return(parametro);
			break;
		}
		case 49: // Moeda (sem pontuação).
		{
			parametro = "[0-9,]";
			return(parametro);
			break;
		}
		case 50: // Número (com pontuação).
		{
			parametro = "[0-9.]";
			break;
		}
		case 51: // Número (sem pontuação).
		{
			parametro = "[0-9]";
			break;
		}
		case 52: // Moeda EUA (com pontuação).
		{
			parametro = "[0-9,.]";
			break;
		}
		case 53: // Número decimal EUA (com pontuação).
		{
			parametro = "[0-9,.]";
			break;
		}
		case 54: // Número EUA (sem pontuação).
		{
			parametro = "[0-9]";
			break;
		}
		case 55: // Número EUA (com pontuação).
		{
			parametro = "[0-9,]";
			break;
		}
		case 56: // Dia (D).
		{
			parametro = "[0-9]";
			break;
		}
		case 57: // Mês (M).
		{
			parametro = "[0-9]";
			break;
		}
	}
}

function mascara_tecla(formato, objeto)
{
	formato = formato.int();
	parametro = ".*";
	switch (formato)
	{
		case 1: // Texto.
		{
			return(parametro);
			break;
		}
		case 2: // CPF (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 3: // CPF (com pontuação).
		{
			parametro = "[0-9.-]";
			return(parametro);
			break;
		}
		case 4: // CNPJ (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 5: // CNPJ (com pontuação).
		{
			parametro = "[0-9./-]";
			return(parametro);
			break;
		}
		case 6: // CPF/CNPJ (somente números).
		{
			parametro = "[0-9./-]";
			return(parametro);
			break;
		}
		case 7: // CPF/CNPJ (com pontuação).
		{
			parametro = "[0-9./-]";
			return(parametro);
			break;
		}
		case 8: // DDD (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 9: // DDD+Telefone (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 10: // DDD+Telefone (com pontuação).
		{
			parametro = "[0-9() -]";
			return(parametro);
			break;
		}
		case 11: // Telefone (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 12: // Telefone (com pontuação).
		{
			parametro = "[0-9-]";
			return(parametro);
			break;
		}
		case 13: // Ramal.
		{
			return(parametro);
			break;
		}
		case 14: // CEP (somente números).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 15: // CEP (com pontuação).
		{
			parametro = "[0-9-]";
			return(parametro);
			break;
		}
		case 16: // Estado.
		{
			parametro = "[a-zA-Z]";
			return(parametro);
			break;
		}
		case 17: // Sexo (M/F).
		{
			parametro = "[MF]";
			return(parametro);
			break;
		}
		case 18: // Dia (DD).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 19: // Mês (MM).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 20: // Ano (AAAA).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 21: // Ano (AA).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 22: // Mês+Ano (MMAAAA).
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 23: // E-Mail.
		{
			parametro = "[0-9a-zA-Z_-@]";
			return(parametro);
			break;
		}
		case 24: // URL (Home page).
		{
			return(parametro);
			break;
		}
		case 25: // Arquivo (nome do arquivo).
		{
			parametro = "[0-9a-zA-Z_]";
			return(parametro);
			break;
		}
		case 26: // Imagem (nome do arquivo).
		{
			parametro = "[0-9a-zA-Z_]";
			return(parametro);
			break;
		}
		case 27: // DD/MM/YYYY.
		{
			parametro = "[0-9/]";
			return(parametro);
			break;
		}
		case 28: // DD/MM/YY.
		{
			parametro = "[0-9/]";
			return(parametro);
			break;
		}
		case 29: // HH:MM:SS.
		{
			parametro = "[0-9]:";
			return(parametro);
			break;
		}
		case 30: // HH:MM.
		{
			parametro = "[0-9:]";
			return(parametro);
			break;
		}
		case 31: // DD/MM/YYYY HH:MM:SS.
		{
			parametro = "[0-9/ :]";
			return(parametro);
			break;
		}
		case 32: // DD/MM/YYYY HH:MM.
		{
			parametro = "[0-9/ :]";
			return(parametro);
			break;
		}
		case 33: // DD/MM/YYYY a DD/MM/YYYY.
		{
			parametro = "[0-9/ ]";
			return(parametro);
			break;
		}
		case 34: // HH:MM:SS a HH:MM:SS.
		{
			parametro = "[0-9: ]";
			return(parametro);
			break;
		}
		case 35: // Número inteiro.
		{
			parametro = "[0-9]";
			return(parametro);
			break;
		}
		case 36: // Número decimal (sem pontuação).
		{
			parametro = "[0-9,]";
			return(parametro);
			break;
		}
		case 37: // Número decimal (com pontuação).
		{
			parametro = "[0-9.,]";
			return(parametro);
			break;
		}
		case 38: // Número decimal EUA (sem pontuação).
		{
			parametro = "[0-9.]";
			return(parametro);
			break;
		}
		case 39: // Moeda (com pontuação).
		{
			parametro = "[0-9.,]";
			return(parametro);
			break;
		}
		case 40: // Moeda EUA (sem pontuação).
		{
			parametro = "[0-9.]";
			return(parametro);
			break;
		}
		case 41: // Booleano (1/0).
		{
			parametro = "[0-1]";
			return(parametro);
			break;
		}
		case 42: // Booleano (1/Null).
		{
			parametro = "[1]";
			return(parametro);
			break;
		}
		case 43: // Booleano (S/N).
		{
			parametro = "[snSN]";
			return(parametro);
			break;
		}
		case 44: // Booleano (Y/N).
		{
			parametro = "[ynYN]";
			return(parametro);
			break;
		}
		case 45: // Booleano Ativo/Inativo.
		{
			parametro = "[aiAI]";
			return(parametro);
			break;
		}
		case 46: // Booleano Sim/Não.
		{
			parametro = "[snSN]";
			return(parametro);
			break;
		}
		case 47: // Booleano Yes/No.
		{
			parametro = "[ynYN]";
			return(parametro);
			break;
		}
		case 48: // Sexo (H/M).
		{
			parametro = "[hmHM]";
			return(parametro);
			break;
		}
		case 49: // Moeda (sem pontuação).
		{
			parametro = "[0-9,]";
			return(parametro);
			break;
		}
		case 50: // Número (com pontuação).
		{
			parametro = "[0-9.]";
			break;
		}
		case 51: // Número (sem pontuação).
		{
			parametro = "[0-9]";
			break;
		}
		case 52: // Moeda EUA (com pontuação).
		{
			parametro = "[0-9,.]";
			break;
		}
		case 53: // Número decimal EUA (com pontuação).
		{
			parametro = "[0-9,.]";
			break;
		}
		case 54: // Número EUA (sem pontuação).
		{
			parametro = "[0-9]";
			break;
		}
		case 55: // Número EUA (com pontuação).
		{
			parametro = "[0-9,]";
			break;
		}
		case 56: // Dia (D).
		{
			parametro = "[0-9]";
			break;
		}
		case 57: // Mês (M).
		{
			parametro = "[0-9]";
			break;
		}
	}
}
