var mb_path = 'http://' + location.hostname + '/messageboard/';


function Browser() {

   var ua, s, i;

   this.isIE = false;

   this.isNS = false;

   this.version = null;



   ua = navigator.userAgent;



   s = "MSIE";

   if ((i = ua.indexOf(s)) >= 0) {

        this.isIE = true;

        this.version = parseFloat(ua.substr(i + s.length));

        return;

   }



   s = "Netscape6/";

   if ((i = ua.indexOf(s)) >= 0) {

      this.isNS = true;

      this.version = parseFloat(ua.substr(i + s.length));

      return;

   }



   // Treat any other "Gecko" browser as NS 6.1.



   s = "Gecko";

   if ((i = ua.indexOf(s)) >= 0) {

      this.isNS = true;

      this.version = 6.1;

      return;

   }

}



var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();

dragObj.zIndex = 0;



function dragStart(event, id) {



   var el;

   var x, y;



   // If an element id was given, find it. Otherwise use the element being

   // clicked on.



   if (id)
      dragObj.elNode = document.getElementById(id);
   else
   {
      if (browser.isIE)
         dragObj.elNode = window.event.srcElement;

      if (browser.isNS)
         dragObj.elNode = event.target;



      // If this is a text node, use its parent element.



      if (dragObj.elNode.nodeType == 3)
         dragObj.elNode = dragObj.elNode.parentNode;

   }



   // Get cursor position with respect to the page.



   if (browser.isIE) {

      x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;

      y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;

   }

   if (browser.isNS) {

      x = event.clientX + window.scrollX;

      y = event.clientY + window.scrollY;

   }



   // Save starting positions of cursor and element.



   dragObj.cursorStartX = x;

   dragObj.cursorStartY = y;

   dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10);

   dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10);



   if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;

   if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 0;



   // Update element's z-index.



   //dragObj.elNode.style.zIndex = ++dragObj.zIndex;



   // Capture mousemove and mouseup events on the page.



   if (browser.isIE) {

      document.attachEvent("onmousemove", dragGo);

      document.attachEvent("onmouseup", dragStop);

      window.event.cancelBubble = true;

      window.event.returnValue = false;

   }

   if (browser.isNS) {

      document.addEventListener("mousemove", dragGo, true);

      document.addEventListener("mouseup", dragStop, true);

      event.preventDefault();

   }

}



function dragGo(event) {

   var x, y;



   // Get cursor position with respect to the page.



   if (browser.isIE) {
      x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
      y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
   }

   if (browser.isNS) {

      x = event.clientX + window.scrollX;
      y = event.clientY + window.scrollY;

   }



   // Move drag element by the same amount the cursor has moved.



   dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";

   dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px";



   if (browser.isIE) {

      window.event.cancelBubble = true;

      window.event.returnValue = false;

   }

   if (browser.isNS)
      event.preventDefault();

}



function dragStop(event) {

   // Stop capturing mousemove and mouseup events.

   if (browser.isIE) {

      document.detachEvent("onmousemove", dragGo);

      document.detachEvent("onmouseup", dragStop);

   }

   if (browser.isNS) {

      document.removeEventListener("mousemove", dragGo, true);

      document.removeEventListener("mouseup", dragStop, true);

   }

}


var current_con_id;
var popupbox_mode = '';
var popupbox_last_id = '';
function popupbox (mode, session_id, subject, id, width, height)
{
   var screen_width;
   var screen_height;
   var set_width;
   var set_height;
   var search_percent_sign;


   screen_width = screen.width;
   screen_height = screen.height;

   search_percent_sign = width.indexOf ('%');
   if (search_percent_sign != -1)
      set_width =  width.substr(0, search_percent_sign) / 100 * screen_width;
   else
   {
      search_percent_sign = width.indexOf ('px');
      set_width =  width.substr(0, search_percent_sign);
   }

   search_percent_sign = height.indexOf ('%');
   if (search_percent_sign != -1)
      set_height =  height.substr(0, search_percent_sign) / 100 * screen_height;
   else
   {
      search_percent_sign = height.indexOf ('px');
      set_height =  height.substr(0, search_percent_sign);
   }

   var contentbox = document.getElementById('contentbox');

   contentbox.style.top = Math.round((screen_height / 2) - (set_height / 2)) + 'px';
   contentbox.style.left = Math.round((screen_width / 2) - (set_width / 2)) + 'px';


   contentbox.style.width = width;
   contentbox.style.height = height;
   contentbox.style.zIndex = 9002;

   if (mode == 'announcement')
   {
      document.getElementById('contentbox_content').innerHTML = loading_img ();
      document.getElementById('contentbox').style.display = 'block';
      document.getElementById('contentbox_title').innerHTML = document.getElementById('msg_' + id).innerHTML;
      make_request('announcement', mb_path + 'announcement.php', '?aid=' + id);
   }
   else if (mode == 'conversation')
   {
      if (current_con_id == id && document.getElementById('contentbox_content').innerHTML != '')
      {
         document.getElementById('contentbox').style.display = 'block';
      }
      else
      {
         document.getElementById('contentbox_content').innerHTML = loading_img ();
         document.getElementById('contentbox').style.display = 'block';
         document.getElementById('contentbox_title').innerHTML = 'Full Conversation';
         make_request('announcement', mb_path + 'post.php', '?mode=conversation&hide_postbox=nopostbox&showlogo=0&msgbox_id=' + session_id + '&con_id=' + id + '&root_php_file=' + root_php_file);
      }


      current_con_id = id;
   }
   else if (mode == "message")
   {
      document.getElementById('contentbox_content').innerHTML = loading_img ();
      document.getElementById('contentbox').style.display = 'block';
      if (subject != "")
         document.getElementById('contentbox_title').innerHTML = subject;
      else
         document.getElementById('contentbox_title').innerHTML = '';
      change_text('contentbox_content', id);
   }
   else if (mode == "video")
   {
      if (popupbox_last_id == id && document.getElementById('contentbox_content').innerHTML != '' && document.getElementById('contentbox').style.display == 'none')
         document.getElementById('contentbox').style.display = "block";
      else
      {
         document.getElementById('contentbox_content').innerHTML = loading_img ();
         document.getElementById('contentbox').style.display = 'block';
         document.getElementById('contentbox_title').innerHTML = 'Video';

         var video_player = '<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe>';

         change_text('contentbox_content', video_player);
      }
   }


   popupbox_mode = mode;
   popupbox_last_id = id;
}


function contentbox_close ()
{
   document.getElementById('contentbox').style.display = 'none';

   if (popupbox_mode == 'video')
   {
      document.getElementById('contentbox_title').innerHTML = '';
      document.getElementById('contentbox_content').innerHTML = '';
   }

}




function f_open_window (url, win_name, win_width, win_height)
{
   var win_open;
   var win_options;

   if (win_width == '')
      win_width = 520;
   if (win_height == '')
      win_height = 400;

   win_options = 'status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
   win_options = win_options + ',width=' + win_width;
   win_options = win_options + ',height=' + win_height;
   win_options = win_options + ',screenX=150,screenY=150,left=150,top=150';

   win_open = window.open('', win_name, win_options);
   win_open.location = url;
   win_open.focus();
   return win_open;
}


function quickmsg_box (action)
{
   thisobj = document.getElementById('quickmsg_box');

   if (action == 'cleartext')
   {
      if (thisobj.value == "Share a quick message")
         thisobj.value = '';

      document.getElementById('quickmsg_box_btn').disabled = false;
   }
   else if (action == 'defaulttext')
   {
      if (thisobj.value == "" && quickmsg_box_default_text == '')
      {
         thisobj.value = 'Share a quick message';
         document.getElementById('quickmsg_box_btn').disabled = true;
      }
   }
   else if (action == "submit")
   {
      make_request('popupmsg', mb_path + 'user_update.php', '?quick_message=' + escape (thisobj.value));
      if (thisobj.value == '')
         thisobj.value = "Share a quick message";
   }

}


function headline_box (action, gid)
{
   thisobj = document.getElementById('quickmsg_box');

   if (action == 'clear')
   {
      if (thisobj.value == "Share a message with the group")
         thisobj.value = '';
      else
         thisobj.select ();
   }
   else if (action == "submit")
   {
      make_request('popupmsg', mb_path + 'group_update.php', '?action=headline&gid=' + gid + '&headline=' + escape (thisobj.value));
      if (thisobj.value == '')
         thisobj.value = "Share a message with the group";
   }

}

var bname = navigator.appName;
var msgbox_text_length = 0;
var request_output = '';
function text_limit(id)
{
   thisobj = document.getElementById(id);
   if (thisobj.value.length==max_text_length) return false;
      return true;
}



function text_counter(id, cnt, max_text_length)
{
   objcnt = document.getElementById(cnt);
   thisobj = document.getElementById(id).value;


   text_limit_left = max_text_length-thisobj.length;

   if(bname == "Netscape")
      objcnt.textContent = text_limit_left;
   else
      objcnt.innerText = text_limit_left;

   msgbox_text_length = thisobj.length;


   if (msgbox_text_length > 0)
   {
      if (text_limit_left > -1)
      {
         document.getElementById('msgbox_submit_button_' + textbox_session_id).disabled = false;
         if (text_limit_left < 10)
            document.getElementById(cnt + '_color').color = 'red';
         else
            document.getElementById(cnt + '_color').color = '#CCCCCC';
      }
      else
      {
         document.getElementById('msgbox_submit_button_' + textbox_session_id).disabled = true;
         document.getElementById(cnt + '_color').color = 'red';
      }

   }
   else
      document.getElementById('msgbox_submit_button_' + textbox_session_id).disabled = true;
}

function create_object(objId)
{
   if (document.getElementById)
      return document.getElementById(objId);
   else if (document.layers)
      return eval("document." + objId);
   else if (document.all)
      return eval("document.all." + objId);
   else
      return eval("document." + objId);
}

function empty(atextfield)
{
   if (atextfield == "" || atextfield == null)
      return true;
   else if (typeof atextfield == "sting")
   {
      if (atextfield.length == 0)
         return true;
      else
         return false;
   }
   else
      return false;
}

String.prototype.trim = function() {
   return this.replace(/^\s+|\s+\$/g,"");
}

function change_text(id, text){
   var thisobj = document.getElementById(id);
   if (thisobj)
      thisobj.innerHTML = text;
}

function text_replace (id, search, newstring) {
   var thisobj = document.getElementById(id);

   search_begin = '<' + search.toUpperCase() + '>';
   search_end = '</' + search.toUpperCase() + '>';

   searchbpos = thisobj.innerHTML.toUpperCase().indexOf (search_begin);

   if (searchbpos != -1)
   {
      searchepos = thisobj.innerHTML.toUpperCase().indexOf (search_end);

      thisobj.innerHTML = thisobj.innerHTML.substr(0, searchbpos) + newstring + thisobj.innerHTML.substring(searchepos);
   }
}

function add_text(id, text, position){
   var thisobj = document.getElementById(id);

   if (position == 'top')
      thisobj.innerHTML = text + thisobj.innerHTML;
   else
      thisobj.innerHTML = thisobj.innerHTML + text;
}

function post_reply (session_id, replyto, pid)
{
   window.scrollTo(0,0);
   message_board_top_display (1);
   textbox_session_id = session_id;
   if (session_id !== '')
      cur_session_id = session_id;

   if (uid > 0)
   {
      if (document.getElementById('contentbox'))
         if (document.getElementById('contentbox').style.display != 'none')
            document.getElementById('contentbox').style.display = 'none';

      if (pid != '')
         if (document.getElementById('msg_' + pid))
            document.getElementById('post_notice_' + textbox_session_id).innerHTML = '<font color=#666666><i>' + replyto + ' says</i></font> ' + document.getElementById('msg_' + pid).innerHTML;

      if (document.getElementById('view_online_tab'))
         style_display_inline ('view_online_tab', 1);

      document.getElementById('msgbox_' + textbox_session_id).style.display = "";
      change_text('msgbox_title_' + textbox_session_id, 'Reply to ' + replyto);
      document.getElementById('msgbox_textarea_' + textbox_session_id).focus();
      document.getElementById('msgbox_textarea_' + textbox_session_id).value = '@' + replyto.replace(" ", "{s}") + ' ';
      //change_text('msgbox_textarea', '@' + replyto.replace(" ", "{s}") + ' ');
      text_counter('msgbox_textarea_' + textbox_session_id,'msgcounter_' + textbox_session_id, 250);
      style_display ('post_footer_' + textbox_session_id, 1);
      set_postbox_size('', '60px');
      reply_pid = pid;
   }
   else
      popup_msg ('<br>Please <a href=\"login.php\" target=\"_blank\">LOGIN</a> first.');
}

function postbox_clear ()
{
   var thisobj = document.getElementById('msgbox_textarea_' + textbox_session_id);

   if (post_msgbox_title == thisobj.value)
      thisobj.value = '';
}

function msg_user (session_id, username)
{
   //window.scrollTo(0,0);
   textbox_session_id = session_id;
   if (uid > 0)
   {
      if (document.getElementById('contentbox'))
         if (document.getElementById('contentbox').style.display != 'none')
            document.getElementById('contentbox').style.display = 'none';

      if (document.getElementById('chat_online_members'))
         style_display ('chat_online_members', 0);

      if (document.getElementById('view_online_tab'))
         style_display_inline ('view_online_tab', 1);

      document.getElementById('msgbox_' + textbox_session_id).style.display = "";
      change_text('msgbox_title_' + textbox_session_id, 'Message ' + username);
      document.getElementById('msgbox_textarea_' + textbox_session_id).focus();
      document.getElementById('msgbox_textarea_' + textbox_session_id).value = '@' + username.replace(" ", "{s}") + ' ';

      text_counter('msgbox_textarea_' + textbox_session_id,'msgcounter_' + textbox_session_id, 250);
      style_display ('post_footer_' + textbox_session_id, 1);
      set_postbox_size('', '60px');

      close_tab ('m_friend_panel');
   }
   else
      popup_msg ('<br>Please <a href=\"login.php\" target=\"_blank\">LOGIN</a> first.');
}


function video_pin (id)
{
   var video_field = document.getElementById('ebc_' + id);
   var video_pin = document.getElementById('pin_' + id);
   var pin_text = document.getElementById('ptx_' + id);

   if(video_field.className == 'reply-hover')
   {
      video_field.className = 'video-block';
      video_pin.alt = 'Show when hover';
      video_pin.src = '../mbimages/icons/pin_down.gif';
      pin_text.innerHTML = 'Show when hover';
   }
   else
   {
      video_field.className = 'reply-hover';
      video_pin.alt = 'Keep video showing';
      video_pin.src = '../mbimages/icons/pin.gif';
      pin_text.innerHTML = 'Keep video showing';
   }
}

function post_favourite (pid)
{
   var thisobj = document.getElementById('status_star_' + pid);
   if(thisobj.className == 'fav')
   {
      thisobj.className = 'fav-action non-fav';
      thisobj.title = 'favorite this post';
      make_request('favourite', mb_path + 'post.php', '?mode=favourite&action=remove&pid=' + pid);
   }
   else
   {
      thisobj.className = 'fav';
      thisobj.title = 'un-favorite this post';
      make_request('favourite', mb_path + 'post.php', '?mode=favourite&action=add&pid=' + pid);
   }
}

function post_delete (pid, post_belong)
{
   if (post_belong == 1) //meaning own post
      var delete_confirm = confirm("Are you sure you want to delete this post? \nThere is no UNDO.")
   else if (post_belong == 2) //belonging to other
   {
      var delete_confirm = confirm("Are you sure you want to delete this post? \nThere is no UNDO.")
      var delete_reason = prompt("Reason for deleting this post:", "");

      if (delete_reason == null || delete_reason == "")
         delete_confirm = false;
   }

   var thispid = document.getElementById('post_' + pid);

   if (delete_confirm)
   {
      thispid.parentNode.removeChild(thispid);
      make_request('delete', mb_path + 'post.php', '?mode=delete&pid=' + pid + "&del_reason=" + escape(delete_reason));
   }
}

function announcement_delete (aid)
{
   var delete_confirm = confirm("Are you sure you want to delete this announcement? \nThere is no UNDO.")

   var thisobj = document.getElementById('anno_' + aid);

   if (delete_confirm)
   {
      thisobj.parentNode.removeChild(thisobj);
      make_request('delete', mb_path + 'announcement.php', '?mode=delete&aid=' + aid);
   }
}

function video_delete (vid)
{
   var delete_confirm = confirm("Are you sure you want to delete this video? \nThere is no UNDO.")

   var thisvid = document.getElementById('post_' + vid);

   if (delete_confirm)
   {
      thisvid.parentNode.removeChild(thisvid);
      make_request('delete', mb_path + 'video.php', '?mode=delete&vid=' + vid);
   }
}

function loading_img ()
{
   return '<img src="../mbimages/icons/ajax.gif"> Loading...';
}


function dropdownlist_selected(list_id)
{

   thisobj = document.getElementById(list_id);
   var len = thisobj.length;
   var i = 0;
   var chosen = "";

   for (i = 0; i < len; i++)
   {
      if (thisobj[i].selected)
         chosen = thisobj[i].value
   }

   return chosen;
}



function fl_filter (mode)
{
   var gender = dropdownlist_selected('fl_filter_gender');

   make_request('headto', mb_path + 'friend_listall.php', '?mode=' + mode + '&uid=' + uid + '&gender=' + gender);
}


function fl_listall (session_id, uid)
{
   window.scrollTo(0,0);
   message_board_top_display (0);
   change_text('boardarea', loading_img ());
   make_request('headto', mb_path + 'friend_listall.php', '?mode=friend_list&uid=' + uid + '&session_id=' + session_id);
}

var root_php_file = '';
function set_root_php_file (name)
{
   root_php_file = name;
}


var cur_mpost_id = '';
var cur_session_id = '';
function make_request (mode, url, parameters)
{
   var http_request = false;
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
              // set type accordingly to anticipated content type
         //http_request.overrideMimeType('text/xml');
         http_request.overrideMimeType('text/html');
      }
   } else if (window.ActiveXObject) { // IE
      try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
      }
   }
   if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
   }

   if (typeof(root_path) != "undefined" && root_path != '' && url.substr (0, 7) != 'http://')
      url = root_path + url;
   //else if (typeof(mb_path) != "undefined")
   //   url = mb_path + url;
   //if (uid == 828)
   //alert (url)
   http_request.onreadystatechange = function() { print_contents(mode, http_request); };
   //alert (url + parameters)
   http_request.open('POST', url + parameters, true);
   http_request.send(null);
}

function set_textbox_session_id (session_id)
{
   textbox_session_id = session_id;
}


function more_post (mode, session_id, more_button_id, url, parameters)
{
   change_text(more_button_id, loading_img ());
   cur_mpost_id = more_button_id;
   cur_session_id = session_id;
   make_request(mode, mb_path + url, parameters);
}

function time ()
{
   return Math.floor(new Date().getTime() / 1000);
}

var chatbox_init = 0;
var chatbox_closed = 0;
var chat_session = '';
var loaded_chat_session = '';
var newpost_text = '';
var last_check_time = 0;
var last_post_time = 0;
var inserted_post_count = 0;
var inserted_post_delete_count = 0;
var inserted_post_id = new Array();
function new_post (mode, session_id, button_id, url, parameters)
{
   chat_session = session_id;
   loaded_chat_session = chat_session;

   if (document.getElementById(button_id))
   {
      thisobj = document.getElementById(button_id);
      var thisobj_display = thisobj.style.display;
   }
   else
   {
      var thisobj_display = 'none';
   }

   if (mode == 'newpost_num')
   {
      if (thisobj_display == "none")
      {
         cur_mpost_id = button_id;
         cur_session_id = session_id;
         //alert (url+parameters + '&lpt=' + last_post_time + '&ct=' +  time())
         make_request(mode, url, parameters + '&lpt=' + last_post_time + '&ct=' + time());
      }
   }
   else if (mode == 'newpost_insert')
   {
      thisobj.style.display = "none";
      cur_mpost_id = button_id;
      cur_session_id = session_id;
      make_request(mode, url, parameters + '&session_id=' + session_id + '&lpt=' + last_post_time + '&lct=' + last_check_time + '&ct=' + time());
   }


}

function topic_create_tag (session_id)
{
   var topic = document.getElementById('topic_text_field').value.trim();

   if (topic != '')
   {
      document.getElementById('msgbox_textarea_' + session_id).focus();
      document.getElementById('msgbox_textarea_' + session_id).value = '<' + document.getElementById('topic_text_field').value.trim() + '> ' + document.getElementById('msgbox_textarea_' + session_id).value;
   }
   contentbox_close ();
}

function topic_fetch (session_id, gid, tid, topic, root_php_file)
{
   topic_tab_close ();
   if (topic == '')
   {
      msgbox_title_changed = 0;
      change_text('msgbox_title_' + session_id, 'What\'s Happening?');
      change_text('message_board_label', '');
   }
   else
   {
      msgbox_title_changed = 1;
      change_text('msgbox_title_' + session_id, '<font color=\"#999999\"><b>TOPIC</b></font> ' + topic);
      change_text('message_board_label', '<font size=\"4\"><font color=\"#999999\"><b>TOPIC</b></font> ' + topic + "</font>");
   }
   topic_tid = tid;

   last_selected_tab_obj = document.getElementById('tab_' + last_selected_tab);
   if (last_selected_tab_obj)
      last_selected_tab_obj.style.background = '';

   change_text('boardarea', loading_img ());
   make_request('boardarea', mb_path + 'post.php', '?mode=topic&&ptext=1&hide_postbox=nopostbox&msgbox_id=' + session_id + '&session_id=' + session_id + "&gid=" + gid + "&tid=" + tid + "&root_php_file=" + root_php_file);
}

function topic_list_fetch (content_id, session_id, gid, mode, cpage, maxpage, sort)
{
   if (!(mode == 'prev' && cpage <= 1) && !(mode == 'next' && cpage >= maxpage))
   {

      if (mode == 'prev')
         var lpage = cpage - 1;
      else if (mode == 'next')
         var lpage = cpage + 1;
      else
         var lpage = cpage;

      make_request(content_id + '_container', mb_path + 'topic_list_fetch.php', '?mode=' + mode + '&session_id=' + session_id  + '&gid=' + gid + '&lpage=' + lpage  + '&sort=' + sort);

      var page_control_content = "<a href=\"javascript: topic_list_fetch ('" + content_id + "', '" + session_id + "', " + gid + ", 'prev', " + lpage + ", " + maxpage + ", '" + sort + "')\" title=\"Previous Page\"><img id=\"ibtn_prev_" + content_id  + "\" src=\"http://www.animeboy.org/images/btn_prev.gif\" border=0 width=14></a><div class=\"page_count_div\">" + lpage + "</div><a href=\"javascript: topic_list_fetch ('" + content_id + "', '" + session_id + "', " + gid + ", 'next', " + lpage + ", " + maxpage + ", '" + sort + "')\" title=\"Next Page\"><img id=\"ibtn_next_" + content_id  + "\" src=\"http://www.animeboy.org/images/btn_next.gif\" border=0 width=14></a>";
      if (content_id == "topic_popular")
         var div_count_id = "topic_popular_control";
      else
         var div_count_id = "topic_new_control";
      change_text(div_count_id, page_control_content);


   }
   if (mode == 'prev')
   {
      if (cpage - 1 <= 1)
         document.getElementById('ibtn_' + mode + '_' + content_id).src = "http://www.animeboy.org/images/btn_" + mode + "_disable.gif";
      else
         document.getElementById('ibtn_' + mode + '_' + content_id).src = "http://www.animeboy.org/images/btn_" + mode + ".gif";
   }
   else if (mode == 'next')
   {
      if (cpage + 1 >= maxpage)
         document.getElementById('ibtn_' + mode + '_' + content_id).src = "http://www.animeboy.org/images/btn_" + mode + "_disable.gif";
      else
         document.getElementById('ibtn_' + mode + '_' + content_id).src = "http://www.animeboy.org/images/btn_" + mode + ".gif";
   }
}


function topic_insert_box (session_id)
{
   var create_topic_msg = "<font color=\"#666666\">TOPIC</font> <input id=\"topic_text_field\" type=\"text\" name=\"topic_text_field\" size=50 style=\"font-size: 14pt\" maxlength=100 onKeyUp=\"text_counter('topic_text_field','topic_max_len', '100')\"><br><font color=\"#666666\">Maximum character: <font id=\"topic_max_len_color\" color=#CCCCCC><span id=\"topic_max_len\">100</span></font></font><br><input id=\"create_topic_btn\" type=\"button\" value=\"Create Tag\" name=\"create_topic_btn\" onclick=\"topic_create_tag('" + session_id + "')\"><br><br>Note: symbol not allowed</p>";

   popupbox ('message', '', 'Create Topic', create_topic_msg, '500px', '220px');
   document.getElementById('topic_text_field').focus();
}


function topic_tab (session_id)
{
   style_display ('topic_tab', '');

   var thisobj = document.getElementById('topic_tab');
   if (thisobj)
   {
      if (thisobj.style.display == "block")
         change_text("topic_tab_icon", "<img src=\"http://www.animeboy.org/mbimages/icons/confirm_n.gif\" width=12 height=12 border=\"0\">");
      else
         change_text("topic_tab_icon", "&#9660;");
   }
   make_request("topic_tab", mb_path + "topic_tab.php", "?session_id=" + session_id);

}


function topic_tab_close ()
{

   var thisobj = document.getElementById('topic_tab');
   if (thisobj)
   {
      style_display ('topic_tab', 0);
      change_text("topic_tab_icon", "&#9660;");
   }
}

var close_tab_timer;
function m_menu_tab (id)
{
   style_display (id, '');
   closing_tab (id, 5000);
}

function closing_tab (id, time)
{
   clearTimeout(close_tab_timer);
   close_tab_timer = setTimeout("close_tab('" + id + "')", time);
}

function close_tab (id)
{
   style_display (id, 0);
}


var online_list_load_time = 0;
function m_friend_panel (session_id)
{
   style_display ('m_friend_panel', '');

   if (time () - online_list_load_time > 35)
   {
      online_list_load_time = time ();
      online_list_load ('m_online_list', session_id, uid);
   }
}



function print_contents (mode, http_request)
{
   if (http_request.readyState == 4)
   {
      if (http_request.status == 200)
      {
         request_output = http_request.responseText;
         if (mode == 'post' || mode == 'create_topic')
         {
            if (mode == 'create_topic')
            {
               if (request_output == "ERROR: DUPLICATED TOPIC")
                  alert (lang_duplicated_topic);

               window.location.reload();

            }
            else
            {

               document.getElementById('msgbox_title_' + textbox_session_id).innerHTML = post_msgbox_title;
               document.getElementById('post_notice_' + textbox_session_id).innerHTML = post_notice;

               var thisobj = document.getElementById('timeline' + cur_session_id);

               var post_data = request_output.split ("|", 3);

               if (thisobj)
               {
                  if (document.getElementById('nopost_field_' + cur_session_id))
                     change_text('nopost_field_' + cur_session_id, '');

                  set_postbox_size('', '0');
                  style_display ('post_footer_' + textbox_session_id, 0);


                  if (post_data[2].indexOf("ERROR:") != -1)
                     popupbox ('message', '', '', post_data[2], '50%', '500px');
                  else
                  {
                     inserted_post_id[inserted_post_count] = post_data[0];
                     inserted_post_count++;


                     add_text('timeline' + cur_session_id, post_data[1], 'top');
                  }
               }
               else
               {
                  if (post_data[2].indexOf("ERROR:") != -1)
                     var post_error = post_data[2];
                  else
                     var post_error = '';

                  popupbox ('message', '', '', '<br><p align=center><font size=4>Message has been sent.</font></p>' + post_error, '50%', '200px')
               }

            }
         }
         else if (mode == 'morepost')
         {
            //document.getElementById('msgbox_submit_button_' + textbox_session_id).disabled = false;

            change_text(cur_mpost_id, '&nbsp;');

            text_replace ('timeline' + cur_session_id, cur_mpost_id, '<hr color="#666666" size="1" noshade>' + request_output)
         }
         else if (mode == 'newpost_num')
         {
            var newpost_data = request_output.split("|", 3);
            loaded_chat_session = newpost_data[2];


            //if (uid == 828)
            // alert (request_output + ' ' + chat_session + ' ' +  loaded_chat_session)
            if (chat_session == loaded_chat_session)
            {

                  //alert (newpost_data[1])

               if (newpost_data[1] > 0)
               {
                  if (newpost_data[0] > last_check_time && (newpost_data[0] != ''))
                     last_check_time = newpost_data[0];


                  style_display ('alert_reply_image', 0);

                  var newpost_div_obj = document.getElementById('newpost_div_' + chat_session);
                  if (newpost_div_obj)
                  {
                     newpost_div_obj.style.display = 'block';
                     if (newpost_data[1] > 1)
                        newpost_text = newpost_data[1] + ' new messages';
                     else
                        newpost_text = newpost_data[1] + ' new message';

                     change_text('newpost_text_' + chat_session, newpost_text);
                     newpost_text = '';
                  }
                  else
                  {
                     if (newpost_data[0] > last_post_time && (newpost_data[0] != ''))
                        last_post_time = newpost_data[0];

                     newpost_text = newpost_data[1] + ' new messages';
                     style_display_inline ('chat_msg_alert', 1);
                     style_display_inline ('alert_reply_image', 1);
                  }

               }
               else
                  window.setTimeout(newpost_check, new_post_refresh_time);
            }
            else
            {
               chatbox_init = 0;
               chatbox_closed = 1;
               style_display ('chatbox', 0);
               style_display ('chat_msg_alert', 0);
               style_display ('chattab_close', 0);
               change_text('chatbox_tab_text', "Closed");
            }

         }
         else if (mode == 'newpost_insert')
         {
            window.setTimeout(newpost_check, new_post_refresh_time);

            var newpost_data = request_output.split("|", 3);

            var extracted_post_id = newpost_data[1].split("-");

            for (var i=0; i<extracted_post_id.length; i++)
            {
               inserted_post_id[inserted_post_count] = extracted_post_id[i];
               inserted_post_count++;
            }


            if (document.getElementById('nopost_field_' + cur_session_id))
               change_text('nopost_field_' + cur_session_id, '');

            if (newpost_data[0] > last_post_time && (newpost_data[0] != ''))
               last_post_time = newpost_data[0];

            add_text('timeline' + cur_session_id, newpost_data[2], 'top');


            var delete_post_tar = 12;

            if (inserted_post_count >= delete_post_tar)
            {
               var delete_post_reach = inserted_post_count - 1 - delete_post_tar;
               for (var i=inserted_post_delete_count; i<inserted_post_count; i++)
               {
                  if (document.getElementById('post_' + inserted_post_id[inserted_post_delete_count]))
                  {
                     var thispid = document.getElementById('post_' + inserted_post_id[inserted_post_delete_count]);
                     thispid.parentNode.removeChild(thispid);
                  }
                  inserted_post_delete_count++;

                  if (inserted_post_delete_count - 1 >= delete_post_reach)
                     break;
               }
            }


         }
         else if (mode == 'headto')
         {
            change_text('boardarea', request_output);
         }
         else if (mode == 'popupmsg')
         {
            popup_msg ('<br>' + request_output);
         }
         else if (mode == 'user_favourite_add')
         {
            popupbox ('message', '', 'Add to Favourite', request_output, '500px', '220px');
         }
         else if (mode == 'user_favourite_remove')
         {
            var thisobj = document.getElementById('ufav' + request_output);
            thisobj.parentNode.removeChild(thisobj);
         }
         else if (mode == 'announcement')
         {
            change_text('contentbox_content', request_output);
         }
         else if (mode == 'chatbox_tab_text')
         {
            change_text('chatbox_tab_text', request_output);
            change_text('chat_online_members_tab_text', request_output);
         }
         else if (mode == "ab_upload_content")
         {
            change_text(mode, request_output);
            adjust_au_content_display ();
         }
         else if (mode == "mobi_login_check")
         {
            if (request_output != 1)
               style_display ('mobi_login_check', 1);
         }
         else
         {
            if (document.getElementById(mode))
               if (request_output != "")
                  change_text(mode, request_output);
         }
      }
      else
      {
         popup_msg ('There was a problem with the request.')
         //alert('There was a problem with the request.');
      }
   }
}

function update_cur_session_id (new_id)
{
   cur_session_id = new_id;
}

function message_board_top_display (show)
{
   if (document.getElementById('message_board_top'))
   {
      var thisobj = document.getElementById('message_board_top');

      if (show)
         thisobj.style.display = 'block';
      else
         thisobj.style.display = 'none';
   }
}




var last_selected_tab = "timeline";
var last_selected_menu = "timeline";
var msgbox_title_changed = 0;
function profile_option (session_id, headto, extra)
{
   if (session_id !== '')
      cur_session_id = session_id;

   var thisobj = document.getElementById('menu_' + headto);
   if (thisobj)
   {
      thisobj.style.background = '#E1F0FF';

      if (last_selected_menu != headto)
      {
         last_selected_menu_obj = document.getElementById('menu_' + last_selected_menu);
         if (last_selected_menu_obj)
            last_selected_menu_obj.style.background = '';

         last_selected_menu = headto;
      }
   }

   var thisobj = document.getElementById('tab_' + headto);
   if (thisobj)
   {
      thisobj.style.background = '#E1F0FF';

      if (last_selected_tab != headto)
      {
         last_selected_tab_obj = document.getElementById('tab_' + last_selected_tab);
         if (last_selected_tab_obj)
            last_selected_tab_obj.style.background = '#f6f6f6';

         last_selected_tab = headto;
      }
   }

   if (headto == 'timeline')
   {
      message_board_top_display (1);
      change_text('boardarea', loading_img ());

      var user_data = extra.split("|", 3);

      if (empty (cur_session_id) && !empty (user_data[2]))
         cur_session_id = user_data[2];

      if (msgbox_title_changed)
         change_text('msgbox_title_' + cur_session_id, 'What\'s Happening?');
      change_text('message_board_label', '');
      topic_tid = '';

      make_request('headto', mb_path + 'post.php', '?mode=timeline&ptext=1&hide_postbox=nopostbox&msgbox_id=' + cur_session_id + '&session_id=' + cur_session_id + '&rq_uid=' + user_data[0] + '&rq_user=' + user_data[1]);
   }
   else if (headto == 'favpost')
   {
      change_text('msgbox_title_' + session_id, 'What\'s Happening?');
      change_text('message_board_label', '');
      topic_tid = '';

      change_text('boardarea', loading_img ());
      make_request('headto', mb_path + 'post.php', '?mode=favpost&ptext=1&hide_postbox=nopostbox&msgbox_id=' + cur_session_id + '&session_id=' + cur_session_id);
   }
   else if (headto == 'atmention')
   {
      change_text('msgbox_title_' + session_id, 'What\'s Happening?');
      change_text('message_board_label', '');
      topic_tid = '';

      msg_alert_off ();

      change_text('boardarea', loading_img ());
      make_request('boardarea', mb_path + 'post.php', '?mode=atmention&&ptext=1&hide_postbox=nopostbox&msgbox_id=' + cur_session_id + '&session_id=' + cur_session_id);
   }
   else if (headto == 'mempost')
   {
      change_text('msgbox_title_' + session_id, 'What\'s Happening?');
      change_text('message_board_label', '');
      topic_tid = '';

      change_text('boardarea', loading_img ());
      make_request('headto', mb_path + 'post.php', '?mode=mempost&dlimit=25&ptext=1&hide_postbox=nopostbox&msgbox_id=' + cur_session_id + '&session_id=' + cur_session_id);
   }
   else if (headto == 'announcement')
   {
      if (document.getElementById('alert_anno_image'))
         document.getElementById('alert_anno_image').style.display = 'none';

      if (document.getElementById('menu_tab_icon'))
         change_text('menu_tab_icon', '&#9660;');


      change_text('msgbox_title_' + session_id, 'What\'s Happening?');
      topic_tid = '';

      change_text('boardarea', loading_img ());
      make_request('headto', mb_path + 'post.php', '?mode=announcement&dlimit=25&ptext=1&hide_postbox=nopostbox&msgbox_id=' + cur_session_id + '&session_id=' + cur_session_id);
   }
   else if (headto == 'pm')
   {
      if (document.getElementById('alert_pm_image'))
         document.getElementById('alert_pm_image').style.display = 'none';
   }
   else if (headto == 'find_friend')
   {
      message_board_top_display (0);
      change_text('boardarea', loading_img ());
      make_request('headto', mb_path + 'friend_listall.php', '?mode=find_friend&session_id=' + session_id);
   }
   else if (headto == 'video')
   {
      message_board_top_display (0);
      change_text('boardarea', loading_img ());
      make_request('headto', mb_path + 'post.php', '?mode=votd&dlimit=25&ptext=1&hide_postbox=nopostbox&msgbox_id=' + cur_session_id + '&session_id=' + cur_session_id);
   }
   else if (headto == 'friendadd')
   {
      make_request('popupmsg', mb_path + 'friend_list.php', '?action=add&rq_uid=' + extra);
      if (uid > 0)
         change_text('friendadd', '<a href="#" onclick="profile_option (\'\', \'frienddel\', \'' + extra + '\')"><img src="../mbimages/icons/friend_del.gif" border=0> Remove from friend list</a>');

   }
   else if (headto == 'frienddel')
   {
      make_request('popupmsg', mb_path + 'friend_list.php', '?action=del&rq_uid=' + extra);
      if (uid > 0)
         change_text('friendadd', '<a href="#" onclick="profile_option (\'\', \'friendadd\', \'' + extra + '\')"><img src="../mbimages/icons/friend_add.gif" border=0> Add Friend</a>');
   }
   else if (headto == 'ban')
   {
      make_request('popupmsg', mb_path + 'ban.php', '?action=ban&rq_uid=' + extra);
      if (uid > 0)
         change_text('banoption', '<a href="#" onclick="profile_option (\'\', \'release\', \'' + extra + '\')"><img src="../mbimages/icons/confirm_release.gif" width=15 border=0> Release this user</a>');
   }
   else if (headto == 'release')
   {
      make_request('popupmsg', mb_path + 'ban.php', '?action=release&rq_uid=' + extra);
      if (uid > 0)
         change_text('banoption', '<a href="#" onclick="profile_option (\'\', \'ban\', \'' + extra + '\')"><img src="../mbimages/icons/confirm_ban.gif" width=15 border=0> Ban this user</a>');
   }
   else if (headto == 'anime_upload')
   {
      topic_tid = '';
      window.scrollTo(0,0);
      message_board_top_display (0);
      change_text('boardarea', "<font size=\"4\"><b>My Anime Upload</b></font><br><br><iframe src=\"http://www.animeboy.org/anime_uploads.php?if=1&limit=12&rq_user="  + extra + "\" name=\"anime_upload\" scrolling=\"auto\" width=\"100%\" height=\"1000\" frameborder=\"0\" allowTransparency=\"false\" marginheight=0></iframe>");
   }
}

function msg_alert_off ()
{
  style_display ('alert_reply_image', 0);
  style_display ('login_bar_msg_alert', 0);
  style_display ('alert_pm_image', 0);

  if (document.getElementById('menu_tab_icon'))
     change_text('menu_tab_icon', '&#9660;');
}



var ul_last_selected_menu = "";
function ul_tab (headto)
{
   var thisobj = document.getElementById('ultab_' + headto);
   if (thisobj)
   {
      thisobj.style.background = '#E1F0FF';

      if (ul_last_selected_menu != headto)
      {
         last_selected_tab_obj = document.getElementById('ultab_' + ul_last_selected_menu);
         if (last_selected_tab_obj)
            last_selected_tab_obj.style.background = '#f6f6f6';

         ul_last_selected_menu = headto;
      }
   }
}




function chat_register_session (session_id)
{
   make_request('update_chat_session', mb_path + 'update_chat_session.php', '?session_id=' + session_id);
}

function ab_upload_close ()
{
   var ab_upload_obj = document.getElementById('ab_upload');
   if (ab_upload_obj)
   {
      style_display_inline ('ab_upload_tab_close', 0);
      style_display ('ab_upload', 0);
   }
}


function chat_close ()
{
   var chatbox_obj = document.getElementById('chatbox');
   if (chatbox_obj)
   {
      style_display_inline ('chattab_close', 0);
      style_display ('chatbox', 0);
      style_display ('chat_online_members', 0);
      style_display_inline ('view_online_tab', 0);
      style_display_inline ('chat_msg_alert', 0);
   }
}

function chat_open (session_id, post_ftime)
{
   ab_upload_close ();

   style_display_inline ('chattab_close', '');
   style_display ('chatbox', '');
   style_display ('chat_online_members', 1);
   style_display_inline ('view_online_tab', 0);
   style_display_inline ('chat_msg_alert', 0);

   var chatbox_obj = document.getElementById('chatbox');
   if (chatbox_obj.style.display == "block")
      window.setTimeout(newpost_check, new_post_refresh_time);

   if (newpost_text != '')
   {
      if (document.getElementById('newpost_div_' + session_id))
      {
         document.getElementById('newpost_div_' + session_id).style.display = 'block';
         change_text('newpost_text_' + session_id, newpost_text);
         newpost_text = '';
      }
   }

   if (chatbox_init == 0)
   {
      chat_register_session (session_id);
      chat_session = session_id;
      loaded_chat_session = session_id;

      var chatbox_height = screen.height - 200;
      document.getElementById('chatbox').style.height = chatbox_height + 'px';
      document.getElementById('chat_online_members').style.height = chatbox_height - 200 + 'px';
      document.getElementById('chat_online_members').style.display = 'block';



      if (chatbox_closed)
      {
         window.setTimeout(newpost_check, new_post_refresh_time);
         chatbox_closed = 0;
      }

      chat_update ();
      change_text('chat_atmention', loading_img ());
      make_request('chat_atmention', mb_path + 'post.php', '?mode=atmention&&ptext=1&hide_postbox=nopostbox&root_path=' + root_path + '&msgbox_id=' + session_id + '&session_id=' + session_id + '&post_ftime=' + post_ftime);
      chatbox_init = 1;
   }
}

function chat_update ()
{
   if (!chatbox_closed)
   {
      online_list_load ('chat_online_members', chat_session_id, chat_uid);
      online_list_check ('Chat');
      window.setTimeout(chat_update, chat_update_refresh_time);
   }
}


function online_list_check (ptext)
{
   make_request('chatbox_tab_text', mb_path + 'chat_active_list.php', '?mode=show_active_user&ptext=' + ptext);
}

function online_list_load (id, session_id, uid)
{
   change_text(id, loading_img ());
   make_request(id, mb_path + 'chat_active_list.php', '?rq_uid=' + uid + '&session_id=' + session_id);
}

function group_option (id, headto, extra)
{
   if (document.getElementById(id) != null)
   {
      for (var i = 1; i <= 4; i++)
      {
         if (document.getElementById('go_' + i))
         {
            if (id == 'go_' + i)
            {
               var thisobj = document.getElementById(id);
               thisobj.style.backgroundColor = "#f7f7f7";
            }
            else
            {
               var thisobj = document.getElementById('go_' + i);
               thisobj.style.backgroundColor = "";
            }
         }
      }
   }

   if (headto == 'group_join')
   {
      if (uid == '')
         popup_msg ('<br>Please <a href=\"login.php?redirectPath=' + escape ('group.php?gid=' + extra) + '\">LOGIN</a> first.');
      else
      {
         var join_confirm = confirm("Are you sure you want to join this group?");

         if (join_confirm)
         {
            change_text('boardarea', loading_img ());
            make_request('headto', mb_path + 'group_join.php', '?gid=' + extra);
         }
      }
   }
   else if (headto == 'group_request')
   {
      var join_confirm = confirm("You will need to be approved by the group admin. Send join request?");

      if (join_confirm)
      {
         change_text('boardarea', loading_img ());
         make_request('headto', mb_path + 'group_join.php', '?gid=' + extra);
      }
   }
   else if (headto == 'group_members')
   {
      change_text('boardarea', loading_img ());
      make_request('headto', mb_path + 'group_members.php', '?gid=' + extra);
   }
   else if (headto == 'group_listall')
   {
      window.scrollTo(0,0);
      message_board_top_display (0);
      change_text('boardarea', loading_img ());
      make_request('headto', mb_path + 'group.php', '?mode=group_listall&displayat=profile&uid=' + extra);
   }
   else if (headto == 'group_leave')
   {
      var leave_confirm = confirm("Are you sure you want to leave this group?");

      if (leave_confirm)
      {
         change_text('boardarea', loading_img ());
         make_request('headto', mb_path + 'group.php', '?mode=group_leave&gid=' + extra);
      }
   }

}






var popupmsg_alpha = 0.9;

function set_style_alpha (alpha)
{
   thisobj.style.filter = 'alpha(opacity=' + (alpha * 100) + ')';
   thisobj.style.MozOpacity = alpha;
   thisobj.style.opacity= alpha;
   thisobj.style.KhtmlOpacity= alpha;
}

function popup_msg (content)
{
   document.getElementById('popupmsg_' + cur_session_id).innerHTML = content;

   thisobj = document.getElementById('popupmsg_' + cur_session_id);


   if (thisobj.style.display == 'none')
   {
      thisobj.style.display = "";
      popupmsg_alpha = 0.9;
      set_style_alpha (popupmsg_alpha);
      setTimeout('popup_msg (\'' + content + '\')', 4000);
   }
   else
   {
      if (popupmsg_alpha > 0)
      {

         set_style_alpha (popupmsg_alpha);

                 popupmsg_alpha -= 0.05;
         setTimeout('popup_msg (\'' + content + '\')', 50);
      }
      else
         thisobj.style.display = "none";
   }
}


function fl_confirm (mode, uid)
{
   if (uid > 0)
   {
      if (mode == 'friendadd')
      {
         change_text('fl_stat_' + uid, '<span id="fl_stat_' + uid + '"><img src="../mbimages/icons/fl_status_friend.gif" width=12 border="0"><font size=1 color="#666666">Friend</font></span>');
         change_text('fl_rq_' + uid, '');
         profile_option ('', mode, uid);
      }
      else if (mode == 'frienddel')
      {
         var delete_confirm = confirm("Are you sure you want to remove this friend from your list? \nThere is no UNDO.")

         if (delete_confirm)
         {
            change_text('fl_box_' + uid, '');
            profile_option ('', mode, uid);
         }
      }

      close_tab ('m_friend_panel');
   }
}


function change_url (url) {
   location.href = url;
}

function group_leave (gid)
{
   var new_creator = document.group_form.new_creator.value;
   var cancel_option = get_checked_value(document.group_form.cancel_option, 'radio');



   if (empty (new_creator) && cancel_option == 2)
      alert ('New creator must be specify');
   else
      make_request('headto', mb_path + 'group.php', '?mode=group_leave&new_creator=' + new_creator + '&gid=' + gid + '&cancel_option=' + cancel_option);

}

function get_checked_value(object, type)
{
   if (type == 'radio')
   {
      if(!object)
         return "";
      var object_length = object.length;
      if(object_length == undefined)
         if(object.checked)
            return object.value;
         else
            return "";

      for (var i = 0; i < object_length; i++)
      {
         if(object[i].checked)
            return object[i].value;
      }

      return "";

   }
}

function get_checkbox_value (id)
{

   var object = document.getElementById(id);
   if(!object)
      return "";
   else
      return object.checked;
}

function style_display (id, show)
{
   var thisobj = document.getElementById(id);
   if (thisobj)
   {
      if (show === '')
      {
         if (thisobj.style.display == "")
            thisobj.style.display = "none";

         if (thisobj.style.display == "none")
            show = 1;
         else
            show = 0;
      }

      if (show)
         thisobj.style.display = "block";
      else
         thisobj.style.display = "none";
   }
}

function style_display_inline (id, show)
{
   var thisobj = document.getElementById(id);
   if (thisobj)
   {
      if (show === '')
      {
         if (thisobj.style.display == "")
            thisobj.style.display = "none";

         if (thisobj.style.display == "none")
            show = 1;
         else
            show = 0;
      }

      if (show)
         thisobj.style.display = "inline";
      else
         thisobj.style.display = "none";
   }
}

function profile_link_change ()
{
   style_display ('profile_field', '');

   thisobj = document.getElementById('profile_field');

   if (thisobj.style.display == "none")
      var profile_link = 'Show Profile';
   else
      var profile_link = 'Hide Profile';

   change_text('show_profile_link', profile_link);

}

function show_online_member_tab ()
{
   style_display ('chat_online_members', '');

   thisobj = document.getElementById('chat_online_members');
   if (thisobj.style.display == "none")
      style_display_inline ('view_online_tab', 1);
   else
      style_display_inline ('view_online_tab', 0);

}

function set_postbox_size (width, height)
{
   thisobj = document.getElementById('msgbox_textarea_' + textbox_session_id);
   if (width != '')
      if (width == '0')
         thisobj.style.width = '';
      else
         thisobj.style.width = width;

   if (height != '')
      if (height == '0')
         thisobj.style.height = '';
      else
         thisobj.style.height = height;
}


function post_attachment (type, id)
{
   if (type == "IMG")
   {
      var text = '<p><table border="1" cellpadding="2" cellspacing="2" style="border-collapse: collapse" bordercolor="#C0C0C0" width="100%"><tr><td width="100%"><iframe src="http://www.animeboy.org/messageboard/attachment_upload.php?session_id=' + id + '" name="attachment_upload" scrolling="no" width="100%" height="50" frameborder="0" allowTransparency="true" marginheight=0></iframe></td></tr></table>';
   }
   else if (type == "VID")
   {
      var text = '<p><table border="1" cellpadding="2" cellspacing="2" style="border-collapse: collapse" bordercolor="#C0C0C0" width="100%"><tr><td width="100%"><b>Youtube Video URL:</b> <input class="inputfield" id="post_video_' + id + '" style="width: 230px" "type="text" name="post_video_url" size="50"></p><p>Example:<br><img border="0" src="../mbimages/video_embed_example.jpg"></td></tr></table>';
   }

   change_text("post_attachment_" + id, text);
}


function time () {

   var time_obj = new Date;
   return parseInt(time_obj.getTime() / 1000);
}


