function checkOnlyAlpha(stringa){
	if (stringa.match(/^([a-z '\-àèéìòù]{1,255})$/i))
		return true;
	else
		return false;
}

function checkNome() {
	nomeVal	= $("#nome").val();
	if(nomeVal == "" || nomeVal == "Nome")
		{
			$("#nomeError").html("Nome richiesto");
			return false;
		}
	else
		{
			if(checkOnlyAlpha(nomeVal) == false)
				{
					$("#nomeError").html("Solo lettere");
					return false;
				}
			else
				{
					$("#nomeError").html("");
					return true;
				}
		}
}
function checkCognome() {
	cognomeVal = $("#cognome").val();
	if( cognomeVal == "" || cognomeVal == "Cognome")
		{
			$("#cognomeError").html("Cognome richiesto");
			return false;
		}
	else
		{
			if(checkOnlyAlpha(cognomeVal) == false)
				{
					$("#cognomeError").html("Solo lettere");
					return false;
				}
			else
				{
					$("#cognomeError").html("");
					return true;
				}
		}
}
function checkEmail() {
	var emailAddressVal = $("#email").val();

	if(emailAddressVal == "" || emailAddressVal == "Email")
		{
			$("#emailError").html("Email richiesta");
			return false;
		}
	else
		{
			var emailReg = /^([\w\-\.]+)@([\w\-]+)\.([\w]{2,4})$/;
			if( !emailReg.test(emailAddressVal) )
				{
					$("#emailError").html("Email non valida");
					return false;
				}
			else
				{
					$("#emailError").html("");
					return true;
				}
		}
}
function checkSesso() {
	var sessoVal = $("#sesso").val();
	if(sessoVal == "m" || sessoVal == "f")
		{
			$("#sessoError").html("");
			return true;
		}
	else
		{
			$("#sessoError").html("Selezionare il proprio sesso");
			return false;
		}
}
function checkTipoPrestito() {
	if($("#tipoprestito").val() != "")
		{
			$("#tipoprestitoError").html("");
			return true;
		}
	else
		{
			$("#tipoprestitoError").html("Selezionare il tipo di prestito desiderato");
			return false;
		}
}
function checkProvincia() {
	if($("#provincia").val() != "")
		{
			$("#provinciaError").html("");
			return true;
		}
	else
		{
			$("#provinciaError").html("Selezionare la provincia di residenza");
			return false;
		}
}
function checkSettore() {
	if($("#settore").val() != "")
		{
			$("#settoreError").html("");
			return true;
		}
	else
		{
			$("#settoreError").html("Selezionare il settore d'impiego");
			return false;
		}
}
function handleImporto() {
	$("#importo").keydown(function(event) {
        // Allow only :
		// 46 : Delete
		// 8 : Backspace
		// 9 : Tab
		// 37-39 : Left-Right
		// 190 : Dot
		
        if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 190 ) {
            // let it happen, don't do anything
        }
        else {
            // Ensure that it is a number and stop the keypress
            if (event.keyCode < 48 || event.keyCode > 57 ) {
                event.preventDefault(); 
            }   
        }
    });
}
function checkImporto() {
	var importoVal = $("#importo").val();
	if( importoVal == "" || importoVal == "Inserisci l'importo")
		{
			$("#importoError").html("Importo richiesto");
			return false;
		}
	else
		{
			var importoReg = /^([0-9\.]+)$/;
			if( !importoReg.test(importoVal) )
				{
					$("#importoError").html("Solo numeri");
					return false;
				}
			else
				{
					return true;
				}
		}
}
function checkPrivacy() {
	var privacyVal = $("#privacy").val();
	if(privacyVal=="s")
		{
			$("#privacyError").html("");
			return true;
		}
	else
		{
			$("#privacyError").html("Accettare le condizioni");
			return false;
		}
}
