This first started after an alternator problem. While driving, I noticed that the battery light was on and I was losing power to all electrical systems. By the time I got to the shop the car was barely drivable; It wouldn't shift gears, it was revving up and down randomly, lights and turn signals were not working correctly, and so on.. After we replaced the alternator I first thought that all of the problems were fixed. However, after about 1 minute of driving, the car would idle dangerously low while waiting at intersections and occasionally stall. After a cold start in the morning, it would run fine for about 2 minutes until it warmed up, and then the problems would start again. Symptoms are almost identical to those in this post: http://repairpal.com/rough-idle-bad-hesitation-on-acceleration-perfect-idle-with-tps-disconnected-614
That problem was solved by replacing the distributor cap. However, to my (very limited) knowledge, the 99 Mazda protege does not have a distributor. Please correct me if I'm wrong, but if I am not, I have no clue where to start.