// aimsLegend.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js
*/

aimsLegendPresent=true;

var drawLegendOnly=false;
var defaultLegTitle=legTitle;

/*
***************************************************************************************

Legend functions 

***************************************************************************************
*/



// send request to create graphic legend
function getLegend() {
	//TW 07/09/01
	/*
	legendVisible=true;
	drawLegendOnly=true;
	var theString=writeXML();
	showRetrieveMap();
	sendToServer(imsURL,theString,98);
	*/
	legendVisible=true;
	drawLegendOnly=true;
	var theString=writeXML();
	showRetrieveMap();
		// if the options to show images are all unchecked then
		// ask the server for the default (main) map image
		if (Image1Check == "unchecked" && Image2Check == "unchecked" && Image3Check == "unchecked")	
	{
		//alert(imsURL + "aimsLegend line 40")
  //alert(theString  + "aimsLegend line 41")
		sendToServer(imsURL,theString,98);
	}else{
		if (Image1Check == "checked"){
			// if image1Check is "checked" then
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage1URL ,theString,98);
		}else if (Image2Check =="checked"){
			// if image2 check is "checked" then
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage2URL ,theString,98);
		}else{
			// otherwise, image 3 is "checked" and
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage3URL ,theString,98);
		}
	}	
}

// write out the legend display
function showLegend() {
	if (showTOC){	
//	if (hasTOC) {
		parent.TextFrame.document.open();
		parent.TextFrame.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head><title>' + titleList[3] + '</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">');
		//TW 07/09/01
		//parent.TOCFrame.document.writeln('<center>');
		//parent.TOCFrame.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="' + titleList[3] + '"></center>');
		parent.TextFrame.document.writeln('<FONT style="font: 11pt Tahoma"><center><B>Legend</center></B>	');	
		parent.TextFrame.document.writeln('<HR size="3" width=100% align="left">');

		parent.TextFrame.document.writeln('<center>');
		parent.TextFrame.document.writeln('<input type="submit" name="LayerList" value="Layer List">');
		parent.TextFrame.document.writeln('</center>');
		
		parent.TextFrame.document.writeln('<script language=vbscript>');
		parent.TextFrame.document.writeln('LayerList.style.backgroundColor="RGB(0,0,153)"');
		parent.TextFrame.document.writeln('LayerList.style.color="RGB(239,189,16)"');
		parent.TextFrame.document.writeln('LayerList.style.fontSize="8pt"');
		parent.TextFrame.document.writeln('LayerList.style.fontFamily="Tahoma"');
		parent.TextFrame.document.writeln('LayerList.style.fontWeight="bold"');
		parent.TextFrame.document.writeln('</script>');
		parent.TextFrame.document.writeln('<font style="font: 4pt Tahoma"><BR></font>');

//		parent.TextFrame.document.writeln("<Table width=100% style='font: 9pt Tahoma'>");
//		parent.TextFrame.document.writeln('<TD align=left><A href=javascript:parent.MapFrame.clickFunction("layerlist") target="TextFrame"><B>Layer List</B></A>');
//		parent.TextFrame.document.writeln('<TD align=right><A href=javascript:parent.MapFrame.clickFunction("legend") target="TextFrame"><B>Legend</B></A>');
//		parent.TextFrame.document.writeln('</TAble>');

		parent.TextFrame.document.writeln('<center>');
		parent.TextFrame.document.writeln('<TABLE  BORDER=3 BORDERCOLORLIGHT="#082984" BORDERCOLORDARK="#082984">');
		parent.TextFrame.document.writeln('<TD>');
		parent.TextFrame.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="Legend"></center>');
		parent.TextFrame.document.writeln('</TD></TABLE>');
		parent.TextFrame.document.writeln('</center>');
		//TW mouse events for layerlist button
		parent.TextFrame.document.writeln('<script language="vbscript">');

		parent.TextFrame.document.writeln('sub LayerList_OnMouseOver()');
		parent.TextFrame.document.writeln('LayerList.style.backgroundcolor="RGB(239,189,16)"');
		parent.TextFrame.document.writeln('LayerList.style.color="RGB(0,0,153)"');
		parent.TextFrame.document.writeln('end sub');
		parent.TextFrame.document.writeln('sub LayerList_OnMouseOut()');
		parent.TextFrame.document.writeln('LayerList.style.backgroundColor="RGB(0,0,153)"');
		parent.TextFrame.document.writeln('LayerList.style.color="RGB(239,189,16)"');
		parent.TextFrame.document.writeln('end sub');
		parent.TextFrame.document.writeln('sub LayerList_OnClick()');
		parent.TextFrame.document.writeln('top.frames("TextFrame").document.location="' + WebServerPath + appDir + '/toc.htm"');
		parent.TextFrame.document.writeln('end sub');
		parent.TextFrame.document.writeln('</script>');
		
		parent.TextFrame.document.writeln('</body></html>');
		parent.TextFrame.document.close();		
	} 	
}

// add Legend to XML request
function addLegendToMap() {
	var SuppressFromLegend=false;

	var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
	legString += 'autoextend="true" backgroundcolor="180,180,180"';
	if (hideLayersFromList) {
		legString += '>\n<LAYERS>\n';
		
		//TW change evaluation for adding Layers to Legend
		for (var legvar=0;legvar<LayerName.length;legvar++) {		
			SuppressFromLegend=false;
			for (var NoList=0;NoList<noListLayer.length;NoList++){
				if (LayerName[legvar] == noListLayer[NoList]) {
					SuppressFromLegend=true;
					NoList=noListLayer.length;
				}else{
					SuppressFromLegend=false;
				}
			}
			if(SuppressFromLegend) legString += '<LAYER id="' + LayerID[legvar] + '" />\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;
}
