var C_MILESTONE_FILTER                       = "2301";
var C_ADD_MILESTONE_VIEW                     = "2302";
var C_UPDATE_MILESTONE_VIEW                  = "2303";

var milestone_obj                         = null;


function showMessage(type, message, title){
    $("#modalMessageViewContent").html(message);
    if(type == 'error')
        $("#modalMessageHeaderContent").css({ "background-color": "#e20000" });
    else if(type == 'success')
        $("#modalMessageHeaderContent").css({ "background-color": "#3A78AD" });
    else if(type == 'warning')
        $("#modalMessageHeaderContent").css({ "background-color": "#FFD42A" });
    $("#modalMessageViewTitle").html(title);
    $("#messageView").modal("show");
}


function showAddMilestone(){
    showProgress("loading Milestone" ) ;
    var data = { "type": C_ADD_MILESTONE_VIEW} ;
    var url  = "index.pzx?c=" + milestone_url + "&t=" + C_ADD_MILESTONE_VIEW  + "&d=" + new Date().getTime() ;
    callServer(url,"json",data,onMilestoneResponse,null) ;
}


function deleteMilestone(id, obj) {
    var data = { 
            "id"            : id,
            "type"          : C_DELETE
            };
    var url = "index.pzx?c=" + plan_url + "&d=" + new Date().getTime() ;
    callServer(url,"json",data,onMilestoneResponse,obj) ;
}


function onMilestoneResponse(obj,resp){
    $('#planLoadingModal').modal('hide');
    if (resp.status != C_OK ) {
        showMessage('error', resp.mesg, "Warning");
        return false;
    }
    
    if(resp.type == C_MILESTONE_FILTER) {
        $('#milestone-table').html('');
        $('#milestone-table').append(resp.data);
    }else if (resp.type == C_ADD_MILESTONE_VIEW || resp.type == C_UPDATE_MILESTONE_VIEW) {
        $("#addMilestoneView").modal("show");
        $('#modalAddMilestoneContent').html(resp.data.all);
        //var functionName = "addPlan()";
        var functionName = "#";
       if (resp.type == C_UPDATE_MILESTONE_VIEW) {
    
           
        }
        var strBtn = "<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Cancel</button>" +
        "<button type=\"button\" class=\"btn btn-info\" data-dismiss=\"modal\">Print</button>" +
                        "<button id=\"btnPlanAdd\" class=\"btn btn-primary\" onclick=\"return "+functionName+";\">Save</button>";

        $('#modalAddMilestoneFooter').show().html(strBtn); 
        
    }else if (resp.type == C_ADD) {
        showMessage('success', resp.mesg, "Success");
        $("#addPlanView").modal("hide");
        $("#showPlanView").modal("hide");
      
    }else if (resp.type == C_DELETE) {
        $("#deletePlanConfirmationView").modal("hide");
       
    }else if (resp.type == C_UPDATE) {
        showMessage('success', resp.mesg, "Success");
        $("#addPlanView").modal("hide");
        $("#showPlanView").modal("hide");
        
    }
}
