/* Copyright 2007 ChrisPhillipsLLC.com */
function fmtDate(elem)
{
	var re = /^\s*(\d+)\D+(\d+)(\D+(\d+))?\s*$/;
	var arr = re.exec(elem.value);

	if (arr) {
		var s = "";
		var month = parseInt(arr[1], 10);
		var day = parseInt(arr[2], 10);
		var year = 0;
		
		if (arr.length == 5 && arr[4] != "")
			year = parseInt(arr[4], 10);
		if (year < 100) {
			var now = new Date();
			var nowyear = parseInt(now.getFullYear(), 10);
			if (year == 0) {
				year = nowyear;
				if (month < now.getMonth() + 1)
					year++;
			} else
				year += parseInt(nowyear / 100, 10) * 100;
		}

		if (month < 10)
			s += "0";
		s += month + "-";
		if (day < 10)
			s += "0";
		s += day + "-" + year;
		elem.value = s;
	}
}

function checkinput(form)
{
	var re = /^\s*(\d{1,4})\D+(\d{1,2})\D+(\d{1,2})\s*$/;
	var arr = re.exec(form.date.value);

	if (!arr || arr.length != 4) {
		form.date.select();
		form.date.focus();
		alert("Start Date is invalid.");
		return false;
	}
	var t1 = new Date(arr[1] + "/" + arr[2] + "/" + arr[3]);
	var now = new Date();
	var t2 = new Date(now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate());
	if (t1.valueOf() < t2.valueOf()) {
		form.date.select();
		form.date.focus();
		alert("Past dates are unavailable.");
		return false;
	}
	form.year.value = arr[1];
	form.month.value = arr[2];
	form.day.value = arr[3];
	return true;
}

function sort(order, m, d, y)
{
	var f = document.getElementById("form1");
	f.order.value = order;
	f.month.value = m;
	f.day.value = d;
	f.year.value = y;
	f.random.value = 0;
	f.submit();
}

function initfocus()
{
//	var elem = document.getElementById("date");
//	if (elem)
//		elem.focus();
//	document.body.scrollTop = 0;
}

