function fnSelectAllTopics(chkObj,GridID)
{
	var igGrid = igtbl_getGridById(GridID);
	if(igGrid.Rows==null) return;
	var isChecked=chkObj.checked;
	var rCount;
	for(rCount=0;rCount<igGrid.Rows.length;rCount++)
	{
		var chBox =igGrid.Rows.getRow(rCount).getCellFromKey("chkAssign")
		var chBoxobj =igGrid.Rows.getRow(rCount).Element.childNodes[3];
		while(chBoxobj && chBoxobj.tagName.toUpperCase()!="INPUT")
			chBoxobj=chBoxobj.childNodes[0];
		if(chBoxobj.disabled==false && chBox!=null)
		{
			chBoxobj.checked=isChecked;
		}
	}
}
function fnSelectAllTopicsOfAThread(chkObj,GridID,forumid)
{
	var igGrid = igtbl_getGridById(GridID);
	if(igGrid.Rows==null) return;
	var isChecked=chkObj.checked;
	var trElement =chkObj.parentNode;
	while(trElement && trElement.tagName!="TR")
		trElement=trElement.parentNode;
	var ClickedRowIndex=trElement.rowIndex-1;
	var rCount;
	for(rCount=ClickedRowIndex+1;rCount<igGrid.Rows.length;rCount++)
	{
		if(parseInt(igGrid.Rows.getRow(rCount).getCellFromKey("ForumID").getValue())==parseInt(forumid))
		{
			var chBox =igGrid.Rows.getRow(rCount).getCellFromKey("chkAssign")
			var chBoxobj =igGrid.Rows.getRow(rCount).Element.childNodes[3];
			while(chBoxobj && chBoxobj.tagName.toUpperCase()!="INPUT")
				chBoxobj=chBoxobj.childNodes[0];
			if(chBox!=null)
			{
				chBoxobj.checked=isChecked;
			}
		}
	}
}
function fnHideORShowChildRows(imgObj,noChilds,igName,ClickedRowIndex)
{
	var igGrid=igtbl_getGridById(igName.id);
	if( igGrid==null)
		igGrid=igtbl_getGridById(igName);
	ClickedOUID=igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue();
	if(imgObj.src.indexOf('collapse.gif')>-1)
	{
		imgObj.src='Images/expand.gif';
		for(var rCount=ClickedRowIndex;rCount<igGrid.Rows.length;rCount++)
		{
		    if(igGrid.Rows.getRow(rCount).getCell(1).getValue()==igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue())
			{
				igGrid.Rows.getRow(rCount).setHidden(false);
				if(rCount+1==igGrid.Rows.length)return;
				if((rCount+1)<=igGrid.Rows.length && igGrid.Rows.getRow(rCount).getCell(0).getValue()==igGrid.Rows.getRow(rCount+1).getCell(1).getValue())
				{
					if(igGrid.Rows.getRow(rCount).getCellFromKey('ContentID').getValue()== null)
					{
						try{
						var imgObj=document.getElementById('imgPlusMinus_FT' + igGrid.Rows.getRow(rCount).getCell(0).getValue());
						imgObj.src='Images/collapse.gif';
						}catch(e){}
					}
				}					
			}
		}			
	}
	else
	{
		imgObj.src='Images/collapse.gif';
		var noIterations=((ClickedRowIndex+noChilds+1)>igGrid.Rows.length)?igGrid.Rows.length-1:(ClickedRowIndex+noChilds+1);
		if(noIterations>=igGrid.Rows.length)
		{
			noIterations=igGrid.Rows.length-1;
		}
		for(var rCount=ClickedRowIndex+1;rCount<=noIterations;rCount++)
		{
			if(igGrid.Rows.getRow(rCount).getCell(1).getValue()==igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue())
			{
				igGrid.Rows.getRow(rCount).setHidden(true);
				if(igGrid.Rows.getRow(rCount).getCellFromKey('ContentID').getValue()== null)
				{
					var imgObj1=document.getElementById('imgPlusMinus_FT' + igGrid.Rows.getRow(rCount).getCell(0).getValue());
					if(imgObj1!=null)
					{
						imgObj1.src='Images/expand.gif';
						imgObj1.click();
					}
				}
			}
		}
	}
}
function fnDeleteForum(forumID,hdnSelectedForumsClientID,deleteConfirmMsg)
{
	if(confirm(deleteConfirmMsg)==true)
	{
		document.getElementById(hdnSelectedForumsClientID).value=forumID;
		__doPostBack('deleteforum',document.getElementById(hdnSelectedForumsClientID).value);
	}
}
function fnDeleteTopic(contentID,hdnSelectedTopicsClientID,deleteConfirmMsg)
{
	if(confirm(deleteConfirmMsg)==true)
	{
		document.getElementById(hdnSelectedTopicsClientID).value=contentID;
		__doPostBack('deletetopic',document.getElementById(hdnSelectedTopicsClientID).value);
	}
}
function fnDelete(gridName,hdnSelectedTopicsClientID,hdnSelectedForumsClientID,deleteConfirmMsg,selectAtleastOneMsg)
{
	var hdnTopics = document.getElementById(hdnSelectedTopicsClientID);
	var hdnForms = document.getElementById(hdnSelectedForumsClientID);
	var CanProceed=fnGetSelectedValues(hdnTopics,hdnForms,gridName,selectAtleastOneMsg);
	hdnForms.value='';
	if(CanProceed ==true)
	{
		if(confirm(deleteConfirmMsg)==true)
		{
			__doPostBack('deletetopic',hdnTopics.value);
		}
	}
	return false;
}
function fnMove(gridName,hdnSelectedTopicsClientID,hdnSelectedForumsClientID,selectAtleastOneMsg,ObjectTypeID)
{
	var hdnTopics = document.getElementById(hdnSelectedTopicsClientID);
	var hdnForms = document.getElementById(hdnSelectedForumsClientID);
	var CanProceed=fnGetSelectedValues(hdnTopics,hdnForms,gridName,selectAtleastOneMsg);
	if(CanProceed ==true)
	{
		popupwindow=window.open("Modules/MoveDiscussion.aspx?ObjectIDList=" + hdnTopics.value +"&ObjectType="+ObjectTypeID,'MoveThreads','resizable=yes,scrollbars=yes,width=600,height=450');
		popupwindow.focus();
	}
	return false;
}
function fnMoveTopic(forumID,ObjectTypeID)
{
	popupwindow=window.open("Modules/MoveDiscussion.aspx?ObjectIDList=" + forumID +"&ObjectType="+ObjectTypeID,'MoveThreads','resizable=yes,scrollbars=yes,width=600,height=450');
	popupwindow.focus();
}
function fnGetSelectedValues(hdnTopics,hdnForms,gridName,selectAtleastOneMsg)
{
	var igGrid=igtbl_getGridById(gridName);
	var rCount;
	hdnTopics.value=''
	for(rCount=0;rCount<igGrid.Rows.length;rCount++)
	{
		var chBoxobj =igGrid.Rows.getRow(rCount).getCellFromKey("chkAssign").Element.childNodes[0];
		while(chBoxobj && chBoxobj.tagName.toUpperCase()!="INPUT")
			chBoxobj=chBoxobj.childNodes[0];
		if(chBoxobj.checked==true)
		{
			if(igGrid.Rows.getRow(rCount).getCellFromKey("ContentID").getValue()==null)
			{
				//if(hdnForms.value=='')hdnForms.value=igGrid.Rows.getRow(rCount).getCellFromKey("ForumID").getValue();
				//else 	hdnForms.value=hdnForms.value + ',' + igGrid.Rows.getRow(rCount).getCellFromKey("ForumID").getValue();
			}
			else
			{
				if(hdnTopics.value=='')hdnTopics.value=igGrid.Rows.getRow(rCount).getCellFromKey("ContentID").getValue();
				else 	hdnTopics.value=hdnTopics.value + ',' + igGrid.Rows.getRow(rCount).getCellFromKey("ContentID").getValue();
			}
		}
	}
	if( hdnTopics.value == '')
	{
		alert(selectAtleastOneMsg);
		return false;
	}
	return true;
}
function fnSaveObjectID(ObjectID,hdnClientID)
{
	document.getElementById(hdnClientID).value=ObjectID;
}
function fnCheckforSelect(hdnClientID,alertselectaforum)
{
	if(document.getElementById(hdnClientID).value=='')
	{
		alert(alertselectaforum);
		return false;
	}
	return true;
}
function fnEditForum(forumID)
{
	popupwindow=window.open("Modules/CreateEditTopic.aspx?ObjectID=" + forumID ,'CreateTopic','resizable=yes,scrollbars=no,width=700,height=250');
	popupwindow.focus();
	if(forumID==-1)
		return false;
}
function fnReply(ContentID,TopicID,Mode,Action,ComponentInstanceID)
{
	popupwindow=window.open("Modules/Reply.aspx?ObjectID=" + ContentID+"&TopicID="+ TopicID+"&Mode="+ Mode+"&action="+ Action+"&ComInstID="+ComponentInstanceID+"&showdisclaimer=false",'Reply','resizable=yes,scrollbars=no,width=800,height=480');
	popupwindow.focus();
}
function fnHideORShowChildForums(imgObj,noChilds,igName,ClickedRowIndex)
{
	var igGrid=igtbl_getGridById(igName.id);
	if( igGrid==null)
		igGrid=igtbl_getGridById(igName);
	ClickedOUID=igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue();
	if(imgObj.src.indexOf('collapse.gif')>-1)
	{
		imgObj.src='../Images/expand.gif';
		for(var rCount=ClickedRowIndex;rCount<igGrid.Rows.length;rCount++)
		{						
		    if(igGrid.Rows.getRow(rCount).getCell(1).getValue()==igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue())
			{
				igGrid.Rows.getRow(rCount).setHidden(false);
				if(rCount+1==igGrid.Rows.length)return;
				if((rCount+1)<=igGrid.Rows.length && igGrid.Rows.getRow(rCount).getCell(0).getValue()==igGrid.Rows.getRow(rCount+1).getCell(1).getValue())
				{
					try{
						var imgObj=document.getElementById('imgPlusMinus_F' + igGrid.Rows.getRow(rCount).getCell(0).getValue());
						imgObj.src='../Images/collapse.gif';
						}catch(e){}
				}
			}
		}
	}
	else
	{
		imgObj.src='../Images/collapse.gif';
		var noIterations=((ClickedRowIndex+noChilds+1)>igGrid.Rows.length)?igGrid.Rows.length-1:(ClickedRowIndex+noChilds+1);
		if(noIterations>=igGrid.Rows.length)
		{
			noIterations=igGrid.Rows.length-1;
		}
		for(var rCount=ClickedRowIndex+1;rCount<=noIterations;rCount++)
		{
			if(igGrid.Rows.getRow(rCount).getCell(1).getValue()==igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue())
			{
				igGrid.Rows.getRow(rCount).setHidden(true);
				var imgObj1=document.getElementById('imgPlusMinus_F' + igGrid.Rows.getRow(rCount).getCell(0).getValue());
				if(imgObj1!=null)
				{
					imgObj1.src='../Images/expand.gif';
					imgObj1.click();
				}
			}
		}
	}
}
function fnMultipleAssign(ObjectTypeID,gridName,hdnSelectedTopicsClientID,hdnSelectedForumsClientID,hdnNamesClientID,selectAtleastOneMsg)
{
	var hdnTopics = document.getElementById(hdnSelectedTopicsClientID);
	var hdnForms = document.getElementById(hdnSelectedForumsClientID);
	var CanProceed=fnGetSelectedValues(hdnTopics,hdnForms,gridName,selectAtleastOneMsg);
	if(CanProceed ==true)
	{
		var objectidlist=hdnTopics.value;
		hdnTopics.value="";
		document.getElementById(hdnNamesClientID).value=GetNamesOfSelectedItems();
		var objname='';
		popupwindow = window.open('Assign.aspx?ObjectID=' + objectidlist + '&ObjectTypeId=' + ObjectTypeID + '&ObjName=' + objname,'Assign','resizable=yes,scrollbars=no,width=600,height=450');
		popupwindow.focus();
	}
	return false;
}
function fnAssignTopic(ObjectID,ObjectTypeID,hdnNamesClientID,rowIndex,igName)
{
	var igGrid=igtbl_getGridById(igName.id);
	if( igGrid==null)
		igGrid=igtbl_getGridById(igName);
	document.getElementById(hdnNamesClientID).value=igGrid.Rows.getRow(rowIndex).getCellFromKey("Title").getValue();
	popupwindow = window.open('Assign.aspx?ObjectID=' + ObjectID + '&ObjectTypeId=' + ObjectTypeID ,'Assign','resizable=yes,scrollbars=no,width=600,height=450');
	popupwindow.focus();
}
function fnGetSelectedItemsNames(id)
{
	return document.getElementById(hdnNamesClientID).value;
}
function GetNamesOfSelectedItems()
{
	var igGrid=igtbl_getGridById(clientGridId);
	var rCount;
	var NameList='';
	for(rCount=0;rCount<igGrid.Rows.length;rCount++)
	{
		var chBoxobj =igGrid.Rows.getRow(rCount).getCellFromKey("chkAssign").Element.childNodes[0];
			while(chBoxobj && chBoxobj.tagName.toUpperCase()!="INPUT")
				chBoxobj=chBoxobj.childNodes[0];
		if(chBoxobj.checked==true)
		{
			if(igGrid.Rows.getRow(rCount).getCellFromKey("ContentID").getValue()!=null)
			{
				NameList=NameList + ',' + igGrid.Rows.getRow(rCount).getCellFromKey("Title").getValue();
			}
		}
	}
	if (NameList.substring(0,1)==",") NameList=NameList.substring(1);
	if (NameList.substring(NameList.length-1)==",") NameList=NameList.substring(0,strVal.length-1);
	return NameList;
}
function fnHierarchyGridHeaderClick(gridName, columnId, button){
	//Add code to handle your event here.
	var columnName=igtbl_getColumnById(columnId);
	if(columnName.HeaderClickAction==2 && columnName.Key != 'Actions' && columnName.Key != 'chkAssign' )
	{
		var columnIndicator=fnGetIndicator(columnName.SortIndicator);
		var keys='sortby,sorttype,page';
		var values=columnName.Key + ',' + columnIndicator + ',' + 1;
		var newUrl=fnGetNewURL(ComponentInstanceID,keys,values);
		document.forms[0].action=newUrl;
		document.forms[0].__VIEWSTATE.disabled=true;
		document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
		document.forms[0].submit();
	}
}
function fnOpenAuthoringEditor(url)
{
	popupwindow = window.open(url,'Editor','resizable=yes,scrollbars=yes,top=100,left=100,width=800,height=600');
	popupwindow.focus();
}
function fnPublishToCDP(ObjectTypeID,ContentID,UserID,FolderPath,ForumID,Action)
{
	document.forms[0].__VIEWSTATE.disabled=true;
	fnPublishToCDPContent(ObjectTypeID,ContentID,UserID,FolderPath,ForumID,Action,applPath,datasource);
}
function fnviewsubscriptions(ContentId)
{
	alert('This functionality is not implemented');
}
function fnAlertsOff(ContentId)
{
	alert('This functionality is not implemented');
}
function fnDeleteReply(TopicID,ID)
{
	if (confirm("Are you sure you want delete the reply?")==true)
	{
		__doPostBack('deletereply',TopicID + "~" + ID );
	}
}
/** Below function is commented by sharma since it is giving stack over flow error on Expand and collapse of the nodes in the tree and implemented a recursive function bellow that**/
/*
function fnHideORShowThreads_Sarma(imgObj,noChilds,igName,ClickedRowIndex)
{
	var igGrid=igtbl_getGridById(igName.id);
	if( igGrid==null)
		igGrid=igtbl_getGridById(igName);
	ClickedOUID=igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue();
	if(imgObj.nameProp=='collapse.gif')
	{
		imgObj.src='Images/expand.gif';	
		for(var rCount=ClickedRowIndex;rCount<igGrid.Rows.length;rCount++)
		{
    		if(igGrid.Rows.getRow(rCount).getCell(1).getValue()==igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue())
			{
				igGrid.Rows.getRow(rCount).setHidden(false);
				if(rCount+1==igGrid.Rows.length)return;
				if((rCount+1)<=igGrid.Rows.length && igGrid.Rows.getRow(rCount).getCell(0).getValue().toLowerCase()==igGrid.Rows.getRow(rCount+1).getCell(1).getValue().toLowerCase())
				{
					try{
					var imgObj=document.getElementById('imgPlusMinus_TH' + igGrid.Rows.getRow(rCount).getCell(0).getValue());
					imgObj.src='Images/collapse.gif';
					}catch(e){}
				}
			}
		}
	}
	else
	{
		imgObj.src='Images/collapse.gif';
		var noIterations=((ClickedRowIndex+noChilds+1)>igGrid.Rows.length)?igGrid.Rows.length-1:(ClickedRowIndex+noChilds+1);
		if(noIterations>=igGrid.Rows.length)
		{
			noIterations=igGrid.Rows.length-1;
		}
		for(var rCount=ClickedRowIndex+1;rCount<=noIterations;rCount++)
		{
			if(igGrid.Rows.getRow(rCount).getCell(1).getValue().toLowerCase()==igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue().toLowerCase())
			{
				igGrid.Rows.getRow(rCount).setHidden(true);
				var imgObj1=document.getElementById('imgPlusMinus_TH' + igGrid.Rows.getRow(rCount).getCell(0).getValue());
				if(imgObj1!=null)
				{
					imgObj1.src='Images/expand.gif';
					imgObj1.click();
				}
			}
		}
	}
}
*/
/**** Below two functions are written by sharma to resove the issue 13853****/
function fnHideORShowThreads(imgObj,noChilds,igName,ClickedRowIndex)
{
	var igGrid=igtbl_getGridById(igName.id);
	if( igGrid==null)
		igGrid=igtbl_getGridById(igName);
	if(imgObj.src.indexOf('collapse.gif')>-1)
		imgObj.src='Images/expand.gif';
	else
		imgObj.src='Images/collapse.gif';
	var ThreadID=igGrid.Rows.getRow(ClickedRowIndex).getCell(0).getValue();
	var ParentID=igGrid.Rows.getRow(ClickedRowIndex).getCell(1).getValue();
	for(var rCount=ClickedRowIndex;rCount<igGrid.Rows.length;rCount++)
	{
		if(igGrid.Rows.getRow(rCount).getCell(1).getValue()==ThreadID)
		{
			if(imgObj.src.indexOf('collapse.gif')>-1)
			{
				var ExpCollObj=document.getElementById('imgPlusMinus_TH' + igGrid.Rows.getRow(rCount).getCell(0).getValue());
				var flag;
				if(ExpCollObj)
					flag=1;
				else
				{
					flag=2;
					var ExpCollObj=document.getElementById('imgPlusMinus_TH' + igGrid.Rows.getRow(rCount).getCell(1).getValue());
				}
				if(ExpCollObj)
				{
					ExpCollObj.src='images/collapse.gif';
					igGrid.Rows.getRow(rCount).setHidden(true);
					if(flag=1)
						ShowHideThreadHirarchy(false,igGrid.Rows.getRow(rCount).getCell(0).getValue(),rCount,igName);
					else
						ShowHideThreadHirarchy(false,igGrid.Rows.getRow(rCount).getCell(1).getValue(),rCount,igName);
				}
			}
			else
				igGrid.Rows.getRow(rCount).setHidden(false);
		}
	}
}
function ShowHideThreadHirarchy(CanShow,ParentID,Index,igName)
{
	var igGrid=igtbl_getGridById(igName.id);
	if( igGrid==null)
		igGrid=igtbl_getGridById(igName);
	for(i=Index+1;i<igGrid.Rows.length;i++)
	{
		if(igGrid.Rows.getRow(i).getCell(1).getValue()==ParentID)
		{
			if(CanShow)
			{
				igGrid.Rows.getRow(i).setHidden(false);
			}
			else
			{
				igGrid.Rows.getRow(i).setHidden(true);
				var ExpCollObj=document.getElementById('imgPlusMinus_TH' + igGrid.Rows.getRow(i).getCell(0).getValue());
				if(ExpCollObj)
					ExpCollObj.src='Images/collapse.gif';
			}
			ThreadsStack[Idx]=i; /*ThreadsStack is an array which is declare in CodeBehind of Discussion.ascx.vb file and Idx is a javascript variable which is declared in Discussion.ascx.vb file */
			Idx++;
			ShowHideThreadHirarchy(CanShow,igGrid.Rows.getRow(i).getCell(0).getValue(),i,igName);
			Idx--;
			i=ThreadsStack[Idx];
		}
	}
}