var MASK_INVALID_TELEPHONE_NUMBER = "You have entered an invalid Telephone Number.";
var MASK_INVALID_TELEPHONE_EXTENSION = "You have entered an invalid Extension.";
var MASK_INVALID_POSTAL_CODE = "You have entered an invalid Postal Code.";
var MASK_INVALID_ZIP_CODE = "You have entered an invalid Zip Code.";
var MASK_INVALID_SIN = "You have entered an invalid Social Insurance Number.";
var MASK_INVALID_INPUT = "You have entered an invalid input.";
var MASK_INVALID_DATE = "You have entered an invalid date.";

function Mask_ParseDate(ctrl, mask)
{

	if (ctrl.value == DATE_FORMAT)
	{
		ctrl.value = "".MaskValue(mask);
	}
	else
	{
		if (ctrl.value.length > 0)
		{
			var splits = ctrl.value.split(' ');
			
			if (splits.length == 3)
			{
				var day = 1;    // default to first day of month
				var month = 0;  // default to january
				var year = parseInt(splits[2]);

				for (var i = 0; i < months.length; i++)
				{
					if (months[i].toLowerCase() == splits[0].toLowerCase())
					{
						month = i;
						break;
					}
				}

				day = splits[1].substring(0, splits[1].length);
				var date = new Date(year, month, day);

				if (date != null)
				{
					var dateStr = "";

					if (date.getMonth() < 9)
						dateStr += "0";

					dateStr += date.getMonth()+1;

					if (date.getDate() < 10)
						dateStr += "0";

					dateStr += date.getDate();
					dateStr += date.getFullYear();

					ctrl.value = dateStr.MaskValue(mask);
				}
			}
		}
	}
}

// updates an update to the field
function Mask_UpdateCalendarContent(ctrlName, date) {
	if (date) {
		// update the view and the data of the calendar control
		if (document.forms[0].elements["__MASK__" + ctrlName]) {
			document.forms[0].elements["__MASK__" + ctrlName].value = (date.getMonth()+1) + "/" + date.getDate() + "/" + date.getFullYear();
			Calendar_SetDateInMS("__MASK__" + ctrlName, ctrlName);
		}
	}	else {
		if (document.forms[0].elements["__MASK__" + ctrlName]) {
			document.forms[0].elements[ctrlName].value = "";
			document.forms[0].elements["__MASK__" + ctrlName].value = "".MaskValue(Mask_GetMask(ctrlName));
		}
	}
}