var managerMISReport = new Component("admin/managerMISReport");
app.registerComponent(managerMISReport);

managerMISReport.init = function(){
    managerMISReport.buttonEvent();
    var date = new Date();
    var currentYear = date.getFullYear();
    var currentMonth = date.getMonth()+1;
    var currentDate = date.getDate();
    fillinAllMonthOptions(
            ["auditMonth_1","auditMonth_2"],
            currentMonth
    );
    fillinAllYearOptions(["auditYear"],currentYear); 
    fiilinDays(currentYear,currentMonth,["auditDay"]);
    fillinWeeks(currentYear,["auditWeeks"]);
//    $("#download_MISReport_form").get(0).action = app.EPRESTAPI_CONTEXT_ROOT + "mis/loginCount?cnumber=" + getCookie("cnumber");
};

managerMISReport.on( "load", function(){
    this.showLoading("mainContent"); 
    managerMISReport.render(
            "template/admin/managerMISReport.html",
            "mainContent",
            {}
   ).done( function(){
       managerMISReport.init();
   });            
         
});

managerMISReport.buttonEvent = function () { 
    
    $("#auditYear").die();
    $("#auditYear").live("change", function(){       
        var year = $(this).val();       
        fillinWeeks(year,["auditWeeks"]); 
        $("#auditMonth_2").change();
    });   
    
    $("#auditMonth_2").die();
    $("#auditMonth_2").live("change", function(){
        var year = $("#auditYear").val();
        var month = $(this).val();
        var daysOfMonth = getMonthDays(year,month);
        fillinDay("auditDay",daysOfMonth);
    });
    
    $("#audit_download").die();
    $("#audit_download").live("click", function(){        
        var requestUrl = app.EPRESTAPI_CONTEXT_ROOT + "mis/loginCount?cnumber=" + getCookie("cnumber")+"&"+ $("#download_MISReport_form").serialize();
        window.location = requestUrl;
    });  
    
    $("#download_byrm").die();
    $("#download_byrm").live("click", function(){        
        var requestUrl = app.EPRESTAPI_CONTEXT_ROOT + "mis/rm?cnumber=" + getCookie("cnumber") ;
        window.location = requestUrl;
    });  
     
};

