You could also check out this thread:
That might have what you want if you are looking for PHP rather than JS.