<!--
****************************************************************************
*  Description: Layout for tickets content                                 *
*  Created: 05/22/2006                                                     *
****************************************************************************
-->

<script type="text/javascript" src="../javascript/modules/support.js?version={VERSION}"></script>
<script type="text/javascript">
    var NotificationBtn = '';
    var ticketid = {TICKETID};

    $(document).ready(function() {
        $('.ticket-header-block:last').css('border-right','none');
	    callTicketSummaries();


        $('#btnDeleteTicket').bind('click',function(){
            deleteTicket();
        });


        $('#btnSubscribe').bind('click',function(){
            ticketAdditionalNotification();
        });

<!-- BEGIN DYNAMIC BLOCK: ticketCustomFieldsCode -->
        customFields.createSubmitButton(ticketid);
        loadCustomFields();
<!-- END DYNAMIC BLOCK: ticketCustomFieldsCode -->

        onLoadFunctions.push(function() { changeTicketType({TICKETID}, '{EXTRA_ARGS}'); } );
    });


    function loadCustomFields() {
        $('#ticketCustomFieldsFormFields').empty();
        customFields.load(0, ticketid, function(control, data) {
            customFields.defaultRenderer(control, data, 'customField_', 'ticketCustomFieldsForm', $('#ticketCustomFieldsFormFields'));
        });
    }

    function deleteTicket()
    {
        var val = confirm(lang("Click OK if you are sure you want to delete this ticket"));
        if(val){
            window.location = "index.php?fuse=support&action=DeleteTicket&ticketid={TICKETID}&sessionHash="+gHash;
        }
    }

    function ticketAdditionalNotification()
    {
        var ticketId = document.getElementById('ticketid').value;
        var ticketAdditionalNotificationId = document.getElementById('ticketAdditionalNotificationId').value;

        if(ticketId == 0){
            return;
        }
        if(ticketAdditionalNotificationId == 0){

            Ext.Ajax.request({
                url: 'index.php?fuse=support&action=AddTicketAdditionalNotification_ASync',
                params: { ticketid:ticketId},
                success: AddTicketAdditionalNotification
            });

        }else{

            Ext.Ajax.request({
                url: 'index.php?fuse=support&action=DeleteTicketAdditionalNotification_ASync',
                params: { additionalNotificationID:ticketAdditionalNotificationId},
                success: DeleteTicketAdditionalNotification
            });

        }
    }

    function AddTicketAdditionalNotification(responseObj)
    {
        var responseArr = responseObj.responseText.split('|');

        if(typeof responseArr[1] == 'undefined' || responseArr[0] != 'OK'){
            alert(responseObj.responseText);
        }else{
            document.getElementById('ticketAdditionalNotificationId').value = responseArr[1];
            $('#btnSubscribe .buttontext').text(lang("Unsubscribe"));
        }
        callTicketSummaries();
    }

    function DeleteTicketAdditionalNotification(responseObj)
    {
        if(responseObj.responseText == 'OK'){
            document.getElementById('ticketAdditionalNotificationId').value = 0;
            $('#btnSubscribe .buttontext').text(lang("Subscribe"));
        }else{
            alert(responseObj.responseText);
        }
        callTicketSummaries();
    }

    function increaseStartValue(increaseValue)
    {

         Ext.Ajax.request({
            url: 'index.php?fuse=support&action=IncreaseStartValue',
            params: { increaseValue:increaseValue},
            success: increaseStartValue_Callback
        });

    }

    function increaseStartValue_Callback(responseObj)
    {
        var responseArr = responseObj.responseText.split('|');
        if(responseArr[0] == 1){
            if(responseArr[1] == -1){
                this.location = "index.php?fuse=support&view=Admin_ViewTicketMessage&ticketID={PREVIOUS_TICKET_ID}";
            }else if(responseArr[1] == 1){
                this.location = "index.php?fuse=support&view=Admin_ViewTicketMessage&ticketID={NEXT_TICKET_ID}";
            }
        }
    }

    {TICKET_TYPE_ARRAY}
</script>


    <div id="ticketHeaderContainer" style="display: block">
           <table cellpadding='0' cellspacing='0' border='0' width="100%">
            <tr>
                <td colspan="6">
                    <div  style="width:auto;">
                        <input type="hidden" id="originalStatus" value="{TICKET_STATUS}" />
                        <input type="hidden" id="originalPriority" value="{TICKET_PRIORITY}" />
                        <input type="hidden" id="originalType" value="{TICKET_TYPE}" />
						<input type="hidden" id="originalSubject" value="{TICKET_SUBJECT}" />
                        <input type="hidden" id="ticket_owner_id" value="{TICKET_OWNER_ID}" />
                        <input type="hidden" id="originalAssignedToName" value="{TICKET_ASSIGNEE}" />
                        <input type="hidden" id="assignedToId" value="{TICKET_ASSIGNED_TO_ID}" />
                        <input type="hidden" id="userId" value="{USER_ID}" />
                        <input type="hidden" id="ticketid" name="ticketid" value="{TICKET_ID}" />
                        <input type="hidden" id="originalDomain" value="{TICKET_DOMAIN}" />

                        <div class="info_user">
                            <div class="heading_line_usr" style="margin-bottom:14px;padding-top:8px;">
                                <span class="snapshot-header-text" style="font-size:21px;">&nbsp;[l]TKT[/l] #{TICKET_HEADER_NUMBER}</span>&nbsp;&nbsp;
                                <span id="tdSubject" style="position:relative;top:-1px;font-size:21px;"><span class="{PRIORITY_COLOR}">&nbsp;{TICKET_HEADER_SUBJECT}</span></span>
                            </div><!-- CLose div.heading_line_usr -->

                            <div id="ticketdetails" style="padding-bottom:10px;display:{ticketheader_style}">

                            </div><!-- Close div.ticketdetials - part that hides on collapse-->
                        </div><!-- Close div.class.info_user -->
                    </div>

        <div id="ticketdetails-min">
            <div class="ticket-meta-data-box">
                <span style="padding-left: 3px;" class="grid-meta">
                    <strong>[l]By[/l]</strong>: {TICKET_OWNERLINK_MIN} <span style="color:#dfdfdf">|</span>
                    <strong>[l]Date[/l]</strong>: {TICKET_DATESUBMITTED} <span style="color:#dfdfdf">|</span>
                    <strong>[l]Elapsed[/l]</strong>: {TICKET_TIMEELAPSED}
                    <!-- BEGIN DYNAMIC BLOCK: packageDropdown -->
                    <span style="color:#dfdfdf">|</span>
                    <strong>[l]Package[/l]</strong>: <span id="tdDomain"> {TICKET_DOMAIN_LINK}&nbsp;&nbsp;</span><span id="ticket_packagename">{TICKET_PACKAGENAME}</span>
                    <!-- END DYNAMIC BLOCK: packageDropdown -->
                </span>
            </div>
        </div>

        <div class="ticket-header ticket-header-nocustomfields">
					      <table style="width:100%" cellpadding="0" cellspacing="0">
					      <tr>
					      <td>
						      <div class="ticket-header-block">
						         <div class="ticket-header-block-title">Department</div>
						         <div class="ticket-header-block-value"><span id="assignedtodept" class="value">{TICKET_DEPARTMENT}</a></div>
						      </div>
					      </td>
					      <td>
						      <div class="ticket-header-block">
						         <div class="ticket-header-block-title">Assigned To</div>
						         <div class="ticket-header-block-value"><span id="assignedtoname" class="value">{TICKET_ASSIGNEE_LINK}</span></div>
						      </div>
					      </td>
					      <td>
						      <div class="ticket-header-block">
						         <div class="ticket-header-block-title">Type</div>
						         <div class="ticket-header-block-value"><span id="tdType" class="value">{TICKET_TYPE_LINK}</span></div>
						      </div>
					      </td>
					      <td>
						      <div class="ticket-header-block">
						         <div class="ticket-header-block-title">Priority</div>
						         <div class="ticket-header-block-value"><span id="tdPriority" class="value" {TICKET_PRIORITYCLASS} >{TICKET_PRIORITY_LINK}</div>
						      </div>
					      </td>
					      <td>
						      <div class="ticket-header-block">
						         <div class="ticket-header-block-title">Status</div>
						         <div class="ticket-header-block-value"><span id="ticket_status_link" class="value">{TICKET_STATUS_LINK}</span></div>
						      </div>
					      </td>
					      <!-- BEGIN DYNAMIC BLOCK: ticketRate -->
					      <td>
					      	<div class="ticket-header-block">
					      		<div class="ticket-header-block-title">Rating</div>
					      		<div class="ticket-header-block-value">{TICKET_RATE}</div>
					      	</div>
					      </td>
						  <!-- END DYNAMIC BLOCK: ticketRate -->
					      </tr>
					      </table>
					</div>

        <div id="ticketdetails-customfields-min">
            <div class="ticket-meta-data-box"><span style="padding-left: 3px;" class="grid-meta"></span></div>
        </div>

                <div class="ticket-customfields">
                    <form id="ticketCustomFieldsForm" method="post">
                        <h1>[l]Ticket Custom Fields[/l] <a href="index.php?fuse=admin&view=ShowCustomFieldsTicketTypes&settings=support" qtip-s="Edit ticket custom fields" id="ticketCustomFieldsEditLink">[l]Edit[/l]</a></h1>
                        <dl class="form" id="ticketCustomFieldsFormFields"></dl>
                    	<div id="ticketCustomFieldsSubmit" style="display:none;"></div>
                    </form>
                </div>

                    <div style="position:relative;clear:both;">
                        <ul id="ajaxTabs" class="tabs" style="margin-bottom:6px;">
                            <li {viewticketmessageactive} name='tickettab' id='tickettab_messages_tab'>
                                <a href="index.php?fuse=support&view=Admin_ViewTicketMessage&ticketID={TICKETID}&email={GUEST_EMAIL}&accesscode={ACCESS_CODE}&customerId={TICKET_OWNER_ID}">Messages</a>
                            </li>

                            <!-- BEGIN DYNAMIC BLOCK: ticketeventtab -->
                            <li {viewticketeventtabactive} name='tickettab' id='tickettab_eventlog_tab'>
                                <a href="index.php?fuse=support&view=Admin_TicketEvents&ticketID={TICKETID}&email={GUEST_EMAIL}&accesscode={ACCESS_CODE}&customerId={TICKET_OWNER_ID}">Event Log</a>
                            </li>
                            <!-- END DYNAMIC BLOCK: ticketeventtab -->

                            <!-- template below used for dynamic tabs that get added after page load -->
                            <!-- BEGIN DYNAMIC BLOCK: tickettab -->
                            <li class="{TICKETTAB_CLASS}" name='tickettab' id='{TICKETTAB_ID}_tab'>
                                <a href="{TICKETTAB_URL}">{TICKETTAB_NAME}</a>
                            </li>
                            <!-- END DYNAMIC BLOCK: tickettab -->
                        </ul>
                        <div style="position:absolute; right:0; bottom:5px; border:1x solid blue">
                            <table>
                                <tr>
                                    <td>
                                        <a class="rich-button white" id="toggleCustomFields"><span class="buttontext">[l]Toggle Custom Fields[/l]</span></a>
                                    </td>
                                    <td>
                                        <a class="rich-button white" style="display:{STYLE_TICKET_NOTIFICATIONS}" id="btnSubscribe"><span class="buttontext">{TICKET_ADDITIONAL_NOTIFICATION_TITLE}</span></a><input type="hidden" id="ticketAdditionalNotificationId" value="{TICKET_ADDITIONAL_NOTIFICATION_ID}" />
</td>
                                    <!-- BEGIN DYNAMIC BLOCK: deleteTicketBtn -->
                                    <td>
                                            <a class="rich-button white" id="btnDeleteTicket"><span class="buttontext">[l]Delete[/l]</span></a>
                                    </td>
                                    <!-- END DYNAMIC BLOCK: deleteTicketBtn -->
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div id="activetickettab">
                    </div>
                </td>
            </tr>
        </table>
    </div>
