function is_valid_date(day, month, year)
{

	if (!(day.match(/^\d$/) || day.match(/^\d\d$/)))
		return false;

	if (day <= 0)
		return false;
	if (month == 'please select')
		return false;
	if (year < 1901 || year > 2038)
		return false;
		
	switch (month)
	{
		case '9':  // september
		case '4':  // april
		case '6':  // june
		case '11': // november
			if (day > 30)
				return false;
				break;
		case '1':  // january
		case '3':  // march
		case '5':  // may
		case '7':  // july
		case '8':  // august
		case '10': // october
		case '12': // december
			if (day > 31)
				return false;
				break;
		
		case '2':  // february
			if ((year % 4) != 0 && day > 28)
				return false;
				break;
			if ((year % 4) == 0 && day > 29)
				return false;
				break;
	}

	return true;
}

function checkform()
{

	errors = 0;
	first_name_error = false;
	last_name_error = false;
	bday_error = false;
	ann_error = false;
	phone_error = false;
	email_error = false;
	postal_code_error = false;
	
	
	/*** Postal Code ***/
	
	document.forms['signup'].postal_code.value = document.forms['signup'].postal_code.value.toUpperCase();
	if (!document.forms['signup'].postal_code.value.match(/^[A-Z]\d[a-zA-Z]\ \d[A-Z]\d$/))
	{
		errors += 1;
		postal_code_error = true;
	}
	
	/*** Birthday ***/
	if (document.forms['signup'].is_bday_na.checked == false)
	{

		// make sure the day entered matches the month
		bday_day = document.forms['signup'].bday_day.value;
		//bday_year = document.forms['signup'].bday_year.value;
		bday_month = document.forms['signup'].bday_month.value;
		
		if (!is_valid_date(bday_day, bday_month, 2004))
		{
			errors += 1;
			bday_error = true;
		}
		
		// compose birthday date string
		//document.forms['signup'].birthday.value = bday_year + "-" + bday_month + "-" + bday_day;
		document.forms['signup'].birthday.value = "2004-" + bday_month + "-" + bday_day;
		//alert (document.forms['signup'].birthday.value);
	}
	
	/*** Anniversary ***/
	// only verify if is_ann_na isn't checked
	if (document.forms['signup'].is_ann_na.checked == false)
	{
		// make sure the day entered matches the month
		ann_day = document.forms['signup'].ann_day.value;
		ann_month = document.forms['signup'].ann_month.value;
		
		if (!is_valid_date(ann_day, ann_month, 2004))
		{
			errors += 1;
			ann_error = true;
		}
		
		// compose anniversary date string
		ann_month = document.forms['signup'].ann_month.value;
		document.forms['signup'].anniversary.value = "2004-" + ann_month + "-" + document.forms['signup'].ann_day.value;
		//alert (document.forms['signup'].anniversary.value);
	}
	
	/*** Phone Number ***/
	phone = document.forms['signup'].phone.value;
	if (phone != "")
	{
		var regExPhoneText = /^\d\d\d-\d\d\d-\d\d\d\d$/;
		if (!phone.match(regExPhoneText))
		{
			errors += 1;
			phone_error = true;
		}
	}
	
	/*** Email ***/
	email = document.forms['signup'].email.value;
	var regExEmailText = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	if (!email.match(regExEmailText))
	{
		errors += 1;
		email_error = true;
	}


	if (errors > 0)
	{
		msg = "Please fix the following:\n\n";
		if (postal_code_error)
			msg += "Invalid Postal Code\n";
		if (bday_error)
			msg += "Invalid Birthday\n";
		if (ann_error)
			msg += "Invalid Anniversary\n";
		if (phone_error)
			msg += "Invalid Phone Number\n";
		if (email_error)
			msg += "Invalid Email\n";
		alert (msg);
		return false;
	}
	else
		return true;

}

/*function doCancel()
{
	document.forms['signup'].ApMode.value='ALL';
	document.forms['signup'].action="subscriberList.php";
	document.forms['signup'].submit();
}*/
