/**
 * @extends SyqComponent
 */
function SyqComponent_fileupload()
{
    this.select = new SyqEvent;
    this.complete = new SyqEvent;
    this.filterNotMatch = new SyqEvent;

    this.saveImgSrc = null;

    this.init = function()
    {
    }

    this.reset = function()
    {
        this.q('#fileName').val('');
        this.q('#tempFileName').val('');
        this.q('#form').removeClass('uploading');
        this.q('#form').removeClass('uploaded');
    };

    this.form_mousemove = function(e)
    {
        if (!this.q('#enable').val()) return;

        var form = this.q('#form');
        this.q('#file').css({
            top: e.pageY-form.offset().top+'px',
            left: e.pageX-form.offset().left+'px'
        });
    };

    this.file_change = function(e)
    {
        this.reset();
        this.q('#fname').html(this.q('#file').val());

        var filter = this.q('#filter').val();
        if (filter!='')
        {
            var re = new RegExp(filter,'i');
            if (!re.test(this.q('#file').val()))
            {
                this.filterNotMatch.call();
                this.reset();
                return false;
            }
        }

        if (!this.select.call(this.q('#file').val())) return false;

        this.q('#form').addClass('uploading');

        this.q('#enable').val('');

        this.q('#form').submit();

        var self = this;
        var frame = this.q('#frame');
        frame.unbind().load(function() {
            var response = $(frame[0].contentWindow.document.body).text();
            self.q('#form').removeClass('uploading');
            self.q('#form').addClass('uploaded');
            self.q('#fileName').val(self.q('#file').val());
            self.q('#tempFileName').val(response);

            self.q('#enable').val('1');

            self.complete.call(response);
            self.q('#file').show();
        });

        this.q('#file').hide();
    };

    this.setImage = function(url)
    {
        if (url) return this.q('#form img').attr('src',url).fadeIn();
        return this.q('#form img').fadeOut();
    };

    this.enable = function(isEnable)
    {
        this.q('#enable').val(isEnable ? '1':'');
    }
};
SyqComponent_fileupload.prototype = new SyqComponent;