Since the document knows which object has Focus already, you just need to add an onFocus handler to form elements, images, and/or links. Now when something on the page gets the focus it will call a javascript function and can even send information to that function as in the simple example below:
<html>
<head>
<script language="JavaScript" type="text/javascript">
function whichOne(fName) {
alert(fName)
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="text1" onFocus="whichOne('The Focus is on form1.text1')"><br>
<input type="text" name="text2" onFocus="whichOne('The Focus is on form1.text2')"><br>
<input type="text" name="text3" onFocus="whichOne('The Focus is on form1.text3')"><br>
<input type="text" name="text4" onFocus="whichOne('The Focus is on form1.text4')">
</form>
</body>
</html>