I would suggest reading the following article:
http://www.julienlecomte.net/blog/2007/10/28/
In a nutshell, the error message you describe happens when code executed from a single javascript entry point runs for a long time. If you can split up your long processing into pieces and call them sequentially using setTimeout(), you will no longer get the error message.
From the article, a good template for long-running javascript routines:
function doSomething (callbackFn [, additional arguments]) {
// Initialize a few things here...
(function () {
// Do a little bit of work here...
if (termination condition) {
// We are done
callbackFn();
} else {
// Process next chunk
setTimeout(arguments.callee, 0);
}
})();
}