Kind of straying away from the topic of JavaScript, but hopefully nobody minds. I think you'll want to look at this page. Only problem I could foresee is that the HTTP_REFERER header isn't always reliable (depends on the client's browser). Are you able to make use of PHP or another server-side language? If so, I'll gladly help if you want to post a new thread in the appropriate forum topic.