function AJAXReq(method,url,bool){
  if(window.XMLHttpRequest){
    myReq = new XMLHttpRequest();
  } else 
  
  if(window.ActiveXObject){
    myReq = new ActiveXObject("Microsoft.XMLHTTP");
    
    if(!myReq){
      myReq = new ActiveXObject("Msxml2.XMLHTTP");
    }
  }
  
  if(myReq){
    execfunc(method,url,bool);
  }else{
    alert("Impossibilitati ad usare AJAX");
  }
}

function PreparaDati(){
  stringa = "";
  var frm = document.forms[1];
  var numeroElementi = frm.elements.length;
  
  for(var i = 0; i < numeroElementi; i++){
    if(i < numeroElementi-1){
      stringa += frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value)+"&";
    }else{
      stringa += frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value);
    }  
  }
}

var myReq;
var stringa;
function InviaDati(FormID)
	{
		PreparaDati();
		if(FormID == 'Mail') AJAXReq("POST","../../../../../Azioni/Azione.php?Azione=1",true);
		if(FormID =='Commento') AJAXReq("POST","../../../../../Azioni/Azione.php?Azione=2",true);
		if(FormID == 'Amico') AJAXReq("POST","../../../../../Azioni/Azione.php?Azione=3",true);
		if(FormID == 'Segnalazione') AJAXReq("POST","../../../../../Azioni/Azione.php?Azione=4",true);

	}

function execfunc(method,url,bool){
  myReq.onreadystatechange = handleResponse;
  myReq.open(method,url,bool);
  
  /* Spiegare setRequestHeader */
  myReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  myReq.send(stringa);
}

function handleResponse(){
  if(myReq.readyState == 4){
    if(myReq.status == 200){
      alert(myReq.responseText);
    }else{
      alert("Niente da fare, AJAX non funziona :(");
    }
  }
}


/*Crea Pdf*/
function MyPdf(Annuncio)
		{
			window.open("http://www.annuncia.it/SottoDomini/Annunci/Operazioni/pdf.php?ID="+Annuncio+"","MyWindowPdf","toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes"); 
			return false;
		}
/*Fine Crea Pdf*/

/*Crea Stampa*/
function MyStampa(Annuncio)
		{
			window.open("http://www.annuncia.it/SottoDomini/Annunci/Operazioni/stampa.php?ID="+Annuncio+"","MyWindowStampa","toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes"); 
			return false;
		}
/*Fine Versione Stampabile*/

