	/********C O N T R O L    F U N C T I O N S**************/
	var g_oHandlerWnd=window;
	
	function initWndFs(){
		g_oHandlerWnd=window.parent;		
	}
	function TextBoxWantEnter(e) {
		var whichCode=e ? (e.which ? e.which:e.keyCode):event.keyCode;
		if (13!=whichCode && 10!=whichCode) return;
		var eventTarget=e ? (e.target ? e.target:e.srcElement):event.srcElement;
		if(!eventTarget) return;
		if(!('text'==eventTarget.type || 'textarea'==eventTarget.type || 'password'==eventTarget.type)) return;
		var bShiftKey=e? (e.shiftKey || e.ctrlKey) :  (event.shiftKey || event.ctrlKey);
		 
		if ("mytext"==eventTarget.name){
			if(!bShiftKey){	tMsgSend(eventTarget.value); }
		}else if("txtprivmsg"==eventTarget.name){
			if(!bShiftKey){	tPrivMsgSend(eventTarget.value); }
		}else if("txtemotemsg"==eventTarget.name){
			tEmoteMsgSend(eventTarget.value);
		}else if("addroomname"==eventTarget.name){
			rAdd(eventTarget.value,'');
		}else if("loginusername"==eventTarget.name || "loginpassword"==eventTarget.name){
			doLogin();
		}
	}
	function tMsgSend(sMsg){
		var sSelected="";
		var oUsersSel=document.chatcontrols.msgto;
		if (oUsersSel) sSelected=oUsersSel.options[oUsersSel.selectedIndex].value;
		tMsgSendEx(sMsg,sSelected,false);
		window.setTimeout("document.chatcontrols.mytext.value=''",10);
	}
	function tPrivMsgSend(sMsg){
		var sSelected=document.frmprivatemsg.txtprivuser.value;
		tMsgSendEx(sMsg,sSelected,false);
		window.setTimeout("document.frmprivatemsg.txtprivmsg.value=''",10);
	}
	function tEmoteMsgSend(sMsg){
		tMsgSendEx(sMsg,"",true);
	}
	function tMsgSendEx(sMsg,sSelected,bIsEmote){
		if (!g_oHandlerWnd) return;
		if (sMsg.length<1) return;
		while(sMsg.charCodeAt(0)<=32){
			sMsg=sMsg.substring(1,sMsg.length);
			if (sMsg.length<1) return;
		}
		while(sMsg.charCodeAt(sMsg.length-1)<=32){
			sMsg=sMsg.substring(0,sMsg.length-1);
			if (sMsg.length<1) return;
		}
		var re = new RegExp("[\n\r]{2,}","g");
		sMsg=sMsg.replace(re,"\n");
		var re = new RegExp("\n","g");
		sMsg=sMsg.replace(re,"<br>");
		if (g_bIsBold) sMsg="<b>" + sMsg + "</b>";
		if (g_bIsItalic) sMsg="<i>" + sMsg + "</i>";
		if (g_bIsUnd) sMsg="<u>" + sMsg + "</u>";
		if (g_sTxtColor.length>0) sMsg="<font color=\"" + g_sTxtColor + "\">" + sMsg + "</font>";
			
		g_oHandlerWnd.typedMsgSend(firstRm(),sMsg,sSelected,bIsEmote);
	}
	
	function rAdd(sRoomName,sTopic){
		if (!g_oHandlerWnd) return;
		if (String(sRoomName).length<1)	return;		
		g_oHandlerWnd.roomAdd(sRoomName,sTopic,false,g_bIsCreatingPrivRoom,g_bIsCreatingModerRoom,g_bIsCreatingPersistRoom);
		if (document.frmAddRoom) document.frmAddRoom.addroomname.value='';
	}		
		
	var g_bIsBold=false;
	var g_bIsItalic=false;
	var g_bIsUnd=false;
	function txtTypeTougle(chType){
		switch(chType){
			case 'b': g_bIsBold=!g_bIsBold; document.imgbold.src=g_bIsBold?"images/chat/t_b_d.gif":"images/chat/t_b.gif"; break;
			case 'i': g_bIsItalic=!g_bIsItalic; document.imgitalic.src=g_bIsItalic?"images/chat/t_i_d.gif":"images/chat/t_i.gif"; break;
			case 'u': g_bIsUnd=!g_bIsUnd; document.imgund.src=g_bIsUnd?"images/chat/t_u_d.gif":"images/chat/t_u.gif"; break;
			default: return;
		}
		txtStyleChange();
	}
	function txtStyleChange(){		
		if (document.chatcontrols && document.chatcontrols.mytext){
			var oStyle=document.chatcontrols.mytext.style;
			if (!oStyle) return;
			if (g_bIsBold) oStyle.fontWeight="bolder"; else oStyle.fontWeight="normal";
			if (g_bIsItalic) oStyle.fontStyle="italic"; else oStyle.fontStyle="normal";
			if (g_bIsUnd) oStyle.textDecoration ="underline"; else oStyle.textDecoration ="none";
		}
	}
	g_sTxtColor="";
	function txtColorChange(sColor){
		g_sTxtColor=sColor;
		document.chatcontrols.mytext.style.color=g_sTxtColor;
		var oColorBtn=document.getElementById("idColorChoice");
		if (oColorBtn) oColorBtn.style.backgroundColor=g_sTxtColor;
		DivHide("popColors",true);
	}
	
	var g_bIsCreatingPrivRoom=false;
	function RoomCrPrivateTougle(){
		g_bIsCreatingPrivRoom=!g_bIsCreatingPrivRoom;
		if (document.imgprivate) document.imgprivate.src=g_bIsCreatingPrivRoom?"images/chat/btn_private_down.gif":"images/chat/btn_private_up.gif";
	}
	var g_bIsCreatingModerRoom=false;
	function RoomCrModerTougle(){
		g_bIsCreatingModerRoom=!g_bIsCreatingModerRoom;
		if (document.imgmoder) document.imgmoder.src=g_bIsCreatingModerRoom?"images/chat/btn_moder_down.gif":"images/chat/btn_moder_up.gif";
	}
	var g_bIsCreatingPersistRoom=false;
	function RoomPersistTougle(){
		g_bIsCreatingPersistRoom=!g_bIsCreatingPersistRoom;
		if (document.imgpersist) document.imgpersist.src=g_bIsCreatingPersistRoom?"images/chat/btn_persist_down.gif":"images/chat/btn_persist_up.gif";
	}
	var g_iCurrStatus=0;
	function StatusAwayTougle(){
		g_iCurrStatus=(0==g_iCurrStatus)?2:0;
		ChatStatusSet();
		statusChange(g_iCurrStatus);
	}
	function ChatStatusSet(){
		if (document.imgaway) document.imgaway.src=(0==g_iCurrStatus)?"images/chat/btn_brick_up.gif":"images/chat/btn_brick_down.gif";
	}
	
	var g_bIsSound=true;
	function ChatSoundTougle(){
		g_bIsSound=!g_bIsSound;
		ChatSoundSet();
	}
	function ChatSoundSet(){
		if (document.imgsound) document.imgsound.src=g_bIsSound?"images/chat/btn_sound_down.gif":"images/chat/btn_sound_up.gif";
	}
	
	var g_bIsAlert=false;
	function ChatAlertTougle(){
		g_bIsAlert=!g_bIsAlert;
		ChatAlertSet();
	}
	function ChatAlertSet(){
		if (document.imgalert) document.imgalert.src=g_bIsAlert?"images/chat/btn_alert_down.gif":"images/chat/btn_alert_up.gif";
	}
		
	function DivIsVisible(sDivId){
		if (sDivId.length<1 || !document.getElementById) return false;
		var divEl=document.getElementById(sDivId);
		return (divEl && divEl.style.visibility.toLowerCase( )=="visible");
	}
	function textadd(sDivId,sTxt){
		document.chatcontrols.mytext.value=document.chatcontrols.mytext.value + sTxt;
		DivHide(sDivId,true);
		document.chatcontrols.mytext.focus();
	}