Hello. I've searched the forum, but couldn't find a solution to my problem.

I'm using a great little script (AjaxTwits) to load multiple contributors' Twitter timelines into my site. With a couple small mods, it works perfectly for my needs. (You can see it in action in the sidebar here.) The only rub is that Twitter occassionally responds slowly, which (notwithstanding AjaxTwits' caching) can cause the script to throw a 404 error that breaks the whole page.

So, I endeavored to add a timeout function that would gracefully output an error message after a set period of time, rather than waiting forever or throwing an error. After a bunch of studying and google searches, I found this script and I adapted it to my needs (code below with key timer functions in bold). The script works in the sense that it properly loads the Twitter feeds. But the timeout function DOES NOT work, even though it works in the original and I barely modified it.

If anyone sees an error in this or can suggest a better approach, I'd greatly appreciate it! Thanks!

function sendAjaxRequest(url, eventhandler) {

// Standard asynchonous AJAX code
		var xhr = new XMLHttpRequest();

xhr.open("POST", url, true );

// The function that will be called asynchronously when the server sends
// back its response
   // If you're using the file system instead of a web server then xhr.status
   // will come back as 0, not 200.  And of course if the page isn't found
   // then a web server will send back a status of 404.  xhr.readyState is 4
   // when the page is done.
   if (xhr.readyState == 4 && xhr.status == 200) {
      clearTimeout(xhrTimeout);   // Looks like we didn't time out!
      // Use xhr.responseText to parse the server's response
	 // alert(xhr.responseText);
	 // I took this out the above line and added the below line to make sure the AjaxTwits continues
// Now that we're ready to handle the response, we can make the request
// Timeout to abort in 5 seconds
var xhrTimeout=setTimeout("ajaxTimeout();",5000);
function ajaxTimeout(){
alert("Well dang, the AJAX request timed out.  Did you lose network "+
         "connectivity for some reason?");
   // Note that at this point you could try to send a notification to the
   // server that things failed, using the same xhr object.

function getAjaxTwits(url, itemCount) {
	var twitter = document.getElementById('AjaxTwits');
	var twitterload = document.getElementById('AjaxTwitsLoader');
	sendAjaxRequest(url, function(ajaxRequest) {
		if (ajaxRequest.responseText) {
			var ans = eval('(' + ajaxRequest.responseText + ')');

			if (ans.item) {
				for (var i = 0; i < itemCount; i++) {
					var li = document.createElement("LI");
					li.className = "twitter-item";				
					var message = hyperlinks(ans.item[i].description);
					message = twitter_users(message);
					li.innerHTML += "<font color='#D36727'><u>" + ans.item[i].feedname + "</u>:</font> ";
					li.innerHTML += message + " [";
		var a = document.createElement("A");
					//	a.href = ans.item[i].url;
						a.href = "http://www.twitter.com/" + ans.item[i].user;
						a.className = "twitter-link";
					//	a.innerHTML = "posted " + ans.item[i].date;
					a.innerHTML = "<span style='white-space:nowrap;'>" + ans.item[i].date + "</span>";
					a.target = "_blank";
					li.innerHTML += "]";

function hyperlinks(text) {
	text = text.replace(/\s(http:\/\/[a-z][a-zA-Z0-9\/\*\-\?\.\&\%\$]*)/ig," <a href=\"$1\" class=\"twitter-link\" \"target\">$1</a>");
	text = text.replace(/\s([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)([\s|\.|\,])/ig," <a href=\"$1\" class=\"twitter-link\" \"target\">$1</a>$2");
	// match www.something.domain/path/file.extension?some=variable&another=asf%
	text = text.replace(/\s(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)([\s|\.|\,])/ig," <a href=\"http://$1\" class=\"twitter-link\" \"target\">$1</a>$2");      
	return text;

function twitter_users(text) {
    text = text.replace(/([\.|\,|\:|\|\|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/ig, "$1<a href=\"http://twitter.com/$2\" class=\"twitter-user\" \"target\">@$2</a>$3 ");
    return text;