function Trim(TRIM_VALUE){
	
	if(TRIM_VALUE.length < 1){
		return "";
	}
	
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}

} //End Function


function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
	return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
	if(VALUE.charAt(iTemp) == w_space){
	}
	else{
	strTemp = VALUE.substring(0,iTemp +1);
	break;
	}
	iTemp = iTemp-1;
	
	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
	return"";
	}
	
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(iTemp,v_length);
		break;
		}
		iTemp = iTemp + 1;
		} //End While
	
	return strTemp;
	
}

function checkEmail(strIndirizzoEmail){
	
	objIndirizzoEmail = new String(strIndirizzoEmail);
	var controlloIndirizzo = objIndirizzoEmail.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.local)|(\..{2,2}))$)\b/gi);
	
	if (controlloIndirizzo){
		controlloIndirizzo = 0; //nessun errore
		}
	else{
		controlloIndirizzo = 1; // errore
	}
	
	return controlloIndirizzo;
}


function checkNLreg(){
	var operazione;
	var email='';
	//alert(document.newsletter.operazioneSI.checked + ' ' + document.newsletter.operazioneNO.checked);
	if(document.all){
		email=Trim(document.newsletter.email.value);
	}
	if(document.getElementById){
		email=Trim(document.getElementById('email').value);
	}
	if(email!=''){		
		if(checkEmail(email)==0){
			document.newsletter.submit();	
		}
		else{
			alert("Attenzione controllare l\'indirizzo email");
		}
	} 
	else{
		alert("Attenzione controllare l\'indirizzo email");
	}
}


function checkUsername(strUsername){
	
	objUsername = new String(strUsername);
	var controlloUsername = objUsername.match(/^\w+$/);

	if (controlloUsername){
		controlloUsername = 0; //nessun errore
		}
	else{
		controlloUsername = 1; // errore
	}
	
	return controlloUsername;
	
}
