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[0];
  
  var numeroElementi = frm.elements.length;
  for(var i = 0; i < numeroElementi-1; i++){
    if (frm.elements[i].value||frm.elements[i].name=="phone"){
		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);
		}
	}else{
		alert (frm.elements[i].name)
		return false;
  	}
  }
  
  return true;
}

var myReq;
var stringa;
function InviaDati(){
	
  if (PreparaDati()){
	/*var accetto = document.getElementById("casella").checked;
	if (accetto!=true){
		if (lang=="ita"){
			alert("In assenza del suo consenso non possiamo trattare i suoi dati ed evadere la sua richiesta");
			}else{
			alert("In case of non-acceptance of the handling of your data, we won't be able to fullfill your request");
			}
	}else{*/
	
		document.getElementById("inviaMailBt").innerHTML="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
		+"codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' id='attendere' width='58' height='25'>"
		+"<param name='movie' value='flash/carica.swf' />"
		+"<param name='quality' value='high' />"
		+"<param name='wmode' VALUE='transparent'>"
		+"<embed src='flash/carica.swf' wmode='transparent' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='58' height='25'></embed>"
		+"</object>";
		AJAXReq("POST","sendMail.php",true);
	//}
  }else{
	 
		  alert("Compilare tutti i campi contrassegnati con *");
	  
  }
}

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){
		document.getElementById("inviaMailBt").innerHTML="<button type='submit' id='go'  value='Subscribe'>Send</button>";
      alert(myReq.responseText);
    }else{
      alert("Niente da fare, AJAX non funziona :(");
    }
  }
}


/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(variabili, containerid,funzione){
	
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid,variabili)
}
page_request.open('POST', funzione, true);
page_request.setRequestHeader("content-type", "application/x-www-form-urlencoded");
page_request.send(variabili);
}

function loadpage(page_request, containerid,variabili){
	var parti = new Array();
parti = variabili.split('|');
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
{
document.getElementById(containerid).innerHTML=page_request.responseText;
if (parti[0]=="variabili=Gallery") initLightbox();
correctPNG();
}else if(page_request.readyState == 2) {
	document.getElementById(containerid).innerHTML="<div class='Titolo'>Attendere Caricamento Pagina</div>";
}
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
