	function trim(trim_string) { 
    // this will get rid of leading spaces 
    while (trim_string.substring(0,1) == ' ') 
        trim_string = trim_string.substring(1, trim_string.length);

    // this will get rid of trailing spaces 
    while (trim_string.substring(trim_string.length-1,trim_string.length) == ' ')
        trim_string = trim_string.substring(0, trim_string.length-1);

	return trim_string;
} 
	function getYear(d) { 
		return (d < 1000) ? d + 1900 : d;
	}
	function isDate (year, month, day) {
	  // month argument must be in the range 1 - 12
	  month = month - 1;  // javascript month range : 0 - 11
	  var tempDate = new Date(year,month,day);
	  if ( (getYear(tempDate.getYear()) == year) &&
	     (month == tempDate.getMonth()) &&
	     (day == tempDate.getDate()) ) {
	      return true;
	  }else{
	     return false;
	  }
	}
	function verdate(chi, formato, messaggio1, messaggio2) {
		if (trim(chi.value) != '') {
			var a=new Array();
			a=chi.value.split('/');

			if (a.length!=3) {
				msg = msg + messaggio2;
				return false;
			}else{
				if (formato == 'it') {
					app		= a[0];
					a[0]		= a[2];
					a[2]		= app;
					if (a[2].length != 2) {
						msg = msg + messaggio2;
						return false;
					}
				}else{
					if (a[0].length != 4) {
						msg = msg + messaggio2;
						return false;
					}
				}
				if (!isDate(a[0],a[1],a[2])) {
					msg = msg + messaggio2;
					return false;
				}
			}
			return true;
		}else{
			msg = msg + messaggio1;
			return false;
		}
	}
	function veremail(chi, messaggio1, messaggio2) {
		// verifica della sintassi dell' e-mail 
		if (trim(chi.value) != '') {
			var str;
			var vet1,vet2;
			 
			 str=chi.value;
			 vet1=str.split("@"); 
			 if (vet1[0]=="" || vet1[0].length < 2 || vet1.length>2) {
				msg = msg + messaggio2;
				return false;
			 }

			 if (typeof(vet1[1])!="undefined") {
				if (vet1[1].length<5) {
					msg = msg + messaggio2;
					return false;
				}
			 }
			 else {
				msg = msg + messaggio2;
				return false;
			 }
			 			
			 vet2=vet1[1].split(".");
			 if (vet2[0].length < 2) {
				msg = msg + messaggio2;
				return false;
			 }
			 if (typeof(vet2[1])!="undefined") {
				if (vet2[1].length<2){
					msg = msg + messaggio2;
					return false;
				}
			 }
			 else {
				msg = msg + messaggio2;
				return false;
			 }
			 
			 return true; 
		}else{
			msg = msg + messaggio1;
			return false;
		}
	}

	function verselect(chi, messaggio){
		// Verifica campo select //	
		if (chi.selectedIndex == 0) 
		{
			msg = msg + messaggio;
			return false;
		}
		return true;
	}
	
	function vertext(chi, messaggio1, messaggio2, max){
		// Verifica campo testo //	
		if (trim(chi.value) == '') 
		{
			msg = msg + messaggio1;
			return false;
		}
		if (max != '') {
			if (chi.value.length > max) {
				msg = msg + messaggio2;
				return false;
			}			
		}
		return true;
	}

	function verinteger(chi,type,min,max,esclude,messaggio1,messaggio2) {
		// verifica su campi Integer 
		if (trim(chi.value) != '') {
			var num;
			num = chi.value;

			if (isNaN(num)) {
				msg = msg + messaggio2;
				return false;
			}   
			
			
			if (min!='') {
				if (max!='') {
					if ((num<min) || (num>max)) {
					msg = msg + messaggio2;
					return false;
					} 
				}
				else {
					if (num<min) {
					msg = msg + messaggio2;
					return false;
					} 
				}
			}
			else {
				if (max!='' && num>max){
					msg = msg + messaggio2;
					return false;
				} 
			}
			
			if (esclude == num) {
				msg = msg + messaggio2;
				return false;
			} 

			num = num - parseInt(num,10);
			
			if (num>0 && type=='int') {
				msg = msg + messaggio2;
				return false;
			}			

			return true; 
		}else{
			msg = msg + messaggio1;
			return false;
		}
	}
	function vercheckbox(chi, messaggio){
	// Verifica campo radio o checkbox //	
		k=false;
		if (chi.length>1) {
			for(i=0; i<=chi.length-1; i++) {
				if (chi[i].checked) k=true;
			}
			if (k == false) 
			{
				msg = msg + messaggio;
				return false;
			}
			return true;
		}
		else
		{
			if (chi.checked) return true;
			else {
				msg = msg + messaggio;
				return false;
			}
		}
	}
	function ver(chi, messaggio, messaggio2, max) {
		switch (chi.type) {
			case "text":
				return (vertext(chi,messaggio, messaggio2, max))
				break
			case "file":
				return (vertext(chi,messaggio, messaggio2, max))
				break
			case "textarea":
				return (vertext(chi,messaggio, messaggio2, max))
				break
			case "select-one":
				return (verselect(chi,messaggio))
				break
			default:
				return (vercheckbox(chi,messaggio))
				break
		}
	}
