function chkDate(dObj, mObj, yObj)
{
	return  checkDate(dObj, mObj, yObj, msg[52]);
}

function checkDate(dObj, mObj, yObj, errMsg)
{
		if (!date_validate(parseInt(dObj.value, 10), parseInt(mObj.value, 10), parseInt(yObj.value, 10))) return alertUser(dObj, errMsg);
		return true;
}

function date_validate(day, month, year)
{
   var chk    = 0;
   var maxDay = 0;

	maxDay = max_day(month, year);

	if ((day < 1) || (day > maxDay))     { chk = 1;}
	else if ((month < 1) || (month > 12)) { chk = 2;}
	else if ((year <= 0))                 { chk = 3;}

	if (chk == 1)      { alert(msg[53]); }
	else if (chk == 2) { alert(msg[54]); }
	else if (chk == 3) { alert(msg[55]); }

	if (chk == 0) { return true; }
	else { return false;}
}

function max_day(mn, yr){
	var mDay;

	if((mn == 4) || (mn == 6) || (mn == 9) || (mn == 11))   {mDay = 30;}
	else if(mn == 2) {

		mDay = isLeapYear(yr) ? 29 : 28;
	} else { mDay = 31;}

	return mDay;
}

function isLeapYear(yr) {
	if (yr % 4 == 0) return true;
	return false;
}



function chkFutureDate(day, month, year) 
{
	return checkFutureDate(day, month, year, msg[57], msg[57], msg[57]) 
}

function checkFutureDate(day, month, year, dayErrMsg, monthErrMsg, yearErrMsg) 
{
	var result = futureDate(day, month, year);

	switch (result) {
		case 0:
			return false; // date is not in the future
			break;

		case 1:
			alert(yearErrMsg.replace('%s', year));
			return true;
			break;

		case 2:
			alert(monthErrMsg.replace('%s', month));
			return true;
			break;

		case 3:
			alert(dayErrMsg.replace('%s', day));
			return true;
			break;

		default:
			return false;
			break;
	}
}

// returns 0 if date is not within future
// 1 for year in the future
// 2 for month in the future
// 3 for day in the future
function futureDate(day, month, year)
{
	var today  = new Date();
	var mYear  = parseInt(today.getFullYear(), 10);
	var mMonth = parseInt(today.getMonth(), 10) + 1; // extra one is added because HAS insists on months from 0-11 and not 1- 12
	var mDay   = parseInt(today.getDate(), 10);
	var chk = 0;

	if (parseInt(year,10) > mYear) chk = 1;
	else if (parseInt(year,10) == mYear && parseInt(month, 10) > mMonth) chk = 2;
	else if (parseInt(year,10) == mYear && parseInt(month, 10) == mMonth && parseInt(day, 10) > mDay) chk = 3;

	return chk;
}

function isFutureDate(day, month, year){
	var today  = new Date();
	var mYear  = parseInt(today.getFullYear(), 10);
	var mMonth = parseInt(today.getMonth(), 10) + 1; // extra one is added because Javascript insists on months from 0-11 and not 1- 12
	var mDay   = parseInt(today.getDate(), 10);
	
	if (parseInt(year,10) < mYear) return false;
	else if (parseInt(year,10) == mYear && parseInt(month, 10) < mMonth) return false;
	else if (parseInt(year,10) == mYear && parseInt(month, 10) == mMonth && parseInt(day, 10) < mDay) return false;

	return true;
}
