// 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 printLoc    = false;
var printWidth  = 0;
var printHeight = 0;
var printMapURL = "";
var printOVURL  = "";
var printLegURL = "";

var legVis2     = false;
var legColor2   = "";

/****************************************************************************************
Print functions 
****************************************************************************************/

// display print form
function printIt() {
	hideLayer("measureBox");
	if (useRicFrame) {
		parent.RicFrame.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;
	iWidth=450;
	iHeight=450;
	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;
}

//Funzione modificata per stampare con le dimensioni richieste
function getPrintMap1(title,xdim,ydim,tleft,tright,tbottom,ttop,checkloc) {

	showRetrieveMap();
	
	//Salva dimensioni della mappa
	var tempWidth  = iWidth;
	var tempHeight = iHeight;

	//Salva extent corrente della mappa
	var templeft   = eLeft;
	var tempright  = eRight;
	var tempbottom = eBottom;
	var temptop    = eTop;

	//Imposta parametri di stampa
	printTitle    = title;
	printLoc      = checkloc;
	printWidth    = parseInt(xdim) + 10;
	printHeight   = parseInt(ydim);
	printleft     = tleft;
	printright    = tright;
	printbottom   = tbottom;
	printtop      = ttop;

	//Imposta dimensioni immagine di stampa
	iWidth        = xdim;
	iHeight       = ydim;

	//Imposta extent di stampa
	eLeft         = printleft;
	eRight        = printright;
	eBottom       = printbottom;
	eTop          = printtop;

	//Imposta visibilita' legenda
	legVis2       = legendVisible;
	legendVisible = printLoc;
	legColor2     = legColor;
	legColor      = "255,255,255";

	//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      = legColor2;
	
	//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() {

	if (printLoc == true) {
	
		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;

	} else {
	
		writePrintPage1();
	
	}

}

// third, get Legend
function getPrintLegend() {
	//  waiting for Legend tags
	if (printLegURL=="") printLegURL = "images/nolegend.gif";
	writePrintPage1();
}

// 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('<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 (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) {
		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('</B></FONT>');
	//Win1.document.writeln('</body></html>');
	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}

//Funzione modificata per stampare con le dimensioni richieste
function writePrintPage1() {

	//Dimensioni della Window di destinazione
	var Win1;
	var xdim = printWidth + 50;
	var ydim = printHeight + 100;

	if (printLoc == true) {
		xdim = printWidth + 190 + 50;
		ydim = printHeight + 100;
	} else {
		xdim = printWidth + 50;
		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";
	//alert(stemp);
		
	//Window di destinazione
	Win1 = window.open("","PrintPage",stemp);

	Win1.document.writeln('<html><head>');
	Win1.document.writeln('<title>Stampa mappa</title>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=10 TOPMARGIN=10>');
	Win1.document.writeln('<FONT FACE="Verdana,Arial">');

	Win1.document.writeln('<TABLE WIDTH="'+printWidth+'px" BORDER="0" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
	Win1.document.writeln('<TR align=left valign=center>');
	Win1.document.writeln('<TD width=171><IMG src="' + appDir + 'images/logo_stampa.jpg" width="140" height="82"></td>');
	Win1.document.writeln('<td width=20>&nbsp;</td>');
	Win1.document.writeln('<td><b><font face="Verdana,Arial" size="6" color="Blue">ATLA</font><font face="Verdana,Arial" size="6" color="Red">EOLICO</font></b>');
	Win1.document.writeln('<br><b><font face="Verdana,Arial" size="2" color="#7B7B7B">Atlante Eolico Interattivo</font></b></TD>');
	if (printTitle != "") {
		Win1.document.writeln('<TR align=left><td>&nbsp;</td><TD><FONT size=2>' + printTitle + '</FONT></TD></TR>');
	}
	Win1.document.writeln('</TABLE>');

	Win1.document.writeln('<TABLE WIDTH="'+printWidth+'px" BORDER="0" CELLSPACING="5" CELLPADDING="0" NOWRAP>');
	Win1.document.writeln('<TR>');
	if ((hasOVMap) && (printLoc) && (printOVURL != "")) {
		Win1.document.writeln('<TD rowspan=2 style="VERTICAL-ALIGN: top">')
		Win1.document.writeln('<IMG alt="" src="' + printMapURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="">')
		Win1.document.writeln('</TD>')
		Win1.document.writeln('<TD style="VERTICAL-ALIGN: top">')
		Win1.document.writeln('<IMG alt="" src="' + printOVURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="">')
		Win1.document.writeln('</TD>')
		Win1.document.writeln('</TR><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>');
	} else {
		Win1.document.writeln('<TD style="VERTICAL-ALIGN: top">')
		Win1.document.writeln('<IMG alt="" src="' + printMapURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="">')
		Win1.document.writeln('</TD>')
	}
	Win1.document.writeln('</TR>');
	Win1.document.writeln('</TABLE>');

	Win1.document.writeln('<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
	Win1.document.writeln('<TR align=left valign=center><td><font face="Verdana,Arial" size="1" color="Black">');
	Win1.document.writeln("Mappa elaborata da ERSE in collaborazione con il Dipartimento di Fisica dell'Università di Genova nell'ambito della Ricerca di Sistema.<BR>");
	Win1.document.writeln("Per una corretta interpretazione si veda il manuale d'uso dell'Atlante Eolico Interattivo di cui questa mappa fa parte,");
	Win1.document.writeln("disponibile sul sito web di ERSE - http://www.erse-web.it - oppure direttamente all'indirizzo http://atlanteeolico.erse-web.it");
	Win1.document.writeln("</FONT></TD></TR>");
	Win1.document.writeln('<TR align=left valign=center><td><font face="Verdana,Arial" size="1" color="Black">');
	//Win1.document.writeln("Cartografia di base: copyright GEOnext - DE AGOSTINI 2002 - Tutti i diritti riservati www.geonext.it - info@geonext.it.");
	Win1.document.writeln("</FONT></TD></TR>");
	Win1.document.writeln('</TABLE>');

	Win1.document.writeln('</FONT>');
	Win1.document.writeln('</body></html>');
	Win1.document.close();
	
	legendVisible = legVis2;
	Win1          = null;
	hideRetrieveMap();
	
}
