The standard JSF implementation doesn't provide facilities for this out the box. Besides, this is more a client side issue than a server side issue, so you'll really need to grab a client side language for this such as JavaScript. Since writing crossbrowser compatible JavaScript code for this particular functional requirement isn't exactly trivial, you'd like to use a JavaScript library for this which takes this into account, like jQuery.
Here's a complete kickoff example of how you could achieve this with help of jQuery.
Just paste this in your template (and preferably also refactor that raw code into its own .js file as well which you include by src attribute) and it'll work regardless of the page you have.