Find the place of a cursor in rectangle

What I think is the easiest way is to first normalize y so the computation is the same as for a square and then check for on which side of the diagonals you are...

var ynorm = y * w / h;
var s1 = x > ynorm ? 0 : 1;
var s2 = (w - x) > ynorm ? 0 : 1;
var area = s1*2 + s2;

the final area variable is a number between 0 and 3 telling in which of the four parts you are.