function WaitForClick(window,message,textColor,bgColor,x)
% WaitForClick(window,message,textColor,bgColor,[x])
%
% WaitForClick is OBSOLETE. Use Ask instead.
%
% Draw the message right-justified in the upper right of the window, wait
% for a mouse click, then erase and exit. If arg "x" is present, then
% string is drawn at that x location.

% 2/4/97  dhb	Wrote it.
% 2/27/97 dgp	Updated, twice
% 3/5/97  dhb	Allow optional onRightInstead arg.
% 3/9/97  dgp	Use AlignRect. Rename "onRightInstead" to "x". Drop x==0 test.
% 5/29/97 dgp	Don't set font.
% 2/14/98 dgp	Changed misleading "screen", throughout, to "window".

windowRect=Screen(window,'Rect');
height=Screen(window,'TextWidth','x'); % estimate x-height by width of "x".
width=Screen(window,'TextWidth',[message 'xx']);
r=[0 0 width 3*height+30];
if nargin>4
	r=OffsetRect(r,x,0);
	r=AlignRect(r,windowRect,RectTop);
else
	r=AlignRect(r,windowRect,RectRight,RectTop);
end
Screen(window,'DrawText',message,r(RectLeft),r(RectBottom),textColor);
GetClicks;
Screen(window,'DrawText',message,r(RectLeft),r(RectBottom),bgColor);
