function isValidDate(the_day,the_month,the_year)
{
	var leap = 0;
	
if ((the_year % 4 == 0) || (the_year % 100 == 0) || (the_year % 400 == 0)) 
{
      leap = 1;
}

if ((the_month == 2) && (leap == 1) && (the_day > 29)) 
{
      return false;
}

if ((the_month == 2) && (leap != 1) && (the_day > 28)) 
{
      return false;
}


if ((the_day > 31) && ((the_month == "1") || (the_month == "3") || (the_month == "5") || (the_month == "7") || (the_month == "8") || (the_month == "10") || (the_month == "12"))) {
      return false;
   }
   if ((the_day > 30) && ((the_month == "4") || (the_month == "6") || (the_month == "9") || (the_month == "11"))) {
      return false;
   }

	return true;
	
}





function check_dob(the_dob_year,the_dob_month,the_dob_day,min_age,max_age)
{
	var the_dob = new Date();
	the_dob.setFullYear(the_dob_year,the_dob_month-1,the_dob_day);
	
	
	var valid_isValidDate = isValidDate(the_dob_day,the_dob_month,the_dob_year);
		
		if (valid_isValidDate != true)
		{
					response = 'Date Of Birth is not a Valid Date';				
					return response;
		}


		var the_date_now = new Date();
		var the_year_today  = the_date_now.getFullYear();
		var the_month_today = the_date_now.getMonth();
		var the_date_today = the_date_now.getDate();
	
		var the_year_min_years_ago = the_year_today - min_age;
		var the_year_max_years_ago = the_year_today - max_age;
	
		var the_date_min_years_ago = new Date();
		var the_date_max_years_ago = new Date();
	
		the_date_min_years_ago.setFullYear(the_year_min_years_ago,the_month_today,the_date_today);
		the_date_max_years_ago.setFullYear(the_year_max_years_ago,the_month_today,the_date_today);
	
		if(the_dob <= the_date_min_years_ago && the_dob >= the_date_max_years_ago)
		{
					return true;
			
		}
		else
		{	
					response = 'Age is not valid ';				
					return response;
		}
	
		
}


