/* 	############################
	# isBlank
	# 
	# Funzione che controlla se il
	# valore passato com parametro 
	# e' stato valorizzato.
	############################	
*/ 
function isBlank(s)
{
	str = s.value.toString();
	if ((str == '') || (str =="") || (str == null))
		{
			return true;			
		}
	else
		{
			return false;
		}
}

/* 	############################
	# checkdate
	# 
	# Funzione che controlla 
	# la coerenza della data 
	# passata come parametro.
	############################	
*/ 
function checkdate(myDate)
	{
	var errmsg = "ATTENZIONE! Sono stati riscontrati i seguenti errori:\n";
	var formok = true;
	d = myDate.value.toString();
	if ((d != '') && (d !="") && (d != null))
		{
			var tst = myDate.value.split("/");
			if (!((1 <= tst[0]) && (tst[0] <= 31) && (1 <= tst[1]) && (tst[1] <= 12) && (1 <= tst[2]) && ((tst[2] <= 100) || (tst[2] >= 1800)))){
				formok = false;
				errmsg += "- La data non è corretta o non è nel formato gg/mm/aaaa\n";
			}
			
			myMese = parseInt(tst[1]);
			switch (myMese) {
				case 2:					
					if(tst[0]=='29') {
						myYear = parseInt(tst[2]);				
						if (!checkYear(myYear)){ 
							formok = false;
							errmsg += "- La data non è corretta";	
						}
					}
					else if ((tst[0]=='30') || (tst[0]=='31')){
						formok = false;
						errmsg += "- La data non è corretta";	
					}
				case 4:					
				case 6:					
				case 9:					
				case 11:
					if(tst[0]=='31'){
						formok = false;
						errmsg += "- La data non è corretta";	
					}					
			}
		}
	if (formok == false){
		alert(errmsg);
		myDate.select();
	}
	return formok;
}

/* 	############################
	# checkYear
	# 
	# Funzione per il controllo 
	# dell' anno bisestile
	# Richiamata da checkdate().
	############################	
*/ 
function checkYear(anno){
	anno1 = parseInt(anno);
	var testAnno1 = anno1 % 400;
	var testAnno2 = anno1 % 4;                              
	var testAnno3 = anno1 % 100;
	var IsBisestile = false;
	// controllo anno bisestile
	if (testAnno1 == 0){
		IsBisestile = true;
	}
	else if ((testAnno2 == 0) && (testAnno3 > 0)){
		IsBisestile = true;
	}
	return IsBisestile;
}

/* 	############################
	# checkNumDec
	# 
	# Funzione per il controllo 
	# dei numeri decimali.
	# Utilizzata da benefit_dettaglio.asp,
	# offerte_dettaglio.asp, ordini_dettaglio.asp e altri
	############################	
*/ 
function checkNumDec(myEl,bAlert){
	var checkStr = myEl.value;
	var checkVal_1 = ".";
	var checkVal_2 = ",";
	var checkVal_3 = "-";  
	var checkOk = true;
	var totCh = 0;
	var totCh2 = 0;
	var num = true;
	checkOk = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		var ch = checkStr.charAt(i);
		if ((ch==checkVal_1)||(ch==checkVal_2)){			
				totCh = totCh + 1;			
		}
		else if ((ch==checkVal_3) && (i==0)){
				num = true;
		}
		else{
			if ((isNaN(ch)) || (ch==' ')){
				num = false;
			}
		}
		//if (ch==checkVal_3){
		//	totCh = totCh + 1;
		//}	
	}
	if ((totCh > 1) || !(num))
	{	
		if (bAlert){
			alert("Inserire il valore in formato numerico e senza separatori di migliaia");
			myEl.select();
		}
		checkOk = false;
	}
	return (checkOk);
}

