function mensagem(t,n){

	if (t=='dominio') return '<b>Falha na solicitação!</b><br>O domínio de origem é inválido.'; /* 300 */
	if (t=='conexao') return '<b>Falha na solicitação!</b><br>Erro na conexão, tente novamente.'; /* 300 */
	if (t=='banco') return '<b>Falha na solicitação!</b><br>Erro no banco de dados, tente novamente.'; /* 330 */
	if (t=='codigo') return '<b>Falha na autenticação!</b><br>Código inválido, atualize a página.'; /* 330 */

	if (t=='formulario') return '<b>Informação!</b><br>Preencha corretamente os campos do formulário.'; /* 370 */
	
	if (t=='item') return '<b>Informação!</b><br>Para continuar selecione um ítem.'; /* 290 */
	if (t=='itens') return '<b>Informação!</b><br>Para continuar faça a seleção do(s) ítem(ns).'; /* 330 */

	if (t=='boleto_imprimir') return '<b>Informação!</b><br>Impressão não disponível para o boleto selecionado.'; /* 380 */
	if (t=='boleto_email') return '<b>Informação!</b><br>Não é possível enviar boleto para o pagamento selecionado.'; /* 420 */
	if (t=='boleto_observacao') return '<b>Informação!</b><br>Não existe observação para o pagamento selecionado.'; /* 420 */

	if (t=='excluir') { /* 270 */
		if (n<=1) {
			return '<b>Deseja continuar a exclusão?</b><br>'+n+' Ítem selecionado.';
		} else if (n>1) {
			return '<b>Deseja continuar a exclusão?</b><br>'+n+' Ítens selecionados.';
		} else {
			return '<b>Deseja continuar a exclusão?</b><br>Os dados serão perdidos.';
		}
	}

	if (t=='excluido') { /* 320 */
		if (n<=1) {
			return '<b>Solicitação executada com sucesso!</b><br>'+n+' Ítem excluído.';
		} else if (n>1) {
			return '<b>Solicitação executada com sucesso!</b><br>'+n+' Ítens excluídos.';
		} else {
			return '<b>Solicitação executada com sucesso!</b><br>Ítem excluído.';
		}
	}
	
	if (t=='concluido') return '<b>Solicitação executada!</b><br>Informações enviadas com sucesso.'; /* 290 */

	if (t=='executando') return '<b>Executando solicitação.</b><br>Favor aguardar o término do processo...'; /* 290 */

}

function janela_mensagem(nome,valor){

	if (nome=='dominio') {
		var titulo = 'Erro';
		var icone = 'icone-erro';
		var tamanho = 300;
		var msg = mensagem('dominio');
	}

	if (nome=='conexao') {
		var titulo = 'Erro';
		var icone = 'icone-erro';
		var tamanho = 300;
		var msg = mensagem('conexao');
	}

	if (nome=='banco') {
		var titulo = 'Erro';
		var icone = 'icone-erro';
		var tamanho = 330;
		var msg = mensagem('banco');
	}

	if (nome=='codigo') {
		var titulo = 'Erro';
		var icone = 'icone-erro';
		var tamanho = 330;
		var msg = mensagem('codigo');
	}

	if (nome=='formulario') {
		var titulo = 'Informação';
		var icone = 'icone-informacao';
		var tamanho = 370;
		var msg = mensagem('formulario');
	}

	if (nome=='item') {
		var titulo = 'Informação';
		var icone = 'icone-informacao';
		var tamanho = 290;
		var msg = mensagem('item');
	}

	if (nome=='itens') {
		var titulo = 'Informação';
		var icone = 'icone-informacao';
		var tamanho = 330;
		var msg = mensagem('itens');
	}

	if (nome=='boleto_imprimir') {
		var titulo = 'Informação';
		var icone = 'icone-informacao';
		var tamanho = 380;
		var msg = mensagem('boleto_imprimir');
	}

	if (nome=='boleto_email') {
		var titulo = 'Informação';
		var icone = 'icone-informacao';
		var tamanho = 420;
		var msg = mensagem('boleto_email');
	}

	if (nome=='boleto_observacao') {
		var titulo = 'Informação';
		var icone = 'icone-informacao';
		var tamanho = 420;
		var msg = mensagem('boleto_observacao');
	}

	if (nome=='excluir') {
		var titulo = 'Confirmar';
		var icone = 'icone-pergunta';
		var tamanho = 270;
		var msg = mensagem('excluir',valor);
	}

	if (nome=='excluido') {
		var titulo = 'Concluido';
		var icone = 'icone-ok';
		var tamanho = 320;
		var msg = mensagem('excluido',valor);
	}

	if (nome=='concluido') {
		var titulo = 'Concluído';
		var icone = 'icone-ok';
		var tamanho = 290;
		var msg = mensagem('concluido');
	}

	if (nome=='executando') {

		Ext.MessageBox.show({
			title: 'Aguarde',
			msg: mensagem('executando'),
			width: 290,
			wait: true
		});

	} else {

		Ext.MessageBox.show({
			title: titulo,
			closable: true,
			icon: icone,
			width: tamanho,
			msg: msg,
			buttons: Ext.MessageBox.OK
		});

	}

}

function limpa_moeda(valor){
	valor = valor.replace('.','');
	valor = valor.replace(',','');
	return parseFloat(valor);
}

Ext.apply(Ext.form.VTypes,{
	usuario: function(val,field){
		var usuario = /^([a-z0-9\.\-\_]){2,}$/;
		var numero = /[^0-9]/;
		if (numero.test(val)) {
			return usuario.test(val);
		} else {
			return false;
		}
	},
	usuarioText: 'O nome de usuário informado é inv&aacute;lido',
	usuarioMask: /[a-z0-9\.\-\_]/i
});

Ext.apply(Ext.form.VTypes,{
	numero: function(val,field){
		var numero = /[0-9]/;
		return numero.test(val);
	},
	numeroText: 'O nome de usuário informado é inv&aacute;lido',
	numeroMask: /[0-9]/i
});

Ext.apply(Ext.form.VTypes,{
	ip: function(val,field){
		var ip = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
		return ip.test(val);
	},
	ipText: 'O IP digitado é inv&aacute;lido',
	ipMask: /[0-9]/i
});

Ext.apply(Ext.form.VTypes,{
	nao_ip: function(val,field){
		var nao_ip = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
		if (nao_ip.test(val)) {
			return false;
		} else {
			return true;
		}
	},
	nao_ipText: 'Este campo não pode ser um endereço IP',
	nao_ipMask: /[a-z0-9\.\-\_]/i
});

Ext.apply(Ext.form.VTypes,{
	dominio: function(val,field){
		if (val.match("^www.")=='www.' || val.match("^http")=='http') {
			return false;
		} else {
			var dominio = /^([a-z0-9\-]+)(\.[a-z0-9\-]+)*([a-z0-9\-]+\.)([a-z]){2,4}$/;
			return dominio.test(val);
		}
	},
	dominioText: 'O dom&iacute;nio informado é inv&aacute;lido, este campo deve estar no formato "dominio.com.br"',
	dominioMask: /[a-z0-9\.\-]/i
});

Ext.apply(Ext.form.VTypes,{
	pasta: function(val,field){
		var pasta = /^([a-zA-Z0-9_\-]){1,}$/;
		return pasta.test(val);
	},
	pastaText: 'O nome informado é inv&aacute;lido',
	pastaMask: /[a-zA-Z0-9_\-]/i
});

Ext.apply(Ext.form.VTypes,{
	imagem: function(val,field){
		var imagem = /[^\.]\.(jpg|jpeg|gif|png)\s*$/;
		return imagem.test(val);
	},
	imagemText: 'O arquivo não é uma imagem: jpg, gif ou png.'
});

Ext.apply(Ext.form.VTypes,{
	cpf: function(val,field){
		if (val!='___.___.___-__') {
			if((val = val.replace(/[^\d]/g,"").split("")).length != 11) return false;
			if(new RegExp("^" + val[0] + "{11}$").exec(val.join(""))) return false;
			for(var s = 10, n = 0, i = 0; s >= 2; n += val[i++] * s--);
			if(val[9] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
			for(var s = 11, n = 0, i = 0; s >= 2; n += val[i++] * s--);
			if(val[10] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
			return true;
		} else {
			return true;
		}
	},
	cpfText: 'CPF informado &eacute; inv&aacute;lido!',
	cpfMask: /[0-9\.\-]/i
});

Ext.apply(Ext.form.VTypes,{
	cnpj: function(val,field){
		if (val!='__.___.___/____-__') {
			exp = /\.|\-|\//g
			var val = val.toString().replace( exp, "" ); 
			var b = [6,5,4,3,2,9,8,7,6,5,4,3,2];
			if((val = val.replace(/[^\d]/g,"").split("")).length != 14) return false;
			for(var i = 0, n = 0; i < 12; n += val[i] * b[++i]);
			if(val[12] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
			for(var i = 0, n = 0; i <= 12; n += val[i] * b[i++]);
			if(val[13] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
			return true;
		} else {
			return true;
		}
	},
	cnpjText: 'CNPJ informado &eacute; inv&aacute;lido!',
	cnpjMask: /[0-9\.\-//]/i
});

Ext.apply(Ext.util.Format,{
	formata_moeda : function(v){
		v = String(v);
		if (v<0) {
			v = Math.abs(v);
			v = String(v);
			var h = '-';
		} else {
			var h = '';
		}
		if (isNaN(v)) {
			v = '0';
		}
		var c = v.substr(v.length-2,2);
		v = v.substr(0,v.length-2);
		v = Math.floor((v*100+0.5)/100).toString();
		if (c.length<2) {
			c = '0' + c;
		}
		for (var i = 0; i < Math.floor((v.length-(1+i))/3); i++) {
			v = v.substring(0,v.length-(4*i+3))+'.'+v.substring(v.length-(4*i+3));
		}
		var r = v + ',' + c;
		if (h) {
			r = h + r;
		}
		return r;
	}
});

Ext.ux.MoneyField = function(config){
	var defConfig = {
		autocomplete: 'off',
		allowNegative: false,
		format: 'BRL',
		currency: 'R$',
		showCurrency: false
	};
	Ext.applyIf(config,defConfig);
	Ext.ux.MoneyField.superclass.constructor.call(this, config);
};

Ext.extend(Ext.ux.MoneyField, Ext.form.TextField,{

initEvents : function(){
	Ext.ux.MoneyField.superclass.initEvents.call(this);
	this.el.on("keydown",this.stopEventFunction,this);
	this.el.on("keyup", this.mapCurrency,this); 
	this.el.on("keypress", this.stopEventFunction,this); 
	},

	KEY_RANGES : { 
		numeric: [48, 57], 
		padnum: [96, 105]
	},

	isInRange : function(charCode, range) { 
		return charCode >= range[0] && charCode <= range[1]; 
	}, 

	formatCurrency : function(evt, floatPoint, decimalSep, thousandSep) {             		    	
		floatPoint  = !isNaN(floatPoint) ? Math.abs(floatPoint) : 2;
		thousandSep = typeof thousandSep != "string" ? "," : thousandSep;
		decimalSep  = typeof decimalSep != "string" ? "." : decimalSep;
		var key = evt.getKey();	    
		
		if (this.isInRange(key, this.KEY_RANGES["padnum"])) { 
			key -= 48; 
		}				
		
		this.sign = (this.allowNegative && (key == 45 || key == 109)) ? "-" : (key == 43 || key == 107 || key == 16) ? "" : this.sign;
		
		var character = (this.isInRange(key, this.KEY_RANGES["numeric"]) ? String.fromCharCode(key) : "");	    
		var field = this.el.dom;
		var value = (field.value.replace(/\D/g, "").replace(/^0+/g, "") + character).replace(/\D/g, "");
		var length = value.length;
		
		if ( character == "" && length > 0 && key == 8) {
			length--;
			value = value.substr(0,length);
			evt.stopEvent();
		}
		
		if(field.maxLength + 1 && length >= field.maxLength) return false;
		
		length <= floatPoint && (value = new Array(floatPoint - length + 2).join("0") + value);
		for(var i = (length = (value = value.split("")).length) - floatPoint; (i -= 3) > 0; value[i - 1] += thousandSep);
		floatPoint && floatPoint < length && (value[length - ++floatPoint] += decimalSep);
		field.value = (this.showCurrency && this.currencyPosition == 'left' ? this.currency : '' ) +
			(this.sign ? this.sign : '') + 
			value.join("") + 
			(this.showCurrency && this.currencyPosition != 'left' ? this.currency : '' );            
	},
	
	mapCurrency : function(evt) {        
		switch (this.format) { 
			case 'BRL':
				this.currency = 'R$';
				this.currencyPosition = 'left';
				this.formatCurrency(evt, 2,',','.'); 
				break; 
			
			case 'EUR':
				this.currency = ' €';
				this.currencyPosition = 'right';
				this.formatCurrency(evt, 2,',','.'); 
				break; 
			
			case 'USD':
				this.currencyPosition = 'left';
				this.currency = '$';
				this.formatCurrency(evt, 2); 
				break;
			
			default: 
				this.formatCurrency(evt, 2); 
		} 
	},
    
	stopEventFunction : function(evt) { 
		var key = evt.getKey(); 
		
		if (this.isInRange(key, this.KEY_RANGES["padnum"])) { 
			key -= 48; 
		}			
		
		if ( (( key>=41 && key<=122 ) || key==32 || key==8 || key>186) && (!evt.altKey && !evt.ctrlKey) ) {
			evt.stopEvent(); 
		}
	},
	
	getCharForCode : function(keyCode){   
		var chr = '';
		switch(keyCode) {
			case 48: case 96:
				chr = '0';
				break;
			
			case 49: case 97:
				chr = '1';
				break;
			
			case 50: case 98:
				chr = '2';
				break;
			
			case 51: case 99:
				chr = '3';
				break;
			
			case 52: case 100:
				chr = '4';
				break;
			
			case 53: case 101:
				chr = '5';
				break;
			
			case 54: case 102:
				chr = '6';
				break;
			
			case 55: case 103:
				chr = '7';
				break;
			
			case 56: case 104:
				chr = '8';
				break;
			
			case 57: case 105:
				chr = '9';
				break;
			
			case 45: case 189: case 109:
				chr = '-';
				break;
			
			case 43: case 107: case 187:
				chr = '+';
				break;
			
			default:
				chr = String.fromCharCode(keyCode); //
				break;
		}
		return chr;
	}	
});

Ext.ComponentMgr.registerType('moneyfield', Ext.ux.MoneyField);

Ext.namespace('Ext.ux.netbox');

Ext.ux.netbox.InputTextMask = function(mask,clearWhenInvalid) {

    if(clearWhenInvalid === undefined)
		this.clearWhenInvalid = true;
	else
		this.clearWhenInvalid = clearWhenInvalid;
    this.rawMask = mask;
    this.viewMask = '';
    this.maskArray = new Array();
    var mai = 0;
    var regexp = '';
    for(var i=0; i<mask.length; i++){
        if(regexp){
            if(regexp == 'X'){
                regexp = '';
            }
            if(mask.charAt(i) == 'X'){
                this.maskArray[mai] = regexp;
                mai++;
                regexp = '';
            } else {
                regexp += mask.charAt(i);
            }
        } else if(mask.charAt(i) == 'X'){
            regexp += 'X';
            this.viewMask += '_';
        } else if(mask.charAt(i) == '9' || mask.charAt(i) == 'L' || mask.charAt(i) == 'l' || mask.charAt(i) == 'A') {
            this.viewMask += '_';
            this.maskArray[mai] = mask.charAt(i);
            mai++;
        } else {
            this.viewMask += mask.charAt(i);
            this.maskArray[mai] = RegExp.escape(mask.charAt(i));
            mai++;
        }
    }

    this.specialChars = this.viewMask.replace(/(L|l|9|A|_|X)/g,'');
};

Ext.ux.netbox.InputTextMask.prototype = {

    init : function(field) {
        this.field = field;

        if (field.rendered){
            this.assignEl();
        } else {
            field.on('render', this.assignEl, this);
        }

        field.on('blur',this.removeValueWhenInvalid, this);
        field.on('focus',this.processMaskFocus, this);
    },

    assignEl : function() {
        this.inputTextElement = this.field.getEl().dom;
        this.field.getEl().on('keypress', this.processKeyPress, this);
        this.field.getEl().on('keydown', this.processKeyDown, this);
        if(Ext.isSafari || Ext.isIE){
            this.field.getEl().on('paste',this.startTask,this);
            this.field.getEl().on('cut',this.startTask,this);
        }
        if(Ext.isGecko || Ext.isOpera){
            this.field.getEl().on('mousedown',this.setPreviousValue,this);
        }
        if(Ext.isGecko){
          this.field.getEl().on('input',this.onInput,this);
        }
        if(Ext.isOpera){
          this.field.getEl().on('input',this.onInputOpera,this);
        }
    },
    onInput : function(){
        this.startTask(false);
    },
    onInputOpera : function(){
      if(!this.prevValueOpera){
        this.startTask(false);
      }else{
        this.manageBackspaceAndDeleteOpera();
      }
    },
    
    manageBackspaceAndDeleteOpera: function(){
      this.inputTextElement.value=this.prevValueOpera.cursorPos.previousValue;
      this.manageTheText(this.prevValueOpera.keycode,this.prevValueOpera.cursorPos);
      this.prevValueOpera=null;
    },

    setPreviousValue : function(event){
        this.oldCursorPos=this.getCursorPosition();
    },

    getValidatedKey : function(keycode, cursorPosition) {
        var maskKey = this.maskArray[cursorPosition.start];
        if(maskKey == '9'){
            return keycode.pressedKey.match(/[0-9]/);
        } else if(maskKey == 'L'){
            return (keycode.pressedKey.match(/[A-Za-z]/))? keycode.pressedKey.toUpperCase(): null;
        } else if(maskKey == 'l'){
            return (keycode.pressedKey.match(/[A-Za-z]/))? keycode.pressedKey.toLowerCase(): null;
        } else if(maskKey == 'A'){
            return keycode.pressedKey.match(/[A-Za-z0-9]/);
        } else if(maskKey){
            return (keycode.pressedKey.match(new RegExp(maskKey)));
        }
        return(null);
    },

    removeValueWhenInvalid : function() {
        if(this.clearWhenInvalid && this.inputTextElement.value.indexOf('_') > -1){
            this.inputTextElement.value = '';
        }
    },

    managePaste : function() {
        if(this.oldCursorPos==null){
          return;
        }
        var valuePasted=this.inputTextElement.value.substring(this.oldCursorPos.start,this.inputTextElement.value.length-(this.oldCursorPos.previousValue.length-this.oldCursorPos.end));
        if(this.oldCursorPos.start<this.oldCursorPos.end){//there is selection...
          this.oldCursorPos.previousValue=
            this.oldCursorPos.previousValue.substring(0,this.oldCursorPos.start)+
            this.viewMask.substring(this.oldCursorPos.start,this.oldCursorPos.end)+
            this.oldCursorPos.previousValue.substring(this.oldCursorPos.end,this.oldCursorPos.previousValue.length);
          valuePasted=valuePasted.substr(0,this.oldCursorPos.end-this.oldCursorPos.start);
        }
        this.inputTextElement.value=this.oldCursorPos.previousValue;
        keycode={unicode :'',
        isShiftPressed: false,
        isTab: false,
        isBackspace: false,
        isLeftOrRightArrow: false,
        isDelete: false,
        pressedKey : ''
        }
        var charOk=false;
        for(var i=0;i<valuePasted.length;i++){
            keycode.pressedKey=valuePasted.substr(i,1);
            keycode.unicode=valuePasted.charCodeAt(i);
            this.oldCursorPos=this.skipMaskCharacters(keycode,this.oldCursorPos);
            if(this.oldCursorPos===false){
                break;
            }
            if(this.injectValue(keycode,this.oldCursorPos)){
                charOk=true;
                this.moveCursorToPosition(keycode, this.oldCursorPos);
                this.oldCursorPos.previousValue=this.inputTextElement.value;
                this.oldCursorPos.start=this.oldCursorPos.start+1;
            }
        }
        if(!charOk && this.oldCursorPos!==false){
            this.moveCursorToPosition(null, this.oldCursorPos);
        }
        this.oldCursorPos=null;
    },

    processKeyDown : function(e){
        this.processMaskFormatting(e,'keydown');
    },

    processKeyPress : function(e){
        this.processMaskFormatting(e,'keypress');
    },

    startTask : function(setOldCursor){
        if(this.task==undefined){
            this.task=new Ext.util.DelayedTask(this.managePaste,this);
      }
        if(setOldCursor!== false){
            this.oldCursorPos=this.getCursorPosition();
      }
      this.task.delay(0);
    },

    skipMaskCharacters : function(keycode, cursorPos){
        if(cursorPos.start!=cursorPos.end && (keycode.isDelete || keycode.isBackspace))
            return(cursorPos);
        while(this.specialChars.match(RegExp.escape(this.viewMask.charAt(((keycode.isBackspace)? cursorPos.start-1: cursorPos.start))))){
            if(keycode.isBackspace) {
                cursorPos.dec();
            } else {
                cursorPos.inc();
            }
            if(cursorPos.start >= cursorPos.previousValue.length || cursorPos.start < 0){
                return false;
            }
        }
        return(cursorPos);
    },

    isManagedByKeyDown : function(keycode){
        if(keycode.isDelete || keycode.isBackspace){
            return(true);
        }
        return(false);
    },

    processMaskFormatting : function(e, type) {
        this.oldCursorPos=null;
        var cursorPos = this.getCursorPosition();
        var keycode = this.getKeyCode(e, type);
        if(keycode.unicode==0){
            return;
        }
        if((keycode.unicode==67 || keycode.unicode==99) && e.ctrlKey){
            return;
        }
        if((keycode.unicode==88 || keycode.unicode==120) && e.ctrlKey){
            this.startTask();
            return;
        }
        if((keycode.unicode==86 || keycode.unicode==118) && e.ctrlKey){
            this.startTask();
            return;
        }
        if((keycode.isBackspace || keycode.isDelete) && Ext.isOpera){
          this.prevValueOpera={cursorPos: cursorPos, keycode: keycode};
          return;
        }
        if(type=='keydown' && !this.isManagedByKeyDown(keycode)){
            return true;
        }
        if(type=='keypress' && this.isManagedByKeyDown(keycode)){
            return true;
        }
        if(this.handleEventBubble(e, keycode, type)){
            return true;
        }
        return(this.manageTheText(keycode, cursorPos));
    },
    
    manageTheText: function(keycode, cursorPos){
      if(this.inputTextElement.value.length === 0){
          this.inputTextElement.value = this.viewMask;
      }
      cursorPos=this.skipMaskCharacters(keycode, cursorPos);
      if(cursorPos===false){
          return false;
      }
      if(this.injectValue(keycode, cursorPos)){
          this.moveCursorToPosition(keycode, cursorPos);
      }
      return(false);
    },

    processMaskFocus : function(){
        if(this.inputTextElement.value.length == 0){
            var cursorPos = this.getCursorPosition();
            this.inputTextElement.value = this.viewMask;
            this.moveCursorToPosition(null, cursorPos);
        }
    },

    isManagedByBrowser : function(keyEvent, keycode, type){
        if(((type=='keypress' && keyEvent.charCode===0) ||
            type=='keydown') && (keycode.unicode==Ext.EventObject.TAB ||
            keycode.unicode==Ext.EventObject.RETURN ||
            keycode.unicode==Ext.EventObject.ENTER ||
            keycode.unicode==Ext.EventObject.SHIFT ||
            keycode.unicode==Ext.EventObject.CONTROL ||
            keycode.unicode==Ext.EventObject.ESC ||
            keycode.unicode==Ext.EventObject.PAGEUP ||
            keycode.unicode==Ext.EventObject.PAGEDOWN ||
            keycode.unicode==Ext.EventObject.END ||
            keycode.unicode==Ext.EventObject.HOME ||
            keycode.unicode==Ext.EventObject.LEFT ||
            keycode.unicode==Ext.EventObject.UP ||
            keycode.unicode==Ext.EventObject.RIGHT ||
            keycode.unicode==Ext.EventObject.DOWN)){
                return(true);
        }
        return(false);
    },

    handleEventBubble : function(keyEvent, keycode, type) {
        try {
            if(keycode && this.isManagedByBrowser(keyEvent, keycode, type)){
                return true;
            }
            keyEvent.stopEvent();
            return false;
        } catch(e) {
            alert(e.message);
        }
    },

    getCursorPosition : function() {
        var s, e, r;
        if(this.inputTextElement.createTextRange){
            r = document.selection.createRange().duplicate();
            r.moveEnd('character', this.inputTextElement.value.length);
            if(r.text === ''){
                s = this.inputTextElement.value.length;
            } else {
                s = this.inputTextElement.value.lastIndexOf(r.text);
            }
            r = document.selection.createRange().duplicate();
            r.moveStart('character', -this.inputTextElement.value.length);
            e = r.text.length;
        } else {
            s = this.inputTextElement.selectionStart;
            e = this.inputTextElement.selectionEnd;
        }
        return this.CursorPosition(s, e, r, this.inputTextElement.value);
    },

    moveCursorToPosition : function(keycode, cursorPosition) {
        var p = (!keycode || (keycode && keycode.isBackspace ))? cursorPosition.start: cursorPosition.start + 1;
        if(this.inputTextElement.createTextRange){
            cursorPosition.range.move('character', p);
            cursorPosition.range.select();
        } else {
            this.inputTextElement.selectionStart = p;
            this.inputTextElement.selectionEnd = p;
        }
    },

    injectValue : function(keycode, cursorPosition) {
        if (!keycode.isDelete && keycode.unicode == cursorPosition.previousValue.charCodeAt(cursorPosition.start))
            return true;
        var key;
        if(!keycode.isDelete && !keycode.isBackspace){
            key=this.getValidatedKey(keycode, cursorPosition);
        } else {
            if(cursorPosition.start == cursorPosition.end){
                key='_';
                if(keycode.isBackspace){
                    cursorPosition.dec();
                }
            } else {
                key=this.viewMask.substring(cursorPosition.start,cursorPosition.end);
            }
        }
        if(key){
            this.inputTextElement.value = cursorPosition.previousValue.substring(0,cursorPosition.start)
                + key +
                cursorPosition.previousValue.substring(cursorPosition.start + key.length,cursorPosition.previousValue.length);
            return true;
        }
        return false;
    },

    getKeyCode : function(onKeyDownEvent, type) {
        var keycode = {};
        keycode.unicode = onKeyDownEvent.getKey();
        keycode.isShiftPressed = onKeyDownEvent.shiftKey;
        
        keycode.isDelete = ((onKeyDownEvent.getKey() == Ext.EventObject.DELETE && type=='keydown') || ( type=='keypress' && onKeyDownEvent.charCode===0 && onKeyDownEvent.keyCode == Ext.EventObject.DELETE))? true: false;
        keycode.isTab = (onKeyDownEvent.getKey() == Ext.EventObject.TAB)? true: false;
        keycode.isBackspace = (onKeyDownEvent.getKey() == Ext.EventObject.BACKSPACE)? true: false;
        keycode.isLeftOrRightArrow = (onKeyDownEvent.getKey() == Ext.EventObject.LEFT || onKeyDownEvent.getKey() == Ext.EventObject.RIGHT)? true: false;
        keycode.pressedKey = String.fromCharCode(keycode.unicode);
        return(keycode);
    },

    CursorPosition : function(start, end, range, previousValue) {
        var cursorPosition = {};
        cursorPosition.start = isNaN(start)? 0: start;
        cursorPosition.end = isNaN(end)? 0: end;
        cursorPosition.range = range;
        cursorPosition.previousValue = previousValue;
        cursorPosition.inc = function(){cursorPosition.start++;cursorPosition.end++;};
        cursorPosition.dec = function(){cursorPosition.start--;cursorPosition.end--;};
        return(cursorPosition);
    }
};

Ext.applyIf(RegExp, {
  escape : function(str) {
    return new String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
  }
});

Ext.ux.InputTextMask=Ext.ux.netbox.InputTextMask;