// JavaScript Document
var debugAJAX=false;



//--------------------------------------------------------------------------------
function ajaxInviaDati(data, url, handlerFunc)
{
  var status = false;
  var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	
	//alert("DATA:"+data+" - URL:"+url+" - HandlerFunc"+handlerFunc)	;
   //istanziamo l'oggetto XMLHttpRequest
  if (window.XMLHttpRequest) 
  {
    req = new XMLHttpRequest();
    //req.onreadystatechange = PocessaDati(handlerFunc);
    req.onreadystatechange = function(){
		 // monitoriamo lo stato dell'invio
		  if (req.readyState == 4)
		  {
		    // restituiamo lo stato della richiesta
		    if (req.status == 200) 
		    {
		      eval(handlerFunc);
		    }else{
		      alert('Problema nella gestione dei dati ' +
		      req.responseText);
		    }
		  }
		
	}
    
    
    
    req.open('POST', 'php/'+url, true);
    req.setRequestHeader('Content-Type', contentType);
	req.send(data);
	status=true;
  }
  // controlliamo la versione di ActiveX
  else if (window.ActiveXObject) 
  {
    req = new ActiveXObject('Microsoft.XMLHTTP')
    if (req)
    {
      req.onreadystatechange =  function(){
		 // monitoriamo lo stato dell'invio
		  if (req.readyState == 4)
		  {
		    // restituiamo lo stato della richiesta
		    if (req.status == 200) 
		    {
		      eval(handlerFunc);
		    }else{
		      alert('Problema nella gestione dei dati ' +
		      req.responseText);
		    }
		  }
		
	};
      req.open('POST', 'php/'+url, true);
      req.setRequestHeader('Content-Type', contentType);
      req.send(data);
      status=true;
    }
  }
  return status;
}
//--------------------------------------------------------------------------------










//--------------------------------------------------------------------------------
// VISUALIZZA LA NUOVA GALLERIA DI IMMAGINI
//--------------------------------------------------------------------------------

// IL DIV CHE ACCOGLIE LA FOTOGALLERY
var idFotoGallery='divFotoGallery';

function newGalleryImg(result)
{
	
	var divFotoGallery = document.getElementById(idFotoGallery);
	
	var arrayImg = result.split("_#_");
	
	
	var ulGallery='';
	
	var n=arrayImg.length-1;
		for(j=n; j >= 0; j--)
		{
		//	alert(n);
			var arrayDatiImg = arrayImg[j].split("_|_");
			
			for(y=0; y <= (arrayDatiImg.length-2); y++)
			{
			//alert(arrayDatiImg[4]);
			
			if(arrayDatiImg[3] =='IMG')
			{
				// LO INSERISCO QUI PER CONCATENARE kwicks+ID_CONT
				var ulGalleryCont='<ul id="kwicks'+arrayDatiImg[4]+'">';
				
				var idCont=arrayDatiImg[4];
				
				ulGallery +='<li class="kwick" id="kwick'+arrayDatiImg[4]+'"><a href=\"dettaglioImg.php?idImg='+arrayDatiImg[2]+'&idCont='+arrayDatiImg[4]+'&css=0" target="_blank"><img   id="img'+arrayDatiImg[2]+'"  title="'+arrayDatiImg[0]+'" src="allegati/img/'+arrayDatiImg[1]+'" /></li>';
			}
			if(arrayDatiImg[3] =='VIDEO')
			{
				ulGallery +='<li class="kwick" id="kwick'+arrayDatiImg[4]+' onclick="ajaxInviaDati(\'idAllegatoCarica='+arrayDatiImg[2]+'\', \'ajax.php\', \'dettaglioImmagine(req.responseText)\'); "><p>'+arrayDatiImg[0]+'</p></li>';
			}
			
			if(arrayDatiImg[3] =='DWNLD')
			{
				ulGallery +='<li class="kwick"  id="kwick'+arrayDatiImg[4]+' ><p><a href="allegati/testo/'+arrayDatiImg[1]+'" target="_blank">'+arrayDatiImg[0]+'</a></p></li>';
			}
			y=y+5;
			}
		
		}
	ulGallery +='</ul> <div id="divRigaBottom" class="divRigaBottom"></div>';
	
	
	
	
	divFotoGallery.innerHTML=ulGalleryCont+ulGallery;
	
	//riattivo le funzioni di fade e di allargamento dell immagine che partono all avvio della pagina
	//newFade();
	
	//inserisco il del contenuto in modo che se si decide di visualizzare una gallery per ogni elemento della pagina
	// si possa fare differenziando tramite idcont
	newLarge("kwicks"+idCont, "kwick"+idCont, "divFotoGallery"+idCont);
	
//____________DEBUG_______________
	if(debugAJAX)
	{
		alert('newGalleryImg ->'+result);
	
		alert('ulGallery ->'+ulGallery);
	}
//________________________________	
}
//--------------------------------------------------------------------------------

//--------------------------------------------------------------------------------
// VISUALIZZA NUOVI COMMENTI
//--------------------------------------------------------------------------------


function newCommenti(result)
{
	
	var ulCommenti = document.getElementById('ulCommenti');
	
	var arrayImg = result.split("_#_");
	
	var ulGallery='<li><h1>COMMENTI</h1></li><li>&nbsp;</li>';
	
	var liGallery='';
	
	
	var n=arrayImg.length-1;
		for(j=n; j >= 0; j--)
		{
		//	alert(n);
			var arrayDatiImg = arrayImg[j].split("_|_");
			
			for(y=0; y <= (arrayDatiImg.length-2); y++)
			{
			

				liGallery ='<li class="liUtenteCommento" ><font>'+arrayDatiImg[4]+'</font>'+arrayDatiImg[1]+'</li><li class=\'liTestoCommento\'>'+arrayDatiImg[3]+'</li ><li class=\'liBarra\'>&nbsp;</li>'+liGallery;
			
			y=y+5;
			}
			
			
			
		}
		
		
	ulGallery +=liGallery+'</ul> <div id="divRigaBottom" class="divRigaBottom"></div>';
	
	
	
	
	ulCommenti.innerHTML=ulGallery;
	
//____________DEBUG_______________
	if(debugAJAX)
	{
		alert('newCommenti ->'+result);
	
		alert('ulCommenti ->'+ulGallery);
	}
//________________________________	
}
//--------------------------------------------------------------------------------


//--------------------------------------------------------------------------------
// VISUALIZZA NUOVI COMMENTI
//--------------------------------------------------------------------------------


function viewProfilo(result)
{
	
	var divProfilo = document.getElementById('divProfilo');
	
	
	
	
	
	divProfilo.innerHTML=result;
	
//____________DEBUG_______________
	if(debugAJAX)
	{
		alert('Profilo ->'+result);
	
	}
//________________________________	
}
//--------------------------------------------------------------------------------


function newCommenti(result)
{
	
	
	var ulCommenti = document.getElementById('ulCommenti');
	
	var arrayImg = result.split("_#_");
	
	var ulGallery='<li><h1>COMMENTI</h1></li><li>&nbsp;</li>';
	
	var liGallery='';
	
	
	var n=arrayImg.length-1;
		for(j=n; j >= 0; j--)
		{
		//	alert(n);
			var arrayDatiImg = arrayImg[j].split("_|_");
			
			for(y=0; y <= (arrayDatiImg.length-2); y++)
			{
			

				liGallery ='<li class="liUtenteCommento" ><font>'+arrayDatiImg[4]+'</font>'+arrayDatiImg[1]+'</li><li class=\'liTestoCommento\'>'+arrayDatiImg[3]+'</li ><li class=\'liBarra\'>&nbsp;</li>'+liGallery;
			
			y=y+5;
			}
			
			
			
		}
		
		
	ulGallery +=liGallery+'</ul> <div id="divRigaBottom" class="divRigaBottom"></div>';
	
	
	
	
	ulCommenti.innerHTML=ulGallery;
	
//____________DEBUG_______________
	if(debugAJAX )
	{
		alert('newCommenti ->'+result);
	
		alert('ulCommenti ->'+ulGallery);
	}
//________________________________	
}
//--------------------------------------------------------------------------------

function deleteCommenti(result)
{
	
	alert(result);	
	
}

