// aimsLegend.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js
*/

aimsLegendPresent=true;
var legendImageLocation = "http://gisweb.ewashtenaw.org/website/mapwashtenaw/";
var drawLegendOnly=false;
var defaultLegTitle = legTitle;

/*
***************************************************************************************

Legend functions 

***************************************************************************************
*/



// send request to create graphic legend
function getLegend() {
	drawLegendOnly=true;
	var theString=writeXML();
	showRetrieveMap();
	sendToServer(imsURL,theString,98);
}

// write out the legend display
function showLegend() {
	
	//if (hasTOC) {
		// changed from TOCFrame to TextFrame
		// CDM Modified to put in GIF file (nice line) and Legend Title
		
		parent.TextFrame.document.open();
		parent.TextFrame.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head><title>Legend</title>');
		parent.TextFrame.document.writeln('<style type="text/css">a {text-decoration:none;}</style>');
		parent.TextFrame.document.writeln('</head>');
		parent.TextFrame.document.writeln('<body BGCOLOR="White" text="Black" leftmargin=0 topmargin=0 rightmargin=0 link="Black" vlink="Black" alink="Black">');
		parent.TextFrame.document.writeln('<center>');
		parent.TextFrame.document.writeln('<BR>');
		parent.TextFrame.document.writeln('<font face="Tahoma" size="3" color="#003193"><b>Legend</b></font><BR>')
		//parent.TextFrame.document.writeln('<IMG SRC="../' + SiteName + '/images/lineonwhite.gif" HSPACE=0 VSPACE=0 BORDER=0 ALT=""><b>'+'</b>');
		parent.TextFrame.document.writeln('<IMG SRC="'+ legendImageLocation + 'images/lineonwhite.gif" HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
		parent.TextFrame.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="Legend"></center>');
	    
		// Puts in a LINE at the bottom of the Legend
		//parent.TextFrame.document.writeln('<IMG SRC="../' + SiteName + '/images/lineonwhite.gif" HSPACE=0 VSPACE=0 BORDER=0 ALT=""><b>'+'</b>');
		parent.TextFrame.document.writeln('<center><IMG SRC="' + legendImageLocation + 'images/lineonwhite.gif" HSPACE=0 VSPACE=0 BORDER=0 ALT="">'); 
		
		//parent.TextFrame.document.writeln('<br>');
		//parent.TextFrame.document.writeln('<IMG SRC="../' + SiteName + '/images/lineonwhite.gif" HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
		//parent.TextFrame.document.writeln('</head>');
		//parent.TextFrame.document.writeln('<body BGCOLOR="White" text="Black" leftmargin=0 topmargin=0 rightmargin=0 link="Gray" vlink="Gray" alink="Gray" onclose="closeIt()">');
		//parent.TextFrame.document.writeln('<form onsubmit="closeIt(); return false;"><center>');

		//parent.TextFrame.document.writeln('<font face="Arial" size="-2"><b>');

		//parent.TextFrame.document.writeln('<INPUT TYPE="button" NAME="hideButton1" VALUE="' + buttonList[0] + '" onClick="closeIt()">');
		//parent.TextFrame.document.writeln('<hr width="75%">');
		//parent.TextFrame.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="' + titleList[3] + '">');
		//parent.TextFrame.document.writeln('<hr width="75%">');
		//parent.TextFrame.document.writeln('<INPUT TYPE="button" NAME="hideButton2" VALUE="' + buttonList[0] + '" onClick="closeIt()">');
		//parent.TextFrame.document.writeln('</b></font></center></FORM>');
		//
		
		parent.TextFrame.document.writeln('</body></html>');
		parent.TextFrame.document.close();

		//  Modified 11/17/08 - NCA - used different method to find image object for Firefox DOM compatibility
		/*
		parent.RightTools.t_Legend.src = "images/Legend_04.gif"
		parent.RightTools.t_Layers.src = "images/Layers_01.gif"
		*/

		parent.RightTools.document.images["t_Legend"].src = "images/Legend_04.gif";
		parent.RightTools.document.images["t_Layers"].src = "images/Layers_01.gif";
		
		legendVisible=true;

	
}

// add Legend to XML request  
function addLegendToMap() {
	
	//CDM Edit - This is the LEGEND TITLE.  THIS IS WHERE IS GENERATES THE LEGEND
	//var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
	
	//var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
	var legString = '<LEGEND title=" " font="Tahoma" width="' + legWidth + '" height="' + legHeight + '" ';
	legString += 'autoextend="true" backgroundcolor="255,255,255" valuefontsize="9" layerfontsize="9" cellspacing="6" ';
	legString += 'swatchheight="10" swatchwidth="15" ';

	//alert(legString)

	
	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;
}
