    var createDrillPage = false;
	var replyArray = new Array();
	var theMin = 0;
	var theMax = 0;
	var theString;
//	var	clipBox = false;   //declared in aimsClick.js
	
	var fID = 1;
	var reverseFieldList = selFieldList.reverse()

	var tempWest = 0;
	var tempNorth = 0;
	var tempEast = 0;
	var tempSouth = 0;
	

// This function is called as soon as the user clicks on the map after selecting the "download image" tool from the toolbar.
// This establishes the upper, left-hand corner of the clip-box.
// It is called again when the user clicks on the map to position the lower, right-hand corner of the clip-box.
function getParametersForDownload(e) {
//alert("entering getParametersForDownload");
	startClipBox(e);

	// Write the XML to retrieve the image for the selected area.
	if (clipBox==true) {
		getMouse();
		dlX = mouseX;
		dlY = mouseY;
		getMapXY(mouseX,mouseY);		// we just clicked here...the UL corner of clip-box.
		tempWest = mapX;
		tempNorth = mapY;
		drawClipBoundary=true;
	} else {
		getMouse();
		getMapXY(mouseX,mouseY);
		tempEast = mapX;
		tempSouth = mapY;
		//these will be used in writeImageClipXML();
		dlSouth = tempSouth;
		dlWest = tempWest;
		dlNorth = tempNorth;
		dlEast = tempEast;
//		Now, give the users a list of all of the features and images so they can choose what the wish to download.
		openSelectDownloadPopup();
		writeSelectDownloadPopup();
	}
}

// Called from writeSelectDownloadPopup...it uses the list of features/images supplied by the user to create a list of 
// files to extract and a list of images to extract.  Then it sends the feature-extract request (if one exists)
// to the map-server.  The map server only handles one request at a time, so if more than one request is to be made, it
// will be made in doDownLoadImage().
function prepareDownload(dlWest,dlSouth,dlEast,dlNorth) {
// Step 1: '<GET_IMAGE>' requests to the map server for each image-layer chosen.
// Step 2: Call the extract server to get the features.
//alert('theClipList='+theClipList);

	// Find all of the image-layers in the list...if any are to be downloaded, add their index to dlImageList.
	dlImageList = '^';
	dlImageCount = 0;
	dlFeatureCount = 0;
	for (var i=0;i<layerCount;i++) {
		if (LayerType[i] == "image" ) {
			theString = LayerName[i];
			if (inClipList(theString) == true) {
				if (dlImageCount==0) {
					var thisImageIndex = i;
				}
				dlImageList = dlImageList + i + '^';

				dlImageCount ++;
			}
		}
		else {
			theString = LayerName[i];
			if (inClipList(theString) == true) {
				dlFeatureCount ++;
			}
		}
	}
	dlLastNbrProc=-1;	// No requests for image-layers have been sent to the map server.
	// Package up the 'feature' layers and make a call to the extract server.
	showRetrieveData();		// Put the animated icon on the screen.
	if (dlFeatureCount > 0) {
		var theString = writeFeatureExtractXML(dlWest,dlSouth,dlEast,dlNorth);
	    sendToServer(imsExtractURL,theString,1004);
	}
	else {
		// process the first image-clip, then end up in processDownloadRequests() to process any additional image-layers.
		dlLastNbrProc=0;
		sendDLRequest(dlWest,dlSouth,dlEast,dlNorth,thisImageIndex);
	}
// We should never get to this routine if no request was made to download features or images.
}

// This is called by useCustomFunction(), immediately after receiving reply from map server.  It calls preparePackageItem.asp
// which waits for the file created by the last map request to be fulfilled.  It handles only images...the features will be extracted before this.
function processDownloadRequests(theReply) {
	var nextID = -1;
	var nextImageNbr = dlLastNbrProc + 1;
	// Get the URL of the most recently created item and add it to the zip list...it won't contain the world-files.
	theURL = getURL(theReply);
	// If the image size exceeds the size set in the map service properties a message like "Requested image is too big..." 
	// is in theReply...in that case theURL would be empty, signalling we got nothing.  Show the user the way to the ftp-site.
	// Create a dynamic window with the link to the proper layer.  writeErrorPopup will process any requested
	// features if the client chooses to do so.
	if (theURL == "") {
		openErrorPopup();
		if (dlPrevURL == "") {
			var featreq = false;
		} else {
			var featreq = true;
		}
		writeErrorPopup(featreq, theReply);
	} else {
		dlPrevURL = theURL;
		dlZipList = dlZipList + theURL;


	// If we are looking at a zip file, don't try to add an image name.
	if (theURL.indexOf(".zip") == -1) {

		// Determine which image is being downloaded...dlCurrentImage is actually the layer number.
		theString = LayerName[dlCurrentImage];
		for (var j=0;j<dlImageName.length;j++) {
			if (dlImageName[j] == theString) {
				var dlPixSize = dlImageRes[j];
				// Add the image-layer name (after the URL) so the files can be renamed.
				dlZipList = dlZipList + "<{" + theString + "}>";
			}
		}
	}
		dlZipList = dlZipList + "^";

		// In order to avoid the "Response from previous request(s) not received." message we call an ASP that will wait for the file
		// to be created on the server before proceeding...then enter this routine again to see if there are more images to download.
		if (dlImageCount>nextImageNbr) {
			nextID = getImageID(nextImageNbr+1);
			// This ASP will wait while the image is created...this avoids the "Response from previous request(s) not received." message.
			//Create the worldfile from the reply and offer it to the client.
  			parent.BottomFrame.document.location = '/_common_UI/asp/preparePackageItem.asp?URL=' + theURL + '&dlWest=' + dlWest + '&dlSouth=' + dlSouth + '&dlEast=' + dlEast + '&dlNorth=' + dlNorth + '&LayerIndex=' + nextID + '&pixsize=' + dlPixSize + '&ziplist=' + dlZipList + '&outputFilePath="c:\ArcIMS\output\"';
			dlLastNbrProc = dlLastNbrProc + 1;
		} else {
		    // All of the requests have been sent...wait for the last image to be created and then zip and send the entire package to the user.
			//There are implied world-files with every image in the ziplist.
			// sendPackage.asp will be called if nextID=-1, else the next <GET_IMAGE> request will be sent via sendDLRequest.
  			parent.BottomFrame.document.location = '/_common_UI/asp/preparePackageItem.asp?URL=' + theURL + '&dlWest=' + dlWest + '&dlSouth=' + dlSouth + '&dlEast=' + dlEast + '&dlNorth=' + dlNorth + '&LayerIndex=9999&pixsize=' + dlPixSize + '&ziplist=' + dlZipList + '&outputFilePath="c:\ArcIMS\output\"';
			dlLastNbrProc=-1;	//reset for the next time a download is requested.
			dlImageList = "";
			dlImageCount = 0;
			dlZipList = "^";
			dlPrevURL = "";
		}
	}
}

// This is called, the first time (if there were feature-extract requests) by prepareDownload(), and afterwards by preparePackageItem.asp
function sendDLRequest(dlWest,dlSouth,dlEast,dlNorth,LayerIndex) {
	dlCurrentImage = LayerIndex;
	var theString = writeImageClipXML(dlWest,dlSouth,dlEast,dlNorth,LayerIndex);
	sendToServer(imsURL,theString,1004);
}

// Give the file to the client.
function shipIt(theZipURL) {
	hideRetrieveData();		// Turn off the animated gif
	parent.BottomFrame.document.location=theZipURL;	// Redirect the file to the user.
}

function inClipList(theString) {
	var tmpString = '^' + theString + '^';
	var retVal = theClipList.indexOf(tmpString);
	if (retVal == -1) {
		return false;
	} else {
		return true;
	}
}

function getImageID(theString) {
// x.substring is 0-relative
	var tmpList = dlImageList;
	for (var i=1;i<=theString;i++) {
		var retVal = tmpList.indexOf('^');
		if (retVal==-1) {
			alert ('An error has occured -- download will not be performed!');
			break;
		} else {
			var tmpList = tmpList.substring(retVal+1);
		}
	}
	// Now, we have the list, starting with the present index...
	retVal = tmpList.indexOf('^');
	tmpList = tmpList.substring(0,retVal);

	return tmpList;
}

// write XML to identify the image(s) to be downloaded.
function writeImageClipXML(west1,south1,east1,north1,thisImageIndex) {

	// There is no way to make an image the active layer, so unless there is only one image in the 
	// map-service, we have to make a list of the available images and ask the user what they want.

	var tempXDistance = Math.abs(west1-east1);
	var tempYDistance = Math.abs(north1-south1);

	theString = LayerName[thisImageIndex];
	for (var j=0;j<dlImageName.length;j++) {
		if (dlImageName[j] == theString) {
			var downloadImageRes = dlImageRes[j];
		}
	}
	var outWidth = tempXDistance/downloadImageRes;
	var outHeight = tempYDistance/downloadImageRes;

	// Write image to create the image.
	// Write the wordFile...could use OnePlan worldFile.asp
	
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n<ENVELOPE minx="' + forceComma(west1) + '" miny="' + forceComma(south1) + '" maxx="' + forceComma(east1) + '" maxy="' + forceComma(north1) + '" />\n';
	//must provide the imagesize parameter.
	theString += '<IMAGESIZE height="' +parseInt(outHeight) + '" width="' + parseInt(outWidth) + '" />\n';

	// tell the server which layers are to be visible
	//add the 'nodefault' so that only the listed image-layer is displayed.
	theString += '<LAYERLIST nodefault="true">\n';
	theString += '<LAYERDEF id="' + LayerID[thisImageIndex] + '" visible="true" ';
	theString += '/>\n';
	theString += '</LAYERLIST>\n';
	
	// map background color
	if (mapTransparent) {
		theString += '<BACKGROUND color="255,255,255" transcolor="255,255,255" />\n';
	} else {
		if (mapBackColor!="") {
			theString += '<BACKGROUND color="' + mapBackColor + '" />\n\n';
		}
	}
	theString += '</PROPERTIES>\n';
	theString += '</GET_IMAGE>\n</REQUEST>\n</ARCXML>';

	return theString;
}

function writeFeatureExtractXML(west1,south1,east1,north1) {
	var tempXDistance = Math.abs(west1-east1);
	var tempYDistance = Math.abs(north1-south1);

//	arbitrary, but necessary...
	var outWidth = 500;
	var outHeight = 500;

	var eString = '<ARCXML version="1.1">\n';
	eString += '<REQUEST>\n<GET_EXTRACT>\n<PROPERTIES>\n';
	eString += '<ENVELOPE minx="' + forceComma(west1) + '" miny="' + forceComma(south1) +'" maxx="' + forceComma(east1) + '" maxy="' + forceComma(north1) + '" />\n';
//	eString += '<IMAGESIZE height="' + outHeight + '" width="' + outWidth + '" />\n';
	eString += '<LAYERLIST>\n';
	for (var i=0;i<LayerID.length;i++) {
		if (LayerType[i] != "image" ) {
			theString = LayerName[i];
			eString += '<LAYERDEF id="' + LayerID[i] + '" ';
			if (inClipList(theString) == true) {
				eString += 'visible="true"/>\n';
			} else {
				eString += 'visible="false"/>\n';
			}
		}
	}
	eString += '</LAYERLIST>\n';
	eString += '</PROPERTIES>\n</GET_EXTRACT>\n</REQUEST>\n';
	eString += '</ARCXML>\n';
	return eString;
}

// start clip-box display
function startClipBox(e) {
//	if (checkIfActiveLayerAvailable()) {
		moveLayer("theMap",hspc,vspc);
		getImageXY(e);
		// keep it within the MapImage
		if ((mouseX<iWidth) && (mouseY<iHeight)) {
			if (clipBox) {
				stopClipBox(e);
			} else {
				x1=mouseX;
				y1=mouseY
				x2=x1+1;
				y2=y1+1;
				zleft=x1;
				ztop=y1;
				zbottom=y1;
				zright=x1;
				boxIt(x1,y1,x2,y2);
				clipBox=true;
				
				//if (isNav4) {
					showLayer("zoomBoxTop");
					showLayer("zoomBoxLeft");
					showLayer("zoomBoxRight");
					showLayer("zoomBoxBottom");
				//} else {
				//	showLayer("zoomBox");
				//}
			}
			highlightedOne="";
		} else {
			if (clipBox) {
				stopClipBox(e);
			}
		}
		return false;
//	}

}

// stop clip-box display.....
function stopClipBox(e) {
	clipBox=false;
	//if (isNav4) {
		hideLayer("zoomBoxTop");
		hideLayer("zoomBoxLeft");
		hideLayer("zoomBoxRight");
		hideLayer("zoomBoxBottom");
	//} else {
	//	showLayer("zoomBox");
	//}
	 /*
	if ((zright <zleft+2) && (zbottom < ztop+2)) {
		
		//getMapXY(mouseX-pixelTolerance,mouseY-pixelTolerance);
		getMapXY(mouseX,mouseY);
		searchTolerance = (xDistance/iWidth) * pixelTolerance;
		tempLeft = mapX-searchTolerance;
		tempTop = mapY-searchTolerance;
		tempRight = mapX+searchTolerance;
		tempBottom = mapY+searchTolerance;
		
		//select(e);
	} else { 
	*/	
		pixelX = xDistance / iWidth;
		var theY = iHeight - ztop;
		pixelY = yDistance / iHeight;
		tempTop = pixelY * theY + eBottom;
		tempRight = pixelX * zright + eLeft;
		tempLeft = pixelX * zleft + eLeft;
		theY = iHeight - zbottom;
		pixelY = yDistance / iHeight;
		tempBottom = pixelY * theY + eBottom;
//	}
		window.scrollTo(0,0);
	
	queryStartRecord=1;
	var theString = writeGetFeatures2(tempLeft,tempBottom,tempRight,tempTop);
	selectEnvelope='maxy="' + forceComma(tempTop) + '" maxx="' + forceComma(tempRight) + '" miny="' + forceComma(tempBottom) + '" minx="' + forceComma(tempLeft) + '"';
	drawClipBoundary=true;
	showBuffer=false;
	selectionMode=2;
	//if (useTextFrame) parent.TextFrame.document.location = "text.htm";
//	sendToServer(imsQueryURL,theString,selectXMLMode);
	return true;

}

function deliverFeatures() {
	// Set the URL to that returned from the previous request (the extract).  Since the image (which was too big
	// to big to be delivered by the server) has not been added to dlZipList...pass dlZipList to deliver features to client.
//    Response.Write "  parent.BottomFrame.document.location = '/_common_UI/asp/sendPackage.asp?URL=" + dlPrevURL + "&ziplist=" + dlZipList + "';" + vbCrLf
    parent.BottomFrame.document.location = '/_common_UI/asp/sendPackage.asp?URL=' + dlPrevURL + '&ziplist=' + dlZipList;
}

//Reference: "http://www.coolnerds.com/jscript/winopen.htm"
//-- This function opens the new, empty window named floater.
function openErrorPopup() {
//function openWindow() {
   winStats='toolbar=no,location=no,directories=no,menubar=no,';
//   winStats+='scrollbars=no,width=325,height=175';
   winStats+='scrollbars=no,width=325,height=325';
   if (navigator.appName.indexOf("Microsoft")>=0) {
      winStats+=',left=100,top=250';
    }else{
      winStats+=',screenX=10,screenY=25';
    }
   floater=window.open("","",winStats);
}
//-- This function writes a little HTML to the new floater window, 
//-- then closes the text stream and gives the window the focus.
function writeErrorPopup(featreq, theReply) {
	parent.MapFrame.hideRetrieveData();
	floater.document.open();
	var s = '<body background="/images/tile10.gif">';
	floater.document.writeln (s);

	var sError;
	sError = "";
	sError = getError(theReply);
	
	if (sError.length != 0) {
		//[ERR0134] Requested Service is not available. 
		s = '<div style="font: 13px Arial, Helvetica, Verdana, sans-serif; color: #000000; font-weight: bold;text-align: center;">Data Was Not Extracted</div>';
		floater.document.writeln (s);

		var sHelpDesk;
		var idx;
		idx = imsURL.indexOf("ServiceName");
		if (idx != -1) {
			sHelpDesk = imsURL.substring(idx+12);
			sHelpDesk = "<a href=\"mailto:HelpDesk@idwr.idaho.gov?subject=" + sHelpDesk + " returned error code " + sError + "\">click here</a>";
		}
		else
		{
			sHelpDesk = "<a href=\"mailto:HelpDesk@idwr.idaho.gov?subject=" + "Unknown ArcIMS application returned error code " + sError + "\">click here</a>";
		}

		switch (sError) {
			case "ERR0134":
				s = "The map service is not running.  If you encounter this more than once please " + sHelpDesk + " to contact our help desk.";
				break;
			default:
				s = "If you encounter this more than once please " + sHelpDesk + " to contact our help desk.";
				break;
		}
		floater.document.writeln (s);
	}
	else
	{
		s = '<center>Images created by the map-server are currently limited to approximately 1-million pixels (ie 1024x1024). ';
		floater.document.writeln (s);
		s = '<center>The portion of the image you have chosen to clip and download is too large to be delivered by the map-server. ';
		floater.document.writeln (s);
		s = 'Please select a smaller portion of the image or go to our web-site and download the entire layer.<br><br>';
		floater.document.writeln (s);
	}

// The client can choose to have the features delivered even though the image is too big.
	if (featreq == true) {
		s = '<a href="javascript:opener.parent.MapFrame.deliverFeatures();this.close();">Get the features you requested (the image will not be sent).</a><br>';
		floater.document.writeln (s);
    }
	//s = '<a href="http://www.idwr.idaho.gov/gisdata/gis_data.htm" target="_new">IDWR GIS Data</a></center>';
	//floater.document.writeln (s);
	floater.document.writeln ("</body>");
	floater.document.close();
	floater.focus();
}
//-- This function writes a little HTML to the new floater window, 
//-- then closes the text stream and gives the window the focus.
function getError(theReply) {
	var sError;
	sError = "";
	var idx;
	var idx2;
	idx = theReply.indexOf("[");
	if (idx != -1) {
		idx2 = theReply.indexOf("]");
		if (idx2 != -1) {
			sError = theReply.substring(idx+1,idx2);
		}
		else
		{
			sError = "";
		}
	}
	else
	{
		sError = "";
	}

	return sError;
}



// These are for debugging...
function openDebugPopup() {
   winStats='width=325,height=375';
   if (navigator.appName.indexOf("Microsoft")>=0) {
      winStats+=',left=10,top=25';
    }else{
      winStats+=',screenX=10,screenY=25';
    }
   floater=window.open("","",winStats);
}
function writeDebugPopup() {
	floater.document.open();
	s = '<br>document.body.scrollLeft=' + document.body.scrollLeft + ', document.body.scrollTop=' + document.body.scrollTop;
	floater.document.writeln (s);
	s = '<br>mouseX=' + mouseX + '; mouseY=' + mouseY;
	floater.document.writeln (s);
	s = '<br>xDistance=' + xDistance + ', yDistance=' + yDistance;
	floater.document.writeln (s);
	s = '<br>mapX=' + mapX + ', mapY=' + mapY;
	floater.document.writeln (s);
	s = '<br>iWidth=' + iWidth + ', iHeight=' + iHeight;
	floater.document.writeln (s);
	s = '<br>scrollLeft=' + document.body.scrollLeft + ', scrollTop=' + document.body.scrollTop;
	floater.document.writeln (s);
	s = '<br>eLeft=' + eLeft + ', eTop=' + eTop + ', eRight=' + eRight + ', eBottom=' + eBottom;
	floater.document.writeln (s);
	floater.document.writeln ("</body>");
	floater.document.close();
	floater.focus();
}

function openSelectDownloadPopup() {
   var winStats='scrollbars=yes,width=400,height=650';
   floater=window.open("","",winStats);
}

//function writeSelectDownloadPopup(theReply) {
function writeSelectDownloadPopup() {
	floater.document.open();
	var i;
	var s = '<html><head><script language="JavaScript">';
	floater.document.writeln (s);
//Pass variables from this routine to the dynamically-created one.
//dlWest,dlSouth,dlEast,dlNorth
	var s = "var dlWest='" + dlWest +"';";
	floater.document.writeln (s);
	var s = "var dlNorth='" + dlNorth +"';";
	floater.document.writeln (s);
	var s = "var dlEast='" + dlEast +"';";
	floater.document.writeln (s);
	var s = "var dlSouth='" + dlSouth +"';";
	floater.document.writeln (s);
	var s = "var layerCount='" + layerCount +"';";
	floater.document.writeln (s);
	var s = "var theClipList='^';";
	floater.document.writeln (s);

	var s = "function inClipList(theString) {";
	floater.document.writeln (s);
	var s = "  var tmpString = '^' + theString + '^';";
	floater.document.writeln (s);
	var s = "  var retVal = theClipList.indexOf(tmpString);";
	floater.document.writeln (s);
	var s = "  if (retVal == -1) {";
	floater.document.writeln (s);
	var s = "    return false;";
	floater.document.writeln (s);
	var s = "  } else {";
	floater.document.writeln (s);
	var s = "    return true;";
	floater.document.writeln (s);
	var s = "  }";
	floater.document.writeln (s);
	var s = "}";
	floater.document.writeln (s);

// If the user has already selected layers, pull those from theClipList.
	var s = "function initForm (form) {";
	floater.document.writeln (s);
	var s = "  if (opener.parent.MapFrame.theClipList != '') {";
	floater.document.writeln (s);
	var s = "    theClipList=opener.parent.MapFrame.theClipList;";
	floater.document.writeln (s);
	var s = "  } else {";
	floater.document.writeln (s);
	var s = "  theClipList='^';";
	floater.document.writeln (s);
	var s = "  }";
	floater.document.writeln (s);
	var s = "  for (var i=0;i<layerCount;i++) {";
	floater.document.writeln (s);
	var s = "    if (inClipList(opener.parent.MapFrame.LayerName[i]) == true) {";
	floater.document.writeln (s);
	var s = "    z = 'form.C'+i+'.checked = true';";
	floater.document.writeln (s);
	var s = "    eval(z);";
	floater.document.writeln (s);
	var s = "    }";
	floater.document.writeln (s);
	var s = "  }";
	floater.document.writeln (s);
	var s = "}";
	floater.document.writeln (s);

	var s = "function testResults (form) {";
	floater.document.writeln (s);
	// If "all layers" was checked, put all of the layers in the extract list.
	var s = "  theClipList='^';";
	floater.document.writeln (s);
	var s = "  var z='form.allLayers.checked';";
	floater.document.writeln (s);
	var s = "  var TestVar = eval(z);";
	floater.document.writeln (s);
	var s = "  if (TestVar == true) {";
	floater.document.writeln (s);
	var s = "    for (var i=0;i<layerCount;i++) {";
	floater.document.writeln (s);
	var s = "      var z='form.C'+i+'.value';";
	floater.document.writeln (s);
	var s = "      if (theClipList != '^') {";
	floater.document.writeln (s);
	var s = "        theClipList=theClipList + '^';";
	floater.document.writeln (s);
	var s = "      }";
	floater.document.writeln (s);
	var s = "      theClipList=theClipList + eval(z);";
	floater.document.writeln (s);
	var s = "    }";
	floater.document.writeln (s);
	var s = "  } else {";
	// Else -- "all layers" was not chosen -- find out what our contestant chose.
	floater.document.writeln (s);
	var s = "    for (var i=0;i<layerCount;i++) {";
	floater.document.writeln (s);
	var s = "      var z='form.C'+i+'.checked';";
	floater.document.writeln (s);
	var s = "      var TestVar = eval(z);";
	floater.document.writeln (s);
	var s = "      if (TestVar == true) {";
	floater.document.writeln (s);
	var s = "        var z='form.C'+i+'.value';";
	floater.document.writeln (s);
	var s = "        if (theClipList != '^') {";
	floater.document.writeln (s);
	var s = "          theClipList=theClipList + '^';";
	floater.document.writeln (s);
	var s = "        }";
	floater.document.writeln (s);
	var s = "        theClipList=theClipList + eval(z);";
	floater.document.writeln (s);
	var s = "      }";
	floater.document.writeln (s);
	var s = "    }";
	floater.document.writeln (s);
	var s = "  }";
	floater.document.writeln (s);
	var s = "  if (theClipList == '^') {";
	floater.document.writeln (s);
	var s = "    alert('You must select something or press Cancel');";
	floater.document.writeln (s);
	var s = "  } else {";
	floater.document.writeln (s);
	var s = "    theClipList=theClipList + '^';";
	floater.document.writeln (s);
	var s = "    opener.parent.MapFrame.theClipList=theClipList";
	floater.document.writeln (s);
//	var s = "    var theString = opener.parent.MapFrame.writeImageClipXML(dlWest,dlSouth,dlEast,dlNorth);";
//	floater.document.writeln (s);
//	var s = "    opener.parent.MapFrame.sendToServer(imsURL,theString,1004);";
//	floater.document.writeln (s);
	var s = "    opener.parent.MapFrame.prepareDownload(dlWest,dlSouth,dlEast,dlNorth);";
	floater.document.writeln (s);
	var s = "    this.close();";
	floater.document.writeln (s);
	var s = "  }";  
	floater.document.writeln (s); 
	var s = "}";
	floater.document.writeln (s);
	var s = "function cancelDownload () {";
	floater.document.writeln (s);
	var s = "  this.close();";
	floater.document.writeln (s);
	var s = "}";
	floater.document.writeln (s);

	//Now write the html-body of the selection-window.
	var s = '</script></head><body onLoad="initForm(frmLayersForDownload)" background="/images/tile10.gif">';
	floater.document.writeln (s);
	var s = '<h3>Choose the layers you wish to download</h3>';
	floater.document.writeln (s);
	var s = '<form name="frmLayersForDownload">';
	floater.document.writeln (s);
	var s = '<table>';
	floater.document.writeln (s);
	for (var i=0;i<layerCount;i++) {
		s = '<tr><td><input type="checkbox" name="C' + i + '" value="' + LayerName[i] + '">' + LayerName[i] + '</td></tr>';
		floater.document.writeln (s);
	}
	s = '<tr><td><hr></td></tr>';
	floater.document.writeln (s);
	s = '<tr><td><input type="checkbox" name="allLayers" value="allLayers">All layers</td></tr>';
	floater.document.writeln (s);
	var s = '</table>';
	floater.document.writeln (s);
	floater.document.writeln ('<p><input type="button" value="Download" onClick="testResults(this.form)" name="B1">');
	floater.document.writeln ('<input type="button" value="Cancel" onClick="cancelDownload()" name="B2"></p></form></body></html>');
	floater.document.close();
	floater.focus();
}
