<!--#set global $topmenu="config"#-->
<!--#set global $statpath="../.."#-->
<!--#set global $helpsubject="Configure+Sorting-0-7"#-->
<!--#include $webdir + "/inc_top.tmpl"#-->

<!--#set global $submenu="sorting"#-->
<!--#include $webdir + "/inc_cmenu.tmpl"#-->

<script type="text/javascript">
  function tvAdd(val){
    var tv = document.getElementById('tvfoldername');
    tv.value = tv.value + val;
    previewtv();
  }
  function tvSet(val){
    var tv = document.getElementById('tvfoldername');
    tv.value = val;
    previewtv();
  }
  function tvClear(){
    var tv = document.getElementById('tvfoldername');
    tv.value = '';
    previewtv();
  }
  function previewtv(){
    var input = document.getElementById('tvfoldername').value;
    var slash = "\\";
    input.toLowerCase()
    input = input.replace(/%ext/g,'avi');
    input = input.replace(/%sn/g,'$T("show-sp-name")');
    input = input.replace(/%s\.n/g,'$T("show-dot-name")');
    input = input.replace(/%s\_n/g,'$T("show-us-name")');
    input = input.replace(/%0s/g,'01');
    input = input.replace(/%s/g,'1');
    input = input.replace(/%en/g,'$T("ep-sp-name")');
    input = input.replace(/%e\.n/g,'$T("ep-dot-name")');
    input = input.replace(/%e\_n/g,'$T("ep-us-name")');
    input = input.replace(/%0e/g,'05');
    input = input.replace(/%e/g,'5');
    input = input.replace(/%fn/g,'$T("sort-File")');
    input = input.replace(/%dn/g,'$T("sort-Folder")');

  document.getElementById('previewtv').innerHTML = getOutput(input);
}

  function getOutput(input){
    var slash = "\\";
    var com = document.getElementById('complete_dir').value;

  // For some reason a simply replace() doesn't replace multiple / characters
  // Work out whether we are using / or \
  for (i=0; i<com.length; i++){
    if (com[i] == "/") slash = "/";
  }

  // Replace / or \ with whatever complete_dir uses
  for (i=0; i<input.length; i++){
    if (input[i] == "/") {
      input = input.replace("/",slash, "gi");
    } else if (input[i] == "\\") {
      input = input.replace("\\",slash, "gi");
    }
  }

  // If the complete_dir ends in / or \, then strip that character
  len = com.length
  if (com.substring(len-1, len) == slash)
  {
    com = com.substring(0, len-1)
  }

  // If the pattern starts with absolute path, don't prepend default folder
  if (input[0] == "/" || input[0] == slash || input[1] == ':') {
    output = input;
  } else {
    output = com+slash+input;
  }
  return output
}

  function movieAdd(val){
    var tv = document.getElementById('moviefoldername');
    tv.value = tv.value + val;
    previewmovie();
  }
  function movieSet(val, val2){
    var tv = document.getElementById('moviefoldername');
    tv.value = val;
    var tv2 = document.getElementById('movieextra');
    tv2.value = val2;
    previewmovie();
  }
  function movieClear(){
    var tv = document.getElementById('moviefoldername');
    tv.value = '';
    previewmovie();
  }
  function movieClearExtra(){
    var tv = document.getElementById('movieextra');
    tv.value = '';
    previewmovie();
  }
  function movieExtraFolder(value)
  {
    document.getElementById('movie_extra_folder').checked = value;
  }
  function previewmovie()
  {
    var input = document.getElementById('moviefoldername').value;
    var input2 = document.getElementById('movieextra').value;
    extra = input2.replace(/%1/g,'1');
    var slash = "\\";
    ext = extra + '.avi'
    input = input.replace(/\.%ext/g,ext);
    input = input.replace(/%ext/g,'avi');
    input = input.replace(/%title/g,'$T("movie-sp-name")');
    input = input.replace(/%\.title/g,'$T("movie-dot-name")');
    input = input.replace(/%\_title/g,'$T("movie-us-name")');
    input = input.replace(/%y/g,'2000');
    input = input.replace(/%decade/g,'00');
    input = input.replace(/%0decade/g,'2000');
    input = input.replace(/%fn/g,'$T("sort-File")');

  var regex = /\{([^\{]*)\}/g;
  var str = input;
  var result;
  while ((result = regex.exec(str)) != null)
  {
    var lower = result[0].toLowerCase();
    input = input.replace(result[0],lower);
  }
  input = input.replace(/{/g,'');
  input = input.replace(/}/g,'');

  document.getElementById('previewmovie').innerHTML = getOutput(input);
}
function dateSet(val){
  var tv = document.getElementById('datefoldername');
  tv.value = val;
  previewdate();
}
function dateClear(){
  var tv = document.getElementById('datefoldername');
  tv.value = '';
  previewdate();
}
function previewdate(){
  var input = document.getElementById('datefoldername').value;
  var slash = "\\";
  input.toLowerCase()
  input = input.replace(/%ext/g,'avi');
  input = input.replace(/%t/g,'$T("show-sp-name")');
  input = input.replace(/%\.t/g,'$T("show-dot-name")');
  input = input.replace(/%\_t/g,'$T("show-us-name")');
  input = input.replace(/%decade/g,'00');
  input = input.replace(/%0decade/g,'2000');
  input = input.replace(/%fn/g,'$T("sort-File")');
  input = input.replace(/%desc/g,'$T("ep-sp-name")');
  input = input.replace(/%\.desc/g,'$T("ep-dot-name")');
  input = input.replace(/%\_desc/g,'$T("ep-us-name")');
  input = input.replace(/%0d/g,'02');
  input = input.replace(/%d/g,'2');
  input = input.replace(/%0m/g,'01');
  input = input.replace(/%m/g,'1');
  input = input.replace(/%y/g,'2009');

  document.getElementById('previewdate').innerHTML = getOutput(input);
}
function showDiv(id)
{
  disp = (document.getElementById(id).style.display == "block") ? "none" : "block";
  document.getElementById(id).style.display = disp;
}
</script>

<h2>$T('configSort')</h2>

<form action="saveSorting" method="post">
<div class="EntryBlock">
  <fieldset class="EntryFieldSet">

<legend>$T('seriesSorting')</legend>

  <input class="radio" type="checkbox" name="enable_tv_sorting" value="1" <!--#if $enable_tv_sorting > 0 then "checked=1" else ""#--> /> <strong>$T('opt-tvsort')</strong><br class="clear" />
  <br class="clear" />
  <strong>$T('affectedCat'):</strong>
  <br class="clear" />
  <select name="tv_cat" multiple="multiple" size=4 class="multiple_cats">
    <!--#for $ct in $cat_list#-->
      <option value="$ct" <!--#if $ct in $tv_categories then 'selected' else ''#--> >$Tspec($ct)</option>
    <!--#end for#-->
  </select>
  <br class="clear" /><br class="clear" />

  <a href="#toggle" onclick="javascript:showDiv('Keytable')">$T('sort-legenda')</a>
    <div id="Keytable">
      <div class="row">
        <span class="heading1">$T('sort-meaning')</span>
        <span class="heading2">$T('sort-pattern')</span>
        <span class="heading3">$T('sort-result')</span>
      </div>
      <div class="row">
        <span class="tripleheight">$T('show-name')</span>
        <span class="pattern">%sn</span>
        <span class="result">$T('show-sp-name')</span>
      <br />
        <span class="pattern">%s.n</span>
        <span class="result">$T('show-dot-name')</span>
      <br />
        <span class="pattern">%s_n</span>
        <span class="result">$T('show-us-name')</span>
      </div>
      <div class="row">
        <span class="doubleheight">$T('show-seasonNum')</span>
        <span class="pattern">%s</span>
        <span class="result">1</span>
      <br />
        <span class="pattern">%0s</span>
        <span class="result">01</span>
      </div>
      <div class="row">
        <span class="doubleheight">$T('show-epNum')</span>
        <span class="pattern">%e</span>
        <span class="result">5</span>
      <br />
        <span class="pattern">%0e</span>
        <span class="result">05</span>
      </div>
      <div class="row">
        <span class="tripleheight">$T('ep-name')</span>
        <span class="pattern">%en</span>
        <span class="result">$T('ep-sp-name')</span>
      <br />
        <span class="pattern">%e.n</span>
        <span class="result">$T('ep-dot-name')</span>
      <br />
        <span class="pattern">%e_n</span>
        <span class="result">$T('ep-us-name')</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('fileExt')</span>
        <span class="pattern">%ext</span>
        <span class="result">avi</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('orgFilename')</span>
        <span class="pattern">%fn</span>
        <span class="result">$T("sort-File")</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('orgDirname')</span>
        <span class="pattern">%dn</span>
        <span class="result">$T("sort-Folder")</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('lowercase')</span>
        <span class="pattern">{$T('TEXT')}</span>
        <span class="result">$T('text')</span>
      </div>
      <!--
      <span class="">$T('orgFilename')</span>
      <span class="">%fn</span>
      <span class="">$T('ep-name')</span>
      <br />-->
  </div><br class="clear" />
  <strong>$T('sortString'):</strong><br class="clear" />
  <input type="text" style="width:400px" size="80" id="tvfoldername" name="tv_sort_string" value="$tv_sort_string" onkeyup="javascript:previewtv()"><input type="button" style="width:100px;" onclick="tvClear()" value="$T('button-clear')"/><br class="clear" />
  <strong>$T('presetSort'):</strong><br class="clear" />
  <input type="button" onclick="tvSet('%sn/Season %s/%sn - %sx%0e - %en.%ext')" value="$T('button-Season1x05')"/>
  <input type="button" onclick="tvSet('%sn/Season %s/%sn - S%0sE%0e - %en.%ext')" value="$T('button-SeasonS01E05')"/>
  <input type="button" onclick="tvSet('%sn/%sx%0e - %en/%sn - %sx%0e - %en.%ext')" value="$T('button-Ep1x05')"/>
  <input type="button" onclick="tvSet('%sn/S%0sE%0e - %en/%sn - S%0sE%0e - %en.%ext')" value="$T('button-EpS01E05')"/><br class="clear" />
  <br class="clear" />
  $T('example'): <span id="previewtv"></span>
  <br class="clear" /><br class="clear" />
</fieldset>
<br />
  <fieldset class="EntryFieldSet">
<legend>$T('genericSort')</legend>
  <input id="complete_dir" type="hidden" value="$complete_dir" />
  <input class="radio" type="checkbox" name="enable_movie_sorting" value="1" <!--#if $enable_movie_sorting > 0 then "checked=1" else ""#--> /> <strong>$T('opt-movieSort')</strong>
  <br class="clear" /><br class="clear" />
  <input class="radio" type="checkbox" name="movie_extra_folder" value="1" <!--#if $movie_extra_folder > 0 then "checked=1" else ""#--> /> <strong>$T('opt-movieExtra')</strong>
  <br class="clear" /><br class="clear" />
  <strong>$T('affectedCat'):</strong>
  <br class="clear" />
  <select name="movie_cat" multiple="multiple" size=4 class="multiple_cats">
    <!--#for $ct in $cat_list#-->
      <option value="$ct" <!--#if $ct in $movie_categories then 'selected' else ''#--> >$Tspec($ct)</option>
    <!--#end for#-->
  </select>

  <br class="clear" /><br class="clear" />
  <a href="#toggle" onclick="javascript:showDiv('Keytable2')">$T('sort-legenda')</a>
    <div id="Keytable2">
      <div class="row">
        <span class="heading1">$T('sort-meaning')</span>
        <span class="heading2">$T('sort-pattern')</span>
        <span class="heading3">$T('sort-result')</span>
      </div>
      <div class="row">
        <span class="tripleheight">$T('sort-title')</span>
        <span class="pattern">%title</span>
        <span class="result">$T('movie-sp-name')</span>
      <br />
        <span class="pattern">%.title</span>
        <span class="result">$T('movie-dot-name')</span>
      <br />
        <span class="pattern">%_title</span>
        <span class="result">$T('movie-us-name')</span>
      </div>
      <div class="row">
        <span class="doubleheight">$T('year')</span>
        <span class="pattern">%y</span>
        <span class="result">2000</span>
      </div>
      <div class="row">
        <span class="doubleheight">$T('extension')</span>
        <span class="pattern">%ext</span>
        <span class="result">avi</span>
      </div>
      <div class="row">
        <span class="doubleheight">$T('partNumber')</span>
        <span class="pattern">%1</span>
        <span class="result">1</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('decade')</span>
        <span class="pattern">%decade</span>
        <span class="result">00</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('decade')</span>
        <span class="pattern">%0decade</span>
        <span class="result">2000</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('orgFilename')</span>
        <span class="pattern">%fn</span>
        <span class="result">$T('sort-File')</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('lowercase')</span>
        <span class="pattern">{$T('TEXT')}</span>
        <span class="result">$T('text')</span>
      </div>
  </div><br class="clear" /><br class="clear" />
  <strong>$T('sortString'):</strong><br class="clear" />
  <input type="text" style="width:400px" size="80" id="moviefoldername" name="movie_sort_string" value="$movie_sort_string" onkeyup="javascript:previewmovie()"><input type="button" onclick="movieClear()" style="width:100px;" value="$T('button-clear')"/><br class="clear" />
  <strong>$T('multiPartLabel'):</strong><br class="clear" />
  <input type="text" style="width:400px" size="80" id="movieextra" name="movie_sort_extra" value="$movie_sort_extra" onkeyup="javascript:previewmovie()"><input type="button" onclick="movieClearExtra()" style="width:100px;" value="$T('button-clear')"/><br class="clear" />
  <strong>$T('presetSort'):</strong><br class="clear" />
  <input type="button" onclick="movieSet('%title (%y)/%title (%y).%ext',' CD%1');movieExtraFolder(false)" value="$T('button-inFolders')"/>
  <input type="button" onclick="movieSet('%title (%y).%ext',' CD%1');movieExtraFolder(true)" value="$T('button-noFolders')"/><br class="clear" />
  <br class="clear" />
  $T('example'): <span id="previewmovie"></span>
  <br class="clear" /><br class="clear" />
</fieldset>
<br />
<fieldset class="EntryFieldSet">
<legend>$T('dateSorting')</legend>

  <input class="radio" type="checkbox" name="enable_date_sorting" value="1" <!--#if $enable_date_sorting > 0 then "checked=1" else ""#--> /> <strong>$T('opt-dateSort')</strong><br class="clear" />
  <br class="clear" />
  <strong>$T('affectedCat'):</strong>
  <br class="clear" />
  <select name="date_cat" multiple="multiple" size=4 class="multiple_cats">
    <!--#for $ct in $cat_list#-->
      <option value="$ct" <!--#if $ct in $date_categories then 'selected' else ''#--> >$Tspec($ct)</option>
    <!--#end for#-->
  </select>
  <br class="clear" /><br class="clear" />
  <a href="#toggle" onclick="javascript:showDiv('Keytable3')">$T('sort-legenda')</a>
    <div id="Keytable3">
      <div class="row">
        <span class="heading1">$T('sort-meaning')</span>
        <span class="heading2">$T('sort-pattern')</span>
        <span class="heading3">$T('sort-result')</span>
      </div>
      <div class="row">
        <span class="tripleheight">$T('show-name')</span>
        <span class="pattern">%t</span>
        <span class="result">$T('show-sp-name')</span>
      <br />
        <span class="pattern">%.t</span>
        <span class="result">$T('show-dot-name')</span>
      <br />
        <span class="pattern">%_t</span>
        <span class="result">$T('show-us-name')</span>
      </div>
      <div class="row">
        <span class="doubleheight">$T('year')</span>
        <span class="pattern">%y</span>
        <span class="result">2009</span>
      </div>
      <div class="row">
        <span class="doubleheight">$T('month')</span>
        <span class="pattern">%m</span>
        <span class="result">1</span>
      <br />
        <span class="pattern">%0m</span>
        <span class="result">01</span>
      </div>
      <div class="row">
        <span class="tripleheight">$T('day-of-month')</span>
        <span class="pattern">%d</span>
        <span class="result">2</span>
      <br />
        <span class="pattern">%0d</span>
        <span class="result">02</span>
      <br />
      </div>
      <div class="row">
        <span class="normalheight">$T('decade')</span>
        <span class="pattern">%decade</span>
        <span class="result">00</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('decade')</span>
        <span class="pattern">%0decade</span>
        <span class="result">2000</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('orgFilename')</span>
        <span class="pattern">%fn</span>
        <span class="result">$T('sort-File')</span>
      </div>
      <div class="row">
        <span class="normalheight">$T('lowercase')</span>
        <span class="pattern">{$T('TEXT')}</span>
        <span class="result">$T('text')</span>
      </div>
  </div><br class="clear" />
  <strong>$T('sortString'):</strong><br class="clear" />
  <input type="text" style="width:400px" size="80" id="datefoldername" name="date_sort_string" value="$date_sort_string" onkeyup="javascript:previewdate()"><input type="button" style="width:100px;" onclick="dateClear()" value="$T('button-clear')"/><br class="clear" />
  <strong>$T('presetSort'):</strong><br class="clear" />
  <input type="button" onclick="dateSet('%t/%t - %y-%0m-%0d - %desc.%ext')" value="$T('button-ShowNameF')"/>
  <input type="button" onclick="dateSet('%y-%0m/%t - %y-%0m-%0d - %desc.%ext')" value="$T('button-YMF')"/>
  <input type="button" onclick="dateSet('%y-%0m-%0d/%t - %y-%0m-%0d - %desc.%ext')" value="$T('button-DailyF')"/><br class="clear" />
  <br class="clear" />
  $T('example'): <span id="previewdate"></span>
</fieldset>


</div><br>
<input type="hidden" name="session" value="$session">
<input type="submit" size="40" value="$T('button-saveChanges')">
</form>

<!--#include $webdir + "/inc_bottom.tmpl"#-->
