Javascript basename() and dirname()

For my next stuff I needed the Javascript equivalents of PHP functions basename() and dirname(). Nothing genius: It obviously supports paths like /home/ozh/stuff.php, http://site.com/file.ext or double backslashed Win32 paths such as C:\\dir\\document.txt. Edit: Mister Ze in comments points out to PHP.JS, an ongoing project aiming to port PHP to Javascript. Some really neat stuff there.