function checkemail (email) {
	var valori=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return valori.test(email);
}

function clearoptions (o) {
	for (i=o.length-1; i>=0; i--) {
		o[i]=null;
	}

	return o.length=0;
}

function in_array (v, a) {
	var found=false;
	var i=0;
	
	while ((!found) && (i<a.length)) {
		found=(v==a[i]);
		i++;
	}
	
	return found;
}

function addoption (frm, value, text) {
	var newopt=new Option;
	newopt.value=value;
	newopt.text=text;
	frm.options[frm.options.length]=newopt;
	return true;
}

function scandate (campo, evn) {
	var valori=['0','1','2','3','4','5','6','7','8','9'];
	var brwGecko=true;
	var kcode;

	if (!campo.readOnly) {
		if (!evn) {
			try {
				var evn=window.event;
				kcode=window.event.keyCode;
			} catch (err) {
				alert ('Evento non trovato (scandata).');
				return false;
			}
		}
	
		if (evn.keyCode) {
			kcode = evn.keyCode;
			brwGecko=false;
		} else {
			kcode = evn.which;
		}
	
		var inarrayResult=in_array(String.fromCharCode(kcode), valori);
	
		if (campo.value.length>=10) {
			if (inarrayResult) {
				campo.value="";
			}
		}
		
		if (!((inarrayResult) || (String.fromCharCode(kcode)=="/") || (String.fromCharCode(kcode)==".") || (kcode==13))) {
			if (!brwGecko) {
				window.event.returnValue=0;
			}
			return false;
		}
		
		if (String.fromCharCode(kcode)==".") {
			if (!brwGecko) {
				window.event.keyCode="/".charCodeAt (0);
			}
		}
		
		if ((campo.value.length+1==3)) {
			campo.value+="/";
		}
		
		if ((campo.value.length+1==6)) {
			campo.value+="/";
		}
		
		if ((String.fromCharCode(kcode)=="/") && ((campo.value.length==3) || (campo.value.length==6) || (campo.value.length<2) || ((campo.value.length>3) && (campo.value.length<5)))) {
			if (!brwGecko) {
				window.event.returnValue=0;
			}
			return false;
		}
	}
	
	return true;
}

function scanyear (campo, evn) {
	var valori=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
	var brwGecko=true;
	var kcode;

	if (!campo.readOnly) {
		if (!evn) {
			try {
				var evn=window.event;
				kcode=window.event.keyCode;
			} catch (err) {
				alert ('Evento non trovato (scanyear).');
				return false;
			}
		}
	
		if (evn.keyCode) {
			kcode=evn.keyCode;
			brwGecko=false;
		} else {
			kcode=evn.which;
		}
	
		var ccode=String.fromCharCode(kcode);
		var inarrayResult=in_array(ccode, valori);
	
	
		if (campo.value.length>=4) {
			if (inarrayResult) {
				campo.value="";
			}
		}
	
		if (!inarrayResult && ((kcode!=8) && (kcode!=13))) {
			if (!brwGecko) {
				window.event.returnValue=0;
			}
			return false;
		}
	}
	
	return true;
}

function checkdate(a, empty) {
	var err=0;
	var dateseparator="/";
	
	if (a.length==10) {
		var day=a.substring(0, 2);// day
		var sep1=a.substring(2, 3);// '/'
		var month=a.substring(3, 5);// month
		var sep2=a.substring(5, 6);// '/'
		var year=a.substring(8, 10);// year
	
		if ((month<1) || (month>12)) {
			err=1;
		}
		
		if ((sep1!=dateseparator) || (sep2!=dateseparator)) {
			err=1;
		}
		
		if ((day<1) || (day>31)) {
			err=1;
		}
		
		if ((year<0) || (year>99)) {
			err=1;
		}
		
		if ((month==4) || (month==6) || (month==9) || (month==11)) {
			if (day==31) {
				err=1;
			}
		}

		if (month==2) {
			if ((day>29) || ((day==29) && ((year%4)!=0))) {
				err=1;
			}
		}
	} else {
		if ((a.length==0) && empty) {
			err=0;
		} else {
			err=1;
		}
	}
	
	return err==0;
}

function scanfloat (campo, evn) {
	var valori=['-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ','];
	var brwGecko=true;
	var kcode;

	if (!campo.readOnly) {
		if (!evn) {
			try {
				var evn=window.event;
				kcode=window.event.keyCode;
			} catch (err) {
				alert ('Evento non trovato (scanfloat).');
				return false;
			}
		}
	
		if (evn.keyCode) {
			kcode=evn.keyCode;
			brwGecko=false;
		} else {
			kcode=evn.which;
		}
	
		var ccode=String.fromCharCode(kcode);
		var inarrayResult=in_array(ccode, valori);
	
		if (!inarrayResult && ((kcode!=8) && (kcode!=13))) {
			if (!brwGecko) {
				window.event.returnValue=0;
			}
			return false;
		}
		
		if (ccode=='-') {
			if (campo.value.indexOf('-')<0) {
				campo.value='-'+campo.value;
			} else { // sentire se sta cosa piace
				campo.value=campo.value.substr(1);
			}
			
			if (!brwGecko) {
				window.event.returnValue=0;
			}
			return false;
		}
	
		if ((ccode=='.') || (ccode==',')) {
			if ((campo.value.indexOf('.')>=0) || (campo.value.indexOf(',')>=0)) {
				if (!brwGecko) {
					window.event.returnValue=0;
				}
				return false;
			} else {
				campo.value=campo.value+',';
	
				if (campo.value.substr(0, 1)==",") {
					campo.value="0"+campo.value;
				}
	
				if (campo.value.substr(0, 2)=="-,") {
					campo.value="-0,"+campo.value.substr(2);
				}
				
				if (!brwGecko) {
					window.event.returnValue=0;
				}
				return false;
			}
		}
	}

	return true;
}

function scanint (campo, evn) {
	var valori=['-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
	var brwGecko=true;
	var kcode;

	if (!campo.readOnly) {
		if (!evn) {
			try {
				var evn=window.event;
				kcode=window.event.keyCode;
			} catch (err) {
				alert ('Evento non trovato (scanint).');
				return false;
			}
		}
	
		if (evn.keyCode) {
			kcode=evn.keyCode;
			brwGecko=false;
		} else {
			kcode=evn.which;
		}
	
		var ccode=String.fromCharCode(kcode);
		var inarrayResult=in_array(ccode, valori);
	
		if (!inarrayResult && ((kcode!=8) && (kcode!=13))) {
			if (!brwGecko) {
				window.event.returnValue=0;
			}
			return false;
		}
	
		if (ccode=='-') {
			if (campo.value.indexOf('-')<0) {
				campo.value='-'+campo.value;
			} else { // sentire se sta cosa piace
				campo.value=campo.value.substr(1);
			}
			
			if (!brwGecko) {
				window.event.returnValue=0;
			}
			return false;
		}
	}
	
	return true;
}