on PrepareMovie
  set the text of field "search_fld" to "Searchstring"
  set the keyDownScript to "CatchKey"
end PrepareMovie


on CatchKey
  if the key = RETURN then
    DeadWindow(1)
  end if
end CatchKey


on closeWindow
  set the keyDownScript to EMPTY
  MyWinClose()
end closeWindow


on DeadWindow wichOne
  Global gSearchOption,gWinObj
  
  set gSearchOption = wichOne
  
  if voidP(gWinObj) or gWinObj = EMPTY then
    close window 1
  else
    close window 2
  end if
end DeadWindow


on MyWinClose
  Global gWinObj,gSearchOption
  
  set mySearchStr = the text of field "search_fld"
  
  if voidP(gWinObj) or gWinObj = EMPTY then
    if gSearchOption = 1 then
      tell the stage to CloseFind(mySearchStr)
    else
      tell the stage to CloseFind("")
    end if
  else
    if gSearchOption = 1 then
      mTalkToMe(gWinObj,"CloseFind(" & numToChar(34) & mySearchStr & numToChar(34) & ")")
    else
      mTalkToMe(gWinObj,"CloseFind(" & numToChar(34) && numToChar(34) & ")")
    end if
  end if
end MyWinClose
