Make this a javascript function