function get_cookie(str,defval) {
	l = str.length
	i = document.cookie.indexOf(str+'=')
	if ( i < 0 ) return defval;
	j = i + l + 1;
	k = document.cookie.indexOf(';',j);
	val = document.cookie.substring(j,k);
	//To ignore non-numbers uncomment next 2 lines
	//val = parseInt(document.cookie.substring(j,j+5));
	//if ( isNaN(val) ) return defval;
	return val;
}

function show_values() {

	/*
		This function is called as soon as the page has loaded.

		It uses the 'max_frames' and 'extra_days' cookies to 
		update the forms' select fields.
	*/

	var max_frames = get_cookie("max_frames",60);
	var extra_days = get_cookie("extra_days",0);
	var active_subtype = get_cookie("active_subtype","");
	var max_frames_index = 6;
	var extra_days_index = 0;

	show(active_subtype);

	for (var i=0; i<document.max_fr_ex_days.max_frames.length; i++) {
		if (document.max_fr_ex_days.max_frames.options[i].value == max_frames)
			max_frames_index = i;
	}
	for (var i=0; i<document.max_fr_ex_days.extra_days.length; i++) {
		if (document.max_fr_ex_days.extra_days.options[i].value == extra_days)
			extra_days_index = i;
	}
	document.max_fr_ex_days.max_frames.selectedIndex=max_frames_index;
	document.max_fr_ex_days.extra_days.selectedIndex=extra_days_index;

	/*
		Update the month, day, and year values in the
		date form in the choose window.

		Check to see if the choose_date window exists and whether the
		query string contains a 'date=' string.

	*/




	var i = location.search.indexOf('date=');
	var j = location.pathname.lastIndexOf('/');
	var date = i >=0	? location.search.substring(i+5,i+13)
				: location.pathname.substring(j+1,j+9);

	// Only N4 and IE4 recognize the RegExp object.
	// Just verify that date is an integer with parseInt.
	// N3 and IE2 recognize this global function.

	//var date_match = new RegExp("^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$");
	var date_match = (("" + parseInt(date)) == date);



	if (parent.choose_date != null && date_match) {
		//alert("There is a choose window over there.");
		//alert("date="+date);
		var y = date.substring(0,4);
		var m = date.substring(4,6);
		var d = date.substring(6);

		var month_index = 0;
		var day_index = 0;
		var year_index = 0;

		/*
			This command sometimes causes an error.
			It tries to alter a 
			page in thorn.mmm.ucar.edu:30000, but if you have
			thorn:30000 as your url, it thinks this is a 
			different domain and won't execute the JavaScript
			command.
		*/

		with(parent.choose_date.document.date_form) {

			for (var i=0; i<month.length; i++) {
				//alert("month="+month+" option=" + month.options[i].value);
				if (month.options[i].value == m) month_index = i;
			}

			for (var i=0; i<day.length; i++) {
				if (day.options[i].value == d) day_index = i;
			}

			for (var i=0; i<year.length; i++) {
				if (year.options[i].value == y) year_index = i;
			}

			month.selectedIndex = month_index;
			day.selectedIndex   = day_index;
			year.selectedIndex  = year_index;

			var expires = getExpires(90);
			Set_Cookie("month", month_index, expires);
			Set_Cookie(  "day",   day_index, expires);
			Set_Cookie( "year",  year_index, expires);



		}



	} else {
	   //alert(parent.choose_date);
	}


}



function Set_Cookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" +escape(value) +
		( (expires) ? ";expires=" + expires.toGMTString() : "") +
		( (path) ? ";path=" + path : "/") + 
		( (domain) ? ";domain=" + domain : "") +
		( (secure) ? ";secure" : "");
}

function getExpires(days_in_future) {
	var expires = new Date();
	expires.setDate(expires.getDate() + days_in_future);
	return expires;
}

