/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp2 = false;
var cid;
var mbpage;
var memberid;
var vtag;
var nopets;
var prevresponse;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp2 = false;
  }
}
@end @*/

if (!xmlHttp2 && typeof XMLHttpRequest != 'undefined') {
  xmlHttp2 = new XMLHttpRequest();
}

// getElementById Special to handle quirky browsers
// most will use getElementById()
function getElementById_s2(id){
  var obj = null;
  if(document.getElementById){
  /* Prefer the widely supported W3C DOM method, if available:- */
  obj = document.getElementById(id);
  }else if(document.all){   /* Branch to use document.all on document.all only browsers. Requires that IDs are unique to the page and do not coincide with NAME attributes on other elements:- */
  obj = document.all[id];
  }
  /* If no appropriate element retrieval mechanism exists on this browser this function always returns null:- */
  return obj;
  }

function updateMBPage(tcid, tpage, tmemberid, tag, tnopets) {
  var obj;
	cid = tcid;
	mbpage = tpage;
	memberid = tmemberid;
	vtag = tag;
	nopets = tnopets;
	
  obj = getElementById_s2("maincontent");
  // Build the URL to connect to
  var url = "/message_board/get_mb_page.php?message_board_category_id=" + tcid + "&page=" + tpage + "&member_id=" + tmemberid + "&tag=" + tag +"&no_pets=" + nopets + "&rand=" + (Math.floor(Math.random()*99999));
  
  // Open a connection to the server
  xmlHttp2.open("GET", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp2.onreadystatechange = updateIt;

  // Send the request
  xmlHttp2.send(null);
}

function updateIt() {
  if (xmlHttp2.readyState == 4) {
    var response = xmlHttp2.responseText;
		if(response != prevresponse) {
     getElementById_s2("maincontent").innerHTML = response;
		}
		prevresponse = response;
		setTimeout('updateMBPage(\''+cid+'\',\''+mbpage+'\',\''+memberid+'\',\''+vtag+'\',\''+nopets+'\')', 5000);
		}
	//else  {  getElementById_s2("maincontent").innerHTML = 'Reloading...';  }
}
