I am trying to add stock checking feature upon "Add to Cart" button click. I want to use AJAX.

I know how to do all the JavaScript stuff, but I am just not sure how to return values from Zen Cart without templates? Ideally I'd like to have a separate file that I can send requests to, but have ability to use ZC internal functions from that file. How can this be done?

Thank you!