$(document).ready(
	function(){
		Current_Date = new Date();
		Today = Current_Date.getDate();
		Current_Month = Current_Date.getMonth();
		Current_Year = Current_Date.getFullYear();

		SixMonthsAheadDateTime = new Date();
		SixMonthsAheadDateTime.setDate(SixMonthsAheadDateTime.getDate()+180);
		six_months_from_now_Day = SixMonthsAheadDateTime.getDate();
		six_months_from_now_Month = SixMonthsAheadDateTime.getMonth();
		six_months_from_now_Year = SixMonthsAheadDateTime.getFullYear();

		first_date = Current_Month + '-' + Today + '-' + Current_Year;
		last_date = six_months_from_now_Month + '-' + six_months_from_now_Day + '-' + six_months_from_now_Year;

		month = new Array(
			'January',
			'February',
			'March',
			'April',
			'May',
			'June',
			'July',
			'August',
			'September',
			'October',
			'November',
			'December'
		);

		months = '<select onchange="get_days(this.value)" id="year_month" name="year_month" class="input-box" style="height:25px;">';
		months+= '<option value="">-Choose Month-</option>';
		i = Current_Month; n_y = 0;
		for(x = 0; x <= 6; x++){
			if(i == 12){
				i = 0;
				n_y++;
			}

			if(n_y == 1){
				use_year = six_months_from_now_Year;
			}else{
				use_year = Current_Year;
			}

			true_month = i+1;

			if(i + ' ' + use_year == Current_Month + ' ' + Current_Year){
				months+= '<option value="' + true_month + '-' + use_year + '_start-' + Today + '">' + month[i] + ' ' + use_year + '</option>';
			}else if(i + ' ' + use_year == six_months_from_now_Month + ' ' + six_months_from_now_Year){
				months+= '<option value="' + true_month + '-' + use_year + '_end-' + six_months_from_now_Day + '">' + month[i] + ' ' + use_year + '</option>';
				break;
			}else{
				months+= '<option value="' + true_month + '-' + use_year + '_all">' + month[i] + ' ' + use_year + '</option>';
			}

			i++;
		}
		months+= '</select>';

		$('#months_years').html(months);
	}
);

function get_days(month_year){
	if(jQuery.trim(month_year) == ''){
		$.post(
			"/form/form-php/kill.php",
			{
				field: 'year_month_day',
				token: token,
				time: new Date().getTime()
			},
			function(data){
				$('#check_year_month_day').attr('class','incomplete-mark');
				$('#year_month_day').html('<option>Day</option>');
			}
		);
	}else{
		$.get(
			"/form/form-php/days-of-month.php",
			{
				month_year: month_year,
				time: new Date().getTime()
			},
			function(data){
				$('#check_year_month_day').attr('class','incomplete-mark');
				$('#year_month_day').html(data);
			}
		);
	}

	return false;
}
