
var req;
function controllo() 
{  
	if ( document.form.username.value == "" && document.form.password.value == "")  { 
		txt = "Nome utente e password mancanti"; 
		alert(txt);    	
	} else if ( document.form.password.value == "")  { 
		txt = "Password mancante"; 
		alert(txt);    
	} else if ( document.form.username.value == "")  { 
		txt = "Nome utente mancante"; 
		alert(txt); 
	} else {   
		checkLogin();
	}  
} 

function controllo_SO() 
{  
	if ( document.form.Rag_soc.value == "")  { 
		txt = "Ragione sociale mancante"; 
		alert(txt);    
	} else if ( document.form.P_iva.value == "")  { 
		txt = "Partita Iva mancante"; 
		alert(txt);
	} else if ( document.form.Prov.value == "")  { 
		txt = "Provincia mancante"; 
		alert(txt);
	} else if ( document.form.user.value == "")  { 
		txt = "Nome mancante"; 
		alert(txt);
	} else if ( document.form.cogn.value == "")  { 
		txt = "Cognome mancante"; 
		alert(txt);
	} else if ( document.form.email.value == "")  { 
		txt = "E-mail mancante"; 
		alert(txt);
	} else {
            document.form.submit();
	}
}

function controllo_Quest() 
{  
	if ( document.form.nome.value == "")  { 
		txt = "Nome mancante"; 
		alert(txt);   
	} else if ( document.form.cognome.value == "")  { 
		txt = "Cognome mancante"; 
		alert(txt);
	} else if ( document.form.email.value == "")  { 
		txt = "E-mail mancante"; 
		alert(txt);
	} else if ( document.form.dom2.value == "null")  { 
		txt = "Non hai risposto alla 2° domanda"; 
		alert(txt);  
	} else {
            document.form.submit();
	}
}

function controllo_Cli() 
{  
	if ( document.form.Rag_soc.value == "")  { 
		txt = "Ragione sociale mancante"; 
		alert(txt);    
	} else if ( document.form.P_iva.value == "")  { 
		txt = "Partita Iva mancante"; 
		alert(txt);
	} else if ( document.form.Cod_Cli.value == "")  { 
		txt = "Codice Cliente mancante"; 
		alert(txt);
	} else if ( document.form.email.value == "")  { 
		txt = "E-mail mancante"; 
		alert(txt);
	} else {
            document.form.submit();
	}
}

function controllo_For() 
{  
	if ( document.form.Rag_soc.value == "")  { 
		txt = "Ragione sociale mancante"; 
		alert(txt);    
	} else if ( document.form.P_iva.value == "")  { 
		txt = "Partita Iva mancante"; 
		alert(txt);
	} else if ( document.form.user.value == "")  { 
		txt = "Nome mancante"; 
		alert(txt);
	} else if ( document.form.cogn.value == "")  { 
		txt = "Cognome mancante"; 
		alert(txt);
	} else if ( document.form.T_uff.value == "")  { 
		txt = "Telefono ufficio mancante"; 
		alert(txt);
	} else if ( document.form.email.value == "")  { 
		txt = "E-mail mancante"; 
		alert(txt);
	} else {
            document.form.submit();
	}
}

function checkLogin() {

	var url =  "/online/checkLogin.jsp?i_1="+document.form.username.value;
       //alert("checkLogin");
	if (window.XMLHttpRequest) {	
		req = new XMLHttpRequest();	
	} else if (window.ActiveXObject) {	
		req = new ActiveXObject("Microsoft.XMLHTTP");	
	}
       
	req.open("GET", url, false);
	req.send(null);
       req.onreadystatechange = existUser();
 	
	
}

function existUser() {
       //alert(req.readyState);
	if (req.readyState == 4) { 
		if (req.status == 200) { 
			//alert("existUser()");
			var ex = req.responseText;
			//alert(ex);
			if (ex.indexOf('y')!=-1) {
			  document.form.submit();
			} else {
				alert("Non sei abilitato all'accesso via internet");
							}
		}
	}
}