advAJAX.setDefaultParameters({
    url : "ajax.php"
});

function EditPost (Id, Cat)
{
	advAJAX.get(
	{
		parameters :
		{
			"Func" : Cat + "_EditPost",
			"Id"   : Id
		},
		onSuccess  : function(obj)
		{
			document.getElementById("_" + Id).innerHTML = "<textarea class='text' style='width: 90%' id='text_" + Id + "'>" + obj.responseText + "</textarea><br /><input type='button' class='submit' value='Editer' onclick='ValidEditPost (\"" + Id + "\", \"" + Cat + "\")' /> <input type='button' class='submit' value='Annuler' onclick='AnnuleEditPost (\"" + Id + "\", \"" + Cat + "\")' />";
		}
	});
}

function ValidEditPost (Id, Cat)
{
	advAJAX.get(
	{
		parameters :
		{
			"Func" : Cat + "_ValidEditPost",
			"Id"   : Id,
			"Mess" : document.getElementById('text_' + Id).value
		},
		onSuccess  : function(obj)
		{
			document.getElementById("_" + Id).innerHTML = obj.responseText;
		}
	});
}

function AnnuleEditPost (Id, Cat)
{
	advAJAX.get(
	{
		parameters :
		{
			"Func" : Cat + "_AnnuleEditPost",
			"Id"   : Id
		},
		onSuccess  : function(obj)
		{
			document.getElementById("_" + Id).innerHTML = obj.responseText;
		}
	});
}

function DeletePost (Id, Cat)
{
	advAJAX.get(
	{
		parameters :
		{
			"Func" : Cat + "_DeletePost",
			"Id"   : Id
		},
		onSuccess  : function(obj)
		{
            //alert(obj.responseText);
			document.getElementById("row_" + Id).parentNode.removeChild (document.getElementById("row_" + Id));
		}
	});
}

function Prev (Str, NodePrev)
{
	advAJAX.get(
	{
		parameters :
		{
			"Func" : "Prevu",
			"Str"   : Str
		},
		onSuccess : function (obj)
		{
			NodePrev.innerHTML = "<div>" + obj.responseText + "</div>";
		}
	});
}

function ConnectChat (NomNode, FormInterf)
{
    NomNode = document.getElementById('IRCNom');
    FormInterf = document.getElementById('IRCInterf');
    
    if (!NomNode.value.length || !NomNode.value.match(/^[A-Za-z0-9\[\]\{\}^\\\|\_\-`]{1,32}$/))
    {
        alert ("Vous devez indiquer votre nom d'utilisateur.");
        return false;
    }
    
    switch (FormInterf.options[FormInterf.selectedIndex].id)
    {
      case "java6669":
        var Port = 6669;
      break;
      
      default:
        var Port = 6667;
      break;
    }
    
    window.open ("index.php?p=chat&interf=" + FormInterf.value + "&port=" + Port + "&nom=" + NomNode.value,
                 "chat",
                 "width=640,height=480");
    
}

function PopComment (Id)
{
    window.open ("index.php?p=com&id=" + Id,
                 "comment",
                 "width=430,height=480,scrollbars=1");
}
