// JavaScript Document
//////////////////////
var theme = 'defaut';

function showArbo(id){
	plus = new Image();
	plus.src = "themes/" + theme + "/images/plus.jpg";
	moins = new Image();
	moins.src = "themes/" + theme + "/images/moins.jpg";
		
	if(document.getElementById('path' + id).style.display == 'none'){
    	new Effect.BlindDown('path' + id, 1);
		document['puce' + id].src = moins.src;
	}else{
		new Effect.BlindUp('path' + id, 1);
		document['puce' + id].src = plus.src;
	}
}


function translationAction(pathid, newsid, strDelete){
	var action = document.getElementById('action' + newsid).value;
	var language = document.getElementById('language' + newsid).value;

	switch(action){
		case 'new':
			document.location.href = 'index.php?module=manager&act=manage_news&act_type=add_translation&pathid=' + pathid + '&newsid=' + newsid;
			break;
		case 'edit':
			document.location.href = 'index.php?module=manager&act=manage_news&act_type=editNews&pathid=' + pathid + '&newsid=' + newsid + '&language=' + language;
			break;
		case 'delete':
			deleteNews(newsid, pathid, strDelete, 'confirm_delete_traduction', language);
			break;
	} 
}

function manianewsAction(pathid, newsid, strDelete){
	var action = document.getElementById('action' + newsid).value;
	var language = document.getElementById('language' + newsid).value;

	switch(action){
		case 'new':
			document.location.href = 'index.php?module=manager&act=manage_manianews&act_type=add_translation&pathid=' + pathid + '&newsid=' + newsid;
			break;
		case 'edit':
			document.location.href = 'index.php?module=manager&act=manage_manianews&act_type=editNews&pathid=' + pathid + '&newsid=' + newsid + '&language=' + language;
			break;
		case 'delete':
			deleteManiaNews(newsid, pathid, strDelete, 'confirm_delete_traduction', language);
			break;
	} 
}

function deleteNews(newsid, pathid, str, action, lng){
	if(lng != null)
		str += ' (' + lng + ')'
	if(confirm(str))
  		location.href= '?module=manager&act=manage_news&do=' + action + '&pathid=' + pathid + '&newsid=' + newsid + '&lng=' + lng;
}

function deleteManiaNews(newsid, pathid, str, action, lng){
	if(lng != null)
		str += ' (' + lng + ')'
	if(confirm(str))
  		location.href= '?module=manager&act=manage_manianews&do=' + action + '&pathid=' + pathid + '&newsid=' + newsid + '&lng=' + lng;
}

function moveManiaNews(newsid, pathid, str, action){
	if(confirm(str))
  		location.href= '?module=manager&act=manage_manianews&do=' + action + '&pathid=' + pathid + '&newsid=' + newsid;
}



function deleteModeratorsCandidates(pathid, str){
	if(confirm(str))
		location.href = '?module=manager&act=moderator_election&do=deleteAllCandidates&pathid=' + pathid;
}


function deleteCandidate(pathid, login, str){
	if(confirm(str))
		location.href = '?module=manager&act=moderator_election&do=deleteCandidate&login=' + login + '&pathid=' + pathid;
}


function deleteNewsFeed(pathid, newsFeedId, str){
	if(confirm(str))
		location.href = '?module=manager&act=manage_news&do=deleteNewsFeed&id=' + newsFeedId + '&pathid=' + pathid;
}

function quitGroup(pathid, str){
	if(confirm(str))
		location.href = '?module=groups&act=quitGroup&id=' + pathid;
}


function disablePath(){
	var rootLeague = document.getElementById("rootLeague");
	var path = document.getElementById("path");
	var lblPath = document.getElementById("lblPath");
	
	if(rootLeague.checked == true){
		path.disabled = true;
		lblPath.style.color = '#CCCCCC';
		lblPath.style.cursor = 'default';
	}else{
		path.disabled = false;
		lblPath.style.color = '#000000';
		lblPath.style.cursor = 'pointer';
	}
}


function disableDate(){
	var day = document.getElementById("day");
	var month = document.getElementById("month");
	var year = document.getElementById("year");
	var bOpen = document.getElementById("open");
	var bClose = document.getElementById("close");
	
	if(bOpen.checked == true){
		day.disabled = false;
		month.disabled = false;
		year.disabled = false;
	}else{
		day.disabled = true;
		month.disabled = true;
		year.disabled = true;
	}
}


function afficherResultats(obj) {
    var tabResult = obj.responseText;
	with(document.getElementById('zoneResultats').style) {
		visibility = 'visible';
	};
    document.getElementById('zoneResultats').innerHTML = tabResult;
}


function loadData() {
     var XHR = new XHRConnection();
	 with(document.getElementById('zoneResultats').style) {
		visibility = 'visible';
	 };
	 with(document.getElementById('zoneInfos').style) {
		visibility = 'hidden';
	};
	 document.getElementById('zoneResultats').innerHTML = '<p>Searching...</p>';
	 
	 XHR.appendData("module", "players");
     XHR.appendData("search", document.getElementById('search').value);
     XHR.sendAndLoad("index.php", "GET", afficherResultats);
}


function showPlayerInfos(obj) {
	var tabResult = obj.responseText;
	with(document.getElementById('zoneInfos').style) {
		visibility = 'visible';
	};
    document.getElementById('zoneInfos').innerHTML = tabResult;	 
}


function loadPlayerInfos(playerLogin){
	var XHR = new XHRConnection();
	 with(document.getElementById('zoneInfos').style) {
		visibility = 'visible';
	 };
	 document.getElementById('zoneInfos').innerHTML = '<p>Loading...</p>';
	 
	 XHR.appendData("module", "players");
     XHR.appendData("playerlogin", playerLogin);
     XHR.sendAndLoad("index.php", "GET", showPlayerInfos);
}

window.onload=montre;
function montre(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
}
