function setDayInForm(chrFormId,numDay) {
	var numDaySel = '#' + chrFormId + '_dd';
	return $(numDaySel).val(numDay);
}

function setMonthInForm(chrFormId,numMonth) {
	var numMonthSel = '#' + chrFormId + '_mm';
	return $(numMonthSel).val(numMonth);
}

function setYearInForm(chrFormId,numYear) {
	var numYearSel = '#' + chrFormId + '_yyyy';
	return $(numYearSel).val(numYear);
}

function getDayFromForm(chrFormId) {
	var numDaySel = '#' + chrFormId + '_dd';
	return $(numDaySel).val();
}

function getMonthFromForm(chrFormId) {
	var numMonthSel = '#' + chrFormId + '_mm';
	return $(numMonthSel).val();
}

function getYearFromForm(chrFormId) {
	var numYearSel = '#' + chrFormId + '_yyyy';
	return $(numYearSel).val();
}

function getDateFromForm(chrFormId) {
	var d = new Date();
	d.setFullYear(getYearFromForm(chrFormId),getMonthFromForm(chrFormId)-1,getDayFromForm(chrFormId));
	return d;
}

function isValidDateFromForm(chrFormId) {
	var chrDateString = getDateString(getYearFromForm(chrFormId),getMonthFromForm(chrFormId),getDayFromForm(chrFormId));
	return $.IsDate(chrDateString);
}

function isValidAgeRange(chrValidationFieldId,blnValidationRule) {
	if (isValidDateFromForm(chrValidationFieldId)) {
		var bDay = getDateFromForm(chrValidationFieldId);
		var numMinAge = parseInt($.ListFirst(blnValidationRule));
		var numMaxAge = parseInt($.ListLast(blnValidationRule));
		var numAge = parseInt(getAge(bDay));
		if (numAge < numMinAge || numAge > numMaxAge) {
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}	
}

function isValidFutureDate(chrFormId) {
	if (isValidDateFromForm(chrFormId)) {
		var chrToday = new Date();
		var chrFormDate = new Date();
		chrFormDate.setFullYear(getYearFromForm(chrFormId),getMonthFromForm(chrFormId)-1,getDayFromForm(chrFormId)); 
		difference = chrFormDate - chrToday;
		days = Math.round(difference/(1000*60*60*24));
		if (days < 0) {
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}

function isValidPastDate(chrFormId) {
	if (isValidDateFromForm(chrFormId)) {
		var chrToday = new Date();
		var chrFormDate = new Date();
		chrFormDate.setFullYear(getYearFromForm(chrFormId),getMonthFromForm(chrFormId)-1,getDayFromForm(chrFormId)); 
		difference = chrFormDate - chrToday;
		days = Math.round(difference/(1000*60*60*24));
		if (days > 0) {
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}

function isInValidKeyCodeOperation(e) {
	var k = getKeyCode(e);
	if (k == 60 || k == 62) {
		return true;
	} else {
		return false;
	}
}

function getDateString(y,m,d) {
	var chrDateString = m + '/' + d + '/' + y;
	return chrDateString;
}

/*
function formatDate(y,m,d) {
	return $.CreateDate(y,m,d);
}*/

function getToday() {
	return new Date();
	//return formatDate(chrToday.getFullYear(),chrToday.getMonth() + 1,chrToday.getDate());
}

function getAge(bDay)
{
	// get the policy inception date to see how old they are on that date
	var inDay = getDateFromForm('policy_inceptionDate');
	//now = new Date();
	now = inDay;
   	born = new Date(bDay);
   	years = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
   	return years;
}


function isDateAtLeastDependentField(chrValidationFieldId,blnValidationRule) {
	//first check if dependent field is valid
	if (isValidDateFromForm(blnValidationRule)) {
		var residentDay = getDateFromForm(chrValidationFieldId);
		var bDay = getDateFromForm(blnValidationRule);
		return isFirstDateSecondDateOrLater(residentDay,bDay)
	} else {
		return false;
	}
}

function isValidDate(sText) {
	return true;	
}

function isDateInFuture(chrValidationFieldId) {
	if (isValidDateFromForm(chrValidationFieldId)) {
		var today = new Date(); 
		var checkDate = getDateFromForm(chrValidationFieldId);
		return isFirstDateSecondDateOrLater(checkDate,today);
	} else {
		return false;	
	}
}

function isDateTodayOrGreater(chrValidationFieldId) {
	if (isValidDateFromForm(chrValidationFieldId)) {
		var checkDate = getDateFromForm(chrValidationFieldId);
		var today = new Date(); 
		return isFirstDateSecondDateOrLater(checkDate,today);
	} else {
		return false;	
	}
}

function isDateTodayOrLesser(chrValidationFieldId) {
	if (isValidDateFromForm(chrValidationFieldId)) {
		var checkDate = getDateFromForm(chrValidationFieldId);
		var today = new Date(); 
		return isFirstDateSecondDateOrLater(today,checkDate);
	} else {
		return false;	
	}
}

function isDateWithinDays(chrValidationFieldId,numDays) {
	if (!isDateInFuture(chrValidationFieldId)) {
		return false;
	} else {
		var checkDate = getDateFromForm(chrValidationFieldId);
		var latestDate = new Date();
		//alert(latestDate);
		var latestDate = latestDate.setDate(latestDate.getDate() + parseInt(numDays)); 
		//alert(latestDate);
		//alert(latestDate);
		if (isFirstDateSecondDateOrLater(checkDate,latestDate)) {
			//if the check date fall on latest date or after then it is not with numDays
			return false;
		} else {
			return true;
		}
		return true;
	}
}

function isFirstDateSecondDateOrLater(chrFirstDate,chrSecondDate) {
	difference = chrFirstDate - chrSecondDate;
	numDays = Math.round(difference/(1000*60*60*24));
	if (numDays < 0) {
		return false;
	} else {
		return true;
	}
}


