<script type="text/javascript">
    function deleteRoutingRule(routingId)
    {
        new Ajax.Request(   'index.php?fuse=support&action=DeleteRoutingRule&ajax=1',
                            {
                               parameters   : 'routingId=' + routingId,
                               onLoading    : function(){resetStatus(lang('Deleting'))},
                               onComplete   : completeDeleteRoutingRule
                            }
        );
    }

    function completeDeleteRoutingRule(responseObj)
    {
        unsetStatus(false);

        var responseArr = responseObj.responseText.split('|');
        if (responseArr[0] == 1) {
            new Effect.Fade('routingrule_' + responseArr[1]);
        }
    }

	function toggleRoutingRules(){
		if($("departmentrules").style.display == "block"){
			$("departmentrules").style.display = "none";
		}else{
			$("departmentrules").style.display = "block";
		}
	}

    function deleteOutcomingEscalationRule(ruleId)
    {
        new Ajax.Request(   'index.php?fuse=support&action=DeleteEscalation&ajax=1',
                            {
                               parameters   : 'escalationId=' + ruleId,
                               onLoading    : function(){resetStatus(lang('Deleting'))},
                               onComplete   : completeDeleteOutcomingEscalationRule
                            }
        );
    }

    function completeDeleteOutcomingEscalationRule(responseObj)
    {
        unsetStatus(false);

        var responseArr = responseObj.responseText.split('|');
        if (responseArr[0] == 1) {
            new Effect.Fade('outcomingEscalation_' + responseArr[1]);
        }
    }

    function deleteIncomingEscalationRule(ruleId)
    {
        new Ajax.Request(   'index.php?fuse=support&action=DeleteEscalation&ajax=1',
                            {
                               parameters   : 'escalationId=' + ruleId,
                               onLoading    : function(){resetStatus(lang('Deleting'))},
                               onComplete   : completeDeleteIncomingEscalationRule
                            }
        );
    }

    function completeDeleteIncomingEscalationRule(responseObj)
    {
        unsetStatus(false);

        var responseArr = responseObj.responseText.split('|');
        if (responseArr[0] == 1) {
            new Effect.Fade('incomingEscalation_' + responseArr[1]);
        }
    }
</script>
<!-- BEGIN DYNAMIC BLOCK: generalDepNotice -->
<div class="yellowbox" style="margin-bottom:5px">
    <h2>[l]NOTICE[/l]:</h2>
    [l]All members belong to the Department General, and this department can't be erased.[/l]
</div>
<!-- END DYNAMIC BLOCK: generalDepNotice -->
<form method="post" action="index.php?fuse=support&action=SaveDepartment">
    <input type="hidden" name="departmentId" value="{departmentId}" />
    {departmentSettingsTitle}
    <table width="100%" border="0">
        <tr>
            <td width="400" valign="top">
                <table width="100%" border="0">
                    <tr>
                        <td colspan="2" class="formfield" style="padding:5px 0">
                            <b>[l]Department Settings[/l]</b>
                        </td>
                    </tr>
                    <tr class="even">
                        <td align="right" class="formlabel" width="1%" nowrap="true">[l]Name[/l]:</td>
                        <td class="formfield"><input type="text" name="name" value="{departmentName}" size="35" /></td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" class="formlabel" nowrap="true">[l]Group members[/l]:</td>
                        <td class="formfield">
                            <select name="departmentGroups[]" multiple="true" size="5" {groupMembersDisabled}>
                            <!-- BEGIN DYNAMIC BLOCK: groupsList -->
                                <option value="{groupId}" {groupSelected} >{groupLabel}</option>
                            <!-- END DYNAMIC BLOCK: groupsList -->
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" valign="top" class="formlabel" nowrap="true">[l]Staff members[/l]:</td>
                        <td class="formfield">
                            <select name="departmentAdmins[]" multiple="true" size="5">
                            <!-- BEGIN DYNAMIC BLOCK: staffList -->
                                <option value="{staffId}" {staffSelected} >{staffLabel}</option>
                            <!-- END DYNAMIC BLOCK: staffList -->
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="padding-top:10px">
                            <input type="submit" value="[l]Save[/l]" class="button_medium" />&nbsp;&nbsp;
                            <!-- BEGIN DYNAMIC BLOCK: deleteButton -->
                            <input type="submit" value="[l]Delete[/l]" onclick="this.form.action='index.php?fuse=support&action=DeleteDepartment'" class="button_medium" />
                            <!-- END DYNAMIC BLOCK: deleteButton -->
                        </td>
                    </tr>
                    <tr>
                    <td colspan="2">
                    	<!-- BEGIN DYNAMIC BLOCK: toggleRules -->
                    	<div style="padding-top:10px;">
                    	<a href="#" onclick="toggleRoutingRules();">[l]Toggle Advanced Rules[/l]</a>
                    	</div>
                    	<!-- END DYNAMIC BLOCK: toggleRules -->
                    </tr>
                </table>
            </td>      
            <td valign="top" width="100%">
				<table width="100%" border="0">
                    <tr>
                        <td><span class="formlabel">[l]Department Lead[/l]{leadLabelHelp}:</span>
                        <span class="formfield">
                            <select name="departmentLead">
                            <!-- BEGIN DYNAMIC BLOCK: staffListLead -->
                                <option value="{staffId}" {leadSelected} >{staffLabel}</option>
                            <!-- END DYNAMIC BLOCK: staffListLead -->
                            </select>
                        </span></td>
                    </tr>				
                    <tr>
						<td><span class="formlabel"><input type="checkbox" name="assign_to_lead" {checkAssignToLead} /></span>                    
                        <span class="formfield">[l]When ticket is assigned or escalated to the department, assign to lead[/l]</span></td>                        
                    </tr>
                    <tr>
						<td><span class="formlabel"><input type="checkbox" name="notify_lead" {checkNotifyLead} /></span>                    
                        <span class="formfield">[l]When ticket is assigned or escalated to the department, notify lead[/l]</span></td>                        
                    </tr>
                    <tr>
						<td><span class="formlabel"><input type="checkbox" name="sendclosed" {checkClosed} /></span>                    
                        <span class="formfield">[l]Send closed tickets to lead[/l]</span></td>                        
                    </tr>
                    <tr>
						<td><span class="formlabel"><input type="checkbox" name="sendfeedback" {checkFeedback} /></span>                    
                        <span class="formfield">[l]Send customer feedback to lead[/l]</span></td>                                               
                    </tr>
                    <tr>
						<td><span class="formlabel"><input type="checkbox" name="sendresolution" {checkResolution} /></span>                    
                        <span class="formfield">[l]Send ticket resolution articles to lead[/l]</span></td>                                                
                    </tr>				
                    <tr>
						<td>
                            <span class="formlabel">[l]When ticket is assigned or escalated to the department, also notify this list[/l]{helpNotificationList}:</span><br />
                            <span class="formfield"><textarea name="notification_list" class="smallTextarea" rows="3">{notificationList}</textarea></span>
                        </td>
                    </tr>
				</table>            
            </td>
        </tr>
    </table>
    
    <div id="departmentrules" style="display:none">
    <table width="100%">
    <tr>
            <!-- BEGIN DYNAMIC BLOCK: applicableRules -->
            <td valign="top">
                <table width="100%" border="0" style="border-left:1px solid rgb(170, 170, 170); border-bottom:1px solid rgb(170, 170, 170)">
                    <tr>
                        <td class="formfield" style="padding:5px 0">
                            <b>[l]Applicable E-mail Routing Rules[/l]</b>
                        </td>
                    </tr>
                    <!-- BEGIN DYNAMIC BLOCK: routingRule -->
                    <tr id="routingrule_{routingRuleId}">
                        <td>
                            <table width="100%" border="0" cellspacing="0">
                                <tr class="trClass">
                                    <td>
                                        <ul>
                                            <li>
                                                {routingRuleName}:
                                                <ul>
                                                    <li>[l]Messages sent to the E-mails:[/l]{emails}:</li>
                                                    <li>[l]Routing type:[/l] {method}</li>
                                                    <!-- BEGIN DYNAMIC BLOCK: emailRoutingSendCopy -->
                                                    <li>[l]Send copy to[/l] {sendCopyTo}</li>
                                                    <!-- END DYNAMIC BLOCK: emailRoutingSendCopy -->
                                                </ul>
                                            </li>
                                        </ul>
                                    </td>
                                    <td valign="top" align="right" nowrap="true">
                                        <a href="index.php?fuse=support&view=AddEditEmailRouting&routing={routingRuleId}&returnToDept={departmentId}">[l]edit[/l]</a> |
                                        <a href="#" onclick="deleteRoutingRule({routingRuleId})">[l]delete[/l]</a>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: routingRule -->
                    <!-- BEGIN DYNAMIC BLOCK: noRoutingRules -->
                    <tr>
                        <td>[l]There are no rules applicable for this department[/l]</td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: noRoutingRules -->
                    <tr>
                        <td colspan="2" align="right">
                            <input type="button" value="[l]Add new[/l]" class="button_medium" onclick="location.href='index.php?fuse=support&view=AddEditEmailRouting&returnToDept={departmentId}'" />
                        </td>
                    </tr>
                </table>
                <table width="100%" border="0" style="margin-top:5px; border-left:1px solid rgb(170, 170, 170); border-bottom:1px solid rgb(170, 170, 170)">
                    <tr>
                        <td class="formfield" style="padding:5px 0">
                            <b>[l]Applicable Escalation Rules for Tickets Belonging to this Department[/l]</b>
                        </td>
                    </tr>
                    <!-- BEGIN DYNAMIC BLOCK: outcomingEscalationRule -->
                    <tr id="outcomingEscalation_{escalationId}">
                        <td>
                            <table width="100%" border="0" cellspacing="0">
                                <tr class="{trClass}">
                                    <td>
                                        <ul>
                                            <li>    
                                                [l]For departments[/l] <b>{depEscRuleDepList}</b><br/>
                                                [l]After[/l] <b>{hoursElapsed}</b> [l]hours since opened[/l]{priority}:
                                                <ul>
                                                    <!-- BEGIN DYNAMIC BLOCK: reassignTicketToDep -->
                                                    <li>[l]Reassign to department[/l] <b>{reassignDepName}</b></li>
                                                    <!-- END DYNAMIC BLOCK: reassignTicketToDep -->
                                                    <!-- BEGIN DYNAMIC BLOCK: reassignTicketToStaff -->
                                                    <li>Reassign to staff member <b>{reassignStaffName}</b></li>
                                                    <!-- END DYNAMIC BLOCK: reassignTicketToStaff -->
                                                    <!-- BEGIN DYNAMIC BLOCK: reassignTicketChangePriority -->
                                                    <li>Change priority to <b>{newPriority}</b></li>
                                                    <!-- END DYNAMIC BLOCK: reassignTicketChangePriority -->
                                                </ul>
                                            </li>
                                        </ul>
                                    </td>
                                    <td valign="top" align="right" nowrap="true">
                                        <a href="index.php?fuse=support&view=AddEditEscalation&escalation={escalationId}&origDepId={departmentId}">[l]edit[/l]</a> |
                                        <a href="#" onclick="deleteOutcomingEscalationRule({escalationId})" >[l]delete[/l]</a>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: outcomingEscalationRule -->
                    <!-- BEGIN DYNAMIC BLOCK: noOutcomingEscalationRules -->
                    <tr>
                        <td>[l]There are no escalation rules originating from this department[/l]</td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: noOutcomingEscalationRules -->
                    <tr>
                        <td colspan="2" align="right">
                            <input type="button" value="[l]Add new[/l]" class="button_medium" onclick="location.href='index.php?fuse=support&view=AddEditEscalation&origDepId={departmentId}'" />
                        </td>
                    </tr>
                </table>
                <table width="100%" border="0" style="margin-top:5px; border-left:1px solid rgb(170, 170, 170); border-bottom:1px solid rgb(170, 170, 170)">
                    <tr>
                        <td class="formfield" style="padding:5px 0">
                            <b>[l]Applicable Escalation Rules for Tickets Escalated to this Department[/l]</b>
                        </td>
                    </tr>
                    <!-- BEGIN DYNAMIC BLOCK: incomingEscalationRule -->
                    <tr id="incomingEscalation_{escalationId}">
                        <td>
                            <table width="100%" border="0" cellspacing="0">
                                <tr class="{trClass}">
                                    <td>
                                        <ul>
                                            <li>    
                                                For department <b>Pre-Sales</b><br/>
                                                After <b>1000</b> hours since opened:
                                                <ul>
                                                    <li>Change priority to <b>Medium</b></li>
                                                </ul>
                                            </li>
                                        </ul>
                                    </td>
                                    <td valign="top" align="right" nowrap="true">
                                        <a href="index.php?fuse=support&view=AddEditEscalation&escalation={escalationId}&targetDepId={departmentId}">[l]edit[/l]</a> |
                                        <a href="#" onclick="deleteIncomingEscalationRule({escalationId})">[l]delete[/l]</a>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: incomingEscalationRule -->
                    <!-- BEGIN DYNAMIC BLOCK: noIncomingEscalationRules -->
                    <tr>
                        <td>[l]There are no escalation rules targeting this department[/l]</td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: noIncomingEscalationRules -->
                    <tr>
                        <td colspan="2" align="right">
                            <input type="button" value="[l]Add new[/l]" class="button_medium" onclick="location.href='index.php?fuse=support&view=AddEditEscalation&targetDepId={departmentId}'" />
                        </td>
                    </tr>
                </table>
            </td>
            <!-- END DYNAMIC BLOCK: applicableRules -->    
    </tr>
    </table>
   </div>
    
</form>
