
    function funnextaction(descr, date1, time1, cid, append2, disabled2, assignid, assignname, append1){
        var desc2=$(descr).val();
        var date2=$(date1).val();
        var time2=$(time1).val();
        var assignid2=$(assignid).val();
        var adminemailid="<?php echo $adminemailid;?>";
        //alert(assignid2);
        var assignname2=$(assignname).val();
        $(disabled2).attr("disabled", true);
        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
        if((desc2!="")&&(date2!="")&&(time2!="")){
            var insert="";
            $.ajax({
                url:"activestream_intermediate.php",
                type:"post",
                data:{insertnextaction:desc2, nextactiondate:date2, nextactiontime:time2, cid:cid, naassign:assignid2},
                success:function(respond){
                    //alert(respond);
                    var cccc=respond.trim()
                    var nid2=cccc;
                    //alert(cccc);
                    var todate=new Date();
                    var d=todate.getDate();
                    var m=todate.getMonth()+1;
                    var y=todate.getFullYear();
                    if(m<10){
                        m="0"+m;
                    }
                    var d1=y+"-"+m+"-"+d;
                    var date3=date2;
                    var date123=date3.split("-")
                    var m3=date123[1];
                    if(m3[0]=="0"){
                        m1=m3[1];
                    }else{
                        m1=m3;
                    }
                    alert(cccc);
                    if(assignid2==adminemailid){
                    var insert="";
                    insert+='<div class="col-md-2">';
                    insert+='<br>';
                    insert+='<div class="checkbox pull-right" style="padding-top:10px;">';
                    insert+='<label>';
                    insert+='<input type="checkbox" value="" id="checkbox1'+cccc+'" onchange=checkitscompleted("#checkbox1'+cccc+'","'+cccc+'","#firstnextaction'+cid+'","'+desc2+'","'+date2+'","'+time2+'","'+cid+'","'+assignid2+'")>';
                    insert+='<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>';
                    insert+='</label>';
                    insert+='</div>';
                    insert+='</div>';
                    insert+='<div class="col-md-10">';
                    insert+='<h5>Next Action';
                    insert+='<input type="hidden" id="na_f_desc_r" value="'+desc2+'">';
                    insert+='<input type="hidden" id="na_f_date_r" value="'+date2+'">';
                    insert+='<input type="hidden" id="na_f_time_r" value="'+time2+'">';
                    insert+='<input type="hidden" id="na_f_id_r" value="'+cccc+'">';
                    insert+='<input type="hidden" id="na_f_assign_r" value="'+assignid2+'">';
                    insert+='<span class="pull-right" style="color:grey;cursor:pointer;" onclick=editfirstnextaction("na_f_desc_r","na_f_date_r","na_f_time_r","'+append2+'","'+cid+'","na_f_id_r","na_f_assign_r")>Edit</span></h5>'
                    insert+='<b>'+desc2+'</b>';
                    insert+='<div class="row" style="padding:10px 0px 10px 10px;">';
                    insert+='<div class="col-sm-8">';
                    //alert(date2+"<"+d1+":");
                    //alert(date2<d1);
                    if(date2=="0000-00-00"){
                    insert+='<div style="background: url(../../Images/tagui6.png);background-repeat: no-repeat;background-size:80px 20px;color:orange;">';
                    insert+='<span style="margin-left:10px;">';
                    insert+='Queued';
                    insert+='</span>';
                    insert+='</div>';
                    }else if(date2<d1){
                    insert+='<div style="background: url(../../Images/tagui4.png);background-repeat: no-repeat;background-size:80px 20px;color:#f8f8f8;">';
                    insert+='<span style="margin-left:10px;">';
                    insert+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                    insert+='</span>';
                    insert+='</div>';
                    }else{
                    insert+='<div style="background: url(../../Images/tagui5.png);background-repeat: no-repeat;background-size:80px 20px;color:white;">';
                    insert+='<span style="margin-left:10px;">';
                    insert+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                    insert+='</span>';
                    insert+='</div>';
                    }
                    insert+='</div>';
                    insert+='<div class="col-sm-4">';
                    insert+='<span class="pull-right"  onclick=shownextactionqueue("#newnextactionadd")>';
                    insert+='<span class="add_new_action"></span>';
                    insert+='</span>';
                    insert+='</div>';
                    insert+='</div>';
                    insert+='</div>';
                    $(append2).empty();
                    $(append2).append(insert);
                    }else{
                        var insert1="";
                        insert1+='<span id="nextactionsecond'+nid2+'">';
                        insert1+='<div class="row" style="padding:10px 0px 10px 0px;" id="nextactionqueue'+nid2+'" onmouseover=functionnextaction1("#nextactionshow1'+nid2+'","#nextactionshow2'+nid2+'") onmouseout=functionnextaction2("#nextactionshow1'+nid2+'","#nextactionshow2'+nid2+'")>';
                        insert1+='<div class="col-sm-2"> <span class="pull-right"  id="nextactionshow1'+nid2+'" style="display:none;"><img src="../../Images/drag-verticalv2.png"></span>';
                        insert1+='<input type="hidden" id="na_s_desc'+nid2+'" value="'+desc2+'">';
                        insert1+='<input type="hidden" id="na_s_date'+nid2+'" value="'+date2+'">';
                        insert1+='<input type="hidden" id="na_s_time'+nid2+'" value="'+time2+'">';   
                        insert1+='<input type="hidden" id="na_s_nid'+nid2+'" value="'+nid2+'">';
                        insert1+='<input type="hidden" id="na_f_assign_r'+nid2+'" value="'+assignid2+'">';
                        insert1+='</div>';
                        insert1+='<div class="col-sm-10">';
                        insert1+='<div class="row">';
                        insert1+='<div class="col-sm-2" style="margin-left:10px;">';
                        //alert(insert1);
                        if(date2=="0000-00-00"){
                        insert1+='<div style="background: url(../../Images/tagui9.png);background-repeat: no-repeat;background-size:80px 20px;color:orange;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+='Queued';
                        insert1+='</span>';
                        insert1+='</div>';
                        }else if(date2<d1){
                        insert1+='<div style="background: url(../../Images/tagui11.png);background-repeat: no-repeat;background-size:80px 20px;color:#f8f8f8;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                        insert1+='</span>';
                        insert1+='</div>';
                        }else{
                        insert1+='<div style="background: url(../../Images/tagui10.png);background-repeat: no-repeat;background-size:80px 20px;color:white;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                        insert1+='</span>';
                        insert1+='</div>';
                        }
                        insert1+='</div>';
                        insert1+='<div class="col-sm-10"><b>';
                        insert1+=desc2+'</b>&nbsp;&nbsp';
                        if((time2!="00:00")&&(time2!="00:00:00")){
                            insert1+=time2;
                        }
                        //alert(insert1);
                        insert1+='&nbsp;&nbsp;&nbsp;&nbsp;';
                        insert1+='<span style="display:none;cursor:pointer;" id="nextactionshow2'+nid2+'">';
                        insert1+='<span style="cursor:pointer;" id="nextactiondelete1'+nid2+'" onclick=functiondeletenextaction("'+nid2+'","'+append1+'")>';
                        insert1+='<i class="glyphicon glyphicon-trash"></i>';
                        insert1+='</span>&nbsp;&nbsp;';
                        //alert(insert1);
                        insert1+='<span style="cursor:pointer;" id="nextactionedit1'+nid2+'" onclick=editsecondnextaction("na_s_desc'+nid2+'","na_s_date'+nid2+'","na_s_time'+nid2+'","na_s_nid'+nid2+'","#nextactionsecond'+nid2+'","'+cid+'","na_f_assign_r'+nid2+'")>';
                        insert1+='<i class="glyphicon glyphicon-pencil"></i>';
                        insert1+='</span>';
                        insert1+='</span>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</span>';
                        alert(insert1);
                        bootbox.alert("Next Action Created Successfully", function(){ console.log('This was logged in the callback!'); });
                        $(descr).val("");
                        $("#na_date1"+cid).append("<option value='' selected></option>")
                        alert(insert1);
                        $(append1).append(insert1);
                    }
                }
            });

        }
    }
    
    
    
    function funnextaction2(descr, date1, time1, cid, append1, hide1, disabled1, assignid, assignname){
        $(disabled1).attr("disabled", true);
        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];

        var desc2=$(descr).val();
        var date2=$(date1).val();
        var time2=$(time1).val();
        var assignid2=$(assignid).val();
        alert(assignid2);
        var assignname2=$(assignname).val();
        if((desc2!="")&&(date2!="")&&(time2!="")){
            $.ajax({
                url:"activestream_intermediate.php",
                type:"post",
                data:{insertnextaction:desc2, nextactiondate:date2, nextactiontime:time2, cid:cid, naassign:assignid2},
                success:function(respond){
                    var nid2=respond.trim()
                    //alert(nid2);
                    var insert1="";
                    var todate=new Date();
                    var d=todate.getDate();
                    var m=todate.getMonth()+1;
                    var y=todate.getFullYear();
                    if(m<10){
                        m="0"+m;
                    }
                    var d1=y+"-"+m+"-"+d;
                    var date3=date2;
                    var date123=date3.split("-")
                    var m3=date123[1];
                    if(m3[0]=="0"){
                        m1=m3[1];
                    }else{
                        m1=m3;
                    }   
                        insert1+='<span id="nextactionsecond'+nid2+'">';
                        insert1+='<div class="row" style="padding:0px 0px 10px 0px;" id="nextactionqueue'+nid2+'" onmouseover=functionnextaction1("#nextactionshow1'+nid2+'","#nextactionshow2'+nid2+'") onmouseout=functionnextaction2("#nextactionshow1'+nid2+'","#nextactionshow2'+nid2+'")>';
                        insert1+='<div class="col-sm-2"> <span class="pull-right"  id="nextactionshow1'+nid2+'" style="display:none;"><img src="../../Images/drag-verticalv2.png"></span>';
                        insert1+='<input type="hidden" id="na_s_desc'+nid2+'" value="'+desc2+'">';
                        insert1+='<input type="hidden" id="na_s_date'+nid2+'" value="'+date2+'">';
                        insert1+='<input type="hidden" id="na_s_time'+nid2+'" value="'+time2+'">';   
                        insert1+='<input type="hidden" id="na_s_nid'+nid2+'" value="'+nid2+'">';
                        insert1+='<input type="hidden" id="na_s_assign'+nid2+'" value="'+assignid2+'">';
                        insert1+='</div>';
                        insert1+='<div class="col-sm-10">';
                        insert1+='<div class="row">';
                        insert1+='<div class="col-sm-2" style="margin-left:-10px;">';
                        //alert(insert1);
                        if(date2=="0000-00-00"){
                        insert1+='<div style="background: url(../../Images/tagui9.png);background-repeat: no-repeat;background-size:80px 20px;color:orange;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+='Queued';
                        insert1+='</span>';
                        insert1+='</div>';
                        }else if(date2<d1){
                        insert1+='<div style="background: url(../../Images/tagui11.png);background-repeat: no-repeat;background-size:80px 20px;color:#f8f8f8;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                        insert1+='</span>';
                        insert1+='</div>';
                        }else{
                        insert1+='<div style="background: url(../../Images/tagui10.png);background-repeat: no-repeat;background-size:80px 20px;color:white;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                        insert1+='</span>';
                        insert1+='</div>';
                        }
                        insert1+='</div>';
                        insert1+='<div class="col-sm-10"><b>';
                        insert1+=desc2+'</b>&nbsp;&nbsp';
                        if((time2!="00:00")&&(time2!="00:00:00")){
                            insert1+=time2;
                        }
                        //alert(insert1);
                        insert1+='&nbsp;&nbsp;&nbsp;&nbsp;';
                        insert1+='<span style="display:none;cursor:pointer;" id="nextactionshow2'+nid2+'">';
                        insert1+='<span style="cursor:pointer;" id="nextactiondelete1'+nid2+'" onclick=functiondeletenextaction("'+nid2+'","'+append1+'")>';
                        insert1+='<i class="glyphicon glyphicon-trash"></i>';
                        insert1+='</span>&nbsp;&nbsp;';
                        //alert(insert1);
                        insert1+='<span style="cursor:pointer;" id="nextactionedit1'+nid2+'" onclick=editsecondnextaction("na_s_desc'+nid2+'","na_s_date'+nid2+'","na_s_time'+nid2+'","na_s_nid'+nid2+'","#nextactionsecond'+nid2+'","'+cid+'","na_s_assign'+nid2+'")>';
                        insert1+='<i class="glyphicon glyphicon-pencil"></i>';
                        insert1+='</span>';
                        insert1+='</span>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</span>';
                        //alert(insert1);
                    $(append1).append(insert1);
                    $(descr).val("");
                    $(date1).val("0000-00-00");
                    $(time1).val("00:00:00");
                    $(hide1).hide();
                }
            });

        }
    }



    function declaredatepicker(dateselect, date, time1, displaybutton) {
        //alert(displaybutton);
        var value1=$(dateselect).val();
        $(date).datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true, 
            todayHighlight: true
        }).datepicker('update', new Date());
        
        $(time1).clockpicker({
            placement: 'bottom',
            align: 'left',
            autoclose: true,
            'default': 'now'
        });
        if(value1=="Queued"){
            $(date).val("0000-00-00");
            $(time1).val("00:00");
            $(date).hide();
            $(time1).hide();
        }else if(value1=="Date"){
            var date1 = new Date()
            date1.setDate(date1.getDate());
            var d=date1.getDate();
            var m=date1.getMonth()+1;
            var y=date1.getFullYear();
            if(d<10) { d='0'+d } if(m<10) { m='0'+m }
            var date2=y+"-"+m+"-"+d;
            $(date).val(date2);
            $(time1).val("00:00");
            $(date).show();
            $(time1).hide();
        }else if(value1=="Date & Time"){
            var date1 = new Date()
            date1.setDate(date1.getDate());
            var d=date1.getDate();
            var m=date1.getMonth()+1;
            var y=date1.getFullYear();
            var h=date1.getHours();
            var i=date1.getMinutes();
            var t=h+":"+i;
            if(d<10) { d='0'+d } if(m<10) { m='0'+m }
            var date2=y+"-"+m+"-"+d;
            $(date).val(date2);
            $(time1).val(t);
            $(date).show();
            $(time1).show();
        }else if(value1=="Tomorrow"){
            var date1 = new Date()
            date1.setDate(date1.getDate() + 1);
            var d=date1.getDate();
            var m=date1.getMonth()+1;
            var y=date1.getFullYear();
            if(d<10) { d='0'+d } if(m<10) { m='0'+m }
            var date2=y+"-"+m+"-"+d;
            $(date).val(date2);
            $(time1).val("00:00");
            $(date).show();
            $(time1).hide();
        }else if(value1=="7 days"){
            var date1 = new Date()
            date1.setDate(date1.getDate() + 7);
            var d=date1.getDate();
            var m=date1.getMonth()+1;
            var y=date1.getFullYear();
            if(d<10) { d='0'+d } if(m<10) { m='0'+m }
            var date2=y+"-"+m+"-"+d;
            $(date).val(date2);
            $(time1).val("00:00");
            $(date).show();
            $(time1).hide();
        }else if(value1=="2 Weeks Time"){
            var date1 = new Date()
            date1.setDate(date1.getDate() + 14);
            var d=date1.getDate();
            var m=date1.getMonth()+1;
            var y=date1.getFullYear();
            if(d<10) { d='0'+d } if(m<10) { m='0'+m }
            var date2=y+"-"+m+"-"+d;
            $(date).val(date2);
            $(time1).val("00:00");
            $(date).show();
            $(time1).hide();
        }else if(value1=="30 days Time"){
            var date1 = new Date()
            date1.setDate(date1.getDate() + 30);
            var d=date1.getDate();
            var m=date1.getMonth()+1;
            var y=date1.getFullYear();
            if(d<10) { d='0'+d } if(m<10) { m='0'+m }
            var date2=y+"-"+m+"-"+d;
            $(date).val(date2);
            $(time1).val("00:00");
            $(date).show();
            $(time1).hide();
        }else if(value1=="31 days Time"){
            var date1 = new Date()
            date1.setDate(date1.getDate() + 31);
            var d=date1.getDate();
            var m=date1.getMonth()+1;
            var y=date1.getFullYear();
            if(d<10) { d='0'+d } if(m<10) { m='0'+m }
            var date2=y+"-"+m+"-"+d;
            $(date).val(date2);
            $(time1).val("00:00");
            $(date).show();
            $(time1).hide();
        }
        $(displaybutton).attr("disabled", false);
            //alert(date2);
    }



    function cancelsecondnextaction(desc, date1, time1, cid, append1, nid, assign){
        var desc2=$(desc).val();
        var date2=$(date1).val();
        var time2=$(time1).val();
        var nid2=$(nid).val();
        var assign2=$(assign).val();
        var append2=$(append1).val();
        //alert("sdf");
        $(append2).empty();
        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
        var insert1="";
        var todate=new Date();
        var d=todate.getDate();
        var m=todate.getMonth()+1;
        var y=todate.getFullYear();
        if(m<10){
            m="0"+m;
        }
        var d1=y+"-"+m+"-"+d;
        var date3=date2;
        var date123=date3.split("-")
        var m3=date123[1];
        if(m3[0]=="0"){
            m1=m3[1];
        }else{
            m1=m3;
        }
        insert1+='<div class="row" style="padding:10px 0px 10px 0px;" id="nextactionqueue'+nid2+'" onmouseover=functionnextaction1("#nextactionshow1'+nid2+'","#nextactionshow2'+nid2+'") onmouseout=functionnextaction2("#nextactionshow1'+nid2+'","#nextactionshow2'+nid2+'")>';
        insert1+='<div class="col-sm-2"> <span class="pull-right"  id="nextactionshow1'+nid2+'" style="display:none;"><img src="../../Images/drag-verticalv2.png"></span>';
        insert1+='<input type="hidden" id="na_s_desc'+nid2+'" value="'+desc2+'">';
        insert1+='<input type="hidden" id="na_s_date'+nid2+'" value="'+date2+'">';
        insert1+='<input type="hidden" id="na_s_time'+nid2+'" value="'+time2+'">';   
        insert1+='<input type="hidden" id="na_s_nid'+nid2+'" value="'+nid2+'">';
        insert1+='<input type="hidden" id="na_s_assign'+nid2+'" value="'+assign2+'">';
        insert1+='</div>';
        insert1+='<div class="col-sm-10">';
        insert1+='<div class="row" style="margin-left:-10px;">';
        //alert(insert1);
        insert1+='<div class="col-sm-2">';
        if(date2=="0000-00-00"){
        insert1+='<div style="background: url(../../Images/tagui9.png);background-repeat: no-repeat;background-size:80px 20px;color:orange;">';
        insert1+='<span style="margin-left:10px;">';
        insert1+='Queued';
        insert1+='</span>';
        insert1+='</div>';
        }else if(date2<d1){
        insert1+='<div style="background: url(../../Images/tagui11.png);background-repeat: no-repeat;background-size:80px 20px;color:#f8f8f8;">';
        insert1+='<span style="margin-left:10px;">';
        insert1+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
        insert1+='</span>';
        insert1+='</div>';
        }else{
        insert1+='<div style="background: url(../../Images/tagui10.png);background-repeat: no-repeat;background-size:80px 20px;color:white;">';
        insert1+='<span style="margin-left:10px;">';
        insert1+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
        insert1+='</span>';
        insert1+='</div>';
        }
        insert1+='</div>';
        insert1+='<div class="col-sm-10">';
        insert1+=desc2+'</b>&nbsp;&nbsp';
        if((time2!="00:00")||(time2!="00:00:00")){
            insert1+=time2;
        }
        insert1+='&nbsp;&nbsp;&nbsp;&nbsp;';
        insert1+='<span style="display:none;cursor:pointer;" id="nextactionshow2'+nid2+'">';
        insert1+='<span style="cursor:pointer;" id="nextactiondelete1'+nid2+'" onclick=functiondeletenextaction("'+nid2+'","'+append2+'")>';
        insert1+='<i class="glyphicon glyphicon-trash"></i>';
        insert1+='</span>&nbsp;&nbsp;';
        insert1+='<span style="cursor:pointer;" id="nextactionedit1'+nid2+'" onclick=editsecondnextaction("na_s_desc'+nid2+'","na_s_date'+nid2+'","na_s_time'+nid2+'","na_s_nid'+nid2+'","#nextactionsecond'+nid2+'","'+cid+'","na_s_assign'+nid2+'")>';
        insert1+='<i class="glyphicon glyphicon-pencil"></i>';
        insert1+='</span>';
        insert1+='</span>';
        insert1+='</div>';
        insert1+='</div>';
        insert1+='</div>';
        insert1+='</div>';
        alert(insert1);
        $(append2).append(insert1);
                
    }



    function funnextactionupdate1(descr, date1, time1, cid, append1, disabled1,nid, assignid, assignname){
        $(disabled1).attr("disabled", true);
        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];

        var desc2=$(descr).val();
        var date2=$(date1).val();
        var time2=$(time1).val();
        var nid2=$(nid).val();
        var assignid2=$(assignid).val();
        var assignname2=$(assignname).val();
        /*alert(desc2);
        alert(date2);
        alert(time2);
        alert(nid2);*/
        if((desc2!="")&&(date2!="")&&(time2!="")){
            $.ajax({
                url:"activestream_intermediate.php",
                type:"post",
                data:{updatenextaction:desc2, nextactiondate:date2, nextactiontime:time2, cid:cid, nid:nid2, naassign:assignid2},
                success:function(respond){
                    var cccc=respond.trim()
                    //alert(cccc);
                    var insert1="";
                    var todate=new Date();
                    var d=todate.getDate();
                    var m=todate.getMonth()+1;
                    var y=todate.getFullYear();
                    if(m<10){
                        m="0"+m;
                    }
                    var d1=y+"-"+m+"-"+d;
                    var date3=date2;
                    var date123=date3.split("-")
                    var m3=date123[1];
                    if(m3[0]=="0"){
                        m1=m3[1];
                    }else{
                        m1=m3;
                    }   
                        insert1+='<span id="nextactionsecond'+nid2+'">';
                        insert1+='<div class="row" style="padding:15px 0px 10px 0px;" id="nextactionqueue'+nid2+'" onmouseover=functionnextaction1("#nextactionshow1'+nid2+'","#nextactionshow2'+nid2+'") onmouseout=functionnextaction2("#nextactionshow1'+nid2+'","#nextactionshow2'+nid2+'")>';
                        insert1+='<div class="col-sm-2"> <span class="pull-right"  id="nextactionshow1'+nid2+'" style="display:none;"><img src="../../Images/drag-verticalv2.png"></span>';
                        insert1+='<input type="hidden" id="na_s_desc'+nid2+'" value="'+desc2+'">';
                        insert1+='<input type="hidden" id="na_s_date'+nid2+'" value="'+date2+'">';
                        insert1+='<input type="hidden" id="na_s_time'+nid2+'" value="'+time2+'">';   
                        insert1+='<input type="hidden" id="na_s_nid'+nid2+'" value="'+nid2+'">';
                        insert1+='<input type="hidden" id="na_s_assign'+nid2+'" value="'+assignid2+'">';
                        insert1+='</div>';
                        insert1+='<div class="col-sm-10">';
                        insert1+='<div class="row" style="margin-left:-5px;">';
                        insert1+='<div class="col-sm-2">';
                        //alert(insert1);
                        if(date2=="0000-00-00"){
                        insert1+='<div style="background: url(../../Images/tagui9.png);background-repeat: no-repeat;background-size:80px 20px;color:orange;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+='Queued';
                        insert1+='</span>';
                        insert1+='</div>';
                        }else if(date2<d1){
                        insert1+='<div style="background: url(../../Images/tagui11.png);background-repeat: no-repeat;background-size:80px 20px;color:#f8f8f8;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                        insert1+='</span>';
                        insert1+='</div>';
                        }else{
                        insert1+='<div style="background: url(../../Images/tagui10.png);background-repeat: no-repeat;background-size:80px 20px;color:white;">';
                        insert1+='<span style="margin-left:10px;">';
                        insert1+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                        insert1+='</span>';
                        insert1+='</div>';
                        }
                        insert1+='</div>';
                        insert1+='<div class="col-sm-10"><b>';
                        insert1+=desc2+'</b>&nbsp;&nbsp';
                        if((time2!="00:00")&&(time2!="00:00:00")){
                            insert1+=time2;
                        }
                        //alert(insert1);
                        insert1+='&nbsp;&nbsp;&nbsp;&nbsp;';
                        insert1+='<span style="display:none;cursor:pointer;" id="nextactionshow2'+nid2+'">';
                        insert1+='<span style="cursor:pointer;" id="nextactiondelete1'+nid2+'" onclick=functiondeletenextaction("'+nid2+'","'+append1+'")>';
                        insert1+='<i class="glyphicon glyphicon-trash"></i>';
                        insert1+='</span>&nbsp;&nbsp;';
                        //alert(insert1);
                        insert1+='<span style="cursor:pointer;" id="nextactionedit1'+nid2+'" onclick=editsecondnextaction("na_s_desc'+nid2+'","na_s_date'+nid2+'","na_s_time'+nid2+'","na_s_nid'+nid2+'","#nextactionsecond'+nid2+'","'+cid+'","na_s_assign'+nid2+'")>';
                        insert1+='<i class="glyphicon glyphicon-pencil"></i>';
                        insert1+='</span>';
                        insert1+='</span>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</div>';
                        insert1+='</span>';
                        //alert(insert1);
                    $(append1).empty();
                    $(append1).append(insert1);
                    $(descr).val("");
                    $(date1).val("0000-00-00");
                    $(time1).val("00:00:00");
                }
            });

        }
    }




    function editsecondnextaction(desc, date1, time1, nid, show, cid, assign){
        var empid=new Array();
        var empname=new Array();
        empid=<?php echo json_encode($emailid1);?>;
        empname=<?php echo json_encode($employeename1);?>;
        var adminid="<?php echo $adminemailid;?>";
        //alert("sad");
        var desc2=$("#"+desc).val();
        var date2=$("#"+date1).val();
        var time2=$("#"+time1).val();
        var nid2=$("#"+nid).val();
        var assign2=$("#"+assign).val();
        //alert(nid2);
        var insert="";
        insert+='<div class="col-md-2">';
        insert+='<input type="hidden" id="csed1" value="'+desc2+'">';
        insert+='<input type="hidden" id="etad1" value="'+date2+'">';
        insert+='<input type="hidden" id="emit1" value="'+time2+'">';
        insert+='<input type="hidden" id="dic1" value="'+cid+'">';
        insert+='<input type="hidden" id="wohs1" value="'+show+'">';
        insert+='<input type="hidden" id="din1" value="'+nid2+'">';
        insert+='<input type="hidden" id="ngissa1" value="'+assign2+'">';
        insert+='</div>';
		insert+='<div class="col-md-10">';
		insert+='<h5><b>Next Action</b></h5>';

        insert+='<input type="hidden" id="na_id_s_e" value="'+nid2+'">';
		insert+='<textarea class="form-control" id="na_descr_s_e'+nid2+'" rows="5" onchange=functionvisiblenextaction("#na_descr_s_e'+nid2+'","#updatenextaction_s_e","#na_date1_e'+nid2+'")>'+desc2+'</textarea><br>';
		insert+='<select name="na_date1" id="na_date1_e'+nid2+'" style="height:30px;border-radius:5px;" onchange=declaredatepicker("#na_date1_e'+nid2+'","#na_date_s_e'+nid2+'","#na_time_s_e'+nid2+'", "#updatenextaction_s_e")>';
		insert+='<option></option>';
		if(date2=="0000-00-00"){
		insert+='<option value="Queued" selected>Queued</option>';
		insert+='<option value="Date">Date</option>';
		insert+='<option value="Date & Time">Date & Time</option>';
		}else if((date2!="0000-00-00")&&(time2=="00:00:00")){
		insert+='<option value="Queued">Queued</option>';
		insert+='<option value="Date" selected>Date</option>';
		insert+='<option value="Date & Time">Date & Time</option>';
		}else{
		insert+='<option value="Queued">Queued</option>';
		insert+='<option value="Date">Date</option>';
		insert+='<option value="Date & Time" selected>Date & Time</option>';
		}
		insert+='<option value="Tomorrow">Tomorrow</option>';
		insert+='<option value="7 days">7 days Time</option>';
		insert+='<option value="2 Weeks Time">2 Weeks Time</option>';
		insert+='<option value="30 days Time">30 days Time</option>';
		insert+='<option value="31 days Time">31 days Time</option>';
		insert+='</select>';
		if(date2!="0000-00-00"){
        insert+='<input type="text" name="na_date" value="'+date2+'" id="na_date_s_e'+nid2+'" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;">';
        }else{
		insert+='<input type="text" name="na_date" value="'+date2+'" id="na_date_s_e'+nid2+'" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
		}
		if(time2!="00:00:00"){
		insert+='<input type="text" name="na_time" value="'+time2+'" id="na_time_s_e'+nid2+'" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;">';
		}else{
		insert+='<input type="text" name="na_time" value="'+time2+'" id="na_time_s_e'+nid2+'" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
		}
		insert+='<span class="pull-right">Assign to&nbsp;&nbsp;&nbsp';
        insert+='<span class="dropdown">';
        for(h=0;h<empid.length;h++){
            if(assign2==adminid){
                ename="Me";
            }else if(empid[h]==assign2){
                ename=empname[h];
            }
        }
        insert+='<input type="hidden" id="na_assign_id'+nid2+'" value="'+assign2+'">';
        insert+='<button class="btn btn-default dropdown-toggle" id="na_assign_name'+nid2+'" type="button" data-toggle="dropdown">'+ename;
        insert+='</button><span class="caret" style="margin-left:-10px;"></span>';
        insert+='<ul class="dropdown-menu">';
        for(h=0;h<empid.length;h++){
        empid1=empid[h];
        if(empid1==assign2){
        employeename11="Me";
        }else{
        employeename11=empname[h];
        }
        insert+='<li><a onclick=funemployee("'+empid1+'","'+employeename11+'","'+cid+'","na_assign_id'+nid2+'","na_assign_name'+nid2+'")>'+employeename11+'</a></li>';
        }
        insert+='</ul>';
        insert+='</span>';
        insert+='</span>';
		insert+='</span>';
		insert+='<br><br>';
		insert+='<input type="button" id="updatenextaction_s_e" class="btn btn-primary" value="Update" onclick=funnextactionupdate1("#na_descr_s_e'+nid2+'","#na_date_s_e'+nid2+'","#na_time_s_e'+nid2+'","'+cid+'","#nextactionsecond'+nid2+'","#updatenextaction_f_e","#din1","#na_assign_id'+nid2+'","#na_assign_name'+nid2+'") >';
		insert+='<span style="margin-left:50px;color:grey;cursor:pointer;" onclick=cancelsecondnextaction("#csed1","#etad1","#emit1","#dic1","#wohs1","#din1","#ngissa1")>Cancel1</span>';

		insert+='<br></div>';
        //alert(insert);
        $(show).empty();
        $(show).append(insert);
        callpicker("#na_date_s_e"+nid2, "#na_time_s_e"+nid2);
    }

 function cancelfirstnextaction1(desc, date1, time1, cid, append1, nid, assign){
        var desc2=$(desc).val();
        var date2=$(date1).val();
        var time2=$(time1).val();
        var nid2=$(nid).val();
        var assign2=$(assign).val();
        var append2=$(append1).val();
        status="pending";
        $.ajax({
            url:"activestream_intermediate.php",
            type:"post",
            data:{completednextaction:nid, status:status},
            success:function(respond){
                //alert(respond);
            }
        });
        $(append2).empty();
        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
        var insert="";
        var todate=new Date();
        var d=todate.getDate();
        var m=todate.getMonth()+1;
        var y=todate.getFullYear();
        if(m<10){
            m="0"+m;
        }
        var d1=y+"-"+m+"-"+d;
        var date3=date2;
        var date123=date3.split("-")
        var m3=date123[1];
        if(m3[0]=="0"){
            m1=m3[1];
        }else{
            m1=m3;
        }
        insert+='<div class="col-md-2">';
        insert+='<br>';
        insert+='<div class="checkbox pull-right" style="padding-top:10px;">';
        insert+='<label>';
        insert+='<input type="checkbox" value="" id="checkbox1'+nid2+'"  onchange=checkitscompleted("#checkbox1'+nid2+'","'+nid2+'","#firstnextaction'+cid+'","'+desc2+'","'+date2+'","'+time2+'","'+cid+'","'+assign2+'")>';
        insert+='<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>';
        insert+='</label>';
        insert+='</div>';
        insert+='<input type="hidden" id="na_f_desc_r" value="'+desc2+'">';
        insert+='<input type="hidden" id="na_f_date_r" value="'+date2+'">';
        insert+='<input type="hidden" id="na_f_time_r" value="'+time2+'">';
        insert+='<input type="hidden" id="na_f_id_r" value="'+nid2+'">';
        insert+='<input type="text" id="na_f_assign_r" value="'+assign2+'">';
        insert+='</div>';
        insert+='<div class="col-md-10">';
        insert+='<h5>Next Action';
        insert+='<span class="pull-right" style="color:grey;cursor:pointer;" onclick=editfirstnextaction("na_f_desc_r","na_f_date_r","na_f_time_r","'+append2+'","'+cid+'","na_f_id_r","na_f_assign_r")>Edit</span></h5>'
        insert+='<b>'+desc2+'</b>';
        insert+='<div class="row" style="padding:10px 0px 10px 0px;">';
        insert+='<div class="col-sm-8">';
        //alert(date2+"<"+d1+":");
        //alert(date2<d1);
        if(date2=="0000-00-00"){
        insert+='<div style="background: url(../../Images/tagui6.png);background-repeat: no-repeat;background-size:80px 20px;color:orange;">';
        insert+='<span style="margin-left:10px;">';
        insert+='Queued';
        insert+='</span>';
        insert+='</div>';
        }else if(date2<d1){
        insert+='<div style="background: url(../../Images/tagui4.png);background-repeat: no-repeat;background-size:80px 20px;color:#f8f8f8;">';
        insert+='<span style="margin-left:10px;">';
        insert+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
        insert+='</span>';
        insert+='</div>';
        }else{
        insert+='<div style="background: url(../../Images/tagui5.png);background-repeat: no-repeat;background-size:80px 20px;color:white;">';
        insert+='<span style="margin-left:10px;">';
        insert+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
        insert+='</span>';
        insert+='</div>';
        }
        insert+='</div>';
        insert+='<div class="col-sm-4">';
        insert+='<span class="pull-right" onclick=shownextactionqueue("#newnextactionadd")>';
        insert+='<span class="add_new_action"></span>';
        insert+='</span>';
        insert+='</div>';
        insert+='</div>';
        insert+='</div>';
        $(append2).append(insert);
                
    }
    
    
function checkitscompleted1(id1, nid2, show,desc2,date2,time2,cid, assign2){
                            alert("fdf");
                            alert(id1);
                            alert(nid2);
                            var empid=new Array();
                            var empname=new Array();
                            empid=<?php echo json_encode($emailid1);?>;
                            empname=<?php echo json_encode($employeename1);?>;
                            var adminid="<?php echo $adminemailid;?>";
                            if($(id1).is(':checked')){
                                status="completed";
                                $.ajax({
                                    url:"activestream_intermediate.php",
                                    type:"post",
                                    data:{completednextaction:nid2, status:status},
                                    success:function(respond){
                                        //alert(respond);
                                        var insert="";
                                        insert+='<div class="col-md-2">';
                                        insert+='<input type="hidden" id="csed1" value="'+desc2+'">';
                                        insert+='<input type="hidden" id="etad1" value="'+date2+'">';
                                        insert+='<input type="hidden" id="emit1" value="'+time2+'">';
                                        insert+='<input type="hidden" id="dic1" value="'+cid+'">';
                                        insert+='<input type="hidden" id="wohs1" value="'+show+'">';
                                        insert+='<input type="hidden" id="din1" value="'+nid2+'">';
                                        insert+='<input type="text" id="ngissa1" value="'+assign2+'">';
                                        insert+='</div>';
                                		insert+='<div class="col-md-10">';
                                		insert+='<h5><b>Next Action</b></h5>';
                                        insert+='<input type="hidden" id="na_id_f_e" value="'+nid2+'">';
                                		insert+='<textarea class="form-control" id="na_descr_s_c" rows="5" onchange=functionvisiblenextaction("#na_descr_s_c","#updatenextaction_f_e","#na_date1_c")></textarea><br>';
                                		insert+='<select name="na_date1" id="na_date1_c" style="height:30px;border-radius:5px;" onchange=declaredatepicker("#na_date1_c","#na_date_s_c","#na_time_s_c")>';
                                		insert+='<option value="Queued" selected>Queued</option>';
                                		insert+='<option value="Date">Date</option>';
                                		insert+='<option value="Date & Time">Date & Time</option>';
                                		insert+='<option value="Tomorrow">Tomorrow</option>';
                                		insert+='<option value="7 days">7 days Time</option>';
                                		insert+='<option value="2 Weeks Time">2 Weeks Time</option>';
                                		insert+='<option value="30 days Time">30 days Time</option>';
                                		insert+='<option value="31 days Time">31 days Time</option>';
                                		insert+='</select>';
                                		insert+='<input type="text" name="na_date" value="0000-00-00" id="na_date_s_c" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
                                		
                                		insert+='<input type="text" name="na_time" value="00:00:00" id="na_time_s_c" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
                                		
                                		insert+='<span class="pull-right">Assign to&nbsp;&nbsp;&nbsp';
                                        insert+='<span class="dropdown">';
                                        for(h=0;h<empid.length;h++){
                                            if(assign2==adminid){
                                                ename="Me";
                                            }else if(empid[h]==assign2){
                                                ename=empname[h];
                                            }
                                        }
                                        insert+='<input type="hidden" id="na_assign_id'+nid2+'" value="'+assign2+'">';
                                        insert+='<button class="btn btn-default dropdown-toggle" id="na_assign_name'+nid2+'" type="button" data-toggle="dropdown">'+ename;
                                        insert+='</button><span class="caret" style="margin-left:-10px;"></span>';
                                        insert+='<ul class="dropdown-menu">';
                                        for(h=0;h<empid.length;h++){
                                        empid1=empid[h];
                                        if(empid1==assign2){
                                        employeename11="Me";
                                        }else{
                                        employeename11=empname[h];
                                        }
                                        insert+='<li><a onclick=funemployee("'+empid+'","'+employeename11+'","'+cid+'","na_assign_id'+nid2+'","na_assign_name'+nid2+'")>'+employeename11+'</a></li>';
                                        }
                                        insert+='</ul>';
                                        insert+='</span>';
                                        insert+='</span>';
                                		insert+='</span>';
                                		insert+='<br><br>';
                                		insert+='<br><br>';
                                		insert+='<input type="button" id="savenextaction_c" class="btn btn-primary" value="Save" onclick=funnextactionupdate1("'+desc2+'","'+date2+'","'+time2+'","'+cid+'","'+show+'","#savenextaction_c","'+nid2+'","'+assign2+'") >';
                                		insert+='<span style="margin-left:50px;color:grey;cursor:pointer;" onclick=cancelfirstnextaction1("#csed1","#etad1","#emit1","#dic1","#wohs1","#din1","#ngissa1")>Cancel</span>';
                                
                                		insert+='</div>';
                                        //alert(insert);
                                        $(show).empty();
                                        $(show).append(insert);
                                        callpicker("#na_date_s_c", "#na_time_s_c");
                                    }
                                });
                            }
                        }
                        
                         function cancelfirstnextaction(desc, date1, time1, cid, append1, nid, assignid){
        var desc2=$(desc).val();
        var date2=$(date1).val();
        var time2=$(time1).val();
        var assignid2=$(assignid).val();
        var nid2=$(nid).val();
        var append2=$(append1).val();
        $(append2).empty();
        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
        var insert="";
        var todate=new Date();
        var d=todate.getDate();
        var m=todate.getMonth()+1;
        var y=todate.getFullYear();
        if(m<10){
            m="0"+m;
        }
        var d1=y+"-"+m+"-"+d;
        var date3=date2;
        var date123=date3.split("-")
        var m3=date123[1];
        if(m3[0]=="0"){
            m1=m3[1];
        }else{
            m1=m3;
        }
        insert+='<div class="col-md-2">';
        insert+='<br>';
        insert+='<div class="checkbox pull-right" style="padding-top:10px;">';
        insert+='<label>';
        insert+='<input type="checkbox" value="" id="checkbox1'+nid2+'"  onchange=checkitscompleted("#checkbox1'+nid2+'","'+nid2+'","#firstnextaction'+cid+'","'+desc2+'","'+date2+'","'+time2+'","'+cid+'","'+assignid2+'")>';
        insert+='<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>';
        insert+='</label>';
        insert+='</div>';
        insert+='<input type="hidden" id="na_f_desc_r" value="'+desc2+'">';
        insert+='<input type="hidden" id="na_f_date_r" value="'+date2+'">';
        insert+='<input type="hidden" id="na_f_time_r" value="'+time2+'">';
        insert+='<input type="text" id="na_f_id_r" value="'+nid2+'">';
        insert+='<input type="text" id="na_f_assign_r" value="'+assignid2+'">';
        insert+='<input type="text" id="na_f_aasdfsad" value="'+append2+'">';
        insert+='</div>';
        insert+='<div class="col-md-10">';
        insert+='<h5>Next Action';
        insert+='<span class="pull-right" style="color:grey;cursor:pointer;" onclick=editfirstnextaction("na_f_desc_r","na_f_date_r","na_f_time_r","'+append2+'","'+cid+'","na_f_id_r","na_f_assign_r")>Edit</span></h5>'
        insert+='<b>'+desc2+'</b>';
        insert+='<div class="row" style="padding:10px 0px 10px 0px;">';
        insert+='<div class="col-sm-8">';
        //alert(date2+"<"+d1+":");
        //alert(date2<d1);
        if(date2=="0000-00-00"){
        insert+='<div style="background: url(../../Images/tagui6.png);background-repeat: no-repeat;background-size:80px 20px;color:orange;">';
        insert+='<span style="margin-left:10px;">';
        insert+='Queued';
        insert+='</span>';
        insert+='</div>';
        }else if(date2<d1){
        insert+='<div style="background: url(../../Images/tagui4.png);background-repeat: no-repeat;background-size:80px 20px;color:#f8f8f8;">';
        insert+='<span style="margin-left:10px;">';
        insert+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
        insert+='</span>';
        insert+='</div>';
        }else{
        insert+='<div style="background: url(../../Images/tagui5.png);background-repeat: no-repeat;background-size:80px 20px;color:white;">';
        insert+='<span style="margin-left:10px;">';
        insert+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
        insert+='</span>';
        insert+='</div>';
        }
        insert+='</div>';
        insert+='<div class="col-sm-4">';
        insert+='<span class="pull-right" onclick=shownextactionqueue("#newnextactionadd")>';
        insert+='<span class="add_new_action"></span>';
        insert+='</span>';
        insert+='</div>';
        insert+='</div>';
        insert+='</div>';
        $(append2).append(insert);
                
    }
    
     function funnextactionupdate(descr, date1, time1, cid, append1, disabled2, nid, assignid, assignname){
        var desc2=$(descr).val();
        var date2=$(date1).val();
        var time2=$(time1).val();
        var assignid2=$(assignid).val();
        var assignname2=$(assignname).val();
        var append2=$(append1).val();
        var nid2=$(nid).val();
        $(disabled2).attr("disabled", true);
        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
        if((desc2!="")&&(date2!="")&&(time2!="")){
            var insert="";
            $.ajax({
                url:"activestream_intermediate.php",
                type:"post",
                data:{updatenextaction:desc2, nextactiondate:date2, nextactiontime:time2, cid:cid, nid:nid2, naassign:assignid2},
                success:function(respond){
                    //alert(respond);
                    var cccc=respond.trim()
                    var insert="";
                    var todate=new Date();
                    var d=todate.getDate();
                    var m=todate.getMonth()+1;
                    var y=todate.getFullYear();
                    if(m<10){
                        m="0"+m;
                    }
                    var d1=y+"-"+m+"-"+d;
                    var date3=date2;
                    var date123=date3.split("-")
                    var m3=date123[1];
                    if(m3[0]=="0"){
                        m1=m3[1];
                    }else{
                        m1=m3;
                    }
                    alert(cccc);
                    if(cccc=="yes"){
                    insert+='<div class="col-md-2">';
                    insert+='<br>';
                    insert+='<div class="checkbox pull-right" style="padding-top:10px;">';
                    insert+='<label>';
                    insert+='<input type="checkbox" value="" id="checkbox1'+nid2+'" onchange=checkitscompleted("#checkbox1'+nid2+'","'+nid2+'","#firstnextaction'+cid+'","'+desc2+'","'+date2+'","'+time2+'","'+cid+'","'+assignid2+'")>';
                    insert+='<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>';
                    insert+='</label>';
                    insert+='</div>';
                    insert+='</div>';
                    insert+='<div class="col-md-10">';
                    insert+='<h5>Next Action';
                    insert+='<input type="hidden" id="na_f_desc_r" value="'+desc2+'">';
                    insert+='<input type="hidden" id="na_f_date_r" value="'+date2+'">';
                    insert+='<input type="hidden" id="na_f_time_r" value="'+time2+'">';
                    insert+='<input type="text" id="na_f_id_r" value="'+nid2+'">';
                    insert+='<input type="text" id="na_f_assign_r" value="'+assignid2+'">';
                    insert+='<span class="pull-right" style="color:grey;cursor:pointer;" onclick=editfirstnextaction("na_f_desc_r","na_f_date_r","na_f_time_r","'+append2+'","'+cid+'","na_f_id_r","na_f_assign_r")>Edit</span></h5>'
                    insert+='<b>'+desc2+'</b>';
                    insert+='<div class="row" style="padding:10px 0px 10px 0px;">';
                    insert+='<div class="col-sm-8">';
                    if(date2=="0000-00-00"){
                    insert+='<div style="background: url(../../Images/tagui6.png);background-repeat: no-repeat;background-size:80px 20px;color:orange;">';
                    insert+='<span style="margin-left:10px;">';
                    insert+='Queued';
                    insert+='</span>';
                    insert+='</div>';
                    }else if(date2<d1){
                    insert+='<div style="background: url(../../Images/tagui4.png);background-repeat: no-repeat;background-size:80px 20px;color:#f8f8f8;">';
                    insert+='<span style="margin-left:10px;">';
                    insert+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                    insert+='</span>';
                    insert+='</div>';
                    }else{
                    insert+='<div style="background: url(../../Images/tagui5.png);background-repeat: no-repeat;background-size:80px 20px;color:white;">';
                    insert+='<span style="margin-left:10px;">';
                    insert+=monthNames[m1]+'&nbsp;&nbsp;'+date123[2];
                    insert+='</span>';
                    insert+='</div>';
                    }
                    insert+='</div>';
                    insert+='<div class="col-sm-4">';
                    insert+='<span class="pull-right" onclick=shownextactionqueue("#newnextactionadd")>';
                    insert+='<span class="add_new_action"></span>';
                    insert+='</span>';
                    insert+='</div>';
                    insert+='</div>';
                    insert+='</div>';
                    alert(insert);
                    alert(append2);
                    $(append2).empty();
                    $(append2).append(insert);
                    }
                }
            });

        }
    }
    
    
    function callpicker(id, id1){
        $(id).datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true, 
            todayHighlight: true
        });
        $(id1).clockpicker({
            placement: 'bottom',
            align: 'left',
            autoclose: true
        });
	}


 function editfirstnextaction(desc, date1, time1, show, cid, nid, assign){
        var empid=new Array();
        var empname=new Array();
        empid=<?php echo json_encode($emailid1);?>;
        empname=<?php echo json_encode($employeename1);?>;
        var adminid="<?php echo $adminemailid;?>";
        var desc2=$("#"+desc).val();
        var date2=$("#"+date1).val();
        var time2=$("#"+time1).val();
        var nid2=$("#"+nid).val();
        var assign2=$("#"+assign).val();
        var insert="";
        insert+='<div class="col-md-2">';
        insert+='<input type="text" id="csed" value="'+desc2+'">';
        insert+='<input type="text" id="etad" value="'+date2+'">';
        insert+='<input type="text" id="emit" value="'+time2+'">';
        insert+='<input type="text" id="dic" value="'+cid+'">';
        insert+='<input type="text" id="wohs" value="'+show+'">';
        insert+='<input type="text" id="din" value="'+nid2+'">';
        insert+='<input type="text" id="ngissa" value="'+assign2+'">';
        insert+='</div>';
		insert+='<div class="col-md-10">';
		insert+='<h5><b>Next Action</b></h5>';

        insert+='<input type="hidden" id="na_id_f_e" value="'+nid2+'">';
		insert+='<textarea class="form-control" id="na_descr_f_e" rows="5" onchange=functionvisiblenextaction("#na_descr_f_e","#updatenextaction_f_e","#na_date1_e")>'+desc2+'</textarea><br>';
		insert+='<select name="na_date1" id="na_date1_e" style="height:30px;border-radius:5px;" onchange=declaredatepicker("#na_date1_e","#na_date_f_e","#na_time_f_e")>';
		insert+='<option></option>';
		if(date2=="0000-00-00"){
		insert+='<option value="Queued" selected>Queued</option>';
		insert+='<option value="Date">Date</option>';
		insert+='<option value="Date & Time">Date & Time</option>';
		}else if((date2!="0000-00-00")&&(time2=="00:00:00")){
		insert+='<option value="Queued">Queued</option>';
		insert+='<option value="Date" selected>Date</option>';
		insert+='<option value="Date & Time">Date & Time</option>';
		}else{
		insert+='<option value="Queued">Queued</option>';
		insert+='<option value="Date">Date</option>';
		insert+='<option value="Date & Time" selected>Date & Time</option>';
		}
		insert+='<option value="Tomorrow">Tomorrow</option>';
		insert+='<option value="7 days">7 days Time</option>';
		insert+='<option value="2 Weeks Time">2 Weeks Time</option>';
		insert+='<option value="30 days Time">30 days Time</option>';
		insert+='<option value="31 days Time">31 days Time</option>';
		insert+='</select>';
		if(date2!="0000-00-00"){
        insert+='<input type="text" name="na_date" value="'+date2+'" id="na_date_f_e" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;">';
        }else{
		insert+='<input type="text" name="na_date" value="'+date2+'" id="na_date_f_e" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
		}
		if(time2!="00:00:00"){
		insert+='<input type="text" name="na_time" value="'+time2+'" id="na_time_f_e" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;">';
		}else{
		insert+='<input type="text" name="na_time" value="'+time2+'" id="na_time_f_e" readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
		}
		insert+='<span class="pull-right">Assign to&nbsp;&nbsp;&nbsp';
        insert+='<span class="dropdown">';
        for(h=0;h<empid.length;h++){
            if(assign2==adminid){
                ename="Me";
            }else if(empid[h]==assign2){
                ename=empname[h];
            }
        }
        insert+='<input type="hidden" id="na_assign_id_f_e" value="'+assign2+'">';
        insert+='<button class="btn btn-default dropdown-toggle" id="na_assign_name_f_e" type="button" data-toggle="dropdown">'+ename;
        insert+='</button><span class="caret" style="margin-left:-10px;"></span>';
        insert+='<ul class="dropdown-menu">';
        for(h=0;h<empid.length;h++){
        empid1=empid[h];
        if(empid1==adminid){
        employeename11="Me";
        }else{
        employeename11=empname[h];
        }
        insert+='<li><a onclick=funemployee("'+empid1+'","'+employeename11+'","'+cid+'","na_assign_id_f_e","na_assign_name_f_e")>'+employeename11+'</a></li>';
        }
        insert+='</ul>';
        insert+='</span>';
        insert+='</span>';
		insert+='</span>';
		insert+='<br><br>';
		insert+='<input type="button" id="updatenextaction_f_e" class="btn btn-primary" value="Update" onclick=funnextactionupdate("#na_descr_f_e","#na_date_f_e","#na_time_f_e","'+cid+'","#wohs","#updatenextaction_f_e","#na_id_f_e","#na_assign_id_f_e","#na_assign_name_f_e") >';
		insert+='<span style="margin-left:50px;color:grey;cursor:pointer;" onclick=cancelfirstnextaction("#csed","#etad","#emit","#dic","#wohs","#din","#ngissa")>Cancel</span>';

		insert+='</div>';
        //alert(insert);
        $(show).empty();
        $(show).append(insert);
        callpicker("#na_date_f_e", "#na_time_f_e");
    }
    
    
    