
// Opens a popupwindow with the specified name and size and loads the given url
var newWindow;
function goPopup(url, name, width, height, options) {
	var top = (screen.height-height) / 2;
	var left = (screen.width-width) / 2;
	if (top < 0) top = 0;
	if (left < 0) left = 0;
	if (options == '') options = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
	newWindow = window.open(url, name, "top="+top+",left="+left+",width="+width+",height="+height+","+options);
	setTimeout("newWindow.focus()", 100);
}

// returns todays date as a string: yyyy-mm-dd
function getToday()
{
	var today = new Date();
	var year = today.getFullYear();
	var month = today.getMonth()+1;
	month = month < 10 ? '0'+month : month;
	var day = today.getDate();
	day = day < 10 ? '0'+day : day;
	return year+'-'+month+'-'+day;
}

// checks if the supplied string is a date: yyyy-mm-dd
function isDate(date)
{
	if (date.search(/^\d{4}\-\d{2}\-\d{2}$/) == -1)
		return false;
	var parts = date.split('-');
	var year = Number(parts[0]);
	var month = Number(parts[1]);
	var day = Number(parts[2]);
	if (month < 1 || day < 1) return false;
	switch (month)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if (day > 31) return false;
			break;

		case 4:
		case 6:
		case 9:
		case 11:
			if (day > 30) return false;
			break;

		case 2:
			if (day > 29)
				return false;
			else if (day == 29 && ((year % 4 != 0) || (year % 400 == 0)))
				return false;
			break;

		default:
			return false;
	}
	return true;

}
