find the varuables that are assumed to exist before this function runns
at first glance one would be $page
the simply wrap up what you have in
function TheFunction ( $page, $other_var, $other_var )
{
.... your code line for line ....
}
or if you don't want to pass in the variables explicityly
function TheFunction ()
{
global $page;
global $var_that_exists_before_function_call;
global $var_that_exists_before_function_call;
.... your code line for line ....
}