/*File: csyPrint.js
** This file was created by Cuesta Systems Inc, June 2004
** It contains print functions used on map load
** Created By: Aida Dodo, Cuesta Systems
** On: June 04, 2004
*/



var t = top.MapFrame;

// print the web page for printing
function csy_writePrintPage() {
	var printMapURL = mapImage;
	//var legVis2 = parent.TextFrame.LgdCheckBox.checked;
	//var logoVis2 = parent.TextFrame.LogoCheck.checked;
	var legVis2 = LgdCheckBox;
	var logoVis2 = true ; 
	var appDir = "";
	var LgdWidth=300;
	var ImgWidth=700;
	
	//var Win1 = open("","PrintPage","width=" + (sWidth*9.5/10) + ",height=" + (sHeight*8/10) + ",top=0,left=0,scrollbars=yes,resizable=yes,menubar=yes");
	//var Win1 = open("","PrintPage","width=10in,height=7.5in,top=0,left=0,scrollbars=yes,resizable=yes,menubar=yes");
	var Win1 = open("","PrintPage","width=900,height=720,top=0,left=0,scrollbars=yes,resizable=yes,menubar=yes");

	Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html"><head>');
	Win1.document.writeln('<LINK rel="stylesheet" type="text/css" href="cuestaStyle.css" />')
	Win1.document.writeln('	<title>MAP OUTPUT</title><script type="text/javascript">function swapImage(widget, newImagePath){widget.src = newImagePath;}</script>');	
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=8 TOPMARGIN=8 halign=center>');
	
	Win1.document.writeln('<TABLE BORDERCOLORLIGHT="#082984" BORDERCOLORDARK="#082984" BORDER="2" NOWRAP style="font: 16pt Arial" >');
	Win1.document.writeln('	<TR>');	

	if (logoVis2) {
		//display the logo
		//AD Oct 22, 2004, used 'title' attribute, instead of 'alt', for netscape compatibility.
		//Win1.document.writeln('		<TD COLSPAN="2"><IMG SRC="' + appDir + 'images/logo.jpg" HSPACE=5 VSPACE=0 BORDER=0 height=50 ALT="Logo" ALIGN="absmiddle">&nbsp;&nbsp;<B>' + PrintTitle + '</B><BR>');
		Win1.document.writeln('		<TD COLSPAN="2"><IMG SRC="' + appDir + 'images/logo.jpg" HSPACE=0 VSPACE=0 BORDER=0 TITLE="Logo" ALIGN="absmiddle">&nbsp;&nbsp;<B>' + PrintTitle + '</B><BR>');
		if (PrintSubTitle != "")
		{   Win1.document.writeln('		<center><span style="font-size:12.0pt;font-family:Tahoma"><B>' + PrintSubTitle + '</B></span></center><BR></TD>');}
		else { Win1.document.writeln('</TD>'); }
	}

	else
	
	{
		// no logo
		Win1.document.writeln('		<TD COLSPAN="2" align=center><B>' + PrintTitle + '</B><BR>');
		if (PrintSubTitle != "")
		{   Win1.document.writeln('		<span style="font-size:12.0pt;font-family:Tahoma"><B>' + PrintSubTitle + '</B><BR></TD>');}
		else { Win1.document.writeln('</TD>'); }
	}
	
	if (legVis2){
		Win1.document.writeln('	</TR>');
		Win1.document.writeln('	<TR>');
		Win1.document.writeln('		<TD valign=top>');
		Win1.document.writeln('			<IMG width=' + ImgWidth + ' SRC="' + printMapURL + '">');
		Win1.document.writeln('		</TD>');

		Win1.document.writeln('		<TD valign=top width=' + LgdWidth + '><div style=\'height: 500px; overflow: auto;\'>');
		Win1.document.writeln(csy_createLegendStr());
		Win1.document.writeln('		</div></TD>');
	}

	else
	
	{
		Win1.document.writeln('	</TR>');
		Win1.document.writeln('	<TR>');
		Win1.document.writeln('		<TD valign=top>');
		Win1.document.writeln('			<IMG width=' + (ImgWidth+LgdWidth) + ' SRC="' + printMapURL + '">');
		Win1.document.writeln('		</TD>');

		Win1.document.writeln('		<TD valign=top>');
		Win1.document.writeln('         &nbsp');
		Win1.document.writeln('		</TD>');
	}
	
	
	Win1.document.writeln('	</TR>');

	if (MapNotes!=""){
		Win1.document.writeln('	<TR>');
		Win1.document.writeln('		<TD colspan=2 ><font face="Tahoma" size=2>' + MapNotes + '</font>');
		Win1.document.writeln('		</TD>');
		Win1.document.writeln('	</TR>');
	}

	
	Win1.document.writeln('</TABLE>');
	
	//Win1.document.writeln('</B></FONT><input type="button" class="doNotPrint" onclick="window.close();" value="Close" />');
	Win1.document.writeln('</B><input id="Close"  type="image" name="Close" class="doNotPrint" src="../NTGO_images/close.gif" value=" Cancel " title="Close" onclick="window.close();"  onMouseOver="swapImage(this,\'NTGO_images/close-over.gif\')" onMouseOut="swapImage(this,\'NTGO_images/CLOSE.gif\')" />');
	//Win1.document.writeln('</body></html>');
	Win1.document.close();
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}


function csy_createLegendStr()
{
	var strTemp="";
	var theCount = t.layerCount;			
	
	for (var i=0;i<theCount;i++) {
	   if (t.loadedLayers[i]==1)
	   {
		//legend
		var strLeg = t.LayerLegendArray[i].split("*");
		var strLegName = t.LayerLegendNameArray[i].split("*");



		if (strLeg.length == 1)
		//legend icon if the layer has only one class
		{
			strTemp += "<span style=font-size:10.0pt;font-family:Tahoma>";
			strConnection = LayerConnectionName[i];
			var connType = getXMLValue("config/connections.xml","type", strConnection);
			var strDriver = getXMLValue("config/connections.xml","driver", strConnection);
			if(connType.toLowerCase() != "wms")
				strTemp += strLeg[0] + "&nbsp;" + LayerName[i] + '</span><br>';
			else
				strTemp += '<IMG id="imgUTMZones" src="' + strDriver + '&SERVICE=WMS&VERSION=1.1.1&REQUEST=getlegendgraphic&LAYER=' + t.LayerName[i] + '&FORMAT=image/png"/></span><br>';
		}

		else if (strLeg.length > 1)
		//legend icon if the layer has more than one class
		{
			strTemp += "<span style=font-size:10.0pt;font-family:Tahoma>&nbsp;&nbsp;&nbsp;" + LayerName[i] + "</span><br>";
			strConnection = LayerConnectionName[i];
			var connType = getXMLValue("config/connections.xml","type", strConnection);
			var strDriver = getXMLValue("config/connections.xml","driver", strConnection);
			if(connType.toLowerCase() != "wms")
			{
				for (var k=0;k<strLeg.length;k++)
				{
					strTemp += "<span style=font-size:9.0pt;font-family:Tahoma>";
					strTemp += strLeg[k] + "&nbsp;" + strLegName[k] + '</span><br>';
				}
			}
			else
				strTemp += '<IMG id="imgUTMZones" src="' + strDriver + '&SERVICE=WMS&VERSION=1.1.1&REQUEST=getlegendgraphic&LAYER=' + t.LayerName[i] + '&FORMAT=image/png"/></span><br>';
		}
		//legend
	   }//if loaded
	}//for
	return strTemp;
}



//***************************************************************************
//** CUSTOM PRINTING
//** function csy_openWordTemplate
//** open the MS Word template and display the map+legend+ov map images
//** Created By: Monica Socol, september 2004
//** Modified By: 
//*/
function csy_openWordTemplate() {
	//alert("in openwordtemplate the document = " + CustomPrintDocName);

	var word = new ActiveXObject('Word.Application');
	var thisdocument = word.Documents.Open(CustomPrintDocName);
	word.visible = true;
	word.Run('callLoadAll'); //word 97 does not allow parameters to be passed to a macro
	
	//word 2000 allows parameters to be passed to a macro
	//if (theLayout == "Current_Map_Window") {
		//word.Run('LoadAll', CustomPrintMapImageName, CustomPrintLegendImageName); 
	//} else {
		//word.Run('LoadAll', CustomPrintMapImageName, CustomPrintOVImageName);
	//}
}
//***************************************************************************
