  var RoadSearch = Class.create();
  RoadSearch.prototype = Object.extend(new App(),
  {
    initialize: function(id, url) 
    {
    this.logger = null; // console; 
    this.url = url;
    this.id = id;
    this.parms = {};    
    this.page = 1;
    },
    
    getRoadTotal : function ()
    {
      var val = 0;
      try
      {
         val = this.data.roads.total; 
      }catch (e) { }
      return val;        
    },

    getRoadCount : function ()
    {
      var val = 0;
      try
      {
         val = this.data.roads.count; 
      }catch (e) { }
      return val;        
    },

    getRoadPage : function ()
    {
      var val = 0;
      try
      {
         val = parseInt(this.data.roads.page); 
      }catch (e) { }
      return val;        
    },
    
    getRoadPageSize : function ()
    {
      var val = 0;
      try
      {
         val = parseInt(this.data.roads.pagesize); 
      }catch (e) { }
      return val;        
    },
        
    getRoadName : function (index)
    {
      var val = "";
      try
      {
         if (this.data.roads.count == 1 && index == 0)
           val = this.data.roads.road.roadname; 
         else
           val = this.data.roads.road[index].roadname; 
      }catch (e) { }
      return val;        
    },
    
    getRoadCode : function (index)
    {
      var val = "";
      try
      {
         if (this.data.roads.count == 1 && index == 0)
           val = this.data.roads.road.id; 
         else
           val = this.data.roads.road[index].id; 
      }catch (e) { }
      return val;        
    },

    getRoadLatitude : function (index)
    {
      var val = 0.0;
      try
      {
         if (this.data.roads.count == 1 && index == 0)
           val = parseFloat(this.data.roads.road.latitude); 
         else
           val = parseFloat(this.data.roads.road[index].latitude); 
      }catch (e) { }
      return val;        
    },

    getRoadLongitude : function (index)
    {
      var val = 0.0;
      try
      {
         if (this.data.roads.count == 1 && index == 0)
           val = parseFloat(this.data.roads.road.longitude); 
         else
           val = parseFloat(this.data.roads.road[index].longitude); 
      }catch (e) { }
      return val;        
    },    

    RoadDisplay: function(page)
    {
      this.page = page;
      this.RoadSearch();
    },
    
    RoadSearch: function(/* search | start, end */)
    {
      if (arguments.length == 2)
      {
        $('roadquery').value = '';
        this.params = {sc: arguments[0], ec: arguments[1]};
        this.page = 1;
      }

      if (arguments.length == 1)
      {
        this.params = {ss: arguments[0]};
        this.page = 1;
      }

      var params = {cmd: 'road', pg : this.page};
      Object.extend(params, this.params);
        
      Element.DisplayMessage(this.id, ' Searching Roads.  Please wait...', {showLoading: true, replaceContent: true, backgroundColor: '#FFF'});
      
      setTimeout((function()
      {                    
        this.sendRequest(params, this.RoadSearchResult.bind(this));
      }).bind(this), 500);
    },
  
    RoadSearchResult: function()
    {
      if (this.isStatusOK()) 
      {
        // hide message
        Element.DisplayMessage(this.id);
        
        var total = this.getRoadTotal();
        var page = this.getRoadPage();
        var pageSize = this.getRoadPageSize();
       
        var start = 1 + pageSize * (page - 1);
        var end = pageSize + pageSize * (page - 1);
        if (end > total)
          end = total;
       
        // draw heading
        var heading = Builder.node('h2', ['Road Result:']);
        $(this.id).appendChild(heading);
        
        if (total > 0)
        {
          heading = Builder.node('h3', ['Showing ' + start + ' - ' + end + ' of ' + total]);
          $(this.id).appendChild(heading);
        } else {
          heading = Builder.node('h3', ['No records are found!']);        
          $(this.id).appendChild(heading);
        }
        
        var sLat = 0.0;
        var sLon = 0.0;

        for (var i = 0, j = start; i < this.getRoadCount(); i++, j++)
        {                  
          var code = this.getRoadCode(i);  
          var name = this.getRoadName(i);
          var lat = this.getRoadLatitude(i);
          var lon = this.getRoadLongitude(i);
          
          var cell = Builder.node('div', {id : 'cell'});                     
          var current;          

          if (i == 0)
          {
            sLat = lat;
            sLon = lon;
            
            current = Builder.node('div', {id : 'result_' + i, className : 'current'});            
          } else {
            current = Builder.node('div', {id : 'result_' + i})
          }          
          
          var result = Builder.node('div', {id: 'result_list'}, [
            Builder.node('a', {href: 'javascript:roadSearch.RoadMap(' + i + ')'}, [
              j + '. ' + name 
              ]),
              /*Builder.node('br'),
              Builder.node('ul',[
                Builder.node('li', {className: 'view'}, [
                  Builder.node('a', {href: 'javascript:RoadSearch.RoadMap(' + i + ')'}, ['View on Map'])
                  ])
                ])*/
             ]);
            current.appendChild(result);
            cell.appendChild(current);
          
           $(this.id).appendChild(cell);
         }
         
         // todo: goto first marker if return only 1 result. 
         //doGoto(sLat, sLon, 7000);                     
         
         var totalPages = parseInt(total/pageSize);
         if ((total % pageSize) != 0)
           totalPages = totalPages + 1;
  
         if (totalPages > 1)
         {
           var numPages = 8;         
           var index = 0;
           var maxIndex = 0;
           var node;   

           index = parseInt((page - 1) / numPages ) * numPages + 1;
           if (index + numPages > totalPages)
             maxIndex = totalPages;
           else
             maxIndex = index + numPages - 1;
          
           if(maxIndex > numPages)
           {
             node = Builder.node('a', {href: 'javascript:roadSearch.RoadDisplay(' + (index - numPages) + ');'}, ['<<   ']);
             $(this.id).appendChild(node);             
           }
         
           var pages = Builder.node('strong', ['Page']);
           $(this.id).appendChild(pages);           
           
           for(var i = index; i <= maxIndex; i++)
           {
             if (i == page)
             {
               if (i != maxIndex)
               {
                node = Builder.node('b',[' ' + i + ' | ']);
               } else {
                node = Builder.node('b',[' ' + i + ' ']);
               }
               $(this.id).appendChild(node);
               
             } else {            

               if (i != maxIndex)
               {
                node = Builder.node('a', {href: 'javascript:roadSearch.RoadDisplay(' + i + ');'}, [' ' + i + ' | ']);
               }else{
                node = Builder.node('a', {href: 'javascript:roadSearch.RoadDisplay(' + i + ');'}, [' ' + i + ' ']);
               }
               $(this.id).appendChild(node);
             }
           } 
           
           if(maxIndex < totalPages)
           {
             node = Builder.node('a', {href: 'javascript:roadSearch.RoadDisplay(' + (index + numPages) + ');'}, ['  >>']);
             $(this.id).appendChild(node);             
           }
         }     
      
         Element.show(this.id);
      }
      else
      {
        Element.DisplayMessage(this.id, this.getMessage(), {replaceContent: true, backgroundColor: '#FFF'});
      }
    },
    
    RoadMap : function(index)
    {
      var pageSize = this.getRoadPageSize();
      for (var i = 0; i < pageSize; i++)
      {
        Element.removeClassName('result_' + i, 'current');
      }      
      Element.addClassName('result_' + index, 'current');
          
      var lat = this.getRoadLatitude(index);
      var lon = this.getRoadLongitude(index);
      
      objSrcMarker.showOnMap(intMarkerZoom,lon,lat);
    } 
  }); 


