function CMqRelIssueUIMgr(objRecordDoc, strTabID)
{	var m_lngCount=0;
	var m_objRecordDoc=objRecordDoc;
	var m_strTabID=strTabID;
	var m_lngVisibleField=0;
	
	function Add(lngFieldID, strFieldCaption, objRelIssue)
	{
		m_lngCount++;
		var objBtn=m_objRecordDoc.getElementById("btnRel" + m_strTabID + "_" + m_lngCount);
		
		if(objBtn){
			objBtn.style.display="";
			objBtn.innerHTML=GetButtonHTML("objRelIssueUIMgr" + strTabID + ".ShowSection(" + lngFieldID + ", true);", lngFieldID, strFieldCaption, "Show " + strFieldCaption, objRelIssue);
	
			if(m_lngVisibleField==0){
				ShowSection(lngFieldID, true);
			}else{
				ShowSection(lngFieldID, false);
			}
		}
	}
	
	function ShowSection(lngFieldID, blnVisible)
	{
		if(lngFieldID!=m_lngVisibleField){
			if(m_objRecordDoc){
				var objCaption=m_objRecordDoc.getElementById("MqFCR_" + lngFieldID);
				
				if(objCaption){
					if(blnVisible){
						objCaption.style.display="";

						var objCaptionOld=m_objRecordDoc.getElementById("MqFCR_" + m_lngVisibleField);
						if(objCaptionOld){
							objCaptionOld.style.display="none";
						}
					}else{
						objCaption.style.display="none";
					}
					
					var objCtrl=m_objRecordDoc.getElementById("MqFR_" + lngFieldID);
					if(objCtrl){
						if(blnVisible){
							objCtrl.style.display="";

							var objCtrlOld=m_objRecordDoc.getElementById("MqFR_" + m_lngVisibleField);
							if(objCtrlOld){
								objCtrlOld.style.display="none";
							}
						}else{
							objCtrl.style.display="none";
						}
					}
					
					var objBtn=m_objRecordDoc.getElementById("btnAction" + lngFieldID);
					
					if(objBtn && blnVisible){
						objBtn.className="TextButton TextButtonOver";
						var objBtnOld=m_objRecordDoc.getElementById("btnAction" + m_lngVisibleField);
						if(objBtnOld){
							objBtnOld.className="TextButton";
						}
					}
				}
				if(blnVisible){
					eval("parent.Record.m_oRRLst"+lngFieldID).Load();
					m_lngVisibleField=lngFieldID;
				}
			}
		}
	}
	
	function GetButtonHTML(strFunction, strID, strCaption, strTooltip, objRelIssue)
	{
		var strColor="";
		if(objRelIssue){
			strColor=objRelIssue.GetLinkedProjColor();
		}
		var strHTML='<div style="padding-right:15px; padding-bottom:10px"><div class="TextButton" style="width:150px;height:60px;cursor:hand;cursor:pointer;text-align:center" onclick="' + strFunction + '" id="btnAction' + strID + '">' +
				 '	<table height="100%" width="100%"><tr>' +
				 '	<td valign="middle" class="TextButton" id="lnkAction' + strID + '">' + strCaption + 
				 '  </td></tr><tr><td valign="bottom"><div style="background-color:' + strColor + ';height:10px;width:100%" /></td></tr></table>' +
				 '	</div></div>';
		return strHTML;
	}
	this.Add=Add;
	this.ShowSection=ShowSection;
}

// TODO: Consider changing tyo a more generic name 
// Move 
function MqRelRecSearch(oDoc, objRelIssue)
{			
	var m_oDoc=oDoc;
	var m_lngMode;
	var m_objRelIssue=objRelIssue;
	
	function GetGridSrc(lngQueryID,lngMode)
	{
		var sURL="";
		var sAddFilter="";
		m_lngMode=lngMode;
		
		if(m_lngMode == this.MODE_ADD_REL_ISSUE)
		{
			sURL="WCDisplayChoices.asp?WCI=DisplayChoices&TBL=tblDts&DS=" + m_objRelIssue.GetLinkedProjDS() + 
							"&CO=0&QueryID=0&Q_R1_F=0&Q_R1_V=*&Q_R2_F=&Q_R2_V=&Q_R3_F=&Q_R3_V=&S_R1_F=0&S_R1_O=ASC&SelID=2&MC=0&MqFID=" + 
							m_objRelIssue.FieldID;
		}else{			
		
			if (g_VWS.DefaultSearchField.FieldID && m_oDoc.getElementById("AddSearch").value)
			{
				sAddFilter= g_VWS.DefaultSearchField.FieldID + "|Contains|" + m_oDoc.getElementById("AddSearch").value + "|AND";
			}
			
			sURL="WCMailInt.ASP?WCI=wciGetQueryResults&QID=" + lngQueryID + "&ASQL=" + encodeURIComponent(sAddFilter);	
		}		
		
		return sURL;	
	}

	this.GetGridSrc=GetGridSrc;

	// TODO: improve the design of the modes
	this.MODE_LINK_TO_ISSUE = 1;
	this.MODE_ADD_CHILD_ISSUE = 2;
	this.MODE_ADD_REL_ISSUE = 3;

}