function certain_dates (theForm) {
	/* Input:

	theForm	reference to the form that contains all the 
			information needed to create full URLs for the
			images that will comprise the animation.
  
	Output:
		string array that contains the middle parts of the 
		image URLs.  Only those URL parts that contain a date 
		for the requested time period are output.

	Called by:
			function myGETsubmit in kit.js

	*/

	//alert("certain_dates input = "+theForm);
	var url_middles = new Array();
	url_middles = theForm.all_middles.value.split(" ");
	//alert("all_middles.value = "+theForm.all_middles.value);
	var start_date = theForm.date.value;
	var extra_days = document.max_fr_ex_days.extra_days.options[document.max_fr_ex_days.extra_days.selectedIndex].value

	output_array = new Array();
	var start_year  = start_date.substring(start_date.length-8,start_date.length-4);
	var start_month = start_date.substring(start_date.length-4,start_date.length-2);
	var start_day   = start_date.substring(start_date.length-2,start_date.length  );
	//alert("day="+start_date.substring(start_date.length-2,start_date.length  ));
	start_date = new Date(start_year, start_month-1, start_day);
	var end_date = new Date();
	end_date.setTime(start_date.getTime() + extra_days*24*3600*1000)
	var loop_date = start_date; 
	while (loop_date.getTime() <= end_date.getTime()) {

		var loop_year  = loop_date.getUTCFullYear();
		loop_year  = pad(loop_year,2);
                //alert("loop_year="+loop_year);
		var loop_month = loop_date.getUTCMonth()+1;
		loop_month = pad(loop_month,2);
		var loop_day   = loop_date.getUTCDate();
		loop_day  = pad(loop_day,2);
		var search_string = loop_year + loop_month + loop_day;
		//On 20040411, Dave Ahijevych started searching for the entire 8-digit date, not just the 6-digit date. If you want to revert to searching for the 6-digit date, uncomment the next line.
		//search_string = search_string.substring(search_string.length-6,search_string.length);
		//alert("input array length = "+url_middles.length+"\nsearch string="+search_string);	

		for (var i=0; i < url_middles.length; i++) {


			// Replace dollar sign with theForm.longstring.value before searching for the date.
			// David Ahijevych modified this on 20040123.

			var url_middle = url_middles[i];
			var s = url_middle.indexOf('$');

			if (s && (s != -1)) {
				if (theForm.longstring == null)
					alert("Found dollar sign, but no replacement string");
				// Replace dollar signs with longstring
				url_middle = url_middle.substring(0,s) + theForm.longstring.value + url_middle.substr(s+1);
			}

			var full_url = new String(theForm.prefix.value+
							  url_middle+
							  theForm.suffix.value );
			//alert("looking for "+search_string+ " in " + full_url);
			var found_string = full_url.indexOf(search_string);
			if ( found_string >= 0 )
				output_array[output_array.length] = url_middles[i];
		}
		loop_date.setTime(loop_date.getTime() + 24*3600*1000); 

	}
	//if (output_array.length == 0) alert("No images for requested dates");
	//alert("output array length = "+output_array.length);	


	return output_array;



}



function pad(number,len) {
	/* 
		1. convert number to a string
		2. If the number has fewer digits than len,
			prepend zeroes until it is len characters long.
		3. Return the zero-padded string number.
	*/

	var str = '' + number;
	while (str.length < len)
		str = '0' + str;
	return str;
}




function slim (input_array,max_frames) {
	/*

	Called by:	function myGETsubmit in kit.js

	Purpose:

		1.	If the number of elements in input_array is 
		greater than max_frames, slim the input array
		down to max_frames elements.

		2.	If the total number of characters in input_array
		is greater than max_query_length, slim the input array
		until the total number of characters is 
		less than max_query_length.

		
	Method:
		Take evenly distributed cross sections of the 
		array and eliminate those elements.

	
	Returns:
		Slimmed-down array of strings

	*/


	var max_query_length = 2010;
	/*	In Microsoft Explorer the animation window URL is 
		truncated at 2083 characters. */


	if (max_frames == null) {
		max_frames = document.max_fr_ex_days.max_frames.options[document.max_fr_ex_days.max_frames.selectedIndex].value;
	}


	var output_array = input_array;
	if (input_array.length > max_frames) {
		//alert(" max_frames="+max_frames+" input_array.length="+input_array.length);
		var index_increment = input_array.length/max_frames;
		//alert("index_increment="+index_increment);
		var slim_array = new Array(max_frames);
		var slim_index = 0;
		var real_index = 0.0;
		for (i=0; i < max_frames; i++) {
			var real_index = index_increment * i;
			var int_index = Math.round(real_index);
			int_index = Math.min(int_index,input_array.length-1);
			//alert("int_index="+int_index);
			//if (i == max_frames -1) alert("last frame="+input_array[int_index]);
			slim_array[i] = new String(input_array[int_index]); 
		}



				
		output_array = slim_array;
	}


	/* Make sure the query length will not be too long. */

	var query_length = output_array.join(' ').length ;

	if (query_length > max_query_length) {

		max_frames = Math.floor(max_frames*max_query_length/query_length);
		//Set_Cookie("max_frames", max_frames, getExpires(90)); 
		alert("Sorry, can only animate  " + max_frames +
			 " frames in this case.\nTry fewer frames."); 
		output_array = slim(output_array,max_frames);
	}

//	alert("output_array="+output_array);
//	alert("output array length = "+output_array.length);	



	status="";
	return output_array;

}
