
////////////////////////////////////////////////////////////////

function GetElementsByTagName( name )
{
 var coll = null;
 if ( document.getElementsByTagName )
 {
  coll = document.getElementsByTagName( name );
 }
 return coll; 
}

function GetElementsByName( name )
{
 var coll = null;
 if ( document.getElementsByName )
 {
  coll = document.getElementsByName( name );
 }
 return coll; 
}

function GetElementById( id )
{
 var obj = null;
 if ( document.getElementById )
 {
  obj = document.getElementById( id );
 }
 return obj; 
}

function SetElementTextByObj( obj, text )
{
 if ( obj )
 {
  nodeName = obj.nodeName;
  if ( nodeName == "input" || nodeName == "select" || nodeName == "option" || nodeName == "textarea" )
  {
   obj.value = text;
  }
  else
  {
   obj.innerHTML = text;
  }
 }
}

function GetElementTextByObj( obj )
{
 var text = "";
 
 if ( obj )
 {
  nodeName = obj.nodeName;
  if ( nodeName == "input" || nodeName == "select" || nodeName == "option" || nodeName == "textarea" )
  {
   text = obj.value;
  }
  else
  {
   text = obj.innerHTML;
  }
 }

 return text;
}

function SetElementTextById( id, text )
{
 var obj = GetElementById( id );
 SetElementTextByObj( obj, text );
}

function GetElementTextById( id )
{
 var obj = GetElementById( id );
 var text = GetElementTextByObj( obj );
 return text;
}

function AppendElementTextById( id, a, sep )
{
 var text = GetElementTextById( id );
 if ( text == "&nbsp;" )
 {
  text = "";
 }
 if ( text.length > 0 )
 {
  text = text + sep;
 }

 text = text + a;
 
 SetElementTextById( id, text );
}

////////////////////////////////////////////////////////////////

function Toggle_ShowHideElemText( the_elem, the_link, text )
{
 var objElem = GetElementById( the_elem );

 if ( objElem )
 {
  var objLink = GetElementById( the_link );

  if ( objLink )
  {
   if ( objElem.style.display == "" ) 
   {
    var str = "[Click here to show " + text + "...]";
    objElem.style.display = "none";
    SetElementTextByObj( objLink, str );
   } 
   else 
   {
    var str = "[Click here to hide " + text + "...]";
    objElem.style.display = "";
    SetElementTextByObj( objLink, str );
   }
  }
 }
}

function Toggle_ShowHideElem( id )
{
 var objElem = GetElementById( id );
 if ( objElem )
 {
  if ( objElem.style.display == "" )
  {
   objElem.style.display = "none";
  }
  else
  {
   objElem.style.display = "";
  }
 }
} 

function Toggle_ShowHide( base )
{
 Toggle_ShowHideElem( base );
 Toggle_ShowHideElem( base + '_plus' );
 Toggle_ShowHideElem( base + '_minus' );
 Toggle_ShowHideElem( base + '_br' );
} 

function IsShowing( id )
{
 var objElem = GetElementById( id );
 if ( objElem )
 {
  if ( objElem.style.display == "" )
  {
   return 1;
  }
 }

 return 0;
}

function Show_Elements( base )
{
 if ( !IsShowing( base ) )
 {
  Toggle_ShowHide( base );
 }
} 

function Show_Element( id )
{
 if ( !IsShowing( id ) )
 {
  Toggle_ShowHideElem( id );
 }
} 

function Hide_Elements( base )
{
 if ( IsShowing( base ) )
 {
  Toggle_ShowHide( base );
 }
} 

function CollapseAll()
{
 var objColl = GetElementsByName( "collapseItem" );
 if ( objColl )
 {
  for ( i = 0; i < objColl.length; ++i )
  {
   var objElem = objColl[ i ];
   if ( objElem )
   {
    var objAttribs = objElem.attributes;
    if ( objAttribs )
    {
     var objAttrId = objAttribs.getNamedItem( "id" );
     if ( objAttrId )
     {
      var attrValue = objAttrId.nodeValue;
      Hide_Elements( attrValue );
     }
    }
   }
  }
 }
}

function ExpandAll()
{
 var objColl = GetElementsByName( "collapseItem" );
 if ( objColl )
 {
  for ( i = 0; i < objColl.length; ++i )
  {
   var objElem = objColl[ i ];
   if ( objElem )
   {
    var objAttribs = objElem.attributes;
    if ( objAttribs )
    {
     var objAttrId = objAttribs.getNamedItem( "id" );
     if ( objAttrId )
     {
      var attrValue = objAttrId.nodeValue;
      Show_Elements( attrValue );
     }
    }
   }
  }
 }
}

////////////////////////////////////////////////////////////////

function setCursor( str )
{
 document.body.style.cursor = str;
}

function setCursorHourglass()
{
 setCursor( "wait" );
}

function setCursorDefault()
{
 setCursor( "default" );
}

////////////////////////////////////////////////////////////////

function resizeText( direction )
{
 var newVal = 0;
 if ( direction == 0 )
 {
  newVal = 0.70;
 }
 else
 {
  var currVal = 0;
  if ( document.body.style.fontSize == "" )
  {
   currVal = "0.70em";
  }
  else
  {
   currVal = document.body.style.fontSize;
  }

  newVal = parseFloat( currVal ) + ( direction * 0.05 );
  if ( newVal <= 0.5 )
  {
   newVal = 0;
  }
 }

 resizeTextValue( newVal );
}

function resizeTextValue( newVal )
{
 if ( newVal > 0 )
 {
  document.body.style.fontSize = newVal + "em";
 }

 if ( newVal > 0 )
 {
  var sm = new SettingsManager();
  sm.setTextSize( newVal );
 }

 onUpdateTextSize();
}

function onUpdateTextSize()
{
 if ( document.body.style.fontSize == "0.7em" )
 {
  SetElementTextById( "resetfont", "Reset Font" )
 }
 else
 {
  SetElementTextById( "resetfont", "<a href=\"#\" onClick=\"resizeText( 0 );return false;\">Reset Font</a>" )
 }

 if ( document.body.style.fontSize == "0.55em" )
 {
  SetElementTextById( "smallfont", "Smaller Font" )
 }
 else
 {
  SetElementTextById( "smallfont", "<a href=\"#\" onClick=\"resizeText( -1 );return false;\">Smaller Font</a>" )
 }
}

function html_entity_decode( str ) 
{
  var elem = document.createElement( "textarea" );
  elem.innerHTML = str.replace( /</g, "&lt;" ).replace( />/g,"&gt;" );
  var text = elem.value;
  elem = null;
  return text;
}

