aimsQueryPresent=true;var showSampleValues=false;var storedQueryCount=0;var storedQueryName=new Array();var storedQueryString=new Array();var storedQueryVariable=new Array();var storedQueryVarCount=new Array();var storedQueryFieldList=new Array();var storedQueryIndex=0;function queryForm(){if(checkIfActiveLayerAvailable()){fieldIndex=0;showSampleValues=false;setLayerFields(ActiveLayerIndex);if(showSampleValues){var theText=writeFieldSample(LayerFields[fieldIndex]);sendToServer(imsQueryURL,theText,40);}else{writeQueryForm();}}};function findForm(){if(checkIfActiveLayerAvailable()){setLayerFields(ActiveLayerIndex);if(useTextFrame){parent.TextFrame.document.location=appDir+"findForm.htm";}else{Win1=open(appDir+"findForm.htm","QueryWindow","width=575,height=150,scrollbars=yes,resizable=yes");}}};function sendQueryString(newString){newString=fixSingleQuotes(newString);newString=swapQuotes(newString);newString=makeXMLsafe(newString);setQueryString=newString;selectionMode=1;selectData.length=0;LayerFields.length=0;LayerFieldType.length=0;LayerFieldCount=0;highlightedOne="";showBuffer=false;showRetrieveData();var theString=writeQueryXML(newString);sendToServer(imsQueryURL,theString,queryXMLMode);};function writeQueryXML(queryString){if(swapSelectFields){selectFields=selFieldList[ActiveLayerIndex];};var theString='<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" geometry="false" envelope="true"';theString+=' featurelimit="'+maxFeaturesReturned+'" beginrecord="'+queryStartRecord+'">\n';theString+='<LAYER id="'+ActiveLayer+'" />';if(useLimitExtent){theString+='<SPATIALQUERY subfields="'+selectFields+'" where="'+queryString+'">';theString+='<SPATIALFILTER relation="area_intersection">\n';theString+='<ENVELOPE maxx="'+forceComma(limitRight)+'" maxy="'+forceComma(limitTop)+'" minx="'+forceComma(limitLeft)+'" miny="'+forceComma(limitBottom)+'" />\n';theString+='</SPATIALFILTER>\n';theString+='</SPATIALQUERY>\n';}else{theString+='<SPATIALQUERY subfields="'+selectFields+'" where="'+queryString+'" />';};theString+='</GET_FEATURES>';theString+='</REQUEST>';theString+='</ARCXML>';selectLayer=ActiveLayer;selectType=ActiveLayerType;selectCount=0;hightlightedOne="";selectPoints.length=1;selectLeft.length=1;selectRight.length=1;selectTop.length=1;selectBottom.length=1;return theString;};function writeFieldSample(theField){var theFields=theField;var theString='<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" geometry="false" envelope="false"';theString+=' featurelimit="'+numberDataSamples+'">\n';theString+='<LAYER id="'+ActiveLayer+'" />';theString+='<QUERY subfields="'+theFields+'" />';theString+='</GET_FEATURES>';theString+='</REQUEST>';theString+='</ARCXML>';selectLayer=ActiveLayer;selectType=ActiveLayerType;selectCount=0;hightlightedOne="";selectPoints.length=1;selectLeft.length=1;selectRight.length=1;selectTop.length=1;selectBottom.length=1;return theString;};function getFind(theValue){selectCount=0;showBuffer=false;highlightedOne="";selectPoints.length=0;selectLeft.length=0;selectRight.length=0;selectTop.length=0;selectBottom.length=0;drawSelectBoundary=false;showGeocode=false;clickCount=0;totalMeasure=0;currentMeasure=0;selectionMode=1;var theNewQueryString="";var theTempString="";var fieldListString=LayerIDField[ActiveLayerIndex]+" "+LayerShapeField[ActiveLayerIndex];var elemCount=0;for(var i=0;i<LayerFields.length;i++){if(LayerFieldType[i].indexOf("12",0)!=-1){theTempString="("+LayerFields[i]+" LIKE '%"+theValue+"%')";if(elemCount>0){theTempString=" OR "+theTempString;};if(theNewQueryString.length+theTempString.length<1024){theNewQueryString=theNewQueryString+theTempString;fieldListString=fieldListString+" "+LayerFields[i];elemCount+=1;}}};if(theNewQueryString!=""){showRetrieveData();showBuffer=false;theNewQueryString=makeXMLsafe(theNewQueryString);setQueryString=theNewQueryString;var theString=writeFindRequest(theNewQueryString,fieldListString);sendToServer(imsQueryURL,theString,findXMLMode);}else{alert(msgList[80]);}};function writeFindRequest(findQuery,fieldList){var theString='<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" geometry="false" envelope="true"';theString+=' featurelimit="'+maxFeaturesReturned+'" beginrecord="'+queryStartRecord+'">\n';theString+='<LAYER id="'+ActiveLayer+'" />\n';if(useLimitExtent){theString+='<SPATIALQUERY subfields="'+fieldList+'" where="'+findQuery+'" />';theString+='<SPATIALFILTER relation="area_intersection">\n';theString+='<ENVELOPE maxx="'+forceComma(limitRight)+'" maxy="'+forceComma(limitTop)+'" minx="'+forceComma(limitLeft)+'" miny="'+forceComma(limitBottom)+'" />\n';theString+='</SPATIALFILTER>\n';theString+='</SPATIALQUERY>\n';}else{theString+='<QUERY subfields="'+fieldList+'" where="'+findQuery+'" />';};theString+='</GET_FEATURES>\n';theString+='</REQUEST>\n';theString+='</ARCXML>';selectLayer=ActiveLayer;selectType=ActiveLayerType;selectCount=0;hightlightedOne="";selectPoints.length=1;selectLeft.length=1;selectRight.length=1;selectTop.length=1;selectBottom.length=1;return theString;};function parseFieldSamples(theReply){var fList="";var lpos1=1;var lpos2=1;var epos=1;var spos=1;var morePoints=true;var moreFeatures=true;var pos=0;var startpos=0;var endpos=0;var featureCount=justGetFeatureCount(theReply);var tempString="";if(featureCount>0){selectData.length=featureCount;for(var i=0;i<featureCount;i++){pos=theReply.indexOf("<FIELDS ",endpos);startpos=pos+8;endpos=theReply.indexOf(' />',startpos);inData=theReply.substring(startpos,endpos);selectData[i]=inData;}}else{selectData.length=0;}};function writeQueryForm(){var startpos=0;var endpos=0;var SampleCount=selectData.length;var theIndex=fieldIndex;var sampleList=new Array();var qField=LayerFields[fieldIndex]+'="';var valueTitle=buttonList[2];var tempString="";var WindowContent='';var HeaderContent='';if(showSampleValues){for(var i=0;i<SampleCount;i++){startpos=selectData[i].indexOf(qField,0);startpos=startpos+qField.length;endpos=selectData[i].indexOf('"',startpos);if(LayerFieldType[theIndex].indexOf("12",0)!=-1){var vData=makeXMLsafe(selectData[i].substring(startpos,endpos));sampleList[i]=dQuote+vData+dQuote;}else if(LayerFieldType[theIndex]=="91"){var theDateObj=new Date(parseFloat(selectData[i].substring(startpos,endpos)));var d=theDateObj.toUTCString();sampleList[i]=d.replace(/GMT|UTC/,"");theDateObj=null;}else{sampleList[i]=selectData[i].substring(startpos,endpos);}};valueTitle=buttonList[3];};var theFrame="parent.MapFrame";if((useExternalWindow)||(!useTextFrame)){theFrame="opener";if(parent.MapFrame!=null){theFrame="opener.parent.MapFrame";}};HeaderContent+=('<script type="text/javascript" language="JavaScript" src="/JS_Library/ArcIMS_Template/aimsQueryForm.js"></script>');HeaderContent+=('			<script language="javascript">\n');HeaderContent+=('			var t = '+theFrame+';\n');HeaderContent+=('			var dQuote = \'"\';\n');HeaderContent+=('			var lastExpr = "";\n');HeaderContent+=('		var currExpr = "";\n');HeaderContent+=('		var sampleList = new Array();\n');HeaderContent+=('		var qField = "";\n');HeaderContent+=('		function addString() {');HeaderContent+=('			lastExpr = document.QueryStuff.QueryString.value;');HeaderContent+=('			qField = document.QueryStuff.QueryField.options[document.QueryStuff.QueryField.selectedIndex].value;');HeaderContent+=('			var qOperator = document.QueryStuff.QueryOperator.options[document.QueryStuff.QueryOperator.selectedIndex].value;');HeaderContent+=('				var fNum = document.QueryStuff.QueryField.selectedIndex;');if(showSampleValues){HeaderContent+=('				qString = t.parseEntity(document.QueryStuff.QueryValue.options[document.QueryStuff.QueryValue.selectedIndex].value);');}else{HeaderContent+=('					var qString = document.QueryStuff.QueryValue.value;');HeaderContent+=('					if (t.LayerFieldType[fNum].indexOf("12",0)!=-1) {');HeaderContent+=('						if (qString.indexOf(dQuote)==-1) {');HeaderContent+=('							qString = dQuote + qString + dQuote;');HeaderContent+=('						}');HeaderContent+=('					}');}HeaderContent+=('					if (t.LayerFieldType[fNum].indexOf("91",0)!=-1) {');HeaderContent+=('						qString = t.formatDate(qString);');HeaderContent+=('					}');HeaderContent+=('					if ((t.LayerFieldType[fNum].indexOf("4",0)!=-1) || (t.LayerFieldType[fNum].indexOf("8",0)!=-1) || ');HeaderContent+=('			 		 (t.LayerFieldType[fNum].indexOf("6",0)!=-1) || (t.LayerFieldType[fNum].indexOf("5",0)!=-1)) {');HeaderContent+=('					qString = t.convertDecimal(qString);');HeaderContent+=('					}');HeaderContent+=('				var qString2 = document.QueryStuff.QueryString.value;');HeaderContent+=('				var theString =  qField + " " + qOperator + " " + qString;');HeaderContent+=('				if (qString2.length>2) {	document.QueryStuff.QueryString.value = qString2 + " AND " + theString; }');HeaderContent+=('				else { document.QueryStuff.QueryString.value = qString2 + theString; }');HeaderContent+=('				currExpr = document.QueryStuff.QueryString.value;');HeaderContent+=('			}\n');HeaderContent+=(' 		function sendQuery() {');HeaderContent+=(' 			var theString = document.QueryStuff.QueryString.value;');HeaderContent+=(' 			if (theString!="") {');HeaderContent+=(' 				var ary = new Array("<",">","="," LIKE "," like "," IS "," is ");');HeaderContent+=(' 				var va = 0;');HeaderContent+=(' 				var arylen = ary.length;');HeaderContent+=(' 				for (i=0;i<arylen;i++) {');HeaderContent+=(' 					a = ary[i];');HeaderContent+=(' 					s = theString.search(a);');HeaderContent+=(' 					va = va + s;');HeaderContent+=(' 				}');HeaderContent+=(' 				if (va == -7) {');HeaderContent+=(' 					alert("'+msgList[109]+'");');HeaderContent+=(' 				} else {');HeaderContent+=(' 					sampleList=null;');HeaderContent+=(' 					t.sendQueryString(theString);');HeaderContent+=(' 					t=null;');HeaderContent+=(' 				}');HeaderContent+=(' 			} else {');HeaderContent+=(' 				alert("'+msgList[110]+'");');HeaderContent+=(' 			}');HeaderContent+=(' 			self.close();');HeaderContent+=(' 		}\n');HeaderContent+=('		</script>');WindowContent+=('			<form name="QueryStuff" onsubmit="sendQuery();return false;">');WindowContent+=('			<table border="0" cellspacing="0" cellpadding="2" width=100%>');WindowContent+=('			<tr><td colspan="3"  bgcolor="'+textFrameBackColor+'">');WindowContent+=('<strong><u>Current Query String:</u></strong></td></tr>');WindowContent+=('			<tr><td colspan="3"  bgcolor="'+textFrameBackColor+'">');WindowContent+=('			<textarea id="Additional_Query" name="QueryString" cols="50" rows="4">'+setQueryString+'</textarea><br />');WindowContent+=('			<input type="submit" value="'+buttonList[6]+'" name="submit" />');WindowContent+=('			<input type="button" name="Clear" value="'+buttonList[8]+'" onclick="clearString()" />');WindowContent+=('			</td></tr>');WindowContent+=('			<tr><td colspan="3"  bgcolor="'+textFrameBackColor+'">');WindowContent+=('<hr /><strong><u>Add Condition to Querystring:</u></strong></td></tr>');WindowContent+=('			<tr><td  bgcolor="'+textFrameBackColor+'"><small>'+msgList[72]+'</small></td>');WindowContent+=('			<td  bgcolor="'+textFrameBackColor+'"><small>'+msgList[73]+'</small></td>');WindowContent+=('			<td  bgcolor="'+textFrameBackColor+'"><small>'+valueTitle+'</small></td>');WindowContent+=('			</tr>');WindowContent+=('			<tr><td  bgcolor="'+textFrameBackColor+'">');WindowContent+=('			<select name="QueryField" onchange="setUp();">');for(var i=0;i<LayerFieldCount;i++){WindowContent+=('<option value="'+LayerFields[i]+'"');if(i==fieldIndex)WindowContent+=(' selected');if(useFieldAlias){if(fieldAliasList[ActiveLayerIndex].length>0){var start=fieldAliasList[ActiveLayerIndex].indexOf(LayerFields[i]+':');if(start==-1){alias=LayerFields[i];}else{start=start+LayerFields[i].length+1;var end=fieldAliasList[ActiveLayerIndex].indexOf("|",start);if(end==-1){end=fieldAliasList[ActiveLayerIndex].length;}else{end=end-start;}alias=fieldAliasList[ActiveLayerIndex].substr(start,end);}WindowContent+=('>'+alias);}}else{WindowContent+=('>'+LayerFields[i]+'</option>');}}WindowContent+=('			</select>');WindowContent+=('			</td><td  bgcolor="'+textFrameBackColor+'">');WindowContent+=('			<select name="QueryOperator">');WindowContent+=('			<option selected value=" = ">=</option>');WindowContent+=('			<option value=" < ">&lt;</option>');WindowContent+=('			<option value=" > ">&gt;</option>');WindowContent+=('			<option value=" <= ">&lt;=</option>');WindowContent+=('			<option value=" >= ">&gt;=</option>');WindowContent+=('			<option value=" LIKE ">LIKE</option>');WindowContent+=('			</select>');WindowContent+=('			</td><td  bgcolor="'+textFrameBackColor+'">');if(showSampleValues){WindowContent+=('			<select name="QueryValue">');for(var i=0;i<SampleCount;i++){tempString=parseEntity(sampleList[i]);tempString=tempString.replace(' ',"&nbsp;");WindowContent+=('<option value=\'' + sampleList[i] + '\'>'+tempString+'</option>');}WindowContent+=('			</select>');}else{WindowContent+=('<input name="QueryValue" size="25" maxlength="1000" >');WindowContent+=('			</td>');}WindowContent+=('			</td>');WindowContent+=('			</tr>');WindowContent+=('			<tr><td colspan="3"  bgcolor="'+textFrameBackColor+'">');WindowContent+=('			<input type="button" name="addIt" value="'+buttonList[5]+'" onclick="addString()" />');WindowContent+=('			</td>');WindowContent+=('			</tr>');WindowContent+=('			</table>');WindowContent+=('</form>');Create_Pop_Up_Window('Query Window',HeaderContent,WindowContent,'QueryFormWindow','width=500,height=300,scrollbars=yes,resizable=yes');sampleList=null;}function tempGetSamples(theField){var WindowContent='';showSampleValues=true;Create_Pop_Up_Window(msgList[74]+LayerName[ActiveLayerIndex]+'. . .','',msgList[75]+numberDataSamples+msgList[76],'QueryWindow','width=575,height=150,scrollbars=yes,resizable=yes');var theText=writeFieldSample(theField);sendToServer(imsQueryURL,theText,40);}function getStoredQueries(){if(checkIfActiveLayerAvailable()){var theString='<ARCXML version="1.1">\n<REQUEST>\n<GET_SERVICE_INFO renderer="false" extensions="true" fields="false" />\n';theString+='</REQUEST>\n</ARCXML>';sendToServer(imsQueryURL,theString,55);}}function parseStoredQueries(theReply){storedQueryCount=0;storedQueryName.length=1;storedQueryString.length=1;storedQueryVariable.length=1;storedQueryVarCount.length=1;storedQueryFieldList.length=1;storedQueryIndex=0;var endpos=1;var pos=-1;var blurb='id="'+ActiveLayer;var startpos=theReply.indexOf("<LAYERINFO",1);var thePos=1;while(thePos!=-1){startpos=theReply.indexOf("<LAYERINFO",1);endpos=theReply.indexOf(">",startpos);thePos=theReply.indexOf(blurb,1);if(thePos!=-1){pos=thePos;thePos=-1;}}var sqpos=0;var sqvpos=0;var sqpos2=0;var vCount=0;if(pos!=-1){var fieldCount=0;epos=theReply.indexOf("</LAYERINFO>",pos);startpos=0;endpos=pos;sqpos=theReply.indexOf("<STOREDQUERY name=",endpos);sqpos2=theReply.indexOf("</STOREDQUERY>",endpos);while((epos>sqpos)&&(sqpos!=-1)){if(sqpos!=-1){startpos=sqpos+19;endpos=theReply.indexOf(dQuote,startpos);blurb=theReply.substring(startpos,endpos);storedQueryName[storedQueryCount]=blurb;var sp2=theReply.indexOf("<QUERY ",endpos);sp2+=7;startpos=theReply.indexOf("where=",sp2);startpos+=7;endpos=theReply.indexOf(dQuote,startpos);blurb=theReply.substring(startpos,endpos);storedQueryString[storedQueryCount]=blurb;startpos=theReply.indexOf("subfields=",sp2);startpos+=11;endpos=theReply.indexOf(dQuote,startpos);storedQueryFieldList[storedQueryCount]=theReply.substring(startpos,endpos);storedQueryVariable[storedQueryCount]="";sqvpos=theReply.indexOf("<SQVAR",startpos);vCount=0;while((sqvpos!=-1)&&(sqvpos<sqpos2)){endpos=sqvpos;startpos=theReply.indexOf("name=",endpos);startpos+=6;endpos=theReply.indexOf(dQuote,startpos);blurb=theReply.substring(startpos,endpos);if(vCount>0){blurb="|"+blurb;}storedQueryVariable[storedQueryCount]=storedQueryVariable[storedQueryCount]+blurb;vCount+=1;sqvpos=theReply.indexOf("<SQVAR",startpos);}storedQueryVarCount[storedQueryCount]=vCount;storedQueryCount+=1;}sqpos=theReply.indexOf("<STOREDQUERY name=",endpos);sqpos2=theReply.indexOf("</STOREDQUERY>",sqpos);}}blurb=null;if(storedQueryCount==0){alert(LayerName[ActiveLayerIndex]+msgList[77]);}else{storedQueryForm();}}function storedQueryForm(){if(checkIfActiveLayerAvailable()){writeStoredQueryForm(storedQueryIndex);}}function writeStoredQueryForm(theIndex){var WindowContent='';var HeaderContent='';storedQueryIndex=theIndex;if(storedQueryVarCount==0){sendStoredQuery(theIndex,"");}else{HeaderContent+=('<script type="text/javascript" language="JavaScript" src="/JS_Library/ArcIMS_Template/aimsQueryForm.js"></script>');HeaderContent+=('<script language="javascript">\n');HeaderContent+=('var t = '+t+';');HeaderContent+=('</script>');WindowContent+=('<div align="center">');WindowContent+=('<small><strong>');WindowContent+=('<form action="" name="theStoreQueryForm" onsubmit="setStyle(); return false;">');WindowContent+=('<table cellspacing="2" nowrap="nowrap" bgcolor="'+textFrameFormColor+'" width="100%">');WindowContent+=('<tr><th colspan="3" align="center">');WindowContent+=('<strong><h2>'+msgList[78]+'</h2></strong><br />');WindowContent+=('<small><strong>'+msgList[79]+'</strong></small>');WindowContent+=('</th></tr>');WindowContent+=('<tr>');WindowContent+=('<td align="left">');WindowContent+=(LayerName[ActiveLayerIndex]);WindowContent+=('<select name="theQuery" onchange="selectQuery()">');for(var i=0;i<storedQueryCount;i++){WindowContent+=('	<option value='+i);if(i==storedQueryIndex){WindowContent+=(' selected');}WindowContent+=('>'+storedQueryName[i]+'</option>');}WindowContent+=('</select>');WindowContent+=('</small></td>');WindowContent+=('<td align="right">');for(var i=0;i<storedQueryVarCount[storedQueryIndex];i++){WindowContent+=('<label for="Stored Query '+i+'">'+buttonList[2]);if(storedQueryVarCount[storedQueryIndex]>1){WindowContent+=(' '+(i+1));}WindowContent+=(':</label>');WindowContent+=('<input type=text id="Stored Query '+i+'" name="theStyle" value="" /><br />');}WindowContent+=('</td>');WindowContent+=('<td align="center">');WindowContent+=('<input type="Button" name="setDU" value="'+buttonList[6]+'" onclick="setStyle()" />  <br />');WindowContent+=('</td></tr></table></form>');WindowContent+=('</b></small></div>');Create_Pop_Up_Window('Stored Query Form',HeaderContent,WindowContent,'QueryWindow','width=575,height=150,scrollbars=yes,resizable=yes');}}function sendStoredQuery(theIndex,theValue){showRetrieveData();var oldString=storedQueryString[theIndex];if(storedQueryVarCount[theIndex]>0){var var1=storedQueryVariable[theIndex].split("|");var var2=theValue.split("|");for(var i=0;i<var1.length;i++){oldString=swapStuff(oldString,var1[i],var2[i]);}}else{oldString=swapStuff(oldString,storedQueryVariable[theIndex],theValue);}var newString=makeXMLsafe(oldString);setQueryString=newString;selectionMode=1;var theString=writeQueryXML(newString);sendToServer(imsQueryURL,theString,queryXMLMode);}function checkStoredQueries(theReply){var startpos=theReply.indexOf("<STOREDQUERY",1);if(startpos==-1){useStoredQuery=false;}}function writeStartQueryXML(queryString,idAndShapeOnly){if(swapSelectFields){selectFields=selFieldList[ActiveLayerIndex];}var theString='<ARCXML VERSION="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" geometry="false" envelope="true"';theString+=' compact="true" featurelimit="'+maxFeaturesReturned+'" beginrecord="0">\n';theString+='<LAYER id="'+LayerID[ActiveLayerIndex]+'" />';if(idAndShapeOnly){theString+='<QUERY subfields="#ID# #SHAPE#" where="'+queryString+'" />';}else{theString+='<QUERY subfields="'+selectFields+'" where="'+queryString+'" />';}theString+='</GET_FEATURES>';theString+='</REQUEST>';theString+='</ARCXML>';return theString;};function setStartQuery(){var theString=writeStartQueryXML(highlightedOne,true);sendToServer(imsQueryURL,theString,20);};function parseStartQuery(theReply){var theError=getXMLErrorMessage(theReply);if(theError==""){if(queryZoom){getXYs(theReply);startLeft=eLeft;startTop=eTop;startRight=eRight;startBottom=eBottom;var fWidth=eRight-eLeft;var fHeight=eTop-eBottom;var mWMargin=0;var mHMargin=0;if(LayerType[ActiveLayerIndex]=="point"){selectType="point";mWMargin=fullWidth*selectPointMargin;mHMargin=fullHeight*selectPointMargin;}else{mWMargin=fWidth*selectMargin;mHMargin=fHeight*selectMargin;}eLeft=eLeft-mWMargin;eRight=eRight+mWMargin;eTop=eTop+mHMargin;eBottom=eBottom-mHMargin;startLeft=eLeft;startTop=eTop;startRight=eRight;startBottom=eBottom;};sendMapXML();}else{alert(theError);}}

