// CONTROLLO SE IL CAMPO E' VUOTO
function CheckVuoto(obj){
	if(obj.value==""){
		//alert('il campo è vuoto')
		//obj.style.background = "#ffcfcf"
		return false
	}else{
		return true
	}
}


// CONTROLLO SE IL CAMPO E' UN NUMERO
function CheckNum(obj){
	if(CheckVuoto(obj)){
		if(isNaN(obj.value)){
			//alert('non è un numero')
			//obj.style.background = "#ffcfcf"
			return false
			
		}else{
			return true
		}
	}
}

// CONTROLLO SE IL CAMPO E' ALFABETICO
function CheckAlph(obj){
	var espresione =/[^a-zA-Z]/g;
	if(CheckVuoto(obj)){
		if(espresione.test(String(obj.value))){
			//alert('Contiene caratterni non consentiti')
			//obj.style.background = "#ffcfcf"	
			return false
			
		}else{
			return true
		}
	}
}

// CONTROLLO SE IL CAMPO E' ALFABETICO
function CheckAlphnum(obj){
	var espresione =/[^0-9a-zA-Z]/g;
	if(CheckVuoto(obj)){
		if(espresione.test(String(obj.value))){
			//alert('Contiene caratterni non consentiti')
			//obj.style.background = "#ffcfcf"	
			return false
			
		}else{
			return true
		}
	}
}

// CONTROLLO DEL CAMPO SE MAGGIORE DEL VALORE
function CheckMag(obj,val){
	if(CheckVuoto(obj)){
		if(obj.value<val){
			//alert('Il numero inserito è minore di '+val)
			//obj.style.background = "#ffcfcf"	
			return false
		}else{
			return true
		}
	}
}

// PER IL CONTROLLO SE LA DATA A E' MINORE DELLA DATA B
var CheckDataAValue = "";
var CheckDataAMemoObj = "";
var CheckDataBValue = "";

// CONTROLLO SE IL COMPO E' UNA DATA
function CheckData(obj){
	var espresione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if(CheckVuoto(obj)){
		if(!espresione.test(String(obj.value))){
			//alert('non è una data')
			//obj.style.background = "#ffcfcf"	
			return false
			
		}else{
			return true
		}
	}
}

// CONTROLLO SE LA DATA INSERITA E' MINORE O MAGGIORE DI QUELLA ODIERNA
function CheckDataToDay(obj){

	if(CheckVuoto(obj)){
		if(CheckData(obj)){
			data = new Date();
			date= String(data.getDate());
			if(date.length<2){date = "0"+date}
			mese = String(data.getMonth()+1);
			if(mese.length<2){ mese = "0"+mese};
			year= data.getYear();
			if(year<1900)year=year+1900;
			
			dataOggi = 	String(year)+String(mese)+String(date)
			
			var dateIns = String(obj.value).split('/')[0]
			if(dateIns.length<2){dateIns = "0"+dateIns}
			var meseIns = String(obj.value).split('/')[1]
			if(meseIns.length<2){meseIns = "0"+meseIns};
			var yearIns = String(obj.value).split('/')[2]
			
			dataIns = String(yearIns)+String(meseIns)+String(dateIns)
			
			if(Number(dataIns)<Number(dataOggi)){
				//alert('La data inserita non può essere prima di oggi')
				//obj.style.background = "#ffcfcf"	
				return false
			}else{
				return true
			}			
		}
	}	
}


// CONTROLLO SE LA DATA A E' MINORE DELLA DATA B
function CheckDataA(obj){
	if(CheckVuoto(obj)){
		if(CheckData(obj)){
			if(CheckDataToDay(obj)){
			
				var dateIns = String(obj.value).split('/')[0]
				if(dateIns.length<2){dateIns = "0"+dateIns}
				var meseIns = String(obj.value).split('/')[1]
				if(meseIns.length<2){meseIns = "0"+meseIns};
				var yearIns = String(obj.value).split('/')[2]
				
				CheckDataAValue = String(yearIns)+String(meseIns)+String(dateIns);
			}
		}
	}
}
function CheckDataB(obj){
	if(CheckVuoto(obj)){
		if(CheckData(obj)){
			if(CheckDataToDay(obj)){
				var dateIns = String(obj.value).split('/')[0]
				if(dateIns.length<2){dateIns = "0"+dateIns}
				var meseIns = String(obj.value).split('/')[1]
				if(meseIns.length<2){meseIns = "0"+meseIns};
				var yearIns = String(obj.value).split('/')[2]
				
				CheckDataBValue = String(yearIns)+String(meseIns)+String(dateIns);
				if(Number(CheckDataAValue) > Number(CheckDataBValue)){
					//alert('Data di partenza minore della data di arrivo')
					//obj.style.background = "#ffcfcf"	
					return false
				}else{
					return true
				}
			}
		}
	}
}



// PER IL CONTROLLO SE LA MAIL A E' UGUALE ALLA MAIL B
var CheckMailAValue = "";
var CheckMailAMemoObj = "";
var CheckMailBValue = "";

// CONTROLLO SE E' UNA MAIL
function CheckMail(obj){
	
	var espresione = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,3})$/
	if(CheckVuoto(obj)){
		if(!espresione.test(String(obj.value))){
			//alert('non e una mail')
			//obj.style.background = "#ffcfcf"	
			return false
			
		}else{
			return true
		}
	}
		
}

// CONTROLLO SE LA MAIL A E' UGUALE ALLA MAIL B
function CheckUgualA(obj){
	if(CheckVuoto(obj)){
		if(CheckMail(obj)){
			 CheckMailAValue = obj.value;
		}
	}
}
function CheckUgualB(obj){
	if(CheckVuoto(obj)){
		if(CheckMail(obj)){
			 CheckMailBValue = obj.value;
			 if(CheckMailAValue!=CheckMailBValue){
			 	//alert('Le mail non corrispondono')
				//obj.style.background = "#ffcfcf"	
				return false
				
			}else{
				return true
			}
		}
	}
}
