<?
$due_flag =($ticket_details['pause_dtime']!='')? $ticket_details['pause_dtime']:'';
$resolution_flag = ($ticket_details['pause_rtime']!='') ? $ticket_details['pause_rtime']:'';
?>
 <section  class="container m-t-md">
   <!-- Announcements -->
   <div class="row">
   <div class="col-md-12">
   <section class="panel shadow-none">
      <? if(isset($_SESSION['message']) || $_SESSION['message']!=''){ ?> <script> $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html('<? echo $_SESSION['message']; ?>'); </script><? } session_destroy();?>
      <? if(isset($operation['message']) && $operation['message']!='' && isset($operation['success'])){ ?>
      <script> $("#<? echo ($operation['success']==1)?'vis_submit_msg_div':'vis_submit_err_div'; ?>").show(); $("#<?= ($operation['success']==1)?'vis_submit_msg_div':'vis_submit_err_div'; ?>").html('<? echo $operation['message']; ?>');   setTimeout(function(){$("#vis_submit_err_div").hide();},10000);</script>
      <? } elseif(isset($operation['message']) && $operation['message']!='') { ?> <script> $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html('<? echo $operation['message']; ?>'); </script><? } ?>			
      <div class="panel-heading b-b">
         <h4 class="panel-title1">
            <div class="col-sm-6 no-padder"><? if($ticket_details['channel_id']<=16 && strstr($ticket_details['icon_path'], "vh vh-"))
               {
                   echo '<i class="'.$ticket_details['icon_path'].'"></i>';
               }
               else
               {
                   echo '<img src="'.VIS_PATH_PROFILE.$ticket_details['icon_path'].'" class="thumb-xs">';
               }
               echo '<span> '.$ticket_details['ticket_hash'].'</span>';
               if(VIS_HEAD_MENU_RATING==1){ ?>
               <span class="vh-yellow m-l-xs"> 
               <? if($ticket_details['rating'] == 0 ) {
                  for($cn=0;$cn<5;$cn++) 	
                  /*if($ticket_details['ticket_status']=='Closed'){						  
                       echo '<a href="?/ticket/add_rating/'.str_replace(' ','-',$ticket_details['subject']).'/'.$ticket_details['ticket_id'].'/'.($cn+1).'" ><i class="vh '.($cn<$ticket_details['rating']?'vh-star':'vh-star-empty').'"></i></a>';
                  }else{
                  echo '<i class="vh '.($cn<$ticket_details['rating']?'vh-star':'vh-star-empty').'"></i>';
                  }*/
                  echo '<i class="vh '.($cn<$ticket_details['rating']?'vh-star':'vh-star-empty').'"></i>';
                     } 
                     else
                     {
                     for($cn=0;$cn<5;$cn++) 							  
                       echo '<i class="vh '.($cn<$ticket_details['rating']?'vh-star':'vh-star-empty').'"></i>';
                     }
                  ?> 
               </span><? } ?>                          
            </div>
            <div class="text-right"> 
               <? if((!isset($ticket_reply) || $ticket_reply=='') && (isset($ticket_feedback) || $ticket_feedback != ''))  { ?>
               <a href="?/ticket/ticket-reply/<?= $ticket_details['ticket_hash']."/".$ticket_details['ticket_id']; ?>" class="link btn btn-link btn-sm vis_link_button"><?= $vis_language['TXTREPLY']; ?></a>
               <?  }
                  else {	?>						
               <a href="?/ticket/ticket-reply/<?= $ticket_details['ticket_hash']."/".$ticket_details['ticket_id']; ?>" class="link btn btn-link btn-sm vis_link_button"><?= $vis_language['TXTREPLY']; ?></a>
               <?  } ?>
               <?  if($ticketCloseSettings != -1 && $ticket_details['status_id']!=3) { ?><button type="button" onclick="close_ticket();" class="btn btn-sm vh-danger-bg"><?= $vis_language['TXTCLOSETICKET']; ?></button><? } ?>
            </div>
         </h4>
      </div>
      <div class="panel-body m-b-n-md">
      <div class="tab-content">
         <div class="tab-pane fade active in" id="TicketDetails">
            <div class="row">
               <div class="col-md-12">
                  <div class="wrapper-sm">
                     <div class="h5 l-h"><span class="font-bold pull-left m-r"><?= $vis_language['TXTSUBJECT']; ?></span><span class="font-bold"><?= $ticket_details['subject']; ?></span></div>
                     <div class="m-t-sm m-b-n-sm">
                        <ul class="navSeprator no-padder">
                           <li><span class="font-bold"><?= $vis_language['TXTCREATEDBY']; ?></span> <span class="text-muted m-l-xs"><?= $ticket_details['first_name'].' '.$ticket_details['last_name']; ?></span></li>
						   <li><span class="font-bold"><?= $vis_language['TXTCREATEDON']; ?></span> <span class="text-muted m-l-xs"><?= format_datetime($ticket_details['receive_date']); ?></span></li>
                           <li><span class="font-bold"><?= $vis_language['TXTMODIFIEDON']; ?></span> <span class="text-muted m-l-xs"><?= format_datetime($ticket_details['modify_date']); ?></span></li>
                        </ul>
                     </div>
                     <div class="row">
                        <section class="bg-white ">
                           <header class="panel-heading bg-white b-t b-b m-b">
                              <div class="row">
                                 <div class="col-md-4">
                                    <div class="row">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTDEPARTMENT']; ?></label>
                                       <div class="col-md-4"><?= $ticket_details['department_name']; ?></div>
                                    </div>
                                 </div>
                                 <div class="col-md-4">
                                    <div class="row m-b-sm">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTSTATUS']; ?></label>
                                       <div class="col-md-4"  style="color:<?php echo $ticket_details['status_color']; ?>"  ><?= $ticket_details['ticket_status']; ?></div>
                                    </div>
                                 </div>
                                 <? if($ticket_type != -1): ?>
                                 <div class="col-md-4">
                                    <div class="row m-b-sm">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTTICKETTYPE']; ?></label>
                                       <div class="col-md-4"><?= $ticket_details['ticket_type']; ?></div>
                                    </div>
                                 </div>
                                 <? endif;?>								 
                                 <? if($ticket_priority != -1): ?>
                                 <div class="col-md-4">
                                    <div class="row m-b-sm">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTPRIORITY']; ?></label>
                                       <div class="col-md-4" style="color:<?php echo $ticket_details['priority_color']; ?>"   ><?= $ticket_details['ticket_priority']; ?></div>
                                    </div>
                                 </div>
                                  <?endif; if($ticket_details['ticket_level']!='' && (isset($module_setting['vis_show_level']) && $module_setting['vis_show_level']==2)):?>
                                  <div class="col-md-4">
                                    <div class="row m-b-sm">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTTICKETLEVEL']; ?></label>
                                       <div class="col-md-4"><?= $ticket_details['ticket_level']; ?></div>
                                    </div>
                                 </div>
                                 <? endif; if($ticket_details['location']!='' && VIS_ITIL==1 && VIS_MODULE_ACCESS_ITIL==1 && (isset($module_setting['vis_show_location']) && $module_setting['vis_show_location']==2)):?>
                                  <div class="col-md-4">
                                    <div class="row m-b-sm">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTLOCATION']; ?></label>
                                       <div class="col-md-4"><?= $ticket_details['location']; ?></div>
                                    </div>
                                 </div> 
                                 <? endif; if($ticket_details['ticket_category']!='' && (isset($module_setting['vis_show_category']) && $module_setting['vis_show_category']==2)):?>
                                  <div class="col-md-4">
                                    <div class="row m-b-sm">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTCATEGORY']; ?></label>
                                       <div class="col-md-4"><?= $ticket_details['ticket_category']; ?></div>
                                    </div>
                                 </div>
                                  <? if($ticket_details['ticket_sub_cateogy']!='' && (isset($module_setting['vis_show_subcategory']) && $module_setting['vis_show_subcategory']==2)): ?>
                                 <div class="col-md-4">
                                    <div class="row m-b-sm">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTTICKETSUBCATEGORY']; ?></label>
                                       <div class="col-md-4"><?= $ticket_details['ticket_sub_cateogy']; ?></div>
                                    </div>
                                 </div>
                                  <? endif; if($ticket_details['ticket_item']!='' && (isset($module_setting['vis_show_item']) && $module_setting['vis_show_item']==2)): ?>
                                  <div class="col-md-4">
                                    <div class="row m-b-sm">
                                       <label class="col-md-4 font-bold"><?= $vis_language['TXTTICKETITEM']; ?></label>
                                       <div class="col-md-4"><?= $ticket_details['ticket_item']; ?></div>
                                    </div>
                                 </div>
                                 <? endif; endif;  if(VIS_HEAD_MENU_ASSIGNEDTO==1){ ?>
                                 <div class="col-md-12">
                                    <div class="row">
                                       <div class="col-md-3 font-bold"><?= $vis_language['TXTASSIGNTO']; ?></div>
                                       <div class="col-md-9">
                                          <? if($ticket_details['owner'] == "") echo $vis_language['TXTUNASSIGNED'];
                                             else{
                                                   $owners=explode(',',$ticket_details['owner']);
                                                   for($i=0;$i<count($owners);$i++){ ?>
                                          <span class="btn btn-xs alert-success m-r-xs"><?= $owners[$i]; ?></span>
                                          <? }
                                             } ?>
                                       </div>
                                    </div>
                                 </div>
                                 <? } 
                                    if(VIS_HEAD_MENU_SLA==1){ ?>
                                 <div class="b m-b m-t col-md-12 vis_new">
                                    <div class="row">
                                       <div class="col-sm-2 m-t-xs">
                                          <label class="font-bold"><?= $vis_language['TXTSLA']; ?></label>
                                       </div>
                                       <div class="col-sm-4 m-t-xs">
									   
                                          <label><?= $vis_language['TXTDUETIME']; ?></label>
                                          <span class="m-l-sm"><i class="vh vh-clock m-r-xs"></i><? if($due_flag!='')echo (is_numeric($due_flag))?count_remain_time($due_flag) : $due_flag; elseif($ticket_details['due_time']<=0 && $ticket_details['user_replied']==1 && $ticket_details['status_id']!=3 && $ticket_details['sdue_time']!=0) echo $vis_language['TXTOVERDUE']; elseif($ticket_details['due_time']>0 && $ticket_details['status_id']!=3 && $ticket_details['user_replied']==1) echo count_remain_time(($ticket_details['due_time'])); else echo $vis_language['TXTUNDUE']; ?></span>
                                       </div>
                                       <div class="col-sm-4 m-t-xs">
                                          <label><?= $vis_language['TXTRESOLUTIONTIME']; ?></label>
                                          <span class="m-l-sm"><i class="vh vh-clock m-r-xs"></i><? if($resolution_flag!='')echo (is_numeric($resolution_flag))?count_remain_time($resolution_flag) : $resolution_flag; elseif($ticket_details['resolution_time']<=0 && $ticket_details['status_id']!=3 && $ticket_details['rdue_time']!=0) echo $vis_language['TXTOVERDUE']; elseif($ticket_details['resolution_time']>0 && $ticket_details['status_id']!=3) echo count_remain_time(($ticket_details['resolution_time'])); else echo $vis_language['TXTUNDUE']; ?></span>
                                       </div>
                                    </div>
                                 </div>
                                 <? } 
                                    if(VIS_ITIL==1 && isset($service_ticket_details) && $service_ticket_details!=-1){?>  
                                 <div class="m-b col-md-12">
                                    <div class="row">
                                       <div class="col-sm-3 m-t-xs">
                                          <label><? echo $vis_language['TXTSERVICEITEM']?></label>
                                          <span class="m-l-sm"><? echo $service_details[0]['name'];?></span>
                                       </div>
                                       <div class="col-sm-3 m-t-xs">
                                          <label><? echo $vis_language['TXTCOST'];?></label>
                                          <span class="m-l-sm"><? echo $service_ticket_details[0]['total_cost'].' '.$domain[0]['currency'];?></span>
                                       </div>
                                       <div class="col-sm-3 m-t-xs">
                                          <label><? echo $vis_language['TXTQUANTITY']; ?></label>
                                          <span class="m-l-sm"><? echo $service_ticket_details[0]['quantity'];?></span>
                                       </div>
                                       <div class="col-sm-3 m-t-xs">
                                          <label><? echo $vis_language['TXTTOTAL']; ?></label>
                                          <span class="m-l-sm"><? echo $service_ticket_details[0]['quantity']*$service_ticket_details[0]['total_cost'].' '.$domain[0]['currency'];?></span>
                                       </div>
                                    </div>
                                 </div>
                                 <? if($service_custom_details!=-1){?>
                                 <div class="row m-t">
                                    <div class="col-md-12">
                                       <? for($i=0;$i<count($service_custom_details);$i++){?>
                                       <!--<div class="form-group">
                                          <label class="col-sm-2 control-label text-right" title=""><? echo $service_custom_details[$i]['field_name']?></label>
                                          <div class="col-sm-10">
                                              <label class="control-label"><? echo $service_custom_details[$i]['field_value'];?>&nbsp;</label>
                                          </div>
                                          </div>-->
                                       <? if($service_custom_details[$i]['field_type']==7 || $service_custom_details[$i]['field_type']==4){
                                          if($t==0){?>
                                       <div class="form-group">
                                          <label class="col-sm-2 control-label text-right" title=""><? echo $service_custom_details[$i]['field_name']?></label>
                                          <div class="col-sm-10">
                                             <label class="control-label"><? echo $service_custom_details[$i]['field_value'];?>&nbsp;</label>
                                             <? }else {?>
                                             , <label class="control-label"><? echo $service_custom_details[$i]['field_value'];?>&nbsp;</label>
                                             <? }$t++;?>
                                             <? }else{
                                                if(($t>0 && $service_custom_details[$i]['field_type']!=7) || ($t>0 && $service_custom_details[$i]['field_type']!=4)){ 
                                                		echo '</div></div>';
                                                		$t=0;
                                                }?>                   
                                             <div class="form-group">
                                                <label class="col-sm-2 control-label text-right" title=""><? echo $service_custom_details[$i]['field_name']?></label>
                                                <div class="col-sm-10">
                                                   <label class="control-label"><? echo $service_custom_details[$i]['field_value'];?>&nbsp;</label>
                                                </div>
                                             </div>
                                             <? }
                                                ?> 		
                                             <? }?> 	
                                          </div>
                                       </div>
                                       <? }?>
                                       <?php }?>    
                                    </div>
                                    <? 
									
									if($user_custom_field_var != '') { ?> 
                                    <div class="btn-group">
                                       <button class="btn btn-default btn-xs btn-rounded" onclick="show_custome_field();"><? echo $vis_language['TXTCUSTOMFIELDS']; ?></button>  
                                    </div>
                                    <?php }?>
                                   
                                    <? if($custom_field_var != '' && $operation['vis_operation']!= 'ticket_reply' && isset($fileddata)){ if(isset($fileddata['totaldata'])){?> 
                                    <div class="btn-group">
                                       <button class="btn btn-default btn-xs btn-rounded" onclick="show_feedback();"><? echo  $vis_language['TXTUSERFEEDBACK']; ?></button>
                                    </div>
                                    <?php }}?>
                                    <? if($user_custom_field_var != '') { ?>
                                    <div id="vis_custom_filed" <?php echo ($readonly==1)?'style="display:none;"':'';?> >
                                       <div >
                                          <p class="pull-right"  <?php echo ($readonly==0)?'style="display:none;"':'';?>><a class="link btn btn-link btn-sm vis_link_button m-t text-xm" href="?/ticket/ticket_details/<?= $ticket_details['ticket_hash']."/".$ticket_details['ticket_id']; ?>/2"><?= $vis_language['TXTEDIT']; ?></a></p>
                                       </div>
                                       <div class="panel-body no-padder">
                                          <form class="form-horizontal" id="frmcustomfielddata">
                                             <div class="wrapper">
                                                <div class="col-md-10"><? echo $user_custom_field_var; ?></div>
                                             </div>
                                          </form>
                                       </div>
                                    </div>
                                    <? } ?>
                                    <?   if(isset($ticket_feeback) || $ticket_feedback !='') { ?>
                                    <div class="tab-pane fade active in" id="TicketDetails">
                                       <div>
                                          <? if($custom_field_var != ''){ ?>
                                          <div class="panel-body form-horizontal" id="vis_feedback_field" style="display:none;">
                                             <!--  <form method="post" name="vis_ticket_feedback" class="form-horizontal">-->
                                             <div class="col-md-12">
                                                <div class="wrapper-sm">
                                                   <? echo $custom_field_var; ?>
                                                   <div class="line line-dashed b-b line-lg pull-in"></div>
                                                   <!-- <input type="hidden" name="vis_ticket_id" id="vis_ticket_id" value="<?php echo $ticket_details['ticket_id']; ?>" /><input type="hidden" name="vis_department" id="vis_department" value="<?php echo $ticket_details['department_id']; ?>" /><input type="hidden" name="vis_module" id="vis_module" value="ticket" /><input type="hidden" name="vis_operation" id="vis_operation" value="add_feedback" />
                                                      </div> <!--/.wrapper-sm .b-b -->
                                                </div>
                                                <div class="col-lg-offset-2 col-lg-10 m-b-lg">
                                                   <!--  <button class="btn btn-primary m-r" id="vis_subbtn" type="submit"><? echo $vis_language['TXTSUBMIT']; ?></button>
                                                      <button class="btn btn-default" onclick="window.location = 'index.php?/ticket/ticket_details/<?= $ticket_details['ticket_hash']."/".$ticket_details['ticket_id']; ?>';" type="button"><?= $vis_language['TXTCANCEL']; ?></button> -->
                                                </div>
                                                <!-- </form>-->
                                             </div>
                                             <? } ?>
                                          </div>
                                          <!-- /.row -->
                                       </div>
                                       <? } ?>
                           </header>
                           <? if(isset($ticket_reply) || $ticket_reply!='') { ?> 
                           <div class="panel-body m-b-n-md">
                           <span class="font-bold pull-left m-r"><? echo $vis_language['TXTREPLY']; ?></span>
                           <div class="form-group m-t-lg pull-in clearfix">
                           <div class="col-sm-12"><textarea autofocus="autofocus" name="vis_ticket_post" id="vis_ticket_post" rows="6" class="form-control input-sm" rows="10"></textarea></div>                                              
                           </div>
                           </div>
                           <footer class="panel-footer bg-empty no-borders">
                           <div class="row">
                           <div class="col-sm-6">
                           <div class="text-left" style="<?= ($attachment>0)?'':'display:none'; ?>">
                           <div id="progress" class="progress" style="display:none; height:14px;"><div class="progress-bar progress-bar-success"></div></div>
                           <span class="btn btn-link btn_upload_file vis_font_size_none text-primary" id="vis_attach_file"><?= $vis_language['TXTATTACHFILE']; ?> <input class="form-control" type="file" id="fileupload"></span>
                           <input type="hidden" id="vis_max_attach" name="vis_max_attach" value="<?= ($attachment-1); ?>" /><input type="hidden" id="vis_attachment_count" name="vis_attachment_count" value="0" />
                           <div style="display:none;" id="vis_attachments"></div><div id="vis_new_attachments" class="p-l-none"></div>
                           </div>
                           </div>
                           <div class="col-sm-4">
                           <? if($ticket_priority != -1): ?>
                           <div class="form-group text-left">
                           <label class="col-xs-6 control-label help-block m-r-n font-bold"><?= $vis_language['TXTCHANGEPRIORITY']; ?>:</label>
                           <div class="col-xs-6 m-b">
                           <select id="vis_ticket_priority" name="vis_ticket_priority" class="form-control input-sm <? if(!is_mobile()) echo 'selectpicker'; ?>" <? if(count($priority_list)>10) echo 'data-live-search="true"';?> >
                           <?php for($i=0;$i<count($priority_list);$i++) {
                              if($ticket_details['priority_id'] == $priority_list[$i]['priority_id'])
                              	echo '<option value="'.$priority_list[$i]['priority_id'].'" selected="selected">'.$priority_list[$i]['priority_name'].'</option>';
                              else echo '<option value="'.$priority_list[$i]['priority_id'].'">'.$priority_list[$i]['priority_name'].'</option>'; } ?>
                           </select>
                           </div>
                           </div>
                           <? endif;?>
                           </div>
                           <div class="col-sm-2 text-right">
                           <input type="hidden" name="vis_ticket_id" id="vis_ticket_id" value="<?= $operation['ticket_id']; ?>" /><input type="hidden" name="vis_module" id="vis_module" value="ticket" />
                           <input type="hidden" name="vis_from_name" id="vis_from_name" value="<?= $client_details[0]['first_name'].' '.$client_details['last_name']; ?>" />
                           <input type="hidden" name="vis_from_email" id="vis_from_email" value="<?= $client_details[0]['email']; ?>" />
                           <button type="button" onclick="window.location = 'index.php?/ticket/ticket_details/<?= $ticket_details['ticket_hash']."/".$ticket_details['ticket_id']; ?>';" class="btn btn-default"><?= $vis_language['TXTCANCEL']; ?></button>
                           <button type="button" class="btn btn-primary" data-loading-text="Loading" id="vis_subbtn" onclick="submit_form();"><?= $vis_language['TXTSUBMIT']; ?></button>
                           <!--<button type="submit" class="btn btn-primary"><?= $vis_language['TXTSUBMIT']; ?></button>
                              <input type="hidden" name="vis_operation" value="reply_ticket">-->
                           </div>
                           </div>
                           </footer>
                           <? } ?>
                        </section>
                        </div>                   
                        <? include(VIS_PATH_TEMPLATE.'ticket_post.php'); ?>
                        </div> <!--/.wrapper-sm .b-b -->
                        </div>
                     </div>
                     <!-- /.row -->
                  </div>
               </div>
               <!-- /.row -->
            </div>
   </section>
   </div>
   </div>
</section>
<? if((isset($ticket_reply) && $ticket_reply!='') || (isset($ticket_feeback) || $ticket_feedback !='')) { ?>
<script>   window.scrollTo(0,600); </script>
<? } ?>


<script>
   $('.start').datetimepicker();
   var curr_stamp=0;
   	<? if(!defined('VIS_HEAD_MENU_HTML_EDITOR') || VIS_HEAD_MENU_HTML_EDITOR==1) { ?>    
   	$(function(){
   		$('#vis_ticket_post').redactor({
   			buttonSource: true,
               minHeight: 180, // pixels
               maxHeight: 180,
               imageUpload: "index.php?vis_tmpst="+new Date().getTime()+"&vis_module=ticket&vis_operation=upload_file&vis_static_area=editor_image_upload",
               imageUploadParam: 'files',                
               focus: true,
               plugins: ['source'],
			   deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet']
   		});
   	});<? } ?>
   function submit_form() {
       if(curr_stamp==0 || (curr_stamp < (Date.now()-10000))){
           curr_stamp = Date.now();
           if($("#vis_ticket_post").val()== '')
           {
               $(window).scrollTop(0);
               $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html('<?= $vis_language['MSGPOSTMESSAGENOTFOUND']; ?>');
               return false;
           }
               if($("#vis_ticket_priority").val()== '')
           {
               $(window).scrollTop(0);
               $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html('<?= $vis_language['MSGERROPRT']; ?>');
               return false;
           }
           $.ajax({
              url: 'index.php',
              dataType: 'json',
              data: {'vis_module':"ticket", 'vis_operation':"reply_ticket", 'vis_ticket_id':$("#vis_ticket_id").val(), 'vis_from_name':$("#vis_from_name").val(), 'vis_attachments':$("#vis_attachments").html(),'vis_ticket_post':$("#vis_ticket_post").val(),'vis_from_email':"<? echo $client_details[0]['email']; ?>",'vis_ticket_priority':$("#vis_ticket_priority").val()},
              type: "POST",
              success: function(data) {
                  $(window).scrollTop(0);
                  window.location = "index.php?/ticket/ticket_details/<?= $ticket_details['ticket_hash']; ?>/<?= $operation['ticket_id']; ?>";			
              }
          });
       }
   }
   function closed_ticket() {
   	$.ajax({
           url: 'index.php',
           data: {'vis_module':"ticket", 'vis_operation':"update_properties", 'vis_ticket_id':$("#vis_ticket_id").val(), 'vis_action':'status', 'vis_update_id':'3'},
           type: "POST",
           success: function(data) {
               $(window).scrollTop(0);
               $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html('<?= $vis_language['MSGSUCCOPRT']; ?>');
               setTimeout(function(){window.location = "index.php?vis_module=ticket&vis_operation=ticket_details&ticket_id=<?= $operation['ticket_id']; ?>"}, 2000);			 
           }
       });
   }
   
   function close_ticket() {
   	$.ajax({
           url: 'index.php',
           data: {'vis_module':"ticket", 'vis_operation':"update_properties", 'vis_ticket_id':<?= $ticket_details['ticket_id']; ?>, 'vis_action':'status', 'vis_update_id':'3'},
           type: "POST",
           success: function(data) {
               $(window).scrollTop(0);
               $("#vis_submit_msg_div").show(); $("#vis_submit_msg_div").html('<?= $vis_language['MSGSUCCOPRT']; ?>');
															<?  if($ticketfeedbSettings != -1){?>setTimeout(function(){window.location = "index.php?/feedback/<?= $clientdetails['email']; ?>/<?= $clientdetails['salt']; ?>/<?= $ticket_details['ticket_id']; ?>"}, 2000); <? }else{?>
               setTimeout(function(){window.location = "index.php?/ticket/ticket_details/<?= $ticket_details['ticket_hash']."/".$ticket_details['ticket_id']; ?>"}, 2000);		
															<? }?>	 
           }
       });
   }
   
   function vis_remove_attachment(attach_id){
   	 $.ajax({
           url: 'index.php',
           data: {'vis_module':"ticket", 'vis_operation':"remove_attachment", 'vis_attachment_id':attach_id },
           type: "POST",
           success: function(data) {  }
       });
       var attachments=$("#vis_attachment_count").val();
   	$("#vis_attachment_count").val(eval(parseInt(attachments)-1));
   	var max_attach=$("#vis_max_attach").val();
   	if((attachments-1)<=max_attach) $("#vis_attach_file").css('display','');
   }
   $(function () {
   	var url = 'index.php?vis_module=ticket&vis_operation=upload_file';
   	$('#fileupload').fileupload({
   		url: url,
   		done: function (e, data) {
   			if(data.result == 1) {
   				 $("#vis_submit_err_div").show(); 
   				 $("#vis_submit_err_div").html('<?php echo addslashes($vis_language['ERRORMSGEXTENSION']); ?>'); window.scrollTo(0,0);
   				 setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
   				
   			}
   			else if(data.result == 2) {
   				 $("#vis_submit_err_div").show(); 
   				 $("#vis_submit_err_div").html('<?php echo $vis_language['MSGSIZEERROR']; ?>'); window.scrollTo(0,0);
   				 setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
   			}
   			else
   			{
   			$("#vis_new_attachments").append(data.result);
   				var max_attach=$("#vis_max_attach").val();
   				var attachments=$("#vis_attachment_count").val();
   				$("#vis_attachment_count").val(eval(parseInt(attachments)+1));
   				if(attachments>=max_attach) $("#vis_attach_file").css('display','none');
   			}
   			 $('#progress').css( 'display','none');
   			 $('#progress .progress-bar').css( 'width','0%');
   		},
           progressall: function (e, data) {
   			$('#progress').css( 'display','');
               var progress = parseInt(data.loaded / data.total * 100, 10);
               $('#progress .progress-bar').css(
                   'width',
                   progress + '%'
               );
           }
   	});
   });
   function show_custome_field()
   {
   	$('#vis_custom_filed').toggle();
   	$('#vis_feedback_field').hide();
   }
   function show_feedback()
   {
   	$('#vis_feedback_field').toggle();
   	$('#vis_custom_filed').hide();
   }
	  function check_customdata()
   {
		 var val =  $('#frmcustomfielddata').find('input[name!=vis_operation]').serialize();
		 var textareaval='';
         $('[id^="field"]' ).each(function(){
		if($(this).is("textarea")){
				 textareaval=textareaval+'&'+this.id+'='+$(this).val();
			}
            });
		 
		 var returns=true;
   	 $.ajax({
             url: 'index.php',
             dataType: 'json',
             data: val+textareaval+'&vis_operation=check_customdata&location=11',
             type: "POST",
			 async:false,
             success: function(data) {
			if(data.res==0)
				 {
					 $("#vis_submit_err_div").show();
					 $("#vis_submit_err_div").html(data.msg); window.scrollTo(0,0);
				 setTimeout(function(){$("#vis_submit_err_div").hide();},10000);
//					  $("#vis_global_msg_div").html(data.msg);

returns=false;
				 }
				 else
				 {
					 returns=true;
				 }
				 
			             }
         });
		 
		 return returns; 
	  
   } 
	
</script>
<script src="<? echo VIS_PATH_SCRIPT; ?>file-upload/jquery.ui.widget.js"></script>
<script src="<? echo VIS_PATH_SCRIPT; ?>file-upload/jquery.fileupload.js"></script>
<script src="<?php echo VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>

