This event can be on a Custom Control or an XPage depending on your requirements. You need to research this a bit because some items are not available in the BeforePageLoad event that are there in the AfterPageLoad, so it really depends on what you need to do. And of course you will write it in JavaScript, but the syntax is almost the same as LS.