<%inherit file="base.html"/>
<%!
	import headphones
	import string
%>

<%def name="headIncludes()">
	<script type="text/javascript" src="../interfaces/brink/js/configscript.js"></script>
</%def>

<%def name="headerIncludes()">
</%def>

<%def name="body()">
    <form id="config" class="ajax" action="configUpdate" method="post">
		<div id="nav-sub-container" class="nav-sub-fixed">
			<ul id="nav-sub">
				<li><a href="#"><span class="wsr Code"></span> Settings Jump Menu</a>
					<ul>
						<li><a href="#WebInterface"><span class="wsr"></span> Web Interface</a></li>
						<li><a href="#DownloadSettings"><span class="wsr"></span> Download Settings</a></li>
						<li><a href="#Quality"><span class="wsr">I</span> Quality & Post Processing</a></li>
						<li><a href="#AdvancedSettings"><span class="wsr"></span> Advanced Settings</a></li>
						<li><a href="#Notifications"><span class="wsr"></span> Notifications</a></li>
					</ul>
				</li>
				<li><a href="#" class="submitForm" ><span class="wsr Approved"></span> Save Changes</a></li>
			</ul>
		</div>
		<div id="config_wrapper"><!--config_wrapper-->
			<div id="WebInterface"><!--Web Interface-->
				<h1><span class="wsr">C</span>Web Interface</h1>
				<small><span class="wsr">W</span>Web Interface changes require a restart to take effect</small>
				<div>
					<table><!--HTTP-->
						<tr>
							<td>
								<h2>HTTP</h2>
								<br /><small>Basic settings for Headphones.</small>
							</td>
							<td></td>
						</tr>
						<tr>
							<td>
								<label for="http_host">Host:</label>
								<br /><small>Localhost or 0.0.0.0</small>
							</td>
							<td>
								<input type="text" name="http_host" value="${config['http_host']}" size="25" maxlength="40" />
							</td>
						</tr>
						<tr>
							<td>
								<label for="http_port">Port:</label>
								<br /><small>Default is: 8181</small>
							</td>
							<td>
								<input type="text" name="http_port" value="${config['http_port']}" size="10" maxlength="40" />
							</td>
						</tr>
						<tr>
							<td>
								<label for="http_username">Username:</label>
								<br /><small>Enter a desired username at login, or leave blank for none.</p>
							</td>
							<td>
								<input type="text" name="http_username" value="${config['http_user']}" size="30" maxlength="40" />
							</td>
						</tr>
						<tr>
							<td>
								<label for="http_password">Password:</label>
								<br /><small>Enter a desired password at login, or leave blank for none.</small>
							</td>
							<td>
								<input type="password" name="http_password" value="${config['http_pass']}" size="30" maxlength="40" />
							</td>
						</tr>
						<tr>
							<td>
								<label for="launch_browser">Launch browser:</label>
								<br /><small>Enabling this feature will open Headphones at startup.</small>
							</td>
							<td>
								<input type="checkbox" name="launch_browser" value="1" ${config['launch_browser']} />
							</td>
						</tr>
						<!--end Startup-->
							
						<!--Layout/Theme-->
							<tr>
								<td><label for="interface">Interface:</label>
									<br /><small>Choose from a verity of different themes</small>
								</td>
								<td>
									<select  name="interface">
									%for interface in config['interface_list']:
										<%
											if interface == headphones.INTERFACE:
												selected = 'selected="selected"'
											else:
												selected = ''
										%>
										<option value="${interface}" ${selected}>
											${interface}
										</option>
									%endfor
									</select>
								</td>
							</tr>
						<!--end layout-->
						<!--API-->
							<tr>
								<td><h2>API:</h2>
									<small><label for="api_enabled">Enabled/Disabled</label></small></td>
								<td><input class="switch" type="checkbox" name="api_enabled" id="api_enabled" value="1" ${config['api_enabled']} /></td>
							</tr>
							<tr id="api_enabled_switch">
								<td>
									<table>
										<tr>
											<td colspan="2">
											<small>Current API:<strong id="api_key">${config['api_key']}</strong></small>
											<input class="submit" type="button" value="Generate" id="generate_api" />
											</td>
										</tr>
									</table>
								</td>
							</tr>
						<!--end API-->
						
						<!--Interval-->
							<tr>
								<td><h2><span class="wsr">P</span>Scan Intervals</h2></td>
							</tr>
							
							<!--NZB Scan-->
								<tr>
									<td>
										<label for="nzb_search_interval">NZB Search:</label><br />
										<small><label id="nzb_search_interval"></label></small>
									</td>
									<td>
										<div class="sliderInterval" for="nzb_search_interval"></div>
									</td>
									<td>
										<input type="text" name="nzb_search_interval" value="${config['nzb_search_interval']}" size="2" maxlength="10" />
									</td>
									<td>
									</td>
								</tr>
							<!--end NZB scan-->
							
							<!--Download Scan-->
							<tr>
								<td>
									<label for="download_scan_interval">Download folder scan every: </label><br />
									<small><label id="download_scan_interval"></label></small>
								</td>
								<td>
									<div class="sliderInterval" for="download_scan_interval"></div>
								</td>
								<td>
									<input type="text" name="download_scan_interval" value="${config['download_scan_interval']}" size="2" maxlength="10" />
								</td>
							</tr>
							<!--end Download Scan-->
							
							<!--Library Scan-->
							<tr>
								<td><label for="library_scan_interval">Library scan:</label><br />
									<small><label id="libraryscan_interval"></label></small>
								</td>
								<td>
									<div class="sliderInterval" for="libraryscan_interval"></div>
								</td>
								<td>
									<input type="text" name="libraryscan_interval" value="${config['libraryscan_interval']}" size="2" maxlength="10" />
								</td>
							</tr>
							<!--end Interval-->
					</table><!--end HTTP-->
				</div>
			</div>
			<!--end Web Interface-->
			
			<!--Download Settings-->
			<div id="DownloadSettings">
				<h1><span class="wsr">u</span>Download Settings</h1>
				<small>Setup SABnzbd or BitTorrent</small>
				
				<!--Sabnzdb-->
				<div>
					<table>
						<tr>
							<td>
								<h2>SABnzbd</h2>
								<small></small>
							</td>
							<td></td>
						</tr>
						<tr>
							<td><label for="sab_host">Host:</label>
								<br /><small>Usually http://localhost:8080</small>
							</td>
							<td><input type="text" name="sab_host" value="${config['sab_host']}" size="30" maxlength="40" /></td>
						</tr>
						<tr>
							<td><label for="sab_username">Username:</label>
								<br /><small>Type the user name for SABnzbd</small>
							</td>
							<td><input type="text" name="sab_username" value="${config['sab_user']}" size="20" maxlength="40" /></td>
						</tr>
						<tr>
							<td><label for="sab_password">Password:</label>
								<br /><small>Enter the password for SABnzbd</small>
							</td>
							<td><input type="password" name="sab_password" value="${config['sab_pass']}" size="20" maxlength="40" /></td>
						</tr>
						<tr>
							<td><label for="sab_apikey">API key:</label></td>
							<td><input type="text" name="sab_apikey" value="${config['sab_api']}" size="36" maxlength="40" /></td>
						</tr>
						<tr>
							<td><label for="sab_category">Category:</label>
								<small>Write the category label name from SABnzbd</small>
							</td>
							<td><input type="text" name="sab_category" value="${config['sab_cat']}" size="20" maxlength="40" /></td>
						</tr>
						<tr>
							<td>
								<label for="download_dir">Download Directory:</label>
								<br /><small>Full path to the directory where SAB downloads your music.</small>
							</td>
							<td><input type="text" name="download_dir" value="${config['download_dir']}" size="40" /></td>
						</tr>
					</table>
				</div>
				<!--end Sabnzdb-->
				
				<!--Torrents-->
				<div>
					<table>	
						<tr>
							<td><h2><span class="wsr">~</span>Torrents</h2></td>
							<td></td>
						</tr>
						<tr>
							<td>
								<label for="blackhole_dir">Black Hole Directory:</label>
								<br /><small>Folder your Download program watches for NZBs</small>
							</td>
							<td>
								<input type="text" name="blackhole_dir" value="${config['blackhole_dir']}" size="40" />
							</td>
						</tr>
						<tr>
							<td><label for="usenet_retention">Usenet Retention:</label>
								<br /><small>Binary retention time</small>
							</td>
							<td><input type="text" name="usenet_retention" value="${config['usenet_retention']}" size="5" maxlength="10" /></td>
						</tr>
						<tr>
							<td>
								<label for="torrentblackhole_dir">Black Hole Directory:</label>
								<br /><small>Folder your Download program watches for Torrents</small>
							</td>
							<td>
								<input type="text" name="torrentblackhole_dir" value="${config['torrentblackhole_dir']}" size="40">	
							</td>
						</tr>
						<tr>
							<td><label for="numberofseeders">Minimum seeders:</label>
								<br /><small>Number of minimum seeders a torrent must have to be accepted</small>
							</td>
							<td><input type="text" name="numberofseeders" value="${config['numberofseeders']}" size="5" /></td>
						</tr>
						<tr>
							<td>
								<label for="download_torent_dir">Music Download Directory:</label>
								<br /><small>Full path to the directory where your torrent client downloads your music <br />i.e. /Users/name/Downloads/music</small>
							</td>
							<td><input type="text" name="download_torrent_dir" value="${config['download_torrent_dir']}" size="40" /></td>
						</tr>
					</table>
				</div>
				<!--end Torrents-->
				
			</div>
			<!--end Download Settings-->
			
			<div><!--Search Providers-->
				<h2><span class="wsr">L</span> Search Providers</h2>
				<small>"We provide you with a automated search service to locate binary files/secgments that can be found on the public access network called Usenet."</small>

				<!--Newznab-->
				<div class="group">
					<table class="configtable">
						<tr>
							<td><input class="switch" type="checkbox" name="newznab" value="1" ${config['use_newznab']} /></td>
							<td>
								<h2><a href="http://www.newznab.com/" target="_blank"><span class="wsr">D</span>Newznab Providers</a></h2>
								<small><label for="newznab">Enabled/Disabled</label></small>
							</td>
						</tr>
					</table>
					<div class="group" id="newznab_switch">
						<div>
							<table id="newznab1">
								<tr><td>
										<label>Host:</label>
										<input type="text" name="newznab_host" value="${config['newznab_host']}" size="30">
										<br /><small>e.g. http://nzb.su</small>
									</td>
								</tr>
								<tr>
									<td>
										<label>API</label>
										<input type="text" name="newznab_apikey" value="${config['newznab_api']}" size="36">
									</td>
								</tr>
								<tr>
									<td>
										<input id="newznab_enabled" type="checkbox" name="newznab_enabled" value="1" ${config['newznab_enabled']} />
										<label>Enabled</label>
									</td>
								</tr>
								<tr>
									<td><input class="newznab-edit-extras" type="button" value ="Edit Extras"/></td>
								</tr>
							</table>
						</div>
						<div id="newznab-dialog">
							%for newznab in config['extra_newznabs']:
							<table id="newznab${newznab_number}">
								<tr>
									<td>
										<label>Newznab Host:</label>
										<input type="text" name="newznab_host${newznab_number}" value="${newznab[0]}" size="30">
									</td>
								</tr>
								<tr>
									<td>
										<label>Newznab API:</label>
										<input type="text" name="newznab_api${newznab_number}" value="${newznab[1]}" size="36">
									</td>
								</tr>
								<tr>
									<td>
										<input id="newznab_enabled" type="checkbox" name="newznab_enabled${newznab_number}" value="1" ${newznab_enabled} /><label>Enabled/Disabled</label>
									</td>
								</tr>
								<tr>
									<td>
										<input type="button" class="remove" id="newznab${newznab_number}" value="Remove ${newznab[0]}">
									</td>
								</tr>
							</table>
							%endfor
							<input type="button" value="Add Newznab" class="add_newznab" id="add_newznab" />
						</div>
					</div>
				</div>
				<!--end Newznab-->

				<!--NZBs.org-->
				<div class="group">
					<table>
						<tr>
							<td><input class="switch" type="checkbox" name="nzbsorg" value="1" ${config['use_nzbsorg']} /></td>
							<td><h2><a href="http://nzbs.org/" target="_blank"><span class="wsr">D</span>Nzbs.org</a></h2>
								<small><label for="nzbsorg"></label></small>
							</td>
						</tr>
					</table>
					<div class="group" id="nzbsorg_switch">
						<table>
							<tr>
								<td><label for="nzbsorg_hash">API Key:</label></td>
								<td><input type="text" name="nzbsorg_hash" value="${config['nzbsorg_hash']}" size="30" maxlength="40"></td>
							</tr>
						</table>
					</div>
				</div>
				<!--end NZBs.org-->
					
				<!--Torrents-->
				<table>
					<tr>
						<td>
							<h2>BitTorrent:</h2>
							<small>A peer-to-peer file sharing (P2P) communications protocol</small>
						</td>
						<td>
							<input type="checkbox" name="use_isohunt" value="1" ${config['use_isohunt']} />
							<label for="use_isohunt">Isohunt</label>
							<br /><br />
							<input type="checkbox" name="use_mininova" value="1" ${config['use_mininova']} />
							<label for="use_mininova">Mininova</label>
							<br /><br />
							<input type="checkbox" name="use_kat" value="1" ${config['use_kat']} />
							<label for="use_kat">Kick Ass Torrents:</label>
						</td>
					</tr>
				</table>
				<!--end Torrents-->
				
			</div>
			<!--end Search Providers-->
			
			<!--Quality-->
			<div id="Quality">
				<h1><span class="wsr">I</span> Quality & Post Processing</h1>
				<small></small>
				<table id="AlbumQuality">
					<tr>
						<td><h2>Album Quality:</h2>
							<small></small>
						</td>
						<td></td>
					</tr>
					<tr>
						<td><label for="prefered_quality">Prefered Quality:</label></td>
							<td>
								<input type="radio" name="preferred_quality" id="QualityExcluding" value="0" ${config['pref_qual_0']} />
								<label for="QualityExcluding">Highest Quality excl. Lossless</label>
								<br /><br />
								<input type="radio" name="preferred_quality" id="QualityIncluding" value="1" ${config['pref_qual_1']} />
								<label for="QualityIncluding">Highest Quality incl. Lossless</label>
								<br /><br />
								<input type="radio" name="preferred_quality" id="QualityLossless" value="2" ${config['pref_qual_2']} />
								<label for="QualityLossless">Lossless Only</label>
								<br /><br />
								<input type="radio" name="preferred_quality" id="QualityPreferred" value="3" ${config['pref_qual_3']} />
								<label for="QualityPreferred">Preferred Bitrate:
									<input type="text" name="preferred_bitrate" value="${config['pref_bitrate']}" size="3" maxlength="5" />kbps
								</label>
							</td>
					</tr>
					<tr>
						<td><label for="detect_bitrate">Auto-Detect Preferred Bitrate </label></td>
							<td><input type="checkbox" name="detect_bitrate" value="1" ${config['detect_bitrate']} /></td>
					</tr>
				</table>
				<!--PostProcessing-->
				<table class="configtable">
					<tr>
						<td><h2>Post Processing:</h2>
							<small></small>
						</td>
						<td>
							<input type="checkbox" name="move_files" value="1" ${config['move_files']} />
							<label for="move_files">Move Downloads</label>
							<br /><br />
							<input type="checkbox" name="rename_files" value="1" ${config['rename_files']} />
							<label for="rename_files">Rename files</label>
							<br /><br />
							<input type="checkbox" name="correct_metadata" value="1" ${config['correct_metadata']} />
							<label for="correct_metadata">Correct metadata</label>
							<br /><br />
							<input type="checkbox" name="cleanup_files" value="1" ${config['cleanup_files']} />
							<label for="cleanup_files">Delete leftover files (.m3u, .nfo, .sfv, .nzb, etc.):</label>
							<br /><br />
							<input type="checkbox" name="add_album_art" value="1" ${config['add_album_art']} />
							<label for="add_album_art">Add album art as 'folder.jpg' to album folder</label>
							<br /><br />
							<input type="checkbox" name="embed_album_art" value="1" ${config['embed_album_art']} />
							<label for="embed_album_art">Embed album art in each file</label>
							<br /><br />
							<input type="checkbox" name="embed_lyrics" value="1" ${config['embed_lyrics']} />
							<label for="embed_lyrics">Embed lyrics</label>
						</td>
					</tr>
					<tr>
						<td><label for="destination_dir">Music Folder:</label>
							<small>i.e. /Users/name/Music/iTunes or /Volumes/share/music</small>
						</td>
							<td><input type="text" name="destination_dir" value="${config['dest_dir']}" size="40" /></td>
					</tr>
				</table><!--end PostProcessing-->
			</div><!--end Quality-->
			
			<div id="AdvancedSettings"><!--AdvancedSettings-->
				<h1><span class="wsr">S</span>Advanced Settings</h1>
				<div><!--Renaming-->
					<table class="configtable">
						<tr>
							<td><h2><span class="wsr">T</span>Renaming</h2></td>
						</tr>
						<tr>
							<td><label for="folder_format">Folder Format:</label>
									<small>Use: $Artist/$artist, $Album/$album, $Year/$year, $Type/$type (release type) and $First/$first (first letter in artist name) <br />
										E.g.: $Type/$First/$artist/$album [$year] = Album/G/girl talk/all day [2010]</small>
							</td>
								<td><input type="text" name="folder_format" value="${config['folder_format']}" size="43" /></td>
						</tr>
						<tr>
							<td><label for="file_format">File Format:</label>
									<small>Use: $Disc/$disc (disc #), $Track/$track (track #), $Title/$title, $Artist/$artist, $Album/$album and $Year/$year</small>
							</td>
							<td><input type="text" name="file_format" value="${config['file_format']}" size="43" /></td>
						</tr>
					</table>
				</div><!--end Renaming-->
				<div><!--Miscellaneous-->
					<table id="Miscellaneous" class="configtable">
						<tr>
							<td><h2><span class="wsr">F</span>Miscellaneous</h2>
								<small>Customize what HP</small>
							</td>
							<td></td>
						</tr>
						<tr>
							<td>
								<h2>Automatically:</h2>
								<small>EPs, Compilations, Live Albums, Remix Albums and Singles</small>
							</td>
							<td>
								<input type="checkbox" name="include_extras" value="1" ${config['include_extras']} />
								<label for="include_extras">Include Extras When Adding an Artist</label>
								<br /><br />
								<input type="checkbox" name="autowant_upcoming" value="1" ${config['autowant_upcoming']} />
								<label for="autowant_upcoming">Mark Upcoming Albums as Wanted</label>
								<br /><br />
								<input type="checkbox" name="autowant_all" value="1" ${config['autowant_all']} />
								<label for="autowant_all">Mark All Albums as Wanted	</label>
							</td>
						</tr>
						<!--Logs-->
						<tr>
							<td>
								<label for="log_dir">Log Directory:</label>
							</td>
							<td>
								<input type="text" name="log_dir" value="${config['log_dir']}" size="40" />
							</td>
						</tr><!--end Logs-->
						<!--Cache-->
						<tr>
							<td>
								<label for="cache_dir">Cache Directory:</label>
							</td>
							<td>
								<input type="text" name="cache_dir" value="${config['cache_dir']}" size="40" />
							</td>
						</tr><!--end Cache-->
					</table>
				</div><!--end Miscellaneous-->
				
				<!--Re-Encoding Options-->
				<div id="Re-EncodingOptions">
					<h2>Re-Encoding Options</h2>
						<small>Re-encode downloads during postprocessing.<br />This option requires the lame or ffmpeg encoder.</small>
					<div><!--Encoder Options-->
						<table id="encoderoptions">
							<tr>
								<td colspan="2"><h2>Encoder Options</h2></td>
							</tr>
							<tr>
								<td><label for="encoderlossless">Only re-encode lossless files (.flac)</label></td>
								<td>
									<input type="checkbox" name="encoderlossless" value="1" ${config['encoderlossless']} />
									<%
										if config['encoder'] == 'lame':
											lameselect = 'selected="selected"'
											ffmpegselect = ''
										else:
											lameselect = ''
											ffmpegselect = 'selected="selected"'
									%>
								</td>
							 </tr>
							<tr>
								<td><label for="encoder">Encoder:</label></td>
								<td>
									<select name="encoder">
										<option value="lame" ${lameselect}>lame</option>
										<option value="ffmpeg" ${ffmpegselect}>ffmpeg</option>
									</select>
								</td>
							</tr>
							<tr>
								<td><label for="encoderoutputformat">Format:</label></td>
								<td>
									<select name="encoderoutputformat">
										%for x in ['mp3', 'ogg', 'm4a']:
										<%
											if config['encoderoutputformat'] == x:
												outputselect = 'selected'
											else:
												outputselect = ''
										%>
										<option value="${x}" ${outputselect}>${x}</option>
										%endfor
									</select>
								</td>
							</tr>
						</table>
					</div><!--end Encoder Options-->
				
					<div><!--Audio Properties-->
						<h2>Audio Properties</h2>
						<!--VBR/CBR-->
						<table class="configtable">
							<tr>
								<td><label for="encodervbrcbr">VBR/CBR:</label></td>
								<td><select name="encodervbrcbr">
								%for x in ['cbr', 'vbr']:
									<%
										if config['encodervbrcbr'] == x:
											outputselect = 'selected'
										else:
											outputselect = ''
									%>
									<option value=${x} ${outputselect}>${x}</option>
								%endfor
								</select></td>
							</tr><!--end VBR/CBR-->
						
							<tr><!--Quality-->
								<td><label for="encoderquality">Quality:</label></td>
								<td><select name="encoderquality">
									%for x in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
									<%
										if config['encoderquality'] == x:
											outputselect = 'selected'
										else:
											outputselect = ''
									%>
									<option value=${x} ${outputselect}>${x}</option>
									%endfor
								</select></td>
							</tr><!--end quality-->
						
							<!--Bitrate-->
							<tr>
								<td><label for="bitrate">Bitrate:</label></td>
								<td><select name="bitrate">
									%for x in [64, 128, 192, 256, 320]:
										<%
											if config["bitrate"] == x:
												bitrateselected = "selected"
											else:
												bitrateselected = ''
										%>	
										<option value=${x} ${bitrateselected}> ${x} kbps</option>
									%endfor
								</select>
						
								<%
									if config["samplingfrequency"] == 44100:
										freq44100 = 'selected="selected"'
										freq48000 = ''
									else:
										freq44100 = ''
										freq48000 = 'selected="selected"'
								%></td>
							</tr><!--end Bitrate-->
					
							<!--Samplings-->
							<tr>
								<td><label>Sampling: </label></td>
								<td><select name="samplingfrequency">
									<option value=44100 ${freq44100}>44.1 kHz</option>
									<option value=48000 ${freq48000}>48.0 kHz</option>
								</select></td>
							</tr><!--end Samplings-->
								
							<!--Advanced Encoding-->			
							<tr>
								<td>
									<label>Advanced Encoding Options:</label>
									<small>Ignores audio properties</small>
								</td>
									<td><input type="text" name="advancedencoder" value="${config['advancedencoder']}" size="43" /></td>
							</tr>
							<tr>
								<td><label>Path to Encoder:</label></td>
								<td><input type="text" name="encoderfolder" value="${config['encoderfolder']}" size="43" /></td>
							</tr><!--end Advanced Encoding-->
						</table>
					</div><!--Audio Properties-->
				</div><!--Re-Encoding Options-->
					
				<!--Notifications-->
				<div id="Notifications">
					<h1><span class="wsr">W</span> Notifications</h1>
					<small></small>
					<!--Prowl-->
					<div class="group">
					<table>
						<tr>
							<td><input class="switch" type="checkbox" name="prowl_enabled" id="prowl" value="1" ${config['prowl_enabled']} /></td>
							<td><h2>Prowl Options</h2>
								<small><label for="prowl_enabled">Enabled/Disabled</label></small>
							</td>
						</tr>
					</table>
					<div class="group" id="prowl_enabled_switch">
					<table>
						
						<tr>
							<td><label for="prowl_keys">API key:</label></td>
							<td><input type="text" name="prowl_keys" value="${config['prowl_keys']}" size="50" /></td>
						</tr>
						<tr>
							<td><label for="prowl_onsnatch">Notify on snatch</label></td>
							<td><input type="checkbox" name="prowl_onsnatch" value="1" ${config['prowl_onsnatch']} /></td>
						</tr>
							<tr><td><label for="prowl_priority">Priority (-2,-1,0,1 or 2):</label></td>
							<td><input type="text" name="prowl_priority" value="${config['prowl_priority']}" size="2"></td>
						</tr>
					</table>
					</div>
					</div>
					<!--end Prowl-->
					<!--XBMC-->
					<div class="group">
					<table>
						<tr>
							<td><input class="switch" type="checkbox" name="xbmc_enabled" id="xbmc" value="1" ${config['xbmc_enabled']} /></td>
							<td><h2>XBMC</h2>
								<small><label for="xbmc_enabled">Enabled/Disabled</label></small>
							</td>
						</tr>
					</table>
					<div class="group" id="xbmc_enabled_switch">
					<table>
						<tr>
							<td><label for="xbmc_host">XBMC Host:</label>
								<small>e.g. http://localhost:8080. Separate hosts with commas</small>
							</td>
							<td><input type="text" name="xbmc_host" value="${config['xbmc_host']}" size="30">
							</td>
						</tr>
						<tr>
							<td><label>XBMC Username:</label></td>
							<td><input type="text" name="xbmc_username" value="${config['xbmc_username']}" size="30"></td>
						</tr>
						<tr>
							<td><label>XBMC Password:</label></td>
							<td><input type="password" name="xbmc_password" value="${config['xbmc_password']}" size="30"></td>
						</tr>
						<tr>
							<td><label>Update XBMC Library:</label></td>
							<td><input type="checkbox" name="xbmc_update" value="1" ${config['xbmc_update']} /></td>
						</tr>
						<tr>
							<td><label>Send Notification to XBMC:</label></td>
							<td><input type="checkbox" name="xbmc_notify" value="1" ${config['xbmc_notify']} /></td>
						</tr>
					</table>
					</div>
					</div>
					<!--end XBMC-->
					
					<!--NMA Options-->
					<div class="group">
					<table>
						<tr>
							<td><input class="switch" type="checkbox" name="nma_enabled" id="nma" value="1" ${config['nma_enabled']} /></td>
							<td>
								<h2>Notify My Android</h2>
								<small><label for="nma_enabled">Enabled/Disabled</label></small>
							</td>
						</tr>
					</table>
					<div class="group" id="nma_enabled_switch">
					<table>
						<tr>
							<td><label for="nma_apikey">NotifyMyAndroid API Key:</label>
								<small>Separate multiple api keys with ",".</small>
							</td>
							<td><input type="text" name="nma_apikey" value="${config['nma_apikey']}" size="30"></td>
						</tr>
						<tr>
							<td><a href="https://play.google.com/store/apps/details?id=com.usk.app.notifymyandroid">Get NotifyMyAndroid</a></td>
						</tr>
						
						<tr>
							<td><label for="nma_onsnatch">Notify on snatch?</label></td>
								<td><input type="checkbox" name="nma_onsnatch" value="1" ${config['nma_onsnatch']} /></td>
						</tr>
						
						<!--Priority-->
						<tr>
							<td><label for="nma_priority">Priority:</label></td>
							<td>
								<select name="nma_priority">
									%for x in [-2,-1,0,1,2]:
										<%
											if config['nma_priority'] == x:
												nma_priority_selected = 'selected'
											else:
												nma_priority_selected = ''
											
											if x == -2:
												nma_priority_value = 'Very Low'
											elif x == -1:
												nma_priority_value = 'Moderate'
											elif x == 0:
												nma_priority_value = 'Normal'
											elif x == 1:
												nma_priority_value = 'High'
											else:
												nma_priority_value = 'Emergency'
										%>
										<option value=${x} ${nma_priority_selected}>${nma_priority_value}</option>
									%endfor
								</select>
							</td>
						</tr><!--end Priority-->
					</table><!--end NMA Options-->
					</div>
				</div><!--end Notifications-->
				
				<div id="NAS">
					<h2>Synology NAS</h2>
					<table>
						<tr>
							<td>
								<input type="checkbox" name="synoindex_enabled" id="synoindex" value="1" ${config['synoindex_enabled']} /><label>Enable Synoindex</label>
							</td>
						</tr>
					</table>
				</div>
				<!--Mirror-->
				<div id="Mirror">
					<h2><span class="wsr">K</span>Mirror</h2>
					<!--Musicbrainz-->
					<table>
						<tr>
							<td><label for="mirror">Musicbrainz Mirror:</label></td>
							<td>
								<select name="mirror" id="mirror">
									%for mirror in config['mirror_list']:
										<%
											if mirror == headphones.MIRROR:
												selected = 'selected="selected"'
											else:
												selected = ''
										%>
										<option value="${mirror}" ${selected}>${mirror}</option>
									%endfor
								</select>
							</td>
						</tr>
					</table><!--end Musicbrainz-->
							
					<!--Custom options-->
					<table id="customoptions">
						<tr><td colspan="2"><h2>Custom Options</h2></td></tr>
						<tr>
							<td><label for="customhost">Host:</label></td>
							<td><input type="text" name="customhost" value="${config['customhost']}" size="20"></td>
						</tr>
						<tr>
							<td><label for="customport">Port:</label></td>
							<td><input type="text" name="customport" value="${config['customport']}" size="8"></td>
						</tr>
						<tr>
							<td><label for="customsleep">Sleep Interval:</label></td>
							<td><input type="text" name="customsleep" value="${config['customsleep']}" size="4"></td>
						</tr>
					</table>
					<!--end Custom options-->
											
					<!--Hp server options-->
					<table id="hpserver">
						<tr>
							<td><h2>Headphones Server</h2>
								<small><a href="http://headphones.codeshy.com/vip" target="_blank"><span class="wsr">D</span>Get an Account</a></small>
							</td>
							<td></td>
						</tr>
						<tr>
							<td><label for="hpuser">Username:</label></td>
							<td><input type="text" name="hpuser" value="${config['hpuser']}" size="20"></td>
						</tr>
						<tr>
							<td><label for="hppass">Password:</label></td>
							<td><input type="password" name="hppass" value="${config['hppass']}" size="15"></td>
						</tr>
					</table>
					<!--end hp server options-->
					
					
				</div><!--End mirror-->
				
			</div><!--end AdvancedSettings-->
		</div><!--end config wrapper-->
    </form>
</%def>

<%def name="javascriptIncludes()">
	<script>
		$(document).ready(function(){
			$('#api_key').click(function(){ $('#api_key').select() });
			$("#generate_api").click(function(){
				$.get('generateAPI', 
					function(data){
						if (data.error != undefined) {
							alert(data.error);
							return;
						}
						$('#api_key').val(data);
				});
			});
		
			$("#newznab-dialog").hide();
			$(".newznab-edit-extras").click(function(){
				$("#newznab-dialog").dialog();
			});
			$(".submitForm").click(function(){
				$("#config").submit();
			});
			//Newznab
			var deletedNewznabs = 0;
			$(".remove").click(function() {
				$(this).parent().parent().remove();
				deletedNewznabs = deletedNewznabs + 1;
			});
			
			$("#add_newznab").click(function() {
				var intId = $("#newznab-dialog > table").size() + deletedNewznabs + 1;
				alert(intId);
				var rowStart = "<tr><td>";
				var rowEnd = "</td></tr>";
				var formfields = $("<table id='newznab" + intId + "'>" +
								rowStart +
								"<label>Newznab Host</label>" +
								"<input type='text' name='newznab_host" + intId + "' size='30'>" +
								rowEnd +
								rowStart +
										"<label>Newznab API</label>" +
										"<input type='text' name='newznab_api" + intId + "' size='36'>" +
								rowEnd +
								rowStart +
									"<input type='checkbox' name='newznab_enabled" + intId + "' value='1' checked />" + 
									"<label>Enabled</label>" + 
								rowEnd);
				var removeButton = $(rowStart + "<input type='button' class='remove' value='Remove' />" + rowEnd);
				removeButton.click(function() {
				$(this).parent().remove();
					deletedNewznabs = deletedNewznabs - 1;
				});
				formfields.append(removeButton);
				formfields.append("</table>");
				$("#add_newznab").before(formfields);
			});
		
			//Mirrors
			
			function mirror(){
				var value = $("#mirror").val();
				if( value == "musicbrainz.org" ){
					$("table#customoptions").hide();
					$("table#hpserver").hide();
					enit();
				} else if ( value == "headphones" ){
					$("table#customoptions").hide();
					$("table#hpserver").show();
					enit();
				} else if ( value == "custom" ){
					$("table#customoptions").show();
					$("table#hpserver").hide();
					enit();
				}
			}
			mirror();
			$("#mirror").change(function(){
				mirror();
			});
			//end Mirrors
			
			enit();
		});
	</script>
</%def>
