For core javascript and DOM references, see https://developer.mozilla.org/en/JavaScript. Do note that not all browser specifics are found there even though they sometimes tell you about IE non-conformance.
There are different ways to go about this.
In javascript_file.js
function countDown(counter) {
// code to deal with counting down, however that's supposed to work.
// [url=https://developer.mozilla.org/en/DOM/window#Methods]window.setTimeout() or window.setInterval()[/url] perhaps
}
echo '<script type="text/javascript" src="javascript_file.js"></script>';
echo '</head><body>';
echo '<body onload="countDown('.$counter.')">';
Or
javascript_file.php
echo 'var counter = ' . $_SESSION['counter'] . ';';
echo <<<EOS
function countDown() {
}
EOS;
echo '<script type="text/javascript" src="javascript_file.php"></script>';
echo '</head><body>';
echo '<body onload="countDown()">';
If you need the count down logic to be handled by php, you'd need to use ajax. Else, just set the counter variable in either of the above ways, and then implement the logic in javascript.