//**********************************************************************************************************************
/**
* DOCUMENT: /core/plugins/events/front/projects.back.js
* DEVELOPED BY: Ryan Stemkoski
* COMPANY: Zipline Interactive
* EMAIL: ryan@gozipline.com
* PHONE: 509-321-2849
* DATE: 4/28/2010
* DESCRIPTION: This document has all of the javascript functions required for the events  plugin.
*/
//***********************************************************************************************************************

//***********************************************************************************************************************
//ON DOCUMENT READY FUNCTIONS
//***********************************************************************************************************************
$(function() {

	//Change recruit list sport
	$('#sports_dropdown').change(function() {
		var sport_id = $(this).val();
		var committed = $('input[name="committed"]:checked').val();
		$.ajax({
			type: "GET",
			url: "/index.php",
			data: "action=output_recruit_list&sport_id="+sport_id+"&committed="+committed,
			success: function(response) {
				$(".recruit_list_table").html(response);
			}
		})
	});
	
	//Switch between all recruits and committed only
	$('input[name="committed"]').change(function() {
		var sport_id = $("#sports_dropdown").val();
		var committed = $(this).val();
		$.ajax({
			type: "GET",
			url: "/index.php",
			data: "action=output_recruit_list&sport_id="+sport_id+"&committed="+committed,
			success: function(response) {
				$(".recruit_list_table").html(response);
			}
		})
	});
	
	//Perform recruit search
	$('#recruit_search_btn').click(function() {
		$('#recruit_search').submit();
	});
	
	//Date range picker
	var dates = $( "#visit_date_start, #visit_date_end" ).datepicker({
		defaultDate: "+1w",
		changeMonth: true,
		numberOfMonths: 2,
		onSelect: function( selectedDate ) {
			var option = this.id == "visit_date_start" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates.not( this ).datepicker( "option", option, date );
		}
	});
	
	//Update positions on sport select
	$('#category_id').live('change', function() {
		var cat_id = $(this).val();

		if(cat_id != ''){
			$.ajax({
				url: "/index.php",
				data: "action=output_choose_positions&category_id=" + cat_id,
				type: "get",
				success: function(returned_data){
					$('#position_select').html(returned_data);
				}
			});
		}
		
	});
	
	$('#share_search_link').click(function() {
		this.select();
	});

});

