function ajaxeish(percorso, file_richiesto, css_id) {
	var data = new Date();
	var request = null;
	var html_response = null;
	if(window.XMLHttpRequest){
		request = new XMLHttpRequest;
	}
	else if(window.ActiveXObject){
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(request) {
		request.open("GET", percorso + file_richiesto + "?" + data);
		request.onreadystatechange = function() {
			if(request.readyState == 4) {
				if(request.status == 200) {
					html_response = request.responseText;
					document.getElementById(css_id).innerHTML = decodeURIComponent(html_response);
				}
				else if(request.status == 400) {
					document.getElementById(css_id).innerHTML = "Mi spiace, ma il file a cui si è cercato di accedere non è stato trovato";
				}
				else if(request.status == 500) {
					document.getElementById(css_id).innerHTML = "Mi spiace, ma si è verificato un problema sul server. Riprovare più tardi";
				}
				else {
					document.getElementById(css_id).innerHTML = "Mi spiace, si è verificato un errore durante la trasmissione dei dati. Riprovare più tardi";
				}
			}
			else {
				document.getElementById(css_id).innerHTML = "<div class=\"loading\">CARICAMENTO IN CORSO...<br/>ATTENDERE PREGO</div>";
			}
		}
		request.send(null);
	}
	else {
		alert("Per utilizzare questa funzione occorre aggiornare il Tuo browser");
	}
}

function cliccato(n_pulsante, tot_pulsanti){
	for(var i=1; i<=tot_pulsanti; i++){
		if (i==n_pulsante) {
			document.getElementById(i).className= "sel";
		}
		else {
			document.getElementById(i).className = "nosel";
		}
	}
}

function setVisibile(nome_campo) {
  if (nome_campo=="azienda")
    document.getElementById('nomeaz').style.visibility = "visible"
  else
    document.getElementById('nomeaz').style.visibility = "hidden";
}

function checkPreventivo() {

	    if (document.getElementById('importo').value <5000)
	    {
         alert("Non è possibile inserire un importo inferiore a 5000 Euro!");
         document.getElementById('importo').focus();
         return false;
        }

		if(document.getElementById('cf').value=="") {
		alert("Inserisci il codice fiscale!");
	        document.getElementById('cf').focus();
	        return false;
		}
if(document.getElementById('nome').value=="") {
		alert("Inserisci il nome!");
	        document.getElementById('nome').focus();
	        return false;
		}
if(document.getElementById('cognome').value=="") {
		alert("Inserisci il cognome!");
	        document.getElementById('cognome').focus();
	        return false;
		}
		if(document.getElementById('citta').value=="") {
		alert("Inserisci la citta'!");
	        document.getElementById('citta').focus();
	        return false;
		}
		
		if (document.getElementById('cap').value!="" && isNaN(parseInt(document.getElementById('cap').value))) {
		alert("Il CAP inserito non e' valido!");
		return false;
		}
		
		if(document.getElementById('email').value=="" || !isEmail(document.getElementById('email').value)) {
		alert("Inserisci un indirizzo valido di e-mail!");
	        document.getElementById('email').focus();
	        return false;
		}
		if(document.getElementById('telefono').value=="") {
		alert("Inserisci il numero di telefono!");
			document.getElementById('telefono').focus();
			return false;
		}
		if (isNaN(parseInt(document.getElementById('telefono').value))) {
			alert("Il numero di telefono non e' valido!");
			document.getElementById('telefono').focus();
			return false;
		}
		/*
		if (document.nomeForm.fax.value!="" && isNaN(parseInt(document.nomeForm.fax.value))) {
		alert("Il numero di Fax non e' valido!");
		return false;
		}
		*/
		if(document.getElementById('importo').value=="") {
			alert("Inserisci l'importo del preventivo!");
			document.getElementById('importo').focus();
	        return false;
		}
		if (isNaN(parseInt(document.getElementById('importo').value))) {
			alert("L'importo inserito non e' valido. Digita solo cifre!");
			document.getElementById('importo').focus();
			return false;
		}
		if (document.getElementById('importo').value.indexOf(",") > -1) {
			alert("Usare il punto per separare i decimali!");
			document.getElementById('importo').focus();
			return false;
		}
		if(document.getElementById('prodotto').value=="") {
			alert("Scegli la tipologia del prodotto!");
			document.getElementById('prodotto').focus();
	        return false;
		}
		var altre = document.getElementById('altro').value;
		if(altre.length > 200) {
			alert("Il testo inserito nel area Altre informazioni supera la lunghezza ammessa (200 caratteri max)");
			document.getElementById('altro').focus();
			return false;
		}
		if(eval("document.getElementById('consenso1').checked==false")) {
			alert("Attenzione: l'inoltro della richiesta di preventivo è subordinata al rilascio del consenso previsto dall'articolo 23 del D.Lgs 30 giugno 2003, n&deg; 196 Codice recante disposizioni in materia di protezione dei dati personali.");
	        return false;
		}
		document.nomeForm.submit();
	}

	function isEmail(str) {
  		// are regular expressions supported?
  		var supported = 0;
  		if (window.RegExp) {
  		  var tempStr = "a";
  		  var tempReg = new RegExp(tempStr);
  		  if (tempReg.test(tempStr)) {
  		  	supported = 1;
  		  }
  		}
  		if (!supported) {
  		  return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  		}
  		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  		return (!r1.test(str) && r2.test(str));
	}


