<dtml-if "fieldName == REQUEST.get('reference_focus', None)">
<!--
function focusOnReferenceField() {
  document.getElementById('<dtml-var fieldName>_link').focus();
}

// I think "unRegisterPloneFunction" should live in plone_ecmascripts/plone_javascripts.js. what do you think?
function unRegisterPloneFunction(func){
    // uregisters a previous function to fire onload. 
    if (window.removeEventListener) window.removeEventListener("load",func,false);
    else if (window.detachEvent) window.detachEvent("onload",func);   
  }

unRegisterPloneFunction(setFocus);
jQuery(focusOnReferenceField);
-->
</dtml-if>
