function valiDate(formname, fieldname) {
/* Javascript date check by Justin Klein Keane  Copyright (C) 2004 

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
	   
*/
var myRegex = new RegExp("^[0-9]{4}\-([0][0-9]|[1][0-2])\-([0-2][0-9]|[3][0-1])$");

var thisfield = eval('document.'+formname+'.'+fieldname+'.value');

if ((thisfield.length>0)) {
	
	if (thisfield.match(myRegex))
		{//valid date format, check for valid date
		var theDay = Math.round(document.theForm.date.value.substr(8,2));
		var theMonth = Math.round(document.theForm.date.value.substr(5,2));
		var theYear = Math.round(document.theForm.date.value.substr(0,4));
		
		if ((theYear%4 == 0) && (theDay > 29) && (theMonth == 2)) {
			alert ("Not a valid date.");
			return false;
			}
		else if ((theYear%4 != 0) && (theDay > 28) && (theMonth == 2)) {
			alert ("Not a valid date.");
			return false;
			}
		else if ((theDay > 30) && (theMonth == 4 || theMonth == 6 || theMonth == 0 || theMonth == 11)) {
			alert ("Not a valid date.");
			return false;
			}
		else {
			return true;
			}
		}
	else
		{
		alert ("Date not in correct format (YYYY-MM-DD)\nExample - (2006-05-01) would be 1st May 2006");
		return false;
		}
	}
	
}
