<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 Deletedept()
	{
		if(!confirm('Are you sure you want to delete this department?'))
			return false;
		document.mydept.action='index.php?fuse=support&action=DeleteDepartment'; 
		document.mydept.submit();
	}	
	
	function disableHandler(chkbox) {
		var inputs = document.mydept.elements['assign_to[]'];
		for (var i = 0; i < inputs.length; i++) {
			var input = inputs[i];
			if (chkbox.checked) {
			disableInputs(chkbox, inputs);
			}
			else {
			enableInputs(chkbox, inputs);
			}
		}
	}
	
	function disableInputs (input, inputs) {
		for (var i = 0; i < inputs.length; i++) {
		var currentInput = inputs[i];
		if (currentInput != input) {
		currentInput.disabled = true;
		currentInput.checked = false;		
		}
		}
	}
	
	function enableInputs (input, inputs) {
		for (var i = 0; i < inputs.length; i++) {
			var currentInput = inputs[i];
			if (currentInput != input) {
			currentInput.disabled = false;
			}
		}
	}
	function Deletemember()
	{
		if(!confirm('Are you sure you want to delete this member?'))
			return false;
		document.mydept.action='index.php?fuse=support&action=DeleteStaff&member={staffId}'; 
		document.mydept.submit();
	}
	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" name="mydept">
    <input type="hidden" name="departmentId" value="{departmentId}" />
    {departmentSettingsTitle}
    <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>

			<!-- BEGIN DYNAMIC BLOCK: newstaffListTable -->
		<tr>
			<td colspan="2" style="padding-top:10px">
				<table width="25%" border="0">
					<tr>
						<td><b>[l]Assign lead to department[/l]</b></td>
					</tr>
					<tr>
						<th>[l]Staff Members[/l]</th>
						<th align="center">[l]Lead[/l]</th>
					</tr>
						<!-- BEGIN DYNAMIC BLOCK: newstaffList -->
					<tr>
						<td>
							{nonstaffLabel}</td>
						<td align="center">
							<span class="formlabel"><input type="radio" name="departmentLead"  value="{nonstaffId}" {nonleadSelected}/></span>
						</td>
					</tr>
						<!-- END DYNAMIC BLOCK: newstaffList -->
				</table>
			</td>
		</tr>
			<!-- END DYNAMIC BLOCK: newstaffListTable -->

			<!-- BEGIN DYNAMIC BLOCK: nonstaffListTable -->
		<tr>
			<td colspan="2" style="padding-top:10px">
				<table width="100%" border="0">
					<tr>
						<th>[l]Staff Members[/l]</th>
						<th align="center">[l]Lead[/l]</th>
						<th align="center">[l]Assign To[/l]</th>
						<th align="center">[l]Notify New[/l]</th>
						<th align="center">[l]Notify Closed[/l]</th>
						<th align="center">[l]Feedback[/l]</th>
						<th align="center">[l]Resolution Article[/l]</th>
					</tr>
						<!-- BEGIN DYNAMIC BLOCK: staffList -->
					<tr>
						<td>
							{staffLabel}
							<input type="hidden" name="departmentAdmins[]" value="{staffId}" />						</td>
						<td align="center">
							<span class="formlabel"><input type="radio" name="departmentLead"  value="{staffId}" {leadSelected} /></span>						</td>											
						<td align="center">
							<span class="formlabel"><input type="checkbox" name="assign_to[]" value="{staffId}" {checkAssignTo} onclick="return disableHandler(this);"/></span>						</td>
						<td align="center">
							<span class="formlabel"><input type="checkbox" name="notify_to[]" value="{staffId}" {checkNotifyTo} /></span>						</td>
						<td align="center">
							<span class="formlabel"><input type="checkbox" name="sendclosed[]" value="{staffId}" {checkClosed} /></span>						</td>
						<td align="center">
							<span class="formlabel"><input type="checkbox" name="sendfeedback[]"  value="{staffId}" {checkFeedback} /></span>						</td>
						<td align="center">
							<span class="formlabel"><input type="checkbox" name="sendresolution[]"  value="{staffId}" {checkResolution} /></span>						</td>
						<td align="center">						
							<input type="submit" value="[l]Delete[/l]" onClick="return Deletemember();" class="button_medium" />						</td>												
					</tr>
						<!-- END DYNAMIC BLOCK: staffList -->
				</table>			</td>
		</tr>
			<!-- END DYNAMIC BLOCK: nonstaffListTable -->
			<!-- BEGIN DYNAMIC BLOCK: noRecordMesage -->
		<tr>	
			<td align="center" colspan="2">	
				{noRecordMesage}			</td>												
		</tr>	
			<!-- END DYNAMIC BLOCK: noRecordMesage -->	
		
		<tr>
			<td style="padding-top:10px">
				<input type="submit" value="[l]Save[/l]" class="button_medium" />			</td>
			<td style="padding-top:10px" align="right">			
				<!-- BEGIN DYNAMIC BLOCK: deleteButton -->
				<input name="submit" type="submit" class="button_xlarge" onclick="return Deletedept();" value="[l]Delete Department[/l]" />
				<!-- END DYNAMIC BLOCK: deleteButton -->			</td>
		</tr>
		<tr>
			<td class="formfield" colspan="2">&nbsp;			</td>
		</tr>	
			<!-- BEGIN DYNAMIC BLOCK: nonstaffListComment -->
		<tr>
			<td valign="top" class="formlabel" nowrap="true" colspan="2"><b>[l]Below is the list of members who do not belong to this Department[/l]:</b></td>
		</tr>
			<!-- BEGIN DYNAMIC BLOCK: nonstaffList -->
		<tr>
			<td class="formfield">
				{nonstaffLabel}			</td>
			<td class="formfield">
				<input type="submit" value="[lh]Add to Department[/lh]" onClick="this.form.action='index.php?fuse=support&action=AddStaff&member={nonstaffId}'" class="button_xlarge"  />			</td>
		</tr>
			<!-- END DYNAMIC BLOCK: nonstaffList -->
			<!-- BEGIN DYNAMIC BLOCK: nonMemberMesage -->
		<tr>
			<td class="formfield" colspan="2">
				{nonMemberMesage}			</td>
		</tr>
			<!-- END DYNAMIC BLOCK: nonMemberMesage -->		
			<!-- END DYNAMIC BLOCK: nonstaffListComment -->		
		<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>
    
    <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>
