
/*-----------------------------
	Ajax Connection 
-----------------------------*/

function Ajax(options){
	
	/*-----------------------------
		Code for Mozilla Safari
	-----------------------------*/
	
	if (window.XMLHttpRequest){
  		xmlhttp = new XMLHttpRequest();
  	}
	
	/*-----------------------------
		Code for IE
	-----------------------------*/
	
	else if (window.ActiveXObject){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	
	if (xmlhttp != null){
			
		xmlhttp.onreadystatechange = eval(options.response);
		xmlhttp.open(options.method,options.url,true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
		xmlhttp.setRequestHeader("Connection", "close"); 
		xmlhttp.send(options.uriComponent);
	}
}


function AjaxWork(){
	
	if(xmlhttp.readyState == 4) { 
      
		var esito = xmlhttp.responseText; 
		
		if(esito){
			
			document.getElementById('dettail').innerHTML = esito;
			showDettail();
				
			
		}else {
				
				
			/* -----------------
				Server 
			------------------- */
				
			 alert('Richiesta Server non riuscita');
		}
	}

}


function AjaxMail(){
	
	if(xmlhttp.readyState == 4) {  
		
		var esito = xmlhttp.responseText; 
		
		try{
			
			document.getElementById('description').innerHTML = esito;
			showDettail();
			
			
		}catch(e){	
						
			document.getElementById('dettail').innerHTML = '<div id="description">'+ esito +'</div><div id="goto"><a class="button" href="javascript:hideDettail()">Chiudi</a></div>';
			showDettail();
		}
	}

}


function SendMail(){
	
	options = new Object();
	
	options.url = '/php/send_mail.php';
	options.method = 'POST';
	options.response = 'AjaxMail';
	options.uriComponent = "nome=" +                   
		encodeURIComponent( document.getElementById("nome").value ) + "&indirizzo=" +                    
		encodeURIComponent( document.getElementById("indirizzo").value ) + "&telefono=" +
		encodeURIComponent( document.getElementById("telefono").value ) + "&posta=" +
		encodeURIComponent( document.getElementById("posta").value ) + "&messaggio=" +
		encodeURIComponent( document.getElementById("messaggio").value ) + "&verify=" +
		encodeURIComponent( document.getElementById("verify").value );
	
	Ajax(options);
}


function getWork(id){
	
	options = new Object();
	
	options.url = '/php/work.php';
	options.method = 'POST';
	options.response = 'AjaxWork';
	options.uriComponent = "id=" + id;
	
	Ajax(options);
}