Its simple to call a piece of javascript code from JSF page.
In case its a not a function include directly
<a:commandbutton onclick="if (!confirm('do you agree ?')) return false" rendered="true" value="Valid"></a:commandbutton>
If you want to call a javascript function then ,
1. Include the javascript file where the function is defined
<script src="/dr/js/ext.js" type="text/javascript">
2. Javascript function would be like
function calcualte()
{
}
3. Call the function from the JSF component
<a:commandButton value="Valid"
rendered="true"
onclick="Calculate">