    <script type="text/javascript">
        var newFilterIndex = 0;
        var calButtonIndex = 0;
        var searchVisible = false;

        function addFilter()
        {
            var newFilterRow = document.getElementById("filterRowTemplate").cloneNode(true);
            newFilterRow.setAttribute('id', 'filterRow_N' + newFilterIndex);
            newFilterIndex++;
            newFilterRow.style.display = isIE? 'block' : 'table-row';
            //newFilterRow.removeAttribute('style');

            // have to insert the new node into the dom before we modify it, or else things won't work out as expected.
            var newFilterRow = document.getElementById("filterTableBody").appendChild(newFilterRow);
        }

        function removeFilter(tr)
        {
            tr.parentNode.removeChild(tr);
            //newFilterIndex--;
            //if (newFilterIndex == 2) {
            //    document.getElementById("tdMatchType").style.display = "none";
            //}
        }

        function ActiveSelect(flag,tr)
        {

            if (flag == "") {
                return;
            }

            var selects = tr.getElementsByTagName("select");
            var inputs = tr.getElementsByTagName("input");
            var divs = tr.getElementsByTagName("div");
            divs[0].style.display = 'none';
            divs[1].style.display = 'none';
            for (var i = 0; i < inputs.length-1; i++) {
                inputs[i].disabled = true;
                inputs[i].style.display = 'none';
            }
            // display "remove" button
            inputs[inputs.length - 1].style.display = "";
            if(flag != ''){
                selects[1].style.display = '';
                selects[1].disabled = false;
                selects[1].options[0].text = lang('Is');
                selects[1].options[1].text = lang('Is Not');
            } else{
                selects[1].style.display = 'none';
                selects[1].disabled = true;
            }
            for (var i = 2; i < selects.length; i++) {
                if (selects[i].name == flag) {
                    selects[i].disabled = false;
                    selects[i].style.display = 'inline';
                } else {
                    selects[i].disabled = true;
                    selects[i].style.display = 'none';
                }
            }
            if (flag =="content[]"){
                inputs[0].style.display = 'inline';
                inputs[0].disabled = false;
                selects[1].options[0].text = lang('Contain');
                selects[1].options[1].text = lang('Not contain');
            }
            if (flag == "timeelapsed[]"){
                divs[0].style.display = 'inline';
                inputs[1].style.display = 'inline';
                inputs[1].disabled = false;
                selects[1].options[0].text = lang('Greater than');
                selects[1].options[1].text = lang('Less than');
            }
            if (flag == "timeSinceLastReply[]"){
                divs[1].style.display = 'inline';
                inputs[2].style.display = 'inline';
                inputs[2].disabled = false;
                selects[1].options[0].text = lang('Greater than');
                selects[1].options[1].text = lang('Less than');
            }
            document.forms['filtersForm'].search.style.opacity = 100;
            document.forms['filtersForm'].search.disabled = false;

            // show next line accepting new conditions
            //only show if we haven't already created the next node
            var currentindex = tr.id.split("_N")[1];
            var shouldbenextindex = ++currentindex;
            if(shouldbenextindex == newFilterIndex){
                if (newFilterIndex > 1) {
                    document.getElementById("tdMatchType").style.display = "";
                }
                addFilter();
            }
        }
        
        Ext.onReady(function(){
            addFilter();
        });
        
    </script>



    <form id="filtersForm" method="post" action="index.php?fuse=support&amp;action=CreateTicketFilter">
        <input type="hidden" name="sessionHash" value="<?php echo $this->gHash; ?>" />
        <table width="100%" border="0">
            <tr>
                <td>
                    <span style="padding-left:5px;"><?php echo $this->lang("Create custom filters which can be saved for future searches"); ?></span>
                    <table border="0">
                        <tbody id="filterTableBody" >
                            <tr id="filterRowTemplate" style="display:none;">
                                <td align="left">
                                    <select id="fieldId" name="fieldId[]" onchange="ActiveSelect(this.value,this.parentNode.parentNode);">
                                        <option value=''>--- <?php echo $this->lang("Select condition"); ?> ---</option>
                                        <option value='staff[]'><?php echo $this->lang("Assigned to"); ?></option>
                                        <option value='ticketstatus[]'><?php echo $this->lang("Status"); ?></option>
                                        <option value='priority[]'><?php echo $this->lang("Priority"); ?></option>
                                        <option value='type[]'><?php echo $this->lang("Ticked type"); ?></option>
                                        <option value='department[]'><?php echo $this->lang("Department"); ?></option>
                                        <option value=''>-----------------</option>
                                        <option value='timeelapsed[]'><?php echo $this->lang("Time Elapsed"); ?></option>
                                        <option value='timeSinceLastReply[]'><?php echo $this->lang("Time Since Last Reply"); ?></option>
                                    </select>
                                </td>
                                <td>
                                    <select name="condition[]" id="condition" style="display:none" disabled='disabled'>
                                        <option value="is"><?php echo $this->lang("Is"); ?></option>
                                        <option value="not"><?php echo $this->lang("Is Not"); ?></option>
                                    </select>
                                    <select name="staff[]" id="staff" style="display:none" disabled='disabled'>
                                        <option value="0"><?php echo $this->lang("Not Assigned"); ?></option>
                                        <?php
                                            foreach ($this->admins as $admin) {
                                                echo '<option value="'.$admin['staffId'].'">'.$admin['staffLabel'].'</option>';
                                            }
                                        ?>
                                    </select>
                                    <select id="ticketstatus" name="ticketstatus[]" style="display:none" disabled='disabled'>
                                        <option value="1">Open</option>
                                        <option value="2"><?php echo $this->lang("Waiting on tech"); ?></option>
                                        <option value="3"><?php echo $this->lang("Waiting on customer"); ?></option>
                                        <option value="-1"><?php echo $this->lang("Closed"); ?></option>
                                    </select>
                                    <select name="priority[]" id="priority" style="display:none" disabled='disabled'>
                                        <option value="3"><?php echo $this->lang("Low"); ?></option>
                                        <option value="2"><?php echo $this->lang("Medium"); ?></option>
                                        <option value="1"><?php echo $this->lang("High"); ?></option>
                                    </select>
                                    <select name="type[]" id="type" style="display:none" disabled='disabled'>
                                        <?php
                                            foreach ($this->types as $type) {
                                                echo '<option value="'.$type['typeId'].'">'.$type['typeLabel'].'</option>';
                                            }
                                        ?>
                                    </select>
                                    <select name="department[]" id="department" style="display:none" disabled='disabled'>
                                        <option value="-1">-----</option>
                                        <?php
                                            foreach ($this->departments as $departments) {
                                                echo '<option value="'.$departments['depId'].'">'.$departments['depLabel'].'</option>';
                                            }
                                        ?>
                                    </select>
                                    <input name="content[]" id="content" size="26" value="" style="display:none" disabled='disabled' />
                                    <div id="telapsed" style="display:none">
                                        <input name="timeelapsed[]" id="timeelapsed" size="4" value="3" style="display:none" disabled='disabled'/> <?php echo $this->lang("Hours"); ?>
                                    </div>
                                    <div id="telapsedLastReply" style="display:none">
                                        <input name="timeSinceLastReply[]" id="timeSinceLastReply" size="4" value="3" style="display:none" disabled='disabled'/> <?php echo $this->lang("Hours"); ?>
                                    </div>
                                </td>
                                <td>&nbsp;&nbsp;<input type="button" class="button_medium" name="remove" value="<?php echo $this->lang("remove");?>" onclick="removeFilter(this.parentNode.parentNode)" style="display:none" /></td>
                            </tr>
                        </tbody>
                    </table>
                    <table>
                        <tr>
                            <td id="tdMatchType" style="display:none"><span style="padding-left:2px;"><?php echo $this->lang("Match type"); ?></span>:
                                <select name="match" id="match">
                                    <option value="AND" selected="selected"><?php echo $this->lang("Against all conditions (AND)"); ?>&nbsp;&nbsp;&nbsp;</option>
                                    <option value="OR"><?php echo $this->lang("Against any condition (OR)"); ?>&nbsp;&nbsp;&nbsp;</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input name="search" type="submit" class="search-button" value="<?php echo $this->lang("Search");?>" disabled='disabled' style="opacity: 0.4;" />&nbsp;&nbsp;
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>