﻿(function ($)
{
    $.widget("ui.combobox", {
        _create: function ()
        {
            var self = this,
					select = this.element.hide(),
					selected = select.children(":selected"),
					value = selected.val() ? selected.text() : "";
            var input = this.input = $("<input>")
					.insertAfter(select)
                    .attr("id", select.attr("id") + "_A")
					.val(value)
                    .attr("readonly", true)
					.autocomplete({
					    delay: 0,
					    minLength: 0,
					    source: function (request, response)
					    {
					        var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
					        response(select.children("option").map(function ()
					        {
					            var text = $(this).text();
					            if (this.value && (!request.term))
					                return {
					                    label: text.replace(
											new RegExp(
												"(?![^&;]+;)(?!<[^<>]*)(" +
												$.ui.autocomplete.escapeRegex(request.term) +
												")(?![^<>]*>)(?![^&;]+;)", "gi"
											), "<strong>$1</strong>"),
					                    value: text,
					                    option: this
					                };
					        }));
					    },
					    select: function (event, ui)
					    {
					        ui.item.option.selected = true;
					        self._trigger("selected", event, {
					            item: ui.item.option
					        });
					        select.trigger("change");
					    },
					    change: function (event, ui)
					    {
					        if (!ui.item)
					        {
					            var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i"),
									valid = false;
					            select.children("option").each(function ()
					            {
					                if ($(this).text().match(matcher))
					                {
					                    this.selected = valid = true;
					                    return false;
					                }
					            });
					            if (!valid)
					            {
					                // remove invalid value, as it didn't match anything
					                $(this).val("");
					                select.val("");
					                input.data("autocomplete").term = "";
					                return false;
					            }
					        }
					    }
					})
					.addClass("ui-widget ui-widget-content ui-corner-left");

            input.data("autocomplete")._renderItem = function (ul, item)
            {
                return $("<li></li>")
						.data("item.autocomplete", item)
						.append("<a>" + item.label + "</a>")
						.appendTo(ul);
            };

            this.button = $("<button type='button'>&nbsp;</button>")
					.attr("tabIndex", -1)
					.attr("title", "Show All Items")
					.insertAfter(input)
					.button({
					    icons: {
					        primary: "ui-icon-triangle-1-s"
					    },
					    text: false
					})
					.removeClass("ui-corner-all")
					.addClass("ui-corner-right ui-button-icon")
					.click(function ()
					{
					    if (input.autocomplete("widget").is(":visible"))
					    {
					        input.autocomplete("close");
					        return;
					    }
					    input.autocomplete("search", "");
					    input.focus();

					    //					    var vt = $.trim(input.val());
					    //					    input.autocomplete("widget").children("li").each(function ()
					    //					    {
					    //					        var s = $.trim($(this).text());
					    //					        if (vt == s)
					    //					        {
					    //                                $(this).first().css("font-weight", "bold");
					    //					        }
					    //					    })
					});
        },
        destroy: function ()
        {
            this.input.remove();
            this.button.remove();
            this.element.show();
            $.Widget.prototype.destroy.call(this);
        }
    });
})(jQuery);
function toJSON(o)
{
    if (o == undefined || o == null) { return "null"; } switch (o.constructor.toString().split(" ")[1])
    {
        case "String()": var v = []; for (var i = 0; i < o.length; i++) { var c = o.charAt(i); if (c >= " ") { if (c == "\\" || c == '"') { v.push("\\"); } v.push(c); } else { switch (c) { case "\n": v.push("\\n"); break; case "\r": v.push("\\r"); break; case "\b": v.push("\\b"); break; case "\f": v.push("\\f"); break; case "\t": v.push("\\t"); break; default: v.push("\\u00"); v.push(c.charCodeAt().toString(16)); } } } return '"' + v.join('') + '"';
        case "Array()": var v = []; for (var i = 0; i < o.length; i++) { v.push(toJSON(o[i])); } return "[" + v.join(",") + "]";
        case "Number()": if (isFinite(o)) { return o.toString(); } else { return toJSON(null); }
        case "Boolean()": return o.toString();
        case "Date()": return __date(o);
        default: if (typeof o == "object") { var v = []; for (attr in o) { if (typeof o[attr] != "function") { v.push('"' + attr + '":' + toJSON(o[attr])); } } if (v.length > 0) { return "{" + v.join(",") + "}"; } return "{}"; } return o.toString();
    }
}
function setDftMsgBox(isCfm, text, callback, elem) { if (isCfm) { $("#dftMsgBox").dialog({ dialogClass: 'confirm', buttons: { "取消": function () { $(this).dialog('close'); }, "确定": function () { callback.call(); } } }); } else { $("#dftMsgBox").dialog({ dialogClass: 'alert', buttons: { "确定": function () { $(this).dialog('close'); if (elem != null && elem != undefined) { $("#" + elem).focus(); } } } }); } $("#dftMsgBox").text(text > 100 ? text.substr(0, 100) : text); }
document.write("<div id='dftMsgBox' title='提示信息' style='display:none;'></div>");
$(function () { $("#dftMsgBox").dialog("destroy"); $("#dftMsgBox").dialog({ width: 300, height: 140, modal: true, resizable: false, autoOpen: false, buttons: { "确定": function () { $(this).dialog('close'); } } }); });
function getStrLength(s, m) { var res = {}; res.O = s.length; res.Q = s.replace(/[^\x00-\xff]/g, "**").length; res.L = 0; var l = 0; for (var i = 0; i < res.O; i++) { if (s.substr(i, 1).charCodeAt(0) < 299) { l++; } else { l += 2; } if (l > m) { break; } else { res.L++; } } return res; }
function changeItem()
{
    var val = $("#ItemSel").val();
    switch (val)
    {
        case "10":
            window.open("http://cms.langxunedu.com/Info/Experience.shtml");
            break;
        case "20":
            window.open("222222222");
            break;
        case "30":
            window.open("http://cms.langxunedu.com/Support.shtml");
            break;
    }
}
function initBasePG()
{
    $("#ItemSel").change(function () { changeItem(); }).combobox();
    $("#ItemSel").val(null);
    $("#ItemSel_A").val("请问我吧");
    $("#ItemSelDiv").show();
}
$(function () { initBasePG(); });
