// 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()
{
	parent.LeftFrame.document.location = "printform.htm";
}

function getPrintMap(title,pWidth,pHeight,quality)  
{

	//Send a request to the server to get the map
	showRetrieveMap();
	printTitle=title;
	var tempWidth = iWidth;
	var tempHeight = iHeight;
	printWidth = pWidth;
    printHeight = pHeight;
	iWidth = Math.floor(parseFloat(printWidth) * quality);
	iHeight = Math.floor(parseFloat(printHeight) * quality);
	//alert(iWidth)
	//alert(iHeight)
	legVis2=legendVisible;
	if (aimsLegendPresent) legendVisible=true;
	var theString = writeXML();
	iWidth=tempWidth ;
	iHeight = tempHeight;
	legendVisible = legVis2;
	
	sendToServer(imsURL,theString,101);
	
	//alert(theString)
	tempWidth=null;
	tempHeight=null;
	theString=null;
}
//------------------------------------------------------------------------------------------------------
function getPrintOV() 
{
	//Get OVMap
	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;
}
//------------------------------------------------------------------------------------------------------
function getPrintLegend() 
{
	//Get Legend
	if (printLegURL=="") printLegURL = "images/nolegend.gif";
	

	//---------------------------------------------
	// Drawing Template
	if (parent.MapFrame.showTemplate == 'ON')
	{
	writePrintPageTemplate();
	}
	else
	{
	writePrintPage();
	}
	//-----------------------------------------------
	
}
//------------------------------------------------------------------------------------------------------
function writePrintPage() 
{

	//Write the web page with the map in it
	var Win1 = window.open("","PrintPage");
	if (!Win1)
	{
		alert("Sorry, the system is unable to print your map at this time.\nThis problem may be caused by a 'Popup Blocker' being enabled on your browser.\n'Popup Blockers' need to be turned off in order to print a map.")
		return
	}
	
	Win1.document.writeln('<html><head>');
	Win1.document.writeln('	<title>Durham County Council GIS</title>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0 onload="var theStr=opener.parent.MapFrame.userPrintInstructions(); alert(theStr)">');
	
	
	
	
	Win1.document.writeln('<FONT FACE="Arial"><B>');
	Win1.document.writeln('<TABLE BORDER="1" 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="'+printWidth+'" HEIGHT="'+printHeight+'">');	
	Win1.document.writeln('				<IMG SRC="' +printMapURL + '" WIDTH="'+printWidth+'" HEIGHT="'+printHeight+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="">'); 
	



	//-----------------------------------------------------------------------------------------------------
	//DHTML for Info box.
	
	//var content='<font size="10">Print out box</font>';
	
	//DHTML variables.
	//var name="PrintOutBox";
	//var inleft=196;
	//var intop=233;
	//var width=485;
	//var height=53;
	//var visible=true;
	//Win1.document.writeln('<div id="' + name + '" style=position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:1; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
	//Win1.document.writeln(content);
	//Win1.document.writeln('</div>');

	//-----------------------------------------------------------------------------------------------------


	Win1.document.writeln('		</TD>');

	//Legend - only draw if needed
	if (parent.MapFrame.showLegendOnPrint==true)
	{
		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>');
	}
	else
	{
		Win1.document.writeln('	</TR>');
	}

	
	



	//Scale
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('			<TD ALIGN="CENTER" VALIGN="TOP">');
	Win1.document.writeln('<FONT face=arial size=-2>Scale 1: ' + parent.ToolFrame.document.forms[0].txtScale.value + '</FONT>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	




	Win1.document.writeln('</TABLE>');
	Win1.document.writeln('</B></FONT>');
	Win1.document.writeln('</body>');
	Win1.document.writeln('</html>');
	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}

function writePrintPageTemplate() 
{

	//Write the web page with the map in it
	var Win1 = window.open("","PrintPage");
	if (!Win1)
	{
		alert("Sorry, the system is unable to print your map at this time.\nThis problem may be caused by a 'Popup Blocker' being enabled on your browser.\n'Popup Blockers' need to be turned off in order to print a map.")
		return
	}
	
	Win1.document.writeln('<html><head>');
	Win1.document.writeln('	<title>Durham County Council GIS</title>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0 onload="var theStr=opener.parent.MapFrame.userPrintInstructions(); alert(theStr)">');
	
	
	
	
	Win1.document.writeln('<FONT FACE="Arial"><B>');
	Win1.document.writeln('<TABLE BORDER="1" 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="'+printWidth+'" HEIGHT="'+printHeight+'">');	
	Win1.document.writeln('				<IMG SRC="' +printMapURL + '" WIDTH="'+printWidth+'" HEIGHT="'+printHeight+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="">'); 
	



	//-----------------------------------------------------------------------------------------------------
	//DHTML for Info box.
	
	//var content='<font size="10">Print out box</font>';
	
	//DHTML variables.
	//var name="PrintOutBox";
	//var inleft=196;
	//var intop=233;
	//var width=485;
	//var height=53;
	//var visible=true;
	//Win1.document.writeln('<div id="' + name + '" style=position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:1; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
	//Win1.document.writeln(content);
	//Win1.document.writeln('</div>');

	//-----------------------------------------------------------------------------------------------------


	Win1.document.writeln('		</TD>');

	//Legend - only draw if needed
	if (parent.MapFrame.showLegendOnPrint==true)
	{
		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>');
	}
	else
	{
		Win1.document.writeln('	</TR>');
	}

	Win1.document.writeln('</TABLE>');

	Win1.document.writeln('<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="0" WIDTH="50%">');
	
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TD ALIGN="LEFT" VALIGN="TOP">');
	Win1.document.writeln('<FONT face=arial size=-2><B>&nbsp;&nbsp;Scale 1: ' + parent.ToolFrame.document.forms[0].txtScale.value + '</B><BR><B>&nbsp;&nbsp;Project:</B> ' + printProject + '<BR><B>&nbsp;&nbsp;Project No:</B> ' + printProjectNo + '<BR><B>&nbsp;&nbsp;Drawing:</B> ' + printDrawing + '<BR><B>&nbsp;&nbsp;Drawing No:</B> ' + printDrawingNo + '<BR></FONT>');
	Win1.document.writeln('		</TD>');

	if (parent.MapFrame.printDir!="")
	{
	Win1.document.writeln('		<TD ALIGN="LEFT" VALIGN="TOP">');
	Win1.document.writeln('<FONT face=arial size=-2>&nbsp;&nbsp;' + printDir + '<BR>&nbsp;&nbsp;' + printService + '<BR>&nbsp;&nbsp;' + printDCC + '<BR></FONT>');
	Win1.document.writeln('		</TD>');
	}


	Win1.document.writeln('		<TD ALIGN="LEFT" VALIGN="TOP">');
	Win1.document.writeln('<FONT face=arial size=-2>&nbsp;&nbsp;' + printOffice + '&nbsp;&nbsp;<BR>&nbsp;&nbsp;' + printAddr1 + '&nbsp;&nbsp;<BR>&nbsp;&nbsp;' + printAddr2 + '&nbsp;&nbsp;<BR>&nbsp;&nbsp;' + printAddr3 + '&nbsp;&nbsp;<BR>&nbsp;&nbsp;' + printAddr4 + '&nbsp;&nbsp;<BR>&nbsp;&nbsp;Tel: ' + printTel + '&nbsp;&nbsp;<BR></FONT>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	
	Win1.document.writeln('</TABLE>');
	
	Win1.document.writeln('</B></FONT>');
	Win1.document.writeln('</body>');
	Win1.document.writeln('</html>');
	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}


