function PopUpScoreboardCalendar(s,m,y) {
	
	var month = m;
	var year = y;
	var season_id = s;
	
	popup('sbpopup');

   	new Ajax.Request('ajax/scoreboard_ajax.php',
	{
	    method: 'GET',
      	parameters: {action: 'displayscoreboardmonthlycalendar',
      				 m: month,
      				 y: year,
      				 s: season_id},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
         	$('sbpopup').update(html);
      	}      	
      
   	}); 
   	
}

function PopUpDivisionScoreboardCalendar(d,s,m,y) {
	
	var division_id = d;
	var season_id = s;
	var month = m;
	var year = y;
	
	popup('sbpopup');

   	new Ajax.Request('ajax/scoreboard_ajax.php',
	{
	    method: 'GET',
      	parameters: {action: 'displaydivisionscoreboardmonthlycalendar',
      				 m: month,
      				 y: year,
      				 d: division_id,
      				 s: season_id},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
         	$('sbpopup').update(html);
      	}      	
      
   	}); 
   	
}

function PopUpTeamScoreboardCalendar(t,s,m,y) {
	
	var team_id = t;
	var season_id = s;
	var month = m;
	var year = y;
	
	popup('sbpopup');

   	new Ajax.Request('ajax/scoreboard_ajax.php',
	{
	    method: 'GET',
      	parameters: {action: 'displayteamscoreboardmonthlycalendar',
      				 m: month,
      				 y: year,
      				 t: team_id,
      				 s: season_id},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
         	$('sbpopup').update(html);
      	}      	
      
   	}); 
   	
}

function calendarTeamDisplay(t,s,m,y) {
	
	var month = m;
	var year = y;
	var season_id = s;
	var team_id = t;
	
   	new Ajax.Request('ajax/scoreboard_ajax.php',
	{
	    method: 'GET',
      	parameters: {action: 'displayteamscoreboardmonthlycalendar',
      				 m: month,
      				 y: year,
      				 t: team_id,
      				 s: season_id},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
         	$('sbpopup').update(html);
      	}      	
      
   	}); 
	
}

function calendarDivisionDisplay(d,s,m,y) {
	
	var month = m;
	var year = y;
	var season_id = s;
	var division_id = d;
	
   	new Ajax.Request('ajax/scoreboard_ajax.php',
	{
	    method: 'GET',
      	parameters: {action: 'displaydivisionscoreboardmonthlycalendar',
      				 m: month,
      				 y: year,
      				 d: division_id,
      				 s: season_id},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
         	$('sbpopup').update(html);
      	}      	
      
   	}); 
	
}

function calendarDisplay(s,m,y) {
	
	var month = m;
	var year = y;
	var season_id = s;
	
   	new Ajax.Request('ajax/scoreboard_ajax.php',
   	{
      	method: 'GET',
      	parameters: {action: 'displayscoreboardmonthlycalendar',
      				 m: month,
      				 y: year,
      				 s: season_id},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
			$('sbpopup').update(html);
      	}      	
      
   	}); 	
	
}

function closeScoreboardCalendarPopup() {
	$('sbpopup').hide();
}

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}

function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('sbblanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	//popUpDiv_height=blanket_height/2-340;//150 is half popup's height
	popUpDiv_height = 250;
	popUpDiv.style.top = popUpDiv_height + 'px';
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-100;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}

function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('sbblanket');
	toggle(windowname);		
}

function switchScoreBoardDay(l,s,d) {
	
	var league_id = l;
	var season_id = s;
	var date = d;
	
   	new Ajax.Request('ajax/leagues_ajax.php',
   	{
       	onCreate: function () {
      	$('psbb_scoreboard_refresh').addClassName('transparencybg').show();
       	},       		
      	method: 'GET',
      	parameters: {action: 'leaguescoreboard',
      				 l: league_id,
      				 s: season_id,
      				 d: date},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
         	weekdays = json.weekdays;
         	scoreboarddate = json.scoreboarddate;
         	
         	$('psbb_scoreboard_refresh').removeClassName('transparencybg').show();
			$('psbb_scoreboard_refresh').update(html);
			$('psbb_calendar_weekly_day').update(weekdays);
			$('psbb_scoreboard_date').update(scoreboarddate);
			
      	}      	
      
   	}); 	
}

function switchDivisionScoreBoardDay(did,s,d) {
	
	var division_id = did;
	var season_id = s;
	var date = d;
	
   	new Ajax.Request('ajax/divisions_ajax.php',
   	{
       	onCreate: function () {
      	$('psbb_scoreboard_refresh').addClassName('transparencybg').show();
       	},       		
      	method: 'GET',
      	parameters: {action: 'divisionscoreboard',
      				 did: division_id,
      				 s: season_id,
      				 d: date},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
         	weekdays = json.weekdays;
         	scoreboarddate = json.scoreboarddate;
         	
         	$('psbb_scoreboard_refresh').removeClassName('transparencybg').show();
			$('psbb_scoreboard_refresh').update(html);
			$('psbb_calendar_weekly_day').update(weekdays);
			$('psbb_scoreboard_date').update(scoreboarddate);
						
      	}      	
      
   	}); 	
}

function switchTeamScoreBoardDay(tid,s,d) {
	
	var team_id = tid;
	var season_id = s;
	var date = d;
	
   	new Ajax.Request('ajax/teams_ajax.php',
   	{
       	onCreate: function () {
      	$('psbb_scoreboard_refresh').addClassName('transparencybg').show();
       	},       		
      	method: 'GET',
      	parameters: {action: 'teamscoreboard',
      				 tid: team_id,
      				 s: season_id,
      				 d: date},
      	failure:'errors',
      	onSuccess:function(transport) { 	
         	var json = transport.responseText.evalJSON(true);
         	html = json.html;
         	weekdays = json.weekdays;
         	scoreboarddate = json.scoreboarddate;
         	
         	$('psbb_scoreboard_refresh').removeClassName('transparencybg').show();
			$('psbb_scoreboard_refresh').update(html);
			$('psbb_calendar_weekly_day').update(weekdays);
			$('psbb_scoreboard_date').update(scoreboarddate);
				
      	}      	
      
   	}); 	
}




