Hello Adam,
First of all you need to create a Script Library (Application -> Code -> Script libraries). When creating one you can choose to use JavaScript (for clientside libraries) or Server JavaScript (for server side functions).
You can then add the script library you created to an XPage (or Custom Control) using the "Resources" property.
Mark