Help my tooltip goes off edge of screen

hi everyone

I have a tooltip that follows the mouse, but i need to to figure out where the edges of the screen are and always keep the tootip on the screen. Its something to do with screen width and height but i cant figure it out .

If anyone can help i`d be greatful

cheers

kippereye