var xmlHttp = false;

// Mozilla, Opera, Safari sowie Internet Explorer 7
if (typeof(XMLHttpRequest) != 'undefined') {
   xmlHttp = new XMLHttpRequest();
   xmlHttp.overrideMimeType('text/xml; charset=ISO-8859-1');
};

if (!xmlHttp) {
  // Internet Explorer 6 und älter
  try {
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e) {
    try {
      xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
      xmlHttp  = false;
    };
  };
};

function sendRequest (thread, title) {
   var expr = /[?&]sid=(\w+)(&.*?)?$/;
   expr.exec(window.location.search);
   var sid = RegExp.$1;
   xmlHttp.open('GET', '?action=tracked&sid='+sid+'&trackthread='+thread+'&title='+title+'&submit=track',true);
   xmlHttp.send(null);
};

function track (read,threadid) {
   actStatus = document.getElementById(threadid);

   var expr = /^(.+?\/)[^\/]+?$/; //
   expr.exec(actStatus.getAttribute('src'));
   var imgLoc = RegExp.$1;

   if (actStatus.getAttribute("title") == 0) {
      if (read == 1) {
	 actStatus.setAttribute('src',imgLoc+'status_thread_new_sticked.gif');
      } else if (read == 0) {
	 actStatus.setAttribute('src',imgLoc+'status_thread_old_sticked.gif');
      }
      document.getElementById("trackeditemsstart").innerHTML ++;
      document.getElementById("trackeditemsend").innerHTML ++;
      actStatus.setAttribute("title",1);
      sendRequest(threadid, 0);
   } else if (actStatus.getAttribute("title") == 1){
      if (read == 1) {
	 actStatus.setAttribute('src',imgLoc+'status_thread_new.gif');
      } else if (read == 0){
	 actStatus.setAttribute('src',imgLoc+'status_thread_old.gif');
      }
      document.getElementById("trackeditemsstart").innerHTML --;
      document.getElementById("trackeditemsend").innerHTML --;
      actStatus.setAttribute("title",0);
      sendRequest(threadid, 1);
   };
};


