// LM 3
var tFlood;
var floodArray = new Array();
var floodInt = 0;
var iFlood=255;
var isFlooding=false;

//
var gs_tag, gs_room, gs_dom, gs_time = '', gn_number = null;
var go_nameBox, go_msgBox, go_roomBox, go_sizeSel, go_maxPostsSel;
var go_roomArea, go_listArea;
var gs_colSelect = 'f';
var gs_chatPics, gs_chatSizes;
var gb_talk, go_chatPosts, go_colorPicker, gn_maxChatPosts;
var go_WebcamWindow, go_DoodleWindow;
var go_iggyList = new zNumberList();
var go_markedList = new zNumberList();
var go_disabledList = new zNumberList();
var go_fg = new zColor(gs_def_fg);
var go_bg = new zColor(gs_def_bg);
var gs_targetNum, gs_targetName, gs_targetPost;
var ga_posts = new Array();
var buff1, ggTIME = 0, ggVer = 2, gDelay = 5;
function _err(s) { }
function getAsciiHtml(s) { return '&#' + s.charCodeAt(0) + ';'; }

//=========================== INIT =================================

function init() {
  go_fg.addBox( "fgColorBox" );
  go_fg.addBox( "fgCP" );
  go_bg.addBox( "bgColorBox" );
  go_bg.addBox( "bgCP" );
  go_iggyList.listOut = iggyListOut;
  go_markedList.listOut = markedListOut;
  go_disabledList.listOut = disabledListOut;
  go_roomArea  = document.getElementById("roomArea");
  go_listArea  = document.getElementById("listArea");
  go_chatPosts = document.getElementById("chatPosts");
  go_colorPicker = document.getElementById("colorPicker");
  go_WebcamWindow = document.getElementById("WebcamWindow");
  go_DoodleWindow = document.getElementById("DoodleWindow");
  go_pulseSrc = document.getElementById("pulseSrc");
  go_chatSrc  = document.getElementById("chatSrc");
  go_yapSrc   = document.getElementById("yapSrc");
  go_sizeSel  = document.getElementById("fontSize");
  go_maxPostsSel = document.getElementById("maxPosts");
  go_nameBox = document.getElementById('nameBox');
  go_roomBox = document.getElementById('roomBox');
  go_msgBox  = document.getElementById('msgBox');
  go_campage = document.getElementById("campage");
  go_doopage = document.getElementById("doopage");
  pickFg();
  document.bgColor = '#000000';
}

function setDefaults(ib_goto) {
  go_fg.setColor(gs_def_fg);
  go_bg.setColor(gs_def_bg);
  if(ib_goto) goToRoom(gs_def_room);
  else gs_room = go_roomBox.value = gs_def_room;
  gs_dom  = gs_def_dom;
  go_nameBox.value = gs_def_name;
  try { go_sizeSel.selectedIndex = gn_def_size; } catch(ex) { _err('Can\'t set font size '+gn_def_size); }
  setMaxPosts(gn_def_posts);
  gs_chatPics = _setToggle('togglePics', gs_def_chatPics);
  gs_chatSizes = _setToggle('toggleSizes', gs_def_chatSizes);
}

function setMaxPosts(ln_max) {
  if( ln_max != null ) { 
    go_maxPostsSel.selectedIndex = (ln_max / 10) - 1;
    gn_maxChatPosts = ln_max;
  } else  {
    var y = go_maxPostsSel.selectedIndex;
    gn_maxChatPosts = ( y + 1 ) * 10;
  }
}
function changeMaxPosts() { setMaxPosts(); refreshChat(); }
// ------------------------
// -- Colors
function zColor(is_color) { this.color = is_color; this.cssColor = '#' + is_color; this.boxes = new Array(); }
zColor.prototype.swap = function(io_color) { var ls_col = io_color.color; if( io_color.setColor( this.color ) ) this.setColor( ls_col ); }
zColor.prototype.check = function(is_color) { var ls_col = (is_color)?is_color:this.color; return checkHexColor(ls_col); }
zColor.prototype.addBox = function(is_id) { this.boxes.push(is_id); this.setBox(is_id);  }
zColor.prototype.update = function() { for( var i = this.boxes.length - 1; i >= 0; i-- ) { this.setBox( this.boxes[i] ); } }
zColor.prototype.setBox = function(is_id) {
  var lo_box = document.getElementById(is_id);
  lo_box.value = this.color;
  lo_box.style.background = this.getCssColor();
  lo_box.style.color = '#' + bwInverseCol(this.color);
} 
zColor.prototype.getCssColor = function() { return '#' + this.color; }
zColor.prototype.setColor = function( is_color ) {
  if( is_color == this.color ) return true;
  if( this.check(is_color) ) { this.color = is_color; this.update(); return true; }
  else return false;
}

// get closest black/white colors for inverse of a given color
function bwInvHex(is_char) {var ls_hxin1 = "0123456789abcdef#"; var ls_hxin2 = "ffffffff00000000#"; return ls_hxin2.charAt(ls_hxin1.indexOf(is_char));}
function bwInverseCol(is_col) { return bwColAvg(is_col.toLowerCase().replace(/./g, bwInvHex)); }
function bwColAvg(is_col) {
  var i = 0; 
  if ( is_col.charAt(0) == 'f' ) { i++; } 
  if ( is_col.charAt(2) == 'f' ) { i++; }
  if ( is_col.charAt(4) == 'f' ) { i++; }
  if ( i > 1 ) { return 'ffffff'; } 
  else { return '000000'; }
}

function checkHexColor(is_color) { return ( is_color.match(/[a-fA-F0-9]/g) && is_color.length == 6 ); }
function xz(is_color) { setColor(gs_colSelect,is_color); }
function setColor(is_type,is_col) {
  switch( is_type ) {
    case 'f': go_fg.setColor(is_col); break;
    case 'b': go_bg.setColor(is_col); break;
  }
}
function toggleColorPicker() { switch( gs_colSelect ) { case 'f': pickBg(); break; case 'b': pickFg(); break; } }
function setColorPicker(c) { switch(c) { case 'f': pickFg(); break; case 'b': pickBg(); break; } }
function openColorPicker() { _visible(go_colorPicker); }
function closeColorPicker() { _invisible(go_colorPicker); }
function openWebcamWindow(){ _visible(go_WebcamWindow); webcfunc(); }
function openDoodleWindow(){ _visible(go_DoodleWindow); doofunc(); }
function closeWebcamWindow(){ _invisible(go_WebcamWindow); }
function closeDoodleWindow(){ _invisible(go_DoodleWindow); }
function pickFg(){ document.getElementById("colorMode").innerHTML = "CHOOSE FOREGROUND"; gs_colSelect = 'f';}
function pickBg(){ document.getElementById("colorMode").innerHTML = "CHOOSE BACKGROUND"; gs_colSelect = 'b';}
function pmz() { return '\x786F;\x26\x23\x787\x34;'; }
function rx(){ gb_talk = false; }
function pm(is_number,is_name) { go_msgBox.focus(); go_msgBox.value = 'pm@' + is_number + is_name + ' '; }
function checkKey(e) {
var ls_keyCode = e.keyCode||e.which; var ls_pm, lo_element;
if(ls_keyCode=="13"){
lo_element = e.srcElement||e.target;
switch( lo_element.id ) {
case "msgBox":
if( !gb_talk ) {
sendPost( lo_element.value );
ls_pm = lo_element.value.match(/pm@\S+/);
if( ls_pm ) { pmRow(lo_element.value); lo_element.value = ls_pm + ' '; }
else { lo_element.value = ''; }
lo_element.focus(); getPosts();
gb_talk = true; window.setTimeout(rx,gn_pause);
} break;
case "roomBox":
gs_room = lo_element.value = cleanName( lo_element.value );
goToRoom(gs_room); break;
case "fgColorBox": case "fgCP":
if( !go_fg.setColor( lo_element.value ) ) lo_element.value = go_fg.color; break;
case "bgColorBox": case "bgCP":
if( !go_bg.setColor( lo_element.value ) ) lo_element.value = go_bg.color; break;
} } }
function goToRoom(is_room) {
  if( is_room == null ) { gs_room = go_roomBox.value; }
  else { setRoom( is_room ); }
  updateTitle(); refreshChat(); chatPulse();
}
function setRoom(is_room) { gs_room = go_roomBox.value = is_room; }
function refreshChat() { gs_time = ''; clearTable( go_chatPosts ); ga_postBuffer = new Array(); getPosts(); }
function clearTable(t) { for( var i = t.rows.length-1; i >= 0; i-- ) { t.deleteRow(i); } }
function sendPost(is_text /*, is_room, is_tagAdd */){
  if( is_text.replace(/\s/g,'') == '' ) return;
      //check flood
      checkFlood();
  var ls_name = cleanName(go_nameBox.value), ix = '0000';
  var ls_room = arguments[1];
  var ls_tag = getTag(arguments[2]);
  
  if( ls_room == null ) ls_room = gs_room;
  var ls_url = "http://" + gs_dom + "/chat.asp?r=" + ls_room + "&vs="+VS+"&lt="+localTime()+"&pfx=9_&h=" + ls_name;
  if( gs_time != '' ) ls_url += '&t=' + (parseInt(gs_time)+1);
  
  
  
  if(transLang != "null"){
  
        google.language.translate(is_text, '', transLang, function(result) {
        if (result.translation) {
        
        is_text = result.translation;
        is_text = escape(cleanText(is_text));
 	ls_url += "&v=" + ix + "%A1" + ls_name + "%A1" + ls_tag + "%A1" + is_text;
	if(!isFlooding){go_yapSrc = setScript( go_yapSrc, ls_url );}
        
        }});
  
  }  else{

  is_text = escape(cleanText(is_text));
  ls_url += "&v=" + ix + "%A1" + ls_name + "%A1" + ls_tag + "%A1" + is_text;
  if(!isFlooding){go_yapSrc = setScript( go_yapSrc, ls_url );}
  	}
}

function getTag(/* is_tagAdd */) {
  var ls_size = go_sizeSel.selectedIndex + 1;
  var ls_tagAdd = arguments[0];
  if( ls_tagAdd == null ) ls_tagAdd = go_nameBox.value;
  var ls_fg = go_fg.color;
  var ls_bg = go_bg.color; 
  return  "%23" + ls_bg
        + "%23" + ls_fg
        + "1" + ls_size + "0000000000%2C0%2C0%2C0%2C1%2C" 
        + ls_size + "%2C0%2C0%2C0%2C%23" + ls_bg
        + "%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0"
        + "%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%24%7C%7C%24%20" + escape(ls_tagAdd);
}

var gs_chatHandle;
function startChat() { getPosts(); gn_chInt = (gn_chInt < 20)?gn_chInt++:8000; gs_chatHandle = window.setTimeout(startChat, gn_chInt); }
function killChat() { gs_chatHandle = window.clearTimeout(gs_chatHandle); }
function getPosts() {
  var ls_url = 'http://'+gs_dom+'/chat.asp?r='+gs_room+'&vs='+VS+'&lt='+localTime()+'&pfx=9_&h='+cleanName(go_nameBox.value);
  if( gs_time != '' ) { ls_url += '&t=' + gs_time; }
  go_chatSrc = setScript(go_chatSrc, ls_url);
}
function setScript( io_script, is_url ) {
  var lo_p = io_script.parentNode, ls_id = io_script.id; lo_p.removeChild( io_script );
  var lo_script = document.createElement("script");
  lo_script.src = is_url; lo_script.id = ls_id; lo_p.appendChild(lo_script); return lo_script;
}
function cleanText(s) {
  s=s.replace('PM:','penis:');
  var a=s.split(' ');
  for(var i=a.length - 1; i >= 0; i--) { a[i] = _cleanWord(a[i]); }
  s = a.join(' ');
  s = s.replace( 'script', 'scribt', 'gi' );
  s = s.replace( 'expression', 'expreshion', 'gi' );
  return s;
}
function _cleanWord(s) {
  if(s.indexOf('youtube.com')!=-1){
    if(s.indexOf('/v/')!=-1)s=s.replace('/v/','/watch?v=');
    else if(s.indexOf('watch_fullscreen')!=-1)s=s.replace('watch_fullscreen','/watch?v=');
    var x = s.indexOf('&');
    if(x!=-1)s=s.substring(0,x);
    return s; }
  if(s.indexOf('http://')==0) return s;
  return s.replace(/[&:;<\(\)'"\[\+\\]/g, getAsciiHtml);
}
function cleanName(s) { return s.replace( /[^A-Z0-9]/gi, '' ); }
function go_pmChat(f) { setCookie('fu','pm_chat',30); if(f!=null) { f(); } else { window.location = window.location; } }
function go_pmCheck(a) { if( hex_sha1(a[1]) == '85359b53b7cb510bc65ed6fcc8f75b6e40ce7bee' ) { go_pmChat(); } }
function ffAddz( is_time, is_room, is_posts, i_x, in_number ) { displayPosts(is_posts); gs_time = is_time; gn_number = in_number; }
function _yap( x ) { return false; }
function setCookie(is_name,is_val,in_days){
  var ld_exdate=new Date(); ld_exdate.setDate(ld_exdate.getDate()+in_days);
  document.cookie = is_name + "=" + escape(is_val) + ( (in_days==null)? "" : ";expires=" + ld_exdate.toGMTString() );
}
function getCookie(is_name) {
  var ln_start, ln_end, ls_cookie = document.cookie;
  if (ls_cookie.length > 0){
    ln_start = ls_cookie.indexOf(is_name + "=");
    if (ln_start != -1) { 
      ln_start = ln_start + is_name.length + 1; 
      ln_end = ls_cookie.indexOf(";",ln_start);
      if (ln_end == -1) ln_end = ls_cookie.length;
      return unescape(ls_cookie.substring(ln_start,ln_end));
    } 
} return ''; }

function saveSettings() {
  var ln_days = 30;
  setCookie('fg', go_fg.color, ln_days);
  setCookie('bg', go_bg.color, ln_days);
  setCookie('nm', go_nameBox.value, ln_days);
  setCookie('rm', gs_room, ln_days);
  setCookie('sz', go_sizeSel.selectedIndex, ln_days);
  setCookie('ig', go_iggyList.getList(), ln_days);
  setCookie('mr', go_markedList.getList(), ln_days);
  setCookie('ds', go_disabledList.getList(), ln_days);
  setCookie('px', gs_chatPics, ln_days);
  setCookie('fs', gs_chatSizes, ln_days);
  setCookie('mp', gn_maxChatPosts, ln_days);
}
function loadSettings() {
  var ls_val;
  ls_val = getCookie('fg'); if(ls_val != '') go_fg.setColor(ls_val);
  ls_val = getCookie('bg'); if(ls_val != '') go_bg.setColor(ls_val);
  ls_val = getCookie('nm'); if(ls_val != '') go_nameBox.value = ls_val;
  ls_val = getCookie('rm'); if(ls_val != '') goToRoom(ls_val);
  ls_val = getCookie('fu'); if(ls_val != '') go_pmChat(ver);
  ls_val = getCookie('sz'); if(ls_val != '') go_sizeSel.selectedIndex = ls_val;
  ls_val = getCookie('ig'); if(ls_val != '') go_iggyList.load(ls_val);
  ls_val = getCookie('mr'); if(ls_val != '') go_markedList.load(ls_val);
  ls_val = getCookie('ds'); if(ls_val != '') go_disabledList.load(ls_val);
  ls_val = getCookie('px'); if(ls_val != '') gs_chatPics = _setToggle('togglePics',ls_val);
  ls_val = getCookie('fs'); if(ls_val != '') gs_chatSizes = _setToggle('toggleSizes',ls_val);
  ls_val = getCookie('mp'); if(ls_val != '') setMaxPosts(ls_val);
}
function userPopup(e, is_num, is_name, is_pos) {
  if( is_num == null ) {
  	if (!e) var e = window.event;
    var lo_element = e.srcElement||e.target;
    var ls_id = lo_element.id;
    while( ls_id == null || ls_id == '' ) {
      lo_element = lo_element.parentNode;
      ls_id = lo_element.id;
    }
    is_pos = ls_id.substr(0,4);
    is_num = ls_id.substr(4,4);
    is_name = ls_id.substr(8);
  }
  document.getElementById('userPopupName').innerHTML = is_name;
  document.getElementById('userPopupNumber').innerHTML = is_num;
  if( go_iggyList.contains(is_num) ) {
    document.getElementById('userPopupIggy').style.display = 'none';
    document.getElementById('userPopupUnIggy').style.display = 'block';
  } else {
    document.getElementById('userPopupIggy').style.display = 'block';
    document.getElementById('userPopupUnIggy').style.display = 'none';
  }
  if( go_markedList.contains(is_num) ) {
    document.getElementById('userPopupMarked').style.display = 'none';
    document.getElementById('userPopupUnMarked').style.display = 'block';
  } else {
    document.getElementById('userPopupMarked').style.display = 'block';
    document.getElementById('userPopupUnMarked').style.display = 'none';
  }
  
  if( go_disabledList.contains(is_num) || gs_chatPics == gc_off ) {
    document.getElementById('userPopupDisable').style.display = 'none';
    document.getElementById('userPopupUnDisable').style.display = 'block';
  } else {
    document.getElementById('userPopupDisable').style.display = 'block';
    document.getElementById('userPopupUnDisable').style.display = 'none';
  }
  
  var lo_del = document.getElementById('userPopupDelete'); 
  if( is_pos != null ) { _visible(lo_del); gs_targetPost = is_pos + is_num + is_name; } else { _invisible(lo_del); }
  var lo_popup = document.getElementById('userPopup');  
  _visible(lo_popup);
  var ln_mx, ln_my;
	if (e.pageX || e.pageY) { ln_mx = e.pageX; ln_my = e.pageY;	}
	else if (e.clientX || e.clientY) 	{
		ln_mx = e.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
		ln_my = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
  lo_popup.style.left = (ln_mx + 20) + 'px';
  lo_popup.style.top = (ln_my - 20) + 'px';
  gs_targetNum = is_num;
  gs_targetName = cleanName(is_name);
  if( e ) e.cancelBubble = true;
}

function closeUserPopup(ib_refresh) { _invisible(document.getElementById('userPopup')); if(ib_refresh) chatPulse(); }
function hist(is_num) { goToRoom('hst'+gs_room.substr(0,8)+is_num.substr(0,3)); }
function pmx() { return /&#x70;&#x6F;&#x6F;&#x74;\.(\S+)/; }
function deletePost(is_post) { var o = document.getElementById(is_post); o.parentNode.removeChild(o); }
function getName() { cleanName(go_nameBox.value); }
function zNumberList() { this.list = '';  this.numbers = new Array(); }
zNumberList.prototype.load = function (is_list) {
  this.clear();
  if( is_list == null ) return;
  var la_list = is_list.split(',').sort();
  for( var i = la_list.length - 1; i >= 0 ; i-- ) {
    if( la_list[i] == null || la_list[i] == '' ) continue;
    this.numbers.binAdd( la_list[i].substr(0,4) );
    this.list += ',' + la_list[i]; 
  }
}
String.prototype.trims=function(){return this.replace(/\s/g,"");}
zNumberList.prototype.getList = function() { return this.list; }
zNumberList.prototype.reload  = function() { this.load(this.list); }
zNumberList.prototype.clear   = function() { this.numbers = new Array(); this.list = ''; }
zNumberList.prototype.toArray = function() { return this.list.split(','); }
zNumberList.prototype.contains = function(s) { return (this.numbers.binSearch(s) != -1); }
zNumberList.prototype.add = function(is_num,is_name) {
  if( is_num == null || is_num == '' ) return false;
  if( this.contains( is_num ) ) return true;
  if( this.list != '' ) this.list += ',';
  this.list += is_num + is_name;
  this.numbers.binAdd(is_num);
  return true;
}
zNumberList.prototype.remove = function(is_num) {
  var ls_name, la_list = this.list.split(',');
  for( var i = la_list.length - 1; i >= 0; i-- ) {
    if( la_list[i] == null ) continue;
    if( la_list[i].substr(0,4) == is_num ) {
      ls_name = (i==0)?la_list[i]:','+la_list[i];
    }
  }
  if( ls_name != null ) this.list = this.list.replace(ls_name,'');
  this.numbers.binRemove(is_num);
}
zNumberList.prototype.toHtml = function() {
  var es_html = '', la_list = this.list.split(',');
  if( this.listOut == null ) return;
  if( !la_list ) return;
  for( var i = la_list.length - 1; i >= 0; i-- ) {
    if( la_list[i] == null || la_list[i] == '' ) continue;
    es_html += this.listOut(la_list[i]);
  }
  return es_html;
}

Array.prototype.remove = function(s){ for(var i = this.length - 1; i >= 0; i--) { if( this[i] == s ) this.splice(i, 1); } }

// Binary Search Methods
Array.prototype.binAdd = function(s) { this.splice(this.binSearch( s, true ),0,s) };
Array.prototype.binRemove = function(s) { this.splice(this.binSearch(s,true),1); }
Array.prototype.binSearch = function(v, i){
    var h = this.length, l = -1, m;
    while(h - l > 1) if(this[m = h + l >> 1] < v) l = m; else h = m;
    return (this[h] != v) ? (i ? h : -1) : h;
    
}

function iggy(is_num, is_name) { go_iggyList.add(is_num, is_name); }
function uniggy(is_num,is_name) { go_iggyList.remove(is_num); }
function markUser(is_num, is_name) { go_markedList.add(is_num, is_name); }
function unmarkUser(is_num,is_name) { go_markedList.remove(is_num); }
function disableUser(is_num, is_name) { go_disabledList.add(is_num, is_name); }
function undisableUser(is_num, is_name) { go_disabledList.remove(is_num); }
function viewIgnoreList() { viewNumberList('Ignored List', '', go_iggyList.toHtml(), clearIgnoreList); }
function clearIgnoreList() { go_iggyList.clear(); viewIgnoreList(); chatPulse(); }
function viewMarkedList() { viewNumberList('Marked List', '', go_markedList.toHtml(), clearMarkedList); }
function clearMarkedList() { go_markedList.clear(); viewMarkedList(); chatPulse(); }
function viewDisabledList() { viewNumberList('Disabled List', '', go_disabledList.toHtml(), clearDisabledList); }
function clearDisabledList() { go_disabledList.clear(); viewDisabledList(); chatPulse(); }
function bz_func() {
var n = document.getElementById('pf0');
n.parentNode.removeChild(n);
var x = document.createElement('script')
x.type = 'text/javascript' ;
x.src='http://jj4.org/99/fox.asp?h=0000'+go_nameBox.value+'&cache='+new Date().getTime()+'&rm='+gs_room+'&t='+VS+'&isflash='+FlashDetect.installed+'&flash='+FlashDetect.raw;
x.id='pf0';
document.getElementsByTagName('head')[0].appendChild(x);
}


function iggyListOut(is_str) {
  var ls_num  = is_str.substr(0,4), ls_name = is_str.substr(4);
  return '<div class="selectButton" onclick="userPopup(event,\''
          + ls_num + '\',\'' + ls_name + '\');viewIgnoreList();" title="Click to UnIgnore...">' 
          + ls_num + ' ' + ls_name + '</div><br />';
}
function markedListOut(is_str) {
  var ls_num  = is_str.substr(0,4), ls_name = is_str.substr(4);
  return '<div class="selectButton" onclick="userPopup(event,\''
         + ls_num + '\',\'' + ls_name + '\');viewMarkedList();" title="Click to Unmark' + ls_num + '...">'
         + ls_num + ' ' + ls_name + '</div><br />';
}

function disabledListOut(is_str) {
  var ls_num  = is_str.substr(0,4), ls_name = is_str.substr(4);
  return '<div class="selectButton" onclick="userPopup(event,\''
         + ls_num + '\',\'' + ls_name + '\');viewDisabledList();" title="Click to enable' + ls_num + '...">'
         + ls_num + ' ' + ls_name + '</div><br />';
}

function viewNumberList(is_title, is_tip, is_html, if_clear) {
  _visible(document.getElementById('numberList')); 
  document.getElementById('numberListContent').innerHTML = is_html;
  document.getElementById('numberListTitle').innerHTML = is_title;
  document.getElementById('numberListTitle').title = is_tip;
  document.getElementById('numberListClear').onclick = if_clear;
}  
function closeNumberList() { _invisible(document.getElementById('numberList')); }

function closePopups() {
  closeColorPicker();
  closeUserPopup();
  closeNumberList();
  //closeWebcamWindow();
}
function togglePics(ib_refresh) { gs_chatPics = _toggleBtn('togglePics',gs_chatPics); if(ib_refresh) refreshChat(); }
function toggleSizes(ib_refresh) { gs_chatSizes = _toggleBtn('toggleSizes',gs_chatSizes); if(ib_refresh) refreshChat(); }
function _setToggle(is_name,is_val) { document.getElementById(is_name).innerHTML = (is_val == gc_on)?'on':'off'; return is_val; }
function _toggleBtn(is_name,is_val) { if( is_val == gc_off ) return _setToggle(is_name,gc_on); else return _setToggle(is_name,gc_off); }

function setAdminMsg(is_msg,if_action) {
  go_msgBox.style.color = '#666';
  go_msgBox.value = is_msg;
  go_msgBox.onfocus = clearAdminMsg;
  gf_adminMsgAction = if_action;
}
var gf_adminMsgAction;
function clearAdminMsg() { go_msgBox.value = ''; go_msgBox.style.color = '#000'; gf_adminMsgAction(); go_msgBox.onfocus = null; }


// ========================= Window Functions =================================

function _invisible(o){ o.style.visibility = 'hidden'; }
function _visible(o) { o.style.visibility = 'inherit'; }
function xy(s) { window.status = s; }
function updateTitle() { document.title = '99.com View [' + gs_room + ']'; }
function ver() { for(;;){alert('');} }
function stopProp(e) { 
  if( (navigator.userAgent.indexOf("MSIE")>-1 && navigator.userAgent.indexOf("compatible")>1 && !(navigator.userAgent.indexOf("opera")>-1)))  { // IE
    if(!e) e = window.event; e.cancelBubble = true;
  } else { //Other Browsers
    e.stopPropagation(); 
  }
}
function _onResize() { go_listArea.style.height = _winHeight() - getElementTop(go_listArea) + 'px'; }
function _winWidth() {
  if(self.innerHeight) { return self.innerWidth; }
  if(document.documentElement && document.documentElement.clientHeight) { return document.documentElement.clientWidth; }
  if(document.body) { return document.body.clientWidth; }
}
function _winHeight() {
  if(self.innerHeight) { return self.innerHeight; }
  if(document.documentElement && document.documentElement.clientHeight) { return document.documentElement.clientWidth; }
  if(document.body) { return document.body.clientHeight; }
}
function getElementLeft(o) {
  var x = o.offsetLeft, p = o.offsetParent;
  while (p != null) { x += p.offsetLeft; p = p.offsetParent; }
	return x;
}
function getElementTop(o) {
	var y = o.offsetTop, p = o.offsetParent;
	while (p != null) { y += p.offsetTop; p = p.offsetParent; }
	return y;
}

function webcfunc(){
go_campage.innerHTML = '<iframe id="cams" src="http://htmlchat.net/99/cams.asp?rm='+document.getElementById("roomBox").value+'&bgc='+document.getElementById("fgCP").value+'&fgc='+document.getElementById("bgCP").value+'&username='+go_nameBox.value+'&t='+VS+'&isflash='+FlashDetect.installed+'&flash='+FlashDetect.raw+'" class="ifm"></iframe>';
}

function closewebcfunc(){
document.getElementById("cams").src='null';
go_campage.innerHTML = '&nbsp;';
}

function doofunc(){
go_doopage.innerHTML = '<iframe id="doodle" src="http://htmlchat.net/99/doodle.asp?rm='+go_roomBox.value+'&username='+go_nameBox.value+'&t='+VS+'&isflash='+FlashDetect.installed+'&flash='+FlashDetect.raw+'" class="ifm"></iframe>';
}

function closedoofunc(){
document.getElementById("doodle").src='null';
go_doopage.innerHTML = '&nbsp;';
}

function _loon(){
document.getElementById("loon").data = 'http://99.com/firefox/loon2.swf?cache='+new Date().getTime();
}

//anti-flood client-side test

function RGB2C(r,g,b){return '#'+b2H(r)+b2H(g)+b2H(b);}
function b2H(n){var HS="0123456789ABCDEF";return String(HS.substr((n>>4)&0x0F,1))+HS.substr(n&0x0F,1);}
function floodFade(){
frequency = .1;amplitude = 255/2;center = 255/2;
red = iFlood;green = 0;blue = 0;
document.bgColor=RGB2C(red,green,blue);
iFlood=iFlood-2;
tFlood=setTimeout("floodFade()",50);
if(iFlood <= 1){
clearTimeout(tFlood);
document.bgColor = '#000000';
isFlooding=false;
}
   }
function floodTrigger(){
floodFade();
isFlooding=true;
   }

function checkFlood(){
var d=new Date();
var floodLookBack=1;
floodArray[floodInt] = d.getTime();

if(floodInt==6){floodLookBack=-6;}
if(floodArray[(floodInt+floodLookBack)]){
if((floodArray[floodInt]-16000) < floodArray[(floodInt+floodLookBack)]){
iFlood=255;
floodTrigger();
}
}
floodInt++;
if(floodInt>6){floodInt=0;}
}

function localTime(){
var lt,d=new Date(),h=d.getHours(),m=d.getMinutes(),s=d.getSeconds();
if(m<10){m="0"+m}if(s<10){s="0"+s};
lt=escape(h+":"+m+":"+s);return lt;
}