function do_cmd(cmd,key,mode){
	
	if(cmd=='logout'){
		if(confirm('This will log you off IM. Continue?')){
			top.checker.close_im();
		}
	}
	else if(mode){
		open_block(cmd, key);
	}
	else{
		parent.fstatic.open_block(cmd, key);
	}
}

function open_block(block,key){
	
	if(block=='groups'){
		ImOpen(do_link('im','im_groups','pp=up'),'groups','350','430','center','yes');		
	}
	else if(block=='friends'){
		ImOpen(do_link('im','im_friends','pp=up'),'friends','350','430','center','yes');
	}
	else if(block=='ignore'){
		ImOpen(do_link('mailbox','myblocks','pp=up'),'ignore','350','430','center','yes');
	}
	else if(block=='options'){
		ImOpen(do_link('im','im_options','pp=up'),'options','350','430','center','yes');
	}
	else if(block=='help'){
		ImOpen(do_link('global','static','pp=up&file=im_help'),'help','350','430','center','yes');
	}
	else if(block=='chat'){
		ImOpen(do_link('im','request','pp=up&logins_key='+key),'chat','600','430','center','yes');
	}
	else if(block=='join'){
		ImOpen(do_link('im','goin','pp=up&cr_key='+key),'join','600','430','center','yes');
	}
}

function ImOpen(mypage,myname,w,h,win_position){
        var win = null;
        
        if(win_position=="topright"){
           LeftPosition = (screen.width) ? (screen.width-w-12) : 0;
           TopPosition = 20;
        }
        else if(win_position=="center"){
           LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
           TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        }
        else {
           LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
           TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        }

        settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=no';
        
        myname = myusername+myname;
        win = window.open(mypage,myname,settings);
}


// --------------------------------------------------------------------------------------------------------------------------------------------



function SetUsrStatus(Id,UsrStatus){
                var img = new Image();
                img.src = "img/im/im_"+UsrStatus+".gif?"+Math.random();
                eval("document.usr_status_"+Id+".src = img.src;");
				var alt = "Offline";
				if(UsrStatus == "busy") alt = "Busy";
				if(UsrStatus == "on") alt = "Available";
				eval("document.usr_status_"+Id+".alt = '" +alt+ "';");
}

function im_close(){
        win = window.open("", "win", "width=1,height=1,screenX=2000,left=2000,screenY=2000,top=2000");
        win.focus();
        win.document.open("text/html");
        win.document.write("<HTML><HEAD><TITLE></TITLE></HEAD><BODY onClose='window.blur();' marginwidth=0 marginheight=0 topmargin=0 leftmargin=0><img src='im_close.php' width=1 height=1><script language='JavaScript'>alert('Your IM session will be closed now.');self.close()</script></BODY></HTML>");
        win.document.close();
}
