﻿// JScript File
var PATH = '';

VehicleStyle =  function(icon1Url,icon2Url,arrowsUrl,iconSize,iconAnchor,windowAnchor,labelClass,labelOffset,labelColor){
    this.bluredIcon  = icon1Url || PATH+'img/dbus.png';
    this.focusedIcon = icon2Url || PATH+'img/dbus_shine.png';
    this.iconSize =   iconSize   || new GSize(50,50);
    this.labelClass = labelClass || "vehicleLabel";
    this.labelColor = labelColor || "#0000ff";
    this.labelOffset = labelOffset || new GSize(10, 10);
    this.iconAnchor = iconAnchor || new GPoint(this.iconSize.width/2,this.iconSize.height/2);
    this.infoWindowAnchor = windowAnchor || new GPoint(25,25);
    this.arrowsUrl = arrowsUrl  ||[PATH+"img/bus/arrow1.png",PATH+"img/bus/arrow2.png",PATH+"img/bus/arrow3.png",PATH+"img/bus/arrow4.png",PATH+"img/bus/arrow5.png",PATH+"img/bus/arrow6.png",PATH+"img/bus/arrow7.png",PATH+"img/bus/arrow8.png"];

}

var VEHICLESTYLE1 = new VehicleStyle();
Vehicle = function(latlng,opt_opts)
{
    //standardowe opcje
    this.latlng_ = latlng;
    this.prevlatlng_ =new GLatLng(0,0);
    this.opts_ = opt_opts||{};
    this.style_  = opt_opts.vehicleStyle ||  VEHICLESTYLE1;
    this.ctrLabelColor = opt_opts.ctrLabelColor || false;
    //parseInt(opt_opts.vehicleType)==1?VEHICLESTYLE1:VEHICLESTYLE1;
    this.opts_.icon = this.createIcon_();
    this.clickable_ = opt_opts.clickable || true;
    this.title_ = opt_opts.title || "";
    this.vehicleType_ = opt_opts.vehicleType;
    
    
    
    this._nb = this.opts_.nb;
    this._id = this.opts_.id;
    this.CnrInfo = this.opts_.cnrInfo;
    this._showCnrInfo=this.opts_.showCnrInfo || false;
    this._isVarLabel = this.opts_.isVarLabel || false;
    this._isDmLabel  = this.opts_.isDmLabel || false;
    this._isNbLabel  = this.opts_.isNbLabel || false;
    this._isNrLabel  = this.opts_.isNrLabel || false;
    this._isKrLabel  = this.opts_.isKrLabel || false;
    this._isTrackLoaded = false;
       
      
    
  
    Vehicle.supportCanvas = false;
    this._ewindow = null;
    //timer kontrolujący update pozycji autobusu, ruch szczałek(by było widać że coś się rusza) i miganie
    this.timerID_ = {rotation:null,position:null,blink:null};
    
    this._smallEWindow = null; //okienko z podstawowymi informacjami o pojezdzie 
    this._bigEWindow = null; //okienko z odjazdami
    
    
    if (document.getElementById('testcanvas').getContext) {
        Vehicle.supportCanvas = true; //Firefox, Opera, Safari
    }else {
        Vehicle.supportCanvas = false;//IE
    }   
  
   //nie obsługuje przenoszenia
    if (opt_opts.draggable) {this.opts_.draggable = false;}
  
  // informacje o kącie obrotu szczałki
    this._angle =0; // real arrow rotation
    this._dangle =0; // random arrow rotation
    
    //Tabliczka pojazdu - istnieje referencja globalna i lokalna
    //lokalna by usunac ja gdy pojazd zniknie z planszy
    this.ewindow_ = null;
    //Referencja do trasy
    this._routeDirection = null;
    GMarker.apply(this, arguments);
    
    GEvent.bind(this,"posUpdated",this,function(newPos){});
    
     
    
 }
 
//Vehicle._ewindow = null;                      //EWindow tabliczka globalna dla pojazdu - jedna globalna 
Vehicle.selEWindow = null;                      //referencja do ostatnio klikniętej tabliczki
Vehicle._ewindowClass = "EWindow";   //styl dla tabliczki


Vehicle.prototype = new GMarker(new GLatLng(0, 0));
Vehicle.selected = null; //globalna referencja do klikniętego pojazdu

Vehicle.prototype.onclick_ = function(){
}

Vehicle.prototype.createIcon_ = function()
{       
       var icon = new GIcon();  
       icon.iconSize=this.style_.iconSize;
       icon.image = this.style_.bluredIcon;  
       icon.iconAnchor = this.style_.iconAnchor;  
       icon.infoWindowAnchor = this.style_.infoWindowAnchor;    
       icon.shadow = "";
       return icon;
}


 
Vehicle.prototype.closeSmallEW = function(){
     if (this._smallEWindow != null)
     {
         this.map_.removeOverlay(this._smallEWindow);
         this._smallEWindow=null;
     }
 }
 

Vehicle.prototype.closeBigEW = function(){
     if (this._bigEWindow != null)
     {
         this.map_.removeOverlay(this._bigEWindow);
         this._bigEWindow=null;
        }
 }
 
 

 Vehicle.prototype.openSmallEW = function(){
      
     if (this._smallEWindow == null)
     {
        this.closeBigEW();//zamknij duże okno jeśli otwarte
        this._smallEWindow = new EInfoWindow(this,this.map_,Vehicle._ewindowClass );
        
        this.map_.addOverlay(this._smallEWindow);
        this._smallEWindow.openOnMarker();
         var me = this;
         this._smallEWindow.onCloseClick = function(){
            me.closeSmallEW();
         }
        this._smallEWindow.showVariance();
     }   
 }
 
 Vehicle.prototype.openBigEW = function(){
         
      if (this._bigEWindow == null)
      {
        //if(!this._trackLoaded){
          if(!this._routeDirection._trackCreated)
              this._routeDirection.refreshInNMode();
          else
              this._routeDirection.addToMap();
          //  this._trackLoaded = true;
        
        //}
        
        
        this.closeBigEW();//zamknij małe okno jeśli otwarte
        this._bigEWindow = new EInfoWindow(this,this.map_,Vehicle._ewindowClass );
        
       // alert(this._routeDirection);
        Vehicle.routeDirection = this._routeDirection;
        
        this._bigEWindow.chSchowStopsChanged = function(checked){
                if(checked) Vehicle.routeDirection.showStops()
                                else Vehicle.routeDirection.hideStops();
        }
        this._bigEWindow.chSchowLineChanged = function(checked){
                if(checked) Vehicle.routeDirection.showPolyline()
                                else Vehicle.routeDirection.hidePolyline();
        }
        this._bigEWindow.chSchowLabelsChanged = function(checked){
                if(checked) Vehicle.routeDirection.showStopsLabel()
                                else Vehicle.routeDirection.hideStopsLabel();
        }
        this._bigEWindow.centre2VClick = function(){
            me.centreMap();
        }
        this._bigEWindow.centr2TClick= function(){
            me._routeDirection.centreMap();
        }
        
        
        this.map_.addOverlay(this._bigEWindow);
        this._bigEWindow.openOnMarker();
        
        this.refreshSchedules();
        var me = this;
        this._bigEWindow.onCloseClick = function(){
            me.closeBigEW();
            Vehicle.selected = null;
            if(this._showCnrInfo)
                me.clearInfo();
         }
         
     }   
 }


//centrowanie mapy do pojazdu
Vehicle.prototype.centreMap = function(){
      //this.map_.setCenter(this.getPoint(),14);
     // this.map_.panTo(this.getPoint());
      this.map_.setCenter(this.getPoint());
            
}

 Vehicle.prototype.refreshSchedules = function()
 {
    this._bigEWindow.getScheduleData(this._id,this.CnrInfo.routeNr,this.CnrInfo.trackT,this.CnrInfo.idp,this._routeDirection.isStopsDrawed,this._routeDirection.isPolylineDrawed,this._routeDirection.isStopsLabelDrawed);
    this._bigEWindow.redraw();
 }
 
 
 
 Vehicle.prototype._clickEvent = function()
 {
    //odznaczenie wcześniej zaznaczonego pojazdu
    if(Vehicle.selected != null){
        Vehicle.selected.closeBigEW();
     }
    Vehicle.selected = this;
    if(this._showCnrInfo){
        this.refreshCnrInfo();//pobierz info o pojezdzie (lewy panel)
   }
    this.openBigEW();
    this.setImage(this.style_.focusedIcon);
 }

Vehicle.prototype.updatePosition = function(){
}

//update na podstawie przliczania z trasy
/*
Vehicle.prototype.updatePosition_1 = function(){
    
    if(this._routeDirection != null)
    {
        var where = this.CnrInfo.dp!=0?(this.CnrInfo.dw/this.CnrInfo.dp) : 0;
        var point = this._routeDirection.getPointBetwenStops(this.CnrInfo.idp, where);
        
        if(this.prevlatlng_ == null)
            this.prevlatlng_ = this._routeDirection.getPointBetwenStops(this.CnrInfo.idp, (where - 0.1) <0 ? 0 : (where - 0.1));
        else
            this.prevlatlng_ = this.getLatLng();
        
        this.setPoint(point);
    
        if(!this.prevlatlng_.equals(point))
        {
            this._angle = this._bearing(this.prevlatlng_,point);
            this._dangle = this._angle;
        }
        
        this.rotate(); //zmień kierunek szczałki
    }
} 
*/

Vehicle.prototype.updatePosition_1 = function(){
          
    if(this._routeDirection != null)
    {
        var where = this.CnrInfo.dp!=0?(this.CnrInfo.dw/this.CnrInfo.dp) : 0;
        var point ;//= this._routeDirection.getPointBetwenStops(this.CnrInfo.idp, where);
        var me = this;

        var evt = GEvent.addListener(this._routeDirection,"partLoaded",function(polyline){
                    GEvent.removeListener(evt);
                    point = polyline.GetPointAtDistance(where * polyline.getLength());
                    
                    if(me.prevlatlng_==null)
                    {
                        me.prevlatlng_= polyline.GetPointAtDistance(((where-0.01)<0?0:(where-0.01)) * polyline.getLength())
                    }
                    else
                        me.prevlatlng_ = me.getLatLng();
                    me.setPoint(point);
                    
                    if(!me.prevlatlng_.equals(point))
                    {
                        me._angle = me._bearing(me.prevlatlng_,point);
                        me._dangle = me._angle;
                    }
                    me.rotate(); //zmień kierunek szczałki
                   // GEvent.trigger(me,"posUpdated",point);
                    me.positionUpdated(point);
                    
                });
                this._routeDirection.loadRoutePart(this.CnrInfo.idp,this.CnrInfo.idp2);
    }
} 

Vehicle.prototype.positionUpdated = function(pos){}


//update na podstawie gps
Vehicle.prototype.updatePosition_0 = function(){
    
       var point = new GLatLng(this.CnrInfo.lat,this.CnrInfo.lng);
     
       this.prevlatlng_ = this.getLatLng();
        
       if(!this.prevlatlng_.equals(point))
        {
            this._angle = this._bearing(this.prevlatlng_,point);
            this._dangle = this._angle;
        }
     this.setPoint(point);  
     this.rotate(); //zmień kierunek szczałki
     ///GEvent.trigger(me,"posUpdated",point);
     this.positionUpdated(point);
}



//update na podstawie przliczania z trasy i gps
Vehicle.prototype.updatePosition_2 = function(){
   
   if(this.CnrInfo.lat!=-1 &&  this.CnrInfo.lat!= 0)
        this.updatePosition_0();
   else
        this.updatePosition_1();
} 

 
Vehicle.prototype.update = function(cnrInfo)
{
    var me = this;
    this.CnrInfo = cnrInfo;
   
    this.updatePosition();
   
    //this.timerID_.position=window.setTimeout(function(){me.setPoint(p);},1000); //update pozycji za 1000s
  
    this.refreshLabels();
    
    if(Vehicle.selected && this._nb == Vehicle.selected._nb)
   {
        this.refreshSchedules();//odśwież rozkład   
        if(this._showCnrInfo)//dodatkowe informacje o pojeździe
            this.refreshCnrInfo();
   }
    
    this.setImage(this.style_.focusedIcon);
    this.timerID_.blink=window.setTimeout(function(){me.setImage(me.style_.bluredIcon);},1000);
     
 }
 
/*
Vehicle.prototype.loadTrack=function()
{
   var me = this;
  if(this.CnrInfo.trackT==null || this.CnrInfo.routeNr==null) return;
  {
    if(this._routeDirection == null)
    {
       this._routeDirection = new RouteDirection(TaStops.map,{style:new PolyStyle({color:this.CnrInfo.routeCol})});//new RouteDirection(this.map_);
       
       this._routeDirection.isStopsDrawed = false;
       this._routeDirection.isPolylineDrawed = false;
   
       this._routeDirection.dataLoaded = function(){
             //alert(me.CnrInfo.trackT);
             
             TaStops.map.addOverlay(me);
             me.updatePosition();
        }    
        this._routeDirection.loadInNMode(this.CnrInfo.routeNr,this.CnrInfo.trackT);
    }
  }
}
*/

var rdm = new RouteDirectionManager();

Vehicle.prototype.loadTrack=function()
{
   var me = this;
  if(this.CnrInfo.trackT==null || this.CnrInfo.routeNr==null) return;
  //{
    /*
    if(this._routeDirection == null)
    {
       this._routeDirection = new RouteDirection(TaStops.map);//new RouteDirection(this.map_);
       this._routeDirection.isStopsDrawed = false;
       this._routeDirection.isPolylineDrawed = false;
       this._routeDirection.dataLoaded = function(){
             TaStops.map.addOverlay(me);
             me.updatePosition();
             
       }
       this._routeDirection.loadInNMode(this.CnrInfo.routeNr,this.CnrInfo.trackT);
    }
    */
    //var me = this;
     var ev = GEvent.addListener(rdm,"load",function(route){
                        if(route._routeNr == me.CnrInfo.routeNr && route._trackT == me.CnrInfo.trackT){
                            me._routeDirection = route;
                            TaStops.map.addOverlay(me);
                            me.updatePosition();
                            //trasa załadowana więc usuń zdarzenie
                            GEvent.removeListener(ev);
                        }
                });
    rdm.loadRouteInNMode(this.CnrInfo.routeNr,this.CnrInfo.trackT);
}


Vehicle.prototype.initialize = function(map)
{    
 this.map_ = map;
 GMarker.prototype.initialize.apply(this, arguments);
  
  //arrow
 var div = document.createElement('div');
 div.style.position = "absolute";
 map.getPane(G_MAP_MARKER_PANE).appendChild(div);
 this.map_ = map;
 this._divArrow = div;
 //label z numerem lini
 div = document.createElement('div');
 div.style.position = "absolute";
 map.getPane(G_MAP_MARKER_PANE).appendChild(div);
 this._labelNr = div;
 
 this._labelNr.className        = this.style_.labelClass;
 //kolor kontrolowany przez numer lini
 if(this.ctrLabelColor)
     this._labelNr.style.background = this.CnrInfo.routeCol;
 else
     this._labelNr.style.background = this.style_.labelColor;
     
 
 this._labelNr.innerHTML = this.CnrInfo.routeNr;
 
 
 if(!this._isNrLabel) this._labelNr.style.display = 'none';
 
 
 //lebel z odchyleniem
 this._varDiv = document.createElement('div');//odchylenie
 this._varDiv.className = this.style_.labelClass +"Var";
 this._varDiv.innerHTML = this.CnrInfo.varStr;
 this._varDiv.style.position = "absolute";
 if(!this._isVarLabel) this._varDiv.style.display = 'none';
 map.getPane(G_MAP_MARKER_PANE).appendChild(this._varDiv);
 
 //label z numerem pojazdu
 this._nbDiv = document.createElement('div');
 this._nbDiv.className = this.style_.labelClass +"Nb";
 this._nbDiv.innerHTML = this._nb;
 this._nbDiv.style.position = "absolute";
 if(!this._isNbLabel) this._nbDiv.style.display = 'none';
 map.getPane(G_MAP_MARKER_PANE).appendChild(this._nbDiv);

 //
 //label z oznaczeniem usterki
 this._dmDiv = document.createElement('div');
 this._dmDiv.className = this.style_.labelClass +"Dm";
 this._dmDiv.innerHTML = "&nbsp;";
 this._dmDiv.style.position = "absolute";
 if(!this._isDmLabel) this._dmDiv.style.display = 'none';
 map.getPane(G_MAP_MARKER_PANE).appendChild(this._dmDiv);
 
 //
 //label z czynn
 this._krDiv = document.createElement('div');
 this._krDiv.className = this.style_.labelClass +"Kr";
 this._krDiv.innerHTML = this.CnrInfo.nrKr;
 this._krDiv.style.position = "absolute";
 if(!this._isKrLabel) this._krDiv.style.display = 'none';
 map.getPane(G_MAP_MARKER_PANE).appendChild(this._krDiv);
 
      
 this.refreshLabels();
  
 
//rotation
 var me = this;

/* if(Vehicle.supportCanvas){
   this._divArrow.innerHTML = '<canvas >' + this.canvasHtml_ + '</canvas>';
   this._arrowImg = new Image();
   this._arrowImg.onload=function(){me.startRotation()};
   this._arrowImg.src=this.style_.arrowsUrl[0];
   }
 else{*/
  me.startRotation(); 
 //}
 
 //events
 GEvent.addDomListener(this,"click",function(){me._clickEvent();});
 }

Vehicle.prototype.refreshLabels = function() {

     if (this._isVarLabel && this._varDiv!=null) {
         var c = this.CnrInfo.varInt / 60;

         if (c < -2)
             this._varDiv.className = this.style_.labelClass + "Var_m2" ;
         else if(c<0 &&c  >=-2)
             this._varDiv.className = this.style_.labelClass + "Var_20" ;
         else if (c > 0  && c <= 1)
             this._varDiv.className = this.style_.labelClass + "Var_01" ;
         else if (c > 1)
             this._varDiv.className = this.style_.labelClass + "Var_p1" ;
         else
             this._varDiv.className = this.style_.labelClass + "Var_00" ;
         this._varDiv.innerHTML = this.CnrInfo.varStr;
     }
     if (this._isDmLabel && this._dmDiv != null) {
         if (this.CnrInfo.dmCode == 0 )
             this._dmDiv.className = this.style_.labelClass + "Dm_0";
         else
             this._dmDiv.className = this.style_.labelClass + "Dm_1";
     }
 }


Vehicle.prototype._bearing= function(from ,to)//obliczenie kąta skierowania szczałki
{
    var lat1 = from.latRadians();
    var lon1 = from.lngRadians();
    var lat2 = to.latRadians();
    var lon2 = to.lngRadians();

    this._angle = - Math.atan2( Math.sin( lon1 - lon2 ) * Math.cos( lat2 ), Math.cos( lat1 ) * Math.sin( lat2 ) - Math.sin( lat1 ) * Math.cos( lat2 ) * Math.cos( lon1 - lon2 ) ) + Math.PI;
    if (this._angle < 0.0 )
      this._angle  += Math.PI * 2.0;
    return this._angle;
}




Vehicle.prototype.rotate = function()
{
    if( this._divArrow==null) return;
   
    var r = 20;
    var delta=Math.PI/8;
    if(this._dangle>15*Math.PI/8) this._dangle = -Math.PI/8;
    
  
    if(Vehicle.supportCanvas)
    {
        for(var i = 0;i<8; ++i)
            if(this._dangle>(i*Math.PI/4 - delta) && this._dangle <=(i*Math.PI/4 + delta))     {this._divArrow.innerHTML='<img src=\''+ this.style_.arrowsUrl[i]  +'\' style=\'position:relative;border:0px;width:20px;height:20px\'></img>';this._divArrow.firstChild.style.top=(r*Math.cos(i*Math.PI/4))+'px';this._divArrow.firstChild.style.left=(-r*Math.sin(i*Math.PI/4))+'px';break;}
   }
    else
    {
        for(var i = 0;i<8; ++i)
            if(this._dangle>(i*Math.PI/4 - delta) && this._dangle <=(i*Math.PI/4 + delta)) {this._divArrow.innerHTML="<div style='position:relative;border:0px;width:20px;height:20px'>";this._divArrow.firstChild.style.top=(r*Math.cos(i*Math.PI/4))+'px';this._divArrow.firstChild.style.left=(-r*Math.sin(i*Math.PI/4))+'px';this._divArrow.firstChild.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+ this.style_.arrowsUrl[i]  +'\',sizingMethod=\'image\')';}
    }
    
    this._dangle = this._angle  +(Math.random() * 0.1) * Math.PI/2;//losujemy nowy kąt w odniesieniu do kąta oryginalnego
    
}
Vehicle.prototype.stopRotation = function()
{
    if (this.timerID_.rotation != null)
        window.clearTimeout(this.timerID_.rotation);
        
    this.timerID_.rotation = null;
}
Vehicle.prototype.startRotation = function(){
      var me  = this;
      if (this.timerID_.rotation == null)
           this.timerID_.rotation=window.setTimeout(function(){me.rotate();},Math.random()*18000); 
     this.rotate();
}


Vehicle.prototype.redraw = function(force) 
{
    GMarker.prototype.redraw.apply(this, arguments);
 
    if( this._divArrow == null) return;
    
    var p = this.map_.fromLatLngToDivPixel(this.getLatLng());
   
    //uwzględnienie promienia    
   var offsetx = this.getIcon().iconAnchor.x - 15;
   var offsety = this.getIcon().iconAnchor.y - 15;
  
   this._divArrow.style.left = (p.x - offsetx) + "px"; //arrow have 15px (10px have transparent marker border so 10+10>15)
   this._divArrow.style.top  = (p.y - offsety) + "px"; 
   
   this._labelNr.style.left = (p.x + this.style_.labelOffset.width) + "px";
   this._labelNr.style.top = (p.y + this.style_.labelOffset.height) + "px";
 
 
   this._krDiv.style.left = this._nbDiv.style.left = this._varDiv.style.left = p.x - this._varDiv.offsetWidth /2 + "px";
   
   var labelTop = p.y - 20 - this._krDiv.offsetHeight;
   this._krDiv.style.top =  labelTop + "px";
   
   labelTop -= this._varDiv.offsetHeight;
   this._varDiv.style.top = labelTop + "px";
    
   labelTop-= this._nbDiv.offsetHeight
   this._nbDiv.style.top  =  labelTop + "px";
  
   this._dmDiv.style.left = p.x + this._varDiv.offsetWidth /2 - this._dmDiv.offsetWidth+ "px";
   this._dmDiv.style.top =  labelTop + "px";
    
   var z = GOverlay.getZIndex(this.latlng_.lat());
   this._divArrow.style.zIndex = z-200000; // in back of the marker
}




Vehicle.prototype.remove = function() 
{
    if(this._bigEWindow!=null){
         this.closeBigEW();
         this._bigEWindow = null;
     }
     
    if(Vehicle.selected!=null && Vehicle.selected._nb == this._nb)
        Vehicle.selected = null;
 
    //usuwanie 
    //this._routeDirection.clearInNMode();
 
    this.stopRotation();
    
    this._arrowImg = null;
    
 
    this._divArrow.innerHTML = "";
    this._labelNr.innerHTML = "";
 
    if(this._divArrow.parentNode!=null){
        this._divArrow.parentNode.removeChild(this._divArrow);
     //   this._divArrow.outerHTML = ""; // pseudo-leak in IE
    }
 
    if(this._labelNr.parentNode!=null){
        this._labelNr.parentNode.removeChild(this._labelNr);
        
        this._nbDiv.parentNode.removeChild(this._nbDiv);
        this._dmDiv.parentNode.removeChild(this._dmDiv);
        this._varDiv.parentNode.removeChild(this._varDiv);
        this._krDiv.parentNode.removeChild(this._krDiv);
      
    }
    
    
    this._divArrow = null;
    this._labelNr = null;
 
    window.clearTimeout(this.timerID_.rotation);
    window.clearTimeout(this.timerID_.position);
    window.clearTimeout(this.timerID_.blink);
 
    GEvent.clearInstanceListeners(this);
    GMarker.prototype.remove.apply(this, arguments);
    
    //odpal info że pojazd został usunięty
    this.removed();
}
Vehicle.prototype.removeRoute = function()
{
    //usuwanie 
    if(this._routeDirection!=null)
        this._routeDirection.lightClear();
    this._routeDirection = null;

}

Vehicle.prototype.removed =  function(){
    


}

Vehicle.prototype.show = function() {
        if (this.div_) {
          this._divArrow.style.display="";
          this.redraw();
        }
        this.hidden = false;
   GMarker.show.apply(this, arguments);

}
      
Vehicle.prototype.hide = function() {
        if (this.div_) {
          this.div_.style.display="none";
        }
        this.hidden = true;
        GMarker.hide.apply(this, arguments);
}

Vehicle.prototype.showNbLabel = function(){
    this._isNbLabel = true;this._nbDiv.style.display = 'block';
    this.redraw();
}

Vehicle.prototype.showDmLabel = function(){
    this._isDmLabel = true;this._dmDiv.style.display = 'block';
    this.redraw();
}

Vehicle.prototype.showVarLabel = function(){
    this._isVarLabel = true;this._varDiv.style.display = 'block';
    this.redraw();
}

Vehicle.prototype.showNrLabel = function(){
    this._isNrLabel = true;this._labelNr.style.display = 'block';
    this.redraw();
}

Vehicle.prototype.hideNbLabel = function(){
    this._isNbLabel = false;this._nbDiv.style.display = 'none';
     this.redraw();
}

Vehicle.prototype.hideDmLabel = function(){
    this._isDmLabel = false;this._dmDiv.style.display = 'none';
     this.redraw();
}

Vehicle.prototype.hideVarLabel = function(){
    this._isVarLabel = false;this._varDiv.style.display = 'none';
     this.redraw();
}

Vehicle.prototype.hideNrLabel = function(){
    this._isNrLabel = false;this._labelNr.style.display = 'none';
     this.redraw();
}
Vehicle.prototype.hideKrLabel = function(){
    this._isKrLabel = false;this._krDiv.style.display = 'none';
     this.redraw();
}

Vehicle.prototype.showKrLabel = function(){
    this._isKrLabel = false;this._krDiv.style.display = 'block';
    this.redraw();
}


Vehicle.prototype.refreshCnrInfo = function(){
    var div = document.getElementById("left_pane");
    
    if(div == null) return;
    
    var me = this;
    
    var wbs = new WebServiceClient("CNR_DajInfoPojazdu");
    wbs.appendProperty("nb",this._nb);
     
    wbs.send(function(data){
        var cnrd = data.getElementsByTagName("V");
        
        if(cnrd==null || cnrd.length == 0){me.clearInfo(); return;}
        
        var v = cnrd[0];
        me._refreshInfo(div,v);
   });          
}

Vehicle.prototype._refreshInfo = function(div, vehNode) {
    var g = function(id) { return document.getElementById(id); }
    var a = function(atrName) { return vehNode.getAttribute(atrName); }

    var tb = g("odch");
    g("nb").value = a("nb");
    g("nr").value = a("nr");
    g("lp").value = a("lp");
    g("wrj").value = a("dt");
    g("zaj").value = a("zaj");
    g("dz").value = a("dz"); //dzien
    g("op").value = a("op");
    g("war_tr").value = a("war");
    g("aw").value = a("al");
    g("od").value = a("np1");
    g("do").value = a("np2");
    g("drp").value = a("drp");
    g("drw").value = a("drw");
    tb.value = a("todch");
    g("dl").value = a("px");
    g("sz").value = a("py");
    g("bryg").value = a("nr_kurs"); ;
    g("zap").value = a("zap"); ;
    g("gps").value = a("gps"); ;

    if (this._isVarLabel) {
        var sodch = parseFloat(a("sodch"));
        var c = sodch / 60;
        if (c < -2)
            tb.className = "small_m2";
        else if (c < 0 && c >= -2)
            tb.className = "small_20";
        else if (c > 0 && c <= 1)
            tb.className = "small_01";
        else if (c > 1)
            tb.className = "small_p1";
        else
            tb.className = "small_00";

    }
    if (this._isDmLabel) {
        if (a("al") == 0)
            g("aw").className = "small_0";
        else
            g("aw").className = "small_1";
    }


}

Vehicle.clearInfo = Vehicle.prototype.clearInfo = function(div,vehNode){
       var g = function(id){return document.getElementById(id);}
       var a = function(atrName){return vehNode.getAttribute(atrName);}
       g("nb").value = "";
       g("nr").value = "";
       g("lp").value = "";
       g("wrj").value = "";
       g("zaj").value = "";
       g("dz").value = "";//dzien
       g("op").value = "";
       g("war_tr").value = "";
       g("aw").value = "";
       g("aw").className = "small";
       g("od").value = "";
       g("do").value = "";
       g("drp").value = "";
       g("drw").value = "";
       g("odch").value = "";
       g("odch").className = "small";
       g("dl").value = "";
       g("sz").value = "";
       g("bryg").value = "";
       g("gps").value = "";
}






//IE 6 nie wspiera array.indexOf
Array.prototype.indexOf = Array.prototype.indexOf ?
    Array.prototype.indexOf :
    function(obj) {
        for(var i = -1, j = this.length; ++i < j;)
            if(this[i] === obj) return i;
        return -1;
    };









 
