// 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
*/

var aimsPrintPresent=true;

var printTitle = "ArcIMS 3.0 HTML Viewer Map";
var printMapURL="";
var printOVURL="";
var printLegURL="";

var legVis2=false;
var printWidth = 0;
var printHeight = 0;
/*
***************************************************************************************

Print functions 

***************************************************************************************
*/

// create web page for printing
// first get Map
function getPrintMap(title,pWidth,pHeight,quality)  {
	showRetrieveMap();
	printTitle=title;
	var tempWidth = iWidth;
	var tempHeight = iHeight;
	printWidth = pWidth;
    printHeight = pHeight;

	iWidth = Math.floor(parseFloat(printWidth) * quality);
	iHeight = Math.floor(parseFloat(printHeight) * quality);

	legVis2=legendVisible;
	if (aimsLegendPresent) legendVisible=true;
	var theString = writeXML();
	iWidth=tempWidth;
	iHeight = tempHeight;
	legendVisible = legVis2;
	sendToServer(imsURL,theString,101);
	tempWidth=null;
	tempHeight=null;
	theString=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 mWidth = parent.MapFrame.getMapWidth();
	var mHeight = parent.MapFrame.getMapHeight();

	var WinPrint = open("","PrintWindow");
	WinPrint.document.writeln('<html><head>');
	WinPrint.document.writeln('	<title>Plan for identification purposes only; not to be used for scaling or formal documentation</title>');
	WinPrint.document.writeln('</head>');
	WinPrint.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
	WinPrint.document.writeln('<FONT FACE="Arial"><B>');
	WinPrint.document.writeln('<TABLE WIDTH=' + mWidth + ' BORDER="2" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
	WinPrint.document.writeln('	<TR>');
	WinPrint.document.writeln('		<TH COLSPAN="1">' + printTitle + '</TH>');
	WinPrint.document.writeln('	</TR>');
	WinPrint.document.writeln('	<TR>');
	WinPrint.document.write('		<TD WIDTH="'+printWidth+'" HEIGHT="'+printHeight+'"');	
	if (hasOVMap) Win1.document.write(' ROWSPAN="1"');
	WinPrint.document.writeln('>');
	WinPrint.document.writeln('				<IMG SRC="' +printMapURL + '" WIDTH="'+printWidth+'" HEIGHT="'+printHeight+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="">'); 
	WinPrint.document.writeln('		</TD>');

	if (hasOVMap) {
		WinPrint.document.writeln('		<TD HEIGHT="150" ALIGN="CENTER">');
	
		WinPrint.document.writeln('			<IMG SRC="' + printOVURL + '" WIDTH=190 HEIGHT=150 HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
						
	WinPrint.document.writeln('		</TD>');
	}
	WinPrint.document.writeln('	</TR>');
	
	WinPrint.document.writeln('</TABLE>');
	WinPrint.document.writeln('</B></FONT>');
	WinPrint.document.close();
	
	legendVisible=legVis2;
	WinPrint=null;
	hideRetrieveMap();
}
