<?php
session_start();
$companyname=$_SESSION['companyname'];
$adminemailid=$_SESSION['emailid'];
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
if(($adminemailid !="")&&($companyname!="")){
require_once('../Control/address.php');
$objaddress=new addressctrl();
require_once('../Control/sales.php');
$objsales=new salesctrl();
require_once('../Control/contact.php');
$objcontact=new contactctrl();
if(isset($_POST['value'])){
    $cid=$_POST['value'];
    $cont_id=$_POST['cont_id'];
    //echo $c_id;
}
$i=0;
$result_status=$objsales->salesselectallemployee($companyname, $adminemailid, "signupdetails", "no");
foreach($result_status as $row_status){
    $emailid1[$i]=$row_status['emailid'];
    $employeename1[$i]=$row_status['employeename'];
    $i++;
}
$k=0;

$result_pipe=$objsales->salesselectallemployee($companyname, $adminemailid, "sales_pipe_type", "no");
foreach($result_pipe as $row_pipe){
    $pipe_id[$k]=$row_pipe['id'];
    $pipe_name[$k]=$row_pipe['pipe_name'];
    $pipe_percentage[$k]=$row_pipe['pipe_percentage'];
    $k++;
}
$k1=0;

$result_call_ans=$objsales->salesselectallemployee($companyname, $adminemailid, "sales_call_answer_type", "no");
foreach($result_call_ans as $row_call_ans){
    $c_ans_id_a[$k1]=$row_call_ans['id'];
    $c_ans_name_a[$k1]=$row_call_ans['c_ans_name'];
    $k1++;
}
?>

<?php
for($kk=0;$kk<count($emailid1);$kk++){
    $emailid11=$emailid1[$kk];
    $employeename11=$employeename1[$kk];
    if($emailid11==$c_owner_id){
        $c_owner_name=$employeename11;
    }
}
?>

<?php
for($i=0;$i<count($cont_id);$i++){
    $c_id=$cont_id[$i];
        if($cid==$c_id){
            break;
        }
}


            $result_contact=$objsales->salesselectedid("viewcontact", $c_id);
            foreach($result_contact as $row_contact){
                $c_companyname=$row_contact['c_companyname'];
                $c_emailid=$row_contact['c_emailid'];
                $c_delete=$row_contact['c_delete']; 
                $c_id=$row_contact['c_id'];
                $c_title=$row_contact['c_title'];
                $c_fname=$row_contact['c_fname'];
                $c_lname=$row_contact['c_lname'];
                $c_jobtitle=$row_contact['c_jobtitle'];
                $c_a_line=$row_contact['c_a_line'];
                $c_a_city=$row_contact['c_a_city'];
                $c_a_state=$row_contact['c_a_state'];
                $c_a_country=$row_contact['c_a_country'];
                $c_a_pincode=$row_contact['c_a_pincode'];
                $c_background=$row_contact['c_background'];
                $c_owner_id=$row_contact['c_owner_id'];
                $c_private=$row_contact['c_private'];
                $c_dob=$row_contact['c_dob'];
                $c_dtime=$row_contact['c_dtime'];
                $c_create_by=$row_contact['c_create_by'];
                $c_create_type=$row_contact['c_create_type'];
                $o_id=$row_contact['o_id'];
                $o_name=$row_contact['o_name'];
                $o_desc=$row_contact['o_desc'];
                $o_phone=$row_contact['o_phone'];
                $o_url=$row_contact['o_url'];
                $o_line=$row_contact['o_line'];
                $o_city=$row_contact['o_city'];
                $o_state=$row_contact['o_state'];
                $o_country=$row_contact['o_country'];
                $o_pincode=$row_contact['o_pincode'];
                $o_create_by=$row_contact['o_create_by'];
                $o_create_type=$row_contact['o_create_type'];
                $s_name=$row_contact['s_name'];
                $s_desc=$row_contact['s_desc'];
                $s_color=$row_contact['s_color'];
                $t_name=$row_contact['t_name'];
                $t_desc=$row_contact['t_desc'];
                $l_name=$row_contact['l_name'];
                $status_id=$row_contact['status_id']; 
                $tag_id=$row_contact['tag_id']; 
                $lead_id=$row_contact['lead_id']; 
                $c_code=$row_contact['c_code'];
                $cont_imagepath=$row_contact['cont_imagepath'];
                $viewrowid="viewcontact".$c_id;
                $viewrowid1="#viewcontact".$c_id;
                $value=$c_companyname."#@".$c_emailid."#@".$c_id."#@".$c_title."#@".$c_fname."#@".$c_lname."#@".$c_jobtitle."#@".$c_a_line."#@".$c_a_city."#@".$c_a_state."#@".$c_a_country."#@".$c_a_pincode."#@".$c_background."#@".$c_owner_id."#@".$c_private."#@".$c_dob."#@".$c_dtime."#@".$c_create_by."#@".$c_create_type."#@".$o_id."#@".$o_name."#@".$o_desc."#@".$o_phone."#@".$o_url."#@".$o_line."#@".$o_city."#@".$o_state."#@".$o_country."#@".$o_pincode."#@".$o_create_by."#@".$o_create_type."#@".$s_name."#@".$s_desc."#@".$s_color."#@".$t_name."#@".$t_desc."#@".$l_name."#@".$c_delete."#@".$status_id."#@".$tag_id."#@".$lead_id;
                //echo $value;
            }
            
                ?>
<style>

.dropdown, .dropdown-toggle{
border:0px;
}

.dropdown a:hover {background-color: white;}


.add_new_action {
    background: url(../../Images/add_delete.png) no-repeat -35px -94px transparent;
    width: 17px;
    height: 17px;
    display: block;
    position: absolute;
    content: "";
    display: block;
    text-indent: -9999px;
    cursor: pointer;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
    position: static;
}
</style>  
                <div class="showcontactidbyid<?php echo $c_id;?>" style="padding:0px 20px;">
                <div class="row" style="background-color:#f0f0f0;padding:0px;margin-top:-15px;margin-left:15px;cursor:pointer;">
                    <span class="btn btn-default" onclick="backcontact()"><span style=" transform: rotate(180deg);" class="glyphicon glyphicon-share-alt"></span></span>
                    <span class="pull-right">
                        <?php if($i==0){ ?>
                        <span class="btn btn-default" style="display:none;" onclick="beforedata('<?php echo $beforeid;?>','<?php echo $afterid;?>','<?php echo $current;?>')"><i class="fa fa-chevron-up"></i></span>
                        <span class="btn btn-default"  onclick="viewcontact('<?php echo $cont_id[$i+1];?>')"><i class="fa fa-chevron-down"></i></span>
                        <?php }else if($i==(count($cont_id)-1)){ ?>
                        <span class="btn btn-default" onclick="viewcontact('<?php echo $cont_id[$i-1];?>')"><i class="fa fa-chevron-up"></i></span>
                        <span class="btn btn-default" style="display:none;" onclick="afterdata('<?php echo $beforeid;?>','<?php echo $afterid;?>','<?php echo $current;?>')"><i class="fa fa-chevron-down"></i></span>
                        <?php }else{ ?>
                        <span class="btn btn-default" onclick="viewcontact('<?php echo $cont_id[$i-1];?>')"><i class="fa fa-chevron-up"></i></span>
                        <span class="btn btn-default"  onclick="viewcontact('<?php echo $cont_id[$i+1];?>')"><i class="fa fa-chevron-down"></i></span>
                        <?php } ?>
                    </span>
                </div>
                <script>
                    function backcontact(){
                       $("#activitystream").show();
                       $("#result").hide();
                    }
                </script>
                <div><br></div>
                <style>
                    .image-upload > input
                    {
                        visibility: hidden;
                    }
                </style>
                <script>
                    function functioneditcontact(cid, page){
                        var path="editcontact.php?cid="+cid+"&page="+page;
                        window.location.replace(path);
                    }
                </script>
                <div class="row">
                    <div class="col-md-2">
                        
                        <div class="image-upload">
                            <label for="file-input">
                                <img src="<?php echo $cont_imagepath;?>" id="contactphoto" width="100%" height="auto" style="z-index:1;cursor:pointer"/>
                            </label>
                            <input id="file-input" type="file" onchange="functionupload(this)"  style="z-index:2;margin-top:-35px;" accept="image/png, image/jpeg, image/jpg">
                        </div>
                    </div>
                    <div class="col-md-10">
                        <b><span style="fornt-size:2em;"><?php echo $c_title."&nbsp;".$c_fname."&nbsp;".$c_lname;?></span></b><i class="fa fa-star" aria-hidden="true"></i>
                        <span class="pull-right" style="color:grey;cursor:pointer;" onclick="functioneditcontact('<?php echo $c_id;?>','employee_actionstream_list_view.php')"><i class="glyphicon glyphicon-pencil"></i>&nbsp;Edit</span>
                        <br>
                        <?php echo $o_name;?>.&nbsp;&nbsp;&nbsp;&nbsp;<span class="btn btn-default"><i class="fa fa-building-o fa-lg" aria-hidden="true"></i><i class="fa fa-building-o" aria-hidden="true"></i>&nbsp;<i class="fa fa-angle-down" aria-hidden="true"></i></span>
                        <br>
                        <?php
                        $result_phone=$objsales->salesselectcontid("sales_phone", $c_id);
                        foreach($result_phone as $row_phone){
                            $phone_number=$row_phone['phone_number'];
                            $phone_type=$row_phone['phone_type'];
                            
                            ?>
                            <b>+<?php echo $c_code;?>&nbsp;<?php echo $phone_number;?></b> &nbsp;&nbsp;<span style="color:grey;"><?php echo $phone_type;?></span><br>
                            <?php
                        }
                        $result_email=$objsales->salesselectcontid("sales_email", $c_id);
                        foreach($result_email as $row_email){
                            $email_name=$row_email['email_name'];
                            ?>
                            <span style="color:#6699cc;"><?php echo $email_name;?></span><br>
                            <?php
                        }
                        $result_url=$objsales->salesselectcontid("sales_url", $c_id);
                        foreach($result_url as $row_url){
                            $url_name=$row_url['url_name'];
                            ?>
                            <span style="color:#6699cc;"><?php echo $url_name;?></span><br>
                            <?php
                        }
                        ?>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-2"></div>
                    <div class="col-md-10">
                        <hr>
                        <span class="pull-right" id="show1<?php echo $c_id;?>" onclick="showdetails('show1<?php echo $c_id;?>','show2<?php echo $c_id;?>','show3<?php echo $c_id;?>')" style="cursor:pointer;padding:10px;margin-top:-40px;background-color:#f0f0f0;border-radius: 5px;">More&nbsp;&nbsp;<i class="fa fa-angle-down" style="margin-top:3px;" aria-hidden="true"></i></span>
                        <span class="pull-right" id="show2<?php echo $c_id;?>" onclick="hidedetails('show1<?php echo $c_id;?>','show2<?php echo $c_id;?>','show3<?php echo $c_id;?>')" style="cursor:pointer;padding:10px;margin-top:-40px;background-color:#f0f0f0;border-radius: 5px;display:none;">Less&nbsp;&nbsp;<i class="fa fa-angle-up" style="margin-top:3px;" aria-hidden="true"></i></span>
                    
                    </div>
                </div>
                    
                <div class="row" id="show3<?php echo $c_id;?>" style="display:none;">
                    <div class="col-md-2"></div>
                    <div class="col-md-10">
                        
                        <div class="row">
                            
                            <div class="col-md-6" style="border-right:1px solid LightGray;">
                                <h4 style="color:LightGray">CONTACT FIELDS</h4>
                                <span style="color:#333">
                                <?php if(($c_a_line=="no data available")||($c_a_line=="")){ }else{ echo $c_a_line; }?><br>
                                <?php if(($c_a_city=="no data available")||($c_a_city=="")){ }else{ echo $c_a_city; } ?><br>
                                <?php if(($c_a_state=="no data available")||($c_a_state=="")){ }else{ echo $c_a_state; }?><br>
                                <?php if(($c_a_country=="no data available")||($c_a_country=="")){ }else{ echo $c_a_country; } ?><br>
                                <?php if(($c_a_pincode=="no data available")||($c_a_pincode=="")){ }else{ echo $c_a_pincode; } ?><br>
                                </span>
                            </div>
                            <div class="col-md-6">
                                <h4 style="color:LightGray;">ORGANIZATION FIELDS</h4>
                                <span style="color:#333;line-height: 1.3;font-family: 'Open Sans', Arial, Helvetica, sans-serif;font-size: 13px;">
                                <?php if(($o_line=="no data available")||($o_line=="")){ }else{ echo $o_line; }?><br>
                                <?php if(($o_city=="no data available")||($o_city=="")){ }else{ echo $o_city; } ?><br>
                                <?php if(($o_state=="no data available")||($o_state=="")){ }else{ echo $o_state; } ?><br>
                                <?php if(($o_country=="no data available")||($o_country=="")){ }else{ echo $o_country; } ?><br>
                                <?php if(($o_pincode=="no data available")||($o_pincode=="")){ }else{ echo $o_pincode; } ?><br>
                                </span>
                            </div>
                            
                        </div>
                        
                        <hr>
                    </div>
                </div>
                    
                            <?php
                            for($kk=0;$kk<count($emailid1);$kk++){
                                $emailid11=$emailid1[$kk];
                                if($c_owner_id==$emailid11){
                                $emp_owner_name=$employeename1[$kk];
                                if($emp_owner_name=="no data available"){
                                    $emp_owner_name="";
                                }
                                }
                            }
                            ?>
                <div class="row">
                    <div class="col-md-2"></div>
                    <div class="col-md-10">
                        <span class="dropdown">
                            <input type="hidden" id="b4" value="<?php echo $c_owner_id;?>">
                            <button class="btn btn-default dropdown-toggle" id="b3" type="button" data-toggle="dropdown"><?php echo $emp_owner_name;?>
                            </button><span class="caret" style="margin-left:-10px;"></span>
                            <ul class="dropdown-menu">
                            <?php
                            for($kk=0;$kk<count($emailid1);$kk++){
                                $emailid11=$emailid1[$kk];
                                $employeename11=$employeename1[$kk];
                            ?>
                                <li><a onclick="funsignup('<?php echo $emailid11;?>','<?php echo $employeename11;?>','<?php echo $c_id;?>')"><?php echo $employeename11;?></a></li>
                            <?php
                            }
                            ?>
                        </ul>
                        </span>&nbsp;&nbsp;&nbsp;&nbsp;
                        <?php
                        if($s_name=="no data available"){
                            $s_name="Status";
                        }
                        ?>
                        <span class="dropdown">
                            <button class="btn btn-default dropdown-toggle" id="b1" type="button" data-toggle="dropdown"><?php echo $s_name;?>
                            </button><span class="caret" style="margin-left:-10px;"></span>
                            <ul class="dropdown-menu">
                            <?php
                            $result_status=$objsales->salesselectallemployee($companyname, $adminemailid, "sales_status", "no");
                            foreach($result_status as $row_status){
                                $status_name=$row_status['status_name'];
                                $status_id=$row_status['id'];
                                if($status_name=="no data available"){
                                    $status_name="";
                                }
                            ?>
                                <li><a onclick="funstatus('<?php echo $status_id;?>','<?php echo $status_name;?>','<?php echo $c_id;?>')"><?php echo $status_name;?></a></li>
                            <?php
                            }
                            ?>
                        </ul>
                        </span>&nbsp;&nbsp;&nbsp;&nbsp;
                        <?php
                        if($t_name=="no data available"){
                            $t_name="Tag";
                        }
                        ?>
                        <span class="dropdown">
                            <button class="btn btn-default dropdown-toggle" id="b2" type="button" data-toggle="dropdown"><?php echo $t_name;?>
                            </button><span class="caret" style="margin-left:-10px;"></span>
                            <ul class="dropdown-menu">
                            <?php
                            $result_tag=$objsales->salesselectallemployee($companyname, $adminemailid, "sales_tag", "no");
                            foreach($result_tag as $row_tag){
                                $tag_name=$row_tag['tag_name'];
                                $tag_id=$row_tag['id'];
                            ?>
                                <li><a onclick="funtag('<?php echo $tag_id;?>','<?php echo $tag_name;?>','<?php echo $c_id;?>')"><?php echo $tag_name;?></a></li>
                            <?php
                            }
                            ?>
                        </ul>
                        </span>
                        
                        
                    </div>
                </div>
                
                    <span id="nextactionview"></span>
                    <script>
                        $(document).ready(function(){
                           var cid="<?php echo $cid;?>";
                           var adminemailid="<?php echo $adminemailid;?>";
                           var companyname="<?php echo $companyname;?>";
                           //alert(cid);
                           $.ajax({
                                url:"nextactionpage.php",
                                type:"post",
                                data:{adminemailid:adminemailid,companyname:companyname,cid:cid},
                                success:function(respond){
                                    //alert(respond);
                                    $("#nextactionview").html(respond);
                                }
                            });
                        });
                    </script>   
                 
                
             <script>
                 
                    function funemployee(id, name, cid, empid, empname){
                        document.getElementById(empname).innerText=name;
                        document.getElementById(empid).value=id;
                    }
             </script>   
                
                <div class="row" style="padding-top:10px;padding-left:10px;">
                    <input type="button" id="addnotebutton" value="Add Note" class="btn btn-default">&nbsp;&nbsp;
                    <input type="button" id="addcallbutton" value="Add Call" class="btn btn-default">&nbsp;&nbsp;
                    <input type="button" id="adddealbutton" onclick="showdealadd" value="Add Deal" class="btn btn-default">&nbsp;&nbsp;
                </div>   
                <br>
                        <?php
                        $gh=0;
                        $result_deal1=$objsales->salesselectcontid("sales_deal", $c_id);
                        foreach($result_deal1 as $row_deal1){
                            $d_stage1121[$gh]=$row_deal1['d_stage'];
                            $d_deal_name1121[$gh]=$row_deal1['d_deal_name'];
                            $d_deal_id1121[$gh++]=$row_deal1['id'];
                        }
                        ?>
                
                        <?php
                        $gh=0;
                        $result_phone=$objsales->salesselectcontid("sales_phone", $c_id);
                        foreach($result_phone as $row_phone){
                            $c_phone_number[$gh]=$row_phone['phone_number'];
                            $c_phone_type[$gh]=$row_phone['phone_type'];
                            $c_phone_id[$gh++]=$row_phone['id'];
                        }
                        ?>
                
                        <?php
                        $gh=0;
                        $employee_contact_emailid=array();
                        $result_employee_contact=$objsales->salesselectcontid("sales_employee_contact", $c_id);
                        foreach($result_employee_contact as $row_employee_contact){
                            $employee_contact_emailid[$gh]=$row_employee_contact['email_id'];
                            $gh++;
                        }
                        ?>
                <span id="addnote" style="display:none;">
                    <div class="row" >
                        <div class="col-sm-6"><h4>Add Note</h4></div>
                        <div class="col-sm-6">
                            <span class="pull-right">Created&nbsp;&nbsp;
                                <span style="color:blue;cursor:pointer;" onclick="funcnotedatechange('#hidenotedate','#note_date','<?php echo date('Y-m-d');?>')" id="hidenotedate">Today</span>
                                <input type="text" name="note_date" value="<?php echo date('Y-m-d');?>" id="note_date"  readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">
                            </span>
                        </div>
                    </div>
                    <div class="row" style="padding:10px;background-color:#dfe6ea">
                        <div class="col-sm-2"></div>
                        <div class="col-sm-10">
                            <textarea class="form-control" rows="5" id="notes_desc"></textarea><br>
                            <div class="row">
                                <div class="col-sm-6">
                                    <select name="selected_notes" id="selected_notes" style="height:30px;border-radius:5px;">
                                        <option value="">Note relates to..</option>
                                        <?php
                                        for($rr=0;$rr<count($d_deal_id1121);$rr++){
                                            if(($d_stage1121[$rr]!="Won")&&($d_stage1121[$rr]!="Lost")){
                                        ?>
                                        <option value="<?php echo $d_deal_id1121[$rr];?>">Pending deal - <?php echo $d_deal_name1121[$rr];?></option> 
                                        <?php
                                            }else if($d_stage1121[$rr]=="Won"){
                                        ?>
                                        <option value="<?php echo $d_deal_id1121[$rr];?>">Won deal - <?php echo $d_deal_name1121[$rr];?></option> 
                                        <?php
                                            }else if($d_stage1121[$rr]=="Lost"){
                                        ?>
                                        <option value="<?php echo $d_deal_id1121[$rr];?>">Lost deal - <?php echo $d_deal_name1121[$rr];?></option> 
                                        <?php
                                            }
                                        }
                                        ?>
                                    </select><span style="color:grey;">Optional</span>
                                </div>
                                <div class="col-sm-6">
                                    <span class="pull-right">
                                        Email these users
                                        <?php
                                        //print_r($employee_contact_emailid);
                                        for($yy=0;$yy<count($employee_contact_emailid);$yy++){
                                            for($yy1=0;$yy1<count($emailid1);$yy1++){
                                                if($employee_contact_emailid[$yy]==$emailid1[$yy1]){
                                                    ?>
                                                    <br><span style="float:left;"><input type="checkbox" onclick="functnotemailthisuser('#check_n<?php echo $yy;?>','<?php echo $employee_contact_emailid[$yy];?>','#sendnoteemailcheckbox')" id="check_n<?php echo $yy;?>" value="<?php echo $employee_contact_emailid[$yy];?>"><?php echo $employeename1[$yy1];?></span>
                                                    <?php
                                                }
                                            }
                                        }
                                        ?>
                                    </span>
                                </div>
                            </div>
                            <input type="hidden" id="sendnoteemailcheckbox" class="form-control"> 
                            <br><br>
                            <input type="button" class="btn btn-primary" id="noteinsertsubmit" value="save" onclick="funinsertnote('#note_date','#notes_desc','#selected_notes','#sendnoteemailcheckbox','<?php echo $c_id;?>')">
                            <span style="margin-left:50px;color:grey;cursor:pointer;" id="cancelnote">Cancel</span>
                        </div>
                    </div>
                    <br>                                                                
                </span>       
                
                <script>
                    function funnoteedit(showid, cid, noteid, desc, date1, notedeal, sendnoteemail){
                        
                        var dealid=new Array();
                        var dealstage=new Array();
                        var dealname=new Array();
                        var dealcount="<?php echo count($d_deal_id1121);?>";
                        dealid=<?php echo json_encode($d_deal_id1121);?>;
                        dealstage=<?php echo json_encode($d_stage1121);?>;
                        dealname=<?php echo json_encode($d_deal_name1121);?>;
                        var employeecontactemailid=new Array();  
                        var emailid1=new Array();
                        var employeename1=new Array();
                        employeecontactemailid=<?php echo json_encode($employee_contact_emailid);?>;
                        emailid1=<?php echo json_encode($emailid1);?>;
                        employeename1=<?php echo json_encode($employeename1);?>;
                        
                        var insert="";
                        
                        insert+='<span id="edittnote_e">';
                        
                        insert+='<div class="row">';
                        insert+='<div class="col-sm-6"><h4>Edit Note</h4></div>';
                        insert+='<div class="col-sm-6">';
                        insert+='<span class="pull-right">Created&nbsp;&nbsp;';
                        insert+='<span style="color:blue;cursor:pointer;" onclick=funcnotedatechange("#hidenotedate_e","#note_date_e","'+date1+'") id="hidenotedate_e">'+date1+'</span>';
                        insert+='<input type="text" name="note_date_e" value="'+date1+'" id="note_date_e"  readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
                        insert+='</span>';
                        insert+='</div>';
                        insert+='</div>';

                        insert+='<div class="row" style="padding:10px;background-color:#dfe6ea">';
                        insert+='<div class="col-sm-2"></div>';
                        insert+='<div class="col-sm-10">';
                        insert+='<textarea class="form-control" rows="5" id="notes_desc_e">'+desc+'</textarea><br>';
                        insert+='<div class="row">';
                        
                        
                        insert+='<div class="col-sm-6">';
                        insert+='<select name="selected_notes" id="selected_notes_e" style="height:30px;border-radius:5px;">';
                        insert+='<option value="">Note relates to..</option>'; 
                        if(notedeal!=""){
                            for(ss=0;ss<dealid.length;ss++){
                                var dealid2=dealid[ss];
                                if(dealid2==notedeal){
                                    //alert("true");
                                    var dealstage1=dealstage[ss];
                                    var dealname1=dealname[ss];
                                    
                                    if((dealstage1!="Won")&&(dealstage1!="Lost")){
                                        insert+='<option value="'+dealid2+'" selected>Pending deal - '+dealname1+'</option>';
                                    }else if(dealstage1=="Won"){
                                        insert+='<option value="'+dealid2+'" selected>Won deal - '+dealname1+'</option>';
                                    }else if(dealstage1=="Lost"){
                                        insert+='<option value="'+dealid2+'" selected>Lost deal - '+dealname1+'</option>';
                                    }
                                }
                            }
                        }
                        if(dealcount>0){
                        for(rr=0;rr<dealid.length;rr++){
                            var dealid1=dealid[rr];
                            var dealstage1=dealstage[rr];
                            var dealname1=dealname[rr];
                            if((dealstage1!="Won")&&(dealstage1!="Lost")){
                                insert+='<option value="'+dealid1+'">Pending deal - '+dealname1+'</option>';
                            }else if(dealstage1=="Won"){
                                insert+='<option value="'+dealid1+'">Won deal - '+dealname1+'</option>';
                            }else if(dealstage1=="Lost"){
                                insert+='<option value="'+dealid1+'">Lost deal - '+dealname1+'</option>';
                            }
                        }
                        }
                        insert+='</select><span style="color:grey;">Optional</span>';
                        insert+='</div>';
                                        
                        insert+='<div class="col-sm-6">';
                        insert+='<span class="pull-right">';
                        insert+='Email these users';
                        for(yy=0;yy<employeecontactemailid.length;yy++){
                            for(yy1=0;yy1<emailid1.length;yy1++){
                                if(employeecontactemailid[yy]==emailid1[yy1]){
                                 insert+='<br><span style="float:left;"><input type="checkbox" onclick=functnotemailthisuser("#check_n_e'+yy+'","'+employeecontactemailid[yy]+'","#sendnoteemailcheckbox_e") id="check_n_e'+yy+'" value="'+employeecontactemailid[yy]+'">'+employeename1[yy1]+'</span>';
                                }
                            }
                        }
                        insert+='</span>';
                        insert+='</div>';
                        
                        insert+='</div>';
                        
                        insert+='<input type="hidden" id="sendnoteemailcheckbox_e" class="form-control">'; 
                        insert+='<br><br>';

                        
                        insert+='<input type="button" class="btn btn-primary" id="noteupdatesubmit" value="update" onclick=funupdatenote("'+showid+'","'+noteid+'","#note_date_e","#notes_desc_e","#selected_notes_e","#sendnoteemailcheckbox_e","'+cid+'")>';
                        insert+='<span style="margin-left:50px;color:grey;cursor:pointer;" onclick=cancelnoteview("'+showid+'","'+cid+'","'+noteid+'","'+desc+'","'+date1+'","'+notedeal+'","'+sendnoteemail+'")>Cancel</span>';
                        insert+='</div>';
                        insert+='</div>';
                        insert+='<br>';                                                          
                        insert+='</span>';
                        $(showid).empty();
                        $(showid).append(insert);
                    }
                </script>    
                <script>
                    function funupdatenote(showid, noteid, dateid, descid, notedealid, sendnoteemailcheckbox, cid){
                        var date1=$(dateid).val();
                        var desc=$(descid).val();
                        var notedeal=$(notedealid).val();
                        var sendnoteemail=$(sendnoteemailcheckbox).val();
                        if(desc!=""){
                            $("#noteupdatesubmit").attr("disabled", true);
                            swal("Notes Updted Successfully","","success");
                            $.ajax({
                                url:"activestream_intermediate.php",
                                type:"post",
                                data:{updatenote:noteid, desc:desc, date1:date1, notedeal:notedeal, sendnoteemail:sendnoteemail, cid:cid},
                                success:function(respond){
                                    //alert(respond)
                                    /*BootstrapAlert.success({
                                      title: "Success!",
                                      message: "Notes Updted Successfully"
                                    }); */
                                    $("#noteinsertsubmit").attr("disabled", false);
                                    cancelnoteview(showid, cid, noteid, desc, date1, notedeal, sendnoteemail);
                                }
                            });
                        }else{
                            $(descid).focus();
                        }
                    }
                </script>
                <script>
                    function cancelnoteview(showid, cid, noteid, desc, date1, notedeal, sendnoteemail){
                          
                        
                        var dealid=new Array();
                        var dealstage=new Array();
                        var dealname=new Array();
                        dealid=<?php echo json_encode($d_deal_id1121);?>;
                        dealstage=<?php echo json_encode($d_stage1121);?>;
                        dealname=<?php echo json_encode($d_deal_name1121);?>;
                        var employeecontactemailid=new Array();  
                        var emailid1=new Array();
                        var employeename1=new Array();
                        employeecontactemailid=<?php echo json_encode($employee_contact_emailid);?>;
                        emailid1=<?php echo json_encode($emailid1);?>;
                        employeename1=<?php echo json_encode($employeename1);?>;
                        
                        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
                        
                        var y=date1[0]+date1[1]+date1[2]+date1[3];
                        if(date1[5]!=0){
                            var m=date1[5]+date1[6];
                        }else{
                            var m=date1[6];
                        }
                        var d=date1[8]+date1[9];
                        var st;
                        var sn;
                        var insert="";
                        
                        
                        
                        insert+='<div id="noteview'+noteid+'" style="clear: both;border: 1px solid #EAEAEA;border-radius: 2px 2px 2px 2px; box-shadow: 0 0 2px #EAEAEA, 0 0 6px #F0F0F0 inset;padding: 6px 10px;margin: 15px 0 20px 0;">';
                        
                        insert+='<div class="timeline_data" style="color: #9D9992;padding-bottom: 6px;line-height: 1;">';
                        if(notedeal==""){
                            insert+='Note - '+monthNames[m]+' '+d+', '+y+'  ';
                        }else{
                            for(kk=0;kk<dealid.length;kk++){
                                if(dealid[kk]==notedeal){
                                    sn=dealname[kk];
                                }
                            }
                            insert+='Note - related to "'+sn+'" '+monthNames[m]+' '+d+', '+y+'  ';
                        } 
                        insert+='<span style="cursor:pointer;" onmouseover=changedeleteicon("snn'+noteid+'") onmouseout=changedeleteicon1("snn'+noteid+'") id="snn'+noteid+'" onclick=funnotedelete("#noteviewid'+noteid+'","'+noteid+'") ><i class="glyphicon glyphicon-trash"></i></span> &nbsp;&nbsp;';
                        insert+='<span style="cursor:pointer;" onmouseover=changeediticon("enn'+noteid+'") onmouseout=changeediticon1("enn'+noteid+'") id="enn'+noteid+'" onclick=funnoteedit("#noteviewid'+noteid+'","'+cid+'","'+noteid+'","'+desc+'","'+date1+'","'+notedeal+'","'+sendnoteemail+'") ><i class="glyphicon glyphicon-pencil"></i></span>';
                        
                        insert+='</div>';
                        
                        insert+='<div>'+desc+'</div>';
                        
                        if(sendnoteemail!=""){
                        insert+='<div style="font-family: Open Sans Italic, Arial, Helvetica, sans-serif;color: #9D9992;">';
                        sq=sendnoteemail.split("#@");
                        for(s1=0;s1<sq.length;s1++){
                            for(s2=0;s2<emailid1.length;s2++){
                                if(sq[s1]==emailid1[s2]){
                                    insert+=employeename1[s2]+', ';
                                }
                            }
                        }
                        insert+=' have been notified by email';
                        insert+='</div>';
                        }
                        
                        
                        insert+='</div>';
                        $(showid).empty();
                        $(showid).append(insert);
                    }
                </script>  
                <script>
                    function funnotedelete(hideid, noteid){
                        swal("Notes Deleted Successfully","","success");
                         $.ajax({
                                url:"activestream_intermediate.php",
                                type:"post",
                                data:{deletenote:noteid},
                                success:function(respond){
                                    //alert(respond);
                                    /*BootstrapAlert.success({
                                      title: "Success!",
                                      message: "Notes Deleted Successfully"
                                    }); */
                                    $(hideid).hide();
                                }
                         });
                    }
                </script>
                <script>
                            function functnotemailthisuser(id,val1,showid){
                                //alert(val1);
                                var em=$(showid).val();
                                if($(id).is(':checked')){
                                    if(em!=""){
                                        em+="#@"+val1;
                                    }else{
                                        em=val1;
                                    }
                                    var em2=em;
                                }else{
                                    var em2="";
                                    em1=em.split("#@");
                                    //alert(em1.length);
                                    for(hh=0;hh<em1.length;hh++){
                                        if(em1[hh]!=val1){
                                            if(em2==""){
                                                em2=em1[hh];
                                            }else{
                                                em2+="#@"+val1;
                                            }
                                        }
                                    }
                                }
                                $(showid).val(em2);
                            }
                        </script>
                <script>
                    function funcnotedatechange(hideid, showdate, startdate){
                        $(hideid).hide();
                        $(showdate).show();
                        $(showdate).datepicker({ 
                            format : "yyyy-mm-dd",
                            autoclose: true 
                        }).datepicker('update', startdate); 
                    }
                </script>
                <script>
                    function funinsertnote(dateid, descid, notedealid, sendnoteemailcheckbox, cid){
                        var date1=$(dateid).val();
                        var desc=$(descid).val();
                        var notedeal=$(notedealid).val();
                        var sendnoteemail=$(sendnoteemailcheckbox).val();
                        var employeecontactemailid=new Array();  
                        var emailid1=new Array();
                        var employeename1=new Array();
                        employeecontactemailid=<?php echo json_encode($employee_contact_emailid);?>;
                        emailid1=<?php echo json_encode($emailid1);?>;
                        employeename1=<?php echo json_encode($employeename1);?>;
                        if(desc!=""){
                            $("#noteinsertsubmit").attr("disabled", true);
                            swal("Notes Created Successfully","","success");
                            $.ajax({
                                url:"activestream_intermediate.php",
                                type:"post",
                                data:{insertnote:desc, date1:date1, notedeal:notedeal, sendnoteemail:sendnoteemail, cid:cid},
                                success:function(respond){
                                    var cccc=respond.trim();
                                    /*BootstrapAlert.success({
                                      title: "Success!",
                                      message: "Notes Created Successfully",
                                    });*/ 
                                    $("#noteinsertsubmit").attr("disabled", false);
                                    $("#addnotebutton").attr("disabled", false);
                                    $("#addnote").hide();
                                    $(descid).val("");
                                    var chlen=employeecontactemailid.length;
                                    for(m=0;m<chlen;m++){
                                        $("#check_n"+m).prop('checked', false); 
                                    }
                                    $(notedealid).val([]);
                                    $(sendnoteemailcheckbox).val("");
                                    var showid="#viewcallnote";
                                    $("#noteinsertsubmit").attr("disabled", false);
                                    funnoteview(showid, cid, cccc, desc, date1, notedeal, sendnoteemail);
                                }
                            });
                        }else{
                            $(descid).focus();
                        }
                    }
                </script>
                <script>
                    function funnoteview(showid, cid, noteid, desc, date1, notedeal, sendnoteemail){
                          
                        
                        var dealid=new Array();
                        var dealstage=new Array();
                        var dealname=new Array();
                        dealid=<?php echo json_encode($d_deal_id1121);?>;
                        dealstage=<?php echo json_encode($d_stage1121);?>;
                        dealname=<?php echo json_encode($d_deal_name1121);?>;
                        var employeecontactemailid=new Array();  
                        var emailid1=new Array();
                        var employeename1=new Array();
                        employeecontactemailid=<?php echo json_encode($employee_contact_emailid);?>;
                        emailid1=<?php echo json_encode($emailid1);?>;
                        employeename1=<?php echo json_encode($employeename1);?>;
                        
                        var monthNames = ["", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
                        
                        var y=date1[0]+date1[1]+date1[2]+date1[3];
                        if(date1[5]!=0){
                            var m=date1[5]+date1[6];
                        }else{
                            var m=date1[6];
                        }
                        var d=date1[8]+date1[9];
                        var st;
                        var sn;
                        var insert="";
                        
                        //alert("sd");
                        
                        insert+='<span id="noteviewid'+noteid+'">';
                        insert+='<div id="noteview'+noteid+'" style="clear: both;border: 1px solid #EAEAEA;border-radius: 2px 2px 2px 2px; box-shadow: 0 0 2px #EAEAEA, 0 0 6px #F0F0F0 inset;padding: 6px 10px;margin: 15px 0 20px 0;">';
                        
                        insert+='<div class="timeline_data" style="color: #9D9992;padding-bottom: 6px;line-height: 1;">';
                        if(notedeal==""){
                            insert+='Note - '+monthNames[m]+' '+d+', '+y+'  ';
                        }else{
                            for(kk=0;kk<dealid.length;kk++){
                                if(dealid[kk]==notedeal){
                                    sn=dealname[kk];
                                }
                            }
                            insert+='Note - related to "'+sn+'" '+monthNames[m]+' '+d+', '+y+'  ';
                        } 
                        insert+='<span style="cursor:pointer;" onmouseover=changedeleteicon("snn'+noteid+'") onmouseout=changedeleteicon1("snn'+noteid+'") id="snn'+noteid+'" onclick=funnotedelete("#noteviewid'+noteid+'","'+noteid+'") ><i class="glyphicon glyphicon-trash"></i></span> &nbsp;&nbsp;';
                        insert+='<span style="cursor:pointer;" onmouseover=changeediticon("enn'+noteid+'") onmouseout=changeediticon1("enn'+noteid+'") id="enn'+noteid+'" onclick=funnoteedit("#noteviewid'+noteid+'","'+cid+'","'+noteid+'","'+desc+'","'+date1+'","'+notedeal+'","'+sendnoteemail+'") ><i class="glyphicon glyphicon-pencil"></i></span>';
                        
                        insert+='</div>';
                        
                        insert+='<div>'+desc+'</div>';
                        
                        if(sendnoteemail!=""){
                        insert+='<div style="font-family: Open Sans Italic, Arial, Helvetica, sans-serif;color: #9D9992;">';
                        sq=sendnoteemail.split("#@");
                        for(s1=0;s1<sq.length;s1++){
                            for(s2=0;s2<emailid1.length;s2++){
                                if(sq[s1]==emailid1[s2]){
                                    insert+=employeename1[s2]+', ';
                                }
                            }
                        }
                        insert+=' have been notified by email';
                        insert+='</div>';
                        }
                        
                        
                        insert+='</div>';
                        insert+='</span>';
                        
                        $(showid).append(insert);
                    }
                </script>
                <span id="addcall" style="display:none;">
                    <div class="row">
                        <div class="col-sm-6"><h4>Add Call</h4></div>
                        <div class="col-sm-6">
                            <span class="pull-right">Date created
                                <span style="color:blue;cursor:pointer;" id="hidecalldate">Today</span>
                                <input type="text" name="call_date" value="<?php echo date('Y-m-d');?>" id="call_date"  readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">
                            </span>
                        </div>
                    </div>
                    <div class="row" style="padding:10px;background-color:#dfe6ea;border-radius:5px;">
                        <span class="row">
                            <span class="col-sm-2">
                                <span class="pull-right">Phone</span>
                            </span>
                            <span class="col-sm-10">
                                <select id="call_phone" name="call_phone" class="form-control" style="width:250px;height:30px;" onchange="funshowphonenum('#call_phone','#showselectedphone')"> 
                                    <option></option>
                                    <?php
                                    for($hg=0;$hg<count($c_phone_type);$hg++){
                                    ?>
                                        <option value="<?php echo $c_phone_id[$hg];?>"><?php echo $c_phone_number[$hg];?>&nbsp;&nbsp;(<?php echo $c_phone_type[$hg];?>)</option>
                                    <?php
                                    }
                                    ?>
                                </select>
                            </span>
                        </span>
                        <span class="row">
                            <span class="col-sm-2">
                                <span class="pull-right">Result</span>
                            </span>
                            <span class="col-sm-10">
                                <select id="call_result" name="call_result" class="form-control" style="width:250px;height:30px;"> 
                                    <?php
                                    for($bh=0;$bh<count($c_ans_id_a);$bh++){
                                    ?>
                                        <option value="<?php echo $c_ans_id_a[$bh];?>"><?php echo $c_ans_name_a[$bh];?></option>
                                    <?php
                                    }
                                    ?>
                                    <option value="Other">Other</option>
                                </select>
                            </span>
                        </span>
                        <span class="row">
                            <span class="col-sm-2">
                                <span class="pull-right">Note</span>
                            </span>
                            <span class="col-sm-10">
                                Called&nbsp;&nbsp;<?php echo $c_fname;?>
                                &nbsp;at &nbsp;
                                <span style="color:blue;cursor:pointer;" id="hidecalltime"><?php echo date('H:i:s');?></span>
                                <input type="text" id="call_time" value="<?php echo date('H:i:s');?>" readonly  style="width:100px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">
                                 <span id="showselectedphone" style="display:none"></span>
                            </span>
                        </span>
                        <span class="row">
                            <span class="col-sm-2">
                                <!--<span class="pull-right">Note</span>-->
                            </span>
                            <span class="col-sm-10">
                                <textarea id="call_desc" class="form-control" rows="5"></textarea>
                            </span>
                        </span>
                        <span class="row">
                            <span class="pull-right">
                                Email these users
                                <?php
                                //print_r($employee_contact_emailid);
                                for($yy=0;$yy<count($employee_contact_emailid);$yy++){
                                    for($yy1=0;$yy1<count($emailid1);$yy1++){
                                        if($employee_contact_emailid[$yy]==$emailid1[$yy1]){
                                            ?>
                                            <br><span style="float:left;"><input type="checkbox" onclick="functemailthisuser('#check<?php echo $yy;?>','<?php echo $employee_contact_emailid[$yy];?>')" id="check<?php echo $yy;?>" value="<?php echo $employee_contact_emailid[$yy];?>"><?php echo $employeename1[$yy1];?></span>
                                            <?php
                                        }
                                    }
                                }
                                ?>
                            </span>
                        </span>
                        <input type="hidden" id="sendemailcheckbox" class="form-control">
                        <br>
                        <span class="row">
                            <span class="col-sm-2">
                                <!--<span class="pull-right">Note</span>-->
                            </span>
                            <span class="col-sm-10">
                                <input type="button" class="btn btn-primary" value="save" onclick="callinsertsubmit('#call_date','#call_phone','#call_result','#call_time','#call_desc','#sendemailcheckbox','#addcall','#viewcallnote','<?php echo $c_id;?>','<?php echo $c_fname;?>','<?php echo $c_lname;?>' )">
                                <span style="margin-left:50px;color:grey;cursor:pointer;" id="cancelcall">Cancel</span>
                            </span>
                        </span>
                        <br><br>
                        
                    </div>
                    <br>
                </span>
                
                <span id="adddeal" style="display:none;">
                    <div class="row">
                        <div class="col-sm-6"><h4>Add Deal</h4></div>
                        <div class="col-sm-6">
                                <span class="pull-right">
                                        Created&nbsp;&nbsp;
                                        <span style="color:blue;cursor:pointer;" id="hidedealdate">Today</span>
                                        <input type="text" name="deal_date" value="<?php echo date('Y-m-d');?>" id="deal_date"  readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">
                                        &nbsp;&nbsp;&nbsp;
                                        <span class="dropdown">
                                            <input type="hidden" id="deal_by_id" value="<?php echo $adminemailid;?>">
                                            <button class="btn btn-default dropdown-toggle" id="deal_by_name" type="button" data-toggle="dropdown"><?php echo "Me";?>
                                            </button><span class="caret" style="margin-left:-10px;"></span>
                                            <ul class="dropdown-menu">
                                            <?php
                                            for($kk=0;$kk<count($emailid1);$kk++){
                                                $emailid11=$emailid1[$kk];
                                                if($emailid11==$adminemailid){
                                                    $employeename11="Me";
                                                }else{
                                                $employeename11=$employeename1[$kk];
                                                }
                                            ?>
                                                <li><a onclick="funemployee('<?php echo $emailid11;?>','<?php echo $employeename11;?>','<?php echo $c_id;?>','deal_by_id','deal_by_name')"><?php echo $employeename11;?></a></li>
                                            <?php
                                            }
                                            ?>
                                        </ul>
                                        </span>
                                </span>
                        </div>
                    </div>
                    <div class="row" style="padding:10px;background-color:#dfe6ea;border-radius:5px;">
                        <span class="row">
                            <span class="col-sm-8">
                                <div class="row">
                                    <span class="col-sm-4">
                                        <span class="pull-right">Deal Name</span>
                                    </span>
                                    <span class="col-sm-8">
                                        <input type="text" id="deal_name" name="deal_name" class="form-control">
                                    </span>
                                </div><br>
                                <div class="row">
                                    <span class="col-sm-4">
                                        <span class=" pull-right">
                                            <span id="monthamout" style="display:none;">Month amount</span>
                                            <span id="amount">Amount</span>
                                        </span>
                                    </span>
                                    <span class="col-sm-8">
                                        <input type="number" name="deal_amount" id="deal_amount" style="width:100px;border-radius:5px;" min="0" max="200000000" onkeyup="calcamoutformonth('#deal_amount', '#deal_month', '#deal_amount1', '#total_amount', '#deal_commission', '#deal_commission_amount', '#deal_commission_amount1')">
                                        <span id="monthamout1" style="display:none;"><b>x</b>
                                            <input type="number" name="deal_month" id="deal_month" style="width:70px;" value="1" min="1" max="40" onkeyup="calcamoutformonth('#deal_amount', '#deal_month', '#deal_amount1', '#total_amount', '#deal_commission', '#deal_commission_amount', '#deal_commission_amount1')"><span style="color:grey;">month</span>
                                        <br>Total Amount ₨<span id="total_amount"></span>
                                        <input type="hidden" name="deal_amount1" id="deal_amount1" style="width:100px;border-radius:5px;">
                                        </span>
                                    </span>
                                </div><br>
                                <div class="row" id="Commission" style="display:none;">
                                    <span class="col-sm-4"> <span class=" pull-right">Commission %</span></span>
                                    <span class="col-sm-8"><!--
                                        <input type="text" name="deal_commission" id="deal_commission" value="0" style="width:100px;" onkeyup="calcamoutformonth('#deal_amount', '#deal_month', '#deal_amount1', '#total_amount', '#deal_commission', '#deal_commission_amount', '#deal_commission_amount1')">
                                        <input type="hidden" name="deal_commission_amount" id="deal_commission_amount" value="0"  style="border-radius:5px;">
                                        <span class="btn">&#37;</span><span style="color:grey">Value ₨<span id="deal_commission_amount1">120</span> based on amount</span> 
                                    </span>-->
                                        <input type="hidden" name="deal_commission" id="deal_commission" value="0" style="width:100px;">
                                        <input type="text" name="deal_commission1" id="deal_commission1" value="0" style="width:100px;" onkeyup="calcamoutformonth1('#deal_amount', '#deal_month', '#deal_amount1', '#total_amount', '#deal_commission', '#deal_commission1', '#deal_commission_amount', '#deal_commission_amount1', '#deal_commission_amount2')">
                                        <input type="text" name="deal_commission_amount2" id="deal_commission_amount2" value="0" style="width:100px;display:none;" onkeyup="calcamoutformonth2('#deal_amount', '#deal_month', '#deal_amount1', '#total_amount', '#deal_commission', '#deal_commission1', '#deal_commission_amount', '#deal_commission_amount1', '#deal_commission_amount2')">
                                        <input type="hidden" name="deal_commission_amount" id="deal_commission_amount" value="0"  style="width:100px;border-radius:5px;">
                                        <input type="button" class="btn" style="background: white;" id="newdealpercentagebtn" value="&#37;">&nbsp;<input type="button" class="btn" id="newdealruppeebtn" style="background: grey;" value="₨"><span style="color:grey" id="dealamoutval">Value ₨<span id="deal_commission_amount1">0</span> based on amount</span> 
                                    </span>
                                </div>
                                
                                <script>
                                    function calcamoutformonth1(damount, dmonth, damount1, totalamount, dealcommision, dealcommision1, dealcommissionamount, showcommision, dealcommissionamount1){
                                        //alert("jhk");
                                        var amt=$(damount).val();
                                        var mth=$(dmonth).val();
                                        var cmp=$(dealcommision1).val();
                                        var tot=amt*mth;
                                        $(damount1).val(tot);
                                        $(totalamount).html(tot);
                                        if((cmp==0)||(cmp=="")){
                                            var commision=0;
                                        }else{
                                            var commision=amt*(cmp/100)*mth;
                                        }
                                        $(dealcommissionamount).val(commision);
                                        $(dealcommissionamount1).val(commision);
                                        $(showcommision).html(commision);
                                    }
                                </script>
                                
                                <script>
                                    function calcamoutformonth2(damount, dmonth, damount1, totalamount, dealcommision, dealcommision1, dealcommissionamount, showcommision, dealcommissionamount1){
                                        //alert("jhk");
                                        var amt=$(damount).val();
                                        var mth=$(dmonth).val();
                                        var cmp=$(dealcommissionamount1).val();
                                        var tot=amt*mth;
                                        $(damount1).val(tot);
                                        $(totalamount).html(tot);
                                        if((cmp==0)||(cmp=="")){
                                            var commision=0;
                                        }else{
                                            var commision=(cmp*100)/(amt*mth);
                                        }
                                        $(dealcommision).val(commision);
                                        $(dealcommision1).val(commision);
                                        $(showcommision).html(cmp);
                                    }
                                </script>
                                <div class="row">
                                    <div class="col-sm-4">
                                        <span class=" pull-right">
                                            Expected close date
                                        </span>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" name="deal_close_date" id="deal_close_date" style="width:100px;">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-4">
                                        <span class="pull-right">
                                            Deal stage
                                        </span>
                                    </div>
                                    <div class="col-sm-8">
                                        <!--$pipe_id $pipe_name $pipe_percentage-->
                                        
                                        <span class="dropdown">
                                            <input type="hidden" id="deal_stage_id" value="<?php echo $pipe_id[0];?>">
                                            <input type="hidden" id="deal_stage_name1" value="<?php echo $pipe_percentage[0];?>">
                                            <button class="btn btn-default dropdown-toggle" id="deal_stage_name" type="button" data-toggle="dropdown" style="background-color:#DA1A55;color:white;"><?php echo $pipe_percentage[0];?>
                                            <span class="caret"></span></button>
                                            <ul class="dropdown-menu">
                                                <?php
                                                for($ff=0;$ff<count($pipe_id);$ff++){
                                                ?>
                                                <li><a onclick="fundeal('<?php echo $pipe_id[$ff];?>','<?php echo $pipe_percentage[$ff];?>', 'deal_stage_id', 'deal_stage_name', 'deal_stage_won', 'deal_stage_Lost', 'deal_stage_name1')"><?php echo $pipe_percentage[$ff];?>(<?php echo $pipe_name[$ff];?>)</a></li>
                                                <?php
                                                }
                                                ?>
                                            </ul>
                                        </span>
                                        <button class="btn btn-default" id="deal_stage_won" type="button" onclick="fundealwon('Won', 'deal_stage_id', 'deal_stage_won', 'deal_stage_name', 'deal_stage_Lost', 'deal_stage_name1')">Won</button>
                                        <button class="btn btn-default" id="deal_stage_Lost" type="button" onclick="fundealLost('Lost', 'deal_stage_id', 'deal_stage_Lost', 'deal_stage_name', 'deal_stage_won', 'deal_stage_name1')">Lost</button>
      
                                    </div>
                                    
                                </div>
                            </span>
                            <span class="col-sm-4">
                                <span class="pull-right" style="padding:20px;background: #E9EEF0;border-radius:5px;">
                                    <input type="checkbox" value="" id="commission_check">Commission<br>
                                    <input type="checkbox" value="" id="multi_month">Multi-month
                                </span>
                            </span>
                        </span><br>
                        <span class="row">
                            <span class="col-sm-2">
                                <span class="pull-right">
                                    Note (Optional)
                                </span>
                            </span>    
                            <span class="col-sm-10">
                                <textarea class="form-control" rows="5" name="deal_desc" id="deal_desc"></textarea>
                            </span> 
                        </span>
                        
                        <br><br>
                        <span class="row">
                            <span class="col-sm-2"></span>
                            <span class="col-sm-10">
                                <input type="button" class="btn btn-primary" value="save" id="adddealsubmit" onclick="dealinsertsubmit('#deal_date', '#deal_by_id', '#deal_name', '#deal_amount1', '#deal_month', '#deal_close_date', '#deal_stage_id', '#deal_stage_name', '#deal_desc', '#deal_commission', '#deal_commission_amount', '#deal_stage_name1','<?php echo $c_id;?>')">
                                <span style="margin-left:50px;color:grey;cursor:pointer;" id="canceldeal">Cancel</span>
                            </span>
                        </span>
                        
                    </div>
                    <br>    
                </span>
                <br>
                <span id="viewcallnote"></span>
                <br>
                <span id="adddealview">
                    <?php
                      $ll=0;
                    $result_deal=$objsales->salesselectcontid("sales_deal", $c_id);
                    foreach($result_deal as $row_deal){
                        $d_id_a[$ll]=$row_deal['id'];
                        $d_deal_name_a[$ll]=$row_deal['d_deal_name'];
                        $d_deal_by_a[$ll]=$row_deal['d_deal_by'];
                        $d_amount_a[$ll]=$row_deal['d_amount'];
                        $d_month_a[$ll]=$row_deal['d_month'];
                        $d_commission_percentage_a[$ll]=$row_deal['d_commission_percentage'];
                        $d_commission_amount_a[$ll]=$row_deal['d_commission_amount'];
                        $d_descr_a[$ll]=$row_deal['d_descr'];
                        $d_stage_a[$ll]=$row_deal['d_stage'];
                        $d_date_a[$ll]=$row_deal['d_date'];
                        $d_closedate_a[$ll]=$row_deal['d_closedate'];
                        $d_c_by_a[$ll]=$row_deal['d_c_by'];
                        $ll++;
                    }
                    
                    ?>
                    <?php
                    for($lm=0;$lm<count($d_id_a);$lm++){
                        $d_id=$d_id_a[$lm];
                        $d_deal_name=$d_deal_name_a[$lm];
                        $d_deal_by=$d_deal_by_a[$lm];
                        $d_amount=$d_amount_a[$lm];
                        $d_month=$d_month_a[$lm];
                        $d_commission_percentage=$d_commission_percentage_a[$lm];
                        $d_commission_amount=$d_commission_amount_a[$lm];
                        $d_descr=$d_descr_a[$lm];
                        $d_stage=$d_stage_a[$lm];
                        $d_date=$d_date_a[$lm];
                        $d_closedate=$d_closedate_a[$lm];
                        $d_c_by=$d_c_by_a[$lm];
                        
                    ?>
                    <br>
                    <span id="dealeditid<?php echo $d_id;?>" >
                        <div style="background-color:#f0f0f0; padding:6px;">
                            <?php
                            if($d_stage=="Won"){
                            ?>
                            <b>
                            <span style="color:#54b0fe;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-thumbs-up"></i></span>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <span style="color:#54b0fe;font-size:14px;font-size:12px;">Won Deal</span></b>
                                
                                <span style="cursor:pointer;" onclick="fundeletedeal('<?php echo $d_id;?>', '#dealeditid<?php echo $d_id;?>')"><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;
                                <span style="cursor:pointer;" onclick="funeditdeal('<?php echo $d_id;?>','<?php echo $d_deal_name;?>','<?php echo $d_date;?>','<?php echo $d_c_by;?>','<?php echo $d_amount;?>','<?php echo $d_month;?>','<?php echo $d_closedate;?>','<?php echo $d_stage;?>','<?php echo $d_descr;?>','<?php echo $d_commission_percentage;?>','<?php echo $d_commission_amount;?>','<?php echo $c_id;?>', '#dealeditid<?php echo $d_id;?>')"><i class="glyphicon glyphicon-pencil"></i></span>
                                <span class="pull-right" style="color:#777;">
                                    <?php
                                    if($d_c_by==$d_deal_by){
                                    ?>
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_c_by==$emailid11){
                                            $empna=$employeename1[$kk1];
                                            }
                                        }
                                        ?>
                                        Owned & created by <?php echo $empna.",";?>
                                    <?php
                                    }else{
                                    ?>
                                    Owned by &nbsp;&nbsp;
                                    
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_deal_by==$emailid11){
                                            echo $employeename1[$kk1].",";
                                            }
                                        }
                                        ?>
                                    created by &nbsp;&nbsp; 
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_deal_by==$emailid11){
                                            echo $employeename1[$kk1].",";
                                            }
                                        }
                                        ?>   
                                    <?
                                    }
                                    ?>
                                    <?php echo date('M',strtotime($d_date));?>&nbsp;&nbsp;
                                    <?php echo date('d',strtotime($d_date));?>,&nbsp;&nbsp;
                                    <?php echo date('Y',strtotime($d_date));?>&nbsp;&nbsp;
                                </span>
                            
                            <?php
                            }else if($d_stage=="Lost"){
                            ?>
                            <b>
                            <span style="color:#666666;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-thumbs-down"></i></span>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <span style="color:#666666;font-size:14px;">Lost Deal</span></b>
                                <span style="cursor:pointer;" onclick="fundeletedeal('<?php echo $d_id;?>', '#dealeditid<?php echo $d_id;?>')"><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;
                                <span style="cursor:pointer;" onclick="funeditdeal('<?php echo $d_id;?>','<?php echo $d_deal_name;?>','<?php echo $d_date;?>','<?php echo $d_c_by;?>','<?php echo $d_amount;?>','<?php echo $d_month;?>','<?php echo $d_closedate;?>','<?php echo $d_stage;?>','<?php echo $d_descr;?>','<?php echo $d_commission_percentage;?>','<?php echo $d_commission_amount;?>','<?php echo $c_id;?>', '#dealeditid<?php echo $d_id;?>')"><i class="glyphicon glyphicon-pencil"></i></span>
                                <span class="pull-right" style="color:#777;font-size:12px;">
                                    <?php
                                    if($d_c_by==$d_deal_by){
                                    ?>
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_c_by==$emailid11){
                                            $empna=$employeename1[$kk1];
                                            }
                                        }
                                        ?>
                                        Owned & created by <?php echo $empna.",";?>
                                    <?php
                                    }else{
                                    ?>
                                    Owned by &nbsp;&nbsp;
                                    
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_deal_by==$emailid11){
                                            echo $employeename1[$kk1].",";
                                            }
                                        }
                                        ?>
                                    created by &nbsp;&nbsp; 
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_deal_by==$emailid11){
                                            echo $employeename1[$kk1].",";
                                            }
                                        }
                                        ?>   
                                    <?
                                    }
                                    ?>
                                    <?php echo date('M',strtotime($d_date));?>&nbsp;
                                    <?php echo date('d',strtotime($d_date));?>,&nbsp;
                                    <?php echo date('Y',strtotime($d_date));?>&nbsp;
                                </span>
                            
                            <?php
                            }else{
                            ?>
                            <b>
                            <span style="color:#db2b5d;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-time"></i></span>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <span style="color:#db2b5d;font-size:14px;">Pending Deal</span></b>
                                <span style="cursor:pointer;" onclick="fundeletedeal('<?php echo $d_id;?>', '#dealeditid<?php echo $d_id;?>')"><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;
                                <span style="cursor:pointer;" onclick="funeditdeal('<?php echo $d_id;?>','<?php echo $d_deal_name;?>','<?php echo $d_date;?>','<?php echo $d_c_by;?>','<?php echo $d_amount;?>','<?php echo $d_month;?>','<?php echo $d_closedate;?>','<?php echo $d_stage;?>','<?php echo $d_descr;?>','<?php echo $d_commission_percentage;?>','<?php echo $d_commission_amount;?>','<?php echo $c_id;?>', '#dealeditid<?php echo $d_id;?>')"><i class="glyphicon glyphicon-pencil"></i></span>
                                <span class="pull-right" style="color:#777;font-size:12px;">
                                    <?php
                                    if($d_c_by==$d_deal_by){
                                    ?>
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_c_by==$emailid11){
                                            $empna=$employeename1[$kk1];
                                            }
                                        }
                                        ?>
                                        Owned & created by <?php echo $empna.",";?>
                                    <?php
                                    }else{
                                    ?>
                                    Owned by &nbsp;&nbsp;
                                    
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_deal_by==$emailid11){
                                            echo $employeename1[$kk1].",";
                                            }
                                        }
                                        ?>
                                    created by &nbsp;&nbsp; 
                                        <?php
                                        for($kk1=0;$kk1<count($emailid1);$kk1++){
                                            $emailid11=$emailid1[$kk1];
                                            if($d_deal_by==$emailid11){
                                            echo $employeename1[$kk1].",";
                                            }
                                        }
                                        ?>   
                                    <?
                                    }
                                    ?>
                                    <?php echo date('M',strtotime($d_date));?>&nbsp;
                                    <?php echo date('d',strtotime($d_date));?>,&nbsp;
                                    <?php echo date('Y',strtotime($d_date));?>&nbsp;&nbsp;
                                </span>
                            
                            <?php
                            }
                            ?>
                        </div>
                        <div style="background-color:#f8f8f8;padding:10px;">
                            <span style="margin-left:50px;">
                            <b><?php echo $d_deal_name;?></b>
                            </span>
                            <br>
                            <?php
                            if(($d_stage=="Won")||($d_stage=="Lost")){
                                ?>
                            <span style="margin-left:50px;">Rs&nbsp;<b><?php echo $d_amount;?></b>            
                                <span class="dropdown">
                                    <?php
                                    if($d_stage=="Won"){
                                    ?>
                                    <input type="hidden" id="deal_stage_id_e<?php echo $d_id;?>" value="Won">
                                    <input type="hidden" id="deal_stage_name1_e<?php echo $d_id;?>" value="Won">
                                    <button class="btn btn-default dropdown-toggle" id="deal_stage_name_e<?php echo $d_id;?>" type="button" data-toggle="dropdown" style="color:black;">Won
                                    <span class="caret"></span></button>
                                    <?php
                                    }
                                    ?>
                                    <?php
                                    if($d_stage=="Lost"){
                                    ?>
                                    <input type="hidden" id="deal_stage_id_e<?php echo $d_id;?>" value="Lost">
                                    <input type="hidden" id="deal_stage_name1_e<?php echo $d_id;?>" value="Lost">
                                    <button class="btn btn-default dropdown-toggle" id="deal_stage_name_e<?php echo $d_id;?>" type="button" data-toggle="dropdown" style="color:black;">Lost
                                    <span class="caret"></span></button>
                                    <?php
                                    }
                                    ?>
                                    <ul class="dropdown-menu" style="cursor:pointer;">
                                        <?php
                                        for($ff=0;$ff<count($pipe_id);$ff++){
                                        ?>
                                        <li><a onclick="fundeal1('<?php echo $pipe_id[$ff];?>','<?php echo $pipe_percentage[$ff];?>', 'deal_stage_id_e<?php echo $d_id;?>', 'deal_stage_name_e<?php echo $d_id;?>', 'deal_stage_name1_e<?php echo $d_id;?>', '#pendingshowdate<?php echo $d_id;?>', '<?php echo $d_id;?>')"><?php echo $pipe_percentage[$ff];?>(<?php echo $pipe_name[$ff];?>)</a></li>
                                        <?php
                                        }
                                        ?>
                                        <li><a onclick="fundeal1('Won','Won', 'deal_stage_id_e<?php echo $d_id;?>', 'deal_stage_name_e<?php echo $d_id;?>', 'deal_stage_name1_e<?php echo $d_id;?>', '#pendingshowdate<?php echo $d_id;?>', '<?php echo $d_id;?>')"><span style="color:#54b0fe;">Won</span></a></li>
                                        <li><a onclick="fundeal1('Lost','Lost', 'deal_stage_id_e<?php echo $d_id;?>', 'deal_stage_name_e<?php echo $d_id;?>', 'deal_stage_name1_e<?php echo $d_id;?>', '#pendingshowdate<?php echo $d_id;?>', '<?php echo $d_id;?>')"><span style="color:#54b0fe;">Lost</span></a></li>
                                    </ul>
                                </span>
                                <span id="pendingshowdate<?php echo $d_id;?>" style="display:none;">
                                &nbsp;&nbsp;&nbsp;chance it will close&nbsp;&nbsp;<input type="text" id="d_date_e<?php echo $d_id;?>" readonly style="background-color:#f0f0f0;border:none;width:100px;" value="<?php echo $d_closedate_a[$lm];?>" onchange="funupdateclosedate1('#d_date_e<?php echo $d_id;?>', '<?php echo $d_id;?>','<?php echo $d_closedate_a[$lm];?>')">
                                </span>
                            </span>
                            <?php
                            }else{
                            ?>
                            <span style="margin-left:50px;"><span style="color:#db2b5d;">Rs&nbsp;<b><?php echo $d_amount;?></b></span>
                            <?php
                            for($ff1=0;$ff1<count($pipe_id);$ff1++){
                                
                                $pipe_id121=$pipe_id[$ff1];
                                if($pipe_id121==$d_stage){
                                    $pipename=$pipe_percentage[$ff1];
                                }
                            }
                            ?>
                                <span class="dropdown">
                                    <input type="hidden" id="deal_stage_id_e<?php echo $d_id;?>" value="<?php echo $d_stage;?>">
                                    <input type="hidden" id="deal_stage_name1_e<?php echo $d_id;?>" value="<?php echo $pipename;?>">
                                    <button class="btn btn-default dropdown-toggle" id="deal_stage_name_e<?php echo $d_id;?>" type="button" data-toggle="dropdown" style="color:black;"><?php echo $pipename;?>
                                    <span class="caret"></span></button>
                                    <ul class="dropdown-menu" style="cursor:pointer;">
                                        <?php
                                        for($ff=0;$ff<count($pipe_id);$ff++){
                                        ?>
                                        <li><a onclick="fundeal1('<?php echo $pipe_id[$ff];?>','<?php echo $pipe_percentage[$ff];?>', 'deal_stage_id_e<?php echo $d_id;?>', 'deal_stage_name_e<?php echo $d_id;?>', 'deal_stage_name1_e<?php echo $d_id;?>', '#pendingshowdate<?php echo $d_id;?>', '<?php echo $d_id;?>')"><?php echo $pipe_percentage[$ff];?>(<?php echo $pipe_name[$ff];?>)</a></li>
                                        <?php
                                        }
                                        ?>
                                        <li><a onclick="fundeal1('Won','Won', 'deal_stage_id_e<?php echo $d_id;?>', 'deal_stage_name_e<?php echo $d_id;?>', 'deal_stage_name1_e<?php echo $d_id;?>', '#pendingshowdate<?php echo $d_id;?>', '<?php echo $d_id;?>')"><span style="color:#54b0fe;">Won</span></a></li>
                                        <li><a onclick="fundeal1('Lost','Lost', 'deal_stage_id_e<?php echo $d_id;?>', 'deal_stage_name_e<?php echo $d_id;?>', 'deal_stage_name1_e<?php echo $d_id;?>', '#pendingshowdate<?php echo $d_id;?>', '<?php echo $d_id;?>')"><span style="color:#54b0fe;">Lost</span></a></li>
                                    </ul>
                                </span>
                                <span id="pendingshowdate<?php echo $d_id;?>" >
                                    &nbsp;&nbsp;&nbsp;chance it will close&nbsp;&nbsp;<input type="text" id="d_date_e<?php echo $d_id;?>" style="background-color:#f0f0f0;border:none;width:100px;" value="<?php echo $d_closedate_a[$lm];?>" onchange="funupdateclosedate1('#d_date_e<?php echo $d_id;?>', '<?php echo $d_id;?>','<?php echo $d_closedate_a[$lm];?>')" readonly>
                                </span>
                            </span>
                            
                            <?php
                            }
                            ?>
                            <br>
                            <span style="margin-left:50px;">
                                <span style="font-family: 'Open Sans', Arial, Helvetica, sans-serif;font-size: 12px;color: #999;margin-top: 2px;margin-bottom: 4px;">
                                    <h5 style="margin-left:50px;">Note</h5>
                                    <span style="margin-left:50px;white-space: normal;text-overflow: ellipsis;overflow: hidden;width:90%;color:black;"><?php echo $d_descr;?></span>
                                </span>
                            </span>
                            <br>
                            
                            </div>
                    </span>
                    
                    
                    <br>
                    <br>
<script>
    $(document).ready(function(){
        var id="#d_date_e<?php echo $d_id;?>";
        var startdate="<?php echo $d_closedate_a[$lm];?>";
        $(id).datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true 
        }).datepicker('update', startdate); 
    });
</script>
                    <?php
                    }
                    ?>
                </span>
                
</div>
<br>
<br>
                
                <script>
                    $(document).on("click", "#hidecalldate", function(){
                       $(this).hide();
                       $("#call_date").show();
                    });
                    $(document).on("click", "#hidecalltime", function(){
                       $(this).hide();
                       $("#call_time").show();
                    });
                </script>
                    <script>
                        function funshowphonenum(selectphone, showid){
                            var cphonetype=new Array();
                            var cphonenumber=new Array();
                            var cphoneid=new Array();
                            var see=$(selectphone).val();
                            //alert(see);
                            cphonetype=<?php echo json_encode($c_phone_type);?>;
                            cphonenumber=<?php echo json_encode($c_phone_number);?>;
                            cphoneid=<?php echo json_encode($c_phone_id);?>;
                            for(var d=0; d<cphonenumber.length;d++){
                                if(see==cphoneid){
                                    var sh="&nbsp;on&nbsp;"+cphonenumber[d]+"&nbsp;&nbsp;(&nbsp;"+cphonetype[d]+"&nbsp;)";
                                }
                            }
                            $(showid).empty();
                            $(showid).show();
                            $(showid).append(sh);
                        }
                    </script>
                        <script>
                            function functemailthisuser(id,val1){
                                //alert(val1);
                                var em=$("#sendemailcheckbox").val();
                                if($(id).is(':checked')){
                                    if(em!=""){
                                        em+="#@"+val1;
                                    }else{
                                        em=val1;
                                    }
                                    var em2=em;
                                }else{
                                    var em2="";
                                    em1=em.split("#@");
                                    //alert(em1.length);
                                    for(hh=0;hh<em1.length;hh++){
                                        if(em1[hh]!=val1){
                                            if(em2==""){
                                                em2=em1[hh];
                                            }else{
                                                em2+="#@"+val1;
                                            }
                                        }
                                    }
                                }
                                $("#sendemailcheckbox").val(em2);
                            }
                        </script>
                <script>
                    function funcalldelete(hideid, callid){
                        swal("Call Deleted Successfully","","success");
                        $.ajax({
                            url:"activestream_intermediate.php",
                            type:"post",
                            data:{deletecall:callid},
                            success:function(respond){
                                    /*BootstrapAlert.success({
                                      title: "Success!",
                                      message: "Call Deleted Successfully"
                                    }); */
                                $(hideid).hide();
                            }
                        });
                    }
                </script>
                <script>
                    function showeditdate(hide1, show1, date1){
                        $(hide1).hide();
                        $(show1).show();
                        var startdate=date1;
                        $(show1).datepicker({ 
                            format : "yyyy-mm-dd",
                            autoclose: true 
                        }).datepicker('update', startdate); 
                    }
                </script>
                <script>
                    function showphonenum(hide1, show1, time1){
                        $(hide1).hide();
                        $(show1).show();
                        var startdate=time1;
                        $(show1).clockpicker({
                            placement: 'bottom',
                            align: 'left',
                            autoclose: true,
                            'default': startdate
                        });
                    }
                </script>
                <script>
                    function funcalledit(showid, cid, callid, calldate, callphone, callresult, calltime, calldesc, sendemailcheckbox, fname, lname){
                        
                        var emailid1=new Array();
                        var employeename1=new Array();
                        var cphonetype=new Array();
                        var cphoneid=new Array();
                        var cphonenumber=new Array();
                        var cansida=new Array();
                        var cansnamea=new Array(); 
                        var employeecontactemailid=new Array();
                        employeecontactemailid=<?php echo json_encode($employee_contact_emailid);?>;
                        cansida=<?php echo json_encode($c_ans_id_a);?>;
                        cansnamea=<?php echo json_encode($c_ans_name_a);?>;
                        emailid1=<?php echo json_encode($emailid1);?>;
                        employeename1=<?php echo json_encode($employeename1);?>;
                        cphonetype=<?php echo json_encode($c_phone_type);?>;
                        cphoneid=<?php echo json_encode($c_phone_id);?>;
                        cphonenumber=<?php echo json_encode($c_phone_number);?>;
                        var adminemailid="<?php echo $adminemailid;?>";  
                        
                        var insert="";
                        var phon1;
                        var phon2;
                        
                        insert+='<span id="editcall">';
                        
                        insert+='<div class="row">';
                        insert+='<div class="col-sm-6"><h4>Edit Call</h4></div>';
                        insert+='<div class="col-sm-6">';
                        insert+='<span class="pull-right">Date created';
                        insert+='<span style="color:blue;cursor:pointer;" id="hideeditdate_e'+callid+'" onclick=showeditdate("#hideeditdate_e'+callid+'","#call_date_e'+callid+'","'+calldate+'")>Today</span>';
                        insert+='<input type="text" name="call_date_e'+callid+'" value="'+calldate+'" id="call_date_e'+callid+'"  readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
                        insert+='</span>';
                        insert+='</div>';
                        insert+='</div>';
                        
                        insert+='<div class="row" style="padding:10px;background-color:#dfe6ea;border-radius:5px;">';
                    
                        insert+='<span class="row">';
                        insert+='<span class="col-sm-2">';
                        insert+='<span class="pull-right">Phone</span>';
                        insert+='</span>';
                        insert+='<span class="col-sm-10">';
                        insert+='<select id="call_phone_e'+callid+'" name="call_phone_e'+callid+'" class="form-control" style="width:250px;height:30px;" onchange=funshowphonenum("#call_phone_e'+callid+'","#showselectedphone_e'+callid+'")>'; 
                        insert+='<option></option>';
                        for(hg=0;hg<cphonetype.length;hg++){
                            if(callphone==cphoneid[hg]){
                                phon1=cphonenumber[hg];
                                phon2=cphonetype[hg];
                                insert+='<option value="'+cphoneid[hg]+'" selected>'+cphonenumber[hg]+'&nbsp;&nbsp;('+cphonetype[hg]+')</option>';
                            }else{
                                insert+='<option value="'+cphoneid[hg]+'">'+cphonenumber[hg]+'&nbsp;&nbsp;('+cphonetype[hg]+')</option>';
                            }
                        }
                        insert+='</select>';
                        insert+='</span>';
                        insert+='</span>';
                        
                        insert+='<span class="row">';
                        insert+='<span class="col-sm-2">';
                        insert+='<span class="pull-right">Result</span>';
                        insert+='</span>';
                        insert+='<span class="col-sm-10">';
                        insert+='<select id="call_result_e'+callid+'" name="call_result_e'+callid+'" class="form-control" style="width:250px;height:30px;">';
                        for(bh=0;bh<cansida.length;bh++){
                            if(callresult==cansida[bh]){
                                insert+='<option value="'+cansida[bh]+'" selected>'+cansnamea[bh]+'</option>';
                            }else{
                                insert+='<option value="'+cansida[bh]+'">'+cansnamea[bh]+'</option>';
                            }
                        }
                        insert+='<option value="Other">Other</option>';
                        insert+='</select>'; 
                        insert+='</span>';
                        insert+='</span>';
                        
                        insert+='<span class="row">';
                        insert+='<span class="col-sm-2">';
                        insert+='<span class="pull-right">Note</span>';
                        insert+='</span>';
                        insert+='<span class="col-sm-10">';
                        insert+='Called&nbsp;&nbsp;'+fname+'&nbsp;at &nbsp;';
                        insert+='<span style="color:blue;cursor:pointer;" id="hidecalltime_e'+callid+'" onclick=showphonenum("#hidecalltime_e'+callid+'","#call_time_e'+callid+'","'+calltime+'")>'+calltime+'</span>';
                        insert+='<input type="text" id="call_time_e'+callid+'" value="'+calltime+'" readonly  style="width:100px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
                        insert+='<span id="showselectedphone_e'+callid+'"> on '+phon1+'  ( '+phon2+' )</span>';
                        insert+='</span>';
                        insert+='</span>';
                        
                        
                        insert+='<span class="row">';
                        insert+='<span class="col-sm-2">';
                        insert+='</span>';
                        insert+='<span class="col-sm-10">';
                        insert+='<textarea id="call_desc_e'+callid+'" class="form-control" rows="5">'+calldesc+'</textarea>';
                        insert+='</span>';
                        insert+='</span>';
                        
                        insert+='<span class="row">';
                        insert+='<span class="pull-right">';
                        insert+='Email these users';  
                        for(yy=0;yy<employeecontactemailid.length;yy++){
                            for(yy1=0;yy1<emailid1.length;yy1++){
                                if(employeecontactemailid[yy]==emailid1[yy1]){
                                    insert+='<br><span style="float:left;"><input type="checkbox" onclick=functemailthisuser("#check_e'+yy+'","'+employeecontactemailid[yy]+'") id="check_e'+yy+'" value="'+employeecontactemailid[yy]+'">'+employeename1[yy]+'</span>';
                                }
                            }
                        }
                        insert+='</span>';
                        insert+='</span>';
                        insert+='<input type="hidden" id="sendemailcheckbox" class="form-contro">';
                        insert+='<br>';
                        
                        //alert(insert);
                        
                        insert+='<span class="row">';
                        insert+='<span class="col-sm-2">';
                        insert+='</span>';
                        insert+='<span class="col-sm-10">';
                        insert+='<input type="button" class="btn btn-primary" value="Update" onclick=callupdatesubmit("'+showid+'","'+callid+'","#call_date_e'+callid+'","#call_phone_e'+callid+'","#call_result_e'+callid+'","#call_time_e'+callid+'","#call_desc_e'+callid+'","#sendemailcheckbox","#addcall","#viewcallnote","'+cid+'","'+fname+'","'+lname+'")>';
                        insert+='<span style="margin-left:50px;color:grey;cursor:pointer;" id="cancelcall" onclick=funcallcancelview("'+showid+'","'+cid+'","'+callid+'","'+calldate+'","'+callphone+'","'+callresult+'","'+calltime+'","'+calldesc+'","'+sendemailcheckbox+'","'+fname+'","'+lname+'")>Cancel</span>';
                        insert+='</span>';
                        insert+='</span>';
                        insert+='<br><br>';
                        
                        insert+='</div>';
                        insert+='<br>';
                        insert+='</span>';
                        //alert(insert);
                        $(showid).empty();
                        $(showid).append(insert);
                    }
                </script>
                <script>
                    function callupdatesubmit(showid,callid,call_date,call_phone,call_result,call_time,call_desc,send_emailcheckbox,addcall,viewcallnote,cid,fname,lname){
                        var employeecontactemailid=new Array();
                        employeecontactemailid=<?php echo json_encode($employee_contact_emailid);?>;
                        var calldate=$(call_date).val();
                        var callphone=$(call_phone).val();
                        var callresult=$(call_result).val();
                        var calltime=$(call_time).val();
                        var calldesc=$(call_desc).val();
                        var sendemailcheckbox=$(send_emailcheckbox).val();
                        /*alert("calldate:"+calldate);
                        alert("callphone:"+callphone);
                        alert("callresult:"+callresult);
                        alert("calltime:"+calltime);
                        alert("calldesc:"+calldesc);
                        alert("sendemailcheckbox:"+sendemailcheckbox);*/
                        var today = new Date();
                        var dd = today.getDate();
                        var mm = today.getMonth()+1; //January is 0!
                        var yyyy = today.getFullYear();
                        var h=today.getHours();
                        var m=today.getMinutes();
                        if(dd<10) {
                            dd = '0'+dd
                        } 
                        
                        if(mm<10) {
                            mm = '0'+mm
                        } 
                        
                        today =yyyy+'-'+ mm + '-' + dd;
                        now=h+":"+m;
                        swal("Call Updated Successfully","","success");
                        $.ajax({
                            url:"activestream_intermediate.php",
                            type:"post",
                            data:{updatecall:callid, calldate:calldate, callphone:callphone, callresult:callresult, calltime:calltime, calldesc:calldesc, cid:cid},
                            success:function(respond){
                                    /*BootstrapAlert.success({
                                      title: "Success!",
                                      message: "Call Updated Successfully"
                                    }); */
                                funcallcancelview(showid, cid, callid, calldate, callphone, callresult, calltime, calldesc, sendemailcheckbox, fname, lname);
                            }
                        });
                    }
                </script>
                <script>
                    function callinsertsubmit(call_date,call_phone,call_result,call_time,call_desc,send_emailcheckbox,addcall,viewcallnote,cid,fname,lname){
                        var employeecontactemailid=new Array();
                        employeecontactemailid=<?php echo json_encode($employee_contact_emailid);?>;
                        var calldate=$(call_date).val();
                        var callphone=$(call_phone).val();
                        if(callphone==""){
                            swal("", "Please choose the phone Number", "warning");
                            return;
                        }
                        var callresult=$(call_result).val();
                        var calltime=$(call_time).val();
                        var calldesc=$(call_desc).val();
                        var sendemailcheckbox=$(send_emailcheckbox).val();
                        /*alert("calldate:"+calldate);
                        alert("callphone:"+callphone);
                        alert("callresult:"+callresult);
                        alert("calltime:"+calltime);
                        alert("calldesc:"+calldesc);
                        alert("sendemailcheckbox:"+sendemailcheckbox);*/
                        var today = new Date();
                        var dd = today.getDate();
                        var mm = today.getMonth()+1; //January is 0!
                        var yyyy = today.getFullYear();
                        var h=today.getHours();
                        var m=today.getMinutes();
                        if(dd<10) {
                            dd = '0'+dd
                        } 
                        
                        if(mm<10) {
                            mm = '0'+mm
                        } 
                        
                        today =yyyy+'-'+ mm + '-' + dd;
                        now=h+":"+m;
                        swal("Call Created Successfully","","success");
                        $.ajax({
                            url:"activestream_intermediate.php",
                            type:"post",
                            data:{insertcall:calldate, callphone:callphone, callresult:callresult, calltime:calltime, calldesc:calldesc, cid:cid},
                            success:function(respond){
                                var cccc=respond.trim();
                                    /*BootstrapAlert.success({
                                      title: "Success!",
                                      message: "Call Created Successfully"
                                    }); */
                                $(call_date).val(today);
                                $(call_phone).val([]);
                                $(call_result).val([]);
                                $(call_time).val(now);
                                $(call_desc).val("");
                                $(send_emailcheckbox).val("");
                                var chlen=employeecontactemailid.length;
                                for(m=0;m<chlen;m++){
                                    $("#check"+m).prop('checked', false); 
                                }
                                $(addcall).hide();
                                $("#addcallbutton").attr("disabled", false);
                                funcallview("#viewcallnote", cid, cccc, calldate, callphone, callresult, calltime, calldesc, sendemailcheckbox, fname, lname);
                            }
                        });
                    }
                </script>
                <script>
                    function funcallview(showid, cid, callid, calldate, callphone, callresult, calltime, calldesc, sendemailcheckbox, fname, lname){
                        
                        var emailid1=new Array();
                        var employeename1=new Array();
                        var cphonetype=new Array();
                        var cphoneid=new Array();
                        var cphonenumber=new Array();
                        emailid1=<?php echo json_encode($emailid1);?>;
                        employeename1=<?php echo json_encode($employeename1);?>;
                        cphonetype=<?php echo json_encode($c_phone_type);?>;
                        cphoneid=<?php echo json_encode($c_phone_id);?>;
                        cphonenumber=<?php echo json_encode($c_phone_number);?>;
                        var adminemailid="<?php echo $adminemailid;?>";  
                        for(kk=0;kk<emailid1.length;kk++){
                            if(adminemailid==emailid1[kk]){
                                var empname=employeename1[kk];
                            }
                        }
                        for(kk1=0;kk1<cphoneid.length;kk1++){
                            if(callphone==cphoneid[kk1]){
                                var ptype=cphonetype[kk1];
                                var pnum=cphonenumber[kk1];
                            }
                        }
                        var insert="";
                        insert+='<div id="callview'+callid+'">';
                        insert+='<div id="callview1'+callid+'" style="clear: both;border: 1px solid #EAEAEA;border-radius: 2px 2px 2px 2px; box-shadow: 0 0 2px #EAEAEA, 0 0 6px #F0F0F0 inset;padding: 6px 10px;margin: 15px 0 20px 0;">';
                        
                        insert+='<div class="timeline_data" style="color: #9D9992;padding-bottom: 6px;line-height: 1;">';
                        insert+=empname+'&nbsp;&nbsp;Created Call - Moment ago ';
                        insert+='<span style="cursor:pointer;" onmouseover=changedeleteicon("sss'+callid+'") onmouseout=changedeleteicon1("sss'+callid+'") id="sss'+callid+'" onclick=funcalldelete("#callview'+callid+'","'+callid+'") ><i class="glyphicon glyphicon-trash"></i></span> &nbsp;&nbsp;';
                        insert+='<span style="cursor:pointer;" onmouseover=changeediticon("eee'+callid+'") onmouseout=changeediticon1("eee'+callid+'") id="eee'+callid+'" onclick=funcalledit("#callview'+callid+'","'+cid+'","'+callid+'","'+calldate+'","'+callphone+'","'+callresult+'","'+calltime+'","'+calldesc+'","'+sendemailcheckbox+'","'+fname+'","'+lname+'") ><i class="glyphicon glyphicon-pencil"></i></span>';
                        insert+='</div>';
                        
                        insert+='<div style="clear: both;color: #666666;line-height: 1.2;height: auto;max-height: 92px;white-space: normal;overflow: hidden;text-overflow: ellipsis;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;word-wrap: break-word;">';
                        insert+='Converstion:'+callresult+' &nbsp; Called &nbsp;'+fname+' '+lname+' at '+calltime+' on '+pnum+' ('+ptype+') - '+calldesc;
                        insert+='</div>';
                        
                        if(sendemailcheckbox!=""){
                        insert+='<div style="font-family: Open Sans Italic, Arial, Helvetica, sans-serif;color: #9D9992;">';
                        sq=sendemailcheckbox.split("#@");
                        for(s1=0;s1<sq.length;s1++){
                            for(s2=0;s2<emailid1.length;s2++){
                                if(sq[s1]==emailid1[s2]){
                                    insert+=employeename1[s2]+', ';
                                }
                            }
                        }
                        insert+=' have been notified by email';
                        insert+='</div>';
                        }
                        
                        insert+='</div>';
                        insert+='</div>';
                        
                        //alert(insert);
                        $(showid).append(insert);
                    }
                </script>
                <script>
                    function funcallcancelview(showid, cid, callid, calldate, callphone, callresult, calltime, calldesc, sendemailcheckbox, fname, lname){
                        
                        var emailid1=new Array();
                        var employeename1=new Array();
                        var cphonetype=new Array();
                        var cphoneid=new Array();
                        var cphonenumber=new Array();
                        emailid1=<?php echo json_encode($emailid1);?>;
                        employeename1=<?php echo json_encode($employeename1);?>;
                        cphonetype=<?php echo json_encode($c_phone_type);?>;
                        cphoneid=<?php echo json_encode($c_phone_id);?>;
                        cphonenumber=<?php echo json_encode($c_phone_number);?>;
                        var adminemailid="<?php echo $adminemailid;?>";  
                        for(kk=0;kk<emailid1.length;kk++){
                            if(adminemailid==emailid1[kk]){
                                var empname=employeename1[kk];
                            }
                        }
                        for(kk1=0;kk1<cphoneid.length;kk1++){
                            if(callphone==cphoneid[kk1]){
                                var ptype=cphonetype[kk1];
                                var pnum=cphonenumber[kk1];
                            }
                        }
                        var insert="";
                        insert+='<div id="callview1'+callid+'" style="clear: both;border: 1px solid #EAEAEA;border-radius: 2px 2px 2px 2px; box-shadow: 0 0 2px #EAEAEA, 0 0 6px #F0F0F0 inset;padding: 6px 10px;margin: 15px 0 20px 0;">';
                        
                        insert+='<div class="timeline_data" style="color: #9D9992;padding-bottom: 6px;line-height: 1;">';
                        insert+=' '+empname+'&nbsp;&nbsp;Created Call - Moment ago ';
                        insert+='<span style="cursor:pointer;" onmouseover=changedeleteicon("sss'+callid+'") onmouseout=changedeleteicon1("sss'+callid+'") id="sss'+callid+'" onclick=funcalldelete("'+showid+'","'+callid+'") ><i class="glyphicon glyphicon-trash"></i></span> &nbsp;&nbsp;';
                        insert+='<span style="cursor:pointer;" onmouseover=changeediticon("eee'+callid+'") onmouseout=changeediticon1("eee'+callid+'") id="eee'+callid+'" onclick=funcalledit("'+showid+'","'+cid+'","'+callid+'","'+calldate+'","'+callphone+'","'+callresult+'","'+calltime+'","'+calldesc+'","'+sendemailcheckbox+'","'+fname+'","'+lname+'") ><i class="glyphicon glyphicon-pencil"></i></span>';
                        insert+='</div>';
                        
                        insert+='<div style="clear: both;color: #666666;line-height: 1.2;height: auto;max-height: 92px;white-space: normal;overflow: hidden;text-overflow: ellipsis;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;word-wrap: break-word;">';
                        insert+='Converstion:'+callresult+' &nbsp; Called &nbsp;'+fname+' '+lname+' at '+calltime+' on '+pnum+' ('+ptype+') - '+calldesc;
                        insert+='</div>';
                        
                        
                        if(sendemailcheckbox!=""){
                        insert+='<div style="font-family: Open Sans Italic, Arial, Helvetica, sans-serif;color: #9D9992;">';
                        sq=sendemailcheckbox.split("#@");
                        for(s1=0;s1<sq.length;s1++){
                            for(s2=0;s2<emailid1.length;s2++){
                                if(sq[s1]==emailid1[s2]){
                                    insert+=employeename1[s2]+', ';
                                }
                            }
                        }
                        insert+=' have been notified by email';
                        insert+='</div>';
                        }
                        
                        insert+='</div>';
                        
                        //alert(insert);
                        $(showid).empty();
                        $(showid).append(insert);
                    }
                </script>
                <script>
                    function changedeleteicon(id) {
                        var x = document.getElementById(id);
                        x.style.color = 'red';
                    }
                    function changedeleteicon1(id) {
                        var x = document.getElementById(id);
                        x.style.color = "#9D9992";
                    }
                    function changeediticon(id) {
                        var x = document.getElementById(id);
                        x.style.color = 'red';
                    }
                    function changeediticon1(id) {
                        var x = document.getElementById(id);
                        x.style.color = "#9D9992";
                    }
                </script>
<script>
    function funeditdeal(d_id,d_deal_name,d_date,d_c_by,d_amount,d_month,d_closedate,d_stage,d_descr,d_commission_percentage,d_commission_amount, cid, divload ){
        
        /*alert("divload:"+divload);
        alert("d_id:"+d_id);
        alert("d_deal_name:"+d_deal_name);
        alert("d_date:"+d_date);
        alert("d_c_by:"+d_c_by);
        alert("d_amount:"+d_amount);
        alert("d_month:"+d_month);
        alert("d_closedate:"+d_closedate);
        alert("d_stage:"+d_stage);
        alert("d_descr:"+d_descr);
        alert("d_commission_percentage:"+d_commission_percentage);
        alert("d_commission_amount:"+d_commission_amount);
        alert("cid:"+cid);*/
        //$(hidediv).hide();
        var emailid1=new Array();
        var employeename1=new Array();
        var pipe_id=new Array();
        var pipe_percentage=new Array();
        var pipe_name=new Array();
        emailid1=<?php echo json_encode($emailid1);?>;
        employeename1=<?php echo json_encode($employeename1);?>;
        var adminemailid="<?php echo $adminemailid;?>";
        pipe_id=<?php echo json_encode($pipe_id);?>;
        pipe_percentage=<?php echo json_encode($pipe_percentage);?>;
        pipe_name=<?php echo json_encode($pipe_name);?>;
        var insert="";
        insert+='<div class="row">';
        insert+='<div class="col-sm-6"><h4>Edit Deal</h4></div>';
        insert+='<div class="col-sm-6">';
        insert+='<span class="pull-right">';
        insert+='Created&nbsp;&nbsp;';
        insert+='<span style="color:blue;cursor:pointer;" id="hidedealdate">Today</span>';
        insert+='<input type="text" name="deal_date_e1" value="'+d_date+'" id="deal_date_e1"  readonly style="width:180px;height:30px;border-radius:5px;margin-left:10px;cursor:pointer;display:none;">';
        insert+='&nbsp;&nbsp;&nbsp;';
        insert+='<span class="dropdown">';
        var empbyname="";
        for(var jh=0;jh<emailid1.length;jh++){
            if(d_c_by==adminemailid){
                empbyname="Me";
            }else if(d_c_by==emailid1[jh]){
                empbyname=emailid1[jh];
            }
        }
        //alert(insert);
        insert+='<input type="hidden" id="deal_by_id_e1" value="'+d_c_by+'">';
        insert+='<button class="btn btn-default dropdown-toggle" id="deal_by_name_e1" type="button" data-toggle="dropdown">'+empbyname+'</button>';
        insert+='<span class="caret" style="margin-left:-10px;"></span>';
        insert+='<ul class="dropdown-menu">';
        //alert(insert);
        for(var kk=0;kk<emailid1.length;kk++){
            emailid11=emailid1[kk];
            if(emailid11==adminemailid){
                employeename11="Me";
            }else{
            employeename11=employeename1[kk];
            }
        insert+='<li><a onclick=funemployee("'+emailid11+'","'+employeename11+'","'+cid+'","deal_by_id_e1","deal_by_name_e1")>'+employeename11+'</a></li>';
                                           
        }
                                         
        insert+='</ul>';
        insert+='</span>';
        
        insert+='</span>';
        insert+='</div>';
        insert+='</div>';
        
        
        insert+='<div class="row" style="padding:10px;background-color:#dfe6ea;border-radius:5px;">';
        
        insert+='<span class="row">';
        insert+='<span class="col-sm-8">';
        insert+='<div class="row">';
        insert+='<span class="col-sm-4">';
        insert+='<span class="pull-right">Deal Name</span>';
        insert+='</span>';
        insert+='<span class="col-sm-8">';
        insert+='<input type="text" id="deal_name_e1" name="deal_name_e1" class="form-control" value="'+d_deal_name+'">';
        insert+='</span>';
        insert+='</div><br>';
        //alert(insert);
        insert+='<div class="row">';
        insert+='<span class="col-sm-4">';
        insert+='<span class=" pull-right">';
        insert+='<span id="monthamout_e1" style="display:none;">Month amount</span>';
        insert+='<span id="amount">Amount</span>';
        insert+='</span>';
        insert+='</span>';
        insert+='<span class="col-sm-8">';
        insert+='<input type="number" value="'+d_amount+'" name="deal_amount_e1" id="deal_amount_e1" style="width:100px;border-radius:5px;" min="0" max="200000000" onkeyup=calcamoutformonth("#deal_amount_e1","#deal_month_e1","#deal_amount1_e1","#total_amount_e1","#deal_commission_e1","#deal_commission_amount_e1","#deal_commission_amount1_e1")>';
        insert+='<span id="monthamout1"><b>x</b>';
        insert+='<input type="number" name="deal_month_e1" id="deal_month_e1" style="width:70px;" value="'+d_month+'" min="1" max="40" onkeyup=calcamoutformonth("#deal_amount_e1","#deal_month_e1","#deal_amount1_e1","#total_amount_e1","#deal_commission_e1","#deal_commission_amount_e1","#deal_commission_amount1_e1")><span style="color:grey;">month</span>';
        insert+='<br>Total Amount ₨<span id="total_amount_e1">'+d_amount+'</span>';
        insert+='<input type="hidden" name="deal_amount1_e1" id="deal_amount1_e1" value="'+d_amount+'" style="width:100px;border-radius:5px;">';
        insert+='</span>';
        insert+='</span>';
        insert+='</div><br>';
        //alert(insert);
        insert+='<div class="row" id="Commission_e1">';
        insert+='<span class="col-sm-4"> <span class=" pull-right">Commission %</span></span>';
        insert+='<span class="col-sm-8">';
        insert+='<input type="text" name="deal_commission_e1" id="deal_commission_e1" value="'+d_commission_percentage+'" style="width:100px;" onkeyup=calcamoutformonth("#deal_amount_e1","#deal_month_e1","#deal_amount1_e1","#total_amount_e1","#deal_commission_e1","#deal_commission_amount_e1","#deal_commission_amount1_e1")>';
        insert+='<input type="hidden" name="deal_commission_amount_e1" id="deal_commission_amount_e1" value="'+d_commission_amount+'"  style="border-radius:5px;">';
        insert+='<span class="btn">&#37;</span><span style="color:grey">Value ₨<span id="deal_commission_amount1_e1">'+d_commission_amount+'</span> based on amount</span>'; 
        insert+='</span>';
        insert+='</div>';
        
        insert+='<div class="row">';
        insert+='<div class="col-sm-4">';
        insert+='<span class=" pull-right">';
        insert+='Expected close date';
        insert+='</span>';
        insert+='</div>';
        insert+='<div class="col-sm-4">';
        insert+='<input type="text" name="deal_close_date_e1" id="deal_close_date_e1" value="'+d_closedate+'" style="width:100px;">';
        insert+='</div>';
        insert+='</div>';
                                
        insert+='<div class="row">';
        insert+='<div class="col-sm-4">';
        insert+='<span class="pull-right">';
        insert+='Deal stage';
        insert+='</span>';
        insert+='</div>';
        insert+='<div class="col-sm-8">';                              
        insert+='<span class="dropdown">'; 
        //alert(insert);  
        var pname="";
        for(var ff1=0;ff1<pipe_id.length;ff1++){
            if(d_stage=="Won"){
                pname="Won";
            }else if(d_stage=="Lost"){
                pname="Lost";
            }else if(d_stage==pipe_id[ff1]){
                pname=pipe_percentage[ff1];
            }   
        }
        //alert(insert);  
        //alert("d_stage:"+d_stage);  
        insert+='<input type="hidden" id="deal_stage_id_e1" value="'+d_stage+'">';
        insert+='<input type="hidden" id="deal_stage_name1_e1" value="'+pname+'">';
        insert+='<button class="btn btn-default dropdown-toggle" id="deal_stage_name_e1" type="button" data-toggle="dropdown" style="background-color:#DA1A55;color:white;">'+pname+'<span class="caret"></span></button>';
        insert+='<ul class="dropdown-menu">';
        //alert(insert);  
        for(ff=0;ff<pipe_id.length;ff++){
        insert+='<li><a onclick=fundeal("'+pipe_id[ff]+'","'+pipe_percentage[ff]+'","deal_stage_id_e1","deal_stage_name_e1","deal_stage_won_e1","deal_stage_Lost_e1","deal_stage_name1_e1")>'+pipe_percentage[ff]+'('+pipe_name[ff]+')</a></li>';
        }
        //alert(insert);  
        insert+='</ul>';
        insert+='</span>';
        insert+='<button class="btn btn-default" id="deal_stage_won_e1" type="button" onclick=fundealwon("Won","deal_stage_id_e1","deal_stage_won_e1","deal_stage_name_e1","deal_stage_Lost_e1","deal_stage_name1_e1")>Won</button>';
        insert+='<button class="btn btn-default" id="deal_stage_Lost_e1" type="button" onclick=fundealLost("Lost","deal_stage_id_e1","deal_stage_Lost_e1","deal_stage_name_e1","deal_stage_won_e1","deal_stage_name1_e1")>Lost</button>';
      
        insert+='</div>';  
                                    
        insert+='</div>';
        insert+='</span>';
        insert+='<span class="col-sm-4">';
        insert+='<span class="pull-right" style="padding:20px;background: #E9EEF0;border-radius:5px;">';
        insert+='<input type="checkbox" value="1" id="commission_check_e1">Commission<br>';
        insert+='<input type="checkbox" value="1" id="multi_month_e1">Multi-month';
        insert+='</span>';
        insert+='</span>';
        insert+='</span><br>';
        insert+='<span class="row">';
        insert+='<span class="col-sm-2">';
        insert+='<span class="pull-right">';
        insert+='Note (Optional)';
        insert+='</span>';
        insert+='</span>';    
        insert+='<span class="col-sm-10">';
        insert+='<textarea class="form-control" rows="5" name="deal_desc_e1" id="deal_desc_e1">'+d_descr+'</textarea>';
        insert+='</span>';
        insert+='</span>';
                       
        //alert(insert);   
        //alert("completed");
        insert+='<br><br>';
        insert+='<span class="row">';
        insert+='<span class="col-sm-2"></span>';
        insert+='<span class="col-sm-10">';
        insert+='<input type="button" class="btn btn-primary" value="Update" id="editdealsubmit" onclick=dealupdatesubmit("'+d_id+'","#deal_date_e1","#deal_by_id_e1","#deal_name_e1","#deal_amount1_e1","#deal_month_e1","#deal_close_date_e1","#deal_stage_id_e1","#deal_stage_name_e1","#deal_desc_e1","#deal_commission_e1","#deal_commission_amount_e1","#deal_stage_name1_e1","'+cid+'","'+divload+'")>';
        insert+='<span style="margin-left:50px;color:grey;cursor:pointer;" onclick=funappenddeal1("'+d_id+'","'+d_deal_name+'","'+d_date+'","'+d_c_by+'","'+d_amount+'","'+d_month+'","'+d_closedate+'","'+d_stage+'","'+d_descr+'","'+d_commission_percentage+'","'+d_commission_amount+'","'+cid+'","'+divload+'")>Cancel</span>';
        insert+='</span>';
        insert+='</span>'; 
                        
        insert+='</div>';
        insert+='<br>';    
        //alert(insert);
        //alert("showdiv:"+showdiv);
        $(divload).empty();
        $(divload).append(insert);
        var startdate=d_date;
        $("#"+deal_date_e1).datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true 
        }).datepicker('update', startdate); 
        var startdate1=d_closedate;
        $("#"+deal_close_date_e1).datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true 
        }).datepicker('update', startdate1); 
                
    }
</script>
<script>
    function dealupdatesubmit(did,deal_date, deal_by_id, deal_name, deal_amount, deal_month, deal_close_date, deal_stage_id, deal_stage_name, deal_desc, deal_commission, deal_commission_amount, deal_stage_name1, cid,divload){
        //alert("sd");
        var dealdate=$(deal_date).val();
        var dealby_id=$(deal_by_id).val();
        var dealname=$(deal_name).val();
        var dealamount=$(deal_amount).val();
        var dealmonth=$(deal_month).val();
        var dealclosedate=$(deal_close_date).val();
        var dealstageid=$(deal_stage_id).val();
        var dealstagename=$(deal_stage_name1).val();
        var dealdesc=$(deal_desc).val();
        var dealcommission=$(deal_commission).val();
        var dealcommissionamount=$(deal_commission_amount).val();
        /*alert("did:"+did);
        alert("dealby_id:"+dealby_id);
        alert("dealname:"+dealname);
        alert("dealamount:"+dealamount);
        alert("dealmonth:"+dealmonth);
        alert("dealclosedate:"+dealclosedate);
        alert("dealstageid:"+dealstageid);
        alert("dealstagename:"+dealstagename);
        alert("dealdesc:"+dealdesc);
        alert("dealcommission:"+dealcommission);
        alert("dealcommissionamount:"+dealcommissionamount);*/
                                    swal("Deal Updated Successfully","","success");
        $.ajax({
            url:"activestream_intermediate.php",
            type:"post",
            data:{updatedeal:did, dealname:dealname, dealdate:dealdate, dealby_id:dealby_id, dealamount:dealamount, dealmonth:dealmonth, dealclosedate:dealclosedate, dealstageid:dealstageid, dealdesc:dealdesc, dealcommission:dealcommission, dealcommissionamount:dealcommissionamount, contid:cid},
            success:function(respond){
                /*BootstrapAlert.success({
                  title: "Success!",
                  message: "Deal Updated Successfully"
                }); */
                funappenddeal1(did, dealname, dealdate, dealby_id, dealamount, dealmonth, dealclosedate, dealstageid, dealdesc, dealcommission, dealcommissionamount, cid, divload);
            }
        });
        
    }
</script>

<script>
    function funappenddeal1(d_id,dealname, dealdate, dealby_id, dealamount, dealmonth, dealclosedate, dealstageid, dealdesc, dealcommission, dealcommissionamount, cid, divload){
        //alert("divload:"+divload);
        //$(hidediv).hide();
        $(divload).empty();
        var adminemailid="<?php echo $adminemailid;?>";
        var emailid1=new Array();
        var employeename1=new Array();
        emailid1=<?php echo json_encode($emailid1);?>;
        employeename1=<?php echo json_encode($employeename1);?>;  
        var pipe_id=new Array();
        var pipe_percentage=new Array();
        var pipe_name=new Array();
        pipe_id=<?php echo json_encode($pipe_id);?>;
        pipe_percentage=<?php echo json_encode($pipe_percentage);?>;
        pipe_name=<?php echo json_encode($pipe_name);?>;
        var insert="";
        insert+='<div style="background-color:#f0f0f0; padding:6px;">';
        if(dealstageid=="Won"){
        insert+='<span style="color:#54b0fe;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-thumbs-up"></i></span>';
        insert+='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        insert+='<span style="color:#54b0fe;font-size:14px;font-size:12px;">Won Deal</span></b>';
                               
        insert+='<span style="cursor:pointer;" onclick=fundeletedeal("'+d_id+'","#dealeditid'+d_id+'")><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;';
        insert+='<span style="cursor:pointer;" onclick=funeditdeal("'+d_id+'","'+dealname+'","'+dealdate+'","'+dealby_id+'","'+dealamount+'","'+dealmonth+'","'+dealclosedate+'","'+dealstageid+'","'+dealdesc+'","'+dealcommission+'","'+dealcommissionamount+'","'+cid+'","'+divload+'")><i class="glyphicon glyphicon-pencil"></i></span>';
        insert+='<span class="pull-right" style="color:#777;">';
        
         if(adminemailid==dealby_id){
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(adminemailid==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+='Owned & created by '+empna+',';
        }else{
        insert+='Owned by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+=empna+'&nbsp;&nbsp;created by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna= employeename1[kk1]+",";
                }
            }
        insert+=empna+',&nbsp;';
        }
        //insert+=empna;
        
        var dateParts = dealdate.split('-');
        var y = parseInt(dateParts[0], 10);
        var m = parseInt(dateParts[1], 10);
        var d = parseInt(dateParts[2], 10);
        //var dayAfter = new Date(y, m-1, d+1);
        insert+=m+'&nbsp;&nbsp;';
        insert+=d+'&nbsp;&nbsp;';
        insert+=y+'&nbsp;&nbsp;';
        insert+='</span>';
        }else if(dealstageid=="Lost"){
        insert+='<b>';
        insert+='<span style="color:#666666;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-thumbs-down"></i></span>';
        insert+='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        insert+='<span style="color:#666666;font-size:14px;">Lost Deal</span></b>';
        
        insert+='<span style="cursor:pointer;" onclick=fundeletedeal("'+d_id+'","#dealeditid'+d_id+'")><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;';
        insert+='<span style="cursor:pointer;" onclick=funeditdeal("'+d_id+'","'+dealname+'","'+dealdate+'","'+dealby_id+'","'+dealamount+'","'+dealmonth+'","'+dealclosedate+'","'+dealstageid+'","'+dealdesc+'","'+dealcommission+'","'+dealcommissionamount+'","'+cid+'","'+divload+'")><i class="glyphicon glyphicon-pencil"></i></span>';
        insert+='<span class="pull-right" style="color:#777;font-size:12px;">';
        
         if(adminemailid==dealby_id){
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(adminemailid==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+='Owned & created by '+empna+',';
        }else{
        insert+='Owned by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+=empna+'&nbsp;&nbsp;created by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna= employeename1[kk1]+",";
                }
            }
        insert+=empna+',&nbsp;';
        }
        
        var dateParts = dealdate.split('-');
        var y = parseInt(dateParts[0], 10);
        var m = parseInt(dateParts[1], 10);
        var d = parseInt(dateParts[2], 10);
        //var dayAfter = new Date(y, m-1, d+1);
        insert+=m+'&nbsp;&nbsp;';
        insert+=d+'&nbsp;&nbsp;';
        insert+=y+'&nbsp;&nbsp;';
        insert+='</span>';
        }else{
        insert+='<b>';
        insert+='<span style="color:#db2b5d;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-time"></i></span>';
        insert+='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        insert+='<span style="color:#db2b5d;font-size:14px;">Pending Deal</span></b>';
        insert+='<span style="cursor:pointer;" onclick=fundeletedeal("'+d_id+'","#dealeditid'+d_id+'")><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;';
        insert+='<span style="cursor:pointer;" onclick=funeditdeal("'+d_id+'","'+dealname+'","'+dealdate+'","'+dealby_id+'","'+dealamount+'","'+dealmonth+'","'+dealclosedate+'","'+dealstageid+'","'+dealdesc+'","'+dealcommission+'","'+dealcommissionamount+'","'+cid+'","'+divload+'")><i class="glyphicon glyphicon-pencil"></i></span>';
        insert+='<span class="pull-right" style="color:#777;font-size:12px;">';
         if(adminemailid==dealby_id){
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(adminemailid==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+='Owned & created by '+empna+',';
        }else{
        insert+='Owned by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+=empna+'&nbsp;&nbsp;created by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna= employeename1[kk1]+",";
                }
            }
        insert+=empna+',&nbsp;';
        }
        var dateParts = dealdate.split('-');
        var y = parseInt(dateParts[0], 10);
        var m = parseInt(dateParts[1], 10);
        var d = parseInt(dateParts[2], 10);
        //var dayAfter = new Date(y, m-1, d+1);
        insert+=m+'&nbsp;&nbsp;';
        insert+=d+'&nbsp;&nbsp;';
        insert+=y+'&nbsp;&nbsp;';
        insert+='</span>';
        }
        insert+='</div>';
        insert+='<div style="background-color:#f8f8f8;padding:10px;">';
        insert+='<span style="margin-left:50px;">';
        insert+='<b>'+dealname+'</b>';
        insert+='</span>';
        insert+='<br>';
        
        if((dealstageid=="Won")||(dealstageid=="Lost")){
        insert+='<span style="margin-left:50px;">Rs&nbsp;<b>'+dealamount+'</b>';       
        insert+='<span class="dropdown">';
        if(dealstageid=="Won"){
        insert+='<input type="hidden" id="deal_stage_id_e'+d_id+'" value="Won">';
        insert+='<input type="hidden" id="deal_stage_name1_e'+d_id+'" value="Won">';
        insert+='<button class="btn btn-default dropdown-toggle" id="deal_stage_name_e'+d_id+'" type="button" data-toggle="dropdown" style="color:black;">Won';
        
        insert+='<span class="caret"></span></button>';
        }
        if(dealstageid=="Lost"){
        insert+='<input type="hidden" id="deal_stage_id_e'+d_id+'" value="Lost">';
        insert+='<input type="hidden" id="deal_stage_name1_e'+d_id+'" value="Lost">';
        insert+='<button class="btn btn-default dropdown-toggle" id="deal_stage_name_e'+d_id+'" type="button" data-toggle="dropdown" style="color:black;">Lost';
        insert+='<span class="caret"></span></button>';
        }
        insert+='<ul class="dropdown-menu" style="cursor:pointer;">';
        for(ff=0;ff<pipe_id.length;ff++){
        insert+='<li><a onclick=fundeal1("'+pipe_id[ff]+'","'+pipe_percentage[ff]+'","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")>'+pipe_percentage[ff]+'('+pipe_name[ff]+')</a></li>';
        }
        insert+='<li><a onclick=fundeal1("Won","Won","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")"><span style="color:#54b0fe;">Won</span></a></li>';
        insert+='<li><a onclick=fundeal1("Lost","Lost","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")"><span style="color:#54b0fe;">Lost</span></a></li>';
        insert+='</ul>';
        insert+='</span>';
        insert+='<span id="pendingshowdate'+d_id+'" style="display:none;">';
        insert+='&nbsp;&nbsp;&nbsp;chance it will close&nbsp;&nbsp;<input type="text" id="d_date_e'+d_id+'" readonly style="background-color:#f0f0f0;border:none;width:100px;" value="'+dealclosedate+'" onchange=funupdateclosedate1("#d_date_e'+d_id+'","'+d_id+'","'+dealclosedate+'")>';
        insert+='</span>';
        insert+='</span>';
        }else{
        insert+='<span style="margin-left:50px;"><span style="color:#db2b5d;">Rs&nbsp;<b>'+dealamount+'</b></span>';
        for(ff1=0;ff1<pipe_id.length;ff1++){
        pipe_id121=pipe_id[ff1];
        if(pipe_id121==dealstageid){
        pipename=pipe_percentage[ff1];
        }
        }
        insert+='<span class="dropdown">';
        insert+='<input type="hidden" id="deal_stage_id_e'+d_id+'" value="'+dealstageid+'">';
        insert+='<input type="hidden" id="deal_stage_name1_e'+d_id+'" value="'+pipename+'">';
        insert+='<button class="btn btn-default dropdown-toggle" id="deal_stage_name_e'+d_id+'" type="button" data-toggle="dropdown" style="color:black;">'+pipename;
        insert+='<span class="caret"></span></button>'; 
        
        insert+='<ul class="dropdown-menu" style="cursor:pointer;">';
        for(ff=0;ff<pipe_id.length;ff++){
        insert+='<li><a onclick=fundeal1("'+pipe_id[ff]+'","'+pipe_percentage[ff]+'","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")>'+pipe_percentage[ff]+'('+pipe_name[ff]+')</a></li>';
        }
        
        insert+='<li><a onclick=fundeal1("Won","Won","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")><span style="color:#54b0fe;">Won</span></a></li>';
        insert+='<li><a onclick=fundeal1("Lost","Lost","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")><span style="color:#54b0fe;">Lost</span></a></li>';
        insert+='</ul>';
        insert+='</span>';
        insert+='<span id="pendingshowdate'+d_id+'">';
        insert+='&nbsp;&nbsp;&nbsp;chance it will close&nbsp;&nbsp;<input type="text" id="d_date_e'+d_id+'" style="background-color:#f0f0f0;border:none;width:100px;" value="'+dealclosedate+'" onchange=funupdateclosedate1("#d_date_e'+d_id+'","'+d_id+'","'+dealclosedate+'") readonly>';
        insert+='</span>';
        insert+='</span>';
        }
        insert+='<br>';
        insert+='<span style="margin-left:50px;">';
        insert+='<span style="font-family:Open Sans, Arial, Helvetica, sans-serif;font-size: 12px;color: #999;margin-top: 2px;margin-bottom: 4px;">';
        insert+='<h5 style="margin-left:50px;">Note</h5>';
        insert+='<span style="margin-left:50px;white-space: normal;text-overflow: ellipsis;overflow: hidden;width:90%;color:black;">'+dealdesc+'</span>';
        insert+='</span>';
        insert+='</span>';
        insert+='<br>';
                            
        insert+='</div>';
        //alert(insert);
        $(divload).append(insert);
        
        var id="#d_date_e"+d_id;
        var startdate=dealclosedate;
        $(id).datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true 
        }).datepicker('update', startdate); 
    }
</script>  
<script>
    function calcamoutformonth(damount, dmonth, damount1, totalamount, dealcommision, dealcommissionamount, showcommision){
        //alert("jhk");
        var amt=$(damount).val();
        var mth=$(dmonth).val();
        var cmp=$(dealcommision).val();
        var tot=amt*mth;
        $(damount1).val(tot);
        $(totalamount).html(tot);
        if((cmp==0)||(cmp=="")){
            var commision=0;
        }else{
            var commision=amt*(cmp/100)*mth;
        }
        $(dealcommissionamount).val(commision);
        $(showcommision).html(commision);
    }
</script>
<script>
    function fundeletedeal(dealid, hideid){
        swal("Deal Deleted Successfully","","success");
        $.ajax({
            url:"activestream_intermediate.php",
            type:"post",
            data:{deletedeal:dealid},
            success:function(respond){
                /*BootstrapAlert.success({
                  title: "Success!",
                  message: "Deal Deleted Successfully"
                }); */
                $(hideid).hide();
            }
        });
    }
</script>
<script>
    function funupdateclosedate(date1, dealid){
        var closedate=$(date1).val();
        //alert(closedate);
        //alert(id);
        swal("Deal Close Date Updated Successfully","","success");
        $.ajax({
            url:"activestream_intermediate.php",
            type:"post",
            data:{updatedealclosedate:closedate, dealstageid:dealid},
            success:function(respond){
                /*BootstrapAlert.success({
                  title: "Success!",
                  message: "Deal Close Date Upadted Successfully"
                }); */
                
            }
        });
    }
</script>
<script>
    function funupdateclosedate1(date1, dealid, orgdate1){
        var closedate=$(date1).val();
        //alert(closedate);
        //alert(id);
        if(orgdate1!=closedate){
        swal("Deal Close Date Updated Successfully","","success");
        $.ajax({
            url:"activestream_intermediate.php",
            type:"post",
            data:{updatedealclosedate:closedate, dealstageid:dealid},
            success:function(respond){
                /*BootstrapAlert.success({
                  title: "Success!",
                  message: "Deal Close Date Upadted Successfully"
                }); */
                
            }
        });
        }
    }
</script>
<script>
    
function fundeal1(id, name, sid, sname, sname1, hidewon, dealid){
    //alert(id);
    document.getElementById(sid).value=id;
    document.getElementById(sname1).value=name;
    document.getElementById(sname).innerText=name;
    if((name=="Won")||(name=="Lose")){
        $(hidewon).hide();
    }else{
        $(hidewon).show();
    }
        swal("Deal Stage Updated Successfully","","success");
        $.ajax({
            url:"activestream_intermediate.php",
            type:"post",
            data:{updatedealstage:id, dealstageid:dealid},
            success:function(respond){
                /*BootstrapAlert.success({
                  title: "Success!",
                  message: "Deal Stage Updated Successfully"
                }); */
            }
        });
}
</script>
<script>
    function dealinsertsubmit(deal_date, deal_by_id, deal_name, deal_amount, deal_month, deal_close_date, deal_stage_id, deal_stage_name, deal_desc, deal_commission, deal_commission_amount, deal_stage_name1, cid){
        var dealdate=$(deal_date).val();
        var dealby_id=$(deal_by_id).val();
        var dealname=$(deal_name).val();
        if(dealname==""){
            swal("", "Fill the deal Name", "warning");
            return;
        }
        var dealamount=$(deal_amount).val();
        if(dealamount==""){
            swal("", "Fill the Deal Amount", "warning");
            return;
        }
        var dealmonth=$(deal_month).val();
        var dealclosedate=$(deal_close_date).val();
        var dealstageid=$(deal_stage_id).val();
        var dealstagename=$(deal_stage_name1).val();
        var dealdesc=$(deal_desc).val();
        var dealcommission=$(deal_commission).val();
        var dealcommissionamount=$(deal_commission_amount).val();
        swal("Deal Created Successfully","","success");
        $.ajax({
            url:"activestream_intermediate.php",
            type:"post",
            data:{insertdeal:dealname, dealdate:dealdate, dealby_id:dealby_id, dealamount:dealamount, dealmonth:dealmonth, dealclosedate:dealclosedate, dealstageid:dealstageid, dealdesc:dealdesc, dealcommission:dealcommission, dealcommissionamount:dealcommissionamount, contid:cid},
            success:function(respond){
                var cccc=respond.trim();
                /*BootstrapAlert.success({
                  title: "Success!",
                  message: "Deal Created Successfully"
                }); */
                $(deal_by_id).val("");
                $(deal_name).val("");
                $(deal_amount).val(0);
                $(deal_month).val(1);
                $(deal_desc).val("");
                $(deal_commission).val(0);
                $(deal_commission_amount).val(0);
                $("#adddealbutton").attr("disabled", false);
                funappenddeal(cccc, dealname, dealdate, dealby_id, dealamount, dealmonth, dealclosedate, dealstageid, dealdesc, dealcommission, dealcommissionamount, cid, "#adddeal");
            }
        });
        
    }
</script>
<script>
    function funappenddeal(d_id,dealname, dealdate, dealby_id, dealamount, dealmonth, dealclosedate, dealstageid, dealdesc, dealcommission, dealcommissionamount, cid, hidediv){
        $(hidediv).hide()
        var adminemailid="<?php echo $adminemailid;?>";
        var emailid1=new Array();
        var employeename1=new Array();
        emailid1=<?php echo json_encode($emailid1);?>;
        employeename1=<?php echo json_encode($employeename1);?>;  
        var pipe_id=new Array();
        var pipe_percentage=new Array();
        var pipe_name=new Array();
        pipe_id=<?php echo json_encode($pipe_id);?>;
        pipe_percentage=<?php echo json_encode($pipe_percentage);?>;
        pipe_name=<?php echo json_encode($pipe_name);?>;
        var insert="";
        insert+='<span id="dealeditid'+d_id+'">';
        insert+='<div style="background-color:#f0f0f0; padding:6px;">';
        if(dealstageid=="Won"){
        insert+='<span style="color:#54b0fe;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-thumbs-up"></i></span>';
        insert+='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        insert+='<span style="color:#54b0fe;font-size:14px;font-size:12px;">Won Deal</span></b>';
                               
        insert+='<span style="cursor:pointer;" onclick=fundeletedeal("'+d_id+',"#dealeditid'+d_id+'")><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;';
        insert+='<span style="cursor:pointer;" onclick=funeditdeal("'+d_id+'","'+dealname+'","'+dealdate+'","'+dealby_id+'","'+dealamount+'","'+dealmonth+'","'+dealclosedate+'","'+dealstageid+'","'+dealdesc+'","'+dealcommission+'","'+dealcommissionamount+'","'+cid+'","#dealeditid'+d_id+'")><i class="glyphicon glyphicon-pencil"></i></span>';
        insert+='<span class="pull-right" style="color:#777;">';
        
         if(adminemailid==dealby_id){
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(adminemailid==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+='Owned & created by '+empna+',';
        }else{
        insert+='Owned by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+=empna+'&nbsp;&nbsp;created by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna= employeename1[kk1]+",";
                }
            }
        insert+=empna+',&nbsp;';
        }
        //insert+=empna;
        
        var dateParts = dealdate.split('-');
        var y = parseInt(dateParts[0], 10);
        var m = parseInt(dateParts[1], 10);
        var d = parseInt(dateParts[2], 10);
        //var dayAfter = new Date(y, m-1, d+1);
        insert+=m+'&nbsp;&nbsp;';
        insert+=d+'&nbsp;&nbsp;';
        insert+=y+'&nbsp;&nbsp;';
        insert+='</span>';
        }else if(dealstageid=="Lost"){
        insert+='<b>';
        insert+='<span style="color:#666666;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-thumbs-down"></i></span>';
        insert+='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        insert+='<span style="color:#666666;font-size:14px;">Lost Deal</span></b>';
        
        insert+='<span style="cursor:pointer;" onclick=fundeletedeal("'+d_id+'","#dealeditid'+d_id+'")><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;';
        insert+='<span style="cursor:pointer;" onclick=funeditdeal("'+d_id+'","'+dealname+'","'+dealdate+'","'+dealby_id+'","'+dealamount+'","'+dealmonth+'","'+dealclosedate+'","'+dealstageid+'","'+dealdesc+'","'+dealcommission+'","'+dealcommissionamount+'","'+cid+'","#dealeditid'+d_id+'")><i class="glyphicon glyphicon-pencil"></i></span>';
        insert+='<span class="pull-right" style="color:#777;font-size:12px;">';
        
         if(adminemailid==dealby_id){
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(adminemailid==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+='Owned & created by '+empna+',';
        }else{
        insert+='Owned by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+=empna+'&nbsp;&nbsp;created by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna= employeename1[kk1]+",";
                }
            }
        insert+=empna+',&nbsp;';
        }
        
        var dateParts = dealdate.split('-');
        var y = parseInt(dateParts[0], 10);
        var m = parseInt(dateParts[1], 10);
        var d = parseInt(dateParts[2], 10);
        //var dayAfter = new Date(y, m-1, d+1);
        insert+=m+'&nbsp;&nbsp;';
        insert+=d+'&nbsp;&nbsp;';
        insert+=y+'&nbsp;&nbsp;';
        insert+='</span>';
        }else{
        insert+='<b>';
        insert+='<span style="color:#db2b5d;font-size:14px;margin-left:10px;"><i class="glyphicon glyphicon-time"></i></span>';
        insert+='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        insert+='<span style="color:#db2b5d;font-size:14px;">Pending Deal</span></b>';
        insert+='<span style="cursor:pointer;" onclick=fundeletedeal("'+d_id+'","#dealeditid'+d_id+'")><i class="glyphicon glyphicon-trash"></i></span>&nbsp;&nbsp;';
        insert+='<span style="cursor:pointer;" onclick=funeditdeal("'+d_id+'","'+dealname+'","'+dealdate+'","'+dealby_id+'","'+dealamount+'","'+dealmonth+'","'+dealclosedate+'","'+dealstageid+'","'+dealdesc+'","'+dealcommission+'","'+dealcommissionamount+'","'+cid+'","#dealeditid'+d_id+'")><i class="glyphicon glyphicon-pencil"></i></span>';
        insert+='<span class="pull-right" style="color:#777;font-size:12px;">';
         if(adminemailid==dealby_id){
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(adminemailid==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+='Owned & created by '+empna+',';
        }else{
        insert+='Owned by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna=employeename1[kk1];
                }
            }
        insert+=empna+'&nbsp;&nbsp;created by &nbsp;&nbsp;';
            for(kk1=0;kk1<emailid1.length;kk1++){
                emailid11=emailid1[kk1];
                if(dealby_id==emailid11){
                empna= employeename1[kk1]+",";
                }
            }
        insert+=empna+',&nbsp;';
        }
        var dateParts = dealdate.split('-');
        var y = parseInt(dateParts[0], 10);
        var m = parseInt(dateParts[1], 10);
        var d = parseInt(dateParts[2], 10);
        //var dayAfter = new Date(y, m-1, d+1);
        insert+=m+'&nbsp;&nbsp;';
        insert+=d+'&nbsp;&nbsp;';
        insert+=y+'&nbsp;&nbsp;';
        insert+='</span>';
        }
        insert+='</div>';
        insert+='<div style="background-color:#f8f8f8;padding:10px;">';
        insert+='<span style="margin-left:50px;">';
        insert+='<b>'+dealname+'</b>';
        insert+='</span>';
        insert+='<br>';
        
        if((dealstageid=="Won")||(dealstageid=="Lost")){
        insert+='<span style="margin-left:50px;">Rs&nbsp;<b>'+dealamount+'</b>';       
        insert+='<span class="dropdown">';
        if(dealstageid=="Won"){
        insert+='<input type="hidden" id="deal_stage_id_e'+d_id+'" value="Won">';
        insert+='<input type="hidden" id="deal_stage_name1_e'+d_id+'" value="Won">';
        insert+='<button class="btn btn-default dropdown-toggle" id="deal_stage_name_e'+d_id+'" type="button" data-toggle="dropdown" style="color:black;">Won';
        
        insert+='<span class="caret"></span></button>';
        }
        if(dealstageid=="Lost"){
        insert+='<input type="hidden" id="deal_stage_id_e'+d_id+'" value="Lost">';
        insert+='<input type="hidden" id="deal_stage_name1_e'+d_id+'" value="Lost">';
        insert+='<button class="btn btn-default dropdown-toggle" id="deal_stage_name_e'+d_id+'" type="button" data-toggle="dropdown" style="color:black;">Lost';
        insert+='<span class="caret"></span></button>';
        }
        insert+='<ul class="dropdown-menu" style="cursor:pointer;">';
        for(ff=0;ff<pipe_id.length;ff++){
        insert+='<li><a onclick=fundeal1("'+pipe_id[ff]+'","'+pipe_percentage[ff]+'","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")>'+pipe_percentage[ff]+'('+pipe_name[ff]+')</a></li>';
        }
        insert+='<li><a onclick=fundeal1("Won","Won","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")"><span style="color:#54b0fe;">Won</span></a></li>';
        insert+='<li><a onclick=fundeal1("Lost","Lost","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")"><span style="color:#54b0fe;">Lost</span></a></li>';
        insert+='</ul>';
        insert+='</span>';
        insert+='<span id="pendingshowdate'+d_id+'" style="display:none;">';
        insert+='&nbsp;&nbsp;&nbsp;chance it will close&nbsp;&nbsp;<input type="text" id="d_date_e'+d_id+'" readonly style="background-color:#f0f0f0;border:none;width:100px;" value="'+dealclosedate+'" onchange=funupdateclosedate("#d_date_e'+d_id+'", "'+d_id+'")">';
        insert+='</span>';
        insert+='</span>';
        }else{
        insert+='<span style="margin-left:50px;"><span style="color:#db2b5d;">Rs&nbsp;<b>'+dealamount+'</b></span>';
        for(ff1=0;ff1<pipe_id.length;ff1++){
        pipe_id121=pipe_id[ff1];
        if(pipe_id121==dealstageid){
        pipename=pipe_percentage[ff1];
        }
        }
        insert+='<span class="dropdown">';
        insert+='<input type="hidden" id="deal_stage_id_e'+d_id+'" value="'+dealstageid+'">';
        insert+='<input type="hidden" id="deal_stage_name1_e'+d_id+'" value="'+pipename+'">';
        insert+='<button class="btn btn-default dropdown-toggle" id="deal_stage_name_e'+d_id+'" type="button" data-toggle="dropdown" style="color:black;">'+pipename;
        insert+='<span class="caret"></span></button>'; 
        
        insert+='<ul class="dropdown-menu" style="cursor:pointer;">';
        for(ff=0;ff<pipe_id.length;ff++){
        insert+='<li><a onclick=fundeal1("'+pipe_id[ff]+'","'+pipe_percentage[ff]+'","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")>'+pipe_percentage[ff]+'('+pipe_name[ff]+')</a></li>';
        }
        
        insert+='<li><a onclick=fundeal1("Won","Won","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")><span style="color:#54b0fe;">Won</span></a></li>';
        insert+='<li><a onclick=fundeal1("Lost","Lost","deal_stage_id_e'+d_id+'","deal_stage_name_e'+d_id+'","deal_stage_name1_e'+d_id+'","#pendingshowdate'+d_id+'","'+d_id+'")><span style="color:#54b0fe;">Lost</span></a></li>';
        insert+='</ul>';
        insert+='</span>';
        insert+='<span id="pendingshowdate'+d_id+'">';
        insert+='&nbsp;&nbsp;&nbsp;chance it will close&nbsp;&nbsp;<input type="text" id="d_date_e'+d_id+'" style="background-color:#f0f0f0;border:none;width:100px;" value="'+dealclosedate+'" onchange=funupdateclosedate("#d_date_e'+d_id+'","'+d_id+'") readonly>';
        insert+='</span>';
        insert+='</span>';
        }
        insert+='<br>';
        insert+='<span style="margin-left:50px;">';
        insert+='<span style="font-family:Open Sans, Arial, Helvetica, sans-serif;font-size: 12px;color: #999;margin-top: 2px;margin-bottom: 4px;">';
        insert+='<h5 style="margin-left:50px;">Note</h5>';
        insert+='<span style="margin-left:50px;white-space: normal;text-overflow: ellipsis;overflow: hidden;width:90%;color:black;">'+dealdesc+'</span>';
        insert+='</span>';
        insert+='</span>';
        insert+='<br>';
                            
        insert+='</div>';
        insert+='</span>';
        //alert(insert);
        $("#adddealview").append(insert);
        
        var id="#d_date_e"+d_id;
        var startdate=dealclosedate;
        $(id).datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true 
        }).datepicker('update', startdate); 
    }
</script>                        
                        
<script>
                            

                            

function fundeal(id, name, sid, sname, id1, id2, sname1){
    document.getElementById(sid).value=id;
    document.getElementById(sname1).value=name;
    document.getElementById(sname).innerText=name;
    document.getElementById(sname).style.backgroundColor = "#DA1A55";
    document.getElementById(sname).style.color = "white";
    document.getElementById(id1).style.backgroundColor = "#e9e9e9";
    document.getElementById(id1).style.color = "black";
    document.getElementById(id2).style.backgroundColor = "#e9e9e9";
    document.getElementById(id2).style.color = "black";
}


function fundealwon(name, sid, id, id1, id2, sname1){
    document.getElementById(sid).value=name;
    document.getElementById(sname1).value=name;
    document.getElementById(id).style.backgroundColor = "#45a2ec";
    document.getElementById(id).style.color = "white";
    document.getElementById(id1).style.backgroundColor = "#e9e9e9";
    //document.getElementById(id1).style.borderStyle = "1px sloid grey";
    document.getElementById(id2).style.backgroundColor = "#e9e9e9";
    document.getElementById(id1).style.color = "#343333";
    document.getElementById(id2).style.color = "#343333";
}

function fundealLost(name, sid, id, id1, id2, sname1){
    document.getElementById(sid).value=name;
    document.getElementById(sname1).value=name;
    document.getElementById(id).style.backgroundColor = "#707680";
    document.getElementById(id).style.color = "white";
    document.getElementById(id1).style.backgroundColor = "#e9e9e9";
    document.getElementById(id2).style.backgroundColor = "#e9e9e9";
    document.getElementById(id1).style.color = "#343333";
    document.getElementById(id2).style.color = "#343333";
}
</script>

<script>
    
    $(document).ready(function(){
        $("#deal_date").datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true, 
            todayHighlight: true
        }).datepicker('update', new Date()); 
        $("#call_date").datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true, 
            todayHighlight: true
        }).datepicker('update', new Date()); 
        $("#note_date").datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true, 
            todayHighlight: true
        }).datepicker('update', new Date()); 
    });
    
    
    $(document).ready(function(){
        $("#deal_close_date").datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true, 
            todayHighlight: true
        }).datepicker('update', new Date()); 
        
        
        $("#call_time").clockpicker({
            placement: 'bottom',
            align: 'left',
            autoclose: true,
            'default': 'now'
        });
    });
</script>
    <style>
        .modal-open .modal {
            display: flex !important;
            align-items: center;
            justify-content: center;
        }
    </style>           
<script>
    function showdetails(id1, id2, id3){
           $("#"+id1).hide();
           $("#"+id2).show();
           $("#"+id3).show();
        }
        function hidedetails(id1, id2, id3){
           $("#"+id2).hide();
           $("#"+id1).show();
           $("#"+id3).hide();
        }
</script> 
                
<script>
    function declaredatepicker(dateselect, date, time1, 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);
            
    }

</script>               

                <script>
                    function funsignup(id, name, cid){
                        document.getElementById("b3").innerText=name;
                        document.getElementById("b4").value=id;
                        
                        swal("Next Action assign updated Successfully","","success");
                        $.ajax({
                           url:"activestream_intermediate.php",
                           type:"post",
                           data:{cont_id:cid, updatesignup:id},
                           success:function(respond){
                               /*
                                BootstrapAlert.success({
                                  title: "Success!",
                                  message: "Next Action assign updated Successfully"
                                }); */
                               document.getElementById("b3").innerText=name;
                               document.getElementById("b4").value=id;
                           }
                        });
                    }
                    function funstatus(id, name, cid){
                        document.getElementById("b1").innerText=name;
                        swal("Next Action status updated Successfully","","success");
                        $.ajax({
                           url:"activestream_intermediate.php",
                           type:"post",
                           data:{cont_id:cid, updatestatus:id},
                           success:function(respond){
                                /*BootstrapAlert.success({
                                  title: "Success!",
                                  message: "Next Action status Updated Successfully"
                                }); */
                               document.getElementById("b1").innerText=name;
                           }
                        });
                    }
                    function funtag(id, name, cid){
                        document.getElementById("b2").innerText=name;
                        swal("Next Action tag updated Successfully","","success");
                        $.ajax({
                           url:"activestream_intermediate.php",
                           type:"post",
                           data:{cont_id:cid, updatetag:id},
                           success:function(respond){
                                /*BootstrapAlert.success({
                                  title: "Success!",
                                  message: "Next Action tag Updated Successfully"
                                }); */
                               document.getElementById("b2").innerText=name;
                           }
                        });
                    }
                </script>    
    

<script>
    function callpicker(id, id1){
        $(id).datepicker({ 
            format : "yyyy-mm-dd",
            autoclose: true, 
            todayHighlight: true
        });
        $(id1).clockpicker({
            placement: 'bottom',
            align: 'left',
            autoclose: true
        });
	}
</script>   
    <span id="activityview"></span>
                    <script>
                        $(document).ready(function(){
                           var cid="<?php echo $cid;?>";
                           //alert(cid);
                           $.ajax({
                                url:"employee_activity_individual.php",
                                type:"post",
                                data:{cid:cid},
                                success:function(respond){
                                    //alert(respond);
                                    $("#activityview").html(respond);
                                }
                            });
                        });
                    </script>     
                    
                <script>
                    //$(document).on("change", "#file-input", function(){
                    function functionupload(input){
                        
                        if (input.files && input.files[0]) {
                            var reader = new FileReader();
            
                            reader.onload = function (e) {
                                $('#contactphoto')
                                    .attr('src', e.target.result)
                                    .width(150)
                                    .height(200);
                            };
            
                            reader.readAsDataURL(input.files[0]);
                        }
                        var cont_id="<?php echo $c_id;?>";
                        var fileUpload = $("#file-input").get(0);
                        var files = fileUpload.files;
                        if (files.length == 0) {
                            swal("", "Please Choose the Contact Logo", "warning");
                            return;
                        }
                        var formData = new FormData();
                        filesd = document.getElementById("file-input").files[0];
                        formData.append("updatephoto","filesd");
                        formData.append("files",filesd);
                        formData.append("cont_id",cont_id);
                        $.ajax({
                            url : "../Control/contact.php",
                            type: 'POST',
                            data : formData,
                            cache       : false,
                            contentType : false,
                            processData : false,
                            success:function(data)
                            {
                                //window.location.replace("college_register.php");
                                swal("","Photo uploaded Successfully", "success");
                            },
                            error: function(xhr) {
                                swal("","Photo uploaded Unsuccessfully", "error");
                                //alert('Error!  Status = ' + xhr.status + " Message = " + xhr.statusText);
                                //console.log('Error!  Status = ' + xhr.status + " Message = " +  xhr.statusText);
                            }
                        });
                    }
                    //});
                </script>
                  
<?php
}else{
echo "<script> location.replace('http://fieldcloud.in/Login.php') </script>";
}?>       