// Global Variables
var sessionID = "";

function showLogin( )
{
   doLogin( );
}


function showAbout( )
{
   if ( document.getElementById("AboutWindow") != null )
   {
      // Initialise the login window
      centerWindow( "AboutWindow" );
      
      // Display the login prompt
      document.getElementById("AboutWindow").style.visibility = "visible";
   }
}


function closeAbout( )
{
   if ( document.getElementById("AboutWindow") != null )
   {
      // Display the login prompt
      document.getElementById("AboutWindow").style.visibility = "hidden";
   }
}


function doLogin( )
{
   // Hard code the login and password values to the demo account
   var LoginName = "demo";
   var Password = "demo";
      
   if ( ( LoginName != null ) && ( Password != null ) )
   {
      // Begin construction of an AJAX request object
      var request = buildRequest( );
      
      var callback = function( )
      {
         // Local Variables
         var login = document.getElementById( "LoginPrompt" );
         var nav = document.getElementById( "Nav" );
         var logout = document.getElementById( "Header_Logout" );
         var sep = document.getElementById( "Header_Sep" );
         
         if ( request.readyState == 4 )
         {
            if( request.status == 200 )
            { 
               var response = parseDocument( request.responseText );
               
               // Attempt to read the session id from the return string
               var elResponse = response.getElementsByTagName("LoginSuccessful");
               
               // Verify that we've recieved a login successful message in response
               if ( elResponse.length == 1 )
               {
                  // Read the session id from the response stream
                  sessionID = nodeValue( elResponse[0], "SessionID" );

                  // Display the navigation items and show the devices
                  nav.style.visibility = "visible";
                  showFindDevices( false );
               }
            }
         }
      }   

      // Build the Parameter List
      var params = new Array(2);
      params[0] = new Parameter( "UserName", LoginName );
      params[1] = new Parameter( "Password", Password );
         
      // Perform the AJAX Call
      ajaxCall( request, "Login", params, callback );
   }
}


function getSessionID( )
{
   return sessionID;
}