// 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;
var onload=0;
var loaded=false;
var watLive=false;
var stoLive=false;
var sanLive=false;
var allLive=false;
var conLive=false;
var plaLive=false;
/*
***************************************************************************************

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() {
	hasTOC = false;
	if (hasTOC) {
		parent.LegendFrame.document.open();
		parent.LegendFrame.document.writeln('<html><head><title>Legend</title>');
		parent.LegendFrame.document.writeln('<style type="text/css">a {text-decoration:none;}</style>');
		parent.LegendFrame.document.writeln('<script language="Javascript">');
		parent.LegendFrame.document.writeln('parent.EnvelopeSide.envside()');
		parent.LegendFrame.document.writeln('parent.EnvelopeBottom.envbottom()');
		parent.LegendFrame.document.writeln('</SCRIPT>');
		parent.LegendFrame.document.writeln('</head>');
		parent.LegendFrame.document.writeln('<body bgcolor=White text="Black" leftmargin=0 topmargin=0 rightmargin=0 link="Red" vlink="Red" alink="Red">');
		parent.LegendFrame.document.writeln('<center>');
		parent.LegendFrame.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="Legend"></center>');
		parent.LegendFrame.document.writeln('</body></html>');
		parent.LegendFrame.document.close();
	} else {
		var Win1 = open("","LegendWindow","width=190,height=300,scrollbars=yes,resizable=yes");
		Win1.document.writeln('<html><head><title>Legend</title>');
		Win1.document.writeln('<style type="text/css">a {text-decoration:none;}</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="Gray" vlink="Gray" alink="Gray" onclose="closeIt()">');
		Win1.document.writeln('<form onsubmit="closeIt(); return false;"><center>');

		Win1.document.writeln('<font face="Arial" size="-2"><b>');

		Win1.document.writeln('<INPUT TYPE="button" NAME="hideButton1" VALUE="Hide Legend" onClick="closeIt()">');
		Win1.document.writeln('<hr width="75%">');
		Win1.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="Legend">');
		Win1.document.writeln('<hr width="75%">');
		Win1.document.writeln('<INPUT TYPE="button" NAME="hideButton2" VALUE="Hide Legend" onClick="closeIt()">');
		Win1.document.writeln('</b></font></center></FORM>');
		Win1.document.writeln('</body></html>');
		Win1.document.close();
		Win1.focus();
		Win1=null;
	}
	hasTOC = true;

}

// add Legend to XML request
function addLegendToMap() {
	var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
	legString += 'autoextend="true" transcolor="255,255,255" />\n';
	if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
	return legString;
}

function addLegendToMapL() {
	var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
	if (pagesize=="A"){
	legString += 'swatchheight="14" swatchwidth="18" layerfontsize="10" valuefontsize="10" titlefontsize="12" cellspacing="1" ';
	} else if (pagesize=="B") {
	legString += 'swatchheight="16" swatchwidth="20" layerfontsize="12" valuefontsize="12" titlefontsize="12" cellspacing="1" ';
	} else if (pagesize=="C") {
	legString += 'swatchheight="16" swatchwidth="20" layerfontsize="14" valuefontsize="14" titlefontsize="14" cellspacing="1" ';
	} else if (pagesize=="D") {
	legString += 'swatchheight="18" swatchwidth="22" layerfontsize="16" valuefontsize="16" titlefontsize="16" cellspacing="1" ';
	} else if (pagesize=="E") {
	legString += 'swatchheight="20" swatchwidth="24" layerfontsize="18" valuefontsize="18" titlefontsize="18" cellspacing="2" ';
	}
	legString += 'autoextend="false" transcolor="255,255,255" />\n';
	if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
	return legString;
}


function addLegendToMapP() {
	var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" columns="2" ';

	if (pagesize=="A"){
	legString += 'swatchheight="14" swatchwidth="18" layerfontsize="10" valuefontsize="10" titlefontsize="12" cellspacing="1" ';
	} else if (pagesize=="B") {
	legString += 'swatchheight="16" swatchwidth="20" layerfontsize="12" valuefontsize="12" titlefontsize="12" cellspacing="1" ';
	} else if (pagesize=="C") {
	legString += 'swatchheight="16" swatchwidth="20" layerfontsize="14" valuefontsize="14" titlefontsize="14" cellspacing="1" ';
	} else if (pagesize=="D") {
	legString += 'swatchheight="18" swatchwidth="22" layerfontsize="16" valuefontsize="16" titlefontsize="16" cellspacing="1" ';
	} else if (pagesize=="E") {
	legString += 'swatchheight="20" swatchwidth="24" layerfontsize="18" valuefontsize="18" titlefontsize="18" cellspacing="2" ';
	}
	legString += 'autoextend="true" transcolor="255,255,255" />\n';
	if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
	return legString;
}

