Ext.namespace('Ext.ux');
Ext.ux.ImageButton = function(cfg) {
    Ext.ux.ImageButton.superclass.constructor.call(this, cfg);
};

Ext.extend(Ext.ux.ImageButton, Ext.Button, {
    onRender : function(ct, position) {
        this.disabledImgPath = this.disabledImgPath || this.imgPath;
        var tplHTML = '<div style="float: left;  padding: 4px; margin: 5px; cursor: {cursor};"><p align="center"><img align="{align}" hspace="{hspace}" vspace="{vspace}" src="{imgPath}" border="0" width="{imgWidth}" height="{imgHeight}" alt="{tooltip}"/></p> <div style=" width: {textWidth}px; height: {textHeight}px; text-align: {textAlign};">{imgText}</div></div>';
        var tpl = new Ext.Template(tplHTML);
        var btn, targs = {
            imgPath : this.disabled ? this.disabledImgPath : this.imgPath,
            textWidth : this.textWidth || "auto",
            textHeight : this.textHeight || "auto",
            align : this.align || "left",
            vspace: this.vspace || "2",
            hspace: this.hspace || "5",
            imgWidth : this.imgWidth || "",
            imgHeight : this.imgHeight || "",
            imgText : this.text || "",
            cursor : this.disabled ? "default" : "pointer",
            textAlign : this.textAlign || "left",
            tooltip : this.tooltip || ""
        };

        btn = tpl.append(ct, targs, true);

        btn.on("click", this.onClick, this);
        btn.on("mouseover", function(o){
	        if (this.overCls) {
        	    btn.addClass(this.overCls);
    	    }
        }
        , this);
        btn.on("mouseout", function(o){
	        if (this.overCls) {
        	    btn.removeClass(this.overCls);
    	    }
        }
        , this);

        if (this.cls) {
            btn.addClass(this.cls);
        }
        this.el = btn;
        if (this.hidden) {
            this.hide();
        }
    },
    disable : function(newImgPath) {
        var replaceImgPath = newImgPath || this.disabledImgPath;
        if (replaceImgPath)
            this.el.dom.firstChild.src = replaceImgPath;
        this.disabled = true;
    },
    enable : function(newImgPath) {
        var replaceImgPath = newImgPath || this.imgPath;
        if (replaceImgPath)
            this.el.dom.firstChild.src = replaceImgPath;
        this.disabled = false;
    }
});
Ext.reg('imageButton', Ext.ux.ImageButton);

/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.app.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
    initComponent : function(){
        Ext.app.SearchField.superclass.initComponent.call(this);
        this.on('specialkey', function(f, e){
            if(e.getKey() == e.ENTER){
                this.onTrigger2Click();
            }
        }, this);
    },

    validationEvent:false,
    validateOnBlur:false,
    trigger1Class:'x-form-clear-trigger',
    trigger2Class:'x-form-search-trigger',
    hideTrigger1:true,
    width:180,
    hasSearch : false,
    paramName : 'query',

    onTrigger1Click : function(){
        if(this.hasSearch){
            this.el.dom.value = '';
            var o = {start: 0};
            this.store.baseParams = this.store.baseParams || {};
            this.store.baseParams[this.paramName] = '';
            this.store.reload({params:o});
            this.triggers[0].hide();
            this.hasSearch = false;
        }
    },

    onTrigger2Click : function(){
        var v = this.getRawValue();
        if(v.length < 1){
            this.onTrigger1Click();
            return;
        }
        var o = {start: 0};
        this.store.baseParams = this.store.baseParams || {};
        this.store.baseParams[this.paramName] = v;
        this.store.reload({params:o});
        this.hasSearch = true;
        this.triggers[0].show();
    }
});


Ext.form.VTypes['numericVal'] = /(^-?dd*,d*$)|(^-?dd*$)|(^-?.dd*$)/; 
Ext.form.VTypes['numericText'] = 'Not a valid number.';
Ext.form.VTypes['numericMask'] = /[-+0-9]/;
Ext.form.VTypes['numeric'] = function(v) {
	return !Ext.form.VTypes['numericVal'].test(v);
}; 
Ext.form.VTypes['floatVal'] = /(^-?dd*,d*$)|(^-?dd*$)|(^-?.dd*$)/; 
Ext.form.VTypes['floatText'] = 'Not a valid number.';
Ext.form.VTypes['floatMask'] = /[-+0-9,]/;
Ext.form.VTypes['float'] = function(v) {
	return !Ext.form.VTypes['floatVal'].test(v);
}; 

