// 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;
var printsize;
var printorient;
var fsize;
var niWidth;
var niHeight;

var printLegend;


/*
***************************************************************************************

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=500,height=350,scrollbars=yes,resizable=yes");
	//}
}

// create web page for printing
	// first get Map
function getPrintMap(title,printsize,printorient,printLeg1,scale) {

	printLegend=printLeg1
	showRetrieveMap();
	printTitle=title;
	var tempWidth = iWidth;
	var tempHeight = iHeight;

	if(printsize=="A" && printorient=="L"){
		iWidth=900;
		niWidth=900;
		iHeight=575;
		niHeight=575;
		fsize="4";
		f1size="3";
	}
	else if(printsize=="A" && printorient=="P"){
		iWidth=660;
		niWidth=660;
		iHeight=800;
		niHeight=800;
		fsize="4";
		f1size="3";
	}
	else if(printsize=="B" && printorient=="L"){
		iWidth=1475;
		niWidth=1475;
		iHeight=825;
		niHeight=825;
		fsize="5";
		f1size="3";
	}
	else if(printsize=="B" && printorient=="P"){
		iWidth=900;
		niWidth=900;
		iHeight=1300;
		niHeight=1300;
		fsize="5";
		f1size="3";
	}
	else if(printsize=="D" && printorient=="L"){
		iWidth=3100;
		niWidth=3100;
		iHeight=1850;
		niHeight=1850;
		fsize="7";
		f1size="5";
	}
	else if(printsize=="D" && printorient=="P"){
		iWidth=1950;
		niWidth=1950;
		iHeight=3000;
		niHeight=3000;
		fsize="7";
		f1size="5";
	}
	else if(printsize=="E" && printorient=="L"){
		iWidth=4075;
		niWidth=4075;
		iHeight=3000;
		niHeight=3000;
		fsize="10";
		f1size="6";
	}
	else if(printsize=="E" && printorient=="P"){
		iWidth=3100;
		niWidth=3100;
		iHeight=3975;
		niHeight=3975;
		fsize="10";
		f1size="6";
	}

/////////////////////////////////////////
	MapeLeft=eLeft;
	MapeRight=eRight;
	MapeTop=eTop;
	MapeBottom=eBottom;

	if(scale == "Automatic"){
	
	} else{
			if (! parseInt(scale)) {
	    		alert("Numeric value expected greater than 1.");
	  		} else {
	   		 var userscale = parseInt(scale)
	    		if (userscale <= 1.0) {
	     		 alert("The specified scale is too small. Please enter a value greater than 1.");
	    		} else {
		//savelast=true;
	     		 zoomToPrintScale(userscale);
    			}
    		}
	}
///////////////////////////////////////////

	legVis2=legendVisible;
	if (aimsLegendPresent) legendVisible=true;
	printing=true;
	var theString = writeXML(printing);

	iWidth=tempWidth;
	iHeight = tempHeight;
	legendVisible = legVis2;
	sendToServer(imsURL,theString,101);
	tempWidth=null;
	tempHeight=null;
	theString=null;
printing=false;
}

// second, get OVMap//NOT NEEDED CURRENTLY
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
	//FOR LATER--IF SOME RADIO BUTTON, THEN URL = NO LEGEND

		//printLegURL = "images/nolegend.gif";
	writePrintPage();
}
// fourth, write the web page
function writePrintPage() {
	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>' + titleList[5] + '</title>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
	Win1.document.writeln('<CENTER>');
	Win1.document.writeln('<FONT FACE="Times"><B>');
	
	Win1.document.writeln('<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3" NOWRAP>');

	//Win1.document.writeln('<TABLE WIDTH="'+niWidth+'" BORDER="2" CELLSPACING="0" CELLPADDING="5" NOWRAP>');
	
	Win1.document.writeln('	<TR>');

	Win1.document.writeln('<TD ALIGN="center"><font size="'+fsize+'">' + printTitle + '</font></TD></TR>');

	Win1.document.writeln('<TR><TD ALIGN="center"><font size="'+f1size+'">Broome County Department of Planning and Economic Development</font></TD>');
	
	
	//Win1.document.writeln('		<TH COLSPAN="1">' + printTitle + '</TH>');
	
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');

	if (printLegend==true) {


	Win1.document.write('		<TD valign="middle" WIDTH="'+(niWidth-200)+'" HEIGHT="'+niHeight+'">');
	Win1.document.writeln('			<IMG SRC="' + printMapURL + '" WIDTH=' + (niWidth-200) + 'HEIGHT=' + niHeight + 'HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
	
	} else {

	Win1.document.write('		<TD valign="middle" COLSPAN ="2" WIDTH="'+niWidth+'" HEIGHT="'+niHeight+'">');
	Win1.document.writeln('			<IMG SRC="' + printMapURL + '" WIDTH=' + niWidth + 'HEIGHT=' + niHeight + 'HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
	
	}

	//if (hasOVMap) Win1.document.write(' ROWSPAN="1"');
	//Win1.document.writeln('>');
	
	Win1.document.writeln('		</TD>');
	
	//if (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>');

	if (printLegend==true) {

	//Win1.document.writeln('	<TR>');
	
	Win1.document.writeln('		<TD ALIGN="CENTER" VALIGN="TOP" WIDTH="200">');
	Win1.document.writeln('			<br><IMG SRC="' + printLegURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	
	} else {

	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();
}

