﻿// Device Object
function Device( name, suburb, lookupdate, image, latitude, longitude, comment )
{
   // Handle Device Construction
   this.m_name = name;
   this.m_suburb = suburb;
   this.m_lookupdate = lookupdate;
   this.m_latitude = latitude;
   this.m_longitude = longitude;
   this.m_image = image;
   this.m_comment = comment;

   
   // *****************************************************
   //  Public Functions
   // *****************************************************
   this.display = function( )
   {
      if ( ( this.m_latitude != "" ) && ( this.m_longitude != "" ) )
      {
         var pin = new VEPushpin( pinID, 
                                  new VELatLong( this.m_latitude, this.m_longitude ), 
                                  imageRoot + this.m_image, 
                                  this.m_name, this.m_suburb + " {" + this.m_lookupdate + "}" );
   
         // Add the pin to the map and increment the pin counter
         map.AddPushpin( pin );

         pinID++;
      }
   }
   
   
   this.getName = function( )
   {
      return this.m_name;
   }
   
   
   this.getSuburb = function( )
   {
      return this.m_suburb;
   }
   
   
   this.getLookupDate = function( )
   {
      return this.m_lookupdate;
   }
   
   
   this.getLatitude = function( )
   {
      return this.m_latitude;
   }
   
   
   this.getLongitude = function( )
   {
      return this.m_longitude;
   }
   
   
   this.getImage = function( )
   {
      return this.m_image;
   }
   
   this.getComment = function( )
   {
      return this.m_comment;
   }
}


// DeviceData Class
function DeviceData( )
{
   // Local Variables
   this.m_collection = new Array( );
   
   
   // *****************************************************
   //  Public Functions
   // *****************************************************
   this.add = function( device )
   {
      // Add the device to the collection
      this.m_collection[ this.m_collection.length ] = device;
   }
   
   
   this.clear = function( )
   {
      // Clear the collection
      this.m_collection.length = 0;
      
      // Call the delete function for the map
      map.DeleteAllPushpins();
   
      // Reset the Pin counter
      pinID = 0;
   }
   
   
   this.display = function( )
   {
      // Iterate through the collection and display each device on the map
      for ( var i = 0; i < this.m_collection.length; i++ )
      {
         this.m_collection[i].display( );
      }
   }
   
   this.toArray = function( )
   {
      // Return the array object to the caller
      return this.m_collection;
   }
   
   
   this.count = function( )
   {
      // Return an integer representing the number of devices in the collection
      return this.m_collection.length;
   }
}
