Merging some scripts from the forums , first pass