I didn't look at your code yet, but you might want to see others' work before you start your own...
http://www.mircscripts.org/archive.php?s...;amp;perpage=20