function check_all_sendto(type){
	var teller=0;
	var veld = type + teller;
	while(document.getElementById(veld))
	{
		if(document.getElementById(type).checked === false){
			document.getElementById(veld).checked = false;
		}else{
			document.getElementById(veld).checked = true;
		}
		edit_sendto(veld);
		teller++;
		var veld = type + teller;
	}
}



function add_to_teamcal(ploegid,training,game,event,editlevel,actionlevel,date){
	
//	if(game==1 && event==0 && training==0){
//		edit_game('',ploegid,'0');
//	}else if(game==0 && event==1 && training==0){
//		edit_event('teampage','eventcalendar',ploegid,'','','',editlevel,actionlevel);
//	}else if(game==0 && event==0 && training==1){
//	
//	}else{
		openlightbox();
		var httpObj = ajaxFunction();
		var query = "teampageajax.php?qrnd=" + Math.random() + '&action=add_to_teamcal' + "&ploegid=" + ploegid + "&training=" + training + "&game=" + game + "&event=" + event + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&date=" + date;
		httpObj.open("GET",query, true);
		httpObj.send(null);
		httpObj.onreadystatechange = function(){
			if(httpObj.readyState == 4){
				document.getElementById('blackbox').innerHTML = httpObj.responseText;	
			}
		}
//	}
}



function edit_sendto(id){
	if(document.getElementById(id)){
		if(document.getElementById(id).checked === true){
			if(document.getElementById('mailto').value==""){
				document.getElementById('mailto').value=document.getElementById('mailto').value + document.getElementById(id).value;
			}else{
				document.getElementById('mailto').value=document.getElementById('mailto').value + ';' + document.getElementById(id).value;
			}
		}else{
			var waarde=document.getElementById(id).value;
			document.getElementById('mailto').value=document.getElementById('mailto').value.replace(waarde + ';', '').replace(';' + waarde, '').replace(waarde, '');
		}
	}
}

function teampag_laden(view,ploegid,accountid,fichelevel,editlevel,actionlevel){
	if(view!="team" && view!="stats"){ 
		check_acces();
	}
	if(document.getElementById('team_button')){ document.getElementById('team_button').className='fiche_button';}
	if(document.getElementById('fan_button')){ document.getElementById('fan_button').className='fiche_button';}	
	if(document.getElementById('absences_button')){ document.getElementById('absences_button').className='fiche_button';}	
	if(document.getElementById('calendar_button')){ document.getElementById('calendar_button').className='fiche_button';}
	if(document.getElementById('message_button')){ document.getElementById('message_button').className='fiche_button';}	
	if(document.getElementById('gallery_button')){ document.getElementById('gallery_button').className='fiche_button';}
	if(document.getElementById('video_button')){ document.getElementById('video_button').className='fiche_button';}
	if(document.getElementById('lists_button')){ document.getElementById('lists_button').className='fiche_button';}
	if(document.getElementById('settings_button')){ document.getElementById('settings_button').className='fiche_button';}
	if(document.getElementById('stats_button')){ document.getElementById('stats_button').className='fiche_button'; var viewfromsite='0'}
	else{ var viewfromsite='1';}
	var button = view + '_button';
	if(document.getElementById(button)){document.getElementById(button).className='fiche_selected_button';}

	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random() + '&view=' + view + "&ploegid=" + ploegid + "&accountid=" + accountid + "&fichelevel=" + fichelevel + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&viewfromsite=" + viewfromsite;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('teampagecontainer').innerHTML = httpObj.responseText;	
			
			chosen_laden();
			if(view=='gallery'){ 		uitvoer_albums('1',ploegid);	}
			else if(view=='absences'){	aanwezighedenophalen('game',ploegid,fichelevel,editlevel,actionlevel);		}
			else if(view=='calendar'){	uitvoer_eventcalendar('teampage',editlevel,actionlevel);		}
			
			else if(view=='fan'){		fansophalen(ploegid,editlevel);		}
			else if(view=='message'){	messageophalen('',ploegid,editlevel,actionlevel);		}	
			else if(view=='lists'){		show_lists('',ploegid,'',editlevel,actionlevel);		}
			else if(view=='video'){		show_video('',ploegid,'','','',fichelevel,actionlevel,'0');		}
			else if(view=='stats'){	stats_show_ranking(document.getElementById('bondteamid').value,'',ploegid,fichelevel,editlevel,actionlevel);}
		}
	}
}

function stats_show_ranking(bondteamid,speeldag,ploegid,fichelevel,editlevel,actionlevel)
{
	if(document.getElementById('ranking_button')){ document.getElementById('ranking_button').className='fiche_selected_button';}
	if(document.getElementById('results_button')){ document.getElementById('results_button').className='fiche_button';}
	if(document.getElementById('graph_button')){ document.getElementById('graph_button').className='fiche_button';}
	if(document.getElementById('overview_button')){ document.getElementById('overview_button').className='fiche_button';}
	window.tab = "ranking";
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=stats_show_ranking" + "&bondteamid=" + bondteamid  + "&speeldag=" + speeldag + "&ploegid=" + ploegid + "&fichelevel=" + fichelevel + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('statscontainer').innerHTML = httpObj.responseText;	
		}
	}
}
function stats_show_results(bondteamid,forteam,ploegid,fichelevel,editlevel,actionlevel)
{

	var startdatum ='';
	var einddatum ='';
	if(document.getElementById('ranking_button')){ document.getElementById('ranking_button').className='fiche_button';}
	if(document.getElementById('results_button')){ document.getElementById('results_button').className='fiche_selected_button';}
	if(document.getElementById('graph_button')){ document.getElementById('graph_button').className='fiche_button';}
	if(document.getElementById('overview_button')){ document.getElementById('overview_button').className='fiche_button';}
	if(document.getElementById('startdatum')){  startdatum = document.getElementById('startdatum').value}
	if(document.getElementById('einddatum')){  einddatum = document.getElementById('einddatum').value}
	window.tab = "results";
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=stats_show_results" + "&bondteamid=" + bondteamid  + "&forteam=" + forteam + "&ploegid=" + ploegid + "&fichelevel=" + fichelevel + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&startdatum=" + startdatum + "&einddatum=" + einddatum;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('statscontainer').innerHTML = httpObj.responseText;	
			calendar();
		}
	}
}
function stats_show_graph(bondteamid,forteam,ploegid,fichelevel,editlevel,actionlevel)
{
	if(document.getElementById('ranking_button')){ document.getElementById('ranking_button').className='fiche_button';}
	if(document.getElementById('results_button')){ document.getElementById('results_button').className='fiche_button';}
	if(document.getElementById('graph_button')){ document.getElementById('graph_button').className='fiche_selected_button';}
	if(document.getElementById('overview_button')){ document.getElementById('overview_button').className='fiche_button';}

	window.tab = "graph";

	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=stats_show_graph" + "&bondteamid=" + bondteamid  + "&forteam=" + forteam + "&ploegid=" + ploegid + "&fichelevel=" + fichelevel + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('statscontainer').innerHTML = httpObj.responseText;	
		}
	}
}
function stats_show_overview(bondteamid,forteam,ploegid,fichelevel,editlevel,actionlevel)
{
	if(document.getElementById('ranking_button')){ document.getElementById('ranking_button').className='fiche_button';}
	if(document.getElementById('results_button')){ document.getElementById('results_button').className='fiche_button';}
	if(document.getElementById('graph_button')){ document.getElementById('graph_button').className='fiche_button';}
	if(document.getElementById('overview_button')){ document.getElementById('overview_button').className='fiche_selected_button';}
	
	window.tab = "overview";

	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=stats_show_overview" + "&bondteamid=" + bondteamid  + "&forteam=" + forteam + "&ploegid=" + ploegid + "&fichelevel=" + fichelevel + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('statscontainer').innerHTML = httpObj.responseText;	
		}
	}
}
function fansophalen(ploegid,editlevel)
{
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=fansophalen" + "&ploegid=" + ploegid + "&editlevel=" + editlevel;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('fancontainer').innerHTML = httpObj.responseText;	
		}
	}
}
function save_fan(accountid,leuze,fanid,ploegid,editlevel)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=savefan" + "&fanid=" + fanid + "&accountid=" + accountid + "&leuze=" + leuze + "&ploegid=" + ploegid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			closelightbox();
			fansophalen(ploegid,editlevel);
		}
	}
}

function save_teampag_settings(ploegid)
{
	check_acces();
	var params="&action=savesettings&ploegid=" + ploegid;
	if(document.getElementById('aanwezigheid_voorlopig_training')){
		params = params + '&aanwezigheid_voorlopig_training=' + document.getElementById('aanwezigheid_voorlopig_training').value;
	}if(document.getElementById('aanwezigheid_afmeldentot_training')){
		params = params + '&aanwezigheid_afmeldentot_training=' + document.getElementById('aanwezigheid_afmeldentot_training').value;
	}if(document.getElementById('aanwezigheid_voorlopig_game')){
		params = params + '&aanwezigheid_voorlopig_game=' + document.getElementById('aanwezigheid_voorlopig_game').value;
	}if(document.getElementById('aanwezigheid_afmeldentot_game')){
		params = params + '&aanwezigheid_afmeldentot_game=' + document.getElementById('aanwezigheid_afmeldentot_game').value;
	}if(document.getElementById('aanwezigheid_voorlopig_event')){
		params = params + '&aanwezigheid_voorlopig_event=' + document.getElementById('aanwezigheid_voorlopig_event').value;
	}if(document.getElementById('aanwezigheid_afmeldentot_event')){
		params = params + '&aanwezigheid_afmeldentot_event=' + document.getElementById('aanwezigheid_afmeldentot_event').value;
	}
	
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + params;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('opslaan').style.display= 'none';
			document.getElementById('saved').style.display= '';
			fade_out('saved');
		}
	}
}

function editfan(type,fanid,ploegid,editlevel)
{
	check_acces();
	if(type !='delete'){	openlightbox();	}

	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=editfan" + "&type=" + type+ "&fanid=" + fanid + "&ploegid=" + ploegid + "&editlevel=" + editlevel;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			if(type !='delete'){
				document.getElementById('blackbox').innerHTML = httpObj.responseText;	
			}if(type !='view'){
				fansophalen(ploegid,editlevel);
			}
		}
	}
}
function list_check_vinkvak(veld)
{
	if(veld.checked == true){	var waarde = '1';}
	else{	var waarde = '0';}
	return waarde;
}

function show_lists(organstructid,ploegid,listid,editlevel,actionlevel)
{

	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=show_lists" + "&organstructid=" + organstructid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&listid=" + listid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('listcontainer').innerHTML = httpObj.responseText;
			lijst_ophalen(organstructid,ploegid,listid,editlevel,actionlevel);
		}
	}
}
function delete_list(organstructid,ploegid,listid,editlevel,actionlevel)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=delete_list" + "&organstructid=" + organstructid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&listid=" + listid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			show_lists(organstructid,ploegid,'',editlevel,actionlevel);
		}
	}
}
function lijst_ophalen(organstructid,ploegid,listid,editlevel,actionlevel)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=lijst_ophalen" + "&organstructid=" + organstructid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&listid=" + listid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('lijstindiv').innerHTML = httpObj.responseText;	
		}
	}
}
function add_listcol(organstructid,ploegid,listid,editlevel,actionlevel,actie,colid)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=add_listcol" + "&organstructid=" + organstructid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&listid=" + listid + "&colid=" + colid + "&do=" + actie;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			lijst_ophalen(organstructid,ploegid,listid,editlevel,actionlevel);
		}
	}
}
function save_list(organstructid,ploegid,listid,editlevel,actionlevel,waarde,accountid,colid)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=save_list" + "&organstructid=" + organstructid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&listid=" + listid + "&colid=" + colid + "&waarde=" + waarde + "&accountid=" + accountid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('opslaan').style.display= 'none';
			document.getElementById('saved').style.display= '';
			stop_fade('saved');
			fade_out('saved');		
		}
	}
}
function save_list_title(organstructid,ploegid,listid,editlevel,actionlevel,waarde,colid)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=save_list_title" + "&organstructid=" + organstructid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&listid=" + listid + "&colid=" + colid + "&waarde=" + waarde ;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById('opslaan').style.display= 'none';
			document.getElementById('saved').style.display= '';
			stop_fade('saved');
			fade_out('saved');		
		}
	}
}
function edit_list(organstructid,ploegid,listid,editlevel,actionlevel)
{
	check_acces();
	openlightbox();
	
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=editlist" + "&listid=" + listid + "&organstructid=" + organstructid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('blackbox').innerHTML = httpObj.responseText;	
			listadministrator_toevoegen('','');
		}
	}
}

function listadministrator_toevoegen(accountid,action)
{
	check_acces();
	var waarde='';
	if(document.getElementById('account_listadministrators')){
		waarde = document.getElementById('account_listadministrators').value;
	}
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=listadministrator_toevoegen" + "&accountid=" + accountid + "&waarde=" + waarde + "&do=" + action;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('listadministrators').innerHTML = httpObj.responseText;	
		}
	}
}
function add_list(organstructid,ploegid,listid,editlevel,actionlevel)
{
	check_acces();
	var param="action=add_list";
	if(document.getElementById('account_listadministrators')){
		param = param + "&account_listadministrators=" + document.getElementById('account_listadministrators').value;
	}if(document.getElementById('listname')){
		param = param + "&listname=" + document.getElementById('listname').value;
	}if(document.getElementById('listpublic')){
		if(document.getElementById('listpublic').checked == true){param = param + "&listpublic=" + "1";}
		else{param = param + "&listpublic=" + "0";}
	}if(document.getElementById('listtype')){
		param = param + "&listtype=" + document.getElementById('listtype').value;
	}if(document.getElementById('showtotals')){
		if(document.getElementById('showtotals').checked == true){param = param + "&showtotals=" + "1";}
		else{param = param + "&showtotals=" + "0";}
	}if(document.getElementById('editownrow')){
		if(document.getElementById('editownrow').checked == true){param = param + "&editownrow=" + "1";}
		else{param = param + "&editownrow=" + "0";}
	}	
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=add_list" + "&organstructid=" + organstructid + "&ploegid=" + ploegid + "&listid=" + listid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&param=" + param;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			closelightbox();
			show_lists(organstructid,ploegid,listid,editlevel,actionlevel);
		}
	}
}
function calc_rijtot(nummer,aantalrij, aantalcols, doel)
{
	nummer = Number(nummer);
	aantalrij = Number(aantalrij);
	aantalcols = Number(aantalcols);
	var rijnummer = nummer;

	while(aantalrij < rijnummer  ){	rijnummer = rijnummer - aantalrij;	}

	var totaal = 0;
	var element = "lv" + rijnummer;
	for(var i=0;i<aantalcols;i++)
	{
		var element = "lv" + rijnummer;
		if(document.getElementById(element)){
			if(document.getElementById(element).type == "checkbox"){
				if(document.getElementById(element).checked == true){
					totaal = Number(totaal) + 1;
				}
			}else if(document.getElementById(element).type == "text"){
				if(isFinite(document.getElementById(element).value)){
					totaal = Number(totaal) + Number(document.getElementById(element).value);
				}		
			}else{
				if(document.getElementById(element).value == 1){
					totaal = Number(totaal) + 1;
				}
			}
		}
		rijnummer = Number(rijnummer) + aantalrij;
	}
	if(document.getElementById(doel)){
		document.getElementById(doel).innerHTML = totaal;
	}	
}
function calc_coltot(nummer,aantalrij, aantalcols, doel)
{
	nummer = Number(nummer);
	aantalrij = Number(aantalrij);
	aantalcols = Number(aantalcols);
	var colnummer = Number(Math.floor( (Number(nummer) - Number(1)) / Number(aantalrij))) + 1;
	colitem = Number(Number(colnummer) * Number(aantalrij)) - Number(aantalrij) + Number(1);
	var totaal = 0;
	for(var i=0;i<aantalrij;i++){
		var element = "lv" + colitem;
		if(document.getElementById(element)){
			if(document.getElementById(element).type == "checkbox"){
				if(document.getElementById(element).checked == true){
					totaal = Number(totaal) + 1;
				}
			}else if(document.getElementById(element).type == "text"){
				if(isFinite(document.getElementById(element).value)){
					totaal = Number(totaal) + Number(document.getElementById(element).value);
				}		
			}else{
				if(document.getElementById(element).value == 1){
					totaal = Number(totaal) + 1;
				}
			}
		}
		colitem = Number(colitem) + 1;
	}
	if(document.getElementById(doel)){
		document.getElementById(doel).innerHTML = totaal;
	}
}

function detail_popup(id,type,editlevel,actionlevel,editable,deletable,addform,view,ploegid,organstructid)
{
	openlightbox();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=detailpopup" + "&ploegid=" + ploegid + "&organstructid=" + organstructid + "&id=" + id+ "&type=" + type + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&editable=" + editable + "&deletable=" + deletable + "&addform=" + addform + "&view=" + view ;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('blackbox').innerHTML = httpObj.responseText;	
		}
	}
}

function aanwezighedenophalen(type,ploegid,fichelevel,editlevel,actionlevel)
{

	if(document.getElementById('showtraining').checked == true){
		var showtraining = 1;
	}else{
		var showtraining = 0;
	}
	if(document.getElementById('showgame').checked == true){
		var showgame = 1;
	}else{
		var showgame = 0;
	}
	if(document.getElementById('showevent').checked == true){
		var showevent = 1;
	}else{
		var showevent = 0;
	}
	check_acces();
	document.getElementById('aanwezigcontainer').innerHTML = '<center><img src=images/loading.gif style="margin-top:15px;"></center>';
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=aanwezigheden" + "&ploegid=" + ploegid + "&trwe=" + type + "&fichelevel=" + fichelevel + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&showtraining=" + showtraining + "&showgame=" + showgame + "&showevent=" + showevent;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			
			var tekst = httpObj.responseText.split('{BREAKSCROLL}');
			
			document.getElementById('aanwezigcontainer').innerHTML = tekst[0];
			tooltip();
			var scroll = tekst[1] - 300;
			$("#scrollaanwezigheden").scrollLeft(scroll);
		}
	}
}

function os(type, id, ploegenaccountid,fichelevel,editlevel,actionlevel,param)
{
	check_acces();
	if(type=='t'){	type='training';}
	if(type=='g'){	type='game';}	
	if(type=='e'){	type='event';}
	openlightbox();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=openstatus" + "&type=" + type + "&id=" + id + "&ploegenaccountid=" + ploegenaccountid + "&fichelevel=" + fichelevel + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&param=" + param;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('blackbox').innerHTML = httpObj.responseText;	
		}
	}
}

function save_status(type, id, orgaanwezigid,comment,ploegenaccountid,ploegid,fichelevel,editlevel,actionlevel,sendmail,param){
	
	check_acces();
	comment = urlencode(comment);
	closelightbox();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=savestatus" + "&type=" + type + "&id=" + id + "&orgaanwezigid=" + orgaanwezigid + "&comment=" + comment + "&ploegenaccountid=" + ploegenaccountid + "&sendmail=" + sendmail + "&param=" + param;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			aanwezighedenophalen(type,ploegid,fichelevel,editlevel,actionlevel);
		}
	}
}


function teampag_del_message(teampagid,ploegid,editlevel,actionlevel,id)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=deletemessage" + "&id=" + id ;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			messageophalen(teampagid,ploegid,editlevel,actionlevel);
		}
	}
}
function teampag_save_message(teampagid,ploegid,editlevel,actionlevel,reageer)
{
	check_acces();
	var message = tinyMCE.get('teampagmessage').getContent();
	var to = document.getElementById('to').value;
	if(document.getElementById('showonwebsite')){
		if(document.getElementById('showonwebsite').checked == true){
			var website = '1';
		}else{
			var website = '0';
		}
	}

	message = encodeURIComponent(message);
	var httpObj = ajaxFunction();
	var url = "teampageajax.php?action=savemessage";
	var to = document.getElementById('mailto').value;
	var params = "qrnd=" + Math.random() + '&to=' + to  + '&message=' + message  + '&teampagid=' + teampagid  + '&ploegid=' + ploegid  + '&editlevel=' + editlevel + '&reageer=' + reageer + '&showonwebsite=' + website;
	httpObj.open("POST",url, true);
	httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	httpObj.setRequestHeader("Content-length", params.length);
	httpObj.setRequestHeader("Connection", "close");	
	httpObj.onreadystatechange = function() {
		if(httpObj.readyState == 4 && httpObj.status == 200) {
			closelightbox();
			messageophalen(reageer,ploegid,editlevel,actionlevel);		
		}
	}
	httpObj.send(params);
}
	
function messageophalen(teampagid,ploegid,editlevel,actionlevel,aantal)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=messageophalen" + "&teampagid=" + teampagid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&aantal=" + aantal;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('messagecontainer').innerHTML = httpObj.responseText;	
		}
	}
}
function edit_message(teampagid,ploegid,trainingid,gameid,eventid,editlevel,actionlevel,reageer)
{
	check_acces();
	openlightbox();

	var httpObj = ajaxFunction();
	var query = "teampageajax.php?qrnd=" + Math.random()  + "&action=editmessage" + "&teampagid=" + teampagid + "&ploegid=" + ploegid + "&editlevel=" + editlevel + "&actionlevel=" + actionlevel + "&trainingid=" + trainingid + "&gameid=" + gameid + "&eventid=" + eventid + "&reageer=" + reageer;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			document.getElementById('blackbox').innerHTML = httpObj.responseText;
			setup_tinymce_message();
		}
	}
}

