I am adding onMouseOver and onMouseOut for the browser status to some hrefs. These hrefs are already being printed by Javascript due to a Javascript array size that is being checked.

My problem is that the following PHP code causes a Javascript error within the onMouseOut attribute of '':
---------------------------------------------
<?
$href = "message.php3?UserLoggedIn=$default->UserLoggedIn&mailbox=" . urlencode($mailbox) . "&array_index=$next_index&index=" ;
$img = "<img src="$default->graphics_url/next.gif" width="12" height="12" alt="$lang->next" border="0"></a>" ;
$img_grey = "<img src="$default->graphics_url/next-grey.gif" width="12" height="12" alt="" border="0">" ;
echo "<script language=javascript>n" ;
echo " if ($next_index < window.top.sorted.length) {n" ;
echo " document.write('<a href="" . $href . "' + window.top.sorted[$next_index] + '">');";
echo " onMouseOver="status='" . $lang->next . "'; return true;" onMouseOut="status='';">n" ;
echo " document.write('$img')n" ;
echo " } else {n" ;
echo " document.write('$img_grey')n" ;
echo " }n" ;
echo "</script>n" ;
?>
---------------------------------------------

I've tried to work this a dozen different ways, but because I'm using a Javascript if,else condition, the variation is limited.

(Message cross-posted in the PHP forum.)
Thanks,
Bruce