
/*-----------------------------
	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 
			------------------- */
				
			document.getElementById('alert').innerHTML = 'Richiesta Server non riuscita';
		}
	}

}


function AjaxMail(){
	
	if(xmlhttp.readyState == 4) { 
      
		var esito = xmlhttp.responseText; 
		
		if(esito){
			
			document.getElementById('description').innerHTML = esito;
			showDettail();
			
			
		}else{	
				
			/* -----------------
				Server 
			------------------- */
			document.getElementById('alert').innerHTML = 'Richiesta Server non riuscita';
		}
	}

}


function SendMail(){
	
	options = new Object();
	
	options.url = '/php/send_mail.php';
	options.method = 'POST';
	options.response = 'AjaxMail';
	
	c_value = '';
	for (i = 0; i < document.contatti.lavoro.length; i++) {
   		if (document.contatti.lavoro[i].checked)
      		c_value += document.contatti.lavoro[i].value + "\n";
   }
	
	options.uriComponent = "telefono=" +
		encodeURIComponent( document.getElementById("telefono").value ) + "&posta=" +
		encodeURIComponent( document.getElementById("posta").value ) + "&messaggio=" +
		encodeURIComponent( document.getElementById("messaggio").value ) + "&lavoro=" +
		encodeURIComponent( c_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);
}
