// aimsCustom.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,
*/

// global variables
	aimsCustomPresent=true;
	// change these to send XML response to custom function.
	// use numbers >= 1000 and match in useCustomFunction()
	// defaults are defined in aimsXML.js and use standard functions
	
	// xml response mode for selection
	selectXMLMode = 6;
	// xml response mode for identify
	identifyXMLMode = 7;
	// xml response mode for query
	queryXMLMode = 8;
	// xml response mode for find
	findXMLMode = 14;
	// xml response mode hyperlink
	hyperlinkXMLMode = 15;

	var geocodeX;
	var geocodeY;
	var searchFeatureX;
	var searchFeatureY;
	var searchFeatureMaxX;
	var searchFeatureMaxY;
	
	var blnGeocodeResultsDone = false;
	
// custom function for handling clicks 
// 		flow redirected here when
//		toolMode set to >=1000
function customMapTool(e) {
//alert("customMapTool");
				if (toolMode == 1001) {
						// insert code here
						return false;
					
				}
				if (toolMode == 1002) {
						// insert code here

				}

}

// send  XML response to custom function
//		flow  redirected here when
//		XMLMode >=1000
function useCustomFunction(theReply) {
//alert("useCustomFunction, theReply = " + theReply);
	if (XMLMode==1001) {
		// insert code here
	} else if (XMLMode==1002) {
		// insert code here
	} else {
		alert(msgList[55] + XMLMode + msgList[56]);
	}
	hideLayer("LoadData");
}

// add custom stuff to Map XML request. . . between selection and geocode
function addCustomToMap1(){
//alert("addCustomToMap1");
	var customString = "";
	/*
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		customString += '<OBJECT units="PIXEL">\n<TEXT coord="5,' + (iHeight-10) + '" label="This is a test">\n';
		customString += '<TEXTMARKERSYMBOL fontstyle="BOLD" fontsize="12" font="ARIAL" fontcolor="' + modeMapColor + '" ';
		customString += 'threed="TRUE" glowing="' + modeMapGlow + '" />\n</TEXT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
	*/
	return customString;
}

// add custom stuff to Map XML request. . . between clickpoints and copyright
function addCustomToMap2(){
//alert("addCustomToMap2");
	var customString = "";
	
	return customString;
}

// add custom stuff to Map XML request. . . under modeOnMap
function addCustomToMap3(){
	var customString = "";
		/*
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		customString += '<OBJECT units="PIXEL">\n<TEXT coord="5,' + (iHeight-10) + '" label="This is a test">\n';
		customString += '<TEXTMARKERSYMBOL fontstyle="BOLD" fontsize="12" font="ARIAL" fontcolor="' + modeMapColor + '" ';
		customString += 'threed="TRUE" glowing="' + modeMapGlow + '" />\n</TEXT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
		alert(customString);
		*/
	// START - FRANK
	//alert("addCustomToMap3, blnQueryExecuted1 = " + parent.InfoFrame.blnQueryExecuted1);
	//if ((BPDCustomPresent) && (parent.InfoFrame.blnQueryExecuted1 == "false")) {
	if (BPDCustomPresent) {
		customString = addCustomSelectToMap();
		parent.InfoFrame.blnQueryExecuted1 = "true";
	}
	// END - FRANK
	
	return customString;
}

// add custom stuff to Map XML request. . . on top of everything
function addCustomToMap4(){
	var customString = "";
	
	// START - FRANK
	if (BPDCustomPresent) {
		customString = addBPDCircleToMap4();
		parent.InfoFrame.blnQueryExecuted2 = "true";
	}
	// END - FRANK
	
	return customString;
}

// extract layers to download
function extractIt() {
//alert("extractIt");
	hideLayer("measureBox");
	alert(msgList[51]);
}

//
// added by Frank Xia for Baltimore Police Dept. Fighting Crime Online Project
// 03-20-2001
// START - FRANK

var BPDCustomPresent = true;
var BPDX;
var BPDY;
var BPDmaxX;
var BPDmaxY;
var BPDRadius;
var BPDCrimeType;
var BPDSelectPresent = false;
var customPointX = new Array();
var customPointY = new Array();
var BPDCircleColor = '225, 50, 50';
var BPDSelectColor = '225, 10, 10';

// send in XML request and get XML response - uses helper applet
function sendToServerBPD(URLString,XMLRequest) {
//alert("sendToServerBPD, URLString / XMLRequest = " + URLString + " / " + XMLRequest);
	// alert("cmd=" + parent.ListFrame.command);
	
	if (parent.PostFrame.document.forms[0]!=null) {
		var theForm = parent.PostFrame.document.forms[0];
		URLString = URLString + cVersion;
		var requestURL = URLString;

		// alert(URLString);
		if (doURLencode) {
			theForm.action = requestURL + "&Form=True&Encode=True";
		} else {
			theForm.action = requestURL + "&Form=True&Encode=False";
		}
		var xmlHeader = '<?xml version="1.0" ' + localeEncoding + '?>';
		theForm.ArcXMLRequest.value = xmlHeader + XMLRequest;
		//if (theForm.FormCharset!=null) theForm.FormCharset.value = charEncoding;
		if (theForm.FormCharset!=null) theForm.FormCharset.value = charSet;				
		if (theForm.BgColor!=null) theForm.BgColor.value = formColor;
		
		theForm.JavaScriptFunction.value = "parent.MapFrame.parseGeocodeResultsBPD";
		// alert("ServiceName: " + theForm.action + "\nXMLRequest:\n " + theForm.ArcXMLRequest.value);
				
		theForm.submit();			
	}  
}

// parse out geocode response and display results in table
function parseGeocodeResultsBPD(theReply) {
//alert("parseGeocodeResultsBPD, theReply = " + theReply);

	blnGeocodeResultsDone = true;
	
	GCscore.length=1;
	if (parent.ListFrame.command == "address") {
		var pos = theReply.indexOf("<GCCOUNT count=");
		var lpos = 0;
		var startpos = pos + 16;
		var startpos2=0;
		var endpos = theReply.indexOf(dQuote,startpos);
		var fString = theReply.substring(startpos,endpos);
		GCpointCount=parseInt(fString);
		var gcCount=0;
		if ((pos>0) && (GCpointCount>0)) {
			pos = theReply.indexOf("<FEATURE");
			if (pos!=-1) {
				while (pos!=-1) {
					lpos = theReply.indexOf("<FIELD",pos);
					if (lpos!=-1) {
							startpos2 = theReply.indexOf('name="SCORE"',lpos);
							startpos = theReply.indexOf("FIELDVALUE valuestring=",startpos2);
							startpos = startpos + 24;
							endpos = theReply.indexOf(dQuote,startpos);
							GCscore[gcCount] = theReply.substring(startpos,endpos);
							startpos2 = theReply.indexOf('name="ADDRESSFOUND"',lpos);
							startpos = theReply.indexOf("FIELDVALUE valuestring=",startpos2);
							startpos = startpos + 24;
							endpos = theReply.indexOf(dQuote,startpos);
							GCaddress[gcCount] = theReply.substring(startpos,endpos);
							startpos2 = theReply.indexOf('name="SHAPEFIELD"',lpos);
							startpos = theReply.indexOf("<POINT x=",startpos2);
							startpos += 10;
							endpos = theReply.indexOf(dQuote,startpos);
							GCpointX[gcCount] = theReply.substring(startpos,endpos);
							startpos = theReply.indexOf("y=",endpos);
							startpos = startpos + 3;
							endpos = theReply.indexOf(dQuote,startpos);
							GCpointY[gcCount] = theReply.substring(startpos,endpos);
							gcCount++;
					}
					pos = theReply.indexOf("<FEATURE",endpos);
				}
			}
						
			showGeocode=true;
			
			if (GCpointCount > 1) {
				var newURL = parent.document.location.href;
				newURL = newURL.substring(0, newURL.lastIndexOf("/"));
				var userSelections = 'CrimeType=' + parent.ListFrame.crime;
				userSelections += '&Cmd=' + parent.ListFrame.command;
				userSelections += '&StartMonth=' + parent.ListFrame.startmonth;
				userSelections += '&StartDay=' + parent.ListFrame.startday;
				userSelections += '&StartYear=' + parent.ListFrame.startyear;
				userSelections += '&NumDays=' + parent.ListFrame.numdays;
				userSelections += '&QueryText=' + parent.ListFrame.address;
				userSelections += '&BPDRadius=' + parent.ListFrame.radius;

				var intCnt;
				var intChoice;
				
				userSelections += "&Count=" + GCpointCount;
				for (intCnt = 0; intCnt < GCpointCount; intCnt++) {
					userSelections += "&Address=" + GCaddress[intCnt] + "&BPDX=" + GCpointX[intCnt] + "&BPDY=" + GCpointY[intCnt];
				}
				
				parent.document.location.href = newURL + "/multimatch.htm?" + escape(userSelections);
				
			} else if (GCpointCount == 1) {
				geocodeX=GCpointX[0];
				geocodeY=GCpointY[0];
				geocodeLabel=GCaddress[0];

				var newURL = parent.document.location.href;
				newURL = newURL.substring(0, newURL.lastIndexOf("/"));
				var userSelections = 'CrimeType=' + parent.ListFrame.crime;
				userSelections += '&Cmd=' + parent.ListFrame.command;
				userSelections += '&StartMonth=' + parent.ListFrame.startmonth;
				userSelections += '&StartDay=' + parent.ListFrame.startday;
				userSelections += '&StartYear=' + parent.ListFrame.startyear;
				userSelections += '&NumDays=' + parent.ListFrame.numdays;
				userSelections += '&BPDX=' + geocodeX;
				userSelections += '&BPDY=' + geocodeY;		
				userSelections += '&QueryText=' + parent.ListFrame.address;
				userSelections += '&BPDRadius=' + parent.ListFrame.radius;

				parent.document.location.href = newURL + "/default.htm?" + escape(userSelections);
				
			}
 		} else {
 			alert("No matching address found in the database...");
 			//parent.ListFrame.document.location.href = imsHost + "bpd/police_querytype.asp?cmd=address";
 		}
 		
 	} else if (parent.ListFrame.command == "school") {
 		
 		var startPos = theReply.indexOf("<FEATURECOUNT") + 21;
 		var endPos = theReply.indexOf("\"", startPos);
 		var numOfFeatures = theReply.substring(startPos, endPos);
 		
		startPos = theReply.indexOf("minx") + 6;
		endPos = theReply.indexOf("\"", startPos);
 		searchFeatureX = theReply.substring(startPos, endPos);
 		
 		startPos = theReply.indexOf("miny") + 6;
 		endPos = theReply.indexOf("\"", startPos);
 		searchFeatureY = theReply.substring(startPos, endPos);
 		
 		var newURL = parent.document.location.href;
 		newURL = newURL.substring(0, newURL.lastIndexOf("/"));
 		var userSelections = 'CrimeType=' + parent.ListFrame.crime;
 		userSelections += '&Cmd=' + parent.ListFrame.command;
 		userSelections += '&StartMonth=' + parent.ListFrame.startmonth;
 		userSelections += '&StartDay=' + parent.ListFrame.startday;
 		userSelections += '&StartYear=' + parent.ListFrame.startyear;
		userSelections += '&NumDays=' + parent.ListFrame.numdays;
		userSelections += '&BPDX=' + searchFeatureX;
		userSelections += '&BPDY=' + searchFeatureY;
		userSelections += '&QueryText=' + parent.ListFrame.school;
		userSelections += '&BPDRadius=' + parent.ListFrame.radius;
		
		parent.document.location.href = newURL + "/default.htm?" + escape(userSelections);
		
 	} else if ((parent.ListFrame.command == "neighborhood") || (parent.ListFrame.command == "policepost")) {
 	
 		var startPos = theReply.indexOf("<FEATURECOUNT") + 21;
 		var endPos = theReply.indexOf("\"", startPos);
 		var numOfFeatures = theReply.substring(startPos, endPos);
 		
		startPos = theReply.indexOf("minx") + 6;
		endPos = theReply.indexOf("\"", startPos);
 		searchFeatureX = theReply.substring(startPos, endPos);
 		
 		startPos = theReply.indexOf("miny") + 6;
 		endPos = theReply.indexOf("\"", startPos);
 		searchFeatureY = theReply.substring(startPos, endPos);
 		
		startPos = theReply.indexOf("maxx") + 6;
		endPos = theReply.indexOf("\"", startPos);
 		searchFeatureMaxX = theReply.substring(startPos, endPos);
 		
 		startPos = theReply.indexOf("maxy") + 6;
 		endPos = theReply.indexOf("\"", startPos);
 		searchFeatureMaxY = theReply.substring(startPos, endPos);
 		
 		var newURL = parent.document.location.href;
 		newURL = newURL.substring(0, newURL.lastIndexOf("/"));
 		var userSelections = 'CrimeType=' + parent.ListFrame.crime;
 		userSelections += '&Cmd=' + parent.ListFrame.command;
 		userSelections += '&StartMonth=' + parent.ListFrame.startmonth;
 		userSelections += '&StartDay=' + parent.ListFrame.startday;
 		userSelections += '&StartYear=' + parent.ListFrame.startyear;
		userSelections += '&NumDays=' + parent.ListFrame.numdays;
		userSelections += '&BPDX=' + searchFeatureX;
		userSelections += '&BPDY=' + searchFeatureY;
		userSelections += '&BPDmaxX=' + searchFeatureMaxX;
		userSelections += '&BPDmaxY=' + searchFeatureMaxY;
		if (parent.ListFrame.command == "neighborhood") {
			userSelections += '&QueryText=' + parent.ListFrame.neighborhood;
		} else {
			userSelections += '&QueryText=' + parent.ListFrame.policepost;
		}
		userSelections += '&BPDRadius=' + parent.ListFrame.radius;
		
		parent.document.location.href = newURL + "/default.htm?" + escape(userSelections);
 	}
}

function setBPDCustomExtent() {
//alert("setBPDCustomExtent");
	if (BPDmaxX != null) {
		eLeft = BPDX;
		eRight = BPDmaxX;
		eTop = BPDmaxY;
		eBottom = BPDY;
	} else {
		eLeft = BPDX - BPDRadius;
		eRight = BPDX + BPDRadius;
		eTop = BPDY + BPDRadius;
		eBottom = BPDY - BPDRadius;
	}
}

function checkBPDParams() {

	webParams = unescape(webParams);
	if (webParams == "") return;
	
	var cmdString = webParams.toUpperCase();
	var startPos = 0;
	var endPos = 0;
	var pos = cmdString.indexOf("BPDX=");
	if (pos!=-1) {
		startPos = pos + 5;
		endPos = cmdString.indexOf("&", startPos);
		if (endPos == -1) endPos = webParams.length;
		BPDX = Number(webParams.substring(startPos, endPos));
	}
	pos = cmdString.indexOf("BPDY="); 
	if (pos!=-1) {
		startPos = pos + 5;
		endPos = cmdString.indexOf("&", startPos);
		if (endPos == -1) endPos = webParams.length;
		BPDY = Number(webParams.substring(startPos, endPos));
	}
	pos = cmdString.indexOf("BPDMAXX=");
	if (pos != -1) {
		startPos = pos + 8;
		endPos = cmdString.indexOf("&", startPos);
		if (endPos == -1) endPos = webParams.length;
		BPDmaxX = Number(webParams.substring(startPos, endPos));
	}
	pos = cmdString.indexOf("BPDMAXY=");
	if (pos != -1) {
		startPos = pos + 8;
		endPos = cmdString.indexOf("&", startPos);
		if (endPos == -1) endPos = webParams.length;
		BPDmaxY = Number(webParams.substring(startPos, endPos));
	}
	pos = cmdString.indexOf("BPDRADIUS="); 
	if (pos!=-1) {
		startPos = pos + 10;
		endPos = cmdString.indexOf("&", startPos);
		if (endPos == -1) endPos = webParams.length;
		BPDRadius = Number(webParams.substring(startPos, endPos));
		//getRingPoints(BPDRadius); // compute circle's coordinates
	}	
	pos = cmdString.indexOf("CRIMETYPE="); 
	if (pos!=-1) {
		startPos = pos + 10;
		endPos = cmdString.indexOf("&", startPos);
		if (endPos == -1) endPos = webParams.length;
		BPDCrimeType = unescape(webParams.substring(startPos, endPos));
		//alert("crime=" + BPDCrimeType);
	}		
}

function getRingPoints(rHeight){
alert("getRingPoints, rHeight = " + rHeight);
	var angle = 0;
//	alert("BPDX = " + BPDX);
	for (i=0;i<=36;i++) {
		if (BPDmaxX != null) {
			customPointX[i] = (BPDmaxX - (BPDmaxX - BPDX) / 2) + (rHeight * Math.cos(angle*(Math.PI/180)));
			customPointY[i] = (BPDmaxY - (BPDmaxY - BPDY) / 2) + (rHeight * Math.sin(angle*(Math.PI/180)));
		} else {
			customPointX[i] = BPDX + (rHeight * Math.cos(angle*(Math.PI/180)));
			customPointY[i]=  BPDY + (rHeight * Math.sin(angle*(Math.PI/180)));
		}
		angle += 10;
		
		// alert("i="+ i + " x="+ customPointX[i] + " y=" + customPointY[i]);		
	}
	// alert("i=10 x="+ customPointX[10] + " y=" + customPointY[10]);	
}

function addCustomSelectToMap(){
//This function sends the request to the spatial server for crimes in
//the extent of the initial map window after a query.
//alert("addCustomSelectToMap");

	var strCrimeType = parent.InfoFrame.strCrimeType;
	
	var selString = "";
	//selString +='<LAYER type="FeatureClass" name="'+ strCrimeType + '" visible="true">\n';
	selString += '<LAYER type="FeatureClass" name="Crimes" visible="true">\n';
	selString +='<DATASET fromlayer="' + ActiveLayer + '" />\n';
	selString += '<SPATIALQUERY where="' + parent.InfoFrame.strWhereClause;

	selString +='<SPATIALFILTER relation="area_intersection" >\n';
	selString +='<POLYGON>\n<RING>\n';
	
	if (eLeft < parent.InfoFrame.trueInitExtentLeft) {
		parent.InfoFrame.initExtentLeft = parent.InfoFrame.trueInitExtentLeft;
	} else {
		parent.InfoFrame.initExtentLeft = eLeft;
	}
	if (eRight > parent.InfoFrame.trueInitExtentRight) {
		parent.InfoFrame.initExtentRight = parent.InfoFrame.trueInitExtentRight;
	} else {
		parent.InfoFrame.initExtentRight = eRight;
	}
	if (eTop > parent.InfoFrame.trueInitExtentTop) {
		parent.InfoFrame.initExtentTop = parent.InfoFrame.trueInitExtentTop;
	} else {
		parent.InfoFrame.initExtentTop = eTop;
	}
	if (eBottom < parent.InfoFrame.trueInitExtentBottom) {
		parent.InfoFrame.initExtentBottom = parent.InfoFrame.trueInitExtentBottom;
	} else {
		parent.InfoFrame.initExtentBottom = eBottom;
	}

	selString += '<POINT x="' + parent.InfoFrame.initExtentLeft + '" y="' + parent.InfoFrame.initExtentTop + '" />\n';
	selString += '<POINT x="' + parent.InfoFrame.initExtentRight + '" y="' + parent.InfoFrame.initExtentTop + '" />\n';
	selString += '<POINT x="' + parent.InfoFrame.initExtentRight + '" y="' + parent.InfoFrame.initExtentBottom + '" />\n';
	selString += '<POINT x="' + parent.InfoFrame.initExtentLeft + '" y="' + parent.InfoFrame.initExtentBottom + '" />\n';

	selString +='</RING>\n</POLYGON>\n';
	selString +='</SPATIALFILTER>\n';
	selString +='</SPATIALQUERY>\n';
	var tlType = LayerType[ActiveLayerIndex];
	if (tlType=="point") {
		selString += writeCrimesRenderer(strCrimeType);
	} else if (tlType=="line") {
		selString +='<SIMPLERENDERER>\n';
		selString +='<SIMPLELINESYMBOL type="dash" color="' + BPDSelectColor + '" width="2" />\n';
		selString +='</SIMPLERENDERER>\n';
	} else {
		selString +='<SIMPLERENDERER>\n';
		selString +='<SIMPLEPOLYGONSYMBOL fillcolor="' + BPDSelectColor + '" filltype="solid" transparency="0.25" boundarycolor="255,255,255" />\n';
		selString +='</SIMPLERENDERER>\n';
	}
	selString +='</LAYER>\n';

	return selString;
}

function writeCrimesRenderer(strCrimeType) {
	var theString = '';

	theString = '<VALUEMAPRENDERER lookupfield="CRIME_CODE">\n';

	switch(strCrimeType) {
		case 'Murder':
			theString += '<EXACT value="1A" label="Murder">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="71" font="ESRI Default Marker" fontcolor="255,0,0" fontsize="16" />\n';
			theString += '</EXACT>\n';
			break;
		case 'Rape':
			theString += '<EXACT value="2A;2B" label="Rape">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="88" font="ESRI Default Marker" fontcolor="255,0,255" fontsize="18" />\n';
			theString += '</EXACT>\n';
			break;
		case 'Robbery':
			theString += '<EXACT value="3A;3B;3C;3D;3E;3F;3G;3H;3J;3K;3L;3M;3N;3P" label="Robbery">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="80" font="ESRI Default Marker" fontcolor="0,0,0" fontsize="16" />\n';
			theString += '</EXACT>\n';
			break;
		case 'Aggravated Assault':
			theString += '<EXACT value="4A;4B;4C;4D" label="Aggravated Assault">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="35" font="ESRI Default Marker" fontcolor="0,255,0" fontsize="16" />\n';
			theString += '</EXACT>\n';
			break;
		case 'Burglary':
			theString += '<EXACT value="5A;5B;5C;5D;5E;5F" label="Burglary">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="34" font="ESRI Default Marker" fontcolor="0,0,255" fontsize="12" />\n';
			theString += '</EXACT>\n';
			break;
		case 'Larceny from Auto':
			theString += '<EXACT value="6A;6B;6C;6D;6E;6F;6G;6H;6J;6K;6L" label="Larceny from Vehicle">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="94" font="ESRI Default Marker" fontcolor="255,0,0" fontsize="20" />\n';
			theString += '</EXACT>\n';
			break;
		case 'Stolen Vehicle':
			theString += '<EXACT value="7A;7B" label="Stolen Vehicle">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="33" font="ESRI Default Marker" fontcolor="255,0,0" fontsize="12" />\n';
			theString += '</EXACT>\n';
			break;
		default:
			theString += '<EXACT value="1A" label="Murder">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="71" font="ESRI Default Marker" fontcolor="255,0,0" fontsize="16" />\n';
			theString += '</EXACT>\n';
			theString += '<EXACT value="2A;2B" label="Rape">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="88" font="ESRI Default Marker" fontcolor="255,0,255" fontsize="18" />\n';
			theString += '</EXACT>\n';
			theString += '<EXACT value="3A;3B;3C;3D;3E;3F;3G;3H;3J;3K;3L;3M;3N;3P" label="Robbery">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="80" font="ESRI Default Marker" fontcolor="0,0,0" fontsize="16" />\n';
			theString += '</EXACT>\n';
			theString += '<EXACT value="4A;4B;4C;4D" label="Aggravated Assault">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="35" font="ESRI Default Marker" fontcolor="0,255,0" fontsize="16" />\n';
			theString += '</EXACT>\n';
			theString += '<EXACT value="5A;5B;5C;5D;5E;5F" label="Burglary">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="34" font="ESRI Default Marker" fontcolor="0,0,255" fontsize="12" />\n';
			theString += '</EXACT>\n';
			theString += '<EXACT value="6A;6B;6C;6D;6E;6F;6G;6H;6J;6K;6L" label="Larceny from Vehicle">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="94" font="ESRI Default Marker" fontcolor="255,0,0" fontsize="20" />\n';
			theString += '</EXACT>\n';
			theString += '<EXACT value="7A;7B" label="Stolen Vehicle">\n';
			theString += '	<TRUETYPEMARKERSYMBOL character="33" font="ESRI Default Marker" fontcolor="255,0,0" fontsize="12" />\n';
			theString += '</EXACT>\n';
	}
	theString += '</VALUEMAPRENDERER>\n';

	return theString;
}

function addBPDCircleToMap4() {
//This function adds the graphic circle to the map view, based on the user's
//choice of 1/2 vs. 1/4 mile.
	var theString = "";
	var k = customPointX.length - 1;
	
	theString += '<LAYER type="acetate" name="Extent">\n';
	theString += '<OBJECT units="database">\n';
	theString += '<POLYGON coords="' + 
					parent.InfoFrame.trueInitExtentLeft + ' ' + parent.InfoFrame.trueInitExtentTop + ';' +
					parent.InfoFrame.trueInitExtentRight + ' ' + parent.InfoFrame.trueInitExtentTop + ';' +
					parent.InfoFrame.trueInitExtentRight + ' ' + parent.InfoFrame.trueInitExtentBottom + ';' +
					parent.InfoFrame.trueInitExtentLeft + ' ' + parent.InfoFrame.trueInitExtentBottom + ';' +
					parent.InfoFrame.trueInitExtentLeft + ' ' + parent.InfoFrame.trueInitExtentTop + '">';
	theString += '<SIMPLEPOLYGONSYMBOL boundarycolor="255,30,30" boundarytransparency="1.0" boundarytype="dash" boundarywidth="2.0" filltransparency="0.0" />\n';
	theString += '</POLYGON>\n';
	theString += '</OBJECT>\n</LAYER>\n';
	
	//The following 'if' block constructs the three acetate layers necessary to
	//show the geocoded address point (yellow star), the address text (offset to
	//the east-northeast of the geocoded point), and a leader line connecting the
	//address label with the geocoded point.
	if (parent.InfoFrame.strQueryType == "Address") {
		theString += '<LAYER type="acetate" name="pntAddress">\n';
		theString += '<OBJECT units="database">\n';
		theString += '<POINT coords="' + parent.InfoFrame.strX + ' ' + parent.InfoFrame.strY + '" >\n';
		theString += '<SIMPLEMARKERSYMBOL color="255,255,0" outline="0,0,0" transparency="0.5" type="star" width="20" />\n';
		theString += '</POINT>\n';
		theString += '</OBJECT>\n';
		theString += '</LAYER>\n';

		/*
		theString += '<LAYER type="acetate" name="lblAddress">\n';
		theString += '<OBJECT units="database">\n';
		theString += '<TEXT coords="' + parseInt(parseInt(parent.InfoFrame.strX) + 200) + ' ' + parseInt(parseInt(parent.InfoFrame.strY) + 100) + '" label="' + parent.InfoFrame.strQueryText + '" >\n';
		theString += '<TEXTMARKERSYMBOL font="Arial" fontcolor="0,0,0" fontsize="12" transparency="0.5" />\n';
		theString += '</TEXT>\n';
		theString += '</OBJECT>\n';
		theString += '</LAYER>\n';
		
		theString += '<LAYER type="acetate" name="addressLeader">\n';
		theString += '<OBJECT units="database">\n';
		theString += '<LINE coords="' + parseInt(parseInt(parent.InfoFrame.strX) + 200) + ' ' + parseInt(parseInt(parent.InfoFrame.strY) + 100) + ';' + parent.InfoFrame.strX + ' ' + parent.InfoFrame.strY + '" >\n';
		theString += '<SIMPLELINESYMBOL color="0,0,0" transparency="0.5" width="2" />\n';
		theString += '</LINE>\n';
		theString += '</OBJECT>\n';
		theString += '</LAYER>\n';
		*/
		
	}
	
	return theString;
}

function reloadBPDPage() {
//alert("reoadBPDPage");
	var newURL = parent.document.location.href;
	newURL = newURL.substring(0, newURL.lastIndexOf("/"));
	parent.document.location.href = newURL + "/police.htm";
}

// request a selection using a shape
function sendBPDCircleSelect() {
//alert("sendBPDCircleSelect");
	toolMode = 4;
	BPDSelectPresent = true;
	queryStartRecord=1;
	selectionMode=3;
	showBuffer=false;
	theType = 2;
	
	if (theType==2) {
		for (i=0; i<customPointX.length;i++) {
			clickPointX[i] = customPointX[i];
			clickPointY[i] = customPointY[i];
		}
		clickCount=clickPointX.length;
	
		if ((clickPointX[0]!=clickPointX[clickCount-1]) && (clickPointY[0]!=clickPointY[clickCount-1])) {
			clickPointX[clickCount]=clickPointX[0];
			clickPointY[clickCount]=clickPointY[0];
			clickCount=clickCount+1;
		}
	}
	showRetrieveData();
	var theString = writeShapeSelect(theType);
	sendToServer(imsQueryURL, theString, selectXMLMode);
}

function showBPDHighlight() {
	highlightedOne = LayerIDField[ActiveLayerIndex] + " = " + selectPoints[selNum];
	//alert("showBPDHighlight, highlightedOne = " + highlightedOne);
	var fWidth = selectRight[selNum] - selectLeft[selNum];
	var fHeight = selectTop[selNum] - selectBottom[selNum];
	var mWMargin = 0;
	var mHMargin = 0;
	if (selectType=="point") {			
		mWMargin = fullWidth * selectPointMargin;
		mHMargin = fullHeight * selectPointMargin;
		if (mWMargin > xDistance/2) {
			mWMargin = xDistance/2;
			mHMargin = yDistance/2;
		}
	} else {
		mWMargin = fWidth * selectMargin;
		mHMargin = fHeight * selectMargin; 
	}
	//saveLastExtent();
	eLeft = selectLeft[selNum] - mWMargin;
	eRight = selectRight[selNum] + mWMargin;
	eTop = selectTop[selNum] + mHMargin;
	eBottom = selectBottom[selNum] - mHMargin;
	legendTemp=legendVisible;
	legendVisible=false;
	//sendMapXML();
}

function maskAddress(strUnmasked) {
	var strStNumNoMask = strUnmasked.substr(0, 2);
	var strSt = strUnmasked.substr(4, strUnmasked.length);
	var strStNumMask = strStNumNoMask + 'xx' + strSt;
	return strStNumMask;
}

function printBPD() {
	var Win1 = parent.TextFrame;
	var theFrame = "parent.MapFrame";
	//var theForm = document.forms[0];
	//var theTitle = theForm.title.value;
	var intTableWidth = 670;
	var intMapWidth;
	var intMapHeight;
	var intOVWidth;
	var intOVHeight;
	var intLegendWidth;
	var intLegendHeight;
	//var intTargetMapWidth = 526;
	var intTargetMapWidth = 670;
	var intTargetMapHeight;
	var intTargetOVWidth;
	var intTargetOVHeight;
	var intTargetLegendWidth;
	var intTargetLegendHeight;
	var fPercent;
	var intNumCols;
		
	Win1 = window.open("","QueryWindow","toolbar=yes,width=800,height=600,scrollbars=yes,resizable=yes,left=0,top=0");
	theFrame = "opener";
	if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
	Win1.document.open();
	Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head><title>' + titleList[24] + '</title></head>');

	Win1.document.writeln('<body bgcolor="' + textFrameBackColor + '" text="Black" link="Blue" vlink="Gray" LEFTMARGIN=0 onload="window.focus()">');
	Win1.document.writeln('<center>');
	//Win1.document.writeln('<IMG SRC="' + imsHost + '/BPDmaps/images/fcobanner_atts.jpg" USEMAP="#fcobanner.jpg" BORDER="0"><BR><BR>');
	//Win1.document.writeln('<MAP name="fcobanner.jpg">\n');
	//Win1.document.writeln('<AREA shape="rect" coords="351,9,438,113" href="http://www.baltimorepolice.org" target="_window">\n');
	//Win1.document.writeln('</MAP>\n');
	Win1.document.writeln('<TABLE border="1" cellspacing="0" cellpadding="2" width="' + intTableWidth + '" nowrap bordercolor="969696"><TR>');

	if ((parent.InfoFrame.strQueryType == "Address") || (parent.InfoFrame.strQueryType == "School")) {
		intNumCols = 4;
	} else {
		intNumCols = 3;
	}
	Win1.document.writeln('<TD bgcolor="99CCFF" align="center" colspan="' + intNumCols + '"><FONT FACE="arial" SIZE="-1"><B>Original Query</B></FONT></TD></TR>');
	Win1.document.writeln('<TD bgcolor="FFFFCC"><FONT FACE="arial" SIZE="-2"><DIV align="center"><U>' + parent.InfoFrame.strQueryType + '</U></DIV></FONT></TD>');
	if ((parent.InfoFrame.strQueryType == "Address") || (parent.InfoFrame.strQueryType == "School")) {
		Win1.document.writeln('<TD bgcolor="FFFFCC"><FONT FACE="arial" SIZE="-2"><DIV align="center"><U>Buffer</U></DIV></FONT></TD>');
	}
	Win1.document.writeln('<TD bgcolor="FFFFCC"><FONT FACE="arial" SIZE="-2"><DIV align="center"><U>Crime Type</U></DIV></FONT></TD>');
	Win1.document.writeln('<TD bgcolor="FFFFCC"><FONT FACE="arial" SIZE="-2"><DIV align="center"><U>Date</U></DIV></FONT></TD></TR>');
	Win1.document.writeln('<TR><TD bgcolor="FFFFCC"><FONT FACE="arial" SIZE="-2"><DIV align="center"><B>' + parent.InfoFrame.strQueryText + '</B></DIV></FONT></TD>');
	if ((parent.InfoFrame.strQueryType == "Address") || (parent.InfoFrame.strQueryType == "School")) {
		Win1.document.writeln('<TD bgcolor="FFFFCC"><FONT FACE="arial" SIZE="-2"><DIV align="center"><B>' + parent.InfoFrame.strRadius + '</B></DIV></FONT></TD>');
	}
	Win1.document.writeln('<TD bgcolor="FFFFCC"><FONT FACE="arial" SIZE="-2"><DIV align="center"><B>' + parent.InfoFrame.strCrimeType + '</B></DIV></FONT></TD>');
	Win1.document.writeln('<TD bgcolor="FFFFCC"><FONT FACE="arial" SIZE="-2"><DIV align="center"><B>' + parent.InfoFrame.intMonth + '/' + parent.InfoFrame.strStartDate + '/' + parent.InfoFrame.strStartYear + ' to ' + parent.InfoFrame.intEndMonth + '/' + parent.InfoFrame.strEndDate + '/' + parent.InfoFrame.strEndYear + '</B></DIV></FONT></TD>');
	Win1.document.writeln('</TR></TABLE><BR>');

	intMapWidth = parent.MapFrame.document.theImage.width;
	intMapHeight = parent.MapFrame.document.theImage.height;
	intOVWidth = parent.TOCFrame.document.images["ovImage"].width;
	intOVHeight = parent.TOCFrame.document.images["ovImage"].height;
	intLegendWidth = parent.TOCFrame.document.images["legendImage"].width;
	intLegendHeight = parent.TOCFrame.document.images["legendImage"].height;
	
	fPercent = parseFloat(intTargetMapWidth / intMapWidth);
	intTargetMapHeight = intMapHeight * fPercent;
	intTargetOVWidth = intOVWidth * fPercent;
	intTargetOVHeight = intOVHeight * fPercent;
	intTargetLegendWidth = intLegendWidth * fPercent;
	intTargetLegendHeight = intLegendHeight * fPercent;

	Win1.document.writeln('<DIV align="center"><BR>');
	Win1.document.writeln('<TABLE width="' + intTableWidth + '" border="2" cellspacing="0" cellpadding="0" bordercolor="969696" nowrap>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TD align="center" width="' + intTargetMapWidth + '" colspan="2">');
	Win1.document.writeln('			<DIV align="center"><IMG align="center" border="0" src="' + parent.MapFrame.document.theImage.src + '" width="' + intTargetMapWidth + '" height="' + intTargetMapHeight + '" hspace="0" vspace="0" border="0" alt=""></DIV>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('	<TR>');
	Win1.document.writeln('		<TD bgcolor="#FFFFCC">');
	Win1.document.writeln('			<div align="center"><IMG border="0" src="' + parent.TOCFrame.document.legendImage.src + '" hspace="0" vspace="0" alt="Map Legend"></div>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('		<TD bgcolor="#FFFFCC">');
	Win1.document.writeln('			<div align="center"><IMG border="0" src="' + parent.TOCFrame.document.ovImage.src + '" hspace="0" width="' + (intTargetMapWidth / 3) + '" vspace="0" alt="Locator Map - The red square represents the area covered by your large map"></div>');
	Win1.document.writeln('		</TD>');
	Win1.document.writeln('	</TR>');
	Win1.document.writeln('</TABLE>');
	Win1.document.writeln('</DIV>');
	Win1.document.writeln('<br>');
	
	Win1.document.writeln('<br><table border="1" cellspacing="0" cellpadding="2" width="720" nowrap bordercolor="969696" bgcolor="' + tableBackColor + '">');
	Win1.document.writeln('<td bgcolor="FFFFCC">');
	Win1.document.writeln(parent.InfoFrame.strMiniDisclaimer);
	Win1.document.writeln('</td></table><br>');
	Win1.document.writeln('<div align="center"><form name="buttonForm"><a href="' + imsHost + 'bpdmaps/explain.htm" target="_blank" name="definitions" id="btnDefinitions"><font face="arial" size="-2" color="black">Click for crime definitions...</font></a><br>');
	Win1.document.writeln('<br><input type="button" name="close" id="btnClose" value="Close" onClick="window.close();"></input></form></div>');
	Win1.document.writeln('</body></html>');
	Win1.document.close();
	Win1.print();
	//Win1.close();
	Win1=null;
}
