Most of the processing done by this script should really be done server-side.
Simple experiments with the XMLHttpRequest object.
View the source and documentation for xHttpRequest.
Test 1, Test 2