function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function checkAccessForm(){
	var minLen;
	minLen = 2;
	if (document.go_login.username.value.length < minLen) {
		alert("The field 'Username' is required!");
		document.go_login.username.focus();
		return false;
	}
	if (document.go_login.password.value.length < minLen) {
		alert("The field 'Password' is required!");
		document.go_login.password.focus();
		return false;
	}
	
	document.go_login.submit();	
}

function checkChangePassword(){
	var minLen = 6;
	if (document.change_pass.old_password.value.length < minLen) {
		alert("The field 'Old Password' must contain at least 6 characters!");
		document.change_pass.old_password.focus();
		return false;
	}
	
	if (document.change_pass.new_password.value.length < minLen) {
		alert("The field 'New Password' must contain at least 6 characters!");
		document.change_pass.new_password.focus();
		return false;
	}
	
	if (document.change_pass.new_password_ret.value.length < minLen) {
		alert("The field 'Retype New Password' must contain at least 6 characters!");
		document.change_pass.new_password_ret.focus();
		return false;
	}
	
	if (document.change_pass.new_password.value != document.change_pass.new_password_ret.value) {
		alert("The value of the field 'New Password' is not equal to the value of the field 'Retype New Password'!");
		document.change_pass.new_password.focus();
		return false;
	}
	
	document.change_pass.submit();
}

function checkFormCareers(){
	modulo = document.manage_careers;
	full_name = trim(modulo.full_name.value);
	email = trim(modulo.email.value);
	cv = trim(modulo.cv.value);
	security_code = trim(modulo.security_code.value);

	
	if(full_name == ""){
		alert ("The field \"Full name\" are required!");
		modulo.full_name.focus();
		return false;	
	}
	
	if(email == ""){
		alert ("The field \"Email\" are required!");
		modulo.email.focus();
		return false;	
	}
	if(cv == ""){
		alert ("The field \"CV\" are required!");
		modulo.cv.focus();
		return false;	
	}
	
	if(security_code == ""){
		alert ("The field \"Security Code\" are required!");
		modulo.security_code.focus();
		return false;	
	}
	
	modulo.submit();	
}

function checkFormContacts(){
	modulo = document.manage_contacts;
	nome = trim(modulo.nome.value);
	cognome = trim(modulo.cognome.value);
	email = trim(modulo.email.value);
	oggetto = trim(modulo.oggetto.value);
	messaggio = trim(modulo.messaggio.value);
	security_code = trim(modulo.security_code.value);
	
	if(nome == ""){
		alert ("Il campo 'Nome' è obbligatorio!");
		modulo.nome.focus();
		return false;	
	}
	
	if(cognome == ""){
		alert ("Il campo 'Cognome' è obbligatorio!");
		modulo.cognome.focus();
		return false;	
	}
	
	if(email == ""){
		alert ("Il campo 'Email' è obbligatorio!");
		modulo.email.focus();
		return false;	
	}
	
	if(oggetto == ""){
		alert ("Il campo 'Oggetto' è obbligatorio!");
		modulo.oggetto.focus();
		return false;	
	}
	
	if(messaggio == ""){
		alert ("Il campo 'Messaggio' è obbligatorio!");
		modulo.messaggio.focus();
		return false;	
	}
	
	if(security_code == ""){
		alert ("The field \"Security Code\" are required!");
		modulo.security_code.focus();
		return false;	
	}
	
	modulo.submit();	
}