// JavaScript Document

function ViewEventDetail(path) {
	
	window.open(path, 'EventDetail','width=360,height=400,resizable=1');
}

function CheckRecurring(fade) {
	if( fade) {
		if( jQuery('input[name=recurring_event]').attr('checked') ) {
			jQuery('tr.recurring-tr').fadeIn();
		} else {
			jQuery('tr.recurring-tr').fadeOut();
		}
	} else {
		if( jQuery('input[name=recurring_event]').attr('checked') ) {
			jQuery('tr.recurring-tr').show();
		} else {
			jQuery('tr.recurring-tr').hide();
		}
	}
}

function CheckAllDay(fade) {
	if( fade) {
		if( jQuery('input[name=all_day]').attr('checked') ) {
			jQuery('tr.time-tr').fadeOut();
		} else {
			jQuery('tr.time-tr').fadeIn();
		}
	} else {
		if( jQuery('input[name=all_day]').attr('checked') ) {
			jQuery('tr.time-tr').hide();
		} else {
			jQuery('tr.time-tr').show();
		}
	}
}


function CheckCostFree(fade) {
	if( fade) {
		if( jQuery('input[name=cost_free]').attr('checked') ) {
			jQuery('input[name=cost]').fadeOut();
		} else {
			jQuery('input[name=cost]').fadeIn();
		}
	} else {
		if( jQuery('input[name=cost_free]').attr('checked') ) {
			jQuery('input[name=cost]').hide();
		} else {
			jQuery('input[name=cost]').show();
		}
	}
}
jQuery(function($) {
		//hide recurring event fields if needed
		CheckRecurring(false);
		
		//hide time fields if needed
		CheckAllDay(false);

		//hide cost field if needed
		CheckCostFree(false);

		//show and hide recurring event fields when the checkbox is clicked
		$('input[name=recurring_event]').click(function() {
			CheckRecurring(true)
		});
		
		//show and hide cost field when the checkbox is clicked
		$('input[name=cost_free]').click(function() {
			CheckCostFree(true)
		});
		
		//show and hide time fields when checkbox is clicked
		$('input[name=all_day]').click(function() {
			CheckAllDay(true)
		});

		//pre-fill the link url field
		$('input[name=link_url]').val('http://');

		$('form#community-add-event-form').submit(function() {
			
			if( $('input[name=link_url]').val() == 'http://') {
				$('input[name=link_url]').val('');
			}

		});
});	
