function ShowDiv( id )
     {
     // safe function to show an element with a specified id
     if (document.getElementById)
          { // DOM3 = IE5, NS6
          document.getElementById(id).style.display = 'block';
          }
     else
          {
          if (document.layers)
               { // Netscape 4
               document.id.display = 'block';
               }
          else
               { // IE 4
               document.all.id.style.display = 'block';
               }
          }
     }

function HideDiv(id)
     {
     //safe function to hide an element with a specified id
     if (document.getElementById)
          { // DOM3 = IE5, NS6
          document.getElementById(id).style.display = 'none';
          }
     else
          {
          if (document.layers)
               { // Netscape 4
               document.id.display = 'none';
               }
          else
               { // IE 4
               document.all.id.style.display = 'none';
               }
          }
     }

/**
* Usage:
* <a href="javascript:show_hide('bird_flu_details');">A Bird Flu vaccine to be discovered</a>
* <div id="bird_flu_details" style="display:none">
*/
function ShowHideDiv(id, show)
     {
     if (el = document.getElementById(id))
          {
          if (null==show) show = el.style.display=='none';
          el.style.display = (show ? '' : 'none');
          }
     }

function PopupWindow( aWidth, aHeight, aUrl, aScrollBar )
     {
     var w = aWidth; // window width
     var h = aHeight; // window height
     // Position window to screen center.
     var t=window.screen.height/2-(h/2); // window`s top position
     var l=window.screen.width/2-(w/2); // window`s left position
     var scrollbar = 'no';
     // Open window.

     if ( aScrollBar )
          {
          scrollbar = 'yes';
          }

     winid=window.open(aUrl,'guide','scrollbars='+scrollbar+',top='+t+',left='+l+',width='+w+',height='+h+'');
     winid.focus();
     }

function OpenNewWindow( aUrl )
     {
     url = new String( aUrl );

     // Add schema if missing
     if ( 'http://' != url.substr( 0, 7 ) )
          {
          url = 'http://' + url;
          }

     winid=window.open( url );
     winid.focus();
     }

// Test whether the cookies are enabled.
// Author: Ivan Georgiev <http ://devcorner.georgievi.net/>
// @return boolean
function IsCookieEnabled()
     {
     var is_enabled = false;
     if ( typeof document.cookie == 'string' )
     if (document.cookie.length==0)
          {
          document.cookie = "test";
          is_enabled = document.cookie == 'test';
          document.cookie = '';
          }
     else
          {
          is_enabled = true;
          }
     return is_enabled;
     }

function TrimLeft( sString )
     {
     while ( sString.substring( 0, 1 ) == ' ' )
          {
          sString = sString.substring( 1, sString.length );
          }
     return sString;
     }

function TrimRight( aString )
     {
     while( aString.substring( aString.length-1, aString.length ) == ' ' )
          {
          aString = aString.substring( 0, aString.length-1 );
          }
     return aString;
     }

function Trim( aString )
     {
     while ( aString.substring(0,1) == ' ' )
          {
          aString = aString.substring( 1, aString.length );
          }
     while ( aString.substring( aString.length-1, aString.length ) == ' ' )
          {
          aString = aString.substring( 0, aString.length-1 );
          }
     return aString;
     }

function Redirect( aUrl )
     {
     window.location = aUrl;
     }

function CharCounter( aInputField, aMaxLength, counterElementId )
    {
    var str = aInputField.value;
    var length = aInputField.value.length;

    if ( length > aMaxLength )
        {
        str = str.substring( 0, aMaxLength );
        aInputField.value = str;
        }

    counter = document.getElementById( counterElementId );
    var size = aMaxLength - length;
    if ( size<0) size = 0;
    counter.innerHTML = size;
    }
