
var sendable;
var sendableSecondLevel;

$j(function() {		
	
			
	$j('form').submit( function (e) {	
		thisObj=$j(this).attr('id');	
		
		if(!sendableSecondLevel) 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();
						
				if(!father.hasClass('hidden')){	
								
						$j('.formError').remove();	
						$j('.errorForm').removeClass('errorForm');
						
										
						if(!val){										
							next.focus();	
							sendable=false;	
						}	
						
						if(!nm){
							
							arrayObj=next.find('input');
							var isChecked=0;
							var tmpNm;
							
							nm="tmp";
							
							arrayObj.each(function(intIndex1) {
								
								isCheckedTmp = $j(this).attr('checked');
								
								tmpNm = $j(this).attr('name');
									
																									
								if(isCheckedTmp){
											
									isChecked=1;
									
								}
							});
							
							sendable=isChecked;	
						}
						
						
						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;
	});		
});


