﻿function enter_Login() {
    if (event.keyCode == 13) {
        $('#loginform').submit();
    }
}

function enter() {
    if (event.keyCode == 13) {
        $('#loginform2').submit();
    }
}

var dlg;

$(function () {
    $("img").fullsize();

    $(".xdialog").each(function () {
        var url = $(this).attr("href");
        $(this).attr("href", "#");
        $(this).click(function () {
            return showdialog(url);
        });
    });

    unreadnotify();

    setInterval(unreadnotify, 60000);
});

function showdialog(url) {
    dlg = new Dialog({
        type: 'iframe',
        value: url
    });
    dlg.show();
    return false;
}

function closedialog(url) {
    if (url == null || url == '') {
        var s = '' + parent.document.location;
        var i = s.indexOf('#');
        if (i > 0) s = s.substring(0, i);
        parent.document.location = s;
    }
    else
        parent.document.location = url;
}

function pickdate(id) {
    $(id).datepicker({
        dateFormat: 'yy-mm-dd',
        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
    });
}

function filloption1(id, data) {
    var s = '<option value=""></option>';
    for (var i in data) s += '<option value="' + data[i] + '">' + data[i] + '</optoin>';
    $(id).html(s);
}

function filloption2(id, data) {
    var s = '<option value="0"></option>';
    for (var i in data) s += '<option value="' + i + '">' + data[i] + '</optoin>';
    $(id).html(s);
}

var hasblink = 0;
var oldtitle = '';
var titlestep = false;
function unreadnotify() {
    $.ajax({
        url: '/Home/UnreadNotify',
        cache: false,
        success: function (data) {
            if (data == '0') {
                $('#unreadcount').text('');
                $('#unreadcount').hide();
                if (hasblink != 0) {
                    $('#unreadcount').clearblink();
                    document.title = oldtitle;
                    clearInterval(hasblink);
                    hasblink = 0;
                }
            } else {
                $('#unreadcount').text('(' + data + ')');
                $('#unreadcount').show();
                if (hasblink == 0) {
                    $('#unreadcount').blink();
                    oldtitle = document.title;
                    hasblink = setInterval(function () {
                        titlestep = !titlestep;
                        document.title = (titlestep ? '【　　　】' : '【新提醒】') + oldtitle;
                    }, 500);
                }
            }
        }
    });
}
