// aimsLegend.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js
*/

aimsLegendPresent=true;

var PrintLegend = false;		// MAIRIM
var drawLegendOnly=false;
var defaultLegTitle=legTitle;

/*
***************************************************************************************

Legend functions 

***************************************************************************************
*/

// send request to create graphic legend
function getLegend() {
	legendVisible=true;
	drawLegendOnly=true;
	var theString=writeXML();
	showRetrieveMap();
	sendToServer(imsURL,theString,98);
}

// write out the legend display
function showLegend() {
	// MAIRIM: original code replaced by
	//document.theLegend.src = legendImage;
	//alert(legendImage);
	//document.all.myiFrame.src = "legend.asp?theLegendURL=" + legendImage;

	var theIFrame = document.getElementById('myiframe');
	theIFrame.src = "legend.asp?theLegendURL=" + legendImage;
	
	// Iframe for the visible layers
	var theIFrameVL = document.getElementById('myiframeVL');
	theIFrameVL.src = "visibleLayersTool.htm";
}

// add Legend to XML request
function addLegendToMap() {
	var legString = "";

	if (PrintLegend) {					// MAIRIM
		//Mairim: remove legend title
		//legString += '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + 600 + '" height="' + 200 + '" ';
		legString += '<LEGEND font="' + legFont + '" width="' + 600 + '" height="' + 200 + '" ';
		legString += 'autoextend="true" cansplit="true" columns="3" backgroundcolor="255,255,255"';
		PrintLegend = false;
	} else {
		//MAIRIM: remove legend title
		//legString += '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
		legString += '<LEGEND font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
		legString += 'autoextend="true" backgroundcolor="255,255,255"';
	}
	//MAIRIM
	legString += ' valuefontsize ="10"'; 
	
	if (hideLayersFromList) {
		legString += '>\n<LAYERS>\n';
		for (var legvar=0;legvar<noListLayer.length;legvar++) {
			if (noListLayer[legvar]) legString += '<LAYER id="' + LayerID[legvar] + '" />\n';
		}
		legString += '</LAYERS>\n';
		legString += '</LEGEND>\n';
	} else {
		legString += ' />\n';
	}
	if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
	return legString;
}

// add Legend to XML request
function addLegendToMap_BK() {
	var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
	legString += 'autoextend="true" backgroundcolor="255,255,255"';
	if (hideLayersFromList) {
		legString += '>\n<LAYERS>\n';
		for (var legvar=0;legvar<noListLayer.length;legvar++) {
			if (noListLayer[legvar]) legString += '<LAYER id="' + LayerID[legvar] + '" />\n';
		}
		legString += '</LAYERS>\n';
		legString += '</LEGEND>\n';
	} else {
		legString += ' />\n';
	}
	if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
	return legString;
}
