
/*
 * TSPilot concept document script support.
 *
 * License:
 *   Copyright 2006-2008 OCLC Online Computer Library Center, Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *
 *   You may obtain a copy of the License at
 *
 *     <http://www.apache.org/licenses/LICENSE-2.0>
 *
 *   Unless required by applicable law or agreed to in writing,
 *   software distributed under the License is distributed on an
 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 *   either express or implied.  See the License for the specific
 *   language governing permissions and limitations under the License.
 *
 */


/* Helpers: Tag Cloud View */

function setTagCloudView()
{
  var id;
  
  for (id = 0; id < arguments.length; id++)
  {
    var view = document.getElementById(arguments[id]);
    
    if (view != null)
    {
      view.className = "TagCloud";
    }
  }
  
  return true;
}

/* Helpers: List View */

function setListView()
{
  var id;
  
  for (id = 0; id < arguments.length; id++)
  {
    var view = document.getElementById(arguments[id]);
    
    if (view != null)
    {
      if (view.className.match(/\bSeparatedList\b/))
      {
        view.className = "ColumnarList";
      }
      else
      {
        view.className = "SeparatedList";
      }
    }
  }
  
  return true;
}

function setColumnarListView()
{
  var id;
  
  for (id = 0; id < arguments.length; id++)
  {
    var view = document.getElementById(arguments[id]);
    
    if (view != null)
    {
      view.className = "ColumnarList";
    }
  }
  
  return true;
}

function setSeparatedListView()
{
  var id;
  
  for (id = 0; id < arguments.length; id++)
  {
    var view = document.getElementById(arguments[id]);
    
    if (view != null)
    {
      view.className = "SeparatedList";
    }
  }
  
  return true;
}

/* Helpers: View */

var view1 =
[
  [ "TagCloud", "ColumnarList" ],
  [ "ColumnarList", "SeparatedList" ],
  [ "SeparatedList", "TagCloud" ]
];

var view2 =
[
  [ "SeparatedList", "ColumnarList" ],
  [ "ColumnarList", "TagCloud" ],
  [ "TagCloud", "SeparatedList" ]
];

function setNextView()
{
  var id;
  var list = arguments[0];
  
  for (id = 1; id < arguments.length; id++)
  {
    var view = document.getElementById(arguments[id]);
    
    if (view != null)
    {
      var found = false;
      
      for (var item in list)
      {
        var re = RegExp("\\b" + list[item][0] + "\\b");
        
        if (view.className.match(re))
        {
          view.className = list[item][1];
          found = true;
          break;
        }
      }
      
      if (!found)
      {
        view.className = list[0][0];
      }
    }
  }
  
  return true;
}

/* Events: Alternative Terms Section */

var objAlternativeTermsLabel = document.getElementById("AlternativeTermsLabel");

if (objAlternativeTermsLabel != null)
{
  objAlternativeTermsLabel.onclick = function ()
  {
    return setListView("AlternativeTermsView");
  }
}

/* Events: Broader Concepts Section */

var objBroaderConceptsLabel = document.getElementById("BroaderConceptsLabel");

if (objBroaderConceptsLabel != null)
{
  objBroaderConceptsLabel.onclick = function ()
  {
    return setListView("BroaderConceptsView");
  }
}

/* Events: Mapped Concepts Section */

var objMappedConceptsLabel = document.getElementById("MappedConceptsLabel");

if (objMappedConceptsLabel != null)
{
  objMappedConceptsLabel.onclick = function ()
  {
    var objMappedConceptsContent = document.getElementById("MappedConceptsContent");

    if (objMappedConceptsContent != null)
    {
      var nodes = objMappedConceptsContent.getElementsByTagName("h3");

      for (var item = 0; item++ < nodes.length; )
      {
        var view = document.getElementById("MappedVocabularyView" + item);

        setListView(view.id);
      }
    }

    return true;
  }
}

var objMappedConceptsContent = document.getElementById("MappedConceptsContent");

if (objMappedConceptsContent != null)
{
  var nodes = objMappedConceptsContent.getElementsByTagName("h3");

  for (var item = 0; item < nodes.length; item++)
  {
    var objLabel = nodes[item];

    objLabel.onclick = function ()
    {
      var item = this.id.replace(/^[^0-9]+/, "");
      var view = document.getElementById("MappedVocabularyView" + item);

      return setListView(view.id);
    }
  }
}

/* Events: Narrower Concepts Section */

var objNarrowerConceptsLabel = document.getElementById("NarrowerConceptsLabel");

if (objNarrowerConceptsLabel != null)
{
  objNarrowerConceptsLabel.onclick = function ()
  {
    return setListView("NarrowerConceptsView");
  }
}

/* Events: Related Concepts Section */

var objRelatedConceptsLabel = document.getElementById("RelatedConceptsLabel");

if (objRelatedConceptsLabel != null)
{
  objRelatedConceptsLabel.onclick = function ()
  {
    return setListView("RelatedConceptsView");
  }
}
