with (SaleItemsForm = function(placeholder, resources){
    //init
    this.placeholder = placeholder;
    this.resources = resources;
    this.statusButton = placeholder.find('.enableButton');
    this.saveButton = placeholder.find('.saveButton');
    this.checkbox = placeholder.find('.enableCheckbox');
    this.statusPicture = placeholder.find('.itemStatusPic');

    // initial styling
    this.handleStatusChange();
    
    var t = this;
    
    this.statusButton.click(function(e){
        e.preventDefault();
        t.invertStatus();
        t.handleStatusChange();
        t.saveData(true);
    });
    
    this.saveButton.click(function(e){
        e.preventDefault();
        
        var res = t.placeholder.validatorRun();
        
        // ignore validation if item disabled or die
        if (!res && t.readStatus() != 0) {
            return;
        }
        
        t.saveData(true);
        $(e.target).hide();
    });
    
    this.placeholder.find('.fieldData').each(function(){
        if (!$(this).val()) {
            t.disableSaveButton = true;
        }
    })

    this.placeholder.find('.fieldData, .fieldCost').each(function(){        
        $(this).bind('change keyup', function(e){
            var control = $(e.target);
            t.handleControlChange.call(t, control);
        });
    })
}) {
    // example:
    prototype.resources = {
        'langButtonEnable': 'Enable',
        'langButtonDisable': 'Disable',
        'langAjaxError': 'Ajax failed',
        'imageDisabled': '/img/cross.png',
        'imageEnabled': '/img/tick.png',
        'imageAjax': '/img/ajax_loading.gif'
    };
    prototype.placeholder = null;
    prototype.statusButton = null;
    prototype.saveButton = null;
    prototype.checkbox = null;
    prototype.statusPicture = null;
    prototype.ajaxEngineData = {};
    prototype.disableSaveButton = false;

    prototype.handleStatusChange = function()
    {
        var status = this.readStatus();

        if (status) {
            this.statusButton.text(this.resources.langButtonDisable);
            this.placeholder.addClass('itemEnabled');
            this.statusPicture.attr('src', this.resources.imageEnabled);

            this.placeholder.validatorDisable();
        } else {
            this.statusButton.text(this.resources.langButtonEnable);
            this.placeholder.removeClass('itemEnabled');
            this.statusPicture.attr('src', this.resources.imageDisabled);

            this.placeholder.validatorEnable();
        }
    }
    
    prototype.handleControlChange = function(control)
    {
        // if field was empty on load, do not show save button.
        if (this.disableSaveButton) {
            return;
        }
        
        this.saveButton.show();
    }

    prototype.readStatus = function()
    {
        if (this.checkbox.is(':checked')) {
            return 1;
        } else {
            return 0;
        }
    }

    prototype.invertStatus = function()
    {
        var status = this.readStatus();
        if (status) {
            this.checkbox.removeAttr('checked');
        } else {
            this.checkbox.attr('checked', 'checked');
        }
    }

    prototype.saveData = function(showSpin)
    {
        if (!delay) {
            var delay = 0;
        }
        
        var params = {};
        params['do'] = 'updateitemsajax';
        params['id'] = this.placeholder.find('.fieldId').val();
        params['data'] = this.placeholder.find('.fieldData').val();
        params['cost'] = this.placeholder.find('.fieldCost').val();
        params['enabled'] = this.readStatus();
        params['type'] = this.placeholder.find('.fieldType').val();

        if (this.isChanged(params)) {
            if (showSpin) {
                this.statusPicture.attr('src', this.resources.imageAjax);
            }

            var t = this;    
            $.post('action.php', params, function(data){
                if (data == 1) {
                    t.handleStatusChange();
                    t.saveButton.hide();
                    t.disableSaveButton = false;
                } else {
                    alert(t.resources.langAjaxError);
                }
            });
            
            this.ajaxEngineData['lastSnapshot'] = this.getSnapshot(params);
        }
    }

    // some ajax tools
    prototype.isChanged = function(data)
    {
        var last = this.ajaxEngineData['lastSnapshot'];
        var current = this.getSnapshot(data);
        if (last != current) {
            return true;
        } else {
            return false;
        }
    }
    prototype.getSnapshot = function(data)
    {
        var hash = '';
        for(i in data) {
            hash += data[i];
        }
        return hash;
    }
}