sorry trovato l'errore

var est = nom.substr(nom.length-4);

non

var est = nom.substr(est.length-4);


ora provo poi ico grazie!