Ext.util.Format.ruMoney = function(v){
	floatValue=parseFloat(v)
	if (isNaN(floatValue)) {
	   return v;
	};
	v = (Math.round((v-0)*100))/100;
	v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
	v = String(v);
	var ps = v.split('.');
	var whole = ps[0];
	var sub = ps[1] ? '.'+ ps[1] : '.00';
	var r = /(\d+)(\d{3})/;
	while (r.test(whole)) {
	    whole = whole.replace(r, '$1' + ',' + '$2');
	}
	v = whole + sub;
	if(v.charAt(0) == '-'){
	    return '-$' + v.substr(1);
	}
	return v+' руб.';
};


Ext.apply(Ext.form.VTypes, {
    daterange : function(val, field) {
        var date = field.parseDate(val);

        if(!date){
            return;
        }
        if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
            var start = Ext.getCmp(field.startDateField);
            start.setMaxValue(date);
            start.validate();
            this.dateRangeMax = date;
        } 
        else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
            var end = Ext.getCmp(field.endDateField);
            end.setMinValue(date);
            end.validate();
            this.dateRangeMin = date;
        }
        /*
         * Always return true since we're only using this vtype to set the
         * min/max allowed values (these are tested for after the vtype test)
         */
        return true;
    },

    password : function(val, field) {
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },

    passwordText : 'Пароли не совпадают'
});

Ext.override(Ext.form.Field, {
	setLabel: function(text){
		var r = this.getEl().up('div.x-form-item');
		r.dom.firstChild.firstChild.nodeValue = String.format('{0}', text);
	},
	getLabel: function(){
		var r = this.getEl().up('div.x-form-item');
		if (r != null)
			return r.dom.firstChild.firstChild.nodeValue;
	},
	showField : function(){
		this.show();
		this.container.up('div.x-form-item').setDisplayed( true );
    },
    hideField : function(){
    	this.hide();
    	this.container.up('div.x-form-item').setDisplayed( false );
    }
}); 

Ext.namespace('Ext.ux.plugins');

Ext.ux.plugins.FormFieldIcon = function(config) {
    Ext.apply(this, config);
};

Ext.extend(Ext.ux.plugins.FormFieldIcon, Ext.util.Observable, {
    init:function(field) {
        Ext.apply(field, {
			onRender: field.onRender.createSequence(function(){		
				var fieldDiv = field.getEl().up("div.x-form-element");				
				fieldDiv.createChild({tag: 'img', src: this.iconUrl, style: this.iconStyle});
			})
		})
	}
});

Ext.ux.plugins.FormFieldText = function(config) {
    Ext.apply(this, config);
};

Ext.extend(Ext.ux.plugins.FormFieldText, Ext.util.Observable, {
    init:function(field) {
        Ext.apply(field, {
			onRender: field.onRender.createSequence(function(){						
				var fieldDiv = field.getEl().up("div.x-form-element");								
				fieldDiv.createChild({tag: 'span', html: this.afterText, style: "margin-left: 4px;"});
			})
		})
	}
});



