I am currently looking for a script that can append a parameter (keyword, medium, source) dynamically using cookies to the end of my CJ, Linkshare, and Performics affiliate links (sid=,mid=,u1=)

It would be really nice, if it were possible to append a whole referring url to the end of the affiliate links. I am about to hunt down a few programmers on some of the freelance boards, but thought I would drop by and see if anyone knew how to do this and if there was a free script out there that would accomplish this feat.