/**
 * @author francesco
 */
var destination_elm = new String();

function lista_elementi()
{
	var parametri = "operazione=listafile";

	destination_elm = "lista_elementi";
	loadingGIF(document.getElementById(destination_elm));
	makeRequest("include_amministrazione/php/contributo.php", handleGenericResponse, "POST", parametri);
}

function handleGenericResponse()
{
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{
			document.getElementById(destination_elm).innerHTML = xmlhttp.responseText;
		}
		else
		{
			var contentHTML = "<b>Errore durante il trasferimento dati.</b>";
			contentHTML += "<br />Stato : " + xmlhttp.status;
			document.getElementById("content").innerHTML = contentHTML;
		}
	}
}

// Inizio classe Elemento
function Elemento(nome, istanza)
{
	this.nome = nome;
	this.istanza = istanza;

	this.carica = function(id)
	{
		var parametri = "operazione=carica&id_" + this.istanza + "=" + id + "&";
		parametri += "&istanza=" + this.istanza + "&nome=" + this.nome;

		destination_elm = "box_" + this.istanza;
		loadingGIF(document.getElementById(destination_elm));
		makeRequest("include_amministrazione/php/elemento.php", this.handlePhpResponse, "POST", parametri);
	}

	this.cancella = function(id)
	{
		if (confirm("Vuoi davvero eliminare questo elemento ?"))
			this.conf_cancella(id);
	}

	this.conf_cancella = function(id)
	{
		var parametri = "operazione=cancella&id_" + this.istanza + "=" + id + "&";
		parametri += "&istanza=" + this.istanza + "&nome=" + this.nome;

		destination_elm = "box_" + this.istanza;
		loadingGIF(document.getElementById(destination_elm));
		makeRequest("include_amministrazione/php/elemento.php", this.handlePhpResponse, "POST", parametri);
	}

	this.inviaFile = function()
	{
		document.getElementById("invia_btn").value = "Invio in corso ...";
		document.getElementById("edit_file").submit();
	}

	this.handlePhpResponse = function()
	{
		if (xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200)
			{
				document.getElementById(destination_elm).innerHTML = xmlhttp.responseText;
			}
			else
			{
				var contentHTML = "<b>Errore durante il trasferimento dati.</b>";
				contentHTML += "<br />Stato : " + xmlhttp.status;
				document.getElementById("content").innerHTML = contentHTML;
			}
		}
	}
}
