Ah scusa... non avevo capito!
In effetti il codice che hai postato è molto simile a quello allegato.