Welcome to WebmasterWorld Guest from 18.104.22.168
I would start by reading any thread in this forum. This forum is, after all, about Affiliate Programs.
The other thing you could try is reading the "library", which is a list of particularly interesting threads, most of which having to do with affiliate programs.
Also, you could do a search on google for "Affiliate Program Script" or something similar.