// 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.TOCFrame.document.location = "printform.htm";
//		alert("ActiveLayer + "+ActiveLayer);
//		alert("ActiveLayerType + "+ActiveLayerType);
//		alert("ActiveLayerIndex + "+LayerName[ActiveLayerIndex]);
		getPrintMap("Sarasota County "+ LayerName[ActiveLayerIndex]+" Map");
	} 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;
	//alert("aimsLegendPresent = "+aimsLegendPresent)
	var theString = writeXML();
	iWidth=tempWidth;
	iHeight = tempHeight;
	legendVisible = legVis2;
	//alert("imsURL = "+imsURL)
	//alert("theString = "+theString)
	sendToServer(imsURL,theString,101);
	tempWidth=null;
	tempHeight=null;
	theString=null;
	printShowHightlight = false;
}
// 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();
}

//By GP, 2003-08-14
//Used to get urlof current map image, the use it in the printing
function getCurrentMapImageURL() {
	//alert("theMap=" + document.getElementById("theMap").innerHTML);
	var returnString = "";
	var ucInString = document.getElementById("theMap").innerHTML;
	var ucBefore = 'src="';
	var ucAfter = dQuote;
	var intLimitpos = ucInString.length;
	var intPos;
	intPos = ucInString.indexOf(ucBefore,0);
	//alert(startpos);
	if ((intPos != -1) && (intPos<intLimitpos)) {
		intPos = intPos + ucBefore.length;
		var endpos = ucInString.indexOf(ucAfter,intPos);
		returnString = ucInString.substring(intPos,endpos);
	}	
	
	
	return returnString;

}




// fourth, write the web page
function writePrintPage() {

	var gpString = getCurrentMapImageURL();
		//	alert("gpString=" + gpString + "//n" + "printMapUrl=" + printMapURL);
	//printMapURL = gpString;


	if(labelShowHighLight){
		alert(PIDlabel);
			var Win2 = open(topURL + "printmap.asp?PIDLable="+PIDlabel+"&MapURL="+printMapURL+"&OVRMap="+printOVURL+"&LegendURL="+printLegURL,"PrintPage3");
	}
	
	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="728" HEIGHT="569"');
	if (hasOVMap) Win1.document.write(' ROWSPAN="2"');
	Win1.document.writeln('>');     //Use gpString to replace printMapURL
	Win1.document.writeln('			<IMG SRC="' + gpString  + '" WIDTH=728 HEIGHT=569 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" WIDTH=160 HEIGHT=150 >');
	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>');
	// RickJ added set to landscape message 082903
	Win1.document.writeln('<script language=javascript>');
	Win1.document.writeln('alert("TO PRINT THE MAP USE THE FILE MENU DROP-DOWN PRINT OPTION ON THE INTERNET BROWSER. SET PAGE ORIENTATION TO LANDSCAPE AND PRINT                            TO SAVE MAP IMAGE- RIGHT MOUSE CLICK IMAGE- SELECT SAVE PICTURE AS- SELECT SAVE AS TYPE- RENAME FILE NAME- NOTE SAVE DIRECTORY")');   
	Win1.document.writeln('</script>');
	// RickJ End

	Win1.document.close();
	
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}

