/**
 * Extends BasicForm adding support non-ajax browser form submission.
 *
 * @author Jonathan Griffin
 */
Ext.override(Ext.form.BasicForm, {
    initEl: function(el) {
        this.el = Ext.get(el);
        this.id = this.el.id || Ext.id();
        if (!(this.ajaxSubmit == false)) {
            this.el.on('submit', this.onSubmit, this);
        }
        this.el.addClass('x-form');
    },
    
    submit: function(options) {
        if (this.ajaxSubmit == false) {
            this.el.dom.action = this.url;
            this.el.dom.submit();
        } else {
            this.doAction('submit', options);
        }
        return this;
    }
});

/**
 * Extends FormLayout adding support on destroy() to clean up field labels.
 *
 * @author Jonathan Griffin
 */
Ext.override(Ext.layout.FormLayout, {
    renderItem : function(c, position, target){
        if(c && !c.rendered && c.isFormField && c.inputType != 'hidden'){
            var args = [
                   c.id, c.fieldLabel,
                   c.labelStyle||this.labelStyle||'',
                   this.elementStyle||'',
                   typeof c.labelSeparator == 'undefined' ? this.labelSeparator : c.labelSeparator,
                   (c.itemCls||this.container.itemCls||'') + (c.hideLabel ? ' x-hide-label' : ''),
                   c.clearCls || 'x-form-clear-left' 
            ];
            if(typeof position == 'number'){
                position = target.dom.childNodes[position] || null;
            }
            if(position){
                c.formItem = this.fieldTpl.insertBefore(position, args, true);
            }else{
                c.formItem = this.fieldTpl.append(target, args, true);
            }
            c.render('x-form-el-'+c.id);
            c.container = c.formItem; // must set after render, because render sets it.
            c.actionMode = 'container';
        }else {
            Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
        }
    }
});

/**
 * Extends BoxComponent adding component support for a managed IFrame.
 *
 * @author Jonathan Griffin
 */
Ext.ux.IFrameComponent = function(config) {
    Ext.apply(this, {
        width: config.width,
        height: config.height
    });
    Ext.ux.IFrameComponent.superclass.constructor.apply(this, arguments);
};
Ext.extend(Ext.ux.IFrameComponent, Ext.BoxComponent, {
     onRender : function(ct, position){
          this.el = ct.createChild({tag: 'iframe', id: 'iframe-'+ this.id, frameBorder: 0, src: this.url, width: this.width, height: this.height});
     }
});
