/**
 * shows or hides the learn more container
 */
function displayLearnMore( elementName, hide )
{
  if( elementName )
  {
    var element = document.getElementById( elementName );
    if( element )
    {
      // toggle if hide is not provided
      if( hide == null )
        hide = (element.style.display == "block");
      
      if( hide )
        element.style.display = "none";
      else
        element.style.display = "block";
    }
  }    
}

/**
 * shows the a map to the given address
 */ 
function showMap( address )
{
  var mapUrl = "http://maps.google.com/maps?q=" + address;
  window.open(mapUrl,'map','toolbars=no,scrollbars=yes');
}

/**
 * LeftNav data
 */
var leftNavName = "";
var leftNavSections = new Array();
var leftNavSectionNames = new Array();

/**
 * registers the name prefix that the LeftNav will control
 */
function leftNavRegisterName( name )
{
  if (name)
    leftNavName = name;
}

/**
 * registers a section that the LeftNav will control
 */
function leftNavRegisterSection( section, displayName )
{
  if (section)
  {
    leftNavSections.push(section);
    
    if (displayName)
      leftNavSectionNames.push(displayName);
    else
      leftNavSectionNames.push(section);
  }
}

/**
 * removes all sections from the LeftNav
 */
function leftNavClearSections()
{
  leftNavSections = new Array();
  leftNavSectionNames = new Array();
}

/**
 * generates the innerHTML for the LeftNav
 */
function generateLeftNav()
{
  var leftNav = document.getElementById("LeftNav");
  
  if (!leftNav || !leftNavSections || leftNavSections.length <= 0)
    return;
    
  var buffer = '<ol>';
  
  for (var i = 0; i < leftNavSections.length; i++)
  {
    var section     = leftNavSections[i];
    var displayName = leftNavSectionNames[i];
    
    if (!section)
      continue;

    if (!displayName)
      displayName = section;
      
    buffer += '<li>';
    buffer += '<div id="LeftNav_' + section + '">';
    buffer += '<a id="LeftNavInner_' + section + '" href="javascript:leftNavDisplayContent(\'' + section + '\');">' + displayName + '</a>';
    buffer += '</div>';
    buffer += '</li>';
  }
  
  buffer += '</ol>';
  
  leftNav.innerHTML = buffer;
}

/**
 * generates the innerHTML for the LeftNav
 */
function generateAnchorLeftNav()
{
  var leftNav = document.getElementById("LeftNav");
  
  if (!leftNav || !leftNavSections || leftNavSections.length <= 0)
    return;
    
  var buffer = '<ol>';
  
  for (var i = 0; i < leftNavSections.length; i++)
  {
    var section     = leftNavSections[i];
    var displayName = leftNavSectionNames[i];
    
    if (!section)
      continue;

    if (!displayName)
      displayName = section;
      
    buffer += '<li>';
    buffer += '<a id="LeftNavInner_' + section + '" href="javascript:setActive(\'' + section  + '\')">' + displayName + '</a>';
    buffer += '</li>';
  }
  
  buffer += '</ol>';
  
  leftNav.innerHTML = buffer;
}

function setActive( sectionName )
{ 
  var anAnchor = null;
  for (var i = 0; i < leftNavSections.length; i++)
  {
    anAnchor = document.getElementById("LeftNavInner_" + leftNavSections[i]);
        
    if( anAnchor )
    {
      anAnchor.className = "";
    }
  } 
  
  anAnchor = document.getElementById( "LeftNavInner_" + sectionName );
  anAnchor.className = "selected";  
  
  document.location.href = leftNavName + ".asp#" + sectionName;
}

/**
 * activates LeftNav item
 */
function leftNavActivateSection( section )
{
  var element = document.getElementById( "LeftNav_" + section );
  var subElement = document.getElementById( "LeftNavInner_" + section );
    
  if( element && subElement)
    element.innerHTML = '<span id="LeftNavInner_' + section + '" class="selected">' + subElement.innerHTML + '</span>';
}

/**
 * deactivates LeftNav item
 */
function leftNavDeactivateSection( section )
{
  var element = document.getElementById( "LeftNav_" + section );
  var subElement = document.getElementById( "LeftNavInner_" + section );
    
  if( element && subElement)
  {
    element.innerHTML = '<a id="LeftNavInner_' + section + '" href="javascript:leftNavDisplayContent(\'' + section + '\');">' + subElement.innerHTML + '</a>';
  }
}

/**
 * hides a single section of the LeftNav content
 */
function leftNavHideContent( section )
{
  if (section)
  {
    var element = document.getElementById( leftNavName + "_" + section );
    if( element )
    {
      element.style.display = "none";
    
      leftNavDeactivateSection(section);
    }
  }
}

/**
 * hides all sections of the LeftNav content
 */
function leftNavHideAllContent()
{
  for (var i = 0; i < leftNavSections.length; i++)
    leftNavHideContent(leftNavSections[i]);
}

/**
 * displays a single section of the LeftNav content
 */
function leftNavDisplayContent( section )
{
  if( section )
  {
    var element = document.getElementById( leftNavName + "_" + section );
    if( element )
    {
      leftNavHideAllContent();

      element.style.display = "block";
      
      leftNavActivateSection(section);
    }
  }
}

