﻿
/* ajax call */

function LoadShipDataToClient( routeID ) {
    var serviceUrl = '/services/InternalServices.aspx?RouteForShips=' + Url.encode(routeID);
    DoWebRequest(serviceUrl, OnGetShipDataCallCompleted); 
    try {
        TrackGAPageView("/map/ships-for-route/");
    }
    catch(e) { }
    return void(0);
}

function OnGetShipDataCallCompleted(executor, eventArgs) {
    if(executor.get_responseAvailable()) {
        HandleGetShipDataResponse(executor);
    }
    else {
        if (executor.get_timedOut())
            window.status = 'Service call timed out';
        else
            if (executor.get_aborted())
				window.status = 'Service call aborted';
    }
}

function HandleGetShipDataResponse(executor)
{   
	var response = executor.get_responseData();
	if (response != null ) {
		LoadShipInfos(response);
	}
}


/** "shipspot"  **/

function shipInfo()
{
	this.name = '';
	this.image = '';
	this.category = '';
	this.length = '';
	this.width = '';
	this.year = '';
	this.carLoad = '';
	this.passengerLoad = '';
	this.url = '';
}

_arrShipInfo = new Array();

function LoadShipInfos( strShipInfos )
{
	var shipSep = '$';
	var fieldSep = '|';
	var numFields = 8; 
	
	_arrShipInfo = '';
	_arrShipInfo =  new Array();
	if (strShipInfos != null) {
		var ships = strShipInfos.split(shipSep);
		if (ships.length > 0) {
			for (var i = 0; i < ships.length; i++) {
				var fields = ships[i].split(fieldSep)
				if (fields && fields.length >= 	numFields) {
					var ship = new shipInfo();
					ship.name = fields[0];
					ship.image =fields[1];
					ship.category = fields[2];
					ship.length = fields[3];
					ship.width = fields[4]
					ship.year = fields[5];
					ship.carLoad = fields[6];
					ship.passengerLoad = fields[7];
					ship.url = fields[8];
					_arrShipInfo[_arrShipInfo.length] = ship;
				}					
			}
			DisplayShipInfo(0);
		}
	}
}

function DisplayShipInfo( shipIndex ) {
	HideShipInfoArea();
	if (_arrShipInfo.length > shipIndex && shipIndex >= 0) {
		SetShipData(_arrShipInfo[shipIndex] );
		ShowShipArea();
	}

	if ( _arrShipInfo.length > 1 ) {
		SetVisibility('shipNavTable', true);
		
		SetInnerHTML('shipCurrentNumber', (shipIndex + 1).toString());
		SetInnerHTML('shipTotalNumber', ' (' +   _arrShipInfo.length.toString() + ')' );
	
		if ( shipIndex > 0 ) {
			SetLinkHref('shipPrevious', 'javascript:DisplayShipInfo(' + (shipIndex -1).toString() + ')  ');
		}
		SetVisibility( 'shipPrevious' , shipIndex > 0) ;
					
		if (  _arrShipInfo.length > (shipIndex + 1) ) {
			SetLinkHref('shipNext', 'javascript:DisplayShipInfo(' + (shipIndex + 1).toString() + ') ');
		}
		SetVisibility( 'shipNext' , _arrShipInfo.length > (shipIndex + 1)) ;
	
	}
	else {
		SetVisibility('shipNavTable', false);
		SetVisibility('shipNext', false);
	}

	return void(0);
}


	
function HideShipInfoArea() {
	SetVisibility('shipinfoarea', false);
	SetVisibility('shipimage', false	);	
	SetVisibility('shipNavTable', false);
	SetVisibility('shipNext', false);
	SetVisibility('shipviewfacilities', false);
	return void(0);
}

function SetShipData( ship ) {
	if (ship) {
		SetInnerHTML('shipname', ship.name);
		SetImageSrc('shipimage', ship.image);	
		SetInnerHTML('shiplength', ship.length);
		SetInnerHTML('shipwidth', ship.width);
		SetInnerHTML('shipcategory',ship.category );
		SetInnerHTML('shipyear',ship.year  );
		SetInnerHTML('shipcarload',ship.carLoad );
		SetInnerHTML('shippassengerload',ship.passengerLoad );
		SetLinkHref('shipurl', ship.url);
	}
}

function ShowShipArea()  {
	SetVisibility('shipinfoarea', true	);	
	SetVisibility('shipimage', true	);	
	SetVisibility('shipviewfacilities', true);
	return void(0);
}	

