/*****************************************************************************
 *
 * File     : MapView.js
 * 
 * Project  : WMS Viewer Client
 * 
 * Contents : 
 *
 * Author: Milan Trninic
 *
 * Copyright 1999-2005 Galdos Systems, Inc.
 * All rights reserved.
 * 
 ***|***************************|***********************|*******************|*/

/************************************************************************
*
*	Global declarations
*
*	
*
*************************************************************************/

/************************************************************************
*
*	function:	MapView
*
*	purpose:	Constructor
*
*************************************************************************/
function MapView()
{
	// method assignments
	this.init = MapView.init;
	this.setSize = MapView.setSize;
	this.initiateGetRequest = MapView.initiateGetRequest;
	this.getResultType = MapView.getResultType;
	this.activateControl= MapView.activateControl;
	this.setParameters = MapView.setParameters;
	this.getSize = MapView.getSize;
	this.getMapViewUI = MapView.getMapViewUI;
	this.showLayer = MapView.showLayer;
	this.onResultReceived = MapView.onResultReceived;

	// instance field declarations
	this._mapViewUI;
	this._mapViewUIBuffer;
	this._mapViewFormUI;

	// initialization
	this.init();
}

/************************************************************************
*
*	function:	init
*
*	purpose:	initializes the globals
*
*************************************************************************/
function MapView.init(mapViewUI)
{
	this._mapViewUI = document.getElementById('mapView1');
	this._mapViewUIBuffer = document.getElementById('mapView2');
	this._mapViewFormUI = document.getElementById('mapViewForm');
	this._mapViewUI.attachEvent("onload", onMapViewResult);
	this._mapViewUIBuffer.attachEvent("onload", onMapViewResult);
}
	
/************************************************************************
*
*	function:	getMapViewUI
*
*	purpose:	gets the view UI element (iframe)
*
*************************************************************************/
function MapView.getMapViewUI()
{
	return this._mapViewUI;
}

/************************************************************************
*
*	function:	initiateGetRequest
*
*	purpose:	initiates the GET request
*
*************************************************************************/
function MapView.initiateGetRequest(request)
{
	return this._mapViewUIBuffer.src = request;
}
	
/************************************************************************
*
*	function:	activateControl
*
*	purpose:	
*
*************************************************************************/
function MapView.activateControl(action)
{
	this._mapViewUI.contentWindow.activateControl(action);
}

/************************************************************************
*
*	function:	setSize
*
*	purpose:	
*
*************************************************************************/
function MapView.setSize(width, height)
{
	this._mapViewUI.width = width;
	this._mapViewUI.height = height;
	if (	this._mapViewUI && 
				this._mapViewUI.contentWindow && 
				this._mapViewUI.contentWindow.setSplashSize)
	{
		this._mapViewUI.contentWindow.setSplashSize(width, height);
	}

	this._mapViewUIBuffer.width = width;
	this._mapViewUIBuffer.height = height;
	if (	this._mapViewUIBuffer && 
				this._mapViewUIBuffer.contentWindow && 
				this._mapViewUIBuffer.contentWindow.setSplashSize)
	{
		this._mapViewUIBuffer.contentWindow.setSplashSize(width, height);
	}
}

/************************************************************************
*
*	function:	onResultReceived
*
*	purpose:	
*
*************************************************************************/
function MapView.onResultReceived()
{
	var temp = this._mapViewUIBuffer;
	this._mapViewUIBuffer = this._mapViewUI;
	this._mapViewUI = temp;
	
	if (this._mapViewFormUI.target == "mapView1") this._mapViewFormUI.target = "mapView2";
	else this._mapViewFormUI.target = "mapView1";
	
	this._mapViewUI.style.display = '';
	this._mapViewUIBuffer.style.display = 'none';
}

/************************************************************************
*
*	function:	getSize
*
*	purpose:	
*
*************************************************************************/
function MapView.getSize()
{
	var size = new Rectangle(this._mapViewUI.width, this._mapViewUI.height);
	return size;
}

/************************************************************************
*
*	function:	getResultType
*
*	purpose:	
*
*************************************************************************/
function MapView.getResultType()
{
	var resultType = "unknown";
	try
	{
		var resultTypeElement = this._mapViewUI.contentWindow.document.getElementById("resultType");
		if (resultTypeElement != null) resultType = resultTypeElement.getAttribute("value");
	}
	catch (exception)
	{
	}
	return resultType;
}

/************************************************************************
*
*	function:	setParameters
*
*	purpose:	
*
*************************************************************************/
function MapView.setParameters(boundingBox, mapSize)
{
	this._mapViewUI.contentWindow.setParameters(boundingBox, mapSize);
}

/************************************************************************
*
*	function:	showLayer
*
*	purpose:	
*
*************************************************************************/
function MapView.showLayer(layerName, show)
{
	this._mapViewUI.contentWindow.showLayer(layerName, show);
}


