What is your script framework..? I suggest you're use framework, like jQuery, mootools, prototype.js, or xajax (specially for ajax).