<!-- Asset Reference Lookup Window Opener
lookupWindow = null;
textArea = null;
referenceFormat = null;
appendValue = false;
// Called from getAssetReference
function openAssetLookupWindow(url_to_open) {
  // Do the opening
  width = 660;
  height = 400;
  leftPos = (screen.width - width) / 2;
  topPos = (screen.height - height) / 2;
  aspects = 'toolbar=yes,status=yes,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left='+leftPos+',top='+topPos;
  lookupWindow = window.open(
    url_to_open, 'AssetLookupWindow', aspects);
  lookupWindow.focus();
}
// Called from "pagetemplate"
function getAssetReference(url, format, form, element, append) {
  // Store reference to focused text area
  referenceFormat = format;
  doc = document.all ? document.all : document;
  textArea = eval('doc.'+form+'.'+element);
  if (append)
    appendValue = true;
  // Open LookupWindow
  openAssetLookupWindow(url);
}
// Called from "asset lookup window"
function insertAssetReference(id, reference, wndw) {
  // Append to previously focused text area
  // FIXME: We'd like to make it work with selections in
  // the textarea.
  append_text = referenceFormat.replace('_id_', id).replace('_reference_', reference);
  if (appendValue)
    append_text = textArea.value + append_text;
  textArea.value = append_text;
  textArea.focus();
  // Close LookupWindow
  wndw.close();
}
//-->
