function RM_Route( regionPrefix, trainId, date, timeZone )
{
	this.loader = 'loader';
	
	this.regionPrefix = regionPrefix;
	this.trainId = trainId;
	this.date = date;

	this.departureStation = {};
	this.arrivalStation = {};
	
	this.installedClasses = {};
	
	this.timeZone = timeZone;
};


RM_Route.prototype.init = function( options )
{
	for ( var i in options )
		this[ i ] = options[ i ];
	
	return this;
}


RM_Route.prototype.onMouseOver = function( ob )
{
	if ( this.installedClasses[ $(ob).attr('id') ] == undefined )
	{
		this.installedClasses[ $(ob).attr('id') ] = {};
		this.installedClasses[ $(ob).attr('id') ].tr = $(ob).attr( 'class' );
		this.installedClasses[ $(ob).attr('id') ].commontr = $(ob).attr( 'class' );
	}
	
	$(ob).addClass( 'flag_empty' );
};


RM_Route.prototype.onMouseOut = function( ob )
{
	$(ob).removeClass( 'flag_empty' );
};


RM_Route.prototype.onClick = function( ob, stationId, stationOrd )
{
	if ( this.departureStation.id != undefined && this.departureStation.id == stationId && this.departureStation.ord == stationOrd )
	{
		this.restoreClasses( this.departureStation.obId );
		this.departureStation = {};
		return;
	}
	
	if ( this.arrivalStation.id != undefined && this.arrivalStation.id == stationId && this.arrivalStation.ord == stationOrd )
	{
		this.restoreClasses( this.arrivalStation.obId );
		this.arrivalStation = {};
		return;
	}
	
	if ( this.departureStation.id != undefined && this.arrivalStation.id != undefined )
	{
		this.restoreClasses( this.departureStation.obId );
		this.restoreClasses( this.arrivalStation.obId );
		this.departureStation = {};
		this.arrivalStation = {};
	}
	
	
	if ( this.departureStation.id == undefined )
		this.departureStation = {
			'obId'	: $(ob).attr('id'),
			'id'	: stationId,
			'ord'	: stationOrd
		};
	else
		this.arrivalStation = {
			'obId'	: $(ob).attr('id'),
			'id'	: stationId,
			'ord'	: stationOrd
		};
	
	
	$(ob).addClass( 'flag' );
	$(ob).addClass( 'select' );
	
	
	if ( this.departureStation.id != undefined && this.arrivalStation.id != undefined )
	{
		if ( parseInt( this.departureStation.ord ) > parseInt( this.arrivalStation.ord ) )
		{
			var tempStation = this.departureStation;
			this.departureStation = this.arrivalStation;
			this.arrivalStation = tempStation;
		}
		
		this.refreshRouteTable();
	}
};


RM_Route.prototype.restoreClasses = function( id )
{
	$('#' + id).attr( 'class', this.installedClasses[ id ].commontr );

	this.installedClasses[ id ].tr = this.installedClasses[ id ].commontr;
};


RM_Route.prototype.refreshRouteTable = function()
{
	regionPrefix = this.regionPrefix.substr( 0, 1 ).toUpperCase() + this.regionPrefix.substr( 1 );
	
	var getData = '&trainId=' + this.trainId;
	getData += '&date=' + this.date;
	getData += '&departureStationId=' + this.departureStation.id;
	getData += '&arrivalStationId=' + this.arrivalStation.id;
	
	obPopup.show( this.loader );
	
	var obSelf = this;
	$.ajax({
		type: 'post',
		url: url.get('ajax') + '?Action=getEtrain' + regionPrefix + 'RouteTableTemplate&rand=' + Math.random() + getData,
		dataType: 'json',
		success: function( data, textStatus )
		{
			obPopup.hide( obSelf.loader );
		
			$('#route-table').html( data.tableHtml );
		
			obSelf.departureStation = {};
			obSelf.arrivalStation = {};			
			obSelf.installedClasses = {};
		},
		error: function( data, textError )
		{
			obMessage.add( 'error', lang.get('error.critical') ).show();
		}
	});
};


RM_Route.prototype.setTimeZone = function( timeZone )
{
	if ( this.timeZone != timeZone )
	{
		$('#timezone-' + this.timeZone).attr( 'class', '' );
		$('#timezone-' + timeZone).attr( 'class', 'active' );
		this.timeZone = timeZone;
	}
}
