<!--#set global $pane="Sorting"#-->
<!--#set global $help_uri="Configure+Sorting-0-7"#-->
<!--#include $webdir + "/_inc_header.tmpl"#-->

<script type="text/javascript">

  // *********************************************************
  // the following is for the Sorting Config -- author: switch

  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>







<form action="saveSorting" method="post" name="fullform">
<input type="hidden" name="session" value="$session">
<input id="complete_dir" type="hidden" value="$complete_dir" />


<div id="config-components">

  <div id="core-component-group1" class="component-group clearfix">
    <div class="component-group-desc">
      <h3>$T('seriesSorting')</h3>
      <p><strong>$T('affectedCat'):</strong><br/>
      <select name="tv_cat" multiple="multiple" 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></p>
    </div>
    <fieldset class="component-group-list">
      <div class="field-pair">
        <input type="checkbox" name="enable_tv_sorting" id="enable_tv_sorting" value="1" <!--#if $enable_tv_sorting > 0 then "checked=1" else ""#--> />
        <label class="clearfix" for="enable_tv_sorting">
          <span class="component-title">$T('opt-tvsort')</span>
        </label>
      </div>
      <div class="field-pair alt">
        <label class="nocheck clearfix" for="tvfoldername">
          <span class="component-title">$T('sortString')</span>
          <input type="text" size="50" id="tvfoldername" name="tv_sort_string" value="$tv_sort_string" onkeyup="javascript:previewtv()">
          <input type="button" class="juiButton" onclick="tvClear()" value="$T('button-clear')"/>
        </label>
      </div>
      <div class="field-pair">
        <div class="nocheck clearfix">
          <span class="component-title">$T('presetSort')</span>
          <span class="component-desc">
            <input type="button" class="juiButton" onclick="tvSet('%sn/Season %s/%sn - %sx%0e - %en.%ext')" value="$T('button-Season1x05')"/>
            <input type="button" class="juiButton" onclick="tvSet('%sn/Season %s/%sn - S%0sE%0e - %en.%ext')" value="$T('button-SeasonS01E05')"/>
          </span>
        </div>
        <div class="nocheck clearfix">
          <span class="component-title">&nbsp;</span>
          <span class="component-desc">
            <input type="button" class="juiButton" onclick="tvSet('%sn/%sx%0e - %en/%sn - %sx%0e - %en.%ext')" value="$T('button-Ep1x05')"/>
            <input type="button" class="juiButton" onclick="tvSet('%sn/S%0sE%0e - %en/%sn - S%0sE%0e - %en.%ext')" value="$T('button-EpS01E05')"/>
          </span>
        </div>
      </div>
      <div class="field-pair alt">
        <label class="nocheck clearfix">
          <span class="component-title">$T('example')</span>
          <span class="component-desc" id="previewtv"></span>
        </label>
      </div>
      <div class="field-pair">
        <label class="nocheck clearfix">
          <span class="component-title">$T('sort-legenda')</span>
          <input type="button" class="juiButton" value="$T('sort-legenda')" onclick="jQuery(this).hide(); jQuery('#Key1').show();"/>
          <table id="Key1" style="display:none">
            <thead><tr>
              <th align="right"><u>$T('sort-meaning')</u></th>
              <th><u>$T('sort-pattern')</u></th>
              <th><u>$T('sort-result')</u></th>
            </tr></thead>
            <tr>
              <td align="right"><strong>$T('show-name'):</strong></td>
              <td>%sN</td>
              <td>$T('show-sp-name')</td>
            </tr><tr>
              <td></td>
              <td>%s.N</td>
              <td>$T('show-dot-name')</td>
            </tr><tr>
              <td></td>
              <td>%s_N</td>
              <td>$T('show-us-name')</td>
            </tr><tr>
            <tr>
              <td></td>
              <td>%sn</td>
              <td>$T('show-sp-name') ($T('case-adjusted'))</td>
            </tr><tr>
              <td></td>
              <td>%s.n</td>
              <td>$T('show-dot-name') ($T('case-adjusted'))</td>
            </tr><tr>
              <td></td>
              <td>%s_n</td>
              <td>$T('show-us-name') ($T('case-adjusted'))</td>
            </tr><tr>
              <td align="right"><strong>$T('show-seasonNum'):</strong></td>
              <td>%s</td>
              <td>1</td>
            </tr><tr>
              <td></td>
              <td>%0s</td>
              <td>01</td>
            </tr><tr>
              <td align="right"><strong>$T('show-epNum'):</strong></td>
              <td>%e</td>
              <td>5</td>
            </tr><tr>
              <td></td>
              <td>%0e</td>
              <td>05</td>
            </tr><tr>
              <td align="right"><strong>$T('ep-name'):</strong></td>
              <td>%en</td>
              <td>$T('ep-sp-name')</td>
            </tr><tr>
              <td></td>
              <td>%e.n</td>
              <td>$T('ep-dot-name')</td>
            </tr><tr>
              <td></td>
              <td>%e_n</td>
              <td>$T('ep-us-name')</td>
            </tr><tr>
              <td align="right"><strong>$T('fileExt'):</strong></td>
              <td>%ext</td>
              <td>avi</td>
            </tr><tr>
              <td align="right"><strong>$T('orgFilename'):</strong></td>
              <td>%fn</td>
              <td>$T("sort-File")</td>
            </tr><tr>
              <td align="right"><strong>$T('orgDirname'):</strong></td>
              <td>%dn</td>
              <td>$T("sort-Folder")</td>
            </tr><tr>
              <td align="right"><strong>$T('lowercase'):</strong></td>
              <td>{$T('TEXT')}</td>
              <td>$T('text')</td>
            </tr>
          </table>
        </label>
      </div>
    </fieldset>
  </div><!-- /component-group1 -->

  <div id="core-component-group2" class="component-group clearfix">
    <div class="component-group-desc">
      <h3>$T('genericSort')</h3>
      <p><strong>$T('affectedCat'):</strong><br/>
      <select name="movie_cat" multiple="multiple" 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></p>
    </div>
    <fieldset class="component-group-list">
      <div class="field-pair">
        <input type="checkbox" name="enable_movie_sorting" id="enable_movie_sorting" value="1" <!--#if $enable_movie_sorting > 0 then "checked=1" else ""#--> />
        <label class="clearfix" for="enable_movie_sorting">
          <span class="component-title">$T('opt-movieSort')</span>
        </label>
      </div>
      <div class="field-pair alt">
        <input type="checkbox" name="movie_extra_folder" id="movie_extra_folder" value="1" <!--#if $movie_extra_folder > 0 then "checked=1" else ""#--> />
        <label class="clearfix" for="movie_extra_folder">
          <span class="component-title">$T('opt-movieExtra')</span>
        </label>
      </div>
      <div class="field-pair">
        <label class="nocheck clearfix" for="moviefoldername">
          <span class="component-title">$T('sortString')</span>
          <input type="text" size="50" id="moviefoldername" name="movie_sort_string" value="$movie_sort_string" onkeyup="javascript:previewmovie()">
          <input type="button" class="juiButton" onclick="movieClear()" value="$T('button-clear')"/>
        </label>
      </div>
      <div class="field-pair alt">
        <label class="nocheck clearfix" for="movieextra">
          <span class="component-title">$T('multiPartLabel')</span>
          <input type="text" size="50" id="movieextra" name="movie_sort_extra" value="$movie_sort_extra" onkeyup="javascript:previewmovie()">
          <input type="button" class="juiButton" onclick="movieClearExtra()" value="$T('button-clear')"/>
        </label>
      </div>
      <div class="field-pair">
        <div class="nocheck clearfix">
          <span class="component-title">$T('presetSort')</span>
          <input type="button" class="juiButton" onclick="movieSet('%title (%y)/%title (%y).%ext',' CD%1');movieExtraFolder(false)" value="$T('button-inFolders')"/>
          <input type="button" class="juiButton" onclick="movieSet('%title (%y).%ext',' CD%1');movieExtraFolder(true)" value="$T('button-noFolders')"/>
        </div>
      </div>
      <div class="field-pair alt">
        <label class="nocheck clearfix">
          <span class="component-title">$T('example')</span>
          <span class="component-desc" id="previewmovie"></span>
        </label>
      </div>
      <div class="field-pair">
        <label class="nocheck clearfix">
          <span class="component-title">$T('sort-legenda')</span>
          <input type="button" class="juiButton" value="$T('sort-legenda')" onclick="jQuery(this).hide(); jQuery('#Key2').show();"/>
          <table id="Key2" style="display:none">
            <thead><tr>
              <th align="right"><u>$T('sort-meaning')</u></th>
              <th><u>$T('sort-pattern')</u></th>
              <th><u>$T('sort-result')</u></th>
            </tr></thead>
            <tr>
              <td align="right"><strong>$T('sort-title'):</strong></td>
              <td>%title</td>
              <td>$T('movie-sp-name')</td>
            </tr><tr>
              <td></td>
              <td>%.title</td>
              <td>$T('movie-dot-name')</td>
            </tr><tr>
              <td></td>
              <td>%_title</td>
              <td>$T('movie-us-name')</td>
            </tr><tr>
              <td align="right"><strong>$T('year'):</strong></td>
              <td>%y</td>
              <td>2000</td>
            </tr><tr>
              <td align="right"><strong>$T('extension'):</strong></td>
              <td>%ext</td>
              <td>avi</td>
            </tr><tr>
              <td align="right"><strong>$T('partNumber'):</strong></td>
              <td>%1</td>
              <td>1</td>
            </tr><tr>
              <td align="right"><strong>$T('decade'):</strong></td>
              <td>%decade</td>
              <td>00</td>
            </tr><tr>
              <td></td>
              <td>%0decade</td>
              <td>2000</td>
            </tr><tr>
              <td align="right"><strong>$T('orgFilename'):</strong></td>
              <td>%fn</td>
              <td>$T('sort-File')</td>
            </tr><tr>
              <td align="right"><strong>$T('lowercase'):</strong></td>
              <td>{$T('TEXT')}</td>
              <td>$T('text')</td>
            </tr>
          </table>
        </label>
      </div>
    </fieldset>
  </div><!-- /component-group2 -->

  <div id="core-component-group3" class="component-group clearfix">
    <div class="component-group-desc">
      <h3>$T('dateSorting')</h3>
      <p><strong>$T('affectedCat'):</strong><br/>
      <select name="date_cat" multiple="multiple" 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></p>
    </div>
    <fieldset class="component-group-list">
      <div class="field-pair">
        <input type="checkbox" name="enable_date_sorting" id="enable_date_sorting" value="1" <!--#if $enable_date_sorting > 0 then "checked=1" else ""#--> />
        <label class="clearfix" for="enable_date_sorting">
          <span class="component-title">$T('opt-dateSort')</span>
        </label>
      </div>
      <div class="field-pair alt">
        <label class="nocheck clearfix" for="datefoldername">
          <span class="component-title">$T('sortString')</span>
          <input type="text" size="50" id="datefoldername" name="date_sort_string" value="$date_sort_string" onkeyup="javascript:previewdate()">
          <input type="button" class="juiButton" onclick="dateClear()" value="$T('button-clear')"/>
        </label>
      </div>
      <div class="field-pair">
        <div class="nocheck clearfix">
          <span class="component-title">$T('presetSort')</span>
          <span class="component-desc">
            <input type="button" class="juiButton" onclick="dateSet('%t/%t - %y-%0m-%0d - %desc.%ext')" value="$T('button-ShowNameF')"/>
            <input type="button" class="juiButton" onclick="dateSet('%y-%0m/%t - %y-%0m-%0d - %desc.%ext')" value="$T('button-YMF')"/>
          </span>
        </div>
        <div class="nocheck clearfix">
          <span class="component-title">&nbsp;</span>
          <span class="component-desc">
            <input type="button" class="juiButton" onclick="dateSet('%y-%0m-%0d/%t - %y-%0m-%0d - %desc.%ext')" value="$T('button-DailyF')"/>
          </span>
        </div>
      </div>
      <div class="field-pair alt">
        <label class="nocheck clearfix">
          <span class="component-title">$T('example')</span>
          <span class="component-desc" id="previewdate"></span>
        </label>
      </div>
      <div class="field-pair">
        <label class="nocheck clearfix">
          <span class="component-title">$T('sort-legenda')</span>
          <input type="button" class="juiButton" value="$T('sort-legenda')" onclick="jQuery(this).hide(); jQuery('#Key3').show();"/>
          <table id="Key3" style="display:none">
            <thead><tr>
              <th align="right"><u>$T('sort-meaning')</u></th>
              <th><u>$T('sort-pattern')</u></th>
              <th><u>$T('sort-result')</u></th>
            </tr></thead>
            <tr>
              <td align="right"><strong>$T('show-name'):</strong></td>
              <td>%t</td>
              <td>$T('show-sp-name')</td>
            </tr><tr>
              <td></td>
              <td>%.t</td>
              <td>$T('show-dot-name')</td>
            </tr><tr>
              <td></td>
              <td>%_t</td>
              <td>$T('show-us-name')</td>
            </tr><tr>
              <td align="right"><strong>$T('year'):</strong></td>
              <td>%y</td>
              <td>2009</td>
            </tr><tr>
              <td align="right"><strong>$T('month'):</strong></td>
              <td>%m</td>
              <td>1</td>
            </tr><tr>
              <td></td>
              <td>%0m</td>
              <td>01</td>
            </tr><tr>
              <td align="right"><strong>$T('day-of-month'):</strong></td>
              <td>%d</td>
              <td>2</td>
            </tr><tr>
              <td></td>
              <td>%0d</td>
              <td>02</td>
            </tr><tr>
              <td align="right"><strong>$T('decade'):</strong></td>
              <td>%decade</td>
              <td>00</td>
            </tr><tr>
              <td></td>
              <td>%0decade</td>
              <td>2000</td>
            </tr><tr>
              <td align="right"><strong>$T('orgFilename'):</strong></td>
              <td>%fn</td>
              <td>$T('sort-File')</td>
            </tr><tr>
              <td align="right"><strong>$T('lowercase'):</strong></td>
              <td>{$T('TEXT')}</td>
              <td>$T('text')</td>
            </tr>
          </table>
        </label>
      </div>
    </fieldset>
  </div><!-- /component-group3 -->

  <div class="component-group-last clearfix">
    <div class="component-group-desc">
      <h3>&nbsp;</h3>
    </div>
    <fieldset class="component-group-list">
      <div class="left_links">
        <a id="save"><span class="config_sprite_container sprite_config_save">&nbsp;</span> $T('button-saveChanges')</a>
      </div>
    </fieldset>
  </div><!-- /component-group -->

</div>

</form>

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