Did you see Joerg's answer in you other e-mail? If you manage to have both data sets on the same grid, this should be easy enough to go from there.
About the masking, you would need to do something like:
(assuming you have topography variable called "topo")
let mask1 = IF (topo GE 0 AND topo LT 100) THEN 1 else 1/0
let mask2 = IF (topo GE 100 AND topo LT 500) THEN 1 else 1/0
Then you need to create a new variable containing only the data in the level you want:
(assuming a variable called "rain")
let rain_100 = rain * mask1
let rain_500 = rain * mask2
Now all you need to do is compute your average anyway you want.
Let me know if you have more questions.
Best regards,
Andre