function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}
function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function checkMail(addr)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(trimAll(addr));
}

function campusModuloLoadPersona()
{
	var selectPersonaIdTic = document.getElementById('selectPersonaIdTic').value;
	
	if (selectPersonaIdTic != '')
	{
		var req = new JSHttpRequest();
		req.caching = false; // Disabilito CACHING, non so come funziona :-)
		req.open('GET', 'campus_modulo_load_persona.php', true);
		req.send({ id_tic: selectPersonaIdTic });		
		
		req.onreadystatechange = function() 
		{
			if (req.readyState == 4) 
			{
				document.getElementById('nome').value = req.responseJS.nome;
				document.getElementById('cognome').value = req.responseJS.cognome;
				document.getElementById('telefono').value = req.responseJS.telefono;
				document.getElementById('email').value = req.responseJS.email;
				
				document.getElementById('struttura').value = req.responseJS.struttura;
				document.getElementById('via').value = req.responseJS.via;
				document.getElementById('ufficio').value = req.responseJS.ufficio;
				document.getElementById('piano').value = req.responseJS.piano;
				document.getElementById('stanza').value = req.responseJS.stanza;
			}
		}
	}	
}
