var GCid = new Array();
var GCpointX = new Array();
var GCpointY = new Array();
var GCpointCount = 0;
var GCscore = new Array();
var GCaddress = new Array();

// character used by browser in decimals - either point or comma
var decimalChar = ((("theChar is" + (10/100)).indexOf("."))==-1) ? "," : ".";

if (imsGeocodeURL=="") {
	imsGeocodeURL= imsURL + "&CustomService=Geocode";
}


// parse out geocode response and display results in table
function parseGeocodeResults(theReply) {
	GCscore.length=1;

	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;
	var tempX,tempY;
	var theFrame;
	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);
					tempX = theReply.substring(startpos,endpos);
					GCpointX[gcCount]= parseFloat(setDecimalString(tempX)); 
					startpos = theReply.indexOf("y=",endpos);
					startpos = startpos + 3;
					endpos = theReply.indexOf(dQuote,startpos);
					tempY = theReply.substring(startpos,endpos);
					GCpointY[gcCount]= parseFloat(setDecimalString(tempY));   
					gcCount++;
				}
				pos = theReply.indexOf("<FEATURE",endpos);
			}
		}

		showGeocode=true;
		geocodeX=GCpointX[0];
		geocodeY=GCpointY[0];
		geocodeLabel=GCaddress[0];

                var evLeft;
      	        var evBottom;
	        var evRight;
	        var evTop;
		var offst = bufferDistance;
		if (ScaleBarUnits == "miles")  {
			offst = offst * 5280;
		} else {
			offst = offst * 1;
		}

		var gPointX, gPointY
		hideLayer('loading');

		//show query to user in the message frame of the MAP
		for (var i=0;i<GCpointCount && i<1;i++) {	//only show the first match
			gPointX = convertDecimal(GCpointX[i].toString()); 
			gPointY = convertDecimal(GCpointY[i].toString());
			evLeft = GCpointX[i] - offst;
			evBottom = GCpointY[i] - offst;
			evRight = GCpointX[i] + offst;
			evTop = GCpointY[i] + offst;
		}

	} else {
		//no match
		alert("Unable to locate address: "+locmsg);
	}
	
}

// format decimal numerics from comma to point
// 	SQL format requires English notation
function convertDecimal(theNumString) {
	var replacer = "."
	var re = /,/g;
	var newString = theNumString.replace(re,replacer);
	return newString;
}
