function ValidaMail(field){
	
	//resetto il CSS
	jQuery(field).css('color','#666666');
	//controllo la stringa
	var inputVal = jQuery(field).val();
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	if(inputVal=='' || inputVal==' '){
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true
	}else if(!emailReg.test(inputVal)) {
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true
	}else{
		jQuery(field).css('color','#666666');
		return false
		}

}


function ValidaNum(field, minN, maxN){
	
	//resetto il CSS
	jQuery(field).css('color','#666666');
	//controllo la stringa
	var inputVal = jQuery(field).val();
	var Nmax=false;
	var Nmin=false;
	
	if(maxN!=0){
		if(inputVal.length<=maxN){
				Nmax=false;
			}else{
				Nmax=true;	
			}
	}else{
		Nmax=false;
	}

	if(minN!=0){
		if(inputVal.length>=minN){
				Nmin=false;
			}else{
				Nmin=true;	
			}
	}else{
		Nmin=false;
	}	
	
	if(inputVal=='' || inputVal==' '){
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true
	}else if(Nmax) {
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true
	}else if(Nmin) {
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true			
	}else if(isNaN(inputVal)) {
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true
	}else{
		jQuery(field).css('color','#666666');
		return false
		}

}


function ValidaTxt(field, minN, maxN){
	
	//resetto il CSS
	jQuery(field).css('color','#666666');
	//controllo la stringa
	var inputVal = jQuery(field).val();
	var Nmax=false;
	var Nmin=false;
	
	if(maxN!=0){
		if(inputVal.length<=maxN){
				Nmax=false;
			}else{
				Nmax=true;	
			}
	}else{
		Nmax=false;
	}

	if(minN!=0){
		if(inputVal.length>=minN){
				Nmin=false;
			}else{
				Nmin=true;	
			}
	}else{
		Nmin=false;
	}	
	
	if(inputVal=='' || inputVal==' '){
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true
	}else if(Nmax) {
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true
	}else if(Nmin) {
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true			
	}else{
		jQuery(field).css('color','#666666');
		return false
		}

}

function ValidaCode(field, tot){
	
	//resetto il CSS
	jQuery(field).css('color','#666666');
	//controllo la stringa
	var inputVal = jQuery(field).val();	
	
	if(Math.floor(inputVal)==tot) {
		jQuery(field).css('color','#666666');
		return false
	}else{
		jQuery(field).css('color','#cc0000');
		jQuery(field).focus();
		return true
		}

}

function ValidaCheckBox(field){
	jQuery(".form-lable-privacy").css('color','#000');
	if (jQuery(field).attr('checked')) {
			jQuery(".form-lable-privacy").css('color','#000');
    		return false
		}else{
			jQuery(".form-lable-privacy").css('color','#cc0000');
			jQuery(field).focus();
			return true
			}
	}
	
function ValidaCheckBoxArray(){
	
	jQuery('#step-abitazione').css('color','#000000');
	var a=0;
	document.getElementById('preventivo').abitazione_all.value="";
	
	for (i=0; i<document.getElementById('preventivo').abitazione.length; i++){
		
		if (document.getElementById('preventivo').abitazione[i].checked==true){
			document.getElementById('preventivo').abitazione_all.value =document.getElementById('preventivo').abitazione_all.value+document.getElementById('preventivo').abitazione[i].value+",";
			a++;
		}
		
	}
	
	if (document.getElementById('servizio_0').checked==true){ 
	
	if(a>0){
			
			return false;
			
		}else{
			jQuery('#step-abitazione').css('color','#CC0000');
			jQuery('#step-abitazione').focus();
			return true;
		}
	}else{
		
		return false;
		}
}


function ValidaIndirizzi(){
	
	if (document.getElementById('noarrivo_1').checked==true){ 
	
		//STESSO INDIRIZZO 
		if(!ValidaTxt('#indirizzoP',3,100) && !ValidaTxt('#pianoP',1,100) && !ValidaTxt('#pianoPA',1,100)){
			return false;
		}else{
			return true;
			}
	
	
	}else{
		
		//INDIRIZZO DIVERSO
		if(!ValidaTxt('#indirizzoP',3,100) && !ValidaTxt('#pianoP',1,100) && !ValidaTxt('#indirizzoA',3,100) && !ValidaTxt('#pianoA',1,100)){
			return false;
		}else{
			return true;
			}
		
	}
	
	
}


function ValidaPrivacy(){
	jQuery('#step-privacy').css('color','#000000');
	if (document.getElementById('privacy').checked==true){ return false;} else{return true;  jQuery('#step-privacy').css('color','#CC0000'); jQuery('#step-privacy').focus();}
}
function ValidaPrivacyR(){
	if (document.getElementById('privacyR').checked==true){ return false;} else{return true; jQuery('#privacyR').focus();}
}
