// 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");
	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) {
	showRetrieveMap();
	printTitle=title;
	var tempWidth = iWidth;
	var tempHeight = iHeight;
	//INIZIO - Baco Layout : GeDeONE 1.2.0.
	//iWidth=450;
	//iHeight=450;
	//FINE - Baco Layout : GeDeONE 1.2.0.
	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;
	//INIZIO - Baco Layout : GeDeONE 1.2.0.
	//i2Width=190;
	//i2Height=150;
	//FINE - Baco Layout : GeDeONE 1.2.0.
	var tempDraw=drawOVExtentBox;
	drawOVExtentBox=true;
	var theString = writeOVXML();
	drawOVExtentBox=tempDraw;
	i2Width=tempWidth;
	i2Height = tempHeight;
	sendToServer(imsOVURL,theString,102);
	tempWidth=null;
	tempHeight=null;
	theString=null;
	writePrintPageM();
}

function getPrintLeg(title) {
   showRetrieveMap();
	printTitle=title;	
	if (aimsLegendPresent) legendVisible=true;
	//drawLegendOnly=true;
	var theString=writeXML();	
	sendToServer(imsURL,theString,103); 
	legVis2=legendVisible;
	
	/*var theString = writeXML();
	iWidth=tempWidth;
	iHeight = tempHeight;
	legendVisible = legVis2;
	sendToServer(imsURL,theString,101);
	*/
	tempWidth=null;
	tempHeight=null;
	theString=null;
	if (printLegURL=="") printLegURL = "images/nolegend.gif";
	//writePrintPageL();
}

// third, get Legend
function getPrintLegend() {
	//  waiting for Legend tags
	if (printLegURL=="") printLegURL = "images/nolegend.gif";
	writePrintPageL();
}
// fourth, write the web page
function writePrintPageM() {
	var Win1 = open("","PrintPage");
	Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
	Win1.document.writeln('<link rel="stylesheet" href="'+pagStile+'" type="text/css"><title>' + titleList[5] + '</title>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White"  LEFTMARGIN=0 TOPMARGIN=0>');
	Win1.document.writeln('<BR><BR><B><CENTER>');
	Win1.document.writeln('<TABLE WIDTH="80%"  CELLSPACING="0" CELLPADDING="0"  border=1 valign="center">');
	Win1.document.writeln('	<TR>');
        //INIZIO - Baco Layout : GeDeONE 1.2.0. 
	//Win1.document.writeln('		<TH COLSPAN="2" height="100">' + printTitle + '</TH>');
        Win1.document.writeln('		<TH COLSPAN="2" height="30">' + printTitle + '</TH>');
	//FINE - Baco Layout : GeDeONE 1.2.0. 
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');
        //INIZIO - Baco Layout : GeDeONE 1.2.0. 
	//Win1.document.write('		<TD WIDTH="450" HEIGHT="450"');
        Win1.document.write('	 <TD WIDTH="' + iWidth + '" HEIGHT="' + iHeight + '"'); 
        //FINE - Baco Layout : GeDeONE 1.2.0. 
	if (hasOVMap) Win1.document.write(' ROWSPAN="2"');
	Win1.document.writeln('>');
	Win1.document.writeln('			<IMG SRC="' + printMapURL + '"  HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
	Win1.document.writeln('		</TD>');
	if (hasOVMap) {
                //INIZIO - Baco Layout : GeDeONE 1.2.0. 
		//Win1.document.writeln('		<TD ALIGN="CENTER" VALIGN="CENTER">');
                Win1.document.writeln('		<TD ALIGN="Left" VALIGN="center">'); 
                //FINE - Baco Layout : GeDeONE 1.2.0. 
		Win1.document.writeln('			<IMG SRC="' + printOVURL + '"  HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
		Win1.document.writeln('		</TD>');
	}
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('</TABLE></CENTER>');
	Win1.document.writeln('</B>');
	Win1.document.writeln('</body></html>');
	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}

// fourth, write the web page
function writePrintPageL() {
	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('<link rel="stylesheet" href="'+pagStile+'" type="text/css"><title>' + titleList[5] + '</title>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White"  LEFTMARGIN=0 TOPMARGIN=0>');
	Win1.document.writeln('<B><CENTER>');
	Win1.document.writeln('<BR><BR><TABLE WIDTH="80%" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TH COLSPAN="2" height="100">' + printTitle + '</TH>');
	Win1.document.writeln('	</TR>');
	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=1 ALT="">');
        Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');

	Win1.document.writeln('</TABLE>');
	Win1.document.writeln('</CENTER></B>');
	Win1.document.writeln('</body></html>');
	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}

