  function now() { date = new Date(); var t = date.getFullYear().toString(); t += (date.getMonth() + 1).toString(); t += (date.getDate()).toString(); t += (date.getHours()).toString(); t += (date.getMinutes()).toString(); t += (date.getSeconds()).toString(); t += (date.getMilliseconds()).toString(); return t; };

    function close_eDlg() {
        //$(".eDlg").hide();
        //$(".eDlg").css("top", "-2000px");
        //$(".eDlg").css("left", "-2000px");
        $(".eDlg").remove();
    };
    function eReport_Refresh(ReportID, CtrlID, ObjID, timeObj)
    {
        if (timeObj) { clearInterval(timeObj); }
        var rep = $("#" + CtrlID).parent();
        var timetype = rep.attr("TimeType") ? rep.attr("TimeType") : "";
        var ctrltype = rep.attr("ControlType");
        var url = "?ctrltype=" + ctrltype + "&ReportID=" + ReportID;
		
		
		if(typeof(AppItem)=="string" && AppItem.length > 0)
		{
			url+="&AppItem=" + AppItem;
		}
		else
		{
			if(typeof(ModelID)=="string" && ModelID.length > 0){url+="&ModelID=" + ModelID;}
		}
		
        if (ObjID.length > 0) { url += "&obj=" + ObjID; }
        if (timetype.length > 0)
        {
            if (timetype == "year")
            {
                url += "&syear=" + rep.attr("SYear") + "&eyear=" + rep.attr("EYear");
            }
            if (timetype == "quarter" || timetype == "month") {
                url += "&year=" + rep.attr("DefaultYear");
            }
            if (timetype == "day") {
                url += "&year=" + rep.attr("DefaultYear") + "&month=" + rep.attr("DefaultMonth");
            }            
        }
        url += "&t=" + now();
        $.ajax({
            type: 'get',
            url: url,
            dataType: "html",
            success: function (data) {
                rep.html(data);

            }
        });

    };
    function eReport_Confirm(ReportID, CtrlID, ObjID, timeObj)
    {      
        
        var rep = $("#" + CtrlID).parent();
        var timetype = rep.attr("TimeType");
        var ctrltype = rep.attr("ControlType");
        var maxyear = 0;
        var minyear = 0;
        if (rep.attr("maxYear").length > 0) maxyear = parseInt(rep.attr("maxYear"));
        if (rep.attr("minYear").length > 0) minyear = parseInt(rep.attr("minYear"));
        var year = 0;
        if (rep.attr("DefaultYear").length > 0) year = parseInt(rep.attr("DefaultYear"));
        var month = 0;
        if (rep.attr("DefaultMonth").length > 0) month = parseInt(rep.attr("DefaultMonth"));

        if ((timetype == "quarter" || timetype == "month") && year == parseInt($(".ereport_year").val()))
        {

            close_eDlg();
            return;
        }

        var url = "?ctrltype=" + ctrltype + "&";
        if (ObjID.length > 0) { url += "obj=" + ObjID + "&"; }
        if (timetype == "year")
        {
            rep.attr("sYear", $(".ereport_syear").val());
            rep.attr("eYear", $(".ereport_eyear").val());
            url += "ReportID=" + ReportID + "&syear=" + $(".ereport_syear").val() + "&eyear=" + $(".ereport_eyear").val();
        }
        if (timetype == "quarter" || timetype == "month")
        {
            rep.attr("DefaultYear", $(".ereport_year").val());
            url += "ReportID=" + ReportID + "&year=" + $(".ereport_year").val();
        }
        if (timetype == "day")
        {
            rep.attr("DefaultYear", $(".ereport_year").val());
            rep.attr("DefaultMonth", $(".ereport_month").val());
            url += "ReportID=" + ReportID + "&year=" + $(".ereport_year").val() + "&month=" + $(".ereport_month").val();
        }
		
		if(typeof(AppItem)=="string" && AppItem.length > 0)
		{
			url+="&AppItem=" + AppItem;
		}
		else
		{
			if(typeof(ModelID)=="string" && ModelID.length > 0){url+="&ModelID=" + ModelID;}
		}
		
		
        url += "&t=" + now();
        if (timeObj) { clearInterval(timeObj); }
        var html = '<div id="eReportLoading" class="loading">&nbsp;</div>';
        rep.append(html);

        $.ajax({
            type: 'get',
            url: url,
            dataType: "html",
            success: function (data) {
                 rep.html(data);
                close_eDlg();
            }
        });

    };
    function eReport_Reset(obj, ReportID, CtrlID, ObjID, timeObj) {
        var rect = obj.getBoundingClientRect();
        var html = '<div class="eDlg">';
        html += '<h1>报表选项<a href="javascript:;" onclick="close_eDlg();"></a></h1>';
        html += '<p></p>';
        html += '<div class="footer"><a class="btn" href="javascript:;" onclick="eReport_Confirm(\'' + ReportID + '\',\'' + CtrlID + '\',\'' + ObjID + '\',' + timeObj + ');">确定</a></div>';
        html += '</div>';
        $(document.body).append(html);


        $(".eDlg").css("top", eScroll().top + rect.top + (rect.bottom - rect.top));
        $(".eDlg").css("left", eScroll().left + rect.left - 200);
        // return;

        var rep = $(obj).parent().parent();

        var timetype = rep.attr("TimeType");
        var ctrltype = rep.attr("ControlType");
        var maxyear = 0;
        var minyear = 0;
        if (rep.attr("maxYear").length > 0) maxyear = parseInt(rep.attr("maxYear"));
        if (rep.attr("minYear").length > 0) minyear = parseInt(rep.attr("minYear"));
        var year = 0;
        if (rep.attr("DefaultYear").length > 0) year = parseInt(rep.attr("DefaultYear"));
        var month = 0;
        if (rep.attr("DefaultMonth").length > 0) month = parseInt(rep.attr("DefaultMonth"));


        html = '<div style="margin:10px;">';
        if (timetype == "year") {
            var syear = 0;
            if (rep.attr("sYear").length > 0) syear = parseInt(rep.attr("sYear"));
            var eyear = 0;
            if (rep.attr("eYear").length > 0) eyear = parseInt(rep.attr("eYear"));

            html += '<select name="select" class="ereport_syear">';
            for (var i = minyear; i <= maxyear; i++) {
                html += '<option value="' + i + '"' + (i == syear ? ' selected="true"' : '') + '>' + i + '年</option>';
            }
            html += '</select>';
            html += ' 至 ';
            html += '<select name="select" class="ereport_eyear">';
            for (var i = minyear; i <= maxyear; i++) {
                html += '<option value="' + i + '"' + (i == eyear ? ' selected="true"' : '') + '>' + i + '年</option>';
            }
            html += '</select>';

        }
        if (timetype == "quarter" || timetype == "month") {
            html += '<select name="select" class="ereport_year">';
            for (var i = minyear; i <= maxyear; i++) {
                html += '<option value="' + i + '"' + (i == year ? ' selected="true"' : '') + '>' + i + '年</option>';
            }
            html += '</select>';
        }
        if (timetype == "day") {

            html += '<select name="select" class="ereport_year">';
            for (var i = minyear; i <= maxyear; i++) {
                html += '<option value="' + i + '"' + (i == year ? ' selected="true"' : '') + '>' + i + '年</option>';
            }
            html += '</select>';

            html += '<select name="select" class="ereport_month">';
            for (var i = 1; i <= 13; i++) {
                html += '<option value="' + i + '"' + (i == month ? ' selected="true"' : '') + '>' + i + '月</option>';
            }
            html += '</select>';
        }
        html += '</div>';
        $(".eDlg p").html(html);
        /*
    layer.open({
    type: 1
	, area: ['200px', '150px']
    //,shade: 0.2 //透明度
  	, title: "报表选项"
	, closeBtn: 1
    , offset: [ (eScroll().top + rect.top) + 'px',( eScroll().left + rect.left - 200) + 'px']
	, scrollbar: false
	, shadeClose: true //开启遮罩关闭
  	, content: html
    , shade: 0
	, btn: ['确定'] //只是为了演示
	, end: function () { }
	, success: function (layero, index) {}
    , yes: function (index) {
        
    }
    });
        */

    };