// aimsPrint.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js,
*		aimsLayers.js, aimsDHTML.js
*		aimsClick.js, aimsNavigation.js,
*		aimsLegend.js
*/

aimsPrintPresent=true;

var printTitle = titleList[4];
var printMapURL="";
var printOVURL="";
var printLegURL="";

var legVis2=false;

/*
***************************************************************************************

Print functions 

***************************************************************************************
*/


// display print form
function printIt() 
{
		hideLayer("measureBox");
		var Win1 = open("PrintFormat.htm","PrintFormWindow","width=600,height=400,scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no");
}

// create web page for printing
	// first get Map
function getPrintMap() {
	showRetrieveMap();
	
	//North Arrow
	var	tempNorthArrowType=NorthArrowType;
	var tempNorthArrowCoords=NorthArrowCoords;
	var tempNorthArrowSize=NorthArrowSize;

	
	//iWidth=PrintMapWidthPxs;
	//iHeight=PrintMapHeightPxs;
	
	NorthArrowType=printArrowType;
	NorthArrowCoords=printArrowCoords;
	NorthArrowSize=printArrowSize;

	//Assign original extents to dummy variables
	var tmpLeft = eLeft;
	var tmpTop  = eTop
	var tmpBottom = eBottom;
	var tmpRight  = eRight;
	
	//Now Assign print extents to original extents
	eLeft  = printLeft;
	eTop   = printTop;
	eRight = printRight;
    eBottom= printBottom;
	
	legVis2=legendVisible;
	if (aimsLegendPresent) 
			legendVisible=true;

	//Prepare Map XML	
	var theString = writeXML();
	
	//Restore Values
	NorthArrowType=tempNorthArrowType;
	NorthArrowCoords=tempNorthArrowCoords;
	NorthArrowSize=tempNorthArrowSize;

	eLeft  = tmpLeft;
	eTop   = tmpTop;
	eRight = tmpBottom;
    eBottom= tmpRight;

	legendVisible = legVis2;
	sendToServer(imsURL,theString,101);
	
	//Clear Temp Variables
	theString=null;
	tempNorthArrowType=null;
	tempNorthArrowCoords=null;
	tempNorthArrowSize=null;
}

// second, get OVMap
function getPrintOV() {
	var tempWidth = i2Width;
	var tempHeight = i2Height;
	i2Width=190;
	i2Height=150;
	var tempDraw=drawOVExtentBox;
	drawOVExtentBox=true;
	var theString = writeOVXML();
	drawOVExtentBox=tempDraw;
	i2Width=tempWidth;
	i2Height = tempHeight;
	sendToServer(imsOVURL,theString,102);
	tempWidth=null;
	tempHeight=null;
	theString=null;
}
// third, get Legend
function getPrintLegend() {
	//  waiting for Legend tags
	if (printLegURL=="") printLegURL = "images/nolegend.gif";
	writePrintPage();
}




// fourth, write the web page
function writePrintPage() {
	
	var Win1 = open("","PrintPage",'menubar=yes,toolbar=no,width=700,height=500,scrollbars=yes,resizable=yes,status=no,dependent=yes');
	
	//Win1.document.open();
	Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
	Win1.document.writeln('<title>PrintMap</title>');
	Win1.document.writeln('</head>');
	
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
	Win1.document.writeln('<TABLE WIDTH="500" BORDER="2" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TH COLSPAN="3"><DIV ALIGN="CENTER"><FONT FACE="ARIAL" SIZE="3"></FONT>' + ArgoMapTitle + '<BR> <FONT FACE="ARIAL" SIZE="2">' + ArgoMapSubTitle + '</FONT></DIV></TH>');
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR COLSPAN="3">');
	Win1.document.writeln('		<TD WIDTH="450" HEIGHT="450" COLSPAN="3">');
	Win1.document.writeln('			<IMG SRC="' + printMapURL + '" WIDTH="'+iWidth +'" HEIGHT="'+ iHeight +'" HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');

	//Print Footer Information 
	Win1.document.writeln('	<TR CLASS="ord_row_1024" COLSPAN="3" HEIGHT="10"> ');

	Win1.document.writeln('		<TD ALIGN="CENTER" VALIGN="TOP">');
	Win1.document.writeln('			<TABLE>');	
	Win1.document.writeln('	<TR ><TD COLSPAN="2"><table width="100%" border="0"><tr>'); 
    Win1.document.writeln(' <td width="15%"><STRONG><FONT FACE="ARIAL" SIZE="1">LEGEND</FONT></STRONG>');
	Win1.document.writeln('<p><img src="'+ FuturehtHostName +'/images/webdesign/legend.gif"></TD></TR>');
				//for(i=0;i<noListLayer.length;i++)
				//{
				//		if(noListLayer[i]==false && LayerVisible[i]==true &&(mapScaleFactor>=LayerMinScale[i] && mapScaleFactor<=LayerMaxScale[i]))
				//		{
				//				Win1.document.writeln('	<TR><TD>');	
				//				Win1.document.writeln(LayerName[i]);
					//			Win1.document.writeln('</TD>');

						//		Win1.document.writeln('<TD>');							
					//			Win1.document.writeln('<IMG SRC="'+ pfzHostName +'/images/webdesign/'+ pfzSymbols[i] +'" HSPACE=0 VSPACE=0 BORDER=0 ALT="" WIDTH="10" HEIGHT="10"><BR>')
					//			Win1.document.writeln('</TD></TR>');
					//	}
				//}
						
	Win1.document.writeln('			</TABLE>');	
	Win1.document.writeln('		</TD>');	

	//Print Footer Information
    Win1.document.writeln('	<TD ALIGN="CENTER" VALIGN="TOP"> </td>');
	Win1.document.writeln('		<td width="85%">');
	Win1.document.writeln('			<FONT FACE="ARIAL" SIZE="1"> ');
	Win1.document.writeln(			Footer[0] + '<BR>' + Footer[1] + '<BR>' + Footer[2] + '<BR>' + Footer[3] + '<BR>' + Footer[4] + '</FONT>');
	Win1.document.writeln('		</FONT>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln(' </tr></table></TD>');

	//Print Incois Logo
	Win1.document.writeln('		<TD ALIGN="CENTER" VALIGN="TOP">');
		Win1.document.writeln('				<IMG SRC="'+ imgIncoisLogoURL +'" >');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	
	Win1.document.writeln('</TABLE>');
	Win1.document.writeln('</td></tr></table>');
	Win1.document.writeln('</body></html>');
	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}