$(document).ready(function() {
	// events search
	var keyword = $('#fulltext').val();
	if (keyword == '') {
		$('#fulltext').css({'color':'#a6a6a6'});
		$('#fulltext').val('insert keyword');
	}
	$('#fulltext').click(function() {
		$('#fulltext').css({'color':'#000'});
		$('#fulltext').val('');									  
	});

});

// Here we change the action
function submitCalendarForm(start, end) {
	var form = document.eventsForm;

	form.start.value=start;
	form.end.value=end;
	form.submit();
}

// If deselectall is true, then the "all topics" checkbox
// is unchecked. Otherwise, all other checkboxes are unchecked
function deSelectAll(deselectall) {
	var inputs = document.eventsForm.getElementsByTagName("input");
	
	for(i = 0; i < inputs.length; i++) {
		if (inputs[i].type=="checkbox") {
			if ((inputs[i].value=="19") == deselectall) {
				inputs[i].checked = false;
			}
		}
	}
}

// Pass the name of 3 element ids, first being day, second being month, third
// being year. Also pass an offset for the day field, if the field is not just 
// numbers, put how many fields are before the list of days. 
// Pre-condition: Initial list should consist of 31 days.
// This function will fix up the option menu for the amount of days of that month.
function smartDate(day_id, month_id, year_id, day_offset) {
	var day_offset = (day_offset == null) ? 0 : day_offset;
	var days_per_month = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	
	var days = document.getElementById(day_id);
	var months = document.getElementById(month_id);
	var years = document.getElementById(year_id);
	
	var month = parseInt(months.options[months.selectedIndex].value, 10);
	var year = parseInt(years.options[years.selectedIndex].value, 10);
	
	if (!month) {
		month = 0;	
	}
	
	// Hold onto this so day can be set, also hold amount of days currently
	var selected_day = days.options[days.selectedIndex].value;
	var current_length = days.length;
	
	// If leap year, change days_per_month index 1 (Febuary) to 29.
	if (year && (year%4) == 0)
		days_per_month[1] = 29;
	
	if (!month) {
		month = 1;		
	}
	
	var days_to_add = (days_per_month[month-1]+day_offset)-days.length;
	var new_length = days.length+days_to_add;
	
	if (days_to_add > 0) {
		for (i = current_length+1; i <= new_length; i++) {	
			var opt = new Option(i-day_offset, i-day_offset);
			days.options[i-1] = opt;
		}
	}
	else {
		days.length += days_to_add;
		if (selected_day > days_per_month[month-1])
			days.options.selectedIndex = days_per_month[month-1]+day_offset-1;
	}
}