<!DOCTYPE html >
<html lang="en">
<head>
  <%include widget_css.html%>
  <script type="text/javascript">
    $(document).ready(function() {
        $('select[name=Type]').change(function() {
          if ($(this).val() == 1) {
            $('.form').addClass('auto');
            $('input[name=URL]').attr('disabled', true);
            $('input[name=Button]').attr('disabled', true);
          }
          else {
            $('.form').removeClass('auto');
            $('input[name=URL]').attr('disabled', false);
            $('input[name=Button]').attr('disabled', false);
          }
        })

        $('select[name=Widget]').change(function() {
//          $('input[name=Title]').val($(this).find('option:selected').html());

          $('select[name=Category]').attr('disabled', true);
          $('select[name=Forum]').attr('disabled', true);
          $('input[name=Articles]').attr('disabled', true);
          if ($('select[name=Type]').val() == 1) {
              $('input[name=URL]').attr('disabled', true);
              $('input[name=Button]').attr('disabled', true);
          }
          var val = $(this).val();
          
          $('.list').addClass('hide');
          if ($('select[name=Type]:selected').val() == 'auto') { $('.article, .forum, .category').show(); }
          
          if (val == 'category_list') {
            $('select[name=Category]').attr('disabled', false).focus();
          }
          else if (val == 'poll') {
            $('select[name=Forum]').attr('disabled', false);
          }
          else if (val == 'collapse') {
            $('input[name=URL]').attr('disabled', false);
            $('input[name=Button]').attr('disabled', false);
          }
          else if(val == 'feature_article' || val == 'editors_pick' || val == 'feature_threads') {
            $('input[name=Articles]').attr('disabled', false).focus();
          }
          else if (val == 'newsletter') {
            $('.list').removeClass('hide');
            $('.article, .forum, .category').hide();
          }
        }).change();
    })
  </script>
</head>
<body>
  <div class="contentwrapper">
    <h1><%if in.ID%>Modify<%else%>Add<%endif%> Widget</h1>
    <hr class="line" />
    <br />
    <%~if error%><p class="error"><%error%></p><%endif%>
    <form action="admin.cgi" method="post" enctype= multipart/form-data>
      <input type="hidden" name="do" value="plugin" />
      <input type="hidden" name="plugin" value="Widgets" />
      <input type="hidden" name="func" value="<%if in.ID%>modify<%else%>add<%endif%>" />
      <input type="hidden" name="submit" value="1" />
      <input type="hidden" name="ID" value="<%in.ID || ''%>" />
      <input type="hidden" name="page" value="<%in.page || ''%>" />
      <div class="dtable form<%if in.Type%> auto<%endif%>">
        <div class="drow">
          <div class="dcell name">Type</div>
          <div class="dcell divider"></div>
          <div class="dcell value">
            <select name="Type">
              <option value="0"<%if not in.Type%> selected="selected"<%endif%>>Manual</option>
              <option value="1"<%if in.Type == 1%> selected="selected"<%endif%>>Automated</option>
            </select>
          </div>
        </div>
        <div class="drow auto">
          <div class="dcell name">Widget</div>
          <div class="dcell divider"></div>
          <div class="dcell value">
            <select name="Widget">
              <option value=""></option>
              <option value="newsletter"<%if in.Widget eq 'newsletter'%> selected="selected"<%endif%>>Newsletter</option>
              <option value="most_popular"<%if in.Widget eq 'most_popular'%> selected="selected"<%endif%>>Most Popular</option>
              <option value="local_listings"<%if in.Widget eq 'local_listings'%> selected="selected"<%endif%>>Local Listings</option>
              <option value="calculators"<%if in.Widget eq 'calculators'%> selected="selected"<%endif%>>Calculators</option>
              <option value="category_list"<%if in.Widget eq 'category_list'%> selected="selected"<%endif%>>Category List</option>
              <option value="feature_article"<%if in.Widget eq 'feature_article'%> selected="selected"<%endif%>>Feature Article</option>
              <option value="feature_threads"<%if in.Widget eq 'feature_threads'%> selected="selected"<%endif%>>Feature Threads</option>
              <option value="editors_pick"<%if in.Widget eq 'editors_pick'%> selected="selected"<%endif%>>Editor's Pick</option>
              <option value="poll"<%if in.Widget eq 'poll'%> selected="selected"<%endif%>>Poll</option>
              <option value="collapse"<%if in.Widget eq 'collapse'%> selected="selected"<%endif%>>Collapse</option>
            </select>
          </div>
        </div>
        <div class="drow">
          <div class="dcell name">Title</div>
          <div class="dcell divider"></div>
          <div class="dcell value"><input type="text" name="Title" value="<%in.Title || ''%>" class="txt midtext" /></div>
        </div>
        <div class="drow">
          <div class="dcell name">Title's CSS</div>
          <div class="dcell divider"></div>
          <div class="dcell value">
              <input type="text" name="TitleStyle" class="txt midtext" value="<%in.TitleStyle || ''%>">
              <br><small>E.g.: color: #ffffff; background: #000000;</small>
          </div>
        </div>
        <div class="drow">
          <div class="dcell name">Sub-title/Content</div>
          <div class="dcell divider"></div>
          <div class="dcell value">
              <textarea name="Subtitle" class="txt midtext" rows="2"><%in.Subtitle || ''%></textarea>
          </div>
        </div>
        <div class="drow list<%if in.Widget ine 'newsletter'%> hide<%endif%>">
          <div class="dcell name">List ID</div>
          <div class="dcell divider"></div>
          <div class="dcell value"><input type="text" name="ListID" value="<%in.ListID || ''%>" class="txt" /></div>
        </div>
        <div class="drow manual">
          <div class="dcell name">Image</div>
          <div class="dcell divider"></div>
          <div class="dcell value"><input type="file" name="Image" value="" class="txt midtext" /></div>
        </div>
        <div class="drow">
          <div class="dcell name">URL</div>
          <div class="dcell divider"></div>
          <div class="dcell value"><input type="text" name="URL" value="<%in.URL || ''%>" placeholder="http://" class="txt midtext" /></div>
        </div>
        <div class="drow">
          <div class="dcell name">Button</div>
          <div class="dcell divider"></div>
          <div class="dcell value"><input type="text" name="Button" value="<%in.Button || ''%>" class="txt shotext" /></div>
        </div>
        <div class="drow auto forum">
          <div class="dcell name">Forum</div>
          <div class="dcell divider"></div>
          <div class="dcell value">
            <select name="Forum"<%if in.Widget ne 'poll' and in.Widget ne 'collapse'%> disabled<%endif%>>
              <option value="1"<%if in.Forum == 1%> selected="selected"<%endif%>>Triathlon Forum</option>
              <option value="2"<%if in.Forum == 2%> selected="selected"<%endif%>>Classifieds</option>
              <option value="7"<%if in.Forum == 7%> selected="selected"<%endif%>>The Womens</option>
              <option value="8"<%if in.Forum == 8%> selected="selected"<%endif%>>Jobs</option>
              <option value="9"<%if in.Forum == 9%> selected="selected"<%endif%>>Notices</option>
              <option value="10"<%if in.Forum == 10%> selected="selected"<%endif%>>Fitters</option>
              <option value="4"<%if in.Forum == 4%> selected="selected"<%endif%>>Lavender Room</option>
            </select>
          </div>
        </div>
        <div class="drow auto article">
          <div class="dcell name">Articles/Threads<br />(Use comma to separate IDs)</div>
          <div class="dcell divider"></div>
          <div class="dcell value"><input type="text" name="Articles" value="<%in.Articles || ''%>" class="txt midtext"<%if in.Widget ne 'editors_pick' and $in.Widget ne 'feature_article' and $in.Widget ne 'feature_threads'%> disabled<%endif%>/></div>
        </div>
        <div class="drow auto category">
          <div class="dcell name">Category</div>
          <div class="dcell divider"></div>
          <div class="dcell value">
            <%~set categories_loop = Plugins::Widgets::fetch_categories%>
            <select name="Category"<%if in.Widget ne 'category_list'%> disabled<%endif%>>
              <option value=""></option>
              <%~loop categories_loop%>
              <option value="<%ID%>"<%if in.Category == $ID%> selected="selected"<%endif%>><%Full_Name%></option>
              <%~endloop%>
            </select>
          </div>
        </div>
        <div class="drow actions">
          <div class="dcell name"></div>
          <div class="dcell divider"></div>
          <div class="dcell value"><input type="submit" name="badd" value="<%if in.ID%>Modify<%else%>Add<%endif%> Widget" class="btn" /></div>
        </div>
      </div>
    </form>
  </div>
</body>
</html>
