// 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 

***************************************************************************************
*/

function getMyLayers(){

	var Win1 = open("/website/broome/public/transitinfo/toc.htm","LegendLayersWindow","width=225,height=450,scrollbars=yes,resizable=yes");
	}
	

// 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() {
	
	if (hasTOC) {
		parent.TOCFrame.document.open();
		parent.TOCFrame.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head><title>' + titleList[3] + '</title>');
		parent.TOCFrame.document.writeln('<style type="text/css">a {text-decoration:none;}</style>');
		parent.TOCFrame.document.writeln('</head>');
		parent.TOCFrame.document.writeln('<body BGCOLOR="White" text="Black" leftmargin=0 topmargin=0 rightmargin=0 link="Black" vlink="Black" alink="Black">');
		parent.TOCFrame.document.writeln('<center>');
		parent.TOCFrame.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="' + titleList[3] + '"></center>');

		parent.TOCFrame.document.writeln('</body></html>');
		parent.TOCFrame.document.close();
	} else {
		var Win1 = open("","LegendLayersWindow","width=225,height=450,scrollbars=yes,resizable=yes");
		Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head><title>' + titleList[3] + '</title>');
		Win1.document.writeln('<style type="text/css">a {text-decoration:underline;}</style>');
		Win1.document.writeln('<script language="Javascript">');
		Win1.document.writeln('	var t;');
		Win1.document.writeln('	var tName = "";');
		Win1.document.writeln('	if (opener) {');
		Win1.document.writeln('		if (opener.name=="MapFrame") {');
		Win1.document.writeln('			t = opener.parent.MapFrame;');
		Win1.document.writeln('			tName = "opener.parent.MapFrame.";');
		Win1.document.writeln('		} else {');
		Win1.document.writeln('			t = opener;');
		Win1.document.writeln('			tName = "opener.";');
		Win1.document.writeln('		}');
		Win1.document.writeln('	} else {');
				
		Win1.document.writeln('		if (parent.MapFrame!=null) {');
		Win1.document.writeln('			t = parent.MapFrame;');
		Win1.document.writeln('			tName = "parent.MapFrame.";');
		Win1.document.writeln('		} else {');
		Win1.document.writeln('			t=document;');
		Win1.document.writeln('		}');
		Win1.document.writeln('	}');
		Win1.document.writeln(' function closeIt() {');
		Win1.document.writeln('		t.legendVisible=false;');
		Win1.document.writeln('		window.close();');
		Win1.document.writeln('	}');
		Win1.document.writeln('</script>');
		Win1.document.writeln('</head>');
		Win1.document.writeln('<body BGCOLOR="White" text="Black" leftmargin=0 topmargin=0 rightmargin=0 link="red" vlink="red" alink="red" onclose="closeIt()">');
		Win1.document.writeln('<form onsubmit="closeIt(); return false;"><center>');

		Win1.document.writeln('<font face="Arial" size="-2">');

		//Win1.document.writeln('<INPUT TYPE="button" NAME="hideButton1" VALUE="' + buttonList[0] + '" onClick="closeIt()">');
		
		
		Win1.document.writeln('<hr width="75%">');
		Win1.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="' + titleList[3] + '">');
		Win1.document.writeln('<hr width="75%">');
		

		//Win1.document.writeln('<INPUT TYPE="button" NAME="hideButton2" VALUE="Show Layers List" onClick=javascript:self.document.location=href="/website/broome/transitinfo/toc.htm"> ');
		Win1.document.writeln('<a href="#" onClick=javascript:self.document.location=href="/website/broome/public/transitinfo/toc.htm"><font face="times" size="2">Show Layers List</font></a><br>');
		
		Win1.document.writeln('<HR WIDTH="75%">');
		//Win1.document.writeln('<HR WIDTH=75%>');
		Win1.document.writeln('<a href="#" onClick="closeIt()"><font face="times" size="2">Close Legend</font></a><br>');
		
		Win1.document.writeln('<HR WIDTH="75%">');


		Win1.document.writeln('</font></center></FORM>');
		Win1.document.writeln('</body></html>');
		Win1.document.close();
		Win1.focus();
		Win1=null;
	}

	//}
	
}
////////////////////////////////////////////////////
// add Legend to XML request
//function addLegendToMap() {
//	var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
//	legString += 'autoextend="true" backgroundcolor="255,255,255"';
	
//		legString += '>\n<LAYERS>\n';

//		for (var legvar=0;legvar<layerCount;legvar++) {
//			if (LayerIsFeature[legvar]) {
//			} else { 
//			legString += '<LAYER id="' + LayerID[legvar] + '" />\n';
//			}
//		}
//		legString += '</LAYERS>\n';
//		legString += '</LEGEND>\n';

//	if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
//	return legString;
//}
///////////////////////////////////////////////////////

// add Legend to XML request
function addLegendToMap() {
	var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
	legString += 'autoextend="true" backgroundcolor="255,255,255"';
	if (useAir==1) {
		legString += '>\n<LAYERS>\n';
		for (var legvar=0;legvar<dynaImageFilenameArray.length;legvar++) {
			if (dynaImageFilenameArray[legvar]) legString += '<LAYER id="' + (legvar+61) + '" />\n';
		}
		legString += '</LAYERS>\n';
		legString += '</LEGEND>\n';
	} else {
		legString += ' />\n';
	}
	if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
	return legString;
}

