// 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 printSize="";
var printOrientation = "landscape";
var printFormat = "html";
var printLegend = false;
var printProperty = false;
var printWin = null;

var legVis2=false;

/*
***************************************************************************************

Print functions 

***************************************************************************************
*/


// display print form
function printIt() {
	parent.TOCFrame.document.location = "printform.asp";
}

// create web page for printing
	// first get Map
function getPrintMap(title, size, orientation, format, addLegend, addPropinfo) {
	if(window.printWin && !window.printWin.closed)
		window.printWin.close();
	printWin = window.open("","printWin", "menubar=1,toolbar=0,top=0,left=0,scrollbars=1,resizable=1");
	printWin.opener = self;
	printWin.focus();

	printWin.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '">');
	printWin.document.writeln('<meta http-equiv="imagetoolbar" content="false">');
	printWin.document.writeln('<head><title>Print Map</title>');
	printWin.document.writeln('<STYLE>');
	printWin.document.writeln('.title {font-family: Times New Roman; font-size: 30px; color: #000073; font-weight: bold;}');
	printWin.document.writeln('.txt {font-family: Times New Roman; font-size: 20px; color: #000073; font-weight: bold;}');
	printWin.document.writeln('</STYLE></head>');
	printWin.document.writeln('<body onload="document.forms[0].submit();">');
	printWin.document.writeln("<p class='title' align='center'>" + title + "</p>");
	printWin.document.writeln("<p class='txt'>PLEASE WAIT:</p>");
	printWin.document.writeln("<p class='txt'>Generating map...</p>");
	
	showRetrieveMap();
	printTitle = title;
	printSize = size;
	printOrientation = orientation;
	printFormat = format;
	printLegend = addLegend;
	printProperty = addPropinfo;
	
	var tempWidth = iWidth;
	var tempHeight = iHeight;
	
	if (size == "Letter") {		//Width: 900 px/9.5 in; Height: 660px/7in
		if (printProperty){
			if(orientation == "landscape"){
				iWidth = 540;	// Use 60% for map, leave 40% for property table
				iHeight = (printFormat=="html")?450:400;
			}else{
				iWidth = 660, iHeight = 400;
			}
		}else{
			if(orientation == "landscape"){
				iWidth = 700;	// Leave 200px for disclaimer, etc.
				iHeight = 600;
			}else{
				iWidth = 660, iHeight=500;
			}
		}
	}else {		// Width: 1470px/15.5in; Height: 900px/9.5in
		if (printProperty) {
			if(orientation == "landscape"){
				iWidth = 880;	// Use 60% for map, leave 40% for property table
				iHeight = (printFormat == "html")? 650:625;
			}else{
				iWidth = 900, iHeight = 850;
			}
		}else{
			iWidth = 1200;	//Leave 270px for disclaimer, etc.
			iHeight = 830;
		}
	}
	legVis2=legendVisible;
	legendVisible=false;

	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;
	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() {
	// If the map output includes property report, just use the pre-made default legend.
	if (printLegend && printProperty)	printLegURL =  "/website/MidMoGIS/proplegend.gif";
	 
	if (!printLegend || (printLegend && printProperty)) {
		writePrintPage();
		return;
	}
	
	// Otherwise, request for legend image.
	printWin.focus();
	printWin.document.writeln("<p class='txt'>Generating legend map...</p>");
	legendVisible=true;
	drawLegendOnly=true;
	
	// Force layers not drawn for ArcMap service. Yan Barnett
	var tmpLayerVisible = new Array();
	if (hideLayersFromList) {
		for(var i=0; i<layerCount; i++){
			tmpLayerVisible[i] = LayerVisible[i];
			LayerVisible[i] = (noListLayer[i])? 0: LayerVisible[i];
		}
	}
	var theString=writeXML();
	showRetrieveMap();
	sendToServer(imsURL,theString,103);
	
	//Set LayerVisible back - Yan Barnett
	if (tmpLayerVisible.length == LayerVisible.length){
		for(var i=0; i<layerCount; i++){
			LayerVisible[i] = tmpLayerVisible[i];
		}
	}
}

// fourth, write the web page
function writePrintPage() {
	//var printWin = open("","PrintPage");
	printWin.focus();

	printWin.document.writeln("<p class='txt'>Formating outputs...</p>");
	printWin.document.writeln('<form method="POST" action="/website/MidMoGIS/mapOutput.asp">');
	printWin.document.writeln('<input type="hidden" name="title" value="' + printTitle +'">');
	printWin.document.writeln('<input type="hidden" name="mapurl" value="' + printMapURL +'">');
	printWin.document.writeln('<input type="hidden" name="legend" value="' + printLegURL  +'">');
	printWin.document.writeln('<input type="hidden" name="size" value="' + printSize +'">');
	printWin.document.writeln('<input type="hidden" name="orientation" value="' + printOrientation +'">');
	printWin.document.writeln('<input type="hidden" name="format" value="' + printFormat +'">');
	
	if (printProperty && PID.length > 0)
		printWin.document.writeln('<input type="hidden" name="pid" value="' + PID[0] +'">');
		
	printWin.document.writeln('</form>');
	printWin.document.writeln('</body></html>');
	printWin.document.close();
	printWin.document.forms[0].submit();
	
	hideRetrieveMap();
	legendVisible=legVis2;
	printWin=null;
	printMapURL="";
	printOVURL="";
	printLegURL="";
	printSize="";
	printLegend = false;
	printProperty = false;
}

