Toyota Repair: Check engine light code p0505, o2 sensors, jap motor


Question
I have a 1999 Rav4 4x4 auto Vin#JT3HP10V2X7124339 **Over 200K***
I had the motor swapped because I loaned it to my friend and she never changed the oil!
PS.  The motor was replaced, but because money was tight at the time the garage gave me a tow and go special without any trace.  I can't tell what kind of motor's in the unit!  It just starts when I turn the key, but has never been the same!
The Check Engine light has been on, and I have replaced the following already, new IAC, EGR valves, both O2 sensors and cleared the code.  It Idles and drives for about 30 minutes, the the light comes back on!  All wires and hoses are ok!  The Rav still idles rough, and at times bogs upon power take off!  My question is:  Is it possible that I could have gotten the wrong motor swap?  Will a Federal or Jap motor still run in a CA Rav with a CA computer!  Is it possible that the motor is a dude, and I got scammed?  I have taken it to every wise man in NJ and the last one told me it needs a new computer @ $1400 bill!  I don't have money like that right now, and I'm trying to figure out what to do!  Or can my computer be rebuilt?  Nothing I have done will get the light to go out!  Any help would be greatly appreciated!
Tnanks

Answer
The computer is usually the last thing to suspect.The p0505 code is an idle air control malfunction, it should be checked to make sure the electrical connector is connected properly first. If the engine that was installed was only the long block, that is, the block with the cylinder head then it will work in a CA certified car. The wiring between the IAC valve and the computer should be checked since the valve ws already replaced, if the wiring between the two is good then the problem may very well be the computer.