{if $error}
	<div class="notice notice-error">
		<div class="inside">
			<p>{$LANG.supportticketinvalid}</p>
		</div>
	</div>
{else}

{literal}
<script language="javascript">
jQuery(document).ready(function(){
    jQuery("#addfileupload").click(function () {
        jQuery("#fileuploads").append("<input type=\"file\" name=\"attachments[]\" size=\"50\"><br />");
        return false;
    });
});
function rating_hover(id) {
  var selrating=id.split('_');
  for(var i=1; i<=5; i++){
    if(i<=selrating[1]) document.getElementById(selrating[0]+'_'+i).style.background="url(images/rating_pos.png)";
    if(i>selrating[1]) document.getElementById(selrating[0]+'_'+i).style.background="url(images/rating_neg.png)";
  }
}
function rating_leave(id){
  for(var i=1; i<=5; i++){
    document.getElementById(id+'_'+i).style.background="url(images/rating_neg.png)";
  }
}
function rating_select(id){
  {/literal}window.location='viewticket.php?tid={$tid}&c={$c}&rating='+id;{literal}
}
</script>
{/literal}

		<div class="bigheader">
			<h2>{$LANG.supportticketsviewticket} #{$tid}</h2>
		</div><!-- .bigheader --> 	

{if $errormessage}
	<div class="notice notice-error">
		<div class="inside">
			<p>{$errormessage}</p>
		</div>
	</div>
{/if}

<div class="table-responsive table-grey">
<table>
        <tr>
          <th>{$LANG.supportticketsdepartment}</th>
          <th>{$LANG.supportticketsdate}</th>
          <th>{$LANG.supportticketssubject}</th>
          <th>{$LANG.supportticketsstatus}</th>
          <th>{$LANG.supportticketsticketurgency}</th>
        </tr>
        <tr>
          <td>{$department}</td>
          <td>{$date}</td>
          <td>{$subject}</td>
          <td>{$status}</td>
          <td>{$urgency}</td>
        </tr>
        
{if $customfields}

		<tr>
			<th colspan="1">{$LANG.newticket_required}</th>
			<th colspan="4">{$LANG.newticket_answer}</th>
		</tr>

	    {foreach key=num item=customfield from=$customfields}
        <tr>
        	<td colspan="1">{$customfield.name}</td>
        	<td colspan="4">{$customfield.value}&nbsp;</td>
        </tr>
        {/foreach}

{/if}        
        
        
</table>
</div>

<div class="ticketreply">
	<div class="user">
		<div class="left">
			{$user}
		</div>
		
		<div class="right">
			{$date}
		</div>
	</div>
	
	<div class="body">
	
		{php}
		    $userdetails = getclientsdetails($GLOBALS['clientsdetails']['id']);   
		    $email = $userdetails['email'];
		    $ticket_gravatar = 'https://www.gravatar.com/avatar/' . md5($email) . '?s=100';
			echo '<img src="' . $ticket_gravatar . '" alt="My gravitar" class="avatar" />';
		{/php}	
	
	
		{$message}
		
		
		{if $attachments}
		<br /><br />
 		<p><strong>{$LANG.supportticketsticketattachments}</strong></p>
 		
		  {foreach from=$attachments key=num item=attachment} <img src="images/article.gif" class="absmiddle" border="0" alt="{$attachment}" /> <a href="dl.php?type=a&id={$id}&i={$num}">{$attachment}</a><br />
		  {/foreach}
  		{/if}
		
		
		<div class="clear">&nbsp;</div>
		
	</div>
	
</div>

  
{foreach key=num item=reply from=$replies}  
  
 <div class="ticketreply">
	<div class="user user-{if $reply.admin}admin{else}client{/if}">
		<div class="left">
			{$reply.user|replace:"<br />
      ":" || "}
		</div>
		
		<div class="right">
			{$reply.date}
		</div>
	</div>
	
	<div class="body">
	
		{if $reply.admin}
		
		<img src="templates/{$template}/images/ticketavatar.png" alt="{$companyname}" class="avatar" />
		
		{else}
	
		{php}
			echo '<img src="' . $ticket_gravatar . '" alt="My gravitar" class="avatar" />';
		{/php}
		
		{/if}	
	
	
		{$reply.message}
		
		
{if $reply.attachments}

<br /><br />
  
  
  
  <p><strong>{$LANG.supportticketsticketattachments}</strong></p>
  
  
  
  {foreach from=$reply.attachments key=num item=attachment} <img src="images/article.gif" class="absmiddle" border="0" alt="{$attachment}" /> <a href="dl.php?type=ar&id={$reply.id}&i={$num}">{$attachment}</a><br />
  {/foreach}{/if}  
  
		<div class="clear">&nbsp;</div>
		
	</div>
	
</div>  
  
{/foreach}
		

{if $showclosebutton}
<p class="center">
	<a href="{$smarty.server.PHP_SELF}?tid={$tid}&amp;c={$c}&amp;closeticket=true" class="button1 color1">{$LANG.supportticketsstatuscloseticket}</a>
</p>
{/if}

		<div class="bigheader">
			<h2>{$LANG.supportticketsreply}</h2>
		</div><!-- .bigheader --> 

<form method="post" action="{$smarty.server.PHP_SELF}?tid={$tid}&amp;c={$c}&amp;postreply=true" enctype="multipart/form-data">



		<div class="feildset">
		
			<div class="col1">
		
				<div>
					<label>
						<span>{$LANG.supportticketsclientname}:{if $loggedin}{else} ({$LANG.required}){/if}</span>
						{if $loggedin}{$clientname}{else}
              				<input type="text" name="replyname" placeholder="{$LANG.newticket_name}" value="{$replyname}" />
              			{/if}
					</label>
				</div>
				
				<div>
					<label>
						<span>{$LANG.supportticketsclientemail}:{if $loggedin}{else} ({$LANG.required}){/if}</span>
						{if $loggedin}{$email}{else}
              				<input type="text" name="replyemail" placeholder="{$LANG.newticket_email}" value="{$replyemail}" />
              			{/if}
					</label>
				</div>
				
				<div>
					<label>
						<span>{$LANG.ticketreply_title_message} ({$LANG.required})</span>
						<textarea name="replymessage" placeholder="{$LANG.newticket_message}">{$replymessage}</textarea>
					</label>
				</div>
				
				
				<div>
					<label>
						<span>{$LANG.supportticketsticketattachments}</span>
						<input type="file" name="attachments[]" size="50" />
              			<a href="#" id="addfileupload"><img src="images/add.gif" class="absmiddle" alt="" border="0" /> {$LANG.addmore}</a><br />
              			<div id="fileuploads"></div>
              			({$LANG.supportticketsallowedextensions}: {$allowedfiletypes})
					</label>
				</div>									
			          
			  <p class="center">
			    <input type="submit" value="{$LANG.supportticketsticketsubmit}" class="button1 color2" />
			  </p>
			  
			  </div>
		
		</div>	  
  
</form>
{/if}