﻿function Chat_GetTopPanel(o)
{
	try
	{
		var p=o;while(p.getAttribute("c_clientID")==null || p.getAttribute("c_clientID")=="")p=p.parentNode;
		return p;
	}catch(e){}
	return null;
}
function Chat_GetClientID(o)
{
	try{ return Chat_GetTopPanel(o).getAttribute("c_clientID");	}catch(e){}
	return "";
}
function Chat_PostCommand(clientID,cmd)
{
	$get(clientID+'_hidCommand').value	= cmd;
	try{eval(unescape($get(clientID+"_lbCommand").href));}catch(e){alert(e.message);}
}


//-----------------------------------------------------------
function __CChat_GetObject(o)
{
	var p=o;while(p.__obj==null)p=p.parentNode;
	return p.__obj;
}
//###########################################################
//###
//###	__CChatMessages
//###
//###########################################################
function __CChatMessages(clientID,topicID,roundID,userID,maxCommentLength)
{
//alert(clientID);
	this.clientID	= clientID;
	this.topicID	= topicID;
	this.roundID	= roundID;
	this.userID		= userID;
	this.itemID		= null;
	this.panMain	= $get(clientID+"_panMain");
	this.panMain.__obj = this;

	this.maxLength = -1; if(maxCommentLength!=null)this.maxLength=1*maxCommentLength;
	this.spanCounter = $get(clientID+"_counter");
	
	this.tblEd = $get(clientID + "_tblEd");
	this.divEd = $get(clientID + "_divEd");
	this.oEditor = null;	// $find(clientID+"_ed1");
	this.editMode = "";
	
	//this.mode = $get(clientID+"_hidMode").value;

	var arr = $get(clientID+"_divRep").childNodes;
	for(var j=0; j<arr.length; j++)
	{
		try
		{
			var p = arr[j];
			if (p.getAttribute("c_msgID")==null)continue;
			var tbl = p.childNodes[0];
			var div = p.childNodes[1];
//			p.__tbl = tbl;
//			p.__div = div;
			var ss = div.innerText;
//alert(div.innerHTML);
			var maxlen = 170;
			if (ss.length>maxlen)ss=ss.substring(0,maxlen)+"...";

			tbl.rows[0].cells[2].innerHTML = ss;
		}catch(e){}
	}
	

}
//-----------------------------------------------------------
//--- ShowHideTopicText
//-----------------------------------------------------------
__CChatMessages.prototype.ShowHideTopicText = function()
{
	var hid = $get(this.clientID+"_hidExpTopic");
	var div	= $get(this.clientID+"_divTopic");
	var exp = !(hid.value == "y");
	
	hid.value = exp ? "y" : "n";
	
	var ss = exp ? "Up" : "Dn";
	for(var j=1; j<=3; j++){ $get(this.clientID+"_imgArrow"+j).src = "/images/arrow" + ss + "1_7x6.gif"; }
	
	if (exp){	div.setAttribute("v_height", div.style.height);	}
	div.style.overflow = exp ? "" : "auto";
	div.style.height = exp ? "" : div.getAttribute("v_height");
}
//-----------------------------------------------------------
//--- ClickMsgTitle
//-----------------------------------------------------------
__CChatMessages.prototype.ClickMsgTitle = function(o)
{
	var p=o;while(p.getAttribute("c_msgID")==null || p.getAttribute("c_msgID")=="")p=p.parentNode;
	var tr=o;while(tr.tagName!="TR")tr=tr.parentNode;
	var itemID = p.getAttribute("c_msgID");

	var exp = p.getAttribute("c_exp")!="n";
	exp = !exp;
	p.setAttribute("c_exp",exp?"y":"n");

	var td;
	td = tr.cells[2];
	td.style.display = exp ? "none" : "";

	td = tr.cells[3];
	td.style.display = exp ? "" : "none";

	td = tr.cells[4];
	td.style.display = exp ? "" : "none";
	
	g_global.GetChildElementsByTagName(p,"div")[0].style.display = exp ? "" : "none";
}
//-----------------------------------------------------------
//--- ClickMsgTitle
//-----------------------------------------------------------
__CChatMessages.prototype.Reply = function(o,mode)
{
//	var fr = $get(this.clientID + "_frmEditor");
//	var tbl=o;while(tbl.tagName!="TABLE")tbl=tbl.parentNode;

	this.editMode = mode;
	var txt = "";
	var div = null;
	if (mode=="ReplyItem" || mode=="EditItem")
	{	
		var p=o;while(p.getAttribute("c_msgID")==null || p.getAttribute("c_msgID")=="")p=p.parentNode;
		this.itemID = p.getAttribute("c_msgID");
	
		var divTxt = p.childNodes[1];
		div = p.childNodes[2];
		if (mode=="ReplyItem")
			txt = "<br/><blockquote>" + divTxt.innerHTML + "</blockquote><br/>";
		else
			txt = divTxt.innerHTML;
		
		//$get(this.clientID + "_hidItemID").value
		//this.itemID = itemID;
	}
	else if (mode=="ReplyTopic")
	{
		div = $get(this.clientID+"_divTopicReply");
	}
//	window.setTimeout( "", 100);
	window.setTimeout( div.appendChild( this.tblEd ), 100);
	window.setTimeout( "", 100);
	window.setTimeout( div.appendChild( this.tblEd ), 100);
	window.setTimeout( "", 100);
	window.setTimeout( div.appendChild( this.tblEd ), 100);
	window.setTimeout( "", 200);
//return;	
	
	$get(this.clientID + "_butSaveReply").value = mode=="EditItem" ? "Save Changes" : "Submit Reply";
	$get(this.clientID + "_hidCommand").value = mode;
	
	var inited = this.oEditor!=null;
	var ed = $find(this.clientID+"_ed1");
	ed.setSize(500,200);
	ed.set_html( txt );
	ed.get_contentArea().style.backgroundImage = "url(/images/editor_background.gif)";
	//ed.get_contentArea().style.backgroundColor = "#ffffcc";
	ed.set_visible(true);
	ed.setFocus();
	this.oEditor = ed;
//return;
//Skin="Outlook"
	if (!inited)	//...not initialized yet
	{
		if (this.maxLength!=-1)
		{
			ed.get_document().body.__obj = this;
			ed.get_textArea().__obj = this;
			
			this.AttachHandlers();
			this.CheckLength();

			ed.add_modeChange(function(editor, args)
			{
				var mode = editor.get_mode();
				if (mode == 3)return;
				var obj = mode == 2 ? editor.get_textArea().__obj : editor.get_document().body.__obj;
				obj.AttachHandlers();
				obj.CheckLength();
			});
		}
	}
}
//-----------------------------------------------------------
//--- AttachHandlers
//-----------------------------------------------------------
__CChatMessages.prototype.AttachHandlers = function() //mode)
{
	var ed = this.oEditor;
	var mode = ed.get_mode();
	if(mode==1)
	{        
		ed.attachEventHandler("onkeyup",	Chat_CheckLength);
		ed.attachEventHandler("onpaste",	Chat_CheckLength);
		ed.attachEventHandler("onblur",		Chat_CheckLength);
	}
	else
	{                              
		var textarea = ed.get_textArea();	//...returns a reference to the textarea in Html mode
//		textarea.onkeydown = Chat_CheckLength;
		
		if(window.attachEvent)
		{                              
			textarea.attachEvent("onkeydown",	Chat_CheckLength);
			textarea.attachEvent("onpaste",		Chat_CheckLength);
			textarea.attachEvent("onblur",		Chat_CheckLength);
		}                            
		else
		{                      
			textarea.addEventListener("keydown",	Chat_CheckLength, true);
			//textarea.addEventListener("keyup",	Chat_CheckLength, true);
			textarea.addEventListener("paste",	Chat_CheckLength, true);
			textarea.addEventListener("blur",	Chat_CheckLength, true);
		}
	}
}
//-----------------------------------------------------------
//--- CheckLength
//-----------------------------------------------------------
__CChatMessages.prototype.CheckLength = function(e)
{
	var textLength = this.oEditor.get_text().length;
	if (textLength >= this.maxLength)
	{
		alert('You are not able to type more than ' + this.maxLength + ' symbols!\nAll extra symbols will be cut on saving changes.');
		try{e.returnValue = false;}catch(e){}
	}
	this.spanCounter.innerHTML = "Characters left: <b>" + (this.maxLength-textLength) + "</b>";
}
//-----------------------------------------------------------
//--- DeleteItem
//-----------------------------------------------------------
__CChatMessages.prototype.DeleteItem_Begin = function(o)
{
	var p=o;while(p.getAttribute("c_msgID")==null || p.getAttribute("c_msgID")=="")p=p.parentNode;
	this.itemID = p.getAttribute("c_msgID");
	var tbl = p.childNodes[0];
	tbl.style.backgroundColor = "yellow";
	if (confirm("Do you want to delete selected message?"))
	{
		ChatWS.DeleteItem(this.clientID, this.itemID, this.userID,
				Chat_DeleteItem_OnComplete, Chat_DeleteItem_OnError);
	}
	tbl.style.backgroundColor = "#f8f8f8";
}
__CChatMessages.prototype.DeleteItem_End = function(o)
{
	$get(this.clientID+"_hidCommand").value = "Refresh";
	var prm = Sys.WebForms.PageRequestManager.getInstance();
	prm._doPostBack(this.clientID+"_lbCommand", '');
}
//-----------------------------------------------------------
//--- DiscardChange
//-----------------------------------------------------------
__CChatMessages.prototype.DiscardChange = function(o)
{
	this.divEd.appendChild( this.tblEd );
	return false;
}
//-----------------------------------------------------------
//--- SaveReply - SaveReply_Begin, SaveReply_End
//-----------------------------------------------------------
__CChatMessages.prototype.SaveReply_Begin = function(o)
{
	try
	{
		var id = this.topicID;
		id = this.itemID;
		if (this.editMode=="ReplyItem")
		{
			ChatWS.ReplyItem(this.clientID, this.topicID, this.itemID, this.roundID, this.oEditor.get_html(), this.userID,
				Chat_SaveMessage_OnComplete, Chat_ReplyItem_OnError);
		}	
		else if ( this.editMode=="EditItem")
		{
			ChatWS.EditItem(this.clientID, this.itemID, this.oEditor.get_html(), 
				Chat_SaveMessage_OnComplete, Chat_EditItem_OnError);
		}
		else if (this.editMode=="ReplyTopic")
		{
			ChatWS.ReplyTopic(this.clientID, this.topicID, this.roundID, this.oEditor.get_html(), this.userID,
				Chat_SaveMessage_OnComplete, Chat_ReplyTopic_OnError);
		}	
//		ChatWS.SaveMessage(this.clientID, this.editMode, id, this.oEditor.get_html(),
//			Chat_SaveMessage_OnComplete, Chat_SaveMessage_OnError);
		return true;
	}
	catch(e)
	{
		alert("Scripting error: " + e.message);
	}

	return false;

}
__CChatMessages.prototype.SaveReply_End = function(o)
{
	$get(this.clientID+"_hidCommand").value = "Refresh";
	var prm = Sys.WebForms.PageRequestManager.getInstance();
	prm._doPostBack(this.clientID+"_lbCommand", '');
}
//-----------------------------------------------------------
//--- ViewProfile
//-----------------------------------------------------------
__CChatMessages.prototype.ViewProfile = function(o)
{
	var p=o;while(p.getAttribute("c_msgID")==null || p.getAttribute("c_msgID")=="")p=p.parentNode;
	var userID = p.getAttribute("c_userid");
	var args = new Function();
	var url = "/Panels/Chat/ViewUserProfile.aspx?uid="+userID;
	var win = g_global.OpenWindow(url,args,600,400,"View User Profile");
	/*
	var win = radopen();
	//$find(this.clientID+"_win2");
	win.setSize(600,400);
	win.set_modal(true);
	win.set_title("View User Profile");
	win.set_behaviors( Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close  + Telerik.Web.UI.WindowBehaviors.Resize );
	win.setUrl(url);
	win.show();
	*/
}
//-----------------------------------------------------------
//--- PrintMessage
//-----------------------------------------------------------
__CChatMessages.prototype.PrintMessage = function(o)
{
	var p=o;while(p.getAttribute("c_msgID")==null || p.getAttribute("c_msgID")=="")p=p.parentNode;
	var tr=o;while(tr.tagName!="TR")tr=tr.parentNode;
	var args = new Function();
	args.message = "<div>" + tr.cells[1].innerHTML + "</div>" + p.childNodes[1].innerHTML;
	var url = "/Panels/Chat/PrintMessage.aspx";
	var win = g_global.OpenWindow(url,args,600,400,"Print Message");
	/*
	radopen();
	win.argument = args;
	win.setSize(600,400);
	win.set_modal(true);
	win.set_title("Print Message");
	win.set_behaviors( Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close  + Telerik.Web.UI.WindowBehaviors.Resize );
	win.setUrl(url);
	win.center();
	win.show();
	*/
}



//<%# DataBinder.Eval(Container.DataItem, "Id")%>,

function Chat_ShowHideItems(o){		__CChat_GetObject(o).ShowHideTopicText();	}
function Chat_ClickMsgTitle(o){		__CChat_GetObject(o).ClickMsgTitle(o);		}
function Chat_Reply(o,mode){		__CChat_GetObject(o).Reply(o,mode);			}
function Chat_DiscardEdit(o){		return __CChat_GetObject(o).DiscardChange(o);  	}
function Chat_SaveReply(o){			return __CChat_GetObject(o).SaveReply_Begin(o); }
function Chat_Delete(o){			__CChat_GetObject(o).DeleteItem_Begin(o);		}
function Chat_ViewProfile(o){		__CChat_GetObject(o).ViewProfile(o);			}
function Chat_PrintMsg(o){			__CChat_GetObject(o).PrintMessage(o);			}

function Chat_CallContextMenu(o){	__CChat_GetObject(o).ShowContextMenu(o);			}
function Chat_ContextMenuSelected(sender, args){__CChat_GetObject(args.get_item().get_menu().get_element().__caller).ContextMenuSelected(args);		}

function Chat_SaveMessage_OnComplete(arg){	$get(arg+"_panMain").__obj.SaveReply_End();	}
function Chat_DeleteItem_OnComplete(arg){	$get(arg+"_panMain").__obj.DeleteItem_End();	}

function Chat_ReplyItem_OnError(err){	alert("Error encountered when calling ChatWS.ReplyItem:\n\n" + g_global.GetAJAXErrorDetails(err));	}
function Chat_EditItem_OnError(err){	alert("Error encountered when calling ChatWS.EditItem:\n\n" + g_global.GetAJAXErrorDetails(err));	}
function Chat_ReplyTopic_OnError(err){	alert("Error encountered when calling ChatWS.ReplyTopic:\n\n" + g_global.GetAJAXErrorDetails(err));	}
function Chat_DeleteItem_OnError(err){	alert("Error encountered when calling ChatWS.DeleteItem:\n\n" + g_global.GetAJAXErrorDetails(err));	}

function Chat_CheckLength(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev	= (window.event) ? window.event : e; //(e) ? e : window.event;
	if(ev==null)return false;	

	var key	= (ev.keyCode) ? ev.keyCode : ev.which;
	var o	= (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	//...defeat Safari bug
	//::::::::::::::::::::::::::::: 

	return o.__obj.CheckLength(e);
}








function Chat_ExpColTopic(o){				__CChat_GetObject(o).ExpColTopic(o);	}
function Chat_Topics_ClickMenu(sender, args)
{
	var but = args.get_item();
	var elem = but.get_element();
	var cmd = but.get_value();
	__CChat_GetObject(elem).ExecCommand(cmd);
}
//###########################################################
//###
//###	__CChatTopics
//###
//###########################################################
function __CChatTopics(clientID,instanceID,userID)
{
//alert(clientID);
	this.clientID	= clientID;
	this.instanceID	= instanceID;
	this.uniqueToken= $get(clientID+"_hidUniqueToken").value;
	this.userID		= userID;

	this.itemID		= null;
	this.panMain	= $get(clientID+"_panMain");
	this.panMain.__obj = this;
	this.divTree	= $get(clientID+"_divTree");
	this.divTreeMenu= $get(clientID+"_divTreeMenu");
	this.divXml		= $get(clientID+"_divXml");
	this.hidExpIDs	= $get(clientID+"_hidExpandedIDs");
	this.divTemp	= $get(clientID+"_divTemp");
	
//	this.oTooltip	= $find(clientID+"_RadToolTip1");
//alert(this.oTooltip==null);
	
	this.isEven=true;
}
//-----------------------------------------------------------
//--- ExecCommand
//-----------------------------------------------------------
__CChatTopics.prototype.ExecCommand = function(cmd)
{
//	var wwWin = window.screen.availWidth - 80;
//	var hhWin = window.screen.availHeight - 80;
//alert(cmd);
	if (cmd=="NewTopic")
	{
		Chat_NewTopic(this.clientID);
	}
	else if (cmd=="SetRounds")
	{
		Chat_SetRounds(this.clientID,this.instanceID);
	}
	else if (cmd=="")
	{
		
	}
	else if (cmd=="StandardReport")
	{
		Chat_StandardReport(this.clientID, this.instanceID, escape(this.uniqueToken) );
	}
	else if (cmd=="SetProfile")
	{
		Chat_SetProfile(this.clientID);
	}
}
//-----------------------------------------------------------
//--- RefreshAll
//-----------------------------------------------------------
__CChatTopics.prototype.RefreshAll = function()
{
	this.isEven=true;
	//var arr = g_global.GetChildElementsByTagName(this.divXml,"div");
//alert(this.divXml.outerHTML);
	this.isTree = false;
	var arr = this.divXml.getElementsByTagName("div");
	for(var j=0; j<arr.length; j++)
	{
		if (g_global.GetChildElementsByTagName(arr[j],"div").length > 0)
		{
			this.isTree=true;
			break;
		}
	}
	var ss=
		"<table style='width:100%; background-color:#f0f0f0; ' cellpadding='6' cellspacing='1'>" +
		"<tr style='background-color:#dcdcdc; color:#003366; font: bold 11px tahoma, verdana, arial, helvetica, sans-serif;'>" +
			"<td>&nbsp;</td>" + 
			"<td style='width:100%'>" + 
				"<table cellspacing='0' cellpadding='0' style='width:100%;'>" +
				"<tr>" + 
					"<td>" + 
						"<b>Topic&nbsp;/&nbsp;Author</b></td>" + 
					"</td>" + 
					"<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>" + 
					"<td style='width:100%;'>" + 
					"</td>" + 
				"</tr>" + 
				"</table>" + 
			"<td align='center'><b>Last&nbsp;Post&nbsp;Info</b></td>" + 
			"<td align='center'><b>Total<br />Messages</b></td>" + 
			"<td align='center'><b>Views</b></td>" + 
		"</tr>";
//alert(this.divXml.outerHTML);
	ss+=this.GetTR(this.divXml,0);
	ss+="</table>";
	
	
	this.divTemp.appendChild(this.divTreeMenu);
	this.divTree.innerHTML = ss;
	
	var tbl = this.divTree.childNodes[0];
	var td = tbl.rows[0].cells[1].childNodes[0].rows[0].cells[2];
	td.innerHTML = "";
	td.appendChild(this.divTreeMenu);
	this.divTreeMenu.style.display = "";
}
//-----------------------------------------------------------
//--- DrawRow
//-----------------------------------------------------------
__CChatTopics.prototype.GetTR = function(xPar,level)
{
	var arr = g_global.GetChildElementsByTagName(xPar,"div");
	var ss="";
	for(var j=0; j<arr.length; j++)
	{
		var x = arr[j];
		var itemID = x.getAttribute("id");
		var descr = x.getAttribute("descr");
		var isExp = this.hidExpIDs.value.indexOf(","+itemID+",")!=-1;
		var ssInfo="";
		var hasReplies = x.getAttribute("totalReplies") != "0";
		if (hasReplies)
		{
			ssInfo = 
			"<table width='150' cellpadding='1' cellspacing='0'>" +
			"<tr>" + 
				"<td align='right' style='white-space:nowrap'>" + 
					x.getAttribute("lastMessageDate") +
				"</td>" + 
			"</tr>" + 
			"<tr>" + 
				"<td align='right'>" + 
					"from&nbsp;" + 
					//<asp:LinkButton Runat="server" ID="lbFromUser" EnableViewState="False" 
					//						Enabled="false" 
					//						OnClick="LinkButton_Click" CommandName="ClickUserName" 
					//						CommandArgument='<%# DataBinder.Eval(Container.DataItem, "lastMemberID")%>'
					//					><%# DataBinder.Eval(Container.DataItem, "lastNickname")%></asp:LinkButton>
					//					<!--   lastAuthor -->
					
					x.getAttribute("lastNickname") +
					
				"</td>" + 
			"</tr>" + 
			"</table>";
		}
		else
		{
			ssInfo = "<div style='color:#990000; text-align:center;'>No&nbsp;replies</div>";
		}
		
		var arr2 = g_global.GetChildElementsByTagName(x,"div");
		var ssPM = this.isTree ? "<img src='/images/pixel.gif' width='16' height='16' />" : "";
		if (arr2.length>0)
		{
		
			ssPM = "<img src='/images/16x16/" + (isExp?"CollapseMinus.gif":"CollapsePlus.gif") + "' width='16' height='16' " + 
						"style='cursor:pointer;' onclick='Chat_ExpColTopic(this)' />";
		}
		

		ss+=
		"<tr style='background-color:" + (this.isEven?"#ffffff":"#f5f5f5") + "'" + 
			" c_token='Row' c_ItemID='" + itemID + "'" +
		">";
		if (level==0)
		{
			ss+=
				"<td valign='top' align='right' style='white-space:nowrap;'>" + 
					ssPM + 
					"<img src='/images/16x16/Page3.gif' width='16' height='16' onclick='Chat_CallContextMenu(this,\"Topic\")' />" + 
				"</td>" + 
				
				"<td>" + 
						"<div><b style='cursor:pointer; color:blue;' " + 
							"title='" + descr + "' " + 
//							"onmouseover='Chat_ShowTooltip(this)' " + 
//							"onmouseout='Chat_HideTooltip(this)' " +
							"onclick='Chat_TopicClick(this)'>" + 
							x.getAttribute("n") + 
							//<%# DataBinder.Eval(Container.DataItem, "Title")%>
						"</b></div>" + 
						"<div>" + x.getAttribute("author") + "</div>" + 
				"</td>";
		}
		else
		{
			var indent = "";for(var k=0;k<level;k++)indent+="&nbsp;&nbsp;";
			ss+=
				"<td valign='top' colspan='2' style='padding:0px;'>" + 
					"<table style='' cellpadding='6' cellspacing='1'>" +
					"<tr>" + 
						"<td>" + indent + "</td>" +
						"<td valign='top' align='right' style='white-space:nowrap;'>" + 
							ssPM + 
							"<img src='/images/16x16/Page3.gif' width='16' height='16' onclick='Chat_CallContextMenu(this,\"Topic\")' />" + 
						"</td>" + 
						
						"<td>" + 
								"<div>" + 
								"<b style='cursor:pointer; color:blue;' " + 
									"title='" + descr + "' " + 
//									"onmouseover='Chat_ShowTooltip(this)' " + 
//									"onmouseout='Chat_HideTooltip(this)' " +
									//(descr!="" ? (" title='"+descr+"' ") : "") +
									"onclick='Chat_TopicClick(this)'>" + 
									x.getAttribute("n") + 
									//<%# DataBinder.Eval(Container.DataItem, "Title")%>
								"</b></div>" + 
								"<div>" + x.getAttribute("author") + "</div>" + 
						"</td>" +
					"<tr>" + 
					"</table>" +
				"</td>";
		}
		
		ss+=
			"<td>" + ssInfo + "</td>" + 

			"<td align='center'><b>" + x.getAttribute("totalReplies") + "</b></td>" + 
			
			"<td align='center'><b>" + x.getAttribute("totalViews") + "</b></td>" + 
		"</tr>";
		
		this.isEven=!this.isEven;
		
		if (isExp)
		{
			ss+= this.GetTR(x, level+1);
		}
	}
	return ss;
}
//-----------------------------------------------------------
//--- ExpColTopic
//-----------------------------------------------------------
__CChatTopics.prototype.ExpColTopic = function(o)
{
	var tr=o;while(tr.getAttribute("c_ItemID")==null)tr=tr.parentNode;
	var itemID = tr.getAttribute("c_ItemID");
	var arr=this.hidExpIDs.value.split(",");
	var ss=",";
	var exists=false;
	for(var j=0; j<arr.length; j++)
	{
		var id = g_global.Trim(arr[j]);
		if (id=="")continue;
		if (id==itemID)
		{
			exists = true;
		}
		else
		{
			ss+=id+",";
		}
	}
	if (!exists)
		ss+=itemID+",";
	this.hidExpIDs.value = ss;
	this.RefreshAll();
}
//-----------------------------------------------------------
//--- ShowContextMenu
//-----------------------------------------------------------
__CChatTopics.prototype.ShowContextMenu = function(o)
{

//var contextMenu = $find("<%= RadContextMenu1.ClientID %>");
	var cm = $find(this.clientID+"_contextMenu1");       
//alert(1);
	cm.get_element().__caller = o;
//alert(2);
	var ev = new Sys.UI.DomEvent(o);
	//$telerik.
//alert(ev==null);
//alert(window.event==null);
	cm.show(window.event);
	//cm.show(ev);
//alert(4);
/*	     
	if ((!e.relatedTarget) || (!$telerik.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget)))
	{
	   
	}
*/	      
	$telerik.cancelRawEvent(event);

/*
	var td		= o;while(td.tagName!="TD"){td=td.parentNode;}
	var tr		= o;while(tr.getAttribute("c_token")==null || tr.getAttribute("c_token").indexOf("Row")==-1)tr=tr.parentNode;
	var pan		= Chat_GetPanel(o,"ListPanel");
	var clientID= pan.getAttribute("c_clientID");
	var panXml	= $get(clientID+"_panXmls");
	var xmlDoc	= panXml.children[0];
	var xml		= xmlDoc.XMLDocument.documentElement;
	var xNode	= xml.selectSingleNode("//ContextMenus/Caller[@ref='"+itemType+"']");

	clickedTag = o;
	try
	{
		try{xNode.selectSingleNode("Item[@guid='"+itemType+".View']").setAttribute("disabled",		tr.getAttribute("c_perm_View")=="y"?"n":"y");		}catch(e){}
		try{xNode.selectSingleNode("Item[@guid='"+itemType+".AddForum']").setAttribute("disabled",	tr.getAttribute("c_perm_AddForum")=="y"?"n":"y");	}catch(e){}
		try{xNode.selectSingleNode("Item[@guid='"+itemType+".Edit']").setAttribute("disabled",		tr.getAttribute("c_perm_Edit")=="y"?"n":"y");		}catch(e){}
		try{xNode.selectSingleNode("Item[@guid='"+itemType+".Publish']").setAttribute("disabled",	(tr.getAttribute("c_IsPublished")=="n" && tr.getAttribute("c_perm_Publish")=="y")?"n":"y");		}catch(e){}
		try{xNode.selectSingleNode("Item[@guid='"+itemType+".Delete']").setAttribute("disabled",	tr.getAttribute("c_perm_Delete")=="y"?"n":"y");		}catch(e){}
		try{xNode.selectSingleNode("Item[@guid='"+itemType+".SetPerm']").setAttribute("disabled",	tr.getAttribute("c_perm_SetPerm")=="y"?"n":"y");	}catch(e){}
		
		//...set references to Popup objects
		try{ td._Popup.hide();}catch(e){} 
		td._Popup = window.createPopup();
		td._RootPopup = td._Popup;
		td.setAttribute("_path", '');
		
		eval("Menu_ShowContextMenu(0, 19, xml, xNode, td, 'Chat_ContextMenuSelected');");
	}
	catch(e)
	{
alert(e.message);
	}
*/
}
//-----------------------------------------------------------
//--- ContextMenuSelected
//-----------------------------------------------------------
__CChatTopics.prototype.ContextMenuSelected = function(args)
{
	var o = args.get_item().get_menu().get_element().__caller;
	var cmd = args.get_item().get_value();
	
//	var o			= clickedTag;
//	var pan			= Chat_GetPanel(o,"ListPanel");
//	var clientID	= pan.getAttribute("c_clientID");
	var appPath		= "/";
	var hidID		= $get(this.clientID+"_hidID");
	var hidCmd		= $get(this.clientID+"_hidCommand");
	var hidValue	= $get(this.clientID+"_hidValue");
	var lb			= $get(this.clientID+"_lbCommand");
	var doCmd		= false;
	var tr			= o;

	hidCmd.value	= cmd;
	try
	{
		tr = Chat_GetPanel(o,"Row");
		//while(tr.getAttribute("c_token")==null || tr.getAttribute("c_token").indexOf("Row")==-1)tr=tr.parentNode;
		hidID.value = tr.getAttribute("c_ItemID");
	}
	catch(e){}

	if(cmd=="EditTopic" || cmd=="ViewTopic" || cmd=="AddSubTopic")
	{
		doCmd = true;
	}
	else if(cmd=="DeleteTopic")
	{	
		var arr = tr.cells;
		for(var j=0; j<arr.length; j++){arr[j].style.backgroundColor = "gold"};
		if (confirm("Do you want to delete selected topic?"))
		{
			doCmd = true;
		}
		for(var j=0; j<arr.length; j++)arr[j].style.backgroundColor = "";
	}
	else if (cmd=="Group.SetPerm")
	{
		var date = new Date();
		var fn = "/Panels/SetPermissions/SetPermissions.aspx";
		var url = fn + "?itemID="+tr.c_ItemID + "&moduleID="+tr.c_ModuleID+"&isFolder="+tr.c_IsFolder+"&time="+date.getTime();
		var args = new Function();

		tr.style.backgroundColor = "yellow";
		if (window.showModalDialog(url, args, 'dialogWidth:500px; dialogHeight:550px; center:yes; edge:raised; scroll:no; status:no;'))
		{
			hidValue.value = args.xPerms.xml;
			doCmd = true;
		}
		tr.style.backgroundColor = "";
	}

	if (doCmd)
		try{eval(unescape(lb.href));}catch(e){alert(e.message);}
}
//-----------------------------------------------------------
//--- EditProfile
//-----------------------------------------------------------
__CChatTopics.prototype.EditProfile = function()
{
	var args = new Function();
	args.callerObject = this;
	args.callback = "args.callerObject.ProfileChanged(args);";
	//var url = "/Panels/Chat/PrintMessage.aspx";
	var url = "/Panels/Chat/MyProfile/Profile.aspx?instid="+this.instanceID;
	var win = g_global.OpenWindow(url,args,600,520,"Edit Profile");

/*
	var url = "/Panels/Chat/MyProfile/default.htm";
	if (window.showModalDialog(url, null, 'dialogWidth:700px; dialogHeight:550px; center:yes; edge:raised; scroll:no; status:yes;'))
	{
		$get(clientID+'_hidCommand').value	= "SetProfile";
		$get(clientID+'_lbCommand').click();
	}
	*/
}
//-----------------------------------------------------------
//--- ProfileChanged
//-----------------------------------------------------------
__CChatTopics.prototype.ProfileChanged = function(args)
{
	args.window.close();
	Chat_PostCommand(this.clientID, "ProfileChanged");
//	$get(this.clientID+"_hidCommand").value	= "ProfileChanged";
//	try{eval(unescape($get(this.clientID+"_lbCommand").href));}catch(e){alert(e.message);}
}
//-----------------------------------------------------------
//--- ClickTitle
//-----------------------------------------------------------
__CChatTopics.prototype.ClickTitle = function(o)
{
	var tr=o;while(tr.getAttribute("c_ItemID")==null)tr=tr.parentNode;
	var itemID		= tr.getAttribute("c_ItemID");
	
	//$get(this.clientID+"_hidCommand").value	= "ViewTopic";
	$get(this.clientID+"_hidID").value		= itemID;
	Chat_PostCommand(this.clientID, "ViewTopic");
	//try{eval(unescape($get(this.clientID+"_lbCommand").href));}catch(e){alert(e.message);}
}

/*
//-----------------------------------------------------------
//--- ShowTooltip
//-----------------------------------------------------------
__CChatTopics.prototype.ShowTooltip = function(o)
{
	var tr=o;while(tr.getAttribute("c_ItemID")==null)tr=tr.parentNode;
	var itemID		= tr.getAttribute("c_ItemID");
//	o.style.backgroundColor='yellow';
	this.oTooltip.set_targetControl(o);
	this.oTooltip.set_content(o.innerHTML);
	this.oTooltip.show();
}
//-----------------------------------------------------------
//--- HideTooltip
//-----------------------------------------------------------
__CChatTopics.prototype.HideTooltip = function(o)
{
	var tr=o;while(tr.getAttribute("c_ItemID")==null)tr=tr.parentNode;
	var itemID		= tr.getAttribute("c_ItemID");
//	o.style.backgroundColor='';
	this.oTooltip.hide();
}
*/





function Chat_SetProfile(clientID){		$get(clientID+"_panMain").__obj.EditProfile();	}
function Chat_TopicClick(o){			__CChat_GetObject(o).ClickTitle(o);		}
//function Chat_ShowTooltip(o){			__CChat_GetObject(o).ShowTooltip(o);	}
//function Chat_HideTooltip(o){			__CChat_GetObject(o).HideTooltip(o);	}
		





























/*
//---------------------------------------------------------
//--- Chat_ClickReply
//---------------------------------------------------------
function Chat_ClickReply(o,itemID)
{
	var clientID = Chat_GetClientID(o);
	if (itemID==null)
	{
		var tbl = $get(clientID + "_tblReply1");
		tbl.style.display = "block";
	}
	else
	{
		Chat_Reply(o,"Add");
	}
}
*/
//---------------------------------------------------------
//--- Chat_DeleteMsg
//---------------------------------------------------------
function Chat_DeleteMsg(o)
{
	var clientID = Chat_GetClientID(o);
	var p=o;while(p.getAttribute("c_msgID")==null || p.getAttribute("c_msgID")=="")p=p.parentNode;
	var tbl=o;while(tbl.tagName!="TABLE")tbl=tbl.parentNode;
	var itemID = p.getAttribute("c_msgID");
	var bg = tbl.style.backgroundColor;
	tbl.style.backgroundColor = "#ffff99";
	if (confirm("Do you want to delete selected item?"))
	{
		return true;
	}
	tbl.style.backgroundColor = bg;
	return false;
}
//---------------------------------------------------------
//--- Chat_ClickEdit
//---------------------------------------------------------
function Chat_ClickEdit(o)
{
	Chat_Reply(o,"Edit");
}
/*
//---------------------------------------------------------
//--- Chat_DiscardReply
//---------------------------------------------------------
function Chat_DiscardReply(o)
{
	try
	{
		var clientID = Chat_GetClientID(o);
//alert();
		var ed = $get( $get(clientID+"_hidEditorClientID").value );
		ed.setHTML("");
//alert(ed==null);
		var tbl = $get(clientID + "_tblReply1");
		tbl.style.display = "none";
	}
	catch(e){}
	return false;
}
*/
//---------------------------------------------------------
//--- Chat_DiscardReplyMsg
//---------------------------------------------------------
function Chat_DiscardReplyMsg(o)
{
	try
	{
		var clientID = Chat_GetClientID(o);
		var tbl = $get(clientID + "_divReply");
		/*
var txt = $get(clientID + "_txtReply");
alert(txt.value.indexOf("\n") + "     " + txt.value.indexOf("\r"));
	txt = g_global.Replace(txt,"\n","<br>");
	// txt.replace("\n","<br>");
alert(txt);
alert(txt.value.indexOf("\n") + "     " + txt.value.indexOf("\r"));
*/

		tbl.style.display = "none";
	}
	catch(e){}
	return false;
}

//---------------------------------------------------------
//--- Chat_GetPanel
//---------------------------------------------------------
function Chat_GetPanel(o,token)
{
	try{var p=o;while(p.getAttribute("c_token")!=token)p=p.parentNode;return p;}catch(e){return null;}
}
//--------------------------------------------------
function ________________________Chat_ContextMenuSelected(cmd)
{
	var o			= clickedTag;
	var pan			= Chat_GetPanel(o,"ListPanel");
	var clientID	= pan.getAttribute("c_clientID");
	var appPath		= "/";
	var hidID		= $get(clientID+"_hidID");
	var hidCmd		= $get(clientID+"_hidCommand");
	var hidValue	= $get(clientID+"_hidValue");
	var lb			= $get(clientID+"_lbCommand");
	var doCmd		= false;
	var tr			= o;

	hidCmd.value	= cmd;
	try
	{
		tr = Chat_GetPanel(o,"Row");
		//while(tr.getAttribute("c_token")==null || tr.getAttribute("c_token").indexOf("Row")==-1)tr=tr.parentNode;
		hidID.value = tr.getAttribute("c_ItemID");
	}
	catch(e){}

	if(cmd=="Topic.Edit"		|| cmd=="Topic.View")
	{
		doCmd = true;
	}
	else if(cmd=="Topic.Delete")
	{	
		var arr = tr.cells;
		for(var j=0; j<arr.length; j++){arr[j].style.backgroundColor = "gold"};
		if (confirm("Do you want to delete selected topic?"))
		{
			doCmd = true;
		}
		for(var j=0; j<arr.length; j++)arr[j].style.backgroundColor = "";
	}
	else if (cmd=="Group.SetPerm")
	{
		var date = new Date();
		var fn = "/Panels/SetPermissions/SetPermissions.aspx";
		var url = fn + "?itemID="+tr.c_ItemID + "&moduleID="+tr.c_ModuleID+"&isFolder="+tr.c_IsFolder+"&time="+date.getTime();
		var args = new Function();

		tr.style.backgroundColor = "yellow";
		if (window.showModalDialog(url, args, 'dialogWidth:500px; dialogHeight:550px; center:yes; edge:raised; scroll:no; status:no;'))
		{
			hidValue.value = args.xPerms.xml;
			doCmd = true;
		}
		tr.style.backgroundColor = "";
	}

	if (doCmd)
		//try{lb.click();}catch(e){	alert(e.message);	}
		try{lb.click();}catch(e){	try{eval(unescape(lb.href));}catch(e){alert(e.message);}	}
}

function Chat_Click(o,scope)
{
	if (scope=="T")	//...click topic Title
	{
		var tr			= Chat_GetPanel(o,"Row");
		var itemID		= tr.getAttribute("c_ItemID");
		var pan			= Chat_GetPanel(o,"ListPanel");
		var clientID	= pan.getAttribute("c_clientID");
		
		var hidID		= $get(clientID+"_hidID");
		var hidCmd		= $get(clientID+"_hidCommand");
		//var hidValue	= $get(clientID+"_hidValue");
		var lb			= $get(clientID+"_lbCommand");

		hidCmd.value	= "Topic.View";
		hidID.value		= itemID;
		//eval(lb.href);
		try{lb.click();}catch(e){	try{eval(unescape(lb.href));}catch(e){alert(e.message);}	}
//alert(itemID);
	}
}
//---------------------------------------------------------
//--- Chat_MyProfile
//---------------------------------------------------------
function Chat_MyProfile(o) //,siteID,controlID)
{
	//var pan			= Forum_GetPanel(o,"MainPanel");
	//Chat_GetClientID(o)
	var url			= "/Panels/Chat/MyProfile/default.htm";
//	var args = new Function();
//	args.ID		= controlID;
//	args.SiteID	= siteID;
	if (window.showModalDialog(url, null, 'dialogWidth:700px; dialogHeight:550px; center:yes; edge:raised; scroll:no; status:yes;'))
	{
		return true;
	}
	return false;
}
//---------------------------------------------------------
//--- Chat_NewTopic
//---------------------------------------------------------
function Chat_NewTopic(clientID)
{
	Chat_PostCommand(clientID, "NewTopic");
//	$get(clientID+'_hidCommand').value	= "NewTopic";
//	eval(unescape($get(clientID+'_lbCommand').href));
}
//---------------------------------------------------------
//--- Chat_SetToolbarView
//---------------------------------------------------------
function Chat_SetToolbarView(clientID,itemID)
{
	var arg = new Function();
	arg._Scope = "ChatInstance";
	arg._ItemID = itemID;
	var url = "/Panels/Editor/ToolbarView/default.htm?sessid=" + $get(clientID+'_hidSessionID').value;
	if (window.showModalDialog(url, arg, 'dialogWidth:780px; dialogHeight:580px; center:yes; edge:raised; scroll:no; status:yes;'))
	{
		//$get(clientID+'_hidCommand').value	= "SetToolbarViews";
		$get(clientID+'_hidValue').value	= arg.toolbar;
		//$get(clientID+'_lbCommand').click();
		Chat_PostCommand(clientID, "SetToolbarViews");
	}
}
//---------------------------------------------------------
//--- Chat_StandardReport
//---------------------------------------------------------
function Chat_StandardReport(clientID,instanceID,uniqueToken) //itemID)
{
	var ww = window.screen.availWidth - 200; if(ww>900)ww=900;
	var hh = window.screen.availHeight - 200;

	var url = "/Panels/Chat/StandardReport/default.aspx?sessid=" + $get(clientID+'_hidSessionID').value +
				"&instanceID=" + instanceID +
				"&uniqueToken=" + uniqueToken;
	window.open(url, "_blank", "width="+ww+"px,height="+hh+"px,location=no,menubar=yes,toolbar=yes,resizable=yes,scrollbars=yes");
}
//---------------------------------------------------------
//--- Chat_SetRounds
//---------------------------------------------------------
function Chat_SetRounds(clientID,instanceID)
{
//alert(instanceID);
	var ids = $get(clientID+"_hidTopicIDs").value;
//alert(ids);
	var url = "/Panels/CHAT/SetRounds/default.aspx?clientID=" + clientID +
		"&instanceID=" + instanceID +
		"&sessid=" + g_global.sessionID + 
		"&tids=" + ids + 
		"&time=" + (new Date()).getTime();
	g_global.OpenAJAXModalWindow(clientID,url,"Set Rounds",700,550);
}
//----------------------------------------------
//--- Modal window commands
//----------------------------------------------
function Chat_Modal_Close(clientID)
{
	g_global.FireMouseEvent( $get(clientID+"_butCancelModal2"), "click");
	var fr  = $get(clientID+"_ifrModal1");
	fr.src = "about:blank";
}
function Chat_Modal_RoundsChanged(clientID)
{
	Chat_Modal_Close(clientID);
	var prm = Sys.WebForms.PageRequestManager.getInstance();
	prm._doPostBack(clientID+"_upTopics", '');
}


//----------------------------------------------
//--- Chat_ShowRoundMesages
//----------------------------------------------
function Chat_ShowRoundMesages(o,num)
{
	var clientID = Chat_GetClientID(o);
//	$get(clientID+'_hidCommand').value	= "ShowRoundMessages";
	$get(clientID+'_hidCurRound').value	= num;
//	eval(unescape($get(clientID+'_lbCommand').href));
	Chat_PostCommand(clientID, "ShowRoundMessages");
}


function Chat_MinHeight(o)
{
	var clientID = Chat_GetClientID(o);
	var p = $get(clientID+"_trMinHeight");
	p.style.display = o.checked ? "block" : "none";
}
function Chat_LimitLength(o)
{
	var clientID = Chat_GetClientID(o);
	var p = $get(clientID+"_trMaxLength");
	p.style.display = o.checked ? "block" : "none";
}





function Chat_VisRule_Click(o)
{
	var clientID = Chat_GetClientID(o);
	var p = $get(clientID+"_tblRulesCohort");
	p.style.display = o.getAttribute("value")=="cohort" ? "block" : "none";
	
//	var item = document.createElement("DIV");	divXml.appendChild(item);
//	item.setAttribute("c_name", "[No name]");
//	Chat_VisRules_Refresh(clientID);

}
function Chat_VisRules_SelectSurveys(o)
{
	var clientID = Chat_GetClientID(o);
	var args = new Function();
	args.selectedItemIDs = $get(clientID+'_hidVRCohort_SurveyIDs').value;
	var url = "/Panels/SelectSurveys/default.htm?sessid=" + $get(clientID+'_hidSessionID').value;
	if (window.showModalDialog(url, args, "dialogWidth:770px; dialogHeight:600px; center:yes; edge:raised; resizable:yes; scroll:yes; status:yes;"))
	{
//alert(args.selectedItemIDs);
		//$get(clientID+'_hidCommand').value	= "VisRules_SelectSurveys";
		$get(clientID+'_hidVRCohort_SurveyIDs').value	= args.selectedItemIDs;
		//$get(clientID+'_lbCommand').click();
		Chat_PostCommand(clientID, "VisRules_SelectSurveys");
	}
}
function Chat_VisRuleVCR_Click(o)
{
	var clientID = Chat_GetClientID(o);
	var val = o.getAttribute("value");
	var p = $get(clientID+"_trVCRDiff");
	p.style.display = val=="different" ? "block" : "none";
	
	Chat_RefreshVCRDiff(clientID);
	
//	var item = document.createElement("DIV");	divXml.appendChild(item);
//	item.setAttribute("c_name", "[No name]");
//	Chat_VisRules_Refresh(clientID);

}
function Chat_RefreshVCRDiff(clientID)
{
	var divXml = $get(clientID+"_divVCRXml");
	var hidXml = $get(clientID+"_hidVCRXml");
	var tbl = $get(clientID+"_tblVCRDiff");
	var tr,td,sel,opt,ss1,ss2,ss3,img;
//alert(divXml.outerHTML + "            " + hidXml.value);
	ss1 = tbl.rows[0].cells[0].innerHTML;
	ss2 = tbl.rows[0].cells[1].innerHTML;
	ss3 = tbl.rows[0].cells[2].innerHTML;
	while(tbl.rows.length>0){ tbl.deleteRow(tbl.rows[1]); }
	tr = g_global.InsertRow(tbl);
	tr.style.backgroundColor = "#dcdcdc";
	td = g_global.InsertCell(tr);	td.innerHTML = ss1;
	td = g_global.InsertCell(tr);	td.innerHTML = ss2;
	td = g_global.InsertCell(tr);	td.innerHTML = ss3;

	var arr = divXml.childNodes;
	var even=true;
	for (var j=0; j<arr.length; j++)
	{
		var item = arr[j];
		var cohortID	= item.getAttribute("c_cohortID");
		var cohortName	= item.getAttribute("c_cohortName");
		var surveyName	= item.getAttribute("c_surveyName");
		var access	= item.getAttribute("c_access");
		tr = g_global.InsertRow(tbl);
		tr.style.backgroundColor = even ? "#ffffff" : "#f5f5f5";
		td = g_global.InsertCell(tr);
		//td.appendChild( document.createTextNode(cohortName) );
		td.innerHTML = cohortName + "<BR><span style='font-size:8px; color:#888888'>SURVEY: " + surveyName + "</span>";
		
		sel = document.createElement("SELECT");
		sel.style.fontSize = "9pt";
		sel.onchange = Chat_SelectChanged;
		Chat_AddOption(sel,	"View All Comments",		"ViewAll",		access);
		Chat_AddOption(sel,	"View Own Comments",		"ViewOwn",		access);
		Chat_AddOption(sel,	"View Same Cohort Comments","ViewSameCohort",access);
		Chat_AddOption(sel,	"No Access",				"NoAccess",		access);
		td = g_global.InsertCell(tr);
		td.appendChild( sel );
		
		img = document.createElement("IMG");
		img.style.width = 16;
		img.style.height = 16;
		img.src = "/images/16x16/del.gif";
		img.onclick = Chat_VCRClickDel;
		td = g_global.InsertCell(tr);
		td.appendChild( img );

		even=!even;
	}
	hidXml.value = divXml.innerHTML;
}
function Chat_AddOption(sel,txt,val, selVal)
{
	var opt = document.createElement("OPTION");
	opt.text = txt;
	opt.value = val;
	if (val.toUpperCase()==selVal.toUpperCase())
		opt.selected = true;
	sel.options.add(opt);
}
function Chat_SelectChanged(e)
{
	var ev = g_global.GetEvent(e);
	var o = ev.srcElement;
	//::::::::::::::::::::::::::::: 
	var tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	var clientID = Chat_GetClientID(o);
	var divXml = $get(clientID+"_divVCRXml");
	var hidXml = $get(clientID+"_hidVCRXml");
	var item = divXml.childNodes[tr.rowIndex-1];
	item.setAttribute("c_access", o.value);
	hidXml.value = divXml.innerHTML;
//alert(divXml.outerHTML);
}
function Chat_VCRClickDel(e)
{
	var ev = g_global.GetEvent(e);
	var o = ev.srcElement;
	//::::::::::::::::::::::::::::: 
	var tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	var bg = tr.style.backgroundColor;
	tr.style.backgroundColor = "yellow";
	if (confirm("Do you want to remove selected cohort?"))
	{
		var clientID = Chat_GetClientID(o);
		var divXml = $get(clientID+"_divVCRXml");
		var item = divXml.childNodes[tr.rowIndex-1];
		divXml.removeChild(item);
		Chat_RefreshVCRDiff(clientID);
	}
	else
	{
		tr.style.backgroundColor = bg;
	}
}
function Chat_VisRules_SelectCohort(o)
{
	var clientID = Chat_GetClientID(o);
	var divXml = $get(clientID+"_divVCRXml");
	var hidXml = $get(clientID+"_hidVCRXml");
//	var surveyID	= divXml.getAttribute("c_surveyID");
//	var surveyName	= divXml.getAttribute("c_surveyName");
//if (surveyID==null || surveyID=="") 
//surveyID=351;

	var args = new Function();
	args.sessid = $get(clientID+'_hidSessionID').value;
//	args.SurveyID = 351;//$get(clientID+'_hidVRCohort_SurveyIDs').value;
	var url = "/Panels/SelectCohorts/default.htm";//?sessid=" + $get(clientID+'_hidSessionID').value;
	if (window.showModalDialog(url, args, "dialogWidth:770px; dialogHeight:600px; center:yes; edge:raised; resizable:yes; scroll:yes; status:yes;"))
	{
		var divTemp = $get(clientID+"_divTemp");
		divTemp.innerHTML = args.xmlStr;
		var divRoot = divTemp.childNodes[0];
		var arr = divRoot.childNodes;
//alert(divRoot.outerHTML);
		for(var j=0; j<arr.length; j++)
		{
			var c = arr[j];
			var div = document.createElement("DIV");
			div.setAttribute("c_surveyID",		divRoot.getAttribute("c_surveyID") );
			div.setAttribute("c_surveyName",	divRoot.getAttribute("c_surveyName") );
			div.setAttribute("c_cohortID",		c.getAttribute("c_cohortID") );
			div.setAttribute("c_cohortName",	c.getAttribute("c_cohortName") );
			div.setAttribute("c_access", "ViewOwn");
			divXml.appendChild(div);
		}
//alert(args.ItemID);

		Chat_RefreshVCRDiff(clientID);
		
//		$get(clientID+'_hidCommand').value	= "VisRules_SelectSurveys";
//		$get(clientID+'_hidVRCohort_SurveyIDs').value	= args.selectedItemIDs;
//		$get(clientID+'_lbCommand').click();
	}
}



//---------------------------------------------------
//--- Chat_PMClick
//---------------------------------------------------
function Chat_VisRules_PMClick(e)
{
	var ev = g_global.GetEvent(e);
	var o = ev.srcElement;
	//::::::::::::::::::::::::::::: 
	var tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	var clientID = Chat_GetClientID(o);
	var divXml = $get(clientID+"_divRulesXml");
	var item = divXml.childNodes[tr.getAttribute("c_index")];
	var exp = item.getAttribute("c_exp");
	item.setAttribute("c_exp", exp=="y"?"n":"y");
	Chat_VisRules_Refresh(clientID);
}
function Chat_VisRules_Refresh(clientID)
{
	var divXml = $get(clientID+"_divRulesXml");
	var arr = divXml.childNodes;
	var pan = $get(clientID+"_divCohortRules");
	var lbl = $get(clientID+"_lInfo_NoCohortRules");
//alert(arr.length);//divXml.outerHTML);
	lbl.style.display	= arr.length >0 ? "none" : "block";
	pan.style.display	= arr.length==0 ? "none" : "block";
	
	if (arr.length==0) return;
	
	while(pan.childNodes.length > 0)pan.removeChild(pan.childNodes[0]);
	
	var tbl = document.createElement("TABLE");	pan.appendChild(tbl);
	var tr,td,txt,img;
	for(var j=0; j<arr.length; j++)
	{
		var item = arr[j];
//alert(j);
		tr = g_global.InsertRow(tbl);
		tr.setAttribute("c_index", j);

		td = g_global.InsertCell(tr);
		var exp = item.getAttribute("c_exp");
		img = document.createElement("IMG");	td.appendChild(img);
		img.style.width = "16";
		img.style.height = "16";
		img.src = "/images/16x16/" + (exp=="y" ? "minus.gif" : "plus.gif");
		img.onclick = Chat_VisRules_PMClick;
		img.style.cursor = "hand";

		
		td = g_global.InsertCell(tr);
		td.style.width = "100%";
		txt = document.createElement("INPUT");	td.appendChild(txt);
		txt.type			= "text";
		txt.style.width		= "400px";
		txt.style.border	= "solid 1px #0000aa";
		txt.style.backgroundImage = "url(/images/small-grid.gif)";
		txt.maxLength		= 100;
		txt.value			= item.getAttribute("c_name");;
//		txt.setAttribute("c_attr",attrName);
//		txt.onchange		= SurveyProps_TxtChanged2;
		
		if (exp=="y")
		{
			Chat_VisRules_Details(clientID,item,tbl,j);
		}
//alert(pan.outerHTML);
	}
//alert(pan.outerHTML);
}
function Chat_VisRules_Details(clientID,item,tbl,ind)
{
	var exp = item.getAttribute("c_exp");
	if (exp!="y")
		return;

	var tr = g_global.InsertRow(tbl);
	tr.setAttribute("c_index",ind);
	var td, img;
	var div2,tbl2,tr2,td2;
	//var type = item.getAttribute("c_type");

	td = g_global.InsertCell(tr);
	td.appendChild( document.createTextNode(" ") );
	
	td = g_global.InsertCell(tr);
	//td.colSpan = 3;

	tbl2 = document.createElement("TABLE");	td.appendChild(tbl2);
	tbl2.cellPadding = 2;
	tbl2.cellSpacing = 0;
	tr2 = g_global.InsertRow(tbl2);
	td2 = g_global.InsertCell(tr2);
	td2.appendChild( document.createTextNode("Time range:") );
	
}
function Chat_VisRules_CreateNew(o)
{
	var clientID = Chat_GetClientID(o);
	var divXml = $get(clientID+"_divRulesXml");
	var item = document.createElement("DIV");	divXml.appendChild(item);
	item.setAttribute("c_name", "[No name]");
	Chat_VisRules_Refresh(clientID);
}
function Chat_VisRules_AddRule(o)
{
	var clientID = Chat_GetClientID(o);
	var divXml = $get(client+"_divRulesXml");
}


function Chat_Register(clientID)
{
	var url = "/Panels/CHAT/Register.aspx?&sessid=" + g_global.sessionID + 
		"&tm=" + (new Date()).getTime();
	g_global.OpenAJAXModalWindow(clientID,url,"Register",600,520);
}
function Chat_Modal_Registered(clientID)
{
	g_global.CloseAJAXModalWindow();
	var prm = Sys.WebForms.PageRequestManager.getInstance();
	prm._doPostBack(clientID+"_upTopics", '');
}

function Chat_SignIn(clientID)
{
	var url = "/Panels/CHAT/SignIn.aspx?&sessid=" + g_global.sessionID + 
		"&tm=" + (new Date()).getTime();
	g_global.OpenAJAXModalWindow(clientID,url,"SignIn",400,400);
}



	/*
		$get(clientID + "_hidReplyMessageID").value = itemID;
		var p=o;while(p.getAttribute("c_msgID")==null || p.getAttribute("c_msgID")=="")p=p.parentNode;
		var panReply = $get(clientID + "_divReply");
		
		panReply.style.display = "block";
		p.appendChild(panReply);
		
		var txt = $get(clientID + "_txtReply");
		try{txt.focus(); }catch(e){}
		try{txt.select();}catch(e){}
		try{txt.click(); }catch(e){}
		*/

