var onlineTimer;
function logInUser(){
	userOnlineNow(true);
}

function logOutUser(){
	userOnlineNow(false);
}
function userOnlineNow(isLogged){
	if(!isLogged && window.screenTop!=undefined && window.screenTop<9999){
		return;
	}
	pars = 'u=' + siteUserId + '&';
	pars += (isLogged)?'login=1':'logout=1';
	url = siteUrl + 'members/online.php';
	if(isLogged)
		new Ajax.Request(url, {method:'post', parameters:pars, onComplete:updatedFunction})
	else
		postViaNormalAjax(url, pars);
}

function updatedFunction(resp){
	rep = resp.responseText;
	if(rep.indexOf('rror')>0){
		if(typeof onlineTimer==='number'){					
			clearInterval(onlineTimer);
		}
		onlineTimer = null;
		return false;
	}

}

function postViaNormalAjax(url, pars){
	  var req = null;
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			 if (req.overrideMimeType) {
					// req.overrideMimeType('text/xml');
			 }
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if(req!=null){
			req.open("POST", url, true);
			try{
			req.onreadystatechange = function(){
				if (req.readyState==4){
					if(req.status==200){
						if(req.responseText){
						}
					}
				}		
			}
			}
			catch(e){}
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			req.setRequestHeader("Content-length",pars.length); 
			req.send(pars);
		}
}
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		if(document.documentElement.clientWidth){
			ch=document.documentElement.clientWidth;
			cw=document.documentElement.clientHeight;
			st=document.documentElement.scrollTop;
		}
		else{
			ch=document.body.clientHeight;
			cw=document.body.clientWidth;
			st=document.body.scrollTop;
		}
		if(ns){
			pX = (this.sx >= 0) ? 0 : innerWidth;
			pY = pageYOffset;
			if(this.sy<0) 
				pY+=innerHeight;
		}
		else{
			pX = (this.sx >= 0) ? 0 : cw;
			pY=st;
			if(this.sy<0) 
				pY+=ch;
		}	
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 50);
	}
	return el;
}
function initiateFloatingAd(){
	if(winW>0&&winH>0){
		document.getElementById('blackout').style.display='block';
		document.getElementById('blackout').style.visibility='visible';
		JSFX_FloatDiv("floating_ad",((winW/2)-(308/2)),((winH/2)-(346/2))).flt();
		document.getElementById('floating_ad').style.display='block';
		loadurl('/iframeCMD.php','action=view_float',false);
	}
	else
		setTimeout('initiateFloatingAd();',5000);
}
function hideFloatingAd(){
	document.getElementById('blackout').style.display='none';
	document.getElementById('blackout').style.visibility='hidden';
	document.getElementById('floating_ad').style.display='none';
}
function chatPopup(){
	document.getElementById('blackout').style.display='block';
	document.getElementById('blackout').style.visibility='visible';
	scroll(0,0);
	boxLeft=(winW/2)-(298/2);
	boxTop=(winH/2)-(222/2);
	standardbody.style.overflow="hidden";
	document.getElementById('popup_div').style.top=boxTop+'px';
	document.getElementById('popup_div').style.left=boxLeft+'px';
	document.getElementById('popup_div').innerHTML='<iframe id="popup_iframe" name="popup_iframe" width="298" height="222" frameborder="0" allowtransparency="true" src="/members/v3messenger/popup.php?internal=1"></iframe>';
	document.getElementById('popup_div').style.display='block';
	document.getElementById('popup_div').style.visbility='visible';
}
function onlineStatus(){
	loadurl('/iframeCMD.php','action=onlineStatus','keepAlive');
}
function getquerystring() {
	var word='onlineStatus';
    qstr = 'action=' + escape(word);
    return qstr;
}
function idleTimeout(){
	window.clearInterval(onlinestatus);
	loadurl('/iframeCMD.php','action=online_status&status=Idle',false);
	onlinestatus=setInterval('onlineStatus()',60000);
}
function refreshContactList(external){
	document.getElementById('chatList').innerHTML='<div id="chatLoading">Loading Contact List<br/>Please Wait</div>';
	loadurl('/members/v3messenger/members/update.php','action=update'+(external==true?'&external=true':''),'chatList');
}