<script language="javascript">  
    $(document).ready(function(){
        $("#SelectWebsite").click(selectWebsite);
        $("#SelectFile").click(selectFile);
        $("#Link_Type").change(selectLinkType);
        $("#modify_form").submit(checkSubmit);
    });

    function selectWebsite() {
        $("#filecontent").hide();
        $("#websitecontent").show();
    }

    function selectFile() {
        $("#websitecontent").hide();
        $("#filecontent").show();
    }

    function selectLinkType() {
        var type = $("#Link_Type").val();

        if (type == 'article') {
            $("#article_photo_form").show();
            $("#video_form").hide();

            for (i = 1; i <= 16 ; i++) {
                $("#article" + i).show();
                $("#photo" + i).hide();
            }

            $("#article_has_video").show();
            $("#photo_body").hide();
            $("#photo_extra").hide();
            $("#photo_large_pic").hide();
        } else if (type == 'photo') {
            $("#article_photo_form").show();
            $("#video_form").hide();

            for (i = 1; i <= 16 ; i++) {
                $("#article" + i).hide();
                $("#photo" + i).show();
            }

            $("#article_has_video").hide();
            $("#photo_body").show();
            $("#photo_extra").show();
            $("#photo_large_pic").show();
        } else {
            $("#article_photo_form").hide();
            $("#photo_body").show();
            $("#video_form").show();
        }
    }

    function checkSubmit() {
        var type = $("#Link_Type").val();

        if (type == 'article') {
            clearVideoData(0);
        } else if (type == 'photo') {
            clearVideoData(0);
            $("#Paragraph1").val($("#Main_Body").val());
        } else if (type == 'video') {
            if ($('#SelectWebsite').is(':checked')) {
                if (! checkUrlVal("#URL") ||
                    $("#Image_Path").val() == "") {
                    if (! confirm("You haven't entered all the information.  The video link may not display properly.  Continue?")) {
                        return false;
                    }
                }

                clearVideoData(1);
            } else {
                if ($("#File_Path").val() == "") {
                    if (! confirm("You haven't entered all the information.  The video link may not display properly.  Continue?")) {
                        return false;
                    }
                }

                clearVideoData(2);
            }
            $("#Paragraph1").val($("#Main_Body").val());
        }
        
        return true;
    }

    function clearVideoData(index) {
        if (index != 1) {
            $("#URL").val("http://");
            $("#Image_Path").val("");
        } else {
            $("#admin_convert_video").attr('checked', true);
        }

        if (index != 2) {
            $("#File_Path").val("");
        }
        
        if (index == 0) {
            $("#admin_convert_video").attr('checked', false);
        }
    }

    function checkUrlVal(id_str) {
        if ($(id_str).val() == '' || $(id_str).val() == "http://") {
            return false;
        }

        return true;
    }
</script>
<div class="row required clear">
  <label for="Title" class="name">Title: <span>*</span></label>
  <div class="value">
    <input type="text" id="Title" name="Title" value="<%if Title%><%escape_html Title%><%endif%>" class="text" />
  </div>
</div>
<div class="row<%unless category_loop_selected%> required<%endunless%> clear">
  <label for="CatLinks.CategoryID" class="name">Category:<%unless category_loop_selected%> <span>*</span><%endunless%></label>
  <div class="value wrappedtext">
  <%~if config.db_gen_category_list == 2%>
    <script type="text/javascript" src="<%config.build_static_url%>/treecats.js"></script>
    <%~set selected_cats = Links::Tools::category_list_selected%>
    <%~loop selected_cats%>
    <input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" />
    <%~endloop%>
    <noscript>
      <ul class="categories">
      <%~loop selected_cats%>
        <li><%Full_Name%></li>
      <%~endloop%>
      <%~if not selected_cats.length%>
        <li><%Links::language('ADD_SELCAT')%></li>
      <%~endif%>
      </ul>
    </noscript>
    <div id="treecats"></div>
    <script type="text/javascript">
      var tc = new treecats({ <%-- selectionMode : 'multiple', --%> cgiURL : '<%config.db_cgi_url%>', imageURL : '<%config.build_static_url%>/<%t%>/images' });
      tc.load();
    </script>
  <%~elsif category_loop_selected%>
    <%~if category_loop.length > 1%>
    <ul class="categories"><%loop category_loop%><li><%Full_Name%><input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" /></li><%endloop%></ul>
    <%~else%>
    <%loop category_loop%><%Full_Name%><input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" /><%endloop%>
    <%~endif%>
  <%~else%>
    <select id="CatLinks.CategoryID" name="CatLinks.CategoryID">
      <%~loop category_loop%>
      <option value="<%escape_html ID%>"<%if selected%> selected="selected"<%endif%>><%'&nbsp;&nbsp;' x $CatDepth%><%Name%></option>
      <%~endloop%>
    </select>
  <%~endif%>
  </div>
</div>
<div class="row required clear">
  <label for="Type" class="name">Type: <span>*</span></label>
  <div class="value">
    <select name="Type" id="Type">
    <option value="editorial"<%if Type eq 'editorial'%> selected<%endif%>>editorial</option>
    <option value="news"<%if Type eq 'news'%> selected<%endif%>>news</option>
    </select>
  </div>
</div>
<div class="row required clear">
  <label for="Link_Type" class="name">Link Type: <span>*</span></label>
  <div class="value">
      <% if modify and Link_Type%>
      <input type="hidden" id="Link_Type" name="Link_Type" value="<%Link_Type%>">
      <%if Link_Type eq 'photo'%>Photo Gallery<%elseif Link_Type eq 'video'%>Video<%else%>Article<%endif%>
      <% else %>
      <select name="Link_Type" id="Link_Type">
        <option value="article"<%if Link_Type eq 'article'%> selected<%endif%>>Article</option>
        <option value="photo"<%if Link_Type eq 'photo'%> selected<%endif%>>Photo Gallery</option>
        <option value="video"<%if Link_Type eq 'video'%> selected<%endif%>>Video</option>
      </select>
      <% endif%>
    </div>
</div>
<div class="row clear">
  <label for="Description" class="name">Description:</label>
  <div class="value">
    <textarea id="Description" name="Description" rows="3" cols="25"><%if Description%><%escape_html Description%><%endif%></textarea>
  </div>
</div>
<div class="row clear">
  <label for="Contact_Name" class="name">Contact Name:</label>
  <div class="value">
    <input type="text" id="Contact_Name" name="Contact_Name" value="<%if Contact_Name%><%escape_html Contact_Name%><%endif%>" class="text" />
  </div>
</div>
<div class="row clear">
  <label for="Contact_Email" class="name">Contact E-mail:</label>
  <div class="value">
    <input type="text" id="Contact_Email" name="Contact_Email" value="<%if Contact_Email%><%escape_html Contact_Email%><%endif%>" class="text" />
  </div>
</div>
<div id='photo_body' class="row clear"<%if Link_Type ne 'photo' and Link_Type ne 'video' %> style="display:none"<% endif %>>
  <label for="Main_Body" class="name">Main Body:</label>
    <div class="value">
      <textarea id="Main_Body" name="Main_Body" rows="3" cols="25"><%if Paragraph1%><%escape_html Paragraph1%><%endif%></textarea>
    </div>
</div>
<div id='video_form'<%if Link_Type ne 'video'%> style="display:none"<%endif%>>
    <% include include_form_video.html %>
</div>
<div id='article_photo_form'<%if Link_Type eq 'video'%> style="display:none"<%endif%>>
    <% include include_form_article_photo.html %>
</div>
<div class="row clear">
  <label for="RelatedArticles" class="name">Related Article IDs:<br />One per line</label>
  <div class="value">
      <textarea id="RelatedArticles" name="RelatedArticles" rows="3" cols="25"><%if RelatedArticles%><%escape_html RelatedArticles%><%endif%></textarea>
  </div>
</div>
<div class="row clear">
  <label for="Related_Article1" class="name">Related Article #1:</label>
  <div class="value">
    <input type="text" id="Related_Article1" name="Related_Article1" value="<%if Related_Article1%><%escape_html Related_Article1%><%endif%>" class="text" />
  </div>
</div>
<div class="row clear">
  <label for="Related_Article2" class="name">Related Article #2:</label>
  <div class="value">
    <input type="text" id="Related_Article2" name="Related_Article2" value="<%if Related_Article2%><%escape_html Related_Article2%><%endif%>" class="text" />
  </div>
</div>
<div class="row clear">
  <label for="Related_Article3" class="name">Related Article #3:</label>
  <div class="value">
    <input type="text" id="Related_Article3" name="Related_Article3" value="<%if Related_Article3%><%escape_html Related_Article3%><%endif%>" class="text" />
  </div>
</div>
<div class="row clear">
  <label for="Related_Article4" class="name">Related Article #4:</label>
  <div class="value">
    <input type="text" id="Related_Article4" name="Related_Article4" value="<%if Related_Article4%><%escape_html Related_Article4%><%endif%>" class="text" />
  </div>
</div>
<div class="row clear">
  <label for="Related_Article5" class="name">Related Article #5:</label>
  <div class="value">
    <input type="text" id="Related_Article5" name="Related_Article5" value="<%if Related_Article5%><%escape_html Related_Article5%><%endif%>" class="text" />
  </div>
</div>
