jQuery.fn.hint_box = function(options){
    this.each(function(index){
        if(this.tagName == "INPUT"){
            var show_hint = function(){
                var args  = {};
                var url   = window.location;
                var rfunc = null;

                if(typeof(options) != "undefined"){
                    if(typeof(options.args) == "function"){
                        args  = options.args.apply(this);
                        url   = options.url;
                    }
                    else if(typeof(options.args) == "object"){
                        args  = options.args;
                        url   = options.url;
                    }
                    if(typeof(options.rfunc) == "function"){
                        rfunc = options.rfunc;
                    }
                }

                if(rfunc == null){
                    rfunc = function(data){
                        var code = "";
                        for(var i in data){
                            code += "<span style=\"display: block; white-space: nowrap; overflow: hidden;\">"+ data[i] +"</span>";
                        }
                        $hint.html(code);
                        if(code != ""){
                            $hint.css("width", $txt.width() + parseInt($txt.css("padding-left")) + parseInt($txt.css("padding-right")));
                            $hint.show();
                        }
                    }
                }

                args["hint_box"]    = 1;
                args["hint_name"]   = $txt.attr("name");
                args["hint_value"]  = $txt.attr("value");

                jQuery.post(url, args, function(data){ rfunc.apply($hint.eq(0), [data]); }, "json");
            }
            var hide_hint = function(){
                setTimeout("$(\"#" + id + "_hint_box_" + index +"\").hide()", 20);
            }
            var click_hint = function(event){
                $txt.val($(event.target).html());
            };

            var id = "";
            if(typeof(options) != "undefined" && typeof(options.id) != "undefined"){
                id = options.id;
            }
            if(typeof(options) != "undefined" && typeof(options.cfunc) == "function"){
                click_hint = options.cfunc;
            }

            $(this).wrap("<div/>");
            $(this).after("<div id=\"" + id + "_hint_box_"+ index +"\" class=\"hint_box\" style=\"display: none; position: absolute;\">Hint</div>");

            var $txt  = $(this);
            var $hint = $txt.next();

            $txt.attr("autocomplete", "off");
            $hint.css("overflow", "auto");

            $(this).blur(hide_hint);
            $(this).focus(show_hint);
            $(this).keyup(show_hint);
            $hint.mousedown(click_hint);
        }
    });
    return this;
};

jQuery.fn.auto_upload = function(options){
    this.each(function(){
        if(this.tagName == "INPUT" && this.type == "file"){
            $(this).wrap("<div />");
            $(this).change(function(){
                var frame_id = Math.round(Math.random() * 1000000);
                var $box     = $(this).parent();
                var $input   = $(this);
                var $copy    = $(this).clone(true);

                if(typeof(options) != "object"){
                    options = {};
                }

                $("body").append(
                    "<div class=\"auto_upload\">" +
                    "<iframe name=\"file_load_"+ frame_id +"\" style=\"display: none;\" src=\"javascript:\"></iframe>" +
                    "<form style=\"display:none;\" method=\"post\" enctype=\"multipart/form-data\" target=\"file_load_"+ frame_id +"\" action=\"\">" +
                    "<input type=\"hidden\" name=\"auto-upload-submit\" value=\"1\" />"+
                    "<input type=\"hidden\" name=\""+ this.name +"\" value=\"1\" />"+
                    "</form>" +
                    "</div>"
                );
                $("body > div.auto_upload:last > iframe").load(function(){
                    if(typeof(options.complete) == "function"){
                        options.complete.apply($copy, [$(this).contents().find('html body').html()]);
                    }
                });
                $("body > div.auto_upload:last > form").append($input);

                $box.html($copy);
                if(typeof(options.begin) == "function"){
                    options.begin.apply($copy);
                }
                $("body > div.auto_upload:last > form").submit();
            });
        }
    });
    return this;
};

