var caratteri_alias_luogo = /^[a-zA-Z0-9\ \'\-\_אטילעשח]+$/;
var caratteri_nome_cognome = /^[a-zA-Zaטילעשח\ \']+$/;
var caratteri_nickname = /^[a-zA-Z\_\-\.\ ]+$/;


function controlla_alias_luogo (evento)
 {
	 if (evento.keyCode == 13 || evento.keyCode == 16 || evento.keyCode == 18 || evento.keyCode == 8) return (true);
	 codice = (navigator.appName != "Microsoft Internet Explorer")?evento.which:evento.keyCode;
	 carattere = String.fromCharCode(codice);

	 if (!carattere.match(caratteri_alias_luogo))  return(false);
	 
	 return (true);
 }

function is_nick_valido (elemento)
 {
	 var re = /^[a-zA-Z][a-zA-Z0-9]{3,9}$/;
	 
	 //alert(re);
	 if (elemento.match(re)) return true;
	 return false;
 }

function controlla_text_alias_luogo(alias_luogo, msg)
 {
	 if (alias_luogo.match(caratteri_alias_luogo)) return (true);
	 
	 //alert("Alias o nome luogo non corretti");
	 alert(msg);
	 return (false);
 }
 
 
 
function isEMailAddr(elem) {
    var str = elem;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}


function isAlfaNumeric(elem) {
    var str = elem;
    var re = /^[a-zA-Z0-9]+$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}

function isNumeric(elem) {
    var str = elem;
    var re = /^[0-9]+$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}

function isAlfabetic(elem) {
    var str = elem;
    var re = /^[a-zA-Zaטילעשח\ \']+$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}


function Trim(StrToTrim)
{
    // CONTROLLA CHE IL VALORE IN INPUT SIA DI TIPO STRING
    if (typeof StrToTrim != "string")
    {
        return StrToTrim;
    }

    // CATTURA IL PRIMO CARATTERE DELLA STRINGA PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO
    var StrBlank = StrToTrim.substring(0, 1);

    // ELIMINA LO SPAZIO VUOTO DALLA PRIMA POSIZIONE DELLA STRINGA
    while (StrBlank == " ")
    {
        StrToTrim = StrToTrim.substring(1, StrToTrim.length);
        StrBlank = StrToTrim.substring(0, 1);
    }

    // CATTURA L'ULTIMO CARATTERE DELLA STRINGA PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO
    StrBlank = StrToTrim.substring(StrToTrim.length - 1, StrToTrim.length);

    // ELIMINA LO SPAZIO VUOTO DALL'ULTIMA POSIZIONE DELLA STRINGA
    while (StrBlank == " ")
    {
        StrToTrim = StrToTrim.substring(0, StrToTrim.length-1);
        StrBlank = StrToTrim.substring(StrToTrim.length-1, StrToTrim.length);
    }

    // ELIMINA POTENZIALI SPAZI VUOTI MULTIPLI ALL'INIZIO ED ALLA FINE DI UNA STRINGA
    while (StrToTrim.indexOf("  ") != -1)
    {
        StrToTrim = StrToTrim.substring(0, StrToTrim.indexOf("  "));
        StrToTrim += StrToTrim.substring(StrToTrim.indexOf("  ") + 1, StrToTrim.length);
    }

    // RESTITUISCE IL VALORE FINALE SENZA SPAZI VUOTI DI CONTORNO
    return StrToTrim;
}

function controlla_campo_numerico (evento, msg)
{
	var valore = (evento.which == undefined)?evento.keyCode:evento.which;

	if (valore == 0)  return (true);
	if (valore == 8)  return (true);
	if (valore == 13) return (true);

	carattere = String.fromCharCode(valore);

	var num_char = 1;
	str_numerica = /^[\d]{1}$/;	//indica tutti e soli i valori numerici
	
	if (!str_numerica.test(carattere))
		{
			if (msg!="") alert(msg);
			return (false);
		}
		
	return (true); 
}