(function($){

    jQuery.fn.recall = function(){

        var options = jQuery.extend({
            title   : false,
            url     : false
        }, options);

        return this.each(function() {

            jQuery(this).click(function(){

                if (options.url===false) {
                    options.url = jQuery(this).attr('href');
                }
                if (options.title===false) {
                    options.title = jQuery(this).text();
                }

                options.url = options.url + '?no_html=1';

                jQuery.get(options.url, function(html) {
                    jQuery("body").append(html);
                    var recall = jQuery("#recall");
                    recall.find("p.recall-send").hide();
                    recall.dialog({
                        resizable: false,			
                        modal: true,
                        buttons: [
                        {
                            text: "Отправить",
                            click: function() {
                                var ser = jQuery(this).find("form").serialize();
                                jQuery.post(options.url, ser, function(html){
                                    recall.html(jQuery(html).html());
                                    recall.find("p.recall-send").hide();
                                    if (recall.find(".msg").text()!='') {
                                        recall.dialog({buttons: [{ text: "Закрыть",  click: function() { jQuery(this).dialog("close"); }}]});
                                    }
                                }, 'html');
                            }
                        }
                        ]
                    });
                }, 'html');
                return false;
            });
        });

    };

})(jQuery);
