// 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;
//======================== misc	=====================
var bParcelQuery, bApplOn, bQueryDistricts, bIdentifyDraw, bSelectParcel = false;
var iGroupLayerCurrentActive = -1, bGroupLayerActive;
var iWinWidth, iWinHeight, iDelay = 0;
//======================== condo	=====================
var bCondo = false, iCondoBldgOid
//====================== notes query====================
var bJointable,jointableName,tempSelectFields,tempQueryString;
var bCodeNote,bZoningReviewNote,bDrawToStrap,bMeasureArea,bFirmLetter,bFirmLetterCount;
var sNoteUser,sCodeID,sCodeDataID,sFolio;

// ======================== customize ====query zoning(check cities straps)=======	Xu 1-17-02
var bQueryZoning,lockedMapX,lockedMapY; 
var bPickZone;
// ======================== customize ===Nexrad========	Xu 1-10-02
var arNexradLayer = new Array(5),arSumRain = new Array(5);
var arCenterXY = new Array(1000),arGridSumRain = new Array(1000);
var arRecNo = new Array(1000);
var arRainColor = new Array(5);
var recCount, bNexrad, timeName;
var gridList,subIDList,subIDExceedList;
var layerIDWatershedSub,layerIDNexrad;

//	arRainColor[1] = "255,255,204"
//	arRainColor[2] = "204,255,204"
//	arRainColor[3] = "102,255,153"
//	arRainColor[4] = "153,204,102"
//	arRainColor[5] = "102,153,51"
	
	arRainColor[1] = "255,255,240"
	arRainColor[2] = "180,255,255"
	arRainColor[3] = "255,255,153"
	arRainColor[4] = "255,153,153"
	arRainColor[5] = "255,110,255"
	
// ======================== Draw parcel map =========		Xu 8-23-01
// used by searchTool.htm,dbAddress_process.asp,dbOwner_process.asp...
var sStrap;
var p = parent.MapFrame;
var t=parent,arQty = new Array(3),poly,sReply;
var sZoning,sFireDistricts,sCommissioner;
//var sFirmZone,sFirmPanel,sFirmCommunity,sFirmDate,sFirmVersion;
var hasWin = false,Win1;
var sZonePolygonID;
var bSale = false;

// ======================== customize ===Planned Development Information query========	Xu 2-18-04
var sDataSheet, sCaseName;

// ======================== Draw parcel sales export =========		Xu 8-29-05
var arParcelInfo = new Array(100);
	for (var i = 0; i < arParcelInfo . length; ++ i)
	arParcelInfo [i] = new Array (10);


function stripStrap(strap1) {
	strap1 = strap1.replace(/[-\s\.]/g,"");
	return strap1;
}	

function formatStrap(strap1) {
	strap1 = stripStrap(strap1);
	strap1 = strap1.toUpperCase();
	strap1 = strap1.substring(0,2) + "-" + strap1.substring(2,4) + "-" + strap1.substring(4,6) + "-" + strap1.substring(6,8) + "-" + strap1.substring(8,13) + "." + strap1.substring(13,17);
	return strap1;
}	

function setLayerActive(layer,mapOpener) {
	if (mapOpener) {
		t = opener.parent;
	}else {
		t = parent;
	}
	if(t.MapFrame.layerCount > 0) {
		for (var l=0;l<t.MapFrame.layerCount;l++){
			if(t.MapFrame.LayerName[l] == layer){
				t.MapFrame.setQueryLayer(l);
				break;
			}
		}
		
		if(t.MapFrame.legendVisible == false)
		{
			t.TOCFrame.document.location=t.MapFrame.appDir+"toc.htm";
		}
	}			
}
function getLayerID(layer) {
	t = parent.MapFrame;
	if(t.layerCount > 0) {
		for (var l=0;l<t.layerCount;l++){
			if(t.LayerName[l] == layer){
				return t.LayerID[l];
			}
		}
	}	
}
function exit() {
	parent.TextFrame2.location = "text.htm";
//	legendOn(false);
	p.hideLayer("LoadData");
}
function legendOn(on) {
	if (on) {
		if (parent.MapFrame.legendVisible) {
			parent.MapFrame.legendVisible = false;
		}
	} else {
		if (!parent.MapFrame.legendVisible) {
			parent.MapFrame.legendVisible = true;
		}
	}
	//alert(parent.MapFrame.legendVisible );
	parent.MapFrame.clickFunction('legend');
}
function clearSetSel() { // Just for measure area 
	p.bSale = false;
	p.bSelectParcel = false;
	p.bPickZone = false;
	p.bNexrad = false;
	p.bQueryZoning = false;
	p.bCodeNote = false;
	p.bDrawToStrap = false;
	p.bZoningReviewNote = false;
	p.bParcelQuery = false;
	p.bQueryDistricts = false;
	p.bApplOn = false;
	p.bDrawToStrap = false;
	p.bFirmLetter = false;
	p.bFirmLetterCount = false;
	p.bTidemarkQuery = false;
	parent.TextFrame2.location='text.htm';
}

function loadPreAppl() {
	if (p.bTidemarkQuery) {
		parent.TextFrame2.location='text.htm';
		doTidemarkQuery();
		p.clickFunction('selectpoint');
	}
	if (p.bParcelQuery) {
		parent.TextFrame2.location='text.htm';
		doParcelQuery();
		p.clickFunction('selectpoint');
	}
	if (p.bQueryZoning) {
		parent.TextFrame2.location='frmZoneID.htm';	
		queryZoning(0);	
	}
	if (p.bCodeNote) {
		parent.TextFrame2.location='dbCodeNote.asp';
		queryCodeNote(0);
	}
	if (p.bZoningReviewNote) {
		parent.TextFrame2.location='dbZoningReviewNote.asp';
		queryZoningReviewNote(0);		
	}
	if (p.bQueryDistricts) {
		parent.TextFrame2.location='text.htm';
		p.clickFunction('selectpoint');
	}
	if (p.bFirmLetter) {
		parent.TextFrame2.location='text.htm';
		firmLetter();
		p.clickFunction('selectpoint');
	}
	if (p.bFirmLetterCount) {
		parent.TextFrame2.location='dbfirmlettercount.asp';
	}
	if (p.bPlanDevQuery) {
		parent.TextFrame2.location='frmPlannedDev.htm';
		queryPlanDev(0);
		p.clickFunction('selectpoint');
	}
}

function identifyHighlight(fieldName, fieldValue ,bMapOpener) 
{
	var dQuote = '"',sQuery;
	if((fieldName.length > 0) && (fieldValue.length > 0))
	{
		if (bMapOpener) {
			t = opener.parent;
		}else {
			t = parent;
		}
			setLayerActive(t.MapFrame.LayerName[t.MapFrame.ActiveLayerIndex],bMapOpener);
			t.MapFrame.clickFunction('silentquery');
			sQuery = fieldName + "=" + dQuote + fieldValue + dQuote;
			t.MapFrame.zoomToMultipleStrap = true;
			t.MapFrame.sendQueryString(sQuery);
	}
	
}

function selectCondoOrStrap(x1, y1) {
	parent.MapFrame.bCondo = false;
	window.status = "Selecting Parcel...";	
	theURL="/dbCondoSelectCheck.asp?x=" + x1 + "&y=" + y1;
	theWin=window.open(theURL, "Parcel", "menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=yes,height=500,width=400");
	theWin.focus();
	hasWin=true;	
}
function drawCondo(strap1,mapOpener,condoBldgOid) {
		t.MapFrame.bCondo = true;
		t.MapFrame.iCondoBldgOid = condoBldgOid;
		doDrawMap( strap1, mapOpener);
	}

function drawCondoOrStrap(strap1,mapOpener) {
	checkCondo(0, strap1, mapOpener);
	checkCondo(1, strap1, mapOpener);
}

function checkCondo(iStep, strap1, mapOpener) {
	if (mapOpener) {
		t = opener.parent;
	}else {
		t = parent;
	}
	switch(iStep){
		case 0:		//-------------- query condo
			t.MapFrame.bCondo = false;
			t.TextFrame2.location="/dbCondoCheck.asp?strap="+ strap1 ;
			break;
		case 1:		//------------draw parcel
			if(t.MapFrame.iDelay == 1 || t.MapFrame.iDelay == 0 )
			{
				window.setTimeout("doDrawMap('" + strap1 + "'," + mapOpener + ");",500);
				break;
			}
	}
}
function doDrawMap(strap1,mapOpener) 
{
	var dQuote = '"',sQuery, id;
	if (mapOpener) {
		t = opener.parent;
	}else {
		t = parent;
	}
	t.StrapFrame.document.TextFormStrap.strap.value = formatStrap(strap1);	
	strap1 = stripStrap(strap1);
	if (strap1 != ""){
		if (t.MapFrame.bCondo)
			setLayerActive(t.MapFrame.CONDOBUILDING,mapOpener);
		else
			setLayerActive("Parcels",mapOpener);

		t.MapFrame.clickFunction('silentquery');
		if (strap1.length == 17) {
			if (strap1.substring(13,17) == "000A")
				alert("Could not locate parcel on map. See 'HELP'" );
		}else {
			alert("Parcel not found -- Drawing selected area ..." );
		}
		if (t.MapFrame.bCondo){
			sQuery = "objectid = " + t.MapFrame.iCondoBldgOid;
			t.MapFrame.bCondo = false;
		}else{
			sQuery = "STRAP like " + dQuote + strap1 + "%" + dQuote;
		}
		t.MapFrame.zoomToMultipleStrap = true;
		t.MapFrame.sendQueryString(sQuery);
	} 
	else 
		alert("No strap number specified.");
}

function doDrawSale(folio,ly1,ly2,ly3,tyF0,tyF1,tyF2,tyF3,tyF4,tyF5,tyF6,tyF7,tyF8,tyF9,yQty1,yQty2,yQty3) 
{
	p.hideLayer("LoadData");
	t = parent;
	var sQuery;
	p.iSaleYearCount = 3;
	p.folio = folio;	
	p.bCondo = bCondo;
	p.arJsYearFolio[1] = ly1;
	p.arJsYearFolio[2] = ly2;
	p.arJsYearFolio[3] = ly3;
	p.arQty[1] = yQty1;
	p.arQty[2] = yQty2;
	p.arQty[3] = yQty3;

	p.arJsLandTypeFolio[0] = tyF0;
	p.arJsLandTypeFolio[1] = tyF1;
	p.arJsLandTypeFolio[2] = tyF2;
	p.arJsLandTypeFolio[3] = tyF3;
	p.arJsLandTypeFolio[4] = tyF4;
	p.arJsLandTypeFolio[5] = tyF5;
	p.arJsLandTypeFolio[6] = tyF6;
	p.arJsLandTypeFolio[7] = tyF7;
	p.arJsLandTypeFolio[8] = tyF8;
	p.arJsLandTypeFolio[9] = tyF9;
	
	setLayerActive("Parcels");
	t.MapFrame.clickFunction('silentquery');
	sQuery = " folioid = " + folio ;
	t.MapFrame.zoomToMultipleStrap = true;
	t.MapFrame.bSale = true;
	t.MapFrame.sendSaleQueryString(sQuery);
}

function querySaleFolio() {
	var sQuery;
	t = parent;
	setLayerActive("Parcels");
	t = parent.MapFrame;
	var theEnvelope = 'maxx="' + t.eLeft + '" maxy="' + t.eBottom + '" minx="' + t.eRight + '" miny="' + t.eTop + '"';
	sQuery = t.writeEnvelopeXML(t.ActiveLayer,t.ActiveLayerType,"folioid",5000,t.queryStartRecord,theEnvelope,t.useLimitExtent) 
	t.sendToServer(t.imsQueryURL,sQuery,1002);
}

function doParcelQuery() {
	p.sStrap = stripStrap(parent.StrapFrame.document.TextFormStrap.strap.value);
	if (p.sStrap != "") {
		theURL="http://" + p.WebURL + "/Scripts/PropertyQuery/PropertyQuery.aspx?STRAP=" + p.sStrap;
		theWin=window.open(theURL, "Parcel", "menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=yes,height=500,width=650");
		theWin.focus();
		hasWin=true;				
	} 
	else {
		alert("No strap number specified.");
	}
}


function doTidemarkQuery() {
	p.sStrap = stripStrap(parent.StrapFrame.document.TextFormStrap.strap.value);
	
	if (p.sStrap != "") {
		theURL="http://permits.leegov.com/tm_bin/tmw_cmd.pl?tmw_cmd=ParcelViewParcel&shl_prc_parcel_no=" + p.sStrap;
		theWin=window.open(theURL , "TidemarkSearch", "menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=yes,height=500,width=650");
		theWin.focus();
		hasWin=true;				
	} 
	else {
		alert("No strap number specified.");
	}
}

function districtLayerQuery(layerName,selectedField,modeNum) {
	setLayerActive(layerName);	
	sQuery = p.writeDistrictXML(p.ActiveLayer,p.ActiveLayerType,selectedField,100,p.queryStartRecord,p.poly) 
	p.sendToServer(p.imsQueryURL,sQuery,modeNum);				
}
function runZoningReviewQuery(strap) {
	var dQuote = '"',sQuery;
	
	strap = p.stripStrap(strap);
	
	if (strap != "NoNoteFound")
		p.sCodeID = strap;

	if( p.sCodeID.length > 0) {
		sQuery = "STRAP  = " + dQuote + p.sCodeID + dQuote;
		p.zoomToMultipleStrap = true;
		p.bZoningReviewNote = true;
		p.bDrawToStrap = true;
		p.queryXMLMode = 1130;
		p.setLayerActive("Parcels");
		p.sendQueryString(sQuery);
	}		
}
function queryZoningReviewNote(iStep) {
	var sQuery,s;
	var dQuote = '"';
	switch(iStep){
		case 0:		//------------draw parcel	
			p.setLayerActive("Parcels");
			p.clickFunction('selectpoint');
			p.queryXMLMode = 1130;
			break;
		case 1131:
			if (p.sStrap == null) p.sStrap = (parent.TextFrame2.document.TextForm.strap.value);
			theURL = "/dbZoningReviewNoteResult.asp?strap="+p.sStrap;
			Win1 = open(theURL,"QueryWindow","width=750,height=450,scrollbars=yes,resizable=yes");
			Win1.focus();	
			hasWin = true;
			p.queryXMLMode = 1133;
			p.bDrawToStrap = false;
			break;
	}
}
function runCodeReviewQuery(id) {
	var dQuote = '"',sQuery;
	
	id = p.stripStrap(id);
	
	if (id != "NoNoteFound")
		p.sCodeID = id;

	if( p.sCodeID.length > 0) {
		sQuery = "STRAP like " + dQuote + p.sCodeID + "%" + dQuote;
		p.zoomToMultipleStrap = true;
		p.bCodeNote = true;
		p.bDrawToStrap = true;
		p.queryXMLMode = 1140;
		p.setLayerActive("Parcels");
		p.sendQueryString(sQuery);
	}		
}
function queryCodeNote(iStep) {
var x1,y1,x2,y2,sQuery,s,id1;
	var dQuote = '"';
	p.sStrap="";
	switch(iStep){
		case 0:		//------------draw parcel
			p.hideLayer("LoadData");
			p.setLayerActive("Parcels");		
			p.queryXMLMode = 1140;
			p.clickFunction('selectpoint');
			break;
		case 1141:		//-------------- query Notes
			theURL = "/dbCodeNoteResult.asp?codeID=" + p.sCodeID ;
			Win1 = open(theURL,"QueryWindow","width=750,height=450,scrollbars=yes,resizable=yes");
			Win1.focus();	
			hasWin = true;
			p.queryXMLMode = 1142;
			p.bDrawToStrap = false;
			break;
		
	}
}

function runDistrictsQuery(strap) {
	var dQuote = '"',sQuery;
	
	strap = p.stripStrap(strap);
	
	if (strap != "NoStrapFound") {
		p.sStrap = strap;
		
		if( p.sStrap.length > 0) 
		{
			sQuery = "STRAP  = " + dQuote + p.sStrap + dQuote;
			p.zoomToMultipleStrap = true;
			p.bQueryDistricts = true;
			p.bDrawToStrap = true;
			p.queryXMLMode = 1150;
			p.setLayerActive("Parcels");
			p.sendQueryString(sQuery);
		}
	}else {
		alert("No Strap Found");
	}			
}

function measureArea() {
	var today = new Date ();
	var tm = today.getTime();
	
	p.bDrawToStrap = false;
//	theURL = "/dbMeasureArea.asp?folioid=" + p.sFolio + "&tm=" + tm ;
	theURL = "/dbMeasureArea.asp?folioid=" + p.sFolio + "&strap=" + p.sStrap + "&tm=" + tm ;
	theWin = window.open(theURL,"MeasureArea","width=675,height=450,scrollbars=1,resizable=1");
	theWin.focus();
	hasWin = true;		
}

function firmLetter() {
	p.sStrap = stripStrap(parent.StrapFrame.document.TextFormStrap.strap.value);
	if ((p.sStrap == "") || (p.sStrap == "NoSTRAPfound")) {
		theURL="/blank.htm"
		theWin=window.open(theURL, "FirmLetter", "menubar=1,resizable=yes,scrollbars=yes,status=no,toolbar=yes,height=870,width=1000");
		theWin.focus();
		hasWin=true;
		alert("No parcel selected.");				
	} 
	else {
		window.open("/FirmLetter.htm", "FirmLetter", "menubar=1,resizable=yes,scrollbars=yes,status=no,toolbar=yes,height=870,width=1000");
//		theURL="/dbFirmLetterQuery.asp?STRAP=" + p.sStrap;
		theURL="/DotNet/FIRMLetter/FirmLetterQuery.aspx?STRAP=" + p.sStrap;
		theWin=window.open(theURL, "FirmLetter", "menubar=1,resizable=yes,scrollbars=yes,status=no,toolbar=yes,height=870,width=1000");
		theWin.focus();
		hasWin=true;
	}
}

function queryPlanDev(iStep) {		
		switch(iStep){
		case 0:		//------------select point from Planned Developments
			p.setLayerActive("Planned Developments");
			p.clickFunction('selectpoint');
			p.queryXMLMode = 1170;
			break;
	
		case 1171:
			p.queryXMLMode = 1173;
			p.bDrawToStrap = false;
				
			if(parent.SearchToolFrame.sCaseName != "" && parent.SearchToolFrame.sDataSheet != "")
			{
				theURL="http://" + parent.SearchToolFrame.sDataSheet;
				theWin=window.open(theURL, "PlannedDevelopments", "menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=yes,height=600,width=800");
				theWin.focus();
				hasWin=true;
			}
			else {
				theURL="/blank.htm"
				theWin=window.open(theURL, "PlannedDevelopments", "menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=yes,height=600,width=800");
				
				theWin.document.open();
				theWin.document.writeln('<html><head><title>Planned Developments</title>');
				theWin.document.writeln('<body BGCOLOR=Silver>');
				theWin.document.writeln('<center>');
				theWin.document.writeln('<FONT FACE=Arial SIZE=-1><b>No Planned Development case selected.</b></FONT>');
				theWin.document.writeln('</center></body></html>');
				theWin.document.close();
				theWin.focus();
				hasWin=true;
				
			}
			break;
		}
}

// **************************
// * Spatial District Query *
// **************************

function queryDistricts(iStep) {
	switch(iStep){
		case 0:		//------------draw parcel
			if (!p.okToSend) {
				//
				// Wait another 2 seconds for map to load
				//
				
				window.setTimeout('queryDistricts(0);',2000);			
					
				break;
			}

			p.hideLayer("LoadData");
			p.setLayerActive("Parcels");		
			p.queryXMLMode = 1151;
			p.clickFunction('selectpoint');
			
			//
			// Allow fall through to open external window
			//

		case 1151:		//-------------- query Districts
	
			p.sStrap = stripStrap(parent.StrapFrame.document.TextFormStrap.strap.value);
	
			/*
			if (hasWin == true){
				if (!Win1.closed ){
					Win1.close();
					Win1=null;
				}
			}
			*/
			if (p.sStrap.length == 17) {
				/*theURL = "../DistrictQuery/SpatialDistrictQuery.asp?strap="+p.sStrap;*/
			//	theURL = "../DistrictQueryDotNet/DistrictQuery.aspx?strap="+p.sStrap;
				theURL = "../DistrictsQuery/DistrictQuery.aspx?strap="+p.sStrap;
				theWin = open(theURL,"QueryWindow","width=850,height=450,scrollbars=1,resizable=1 toolbar=1 menubar=1");
				theWin.creator = self;
				theWin.focus();	
				hasWin = true;				
				//p.bDrawToStrap = false;
				p.bDrawToStrap = true;
			}else {
				hasWin = false;
				alert("Invalid STRAP");
			}		
			break;
			
	}
}

function queryZoning(iStep) {
	var s,sCity,x1,y1,x2,y2,sQuery,theEnvelope,zoneCity;
	var dQuote = '"';
	
	switch(iStep){
		case 0:		//------------draw parcel
			p.setLayerActive("Parcels");
			p.clickFunction('selectpoint');
			p.queryXMLMode = 1120;
			break;
		case 1121:
			parent.TextFrame2.document.TextFormZoneID.zoneID.value = "";
			sStrap = p.justGetFieldValue(sReply,"STRAP",0);
			if (sStrap.length > 0) {
				parent.StrapFrame.document.TextFormStrap.strap.value = p.formatStrap(sStrap);
			}
			sCity = sStrap.substring(6,7);
			switch(sCity){
				case "C":
					alert("City of Cape Coral Zoning. Contact number -- (239) 574-0553.");
					p.hideLayer("LoadData");
					break;
			//	case "P":
			//		alert("City of Fort Myers Zoning");
			//		p.hideLayer("LoadData");
			//		break;
			//	case "B":
			//		alert("City of Bonita Zoning.");
			//		p.hideLayer("LoadData");
			//		break;
				default: {
					p.queryXMLMode = 1122;
					p.bPickZone = true;
					p.setLayerActive("Zoning - County");
					searchTolerance = (xDistance/iWidth) * pixelTolerance;
					x1 = p.lockedMapX - searchTolerance;
					y1 = p.lockedMapY - searchTolerance;
					x2 = p.lockedMapX + searchTolerance;
					y2 = p.lockedMapY + searchTolerance;
					theEnvelope ='maxy="' + y2 + '" maxx="' + x2 + '" miny="' + y1 + '" minx="' + x1 + '"';
					s = p.writeEnvelopeXML(p.ActiveLayer,p.ActiveLayerType,"ZONE ZONING",100,p.queryStartRecord,theEnvelope); 
					p.sendToServer(p.imsQueryURL,s,p.queryXMLMode);
					if (sStrap.length < 1 ) { 
						parent.StrapFrame.document.TextFormStrap.strap.value = "Not a parcel";
					}
				}	
			}
			break;
		case 1122:
			//alert(sReply);
			if (p.justGetFeatureCount(sReply) > 0) {
				parent.TextFrame2.document.TextFormZoneID.zoneID.value = p.justGetFieldValue(sReply,"ZONING", 0);
				
				sZonePolygonID = p.justGetFieldValue(sReply,"ZONE",0);
				p.queryXMLMode = 1124;
				sQuery = "ZONE like " + dQuote + sZonePolygonID + "%" + dQuote;
				p.toolMode = 177;
				p.sendQueryString(sQuery);
			} else {
				p.hideLayer("LoadData");
				p.toolMode = 11;	//------- set to other than 177 for clear selection
				p.clearSelection();
				p.toolMode = 177;	//------- reset p.toolMode to 177
				p.queryXMLMode = 1120;
				parent.TextFrame2.document.TextFormZoneID.zoneID.value = "No Zoning found";
			}
			break;
	}
}
		
//=================================================

//----------------customize-----get record number list for Nexrad-----Xu 1/8/02
function getRecNo(theReply) {
	var xy,pos;
	recCount = justGetFeatureCount(theReply);

	gridList = getAllFieldValues(theReply,"RECNO",recCount);
	
	pos = 0;
	for (var i=1;i<recCount+1;i++) {
		xy = getEnvelopeXYs(theReply, pos);
		arCenterXY[i] = Math.abs(xy[2]+xy[0])/2.004 + " " + Math.abs(xy[3]+xy[1])/2;
		arRecNo[i] = justGetFieldValue(theReply,"RECNO",pos);		
		pos = xmlEndPos;
	}
	
}
//----------------customize-----get SubID for Nexrad-----Xu 6/3/02
function getSubID(theReply) {
	var i;
	i = justGetFeatureCount(theReply);
	subIDList = getAllFieldValues(theReply,"SUBID",i);
	
	var theForm1 = parent.TextFrame2;
	theForm1.runQuery();
}

function drawNexrad(gridList,time3,recNoSumIn,lyRecNo1,lyRecNo2,lyRecNo3,lyRecNo4,lyRecNo5,SumRain1,SumRain2,SumRain3,SumRain4,SumRain5,subIDExList) {
	var pos,sQuery;
	p.timeName = time3;
	p.arNexradLayer[1] = lyRecNo1;
	p.arNexradLayer[2] = lyRecNo2;
	p.arNexradLayer[3] = lyRecNo3;
	p.arNexradLayer[4] = lyRecNo4;
	p.arNexradLayer[5] = lyRecNo5;
	p.arSumRain[1] = SumRain1;
	p.arSumRain[2] = SumRain2;
	p.arSumRain[3] = SumRain3;
	p.arSumRain[4] = SumRain4;
	p.arSumRain[5] = SumRain5;
	p.subIDExceedList = subIDExList;

	for (var i=1;i<p.recCount+1;i++) {
		pos = recNoSumIn.indexOf(p.arRecNo[i],0);
		if (pos == -1 ) { 
			p.arGridSumRain[i] = 0;
		} else {
			pos = recNoSumIn.indexOf(",",pos);
			p.arGridSumRain[i] = Math.round(recNoSumIn.substring(pos+1,recNoSumIn.indexOf(";",pos+2))*100)/100;	
		}	
	}
	setLayerActive("Nexrad");
	sQuery = " RECNO in (" + gridList + ")";
	p.sendSaleQueryString(sQuery);
}

function queryNexradRecNo(iStep) {
	var sQuery;
	
	var theEnvelope = 'maxx="' + p.eLeft + '" maxy="' + p.eBottom + '" minx="' + p.eRight + '" miny="' + p.eTop + '"';	
	
	switch(iStep){
		case 0:	
			setLayerActive("Nexrad Grid");
			layerIDNexrad = LayerID[ActiveLayerIndex];
			sQuery = p.writeEnvelopeXML(p.ActiveLayer,p.ActiveLayerType,"#ALL#",5000,p.queryStartRecord,theEnvelope,p.useLimitExtent) 
			p.sendToServer(p.imsQueryURL,sQuery,1003);
			break;
		case 1004:	
			setLayerActive("Watersheds");
			layerIDWatershedSub = LayerID[ActiveLayerIndex];
			sQuery = p.writeEnvelopeXML(p.ActiveLayer,p.ActiveLayerType,"SUBID",5000,p.queryStartRecord,theEnvelope,p.useLimitExtent) 
			p.sendToServer(p.imsQueryURL,sQuery,1004);
			break;
		case 1005:	
			p.sendToServer(t.imsQueryURL,sQuery,1005);
			break;	
	}
}

function getWindowSize() {
	iWinWidth = 0;
	iWinHeight = 0;
	if( typeof(window.innerWidth) == 'number'){
		//non-IE
		iWinWidth = window.innerWidth;
		iWinHeight = window.innerHeight;
	} else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		iWinWidth = document.documentElement.clientWidth;
		iWinHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		iWinWidth = document.body.clientWidth;
		iWinHeight = document.body.clientHeight;
	}
}
 

//=============================================================



// custom function for handling clicks 
// 		flow redirected here when
//		toolMode set to >=1000

function customMapTool(e) {
				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) {
	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(){
	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(){
	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);
		*/
	return customString;
}

// add custom stuff to Map XML request. . . on top of everything
function addCustomToMap4(){
	var customString = "";
	
	return customString;
}

// extract layers to download
function extractIt() {
	hideLayer("measureBox");
	alert(msgList[51]);
}


