

var teamListContainer = null;
var params={};
var G_PROJECT_ID;
var PROJECT_DETAILS = "";
var ownerEmail = "";
var upgradeMsg = "";

$(document).ready(function () {

     

    ownerEmail = user_email;
    // alert(ownerEmail);
    window.location.search.replace(/[?&;#]+([^=&]+)=([^&]*)/gi,function(str,key,value){params[key] = value;});

    teamListContainer = $(".cl-div-project-team-p-holder").find(".cl-div-p-item-holder");

    PROJECT_DOM = $(teamListContainer).find(".cl-div-project-team").clone();

    attachOverviewEventListener($("#id-project-team-container"), true);
    // attachAddTeamMemberEventListener($("#id-project-team-container"), false);

    if(typeof params.edit !== "undefined" && params.edit ==="true" && (typeof params.id !== "undefined")){
        editMode = true;
        
        G_PROJECT_ID=params.id;
        
        $.post("API.php",{project: "DETAILS", id:G_PROJECT_ID}, function(data){
                // alert(JSON.stringify(data));
                PROJECT_DETAILS = data[0];
                // console.log(PROJECT_DETAILS);
                var projTitle = $(".projectOverview").find('#id-team-project-title').html('Project Team - '+PROJECT_DETAILS.project_title);
                ownerId = PROJECT_DETAILS.creating_user_id;
        }, 'json');

        $("#id-project-overview-bclink").attr("href", "projectOverview.php?edit=true&id="+G_PROJECT_ID);
        console.log('type '+PROJECT_DETAILS.subscription_type);
        if(PROJECT_DETAILS.subscription_type == 'Supporter' || PROJECT_DETAILS.subscription_type == 'free'){
            console.log('type '+PROJECT_DETAILS.subscription_type);
            attachAddTeamMemberEventListener($("#id-project-team-container"), false, "Thank you for using isUD. You are limited to 1 team member per project. If you would like to add a team member, please upgrade your Membership. If you would like additional members added to your project, please contact us at info@thisidud.com.");
        }
        else{
        
            $.post("API.php",{projectTeam:"LIST",project_id:G_PROJECT_ID},
               function (data) {
                   if(data)
                   {
                     var activeTeamSize = $(data).filter(function (i,n){return n.status==='1'});
                     console.log('Team Size  ');
                     console.log(activeTeamSize);
                     console.log(activeTeamSize.length);
                     console.log((data));
                     if(activeTeamSize.length >= 15){
                            console.log('showing upgradeMsg');
                            // upgradeMsg = "Sorry, you are limited to 15 members per project. If you would like to add a dierent team member, you will have to remove an existing team member. If you would like additional members added to your project, please contact us at info@thisidud.com.";
                            console.log(upgradeMsg);
                            attachAddTeamMemberEventListener($("#id-project-team-container"), false, "Thank you for using isUD. You are limited to 15 team members per project. If you would like to add a different member, you will have to remove an existing team member. If you would like additional members added to your project, please contact us at info@thisidud.com.");
                        }
                    else{
                            attachAddTeamMemberEventListener($("#id-project-team-container"), true);
                        }
                     show_team_members(data);
                   }
                   else{
                     alert("error");
                   }

             },"json");

        }

         $.post("API.php",{projectTeam:"GET_INVITES",project_id:G_PROJECT_ID},
            function(data){
                if(data){
                    console.log(data);
                    show_invited_members(ownerId, data, G_PROJECT_ID);
                }else{
                 alert("error");
               }

        }, "json");
    }

    $("#id-btn-notify-close").click(function(){
            $("#id-modal-upgrade-membership-popup").modal('hide');
        });

    //Adding a Team Member - Create
    // $("#id-btn-add-team-member-submit").click(function
    $('#id-form-add-team-member').submit(function(e) {  

       var insertModal = $("#id-modal-create-project-success-popup");
       var action = $(insertModal).find("#id-team-member-status").attr("action");
        
       var userID = "";
        
        var userEmail = $(insertModal).find("#id-project-inp-email").val();
           var projectPermission = $(insertModal).find("input[name=name-radio-p-team-member-type]:checked").val();
           var projectRole = $(insertModal).find("#id-project-inp-teamrole").val();
           var memberStatus = 1;

             e.preventDefault();
             $.post("API.php", { register: "GETUSER", username: userEmail }, function (data) {
                // alert(JSON.stringify(data));
                if(data.length > 0){
                    // alert('in if');
                    // alert(JSON.stringify(data));
                    userID = data[0]['_id'];
                    userLastName = data[0]['last_name'];

                    if(userID != ownerId){
                        if(action=="insert"){
                            // addMemberToTeam(userID, projectPermission, projectRole, memberStatus);
                            // $.post("API.php", { projectTeam: "CREATE", project_id: G_PROJECT_ID, user_id: userID, project_permission_id: projectPermission, project_role_id: projectRole, status: memberStatus }, function (data) {
                            //     if(data){
                            //         alert(JSON.stringify(data));
                            //         // alert('Successfully added');
                            //         location.reload(true);
                            //     }else{
                            //         // alert(JSON.stringify(data));
                            //         alert('error'); 
                            //     }
                            // },"json");
                            jQuery.support.cors = true;
                            jQuery.ajax({
                                    url: "API.php",
                                    data: { projectTeam: "CREATE", project_id: G_PROJECT_ID, user_id: userID, project_permission_id: projectPermission, project_role_id: projectRole, status: memberStatus },
                                    type: 'POST',
                                    success: function(data) {
                                        // alert(JSON.stringify(data));
                                        // location.reload(true);
                                        window.location=window.location;
                                        return false;
                                    },
                                    error: function(data) {
                                        // alert(JSON.stringify(data));
                                        alert('API failed. Please try again or contact isud team.');
                                        return false;
                                    }
                                });
                            notifyMember('exists', userEmail, userLastName,'' ,'' );
                        }                
                        if(action=="edit"){
                            // updateMemberToTeam(userID, projectPermission, projectRole, memberStatus);
                            // notifyMember('exists', userEmail, userLastName,'' ,'' );
                            jQuery.support.cors = true;
                            jQuery.ajax({
                                    url: "API.php",
                                    data: { projectTeam: "UPDATE", project_id: G_PROJECT_ID, user_id: userID, project_permission_id: projectPermission, project_role_id: projectRole, status: memberStatus },
                                    type: 'POST',
                                    success: function(data) {
                                        // alert(JSON.stringify(data));
                                        // location.reload(true);
                                        window.location=window.location;
                                        return false;
                                    },
                                    error: function(data) {
                                        // alert(JSON.stringify(data));
                                        alert('API failed. Please try again or contact isud team.');
                                        return false;
                                    }
                                });
                        }
                    }
                    else{
                        alert('You cannot add yourself to the team');
                    }
                }
                else{
                    // alert('in else');
                    // addMemberInvite(ownerId, userEmail, projectPermission);
                    $.post("API.php", { projectTeam: "TEAMINVITE", owner_id: ownerId, project_id: G_PROJECT_ID, user_email: userEmail, project_role_id: projectRole, project_permission_id: projectPermission}, function (data) {
                        // alert("After API Call " + JSON.stringify(data));
                        var obj = JSON.parse(data);
                       // alert('Response ' + obj.response);
                        if(obj.response == true){
                           // alert(JSON.stringify(data));
                            alert('Invitation Success');
                            notifyMember('new', userEmail, '','' ,'' );
                            window.location=window.location;
                        }else{
                            alert('Invitation Error');
                            console.log(data);
                        }
                    },"json");

                    
                }
            
            }, 'json');
      

    });

    // $("#id-btn-delete-team-member-submit").click(function(){
       $('#id-form-delete-team-member').submit(function(e) {  

        e.preventDefault();
       var deleteModal = $("#id-modal-delete-project-member-popup");
       var action = $(deleteModal).find("#id-team-member-status").attr("action");
        // alert(action);
       var userID = "";
       if(action=="delete"){
        
        var userID = $("#id-modal-delete-project-member-popup").attr('user-id');
           var projectPermission = $("#id-modal-delete-project-member-popup").attr('permission-id');
           var projectRole = $("#id-modal-delete-project-member-popup").attr('role-id');
           var memberStatus = 0;
            // alert(userID + "--" + projectPermission + "--" + projectRole + "--" + memberStatus);
            // updateMemberToTeam(userID, projectPermission, projectRole, memberStatus);
            jQuery.support.cors = true;
            jQuery.ajax({
                    url: "API.php",
                    data: { projectTeam: "UPDATE", project_id: G_PROJECT_ID, user_id: userID, project_permission_id: projectPermission, project_role_id: projectRole, status: memberStatus },
                    type: 'POST',
                    success: function(data) {
                        // alert(JSON.stringify(data));
                        location.reload(true);
                        return false;
                    },
                    error: function(data) {
                        // alert(JSON.stringify(data));
                        alert('API failed. Please try again or contact isud team.');
                        return false;
                    }
                });

       }
       else{
        alert('error!');
       }
      
    });


    
});

function show_invited_members(ownerId, invited_members_list, G_PROJECT_ID){
    //alert('Inside function' + JSON.stringify(invited_members_list));
    // var list = JSON.parse(invited_members_list);
    var list = JSON.parse(invited_members_list);
    $.each(list, function(index, elem){ 
        // alert('hi');
        var List = $(PROJECT_DOM).clone();
        console.log(elem);
        var Name = $(List).find(".cl-span-project-team-user-name");
        var Email = $(List).find(".cl-span-project-team-user-email");
        var Auth = $(List).find(".cl-span-project-team-user-auth");
        var Role = $(List).find(".cl-span-project-team-user-role");
        var Status = $(List).find(".cl-span-project-team-user-status");
        var Actions = $(List).find(".cl-span-project-team-user-actions");

        var user_actions = '<div class="cl-i-project-team-member-resend" style="margin-left:20px;font-size:12px; font-family: SofiaPro-Light,sans-serif; font-weight: bold; color: #002f56;" aria-hidden="true" title="Edit">Re-Send Invite</div>';
        
        $(Name).html(" ");
        $(Email).html(elem.email);
        $(Auth).html(elem.authName);
        $(Auth).attr('value', elem.authId);
        $(Role).html(elem.authName == 'admin' ? 'Project Manager' : elem.roleName);
        $(Role).attr('value', elem.roleId);
        $(Status).html('Invited');
        // $(Actions).html(user_actions);
        $(Actions).html(" ");

        $(teamListContainer).append(List);

    });
   // attachResendInvitationTeamMemberEventListener($("#id-project-team-container"));
}

var show_team_members = function(team_list){

    $(teamListContainer).empty();

    $.each(team_list, function(index, elem){
        var List = $(PROJECT_DOM).clone();
        console.log(elem);
        var Name = $(List).find(".cl-span-project-team-user-name");
        var Email = $(List).find(".cl-span-project-team-user-email");
        var Auth = $(List).find(".cl-span-project-team-user-auth");
        var Role = $(List).find(".cl-span-project-team-user-role");
        var Status = $(List).find(".cl-span-project-team-user-status");
        var Actions = $(List).find(".cl-span-project-team-user-actions");
        
        $(List).attr("project_id","project_id-"+elem.project_id);
        $(List).attr("member-id",elem.user_id);
        $(List).attr("member-status",elem.status);
        $(List).attr("member-auth",elem.authName);

        // id="id-edit-'+elem.user_id+'"
        if(elem.status == '1'){
            var user_actions = '<div class="cl-i-project-team-member-edit" style="margin-left:20px;font-size:12px; font-family: SofiaPro-Light,sans-serif; font-weight: bold; color: #002f56;" aria-hidden="true" title="Edit">Edit</div>';
            user_actions += '<div class="cl-i-project-team-member-remove" style="margin-left:20px;font-size:12px; font-family: SofiaPro-Light,sans-serif; font-weight: bold; color: #002f56;" aria-hidden="true" title="Remove">Remove</div>';
        }
        else{
            var user_actions = '';
        }
        
        $(Name).html(elem.name);
        $(Email).html(elem.email);
        $(Auth).html(elem.authName);
        $(Auth).attr('value', elem.authId);
        $(Role).html(elem.authName == 'admin' ? 'Project Manager' : elem.roleName);
        $(Role).attr('value', elem.roleId);
        $(Status).html(elem.status == '1' ? 'Active' : 'Inactive');

        $(Actions).html(elem.authName == 'admin' ? '' : user_actions);

        $(teamListContainer).append(List);
    });
    attachEditRemoveTeamMemberEventListener($("#id-project-team-container"), true);
}

function attachOverviewEventListener(projectElem, attach){
    var btn = $(projectElem).find(".cl-project-edit-btn");
    if(!attach){
        $(btn).css("cursor", "no-drop");
        $(btn).click(function(ev){
            return false;
        });
    } else {
        $(btn).css("cursor", "pointer");
        $(btn).click(function(ev){
            var target = "projectOverview.php?edit=true&id="+G_PROJECT_ID ;
            window.location.href = target;
        });
    }
}


function attachAddTeamMemberEventListener(projectElem, attach, upgradeMsg=''){
    var btn = $(projectElem).find(".cl-project-update-btn");
    if(!attach){
        console.log('inside event');
        $(btn).css("cursor", "no-drop");
        // $(btn).css("background-color","#555");
        // $(btn).css("border","1px solid #555");
        $(btn).click(function(ev){
            if(upgradeMsg != ""){
                var modal = $("#id-modal-upgrade-membership-popup");
                $(modal).find("#id-team-pop-up-title").html("Add Team Member");
                $(modal).find("#id-span-upgrade-message").html(upgradeMsg);
                $(modal).modal('show');
            }
            return false;
        });
        
    } else {
        $(btn).css("cursor", "pointer");
        $(btn).click(function(ev){
            addTeamMember("Success",G_PROJECT_ID);
        });
    }
}

var show_upgrade_popup = function (msg){
    console.log('inside the popup function');
    var modal = $("#id-modal-upgrade-membership-popup");
    $(modal).find("#id-team-pop-up-title").html("Upgrade Membership");
    $(modal).find("#id-span-upgrade-message").html(msg);
    $(modal).modal('show');
}


var addTeamMember = function (msgSuccess,project_id){
    // $("#id-create-project-success-popup-msg").find("#id-team-pop-up-title").html("Add Team Member");
    var modal = $("#id-modal-create-project-success-popup");
    $(modal).find("#id-team-pop-up-title").html("Add Team Member");
    $(modal).find("#id-btn-edit-project").attr("project_id",project_id);
    $(modal).find("#id-btn-project-dashboard").attr("project_id",project_id);
    $(modal).find("#id-team-member-status").attr("action","insert");
    $(modal).modal('show');

    $.post("API.php", { register: "PROJECT_SIGNUP_ROLES" }, function (data) {
        // console.log('inside api');
        var container = $("#id-project-inp-teamrole");
        var generated_option = '';
        $(container).html('');
        // alert(JSON.stringify(data));
        $.each(data, function(index,elem){
            // alert(elem.name);
            generated_option += '<option value="'+elem.role_id+'">'+elem.name+'</option>';
        });
        container.html(generated_option);
        $(container).selectpicker('refresh');
    }, 'json');
}


function addMemberToTeam(userID, projectPermission, projectRole, memberStatus){
            // alert(userID+' '+projectPermission+' '+projectRole+' '+memberStatus);
            $.post("API.php", { projectTeam: "CREATE", project_id: G_PROJECT_ID, user_id: userID, project_permission_id: projectPermission, project_role_id: projectRole, status: memberStatus }, function (data) {
            
            if(data){
                alert(JSON.stringify(data));
                // alert('Successfully added');
                // location.reload(true);
            }else{
                // alert(JSON.stringify(data));
                alert('error'); 
            }
        },"json");
}

function updateMemberToTeam(userID, projectPermission, projectRole, memberStatus){
            alert(userID+' '+projectPermission+' '+projectRole+' '+memberStatus);
            jQuery.support.cors = true;
        //     $.post("API.php", { projectTeam: "UPDATE", project_id: G_PROJECT_ID, user_id: userID, project_permission_id: projectPermission, project_role_id: projectRole, status: memberStatus }, function (data) {
        //     alert('yes');
        //     alert(JSON.stringify(data));
        //     if(data){
        //         alert(JSON.stringify(data));
        //         // alert('Successfully added');
        //         location.reload(true);
        //     }else{
        //         // alert(JSON.stringify(data));
        //         alert('error'); 
        //     }
        // },"json");

            jQuery.ajax({
                    url: "API.php",
                    data: { projectTeam: "UPDATE", project_id: G_PROJECT_ID, user_id: userID, project_permission_id: projectPermission, project_role_id: projectRole, status: memberStatus },
                    type: 'POST',
                    success: function(data) {
                        alert(JSON.stringify(data));
                        return false;
                    },
                    error: function(data) {
                        alert(JSON.stringify(data));
                        alert('API failed');
                        return false;
                    }
                });


}


function addMemberInvite(ownerId, userEmail, projectPermission){
            // alert('inside invite func');
            // alert(ownerId+" "+G_PROJECT_ID+" "+userEmail+" "+projectPermission+" ;");
            $.post("API.php", { projectTeam: "TEAMINVITE", owner_id: ownerId, project_id: G_PROJECT_ID, user_email: userEmail, project_permission_id: projectPermission}, function (data) {
                // alert('IN INVITE FUNCTION :  '+JSON.stringify(data));
            if(data.response == true){
                // alert(JSON.stringify(data));
                alert('INVITE SUCCESS');
                // location.reload(true);
            }else{
                alert('INVITE ERROR');
                console.log(data);
            }
        },"json");
}


function notifyMember(status, userEmail, userName, projectName, projectOwner){

    var notify_subject = "You have been added to the isUD Project: "+PROJECT_DETAILS.project_title;
    var notify_body = "<html><body>";

    // alert(PROJECT_DETAILS.project_title);
    if(status=="exists"){
            notify_body += 'Hello, '+ userName;
            notify_body += '<p> '+ownerEmail+' has added you to the isUD Project: '+PROJECT_DETAILS.project_title+' .<br><br>';
            notify_body += 'Please login to your isUD account to access the project. '+user_last_name+' is the project manager overseeing the isUD Certification process and is your primary point of contact.<br>';
            notify_body += "<br> We look forward to working with you and your team as you pursue isUD certification. </p>";
            notify_body += "<b>isUD Team</b><br><br>";
            notify_body += '</body></html>';
            // notify_body += '<a href= "https://thisisud.com/dashboard/register.php"> Login </a>';
            notify_body += '<a href= "https://thisisud.com/dashboard/register.php"> LOGIN </a>';
    }else if(status=="new"){
            // alert('new');
            notify_body += 'Hello,';
            notify_body += '<p> '+ownerEmail+' has added you to the isUD Project: '+PROJECT_DETAILS.project_title+' .<br><br>';
            notify_body += 'Please create an account with isUD to access the project. '+user_last_name+' is the project manager overseeing the isUD Certification process and is your primary point of contact.<br>';
            notify_body += "<br> We look forward to working with you and your team as you pursue isUD certification. </p>";
            notify_body += "<b>isUD Team</b><br><br>";
            notify_body += '</body></html>';
            notify_body += '<a href= "https://thisisud.com/dashboard/register.php"> CREATE ACCOUNT </a>';
            // notify_body += '<a href= "https://thisisud.com/dashboard/register.php"> Login </a>';
            // notify_body += '<a href= "https://thisisud.com/dashboard/register.php?verify=true&user="'.$username.'"&vtoken="'.$ret->message.'"> CREATE ACCOUNT </a>';

    }   
    
    $.post("API.php", { notify: "NOTIFY_BY_EMAIL", destination_email: userEmail, subject: notify_subject, message_body: notify_body }, function (data) {
        console.log('notified');
        // alert(JSON.stringify(data));
    }, 'json');
}


function attachEditRemoveTeamMemberEventListener(projectElem, attach){
    var btn = $(projectElem).find(".cl-i-project-team-member-edit");
    var btn_remove = $(projectElem).find(".cl-i-project-team-member-remove");
    if(!attach){
        $(btn).css("cursor", "no-drop");
        $(btn).click(function(ev){
            return false;
        });
        $(btn_remove).css("cursor", "no-drop");
        $(btn_remove).click(function(ev){
            return false;
        });
    } else {
        $(btn).css("cursor", "pointer");
        $(btn).click(function(ev){
            var memberRoot = $(this).parent().parent().parent().parent().parent();
            EditTeamMember(memberRoot,G_PROJECT_ID);
        });
        $(btn_remove).css("cursor", "pointer");
        $(btn_remove).click(function(ev){
            var memberRoot = $(this).parent().parent().parent().parent().parent();
            RemoveTeamMember(memberRoot,G_PROJECT_ID);
        });
    }
}

function attachResendInvitationTeamMemberEventListener(projectElem){
    var btn = $(projectElem).find(".cl-i-project-team-member-resend");
    $(btn).css("cursor", "pointer");
    $(btn).click(function(ev){
      var userEmail = $(projectElem).find('.cl-span-project-team-user-email').text();
      // alert(userEmail);
      notifyMember('new', userEmail, '','' ,'' );
      window.location=window.location;       
      alert('Resend Invitation Success');
    });
}

var EditTeamMember = function (memberRoot,project_id){
    // $("#id-create-project-success-popup-msg").find("#id-team-pop-up-title").html("Edit Team Member");
    var modal = $("#id-modal-create-project-success-popup");
    var memberId = $(memberRoot).attr("member-id");
    var memberEmail = $(memberRoot).find('.cl-span-project-team-user-email').text();
    var projectPermission = $(memberRoot).find(".cl-span-project-team-user-auth").attr('value');
    var projectRole = $(memberRoot).find(".cl-span-project-team-user-role").attr('value');
    // alert(projectRole);
    // $('#id-project-inp-teamrole [value='+projectRole+']').attr('selected', 'true');
    $('select[name=id-project-inp-teamrole]').val(projectRole);
    $('.selectpicker').selectpicker('refresh');
    $(modal).find("input[name=name-radio-p-team-member-type]").filter("input[value="+projectPermission+"]").attr("checked", "checked");
    $(modal).find("input[name=name-radio-p-team-member-type]").filter("input[value="+projectPermission+"]").prop("checked", "checked");
    $(modal).find('#id-project-inp-email').val(memberEmail);
    $(modal).find("#id-team-member-status").attr("value",1);
    $(modal).find("#id-team-member-status").attr("action","edit");
    $(modal).find("#id-team-pop-up-title").html("Edit Team Member");
    $(modal).find("#id-btn-edit-project").attr("project_id",project_id);
    $(modal).find("#id-btn-project-dashboard").attr("project_id",project_id);
    $(modal).modal('show');

    $.post("API.php", { register: "PROJECT_SIGNUP_ROLES" }, function (data) {
        var container = $("#id-project-inp-teamrole");
        var generated_option = '';
        $(container).html('');
        // alert(JSON.stringify(data));
        $.each(data, function(index,elem){
            // alert(elem.name);
            generated_option += '<option value="'+elem.role_id+'">'+elem.name+'</option>';
        });
        container.html(generated_option);
        $(container).selectpicker('refresh');
    }, 'json');
}

var RemoveTeamMember = function (memberRoot,project_id){
    // $("#id-team-pop-up-title").html("Remove Team Member");
    var modal = $("#id-modal-delete-project-member-popup");
    $(modal).find("#id-team-pop-up-title").html("Remove Team Member <p>Are you sure you want to remove the following team member from this project?</p>");
    $(modal).find("#id-btn-edit-project").attr("project_id",project_id);
    $(modal).find("#id-btn-project-dashboard").attr("project_id",project_id);
    $(modal).find("#id-team-member-status").attr("value",0);
    $(modal).find("#id-team-member-status").attr("action","delete");
    $(modal).attr('user-id', $(memberRoot).attr("member-id"));
    $(modal).attr('role-id', $(memberRoot).find('.cl-span-project-team-user-role').attr("value"));
    $(modal).attr('permission-id', $(memberRoot).find('.cl-span-project-team-user-auth').attr("value"));


    // $(modal).find("#id-project-inp-email").addClass("hide");
    // $(modal).find("#id-radio-controls").addClass("hide");

    var memberId = $(memberRoot).attr("member-id");
    var memberEmail = $(memberRoot).find('.cl-span-project-team-user-email').text();
    var projectPermission = $(memberRoot).find(".cl-span-project-team-user-auth").text();
    var projectRole = $(memberRoot).find(".cl-span-project-team-user-role").text();

    $(modal).find("#id-member-email-container").html("<div><b class='label cl-label-login-short' for='id-login-inp-email'>E-mail Address</b></div><div><label class='label cl-label-login-short' for='id-login-inp-email'>"+ memberEmail +"</label></div>");
    $(modal).find("#id-member-permission-radio-container").html("<div><b class='label cl-label-login-short' for='id-login-inp-email'>Project Authorization</b></div><div><label class='label cl-label-login-short' for='id-login-inp-email'>"+ projectPermission +"</label></div>");
    $(modal).find("#id-member-role-container").html("<div><b class='label cl-label-login-short' for='id-login-inp-email'>Project Role</b></div><div><label class='label cl-label-login-short' for='id-login-inp-email'>"+ projectRole +"</label></div>");
    
    $(modal).modal('show');

    // console.log(memberId + "--" + memberEmail + "--" + projectPermission + "--" + projectRole);

    $.post("API.php", { register: "PROJECT_SIGNUP_ROLES" }, function (data) {
        // console.log('inside api');
        var container = $("#id-project-inp-teamrole");
        var generated_option = '';
        $(container).html('');
        // alert(JSON.stringify(data));
        $.each(data, function(index,elem){
            // alert(elem.name);
            generated_option += '<option value="'+elem.role_id+'">'+elem.name+'</option>';
        });
        container.html(generated_option);
        $(container).selectpicker('refresh');
    }, 'json');
};