// JavaScript Document
//INIZIO ajax
// funzione per la chiamata dell'oggetto XMLHttpRequest
function ajax(){
  var ajaxRequest;
  try{
    // controllo per i browser diversi da IE
    ajaxRequest = new XMLHttpRequest();
  }catch (e){
    // contorollo per IE
    try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      try{
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
        // controllo per i browser che non supportano l'XMLHttpRequest
        alert("Il browser non supporta questo ShoutBox");
        return false;
      }
    }
  }
  return ajaxRequest;
}

// funzione per il salvataggio dei dati
function mostra(){
  
  htmlRequest = ajax();
  if (htmlRequest==null){ 
    alert ("Il browser non supporta richieste HTTP");
    return;
  } 
 var stringa = document.autocompletamento.findme.value;
stringa=stringa.replace(/\\/g,'\\\\');
stringa=stringa.replace(/\'/g,'\\\'');
stringa=stringa.replace(/\"/g,'\\"');
stringa=stringa.replace(/\0/g,'\\0');



 
  // inviamo i parametri al file per l'INSERT nel database
  htmlRequest.open('POST', 'mostraRisultati.php');
  htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  htmlRequest.send('findme='+stringa); 


  htmlRequest.onreadystatechange = function(){
    // Restituisce lo stato della richiesta
    if(htmlRequest.readyState == 4){
      // Restituice il corpo della risposta come stringa
      document.getElementById("listaSuggerimenti").innerHTML = htmlRequest.responseText;
	 
    }
  }
  // svuotiamo il modulo per il messaggio
  //document.autocompletamento.findme.value = '';
  //document.autocompletamento.findme.focus();
 
}

/** funzione per mostrare i dati
function mostra() {
  htmlRequest = ajax();
  // controllo nel caso in cui non possa richiamato l'oggetto Xmlhttp
  if (htmlRequest==null){ 
    alert ("Il browser non supporta richieste HTTP");
    return;
  }
  htmlRequest.onreadystatechange = function(){
    // Restituisce lo stato della richiesta
    if(htmlRequest.readyState == 4){
      // Restituice il corpo della risposta come stringa
      document.getElementById("moduloMessaggeria").innerHTML = htmlRequest.responseText;
	 
    }
  }
  // chiamata della pagina PHP che estrae i records 
  htmlRequest.open("GET", "mostraMessaggeria.php", true);
  htmlRequest.send(null);
}
// chiamata alla funzione

// intevallo per l'aggiornamento della pagina

setInterval("mostra();", 10000);
*/


  function scegli(id,url){
  for(var i=0; i<document.images.length; i++){
    document.images[i].style.border='1px solid #ffffff';
  }
  
  var idelemento="select_"+id;
  
   document.getElementById(idelemento).style.border='1px solid #ED3030';
  parent.document.getElementById("ok").innerHTML="Ok!";
  parent.document.getElementById("url_scelto").value=url;
 
 
 parent.document.getElementById("imganteprima").innerHTML="<img src='http://www.condividiquesto.it/"+url+"' width='100' height='100' alt='anteprima' class='linkfbfloat'>";
  parent.document.getElementById("Submit").disabled = false;
  
  }
  function copiatitolo(){
    var stringa = document.creazione.titolo.value;
    document.getElementById("titoloanteprima").innerHTML = stringa;
  
  }
   function copiadesc(){
    var stringa = document.creazione.descrizione.value;
    document.getElementById("descanteprima").innerHTML = stringa;
  
  }
  
  
