// minical asp calendar; code by scott, 2010; last modified by scott, 1/17/2010

// establish the current date for script initialization. 
var current_day = new Date()
current_day = (current_day.getMonth()+1) + "/" + current_day.getDate() + "/" + current_day.getFullYear();

// default view in iframe(lessons,clinics,events,concerts)
var v = 0;

// redraw the calendar.  requires jQuery ajax library
function mc_redraw(date) {
	current_day = date;
	$(document).ready(function(){
		// redraw the mini calendar					   
		$("#minical").load("/cust/activity/cal.asp?draw=yes&d="+date);
		// reload the iframe content
		$('#eventframe').attr('src','/Calendar/'+date+'/'+v+'/'+$('#location_cal option:selected').val());
	});
}

// change the day in the calendar within same month. 
function mc_changedate_samemonth(t,date,y) {
	current_day = date;
	var cells = $("#minicaltable td");
	$(cells).removeClass("selected");
	if (y) {
		$("#"+y).addClass("selected");
	}
	else {
		$(t).addClass("selected");
	}
	x = date.split('/');
	document.getElementById('eventframe').contentWindow.scrolltodate(x[1]);
}

// shifting from day to day.  we need to determine if this click results in a month change.
function mc_shift_day(c) {
	a = current_day.split("/");
	var startDate = new Date(a[2],a[0]-1,a[1]);
	var endDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate()-0+c);
	date = endDate.getMonth()+1 + "/" + endDate.getDate() + "/" + endDate.getFullYear();
	t = "d_"+endDate.getFullYear()+"_"+parseInt(endDate.getMonth()+1)+"_"+parseInt(endDate.getDate());
	if (endDate.getMonth() == startDate.getMonth()) {
		mc_changedate_samemonth(0,date,t);
	}
	else {
		mc_redraw(date);
	}
}

$(document).ready(function() {
	if ($('#location_cal').length > 0) {  
		$('#location_cal').change(function() {
			//if ($('#location_cal option:selected').val() == 0) { document.location = '/' + $(this).attr('rel') + '/'; }
			//else {
			//	loc = $('#location_cal option:selected').html().split(',');
				//document.location = '/'+$(this).attr('rel')+'/'+$('#location_cal option:selected').val()+'-'+loc[0]+'/';	
				$('#eventframe').attr('src','/Calendar/'+current_day+'/'+v+'/'+$('#location_cal option:selected').val());
			//}
		});
	}
});

// load subset of activity types
function loadcal(x) {
	v = x;
	document.getElementById('tab0').className = 'tab_all';
	document.getElementById('tab1').className = 'tab_lessons';
	document.getElementById('tab2').className = 'tab_clinics';
	document.getElementById('tab3').className = 'tab_events';
	document.getElementById('tab4').className = 'tab_concerts';
	document.getElementById('tab'+x).className = 'tab_front';
	date = current_day;
	$(document).ready(function(){				   
		$('#eventframe').attr('src','/Calendar/'+date+'/'+v+'/'+$('#location_cal option:selected').val());
	});
}
