﻿//使用Jquery 的Ajax和Dialog
$.ui.dialog.defaults.bgiframe = true;
$.ui.dialog.defaults.autoOpen = false;
$.ui.dialog.defaults.modal = true;

$AjaxCompleteUnblockUI = true;

$(function(){
    if ($.datepicker)
        $.datepicker.setDefaults({changeMonth: true, changeYear: true, dateFormat: 'yy-mm-dd'});

    $.ajaxSetup({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: 'json',
        beforeSend: function() {$AjaxCompleteUnblockUI = true; $.blockUI({ message: "<h3>Please wait...</h3>"}); },
        error: function(xhr) {if (xhr.status == 0) return; alert("ERROR: " + xhr.status + "-" + xhr.statusText); $.unblockUI({fadeOut: 1000});},
        complete: function() {if ($AjaxCompleteUnblockUI) $.unblockUI({fadeOut: 1000}); }
    });

    $("div tr[class=gridrow]").hover(
        function(){ $(this).children('td').addClass("hover"); },
        function(){ $(this).children('td').removeClass("hover"); }
    );

    $(".btn").hover(
        function(){ $(this).addClass("btnHover"); },
        function(){ $(this).removeClass("btnHover"); }
    );
    $('.pager a, .blockUI').click(function() { _showBlock();});
    $('.entry p span[style]').removeAttr("style");
    $('.article p span[style]').removeAttr("style");
    setTimeout(_kt, 60000);
});
function _showBlock() { $.blockUI({ message: "<h3>Please wait...</h3>"}); }
function _hideBlock() {
    $.unblockUI();
    $("div tr[class=gridrow]").hover(
        function(){ $(this).children('td').addClass("hover"); },
        function(){ $(this).children('td').removeClass("hover"); }
    );
    $('.pager a, .blockUI').click(function() { _showBlock();});
    $(".btn").hover(
        function(){ $(this).addClass("btnHover"); },
        function(){ $(this).removeClass("btnHover"); }
    );
}
function __ShowProperties(obj) {
    if (!obj) alert("Is null");
    var win = window.open("");
    var doc = win.document;
    __ShowProperites2(doc, "", obj);
    doc.close();
}
function __ShowProperites2(doc, pname, obj) {
    if (typeof(obj) == "object") {
        for (var prop in obj) {
            __ShowProperites2(doc, pname + "." + prop, obj[prop]);
        }
    } else {
        var v = obj;
        if (typeof(obj) == "string") v = '"' + v + '"';
        doc.write("<b>", pname , "</b>:", v, "<hr><br/>");
    }
}
function __EnableButton(jel, enable) {
    if (enable) {
        jel.removeClass("btnDisabled");
        jel.removeAttr('disabled');
    } else {
        jel.addClass("btnDisabled");
        jel.attr('disabled', 'disabled');
    }
}
function _kt() {
    $.ajax({
        url: $webRoot + "/common/MiscSVC.asmx/KT",
        data: JSON.stringify({}),
        beforeSend: function() {},
        success: function(result){
            if (result.Result)
                $('img[id$=connectImg]').attr("src", $webRoot + "/images/connect.gif");
            else
                $('img[id$=connectImg]').attr("src", $webRoot + "/images/connect_d.gif");
        },
        error: function () {$('img[id$=connectImg]').attr("src", $webRoot + "/images/connect_d.gif");},
        complete: function() {setTimeout(_kt, 60000);}
    });
}

