						//class="validate,text,required,check:UID"
						
						var FormCheck = new Class({
						    //implements
						    Implements: [Options],
						
						    //options
						    options:{
						    	send		: true,
						    	checksend	: true,
						    	page		: "",
								table		: "",
								message		: "",
								title		: "",
								fcktext		: "",
								iCaptcha	: 5,
								firevent	: true,
								sendmessage	: true,
								othersend	: false,
								sUrl		: 'checkvalue.php',
								iFrom		: '',
														    							    	
 								regexp 	: {
									//Funzioni e regex di controllo
									required : /[^.*]/,
									alpha : /^[a-z ._-]+$/i,
									alphanum : /^[a-z0-9 ._-]+$/i,
									digit : /^[-+]?[0-9]+$/,
									nodigit : /^[^0-9]+$/,
									number : /^[-+]?\d*\.?\d+$/,
									email : /^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i,
									phone : /^[\d\s ().-]+$/,
									url : /^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&amp;%\$#\=~])*$/i,
									cf :/^[A-Z]{6}[A-Z0-9]{2}[A-Z][A-Z0-9]{2}[A-Z][A-Z0-9]{3}[A-Z]$/i
								},
								
								alerts 	: {
									required : "Campo obligatorio.",
									alpha : "Il campo non pu\u00F2 contenere caratteri speciali.",
									alphanum : "Il campo pu\u00F2 contenere solo caratteri alfanumerici.",
									nodigit : "Il campo no pu\u00F2 contenere numeri.",
									digit : "Il campo puoacute; contenere solo numeri interi.",
									digitmin : "Il campo deve contenere almeno %0 caratteri.",
									digitltd : "Il campo deve contenere un minimo %0 e un massimo %1 caratteri.",
									number : "Il campo pu\u00F2 contenere solo valori numerici.",
									email : "Inserire un\'email valida.",
									phone : "Inserire un numero di telefono valido.",
									url : "Inserire un url valido.",
									cf : "Inserire un codice fiscale valido.",
									privacy : "Per procedere \u00E9 necessario accettare l'informativa.",
									piva : "Inserire una partita iva valida.",
									CodFisc : "Il codice fiscale inserito \u00E9 gi\u00E1 presente nel database.",
									PIVA : "La partita iva inserita \u00E9 gi\u00E1 presente nel database.",
									Email : "L\'email inserita \u00E9 gi\u00E1 presente nel database.",
									captcha : "Il Codice inserito non \u00E8 valido.",
									UID : "L\'username scelta \u00E9 gi\u00E1 presente nel database.",
									
									confirm : "uguale a %0",
									differs : "diverso da %0",
									length_str: "Lunghezza errata, deve essere tra %0 e %1.",
									length_fix: "Lunghezza errata, deve essere esattamente di %0 caratteri.",
									lengthmax : "Lunghezza errata, massimo %0 caratteri.",
									lengthmin : "Lunghezza errata, minimo %0 caratteri.",
									checkbox : "Selezionare almeno un valore.",
									radios : "Selezionare almeno un valore.",
									select : "Selezionare almeno un valore."
								}
						    },
						
							initialize: function(el,options){
								this.setOptions(options);
								this.el = $(el);
								this.ncaptcha=0;
								if(this.el!=null){
									this.items = this.el.getElements("*[class*=validate]");
						        
									this.el.addEvent('submit', function(event){
										event.stop();
										this.overlayer();
										this.checkit();			
									}.bind(this));									
								}
							},
							
							overlayer: function(){
								this.lPOverlay = new Element("div", {
								    'id': "lbCheckOverlay", 
								    'styles':{
									    'opacity': '0.8',
						                'position': 'fixed',
						                'z-index': '9999',
						                'left': 0,
						                'top': 0,
						                'width': '100%',
						                'height': '100%',
						                'background-color': '#1265A0',
						                'cursor': 'pointer'
								    }
							    });	
										    	
								this.lPOverlay.set('html','<img src="../images/loader.gif" alt="Loading" style="margin-top: 30%; border: 0" \/><br \/><b style="font-size: 18px; font-weight: bold; color: #ffffff">Verifica dei dati inseriti<\/b>');
								
								//testo le compatibilità e in caso provvedo
								compatibleOverlay = Browser.Engine.trident4 || (this.lPOverlay.currentStyle && (this.lPOverlay.currentStyle.position != "fixed"));
								if (compatibleOverlay) this.lPOverlay.style.position = "absolute";
								$(document.body).grab(this.lPOverlay);
							    this.lPOverlay.inject(document.body);
							},
															
							checkit: function(){
								this.options.send = true;
								var aryEl = [];
								this.items.each(function(input,index) {
								    aryEl.push(input);
								    //alert(input.getProperty('class'))
						        });
						        
						        //alert(aryEl[1].getProperty("class"))
								for(i=0; i<=aryEl.length-1; i++){
									var input = aryEl[i];
									aryCheck = input.getProperty("class").split(',');

									//Caso richiesto
									if(aryCheck.indexOf('required')>-1){
										if(!this.options.regexp.required.test(input.get('value'))){
											this.setError(input,'required');
											break;
										};
									};

									//Caso alpha
									if(aryCheck.indexOf('alpha')>-1 && input.get('value')!=""){
										if(!this.options.regexp.alpha.test(input.get('value'))){
											this.setError(input,'alpha');
											break;
										};
									};
									
									//Caso alphanum
									if(aryCheck.indexOf('alphanum')>-1 && input.get('value')!=""){
										if(!this.options.regexp.alphanum.test(input.get('value'))){
											this.setError(input,'alphanum');
											break;
										};
									};

									//Caso digit
									if(aryCheck.indexOf('digit')>-1 && input.get('value')!=""){
										if(!this.options.regexp.digit.test(input.get('value'))){
											this.setError(input,'digit');
											break;
										};
									};

									//Caso nodigit
									if(aryCheck.indexOf('nodigit')>-1 && input.get('value')!=""){
										if(!this.options.regexp.nodigit.test(input.get('value'))){
											this.setError(input,'nodigit');
											break;
										};
									};

									//Caso number
									if(aryCheck.indexOf('number')>-1 && input.get('value')!=""){
										if(!this.options.regexp.number.test(input.get('value'))){
											this.setError(input,'number');
											break;
										};
									};

									//Caso email
									if(aryCheck.indexOf('email')>-1 && input.get('value')!=""){
										if(!this.options.regexp.email.test(input.get('value'))){
											this.setError(input,'email');
											break;
										};
									};

									//Caso phone
									if(aryCheck.indexOf('phone')>-1 && input.get('value')!=""){
										if(!this.options.regexp.phone.test(input.get('value'))){
											this.setError(input,'phone');
											break;
										};
									};

									//Caso url
									if(aryCheck.indexOf('url')>-1 && input.get('value')!=""){
										if(!this.options.regexp.url.test(input.get('value'))){
											this.setError(input,'url');
											break;
										};
									};
									
									//Caso cf
									if(aryCheck.indexOf('codfisc')>-1 && input.get('value')!=""){
										if(!this.cCF(input.get('value'))){
											this.setError(input,'cf');
											break;
										};
									};						
									
									//Caso piva
									if(aryCheck.indexOf('piva')>-1 && input.get('value')!=""){
										if(!this.cPIVA(input.get('value'))){
											this.setError(input,'piva');
											break;
										};
									};/**/					

									//Caso privacy
									if(aryCheck.indexOf('privacy')>-1){
										if(!input.checked){
											this.setError(input,'privacy');
											break;
										};
									};
									
									//Caso controllo valore
									if(aryCheck.indexOf('chkvalue')>-1 && input.get('value')!=""){
										var type = input.getProperty("class");
										if(type.indexOf('piva')>-1){
											if(this.chkValue("iTable="+this.options.iFrom+"&iKey=PIVA&iValue="+input.getProperty('value'))){
												this.setError(input,'PIVA');
												break;												
											}
										};
										if(type.indexOf('email')>-1){
											if(this.chkValue("iTable="+this.options.iFrom+"&iKey=Email&iValue="+input.getProperty('value'))){
												this.setError(input,'Email');
												break;												
											}
										};
										if(type.indexOf('uid')>-1){
											if(this.chkValue("iTable="+this.options.iFrom+"&iKey=UID&iValue="+input.getProperty('value'))){
												this.setError(input,'UID');
												break;												
											}
										};
										
										if(type.indexOf('captcha')>-1){
											if(!this.chkValue("chk=session&icode="+input.getProperty('value'))){
												this.setError(input,'captcha');
												this.refreshcode();
												break;												
											}
										};
									};
								}
								
								(function(){this.sendit();}.bind(this)).delay('2000');
							},
							
							sendit: function(){
								/*alert(this.options.send + " - " + this.options.checksend)
								this.options.send = false*/
								if(this.options.send && this.options.checksend){
									new Request({
										url: this.el.getProperty('action'),
										method: this.el.getProperty('method'),
										data : this.el.toQueryString(),
										async: 'true',
										onRequest: function(){
											$('submit').setProperty('disabled', 'disabled')
										},
										onSuccess: function(result){
											$('submit').removeProperty('disabled');
											if(result.substr(0,2)=="ok"){
												var url = result.split("|");
												location.href = url[1];
											}else{
												if(this.options.page == 'login'){
													alert('User name o password errati.');													
												}else if(this.options.page == 'senddata'){
													if(result.substr(0,5)=="error"){
														var data = result.split("|");
														this.setError($(data[1]),'',data[2]);
													}else{
														alert(result)
														alert('Si è verificato un errore di script.\nLa preghiamo di riprovare più tardi.\nQualora l\'errore dovesse persistere la preghiamo di contattarci.');													
													}
												}else{
													alert(result)
													alert('Si è verificato un errore di script.\nLa preghiamo di riprovare più tardi.\nQualora l\'errore dovesse persistere la preghiamo di contattarci.');													
												}
											}
										}.bind(this)
									}).send();
								}
							},
							
							setError: function(input,res,msg){
								this.options.send = false;
								if(this.err!=undefined) this.err.destroy();
								input.setStyle('border-color','#ff0000');
								this.err = new Element("div", {
									'id': "lberr",
									'styles':{
										'color': '#ff0000',
										'font-weight': 'bold',
										'margin-top': '3px',
										'font-size': '10px',
										'width': 'auto',
										'margin': '0',
										'padding': '0'
									}
								});
								if(msg==undefined){
									this.err.set('text',eval('this.options.alerts.'+res));									
								}else{
									this.err.set('text',msg);									
								}
								this.err.inject(input, 'before');
								
								new Fx.Scroll(document.body).toElement(this.err);

								this.lPOverlay.destroy();
								input.addEvent('click', function(){
									this.err.destroy();
									input.setStyle('border-color', '#B3B3B3');
								}.bind(this));
							},
							
							cPIVA: function(pi){
								var validi, i, s, c, validi;
								if( pi == "" ){
									return false;
								}
								/*if( pi == $('txtCodFisc').getProperty('value') )  return true;*/
								if( pi.length != 11 ){
									return false;				
								}
								validi = "0123456789";
								for( i = 0; i < 11; i++ ){
									if( validi.indexOf( pi.charAt(i) ) == -1 ){
										return false;
									}
								}
								s = 0;
								for( i = 0; i <= 9; i += 2 )
									s += pi.charCodeAt(i) - '0'.charCodeAt(0);
								for( i = 1; i <= 9; i += 2 ){
									c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
									if( c > 9 )  c = c - 9;
									s += c;
								}
								if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) ){
									return false;
								}
								return true;
							},
					
							cCF: function(cf) {
								var validi, i, s, set1, set2, setpari, setdisp;
								//alert(cf + " - " + $('txtPIVA').getProperty('value'))
								if( cf == $('txtPIVA').getProperty('value') )  return true;
								if( cf == "" ){
									form.setError(codfisc,'','Il campo non pu\u00E1 contenere un valore nullo..');
									return false;
								}
								cf = cf.toUpperCase();
								if( cf.length != 16 ){
									return false;
								}
								validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
								for( i = 0; i < 16; i++ ){
									if( validi.indexOf( cf.charAt(i) ) == -1 ){
										return false;					
									}
								}
								set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
								set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
								setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
								setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
								s = 0;
								for( i = 1; i <= 13; i += 2 )
									s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
								for( i = 0; i <= 14; i += 2 )
									s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
								if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) ){
									form.setError(codfisc,'','Il Codice Fiscale inserito non \u00E8 valida.');
									return false;
									
								}
								return true;
							},
							
							chkValue: function(sSend){
								var value =new Request.JSON({
									url: "../includes/checkvalue.php", 
									method: "get",
									onSuccess: function(resp){
										return resp;
									}
								}).send(sSend);								
							},
							
							refreshcode: function(){
								if(this.ncaptcha <=this.options.iCaptcha){
									$('imgCaptcha').src='../includes/captcha/captcha.php?' + (new Date()).getTime();
								}else{
									alert("Sono stati effettuati troppi reload, ricaricare la pagina.");
								}							
								this.ncaptcha++;
							}
					});
