

var speed=15; // scroll speed (bigger = faster)
var dR=false; // reverse direction

var step = 1; 
function objWidth(obj) {
	if(obj.offsetWidth) return obj.offsetWidth; 
	if (obj.clip) return obj.clip.width; 
	return 0;
} 

function objHeight(obj) {
	if(obj.offsetHeight) return obj.offsetHeight; 
	if (obj.clip) return obj.clip.height; 
	return 0;
} 

function scrF(i,sH,eH){
	var x=parseInt(i.top)+(dR? step: -step); 
	if (dR && x>sH) x=-eH;
		else if(x<2-eH)x=sH;i.top = x+'px';
} 

function startScroll(sN,txt){
	var scr=document.getElementById(sN); 
	var sW = objWidth(scr)-6; 
	var sH = objHeight(scr); 
	scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>'; 
	var sTxt=document.getElementById(sN+'in'); 
	var eH=objHeight(sTxt); 
	sTxt.style.top=(dR? -eH : sH)+'px'; 
	sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)'; 
	setInterval(function() {scrF(sTxt.style,sH,eH);},1000/speed);
}
var readyState={
	inattivo: 0,
	inizializzaro: 1,
	richiesta: 2,
	risposta: 3,
	completato: 4
};

var statusText = new Array();
	statusText[100]="Continue";
	statusText[200]="OK";
	statusText[400]="Bad Request";
	statusText[401]="Unauthorized";
	statusText[403]="Forbidden";
	statusText[404]="Not found";
	statusText[500]="Internal Server Error";
	statusText[503]="Service Unavailable";

function createXMLHttpRequest() {
	if(window.XMLHttpRequest) {
	try { 
	xmlHttpRequest = new XMLHttpRequest();
	} catch(e) { return null; }
	} else if(window.ActiveXObject) {
	try {
	xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
	try {
	xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) { return null; }
	}
	} else return null;
	return xmlHttpRequest;
}
function checkForm() {

	var ok = true;
	var msg = "";
	var email = document.getElementById("txtEmail").value;
	
	var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/
	// controllo se email formato corretto se esiste anche:
	
	Nome = document.getElementById("txtNome").value;
	Cognome = document.getElementById("txtCognome").value;
	Messaggio = document.getElementById("txtMessaggio").value;
	Azienda = document.getElementById("txtAzienda").value;
	Oggetto = document.getElementById("txtOggetto").value;
	Telefono = document.getElementById("txtTelefono").value;
	
	if (Nome == ""){
		msg = "Nome ";
	}
	if (Cognome == ""){
		msg += "Cognome ";
	}
	if (Messaggio == ""){
		msg += "Messaggio ";
	}	
	if (!re.test(email)){
		msg += "Email Valida ";
	}
	
	if (document.getElementById("chkPrivacy").checked != true){
		msg += "Privacy";
	}
    if (msg != ""){
		alert("Inserire : " + msg);
	} else
	{
	 // mail valida
		var ajax = createXMLHttpRequest();
		//var did = gebi("didascalia");
			if (ajax){
				//modifichiamo questa parte perchè andiamo a fare la chiamata
				ajax.open("GET", "/inviamessaggio.asp?email=" + email + "&msg=" + Messaggio + "&Nome=" + Nome + "&Cognome=" + Cognome + "&Azienda=" + Azienda + "&Oggetto=" + Oggetto + "&Telefono=" + Telefono, true);
				ajax.setRequestHeader("connection", "close");
				ajax.send(null);
				ajax.onreadystatechange=function(){
					if (ajax.readyState===readyState.completato){
						if (statusText[ajax.status]==="OK"){
							if (ajax.responseText == "OK"){
								alert("MESSAGGIO INVIATO");
								document.getElementById("txtNome").value = "";
								document.getElementById("txtCognome").value = "";
								document.getElementById("txtMessaggio").value = "";
								document.getElementById("txtAzienda").value = "";
								document.getElementById("txtOggetto").value = "";
								document.getElementById("txtTelefono").value = "";	
								document.getElementById("txtEmail").value = "";
							} 
						}	
					}
				}
				
			}	 
	 
	}
}




