<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
include('../includes/header_in.php');

$BID =isset($_GET['BID'])?$_GET['BID']:0;
 $cid  = $_SESSION['id'];
 $scope ='specs-brief';
 
 
   $result = mysql_query("SELECT specs.*,projects.projectName,client.clientName FROM projects,client,specs where specs.companyID='$id' AND specs.SPECID='$BID' AND specs.spec_status='1' AND projects.projectSerial=specs.spec_project AND client.clientSerial=specs.spec_client ");
   		$row = mysql_fetch_array($result , MYSQL_ASSOC);  		
			$PreparedBy = "";
  		 if($row["PreparedBy"]==$row["companyID"]){
			$resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='".$row["spec_preparedby"]."'"); 
			$PreparedBy .= mysql_result($resultPre,0,0);
			$PreparedBy .=" ". mysql_result($resultPre,0,1);
		 }
		 else{
			 $resultPre = mysql_query("SELECT internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_id='".$row["spec_preparedby"]."'"); 
			 $PreparedBy .= mysql_result($resultPre,0,0);
			 $PreparedBy .=" ". mysql_result($resultPre,0,1);
		 }	
          
?>
<style>
    .editfield{display:none}
    .pheadin-txt .panel-numbering,.pheadin-txt .htitle {font-size:14px; font-weight:bold}
        .whead{    padding: 4px 0 8px 0;}
        .panel-edit a{margin-right:7px}
     .panel-edit span{margin-left:7px}
      .panel-edit{text-align:right}
      .panel-detail{padding:0 !important}
      .update_alert{width:30% !important; margin:0 auto 2px auto !important; padding:3px !important; text-align:center }
.panel-edit .glyph{float:right}
    .delhead{float:right}
    .delhead .fa{color:#900; font-size:16px;padding-right:0px !important}
    .delhead{margin: 0 0 0 10px !important}
</style>
<section class="content">
    <div class="container">
        <div class="row">
            <div class="main-content">
                <h5>
                    <?php if (isset($_REQUEST["msg"])) { ?>
                    <?php echo $_REQUEST["msg"]; ?>
                    <?php } ?>
                </h5>
                
                
                <div class="widget">
 <div class="whead"> <h6> <i class="fa fa-play-circle"></i>  Specs Scope </h6>   </div>

                    <form enctype="multipart/form-data" style="overflow:hidden">

                        <div class="formRow fRow">
                              <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Project Name:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
<?php echo $row["projectName"]; ?>
                                 </div>

                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Prepared By:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
<?php echo $PreparedBy; ?>
                                 </div>
                             <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Spec Name:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
<?php echo $row["title"]; ?>
                                 </div>

                        </div>
                        
                        <div class="formRow fRow">
                              <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Spec Code:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">

                                 </div>

                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Client Name:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
<?php echo $row["clientName"]; ?>
                                 </div>
                             <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Date prepared:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
<?php echo $row["dateCreated"]; ?>
                                 </div>

                        </div>
                    </form>

                </div>
                
                
  <div class="widget">
 <div class="whead"> <h6> <i class="fa fa-play-circle"></i>General</h6>   </div>
  <div class="formRow fRow" style="padding:21px 0 !important">
 <div class="col-md-12">
     <div class="col-md-12">
          
             <div class="newheading" id="gnewheading" >
                 <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left">New Heading</div>
               <form id="gnewheadingform" method="post" action="">
                 <div class="col-md-10 com-sm-8">
                     <input type="text" name="nheading" value="" /></div>
                  <input type="hidden" name="scopename" value="<?php echo $scope?>">
                  <input type="hidden" name="brieftype" value="General">
                   <input type="hidden" name="task" value="newheading">
                  <input type="hidden" name="brief_id" value="<?php echo $BID?>">
                  
                 </form>
                  <div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="#" onclick="savegnewheading()"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a></div>
             </div>
         </div>
 </div>
      </div>
 <?php $query ="SELECT * from scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type ='General'";  
 $result = mysql_query($query);
$i=1.1;
 ?>
 <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {?>
 <div class="formRow fRow">
     
     <div class="col-md-12 panel-detail">
         <div class="col-md-12">
             <div class="pheadin-txt" id="pheading-<?php echo $row['id'] ?>" >
                 <div class=" alert-success update_alert" id="alert-<?php echo $row['id'] ?>"> </div>

             <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left"><?php echo $i?></div>
             <div class="col-md-10 com-sm-8 htitle" id="headingf-<?php echo $row['id']?>"><?php echo $row['heading']?> </div>
             <?php if($row['company_id'] == $cid) {?>
             <div class="col-md-1 col-sm-2  panel-edit" style="float:right; cursor:pointer">
               <a class="delhead" href="javascript:void(0)" onclick="deleteHeading('<?php echo $row["id"]; ?>')">
                                                          <i class="fa fa-times" title="Delete"></i>
                                                        </a> 
                 <div class="glyph"  onclick="openedit('heading','<?php echo  $row['id'];?>')">
                                                        <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                    </div> 
             </div>
             <?php } ?>
             </div>
               <?php if($row['company_id'] == $cid) {?>
             <div class="editfield" id="peditheading-<?php echo $row['id']; ?>" >
                <form action="" method="post" id="formforheading-<?php  echo $row['id']?>">
                 <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left"><?php echo $k?></div>
                 <div class="col-md-10 com-sm-8"><input type="text" required name="headingtext" value="<?php echo $row['heading']?>" /></div>
                <input type="hidden" name="task" value="editheading"> 
                <input type="hidden" name="headingid" value="<?php echo $row['id']?>">
                </form>
                  <div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="javascript:void(0)" onclick="submitheadingform('<?php echo $row['id']?>')"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a>|<span onclick="closeedit('heading','<?php echo $row['id']?>')" style="cursor:pointer"><img src="../images/icon-del1.png" width="10" height="10" border="0"></span></div>
             </div>
               <?php }?>
         </div>
        
          <?php $query2 ="SELECT * from scope_brief_description WHERE `heading_id` = '".$row['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid'";  
             $results = mysql_query($query2);
             $row2 = mysql_fetch_object($results);
           
             ?> 
           <div class="col-md-12">
            <div id="ptext-<?php echo $row['id']; ?>" >
                
             <div class="col-md-1 col-sm-2 panel-numbering" style="padding:0 3px;float:left">&nbsp;</div> 
             <div class="col-md-10 com-sm-8 "  id="btextf-<?php echo $row['id'] ?>"><?php echo @$row2->description ?> </div>
             
             <div  class="col-md-1 col-sm2 panel-edit" style="float:right; cursor:pointer" onclick="openedit('text','<?php echo $row['id'] ?>')">
              <div class="glyph">
                                                        <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                    </div> 
             </div>
             </div>
             <div class="editfield" id="pedittext-<?php echo $row['id']; ?>" >
             <div class="col-md-1 col-sm-2 panel-numbering" style="padding:0 3px;float:left">&nbsp;</div> 
             <form method="post" action="" id="submittextfor-<?php echo $row['id']; ?>">
                 <div class="col-md-10 com-sm-8"><textarea name="btext" required class="ckeditor" id="btext-<?php echo $row['id']?>"> <?php echo @$row2->description ?></textarea></div>
                 <input type="hidden" name="bdescid" value="<?php echo @$row2->id?>">
                  <input type="hidden" name="headingid" value="<?php echo $row['id']?>">
                  
                  <input type="hidden" name="scopename" value="<?php echo $scope?>">
                  <input type="hidden" name="task" value="changedesc">
                  <input type="hidden" name="brief_id" value="<?php echo $BID?>">
                   </form>  
                  <div class="col-md-1 col-sm2 panel-edit" style="float:right"><a style="cursor:pointer" href="#" onclick="submittextform('<?php echo $row['id']?>')"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a>|<span onclick="closeedit('text','<?php echo $row['id'] ?>')" style="cursor:pointer"><img src="../images/icon-del1.png" width="10" height="10" border="0"></span></div>
             </div>
         </div>
     </div>
     
 </div>
 
 <?php $i=$i+0.1; } ?>
 
 </div>
                
         <div class="widget">
 <div class="whead"> <h6> <i class="fa fa-play-circle"></i>Products </h6>   </div>
  <div class="formRow fRow" style="padding:21px 0 !important">
 <div class="col-md-12">
     <div class="col-md-12">
          
             <div class="newheading" id="pnewheading" >
                 <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left">New Heading</div>
               <form id="pnewheadingform" method="post" action="">
                 <div class="col-md-10 com-sm-8">
                     <input type="text" name="nheading" value="" /></div>
                  <input type="hidden" name="scopename" value="<?php echo $scope?>">
                   <input type="hidden" name="brieftype" value="Products">
                   <input type="hidden" name="task" value="newheading">
                  <input type="hidden" name="brief_id" value="<?php echo $BID?>">
                  
                 </form>
                  <div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="#" onclick="savepnewheading()"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a></div>
             </div>
         </div>
 </div>
      </div>
 <?php $query ="SELECT * from scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type='Products'";  
 $result = mysql_query($query);
$i = 2.1;
 ?>
 <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {?>
 <div class="formRow fRow">
     
     <div class="col-md-12 panel-detail">
         <div class="col-md-12">
             <div class="pheadin-txt" id="pheading-<?php echo $row['id'] ?>" >
                 <div class=" alert-success update_alert" id="alert-<?php echo $row['id'] ?>"> </div>
             <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left"><?php echo $i?></div>
             <div class="col-md-10 com-sm-8 htitle" id="headingf-<?php echo $row['id']?>"><?php echo $row['heading']?> </div>
             <?php if($row['company_id'] == $cid) {?>
             <div class="col-md-1 col-sm-2  panel-edit" style="float:right; cursor:pointer">
               <a class="delhead" href="javascript:void(0)" onclick="deleteHeading('<?php echo $row["id"]; ?>')">
                                                          <i class="fa fa-times" title="Delete"></i>
                                                        </a> 
                 <div class="glyph"  onclick="openedit('heading','<?php echo  $row['id'];?>')">
                                                        <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                    </div> 
             </div>
             <?php } ?>
             </div>
               <?php if($row['company_id'] == $cid) {?>
            <div class="editfield" id="peditheading-<?php echo $row['id']; ?>" >
                <form action="" method="post" id="formforheading-<?php  echo $row['id']?>">
                 <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left"><?php echo $k?></div>
                 <div class="col-md-10 com-sm-8" ><input type="text" required name="headingtext" value="<?php echo $row['heading']?>" /></div>
                <input type="hidden" name="task" value="editheading"> 
                <input type="hidden" name="headingid" value="<?php echo $row['id']?>">
                </form>
                  <div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="javascript:void(0)" onclick="submitheadingform('<?php echo $row['id']?>')"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a>|<span onclick="closeedit('heading','<?php echo $row['id']?>')" style="cursor:pointer"><img src="../images/icon-del1.png" width="10" height="10" border="0"></span></div>
             </div>
               <?php }?>
         </div>
        
          <?php $query2 ="SELECT * from scope_brief_description WHERE `heading_id` = '".$row['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid' ";  
             $results = mysql_query($query2);
             $row2 = mysql_fetch_object($results);
           
             ?> 
           <div class="col-md-12">
            <div id="ptext-<?php echo $row['id']; ?>" >
                
             <div class="col-md-1 col-sm-2 panel-numbering" style="padding:0 3px;float:left">&nbsp;</div> 
             <div class="col-md-10 com-sm-8 "  id="btextf-<?php echo $row['id'] ?>"><?php echo @$row2->description ?> </div>
             
             <div  class="col-md-1 col-sm2 panel-edit" style="float:right; cursor:pointer" onclick="openedit('text','<?php echo $row['id'] ?>')">
              <div class="glyph">
                                                        <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                    </div> 
             </div>
             </div>
             <div class="editfield" id="pedittext-<?php echo $row['id']; ?>" >
             <div class="col-md-1 col-sm-2 panel-numbering" style="padding:0 3px;float:left">&nbsp;</div> 
             <form method="post" action="" id="submittextfor-<?php echo $row['id']; ?>">
                 <div class="col-md-10 com-sm-8"><textarea id="btext-<?php echo $row['id']?>" class="ckeditor" name="btext" required> <?php echo @$row2->description ?></textarea></div>
                 <input type="hidden" name="bdescid" value="<?php echo @$row2->id?>">
                  <input type="hidden" name="headingid" value="<?php echo $row['id']?>">
                  <input type="hidden" name="scopename" value="<?php echo $scope?>">
                  <input type="hidden" name="task" value="changedesc">
                  <input type="hidden" name="brief_id" value="<?php echo $BID?>">
                   </form>  
                  <div class="col-md-1 col-sm2 panel-edit" style="float:right"><a style="cursor:pointer" href="#" onclick="submittextform('<?php echo $row['id']?>')"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a>|<span onclick="closeedit('text','<?php echo $row['id'] ?>')" style="cursor:pointer"><img src="../images/icon-del1.png" width="10" height="10" border="0"></span></div>
             </div>
         </div>
     </div>
     
 </div>
 
 <?php $i=$i+0.1; } ?>
 
 </div>

                
                   <div class="widget">
 <div class="whead"> <h6> <i class="fa fa-play-circle"></i>Execution </h6>   </div>
  <div class="formRow fRow" style="padding:21px 0 !important">
 <div class="col-md-12">
     <div class="col-md-12">
          
             <div class="newheading" id="enewheading" >
                 <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left">New Heading</div>
               <form id="enewheadingform" method="post" action="">
                 <div class="col-md-10 com-sm-8">
                     <input type="text" name="nheading" value="" /></div>
                  <input type="hidden" name="scopename" value="<?php echo $scope?>">
                  <input type="hidden" name="brieftype" value="Execution">
                   <input type="hidden" name="task" value="newheading">
                  <input type="hidden" name="brief_id" value="<?php echo $BID?>">
                  
                 </form>
                  <div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="#" onclick="saveenewheading()"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a></div>
             </div>
         </div>
 </div>
      </div>
 <?php $query ="SELECT * from scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type='Execution'";  
 $result = mysql_query($query);
$i=3.1;
 ?>
 <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {?>
 <div class="formRow fRow">
     
     <div class="col-md-12 panel-detail">
         <div class="col-md-12">
             <div class="pheadin-txt" id="pheading-<?php echo $row['id'] ?>" >
                 <div class=" alert-success update_alert" id="alert-<?php echo $row['id'] ?>"> </div>
             <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left"><?php echo $i?></div>
             <div class="col-md-10 com-sm-8 htitle" id="headingf-<?php echo $row['id']?>"><?php echo $row['heading']?> </div>
             <?php if($row['company_id'] == $cid) {?>
             <div class="col-md-1 col-sm-2  panel-edit" style="float:right; cursor:pointer" >
                   <a class="delhead" href="javascript:void(0)" onclick="deleteHeading('<?php echo $row["id"]; ?>')">
                                                          <i class="fa fa-times" title="Delete"></i>
                                                        </a> 
                <div class="glyph" onclick="openedit('heading','<?php echo  $row['id'];?>')">
                                                        <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                    </div> 
             
             </div>
             <?php } ?>
             </div>
               <?php if($row['company_id'] == $cid) {?>
             <div class="editfield" id="peditheading-<?php echo $row['id']; ?>" >
                <form action="" method="post" id="formforheading-<?php  echo $row['id']?>">
                 <div class="col-md-1 col-sm-2  panel-numbering" style="padding:0 3px;float:left"><?php echo $k?></div>
                 <div class="col-md-10 com-sm-8"><input type="text" required name="headingtext" value="<?php echo $row['heading']?>" /></div>
                <input type="hidden" name="task" value="editheading"> 
                <input type="hidden" name="headingid" value="<?php echo $row['id']?>">
                </form>
                  <div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="javascript:void(0)" onclick="submitheadingform('<?php echo $row['id']?>')"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a>|<span onclick="closeedit('heading','<?php echo $row['id']?>')" style="cursor:pointer"><img src="../images/icon-del1.png" width="10" height="10" border="0"></span></div>
             </div>
               <?php $i=$i+0.1; }?>
         </div>
        
          <?php $query2 ="SELECT * from scope_brief_description WHERE `heading_id` = '".$row['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid'";  
             $results = mysql_query($query2);
             $row2 = mysql_fetch_object($results);
           
             ?> 
           <div class="col-md-12">
            <div id="ptext-<?php echo $row['id']; ?>" >
                
             <div class="col-md-1 col-sm-2 panel-numbering" style="padding:0 3px;float:left">&nbsp;</div> 
             <div class="col-md-10 com-sm-8 "><?php echo @$row2->description ?> </div>
             
             <div  class="col-md-1 col-sm2 panel-edit" style="float:right; cursor:pointer" onclick="openedit('text','<?php echo $row['id'] ?>')">
     <div class="glyph">
                                                        <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                    </div> 
             </div>
             </div>
             <div class="editfield" id="pedittext-<?php echo $row['id']; ?>" >
             <div class="col-md-1 col-sm-2 panel-numbering" style="padding:0 3px;float:left">&nbsp;</div> 
             <form method="post" action="" id="submittextfor-<?php echo $row['id']; ?>">
                 <div class="col-md-10 com-sm-8"  id="btextf-<?php echo $row['id'] ?>"><textarea class="ckeditor" id="btext-<?php echo $row['id']?>" name="btext" required> <?php echo @$row2->description ?></textarea></div>
                 <input type="hidden" name="bdescid" value="<?php echo @$row2->id?>">
                  <input type="hidden" name="headingid" value="<?php echo $row['id']?>">
                  <input type="hidden" name="scopename" value="<?php echo $scope?>">
                  <input type="hidden" name="task" value="changedesc">
                  <input type="hidden" name="brief_id" value="<?php echo $BID?>">
                   </form>  
                  <div class="col-md-1 col-sm2 panel-edit" style="float:right"><a style="cursor:pointer" href="#" onclick="submittextform('<?php echo $row['id']?>')"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a>|<span onclick="closeedit('text','<?php echo $row['id'] ?>')" style="cursor:pointer"><img src="../images/icon-del1.png" width="10" height="10" border="0"></span></div>
             </div>
         </div>
     </div>
     
 </div>
 
 <?php } ?>
 
 </div>
            </div>
            </div>
        </div>
    </section>



</body>
</html>
<script>
    function openedit(str, id){
        
        var eid = "pedit"+str+"-"+id;
         var pid = "p"+str+"-"+id;
         $("#"+pid).hide();
        $("#"+eid).show();
    }
     function closeedit(str, id){
        
        var eid = "pedit"+str+"-"+id;
         var pid = "p"+str+"-"+id;
         $("#"+eid).hide();
         $("#"+pid).show();
        
    }
    
      function submittextform(id){
                  var ht = $('body .cke_editable.cke_contents_ltr').html();
    $("#btext-" + id).val(ht);
        for (instance in CKEDITOR.instances) {
            CKEDITOR.instances[instance].updateElement();
        }  
    formData = $("#submittextfor-"+id).serialize();
        url = "briefActions.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
            if (data == 0) {
alert('error');
                }

                else {
                    $("#btextf-" + id).html(data);
                    closeedit('text', id);
                    $("#alert-" + id).html("Descripton updated successfully");
                    $("#alert-" + id).show();
                    setTimeout(function () {
                       $("#alert-" + id).hide();
                    }, 2000);
                }
            },
            error: function (e) {
         
            }
        });
        
    }
    function savepnewheading(){
        
            formData = $("#pnewheadingform").serialize();
        url = "briefActions.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
             if (data == 0) {

                   alert('error');
//                  location.reload();
                }

                else {
                  $("#headingf-" + id).html(data);
                    closeedit('heading', id);
                    $("#alert-" + id).html("Heading updated successfully");
                    $("#alert-" + id).show();
                    setTimeout(function () {
                       $("#alert-" + id).hide();
                    }, 2000);
                }
            },
            error: function (e) {
         
            }
        });
    }
        function saveenewheading(){
        
            formData = $("#enewheadingform").serialize();
        url = "briefActions.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
             if (data == 0) {

                   alert('error');
//                  location.reload();
                }

                else {
                  $("#headingf-" + id).html(data);
                    closeedit('heading', id);
                    $("#alert-" + id).html("Heading updated successfully");
                    $("#alert-" + id).show();
                    setTimeout(function () {
                       $("#alert-" + id).hide();
                    }, 2000);
                }
            },
            error: function (e) {
         
            }
        });
    }
        function savegnewheading(){
        
            formData = $("#gnewheadingform").serialize();
        url = "briefActions.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
             if (data == 0) {

                   alert('error');
//                  location.reload();
                }

                else {
                  $("#headingf-" + id).html(data);
                    closeedit('heading', id);
                    $("#alert-" + id).html("Heading updated successfully");
                    $("#alert-" + id).show();
                    setTimeout(function () {
                       $("#alert-" + id).hide();
                    }, 2000);
                }
            },
            error: function (e) {
         
            }
        });
    }
    
     function submitheadingform(id){
            
            formData = $("#formforheading-"+id).serialize();
        url = "briefActions.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
           

                if (data == 1) {

                  alert(" Updated Successfully");
                  location.reload();
                }
               
                else {
                  alert(data);
                }
            },
            error: function (e) {
         
            }
        }); 
            
        }
  function deleteHeading(id){
    if (id > 0) {
    alertify.confirm("Are you sure you want to delete heading.", function (e) {
    if (e) {
    url = "briefActions.php";

    $.ajax({
    url: url,
            type: 'POST',
            data: {task:'deleteheading', hid:id},
            success: function (data) {
            if (data == 1) {
            location.reload();
            }

            else {
            alert("Something went wrong. Please try later");
            }
            },
            error: function (e) {

            }
    });
    } else {
    return 0;
    }


    });
    }
   
    }
 
    </script>