function Validazione(NomeForm){
	
	//reg exp
	// http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
	numReg = /^[-+]?[0-9]*\.?[0-9]+$/,
	emailReg = /^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i,
	urlReg = /^(https?:\/\/)?[\da-z\.\-]+\.[a-z\.]{2,6}[#&+_\?\/\w \.\-=]*$/i,
	dataReg = /^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d$/i,
	
	//testi tipologia campo
	txtLibero = "Inserire un testo libero"
	txtNumero = "Il campo deve essere di tipo numerico"
	txtEmail = "Indirizzo email non valido"
	txtURL = "Indirizzo URL non valido"
	txtData = "Data non valida (gg/mm/aaaa)"
	txtMin = "Minimo &1 Caratteri" //&1 variabile contenente il valore impostato nell'input
	txtMax = "Max &1 Caratteri" //&1 variabile contenente il valore impostato nell'input
	txtPassErr = "Le password non Coincidono"
	
	result = true //variabile di controllo risultati
	// per ogni campo di tipo input
		$('#'+ NomeForm +' input').each(function(){	
		
			//se c'è la specifica del Div di verifica il campo deve essere obbligatorio	("divValid")
			if ($(this).attr('divValid')){
				temp = true
				var IDiv = $(this).attr('divValid')
				// prima distinzione in base al tipo di input
				switch ($(this).attr('type')){
				// se è di tipo testo e password controllare se contiene valore altrimenti...
				case 'text' : {
					if (! $(this).val()){
						result = false
						temp = false
					}
					else {
						//se vi sono attributi di min e max controllare se i caratteri contenuti rispettano i requisiti
						var attivamsg=false  //default
						if ($(this).attr('min') || $(this).attr('max')){
							Minimo = $(this).attr('min')
							Massimo = $(this).attr('max')
							if ($(this).val().length < Minimo ){
								txtMinErr = txtMin.replace('&1',Minimo)
								$('#'+  IDiv).html(txtMinErr)
								result = false
								temp = false
							}
							else if ($(this).val().length > Massimo){
								txtMaxErr = txtMax.replace('&1',Massimo)
								$('#'+  IDiv).html(txtMaxErr)
								result = false
								temp = false
							}
						}
						// se vi è l'attributo "tipo" controllare con le Reg Exp
						switch ($(this).attr('tipo')){

							case 'numero' :{
								//alert (IDiv)
								if (! numReg.test($(this).val())){
									//alert ("interno")
									attivamsg=true
									$('#'+IDiv).html(txtNumero)
									result = false
									temp = false
								}
							break;
							} 
							
							case 'email':{				
								if (! emailReg.test($(this).val())){					
									$('#'+  IDiv).html(txtEmail)
									result = false
									temp = false
								}
							break;
							}
							
							case 'url':{
								if (! urlReg.test($(this).val())){
									$('#'+  IDiv).html(txtURL)
									result = false
									temp = false
								}
							break;
							}
							
							case  'data':{
								if (! dataReg.test($(this).val())){
									$('#'+  IDiv).html(txtData)
									result = false
									temp = false
								}
							break;
							}
						}
					}
				break;
				
				}
				
				case 'password' :{
					if (! $(this).val()){
						result = false
						temp = false
					}
					else {
						//se vi sono attributi di min e max controllare se i caratteri contenuti rispettano i requisiti
						if ($(this).attr('min') || $(this).attr('max')){
							Minimo = $(this).attr('min')
							Massimo = $(this).attr('max')
							if ($(this).val().length < Minimo ){
								txtMinErr = txtMin.replace('&1',Minimo)
								$('#'+  IDiv).html(txtMinErr)
								result = false
								temp = false
							}
							else if ($(this).val().length > Massimo){
								txtMaxErr = txtMax.replace('&1',Massimo)
								$('#'+  IDiv).html(txtMaxErr)
								result = false
								temp = false
							}
						}
					}
					break;
				}

				case 'checkbox' :{
					if ($(this).is(":not(':checked')")){
						result = false
						temp = false
					}
					break;
				}
				
				case 'radio' : {
				 	if ($(this).is(":not(':checked')")){
						result = false
						temp = false
					}
					break;
				}
				
			}
			//alert(temp)
			if (temp == true) {
				$('#'+ IDiv).hide()
				$(this).removeClass('NotValid')
			}
			else {
				if (attivamsg) {$('#'+ IDiv).show()}
				$(this).addClass('NotValid')
			}
		}
	});
		
		
		//per ogni select option
		$('#'+ NomeForm +' select').each(function(){	
			//se il campo deve essere obbligatorio	
			if ($(this).attr('divValid')){
				var IDiv = $(this).attr('divValid')
				if ($(this).val() == '') {
					$('#'+  IDiv).show()					
					$(this).addClass('NotValid')
					result = false
				}
				else
				{
						$('#'+  IDiv ).hide()
						$(this).removeClass('NotValid')
				}
			}
		});
		
		
		//in caso di verifica password
		Passprincipale = 1
		PassConferma = 1
		$('#'+ NomeForm +' input:password ').each(function(){	
			if ($(this).attr('pass')) {
				Passprincipale = $(this).val()	
			}
			if ($(this).attr('conferma')) {
				PassConferma = $(this).val()	
				IDiv = $(this).attr('divValid')
				if (Passprincipale != PassConferma){
					$('#'+  IDiv).html(txtPassErr)
					$('#'+  IDiv).show()
					$(this).addClass('NotValid')
					this.focus()
					$(this).val('')
					result = false
				}
				else{
						$('#'+  IDiv ).hide()
						$(this).removeClass('NotValid')
				} 
			}
		});



		if (result == true) {
			return true
		}
		else {
			alert("Attenzione, campi obbligatori mancanti")
			// Riporta ad inizio pagina, deve essere presente il tag "a" con "name=inizio_scheda"
			location.href= "#inizio_scheda"
			$('#SalvataggioInCorso').hide()
			return false
		}

}
