jQuery(document).ready(function()
{
	jQuery('#searchteam').click(function()
	{
		jQuery.ajax({
			type: "post",
			url: ajax_url,
			data: {
				action: 'get_liste_team_by_pattern',
				pattern: jQuery("#searchteamtxt").val()
			},
			success: function(html){
				jQuery("#teamliste").html(html);
			}
		});
	});
});

function select_teams_page()
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'get_liste_team_by_page',
			page: jQuery("#selectpageteam").val()
		},
		success: function(html){
			jQuery("#teamliste").html(html);
		}
	});
}

function create_team()
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'create_team',
			team: jQuery("#new_team").val(),
			flag: jQuery("#flag").val(),
			password: jQuery("#new_password").val()
		},
		success: function(html) {
			jQuery("#koth").html(html);
		}
	});
}

function desinscrire_team(id_team)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'desinscrire_team',
			id_team: id_team
		},
		success: function(html) {
			jQuery("#koth").html(html);
		}
	});
}
function inscrire_team(id_team)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'inscrire_team',
			id_team: id_team
		},
		success: function(html) {
			jQuery("#koth").html(html);
		}
	});
}

function update_team(id_team)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'update_team',
			id_team: id_team,
			name: jQuery("#nametxt").val(),
			flag: jQuery("#flagselect").val(),
			password: jQuery("#passwordtxt").val(),
			site: jQuery("#webtxt").val(),
			irc: jQuery("#irctxt").val()
		},
		success: function(html) {
			jQuery("#koth-log").html(html);
		}
	});
};

function kick_player()
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'kick_player',
			id_player: jQuery("#playerselect").val()
		},
		success: function(html) {
			if (html)
				jQuery("#koth-log").html(html);
			else
				window.location.reload();
		}
	});
}

function voter_team(radio)
{
	var id_team = 0;
	
	if (radio.checked)
		id_team = radio.value;
	else
	{
		for (var i=0; i<radio.length; i++)
		{
			if (radio[i].checked)
				id_team = radio[i].value;
		}
	}

	if (id_team == 0)
		alert("Aucune team sélectionnée");
	else
		jQuery.ajax({
			type: "post",
			url: ajax_url,
			data: {
				action: 'voter_team',
				id_team: id_team
			},
			success: function(html) {
				jQuery("#koth").html(html);
			}
		});
}

function update_score()
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'update_score',
			score_king: jQuery("#score_king").val(),
			score_challenger: jQuery("#score_challenger").val()
		},
		success: function(html) {
			jQuery("#koth").html(html);
		}
	});
}

function busting(is_bust, is_joueur, id)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'busting',
			is_bust: is_bust,
			is_player: is_joueur,
			id: id
		},
		success: function(html) {
			if (html)
				jQuery("#koth-log").html(html);
			else
				window.location.reload();
		}
	});
}

function change_captain(id_team)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'change_captain',
			id_team: id_team,
			id_player: jQuery("#playerselect").val()
		},
		success: function(html) {
			if (html)
				jQuery("#koth-log").html(html);
			else
				window.location.reload();
		}
	});
}

function rejoindre_team(id_player, id_team)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'rejoindre_team',
			id_player: id_player,
			id_team: id_team,
			password: jQuery("#jointeamtxt").val()
		},
		success: function(html) {
			if (html)
				jQuery("#koth-log").html(html);
			else
				window.location.reload();
		}
	});
}

function quitter_team(id_player, id_team)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'quitter_team',
			id_player: id_player,
			id_team: id_team
		},
		success: function(html) {
			if (html)
				jQuery("#koth-log").html(html);
			else
				window.location.reload();
		}
	});
}

function delete_team(id_team)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'delete_team',
			id_team: id_team
		},
		success: function(html) {
			if (html)
				jQuery("#koth-log").html(html);
			else
				window.location.reload();
		}
	});
}

function go_admin()
{
	window.location = window.location + "&admin=1";
}

function update_profil(id_player)
{
	jQuery.ajax({
		type: "post",
		url: ajax_url,
		data: {
			action: 'update_profil',
			id_player: id_player,
			etproguid: jQuery("#etproguidtxt").val(),
			pbguid: jQuery("#pbguidtxt").val()
		},
		success: function(html) {
			if (html)
				jQuery("#koth-log").html(html);
			else
				window.location.reload();
		}
	});
}

function toogle_visibility(id)
{
	var type = document.getElementById(id).className;
	if (type == "koth-hidden")
		document.getElementById(id).className = "koth-visible";
	else
		document.getElementById(id).className = "koth-hidden";
}