function wBB_AJAX_Init(threadlistid) {
 if (ajax_compatible)	{
  var tds = fetch_tags(fetch_object(threadlistid), 'td');
  for (var i = 0; i < tds.length; i++) {
   if (tds[i].hasChildNodes() && tds[i].id && tds[i].id.substr(0, 4) == 'wbb_') {
    var atags = fetch_tags(tds[i], 'a');
    for (var j = 0; j < atags.length; j++) {
     var details = tds[i].id.split('_');
     switch (details[1]) {
      case 'boardtitle':
      if (canBoardTitle) {
       tds[i].style.cursor = 'default';
       tds[i].ondblclick = function() { try { titleedit.restore(); } catch(e) {} titleedit = new wBB_AJAX_TitleEdit(this, 'boardtitle'); };
      }
      break;

      case 'threadtitle':
       if (canThreadTitle || canOwnThreadTitle) {
       tds[i].style.cursor = 'default';
       tds[i].ondblclick = function() { try { titleedit.restore(); } catch(e) {} titleedit = new wBB_AJAX_TitleEdit(this, 'threadtitle'); };
      }
      break;
     }
     break;
    }

    if (canOpenClose || canOwnOpenClose) {
     if (tds[i].id.substr(4, 6) == 'status') {
      tds[i].style.cursor = 'default';
      wBB_DblClick_Handler(tds[i], function(e) { openclose = new wBB_AJAX_OpenClose(this); });
     }
    }

   }
  }
 }
}

function wBB_AJAX_OpenClose(obj) {
 this.obj = obj;
 this.threadid = this.obj.id.substr(this.obj.id.lastIndexOf('_') + 1);
 this.imgobj = fetch_object('threadstatus_' + this.threadid);
 this.xml_sender = null;

 this.toggle = function toggle_openclose() {
  this.xml_sender = new AJAX_Handler_wBB(true);
  this.xml_sender.onreadystatechange(this.onreadystatechange);
  this.xml_sender.send('ajax_wbb.php', 'action=threadopenclose&tid=' + this.threadid + '&src=' + AJAX_PHP.urlencode(this.imgobj.src));
 }

 var me = this;

 this.onreadystatechange = function() {
  if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText) {
   me.imgobj.src = me.xml_sender.handler.responseText;
   if (iobj = fetch_object("tlist_" + me.threadid)) {
    if (me.imgobj.src.indexOf('_lock') != -1) {						// locked thread
     iobj.value = iobj.value | 1;
    } else {																							// unlocked thread
     iobj.value = iobj.value & ~1;
    }
   }
	
   if (is_ie) {
    me.xml_sender.handler.abort();
   }
  }
 }

 if (!canOpenClose) {
  editok = checkRights(this.threadid);
  if (editok) this.toggle();
 } else {
  this.toggle();
 }
// this.toggle();
}

function wBB_AJAX_TitleEdit(obj, boardtitle) {
 this.obj = obj;
 this.threadid = this.obj.id.substr(this.obj.id.lastIndexOf('_') + 1);
 this.linkobj = fetch_object(boardtitle + '_' + this.threadid);
 this.container = this.linkobj.parentNode;
 this.editobj = null;
 this.xml_sender = null;

 this.origtitle = '';
 this.editstate = false;

 this.edit = function() {
  if (this.editstate == false) {
   // create the new editor input box properties...
   this.inputobj = document.createElement('input');
   this.inputobj.type = 'text';
   this.inputobj.size = 50;
   this.inputobj.maxLength = 85;
   this.inputobj.style.width = Math.max(this.linkobj.offsetWidth, 250) + 'px';
   this.inputobj.className = 'bginput';
   this.inputobj.value = AJAX_PHP.unhtmlspecialchars(this.linkobj.innerHTML);
   this.inputobj.title = this.inputobj.value;

   this.inputobj.onblur = function (e) { titleedit.restore(); };
   this.inputobj.onkeypress = function (e) {
    e = e ? e : window.event;
    switch (e.keyCode) {
     case 13: // return / enter
      titleedit.inputobj.blur();
      return false;
     case 27: // escape
      titleedit.inputobj.value = titleedit.origtitle;
      titleedit.inputobj.blur();
      return true;
    }
   };

   this.editobj = this.container.insertBefore(this.inputobj, this.linkobj);
   this.editobj.select();
   this.origtitle = this.linkobj.innerHTML;
   this.linkobj.style.display = 'none';
   this.editstate = true;
  }
 }

 this.restore = function() {
  if (this.editstate == true) {
   if (this.editobj.value != this.origtitle) {
    this.linkobj.innerHTML = AJAX_PHP.htmlspecialchars(this.editobj.value);
    this.save(this.editobj.value);
   } else {
    this.linkobj.innerHTML = this.editobj.value;
   }

   this.container.removeChild(this.editobj);
   this.linkobj.style.display = '';
   this.editstate = false;
  }
 }

 this.save = function(titletext) {
  this.xml_sender = new AJAX_Handler_wBB(true);
  this.xml_sender.onreadystatechange(this.onreadystatechange);
  var dovalue = "update" + boardtitle;
  this.xml_sender.send('ajax_wbb.php', 'action=' + dovalue + '&tid=' + this.threadid + '&title=' + AJAX_PHP.urlencode(titletext));
 }

 var me = this;

 this.onreadystatechange = function() {
  if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText) {

   me.linkobj.innerHTML = me.xml_sender.handler.responseText;
			
   if (is_ie) {
    me.xml_sender.handler.abort();
   }

  }
 }
 if (boardtitle == 'threadtitle') {
  if (!canThreadTitle) {
   editok = checkRights(this.threadid);
   if (editok) this.edit();
  } else {
   this.edit();
  }
 } else {
  this.edit();
 }
// this.edit();
}

function checkRights(threadid) {
 var thids = threadids.split(',');
 var starter = threadstarter.split(',');
 var editok = 0;
 for (var x = 0; x < thids.length; x++) {
  if (thids[x] == threadid && starter[x] == myAJAXid) {
   var editok = 1;
   break;
  }
 }
return editok;
}

