
    
	var logged = false;
	var loggedon = false;
	
    function enableTaskBoxes()
    {
		controls = document.getElementsByName('taskBox');
		for(i = 0; i < controls.length; i++)
			controls[i].style.display = 'block';
	}
	
    function toggleElement(e)
    {
        if(document.getElementById(e+"_desc").style.display == "none")
        {
            document.getElementById(e+"_desc").style.display = "block";
            document.getElementById(e+'_toggle').src = "images/minus.gif";
        }
        else
        {
            document.getElementById(e+"_desc").style.display = "none";
			document.getElementById(e+'_toggle').src = "images/plus.gif";
		}
    }
    
    var origContent = new Array();
    function modifyDesc(e)
    {
		if(logged)
		{
			var content = document.getElementById(e+'_desc_content').innerHTML;
			content = content.replace("Description : ","");
			origContent[e] = content;
			while(content.search('<br>') != -1)
				content = content.replace("<br>","\n");
			
			document.getElementById(e+'_desc').innerHTML = '<textarea rows="2" style="width:70%;" id="modifdesc_'+e+'" ondblclick="valid_modif('+e+');">'+content+'</textarea><div style="float:right"><a class="button" onclick="valid_modif('+e+');">Valider</a> <a class="button" onclick="cancelEdit('+e+');">Annuler</a></div>';
		}
	}
	
	function cancelEdit(e)
	{
		document.getElementById(e+'_desc').innerHTML = '<div style="float:right;font-size:small"><a onclick="modifyDesc('+e+');" class="button">Modifier</a> <a onclick="deleteTask('+e+');" class="button">Supprimer</a></div><div id="'+e+'_desc_content"  ondblclick="modifyDesc('+e+');">Description : '+origContent[e]+'</div>';
	}
	
	function removeTextArea(e,text)
	{
		document.getElementById(e+'_desc').innerHTML = '<div style="float:right;font-size:small"><a onclick="modifyDesc('+e+');" class="button">Modifier</a> <a onclick="deleteTask('+e+');" class="button">Supprimer</a></div><div id="'+e+'_desc_content"  ondblclick="modifyDesc('+e+');">Description : '+text+'</div>';
	}
	
	function valid_modif(e)
	{
		if(logged)
		{
			document.getElementById('loading').style.display = 'block';
			var content = document.getElementById('modifdesc_'+e).value;
			var DSLScript = document.createElement("script");
			DSLScript.src  = 'ajax/ajax_todo.php?action=modifytask&user='+logged+'&id='+e+'&content='+encodeURIComponent(content)+'';
			DSLScript.type = "text/javascript";
			document.body.appendChild(DSLScript);
		}
	}
	
	function login()
	{
		document.getElementById('loading').style.display = 'block';
		var cookie = document.getElementById('cookie').checked;
		var login = document.getElementById('login').value;
		var password = document.getElementById('password').value;
		var DSLScript = document.createElement("script");
		DSLScript.src  = 'ajax/ajax_todo.php?action=login&login='+login+'&password='+password+'&cookie='+cookie+'';
		DSLScript.type = "text/javascript";
		document.body.appendChild(DSLScript);
	}
	
	function disconnect()
	{
		document.getElementById('loading').style.display = 'block';
		var DSLScript = document.createElement("script");
		DSLScript.src  = 'ajax/ajax_todo.php?action=disconnect';
		DSLScript.type = "text/javascript";
		document.body.appendChild(DSLScript);
	}
	
	function removeTask(e)
	{
		var node = document.getElementById(e+"_glob");
		var parent = node.parentNode;
		parent.removeChild(node);
	}
	
	function deleteTask(e)
	{
		if(logged)
		{
			var rep = confirm("Supprimer ?");
			if(rep)
			{
				document.getElementById('loading').style.display = 'block';
				var login = document.getElementById('login').value;
				var password = document.getElementById('password').value;
				var DSLScript = document.createElement("script");
				DSLScript.src  = 'ajax/ajax_todo.php?action=delete&user='+logged+'&id='+e+'';
				DSLScript.type = "text/javascript";
				document.body.appendChild(DSLScript);
			}
		}
	}
	
	function newTask(type)
	{
		if(type)
		{
			if(type == 'bug')
				typetext = '[Bug]';
			else if(type == 'idea')
				typetext = '[Idée]';
			else
				typetext = '[Autre]';
		}
		else
			typetext = '';
		var title = prompt("Entrez un nom pour la tâche",typetext+'Nouvelle tâche');
		if(title)
		{
			var desc = prompt("Entrez une description claire");
			if(desc)
			{
				var DSLScript = document.createElement("script");
				DSLScript.src  = 'ajax/ajax_todo.php?action=newtask&title='+title+'&desc='+desc+'';
				DSLScript.type = "text/javascript";
				document.body.appendChild(DSLScript);
			}
		}
	}
	
	function modifyProgress(e)
	{
		if(logged)
		{
			var oldprogress = document.getElementById(e+'_progresstextp').innerHTML;
			var progress = prompt("Entrez la nouvelle progression de la tâche", oldprogress);
			if(progress)
			{
				var DSLScript = document.createElement("script");
				DSLScript.src  = 'ajax/ajax_todo.php?action=progress&user='+logged+'&id='+e+'&newprogress='+progress+'';
				DSLScript.type = "text/javascript";
				document.body.appendChild(DSLScript);
			}
		}
	}
	
	function setProgress(e,p)
	{
		document.getElementById(e+'_progress').style.width = p+'%';
		document.getElementById(e+'_progresstextp').innerHTML = p+'';
		if(p == 0)
			document.getElementById(e+'_title').style.color = '#ff0000';
		else if(p == 100)
			document.getElementById(e+'_title').style.color = '#00aa00';
		else
			document.getElementById(e+'_title').style.color = '#ff7000';
	}
	
	function modifyTitle(e)
	{
		if(logged)
		{
			var oldtitle = document.getElementById(e+'_title').innerHTML;
			var title = prompt("Entrez le nouveau titre de la tâche", oldtitle);
			if(title)
			{
				var DSLScript = document.createElement("script");
				DSLScript.src  = 'ajax/ajax_todo.php?action=title&user='+logged+'&id='+e+'&title='+encodeURIComponent(title)+'';
				DSLScript.type = "text/javascript";
				document.body.appendChild(DSLScript);
			}
		}
	}
	
	function setTitle(e,t)
	{
		document.getElementById(e+'_title').innerHTML = t;
	}
	
	function modifyType(e,oldtype)
	{
		if(logged)
		{
			if(oldtype == 1)
				oldtype = 'Bug';
			else if(oldtype == 2)
				oldtype = 'Idée';
			else
				oldtype = 'Autre';
				
			var type = prompt("Entrez le nouveau type", oldtype);
			
			if(type)
			{
				if(type.toLowerCase() == 'bug')
					type = 1;
				else if(type.toLowerCase() == 'idée' || type.toLowerCase() == 'amélioration')
					type = 2;
				else
					type = 0;
				
				var DSLScript = document.createElement("script");
				DSLScript.src  = 'ajax/ajax_todo.php?action=type&user='+logged+'&id='+e+'&type='+type+'';
				DSLScript.type = "text/javascript";
				document.body.appendChild(DSLScript);
			}
		}
	}
	
	function setIcon(e,i)
	{
		var file = 'images/unknown.png';
		if(i == 1)
			file = 'images/bug.png';
		else if(i == 2)
			file = 'images/idea.png';
		document.getElementById(e+'_icon').src = file;
	}

