var CarTrack = {}
CarTrack.Init = function(){
    this.Url='Treackdata';
    this.async=true;
    this.httpMethod='post';
    this.httpParams={ uid: uidkey,id:0,CarId: -1,Maps: 1,date: new Date()};
    this.callbackArgsArray = '';
    this.JsonData={};
    this.speed = 100; 
	this.timer = null; 
	this.Start =0;
	this.Finish=0;
}	
   
CarTrack.SetSF = function(Maps,Carid,st,fn,date){
 	this.Start =st;
	this.Finish=fn;
	this.httpParams.CarId=Carid;
	this.httpParams.Maps=Maps;
	this.httpParams.date=date.format('d.m.Y');
	this.Update();  
}

CarTrack.Update = function(){
    this.timer=null;
    if (this.Start<this.Finish){
        this.httpParams.id=this.Start;
        this.Start++;
        AllCarLines.Draw(this.httpParams.CarId);
        this.httpParams.uid=uidkey;
        try {
	            Ext.Ajax.request({
			        url: this.Url,
			        params: this.httpParams,
			        success: this.Callback,
			        failure:this.Onerror,
			        scope: this
		        });
            } catch (err){}         
    }else {
        this.Start=0;
        this.Finish=0;
         AllCarLines.Draw(this.httpParams.CarId);
    }
}

CarTrack.Onerror = function (xmlHttpRequest,callbackArgsArray){
    alert('Ошибка');
}

CarTrack.Callback = function (form, action){
   CarTrack.JsonData= Ext.util.JSON.decode(form.responseText); 
    
    try {
        AllCarLines.Update(this.JsonData);
      //  AllCarLines.Test(CarTrack.httpParams);
    } catch (err)
    { 	
      //   console.log(err);
    } finally 	
    { 	
    	//alert('Завершающие действия');
    };
     	
	this.timer = setTimeout(function(){CarTrack.Update()}, this.speed);	
}

CarTrack.Stop = function(){
	clearTimeout(this.timer);
	this.timer=null;
}
