-- commonMovieScript
-----------------------------------
-- CREATED:
--              11.02.2008
--
-- DESCRIPTION:      
--              Shared Global Handlers c03 Alex da Franca -- alex@farbflash.de
--              -------------------------------------------------------------------
--              these handlers are shared between all of my scripts Alex da Franca c2003 alex@farbflash.de
--              for private use of my scripts -> poor documentation -> use at own risk ;-)

-- HISTORY:
--              geaendert am 21.06.03
--              mGetInstance 0 -- clears all stored instances -> same as recompile all scripts, but that would clear all contents of (script "commonMovieScript").pGList
--              mApplyDynamic

--              alex am 13.03.2004 um 13:49
--              added DEBUG_FUNCTIONS

--              alex am 15.03.2004 um 08:50
--              added mGetPlatform() to get OSX
--              alex am 31.03.2004 um 11:42
--              added clearglobals to mDestroy handler

--              added support for new director MX2004 sprite names in my handlers by changing mGetKanal() to accept strings

--              alex am Freitag, 4. Juni 2004
--              took care about missing font asset xtra, if it isn't present, we'll get not a script error anymore
--              but rather the presence of the font is not checked instead, but rather assumed

--              alex am 16. Juni 2004 um 10:12
--              added mGetNextLowerPowerOfTwo

--              alex am 18. Juli 2004 um 08:02
--              added mMyClearGlobals() to erase the faked globals and get the new globallist

--              alex am 8. Oktober 2004 um 10:31
--              new tempmember handling due to a bug in director

--              alex am 23. November 2004 um 10:59
--              added mGetThisMovieName() and mSetThisMovieName() to identify the movie independant of the filename
--              this is needed for some places, where the standard scripts act differently in the different movies

--              Scriptmarker (21.07.2005 at 11:55 Uhr): changes // Scriptmarker
--              added mSplitPath

--
-- WARNINGS:
--              IMPORTANT NOTE !!
--              if you use my scripts you MUST call 'mCallDestroy()' at stopmovie in order to clean up temporary members used by my scripts
--              due to a bug in director I had to change the old behaavior of erasing the members on endsprite, when I was done with it !
--              so now I use a list of temporary members, which is maintained during runtime, but must be processed when the movie is stopped
--              (unless you want to fill up your castlib with temporary members :-)

--              If this script is NOT the first moviescript in your movie containing a stopmovie handler this one gets overriddden and
--              you must call 'mCallDestroy()' in your stopmovie handler.
--              otherwise when it this script comes before your script with the stopmovie handler your handler will never be called
--              since the stopmovie event is caught here...
--              in that case just comment it out here and add the 'mCallDestroy()' to your own stopmovie handler

--              on stopmovie me
--              mCallDestroy
--              end
-- TODO:
--              -
-----------------------------------

on _____________________PROPERTY_DECLARATION me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
property ancestor
property pGList
property pCaseLists


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ___________________STANDARD_EVENTS me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on new me
  Script_Root_Object = member("Script_Root_Object")
  if ilk(Script_Root_Object) = #member then
    if Script_Root_Object.type = #script then
      ancestor = new(script "Script_Root_Object")
      mSetScriptName me, "commonMovieScript"
    end if
  end if
  return me
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mFilterString me, string_Input, string_keyword
  -----------------------------------
  -- CREATED: 26.02.2010
  -- ACTION: Filter to constrain the results
  --                       use "%" or "^" as the first char if the filter shall be =>
  --                                                     'word STARTS with <string_keyword>'
  --                       use "$" as the last char if the filter shall be =>
  --                                                     'word ENDS with <string_keyword>'
  --                       (HINT: if searching for the exact phrase use ^keyword$ as filter)
  --                       otherwise the string <string_keyword> may appear anywhere in the word =>
  --                                                     'word CONTAINS <string_keyword>'
  -- INPUT: <string_Input> ; string
  --        <string_keyword> ; string
  -- RETURNS: boolean (integer 1 or 0) ; true or false
  -- EXAMPLE: put xscr().mFilterString("commonmoviescript", "%comm") -- STARTS
  --          -- 1
  --          put xscr().mFilterString("commonmoviescript", "ript$")
  --          -- 1
  --          put xscr().mFilterString("commonmoviescript", "%commonmoviescript$")
  --          -- 1
  --          put xscr().mFilterString("commonmoviescript", "movie")
  --          -- 1
  -----------------------------------
  
  string_Input = string(string_Input)
  if length(string_Input) < 1 then return 0
  
  string_keyword = string(string_keyword)
  if length(string_keyword) < 1 then return 1
  
  if string_keyword starts "^" then
    delete char 1 of string_keyword
    offs = offset(string_keyword, string_Input)
    return (offs = 1)
  else if string_keyword starts "%" then
    delete char 1 of string_keyword
    offs = offset(string_keyword, string_Input)
    return (offs = 1)
  else if the last char of string_keyword = "$" then
    delete the last char of string_keyword
    offs = offset(string_keyword, string_Input)
    return (offs = (length(string_Input) - length(string_keyword) + 1))
  else
    offs = offset(string_keyword, string_Input)
    return (offs > 0)
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetGlobalList me
  -----------------------------------
  --         ACTION: We keep a list of "faked global variables"
  --                 Using real global variables has the drawback,
  --                 that they may clash with the host movies globals
  --                 and even worse: all movie instances running in the same player
  --                 instance -> MIAWs share only one global space
  --                 Since these scripts are also used in my authoring tools
  --                 they can behave nicely, if running as miaws in any environment
  --         INPUT: -
  --         RETURNS: property list with global variables
  --         NOTES: If possible only use the set and get handlers (mSetGlobalValue, mGetGlobalValue)
  -----------------------------------
  
  if voidP(pGList) then
    pGList = [:]
    scr = mGetXScript(#regisx)
    if not listP(scr) then
      if mCheckForXtra(me, "BudAPI") = 1 then call(#regisb, scr)
      if mCheckForXtra(me, "vList") = 1 then call(#regisv, scr)
    end if
  end if
  return pGList
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMyClearGlobals me
  -----------------------------------
  --         CREATED: 11.02.2008
  --         ACTION: Clear the global list at runtime (at authortime a "Recompile all scripts" does the same)
  --                 See description for "Faked globals" at handler [#mGetGlobalList_commonMovieScript mGetGlobalList]
  --         INPUT: -
  --         RETURNS: -
  -----------------------------------
  
  pGList = [:]
  return pGList
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetGlobalValue me, propName, newValue
  -----------------------------------
  --         ACTION: Set the value for a "global" variable
  --                 If the "global" with the name #propname doesn't exits it gets created
  
  --                 Interface to the "private globals" stored in this uninstatiated script as property
  --                 See description for "Faked globals" at handler [#mGetGlobalList_commonMovieScript mGetGlobalList]
  
  --         INPUT: propName: symbol; name of global value
  --                newValue: any value
  --         RETURNS: -
  -----------------------------------
  
  g = mGetGlobalList(me)
  g.setaprop(propName, newValue)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetGlobalValue me, propName
  -----------------------------------
  --         ACTION: Get the value for a "global" variable
  --                 If the "global" with the name #propname doesn't exits it returns void
  
  --                 Interface to the "private globals" stored in this uninstatiated script as property
  --                 See description for "Faked globals" at handler [#mGetGlobalList_commonMovieScript mGetGlobalList]
  
  --         INPUT: propName: symbol; name of global value
  --         RETURNS: -
  -----------------------------------
  
  g = mGetGlobalList(me)
  return g.getaprop(propName)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCallDestroy me
  -----------------------------------
  --         CREATED: 12.02.2008
  --         ACTION: Call to clean everything up on stopmovie
  --         INPUT: -
  --         RETURNS: -
  -----------------------------------
  
  delayedCallBackList = mGetGlobalValue(me, #delayedCallBackList)
  if ilk(delayedCallBackList) = #proplist then
    jobs = delayedCallBackList[#jobs]
    repeat with n = count(jobs) down to 1
      toName = jobs.getPropAt(n)
      dto = timeout(toName)
      if ilk(dto) = #timeout then dto.forget()
    end repeat
    delayedCallBackList[#jobs] = [:]
  end if
  
  sendAllSprites(#mStopMovieWasCalled)
  
  theGlobs = mGetGlobalList(me)
  gParentScriptInstances = theGlobs.getaprop(#gParentScriptInstances)
  
  if listP(gParentScriptInstances) then call(#mDestroy, gParentScriptInstances)
  
  
  --------------- some instances in the actorlist delete other instances from the actorlist
  --------------- therefore, we can't simply repeat through all, we need a duplicate
  --------------- the same is true for the timeoutlist
  
  lists = [the actorList, the timeoutlist]
  repeat with theList in lists
    dupL = []
    repeat with obj in theList
      add dupL, obj
    end repeat
    cnt = count(dupL)
    repeat with n = cnt down to 1
      call(#mDestroy, [dupL[n]])
    end repeat
  end repeat
  
  
  
  f = member("debuginfotextmember")
  if mGetMemType(me, f) = #field then f.text = ""
  
  theGlobs[#gParentScriptInstances] = [:]
  
  mEraseAllTempMembers me
  
  --  clearglobals
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetPlayBackModeValue me, symbol_Prop
  if ilk(symbol_Prop) <> #symbol then symbol_Prop = #playBackMode
  playBackModeValueList = mGetGlobalValue(me, #playBackModeValueList)
  if not(objectP(playBackModeValueList)) then playBackModeValueList = [:]
  return playBackModeValueList[symbol_Prop]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetPlayBackModeValue me, symbol_Prop, any_value
  if ilk(symbol_Prop) <> #symbol then exit
  playBackModeValueList = mGetGlobalValue(me, #playBackModeValueList)
  if not(objectP(playBackModeValueList)) then
    playBackModeValueList = [:]
    mSetGlobalValue(me, #playBackModeValueList, playBackModeValueList)
  end if
  playBackModeValueList[symbol_Prop] = any_value
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____WOODY_CHANGES
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx color( -> rgb(
-- 

on Authoring_ExchangeScriptListColorsToRGBs me
  -----------------------------------
  --         CREATED: 12.02.2008
  --         ACTION: fix the score data which has #color instead of #rgb when authored with D10
  --                 which fails with the older player (AUTHORING ONLY!)
  --         INPUT: -
  --         RETURNS: -
  -----------------------------------
  
  theLastFrame = the lastFrame
  theLastChannel = the lastChannel
  
  repeat with theFrame = 1 to theLastFrame
    go to theFrame
    
    repeat with theSprite = 1 to theLastChannel
      tScriptList = sprite(theSprite).scriptList
      if listP(tScriptList) then
        cnt = count(tScriptList)
        doChange = 0
        
        repeat with behNr = 1 to cnt
          thisBeh = tScriptList[behNr]
          if stringP(thisBeh[2]) then
            tString = thisBeh[2]
            offs = offset("color(", tString)
            repeat while offs > 0 
              doChange = 1
              put "rgb(" into char offs to (offs+5) of tString
              offs = offset("color(", tString)
            end repeat
            thisBeh[2] = tString
          end if
        end repeat
        
        if doChange then
          sprite(theSprite).setScriptList(tScriptList)
        end if
      end if
    end repeat
    
  end repeat
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCheckWoody me
  glob = mGetGlobalList(me)
  woody = glob.getaprop(#gWoody)
  if voidP(woody) then
    prodVers = the productVersion
    offs = offset(".", prodVers)
    if offs > 0 then prodVers = char 1 to offs-1 of prodVers
    prodVers = integer(prodVers)
    if prodVers >= 10 then woody = 1
    else woody = 0
    glob[#gWoody] = woody
  end if
  return woody
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetVersionNumber me
  -----------------------------------
  --         CREATED: 12.02.2008
  --         ACTION: Get player veersion number as float, so that proper maths can be made
  --         INPUT: -
  --         RETURNS: float => director player version number
  -----------------------------------
  
  glob = mGetGlobalList(me)
  vNum = glob.getaprop(#gVersionNumber)
  if voidP(vNum) then
    prodVers = the productVersion
    vNum = mGetFloatVersionNumber(me, prodVers)
    glob[#gVersionNumber] = vNum
  end if
  
  return vNum
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetFloatVersionNumber me, prodVers
  offs = offset(".", prodVers)
  if offs > 0 then
    intVers = char 1 to offs of prodVers
    delete char 1 to offs of prodVers
  else
    intVers = ""
  end if
  cnt = length(prodVers)
  repeat with n = 1 to cnt
    c = prodVers.char[n]
    if integerP(integer(c)) then
      put c after intVers
    else if c <> "." then
      exit repeat
    end if
  end repeat
  
  return value(intVers)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mIsAtLeastVersionOf me, proplist_or_number_productVersionInfo
  -----------------------------------
  --         CREATED: 08.02.2011
  --         ACTION: Check whether player version number and productbuildversion
  --                 meet at least a certain value
  --         INPUT: <proplist_or_number_productVersionInfo> ; proplist or number ; if number: =>
  --                                                             at least version xy
  --                             if proplist then at least version productVersionInfo[#versionNumber] => #number
  --                                  AND (if defined) productVersionInfo[#buildnumber] => number
  --         RETURNS: boolean (integer) => true if current version is at least the specified version or higher
  -----------------------------------
  
  if ilk(proplist_or_number_productVersionInfo) = #proplist then
    versionNumber = proplist_or_number_productVersionInfo[#versionNumber]
    buildnumber = proplist_or_number_productVersionInfo[#buildnumber]
  else
    versionNumber = proplist_or_number_productVersionInfo
    buildnumber = 0
  end if
  
  if ilk(versionNumber, #number) <> 1 then versionNumber = 0 -- in dubio pro reo
  if ilk(buildnumber, #number) <> 1 then buildnumber = 0 -- in dubio pro reo
  
  currVersion = mGetVersionNumber(me)
  
  if currVersion > versionNumber then return true
  if currVersion < versionNumber then return false
  
  env = mGetEnvironment(me)
  currentBuildNumber = integer(env[#productBuildVersion])
  if buildnumber > currentBuildNumber then return false
  return true
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetEnvironment me
  -----------------------------------
  --         CREATED: 18.05.2009
  --         ACTION: Getting the environment properts list is very slow,
  --                 therefore we make sure to get it only once and store the rsult
  --         INPUT: -
  --         RETURNS: property list => the environment
  -----------------------------------
  
  env = mGetGlobalValue(me, #theEnvironment)
  if not(objectP(env)) then
    
    if the runmode contains "aut" then
      -- there is a really lame bug in the mac version
      -- where querying the environment takes ages!
      -- now it is only the first call, therefore we save the result
      -- and in authoring we even save it in a global, so that we
      -- do not have to wait on each moviestart!
      global gLameAuthoringHack_forSlowEnvironment_onMac
      if not(objectP(gLameAuthoringHack_forSlowEnvironment_onMac)) then
        gLameAuthoringHack_forSlowEnvironment_onMac = the environment
      end if
      env = gLameAuthoringHack_forSlowEnvironment_onMac
    else
      env = the environment
    end if
    
    mSetGlobalValue(me, #theEnvironment, env)
  end if
  return env
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetPlatform me
  -----------------------------------
  --         CREATED: 12.02.2008
  --         ACTION: Get the platform as symbol
  --                 the advantage is that the result is cached in the global list
  --                 and the distinction between OS9 and OSX is made
  --         INPUT: -
  --         RETURNS: symbol => platform identifier; range: #os9, #osx, #win
  -----------------------------------
  
  glob = mGetGlobalList(me)
  gPlatform = glob.getaprop(#gPlatform)
  
  if voidP(gPlatform) then
    
    isMac = the platform contains "Macintosh"
    if isMac then
      
      onX = value(char 1 of (the last word of (mGetEnvironment(me)).osversion)) <= 5
      if onX then gPlatform = #osx
      else gPlatform = #os9
    else
      gPlatform = #win
    end if
    
    glob.setaprop(#gPlatform, gPlatform)
  end if
  
  return gPlatform
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCheckMemberType me, memref, aType
  -----------------------------------
  --         CREATED: 12.02.2008
  --         ACTION: Check if the member reference <memref> is of type <aType>
  --                 This handler works in D<10 and D>=10
  --         INPUT: member reference
  --                symbol
  --         RETURNS: boolean (integer)
  -----------------------------------
  
  if voidP(memref) then return 0
  return (memref.type = aType)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetMemType me, memref
  -----------------------------------
  --         CREATED: 12.02.2008
  --         ACTION: Return the type of member <memref>
  --                 This handler works in D<10 and D>=10
  --                 If memref is not a valid member this handler returns #empty, like D<10 used to
  --         INPUT: member reference
  --         RETURNS: symbol => member type; range: every member type and #empty
  -----------------------------------
  if ilk(memref) <> #member then return #empty
  return memref.type
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCreateTimeout me, theName, theDuration, theHandler, theTarget
  -----------------------------------
  --         CREATED: 12.02.2008
  --         ACTION: Create/Get timeout object
  --                 This handler works the same with the old player <10 and the new player >=10
  --         INPUT: || theName     || string  || name for new timeout object||
  --                || theDuration || integer || timeout perios in milliseconds||
  --                || theHandler  || symbol  || handler to be called on each timepout event||
  --                || theTarget   || object  || object to be sent the timeout event <theHandler>||
  --         RETURNS: timeout object
  -----------------------------------
  
  dto = timeout(theName)
  
  if ilk(dto) = #timeout then return dto.new(theDuration, theHandler, theTarget)
  
  return timeout().new(theName, theDuration, theHandler, theTarget)
  
  
  if mCheckWoody(me) = 1 then
    return timeout().new(theName, theDuration, theHandler, theTarget)
  else
    return timeout(theName).new(theDuration, theHandler, theTarget)
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____HANDLE_KEY_EVENTS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- this handler is supposed to get keyevents first to decide, if there are high level things to do

-- for example to quit the movie
-- some of my scripts use the keydownscript to get keyevents
-- and they call this handler first to give some keyevents precedence

on mHandleKeyEvent me, tk, kc
  
  theGlobs = mGetGlobalList(me)
  if theGlobs.getaprop(#gCustomKeyHandling) = 1 then return mProcessKeyDownEvent(tk, kc)
  
  retval = 0
  
  if (the exitlock = 1) then
    if the commanddown then
      case kc of
        12, 47:
          retval = 1
          dto = mCreateTimeout(me, "quitTimeOut", 100, #mDoQuit, me)
        otherwise
          if ((tk = "q") or (tk = ".")) then
            retval = 1
            dto = mCreateTimeout(me, "quitTimeOut", 100, #mDoQuit, me)
          end if
      end case
    end if
    
  end if
  
  
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSuspendAllKeyEvents me, flag
  sendAllSprites(#mSuspendKeyEvents, flag)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSuspendAllMouseEvents me, flag
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDoQuit me
  
  if (the markerlist).getaprop(marker(0)) <> "abspann" then
    dto = mCreateTimeout(me, "quitTimeOut", 5000, #mQuitMovie, me)
    go "abspann"
  else
    mQuitMovie me
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mQuitMovie me
  if ilk(timeout("quitTimeOut")) = #timeout then timeout("quitTimeOut").forget()
  mCallDestroy me
  if not(the runmode contains "plug") then halt
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____PROCESS_CALLBACK_EVENTS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDoCallBack me, callbackObject, p1, p2, p3
  -----------------------------------
  -- CREATED: 22.07.2009
  -- ACTION: This is the standard way to send callback events to callbackObjects of the format:
  --             [#handler:symbol, #target:object]
  --             NOTE: If the #handler property is NOT a symbol, then it is considered a special case
  --                   where the result will simply be "put" into the message window => suited for debugging
  -- INPUT: <callbackObject> ; object (propertylist) ; required ; a callBack object of the format:
  --             [#handler:symbol, #target:object], which can be any number of additional properties
  --             since this object will be provided as parameter to the recipient
  --             the recipient can access all these additional properties
  --         <p1 - p3> ; arbitrary parameters ; just in case additional parameters are required,
  --             which can not, for some reason, be stored in the object <callbackObject> itself
  -- RETURNS: either a string or any value. In case of a parameter error
  --             an errorstring is returned and the callback was NOT successfully called.
  -- EXAMPLE: theResult = xscr().mDoCallBack(callBackObject)
  -----------------------------------
  
  if not(objectP(callbackObject)) then return "Wrong paramater, callbackObject is not an object!"
  
  hnd = callbackObject[#handler]
  if not(symbolP(hnd)) then
    put "Script 'commonMovieScript': Handler 'mDoCallBack':"
    put "---------------------------"
    put "callbackObject:" && callbackObject
    put "------"
    put "p1:" && p1
    put "------"
    put "p2:" && p2
    put "------"
    put "p3:" && p3
    put "---------------------------"
    return "callbackObject[#handler] is not a symbol"
  end if
  
  tgt = callbackObject[#target]
  case ilk(tgt) of
    #script, #instance:
      retval = call(hnd, [tgt], callbackObject, p1, p2, p3)
    #list, #proplist:
      if count(tgt) = 0 then
        put "Script 'commonMovieScript': Handler 'mDoCallBack':"
        put "---------------------------"
        put "callbackObject:" && callbackObject
        put "------"
        put "p1:" && p1
        put "------"
        put "p2:" && p2
        put "------"
        put "p3:" && p3
        put "---------------------------"
        retval = 1
      else
        retval = call(hnd, tgt, callbackObject, p1, p2, p3)
      end if
      
    otherwise:
      spr = mGetKanal(me, tgt)
      if spr < 1 then return "callbackObject[#target] is neither an object nor a spritenumber/name:" && callbackObject[#target]
      retval = sendSprite(spr, hnd, callbackObject, p1, p2, p3)
  end case
  
  -- due to a stupid bug in 11.5.9.629 we can get <NULL> as a result of call() and on windows/shockwave it compares to 1 as true
  -- voidP(<NULL>) = false, but ilk(<NULL>) = #void therefore we force void here
  -- unfortunately there is another bug in director, which will throw a script error, if we use ilk() on deeted 3-D models
  -- therefore we have to check voidP() BEFORE ilk()! oh well...
  if voidP(retval) then retval = void
  if ilk(retval) = #void then retval = void
  
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDoDelayedCallback me, proplist_callbackObject, integer_DelayTime, any_param1, any_param2, any_param3
  -----------------------------------
  -- CREATED: 04.02.2010
  -- ACTION: Break the event chain by deleying a call by at least one milliseconds
  -- INPUT:  <callbackObject> ; object (propertylist) ; required ; a callBack object of the format:
  --             [#handler:symbol, #target:object], which can be any number of additional properties
  --             since this object will be provided as parameter to the recipient
  --             the recipient can access all these additional properties
  --         <integer_DelayTime> ; integer ; timeoutlength in milliseconds, optional, default = 1
  --         <any_param1 - any_param3> ; arbitrary parameters ; just in case additional parameters are required,
  --             which can not, for some reason, be stored in the object <callbackObject> itself
  -- RETURNS: true for success
  -- EXAMPLE: cb = [#target:me, #handler:#foo]
  --          xscr().mDoDelayedCallback(cb, 1, "abc", 3, [])
  -----------------------------------
  
  delayedCallBackList = mGetGlobalValue(me, #delayedCallBackList)
  if ilk(delayedCallBackList) <> #proplist then
    delayedCallBackList = [:]
    delayedCallBackList[#lastIndex] = 0
    delayedCallBackList[#jobs] = [:]
    mSetGlobalValue(me, #delayedCallBackList, delayedCallBackList)
  end if
  
  if ilk(integer_DelayTime) <> #integer then integer_DelayTime = 1
  integer_DelayTime = max(1, integer_DelayTime)
  
  delayedCallBackList[#lastIndex] = delayedCallBackList[#lastIndex] + 1
  if delayedCallBackList[#lastIndex] = the maxinteger then delayedCallBackList[#lastIndex] = 1
  
  toName = "delayedCallbackTimeout" & mGetMemoryAddress(me, me) & delayedCallBackList[#lastIndex]
  
  delayedCallBackList[#jobs][toName] = [#cobj: proplist_callbackObject, #params:[any_param1, any_param2, any_param3]]
  
  dto = mCreateTimeOut(me, toName, integer_DelayTime, #delayedCallCallback, me)
  
  return 1
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- cal the callback after the delay timeout

on delayedCallCallback me, dto
  if ilk(dto) <> #timeout then exit
  toName = dto.name
  dto.forget()
  delayedCallBackList = mGetGlobalValue(me, #delayedCallBackList)
  if ilk(delayedCallBackList) <> #proplist then exit
  thisJob = delayedCallBackList[#jobs][toName]
  if voidP(thisJob) then exit
  delayedCallBackList[#jobs].deleteProp(toName)
  mDoCallBack me, thisJob[#cobj], thisJob[#params][1], thisJob[#params][2], thisJob[#params][3]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____MOVIE_IDENTIFIER_HANDLERS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on mSetThisMovieName me, aName
  glob = mGetGlobalList(me)
  glob.setaprop(#movieIdentifier, aName)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetThisMovieName me
  glob = mGetGlobalList(me)
  str = string(glob.getaprop(#movieIdentifier))
  if length(str) > 0 then return str
  str = mSplitPath(me, the moviename).basename
  mSetThisMovieName me, str
  return str
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____SPRITE_NAMING_HANDLERS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- these are handlers for my own sprite naming routines with the names of the named sprites currently in the score
-- with director >= 10 you can name the sprites as a built into director function, which is in most circumstances more convenient
-- but with this approach you can
-- a.) change the sprite names at runtime (to temporarely enable/disable sendSprite calls)
-- b.) have multiple different names for one sprite

on mGetKanal me, einname
  theGlobs = mGetGlobalList(me)
  if not listP(theGlobs.getaprop(#gSpriteNamenliste)) then theGlobs[#gSpriteNamenliste] = [:]
  kanalnummer = getaprop((theGlobs.gSpriteNamenliste), einname)
  
  if voidP(kanalnummer) then
    
    if ilk(einname) = #integer then -- integer passed ? check if the sprite is empty
      if sprite(einname).member.type = #empty then kanalnummer = -1
      else kanalnummer = einname
      
    else -- otherwise (string ?), if this is MX 2004, we check for regular sprite names:
      
      if mCheckWoody(me) = 1 then
        sprnam = string(einname)
        if length(sprnam) > 0 then -- unfortunately sprite("") yields a result in D10
          spr = sprite(sprnam)
          if voidP(spr) then
            kanalnummer = -1
          else
            kanalnummer = spr.spritenum
            if ((kanalnummer = 1) and (the scriptexecutionstyle = 9)) then
              if sprite(1).name = "" then kanalnummer = -1
            end if
          end if
        else
          kanalnummer = -1
        end if
      else
        kanalnummer = -1
      end if
    end if
  end if
  
  return kanalnummer
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMeldeKanalname me, einname, einkanal
  theGlobs = mGetGlobalList(me)
  if not listP(theGlobs.getaprop(#gSpriteNamenliste)) then theGlobs[#gSpriteNamenliste] = [:]
  (theGlobs.gSpriteNamenliste)[einname] = einkanal
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMeldeAbKanalname me, einname, einkanal
  theGlobs = mGetGlobalList(me)
  if not listP(theGlobs.getaprop(#gSpriteNamenliste)) then theGlobs[#gSpriteNamenliste] = [:]
  derwert = getaprop((theGlobs.gSpriteNamenliste), einname)
  if derwert = einkanal then deleteProp (theGlobs.gSpriteNamenliste), einname
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____DEBUG_FUNCTIONS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- my own 'put' function, which can be enabled and disabled (to avoid clutter in the message window)
-- which can 'put' image objects (create new #bitmap members)
-- logs the put results in a field, which can be used to put at runtime
-- and send the put results in an email back to the movie author to trouble shoot projectors

on mEnablePut me, val
  
  glob = mGetGlobalList(me)
  
  if voidP(val) then val = not(glob.getaprop(#gDebugDisabled))
  else val = not(val)
  
  glob[#gDebugDisabled] = val
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mPut me, str, overwrite, dername
  
  global gDebug
  if not voidP(gDebug) then
    if gDebug = 0 then exit
  end if
  
  if (mGetGlobalList(me)).getaprop(#gDebugDisabled) then exit
  
  debugFlags = xscr().mGetGlobalValue(#gDebugFlags)
  if not(listP(debugFlags)) then debugFlags = []
  
  if debugFlags.getPos(4) then -- critical messages!
    sendSprite(xscr().mGetKanal(#keynaviStatus), #mSetText, str)
  end if
  
  if ilk(overwrite) = #integer then
    doit = (debugFlags.getPos(overwrite) > 0)
  else
    doit = 1
  end if
  
  if doit then mLogDebugInfo me, str
  
  if ilk(str) = #image then
    mDebugImage me, str, overwrite, dername
  else
    if the runmode contains "aut" then
      if overwrite = 64 then
        put str
      else
        if debugFlags.getPos(1) then
          put str
        end if
      end if
    end if
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDebugImage me, img, overwrite, dername
  
  if not(the runmode contains "aut") then exit
  
  if voidP(dername) then dername = "DebugImg"
  
  if overwrite = 1 then
    neuer = member(dername)
    if mGetMemType(me, neuer) <> #bitmap then overwrite = 0
  end if
  
  if not(overwrite) then
    neuer = new(#bitmap)
    neuer.name = dername
  end if
  
  neuer.image = img
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mLogDebugInfo me, str
  f = member("debuginfotextmember")
  if mGetMemType(me, f) <> #field then
    f = new(#field)
    f.name = "debuginfotextmember"
  end if
  
  if mGetVersionNumber(me) > 11 then
    oldscrolltop = f.scrolltop
    if oldscrolltop > f.height - f.pageheight - f.lineheight then
      oldscrolltop = #unten
    end if
  end if
  
  altertext = f.text
  if the number of lines of altertext > 500 then put line 300 to 500 of altertext into field "debuginfotextmember"
  put "------------------------"&RETURN&RETURN & str & return after field "debuginfotextmember"
  
  if not voidP(oldscrolltop) then
    if oldscrolltop = #unten then
      f.scrolltop = f.height - f.pageheight + f.lineheight
    else
      f.scrolltop = oldscrolltop
    end if
  end if
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mWatch me, theIdentifier, theValue
  
  t = member("temp_watcher_field")
  if ilk(t) <> #member then
    t = new(#field)
    t.name = "temp_watcher_field"
  end if
  
  if mGetMemType(me, t) <> #field then
    put "Hey !! temp_watcher_field is NOT a #field"
    exit -- something must ne very wrong
  end if
  
  offs = offset(RETURN & theIdentifier & ": ", t.text)
  if offs > 0 then
    l = the number of lines of char 1 to offs of field t
    put theIdentifier & ": " & theValue into line l of field t
  else
    put RETURN & theIdentifier & ": " & theValue after field t
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____MEMBER_UTILITIES
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- Referencing members by name is slow
-- this searches through a given castlib starting at a given slotnumber
-- this is also useful, to avoid conflicts with duplicate names

-- this handler is here for compatibility with my older scripts

-- prueft die existenz eines members nach namen von der stelle <num> bis zum ende der castlib <cl>
-- musste ich machen als ich festgestellt habe, dass director dafuer 4x solange braucht, weil er alle casts durchsucht

on mSuchMemFwd me, num, cl, dername
  anz = the number of members of castlib cl
  repeat with n = num to anz
    mem = member(n, cl)
    if mem.name = dername then return mem
  end repeat
  return 0
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx Creation of New Members - ROUTINEN
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetNewMember me, aType
  
  if voidP(aType) then aType = #bitmap
  
  if ilk(aType) <> #symbol then aType = symbol(aType)
  
  tempMembers = mGetTempMemberList(me, aType)
  if count(tempMembers) < 1 then
    neuer = new(aType)
  else
    neuer = tempMembers[1]
    tempMembers.deleteAt(1)
  end if
  
  --  ((mGetGlobalList(me)).gDeleteListe).add(neuer)
  
  return neuer
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mEraseMember me, aMember
  if ilk(aMember) <> #member then exit
  aType = aMember.type
  
  glob = mGetGlobalList(me)
  gTempMemberList = glob.getaprop(#gTempMemberList)
  if gTempMemberList = #moviestopped then
    -- stopmoviehandler already was called (this is perhaps a stack inited by endsprite)
    -- so we just delete the thing and leave, no risk of running into the bug we want to prevent
    aMember.erase()
    exit
  end if
  
  tempMembers = mGetTempMemberList(me, aType)
  if tempMembers.getPos(aMember) < 1 then tempMembers.add(aMember)
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetTempMemberList me, aType
  
  glob = mGetGlobalList(me)
  
  gTempMemberList = glob.getaprop(#gTempMemberList)
  if ilk(gTempMemberList) <> #proplist then
    gTempMemberList = [:]
    glob.setaprop(#gTempMemberList, gTempMemberList)
  end if
  
  thisType = gTempMemberList.getaprop(aType)
  if ilk(thisType) <> #list then
    thisType = []
    gTempMemberList.setaprop(aType, thisType)
  end if
  
  return thisType
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mEraseAllTempMembers me
  glob = mGetGlobalList(me)
  
  gTempMemberList = glob.getaprop(#gTempMemberList)
  if ilk(gTempMemberList) = #proplist then
    anz = count(gTempMemberList)
    repeat with n = anz down to 1
      li = gTempMemberList[n]
      gTempMemberList.deleteAt(n)
      liCnt = count(li)
      repeat with m = liCnt down to 1
        mem = li[m]
        li.deleteAt(m)
        if ilk(mem) = #member then mem.erase()
      end repeat
    end repeat
  end if
  glob.setaprop(#gTempMemberList, #moviestopped)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____TEXT_UTILITIES
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- common textmember and font handlers


-- xxxxxxxxxxxxxxxxxx get a list of all installed fonts
-- and save it as global for further use, since it is slow to get the complete list

on InitFonts me
  -- comment here to use a *real* global:
  
  if not the runmode contains "aut" then return ["Arial"] -- just to be safe
  -- this handler should not be called anymore in runtime
  -- as mGetAFont() doesn't call it anymore
  -- the lame reason is:
  -- the new D11 player fucked up the unsupported function FontList()
  -- :-( SHAME!
  
  -- faked global:
  globs = mGetGlobalList(me)
  gFontList = globs.getaprop(#gFontList)
  
  -- -- real global:
  --  global gFontlist
  
  
  if voidP(gFontList) then
    m = new(#font)
    
    -- alex am Freitag, 4. Juni 2004
    if not objectP(m) then
      gFontList = ["Arial"]
    else
      gFontList = m.FontList()
      m.erase()
    end if
    --/ alex am Freitag, 4. Juni 2004
    
    gFontList.sort()
    
    if not gFontList[1].length then gFontList.deleteAt(1)
    
    -- comment here to use a *real* global:
    -- faked global:
    theGlobs = mGetGlobalList(me)
    theGlobs[#gFontList] = gFontList
    
    -- -- real global: <nothing>
    
  end if
  return gFontList
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


-- xxxxxxxxxxxxxxxxxx there's a bug in textmembers, which are larger than 16383 lines
-- Thank you James Newton for the following bugfix !

on GetScrollRatio me, aMember -------------------------------------------
  -- INPUT: <aMember> is a text member (or any other kind of member)
  -- OUTPUT: an integer power of 2 representing the factor by which
  --         a member of that height is scrolled
  --------------------------------------------------------------------
  
  tRatio = 1
  
  if mGetMemType(me, aMember) = #text then
    -- Text members with more than 16383 lines of text scroll in
    -- steps of a power of two and the scrollTop value indicates
    -- the number of steps (not the number of pixels) from the top
    tHeight = aMember.height / 16384
    
    repeat while tHeight
      tHeight = tHeight / 2
      tRatio = tRatio * 2
    end repeat
    
  end if
  
  return tRatio
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- xxxxxxxxxxxxxxxxxx get a temporary textmember named "tempDruckText"
-- creates a new textmember if member("tempTextMem") is not found in the current movie

on mGetATextMem me, theFont, theFontsize, aliasFlag
  
  temptext = member("tempTextMem")
  
  if mGetMemType(me, temptext) <> #text then
    temptext = new(#text)
    temptext.name = "tempTextMem"
    temptext.text = " "
    
    temptext.leftindent = 0
    temptext.rightindent = 0
    temptext.firstindent = 0
    temptext.topspacing = 0
    temptext.bottomspacing = 0
    temptext.charspacing = 0
    temptext.alignment = #left
  end if
  
  if (temptext.font <> theFont) then temptext.font = theFont
  if (temptext.fontsize <> theFontsize) then temptext.fontsize = theFontsize
  
  -- polen problem:
  thePrefs = (mGetGlobalList(me)).getaprop(#gPrefs)
  if ilk(thePrefs) = #proplist then
    textAA = thePrefs.getaprop(#textAA)
    if not voidP(textAA) then
      if textAA = 0 then aliasFlag = 0
    end if
  end if
  --/ polen problem
  
  if aliasFlag then
    if not(temptext.antialias) then temptext.antialias = 1
    if (temptext.antialiasThreshold > theFontsize - 1) then temptext.antialiasThreshold = theFontsize - 1
    
    if not(temptext.kerning) then temptext.kerning = 1
    if (temptext.kerningThreshold > theFontsize - 1) then temptext.kerningThreshold = theFontsize - 1
    
  else
    if (temptext.antialias) then temptext.antialias = 0
    if (temptext.kerning) then temptext.kerning = 0
  end if
  
  return temptext
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- xxxxxxxxxxxxxxxxxx gets a font by name and returns the name if successful
-- if not successful checks for "Arial"
-- if that fails also, takes the first installed font of the list of installed fonts
on mGetAFont me, theFont
  
  return theFont -- :-( the unsupported fontlist() method of font members now can crash the browser - tolle wurst!
  
  
  fontliste = InitFonts(me)
  if not (fontliste).getPos(theFont) then
    
    -- alex am Freitag, 4. Juni 2004
    if count(fontliste) = 1 then return theFont
    -- special case: font asset xtra is missing, so initFonts() returned ["Arial"] and we can't check the font
    -- and instead simply use it at the 'own risk' of the caller
    -- it will replaced by the default font from director if missing
    --/ alex am Freitag, 4. Juni 2004
    
    schriftname = ""
    repeat with schrift in fontliste
      if schrift contains "Arial" then
        schriftname = schrift
        exit repeat
      end if
    end repeat
    if schriftname = "" then theFont = fontliste[1] -- if Arial doesn't exist take the first font in the fontlist
    else theFont = schriftname
  end if
  
  if mGetMemType(me, member("sprachnemenufield")) = #field then
    spr = call(#mGetPrefValue, [mGetXScript(#GetSetPrefs)], #gLanguage)
    if ilk(spr) = #integer then
      spr = spr + 1
      dertext = member("sprachnemenufield").text
      
      -- !!! russisch hardcode !!
      if spr = 14 then spr = 3
      
      if dertext.line.count >= spr then
        
        case dertext.line[spr] of
            
          "Russian":
            
            if the platform contains "mac" then
              if (fontliste).getPos("Lucida Grande CY *") then
                return "Lucida Grande CY *"
              end if
            else
              if (fontliste).getPos("Futura Cyr Bk *") then
                return "Futura Cyr Bk *"
              end if
              
            end if
            
            
          "Czech", "Polish":
            if the platform contains "mac" then
              if (fontliste).getPos("Geneva CE *") then
                return "Geneva CE *"
              end if
            else
              if (fontliste).getPos("Futura CE Bk *") then
                return "Futura CE Bk *"
              end if
            end if
            
        end case
      end if
    end if
  end if
  
  return theFont
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetLineHeight me, textOrField
  
  -- not a member:
  if ilk(textOrField) <> #member then return 0
  
  -- #field member:
  if textOrField.type = #field then return textOrField.lineheight
  
  -- #text member:
  if textOrField.type = #text then
    
    -- if there the linespace <> #automatic, we are done
    if textOrField.fixedLinespace > 0 then return textOrField.fixedLinespace
    
    -- if the textmember is empty, we fill a dummy char:
    if textOrField.char.count < 1 then
      textOrField.text = "J"
      firstlocV = textOrField.charPosToLoc(1)[2]
      textOrField.text = ""
      return firstlocV
    end if
    
    -- now we look at the charPos of the first chars of each line:
    firstlocV = textOrField.charPosToLoc(1)[2]
    
    secondLine = textOrField.locToCharPos(point(0, firstlocV + 1))
    if secondLine = 1 then return firstlocV
    
    secondLocV = textOrField.charPosToLoc(secondLine)[2]
    
    --    return secondLocV - firstlocV -- height of line 1 maybe header line...
    
    thirdLine = textOrField.locToCharPos(point(0, secondLocV + 1))
    if thirdLine = secondLine then return secondLocV - firstlocV
    
    thirdLocV = textOrField.charPosToLoc(thirdLine)[2]
    
    return thirdLocV - secondLocV
    
  end if
  
  return 0
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- build a list of lists of *wrapped* lines of the following format:
-- [[firstCharOfLine, lastCharOfLine, topOfLineInPixels, bottomOfLineInPixels], ...]
-- so the count of the returned list is the real number of lines after wordwrapping

-- beware, that this handler is slow, especially for fields
-- don't use it with very huge text or fieldmembers

on mGetLinesOfWrappedText me, textOrField
  retlist = []
  
  --  ms = the milliseconds
  
  -- not a textmember:
  theType = mGetMemType(me, textOrField)
  case theType of
    #text:
      
      if textOrField.char.count < 1 then return retlist
      
      lc = textOrField.char.count
      firstline = 1
      oben = 0
      
      firstlocV = textOrField.charPosToLoc(firstline)[2]
      
      secondLine = textOrField.locToCharPos(point(0, firstlocV + 1))
      
      repeat while firstline <> secondLine
        retlist.add([firstline, secondLine - 1, oben, firstlocV])
        oben = firstlocV + 1
        firstline = secondLine
        firstlocV = textOrField.charPosToLoc(firstline)[2]
        if firstlocV < 1 then exit repeat
        secondLine = textOrField.locToCharPos(point(0, firstlocV + 1))
      end repeat
      
      retlist.add([firstline, lc, oben, firstlocV])
      
    #field:
      
      if textOrField.char.count < 1 then return retlist
      
      lc = textOrField.char.count
      firstline = 1
      oben = 0
      unten = textOrField.charPosToLoc(lc)[2]
      
      firstlocV = textOrField.charPosToLoc(firstline)[2]
      
      secondLine = textOrField.locToCharPos(point(0, firstlocV + 1))
      
      repeat while firstlocV < unten
        if firstline <> secondLine then
          retlist.add([firstline, secondLine - 1, oben, firstlocV])
          oben = firstlocV + 1
          firstline = secondLine
          firstlocV = textOrField.charPosToLoc(firstline)[2]
          if firstlocV < 1 then exit repeat
          secondLine = textOrField.locToCharPos(point(0, firstlocV + 1))
        else
          firstlocV = firstlocV + 1
          secondLine = textOrField.locToCharPos(point(0, firstlocV + 1))
        end if
      end repeat
      
      retlist.add([firstline, lc, oben, firstlocV])
      
  end case
  
  --  mPut the milliseconds - ms
  
  return retlist
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- polnisches problem:
-- xxxxxxxxxxxxxxxxxx some fonts on easter european machines crash, when antialiasing = 1 :-(

-- usually I store the result in the preferences, so that every user can force non-antialiasing of fonts, when there is a font problem
-- so on startmovie, when I read the prefs in I do something like:
--  if ilk(prefliste.getaprop(#textAA)) <> #integer then prefliste[#textAA] = mCheckForTextAA()

on mCheckForTextAA me
  retval = 1
  temptext = mGetATextMem(me, mGetAFont(me, "Arial"), 14, 0)
  temptext.text = "I"
  img = temptext.image.extractAlpha()
  img = img.trimwhitespace()
  
  w1 = img.width
  
  if w1 < 1 then return 0
  
  temptext.antialias = 1
  temptext.antialiasThreshold = 10
  
  temptext.kerning = 1
  temptext.kerningThreshold = 10
  
  temptext.text = "I"
  img = temptext.image.extractAlpha()
  img = img.trimwhitespace()
  
  w2 = img.width
  
  diff = abs(w2 - w1)
  
  return (diff < 2)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____OBJECT_REFERENCING
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx check for availability of scripting xtra by name and store result for further access
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCheckForXtra me, whichXtra
  globs = mGetGlobalList(me)
  theXtras = globs.getaprop(#gXtras)
  if ilk(theXtras) <> #proplist then
    theXtras = [:]
    globs[#gXtras] = theXtras
  end if
  xtraPresent = theXtras.getaprop(whichXtra)
  if voidP(xtraPresent) then
    xtraPresent = 0
    numX = the number of xtras
    repeat with n = 1 to numX
      if (the name of xtra n = whichXtra) then
        xtraPresent = 1
        exit repeat
      end if
    end repeat
    theXtras.setaprop(whichXtra, xtraPresent)
  end if
  return xtraPresent
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx stored script instances:

on mGetInstance me, instName, useRawNew
  
  if ilk(instName) = #string then instName = symbol(instName)
  
  theGlobs = mGetGlobalList(me)
  gParentScriptInstances = theGlobs.getaprop(#gParentScriptInstances)
  
  if ilk(gParentScriptInstances) <> #proplist then
    gParentScriptInstances = [:]
    theGlobs[#gParentScriptInstances] = gParentScriptInstances
  end if
  
  saveScr = gParentScriptInstances.getaprop(instName)
  if ilk(saveScr) = #instance then return saveScr
  
  if mGetMemType(me, member(string(instName))) = #script then
    if useRawNew = 1 then saveScr = rawnew(script string(instName))
    else saveScr = new(script string(instName))
    gParentScriptInstances.setaprop(instName, saveScr)
    return saveScr
  end if
  
  if saveScr = -1 then return 0
  gParentScriptInstances.setaprop(instName, -1)
  inst = mGetXScript(instName)
  if not(listP(inst)) then
    if ilk(inst) = #instance then inst = inst.script
    if useRawNew = 1 then saveScr = rawnew(inst)
    else saveScr = new(inst)
    gParentScriptInstances.setaprop(instName, saveScr)
    return saveScr
  end if
  
  return 0
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
------------- get an instance WITHOUT instantiating, if it doesn't existing
------------- "mGetInstance" creates automatically an instance, sometimes, this is not what we want

on mGetInstanceReference me, instName
  
  theGlobs = mGetGlobalList(me)
  gParentScriptInstances = theGlobs.getaprop(#gParentScriptInstances)
  
  if ilk(gParentScriptInstances) <> #proplist then return 0
  
  saveScr = gParentScriptInstances.getaprop(instName)
  
  return saveScr
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx delete a stored script instance:

on mDeleteInstance me, instName, dontCallDestroyHandler
  theGlobs = mGetGlobalList(me)
  gParentScriptInstances = theGlobs.getaprop(#gParentScriptInstances)
  if ilk(gParentScriptInstances) <> #proplist then exit
  if dontCallDestroyHandler <> 1 then
    saveScr = gParentScriptInstances.getaprop(instName)
    if ilk(saveScr) = #instance then call(#mDestroy, [saveScr])
  end if
  gParentScriptInstances.deleteprop(instName)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx reload a stored script instance:

on mReloadInstance me, instName, useRawNew, dontCallDestroyHandler
  mDeleteInstance me, instName, dontCallDestroyHandler
  return mGetInstance(me, instName, useRawNew)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx replace a stored script instance:

on mReplaceInstance me, instName, scriptInstance, dontCallDestroyHandler
  if not(objectP(scriptInstance)) then exit
  theGlobs = mGetGlobalList(me)
  gParentScriptInstances = theGlobs.getaprop(#gParentScriptInstances)
  if ilk(gParentScriptInstances) <> #proplist then exit
  if dontCallDestroyHandler <> 1 then
    saveScr = gParentScriptInstances.getaprop(instName)
    if ilk(saveScr) = #instance then call(#mDestroy, [saveScr])
  end if
  gParentScriptInstances.setaprop(instName, scriptInstance)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx script instances in the models userdata[#myParentScript]:
-- many of my behaviors use model.userdata[#myParentScript] to store script objects, which then get the events sent by the Event Router Behavior for mouse Events

on mGetParentScriptList me, theModel
  retval = []
  if voidP(theModel) then return retval
  if [#model, #group, #camera, #light].getPos(ilk(theModel)) > 0 then
    ud = theModel.userdata
    scr = ud.getaprop(#myParentScript)
    if ilk(scr) = #instance then
      scr = [scr]
      ud.setaprop(#myParentScript, scr)
    end if
    if not(listP(scr)) then
      scr = []
      ud.setaprop(#myParentScript, scr)
    end if
    return scr
  end if
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetMemoryAddress me, theObject
  -----------------------------------
  -- CREATED: 08.12.2009
  -- ACTION: Convert argument into a string and chop the last char
  --         Usually used to get a unique identifier for a scriptinstance (=> the last word of string(me))
  --         but without the trailing ">".
  --         Not only this looks nicer, but also if used for a filename the ">" character is problematic in a filename
  -- INPUT: <theObject> ; any ilk which can be converted to a string
  -- RETURNS: string ; the stringified object without the trailing char
  -- EXAMPLE: uniqueInstanceIdentifier = xscr().mGetMemoryAddress(me)
  -----------------------------------
  
  theObject = the last word of string(theObject)
  delete the last char of theObject
  return theObject
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetPropertyRecursive me, proplist_source, list_propnames
  -----------------------------------
  -- CREATED: 08.03.2010
  -- ACTION: Dereference a proplist recursively
  -- INPUT: <proplist_source> ; property list ; the source list
  --        <list_propnames> ; linear list ; linear list with property names, which lead to the last property
  -- RETURNS: any value
  -- EXAMPLE: sourceList = [#one:[#two:[#three:3]]]
  --          val = xscr().mGetPropertyRecursive(sourceList, [#one, #two, #three])
  -----------------------------------
  
  if ilk(proplist_source) <> #proplist then return void
  if not(listP(list_propnames)) then return void
  cnt = count(list_propnames)
  if cnt < 1 then return void
  if cnt = 1 then return proplist_source[list_propnames[1]]
  propname = list_propnames[1]
  list_propnames.deleteAt(1)
  return mGetPropertyRecursive(me, proplist_source[propname], list_propnames)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCheckForValidImage me, image_img
  -----------------------------------
  -- CREATED: 21.04.2010
  -- ACTION: Check whether the parameter is a valid image object.
  --         Unfortunately there are sometimes cases where we end up with an
  --         image object, which errors out on each IL operation
  --         It is image:0 its ilk() is #image, but you can't even refer to its width
  --         without running into script errors. Therefore we need a lame string comparison
  --         as this image object has none of an image objects properties and methods :-(
  --         LAME!! Because string comaparison is a lame and slow hack. So don't use this handler "for fun"
  -- INPUT: <image_img> ; any
  -- RETURNS: boolean ; true if the parameter is an image with a with or height > 0
  -- EXAMPLE: put xscr().mCheckForValidImage(image(1,1,1))
  --          -- 1
  -----------------------------------
  
  if ilk(image_img) <> #image then return 0
  if string(image_img) = "<image:0>" then return 0
  if image_img.width * image_img.height < 1 then return 0
  return 1
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____MATH_UTILITIES
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- xxxxxxxxxxxxxxxxxx Ease in, Ease out with sin() and cos()
on mApplyDynamic me, proz, methode
  proz = min(1.0, max(0.0, proz))
  
  case methode of
    #easeIn:
      --      methode = #cosinus
      return 1 - cos(pi()/2 * proz)
    #easeOut:
      --      methode = #sinus
      return sin(pi()/2 * proz)
    #easeInOut:
      --      if proz < 0.5 then methode = #cosinus
      --      else methode = #sinus
      return (1 - ((cos(pi() * proz) + 1) / 2.0))
  end case
  
  return proz
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx powers of 2 for textures
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mIsPowerOfTwo me, integer_num
  return (bitand(integer_num, integer_num - 1) = 0)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetNextPowerOfTwo me, breite
  powerList = mGetPowerOf2List(me)
  retval = powerList.findPosNear(integer(breite))
  return powerList[min(retval, powerList.count)]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetNextLowerPowerOfTwo me, breite
  powerList = mGetPowerOf2List(me)
  if powerList.getPos(breite) > 0 then return breite
  return powerList[max(1, powerList.findPosNear(integer(breite)) - 1)]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetPowerOf2List me
  theGlobs = mGetGlobalList(me)
  gPowerList = theGlobs.getaprop(#gPowerList)
  if ilk(gPowerList) <> #list then
    gPowerList = [1,2,4,8,16,32,64,128,256,512,1024]
    gPowerList.sort()
    theGlobs[#gPowerList] = gPowerList
  end if
  return gPowerList
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____STRING_FUNCTIONS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



-- split a path into its three elements => base directory, basename and extension:

on mSplitPath me, fname, delim -- delim optional: default = the systems pathdelimiter
  
  olddelim = the itemdelimiter
  delim = string(delim)
  if length(delim) < 1 then
    delim =  the last char of the moviepath
    if length(delim) < 1 then
      
      if the runmode contains "plug" then
        delim = "/"
      else
        delim = the last char of the applicationpath
      end if
      
      
      if length(delim) < 1 then delim = "/"
    end if
  end if
  the itemdelimiter = delim
  dateiname = the last item of fname
  delete the last item of fname
  put delim after fname
  the itemdelimiter = olddelim
  
  ext = mSplitFromEnd(me, dateiname, ".")
  
  return [#basedir:fname, #basename:ext[#basename], #extension:ext[#extension]]
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSplitFromEnd me, string_source, char_delim
  -----------------------------------
  -- CREATED: 23.03.2010
  -- ACTION: Get the file extension
  --         (or use any other SINGLE char to get the remaining bits of a string AFTER that char)
  -- INPUT: <string_source> ; string ; the input string
  --        <char_delim> ; string ; one char to be used as the itemdelimiter => optional, default = "."
  -- RETURNS: property list with [#basename:"", #extension:""]
  -- EXAMPLE: put xscr().mSplitFromEnd("com.adobe.director.plist", ".")
  --          -- [#basename:"com.adobe.director", #extension:"plist"]
  -----------------------------------
  
  char_delim = string(char_delim)
  if length(char_delim) > 0 then
    char_delim = char 1 of char_delim
  else
    char_delim = "." -- defaults to . => find file extension
  end if
  
  if offset(char_delim, string_source) < 1 then
    return [#basename:string_source, #extension:""]
  end if
  
  olddelim = the itemdelimiter
  the itemdelimiter = char_delim
  ext = the last item of string_source
  delete the last item of string_source
  the itemdelimiter = olddelim
  return [#basename:string_source, #extension:ext]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mConvertAbsolutePathToRelative me, aPath, newDelim, anAbsoluteBasedir
  
  
  
  anAbsoluteBasedir = string(anAbsoluteBasedir)
  if length(anAbsoluteBasedir) < 1 then
    
    if not(the runmode contains "auth") then
      externalPathHackList = mGetPlayBackModeValue(me, #externalPathHackList)
      if listP(externalPathHackList) then
        
        delim = the last char of the moviepath
        if length(delim) < 1 then
          if (the runmode contains "plug") then
            delim = "/"
          else
            delim = the last char of the applicationpath
          end if
        end if
        
        repeat with thisHack in externalPathHackList
          if ilk(thisHack) = #proplist then
            ident = thisHack[#identifier]
            
            if delim <> "/" then
              offs = offset("/", ident)
              repeat while offs > 0
                put delim into char offs of ident
                offs = offset("/", ident)
              end repeat
            end if
            
            if offset(ident, aPath) > 0 then
              if aPath starts thisHack[#basePath] & ident then
                anAbsoluteBasedir = thisHack[#basePath]
                exit repeat
              end if
            end if
          end if
        end repeat
      end if
    end if
    
  if length(anAbsoluteBasedir) < 1 then anAbsoluteBasedir = the moviepath
    
  end if
  
  if length(anAbsoluteBasedir) < 1 then return aPath
  
  delim = the last char of the moviepath
  if length(delim) < 1 then delim = the last char of the applicationpath
  
  newDelim = string(newDelim)
  if length(newDelim) < 1 then newDelim = delim
  
  offs = offset(anAbsoluteBasedir, aPath)
  if offs <> 1 then
    put "Script:commonMovieScript; Handler:mConvertAbsolutePathToRelative; The path:" &&QUOTE& aPath &QUOTE&& "is not inside the current path specified" &&QUOTE& anAbsoluteBasedir &QUOTE
    return aPath
  end if
  delete char 1 to length(anAbsoluteBasedir) of aPath
  if delim = newDelim then return aPath
  
  offs = offset(delim, aPath)
  repeat while offs > 0
    put newDelim into char offs of aPath
    offs = offset(delim, aPath)
  end repeat
  
  return aPath
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- convert a relative path to an absolute path: (Sorry, the name of this handler couldn't be more stupid ;-)
on mGetRelativePath me, aPath, mp -- mp optional: default = the moviepath
  
  if aPath contains "maxState" then
    nothing
  end if
  
  if not(the runmode contains "auth") then
    externalPathHackList = mGetPlayBackModeValue(me, #externalPathHackList)
    if listP(externalPathHackList) then
      repeat with thisHack in externalPathHackList
        if ilk(thisHack) = #proplist then
          if aPath starts thisHack[#identifier] then
            mp = thisHack[#basePath]
            --            alert "changed basepath to:" && mp
            regexp = thisHack[#regexp]
            if ilk(regexp) = #proplist then
              searchString = string(regexp[#searchString])
              if length(searchString) > 0 then
                replacementString = string(regexp[#replacementString])
                aPath = jReplaceAll(aPath, searchString, replacementString, "ig", 1)
              end if
            end if
            exit repeat
          end if
        end if
      end repeat
    end if
  end if
  
  mp = string(mp)
  if length(mp) < 1 then
    mp = the moviepath
    if length(mp) < 1 then
      if the runmode contains "plug" then
        mp = ""
      else
        mp = the applicationpath
      end if
      if length(mp) < 1 then
        mp = "@/"
      end if
    end if
  end if
  
  offs = offset(mp, aPath)
  if offs = 1 then
    delete char 1 to length(mp) - 1 of aPath
  end if
  
  delim = the last char of mp
  if ["\", "/", ":"].getPos(delim) < 1 then
    delim =  the last char of the moviepath
    if length(delim) < 1 then
      if the runmode contains "plug" then
        --        delim = ""
      else
        delim = the last char of the applicationpath
      end if
      if length(delim) < 1 then delim = "/"
    end if
    put delim after mp
  end if
  
  --  delimList = ["\", "/", ":"]
  --  delimList.deleteOne(delim)
  --  
  --  repeat with thisDelim in delimList
  --    offs =  offset(thisDelim, aPath)
  --    repeat while offs > 0
  --      put delim into char offs of aPath
  --      offs =  offset(thisDelim, aPath)
  --    end repeat
  --  end repeat
  
  aPath = mGetDelimitedPath(me, aPath, delim)
  
  offs = offset("://", aPath)
  if ((offs > 3) and (offs < 7)) then
    -- ought to be an absolute internet link
    return aPath
  end if
  
  if char 1 of aPath = "@" then delete char 1 of aPath
  
  if (aPath.char[1 .. 3] = ".."&delim) then put delim before aPath
  offs = offset(delim&".."&delim, aPath)
  repeat while offs > 0
    put delim&delim into char offs to (offs + 3) of aPath
    offs = offset(delim&".."&delim, aPath)
  end repeat
  
  
  if (char 2 of aPath = delim) then
    delete char 1 of aPath
    olddelim = the itemdelimiter
    the itemdelimiter = delim
    delete the last item of mp
    repeat while char 1 of aPath = delim
      delete char 1 of aPath
      delete the last item of mp
    end repeat
    put delim after mp
  end if
  
  if char 1 of aPath = delim then delete char 1 of aPath
  
  olddelim = the itemdelimiter
  the itemdelimiter = delim
  platte = item 1 of mp
  anf = item 1 of aPath
  the itemdelimiter = olddelim
  
  if anf = "http:" or anf = "ftp:" or anf = "https:" then return aPath
  else if anf = platte then return aPath
  return mp & aPath
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- converts each of the three pathdelimiters ("\", ":", "/") to the platform specific delimiter

on mGetDelimitedPath me, thePath, delim -- delim optional: default = the systems pathdelimiter
  
  delim = string(delim)
  if length(delim) < 1 then
    delim = the last char of the moviepath
    if length(delim) < 1 then
      if not(the runmode contains "plug") then
        delim = the last char of the applicationpath
      end if
      if length(delim) < 1 then delim = "/"
    end if
  end if
  
  offs = offset("://", thePath)
  if ((offs > 3) and (offs < 7)) then
    -- must be an internet link
    delim = "/"
  end if
  
  
  if delim = "\" then
    if length(thePath) > 1 then
      if thePath.char[2] = ":" then
        num = charToNum(thePath.char[1])
        if (num > 64 and num < 91) or (num > 96 and num < 123) then
          praef = thePath.char[1 .. 2]
          delete char 1 to 2 of thePath
        else
          praef = ""
        end if
      else
        praef = ""
      end if
    else
      praef = ""
    end if
    
  else if delim = "/" then
    
    if offset("https:", thePath) = 1 then
      praef = thePath.char[1 .. 6]
      delete char 1 to 6 of thePath
    else if offset("http:", thePath) = 1 then
      praef = thePath.char[1 .. 5]
      delete char 1 to 5 of thePath
    else if offset("ftp:", thePath) = 1 then
      praef = thePath.char[1 .. 4]
      delete char 1 to 4 of thePath
    else
      praef = ""
    end if
    
    ----------- now we want to strip the domain too, because there could be a : for the port
    ----------- but : is one of the chars we want to translate, therefore we exclude the doamin also
    if length(praef) > 0 then
      
      repeat with xy = 1 to 2
        if char 1 of thePath = "/" then
          praef = praef & "/"
          delete char 1 of thePath
        end if
      end repeat
      
      domain = offset("/", thePath)
      if domain = 0 then domain = length(thePath)
      praef = praef & thePath.char[1 .. domain]
      delete char 1 to domain of thePath
    end if
    ------------
    
  else
    praef = ""
  end if
  
  delimLi = ["\", ":", "/"]
  delimLi.deleteOne(delim)
  
  repeat with thisDelim in delimLi
    offs = offset(thisDelim, thePath)
    repeat while offs > 0
      put delim into char offs of thePath
      offs = offset(thisDelim, thePath)
    end repeat
  end repeat
  
  put praef before thePath
  
  return thePath
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx Check for file existence
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCheckFileExists me, aPath
  if ilk(aPath) <> #string then return 0
  if not(aPath.length) then return 0
  
  if (the runmode contains "plug") then
    retValue = 1 -- can't do this check in shockwave
    
  else
    
    retValue = 0
    
    if mCheckForXtra(me, "BudAPI") then -- if buddy is present...
      --  -- budApi version:
      
      -- alex am 6.03.2004 um 09:06
      
      -- ich weiss nicht wirklich, ob es schlauer ist baShortFileName() zu verwenden
      -- wegen alten versionen von BudApi, OS9, windows... ???
      -- so: handle with care
      --    retValue = baFileExists(aPath)
      
      retValue = (string(baShortFileName(aPath)) <> "")
      --/ alex am 6.03.2004 um 09:06
      
    else if mCheckForXtra(me, "FileXtra4") then -- if not buddy then try filextra
      --  -- filextra3 version:
      fx = (xtra "filextra4").new()
      if objectP(fx) then retValue = fx.fx_FileExists(aPath)
      fx = 0
    else if mCheckForXtra(me, "fileio") then
      -- if all else fails, try the slower fileio version by trying to open the file
      -- -- fileio version:
      fio = (xtra "fileio").new()
      if objectP(fio) then
        fio.openFile(aPath, 0)
        if fio.status() = 0 then
          fio.closeFile()
          retValue = 1
        end if
      end if
      fio = 0
      
    else
      retValue = 1 -- in dubio pro reo
    end if
    
  end if
  
  return retValue
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetUniqueFilename me, fullPath, backUpSuffix
  
  backUpSuffix = string(backUpSuffix)
  if length(backUpSuffix) < 1 then
    backUpSuffix = mCreateDateSuffix(me, "_BAK_")
  end if
  
  if mCheckFileExists(me, fullPath) = 1 then
    
    splitPath = mSplitPath(me, fullPath)
    dd = 0
    dup = splitPath.getaprop(#basedir) & splitPath.getaprop(#basename) & backUpSuffix & "." & splitPath.getaprop(#extension) & "_" & dd
    repeat while mCheckFileExists(me, dup) = 1
      dd = dd + 1
      dup = splitPath.getaprop(#basedir) & splitPath.getaprop(#basename) & backUpSuffix & "." & splitPath.getaprop(#extension) & "_" & dd
    end repeat
    
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCreateDateSuffix me, praefix
  
  d = the systemdate
  
  monat = integer(d.month)
  if monat < 10 then monat = "0" & monat
  tag = integer(d.day)
  if tag < 10 then tag = "0" & tag
  
  return praefix & monat & "_" & tag
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- dummy handler for translate function

on mTranslate me, aString, variablesList
  theGlobs = mGetGlobalList(me)
  uebersetzungsListe = theGlobs.getaprop(#gUebersetzung)
  if ilk(uebersetzungsListe) <> #proplist then return mReplacePlaceHoldersInString(me, aString, variablesList)
  
  uebersetzung = uebersetzungsListe.getaprop(aString)
  if voidP(uebersetzung) then return mReplacePlaceHoldersInString(me, aString, variablesList)
  
  currLang = call(#mGetPrefValue, [mGetXScript(#GetSetPrefs)], #gLanguage)
  if voidP(currLang) then
    currLang = theGlobs.getaprop(#gSprache)
    if voidP(currLang) then currLang = 0
    call(#mSetPrefValue, [mGetXScript(#GetSetPrefs)], #gLanguage, currLang)
  end if
  ind = currLang + 1
  if ind > count(uebersetzung) then ind = 1
  
  return mReplacePlaceHoldersInString(me, uebersetzung[ind], variablesList)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mReplacePlaceHoldersInString me, aString, variablesList
  theIlk = ilk(variablesList)
  if theIlk = #proplist then
    cnt = count(variablesList)
    if cnt > 0 then
      repeat with n = 1 to cnt
        str = string(variablesList[n])
        prop = variablesList.getPropAt(n)
        srchStr = "%%" & prop & "%%"
        len = length(srchStr) - 1
        offs = offset(srchStr, aString)
        repeat while offs > 0
          put str into char offs to offs + len of aString
          offs = offset(srchStr, aString)
        end repeat
      end repeat        
    end if
  else if theIlk = #list then -- printf like replacement
    if count(variablesList) > 0 then
      offs = offset("%s", aString)
      str = string(variablesList[1])
      repeat while offs > 0
        put str into char offs to offs + 1 of aString
        if count(variablesList) > 1 then variablesList.deleteAt(1)
        str = string(variablesList[1])
        offs = offset("%s", aString)
      end repeat
    end if
  end if
  return aString
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx encodes spaces as %20 rather than "+" as lingos urlencode does
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on mUrlEncode me, srcText
  
  srcText = urlencode(string(srcText))
  
  offs = offset("+", srcText)
  
  if offs then
    
    newtext = ""
    replText = "%20"
    
    repeat while offs
      
      if offs > 1 then put char 1 to (offs - 1) of srcText & replText after newtext
      else put replText after newtext
      
      delete char 1 to offs of srcText
      
      offs = offset("+", srcText)
      
      if offs = 0 then put srcText after newtext
      
    end repeat
    
  else
    
    return srcText
  end if
  
  return newtext
  
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx the missing reverse for urlencode
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on urlDecode me, theString
  
  newString = ""
  
  -- replace all %
  proc_pos = offset("%", theString)
  -- replace the + with SPACE
  plus_pos = offset("+", theString)
  
  repeat while (proc_pos > 0) or (plus_pos > 0)
    
    if (plus_pos < proc_pos) and (plus_pos > 0) then
      if plus_pos > 1 then put char 1 to (plus_pos - 1) of theString after newString
      
      put SPACE after newString
      
      delete char 1 to plus_pos of theString
      
    else
      if proc_pos > 1 then put char 1 to (proc_pos - 1) of theString after newString
      
      tHH = bitAnd(chartonum(char (proc_pos + 1) of theString), 95)
      if (tHH > 26) then tHH = tHH - 55
      else tHH = tHH - 16
      
      tHL = bitAnd(chartonum(char (proc_pos + 2) of theString), 95)
      if (tHL > 26) then tHL = tHL - 55
      else tHL = tHL - 16
      
      put numtoChar((tHH * 16) + tHL) after newString
      
      delete char 1 to (proc_pos + 2) of theString
    end if
    
    proc_pos = offset("%", theString)
    plus_pos = offset("+", theString)
    
  end repeat
  
  put theString after newString
  
  return newString
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSymbolify me, any_var
  any_var = string(any_var)
  repeat while char 1 of any_var = "#"
    delete char 1 of any_var
  end repeat
  any_var = mString2Symb(me, any_var)
  return symbol(any_var)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mString2Symb me, str
  
  offs = offset(" ", str)
  repeat while offs > 0
    put "_s_" into char offs of str
    offs = offset(" ", str)
  end repeat
  
  offs = offset(".", str)
  repeat while offs > 0
    put "_d_" into char offs of str
    offs = offset(".", str)
  end repeat
  
  offs = offset("-", str)
  repeat while offs > 0
    put "_b_" into char offs of str
    offs = offset("-", str)
  end repeat
  
  if integerP(integer(str.char[1])) then put "n__" before str
  
  if length(str) < 1 then str = "xxx_" & the milliseconds
  
  return str
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSymb2String me, sym
  str = string(sym)
  
  offs = offset("_s_", str)
  repeat while offs > 0
    put " " into char offs to offs+2 of str
    offs = offset("_s_", str)
  end repeat
  
  offs = offset("_d_", str)
  repeat while offs > 0
    put "." into char offs to offs+2 of str
    offs = offset("_d_", str)
  end repeat
  
  offs = offset("_b_", str)
  repeat while offs > 0
    put "-" into char offs to offs+2 of str
    offs = offset("_b_", str)
  end repeat
  
  if str starts "n__" then delete char 1 to 3 of str
  
  return str
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mHTMLize me, str
  if offset("<html", str) < 1 then
    titlePos = offset("</title>", str)
    if titlePos < 1 then
      theTitle = "<title>untitled</title>"
      put theTitle before str
      firstchar = length(theTitle)
    else
      firstchar = titlePos + 7
    end if
    if offset("<body", str) < 1 then
      put "<body>" after char firstchar of str
      put "</body>" after str
    end if
    put "<html>" before str
    put "</html>" after str
  end if
  return str
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mValidateEmailAddress me, emailAddress
  retval = 0
  oldd = the itemdelimiter
  the itemdelimiter = "@"
  numItems = the number of items of emailAddress
  if numitems > 1 then
    if length(item 1 of emailAddress) > 0 then
      if length(item 2 of emailAddress) > 0 then
        offs = offset(".", item 2 of emailAddress)
        if offs > 1 then
          if offs < (length(item 2 of emailAddress) - 1) then
            if offs > (length(item 2 of emailAddress) - 4) then
              retval = 1
            end if
          end if
        end if
      end if
    end if
  end if
  the itemdelimiter = oldd
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- the naming convention used throughout all my movies for names, filename etc.:
-- Names must be only alphanumeric chars and the underscore and should not start with a number
-- As a rule of thumb: every string which can be made into a symbol is valid.

on mValidateName me, str
  if ilk(str) <> #string then return 0
  if length(str) < 1 then return 0
  if "0123456789" contains char 1 of str then return 0
  return string(symbol(str)) = str
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____________CONVERT_CASE
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mUpperCase me, aString
  
  if not(listP(pCaseLists)) then mCreateCaseLists me
  
  lowercase = pCaseLists.getaprop(#lowercase)
  uppercase = pCaseLists.getaprop(#uppercase)
  
  repeat with i = length(aString) down to 1
    pos = getPos(lowercase, char i of aString)
    if pos > 0 then
      put uppercase[pos] into char i of aString
    end if
  end repeat
  
  return aString
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mLowerCase me, aString
  
  if not(listP(pCaseLists)) then mCreateCaseLists me
  
  lowercase = pCaseLists.getaprop(#lowercase)
  uppercase = pCaseLists.getaprop(#uppercase)
  
  repeat with i = length(aString) down to 1
    pos = getPos(uppercase, char i of aString)
    if pos > 0 then
      put lowercase[pos] into char i of aString
    end if
  end repeat
  
  return aString
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCreateCaseLists me
  
  pCaseLists = [:]
  
  if the platform contains "Macintosh" then
    vA = numToChar(229)
  else
    vA = numToChar(194)
  end if
  
  -- pUPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZZÁÀ"&vA& "ÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙ€ÜÆØŒŸ"
  -- pLowercase = "abcdefghijklmnopqrstuvwxyzáà"&"â"&"äãåçéèêëíìîïñóòôöõúùûüæøœÿ"
  pCaseLists.setaprop(#uppercase, ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Á", "À", vA, "A", "Ä", "Ã", "Å", "Ç", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ñ", "Ó", "Ò", "Ô", "Ö", "Õ", "Ú", "Ù", "U", "Ü", "Æ", "Ø", "Œ", "Ÿ"])
  pCaseLists.setaprop(#lowercase, ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "á", "à", vA, "â", "ä", "ã", "å", "ç", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ñ", "ó", "ò", "ô", "ö", "õ", "ú", "ù", "û", "ü", "æ", "ø", "œ", "ÿ"])
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ____DATE_FUNCTIONS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetWeekDay me, dateObject, lang
  if ilk(dateObject) <> #date then dateObject = the systemdate
  vN = (dateObject - date(20030505)) mod 7
  vN = vN + 1 + (7 * (vN < 0))
  case lang of
    "de":
      li = ["Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"]
    "pt":
      li = ["Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado","Domingo"]
    "fr":
      li = ["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"]
    "es":
      li = ["Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo"]
    "it":
      li = ["Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato","Domenica"]
    "nl":
      li = ["Maandag","Dinsdag","Woensdag","Donderdag","Vrijdag","Zaterdag","Zondag"]
    "en":
      li = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
    otherwise:
      return vN
  end case
  return li.getAt(vN)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mFormatdate me, theFormat, theDate
  theFormat = string(theFormat)
  if length(theFormat) < 1 then theFormat = "yyyy/mm/dd"
  if ilk(theDate) <> #date then theDate = the systemdate
  
  offs = offset("y", theFormat)
  if offs > 0 then
    ende = offs+1
    repeat while char ende of theFormat = "y"
      if ende > length(theFormat) then exit repeat
      ende = ende+1
    end repeat
    len = ende - offs
    if len < 3 then theYear = char 3 to 4 of string(theDate.year)
    else theYear = string(theDate.year)
    put theYear into char offs to offs + len -1 of theFormat
  end if
  
  theFormat = mReplaceCharWithNumber(me, theFormat, "m", theDate.month)
  
  theFormat = mReplaceCharWithNumber(me, theFormat, "d", theDate.day)
  
  return theFormat
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mReplaceCharWithNumber me, theString, theChar, theNumber
  offs = offset(theChar, theString)
  if offs > 0 then
    ende = offs+1
    repeat while char ende of theString = theChar
      if ende > length(theString) then exit repeat
      ende = ende+1
    end repeat
    len = ende - offs
    theNumber = string(theNumber)
    repeat while length(theNumber) < len
      put "0" before theNumber
    end repeat
    put theNumber into char offs to offs + len -1 of theString
  end if
  return theString
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentDateAmerican me
  return mGetDateAmericanFormat(me, the systemdate)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentTimeAmerican me
  return mGetTimeAmericanFormat(me, the systemdate)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetDateAmericanFormat me, dateObject
  return dateObject.month & "/" & dateObject.day & "/" & dateObject.year
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetTimeAmericanFormat me, dateObject, withoutSeconds
  
  secs = dateObject.seconds
  hr = secs / (60*60)
  if hr > 11 then ampm = "pm"
  else ampm = "am"
  
  secs = secs - (60*60*hr)
  
  mins = secs / 60
  if mins < 10 then mins = "0" & mins
  
  if not withoutSeconds then
    
    secs = secs - (60*mins)
    if secs < 10 then secs = "0" & secs
    
    return hr & ":" & mins & ":" & secs && ampm
    
  else
    return hr & ":" & mins && ampm
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetDateTimeString me, date_Date
  
  if ilk(date_Date) <> #date then theDate = the systemdate
  else theDate = date_Date
  
  theYear = theDate.year
  
  theDay = theDate.day
  if theDay < 10 then theDay = "0" & theDay
  
  theMonth = theDate.month
  if theMonth < 10 then theMonth = "0" & theMonth
  
  theTime = mGetTimeStringFromSeconds(me, theDate.seconds)
  
  return theYear & "-" & theMonth & "-" & theDay & "T" & theTime
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetTimeStringFromSeconds me, integer_SecondsSinceMidnight
  
  if ilk(integer_SecondsSinceMidnight) <> #integer then secs = (the systemdate).seconds
  else secs = integer_SecondsSinceMidnight
  
  hours = secs / 3600
  if hours < 10 then hours = "0" & hours
  secs = secs mod 3600
  mins = secs / 60
  if mins < 10 then mins = "0" & mins
  secs = secs mod 60
  if secs < 10 then secs = "0" & secs
  
  return hours & ":" & mins & ":" & secs
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on interface me
  str = "Common Movie Script  by alex da franca c2003 -- alex@farbflash.de -- all rigths reserved"
  put RETURN & "Shared Global Handlers" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetGlobalList me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mMyClearGlobals me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mCallDestroy me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____WOODY_CHANGES" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on Authoring_ExchangeScriptListColorsToRGBs me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mCheckWoody me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetVersionNumber me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetPlatform me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mCheckMemberType me, memref, aType" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetMemType me, memref" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mCreateTimeout me, theName, theDuration, theHandler, theTarget" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____HANDLE_KEY_EVENTS" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mHandleKeyEvent me, tk, kc" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mSuspendAllKeyEvents me, flag" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mSuspendAllMouseEvents me, flag" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mDoQuit me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mQuitMovie me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____MOVIE_IDENTIFIER_HANDLERS" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mSetThisMovieName me, aName" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetThisMovieName me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____SPRITE_NAMING_HANDLERS" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetKanal me, einname" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mMeldeKanalname me, einname, einkanal" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mMeldeAbKanalname me, einname, einkanal" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____DEBUG_FUNCTIONS" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mEnablePut me, val" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mPut me, str, overwrite, dername" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mDebugImage me, img, overwrite, dername" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mLogDebugInfo me, str" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____MEMBER_UTILITIES" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mSuchMemFwd me, num, cl, dername" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetNewMember me, aType" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mEraseMember me, aMember" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetTempMemberList me, aType" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mEraseAllTempMembers me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____TEXT_UTILITIES" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on InitFonts me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on GetScrollRatio me, aMember -------------------------------------------" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetATextMem me, theFont, theFontsize, aliasFlag" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetAFont me, theFont" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetLineHeight me, textOrField" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetLinesOfWrappedText me, textOrField" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mCheckForTextAA me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____OBJECT_REFERENCING" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mCheckForXtra me, whichXtra" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetInstance me, instName" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetParentScriptList me, theModel" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____MATH_UTILITIES" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mApplyDynamic me, proz, methode" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetNextPowerOfTwo me, breite" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetNextLowerPowerOfTwo me, breite" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____STRING_FUNCTIONS" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mSplitPath me, fname, delim -- delim optional: default = the systems pathdelimiter" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetRelativePath me, aPath, mp -- mp optional: default = the moviepath" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetDelimitedPath me, thePath, delim -- delim optional: default = the systems pathdelimiter" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mCheckFileExists me, aPath" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mTranslate me, aString" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mUrlEncode me, srcText" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on urlDecode me, theString" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mString2Symb me, str" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mSymb2String me, sym" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx put <html>, <title> and <body> tags around chunk in order to use it as html of a text member" after str
  put RETURN & "on mHTMLize me, str" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on ____DATE_FUNCTIONS" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetWeekDay me, dateObject, lang" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetCurrentDateAmerican me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetCurrentTimeAmerican me" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetDateAmericanFormat me, dateObject" after str
  put RETURN & "" after str
  
  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str
  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str
  put RETURN & "on mGetTimeAmericanFormat me, dateObject, withoutSeconds" after str
  put RETURN & "" after str
  
  return str
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on getReferenceString me
  return "xscr()"
end
