var sendable;

$j(function() {		
	
			
	$j('form').submit( function (e) {	
		thisObj=$j(this).attr('id');		  
		sendable=true;				
		
		$j('#'+thisObj+' em').each(function(intIndex) {	
				
			thisObj=$j(this);
			
			if(sendable && thisObj.text() == "*")	{	
				var next = thisObj.parent().next();					
				var nm = next.attr('id');
				var val = next.attr('value');
				
				var father = thisObj.parent().parent();
				
				$j('.formError').remove();	
				$j('.errorForm').removeClass('errorForm');

				if(!val){
										
					next.focus();	
					sendable=false;	
				}	
				
				if(sendable){
					
					var classe=father.attr('class');
					var pos=classe.indexOf("checkChar");
					
					if(pos!=-1){
						
						var numChar=(val)?val.length:0;
						var num=Number(classe.substr(pos+9,2));
						sendable=(numChar>=num);
						if(!sendable){							
							var message=_NUMBERCHAR.replace('%n',num);
							father.after('<div class="formError">'+message+'</div>');
							father.addClass('errorForm');									
							next.focus();
						}
						
					}
					
					var isEmail=(nm.indexOf("email") != -1);	
					
					if(isEmail && !isValidEmail(val)){
						$j('.formError').remove();	
						father.after('<div class="formError">'+_VALIDEMAIL+'</div>');	
						father.addClass('errorForm');
						next.focus();	
						sendable=false;	
					}	
					
					var isConferma=(nm.indexOf("conferma") != -1);
					
					if(isConferma) {
						
						var isError=(father.prev().attr('class')=="formErrorRegister");
						var prev = (!isError)?father.prev().find('input'):father.prev().prev().find('input');
						var valPrev = prev.attr('value');
						var isConferma=(valPrev==val);
						
						if(!isConferma){
							$j('.formError').remove();	
							father.after('<div class="formError">'+_VALIDECONFIRM+'</div>');	
							father.addClass('errorForm');
							sendable=false;	
							next.focus();
						}
					}
				
				}
			}
		});	
		if(sendable) return true;		
		return false;
	});		
});

