//
// Created 20040119 RB
//
//
// -------------------------------------------------------------------------
// JS script for fleetstar.html - frameset for site
//
// Functions to relay JS calls from maplet running in JRE
// to legacy functions in actual page in site (mainFrame)
// -------------------------------------------------------------------------


function mapletReady(theSession)
{
	window.status = "Maplet: ready";
	mainFrame.mapletReady(theSession);
}

function serviceFailed(serviceID)
{
	window.status = "Maplet: service not running: " + serviceID;
	mainFrame.serviceFailed(serviceID);
}

function getLocationDone()
{
	window.status = "Maplet: get location, done";
	mainFrame.getLocationDone();
}

function mapletAlert(warning)
{
	window.status = "Maplet alert: " + warning;
	mainFrame.mapletAlert(warning);
}

function mapletReplayReady(requestID)
{
	window.status = "Maplet replay ready, reqID: " + requestID;
	mainFrame.mapletReplayReady(requestID);
}

function selectRecord(ts)
{
	window.status = "Maplet select record, ts: " + ts;
	mainFrame.selectRecord(ts);
}

function confirmMaplet()
{
	/*
		this function reacts differently when a different number of arguments are passed
		we call this behaviour 'polymorphism' doesn't that sound cool!
	*/

	if (arguments.length == 4)
	{
		// addLocation page
		window.status = "Maplet: confirmMaplet(" + arguments[0] + ", " + arguments[1] + ", " + arguments[2] + ", " + arguments[3] + ")";
		mainFrame.confirmMaplet(arguments[0], arguments[1], arguments[2], arguments[3]);
	}
	if (arguments.length == 2)
	{
		// addRoute page
		window.status = "Maplet: confirmMaplet(" + arguments[0] + ", " + arguments[1] + ")";
		mainFrame.confirmMaplet(arguments[0], arguments[1]);
	}
}

function geocodeFailed(dummy)
{
	window.status = "Maplet: geocode failed";
	mainFrame.geocodeFailed(dummy);
}

function mapletTicker(arg, msg)
{
	window.status = "Maplet: mapletTicker(" +  arg + ", " + msg + ")";
	mainFrame.mapletTicker(arg, msg);
}

function routingFailed(msg)
{
	window.status = "Maplet: routing failed, msg: " +  msg;
	mainFrame.routingFailed(msg);
}

function gotDescr(id)
{
	window.status = "Maplet: got description, id: " +  id;
	mainFrame.gotDescr(id);
}

function MoveFooter() {
	//Moves the footer to the bottom of the page when the window is resized (for those accessing fleetstar.html not in the fixed-sized popup window).
	var footer = document.getElementById('bottomFrame');
	var y = parseInt(document.body.clientHeight) - 28; //Footer Frame is 28 pixels high;
	var size = y + document.body.scrollTop + "px";	
	footer.style.position = "absolute";
	footer.style.left = "0px";
	footer.style.top = size;  	
}

function FillMapToScreen() {
	//Makes the map take up any available room when page is resized. Ideally would sit in map.js but needs to know the entire window size and map.js is loaded into mapFrame.
	//This is only intended to be used from Manage / Locate screen! If used from other screens it will not work as the left-hand alignment is fixed to start at 310px.

		var map = document.getElementById('mapFrame');
		var scrWidth = parseInt(document.body.clientWidth);
		var newWidth = scrWidth - 310 // 310 is the normal left-hand point of the mapFrame.
		newWidth < 150 ? newWidth = 150: newWidth = newWidth;		
		
		map.style.width = newWidth + "px"; //Now make the map as wide as possible.
		var topFrame = document.getElementById('navFrame');
		var footerFrame = document.getElementById('bottomFrame');
		var topHeight = parseInt(topFrame.height);
		var footerHeight = parseInt(footerFrame.height);
		var scrHeight = parseInt(document.body.clientHeight);
		var newHeight = scrHeight - topHeight - footerHeight - 20;
		newHeight < 150 ? newHeight = 150: newHeight = newHeight;		
		
		map.style.height = newHeight + "px"; //Whatever is left of the screen height.
		var ajaxdiv = mapFrame.document.getElementById('ajaxmap');
 		ajaxdiv.style.width = newWidth + "px";
 		ajaxdiv.style.height = newHeight + "px";

}

function RemoveSVFrame() {
    var svfr = document.getElementById('SVFrame');
    svfr.style.display="none";
}

function SizeSV() {
    //A bit smaller than the map frame.
    var map = document.getElementById('mapFrame');
    var svfr = document.getElementById('SVFrame');
	
	svfr.style.top = "110px";
	svfr.style.left = "330px";
	svfr.style.display = "block";
	svfr.style.position = "absolute";
	
	var scrWidth = parseInt(document.body.clientWidth);
	var newWidth = scrWidth - 310 // 310 is the normal left-hand point of the mapFrame.
	newWidth < 150 ? newWidth = 150: newWidth = newWidth - 30;		

	
	svfr.style.width = newWidth - 50 + "px"; //Not as wide as mapframe
	var topFrame = document.getElementById('navFrame');
	var footerFrame = document.getElementById('bottomFrame');
	var topHeight = parseInt(topFrame.height);
	var footerHeight = parseInt(footerFrame.height);
	var scrHeight = parseInt(document.body.clientHeight);
	var newHeight = scrHeight - topHeight - footerHeight - 20;
	newHeight < 150 ? newHeight = 150: newHeight = newHeight - 30;		
	
	svfr.style.height = newHeight - 50+ "px"; //Whatever is left of the screen height minus a bit more.
	var svdiv = SVFrame.document.getElementById('svdiv');
	svdiv.style.width = newWidth + "px";
	svdiv.style.height = newHeight + "px";
}