/**
 * Concatenates the values of a variable into an easily readable string
 *
 * ex: document . write('<pre>' + print_r(obj) + '</pre>');
 * alert(print_r(obj))
 *
 * by Matt Hackett [scriptnode.com]
 * @param {Object} x The variable to debug
 * @param {Number} max The maximum number of recursions allowed (keep low, around 5 for HTML elements to prevent errors) [default: 10]
 * @param {String} sep The separator to use between [default: a single space ' ']
 * @param {Number} l The current level deep (amount of recursion). Do not use this parameter: it's for the function's own use
 */
function print_r(x, max, sep, l)
{
    l = l || 0;
    max = max || 10;
    sep = sep || ' ';
    if (l > max) {
        return "[WARNING: Too much recursion]\n";
    }
    var
		i,
		r = '',
		t = typeof x,
		tab = '';

    if (x === null) {
        r += "(null)\n";
    } else if (/object/i . test(t)) {
            l++;
            for (i = 0; i < l; i++) {
                tab += sep;
            }
            if (x && x . length) {
                t = 'array';
            }
            r += '(' + t + ") :\n";
            for (i in x) {
                try {
                    r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1));
                }
                catch (e) {
                    return '[ERROR: ' + e + "]\n";
                }
            }
        } else {
            if (t == 'string') {
                if (x == '') {
                    x = '(empty)';
                }
            }
            r += '(' + t + ') ' + x + "\n";
        }
        return r;
}

/**
 * Event
 *
 * @package BancoDeClasses
 * @author Luis Fernando Gomes
 * @copyright 01/2010
 * @version 1.0
 * @access public
 *
 * Histórico:
 *
 * Data			| Versão | Modificação
 * ------------------------------------------------------------------------------------------------
 * 				|   	 | ------------------------------------------------------------------------
 * ------------------------------------------------------------------------------------------------
 *
 */
var Event = {
	/**
	 * add()
	 *
	 * Adiciona um evento a um objeto.
	 *
	 * @author Luis Fernando Gomes
	 * @copyright 01/2010
	 * @version 1.0
	 *
	 * Histórico:
	 *
	 * Data			| Versão | Modificação
	 * ------------------------------------------------------------------------------------------------
	 * 				|   	 | ------------------------------------------------------------------------
	 * ------------------------------------------------------------------------------------------------
	 *
	 * Ex:
	 * obj = document . getElementById('id');
	 *
	 * Event . add(obj, 'click', nomeDaFuncao);
	 * Event . add(obj, 'keypress', function() { //faça qualquer coisa });
	 *
	 * @param object obj								O objeto que receberá o evento.
	 * @param string type								O tipo de evento. Ex: 'click', 'keypress', 'focus'.
	 * @param function/string fn						A função a ser executada.
	 * @return
	 */
	add : function (obj, type, fn)
	{
	    if (obj . attachEvent) {
	        obj['e' + type + fn] = fn;
	        obj[type + fn] = function ()
	        {
	            obj['e' + type + fn](window . event);
	        }
	        obj . attachEvent('on' + type, obj[type + fn]);
	    } else {
	    	obj . addEventListener(type, fn, false);
	    }
	},
	/**
	 * remove()
	 *
	 * Remove um evento de um objeto.
	 *
	 * @author Luis Fernando Gomes
	 * @copyright 01/2010
	 * @version 1.0
	 *
	 * Histórico:
	 *
	 * Data			| Versão | Modificação
	 * ------------------------------------------------------------------------------------------------
	 * 				|   	 | ------------------------------------------------------------------------
	 * ------------------------------------------------------------------------------------------------
	 *
	 * Ex:
	 * obj = document . getElementById('id');
	 *
	 * Event . remove(obj, 'click', nomeDaFuncao)
	 *
	 * @param object obj								O objeto que receberá o evento.
	 * @param string type								O tipo de evento. Ex: 'click', 'focus'.
	 * @param function/string fn						A função a ser executada.
	 * @return
	 */
	remove : function (obj, type, fn)
	{
	    if (obj . detachEvent) {
	        obj . detachEvent('on' + type, obj[type + fn]);
	        obj[type + fn] = null;
	    } else {
	    	obj . removeEventListener(type, fn, false);
	    }
	}
}

function insertAfter(newElement, targetElement)
{
    var parent = targetElement . parentNode;
    if (parent . lastChild == targetElement) {
        parent . appendChild(newElement);
    } else {
        parent . insertBefore(newElement, targetElement . nextSibling);
    }
}

//#####################################
//mensagens de erro customizáveis
//#####################################

mensagens = new Array();
mensagens['branco'] = 'Campo obrigat\u00F3rio n\u00E3o preenchido';
mensagens['cep'] = 'CEP inv\u00E1lido!';
mensagens['cnpj'] = 'CNPJ inv\u00E1lido!';
mensagens['cpf'] = 'CPF inv\u00E1lido!';
mensagens['data'] = 'Data inv\u00E1lida!';
mensagens['email'] = 'Email inv\u00E1lido!';
mensagens['telefone'] = 'Telefone inv\u00E1lido!';
mensagens['hora'] = 'Hora inv\u00E1lida!';
mensagens['nome'] = 'Nome inv\u00E1lido!';
mensagens['rg'] = 'RG inv\u00E1lido!';
mensagens['url'] = 'URL inv\u00E1lida!';
mensagens['valor'] = 'Valor inv\u00E1lido!';
mensagens['confirmacao'] = 'Campos de confirma\u00E7\u00E3o diferentes';
mensagens['selecione'] = 'Selecione uma op\u00E7\u00E3o: ';

//#####################################
//constantes
//#####################################

if (document . all) {
    sender = 'event . srcElement';
} else {
    sender = 'e . target';
}

//#####################################
//objeto xform
//#####################################
function xform(obj)
{
    setTabIndex(obj);

    this . form = obj;
    this . formId = obj . id;
    this . campos = new Array();
    this . total = 0;
    
    this . exibirObrigatorios = true; // exibir os span's com asterisco

    //metodo para adicionar inputs
	this . adicionar = function(campo, tipoValidacao, branco, confirmacao, objConfirmacao)
	{
		// seta valor default 
		var tipoValidacao = typeof(tipoValidacao) != 'undefined' || tipoValidacao != '' ? tipoValidacao : 'tudo';
		var branco = typeof(branco) != 'undefined' ? branco : false;
		var confirmacao = typeof(confirmacao) != 'undefined' ? confirmacao : false;
    	var objConfirmacao = typeof(objConfirmacao) != 'undefined' ? objConfirmacao : document . createElement('INPUT');

        // teste para radio button
		var campoId = campo . length > 0 && campo[0] . type == 'radio' ? campo[0] . id : campo . id;
        var campoName = campo . length > 0 && campo[0] . type == 'radio' ? campo[0] . name : campo . name; 
//        alert(campoId + ' ' + campoName);

//        if (campo . length > 0 && campo[0] . type == 'radio') {
//    	    //alert(campo[0] . id);
//    	    var campoId = campo[0] . id;
//	        var campoName = campo[0] . id;
//        } else {
//            //alert(campo . id);
//        	var campoId = campo . id;
//        	var campoName = campo . id;
//        }

		// flag
		var chave = -1;
		for (key in this . campos) {
            var thisObj = this . campos[key];

            if (typeof(thisObj) != 'object') {
                continue;
            }

            // teste para radio button 
            var thisId = thisObj . campo . length > 0 && thisObj . campo[0] . type == 'radio' ? thisObj . campo[0] . id : this . campos[key] . campo . id;
            var thisName = thisObj . campo . length > 0 && thisObj . campo[0] . type == 'radio' ? thisObj . campo[0] . name : this . campos[key] . campo . name;
            
//            if (this . campos[key] . campo . length > 0 && this . campos[key] . campo[0] . type == 'radio') {
//	            var thisId = this . campos[key] . campo[0] . id;
//                var thisName = this . campos[key] . campo[0] . name;
//	        } else {
//	        	var thisId = this . campos[key] . campo . id;
//                var thisName = this . campos[key] . campo . name;
//	        }
	        // testa se já esxiste o campo na validação 
			if (thisId === campoId) {
	            chave = key;
	        }
		}
		// se não existe adiciona 
		if (chave == -1) {
	    	this . campos[this . total++] = new xinput(campo, tipoValidacao, branco, confirmacao, objConfirmacao);

            objInput = campo;
            // acrescenta span se obrigatório
            if (this . exibirObrigatorios && !this . campos[this . total - 1] . branco && objInput . type != 'hidden') {
            	objSpan = document . createElement('SPAN');
            	objSpan . className = 'erro';
            	objSpan . innerHTML = ' *';
            	if (objInput . parentNode) {
                    var objParent = objInput . parentNode;
                    // There is no insertAfter method, 
                    // however it can be emulated using 
                    // a combination of insertBefore and nextSibling.
                    objParent . insertBefore(objSpan, objInput . nextSibling);
        		}
            }
	    	//alert('adicionando: ' + campoName + ' total: ' + this . total);
	    }
        //alert('campo: ' + campoName + ' ok');
	}
    //metodo para remover inputs
	this . remover = function(campo)
	{
        // teste para radio button 
        var campoId = campo . length > 0 && campo[0] . type == 'radio' ? campo[0] . id : campo . id;
        var campoName = campo . length > 0 && campo[0] . type == 'radio' ? campo[0] . name : campo . name;

//        if (campo . length > 0 && campo[0] . type == 'radio') {
//    	    //alert(campo[0] . id);
//    	    var campoId = campo[0] . id;
//	        var campoName = campo[0] . id;
//        } else {
//            //alert(campo . id);
//        	var campoId = campo . id;
//        	var campoName = campo . id;
//        }

		// flag 
		var chave = -1;
        // testa se existe o campo na validação 
		for (key in this . campos) {
            var thisObj = this . campos[key];

            if (typeof(thisObj) != 'object') {
                continue;
            }

            // teste para radio button 
            var thisId = thisObj . campo . length > 0 && thisObj . campo[0] . type == 'radio' ? thisObj . campo[0] . id : this . campos[key] . campo . id;
            var thisName = thisObj . campo . length > 0 && thisObj . campo[0] . type == 'radio' ? thisObj . campo[0] . name : this . campos[key] . campo . name;

//            if (this . campos[key] . campo . length > 0 && this . campos[key] . campo[0] . type == 'radio') {
//	            var thisId = this . campos[key] . campo[0] . id;
//                var thisName = this . campos[key] . campo[0] . name;
//	        } else {
//	        	var thisId = this . campos[key] . campo . id;
//                var thisName = this . campos[key] . campo . name;
//	        }
	        // testa se já esxiste o campo na validação 
			if (thisId === campoId) {
	            chave = key;
	        }
		}
		// se existe remove 
		if (chave != -1) {
            objInput = campo;
            // remove o span se obrigatório
            if (this . exibirObrigatorios && !this . campos[parseInt(chave)] . branco && objInput . type != 'hidden') {
            	if (objInput . parentNode) {
                    objParent = objInput . parentNode;
                    for (var i = 0; i < objParent . childNodes . length; i++) {
                        objChild = objParent . childNodes[i];
                        if (objChild . className == 'erro') {
                            objParent . removeChild(objChild);
                        }
                	}
        		}
            }
		    var thisOnKeyUp = 'Event . remove(objInput, "keyup", function() ' + "\n" + '{' + "\n\t" + 'this . value = ' + this . campos[parseInt(chave)] . mascara + '(this . value);' + "\n" + '});';
            if (this . campos[parseInt(chave)] . mascara != '' && this . campos[parseInt(chave)] . mascara != 'tudo') {
                eval(thisOnKeyUp);
            }
			for (i = parseInt(chave); i < (this . campos . length - 1); i++) {
				this . campos[i] = this . campos[(i + 1)];
			}
			this . campos . pop();
			this . total--;
			//alert('removendo: ' + campoName + ' total: ' + this . total);
		}
	}
    this . valida = function()
    {
        //alert(this . name);
        setTabIndex(this);
    
    	obj = this . parent; // this aqui é o objForm
        var ixx = obj . campos;
    
    	//alert(ixx.valueOf());
        ixx . sort(sortCampos);
    
        for (y = 0; y < ixx . length; y++) {
        	//alert(print_r(ixx[y] . campo, 5));
        	//alert(ixx[y] . campo . name + ' ' + ixx[y] . campo . type + ' ' + ixx[y] . campo . tabIndex/* + ' ' + ixx[y] . campo[0] . tabIndex*/);
            
            if (ixx[y] . campo . length > 0 && ixx[y] . campo[0]) {
                if (ixx[y] . campo[0] . type == 'radio') {
                    var objCampo = ixx[y] . campo[0];
                    if (!window . returnValueRadioButton) {
                        alert('Necessário radioButtonFunctions.js');
                        continue;
                    }
                    var campoValue = returnValueRadioButton(ixx[y] . campo);
                }
                if (ixx[y] . campo . type == 'select-one') {
                    var objCampo = ixx[y] . campo;
                    var campoValue = objCampo . value;
                }
                //alert('campo: ' + ixx[y] . campo . type + ' campo[0]: ' + ixx[y] . campo[0] . type);
            } else {
                if (ixx[y] . campo . type == 'checkbox') {
                    var objCampo = ixx[y] . campo;
                    if (!window . returnValueCheckbox) {
                        alert('Necessário checkboxFunctions.js');
                        continue;
                    }
                    var campoValue = returnValueCheckbox(ixx[y] . campo);
                } else {
                    var objCampo = ixx[y] . campo;
                    var campoValue = objCampo . value;
                }
            }
            /*if (ixx[y] . campo . length > 0 && (ixx[y] . campo[0] . type == 'radio')) {
                var objCampo = ixx[y] . campo[0];
                if (!window . returnValueRadioButton) {
                    alert('Necessário radioButtonFunctions.js');
                    continue;
                }
                var campoValue = returnValueRadioButton(ixx[y] . campo);                
            } else {
                var objCampo = ixx[y] . campo;
                var campoValue = objCampo . value;
            }*/
            var campoId = objCampo . id;
	        var campoName = objCampo . name;
            var campoTitle = objCampo . title;
            var txt = '';
            if (campoId) {
                var txt = '|campoId: ' + campoId;
            }
            if (campoName) {
                var txt = txt + '|campoName: ' + campoName;
            }
            //alert(txt);
    		if (!branco(campoValue)) {
    	        // valida campos com confirmação de valores 
    	        if (ixx[y] . confirmacao) {
    	            if (objCampo . value != ixx[y] . objConfirmacao . value) {
    	                //alert(mensagens['confirmacao'] + campoName + ', ' + ixx[y] . objConfirmacao . name);
                        alert(mensagens['confirmacao']);
    	                objCampo . focus();
    	                return false;
    	            }
    	        }
    	        // teste para radio button
                if (ixx[y] . campo . length > 0 && ixx[y] . campo[0] . type == 'radio') {
                    var i = returnIndexRadioButton(ixx[y] . campo);
    				if (i < 0) {
    					alert(mensagens['selecione'] + ixx[y] . campo[0] . name);
    					ixx[y] . campo[0] . focus();
    					return false;
    	            }
                }
    			switch (ixx[y] . tipo) {
    			    case 'cep':
    			    	if (!verificaCEP(campoValue)) {
    		                alert(mensagens['cep']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    
    			    case 'cnpj':
    			    	if (!verificaCNPJ(campoValue)) {
    		                alert(mensagens['cnpj']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    
    				case 'cpf':
    					if (!verificaCPF(campoValue)) {
    		                alert(mensagens['cpf']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    
    				case 'dataBr':
    					if (!verificaData(campoValue)) {
    		                alert(mensagens['data']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    
    				case 'email':
    					if (!verificaEmail(campoValue)) {
    		                alert(mensagens['email']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    
    				case 'fone5':
    					if (!verificaFone5(campoValue)) {
    		                alert(mensagens['telefone']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
                        
                    case 'hora':
    					if (!verificaHora(campoValue)) {
    		                alert(mensagens['hora']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    
                    case 'nome':
    					if (!verificaNome(campoValue)) {
    		                alert(mensagens['nome']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    
    			    case 'rg':
    			    	if (!verificaRG(campoValue)) {
    		                alert(mensagens['rg']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    
    			    case 'url':
    			    	if (!verificaUrl(campoValue)) {
    		                alert(mensagens['url']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;

                    case 'valor':
    			    	if (!verificaValor(campoValue)) {
    		                alert(mensagens['valor']);
    		                objCampo . focus();
    		                return false;
    		            }
    			        break;
    			}
    		} else {
    			// valida campos obrigatórios 
    			if (!ixx[y] . branco) {
                    // sendo vedado branco e value vazia
                    if (campoTitle) {
                        //alert(mensagens[0] + ': ' + objCampo . id);
                        alert(mensagens['branco'] + ': ' + campoTitle);
                    } else {
                        alert(mensagens['branco'] + '!');
                    }
                    //document . getElementById(objCampo . id) . focus();
                    try {                
        				objCampo . focus();
        			} catch (e){}
                    return false;
    	        }
    		}
        }
        return true;
    }
    obj . onsubmit = this . valida;
    obj . parent = this;
}

//#####################################
//objeto xinput
//#####################################
function xinput(objInput, tipoValidacao, branco, confirmacao, objConfirmacao)
{
	// seta valor default 
	this . campo = typeof(objInput) != 'undefined' ? objInput : document . createElement('INPUT');
	this . tipo = typeof(tipoValidacao) != 'undefined' && tipoValidacao != '' ? tipoValidacao : 'tudo';
    this . branco = typeof(branco) != 'undefined' ? branco : false;
    this . confirmacao = typeof(confirmacao) != 'undefined' ? confirmacao : false;
    this . objConfirmacao = typeof(objConfirmacao) != 'undefined' ? objConfirmacao : document . createElement('INPUT');

    var thisOnKeyUp = 'Event . add(objInput, "keyup", function() ' + "\n" + '{' + "\n\t" + 'this . value = ' + this . tipo + '(this . value);' + "\n" + '});';
    if (objInput . length > 0 && objInput[0] . type == 'radio') {
        var thisOnKeyUp = '//alert("teste")';//'setEventRadioButton(objInput, "keyup", function() ' + "\n" + '{' + "\n\t" + 'this . value = ' + this . tipo + '(this . value);' + "\n" + '});'
    }
    

	switch (this . tipo) {
		case 'tudo':
            this . mascara = this . tipo;
	        break;

	    case 'cep':
	    	// Seta tamanho do campo 
	        objInput . setAttribute('maxLength', 9);
	        // Seta Mascara 
            this . mascara = this . tipo;
	        eval(thisOnKeyUp);
			// Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'inteiro');
			}
	        break;

	    case 'cnpj':
	    	// Seta tamanho do campo 
	        objInput . setAttribute('maxLength', 19);
	        // Seta Mascara 
            this . mascara = this . tipo;
	        eval(thisOnKeyUp);
			// Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'inteiro');
			}
	        break;

		case 'cpf':
	        // Seta tamanho do campo 
			objInput . setAttribute('maxLength', 14);
	        // Seta Mascara 
            this . mascara = this . tipo;
	        eval(thisOnKeyUp);
			// Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'inteiro');
			}
	        break;

		case 'dataBr':
	        // Seta tamanho do campo 
			objInput . setAttribute('maxLength', 10);
	        // Seta Mascara 
            this . mascara = this . tipo;
	        eval(thisOnKeyUp);
			// Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'inteiro');
			}
//			objInput . onkeydown = permDefaultCharacters;
	        break;

		case 'email':
	        // Seta tamanho do campo 
			objInput . setAttribute('maxLength', 150);
            // Seta Mascara 
            this . mascara = '';
	        // Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'email');
			}
	        break;

		case 'fone5':
	        // Seta tamanho do campo 
			objInput . setAttribute('maxLength', 14);
	        // Seta Mascara 
            this . mascara = this . tipo; 
	        eval(thisOnKeyUp);
			// Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'inteiro');
			}
	        break;
            
        case 'hora':
	        // Seta tamanho do campo 
			objInput . setAttribute('maxLength', 5);
            // Seta Mascara 
            this . mascara = this . tipo;
	        eval(thisOnKeyUp);
			// Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'inteiro');
			}
	        break;

		case 'nome':
	        // Seta tamanho do campo 
			objInput . setAttribute('maxLength', 255);
			// Seta Mascara 
            this . mascara = this . tipo;
	        //eval(thisOnKeyUp);
			// Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'nome');
			}
	        break;

	    case 'rg':
	        // Seta tamanho do campo 
			//objInput . setAttribute('maxLength', 13); // com trços
            objInput . setAttribute('maxLength', 10); // sem trços
	        // Seta Mascara 
            this . mascara = this . tipo;
	        eval(thisOnKeyUp);
			// Seta tratador de tecla 
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'inteiro');
			}
	        break;

		case 'url':
            // Seta Mascara 
            this . mascara = this . tipo;
	        eval(thisOnKeyUp);
			/** Seta tratador de tecla
			objInput . onkeypress = function(e)
			{
				return validaTecla(e, 'url');
			}**/
	        break;

	   default :
            // Seta Mascara 
            this . mascara = this . tipo;            
			eval(thisOnKeyUp);
            var onKeyPress = 'validaTecla(e, "' + this . tipo + '");';
            objInput . onkeypress = function(e)
			{
                return eval(onKeyPress);
			}
			//alert(objInput . onkeypress);
	}
}

//#####################################
//Funções de Máscara
//#####################################

/*Função que padroniza alpha */
function alpha(v)
{
    v += '';
    v = v . replace(/[^a-z]/ig, ''); //Remove tudo o que não é letra
    return v;
}

/*Função que padroniza alfanumerico */
function alfanumerico(v)
{
    v += '';
    v = v . replace(/[^a-z0-9]/ig, ''); //Remove tudo o que não é dígito ou letra
    return v;
}

/*Função que padroniza CEP 12345-678*/
function cep(v)
{
    v = v . replace(/\D/g, ''); //Remove tudo o que não é dígito
    v = v . replace(/^(\d{5})(\d)/, '$1-$2');
    return v;
}

/*Função que padroniza CNPJ 12.345.678/9012-34*/
function cnpj(v)
{
    v += '';
    v = v . replace(/\D/g, ''); //Remove tudo o que não é dígito
    v = v . replace(/^(\d{3})(\d)/, '$1.$2');
    v = v . replace(/^(\d{3})\.(\d{3})(\d)/, '$1.$2.$3');
    v = v . replace(/\.(\d{3})(\d)/, '.$1/$2');
    v = v . replace(/(\d{4})(\d)/, '$1-$2');
    return v;
}

/*Função que padroniza CPF 123.456.789-01*/
function cpf(v)
{
    v += '';
    v = v . replace(/\D/g, ''); //Remove tudo o que não é dígito
    v = v . replace(/(\d{3})(\d)/, '$1.$2');
    v = v . replace(/(\d{3})(\d)/, '$1.$2');

    v = v . replace(/(\d{3})(\d{1,2})$/, '$1-$2');
    return v;
}

/*Função que padroniza DATA*/
function dataBr(v)
{
    v += '';
    v = v . replace(/\D/g, ''); //Remove tudo o que não é dígito
    v = v . replace(/(\d{2})(\d)/, '$1/$2');
    v = v . replace(/(\d{2})(\d)/, '$1/$2');
    return v;
}

/*Função que padroniza  telefone (11) 4184-1241*/
function fone5(v)
{
    v += '';
    v = v . replace(/\D/g, ''); //Remove tudo o que não é dígito
    v = v . replace(/^(\d\d)(\d)/g, '($1) $2');
    v = v . replace(/(\d{4})(\d)/, '$1-$2');
    return v;
}

/*Função que padroniza Hora*/
function hora(v)
{
    v = v . replace(/\D/g, '');
    v = v . replace(/(\d{2})(\d)/, "$1:$2")
    return v;
}

/*Função que padroniza  telefone (11) 4184-1241*/
function inteiro(v)
{
    v += '';
    return v . replace(/\D/g, ''); //Remove tudo o que não é dígito
}

/*Função que padroniza nome*/
function nome(v)
{
	// ,<.>;:/?[{]}| [0-9'"!@#\$£%¢¨¬&\*\(\)-_=\+] 
    //v = v . replace(/[^a-z À-ú\W]/gi, '');
    return v;
}

/*Função que padroniza Rg 123.123.123-1*/
function rg(v)
{
    v += '';
    v = v . replace(/\D/g, ''); //Remove tudo o que não é dígito
	//v = v . replace(/^(\d{3})(\d{3})(\d{3})(\d)/g, "$1.$2.$3-$4");
    return v;
}

/*Função que padroniza o Site*/
function url(v)
{
    v += '';
    v = v . replace(/^http:\/\/?/, '');
    dominio = v;
    caminho = '';
    if (v . indexOf('/') > -1) {
    	dominio = v . split('/')[0];
        caminho = v . replace(/[^\/]*/, '');
        dominio = dominio . replace(/[^\w\.\+-:@]/g, '');
        caminho = caminho . replace(/[^\w\d\+-@:\?&=%\(\)\.]/g, '');
        caminho = caminho . replace(/([\?&])=/, "$1");
    }
    if (caminho != '') {
    	dominio = dominio . replace(/\.+$/, '');
    }
    if (dominio != '') {
    	v = 'http://' + dominio + caminho;
    } else {
    	v = dominio + caminho;
    }
    return v;
}

/*Função que padroniza valor monétario*/
function valor(v)
{
    v += '';
    v = v . replace(/\D\./g, ''); //Remove tudo o que não é dígito
    //v = v . replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/, "$1.$2");
    //v = v . replace(/(\d{3})(\d)/g, "$1,$2");
    //v = v . replace(/(\d)(\d{2})$/, "$1.$2"); //Coloca ponto antes dos 2 últimos digitos
    return v;
}

//#####################################
//insere/remove o sinal de negatico de um campo
//#####################################

function inverte(a)
{
    valor = a . value;
    if (valor . indexOf('-') == -1) {
        a . value = '-' + valor;
    } else {
        a . value = valor . substr(1, 100);
    }
}

//#####################################
//Funcoes de validação
//#####################################
function branco(valor)
{
    if (valor == '') {
        return true;
    } else {
        return false;
    }
}

/************************************************
* function verificaCEP
* Verifica se um CEP é válido
* Input: cep a ser verificado
* exp = /((\d){3}).((\d){3}).((\d){3})-(\d)/
************************************************/
function verificaCEP(xcep)
{
    exp = /^\d{5}\-\d{3}$/;
	if (!exp . test(xcep)) {
        return false;
    } else {
        return true;
    }
}

/**
 *
 * VALIDA CNPJ COM 14 OU 15 DIGITOS
 * A VALIDAÇÃO É FEITA COM OU SEM OS CARACTERES SEPARADORES, PONTO, HIFEN, BARRA
 *
 * ESTE MÉTODO FOI ADAPTADO POR: 
 * Shiguenori Suguiura Junior <junior@dothcom.net>
 * 
 * http://blog.shiguenori.com
 * http://www.dothcom.net
 * 
 */
function verificaCNPJ(scnpj, element) 
{
    if (!/^(\d{2,3}).?(\d{3}).?(\d{3})\/?(\d{4})-?(\d{2})/ . test(scnpj)) {
        return false;
    }
   // DEIXA APENAS OS NÚMEROS
   cnpj = scnpj . replace(/\D/g, '');
   /*cnpj = cnpj.replace('/','');
   cnpj = cnpj.replace('.','');
   cnpj = cnpj.replace('.','');
   cnpj = cnpj.replace('-','');*/
 
   var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
   digitos_iguais = 1;

   if (cnpj.length < 14 && cnpj.length < 15) {
      return false;
   }
   for (i = 0; i < cnpj.length - 1; i++) {
      if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {
         digitos_iguais = 0;
         break;
      }
   }
 
   if (!digitos_iguais) {
      tamanho = cnpj.length - 2;
      numeros = cnpj.substring(0, tamanho);
      digitos = cnpj.substring(tamanho);
      soma = 0;
      pos = tamanho - 7;
 
      for (i = tamanho; i >= 1; i--) {
         soma += numeros.charAt(tamanho - i) * pos--;
         if (pos < 2) {
            pos = 9;
         }
      }
      resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
      if (resultado != digitos.charAt(0)) {
         return false;
      }
      tamanho = tamanho + 1;
      numeros = cnpj.substring(0,tamanho);
      soma = 0;
      pos = tamanho - 7;
      for (i = tamanho; i >= 1; i--){
         soma += numeros.charAt(tamanho - i) * pos--;
         if (pos < 2){
            pos = 9;
         }
      }
      resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
      if (resultado != digitos.charAt(1)) {
         return false;
      }
      return true;
   } else {
      return false;
   }
} 

/************************************************
* function verificaCGC
* Verifica se um CGC é válido
* Input: cgc a ser verificado
************************************************/
function verificaCGC(scgc)
{
	cgc = scgc . replace(/\D/g,'');
    if ((cgc . indexOf('-') != -1) || (cgc . indexOf('.') != -1) || (cgc . indexOf('/') != -1)) {
        return false;
    }
    var df, resto, dac = '';
    df = 5 * cgc . charAt(0) + 4 * cgc . charAt(1) + 3 * cgc . charAt(2) + 2 * cgc . charAt(3) + 9 * cgc . charAt(4) + 8 * cgc . charAt(5) + 7 * cgc . charAt(6) + 6 * cgc . charAt(7) + 5 * cgc . charAt(8) + 4 * cgc . charAt(9) + 3 * cgc . charAt(10) + 2 * cgc . charAt(11);
    resto = df % 11;
    dac += ((resto <= 1) ? 0 : (11 - resto));
    df = 6 * cgc . charAt(0) + 5 * cgc . charAt(1) + 4 * cgc . charAt(2) + 3 * cgc . charAt(3) + 2 * cgc . charAt(4) + 9 * cgc . charAt(5) + 8 * cgc . charAt(6) + 7 * cgc . charAt(7) + 6 * cgc . charAt(8) + 5 * cgc . charAt(9) + 4 * cgc . charAt(10) + 3 * cgc . charAt(11) + 2 * parseInt(dac);
    resto = df % 11;
    dac += ((resto <= 1) ? 0 : (11 - resto));
    return (dac == cgc . substring(cgc . length - 2, cgc . length));
}

/************************************************
* function verificaCPF
* Verifica se um CPF é válido
* Input: cpf a ser verificado
************************************************/
function verificaCPF(xcpf)
{
    var cpf = xcpf . replace(/\D/g, '');
	var dac = '', inicio = 2, fim = 10, soma, digito, i, j;
    for (j = 1; j <= 2; j++) {
        soma = 0;
        for (i = inicio; i <= fim; i++) {
            soma += parseInt(cpf . substring(i - j - 1, i - j)) * (fim + 1 + j - i);
        }
        if (j == 2) {
            soma += 2 * digito;
		}
        digito = (10 * soma) % 11;
        if (digito == 10) {
            digito = 0;
		}
        dac += digito;
        inicio = 3;
        fim = 11;
    }
    return (dac == cpf . substring(cpf . length - 2, cpf . length));
}

function verificaData(data, gtt)
{
    gtt = gtt || false;
    if ((data == null) || (data . length < 10)) {
        return false;
    }
    var jsDataValida = true;
    var jsDia = data . substring(0, 2) - 0;
    var jsMes = data . substring(3, 5) - 1;
    var jsAno = data . substring(6, 10) - 0;
    var oData = new Date(jsAno, jsMes, jsDia);
    if (jsDia != oData . getDate()) {
        jsDataValida = false;
    }
    if (jsMes != oData . getMonth()) {
        jsDataValida = false;
    }
    if (jsAno != oData . getFullYear()) {
        jsDataValida = false;
    }
    if (gtt) {
        var oDataHoje = new Date();
        if (oData < oDataHoje) {
            jsDataValida = false;
        }
    }
    return jsDataValida;
}

function verificaEmail(email)
{
    var s = new String(email);
    // { } ( ) < > [ ] | \ /
    if ((s . indexOf('{') >= 0) || (s . indexOf('}') >= 0) || (s . indexOf('(') >= 0) || (s . indexOf(')') >= 0) || (s . indexOf('<') >= 0) || (s . indexOf('>') >= 0) || (s . indexOf('[') >= 0) || (s . indexOf(']') >= 0) || (s . indexOf('|') >= 0) || (s . indexOf('\'') >= 0) || (s . indexOf('/') >= 0)) {
    	return false;
    }
    // & * $ % ? ! ^ ~ ` ' "
    if ((s . indexOf('&') >= 0) || (s . indexOf('*') >= 0) || (s . indexOf('$') >= 0) || (s . indexOf('%') >= 0) || (s . indexOf
        ('?') >= 0) || (s . indexOf('!') >= 0) || (s . indexOf('^') >= 0) || (s . indexOf('~') >= 0) || (s . indexOf('`') >= 0) || (s . indexOf("'") >= 0)) {
       	return false;
	}
    // , ; : = #
    if ((s . indexOf(',') >= 0) || (s . indexOf(';') >= 0) || (s . indexOf(':') >= 0) || (s . indexOf('=') >= 0) || (s . indexOf('#') >= 0)) {
    	return false;
    }
    // procura se existe apenas um @
    if ((s . indexOf('@') < 0) || (s . indexOf('@') != s . lastIndexOf('@'))) {
    	return false;
    }
    // verifica se tem pelo menos um ponto após o @
    if (s . lastIndexOf('.') < s . indexOf('@')) {
        return false;
    }
    return true;
}

/************************************************
* function verificaTelefone
* Verifica se um telefone é válido
* Input: telefone a ser verificado
* exp = /\(\d{2}\) \d{4}\-\d{4}/
************************************************/
function verificaFone5(tel)
{
    exp = /\(\d{2}\) \d{4}\-\d{4}/;
	if (!exp . test(tel)) {
        return false;
    } else {
        return true;
    }
}

function verificaHora(xhora)
{
    exp = /([0-1]\d|[2][0-3]):([0-5]\d)(:([0-5]\d))?/;
	if (!exp . test(xhora)) {
        return false;
    } else {
        return true;
    }
}

function verificaNome(nome)
{
    //exp = /^[a-z\u00A1-\uFFFF]*$/i;
    exp = /^[a-z\u00C0-\u00ff A-Z]+$/i;
	if (!exp . test(nome)) {
        return false;
    } else {
        return true;
    }
}

/************************************************
* function verificaRG
* Verifica se um RG é válido
* Input: rg a ser verificado
* exp = /((\d){3}).((\d){3}).((\d){3})-(\d)/
************************************************/
function verificaRG(xrg)
{
    //exp = /((\d){3}).((\d){3}).((\d){3})-(\d)/; // comtraços
    exp = /((\d){10})/; // sem traços
	if (!exp . test(xrg)) {
        return false;
    } else {
        return true;
    }
}

function verificaUrl(xurl)
{
	exp = /^((ht|f)tp(s?)\:\/\/|~\/|\/){1}([0-9a-zA-Z]+:[0-9a-zA-Z]+@)?(([a-zA-Z]{1}([0-9a-zA-Z-]+\.?){1,}(\.[0-9a-zA-Z]{2,5}){1})(:[0-9]{1,5})?)+((\/?[0-9a-zA-Z_-]+\/)+|\/?)([0-9a-zA-Z]+([0-9a-zA-Z_-]?[0-9a-zA-Z]+)?\.[0-9a-zA-Z]{3,4})?([,][0-9a-zA-Z]+)*((\?[0-9a-zA-Z]+=[0-9a-zA-Z]+)?(&[0-9a-zA-Z]+=[0-9a-zA-Z]+)*([,][0-9a-zA-Z]*)*)?$/;
	if (!exp . test(xurl)) {
        return false;
    } else {
        return true;
    }
}

function verificaValor(xvalor)
{
	exp = /^\d+(.\d{1,})?$/;
	if (!exp . test(xvalor)) {
        return false;
    } else {
        return true;
    }
}

function sortCampos(xinputA, xinputB)
{
    if (xinputA . campo . length > 0 && xinputA . campo[0] . type == 'radio') {
        var tabIndexA = xinputA . campo[0] . tabIndex;
        var idA = xinputA . campo[0] . id;
    } else {
        var tabIndexA = xinputA . campo . tabIndex;
        var idA = xinputA . campo . id;
    }

	if (xinputB . campo . length > 0 && xinputB . campo[0] . type == 'radio') {
        var tabIndexB = xinputB . campo[0] . tabIndex;
        var idB = xinputB . campo[0] . id;
    } else {
    	var tabIndexB = xinputB . campo . tabIndex;
        var idB = xinputB . campo . id;
    }
	//alert(idA + ' = ' + tabIndexA + ' : ' + idB + ' = ' + tabIndexB);
	return tabIndexA - tabIndexB;
}

//#####################################
//tratadores de teclas
//#####################################

function permDefaultCharacters(e)
{
	e = typeof(e) != 'undefined' ? e : null;

	var teclasPermitidas = new Array(8/**Backspace**/, 9/**TAB**/, 19/**pause/break**/, 20/**caps lock**/, 27/**escape**/, 33/**page up**/, 34/**page down**/, 35/**End**/, 36/**Home**/, 37/**Seta Esquerda**/, 38/**Seta Cima**/, 39/**Seta Direita**/, 40/**Seta Baixo**/, 45/**Insert**/, 46/**Delete**/, 112/**F1**/, 113/**F2**/, 114/**F3**/, 115/**F4**/, 116/**F5**/, 117/**F6**/, 118/**F7**/, 119/**F8**/, 120/**F9**/, 121/**F10**/, 122/**F11**/, 123/**F12**/, 144/**num lock**/, 145/**scroll lock**/);

	//alert(teclasPermitidas.valueOf());

	if (!e) {
	    var e = window . event;
	}

	alvo = eval(sender);

	var charCode = (e . which) ? e . which : e . keyCode;

	var x = charCode;
	for (var i = 0; i < teclasPermitidas . length; i++) {
		if (x == teclasPermitidas[i]) {
			return true;
		}
	}
    return false;
}

/**
 * validaTecla()
 *
 * @author Luis Fernando Gomes
 * @copyright 11/2009
 * @version 1.0
 *
 * Função para limitar o uso de teclas desnecessárias em certos campos.
 *
 * IMPORTANTE
 * A função deve ser chamada no evento ONKEYPRESS, pelo seguinte motivo:
 *
 * No evento onkeypress a validação é feita por caracter ascii.
 * Não possível validar por exemplo as teclas de setas, home, end, etc. 
 * Para termos o código dessas teclas, a função tem de ser chamada no evento onkeydown.
 * Outra coisa importante, no evento onkeydown as teclas numéricas do teclado alfa, 
 * e do teclado numérico são diferentes: Por exemplo, o "1" do teclado alfa, ou seja, 
 * que está em cima do "Q", tem o código 49, já no teclado numérico esse código é 105.
 * É por isso que quando a função era chamada no evento onkeypress, letras eram
 * liberadas, pois nesse evento a validação é feita pelo caractere ascii, e nesse caso o
 * código referente ao "1" dos dois teclados é o mesmo, 49.
 *
 * Histórico:
 *
 * Data			| Versão | Modificação
 * ------------------------------------------------------------------------------------------------
 * 				|  		 | ------------------------------------------------------------------------
 * ------------------------------------------------------------------------------------------------
 *
 * @param string e				O objeto window . event.
 * @param string tipo			O tipo de validação.
 * @return bool
 */
function validaTecla(e, tipo)
{
	// INICIALIZO AS VARIÁVEIS
	e = typeof(e) != 'undefined' ? e : null;
	tipo = typeof(tipo) != 'undefined' || tipo != '' ? tipo : 'tudo';

	// TESTE PARA IE FF
	if (!e) {
	    var e = window . event;
	}

	// TESTE PARA INICIALIZAR O target
	alvo = eval(sender);

	// PEGA O VALOR DA TECLA PRESSIONADA
	var charCode = (e . which) ? e . which : e . keyCode; 
	var charValue = String . fromCharCode(charCode); //alert(charCode + '=>' + charValue);

					// 0=> todos 1=> cada 
	var ControlChars = new Array(false, false); //1 a 31 e 127
	var SpecialChars = new Array(false, false); //32 a 47 e 58 a 64 e 91 a 96 e 123 a 126 e 128 a 254
	var DigitsOfNumbers = new Array(false, false); //48 a 57
	var Letters = false; //65 a 90 e 97 a 122
	var LettersUpper = new Array(false, false);
	var LettersLower = new Array(false, false);
	var Accents = false; //259 a 221 e 224 a 255

	// ########################## ControlChars ########################## 
	var PermControlChars = new Array(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);

	var CodeASCIIControlChars = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 127);

	// ########################## SpecialChars ########################## 
	//32 a 47
	var PermSlCs31a47 = new Array(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);

	//58 a 64
	var PermSlCs58a64 = new Array(true, true, true, true, true, true, true);

	//91 a 96
	var PermSlCs91a96 = new Array(true, true, true, true, true, true);

	//123 a 126
	var PermSlCs123a126 = new Array(true, true, true, true);

	//VerySecialChars
	var PermVerySecialChars = new Array(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);

	//32 a 47
	var CodeASCIISlCs31a47 = new Array(32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47);

	//58 a 64
	var CodeASCIISlCs58a64 = new Array(58, 59, 60, 61, 62, 63, 64);

	//91 a 96
	var CodeASCIISlCs91a96 = new Array(91, 92, 93, 94, 95, 96);

	//123 a 126
	var CodeASCIISlCs123a126 = new Array(123, 124, 125, 126);

	//VerySecialChars
	var CodeASCIIVerySecialChars = new Array(128, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 142, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 197, 198, 208, 215, 216, 222, 223, 229, 230, 240, 247, 248, 254);

	var PermSpecialChars = new Array() . concat(PermSlCs31a47, PermSlCs58a64, PermSlCs91a96, PermSlCs123a126, PermVerySecialChars);
	var CodeASCIISpecialChars = new Array() . concat(CodeASCIISlCs31a47, CodeASCIISlCs58a64, CodeASCIISlCs91a96, CodeASCIISlCs123a126, CodeASCIIVerySecialChars);

    // ########################## DigitsOfNumbers ##########################
	//&#48; to &#57;      Digits or numbers 0-9
	var PermDigitsOfNumbers = new Array(true, true, true, true, true, true, true, true, true, true);
	var CodeASCIIDigitsOfNumbers = new Array(48, 49, 50, 51, 52, 53, 54, 55, 56, 57);

	// ########################## Letters ########################## 
	//&#65; to &#90;     Letters A-Z
	var PermLettersUpper = new Array(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
	var CodeASCIILettersUpper = new Array(65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90);

	//&#97; to &#122;     Letters a-z
	var PermLettersLower = new Array(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
	var CodeASCIILettersLower = new Array(97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122);

	//&#159; to &#221;     Letters Accents A-Z
	var PermLettersAccentsUpper = new Array(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
	var CodeASCIILettersAccentsUpper = new Array(159, 192, 193, 194, 195, 196, 199, 200, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 217, 218, 219, 220, 221);

	// ########################## Accents ########################## 
	//&#224; to &#255;     Letters Accents a-z
	var PermLettersAccentsLower = new Array(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
	var CodeASCIILettersAccentsLower = new Array(224, 225, 226, 227, 228, 231, 232, 233, 234, 235, 236, 237, 238, 239, 241, 242, 243, 244, 245, 246, 249, 250, 251, 252, 253, 255);

	// ########################## TIPOS DE VALIDAÇÃO ##########################
	switch (tipo){
		case 'tudo':
			ControlChars[0] = true; //1 a 31 e 127
			SpecialChars[0] = true; //32 a 47 e 58 a 64 e 91 a 96 e 123 a 126 e 128 a 254
			DigitsOfNumbers[0] = true; //48 a 57
			Letters = true; //65 a 90 e 97 a 122
			Accents = true; //259 a 221 e 224 a 255
		break;
        
        case 'alpha':
			ControlChars[0] = true; //1 a 31 e 127
			Letters = true; //65 a 90 e 97 a 122
		break;

        case 'alfanumerico':
			ControlChars[0] = true; //1 a 31 e 127
			DigitsOfNumbers[0] = true; //48 a 57
			Letters = true; //65 a 90 e 97 a 122
		break;
        
		case 'controlChars':
			ControlChars[0] = true; //1 a 31 e 127
		break;

		case 'email':
			ControlChars[0] = true; //1 a 31 e 127
			Letters = true; //65 a 90 e 97 a 122
			DigitsOfNumbers[0] = true; //48 a 57
			SpecialChars[1] = true;
			var PermSpecialChars = new Array(true);
			var CodeASCIISpecialChars = new Array('46');
			if (charValue == '@') {
				if(alvo . value . indexOf(charValue) != -1) {
	            	return false;
	            } else {
	            	return true;
	            }
	        }
		break;

		case 'inteiro':
			ControlChars[0] = true; //1 a 31 e 127
			DigitsOfNumbers[0] = true; //48 a 57
		break;

		case 'nome':
			ControlChars[0] = true; //1 a 31 e 127
			Letters = true; //65 a 90 e 97 a 122
			Accents = true; //259 a 221 e 224 a 255

			SpecialChars[1] = true;
			var PermSpecialChars = new Array(true);//Space - SPC
			var CodeASCIISpecialChars = new Array('32');
		break;

		case 'url':
			ControlChars[0] = true; //1 a 31 e 127
			Letters = true; //65 a 90 e 97 a 122

			SpecialChars[1] = true;
			var PermSpecialChars = new Array(true, true, true, true);
			var CodeASCIISpecialChars = new Array(38, 47, 61, 63);// & , (slash), =, ?
		break;

        case 'valor':
			ControlChars[0] = true; //1 a 31 e 127
			DigitsOfNumbers[0] = true; //48 a 57
			if (charValue == '.') {
				if(alvo . value . indexOf(charValue) != -1) {
	            	return false;
	            } else {
	            	return true;
	            }
	        }
		break;
	}

	// CONCATENA OS ACENTOS NAS LETRAS
	if (Accents) {
 		PermLettersUpper = PermLettersUpper . concat(PermLettersAccentsUpper);
 		CodeASCIILettersUpper = CodeASCIILettersUpper . concat(CodeASCIILettersAccentsUpper);
 		PermLettersLower = PermLettersLower . concat(PermLettersAccentsLower);
 		CodeASCIILettersLower = CodeASCIILettersLower . concat(CodeASCIILettersAccentsLower);
 	}

	// ########################## Teclas Permitidas ##########################
	var arrayTeclas = new Array();

	if (ControlChars[0]) {
		//  CONCATENA AO ARRAY TODO AO DAS TECLAS 
		arrayTeclas = arrayTeclas . concat(CodeASCIIControlChars);
	} else {
		if (ControlChars[1]) {
			//  PERCORRE O ARRAY 
			for (i = 0; i < CodeASCIIControlChars . length; i++) {
				if (PermControlChars[i]) {
					//  ACRESCENTA AO ARRAY 
					arrayTeclas . push(CodeASCIIControlChars[i]);
			    }
		 	}
		}
	}

	if (SpecialChars[0]) {
		arrayTeclas = arrayTeclas . concat(CodeASCIISpecialChars);
	} else {
		if (SpecialChars[1]) {
			for (i = 0; i < PermSpecialChars . length; i++) {
		 		if (PermSpecialChars[i]) {
					arrayTeclas . push(CodeASCIISpecialChars[i]);
			    }
		 	}
		}
	}

	if (DigitsOfNumbers[0]) {
		arrayTeclas = arrayTeclas . concat(CodeASCIIDigitsOfNumbers);
	} else {
		if (DigitsOfNumbers[1]) {
			for (i = 0; i < PermDigitsOfNumbers . length; i++) {
		 		if (PermDigitsOfNumbers[i]) {
					arrayTeclas . push(CodeASCIIDigitsOfNumbers[i]);
			    }
		 	}
		}
	}

	if (Letters) {
		arrayTeclas = arrayTeclas . concat(CodeASCIILettersUpper, CodeASCIILettersLower);

	} else {
		if (LettersUpper[0]) {
			arrayTeclas = arrayTeclas . concat(CodeASCIILettersUpper);
		} else {
			if (LettersUpper[1]) {
				for (i = 1; i < PermLettersUpper . length; i++) {
			 		if (PermLettersLower[i]) {
						arrayTeclas . push(CodeASCIILettersUpper[i]);
				    }
			 	}
			}
		}
		if (LettersLower[0]) {
			arrayTeclas = arrayTeclas . concat(CodeASCIILettersLower);
		} else {
			if (LettersLower[1]) {
				for (i = 0; i < PermLettersLower . length; i++) {
			 		if (PermLettersLower[i]) {
						arrayTeclas . push(CodeASCIILettersLower[i]);
				    }
			 	}
			}
		}
	}

	teclasPermitidas = arrayTeclas;
	// alert(teclasPermitidas . valueOf());
	//  PERCORRE O ARRAY PROCURANDO A TECLA PRESSIONADA 
	for (var i = 0; i < teclasPermitidas . length; i++) {
		if (charCode == teclasPermitidas[i]) {
			//  RETORNA VERDADEIRO SE ACHOU
			return true;
		}
	}
	// RETORNA FALSO SE NÃO ACHOU
    return false;
}

function setTabIndex(objForm)
{
    var tabIndex = 0;
    for (var i = 0; i < objForm . elements . length; i++) {
        obj = objForm . elements[i];
        tabIndex = obj . name;
        obj . tabIndex = (i + 1);
    }
}

function invertTabIndex(objForm)
{
    for (var i = 0, j = objForm . elements . length; i < objForm . elements . length; i++, j--) {
        objForm . elements[i] . tabIndex = j;
    }
}