Three things to note:
1) The tension on the block that is hanging is equal to the tension on the block on the horizontal surface.
2) When you choose your coordinate systems for each Free-Body diagram, always choose one of the positive directions in the direction of the acceleration of the blocks. This will save you enormous troubles with negative signs. (You do realize the acceleration of both blocks has the same magnitude, right?)
3) When you take the sum of forces you are doing it only for the FBD under consideration. So only use the forces in that FBD. Also the mass is the mass of the object in the FBD, not the total mass.
You will wind up with a system of equations to solve.