
var lockAuotGetKeyword = false;
function auotGetKeyword(trigger, target, url) {
    jQuery(trigger).click(function () {
        if (lockAuotGetKeyword) { return; }
        var temp = "";
        var original = jQuery(target).val();
        jQuery(":text:visible,textarea:visible").each(function () {
            temp += jQuery(this).val();
        });

        jQuery("textarea[name$='EditorContent']").each(function () {
            var ckeditor = jQuery(this).attr("id") + '$$ckeditor$$obj';
            if (ckeditor) { temp += eval(ckeditor).getData(); }
        });
        temp = temp.replace(/<[^>].*?>/g, "");
        var xtext = { type: "auotGetKeyword", source: temp };
        var xmlDoc = jQuery.CreateXmlDoc(xtext);
        jQuery.ajax({
            url: url,
            type: "post",
            data: xmlDoc,
            processData: false,
            beforeSend: function () {
                jQuery(target).val("正在提取关键字，请稍后...");
                jQuery(target).attr("disabled", true);
                lockAuotGetKeyword = true;
            },
            success: function (data) {
                var keyword = data.getElementsByTagName("keyword")[0].firstChild;
                if (keyword) {
                    jQuery(target).val(keyword.data);
                }
                else {
                    jQuery(target).val('');
                }
            },
            error: function () {
                alert("很抱歉，请求出错，请重试.");
                jQuery(target).val(original);
            },
            complete: function () {
                jQuery(target).attr("disabled", false);
                lockAuotGetKeyword = false;
            }
        });
    });
}