/*****************************************************************************
*
* File     : ScalePanel.js
* 
* Project  : WMS Viewer Client
* 
* Contents : Displays the contents of the scale configuration.
*
* Author: Milan Trninic
*
* Copyright 1999-2005 Galdos Systems, Inc.
* All rights reserved.
* 
***|***************************|***********************|*******************|*/

/************************************************************************
*
*	Global declarations
*
*
*************************************************************************/

/************************************************************************
*
*	function:	ScalePanel
*
*	purpose:	Constructor
*
*************************************************************************/
function ScalePanel()
{
	// superclass
	var uiElement = document.getElementById("scalePanel");
	this._superClass = StackedPanel;
	this._superClass(uiElement);
	
	// method assignments
	this.init = ScalePanel.init;
	this.setSize = ScalePanel.setSize;	
	this.sendHarvestRequest = ScalePanel.sendHarvestRequest;
	this.handleHarvestResponse = ScalePanel.handleHarvestResponse;
	this.getXmlHttpObject = ScalePanel.getXmlHttpObject;	

	// instance field declarations
	this._superClass;
	this._scaleLegendUI;
	this._xmlhttp;	

	// initialization
	this.init();
}

/************************************************************************
*
*	function:	init
*
*	purpose:	initializes the globals
*
*************************************************************************/
function ScalePanel.init()
{
	this._scaleLegendUI = document.getElementById("scaleLegend");
}

/************************************************************************
*
*	function:	setSize
*
*	purpose:	
*
*************************************************************************/
function ScalePanel.setSize(width, height)
{
	// For explanation of the purpose of the temp variable, see the documentation
	this.temp = this._superClass.setSize;
	this.temp(width, height);
	//this._superClass.setSize(width, height);
	this._scaleLegendUI.style.height = height * 0.88;
	this._scaleLegendUI.style.width = width * 0.98;
}

/************************************************************************
*
*	function:	sendHarvestRequest
*
*	purpose:	
*
*************************************************************************/
function ScalePanel.sendHarvestRequest(wmsAddress, handler)
{
	this._xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	this._xmlhttp.onreadystatechange = handler;
	// Use POST because no time for finding how to disable IE caching of GET
	this._xmlhttp.open("POST", "fpsPortal?request=getScaleConfiguration&url=" + escape(wmsAddress), true);
	this._xmlhttp.send();
}

/************************************************************************
*
*	function:	handleHarvestResponse
*
*	purpose:	
*
*************************************************************************/
function ScalePanel.handleHarvestResponse()
{
	var xml = this._xmlhttp.responseXML;
	// TODO Implement cached xslt
	var scaleLegend = transform(xml, "xsl/scaleLegend.xsl");
	this._scaleLegendUI.innerHTML = scaleLegend;
}

/************************************************************************
*
*	function:	getXmlHttpObject
*
*	purpose:	
*
*************************************************************************/
function ScalePanel.getXmlHttpObject()
{
	return this._xmlhttp;
}
