aimsXMLPresent=true;
var cVersion = "&ClientVersion=3.1"; 
var selectXMLMode = 6;
var queryXMLMode = 8;
var findXMLMode = 14;
var charEncoding = "UTF-8";
var localeEncoding = 'encoding="' + charEncoding + '" ';
var charSet = "ISO-8859-1"
var formColor = "#000000";
var XMLMode = 1;
var okToSend = true;
var xHalf = xDistance/2;
var yHalf = yDistance/2;
var xmlEndPos = 0;
var drawOVExtentBox=false;
var forceNewOVMap = false;
var connectorURL = "http://" + hostName + "/servlet/com.esri.esrimap.Esrimap?ServiceName=redirect";
var activeMapServiceIndex = 0;
var forceCommaInRequest = new Array();
forceCommaInRequest[activeMapServiceIndex] = false;
var forceCommaInOV = false;
var pastStart=false;
if (hasOVMap != true) pastStart = true;

function sendToServer(URLString,XMLRequest,theType) {
	if (parent.PostFrame.document.forms[0]!=null) {
		if (okToSend) {
			XMLMode = theType;
			if (XMLMode==1) showRetrieveMap();
			okToSend = false;
			var theForm = parent.PostFrame.document.forms[0];
			URLString = URLString + cVersion;
			var requestURL = URLString;
			if (theForm.RedirectURL!=null) {
				if (isNotSameHostInURL(URLString, hostName)) {
					requestURL = connectorURL;
					theForm.RedirectURL.value = URLString;		
				} else {
					theForm.RedirectURL.value = "";
				}
			}
			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 = charSet;
			if (theForm.BgColor!=null) theForm.BgColor.value = formColor;
			theForm.submit();
				
		} else {
			alert(msgList[10]);
			hideRetrieveMap();
			hideRetrieveData();
		}
	} else {
		alert(msgList[11]);
			hideRetrieveMap();
			hideRetrieveData();
	}
		
}



function sendMapXML() {	if (InToolBar!=true) {
		beforeMapRefresh();
		if (InActiveArea==true){
			if (FromURL){
				FromURL=false;
				var temp=parent.document.location.href;
				var i=temp.indexOf("?");
				if (i!=-1)
				{
					var ValAtt=temp.split('?')[1].split('&');
					var MinX=ValAtt[0].split('=')[1];
					var MinY=ValAtt[1].split('=')[1];
					var MaxX=ValAtt[2].split('=')[1];
					var MaxY=ValAtt[3].split('=')[1];
					var Lid=ValAtt[4].split('=')[1];
					CopyrightText = Map_Description[Lid]; 
	                                for (var ii=0;ii<layerCount;ii++)
	                                {
	                                  if(LayerID[ii]!=1 && LayerVisible[ii]!=2)
	                                  {
	                                    LayerVisible[ii] = (LayerID[ii]==Lid) ? 1 : 0;	  
	                                  }
	                                }
	                                ImageRef="/gifs/m"+Lid+".gif";
	                                if (is5up) document.getElementById("iClock").src=ImageRef;
	                                else document.all.iClock.src=ImageRef;
	                        }
	}
			showRetrieveMap();
			var theText = writeXML();
			if (debugOn==2) alert(msgList[12] + theText);
			sendToServer(imsURL,theText,1);
		}
	}
	else {
		
	eLeft = MSstartLeft;
	eRight = MSstartRight;
	eTop = MSstartTop;
	eBottom = MSstartBottom;
	showRetrieveMap();
	var theText = writeXML();
	if (debugOn==2) alert(msgList[12] + theText);
	sendToServer(imsURL,theText,1);	
	}
}


function processXML(theReplyIn) {
	if (doURLencode) {
		theReplyIn = replacePlus(theReplyIn);
		var theReply = unescape(theReplyIn);
	} else {
		var theReply = theReplyIn;
	}	
	okToSend = true;
	var theError = getXMLErrorMessage(theReply);
	switch(XMLMode) {
		case 1:
			var theURL = "";
			theURL = getURL(theReply);
			
			if (theURL != "") {
				getXYs(theReply);
				document.theImage.src = theURL;
				afterMapRefresh();
				if (toolMode==3) {
					moveLayer("theMap",hspc,vspc);
					clipLayer2("theMap",0,0,iWidth,iHeight);
					window.setTimeout('showLayer("theMap");',1000);
					if (hasLayer("theMapClicks")) {
						moveLayer("theMapClicks",hspc,vspc);
						clipLayer2("theMapClicks",0,0,iWidth,iHeight);
				
					}
				}
				
			}
			else
			{
			  alert(msgList[14] + theError);
			}
			if (toolMode==20) {
				updateMeasureBox();
			}
			if (hasOVMap) {
				if (ovIsVisible) {
					if ((!pastStart) || (forceNewOVMap)) {
						theText = writeOVXML();
						sendToServer(imsOVURL,theText,2);
					} else {
						putExtentOnOVMap();
						hideRetrieveMap();
					}
				} else {
					if ((!pastStart) || (forceNewOVMap)) {
						theText = writeOVXML();
						sendToServer(imsOVURL,theText,2);
					} else {
						hideRetrieveMap();
					}
				
				}
			} else {
				hideRetrieveMap();
			}
			if (is5up) document.getElementById('FExtent').src="/gifs/t/i_fullextent.gif";
			else document.all.FExtent.src="/gifs/t/i_fullextent.gif";
			break;

		case 2:
			var theURL = "";
			theURL = getURL(theReply);
			
			if (!pastStart) {
				getOVXYs(theReply);
				pastStart=true;	
			}
			if (theURL != "") {
				if (is5up) document.getElementById('ovImage').src=theURL;
				else ovImageVar.src = theURL; 
			}
			else {
			  alert(msgList[16] + theError);
			}
			if (ovIsVisible) putExtentOnOVMap();
			hideRetrieveMap();
			break

		case 3:
			if (getLimitExtent) {
				getXYs(theReply);
				fullLeft = eLeft;
				fullRight = eRight;
				fullTop = eTop;
				fullBottom = eBottom;
				fullOVLeft = eLeft;
				fullOVRight = eRight;
				fullOVTop = eTop;
				fullOVBottom = eBottom;
				limitLeft = eLeft;
				limitRight = eRight;
				limitTop = eTop;
				limitBottom = eBottom;
			} else {
				fullLeft = limitLeft;
				fullRight = limitRight;
				fullTop = limitTop;
				fullBottom = limitBottom;
				fullOVLeft = limitLeft;
				fullOVRight = limitRight;
				fullOVTop = limitTop;
				fullOVBottom = limitBottom;
				
				
			}
			
			fullWidth = Math.abs(fullRight - fullLeft);
			fullHeight = Math.abs(fullTop - fullBottom);
			fullOVWidth = Math.abs(fullOVRight - fullOVLeft);
			fullOVHeight = Math.abs(fullOVTop - fullOVBottom);
			theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_SERVICE_INFO />\n';
			theString += '</REQUEST>\n</ARCXML>';
				theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_SERVICE_INFO  renderer="false" extensions="true" />\n';
				theString += '</REQUEST>\n</ARCXML>';
				sendToServer(imsURL,theString,4);
			
			break

		case 4:
			forceCommaInRequest[activeMapServiceIndex] = false;
			processStartExtent(theReply);			
			break

		case 5:
			processCatalog(theReply);			
			break

		case 25:
			var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_SERVICE_INFO  renderer="false" extensions="true" />\n';
			theString += '</REQUEST>\n</ARCXML>';
			sendToServer(imsURL,theString,4);
			
			break

		case 26:
			break

		case 27:
			break

		case 98:
			var theURL = "";
			theURL = getURL(theReply);
			if (theURL != "") {
				document.theImage.src = theURL;
			}
			hideRetrieveMap();
			
			break

		case 99:
			var theURL = "";
			theURL = getURL(theReply);
			if (theURL != "") {
				document.theImage.src = theURL;
			}
			else {
				alert(msgList[14] + theReply);
			}
			hideRetrieveMap();
			
			break

		case 900:
			var theURL = "";
			theURL = getURL(theReply);
			if (theURL != "") {
				getXYs(theReply);
				document.theImage.src = theURL;
			}
			
			break


		case 902:
			var theURL = "";
			theURL = getURL(theReply);
			if (theURL != "") {
				document.ovImage2.src = theURL; 
			}
			var tempLeft = fullLeft;
			var tempRight = fullRight;
			var tempTop = fullTop;
			var tempBottom = fullBottom;
			getOVXYs(theReply);
			fullLeft = tempLeft;
			fullRight = tempRight;
			fullTop = tempTop;
			fullBottom = tempBottom;
			
			break
		
		case 998:
			var tempLeft = limitLeft;
			var tempRight = limitRight;
			var tempTop = limitTop;
			var tempBottom = limitBottom;
			getOVXYs(theReply);
			limitLeft = tempLeft;
			limitRight = tempRight;
			limitTop = tempTop;
			limitBottom = tempBottom;
			var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_SERVICE_INFO renderer="false" extensions="false" fields="false" />\n';
			theString = theString + '</REQUEST>\n</ARCXML>';
			sendToServer(imsURL,theString,3);			
			break

		case 999:
			var tempLeft = eLeft;
			var tempRight = eRight;
			var tempTop = eTop;
			var tempBottom = eBottom;
			getXYs(theReply);
			imageLimitLeft=eLeft;
			imageLimitRight=eRight;
			imageLimitTop=eTop
			imageLimitBottom=eBottom;
			eLeft = tempLeft;
			eRight = tempRight;
			eTop = tempTop;
			eBottom = tempBottom;
			sendMapXML();
			break

		default:
			alert(theReply + msgList[19]);			
		}
			
}


function writeBlankMapXML() {
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n<ENVELOPE minx="' + forceComma(limitLeft) + '" miny="' + forceComma(limitBottom) + '" maxx="' + forceComma(limitRight) + '" maxy="' + forceComma(limitTop) + '" />\n';
	theString += '<IMAGESIZE height="' + iHeight + '" width="' + iWidth + '" />\n';
	var visString = "";
	if (aimsLayersPresent) {
		theString += '<LAYERLIST >\n';
		for (var i=0;i<layerCount;i++) {
			theString += '<LAYERDEF name="' + LayerName[i] + '" visible="false" />\n';
			
		}
		theString += '</LAYERLIST>\n';
	}
	theString += '</PROPERTIES>\n';
	theString += '</GET_IMAGE>\n</REQUEST>\n</ARCXML>';
	sendToServer(imsURL,theString,999);
}


function writeXML() {
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n<ENVELOPE minx="' + forceComma(eLeft) + '" miny="' + forceComma(eBottom) + '" maxx="' + forceComma(eRight) + '" maxy="' + forceComma(eTop) + '" />\n';
	theString += '<IMAGESIZE height="' + iHeight + '" width="' + iWidth + '" />\n';
	var visString = "";
	if (aimsLayersPresent) {
		if (toggleVisible) {
			theString += '<LAYERLIST order="true">\n';
			for (var i=0;i<layerCount;i++){
				if (LayerVisible[i]==1 && LayerID[i]!=1 && LayerID[i]!=2) {
					theString += '<LAYERDEF id="' + LayerID[i] + '" visible="true"  />\n';
				}
				else if(LayerID[i]!=1){
					theString += '<LAYERDEF id="' + LayerID[i] + '" visible="false" />\n';
				}
				
			}
			for (var i=0;i<layerCount;i++) {
				if (LayerVisible[i]==1 && LayerID[i]==1) {
					theString += '<LAYERDEF id="1" visible="true" />\n';
				}
				else if(LayerID[i]==1)
				{
				  theString += '<LAYERDEF id="1" visible="false" />\n';
				}
			}
			theString += '<LAYERDEF id="2" visible="true" />\n';
			theString += '<LAYERDEF id="100" visible="true" />\n';
                        theString += '</LAYERLIST>\n';
		}
	}
	if (mapTransparent) {
		theString += '<BACKGROUND color="255,255,254" transcolor="255,255,254" />\n';
	} else {
		if (mapBackColor!="") {
			theString += '<BACKGROUND color="' + mapBackColor + '" />\n\n';
		}
	}
	
	theString += '</PROPERTIES>\n';
	
	if (aimsClickPresent){
		if (clickCount>0) {
			// draw click points and lines between them on map
			var clickColor = selectColor;
			if (clickType==1) clickColor = clickMarkerColor;
			theString += '<LAYER type="acetate" name="allTheClicks">\n';
			if (clickCount>1) {
				theString += '<OBJECT units="database">\n<LINE coords="' + forceComma(clickPointX[0]) + coordsDelimiter + forceComma(clickPointY[0]);
				for (var i=1;i<clickCount;i++) {
					theString += pairsDelimiter  + forceComma(clickPointX[i]) + coordsDelimiter + forceComma(clickPointY[i]); 
				}
				theString += '" >\n';
				theString += '<SIMPLELINESYMBOL type="solid" color="' + clickMarkerColor;
				theString += '" width="3" />\n</LINE>\n</OBJECT>\n'; 
				theString += '<OBJECT units="database">\n<LINE coords="' + forceComma(clickPointX[0]) + coordsDelimiter + forceComma(clickPointY[0]);
				for (var i=1;i<clickCount;i++) {
					theString += pairsDelimiter  + forceComma(clickPointX[i]) + coordsDelimiter + forceComma(clickPointY[i]); 
				}
				theString += '" >\n';
				theString += '<SIMPLELINESYMBOL type="solid" color="255,255,255" width="1" />\n</LINE>\n</OBJECT>\n'; 
	 		}
			for (var i=0;i<clickCount;i++) {
				theString += '<OBJECT units="acetate">\n<POINT coords="' + forceComma(clickPointX[i]) + coordsDelimiter + forceComma(clickPointY[i]) + '">\n';
				theString += '<SIMPLEMARKERSYMBOL  type="' + clickMarkerType + '"';
				theString += ' color="' + clickMarkerColor + '" width="' + clickMarkerSize + '" />\n</POINT>\n</OBJECT>\n';
			}
			theString += '</LAYER>\n';
		}
	}
	
	if (drawCopyright) {
		CopyrightCoords = CopyrightCoordsX*mWidth +' '+CopyrightCoordsY*mHeight;
		checkCoords();
		theString += '<LAYER type="acetate" name="theCopyright" id="100">\n';		
		theString += '<OBJECT units="pixel">\n<TEXT coords="' + CopyrightCoords + '" label="' + CopyrightText + '">\n';
		theString += '<TEXTMARKERSYMBOL fontstyle="' + CopyrightStyle + '" fontsize="' + CopyrightSize + '" ';
		theString += 'font="' + CopyrightFont + '" fontcolor="' + CopyrightColor + '" antialiasing="True" ';
		if (CopyrightBackground.toUpperCase()=="TRUE") theString += 'blockout="' + CopyrightBGColor + '" ';
		theString += 'shadow="32,32,32" overlap="false" ';
		if (CopyrightGlow.toUpperCase()=="TRUE") theString += ' glowing="' + CopyrightGlowColor + '" ';
		theString += '/>\n</TEXT>\n</OBJECT>\n';
		theString += '</LAYER>\n';
	}

	if (drawNorthArrow) {
		// draw a north arrow
		theString += '<LAYER type="ACETATE" name="theNorthArrow">\n';
		theString += '<OBJECT units="PIXEL">\n<NORTHARROW type="' + NorthArrowType + '" size="' + NorthArrowSize + '" coord="' + NorthArrowCoords + '" shadow="32,32,32" ';
		theString += 'angle="' + NorthArrowAngle + '" antialiasing="True" overlap="False" />\n</OBJECT>\n';
		theString += '</LAYER>\n';
	}	
	if (drawModeOnMap) {
		theString += '<LAYER type="acetate" name="theMode">\n';
		theString += '<OBJECT units="pixel">\n<TEXT coords="5' + coordsDelimiter + (iHeight-10) + '" label="' + modeBlurb + '">\n';
		theString += '<TEXTMARKERSYMBOL fontstyle="BOLD" fontsize="12" font="ARIAL" fontcolor="' + modeMapColor + '" ';
		theString += 'threed="TRUE" glowing="' + modeMapGlow + '" overlap="false" />\n</TEXT>\n</OBJECT></LAYER>';
	
	}
	
	theString += '</GET_IMAGE>\n</REQUEST>\n</ARCXML>';
	return theString;
}

function writeOVXML() {
	var extentRatio = xDistance/fullWidth;
	var midX = eLeft + xHalf;
	var midY = eBottom + yHalf;
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_IMAGE><PROPERTIES>\n';
	theString += '<ENVELOPE minx="' + forceOVComma(fullOVLeft) + '" miny="' + forceOVComma(fullOVBottom) + '" maxx="' + forceOVComma(fullOVRight) + '" maxy="' + forceOVComma(fullOVTop) + '" />\n';
	theString += '<IMAGESIZE height="' + i2Height + '" width="' + i2Width + '" printheight="' + i2Height+ '" printwidth="'+ i2Width +'" />\n';
	if ((toggleOVVisible) && (imsURL==imsOVURL)) {
		theString += '<LAYERLIST >\n';
		for (var i=0;i<layerCount;i++) {
			if (LayerVisible[i]==1) {
				visString = "true";
			}
			else {
				visString = "false";
			}
			theString += '<LAYERDEF name="' + LayerName[i] + '" visible="' + visString + '" />\n';
			
		}
		theString += '</LAYERLIST>\n';
	}
	if (mapBackColor!="") {
		theString += '<BACKGROUND color="' + mapBackColor + '" />\n';
	}
	
	theString += '</PROPERTIES>\n';
	if (drawOVExtentBox) {
		theString += '<LAYER type="acetate" name="ACETATE">\n';
		if (extentRatio<(1/100)) {
			theString += '<OBJECT units="database">\n<POINT coord="' + forceOVComma(midX) + coordsDelimiter + forceOVComma(midY) + '">\n';
			theString += '<SIMPLEMARKERSYMBOL  type="Square" color="' + ovBoxColor + '" width="4" />\n</POINT></OBJECT>\n';
		} else {
			theString += '<OBJECT units="database">\n<LINE coords="' + forceOVComma(eLeft) + coordsDelimiter + forceOVComma(eBottom) + pairsDelimiter + forceOVComma(eLeft) + coordsDelimiter + forceOVComma(eTop) + pairsDelimiter;
			theString += forceOVComma(eRight) + coordsDelimiter + forceOVComma(eTop) + pairsDelimiter + forceOVComma(eRight) + coordsDelimiter + forceOVComma(eBottom) + pairsDelimiter + forceOVComma(eLeft) + coordsDelimiter + forceOVComma(eBottom) + '">\n';
			theString += '<SIMPLELINESYMBOL type="solid" color="' + ovBoxColor + '" width="3" />\n</LINE></OBJECT>\n';
		}
		theString += '</LAYER>\n';
	}
	theString += '</GET_IMAGE>\n</REQUEST>\n</ARCXML>';
	return theString;
}

function getXYs(theString) {
	var tempStr = "";
	var smallStr = "";
	var startpos = 0;
	var endpos = 0;
	var theReply = theString
	var theXYs =  getEnvelopeXYs(theString, 0)
	eLeft = theXYs[0];
	eBottom = theXYs[1];
	eRight = theXYs[2];
	eTop = theXYs[3];
	xDistance = Math.abs(eRight-eLeft);
	yDistance = Math.abs(eTop-eBottom);
	xHalf = xDistance / 2;
	yHalf = yDistance / 2;
	panX = xDistance * panFactor;
	panY = yDistance * panFactor;
	var sFactor = xDistance / iWidth
	if (aimsLayersPresent) {
		if (sFactor!=mapScaleFactor) {
			mapScaleFactor = sFactor;
			if (aimsLayersPresent) {
				if (LayerListOpen) writeLayerListForm();
			}
			
		} 
	}
}


function getOVXYs(theString) {
	var tempStr = "";
	var smallStr = "";
	var startpos = 0;
	var endpos = 0;
	var tempComma = forceCommaInRequest[activeMapServiceIndex];
	var theXYs =  getEnvelopeXYs(theString, 0)
	forceCommaInOV = forceCommaInRequest[activeMapServiceIndex];
	forceCommaInRequest[activeMapServiceIndex] = tempComma;
	fullOVLeft = theXYs[0];
	fullOVBottom = theXYs[1];
	fullOVRight = theXYs[2];
	fullOVTop = theXYs[3];
	fullOVWidth = Math.abs(fullOVRight - fullOVLeft);
	fullOVHeight = Math.abs(fullOVTop - fullOVBottom);
}

function getURL(theReply) {
	var theURL = "";
	var startpos = 0;
	var endpos = 0;
	var pos = theReply.indexOf("OUTPUT");
	if (pos != -1) {
		theURL = getInsideString(theReply,'url="',dQuote,pos,0,false);
	}
	if (hostName==localhostName)  theURL='http://'+localhostName+'/output'+theURL.split('output')[1];
	return theURL;

}



function justGetMap(theURL, extentLeft, extentTop, extentRight, extentBottom, getOVMap) {
	var mode = 900;
	if (getOVMap) mode = 1;
	if (extentLeft!="") eLeft = extentLeft;
	if (extentTop!="") eTop = extentTop
	if (extentRight!="") eRight = extentRight;
	if (extentBottom!="") eBottom = extentBottom;
	var theText = writeXML();
	if (debugOn==2) alert(msgList[12] + theText);	
	sendToServer(theURL,theText,mode);
}

function getEnvelopeXYs(theString, startpos) {
	var theEnvelope = new Array();
	theString = theString.toUpperCase();
	var tempString = "";
	var pos = theString.indexOf("ENVELOPE",startpos);
	if (pos!=-1) {
		pos = pos + 8;
		startpos = theString.indexOf("MINX=",pos);
		startpos += 6;
		var endpos = theString.indexOf(dQuote,startpos);
		tempString = theString.substring(startpos,endpos);
		theEnvelope[0] = parseFloat(setDecimalString(tempString)); 
		startpos = theString.indexOf("MINY=",pos);
		startpos += 6;
		endpos = theString.indexOf(dQuote,startpos);
		tempString = theString.substring(startpos,endpos);
		theEnvelope[1] = parseFloat(setDecimalString(tempString)); 
		startpos = theString.indexOf("MAXX=",pos);
		startpos += 6;
		endpos = theString.indexOf(dQuote,startpos);
		tempString = theString.substring(startpos,endpos);
		theEnvelope[2] = parseFloat(setDecimalString(tempString)); 
		startpos = theString.indexOf("MAXY=",pos);
		startpos += 6;
		endpos = theString.indexOf(dQuote,startpos);
		tempString = theString.substring(startpos,endpos);
		theEnvelope[3] = parseFloat(setDecimalString(tempString)); 
		xmlEndPos = endpos;
	}
	return theEnvelope;

}

function setDecimalString(numberString) {
	if (numberString.indexOf(",")!=-1) forceCommaInRequest[activeMapServiceIndex] = true;
	if (decimalChar==".") {
		numberString = numberString.replace(/,/g, ".");
	} else {
		numberString = numberString.replace(/./g, ",");
	}
	return numberString;
}

function forceComma(theNumber) {
	var comma = ",";
	var dot = ".";
	var charOut = comma;
	var charIn = dot;
	var numberString = new String(theNumber);
	if (forceCommaInRequest[activeMapServiceIndex]) {
		charOut = dot;
		charIn = comma;
	}
	var pos = numberString.indexOf(charOut);
	if (pos!=-1) {
		var begin = numberString.substring(0,pos);
		var ending = numberString.substring(pos+1, numberString.length);
		numberString = begin + charIn + ending;
	}
	return numberString;
}
function forceOVComma(theNumber) {
	var comma = ",";
	var dot = ".";
	var charOut = comma;
	var charIn = dot;
	var numberString = new String(theNumber);
	if (forceCommaInOV) {
		charOut = dot;
		charIn = comma;
	}
	var pos = numberString.indexOf(charOut);
	if (pos!=-1) {
		var begin = numberString.substring(0,pos);
		var ending = numberString.substring(pos+1, numberString.length);
		numberString = begin + charIn + ending;
	}
	return numberString;
}


function getXMLErrorMessage(theString) {
	var pos1 = 0;
	var pos2 = 0;
	var pos3 = 0;
	var theError = "";
	pos3 = theString.indexOf("<ERROR");
	if (pos3!=-1) {
		pos1 = theString.indexOf(">",pos3);
		pos1 += 1;
		pos2 = theString.indexOf("</ERROR");
		theError = theString.substring(pos1,pos2)
	}
	return theError;

}


function isNotSameHostInURL(theURL, theHost) {
	var startpos = theURL.indexOf("//");
	if (startpos==-1) {
		startpos = 0;
	} else {
		startpos = startpos + 2;
	}
	var endpos = theURL.indexOf("/",startpos);
	if (endpos==-1) endpos = theURL.length;
	var thisHost = theURL.substring(startpos,endpos);
	if (thisHost==theHost) {
		return false;
	} else {
		return true;
	}
}