// 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 printScale  = 0;
var printWidth  = 750;
var printHeight = 550;

var legVis2=false;

/*
***************************************************************************************

Print functions 

***************************************************************************************
*/


// display print form
function printIt() {
	hideLayer("measureBox");
	getPrintMap("");
	//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;

	//Salva impostazioni correnti
	var tempWidth  = iWidth;
	var tempHeight = iHeight;
	var tempLeft   = eLeft;
	var tempBottom = eBottom;
	var tempRight  = eRight;
	var tempTop    = eTop;
	var tempColor  = legColor;
	var tempTitle  = legTitle;

	//Dimensioni di stampa	
	iWidth  = printWidth;
	iHeight = printHeight;
	
	//Impostazioni della legenda
	legColor  = "255,255,255";
	legTitle  = "";
	
	//Calcola l'extent di stampa alla scala corrente
	printScale  = parseInt(mapScaleFactor * (567./15.) * 100);
	var x       = (eLeft + eRight) / 2.;
	var y       = (eBottom + eTop) / 2.;
	var dx      = (printScale * iWidth) / 100. / (567./15.);
	var dy      = (printScale * iHeight) / 100. / (567./15.);
	var eLeft   = x - dx/2;
	var eRight  = x + dx/2;
	var eBottom = y - dy/2;
	var eTop    = y + dy/2;
	
	//Imposta visibilita' legenda
	legVis2 = legendVisible;
	if (aimsLegendPresent) legendVisible = true;
	
	//Crea istruzione XML per la stampa
	var theString = writeXML();
	
	//Ripristina parametri modificati
	iWidth        = tempWidth;
	iHeight       = tempHeight;
	eLeft         = tempLeft;
	eRight        = tempRight;
	eBottom       = tempBottom;
	eTop          = tempTop;
	legendVisible = legVis2;
	legColor      = tempColor;
	legTitle      = tempTitle;
	
	//Esegue la stampa
	sendToServer(imsURL,theString,101);
	
	//Reset
	tempWidth  = null;
	tempHeight = null;
	theString  = null;
	tempLeft   = null;
	tempRight  = null;
	tempBottom = null;
	tempTop    = 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() {

	//Dimensioni della Window di destinazione
	var Win1;
	var xdim = printWidth + 190 + 50;
	var ydim = printHeight + 100;

	if ((xdim+50) > screen.width)   xdim = screen.width-50;
	if ((ydim+50) > screen.height)  ydim = screen.height-50;

	var xpos = (screen.width-xdim)/2;
	var ypos = (screen.height-ydim-50)/2;
	xpos.round;
	ypos.round;

	var stemp = "height="+ydim+",width="+xdim+",top="+ypos+",left="+xpos+",status=no,toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes";
		
	//Window di destinazione
	Win1 = window.open("","PrintPage",stemp);
	
	//Check se creata la finestra popup o bloccata dal programma
	if (Win1 != null) {
		//Intestazione
		Win1.document.open();
		Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '">');
		Win1.document.writeln('<meta http-equiv="imagetoolbar" content="false">');
		Win1.document.writeln('<head><title>' + titleList[5] + '</title>');
		Win1.document.writeln('<LINK href="' + appDir + 'imagespd/tutto_padova.css" type="text/css" rel="stylesheet">');
		Win1.document.writeln('</head>');
		Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
		//Titolo della pagina
		Win1.document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
		Win1.document.writeln('<tr><td height="22"><img src="' + appDir + 'imagespd/cartografia.gif" border="0" hspace="5" width="160" height="20" vspace="1"></td></tr>');
		Win1.document.writeln('<tr><td><FONT FACE="Arial" size="1">&nbsp;&nbsp;Per trovare vie, numeri civici, farmacie, scuole ecc. localizzate sulla cartografia del Comune di Padova</FONT></td></tr>');
		Win1.document.writeln('<tr><td height="10"></td></tr>');
		Win1.document.writeln('</table>');
		Win1.document.writeln('<center>');
		//Mappa+Localizzatore+Legenda
		Win1.document.writeln('<TABLE BORDER="2" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
		Win1.document.writeln('<TR>');
		if (hasOVMap) {
			Win1.document.write('<TD WIDTH="'+printWidth+'" HEIGHT="'+printHeight+'" ROWSPAN="2">');
		} else {
			Win1.document.write('<TD WIDTH="'+printWidth+'" HEIGHT="'+printHeight+'">');
		}
		Win1.document.writeln('<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
		Win1.document.writeln('<TR><TD>');
		//Mappa
		Win1.document.writeln('<IMG SRC="' + printMapURL + '" WIDTH='+printWidth+' HEIGHT='+printHeight+' HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
		Win1.document.writeln('</TD></TR><TR><TD align="center">');
		//Scala
		Win1.document.writeln('<IMG SRC="' + appDir + 'imagespd/scala.gif" HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
		Win1.document.writeln('<BR>');
		Win1.document.writeln('<FONT FACE="Arial" size="1">Scala 1 cm = ' + (printScale/100) + ' m</FONT>');
		Win1.document.writeln('</TD></TR></TABLE>');
		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>');
		Win1.document.writeln('<TR><TD ALIGN="CENTER" VALIGN="TOP">');
		//Legenda	
		Win1.document.writeln('<table width="100%" height="100%" border="0" cellspacing="2" cellpadding="2">');
		//Win1.document.writeln('<tr><td colspan=2 class="titric">LEGENDA: </td></tr>');
		//Win1.document.writeln('<tr><td><img src="' + appDir + 'simboli/ico_farmacie.gif" width="17" height="17" border="0"></td><td><FONT FACE="Arial" size="1">Farmacie</font></td></tr>');
		//Win1.document.writeln('<tr><td><img src="' + appDir + 'simboli/ico_scuola.gif" width="17" height="17" border="0"></td><td><FONT FACE="Arial" size="1">Scuole</font></td></tr>');
		//Win1.document.writeln('<tr><td><img src="' + appDir + 'simboli/ico_logo.gif" width="17" height="17" border="0"></td><td><FONT FACE="Arial" size="1">Uffici comunali</font></td></tr>');
		//Win1.document.writeln('<tr><td><img src="' + appDir + 'simboli/ico_cinema.gif" width="17" height="17" border="0"></td><td><FONT FACE="Arial" size="1">Cinema</font></td></tr>');
		//Win1.document.writeln('<tr><td><img src="' + appDir + 'simboli/ico_musei.gif" width="17" height="17" border="0"></td><td><FONT FACE="Arial" size="1">Musei e Monumenti</font></td></tr>');
		//Win1.document.writeln('<tr><td><img src="' + appDir + 'simboli/ico_disabili.gif" width="17" height="17" border="0"></td><td><FONT FACE="Arial" size="1">Parcheggi per disabili</font></td></tr>');
		//Win1.document.writeln('<tr><td><img src="' + appDir + 'simboli/ico_park.gif" width="17" height="17" border="0"></td><td><FONT FACE="Arial" size="1">Parcheggi</font></td></tr>');
		//Win1.document.writeln('</table>');
		Win1.document.writeln('<TD class="titric" ALIGN="CENTER" VALIGN="TOP">');
		Win1.document.writeln('LEGENDA:<BR>');
		Win1.document.writeln('<IMG SRC="' + printLegURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
		Win1.document.writeln('</TD></TR></TABLE>');
		Win1.document.writeln('</body></html>');
		Win1.document.close();
	
		legendVisible=legVis2;
		Win1=null;
		hideRetrieveMap();
	}
}


