google.load('jquery', '1.3');

var Common = {
    confirm : function(a,b){
        return window.confirm(a,b)
    },
    msg : {
        msgTimeout : {},
        default_msgbox : 'msg',
        show : function(msg, msgbox, autofade){
            if (arguments.length == 2)
                autofade = 5000;
            if (autofade) autofade = 5000;
            if (!msgbox) msgbox = this.default_msgbox;
            this.clearTimeout(msgbox);
            $('#'+msgbox).html(msg).fadeIn();
            if (autofade){
                this.msgTimeout[msgbox] = setTimeout(function(){
                    $('#'+msgbox).fadeOut();
                }, autofade);
            }
        },
        hide : function(msgbox){
            if (!msgbox) msgbox = default_msgbox;
            this.clearTimeout(msgbox);
            $('#'+msgbox).fadeOut();
        },
        clearTimeout : function(msgbox){
            if (this.msgTimeout[msgbox])
                window.clearTimeout(this.msgTimeout[msgbox]);
            delete this.msgTimeout[msgbox];
        },
        showerror : function(msg, msgbox, autofade){
            $('#'+msgbox).css('background-color', '#fea');
            Common.msg.show(msg, msgbox, autofade);
            if (this.showerror.timeout_id)
            {
                clearTimeout(this.showerror.timeout_id);
                delete this.showerror.timeout_id;
            }
            this.showerror.timeout_id = setTimeout(function(){
                $('#'+msgbox).animate({backgroundColor:'white'}, 500);
                delete Common.msg.showerror.timeout_id;
            }, 1500);
        }
    },
    textarea : {
        getSelection : function(textarea){
            selectionStart = textarea.selectionStart;
            selectionEnd = textarea.selectionEnd;
            before = textarea.value.substr(0, textarea.selectionStart);
            selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
            after = textarea.value.substr(textarea.selectionEnd);
            return {
                selectionStart : selectionStart,
                selectionEnd : selectionEnd,
                before : before,
                selection : selection,
                after : after,
                wrap : function(prefix, suffix) {
                    textarea.value = before + prefix + selection + suffix + after;
                    textarea.select();
                    textarea.selectionEnd = selectionEnd + prefix.length;
                    textarea.selectionStart = selectionStart + prefix.length;
                }
            }
        }
    }
};

google.setOnLoadCallback(function (){

});
