<%pre>
#include <memory>
#include <vdr/channels.h>
#include <vdr/config.h>
#include <vdr/epg.h>
#include <vdr/i18n.h>
#include <iomanip>
#include "exception.h"
#include "tools.h"
#include "epgsearch.h"
#include "setup.h"
#include "i18n.h"
#include "users.h"

using namespace std;
using namespace vdrlive;

</%pre>
<%args>
	// input parameters
	string searchtimerid;
	string test;

	// form parameters
	string search = "";
	int mode = 0;
	bool matchcase = false;
	int tolerance = 1;
	bool usetitle = false;
	bool usesubtitle = false;
	bool usedescr = false;
	int usechannel = SearchTimer::NoChannel;
	tChannelID channelidfrom;
	tChannelID channelfrom;
	tChannelID channelidto;
	tChannelID channelto;
	string changrpsel = "";
	bool usetime = false;
	string start_h = "00";
	string start_m = "00";
	string stop_h = "00";
	string stop_m = "00";
	bool useduration = false;
	int durationmin = 0;
	int durationmax = 90;
	bool useweekday = false;
	bool wday_mon = false;
	bool wday_tue = false;
	bool wday_wed = false;
	bool wday_thu = false;
	bool wday_fri = false;
	bool wday_sat = false;
	bool wday_sun = false;
	bool useinfavorites = false;
	int useassearchtimer = 0;
	int searchtimeraction = 0;
	bool seriesrecording = false;
	string directory = "";
	int delrecafterdays = 0;
	int keeprecs = 0;
	int pauseonrecs = 0;
	int blacklistmode = 0;
	string blacklistids[];
	int switchminbefore = 0;
	bool useextepginfo = false;
	string extepgvalues[];
	bool avoidrepeats = false;
	int allowedrepeats = 0;
	int repeatswithindays = 0;
	bool comparetitle = false;
	int comparesubtitle = 0;
	bool comparesummary = false;
	unsigned avoidrepeatscatselected[];
	int priority = 0;
	int lifetime = 0;
	int marginstart = 0;
	int marginstop = 0;
	bool usevps = false;
	bool delmode = false;
	int delaftercountrecs = 0;
	int delafterdaysoffirstrec = 0;
	string blacklistids_internal;
	string useassearchtimerfrom;
	string useassearchtimerto;
	bool ignoreMissingEPGCats = false;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%request scope="page">
ExtEPGInfos extEPGInfos;
ChannelGroups channelGroups;
Blacklists blacklists;
RecordingDirs recordingdirs;
SearchTimer* editsearchtimer;
</%request>
<%include>page_init.eh</%include>
<{
if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
}>
<%cpp>

	if (!cUser::CurrentUserHasRightTo(UR_EDITSTIMERS))
		throw HtmlError( tr("Sorry, no permission. Please contact your administrator!") );

#define SELECTIF(x) reply.out() << ( (x) ? "selected=\"selected\"" : "" );
#define CHECKIF(x) reply.out() << ( (x) ? "checked=\"checked\"" : "" );

	SearchTimers searchtimers;
	bool testmode = !test.empty();
	editsearchtimer = NULL;

	if ( request.getMethod() == "POST") {
		SearchTimer searchtimer;
		if ( !searchtimerid.empty() && !testmode) {
			editsearchtimer = searchtimers.GetByTimerId( searchtimerid );
			if ( editsearchtimer == 0 )
				throw HtmlError( tr("Couldn't find searchtimer. Maybe you mistyped your request?") );
			searchtimer.SetId(editsearchtimer->Id());
		}

		searchtimer.SetSearch(search);
		searchtimer.SetSearchMode(mode);
		searchtimer.SetTolerance(tolerance);
		searchtimer.SetMatchCase(matchcase);
		searchtimer.SetUseTitle(usetitle);
		searchtimer.SetUseSubtitle(usesubtitle);
		searchtimer.SetUseDescription(usedescr);
		searchtimer.SetUseExtEPGInfo(useextepginfo);
		if (useextepginfo)
		{
			vector< string > infos;
			unsigned int i=0;
			for (ExtEPGInfos::iterator extinfo = extEPGInfos.begin(); extinfo != extEPGInfos.end(); ++extinfo, i++)
			{
			ostringstream os;
			os << extinfo->Id() << "#" << (i<extepgvalues.size()?extepgvalues[i]:"");
			infos.push_back(os.str());
			}
			searchtimer.SetExtEPGInfo(infos);
			searchtimer.SetIgnoreMissingEPGCats(ignoreMissingEPGCats);
		}
		searchtimer.SetUseChannel((SearchTimer::eUseChannel)usechannel);
		if (usechannel == SearchTimer::Interval)
		{
			searchtimer.SetChannelMin(channelfrom);
			searchtimer.SetChannelMax(channelto);
		}
		if (usechannel == SearchTimer::Group)
			searchtimer.SetChannelText(changrpsel);

		searchtimer.SetUseTime(usetime);
		if (usetime)
		{
			searchtimer.SetStartTime(StringToInt(start_h) * 100 + StringToInt(start_m));
			searchtimer.SetStopTime(StringToInt(stop_h) * 100 + StringToInt(stop_m));
		}
		searchtimer.SetUseDuration(useduration);
		if (useduration)
		{
			searchtimer.SetMinDuration(durationmin);
			searchtimer.SetMaxDuration(durationmax);
		}
		searchtimer.SetUseDayOfWeek(useweekday);
		if (useweekday)
		{
			int dayofweek = 0;
			if (wday_sun) dayofweek |= 0x01;
			if (wday_mon) dayofweek |= 0x02;
			if (wday_tue) dayofweek |= 0x04;
			if (wday_wed) dayofweek |= 0x08;
			if (wday_thu) dayofweek |= 0x10;
			if (wday_fri) dayofweek |= 0x20;
			if (wday_sat) dayofweek |= 0x40;
			searchtimer.SetDayOfWeek(-dayofweek);
		}
		searchtimer.SetUseInFavorites(useinfavorites);
		searchtimer.SetUseAsSearchTimer(useassearchtimer);
		if (useassearchtimer == 2)
		{
			// TRANSLATORS: only adjust the ordering and separators, don't translate the m's, d's and y's
			searchtimer.SetUseAsSearchTimerFrom(useassearchtimerfrom, tr("mm/dd/yyyy"));
			// TRANSLATORS: only adjust the ordering and separators, don't translate the m's, d's and y's
			searchtimer.SetUseAsSearchTimerTil(useassearchtimerto, tr("mm/dd/yyyy"));
		}
		searchtimer.SetSearchTimerAction(searchtimeraction);
		searchtimer.SetUseSeriesRecording(seriesrecording);
		searchtimer.SetDirectory(directory);
		searchtimer.SetDelRecsAfterDays(delrecafterdays);
		searchtimer.SetKeepRecs(keeprecs);
		searchtimer.SetPauseOnRecs(pauseonrecs);
		searchtimer.SetBlacklistMode(blacklistmode);
		if (blacklistmode == 1)
			searchtimer.ParseBlacklist(blacklistids_internal);

		searchtimer.SetSwitchMinBefore(switchminbefore);
		searchtimer.SetAvoidRepeats(avoidrepeats);
		if (avoidrepeats)
		{
			searchtimer.SetAllowedRepeats(allowedrepeats);
			searchtimer.SetRepeatsWithinDays(repeatswithindays);
			searchtimer.SetCompareTitle(comparetitle);
			searchtimer.SetCompareSubtitle(comparesubtitle);
			searchtimer.SetCompareSummary(comparesummary);
		}
		unsigned long catsselected = 0;
		for (unsigned int i=0; i< avoidrepeatscatselected.size(); i++)
			catsselected |= (1<< (avoidrepeatscatselected[i]-1));
		searchtimer.SetCompareCategories(catsselected);
		searchtimer.SetPriority(priority);
		searchtimer.SetLifetime(lifetime);
		searchtimer.SetMarginStart(marginstart);
		searchtimer.SetMarginStop(marginstop);
		searchtimer.SetUseVPS(usevps);
		searchtimer.SetDelMode(delmode);
		if (delmode)
		{
			searchtimer.SetDelAfterCountRecs(delaftercountrecs);
			searchtimer.SetDelAfterDaysOfFirstRec(delafterdaysoffirstrec);
		}
		if (!testmode)
		{
			searchtimers.Save(&searchtimer);
			return reply.redirect("searchtimers.html");
		}
		else
		{
			searchtimer.SetId(0);
			string md5 = SearchResults::AddQuery(searchtimer.ToText());
			return reply.redirect("searchresults.html?searchtimerquery=" + md5);
		}
	}
	pageTitle = !searchtimerid.empty() ? tr("Edit search timer") : tr("New search timer");

	if (  !searchtimerid.empty() ) {
		SearchTimer* searchtimer = searchtimers.GetByTimerId( searchtimerid );
		if ( searchtimer == 0 )
			throw HtmlError( tr("Couldn't find searchtimer. Maybe you mistyped your request?") );

		search = searchtimer->Search();
		mode = searchtimer->SearchMode();
		tolerance = searchtimer->Tolerance();
		matchcase = searchtimer->MatchCase();
		usetitle = searchtimer->UseTitle();
		usesubtitle = searchtimer->UseSubtitle();
		usedescr = searchtimer->UseDescription();
		usechannel = searchtimer->UseChannel();
		channelfrom = searchtimer->ChannelMin();
		channelto = searchtimer->ChannelMax();
		if (!channelto.Valid() && channelfrom.Valid())
			channelto = channelfrom;
		if (usechannel == SearchTimer::Group)
			changrpsel = searchtimer->ChannelText();
		usetime = searchtimer->UseTime();
		ostringstream os;
		os << setw(2) << setfill('0') << ( searchtimer->StartTime() / 100 ) % 100;
			start_h = os.str();
		os.str("");
		os << setw(2) << setfill('0') << searchtimer->StartTime() % 100;
			start_m = os.str();
		os.str("");
		os << setw(2) << setfill('0') << ( searchtimer->StopTime() / 100 ) % 100;
			stop_h = os.str();
		os.str("");
		os << setw(2) << setfill('0') << searchtimer->StopTime() % 100;
			stop_m = os.str();
		useduration = searchtimer->UseDuration();
		if (useduration)
		{
			durationmin = searchtimer->MinDuration();
			durationmax = searchtimer->MaxDuration();
		}
		useweekday = searchtimer->UseDayOfWeek();
		if (useweekday)
		{
			int dayofweek = searchtimer->DayOfWeek();
			if (dayofweek >= 0)
			{
				wday_sun = (dayofweek == 0);
				wday_mon = (dayofweek == 1);
			wday_tue = (dayofweek == 2);
				wday_wed = (dayofweek == 3);
			wday_thu = (dayofweek == 4);
				wday_fri = (dayofweek == 5);
				wday_sat = (dayofweek == 6);
			}
			else
			{
			wday_sun = -dayofweek & 0x01;
			wday_mon = -dayofweek & 0x02;
			wday_tue = -dayofweek & 0x04;
			wday_wed = -dayofweek & 0x08;
			wday_thu = -dayofweek & 0x10;
			wday_fri = -dayofweek & 0x20;
			wday_sat = -dayofweek & 0x40;
			}
		}
		useinfavorites = searchtimer->UseInFavorites();
		useassearchtimer = searchtimer->UseAsSearchTimer();
		if (useassearchtimer == 2)
		{
			useassearchtimerfrom = searchtimer->UseAsSearchTimerFrom(tr("mm/dd/yyyy"));
			useassearchtimerto = searchtimer->UseAsSearchTimerTil(tr("mm/dd/yyyy"));
		}
		searchtimeraction = searchtimer->SearchTimerAction();
		seriesrecording = searchtimer->UseSeriesRecording();
		directory = searchtimer->Directory();
		delrecafterdays = searchtimer->DelRecsAfterDays();
		keeprecs = searchtimer->KeepRecs();
		pauseonrecs = searchtimer->PauseOnRecs();
		blacklistmode = searchtimer->BlacklistMode();
		switchminbefore = searchtimer->SwitchMinBefore();
		useextepginfo = searchtimer->UseExtEPGInfo();
		vector< string > infos = searchtimer->ExtEPGInfo();
		for(unsigned int i=0; i<extEPGInfos.size(); i++)
		{
			if (i<infos.size())
			{
			vector< string > parts = StringSplit( infos[i], '#' );
			extepgvalues.push_back(parts.size() > 1?parts[1]:"");
			}
			else
			extepgvalues.push_back("");
		}
		ignoreMissingEPGCats = searchtimer->IgnoreMissingEPGCats();
		avoidrepeats = searchtimer->AvoidRepeats();
		allowedrepeats =  searchtimer->AllowedRepeats();
		repeatswithindays = searchtimer->RepeatsWithinDays();
		comparetitle = searchtimer->CompareTitle();
		comparesubtitle = searchtimer->CompareSubtitle();
		comparesummary = searchtimer->CompareSummary();
		for(unsigned int i=0; i<extEPGInfos.size(); i++)
		{
			bool selected = searchtimer->CompareCategories() & (1<<i);
			avoidrepeatscatselected.push_back(selected);
		}
		priority = searchtimer->Priority();
		lifetime = searchtimer->Lifetime();
		marginstart = searchtimer->MarginStart();
		marginstop = searchtimer->MarginStop();
		usevps = searchtimer->UseVPS();
		delmode = searchtimer->DelMode();
		delaftercountrecs = searchtimer->DelAfterCountRecs();
		delafterdaysoffirstrec = searchtimer->DelAfterDaysOfFirstRec();		

		editsearchtimer = searchtimer;
	}
	else
	{
		for(unsigned int i=0; i<extEPGInfos.size(); i++)
			extepgvalues.push_back("");
		for(unsigned int i=0; i<extEPGInfos.size(); i++)
			avoidrepeatscatselected.push_back(false);
		usetitle = true;
		usesubtitle = true;
		usedescr = true;
		priority = lexical_cast< int >(EPGSearchSetupValues::ReadValue("DefPriority"));
		lifetime = lexical_cast< int >(EPGSearchSetupValues::ReadValue("DefLifetime"));
		marginstart = lexical_cast< int >(EPGSearchSetupValues::ReadValue("DefMarginStart"));
		marginstop = lexical_cast< int >(EPGSearchSetupValues::ReadValue("DefMarginStop"));
	}
</%cpp>
<& pageelems.doc_type &>
<html>
	<head>
		<title>VDR Live - <$ editsearchtimer ? tr("Edit search timer") : tr("New search timer") $></title>
		
		<& pageelems.stylesheets &>
		<& pageelems.ajax_js &>

		<script type="text/javascript">
		function initform()
		{
			changedsearchmode(document.getElementById("search_mode"));
			changedchannelmode(document.getElementById("channel_mode"));
			changedusetime(document.getElementById("usetime"));
			changeduseduration(document.getElementById("useduration"));
			changeduseweekday(document.getElementById("useweekday"));
			changeduseassearchtimer(document.getElementById("useassearchtimer"));
%	if (extEPGInfos.size() > 0) {
			changeduseextepginfo(document.getElementById("useextepginfo"));
%	}
			changedavoidrepeats(document.getElementById("avoidrepeats"));
			changedblacklistmode(document.getElementById("blacklistmode"));
			changeddelmode(document.getElementById("delmode"));
		}

		function checksearch()
		{
			if (document.getElementById("searchterm").value.length <= 3)
				return confirm('<$ tr("Search text too short - use anyway?") $>');
			return true;
		}

		function changedsearchmode(selection)
		{
			document.getElementById("tolerance").style.display = (selection.options[selection.selectedIndex].value == 5 ? "block" : "none");
		}

		function changedchannelmode(selection)
		{
			document.getElementById("channelinterval").style.display = (selection.options[selection.selectedIndex].value == 1 ? "block" : "none");
			document.getElementById("channelgroup").style.display = (selection.options[selection.selectedIndex].value == 2 ? "block" : "none");
		}

		function changedusetime(selection)
		{
			document.getElementById("timesettings").style.display = (selection.checked ? "block" : "none");
		}

		function changeduseduration(selection)
		{
			document.getElementById("durationsettings").style.display = (selection.checked ? "block" : "none");
		}

		function changeduseweekday(selection)
		{
			document.getElementById("weekdaysettings").style.display = (selection.checked ? "block" : "none");
		}

		function changeduseassearchtimer(selection)
		{
			document.getElementById("searchtimermodesettings").style.display = 
				(selection.options[selection.selectedIndex].value > 0) ? "block" : "none";
			document.getElementById("useassearchtimeruserdef").style.display = 
				(selection.options[selection.selectedIndex].value == 2) ? "block" : "none";
			changedsearchtimermode(document.getElementById("searchtimer_mode"));
		}

		function changedsearchtimermode(selection)
		{
			document.getElementById("searchtimermode1settings").style.display =
				(selection.options[selection.selectedIndex].value == 0 &
				document.getElementById("useassearchtimer").options[document.getElementById("useassearchtimer").selectedIndex].value > 0) ? 
				"block" : "none";
			document.getElementById("searchtimermode3settings").style.display =
				(selection.options[selection.selectedIndex].value == 2 & 
				document.getElementById("useassearchtimer").options[document.getElementById("useassearchtimer").selectedIndex].value > 0) ? 
				"block" : "none";
		}

		function changeduseextepginfo(selection)
		{
			document.getElementById("use_extepg_settings").style.display = (selection.checked ? "block" : "none");
		}

		function changedextepginfo(selection)
		{
			var i;
			document.getElementById(selection.name + "_value").value = "";
			for(i=0;i<selection.length;i++)
			{
				if (selection.options[i].selected)
				{
				if (document.getElementById(selection.name + "_value").value != "")
					document.getElementById(selection.name + "_value").value += ",";
				document.getElementById(selection.name + "_value").value += selection.options[i].value;
				}
			}
		}

		function changedavoidrepeats(selection)
		{
			document.getElementById("avoidrepeatssettings").style.display = (selection.checked ? "block" : "none");
		}

		function changedblacklistmode(selection)
		{
			document.getElementById("blacklistmodesettings").style.display =
				(selection.options[selection.selectedIndex].value == 1 ? "block" : "none");
		}

		function changedblacklistsel(selection)
		{
			var i;
			document.getElementById("blacklistids_internal").value = "";
			for(i=0;i<selection.length;i++)
			{
				if (selection.options[i].selected)
				{
				if (document.getElementById("blacklistids_internal").value != "")
					document.getElementById("blacklistids_internal").value += "|";
				document.getElementById("blacklistids_internal").value += selection.options[i].value;
				}
			}
		}
		function changeddirselection(selection)
		{
			document.getElementById("directory").value = selection.value;
		}
		function changeddelmode(selection)
		{
			document.getElementById("delmodesettings").style.display = (selection.checked ? "block" : "none");
		}
		//--></script>

	</head>
	<body onload="initform()">
		<& pageelems.logo &>
		<& menu active=("searchtimers") &>
			<div class="inhalt">
				<form method="post" name="edit_searchtimer" action="edit_searchtimer.ecpp">
					<input type="hidden" name="searchtimerid" value="<$ searchtimerid $>"/>
					<input type="hidden" name="blacklistids_internal" value="<$ blacklistids_internal $>" id="blacklistids_internal"/>
					<table class="formular" cellpadding="0" cellspacing="0">
						<tr class="head">
							<td  class="toprow leftcol rightcol" colspan="2"><div class="boxheader"><div><div><$ editsearchtimer ? tr("Edit search timer") : tr("New search timer") $></div></div></div></td>
						</tr>

						<!-- Search term -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Search term") $>:</div></td>
							<td class="rightcol"><input type="text" name="search" value="<$ search $>" size="90" id="searchterm" /></td>
						</tr>

						<!-- Search mode -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Search mode" ) $>:</div></td>
							<td class="rightcol">
								<div style="float:left; max-width:50%; margin-right:20px">
									<select onchange="changedsearchmode(this)" name="mode" size="1" id="search_mode">
										<option value="0" <{ SELECTIF(mode == 0) }> ><$ tr("phrase") $></option>
										<option value="1" <{ SELECTIF(mode == 1) }> ><$ tr("all words") $></option>
										<option value="2" <{ SELECTIF(mode == 2) }> ><$ tr("at least one word") $></option>
										<option value="3" <{ SELECTIF(mode == 3) }> ><$ tr("match exactly") $></option>
										<option value="4" <{ SELECTIF(mode == 4) }> ><$ tr("regular expression") $></option>
										<option value="5" <{ SELECTIF(mode == 5) }> ><$ tr("fuzzy") $></option>
									</select>
								</div>
								<div id="tolerance" style="display: none">
										<$ tr("Tolerance" ) $>:
										<input type="text" name="tolerance" size="2" value="<$ tolerance $>" />
								</div>
							</td>
						</tr>

						<!-- Match case -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Match case") $>:</div></td>
							<td class="rightcol"><input type="checkbox" name="matchcase" value="1" <{ CHECKIF(matchcase) }> id="matchcase"/></td>
						</tr>

						<!-- Search in -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Search in") $>:</div></td>
							<td class="rightcol">
								<div class="dotted">
									<input type="checkbox" name="usetitle" value="1" <{ CHECKIF(usetitle) }> />
									<label for="usetitle"><$ tr("Title") $> </label>
								</div>
								<div class="dotted">
									<input type="checkbox" name="usesubtitle" value="1" <{ CHECKIF(usesubtitle) }> />
									<label for="usesubtitle"><$ tr("Episode") $> </label>
								</div>
								<div class="dotted">
									<input type="checkbox" name="usedescr" value="1" <{ CHECKIF(usedescr) }> />
									<label for="usedescr"><$ tr("Description") $> </label>
								</div>
							</td>
						</tr>

%						if (extEPGInfos.size() > 0) {
						<!-- Use ext. EPG categories -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Use extended EPG info" ) $>:</div></td>
							<td class="rightcol">
								<input type="checkbox" name="useextepginfo" value="1" <{ CHECKIF(useextepginfo) }> onclick="changeduseextepginfo(this)" id="useextepginfo"/>
								<div id="use_extepg_settings" style="display: none">
									<table class="dependent" border="0" cellspacing="0" cellpadding="0">
%										int i=0; for (ExtEPGInfos::iterator extinfo = extEPGInfos.begin(); extinfo != extEPGInfos.end(); ++extinfo, i++) {
										<tr>
											<td class="label"><div class="withmargin"><$ extinfo->Name() $></div></td>
											<td><input type="text" name="extepgvalues" value="<$extepgvalues[i]$>" size="20" id="extepg_<{ reply.out() << extinfo->Id(); }>_value"/></td>
%											if (extinfo->Values().size() > 0) {
											<td >
												<select size="3" multiple="multiple" align="left" valign="top" name="extepg_<{ reply.out() << extinfo->Id(); }>" onchange="changedextepginfo(this)">
%											for (unsigned int j=0; j<extinfo->Values().size(); j++) {
													<option value="<{ reply.out() << extinfo->Values()[j];}>"
%													if (extinfo->Selected(j, extepgvalues[i])) {
																											selected="selected"
%                                               }
																									> <{ reply.out() << extinfo->Values()[j]; }> </option>
%                                               }
												</select>
											</td>
										</tr>
%                                       }
%                                   }
									<!-- Ignore missing EPG categories -->
									<tr>
										<td>
											<div class="dotted">
												<input type="checkbox" name="ignoreMissingEPGCats" value="1" <{ CHECKIF(ignoreMissingEPGCats) }> />
												<label for="ignoreMissingEPGCats"><$ tr("Ignore missing EPG info") $> </label>
												<& tooltip.help text=(tr("When active this can cause very many timers. So please always first test this search before using it as search timer!")) &>
											</div>
										</td>
									</tr>
									</table>
								</div>
							</td>
						</tr>
%						}


						<!-- Use channel -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Use channel" ) $>:</div></td>
							<td class="rightcol">
								<select onchange="changedchannelmode(this)" name="usechannel" size="1" id="channel_mode">
									<option value="0" <{ SELECTIF(usechannel == 0) }> ><$ trVDR("no") $></option>
									<option value="1" <{ SELECTIF(usechannel == 1) }> ><$ tr("interval") $></option>
									<option value="2" <{ SELECTIF(usechannel == 2) }> ><$ tr("channel group") $></option>
									<option value="3" <{ SELECTIF(usechannel == 3) }> ><$ tr("only FTA") $></option>
								</select>

								<div id="channelinterval" style="display: none;">
									<table class="dependent" border="0" cellpadding="0" cellspacing="0" class="dependent">
										<tr>
											<td class="label"><div class="withmargin"><$ tr("from channel" ) $>:</div></td>
											<td><& channels_widget name=("channelfrom") channelid=(true) selected=(channelfrom) &></td>
										</tr>
										<tr>
											<td class="label"><div class="withmargin"><$ tr("to channel" ) $>:</div></td>
											<td><& channels_widget name=("channelto") channelid=(true) selected=(channelto) &></td>
										</tr>
									</table>
								</div>

								<div id="channelgroup" style="display: none">
%									if (channelGroups.size() > 0) {
									<select name="changrpsel" size="1" id="changrpsel">
%										int i=0; for (ChannelGroups::iterator changrp = channelGroups.begin(); changrp != channelGroups.end(); ++changrp, i++) {
										<option value="<$ changrp->Name() $>" <{ SELECTIF(changrpsel == changrp->Name()) }> ><$ changrp->Name() $></option>
%										         }
									</select>
%									}
								</div>
							</td>
						</tr>

						<!-- Use time -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Use time") $>:</div></td>
							<td class="rightcol">
								<input type="checkbox" name="usetime" value="1" <{ CHECKIF(usetime) }> onclick="changedusetime(this)" id="usetime" />
								<div id="timesettings" style="display: none">
									<table class="dependent" border="0" cellpadding="0" cellspacing="0" class="dependent">
										<tr>
											<td class="label"><div class="withmargin"><$ tr("Start after") $>:</div></td>
											<td>
												<input type="text" size="2" maxlength="2" name="start_h" value="<$ start_h $>" /> : <input type="text" size="2" maxlength="2" name="start_m" value="<$ start_m $>" />
												<& tooltip.help text=(tr("The time the show may start at the earliest")) &>
											</td>
										</tr>
										<tr>
											<td class="label"><div class="withmargin"><$ tr("Start before") $>:</div></td>
											<td>
												<input type="text" size="2" maxlength="2" name="stop_h" value="<$ stop_h $>" /> : <input type="text" size="2" maxlength="2" name="stop_m" value="<$ stop_m $>" />
												<& tooltip.help text=(tr("The time the show may start at the latest")) &>
											</td>
										</tr>
									</table>
								</div>
							</td>
						</tr>

						<!-- Use duration -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Use duration") $>:</div></td>
							<td class="rightcol">
								<input type="checkbox" name="useduration" value="1" <{ CHECKIF(useduration) }> onclick="changeduseduration(this)" id="useduration" />
								<div id="durationsettings" style="display: none">
									<table class="dependent" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td class="label"><div class="withmargin"><$ tr("Min. duration") $>:</div></td>
											<td><input type="text" size="3" maxlength="3" name="durationmin" value="<$ durationmin $>" /> min</td>
										</tr>
										<tr>
											<td class="label"><div class="withmargin"><$ tr("Max. duration") $>:</div></td>
											<td><input type="text" size="3" maxlength="3" name="durationmax" value="<$ durationmax $>" /> min</td>
										</tr>
									</table>
								</div>
							</td>
						</tr>

						<!-- Use weekday -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Use day of week") $>:</div></td>
							<td class="rightcol">
								<input type="checkbox" name="useweekday" value="1" <{ CHECKIF(useweekday) }> onclick="changeduseweekday(this)" id="useweekday" />
								<div id="weekdaysettings" style="display: none" class="dependent">
									<div class="dotted"><input type="checkbox" name="wday_mon" value="1" <{ CHECKIF(wday_mon) }> /> <$ tr("Monday") $></div>
									<div class="dotted"><input type="checkbox" name="wday_tue" value="1" <{ CHECKIF(wday_tue) }> /> <$ tr("Tuesday") $></div>
									<div class="dotted"><input type="checkbox" name="wday_wed" value="1" <{ CHECKIF(wday_wed) }> /> <$ tr("Wednesday") $></div>
									<div class="dotted"><input type="checkbox" name="wday_thu" value="1" <{ CHECKIF(wday_thu) }> /> <$ tr("Thursday") $></div>
									<div class="dotted"><input type="checkbox" name="wday_fri" value="1" <{ CHECKIF(wday_fri) }> /> <$ tr("Friday") $></div>
									<div class="dotted"><input type="checkbox" name="wday_sat" value="1" <{ CHECKIF(wday_sat) }> /> <$ tr("Saturday") $></div>
									<div class="dotted"><input type="checkbox" name="wday_sun" value="1" <{ CHECKIF(wday_sun) }> /> <$ tr("Sunday") $></div>
									<br style="clear: both" /><!-- Der muss da sein damit die H�henberechnung klappt. Glaubt mir, ist so. -->
								</div>
							</td>
						</tr>

						<!-- Use blacklists -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Use blacklists" ) $>:</div></td>
							<td class="rightcol">
								<select onchange="changedblacklistmode(this)" name="blacklistmode" size="1" id="blacklistmode">
									<option value="0" <{ SELECTIF(blacklistmode == 0) }> ><$ trVDR("no") $></option>
									<option value="1" <{ SELECTIF(blacklistmode == 1) }> ><$ tr("Selection") $></option>
									<option value="2" <{ SELECTIF(blacklistmode == 2) }> ><$ tr("all") $></option>
								</select>
								<div class="dependent" id="blacklistmodesettings" style="display: none">
%								if (blacklists.size() > 0) {
									<select name="blacklists" multiple="multiple" size="5" onchange="changedblacklistsel(this)">
%									int i=0; for (Blacklists::iterator blacklist = blacklists.begin(); blacklist != blacklists.end(); ++blacklist, i++) {
										<option value="<$ blacklist->Id() $>" <{ SELECTIF(editsearchtimer && editsearchtimer->BlacklistSelected(blacklist->Id())) }>><$ blacklist->Search() $></option>
%									         }
									</select>
%								}
								</div>
							</td>
						</tr>

						<!-- Use in favorites menu -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Use in favorites menu") $>:</div></td>
							<td class="rightcol"><input type="checkbox" name="useinfavorites" value="1" <{ CHECKIF(useinfavorites) }>/></td>
						</tr>

						<!-- Use as search timer -->
						<tr>
							<td class="label leftcol"><div class="withmargin"><$ tr("Use as search timer" ) $>:</div></td>
							<td class="rightcol">
								<div>
									<select onchange="changeduseassearchtimer(this)" name="useassearchtimer" size="1" id="useassearchtimer">
										<option value="0" <{ SELECTIF(useassearchtimer == 0) }> ><$ trVDR("no") $></option>
										<option value="1" <{ SELECTIF(useassearchtimer == 1) }> ><$ trVDR("yes") $></option>
										<option value="2" <{ SELECTIF(useassearchtimer == 2) }> ><$ tr("user defined") $></option>
									</select>
								</div>
								<div id="useassearchtimeruserdef" style="display: none">
									<table class="dependent" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td class="label"><div class="withmargin"><$ tr("from date") $>:</div></td>
											<td><input id="datefrom" name="useassearchtimerfrom" type="text" class="DatePicker" value="<$ useassearchtimerfrom $>" /></td>
										</tr>
										<tr>
											<td class="label"><div class="withmargin"><$ tr("to date") $>:</div></td>
											<td><input id="dateto" name="useassearchtimerto" type="text" class="DatePicker" value="<$ useassearchtimerto $>" /></td>
										</tr>
									</table>
								</div>
								<div id="searchtimermodesettings" style="display: none">
									<select onchange="changedsearchtimermode(this)" name="searchtimeraction" size="1" id="searchtimer_mode">
										<option value="0" <{ SELECTIF(searchtimeraction == 0) }> ><$ tr("Record") $></option>
										<option value="1" <{ SELECTIF(searchtimeraction == 1) }> ><$ tr("Announce only") $></option>
										<option value="2" <{ SELECTIF(searchtimeraction == 2) }> ><$ tr("Switch only") $></option>
									</select>
								</div>
								<div id="searchtimermode1settings" style="display: none">
									<table class="dependent" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td class="label"><div class="withmargin"><$ tr("Series recording") $>:</div></td>
											<td><input type="checkbox" name="seriesrecording" value="1" <{ CHECKIF(seriesrecording) }>/></td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ tr("Directory") $>:</div></td>
											<td><input type="text" name="directory" id="directory" value="<$ directory $>" size="70" /><br>
											<select onchange="changeddirselection(this)" name="recordingdirsselection" size="1" id="recordingdirsselection" style="margin-top: 5px">
											<option/>
%											for (RecordingDirs::iterator rdir = recordingdirs.begin(); rdir != recordingdirs.end(); ++rdir) {
												<option value="<$ *rdir $>"><$ *rdir $></option>
%											}
											</select>
											</td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ tr("Delete recordings after ... days") $>:</div></td>
											<td>
												<input type="text" name="delrecafterdays" id="delrecafterdays" size="2" value="<$ delrecafterdays $>"/>&nbsp;&nbsp;
												<$ tr("Keep ... recordings") $>:
												<input type="text" name="keeprecs" size="2" value="<$ keeprecs $>"/>
											</td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ tr("Pause when ... recordings exist") $>:</div></td>
											<td><input type="text" name="pauseonrecs" id="pauseonrecs" size="2" value="<$ pauseonrecs $>"/></td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ tr("Avoid repeats" ) $>:</div></td>
											<td><input type="checkbox" name="avoidrepeats" value="1" <{ CHECKIF(avoidrepeats) }> onclick="changedavoidrepeats(this)" id="avoidrepeats"/>
												<div id="avoidrepeatssettings" style="display: none">
													<table class="dependent" border="0" cellpadding="0" cellspacing="0">
														<tr>
															<td class="label"><div class="withmargin"><$ tr("Allowed repeats") $>:</div></td>
															<td>
																<input type="text" size="3" maxlength="3" name="allowedrepeats" value="<$ allowedrepeats $>" /><span class="withmargin"><$ tr("Only repeats within ... days") $>:</span><input type="text" size="3" maxlength="3" name="repeatswithindays" value="<$ repeatswithindays $>" />
															</td>
														</tr>

														<tr>
															<td class="label"><div class="withmargin"><$ tr("Compare title" ) $>:</div></td>
															<td><input type="checkbox" name="comparetitle" value="1" <{ CHECKIF(comparetitle) }>/>
														</tr>

														<tr>
															<td class="label"><div class="withmargin"><$ tr("Compare subtitle" ) $>:</div></td>
															<td><select name="comparesubtitle" size="1" id="comparesubtitle">
										<option value="0" <{ SELECTIF(comparesubtitle == 0) }> ><$ trVDR("no") $></option>
										<option value="1" <{ SELECTIF(comparesubtitle == 1) }> ><$ trVDR("yes") $></option>
										<option value="2" <{ SELECTIF(comparesubtitle == 2) }> ><$ tr("if present") $></option></select>
														</tr>

														<tr>
															<td class="label"><div class="withmargin"><$ tr("Compare summary" ) $>:</div></td>
															<td><input type="checkbox" name="comparesummary" value="1" <{ CHECKIF(comparesummary) }>/>
														</tr>

%														if (extEPGInfos.size() > 0) {
%															int i=0; for (ExtEPGInfos::iterator extinfo = extEPGInfos.begin(); extinfo != extEPGInfos.end(); ++extinfo, i++) {
														<tr>
															<td class="label"><div class="withmargin"><$ tr("Compare" ) $> <$ extinfo->Name() $>:</div></td>
															<td><input type="checkbox" name="avoidrepeatscatselected" value="<$ i+1 $>" <{ CHECKIF(avoidrepeatscatselected[i]) }>/></td>
														</tr>
%															}
%														}
													</table>
												</div>
											</td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ trVDR("Priority") $>:</div></td>
											<td><input type="text" name="priority" size="2" value="<$ priority $>"/></td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ trVDR("Lifetime") $>:</div></td>
											<td><input type="text" name="lifetime" size="2" value="<$ lifetime $>"/></td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ trVDR("Setup.Recording$Margin at start (min)") $>:</div></td>
											<td><input type="text" name="marginstart" size="2" value="<$ marginstart $>"/></td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ trVDR("Setup.Recording$Margin at stop (min)") $>:</div></td>
											<td><input type="text" name="marginstop" size="2" value="<$ marginstop $>"/></td>
										</tr>

										<tr>
											<td class="label"><div class="withmargin"><$ tr("Use VPS") $>:</div></td>
											<td><input type="checkbox" name="usevps" value="1" <{ CHECKIF(usevps) }>/></td>
										</tr>
										<tr>
											<td class="label"><div class="withmargin"><$ tr("Auto-delete search timer") $>:</div></td>
											<td><input type="checkbox" name="delmode" value="1" <{ CHECKIF(delmode) }> onclick="changeddelmode(this)" id="delmode"/>
											<div id="delmodesettings" style="display: none">
												<table class="dependent" border="0" cellpadding="0" cellspacing="0" class="dependent">
													<tr>
														<td class="label"><div class="withmargin"><$ tr("after ... recordings") $>:</div></td>
														<td>
															<input type="text" size="3" maxlength="3" name="delaftercountrecs" value="<$ delaftercountrecs $>" />
														</td>
													</tr>
													<tr>
														<td class="label"><div class="withmargin"><$ tr("after ... days after first rec.") $>:</div></td>
														<td>
															<input type="text" size="3" maxlength="3" name="delafterdaysoffirstrec" value="<$ delafterdaysoffirstrec $>" />
														</td>
													</tr>
												</table>
											</div>
											</td>
										</tr>
									</table>
								</div>

								<div id="searchtimermode3settings" style="display: none">
									<table class="dependent" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td class="label"><div class="withmargin"><$ tr("Switch ... minutes before start") $>:</div></td>
											<td><input type="text" name="switchminbefore" id="switchminbefore" size="2" value="<$ switchminbefore $>"/></td>
										</tr>
									</table>
								</div>
							</td>
						</tr>

						<tr>
							<td class="buttonpanel leftcol rightcol bottomrow" colspan="2">
								<div class="withmargin">
								<button class="green" type="submit" name="test" value="test" onclick="return checksearch();"><$ tr("Test") $></button>
								<button class="green" type="submit" name="save" onclick="return checksearch();"><$ tr("Save") $></button>
								<button type="button" class="red" onclick="history.back()"><$ tr("Cancel") $></button>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
	</body>
</html>
<%include>page_exit.eh</%include>