// 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
*/

var aimsPrintPresent=true;

var printTitle = "REGIS Web Based Map";
var printMapURL="";
var printOVURL="";
var printLegURL="";

var legVis2=false;

/*
***************************************************************************************

Print functions 

***************************************************************************************
*/


// display print form
function printIt() {
	hideLayer("measureBox");
	if (useTextFrame) {
		parent.TextFrame.document.location = "printform.htm";
	} else {
		var Win1 = open("printform.htm","PrintFormWindow","left=120,top=400,width=575,height=200,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=750;
	iHeight=750;
	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;
}
// 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
        // alert("Step 8");
        var theString = writeLegendXML();
        sendToServer(imsURL,theString,105);
	//if (printLegURL=="") printLegURL = "images/nolegend.gif";
	//writePrintPage();
}
// fourth, write the web page
function writePrintPage() {
	//var regis_logo = "images/REGIS_logo.jpg";
	var hostName = document.location.host;
	var Win1 = open("","PrintPage");
	//Win1.document.open();
	Win1.document.writeln('<html><head>');
	Win1.document.writeln('	<title>Map Output</title>');
	Win1.document.writeln('<SCRIPT LANGUAGE="javascript">');
	Win1.document.writeln('	function printWarning() { ');
	Win1.document.writeln('	alert("This page is constructed to be printed using Landscape layout. Be sure you change your print settings from Portrait to Landscape before you print this page!")');
	Win1.document.writeln('	} ');
	Win1.document.writeln('</SCRIPT>');
	Win1.document.writeln('</head>');
	Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0 onload="printWarning()">');
	Win1.document.writeln('<FONT FACE="Arial"><B>');
	Win1.document.writeln('<TABLE WIDTH="800" HEIGHT="550" 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="650" HEIGHT="550"');
	if (hasOVMap) Win1.document.write(' ROWSPAN="2"');
	Win1.document.writeln('>');
	Win1.document.writeln('			<IMG SRC="' + printMapURL + '" WIDTH=650 HEIGHT=600 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 HEIGHT="450" WIDTH="150" ALIGN="CENTER" VALIGN="TOP">');
	Win1.document.writeln('			<IMG SRC="' + printLegURL + '" HEIGHT=450 WIDTH=140 HSPACE=0 VSPACE=0 BORDER=0>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	
	//Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('<TD height="35">');
	Win1.document.writeln('<div align="center"><font size="1">');
	Win1.document.writeln('This map does not represent a legal document.  It is intended to serve as an aid in graphic');
	Win1.document.writeln(' representation only.  Information shown on this map is not warranted for accuracy and should');
	Win1.document.writeln(' be verified through other means');
	Win1.document.writeln('</div></font>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('		<TD HEIGHT="35">');
	Win1.document.writeln('			<IMG SRC="http://'+hostName+'/website/transportation/images/REGIS_Logo.jpg" WIDTH=95 height=30>');
	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.focus();
	Win1=null;
	hideRetrieveMap();
}

function writeTablePage() {
	theReply = storedReply;
	if (toolMode == 19 && tipProjectWinSetting == 4) bufGetAttribute = true;
	//alert(theReply);
	if (bufGetAttribute) {
		setLayerFields(bufferTargetLayerIndex);
	} else {
		setLayerFields(ActiveLayerIndex);
	}
	bufGetAttribute = false;
	var theError = getXMLErrorMessage(theReply);
	var fList="";
	var lpos1 = 1;
	var lpos2 = 1;
	var epos = 1;
	var spos = 1;
	var morePoints=true;
	var moreFeatures=true;
	var featureCount = justGetFeatureCount(theReply);
	var pos = 0;
	var startpos = 0;
	var endpos = xmlEndPos;
	var stillMore = false
	pos = theReply.indexOf('hasmore="true"',endpos);
	if (pos!=-1) stillMore = true;
	pos=0;
	var tempCount = 0;
	var selectedData="";
	var inData="";
	var xStr="";
	var yStr="";
	var eNorth="";
	var eSouth="";
	var eWest="";
	var eEast="";
	var fCount = featureCount;
	//alert("displayAttributeData()[featurecount=" + featureCount + "]");
	selectCount = 0;
	var tempString="";
	var theFrame = "parent.MapFrame";
	if (featureCount > 0) {
		newSelectCount += 1;
		//alert("displayAttributeData()[opening html page]");
			var Win1 = open("","PrintPage");
			theFrame = "opener";
			if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
			Win1.document.open();
			Win1.document.writeln('<html><head><title>Results Print Page</title>');
			Win1.document.writeln('<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">');
			Win1.document.writeln('var t;');
			Win1.document.writeln('var par;');
			Win1.document.writeln(' if (opener) {  ');
			Win1.document.writeln(' 	if (opener.name=="MapFrame") {  ');
			Win1.document.writeln(' 		t = opener.parent.MapFrame;  ');
			Win1.document.writeln('			par = opener.parent;  ');
			Win1.document.writeln(' 	} else {  ');
			Win1.document.writeln('	        	t = opener; ');
			Win1.document.writeln('			par = opener;  ');
			Win1.document.writeln('		}  ');
			Win1.document.writeln(' } else {  ');
			Win1.document.writeln('		if (parent.MapFrame) {  ');
			Win1.document.writeln('			t = parent.MapFrame;  ');
			Win1.document.writeln('			par = parent;  ');
			Win1.document.writeln('		} else {  ');
			Win1.document.writeln('			t=document;  ');
			Win1.document.writeln('		}  ');
			Win1.document.writeln('	}  ');
			Win1.document.writeln('  ');
			Win1.document.writeln('	function printWarning() { ');
			Win1.document.writeln('	alert("This page is constructed to be printed using Landscape layout. Be sure you change your print settings from Portrait to Landscape before you print this page!")');
			Win1.document.writeln('	} ');
			Win1.document.writeln('var srtTextID=""');
			Win1.document.writeln('function CVGprint() {');
			Win1.document.writeln('// CVG function to parse out HTML table and create a printable report document.');
			Win1.document.writeln('//alert("Print Function")'); 

			Win1.document.writeln('}');
			Win1.document.writeln('function loadHelp() {');
			Win1.document.writeln('var Win2;');
			Win1.document.writeln('Win2 = window.open("http://'+hostName+'/website/public/helpIdentifyResults.htm","Help","width=800,height=550,scrollbars=yes,resizable=yes");');
			Win1.document.writeln('Win2 = null;');
			Win1.document.writeln('}');
			Win1.document.writeln('function extract() {');
			Win1.document.writeln('    if (document.all){');
			Win1.document.writeln('    var aryHead = new Array();');
			Win1.document.writeln('    var aryCells = new Array();');
			Win1.document.writeln('    var aryCount=0');
			Win1.document.writeln('        for (var i=0;i < parent.TextFrame.document.all.length; i++){');
			Win1.document.writeln('		//alert(parent.TextFrame.document.all(i).tagName);');
			Win1.document.writeln('            if (parent.TextFrame.document.all(i).tagName == "TH"){');
			Win1.document.writeln('              aryHead[aryCount] = parent.TextFrame.document.all(i).outerHTML');
			Win1.document.writeln('              aryCount++');
			Win1.document.writeln('            } ');
			Win1.document.writeln('         }');
			Win1.document.writeln('         aryCount = 0');
			Win1.document.writeln('         for (var i=0;i < parent.TextFrame.document.all.length; i++){');
			Win1.document.writeln('            if (parent.TextFrame.document.all(i).tagName == "TD"){');
			Win1.document.writeln('               aryCells[aryCount] = parent.TextFrame.document.all(i).outerHTML');
			Win1.document.writeln('              aryCount++');
			Win1.document.writeln('            } ');
			Win1.document.writeln('         } ');   
			Win1.document.writeln('      formatTable(aryHead,aryCells);');
			Win1.document.writeln('    }');
			Win1.document.writeln('}');

			Win1.document.writeln('function formatTable(aryHead,aryCells) {');
			Win1.document.writeln('  alert(aryHead,aryCells);');
			Win1.document.writeln('  strTextID = "<TABLE width=\'600\' bgColor=white border=1 cellPadding=0 cellSpacing=0><TBODY>";');
			Win1.document.writeln('  numMax = Math.ceil(aryHead.length / 8)');
			Win1.document.writeln('  numLimit1 = 0');
			Win1.document.writeln('  numLimit2 = 0');
			Win1.document.writeln('  numRunningTotal1 = 0');
			Win1.document.writeln('  numRunningTotal2 = 0');
			Win1.document.writeln('  rowNumber = 0');
			Win1.document.writeln('  //alert(aryHead.length);');
			Win1.document.writeln('  if (aryHead.length <= 8) {');
                        Win1.document.writeln('    //alert("Case 1");');
			Win1.document.writeln('    for (var j=0;j < numMax;j++){');
			Win1.document.writeln('      strTextID += "<TR>"');
			Win1.document.writeln('      for (numRunningTotal1;numRunningTotal1 < aryHead.length; numRunningTotal1++){');
			Win1.document.writeln('        numLimit1++');
			Win1.document.writeln('        strTextID += aryHead[numRunningTotal1]');

			Win1.document.writeln('      }');
			Win1.document.writeln('      numRunningTotal1++');
			Win1.document.writeln('      numLimit1 = 0');
			Win1.document.writeln('      strTextID += "</TR>"');
			Win1.document.writeln('      for (numRunningTotal2;numRunningTotal2 < aryCells.length; numRunningTotal2++){');
			Win1.document.writeln('        numLimit2++');
			Win1.document.writeln('        strTextID += aryCells[numRunningTotal2]');
			Win1.document.writeln('        if (numLimit2 == 8 || numLimit2 == aryHead.length) {');
			Win1.document.writeln('          numLimit2 = 0');
			Win1.document.writeln('          strTextID += "</TR><TR>"');
			Win1.document.writeln('        }');
			Win1.document.writeln('      }');
			Win1.document.writeln('      strTextID += "</TR>"');
			Win1.document.writeln('    }');
			Win1.document.writeln('  } else { ');
                        Win1.document.writeln('    //alert("Case 2");');
                        Win1.document.writeln('    alert("More than eight attributes present.  Unable to print.");');
                        Win1.document.writeln('    return;');
			Win1.document.writeln('    for (var j=0;j < numMax;j++){');
			Win1.document.writeln('      strTextID += "<TR>"');
			Win1.document.writeln('      for (numRunningTotal1;numRunningTotal1 < aryHead.length; numRunningTotal1++){');
			Win1.document.writeln('        numLimit1++');
			Win1.document.writeln('        strTextID += aryHead[numRunningTotal1]');
			Win1.document.writeln('        if ((numLimit1 % 8 == 0) || numLimit1 == aryHead.length) {');
			Win1.document.writeln('          strTextID += "</TR><TR>"');
			Win1.document.writeln('          startCol = numLimit1 - 7');
			Win1.document.writeln('          //alert("Start Col: " + startCol)');
			Win1.document.writeln('          endCol = numLimit1');
			Win1.document.writeln('          //alert("End Col: " + endCol)');
			Win1.document.writeln('          //alert("Row Number: " + rowNumber)');
			Win1.document.writeln('          for (numRunningTotal2;numRunningTotal2 < aryCells.length; numRunningTotal2++){');
			Win1.document.writeln('            for (colCheck = startCol;colCheck < endCol; colCheck++){');
			Win1.document.writeln('              //alert("RowNumber: " + rowNumber);');
			Win1.document.writeln('              //alert("Head Length: " + aryHead.length);');
			Win1.document.writeln('              //alert("col Check: " + colCheck);');
			Win1.document.writeln('              //alert("Running Total: " + numRunningTotal2);');
			Win1.document.writeln('              //alert((((rowNumber - 1) * aryHead.length) + colCheck));');
			Win1.document.writeln('              if (numRunningTotal2 == (((rowNumber * aryHead.length) + colCheck)) - 1) {');
			Win1.document.writeln('                strTextID += aryCells[numRunningTotal2]');
			Win1.document.writeln('              }');
			Win1.document.writeln('            }');
			Win1.document.writeln('            if ((numRunningTotal2 == 8) || (numRunningTotal2 % 8 == 0 && numRunningTotal2 != 0)) {');
			Win1.document.writeln('              rowNumber++');
			Win1.document.writeln('              strTextID += "</TR><TR>"');
			Win1.document.writeln('            }');
			Win1.document.writeln('          }');
			Win1.document.writeln('        }');
			Win1.document.writeln('      }');
			Win1.document.writeln('    }');
			Win1.document.writeln('  }');
			Win1.document.writeln(' strTextID += "</TBODY></TABLE>"');
			Win1.document.writeln(' writePage();');
			Win1.document.writeln('}');
                        Win1.document.writeln(' ');
			Win1.document.writeln('function writePage() {');
                        Win1.document.writeln('Win2 = window.open("","ReportWindow","width=675,height=240,scrollbars,resizable,alwaysRaised,toolbar");');
			Win1.document.writeln('Win2.document.writeln("<html><head><title>Query/Selection Results</title></head>");');
			Win1.document.writeln('Win2.document.writeln(strTextID);');
			Win1.document.writeln('}');
			Win1.document.writeln('</SCRIPT></head>');
			Win1.document.writeln('<BODY link="Red" vlink="Blue" LEFTMARGIN=0 onload="printWarning();">');
			Win1.document.writeln('<TABLE WIDTH="100%" BORDER="2" BORDERCOLOR="#003366" CELLSPACING="0" CELLPADDING="2" NOWRAP>');
			Win1.document.writeln('	<TR>');
			Win1.document.writeln('		<TH COLSPAN="2" bgcolor="#3399FF"><Font size="+1" color="#330066">GVMC Transportation Division Query Results</FONT></TH>');
			Win1.document.writeln('	</TR>');
			Win1.document.writeln('<TR><TD colspan="2">');
       			if ((toolMode == 19) && (tipProjectWinSetting == 4)) {
				bufGetAttribute = true;
				Win1.document.writeln('<center><FONT FACE="Arial" SIZE="-1" ><b>All TIP projects within '+resultPrintDistance+' '+resultPrintUnits+' of '+resultPrintSource+'</b>');
			} else if (bufGetAttribute) {
				Win1.document.writeln('<center><FONT FACE="Arial" SIZE="-1" ><b>' + LayerName[bufferTargetLayerIndex] + '</b>');
			} else {	
			Win1.document.write('<center><FONT FACE="Arial" SIZE="4" ><b>Results from ' + LayerName[ActiveLayerIndex] + '</b></font>');
			}
			Win1.document.writeln('<br><br><table border="1" cellspacing="0" cellpadding="1"');
		endpos = 1;
		for (var i=0;i<fCount;i++) {
			//alert(endpos);
			if (toolMode != 4) {
				var theXYs = getEnvelopeXYs(theReply, endpos)
				//selectLeft[selectCount] = theXYs[0];
				//selectBottom[selectCount] = theXYs[1];
				//selectRight[selectCount] = theXYs[2];
				//selectTop[selectCount] = theXYs[3];
				endpos = xmlEndPos;
                                 
                                // CVG Code added to Zoom to Extent of selected features - CVG
                                if( i == 0 ) {
                                	var maxLeft = theXYs[0];
                                	var maxBottom = theXYs[1];
                                	var maxRight = theXYs[2];
                                	var maxTop = theXYs[3];
                                } else {
                                	var maxLeft = Math.min( maxLeft, theXYs[0] );
                                	var maxBottom = Math.min( maxBottom, theXYs[1] );
                                	var maxRight = Math.max( maxRight, theXYs[2] );
                                	var maxTop = Math.max( maxTop, theXYs[3] );
                                }
			}
			//alert(endpos);
			inData = parseRecordString(theReply, endpos);
			endpos = xmlEndPos;
			selectedData = clearLeadingSpace(inData);
			
			epos = theReply.indexOf("</FEATURE",endpos);
			if (showSelectedData) {
				//alert("2\n" + selectedData);
				var showHyper = false;
				if (hyperLinkLayers!=null) {
					for (var s1=0;s1<hyperLinkLayers.length;s1++) {
						if (hyperLinkLayers[s1] == LayerName[ActiveLayerIndex]) showHyper=true;
					}
				}
				var fName = getFieldNames(selectedData);
				var fValue = getFieldValues(selectedData);
                                 //alert(fName);
                                // Bob - The following code removes the ID and Shape fields from the fName and fValue strings
				var currentName = "";
				var currentValue = "";
				var y = 0;
				var fName1 = new Array();
				var fValue1 = new Array();
				var fName2 = new Array();


				var fValue2 = new Array();
				for(var z = 0;z<fName.length;z++) {
					currentName = fName[z];
					currentValue = fValue[z];
					if ((currentName.indexOf("SE_ROW_ID") == -1) && (currentName.indexOf(".FID") == -1)&& (currentName.indexOf("#SHAPE#") == -1) && (currentName.indexOf("#ID#") == -1)) {
						fName1[y] = currentName;
						fValue1[y] = currentValue;
						y++;
					}
				}	 
				selectPoints[selectCount] = getIdValue(fName1, fValue1);

				//now we eliminate fields without aliases listed in imsParams
				var q = 0;
				for (var f=0;f<fName1.length;f++) {
					if (useFieldAlias) {
						for (var f3=0;f3<AliasFieldName.length;f3++) {
							if (AliasFieldName[f3]==fName1[f]) {
								fName2[q] = fName1[f];
								fValue2[q] = fValue1[f];
								q++;
							}
						}
					}
				}	
				if (selectCount==0) {
					Win1.document.write('<tr>');
					for (var f=0;f<fName2.length;f++) {
						var f2 = -1;
						if (useFieldAlias) {
							for (var f3=0;f3<AliasFieldName.length;f3++) {
								if (AliasFieldName[f3]==fName2[f]) f2=f3;
							}
						}
						if (f2!=-1) {
							Win1.document.write('<th><FONT FACE="Arial" STYLE="Bold" SIZE="-2">' + AliasFieldAlias[f2] + '</FONT></a></th>');
						}
					}
					Win1.document.writeln('</tr>');
				}
				Win1.document.write('<tr>');
				for (var f=0;f<fName2.length;f++) {	
					Win1.document.write('<TD valign="top">');
					var isHyper=false;
					if (showHyper) {
						for (var s1=0;s1<hyperLinkFields.length;s1++) {
							if (hyperLinkFields[s1]==fName2[f]) {
								Win1.document.write('<a href="' + fValue2[f] + '" target="_blank">');
								isHyper=true;
							}

						}
					}
					var s2 = -1;
					for (var s1=0;s1<LayerFields.length;s1++) {
						if (fName2[f]==LayerFields[s1]) s2=s1;
					}

					if (LayerFieldType[s2]=="91") {
						//alert(fName2[f]);
						if (isNaN(fValue2[f])) {
							var theDate = fValue2[f];
						} else {
							//var theDate = new Date(parseInt(fValue2[f]));
							var theDateObj = new Date(parseFloat(fValue2[f]));
                                                        // CVG Modified Date format to Locale rather than GMT
							var theDate = theDateObj.toLocaleString();
						}
						Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + theDate + '</FONT>');
						theDate=null;
					} else {
						Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + fValue2[f] + '</FONT>');
					}
					if (isHyper) Win1.document.write('</a>');
					Win1.document.writeln('</td>');
				}
				Win1.document.writeln('</tr>');
				fName1 = null;


				fValue1 = null;
				fName2 = null;
				fValue2 = null;
				
			}
			selectCount += 1;
					
		}
		if (showSelectedData) {
			
			Win1.document.writeln('</table>');
			Win1.document.writeln('</font>');
			Win1.document.writeln('</TD></tr>');
			Win1.document.writeln('	<TR>');
			Win1.document.writeln('<TD height="35" bgcolor="#3399FF">');
			Win1.document.writeln('<div align="center"><font size="1" color="#330066"><b>');
			Win1.document.writeln('This table does not represent a legal document.  It is intended to serve as an aid in graphic');
			Win1.document.writeln(' representation only.  Information shown in this table is not warranted for accuracy and should');
			Win1.document.writeln(' be verified through other means');
			Win1.document.writeln('</b></div></font>');
			Win1.document.writeln('		</TD>');
			Win1.document.writeln('		<TD HEIGHT="35">');
			Win1.document.writeln('			<IMG SRC="http://'+hostName+'/website/transportation/images/GVMC-Logo.gif" WIDTH=95 height=30>');
			Win1.document.writeln('</TD>');
			Win1.document.writeln('	</TR>');
			Win1.document.writeln('</table>');
			Win1.document.writeln('</center></body></html>');
			Win1.document.close();
			Win1.resizeTo(Win1.screen.width,Win1.screen.height);
			Win1.moveTo(0,0);
		}			
	} else {
		alert("There are no results to display.");
		Win1.close();
	}
}

function multiTablePrint() {
	generateStartPrint();
	//Loop through the replies and print each table
	for (var y=0;y<selectedIdentifyReplies.length;y++) {
		fullSetActiveLayer(selectedIdentifyLayers[y]);
		generateResultsPrint(selectedIdentifyReplies[y]);
	}
	generateEndPrint();
	}

//part of automated identify sequence. Places opening set of HTML code for document
function generateStartPrint(){
	tablePrintWin = window.open("","PrintWindow");
	tablePrintWin.document.open();
	var Win1 = tablePrintWin;
	Win1.document.writeln('<html><head><title>Query/Selection Results</title>');
	Win1.document.writeln('<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">');
	Win1.document.writeln('var t;');
	Win1.document.writeln('var par;');
	Win1.document.writeln(' if (opener) {  ');
	Win1.document.writeln(' 	if (opener.name=="MapFrame") {  ');
	Win1.document.writeln(' 		t = opener.parent.MapFrame;  ');
	Win1.document.writeln('			par = opener.parent;  ');
	Win1.document.writeln(' 	} else {  ');
	Win1.document.writeln('	        	t = opener; ');
	Win1.document.writeln('			par = opener;  ');
	Win1.document.writeln('		}  ');
	Win1.document.writeln(' } else {  ');
	Win1.document.writeln('		if (parent.MapFrame) {  ');
	Win1.document.writeln('			t = parent.MapFrame;  ');
	Win1.document.writeln('			par = parent;  ');
	Win1.document.writeln('		} else {  ');
	Win1.document.writeln('			t=document;  ');
	Win1.document.writeln('		}  ');
	Win1.document.writeln('	}  ');
	Win1.document.writeln('	function printWarning() { ');
	Win1.document.writeln('	alert("This page is constructed to be printed using Landscape layout. Be sure you change your print settings from Portrait to Landscape before you print this page!")');
	Win1.document.writeln('	window.focus(); ');
	Win1.document.writeln('	} ');
	Win1.document.writeln('</SCRIPT></head>');
	Win1.document.writeln('<BODY link="Red" vlink="Blue" LEFTMARGIN=0 onload="printWarning();">');
	Win1.document.writeln('<TABLE WIDTH="100%" BORDER="2" BORDERCOLOR="#003366" CELLSPACING="0" CELLPADDING="2" NOWRAP>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TH COLSPAN="2" bgcolor="#3399FF"><Font size="+1" color="#330066">GVMC Transportation Division Query Results</FONT></TH>');
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">');
	Win1.document.writeln('var srtTextID=""');
	Win1.document.writeln('function extract() {');
	Win1.document.writeln('    if (document.all){');
	Win1.document.writeln('    var aryHead = new Array();');
	Win1.document.writeln('    var aryCells = new Array();');
	Win1.document.writeln('    var aryCount=0');
	Win1.document.writeln('        for (var i=0;i < parent.TextFrame.document.all.length; i++){');
	Win1.document.writeln('		//alert(parent.TextFrame.document.all(i).tagName);');
	Win1.document.writeln('            if (parent.TextFrame.document.all(i).tagName == "TH"){');
	Win1.document.writeln('              aryHead[aryCount] = parent.TextFrame.document.all(i).outerHTML');
	Win1.document.writeln('              aryCount++');
	Win1.document.writeln('            } ');
	Win1.document.writeln('         }');
	Win1.document.writeln('         aryCount = 0');
	Win1.document.writeln('         for (var i=0;i < parent.TextFrame.document.all.length; i++){');
	Win1.document.writeln('            if (parent.TextFrame.document.all(i).tagName == "TD"){');
	Win1.document.writeln('               aryCells[aryCount] = parent.TextFrame.document.all(i).outerHTML');
	Win1.document.writeln('              aryCount++');
	Win1.document.writeln('            } ');
	Win1.document.writeln('         } ');   
	Win1.document.writeln('      formatTable(aryHead,aryCells);');
	Win1.document.writeln('    }');
	Win1.document.writeln('}');
	Win1.document.writeln('function formatTable(aryHead,aryCells) {');
	Win1.document.writeln('  alert(aryHead,aryCells);');
	Win1.document.writeln('  strTextID = "<TABLE width=\'600\' bgColor=white border=1 cellPadding=0 cellSpacing=0><TBODY>";');
	Win1.document.writeln('  numMax = Math.ceil(aryHead.length / 8)');
	Win1.document.writeln('  numLimit1 = 0');
	Win1.document.writeln('  numLimit2 = 0');
	Win1.document.writeln('  numRunningTotal1 = 0');
	Win1.document.writeln('  numRunningTotal2 = 0');
	Win1.document.writeln('  rowNumber = 0');
	Win1.document.writeln('  //alert(aryHead.length);');
	Win1.document.writeln('  if (aryHead.length <= 8) {');
        Win1.document.writeln('    //alert("Case 1");');
	Win1.document.writeln('    for (var j=0;j < numMax;j++){');
	Win1.document.writeln('      strTextID += "<TR>"');
	Win1.document.writeln('      for (numRunningTotal1;numRunningTotal1 < aryHead.length; numRunningTotal1++){');
	Win1.document.writeln('        numLimit1++');
	Win1.document.writeln('        strTextID += aryHead[numRunningTotal1]');
	Win1.document.writeln('      }');
	Win1.document.writeln('      numRunningTotal1++');
	Win1.document.writeln('      numLimit1 = 0');
	Win1.document.writeln('      strTextID += "</TR>"');
	Win1.document.writeln('      for (numRunningTotal2;numRunningTotal2 < aryCells.length; numRunningTotal2++){');
	Win1.document.writeln('        numLimit2++');
	Win1.document.writeln('        strTextID += aryCells[numRunningTotal2]');
	Win1.document.writeln('        if (numLimit2 == 8 || numLimit2 == aryHead.length) {');
	Win1.document.writeln('          numLimit2 = 0');
	Win1.document.writeln('          strTextID += "</TR><TR>"');
	Win1.document.writeln('        }');
	Win1.document.writeln('      }');
	Win1.document.writeln('      strTextID += "</TR>"');
	Win1.document.writeln('    }');
	Win1.document.writeln('  } else { ');
        Win1.document.writeln('    //alert("Case 2");');
        Win1.document.writeln('    alert("More than eight attributes present.  Unable to print.");');
        Win1.document.writeln('    return;');
	Win1.document.writeln('    for (var j=0;j < numMax;j++){');
	Win1.document.writeln('      strTextID += "<TR>"');
	Win1.document.writeln('      for (numRunningTotal1;numRunningTotal1 < aryHead.length; numRunningTotal1++){');
	Win1.document.writeln('        numLimit1++');
	Win1.document.writeln('        strTextID += aryHead[numRunningTotal1]');
	Win1.document.writeln('        if ((numLimit1 % 8 == 0) || numLimit1 == aryHead.length) {');
	Win1.document.writeln('          strTextID += "</TR><TR>"');
	Win1.document.writeln('          startCol = numLimit1 - 7');
	Win1.document.writeln('          //alert("Start Col: " + startCol)');
	Win1.document.writeln('          endCol = numLimit1');
	Win1.document.writeln('          //alert("End Col: " + endCol)');
	Win1.document.writeln('          //alert("Row Number: " + rowNumber)');
	Win1.document.writeln('          for (numRunningTotal2;numRunningTotal2 < aryCells.length; numRunningTotal2++){');
	Win1.document.writeln('            for (colCheck = startCol;colCheck < endCol; colCheck++){');
	Win1.document.writeln('              //alert("RowNumber: " + rowNumber);');
	Win1.document.writeln('              //alert("Head Length: " + aryHead.length);');
	Win1.document.writeln('              //alert("col Check: " + colCheck);');
	Win1.document.writeln('              //alert("Running Total: " + numRunningTotal2);');
	Win1.document.writeln('              //alert((((rowNumber - 1) * aryHead.length) + colCheck));');
	Win1.document.writeln('              if (numRunningTotal2 == (((rowNumber * aryHead.length) + colCheck)) - 1) {');
	Win1.document.writeln('                strTextID += aryCells[numRunningTotal2]');
	Win1.document.writeln('              }');
	Win1.document.writeln('            }');
	Win1.document.writeln('            if ((numRunningTotal2 == 8) || (numRunningTotal2 % 8 == 0 && numRunningTotal2 != 0)) {');
	Win1.document.writeln('              rowNumber++');
	Win1.document.writeln('              strTextID += "</TR><TR>"');
	Win1.document.writeln('            }');
	Win1.document.writeln('          }');
	Win1.document.writeln('        }');
	Win1.document.writeln('      }');
	Win1.document.writeln('    }');
	Win1.document.writeln('  }');
	Win1.document.writeln(' strTextID += "</TBODY></TABLE>"');
	Win1.document.writeln(' writePage();');
	Win1.document.writeln('}');
        Win1.document.writeln(' ');
	Win1.document.writeln('</SCRIPT>');
	Win1.document.writeln('<div align="center">');				
}

//part of automated identify sequence. Places results into HTML document
function generateResultsPrint(theReply){
	var theError = getXMLErrorMessage(theReply);
	var fList="";
	var lpos1 = 1;
	var lpos2 = 1;
	var epos = 1;
	var spos = 1;
	var morePoints=true;
	var moreFeatures=true;
	var featureCount = justGetFeatureCount(theReply);
	var pos = 0;
	var startpos = 0;
	var endpos = xmlEndPos;
	var stillMore = false
	pos = theReply.indexOf('hasmore="true"',endpos);
	if (pos!=-1) stillMore = true;
	pos=0;
	var tempCount = 0;
	var selectedData="";
	var inData="";
	var xStr="";
	var yStr="";
	var eNorth="";
	var eSouth="";
	var eWest="";
	var eEast="";
	var fCount = featureCount;
	selectCount = 0;
	var tempString="";
	var Win1 = tablePrintWin;
	var theFrame = "parent.MapFrame";
	Win1.document.writeln('<tr><td colspan="2" align="center">');
	if (featureCount > 0) {
		Win1.document.writeln('<FONT COLOR="Black" FACE="Arial"><b>Results from ' + LayerName[ActiveLayerIndex] + '</b></font>');
		Win1.document.writeln('<table border="1" cellspacing="0" cellpadding="2" nowrap>');
		newSelectCount += 1;
		endpos = 1;
		var intEndPos = theReply.lastIndexOf("</FEATURE>");
		var strReplyEnd = theReply.slice(intEndPos);
		var intEnvelopePos = strReplyEnd.indexOf("<ENVELOPE");
		for (var i=0;i<fCount;i++) {
			//alert(endpos);
			if (toolMode != 4) {
				var theXYs = getEnvelopeXYs(theReply, endpos)
				//selectLeft[selectCount] = theXYs[0];
				//selectBottom[selectCount] = theXYs[1];
				//selectRight[selectCount] = theXYs[2];
				//selectTop[selectCount] = theXYs[3];
				endpos = xmlEndPos;
                                 
                                // CVG Code added to Zoom to Extent of selected features - CVG
                                if( i == 0 ) {
                                	var maxLeft = theXYs[0];
                                	var maxBottom = theXYs[1];
                                	var maxRight = theXYs[2];
                                	var maxTop = theXYs[3];
                                } else {
                                	var maxLeft = Math.min( maxLeft, theXYs[0] );
                                	var maxBottom = Math.min( maxBottom, theXYs[1] );
                                	var maxRight = Math.max( maxRight, theXYs[2] );
                                	var maxTop = Math.max( maxTop, theXYs[3] );
                                }
			}
			//alert(endpos);
			inData = parseRecordString(theReply, endpos);
			endpos = xmlEndPos;
			selectedData = clearLeadingSpace(inData);
			
			epos = theReply.indexOf("</FEATURE",endpos);
			if (showSelectedData) {
				//alert("2\n" + selectedData);
				var showHyper = false;
				if (hyperLinkLayers!=null) {
					for (var s1=0;s1<hyperLinkLayers.length;s1++) {
						if (hyperLinkLayers[s1] == LayerName[ActiveLayerIndex]) showHyper=true;
					}
				}
				var fName = getFieldNames(selectedData);
				var fValue = getFieldValues(selectedData);
                                 //alert(fName);
                                // Bob - The following code removes the ID and Shape fields from the fName and fValue strings
				var currentName = "";
				var currentValue = "";
				var y = 0;
				var fName1 = new Array();
				var fValue1 = new Array();
				var fName2 = new Array();
				var fValue2 = new Array();
				for(var z = 0;z<fName.length;z++) {
					currentName = fName[z];

					currentValue = fValue[z];
					if ((currentName.indexOf("SE_ROW_ID") == -1) && (currentName.indexOf(".FID") == -1)&& (currentName.indexOf("#SHAPE#") == -1) && (currentName.indexOf("#ID#") == -1)) {
						fName1[y] = currentName;
						fValue1[y] = currentValue;
						y++;
					}
				}	 
				selectPoints[selectCount] = getIdValue(fName1, fValue1);

				//now we eliminate fields without aliases listed in imsParams
				var q = 0;
				for (var f=0;f<fName1.length;f++) {
					if (useFieldAlias) {
						for (var f3=0;f3<AliasFieldName.length;f3++) {
							if (AliasFieldName[f3]==fName1[f]) {
								fName2[q] = fName1[f];
								fValue2[q] = fValue1[f];
								q++;
							}
						}
					}
				}
					
				if (selectCount==0) {
					Win1.document.write('<tr><th><FONT FACE="Arial" SIZE="-2">Rec</FONT></a></th>');
					for (var f=0;f<fName2.length;f++) {
						var f2 = -1;
						if (useFieldAlias) {
							for (var f3=0;f3<AliasFieldName.length;f3++) {
								if (AliasFieldName[f3]==fName2[f]) f2=f3;
							}
						}
						if (f2!=-1) {
							Win1.document.write('<th><FONT FACE="Arial" STYLE="Bold" SIZE="-2">' + AliasFieldAlias[f2] + '</FONT></a></th>');
						}
					}
					Win1.document.writeln('</tr>');
				}
				Win1.document.write('<tr><td>');
				if (toolMode == 4) Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + (selectCount+queryStartRecord+1) + '</FONT>');
				Win1.document.writeln('</td>');
				for (var f=0;f<fName2.length;f++) {	
					Win1.document.write('<TD valign="top">');
					var isHyper=false;
					if (showHyper) {
						for (var s1=0;s1<hyperLinkFields.length;s1++) {
							if (hyperLinkFields[s1]==fName2[f]) {
								Win1.document.write('<a href="' + fValue2[f] + '" target="_blank">');
								isHyper=true;
							}

						}
					}
					var s2 = -1;
					for (var s1=0;s1<LayerFields.length;s1++) {
						if (fName2[f]==LayerFields[s1]) s2=s1;
					}

					if (LayerFieldType[s2]=="91") {
						//alert(fName2[f]);
						if (isNaN(fValue2[f])) {
							var theDate = fValue2[f];
						} else {
							//var theDate = new Date(parseInt(fValue2[f]));
							var theDateObj = new Date(parseFloat(fValue2[f]));
                                                        // CVG Modified Date format to Locale rather than GMT
							var theDate = theDateObj.toLocaleString();
						}
						Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + theDate + '</FONT>');
						theDate=null;
					} else {
						Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + fValue2[f] + '</FONT>');
					}
					if (isHyper) Win1.document.write('</a>');
					Win1.document.writeln('</td>');
				}
				Win1.document.writeln('</tr>');
				fName1 = null;


				fValue1 = null;
				fName2 = null;
				fValue2 = null;
				
			}
			selectCount += 1;
					
		}		
		Win1.document.writeln('</table></font>');		
	} else {
		Win1.document.writeln('<br>');
		Win1.document.writeln('<HR width="60%">');
		Win1.document.writeln('<div align="center">');
		Win1.document.writeln('<FONT FACE="Arial" color="black"><B>' + LayerName[ActiveLayerIndex] +'</B></font><FONT FACE="Arial" size="-2" color="black">');
		Win1.document.writeln('<br>No Features Found.</div>');
		Win1.document.writeln('<HR width="60%">');
		if (debugOn>0) {
			Win1.document.writeln('<p>Returned ArcXML Response:<br>');
			Win1.document.writeln(untag(theReply));
		} else {
			if (theError!="") {
				Win1.document.writeln('<p>Server returned:<br>');
				Win1.document.writeln(theError);
			}
		}	
		Win1.document.writeln('</FONT>');
	}
	Win1.document.writeln('</td></tr>');
}

//part of automated identify sequence. Places closing set of HTML code for document
function generateEndPrint(){
	var Win1 = tablePrintWin;
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('<TD height="35" bgcolor="#3399FF">');
	Win1.document.writeln('<div align="center"><font size="1" color="#330066"><b>');
	Win1.document.writeln('This table does not represent a legal document.  It is intended to serve as an aid in graphic');
	Win1.document.writeln(' representation only.  Information shown in this table is not warranted for accuracy and should');
	Win1.document.writeln(' be verified through other means');
	Win1.document.writeln('</b></div></font>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('		<TD HEIGHT="35">');
	Win1.document.writeln('			<IMG SRC="http://'+hostName+'/website/transportation/images/GVMC-Logo.gif" WIDTH=95 height=30>');
	Win1.document.writeln('</TD>');
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('</table>');
	Win1.document.writeln('</center></body></html>');
	tablePrintWin.document.close();
}


