function rewrite2() {
	tbl.local_date.value = datestring(observer);
}		// end rewrite2()


function reset1() {
	// initialize date from system clock
	setNow();	
	rewrite2();		
}		// end reset1()


function setDateTime(rel) {
	// handles changes to the time and date fields in table1. Also handles time step buttons.
	// 'rel' is relative adjustment in minutes. If rel = 0 evaluate date and time fields.
	var vald = tbl.local_date.value;
	// date field
	var col1 = vald.indexOf("/");
	var col2 = vald.lastIndexOf("/");
	var col3 = vald.length;
	var day = 1;
	var month = 1;
	if (col1>0) day = parseInt(vald.substring(0,col1),10);
	if (col2>0) month = parseInt(vald.substring(col1+1,col2),10);
	var year = parseInt(vald.substring(col2+1,col3),10);
	month_length[1] = leapyear(year)?29:28;
	if ((month>12) || (month<0)) month = 1;

	if ((day > month_length[month-1]) || (day<0)) {
		day = 1;
		month = 1;
	}
	
	observer.day = day;
	observer.month = month;
	observer.year = year;
	// time field
	observer.hours = 0;
	observer.minutes = 0;
	observer.seconds = 0;
	rewrite2();
}	// setDateTime()


function setNow() {
	// Handles 'Now' button
	var now = new Date();
	observer.year = now.getFullYear();
	month_length[1]=leapyear(observer.year)?29:28;
	observer.month = now.getMonth()+1;
	observer.day = now.getDate();
	observer.hours = 0;
	observer.minutes = 0;
	observer.seconds = 0;
	rewrite2();
}		// setNow()


function setAll(checked) {
	tbl.season.checked = tbl.perihelion.checked = checked;
	tbl.phase.checked = tbl.perigee.checked = checked;
	tbl.solconj.checked = tbl.moonconj.checked = tbl.planconj.checked = checked;
	tbl.elong.checked = tbl.quadrature.checked = checked;
}

function switchboard(funct) {
	// find out what has been requested and call corresponding page maker
	var starttime = new Date();	// if timer_on: Measure execution time
	var sel = {
		season: (tbl.season.checked),
		sol_peri: (tbl.perihelion.checked),
		phase: (tbl.phase.checked),
		moon_peri: (tbl.perigee.checked),
		conj_sol: (tbl.solconj.checked),
		conj_moon: (tbl.moonconj.checked),
		conj_planet: (tbl.planconj.checked),
		maxelong: (tbl.elong.checked),
		quadrature: (tbl.quadrature.checked),
		pl_peri: false
		}
	var dspan = datecount[tbl.Times.selectedIndex];
	doPlanetEvents(observer, dspan, sel);
	var endtime = new Date();
	if (timer_on) alert("Function executed in " + ((endtime.getTime() - starttime.getTime())/1000) + "seconds");
}

