﻿$F = function(o)
{
    return $("#" + o).val();
};

(function($)
{
    $.fn.listify = function(settings)
    {
        settings = $.extend({
            hoverClass: "over",
            cursorType: "default",
            selector: "tbody tr"
        }, settings);
        $(settings.selector, this).each(function()
        {
            $(this)
			.css("cursor", settings.cursorType)
			.hover(
				function() { $(this).addClass(settings.hoverClass) },
				function() { $(this).removeClass(settings.hoverClass) }
			);
        });
        return this;
    }
})(jQuery)

function CheckNull(text)
{ 
    if(text)
    { 
        return text;
    }
    return "";
}

function enterClick(id)
{

    if (event.keyCode == 13)
    {
        event.keyCode = 9;
        event.returnValue = false;
        $("#" + id).click();
    }
}

function SubmitKeyClick(id) {
    evt = (evt) ? evt : ((window.event) ? window.event : "")
    keyCode = evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode);
    if (keyCode == 13) {
        $("#" + id).click();
    }
} 

function IsCheckedList(checkName)
{
    return $(":checkbox[name='" + checkName + "'];[checked]:").length > 0;
}

function SetCheckedList(checkName, checked)
{
    $(":checkbox[name='" + checkName + "']:").each(function()
    {
        this.checked = checked;
    });
}

function SetCheckedListIdStart(startName, checked)
{
    $(":checkbox[id^='" + startName + "']:").each(function()
    {
        this.checked = checked;
    });
}

function SetCheckedListByIDS(ids, checked)
{
    var arr = ids.split(',');
    $.each(arr, function(i, content)
    {
        $("#" + content).attr("checked", checked);
    });
}


function SetDisabledListByIDS(ids, checked) {
    var disabled;
    if (checked) {
        disabled = true;
    }
    else {
        disabled = false;
    }
    var arr = ids.split(',');
    $.each(arr, function(i, content) {
        $("#" + content).attr("disabled", disabled);
        $("#" + content).attr("checked", false);
    });
}



function GetSelectText(id)
{
    return $("select[@id=" + id + "] option[@selected]").text();
    //return $("#" + id).text();
}

function GetSelectValue(id)
{
    //return $("select[@id=" + id + "] option[@selected]").val();
    return $("#" + id).val();
}

function GetSelectValueobject(id)
{
    //return $("select[@id=" + id + "] option[@selected]").val();
    return $("#" + id).val();
}

function SetSelect(id, value)
{
    $("#" + id + "").val(value);
}

function SetSelectByIndex(id, index)
{
    $("#" + id)[0].selectedIndex = index;
}

function AddSelect(id, value, text)
{
    $("<option value='" + value + "'>" + text + "</option>").appendTo("#" + id);
}

function AddSelectobject(id, value, text)
{
    $("<option value='" + value + "'>" + text + "</option>").appendTo("#" + id);
}

function AddSelectobject2(id, value, text,css,alertText,url)
{
    
    $("<option value='" + value + "' class='" + css + "' alertText='" + alertText + "' url='" + url + "'>" + text + "</option>").appendTo("#" + id);
}

function DeleteSelect(id, value)
{
    $("select[@id=" + id + "] option").each(function()
    {
        if ($(this).val() == value)
        {
            $(this).remove();
        }
    }
    )
}

function ClearSelect(id)
{
    $("#" + id).empty(); //清空下拉框
}

function ClearSelectobject(id)
{
    $("#" + id).empty(); //清空下拉框
}

function InsertImg(src) {
    try {
        //var html = tinyMCE.get("Intro").getContent();
        //var inst = tinyMCE.getInstanceById("Intro");
        //inst.setContent("");
        //inst.setContent(html + '<img  alt="" src="' + src + '">');
        tinyMCE.execCommand('mceInsertContent', false, '<img  alt="" src="' + src + '">');
    }
    catch (err) {
        var html = tinyMCE.get("intro").getContent();
        var inst = tinyMCE.getInstanceById("intro");
        inst.setContent("");
        inst.setContent(html + '<img  alt="" src="' + src + '">');
    }
}

//图片选择器
function ImageSelector(maxNum, name, imgDiv) {
    if (!imgDiv) imgDiv = '';
    var dlg = new $.ui.dialog({ id: 'd1', title: '\u56fe\u7247\u52a9\u624b', page: '/ImageList/?imgDiv=' + imgDiv + '&activeID=' + name + '&maxNum=' + maxNum, width: 779, height: 577, cover: true, rang: true });
    dlg.ShowDialog();
}

function SetImageSelector(maxNum, name, retvalue, imgDiv)
{
    if (!retvalue) return;

    var imageID = $("#" + name);
    var divName;
    var tempImg;
    if (imgDiv) {
        divName = imgDiv;
        tempImg = '<div class="expdiv"><div class="expbtn"></div><a href="{0}" target="_blank"><img src="{0}" alt="{1}" width="160" height="120" border="0" /></a></div>';
    }
    else {
        divName = "div" + name + "Image";
        tempImg = '<div class="expdiv"><div class="expbtn"><a attid="{2}" style="cursor:pointer" onclick="delImg(\'{3}\',this)" title="删除"></a></div><a href="{0}" target="_blank"><img src="{0}" alt="{1}" width="160" height="120" border="0" /></a></div>';
    }
    
    var divImage = $("#" + divName);
    var strImageID = imageID.val()+'';
    var strDivImage = divImage.html();
    var ids = strImageID.split(',');
    for (var k = 0; k < ids.length; k++) {
        if (parseInt(ids[k]) == parseInt(retvalue[1]))
            return;
    }
    if (strDivImage) {
        strDivImage = divImage.html();
    }

    var img = tempImg.replace(/\{0}/g, retvalue[2]).replace(/\{1}/g, retvalue[0]).replace(/\{2}/g, retvalue[1]).replace(/\{3}/g, name);

    strDivImage += img;
    divImage.html(strDivImage);
    if (strImageID == "") {
        strImageID = retvalue[1];
    }
    else {
        strImageID = strImageID + ',' + retvalue[1];
    }
    $("#" + name).val(strImageID);
    strImageID = strImageID + '';
    if (strImageID != "" && strImageID.split(',').length == maxNum) {
        $("#btn" + name).attr("disabled", true);
        return;
    }
}

//初始化图片选择器
function InitImageSelector(maxNum, name)
{
    var ids = $("#" + name).val();

    if (ids)
    {
        $.getJSON('/Ajax/Attachment/GetAttachmentNameAndImageNameByIds?ids=' + ids + '&rnd=' + Math.random(), function(json) {
            var divImage = $("#div" + name + "Image");

            var imgSrcs = json.bigImageUrls.split(',');
            var imgIds = json.ids.split(',');
            var imgNames = json.names.split(',');
            var tempImg = '<div class="expdiv"><div class="expbtn"><a attid="{2}" style="cursor:pointer" onclick="delImg(\'{3}\',this)" title="删除"></a></div><a href="{0}" target="_blank"><img src="{0}" alt="{1}" width="160" height="120" border="0" /></a></div>';

            var imgs = '';
            var i = 0;
            for (i = 0; i < imgSrcs.length; i++) {
                if (imgSrcs[i]) {
                    imgs += tempImg.replace(/\{0}/g, imgSrcs[i]).replace(/\{1}/g, imgNames[i]).replace(/\{2}/g, imgIds[i]).replace(/\{3}/g, name);
                }
            }
            if (imgIds.length == maxNum) {
                $("#btn" + name).attr("disabled", true);
            }
            divImage.html(imgs);
        });
    }
}


function DialogClose() {
    $('#dialog').dialog('close');
}

function GetDialog() {
    return $('#dialog');
}

function delImg(name, obj) {
    $(obj).parent().parent().remove();
    var id = $(obj).attr("attid");
    delHiddenImgid(name, id);
    $("#btn" + name).attr("disabled", false);
}

function delHiddenImgid(name, id) {

    var imageID = $('#' + name);
    var strImageID = imageID.val();

    if (strImageID) {
        if (strImageID.indexOf(id + ',') != -1)//在中间
        {
            strImageID = imageID.val().replace(id + ',', '');
        }
        else if (strImageID.indexOf(',' + id) != -1)//在最后
        {
            strImageID = imageID.val().replace(',' + id, '');
        }
        else if (strImageID.indexOf(id) != -1)//就一个 且存在
        {
            strImageID = '';
        }
        else //就一个 不存在
        {
            strImageID = imageID.val();
        }
    }
    else {
        strImageID = id;
    }
    imageID.val(strImageID);

    $("#" + name).val(strImageID);
    return strImageID;
}

//文件选择器
function AttachmentSelector(isSingleSelect, name) {
    var divIFrame = '<div id="dialogAttach" isSingleSelect="' + isSingleSelect + '", AttachmentSelectorName="' + name + '" title="文件选择器"><iframe src="/AttachmentList/" width="100%" height="400" frameborder="0" scrolling="no" title="文件选择器"></iframe>{0}</div>';
    divIFrame = divIFrame.replace('{0}', '<Script type="text/javascript"> $(document).ready(function() {     $("#dialogAttach").dialog({   bgiframe: true,   autoOpen: false, width:600,  height: 550,   modal: true,   buttons: {   "关闭": function() { $(this).dialog("close"); }   }     }); });  	</script>');
    var objDivIFrame = document.getElementById('dialogAttach');
    if (!objDivIFrame) {
        $(document.body).append(divIFrame);
    }
    $('#dialogAttach').attr("isSingleSelect", isSingleSelect);
    $('#dialogAttach').attr("AttachmentSelectorName", name);

    $('#dialogAttach').dialog('open');
}

function DialogAttachClose()
{
    $('#dialogAttach').dialog('close');
}


function GetDialogAttach()
{
    return $('#dialogAttach');
}

function SetAttachmentSelector(isSingleSelect, name, retvalue) {

    if (!retvalue) return; 
    var attachemetID = $("#" + name);
    var attachemetName = $("#" + name + "AttachmentName");
    //    var attachemetName = $("#AttachmentName");
    var strAttachemetID = attachemetID.val();
    var strAttachemetName = attachemetName.val();
    
    if (!isSingleSelect)
    {
        if (strAttachemetID)
        {
            if (strAttachemetID.indexOf(retvalue[1] + ',') != -1)
            {
                attachemetID.val(attachemetID.val().replace(retvalue[1] + ',', '') + ',' + retvalue[1]);
                attachemetName.val(attachemetName.val().replace(retvalue[0] + ',', '') + ',' + retvalue[0]);
            }
            else if (strAttachemetID.indexOf(',' + retvalue[1]) != -1)//在最后
            {
                attachemetID.val(attachemetID.val().replace(',' + retvalue[1], '') + ',' + retvalue[1]);
                attachemetName.val(attachemetName.val().replace(',' + retvalue[0], '') + ',' + retvalue[0]);
            }
            else if (strAttachemetID.indexOf(retvalue[1]) != -1)//就一个 且存在
            {
                attachemetID.val(retvalue[1]);
                attachemetName.val(retvalue[0]);
            }
            else //就一个 不存在
            {
                attachemetID.val(attachemetID.val() + ',' + retvalue[1]);
                attachemetName.val(attachemetName.val() + ',' + retvalue[0]);
            }

        }
        else
        {
            attachemetID.val(retvalue[1]);
            attachemetName.val(retvalue[0]);
        }

    }
    else
    {
        attachemetName.val(retvalue[0]);
        attachemetID.val(retvalue[1]);

    }
}


function checkStrong(sPW) {
    Modes = 0;
    for (i = 0; i < sPW.length; i++) {
        Modes |= CharMode(sPW.charCodeAt(i));
    }
    return bitTotal(Modes);
}

function CharMode(iN) {
    if (iN >= 48 && iN <= 57) //数字 
        return 1;
    if (iN >= 65 && iN <= 90) //大写字母 
        return 2;
    if (iN >= 97 && iN <= 122) //小写 
        return 4;
    else
        return 8; //特殊字符 
}

function bitTotal(num) {
    modes = 0;
    for (i = 0; i < 4; i++) {
        if (num & 1) modes++;
        num >>>= 1;
    }
    return modes;
}

function checkPasswod() {

    var csint = checkStrong($(this).val());

    if (csint == 0) {
        $('#hint').css({ 'color': '#C00' }).html('弱');
        $('#s').css({ background: '#fff' });
    }
    else if (csint==1)
    {
        $('#hint').css({ 'color': '#C00' }).html('弱');
        $('#s').css({ background: '#C00', width: '50px', height: '10px' });
    }
    else if (csint == 2)
    {
        $('#hint').css({ 'color': '#F90' }).html('中等');
        $('#s').css({ 'background': '#F90', 'width': '100px', 'height': '10px' });
    }
    else if (csint == 3)
    {
        $('#hint').css({ 'color': '#060' }).html('强');
        $('#s').css({ 'background': '#060', 'width': '150px', 'height': '10px' });
    }
    else
    {
        $('#hint').css({ 'color': '#060' }).html('超强');
        $('#s').css({ 'background': '#060', 'width': '200px', 'height': '10px' });
    }
}

function GetModifier(table, id) {
    $.post("/Ajax/Log/GetModifier/", { table: table, id: id }, function(json) {
        if (json) {
            $('#Modifier').text(json);
            $('#Modifier').css("color", "blue");
        }
        else {
            $('#Modifier').text("暂无修改者！");
            $('#Modifier').css("color", "blue");
        }
    }, "json");
}

function ShowModifier(table) {
    $("td[id]").each(function() {
        var td = $(this);
        var id = $(this).attr("id");
        $.ajax({ type: "POST",
            url: "/Ajax/Log/GetModifier/",
            data: "table=" + table + "&id=" + id,
            async: false,
            dataType: "json",
            success: function(json) {
                if (json) {
                    td.text(json);
                    td.show();
                }
                else {
                    td.text("");
                    td.show();
                }
            }
        }
       );

    });
    if ($("#btnShowModifier").val() == "显示修改者") {
        $("#btnShowModifier").val("隐藏修改者");
        $("td").show();
        $("#modifier").show();
    } else if ($("#btnShowModifier").val() == "隐藏修改者") {
    $("#btnShowModifier").val("显示修改者");
        $("td[id]").hide();
        $("#modifier").hide();
    }
}

$(document).ready(function() {
    $(function() {
        var maxwid = 295, maxhei = 300;
        $(".img_Show_295_300").each(function() {
            if ($(this).width() > maxwid || $(this).height() > maxhei) {
                if ($(this).width() > maxwid && ($(this).width() / maxwid > $(this).height() / maxhei)) {
                    $(this).width(maxwid);
                    $(this).height(maxwid / $(this).width() * $(this).height());
                } else if ($(this).height() > maxhei && ($(this).width() / maxwid < $(this).height() / maxhei)) {
                    $(this).height(maxhei);
                    $(this).width(maxhei / $(this).height() * $(this).width());
                } else {
                    $(this).height(maxwid / $(this).width() * $(this).height());
                    $(this).width(maxhei / $(this).height() * $(this).width());
                }
            }
        })
    })
})

eval(function(p, a, c, k, e, d) { e = function(c) { return (c < a ? "" : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) d[e(c)] = k[c] || e(c); k = [function(e) { return d[e] } ]; e = function() { return '\\w+' }; c = 1; }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p; } ('0 2=A;k B(g){v(!2){0 f=\'<z E="9" F="C" D="u" d="n:o.7=\\\'/5?w=6&h=8&l=4&\\\'+1.3();" m="p: s; t-q: r; c-b: M; *c-b: e;!N; *c-b: e;" /><j><a O="#" d="$(\\\'#9\\\').i(\\\'7\\\',\\\'/5?w=6&h=8&l=4&\\\'+1.3())"></a></j>\';$(f).K("#"+g);$("#9").i("7","/5?w=6&h=8&l=4&"+1.3());2=J}};k L(){0 x=G;0 y=I;P x*x*y}', 52, 52, 'var|Math|isCreateCheckImage|random||CheckCode|85|src|28|imgCheckCode||top|margin|onclick|2px|strImg|txtCheckImage||attr|span|function||style|JavaScript|this|cursor|align|middle|pointer|vertical|code|if||||img|false|CreateCheckImage|点击更换验证码|class|id|alt|56||23|true|insertAfter|InterferenceAlgorithm|0px|important|href|return'.split('|'), 0, {}))

