var $jQ = jQuery.noConflict();

jQuery(document).ready(function()
{
	var bindReportConstraintBehaviors = function(scope) {
	    
	    $jQ('#chk-15').click(function(){
            $jQ('.chk-15_Input').attr("disabled", !$jQ(this).attr("checked"));
	    });
	    
		$jQ('#chk-16').click(function(){
            $jQ('.chk-16_Input').attr("disabled", !$jQ(this).attr("checked"));
	    });

	    $jQ('#chk-17').click(function(){
            $jQ('.chk-17_Input').attr("disabled", !$jQ(this).attr("checked"));
	    });
	
		$jQ('#chk-18').click(function(){
            $jQ('.chk-18_Input').attr("disabled", !$jQ(this).attr("checked"));
	    });
	    
		$jQ('#chk-19').click(function(){
            $jQ('.chk-19_Input').attr("disabled", !$jQ(this).attr("checked"));
	    });
	    
		$jQ('#chk-20').click(function(){
            $jQ('.chk-20_Input').attr("disabled", !$jQ(this).attr("checked"));
	    });
	    
		$jQ('#chk-21').click(function(){
            $jQ('.chk-21_Input').attr("disabled", !$jQ(this).attr("checked"));
	    });
	}

	bindReportConstraintBehaviors();

	$jQ('.miniCalendar').hover(
		function()
		{
			$jQ(this).css('background', '#eee');
		},
		function()
		{
			$jQ(this).css('background', '#fff');
		}		
	);
		
	$jQ('#moveCalendarLeft').click(
		function()
		{
			$month = $jQ('.miniCalendar:first').attr('id');
	
			$jQ.ajax({
				type: "POST",
				url:  "../includes/ajax/getCalendar.php",
				data: "month=" + $month + "&which=prev",
				success: function(data){
					if (data)
					{
						if (data != $jQ('.miniCalendar:first').attr('innerHTML'))
						{					
							$jQ('#calendar_container').prepend(data);
							
							$firstMonth = $jQ('.miniCalendar:first').attr("id");
							
							$jQ('#'+$firstMonth).hover(
								function()
								{
									$jQ(this).css('background', '#eee');
								},
								function()
								{
									$jQ(this).css('background', '#fff');
								}
							);
				
							$jQ('.miniCalendar:last').remove();	
						}
					}
				},
				error:function(){
				}
			});			
		}
	);

	$jQ('#moveCalendarRight').click(
		function()
		{
			$month = $jQ('.miniCalendar:last').attr('id');
		
			$jQ.ajax({
				type: "POST",
				url:  "../includes/ajax/getCalendar.php",
				data: "month=" + $month + "&which=next",
				success: 
					function(data)
					{
						if (data)
						{
							if (data != $jQ('.miniCalendar:last').attr('innerHTML'))
							{
								$jQ('#calendar_container').append(data);
			
								$lastMonth = $jQ('.miniCalendar:last').attr("id");
		
								$jQ('#'+$lastMonth).hover(
									function()
									{
										$jQ(this).css('background', '#eee');
									},
									function()
									{
										$jQ(this).css('background', '#fff');
									}
								);
		
								$jQ('.miniCalendar:first').remove();
							}
						}
					},
				error:
					function()
					{
					
					}
			});	
		}
	);

	$jQ('.courseChkBox').click(
		function()
		{
			var $totalHours = 0;
			
			$jQ('.courseChkBox:checked').each(
				function() {
					var $courseID = $jQ(this).attr('id').substr('checkbox'.length);
					var $courseHours = parseInt($jQ('#hours' + $courseID).val());
					$totalHours += $courseHours;
				}
			);
			
			$jQ('#total').attr('value', $totalHours);
			$jQ('#total2').attr('value', $totalHours);
		}
	);
	
	if ($jQ('#pageHome').attr('id'))
	{
		$jQ('.courseChkBox').attr("checked",false);
		checkCourseSelections();
	}
});


function checkCourseSelections()
{
	var $totalHours = 0;
	
	$jQ('.courseChkBox:checked').each(
		function() {
			var $courseID = $jQ(this).attr('id').substr('checkbox'.length);
			var $courseHours = parseInt($jQ('#hours' + $courseID).val());
			$totalHours += $courseHours;
		}
	);
	
	$jQ('#total').attr('value', $totalHours);
	$jQ('#total2').attr('value', $totalHours);
}

function composeMessageTo($userID) 
{    
    $jQ.prompt("Sending Message to user"+$userID);
}

