// 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;

//TW 07/09/01
//var printTitle = titleList[4];
var printMapURL="";
var printOVURL="";
var printLegURL="";
var printsize="";

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, pagesize) {
	showRetrieveMap();
	printTitle=title;
	printsize = pagesize;
	var tempWidth = iWidth;
	var tempHeight = iHeight;
	//TW 07/09/01
	iWidth=755;
	iHeight=550;
	//iWidth=450;
	//iHeight=450;
	legVis2=legendVisible;
	printsize == "large"
	
	//TW 07/09/01
	/*
	if (aimsLegendPresent) legendVisible=true;
	var theString = writeXML();
	iWidth=tempWidth;
	iHeight = tempHeight;
	legendVisible = legVis2;
	sendToServer(imsURL,theString,101);
	*/
	//TW add code to use the correct IMS Map Service
		// if the options to show images are all unchecked then
		// ask the server for the default (main) map image
	if (Image1Check == "unchecked" && Image2Check == "unchecked" && Image3Check == "unchecked")	
	{
		sendToServer(imsURL,theString,101);
	}
	else
	{
		if (Image1Check == "checked"){
			// if image1Check is "checked" then
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage1URL,theString,101);
		}else if (Image2Check =="checked"){
			// if image2 check is "checked" then
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage2URL,theString,101);
		}else{
			// otherwise, image 3 is "checked" and
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage3URL,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();
}

//TW 07/09/01
function CheckForLegend() {
	showRetrieveMap();
	
	showRetrieveMap();
	PrintPage ="true";	
	
	//var theString=writeXML();
		// if the options to show images are all unchecked then
		// ask the server for the default (main) map image
		if (Image1Check == "unchecked" && Image2Check == "unchecked" && Image3Check == "unchecked")	
	{
		sendToServer(imsURL,CurrentXML,98);
	}else{
		if (Image1Check == "checked"){
			// if image1Check is "checked" then
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage1URL ,CurrentXML,98);
		}else if (Image2Check =="checked"){
			// if image2 check is "checked" then
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage2URL ,CurrentXML,98);
		}else{
			// otherwise, image 3 is "checked" and
			// ask the sever for the corresponding image backdrop map service
			sendToServer(imsImage3URL ,CurrentXML,98);
		}
	}
}	

// fourth, write the web page
function writePrintPage() {

	//TW 07/09/01
	var Win1 = open("","PrintPage","width=700,height=700,top=0,left=0,scrollbars=no,resizable=yes,menubar=yes");
	//var Win1 = open("","PrintPage");
	//Win1.document.open();
	Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
	Win1.document.writeln('	<title>GIS Locator Print Previewo</title>');
	//Win1.document.writeln('	<title>' + titleList[5] + '</title>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0 halign=center>');
	//TW 07/09/01
	/*
	Win1.document.writeln('<FONT FACE="Arial"><B>');
	Win1.document.writeln('<TABLE WIDTH="650" BORDER="2" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TH COLSPAN="2">' + printTitle + '</TH>');
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');
	Win1.document.write('		<TD WIDTH="450" HEIGHT="450"');
	if (parent.hasOVMap) Win1.document.write(' ROWSPAN="2"');
	Win1.document.writeln('>');
	Win1.document.writeln('			<IMG SRC="' + printMapURL + '" WIDTH=450 HEIGHT=450 HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
	Win1.document.writeln('		</TD>');
	if (parent.hasOVMap) {
		Win1.document.writeln('		<TD HEIGHT="150" ALIGN="CENTER">');
		Win1.document.writeln('			<IMG SRC="' + printOVURL + '" WIDTH=190 HEIGHT=150 HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
		Win1.document.writeln('		</TD>');
	}
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TD ALIGN="CENTER" VALIGN="TOP">');
	Win1.document.writeln('			<IMG SRC="' + printLegURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	
	Win1.document.writeln('</TABLE>');
	*/
	
	
	Win1.document.writeln('<CENTER>');
	Win1.document.writeln('<TABLE width=700 height=700 BORDERCOLORLIGHT="#082984" BORDERCOLORDARK="#082984" BORDER="2" NOWRAP style="font: 16pt Arial">');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TD COLSPAN="2"><IMG SRC="' + WebServerPath + '/website/' + WebAppName + '/images/' + parent.LogoImage + '" WIDTH=' + parent.logoSmallWidth + ' HEIGHT=' + parent.logoSmallHeight + ' HSPACE=5 VSPACE=0 BORDER=0 ALT="' + parent.LogoAltText+ '" ALIGN="absmiddle">&nbsp;&nbsp;<B>' + PrintTitle + '</B><BR></TD>');
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TD>');
	Win1.document.writeln('			<IMG SRC="' + CurrentMapURL + '" WIDTH=755 HEIGHT=550 HSPACE=0 VSPACE=0 BORDER=0>');
	Win1.document.writeln('		</TD>');
	/*Win1.document.writeln('		<TD valign=top >');
	Win1.document.writeln('			<IMG SRC="' + CurrentLegendURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="Legend">');
	Win1.document.writeln('		</TD>');
	*/
	Win1.document.writeln('	</TR>');

	/*
	//if (hasOVMap) Win1.document.write(' ROWSPAN="2"');
	
	//	if (hasOVMap) {
	if (top.document.TextFrame){
		Win1.document.writeln('	<TR>');
		Win1.document.writeln('		<TD HEIGHT="150" ALIGN="CENTER">');
		Win1.document.writeln('			<IMG SRC="' + printOVURL + '" WIDTH=150 HEIGHT=150 HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
		Win1.document.writeln('		</TD>');
		Win1.document.writeln(' </TR>');
	}
	*/
	
	Win1.document.writeln('</TABLE>');
	
	Win1.document.writeln('</B></FONT>');
	//Win1.document.writeln('</body></html>');
	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}

