/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                          INIZIALIZZAZIONE AJAX                                                          *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
// NOTA AGLI SCRIPT AJAX : Il post non funziona con mozilla

//VAR GLOBALI PER SCRIPTS AJAX
var chiamaPagina = null;

// Creo un oggetto XMLHttpRequest che fa richieste http in background
function creaXMLHttpRequest(eventoAjax) { 
	var xmlhttp = null;

	if(window.ActiveXObject) { // IE < v.7
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest) { // Mozilla, Firefox, Safari, Netscape, IE7
		xmlhttp = new XMLHttpRequest();
	}

	if(xmlhttp) {
		xmlhttp.onreadystatechange = eventoAjax;
		return xmlhttp;
	}		
}


var globalDivDescr = "";




/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                             SPOSTA DOCUMENTI                                                            *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
function doMove() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		window.location.reload();
	}
}

function spostaDocumenti(idel) {

	var arrDocumenti = new Array();
	
	var url = "../controls/comandi.php";
	var idSezione = document.getElementById(["sezione" + idel]).value;
	var contadoc = document.getElementById(["contadocs_" + idel]).value;
	
	for(var i=0; i<contadoc; i++) {
		iddoc = document.getElementById(["movedoc_" + idel + "_" + i]).value;
		elcheck = document.getElementById(["movedoc_" + idel + "_" + i]).checked;

		if(elcheck) { //Inserisco l'elemento nell'array se non c'era gi�
			arrDocumenti.push(iddoc);
		}
	}	
	
	if(arrDocumenti.length > 0) {
		
		chiamaPagina = creaXMLHttpRequest(doMove);
		//window.open(url + "?_idel=" + idel + "&_idsez=" + idSezione + "&_eledocs=" + listaDoc + "&cmd=docs_move&rand=" + escape(Math.random()), "get");
		chiamaPagina.open("GET", url + "?_idel=" + idel + "&_idsez=" + idSezione + "&_eledocs=" + arrDocumenti + "&cmd=docs_move&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
	else {
		alert(genNoDocsMove);	
		document.getElementById(["sezione" + idel]).selectedIndex = 0;
	}
}


/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                                ALLEGATI                                                                 *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
function aggiornaDescrizione() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		var descr = chiamaPagina.responseText;
		document.getElementById([globalDivDescr]).innerHTML = descr;	
	}
}

function salvaDescrizione(tipoallegato, id) {

	var url = "../controls/comandi.php";
	var idall = document.getElementById([tipoallegato + "_idall_" + id]).value;
	var descr = document.getElementById([tipoallegato + "_txtdescr_" + id]).value;
	globalDivDescr = tipoallegato + "_divdescr_" + id;

	document.getElementById([tipoallegato + "_loading_" + id]).style.display = "";
	document.getElementById([tipoallegato + "_textarea_" + id]).style.display = "none";	
	chiamaPagina = creaXMLHttpRequest(aggiornaDescrizione);
	//window.open(url + "?cmd=all_descr&_idall=" + idall + "&dsc=" + descr + "&tipoall=" + tipoallegato + "&cicla=" + id + "&rand=" + escape(Math.random()), "get");
	chiamaPagina.open("GET", url + "?cmd=all_descr&_idall=" + idall + "&dsc=" + descr + "&tipoall=" + tipoallegato + "&cicla=" + id + "&rand=" + escape(Math.random()));	
	chiamaPagina.send(null);
}


function aggiornaElencoAllegati() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		var result = chiamaPagina.responseText;
		document.getElementById([globalDivDescr]).innerHTML = result;
	}
}

function eliminaAllegati(idel, idcont, tipoAllegato, nomediv) {
	var arrAllegati = new Array();
	var url = "../controls/comandi.php";
	var contaAllegati = document.getElementById(["conta_" + tipoAllegato]).value;
	
	globalDivDescr = nomediv;
	//globalDivDescr = "div_" + tipoAllegato;
	
	document.getElementById(["del_loading_" + tipoAllegato]).style.display = "none";	
	document.getElementById(["del_" + tipoAllegato]).style.display = "";		
	
	for(var i=1; i<parseInt(contaAllegati)+1; i++) {
		idall = document.getElementById([tipoAllegato + "_idall_" + i]).value;
		check = document.getElementById([tipoAllegato + "_del_all_" + i]).checked;
		
		if(check) { //Inserisco l'elemento nell'array se non c'era già
			arrAllegati.push(idall);
		}
	}	

	if(arrAllegati.length > 0) {
		chiamaPagina = creaXMLHttpRequest(aggiornaElencoAllegati);
		//window.open(url + "?cmd=all_del&_idel=" + idel + "&_idcont=" + idcont + "&_eleall=" + arrAllegati + "&tipoall=" + tipoAllegato + "&rand=" + escape(Math.random()), "get");
		chiamaPagina.open("GET", url + "?cmd=all_del&_idel=" + idel + "&_idcont=" + idcont + "&_eleall=" + arrAllegati + "&tipoall=" + tipoAllegato + "&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
	else {
		alert(genNoAllDel);	
	}
}





/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                                  ACCOUNT                                                                *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
function aggiornaMail() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		var descr = chiamaPagina.responseText;
		document.getElementById([globalDivDescr]).innerHTML = descr;	
		mail = document.getElementById(["mail"]).focus();
	}
}

function verificaMail(codutente) {

	var url = "../controls/comandi.php";
	globalDivDescr = "divmailutente";

	document.getElementById(["testoverifica"]).value = "";
	mail = document.getElementById(["mail"]).value;
	oldmail = document.getElementById(["oldmail"]).value;	

	if(mail != ""){
		if(controllaMail(mail)) {
			chiamaPagina = creaXMLHttpRequest(aggiornaMail);
			//window.open(url + "?cmd=verificamail&_mail=" + mail + "&_oldmail=" + oldmail + "&codutente=" + codutente +"&rand=" + escape(Math.random()), "get");
			chiamaPagina.open("GET", url + "?cmd=verificamail&mail=" + mail + "&oldmail=" + oldmail + "&codutente=" + codutente +"&rand=" + escape(Math.random()));	
			chiamaPagina.send(null);
		}
	}
	else {
		alert("Inserire un indirizzo mail");
	}
}

/*
function esitoCambioFoto() {
	//alert('../public/users_foto/' + chiamaPagina.responseText);
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		if (gloabalDiv == "fotoelement") { // Immagine elemento
			document.getElementById(["img_" + gloabalDiv]).src='../public/element_images/' + chiamaPagina.responseText;
		}
		else if (gloabalDiv == "fotoaccount") { // Foto account
			document.getElementById(["img_" + gloabalDiv]).src='../public/users_foto/' + chiamaPagina.responseText;		
		}
		document.getElementById(["dv_" + gloabalDiv]).style.display = "none";
		// Manca aggiornamento icone div "dv_" + gloabalFotoAccount;
	}
}

/* NON USASTO  * /
function caricaFoto(elemento) {

	var url = "../controls/comandi.php";
	gloabalDiv = elemento;
	var foto = document.getElementById([elemento]).value;

	if(foto == "") {
		alert("Non e' stato scelto alcun file da caricare");
		return false;
	}
	else {
		if (elemento == "fotoelement") { // Immagine elemento
			chiamaPagina = creaXMLHttpRequest(esitoCambioFoto);
			window.open(url + "?_foto=" + foto + "&cmd=el_foto&rand=" + escape(Math.random()), "get");
			//chiamaPagina.open("GET", url + "?_foto=" + foto + "&cmd=account_foto&rand=" + escape(Math.random()));
		}
		else if (elemento == "fotoaccount") { // Foto account
			chiamaPagina = creaXMLHttpRequest(esitoCambioFoto);
			window.open(url + "?_foto=" + foto + "&cmd=account_foto&rand=" + escape(Math.random()), "get");
			//chiamaPagina.open("GET", url + "?_foto=" + foto + "&cmd=account_foto&rand=" + escape(Math.random()));
		
		}
		chiamaPagina.send(null);
	}
}


function selFoto(elemento,id) {

	var url = "../controls/comandi.php";
	gloabalDiv = elemento;

	if(id == "") {
		alert("Non è stato selezionato alun file");
		return false;
	}
	else {
		chiamaPagina = creaXMLHttpRequest(esitoCambioFoto);
		//window.open(url + "?_foto=" + foto + "&cmd=account_selfoto&rand=" + escape(Math.random()), "get");
		chiamaPagina.open("GET", url + "?_foto=" + id + "&cmd=account_selfoto&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
}
*/

/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                        MODIFICA PASSWORD ACCOUNT                                                        *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
function boxPwd(elemento) {
	var popup = document.getElementById([elemento]);

	document.getElementById(["pwd1"]).value='';
	document.getElementById(["pwd2"]).value='';
	popup.style.display == 'none' ? popup.style.display='' : popup.style.display='none';
}

function esitoCambioPwd() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		document.getElementById(["dv_pwd"]).style.border='1px solid #ccc';
		document.getElementById(["dv_pwd"]).style.padding='0.5em';		
		document.getElementById(["dv_pwd"]).style.color='#f00';		
		document.getElementById(["dv_pwd"]).innerHTML=chiamaPagina.responseText;
	}
}

function cambiaPwd(pwd1,pwd2,codutente) {

	var url = "../controls/comandi.php";
	//var pass1 = document.getElementById([pwd1]).value;
	//var pass2 = document.getElementById([pwd2]).value;
	
	if(pwd1 == "" || pwd2 == "") {
		alert("Non è stata inserita alcuna password");
		return false;
	}
	else if(pwd1 != pwd2) {
		alert("Attenzione, le due password non coincidono");
		return false;
	}

	else {
		chiamaPagina = creaXMLHttpRequest(esitoCambioPwd);
		chiamaPagina.open("GET", url + "?_pwd=" + pwd1 + "&codutente=" + codutente + "&cmd=account_pwd&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
}


/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                               GRUPPI UTENTI                                                             *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
function aggiungiUtenti(IdGruppo, IdMacroProfilo, IdAzione, azione, sizeSelect) {

	var url = "../controls/comandi.php";
	var listautenti_ins = "";
	var listautenti_del = "";
	
	if(azione == "ins") {
		arrayvalori = document.getElementById(["utenti_presenti[]"]);
			
		for (var i=0; i<arrayvalori.length; i++) {
			if(arrayvalori[i].selected == true) {
				listautenti_ins = listautenti_ins != "" ? listautenti_ins + "," + arrayvalori[i].value : listautenti_ins + arrayvalori[i].value;
				 // alert(arrayvalori[i].value);
			}
		}
		// alert(listautenti_ins);
	}
	else { //Tolgo
		arrayvalori = document.getElementById(["utenti_inseriti[]"]);
		
		for (var i=0; i<arrayvalori.length; i++) {
			if(arrayvalori[i].selected == true) {
				listautenti_del = listautenti_del != "" ? listautenti_del + "," + arrayvalori[i].value : listautenti_del + arrayvalori[i].value;
				 // alert(arrayvalori[i].value);
			}
		}
	}
	//alert(listautenti_ins);
	//alert(listautenti_del);
		
	if (listautenti_ins != "" || listautenti_del != "") {
		chiamaPagina = creaXMLHttpRequest(aggiornaBoxUtenti);
		//window.open(url + "?cmd=group_insutenti&_akt=" + azione + "&_idaz=" + IdAzione + "&_idgroup=" + IdGruppo + "&_idliv=" + IdMacroProfilo + "&_lins=" + listautenti_ins + "&_ldel=" + listautenti_del + "&_ss=" + sizeSelect + "&rand=" + escape(Math.random()), "get");
		chiamaPagina.open("GET", url + "?cmd=group_insutenti&_akt=" + azione + "&_idaz=" + IdAzione + "&_idgroup=" + IdGruppo + "&_idliv=" + IdMacroProfilo + "&_lins=" + listautenti_ins + "&_ldel=" + listautenti_del + "&_ss=" + sizeSelect + "&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}

}

function aggiornaBoxUtenti() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		//alert(chiamaPagina.responseText);
		document.getElementById(["responseAjax"]).innerHTML=chiamaPagina.responseText;
	}
}




/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                                  UTENTI                                                                 *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
function caricaElencoUtenti(nometabella,cmdPag) {
		
	var url = "../controls/comandi.php";
	globalDivDescr = "div_elencoutenti";
	var arrCampi = new Array('cognome','nome','mail','telefono','fax','cell','indirizzo','cap','citta','prov','idanag','userid', 'pwd1', 'pwd2');
	if (nometabella != "") { //Nessuna tab anagrafica
		for(var x=0; x<arrCampi.length; x++) {
			if(nometabella == '000') {
				document.getElementById([arrCampi[x]]).readOnly = false;
				document.getElementById([arrCampi[x]]).value = '';
				document.getElementById([arrCampi[x]]).style.backgroundColor = '#fff';
				document.getElementById([arrCampi[x]]).style.border = '1px solid #ccc';				
				document.getElementById([arrCampi[x]]).className = 'bordoPiatto';				
			}
			else {
				document.getElementById([arrCampi[x]]).readOnly = true;
				document.getElementById([arrCampi[x]]).className = 'readonly';
			}
		}

		chiamaPagina = creaXMLHttpRequest(inserisciUtente);
		//window.open(url + "?cmd=utente_id&tab=" + nometabella + "&rand=" + escape(Math.random()), "get");
		chiamaPagina.open("GET", url + "?cmd=utente_elenco&tab=" + nometabella + "&cmdPag=" + cmdPag + "&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
}

function inserisciUtente() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		var codiceutente = chiamaPagina.responseText;
		document.getElementById([globalDivDescr]).innerHTML = codiceutente;	
	}
}


function scaricaCodiceUtente(valore) {
	alert(valore);
}

/*******************************************************************************************************************************************/
function asseganDatiUtente(nometabella,idanagrafica) {

	var url = "../controls/comandi.php";
	globalDivDescr = "datiutente";

	if (nometabella != "") {
		chiamaPagina = creaXMLHttpRequest(mostraDatiUtente);
		//window.open(url + "?cmd=utente_id&tab=" + nometabella + "&rand=" + escape(Math.random()), "get");
		chiamaPagina.open("GET", url + "?cmd=utente_dati&tab=" + nometabella + "&_idanag=" + idanagrafica + "&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
}

function mostraDatiUtente() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		var datiutente = chiamaPagina.responseText;
		document.getElementById([globalDivDescr]).innerHTML = datiutente;	
	}
}
/*******************************************************************************************************************************************/

function OLD_mostraDatiUtente(tabella,idanagrafica) {

	var url = "../controls/comandi.php";
	globalDivDescr = "div_elencoutenti";

	if (idanagrafica != "") {
		chiamaPagina = creaXMLHttpRequest(asseganDatiUtente);
		//window.open(url + "?cmd=utente_id&tab=" + nometabella + "&rand=" + escape(Math.random()), "get");
		chiamaPagina.open("GET", url + "?cmd=utente_mostra&tab=" + tabella + "&_idanag=" + idanagrafica + "&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
}


function caricaCodiceUtente(stringa) {
	var arrPosizioni = new Array();
	
		//alert(stringa);
		
		//Metto in un array le posizioni delle |
		pos = 0;		
		for(var i=0;i<stringa.length;i++){
			if(stringa.substr(i,1) == "|") {
				valore = stringa.substring(pos, i-1);
				pos = i+2;
				//Nome, Cognome, Email, idanagrafica
				arrPosizioni.push(valore);
			}
		}
		
		cognome = arrPosizioni[0];
		nome = arrPosizioni[1];
		mail = arrPosizioni[2];
		userid = arrPosizioni[2];
		idanag = arrPosizioni[3];
		
		document.getElementById(["userid"]).value = userid;
		
		var arrNomiCampidaQuery = new Array('nome','cognome','mail','idanag');
		var arrNomiCampiAltri = new Array('telefono','fax','cell','indirizzo','cap','citta','prov','userid','pwd1','pwd2');		
		
		for(var x=0; x<arrNomiCampidaQuery.length; x++) {
			if(arrPosizioni[x] == "") {
				document.getElementById([arrNomiCampidaQuery[x]]).readOnly = false;
				document.getElementById([arrNomiCampidaQuery[x]]).className = '';
			}
			else {
				document.getElementById([arrNomiCampidaQuery[x]]).readOnly = true;
				document.getElementById([arrNomiCampidaQuery[x]]).className = 'readonly';
			}
		}

		for(var x=0; x<arrNomiCampiAltri.length; x++) {
			if(document.getElementById([arrNomiCampiAltri[x]]).value == "") {
				document.getElementById([arrNomiCampiAltri[x]]).readOnly = false;
				document.getElementById([arrNomiCampiAltri[x]]).className = '';
			}
			else {
				document.getElementById([arrNomiCampiAltri[x]]).readOnly = true;
				document.getElementById([arrNomiCampiAltri[x]]).className = 'readonly';
			}
		}



		//Tolgo gli spazi tra le |. La ricerca inizia dalla fine della stringa!
		//idanagrafica = stringa.substring(0, arrPosizioni[0]-1);		
		
		//cognome = stringa.substring(arrPosizioni[0]+2, arrPosizioni[1]-1);
		//nome = stringa.substring(arrPosizioni[1]+2, arrPosizioni[2]-1);
		//mail = stringa.substring(arrPosizioni[2]+2, arrPosizioni[3]-1);				
		//telefono = stringa.substring(arrPosizioni[3]+2, arrPosizioni[4]-1);
		//fax = stringa.substring(arrPosizioni[4]+2, arrPosizioni[5]-1);				
		//cellulare = stringa.substring(arrPosizioni[5]+2, arrPosizioni[6]-1);
		//indirizzo = stringa.substring(arrPosizioni[6]+2, arrPosizioni[7]-1);
		//cap = stringa.substring(arrPosizioni[7]+2);				
		/*
		citta = stringa.substring(arrPosizioni[7]+2, arrPosizioni[9]-1);		
		prov = stringa.substring(arrPosizioni[10]+2, arrPosizioni[11]-1);						
		*/


		document.getElementById(["cognome"]).value = cognome;	
		document.getElementById(["nome"]).value = nome;	
		document.getElementById(["mail"]).value = mail;					
		document.getElementById(["idanag"]).value = idanag;							
	/*
		document.getElementById(["telefono"]).value = telefono;					
		document.getElementById(["fax"]).value = fax;					
		document.getElementById(["cell"]).value = cellulare;					
		document.getElementById(["indirizzo"]).value = indirizzo;					
		document.getElementById(["cap"]).value = cap;
		document.getElementById(["citta"]).value = citta;															
		document.getElementById(["prov"]).value = prov;									
		document.getElementById(["idanag"]).value = idanagrafica;							
		document.getElementById(["userid"]).value = userid;
	*/
}


/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                        CONTATTA AUTORI DOCUMENTI                                                        *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
var gloabalDivID = "";
var urlimg = "layout/icons/";

function statoBusta(indice, codUtente) {
	var icona = "";
	var busta = document.getElementById(["busta_" + indice + "_" + codUtente]).src;
	var boxMex = document.getElementById(["mail_" + indice + "_" + codUtente]);
	
	busta.substr(busta.lastIndexOf("/")+1, busta.length) == "mail_closed.jpg" ? icona = "mail_open.jpg" : icona = "mail_closed.jpg";
	boxMex.style.display == 'none' ? boxMex.style.display='' : boxMex.style.display='none';
	document.getElementById(["busta_" + indice + "_" + codUtente]).src = urlimg + icona;							
}

function pulisciBoxAut(cicla,CodUtente) {
	
	var textarea = "<textarea cols='6' rows='8' id='txt_" + cicla + "_" + CodUtente + "' style='width:90%'></textarea><br>";
	textarea = textarea + "<input type='hidden' id='user_" + cicla + "_" + CodUtente + "' value='" + CodUtente + "'>";
	textarea = textarea + "<img src='layout/btn_invia.jpg' alt='Spedisci' title='Spedisci' class='imgMid' onClick='return contattaReferente(" + cicla + "," + CodUtente + ")'>";
	
	document.getElementById(["mail_" + gloabalDivID]).style.border='0';
	document.getElementById(["mail_" + gloabalDivID]).style.padding='0';		
	document.getElementById(["mail_" + gloabalDivID]).style.color='#000';	
	document.getElementById(["busta_" + cicla + "_" + CodUtente]).src = urlimg + "mail_closed.jpg";								
	document.getElementById(["mail_" + gloabalDivID]).innerHTML=textarea;
	document.getElementById(["mail_" + gloabalDivID]).style.display='none';
	
}


function esitoContatto() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		document.getElementById(["mail_" + gloabalDivID]).style.border='1px solid #ccc';
		document.getElementById(["mail_" + gloabalDivID]).style.padding='0.5em';		
		document.getElementById(["mail_" + gloabalDivID]).style.color='#f00';		
		document.getElementById(["txt_" + gloabalDivID]).display='none';		
		document.getElementById(["busta_" + gloabalDivID]).src = "layout/icons/mail_closed.jpg";
		document.getElementById(["mail_" + gloabalDivID]).innerHTML=chiamaPagina.responseText;
	}
}

function contattaAutore(indice, codUtente) {

	var url = "controls/comandi.php";
	var descr = document.getElementById(["txt_" + indice + "_" + codUtente]).value;
	var mex = document.getElementById(["txt_" + indice + "_" + codUtente]).value;
		
	gloabalDivID = indice + "_" + codUtente;
	
	if(mex == "") {
		alert("Nessun messaggio lasciato");
		return false;
	}	
	else {	
		chiamaPagina = creaXMLHttpRequest(esitoContatto);
		chiamaPagina.open("GET", url + "?cmd=mexaut&_userid=" + codUtente + "&_mex=" + descr + "&_cicla= " + indice + "&_nomediv=" + gloabalDivID + "&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
}


/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                        AGGIUNGI OGGETTI FORM                                                        *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
function creaCampi() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		document.getElementById(["campi_oggetto"]).style.backgroundColor="#ececec";
		document.getElementById(["campi_oggetto"]).innerHTML=chiamaPagina.responseText;
	}
}

function aggiungiElementi(idform,numero) {

	var url = "../controls/comandi.php";
	//var pass1 = document.getElementById([pwd1]).value;
	//var pass2 = document.getElementById([pwd2]).value;
	
	if(isNaN(numero)) {
		alert("Il campo deve contenere un numero");
		return false;
	}
	else {
		chiamaPagina = creaXMLHttpRequest(creaCampi);
		chiamaPagina.open("GET", url + "?idform=" + idform + "&numero=" + numero + "&cmd=oggettiform&rand=" + escape(Math.random()));
		chiamaPagina.send(null);
	}
}





/*
*******************************************************************************************************************************************
*                                                                                                                                         *
*                                                                PAGINAZIONE                                                              *
*                                                                                                                                         *
*******************************************************************************************************************************************
*/
function scriviPaginazione() {
	if(chiamaPagina.readyState == 4 && chiamaPagina.status == 200) {
		document.getElementById(["cls_paginazione"]).innerHTML = "";
//		document.getElementById(["cls_paginazione"]).style.height = "0px";
//		document.getElementById(["cls_paginazione"]).style.width = "0px";				
		document.getElementById(["cls_paginazione"]).display='none';
		document.getElementById(["allegati"]).innerHTML = "";
		document.getElementById(["allegati"]).innerHTML = chiamaPagina.responseText;
	}
}

function paginazioneAjax(idelemento,idcontenuto,begin,recperpag,href) {
	
	var url = "../controls/comandi.php";
	var cmd = "pagajax";

	chiamaPagina = creaXMLHttpRequest(scriviPaginazione);
	//window.open(url + "?cmd=" + cmd + "&_idel=" + idelemento + "&_idcont=" + idcontenuto + "&_begin=" + begin + "&_recperpag=" + recperpag + "&_uri=" + href + "&rand=" + escape(Math.random()), "get");
	chiamaPagina.open("GET", url + "?cmd=" + cmd + "&_idel=" + idelemento + "&_idcont=" + idcontenuto + "&_begin=" + begin + "&_quanti=" + recperpag + "&_uri=" + href + "&rand=" + escape(Math.random()), "GET");
	chiamaPagina.send(null);
}	
