The best method to embed custom javascript in SharePoint pages is to create a .js file and then include it in the SharePoint Page. If you would like to include javascript functions in the onload event of a sharepoint page, use the _spBodyOnLoadFunctionNames array. Include the push method in your script with the title of your function. The function should not include parameters...
<script>
function runOnLoad(){
}
_spBodyOnLoadFunctionNames.push("runOnLoad");
</script>
Hope this helps!!! Good luck in the World of SharePoint!