// 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 printDPI = 300;		// Hannah Added: printer DPI--may be overridden by print form
var printHeight = 450;	// Hannah Added: default print dimensions
var printWidth = 450;	// Hannah Added

aimsPrintPresent=true;

var printTitle = titleList[4];
var printMapURL="";
var printOVURL="";
var printLegURL="";

var legVis2=false;

/*
***************************************************************************************

Print functions 

***************************************************************************************
*/


// display print form
function printIt() {
	hideLayer("measureBox");
	if (useTextFrame) {
		parent.TextFrame.document.location = "printform.htm";
	} else {
		var Win1 = open("printform.htm","PrintFormWindow","width=575,height=150,scrollbars=yes,resizable=yes");
	}
}

// create web page for printing
	// first get Map
function getPrintMap(title, w, h) {
	showRetrieveMap();
	printTitle=title;
	//var tempWidth = iWidth;
	//var tempHeight = iHeight;
	//iWidth=450;
	//iHeight=450;
	legVis2=legendVisible;
	if (aimsLegendPresent) legendVisible=true;
	// Hannah Added: set print size to input values
	if (w != "") printWidth = parseInt(w);	
	if (h != "") printHeight = parseInt(h);
	// Hannah Added: set XMLMode so get print res.
	XMLMode = 101;
	// Hannah Added: enlarge legend in proportion to map
	var tempLegW = legWidth;
	var tempLegH = legHeight;
	legWidth = parseInt(printWidth/4);
	legHeight = parseInt(printWidth/3);
	// Hannah Added
	var theString = writeXML(crimeSQL);
	legWidth = tempLegW;	// Hannah Added: restore default leg vars
	legHeight = tempLegH;	// Hannah Added
	//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;
	i2Width=parseInt(printWidth/4);		// Hannah Added: scale to print 
	i2Height=parseInt(printHeight/4);	// Hannah Added: scale to print
	var tempDraw=drawOVExtentBox;
	drawOVExtentBox=true;
	XMLMode = 102;
	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");
	Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
	Win1.document.writeln('	<title>' + titleList[5] + '</title>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
	Win1.document.writeln('<FONT FACE="Arial"><STRONG>');
	Win1.document.writeln('<TABLE BORDER="2" CELLSPACING="0" CELLPADDING="0" NOWRAP>'); //Hannah Added: omit width
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TH COLSPAN="2" style="font-size:' + parseInt(printWidth/20) + 'px">' + printTitle + '</TH>');	// Hannah Added: scale title
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');
	Win1.document.write('		<TD');
	if (hasOVMap) Win1.document.write(' ROWSPAN="2"');
	Win1.document.writeln('>');
	Win1.document.writeln('			<IMG SRC="' + printMapURL + '" WIDTH=' + printWidth + ' HEIGHT=' + printHeight + ' HSPACE=0 VSPACE=0 BORDER=0 ALT="Main map">'); //BB: set size
	Win1.document.writeln('		</TD>');
	if (hasOVMap) {
		Win1.document.writeln('		<TD height="' + parseInt(printHeight/4) + '" valign="top">'); //BB: set size
		Win1.document.writeln('			<IMG SRC="' + printOVURL + '" WIDTH=' + parseInt(printWidth/4) + ' HEIGHT=' + parseInt(printHeight/4) + ' HSPACE=0 VSPACE=0 BORDER=0 ALT="Overview">'); // BB: set size
		Win1.document.writeln('		</TD>');
	}
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TD ALIGN="CENTER" VALIGN="TOP">');
	Win1.document.write('         <span style="font-size:' + parseInt(printWidth/40) + 'px">');
	Win1.document.writeln(legTitle + '</span><br><br> '); // BB: add Legend title, set size
	Win1.document.write('			<IMG SRC="' + printLegURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="Legend"');
	Win1.document.writeln(' width="' + parseInt(printWidth/4) + '" >'); // BB: set size
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('<TR><TD COLSPAN="2" VALIGN="top">');
	Win1.document.writeln('<FONT FACE="Arial" SIZE="1">');
	Win1.document.writeln('Disclaimer Statement<BR>');
	Win1.document.writeln('The information contained herein is believed to be true and correct however, it is not warranted or certified for accuracy.');
	Win1.document.writeln('The City shall not be liable for errors contained herein or for incidental consequential damages in connection with the use of this material.');
	Win1.document.writeln('Any use or re-use of this information will be at the risk of the user.');
	Win1.document.writeln('</FONT></TD>');
	Win1.document.writeln('</TR>');
	
	if (printPatchContent != "") {
		Win1.document.writeln(' <TR><TD COLSPAN="2" ALIGN="CENTER">');
		Win1.document.writeln( printPatchContent );
		Win1.document.writeln(' </TD></TR></TABLE>');
        }

	Win1.document.writeln('</TABLE>');
	Win1.document.writeln('</STRONG></FONT>');
	Win1.document.writeln('</body></html>');
	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}