var currdiv = 0;
function getUrlArg(akey){
var re = new RegExp("[\\?|&]"+akey+"=([^&]*)(&|$)","i");
var surl = document.URL;
var m = surl.match(re);
if( m && m[1]){
return unescape(m[1]);
}
return null;
}


var iTimer = null;
function showMsg(){
var tstr = '';
tstr += msgDivs[currdiv];
if(tb.clientHeight < 24){
tstr = tstr.replace(/class="userName"/ig,'class="userName" style="float:left;margin-top:-1px;" ');
}
document.getElementById("divPreview").innerHTML = tstr;

if(currdiv == 0)
currdiv = msgDivs.length-1;
else
currdiv --;
	
iTimer = window.setTimeout("showMsg()",2500);
}


function makeWindowName(wn) {
wn = wn.replace(/@/,"at");
wn = wn.replace(/\./g,"dot");
wn = wn.replace(/\//g,"slash");
wn = wn.replace(/&/g,"amp");
wn = wn.replace(/\'/g,"tick");
wn = wn.replace(/=/g,"equals");
wn = wn.replace(/#/g,"pound");
wn = wn.replace(/:/g,"colon");	
wn = wn.replace(/%/g,"percent");
wn = wn.replace(/-/g,"dash");
wn = wn.replace(/ /g,"blank");
wn = wn.replace(/\?/g,"mk");
return wn;
};

function cleanUpNick(ts){
return ts.replace(/:.*$/igm,"");
}

function cleanUpBBCode(bbstr){
var ts = bbstr;
ts = ts.replace(/\[icon\](http[^\[]*)\[\/icon\]/igm,'<img border=0 src="$1"></img>');
ts = ts.replace(/\[img\](http[^\[]*)\[\/img\]/igm,'<img border=0 height="100%" src="$1"></img>');
ts = ts.replace(/\[([^\]]*)\]/igm,"");
ts = ts.replace(/\[\/([^\]]*)\]/igm,"");
ts = ts.replace(/^MARQUEE:/,"");

return ts;
}


function openWebChat(){
var surl = 'http://say-on.com/webchat/?'+document.URL.replace(/^[^?]*\?/,"").replace("#","");
var owin = window.open(surl,'WebChat_'+makeWindowName(roomid.substr(roomid.length-10)),'width=640px,height=480px,resizable=yes');
try{
owin.focus();
}catch(err){
document.getElementById("divPreview").innerHTML = '<a target="_blank" href="'+surl+'">'+st+'</a>';
if(iTimer)
clearTimeout(iTimer);
}
return false;
}

function showbgImg(bshow){
if(bshow){
var sbd = document.body.style;
var spv = document.getElementById("divPreview").style;
	
if(typeof(sbd.filter)!="undefined"){
sbd.backgroundImage = "none";
sbd.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="images/previewbg.png"';
spv.width = '164px';
spv.height = '58px';
}else{
sbd.backgroundImage = "url('images/previewbg.png')";
sbd.backgroundRepeat = 'no-repeat';
sbd.backgroundPosition = 'left top';
spv.width = '150px';
spv.height = '44px';
}
spv.paddingLeft = '14px';
spv.paddingTop = '14px';
spv.paddingRight = '0px';
spv.paddingBottom  = '0px';
spv.overflow = 'hidden';
}

}
var tb;
function init(){

roomid = getUrlArg("roomid");
if(!roomid){
return;
}
if(getUrlArg('noclk'))
 document.body.onclick = null;
tb = (document.compatMode!="BackCompat")? document.documentElement : document.body;

showbgImg( tb.clientHeight == 86 && tb.clientWidth == 172 );

var st = getUrlArg("title");
msgDivs[msgDivs.length] = st?st:roomid;

currdiv = msgDivs.length-1;
showMsg();


}

onload = init;

