function checkIfAdult(idYear, idMonth, idDay, idColumnLabelToHighlight)
{
var varYear = document.getElementById(idYear).value;
var varMonth = document.getElementById(idMonth).value;
var varDate = document.getElementById(idDay).value;
var toDay = new Date();
var AgeToCompare = new Date();
AgeToCompare.setDate(varDate);
AgeToCompare.setMonth((parseInt(varMonth)-1));
AgeToCompare.setFullYear(varYear);
//alert("Diff : ");
var currentYear = toDay.getFullYear();
var toCompareYear = AgeToCompare.getFullYear();
//alert("Inside");
var currentMonth = toDay.getMonth();
var toCompareMonth = AgeToCompare.getMonth();
//alert("Inside");
var currentDay = toDay.getDate();
var toCompareDay = AgeToCompare.getDate();
//alert("Inside");
var toReturn = true;
//alert("Diff : " + (currentYear - toCompareYear)) ;
document.getElementById(idColumnLabelToHighlight).style.color="#000000";
if( (currentYear - toCompareYear) > 17 )
{
//alert("> 17");
toReturn = true;
}
else if( (currentYear - toCompareYear) == 17 )
{
//alert("= 17");
//alert("Diff : " + (currentMonth - toCompareMonth)) ;
if( (currentMonth - toCompareMonth) > 0 )
{
toReturn = true;
}
else if( (currentMonth - toCompareMonth) == 0 )
{
//alert("Diff : " + (currentDay - toCompareDay)) ;
if( (currentDay - toCompareDay) > 0 )
{
toReturn = true;
}
else
{
toReturn = false;
}
}
else
{
toReturn = false;
}
document.getElementById(idColumnLabelToHighlight).style.color="#000000";
}
else
{
toReturn = false;
}
if(toReturn == false)
{
alert("Date Error : Only adults can book use this.");
document.getElementById(idColumnLabelToHighlight).style.color="#ff0000";
return false;
}
return toReturn;
}
No comments:
Post a Comment