//选择图标
; RoadUI.SelectIco = function (options) {
    var instance = this;
    var defaults = {
        obj: null,
        x: true
    };

    this.opts = $.extend(defaults, options);
    var $source = $(this.opts.obj);
    var validate = $source.attr('validate');
    var val = $source.val();
    var id = $source.attr('id');
    var name = $source.attr('name');
    var more = $source.attr('more');
    var source = $source.attr("source");
    var title = $source.attr("title");
    var isimg = $source.attr("isimg") || "1";//是否选图片图标
    var isfont = $source.attr("isfont") || "1";//是否选字体图标
    if (title === null || title == undefined) title = "选择图标";


    if (name === null || name == undefined) name = id;
    more = more === null || more == undefined ? "0" : more.toLowerCase() === "true" || more == "1" ? "1" : "0";
    source = source === null || source == undefined ? "/RoadFlowResources/images/ico" : source;

    $source.removeClass().addClass("text1");
    $source.css({
        "border-right": "0", "border-left": "0", "border-radius": "0", "-webkit-border-radius": "0"
    });
    $source.prop("readonly", true);
    //$source.css({ "background-position-x": "3px", "color": "#666", "background-image": "url(" + RoadUI.Core.rooturl() + RoadUI.Core.rfPath + val + ")", "background-repeat": "no-repeat", "padding-left": "23px", "background-position-y": "center" });
    var $button = $('<button type="button" style="border:1px solid #b7b6b4;width:30px;border-radius:4px 0 0 4px;height:25px;vertical-align: middle;"></button>')
    var $but = $('<input type="button" class="mybutton" style="margin:0;border-radius: 0 4px 4px 0; -webkit-border-radius: 0 4px 4px 0;" value="选择" />');
    var $label = $('<label type="msg"></label>');

    if (val && $.trim(val).length > 0) {
        if ($.trim(val).substr(0, 2) == "fa") {
            $button.append('<i style="font-size:14px;" class="fa ' + val + '"></i>');
        } else {
            $button.append('<img src="' + val + '" />');
        }
    }

    if ($source.prop("disabled")) {
        $but.prop("disabled", true);
    }
    else {
        $but.bind('click', function () {
            var $obj1 = $(this).prev();
            var openerattr = $obj1.attr("opener") || "";
            var openerid = $obj1.attr("openerid") || (RoadUI.Core.queryString("tabid") || "");
            new RoadUI.Window().open({
                id: "ico_" + id, title: title, width: 800, height: 506,
                openerid: openerid,
                opener: openerattr ? eval(openerattr) : null,
                url: RoadUI.Core.rooturl() + '/RoadFlowCore/Controls/SelectIco_Index?more=' + more + '&id=' + id + '&source=' + source + '&values=' + val + "&isfont=" + isfont + "&isimg=" + isimg, openerid: RoadUI.Core.queryString("tabid")
            });
        });
    }
    $source.before($button);
    $source.after($but, $label);
    this.setIco = function ($obj, ico) {
        if (!ico) {
            ico = $obj.val();
        }
        var $button = $obj.prev();
        if (ico && $.trim(ico).length > 0) {
            if (ico && $.trim(ico).substr(0, 2) == "fa") {
                $button.html('').append('<i style="font-size:14px;" class="fa ' + $.trim(ico) + '"></i>');
            }
            else {
                $button.html('').append('<img src="' + $.trim(ico) + '" />');
            }
        }
    }
};