<%
"use strict";

import "/js/utility.js"
import "/tv/js/constants.js"
import "/tv/js/tvutil.qjs"

    var myth = new Myth();
    var dvr = new Dvr();
    var guide = new Guide();
    var rtti = new Rtti();

    var startTime = new Date();
    if (getArg("StartTime"))
        startTime = myth.ParseISODateString(getArg("StartTime"));

    var chanId = 0;
    if (getIntegerArg("ChanId"))
        chanId = getIntegerArg("ChanId");

    var recordedId = 0;
    if (getIntegerArg("RecordedId"))
        recordedId = getIntegerArg("RecordedId");

    var recRuleId = 0;
    if (getIntegerArg("RecRuleId"))
        recRuleId = getIntegerArg("RecRuleId");

    var recRule = dvr.GetRecordSchedule(recRuleId, "", recordedId, chanId, startTime, false);

    if (chanId <= 0)
        chanId = recRule.ChanId;
    if (recordedId > 0)
    {
        chanId = recRule.ChanId;
        startTime = recRule.StartTime;
    }

    var inputList = dvr.GetInputList().Inputs;
    var storageGroupList = dvr.GetRecStorageGroupList();
    var playGroupList = dvr.GetPlayGroupList();
    var recGroupList = dvr.GetRecGroupList();
    var filterList = dvr.GetRecRuleFilterList().RecRuleFilters;
    //var transcoderList = dvr.GetTranscodeProfileList();

    var program = guide.GetProgramDetails(chanId, startTime);
    var channel = program.Channel;

    if (channel.ChanId == 0 && chanId > 0)
    {
        var channelService = new Channel();
        channel = channelService.GetChannelInfo(chanId);
    }

    var upcomingShowings = [];
    var upcomingConflicts = [];
    if (recRule.Id > 0)
    {
        upcomingShowings = dvr.GetUpcomingList(0, 5, true, recRule.Id, 0).Programs; // Next 5 showings
        upcomingConflicts = dvr.GetConflictList(0, 5, recRule.Id).Programs; // Next 5 conflicts
    }

    var cast = new Object;
    if (isValidObject(program))
    {
        var castList = program.Cast.CastMembers;

        for (var idx = 0; idx < castList.length; idx++)
        {
            if (!cast[castList[idx].TranslatedRole])
                cast[castList[idx].TranslatedRole] = "";
            else
                cast[castList[idx].TranslatedRole] += ", ";

            cast[castList[idx].TranslatedRole] += castList[idx].Name;
        }

        var duration = program.EndTime - program.StartTime;

        program.Duration = "";
        program.Duration += Math.floor(duration / 1000 / 60 / 60) > 0 ? Math.floor(duration / 1000 / 60 / 60) + "hr " : "";
        program.Duration += (Math.floor(duration / 1000 / 60) % 60) > 0 ? (Math.floor(duration / 1000 / 60) % 60) + "m" : "";
    }

%>
<link rel="stylesheet" type="text/css" href="/3rdParty/jquery/jqueryUI/css/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="/css/site.css">
<link rel="stylesheet" type="text/css" href="/tv/css/common.css">
<link rel="stylesheet" type="text/css" href="/css/settings.css">
<link rel="stylesheet" type="text/css" href="/tv/css/schedule.css">
<script src="/js/utility.js"></script> <!-- ECMA not JS -->
<script type="text/javascript" src="/3rdParty/jquery/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="/3rdParty/jquery/jqueryUI/js/jquery-ui-1.10.3.js"></script>
<script src="/js/settings.js"></script>
<script src="/tv/js/common.js"></script>
<script src="/tv/js/schedule.js"></script>

<!-- Popup Program Details Box -->
<div id="programDetails" class="programExDetail" style="display:none;">
</div>

<div class="notifyPopup" id="saveFormDataSuccess">
    <%=qsTr("Changes Saved")%>
</div>

<div class="notifyPopup" id="saveFormDataError">
    <%=qsTr("Save Failed!")%>
</div>

<div style="border:1px #CC0000 solid;background-color: rgba(102, 0, 0, 0.7);padding:7px;margin:5px;text-align:center;">
    This feature is in beta and is missing some functionality. Please report any bugs you encounter ...
</div>

<div class="header">
    <div class="headerChannel">
        <%if (channel.ChanId > 0 && channel.IconURL) {%><img class="channelIcon" height="70" alt="<%=escapeHTML(channel.ChannelName)%> Icon" title="<%=escapeHTML(channel.ChannelName)%>" src="<%=channel.IconURL%>&amp;Height=70" /><%}%>
        <!-- <%=escapeHTML(recRule.CallSign)%> -->
        <!-- <%=chanId%> <%=recRule.ChanId%> <%=channel.ChanId%> -->
    </div>

    <div class="headerTitle">
        <span class="recRuleTitle"><%=escapeHTML(recRule.Title)%></span>
        <span class="recRuleSubTitle"><%=escapeHTML(recRule.SubTitle)%></span>
        <span class="recRuleStartTime"><%=myth.GetFormatDate(recRule.StartTime)%>, <%=myth.GetFormatTime(recRule.StartTime)%> - <%=myth.GetFormatTime(recRule.EndTime)%></span>
    </div>

</div>

<div id="scheduleEditor">
  <ul>
    <li><a href="#page-1"><%=qsTr("Details")%></a></li>
    <li><a href="#page-2"><%=qsTr("Schedule Options")%></a></li>
    <li><a href="#page-3"><%=qsTr("Filters")%></a></li>
    <li><a href="#page-4"><%=qsTr("Storage Options")%></a></li>
    <li><a href="#page-5"><%=qsTr("Post Processing")%></a></li>
    <li><a href="#page-6"><%=qsTr("Metadata Options")%></a></li>
  </ul>
  <form action="/tv/ajax_backends/dvr_util.qsp" autocomplete="on">
    <input type="hidden" name="_action" value="saveRecordingRule">
    <input type="hidden" name="Id" id="rule-Id" value="<%=recRule.Id%>">
    <input type="hidden" name="Title" value="<%=recRule.Title%>">
    <input type="hidden" name="SubTitle" value="<%=recRule.SubTitle%>">
    <input type="hidden" name="Description" value="<%=recRule.Description%>">
    <input type="hidden" name="Category" value="<%=recRule.Category%>">
    <input type="hidden" name="StartTime" value="<%=recRule.StartTime.toISOString()%>">
    <input type="hidden" name="EndTime" value="<%=recRule.EndTime.toISOString()%>">
    <input type="hidden" name="SeriesId" value="<%=recRule.SeriesId%>">
    <input type="hidden" name="ProgramId" value="<%=recRule.ProgramId%>">
    <input type="hidden" name="ChanId" value="<%=recRule.ChanId%>">
    <input type="hidden" name="CallSign" value="<%=recRule.CallSign%>">
    <div id="page-1"> <!-- Program/Rule Details -->
        <div class="recRuleDetails">

            <div class="recRuleDescription">
                <%=escapeHTML(recRule.Description)%>
            </div>

            <% if (isValidObject(program)) { %>
            <!-- <div class="programDetails"> -->
                <div class="programSeasonEpisode">
                    <% if (program.Season > 0) { %>
                        <span class="label"><%=qsTr("Season")%>:</span> <span class="value"><%=program.Season%></span>
                    <% } %>
                    <% if (program.Episode > 0) { %>
                        <span class="label"><%=qsTr("Episode")%>:</span> <span class="value"><%=program.Episode%>
                        <% if (program.TotalEpisodes > 0) { %> / <%=program.TotalEpisodes%> <% } %>
                    <% } %>
                    </span>
                </div>

                <div class="programCast">
                <% for (var role in cast)
                   {
                %>
                    <p><span class="label"><%=role%>:</span> <span class="value"><%=cast[role]%></span></p>
                <% } %>
                </div>

                <div class="programDuration">
                    <span class="label"><%=qsTr("Duration")%>:</span> <span class="value"><%=program.Duration%></span>
                </div>

                <div class="programCategory">
                    <span class="label"><%=qsTr("Category")%>:</span> <span class="value"><%=toCapitalCase(program.Category)%></span>
                </div>
            <!-- </div> -->
            <%}%>

            <div class="upcomingShowings" id="upcomingShowings">
                <span class="label"><%=qsTr("Next 5 Showings")%>:</span>
                <div id="upcomingShowingsList">
                <%  if (upcomingShowings.length == 0)
                    {
                %>
                        <div><%=qsTr("No Upcoming Showings")%></div>
                <%  }

                    for (var listIdx = 0; listIdx < upcomingShowings.length; listIdx++)
                    {
                        showing = upcomingShowings[listIdx];
                        // RecStatusToClass() - /tv/js/tvutil.qjs
                        var statusClass = RecStatusToClass(showing.Recording.Status);
                        //var statusClass = rtti.GetEnum( "RecStatus::Type" ).EnumItems[ showing.Recording.Status ].Value;
                        var programIdentifier = showing.Channel.ChanId + "_" + showing.StartTime.toISOString();
                        var showingChannelIcon = "/tv/images/channel_icon.svg";
                        if (showing.Channel.IconURL)
                            showingChannelIcon = showing.Channel.IconURL + "&amp;Height=45";
                %>
                        <div class="upcomingShowing">
                            <div class="channelIconBox">
                                <img class="channelIcon" height="45" alt="<%=escapeHTML(showing.Channel.ChannelName)%> Icon" title="<%=escapeHTML(showing.Channel.ChanNum)%> <%=escapeHTML(showing.Channel.ChannelName)%>" src="<%=showingChannelIcon%>" lazyload />
                            </div>
                            <div class="programBox <%=statusClass%>" id="<%=programIdentifier%>" data-chanid="<%=showing.Channel.ChanId%>" data-starttime="<%=showing.StartTime.toISOString()%>" onMouseOver="startDetailTimer(this, 'program');" onMouseOut="hideDetail(this);">
                                <div class="programHeader"><span class="programTitle"><%=showing.Title%></span><span class="programDateTime"><%=myth.GetFormatDate(showing.StartTime)%>, <%=myth.GetFormatTime(showing.StartTime)%> - <%=myth.GetFormatTime(showing.EndTime)%></span></div>
                                <div class="programBody"><span class="programSubtitle"><%=showing.SubTitle%></span><span class="programRecordingStatus"><%=dvr.RecStatusToString(showing.Recording.Status)%></span></div>
                            </div>
                        </div>
                <%  } %>
                </div>
            </div>

            <div class="upcomingConflicts" id="upcomingConflicts">
                <span class="label"><%=qsTr("Next 5 Conflicts")%>:</span>
                <div id="upcomingConflictsList">
                <%  if (upcomingConflicts.length == 0)
                    {
                %>
                        <div><%=qsTr("No Conflicts")%></div>
                <%  }

                    for (var listIdx = 0; listIdx < upcomingConflicts.length; listIdx++)
                    {
                        conflict = upcomingConflicts[listIdx];
                        // RecStatusToClass() - /tv/js/tvutil.qjs
                        var statusClass = RecStatusToClass(conflict.Recording.Status);
                        var programIdentifier = conflict.Channel.ChanId + "_" + conflict.StartTime.toISOString();
                        var conflictChannelIcon = "/tv/images/channel_icon.svg";
                        if (conflict.Channel.IconURL)
                            conflictChannelIcon = conflict.Channel.IconURL + "&amp;Height=45";
                %>
                        <div class="upcomingConflict">
                            <div class="channelIconBox">
                                <img class="channelIcon" height="45" alt="<%=escapeHTML(conflict.Channel.ChannelName)%> Icon" title="<%=escapeHTML(conflict.Channel.ChanNum)%> <%=escapeHTML(conflict.Channel.ChannelName)%>" src="<%=conflictChannelIcon%>" lazyload />
                            </div>
                            <div class="programBox <%=statusClass%>" id="<%=programIdentifier%>" data-chanid="<%=conflict.Channel.ChanId%>" data-starttime="<%=conflict.StartTime.toISOString()%>" onMouseOver="startDetailTimer(this, 'program');" onMouseOut="hideDetail(this);">
                                <div class="programHeader"><span class="programTitle"><%=conflict.Title%></span><span class="programDateTime"><%=myth.GetFormatDate(conflict.StartTime)%>, <%=myth.GetFormatTime(conflict.StartTime)%> - <%=myth.GetFormatTime(conflict.EndTime)%></span></div>
                                <div class="programBody"><span class="programSubtitle"><%=conflict.SubTitle%></span><span class="programRecordingStatus"><%=dvr.RecStatusToString(conflict.Recording.Status)%></span></div>
                            </div>
                        </div>
                <%  } %>
                </div>
            </div>
            <div style="clear:both;"> <!-- Prevent parent collapsing because of floats --> </div>
        </div>
    </div> <!-- End Program/Rule Details -->
    <div id="page-2"> <!-- Schedule Options -->
        <fieldset>

    <!-- Recording Rule Type -->
        <div class="setting setting-select">
            <label for="rule-Type"><%=qsTr("Rule Type")%>:</label>
            <select name="Type" id="rule-Type" autofocus required>
            <% for (var name in RecordingType)
               {
                    if (RecordingType[name] == RecordingType.NOTRECORDING)
                        continue;
                    if (RecordingType[name] == RecordingType.OVERRIDERECORD)
                        break;

                    var selected = (RecordingType[name] == recRule.Type) ? "selected" : "";
            %>
                <option value="<%=RecordingType[name]%>" <%=selected%>><%=dvr.RecTypeToDescription(RecordingType[name])%></option>
            <% } %>
            </select>
        </div>

    <!-- Recording Priority -->
        <div class="setting setting-range">
            <label for="rule-RecPriority"><%=qsTr("Priority")%>:</label>
            <span>-99</span>
            <input type="range" name="RecPriority" id="rule-RecPriority" value="<%=recRule.RecPriority%>" min="-99" max="99" onmousemove="MythSettings.UpdateRangeValue(this)" onChange="MythSettings.UpdateRangeValue(this)" required>
            <span>99</span>
            <output name="RecPriority-Value" id="rule-RecPriority-Value" for="range"><%=recRule.RecPriority%></output>
        </div>

    <!-- Start Time Offset -->
        <div class="setting setting-range">
            <label for="rule-StartOffset"><%=qsTr("Start Early/Late")%>:</label>
            <span>-240</span>
            <input type="range" name="StartOffset" id="rule-StartOffset" value="<%=recRule.StartOffset%>" min="-240" max="240" onmousemove="MythSettings.UpdateRangeValue(this)" onChange="MythSettings.UpdateRangeValue(this)" required>
            <span>240</span>
            <output name="rangeValue" id="rule-StartOffset-Value" for="range"><%=recRule.StartOffset%></output> <%=qsTr("Minutes")%>
        </div>

    <!-- End Time Offset -->
        <div class="setting setting-range">
            <label for="rule-EndOffset"><%=qsTr("End Early/Late")%>:</label>
            <span>-240</span>
            <input type="range" name="EndOffset" id="rule-EndOffset" value="<%=recRule.EndOffset%>" min="-240" max="240" onmousemove="MythSettings.UpdateRangeValue(this)" onChange="MythSettings.UpdateRangeValue(this)" required>
            <span>240</span>
            <output name="EndOffset-Value" id="rule-EndOffset-Value" for="range"><%=recRule.EndOffset%></output> <%=qsTr("Minutes")%>
        </div>

    <!-- Duplicate Check Method -->
        <div class="setting setting-select">
            <label for="rule-DupMethod"><%=qsTr("Duplicate Matching")%>:</label>
            <select name="DupMethod" id="rule-DupMethod" required>
            <% for (var name in RecordingDupMethodType)
               {
                   var selected = (RecordingDupMethodType[name] == recRule.DupMethod) ? "selected" : "";
            %>
                <option value="<%=RecordingDupMethodType[name]%>" <%=selected%>><%=dvr.DupMethodToDescription(RecordingDupMethodType[name])%></option>
            <% } %>
            </select>
        </div>

    <!-- Look for duplicates in ... -->
        <div class="setting setting-select">
            <label for="rule-DupIn">&nbsp;</label>
            <select name="DupIn" id="rule-DupIn" required>
            <% for (var name in RecordingDupInType)
               {
                   var selected = (RecordingDupInType[name] == recRule.DupIn) ? "selected" : "";
            %>
                <option value="<%=RecordingDupInType[name]%>" <%=selected%>><%=dvr.DupInToDescription(RecordingDupInType[name])%></option>
            <% } %>
            </select>
        </div>


    <!-- Preferred Input -->
        <div class="setting setting-select">
            <label for="rule-PreferredInput"><%=qsTr("Input")%>:</label>
            <select name="PreferredInput" id="rule-PreferredInput" required>
                <option value="0"><%=qsTr("Use any available Input")%></option>
            <% for (var idx = 0; idx < inputList.length; idx++)
               {
                   var selected = (inputList[idx].id == recRule.PreferredInput) ? "selected" : "";
            %>
                <option value="<%=inputList[idx].id%>" <%=selected%>>Prefer input <%=inputList[idx].DisplayName%></option>
            <% } %>
            </select>
        </div>

    <!-- Rule Active/Inactive -->
        <div class="setting setting-toggle">
            <span>Enabled</span>
            <div class="setting-toggle-background">
                <input type="range" name="Inactive" id="rule-Inactive" value="<%=recRule.Inactive ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Disabled</span>
        </div>

    <!-- Save -->
        <div class="setting setting-button">
            <button type="button"  name="Save" onClick="saveRecordingSchedule(this.form);"><%=qsTr("Save Changes")%></button>
        </div>

        </fieldset>
    </div>  <!-- End Schedule Options -->
    <div id="page-3"> <!-- Filters -->
        <fieldset>
<%
    for (var idx = 0; idx < filterList.length; idx++)
    {
%>
        <div class="setting setting-toggle">
            <label for="rule-Filter[_<%=filterList[idx].Id%>]"><%=escapeHTML(filterList[idx].Description)%>:</label>
            <span>Disabled</span>
            <div class="setting-toggle-background">
                <input type="range" name="Filter[_<%=filterList[idx].Id%>]" id="rule-Filter-<%=filterList[idx].Id%>" value="<%=(recRule.Filter & (1 << filterList[idx].Id)) ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Enabled</span>
        </div>
<%
    }
%>
    <!-- Save -->
        <div class="setting setting-button">
            <button type="button"  name="Save" onClick="saveRecordingSchedule(this.form);"><%=qsTr("Save Changes")%></button>
        </div>

        </fieldset>
    </div> <!-- Filters -->
    <div id="page-4"> <!-- Storage Options -->
        <fieldset>
    <!-- Profile -->
    <!-- Let's disable this and see how many people notice, Recording Profiles
         are increasingly irrelevant with digital tuners and increased disk
         capacity and the code behind them is a complete mess -->
<!--         <div class="setting setting-select">
            <label for="rule-RecProfile"><%=qsTr("Recording Profile")%>:</label>
            <select name="RecProfile" id="rule-RecProfile" required>
                <option value="Default"><%=qsTr("Default")%></option>
                <option value="LiveTV"><%=qsTr("LiveTV")%></option>
                <option value="High Quality"><%=qsTr("High Quality")%></option>
                <option value="Low Quality"><%=qsTr("Low Quality")%></option>
            </select>
        </div> -->

    <!-- Rec Group -->
        <div class="setting setting-select">
            <label for="rule-RecGroup"><%=qsTr("Recording Group")%>:</label>
            <select name="RecGroup" id="rule-RecGroup" required>
            <% for (var idx = 0; idx < recGroupList.length; idx++)
               {
                   var selected = (recGroupList[idx] == recRule.RecGroup) ? "selected" : "";
            %>
                <option value="<%=recGroupList[idx]%>" <%=selected%>><%=recGroupList[idx]%></option>
            <% } %>
            </select>
        </div>

    <!-- Storage Group -->
        <div class="setting setting-select">
            <label for="rule-StorageGroup"><%=qsTr("Storage Group")%>:</label>
            <select name="StorageGroup" id="rule-StorageGroup" required>
            <% for (var idx = 0; idx < storageGroupList.length; idx++)
               {
                   var selected = (storageGroupList[idx] == recRule.StorageGroup) ? "selected" : "";
            %>
                <option value="<%=storageGroupList[idx]%>" <%=selected%>><%=storageGroupList[idx]%></option>
            <% } %>
            </select>
        </div>

    <!-- Playback Group -->
        <div class="setting setting-select">
            <label for="rule-PlayGroup"><%=qsTr("Playback Group")%>:</label>
            <select name="PlayGroup" id="rule-PlayGroup" required>
                <option value="Default"><%=qsTr("Default")%></option>
            <% for (var idx = 0; idx < playGroupList.length; idx++)
               {
                   var selected = (playGroupList[idx] == recRule.PlayGroup) ? "selected" : "";
            %>
                <option value="<%=playGroupList[idx]%>" <%=selected%>><%=playGroupList[idx]%></option>
            <% } %>
            </select>
        </div>

    <!-- Episode Limit -->
        <div class="setting setting-range">
            <label for="rule-MaxEpisodes"><%=qsTr("Episode Limit")%>:</label>
            <span>No Limit</span>
            <input type="range" name="MaxEpisodes" id="rule-MaxEpisodes" value="<%=recRule.MaxEpisodes%>" min="0" max="50" onmousemove="MythSettings.UpdateRangeValue(this)" onChange="MythSettings.UpdateRangeValue(this)" required>
            <span>50</span>
            <output name="MaxEpisodes-Value" id="rule-MaxEpisodes-Value" for="range"><%=recRule.MaxEpisodes%></output> <%=qsTr("Episodes")%>
        </div>

    <!-- What to do in event of hitting limit -->
        <div class="setting setting-select">
            <label for="rule-MaxNewest">&nbsp;</label>
            <select name="MaxNewest" id="rule-MaxNewest" required>
                <option value="1"><%=qsTr("Delete old and record new")%></option>
                <option value="0"><%=qsTr("Don't record new")%></option>
            </select>
        </div>

    <!-- Auto-Expire -->
        <div class="setting setting-toggle">
            <label for="rule-AutoExpire"><%=qsTr("Allow Auto-Expire")%>:</label>
            <span>No</span>
            <div class="setting-toggle-background">
                <input type="range" name="AutoExpire" id="rule-AutoExpire" value="<%=recRule.AutoExpire ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Yes</span>
        </div>

    <!-- Save -->
        <div class="setting setting-button">
            <button type="button"  name="Save" onClick="saveRecordingSchedule(this.form);"><%=qsTr("Save Changes")%></button>
        </div>

        </fieldset>
    </div> <!-- End Storage Options -->
    <div id="page-5"> <!-- Post Processing -->
        <fieldset>

    <!-- Auto-Metadata Lookup -->
        <div class="setting setting-toggle">
            <label for="rule-AutoMetaLookup"><%=qsTr("Look Up Metadata")%>:</label>
            <span>No</span>
            <div class="setting-toggle-background">
                <input type="range" name="AutoMetaLookup" id="rule-AutoMetaLookup" value="<%=recRule.AutoMetaLookup ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Yes</span>
        </div>

    <!-- Auto-Commercial Flag -->
        <div class="setting setting-toggle">
            <label for="rule-AutoCommflag"><%=qsTr("Commercial Flag")%>:</label>
            <span>No</span>
            <div class="setting-toggle-background">
                <input type="range" name="AutoCommflag" id="rule-AutoCommflag" value="<%=recRule.AutoCommflag ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Yes</span>
        </div>

    <!-- Auto-Transcode -->
        <div class="setting setting-toggle">
            <label for="rule-AutoTranscode"><%=qsTr("Transcode")%>:</label>
            <span>No</span>
            <div class="setting-toggle-background">
                <input type="range" name="AutoTranscode" id="rule-AutoTranscode" value="<%=recRule.AutoTranscode ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Yes</span>
        </div>

    <!-- Transcoding Profiles -->
        <div class="setting setting-select">
            <label for="Transcoder"><%=qsTr("Transcoder")%>:</label>
            <select name="_Transcoder" id="rule-Transcoder" required disabled>
                <option value="0"><%=qsTr("Default")%></option>
              <%
              // for (var idx = 0; idx < transcoderList.length; idx++)
              // {
              //     var selected = (transcoderList[idx] == recRule.Transcoder) ? "selected" : "";
              // % >
              //  <option value="< %=transcoderList[idx]% >" < %=selected% >>< %=transcoderList[idx]% ></option>
              // < % }
              %>
            </select>
            <span style="color:#880000;">Not currently working</span>
            <input type="hidden" name="Transcoder" value="<%=recRule.Transcoder%>">
        </div>

    <!-- Auto-User Job #1 -->
        <div class="setting setting-toggle">
            <label for="rule-AutoUserJob1"><%=qsTr("Run User Job 1")%>:</label>
            <span>No</span>
            <div class="setting-toggle-background">
                <input type="range" name="AutoUserJob1" id="rule-AutoUserJob1" value="<%=recRule.AutoUserJob1 ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Yes</span>
        </div>

    <!-- Auto-User Job #2 -->
        <div class="setting setting-toggle">
            <label for="rule-AutoUserJob2"><%=qsTr("Run User Job 2")%>:</label>
            <span>No</span>
            <div class="setting-toggle-background">
                <input type="range" name="AutoUserJob2" id="rule-AutoUserJob2" value="<%=recRule.AutoUserJob2 ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Yes</span>
        </div>

    <!-- Auto-User Job #3 -->
        <div class="setting setting-toggle">
            <label for="rule-AutoUserJob3"><%=qsTr("Run User Job 3")%>:</label>
            <span>No</span>
            <div class="setting-toggle-background">
                <input type="range" name="AutoUserJob3" id="rule-AutoUserJob3" value="<%=recRule.AutoUserJob3 ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Yes</span>
        </div>

    <!-- Auto-User Job #4 -->
        <div class="setting setting-toggle">
            <label for="rule-AutoUserJob4"><%=qsTr("Run User Job 4")%>:</label>
            <span>No</span>
            <div class="setting-toggle-background">
                <input type="range" name="AutoUserJob4" id="rule-AutoUserJob4" value="<%=recRule.AutoUserJob4 ? "1" : "0"%>" min="0" max="1" required>
            </div>
            <span>Yes</span>
        </div>

    <!-- Save -->
        <div class="setting setting-button">
            <button type="button"  name="Save" onClick="saveRecordingSchedule(this.form);"><%=qsTr("Save Changes")%></button>
        </div>

        </fieldset>
    </div> <!-- End Post Processing -->
    <div id="page-6"> <!-- Metadata Options -->

    <!-- Internet Reference Number -->
        <div class="setting setting-text">
            <label for="rule-Inetref"><%=qsTr("TVDB or TMDB ID")%>:</label>
            <input type="text" name="Inetref" id="rule-Inetref" value="<%=recRule.Inetref%>">
        </div>

    <!-- Season -->
        <div class="setting
        setting-text">
            <label for="rule-Season"><%=qsTr("Season")%>:</label>
            <input type="text" name="Season" id="rule-Season" value="<%=recRule.Season == 0 ? program.Season : recRule.Season%>">
        </div>

    <!-- Episode -->
        <div class="setting setting-text">
            <label for="rule-Episode"><%=qsTr("Episode")%>:</label>
            <input type="text" name="Episode" id="rule-Episode" value="<%=recRule.Episode == 0 ? program.Episode : recRule.Episode%>">
        </div>

    <!-- Lookup -->
        <div class="setting setting-button">
            <button type="button" name="MetadataLookup"><%=qsTr("Lookup Metadata")%></button>
            <span style="color:#880000;">Not currently working</span>
        </div>

    <!-- Save -->
        <div class="setting setting-button">
            <button type="button"  name="Save" onClick="saveRecordingSchedule(this.form);"><%=qsTr("Save Changes")%></button>
        </div>

    </div> <!-- End Metadata Options -->
  </form>
</div>

<script type="text/javascript" nonce="<%=CSP_NONCE%>">
    //$("#rule-DupMethod option[value='<%=recRule.DupMethod%>']").prop("selected", true);
    //$( "#rule-DupMethod" ).val("<%=recRule.DupMethod%>");

    $( "#scheduleEditor" ).tabs({ active: 1 });
    if ($("#rule-Id").val() <= 0)
    {
        $("#upcomingShowings").hide();
        $("#upcomingConflicts").hide();
    }
</script>
