$( document ).ready( function() {
	
	if( $( 'linkedDates' ) ) {
	
		// Prepare to show a date picker linked to three select controls 
		function readLinked() { 
			$("#linkedDates").val($("#selectMonth").val() + "/" + 
				$("#selectDay").val() + "/" + $("#selectYear").val()); 
			return {}; 
		} 
		 
		// Update three select controls to match a date picker selection 
		function updateLinked(date) { 
			$("#selectMonth").val(date.substring(0, 2)); 
			$("#selectDay").val(date.substring(3, 5)); 
			$("#selectYear").val(date.substring(6, 10)); 
		} 
		 
		// Prevent selection of invalid dates through the select controls 
		function checkLinkedDays() { 
			var daysInMonth = 32 - new Date($("#selectYear").val(), 
				$("#selectMonth").val() - 1, 32).getDate(); 
			$("#selectDay option").attr("disabled", ""); 
			$("#selectDay option:gt(" + (daysInMonth - 1) +")").attr("disabled", "disabled"); 
			if ($("#selectDay").val() > daysInMonth) { 
				$("#selectDay").val(daysInMonth); 
			} 
		} 


		$("#linkedDates").datepicker({ 
			beforeShow: readLinked, 
			onSelect: updateLinked, 
			showOn: "both", 
			buttonImage: "/media/images/buttons/calendar.gif", 
			buttonImageOnly: true 
		}); 
		$("#selectMonth, #selectYear").change(checkLinkedDays);
	
	}

});