<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title></title>
	<script type="text/javascript">
		var strTheme;
		
		if(opener){
			if(opener.opener){
				if(opener.opener.m_strTheme){
					strTheme = opener.opener.m_strTheme;
				}
			}
		}
		
		if(!strTheme){
			strTheme = "../../theme/css/CensusMain.css";
		}
		
		document.write("<link rel='stylesheet' title='Silver' type='text/css' href='" + strTheme + "' />");
		
	</script>
	<!--MqRelPath--><script type="text/javascript" src="/connect/js/mqsysutils.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqsysutils.js"></script></MqAbsPath-->
	<script type="text/javascript" src="/connect/js/VNHTMLDocInit.js"></script>
	<!--MqRelPath--><script type="text/javascript" src="/connect/js/mqlist.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqlist.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="/connect/js/mqformelements.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqformelements.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="/connect/js/cmqstring.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqstring.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="/connect/js/cmqsysmsg.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqsysmsg.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="/connect/js/cmqlookupitemint.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqsysmsg.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="/connect/js/window.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/window.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../js/constants.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/window.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="/connect/js/CMqRelIssueUIMgr.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/CMqRelIssueUIMgr.js"></script></MqAbsPath-->
	
	
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css">
	
	<script type="text/javascript">
			var objSysMsg = new CMqSysMsg;	
			var m_objMqButton=new MqButton();
			var m_objRef=opener;
			var m_MblBool = g_MqRef.MqBrowser.mobile;
			
			if(!m_objRef){
				m_objRef=parent;
			}
			
		    var m_MqList=new MqList();
			var MSG_MUST_SELECT_ISSUE=g_MqRef.RESX["MSG_MUST_SELECT_ISSUE"];
			var MSG_MUST_ENTER_ISSUE_NUMBER=g_MqRef.RESX["MSG_MUST_ENTER_ISSUE"];
			var MSG_ISSUE_NUMBER_MUST_BE_NUMERIC=g_MqRef.RESX["MSG_MUST_ENTER_NUMERIC_ID"];
			var MSG_EMAIL_LINKED_TO_ISSUE_X = g_MqRef.RESX["MSG_EMAIL_LINKED_TO_ISSUE_X"];
			var MSG_EMAIL_NOT_LINKED_TO_ISSUE_X = g_MqRef.RESX["MSG_EMAIL_NOT_LINKED_TO_ISSUE_X"];
			var NO_EMAIL_SELECTED = 0;
			
			var objRequest;
			var mstrCurrentLocation;
			var m_lngSelectedIssue=0;
			var m_lngCurrentPage=0;
			var objString = new CMqString();
			var m_lngEmailID="<WC@EMAIL_ID></WC@EMAIL_ID>";
			var m_lngIssueID="<WC@CURRENT_ISSUE_ID></WC@CURRENT_ISSUE_ID>";
			var m_strFieldID = g_MqRef.MqStr.GetQueryStringValue(location.search,"FldID");
			var m_lngMode = g_MqRef.MqStr.GetQueryStringValue(location.search,"Mode");
			var m_objFormElement=new CMqFormElement();
			var mstrPathPrefix="../../";
			var m_objLookupItemInfo=new CMqLookupItemInfo();
			m_objLookupItemInfo.MultiSelect=false;
			var m_lngProjID=m_objRef.m_lngProjID;

			var objRelIssue;
		    var m_oRelRecS;
			
			if(m_objRef.g_objRelIssueCol)
			{
				objRelIssue=m_objRef.g_objRelIssueCol.Item(m_strFieldID, m_lngProjID);
			
			}
			// objRelIssuecan be null if LINK_TO_ISSUE
			m_oRelRecS=new MqRelRecSearch(document,objRelIssue);

			if(!m_lngMode){
				m_lngMode =m_oRelRecS.MODE_LINK_TO_ISSUE;
				
			}
			
			if(m_lngMode == m_oRelRecS.MODE_ADD_CHILD_ISSUE){
				document.title = g_MqRef.RESX["CHILD.ADD_CHILD_REC"];
			}else{			
				if(m_lngMode == m_oRelRecS.MODE_ADD_REL_ISSUE){
					document.title = g_MqRef.RESX["RELREC.ADD_RELATED_REC"];
				}else{
					document.title=g_MqRef.RESX["EML.LINK_TO_RECORD"];
				}
			}
			
			if(m_objRef){
				objRequest = m_objRef.objRequest;
				mstrCurrentLocation = m_objRef.mstrCurrentLocation;
				
				if(!objRequest){
					objRequest = m_objRef.m_objRequest;
				}
				if(!mstrCurrentLocation){
					mstrCurrentLocation = m_objRef.m_strCurrentLocation;
				}
			}
			
		function DisableControls()
		{
			var objRadioBtn2 = document.getElementById("radIssues02");
			var objRadioBtn1 = document.getElementById("radIssues01");
			var objTxtBox = document.getElementById("txtIssueNum");
			var objIFrame = document.getElementById("ifrLinkToIssue");
			
			if(objRadioBtn1.checked)
			{
				objTxtBox.disabled = true;
				objIFrame.disabled = false;
				objIFrame.focus();
			}
			else
			{
				objTxtBox.disabled = false;
				objIFrame.disabled = true;
				objTxtBox.focus();
				
			}
		}
		
		function GetIFrameHTML()
		{
			var strHTML='<iframe  name="ifrLinkToIssue" id="ifrLinkToIssue"' +
						' border="0"' +
						' frameborder="0" marginheight="0" marginwidth="0" src="' + m_oRelRecS.GetGridSrc(<WC@VIEW_QUERY_ID></WC@VIEW_QUERY_ID>, m_lngMode) + '"></iframe>';
	
			
			return strHTML;
		}
		
		
		function Initialize()
		{

			var objRadioBtn1 = document.getElementById("radIssues01");
			var objIFrame = document.getElementById("ifrLinkToIssue");
			var objTxtBox = document.getElementById("txtIssueNum");
			var lngCurrentIssueID;
			objIFrame.focus();
			objTxtBox.disabled = true;
			objRadioBtn1.checked = true;
			if(m_objRef){
				if(m_objRef.opener){
					if(m_objRef.opener.objRecord){
						if(m_objRef.opener.objRecord.GetRecordId){
							lngCurrentIssueID = m_objRef.opener.objRecord.GetRecordId()
						}
					}
				}
			}
			
			if(!lngCurrentIssueID){
				lngCurrentIssueID = m_lngIssueID;
			}
			
			if(lngCurrentIssueID){
				if(lngCurrentIssueID>0){
					objTxtBox.value=lngCurrentIssueID;
				}
			}
			
			if(m_lngMode == m_oRelRecS.MODE_ADD_REL_ISSUE){
				document.getElementById("selItemTxt").innerHTML=g_MqRef.RESX["EML.SELECT_LINK_TO_RECORD"];
				document.getElementById("enterItemTxt").innerHTML=g_MqRef.RESX["EML.LINK_TO_RECORD"];
				document.getElementById("txtIssueNum").value="";
			}
			
			if (g_VWS)
			{
				if (g_VWS.DefaultSearchField)
				{
					if (g_VWS.DefaultSearchField.FieldID)
					{
						var objAddSQL=document.getElementById("AddSQL");
						if(objAddSQL){
							objAddSQL.style.visibility="visible";
						}
						
						var oFld=g_VWS.ViewFields().Field(g_VWS.DefaultSearchField.FieldID);
						if (oFld){
							var objAddSQLCaption=document.getElementById("AddSQLCaption");
							if(objAddSQLCaption){
								objAddSQLCaption.innerHTML=g_MqRef.MqStr.Format(g_MqRef.RESX["RELREC.ADDSQL_CAPTION"], oFld.GetCaption());
							}
						}
					}
				}
			}
		}

		
		
		function LinkChildIssueToParent()
		{
			var ID_CONTENT_RESULT = 0;
			var ID_CONTENT_MESSAGE = 1;
			var ID_CONTENT_CHILD_ISSUE_NUMBER = 2;
			
			var lngIssueNumber=GetIssueNumber();
			
			if(lngIssueNumber>0){
				if(objRequest){
					var co = objRequest.Get(mstrCurrentLocation + "../ASP/AddRelRec.asp?pid=" + m_lngIssueID + "&fid=" + m_strFieldID + "&cid=" + lngIssueNumber);
					if (co!=objRequest.CANCEL_PROCESS){
						
						var objResponse=objRequest.Response(co);
							
						if (objResponse){
							if (objResponse.HasErrors()){
								objResponse.ProcessErrors("",true,window);
							}else{
								var arrContent = co.split("*|*");

								if(arrContent.length >= 1){
									if(arrContent[ID_CONTENT_RESULT] == "1"){
										UpdateCallerCtrl(m_strFieldID, arrContent[ID_CONTENT_CHILD_ISSUE_NUMBER], arrContent[ID_CONTENT_MESSAGE]);
										CloseWindow();
									}else{
										if(arrContent[ID_CONTENT_MESSAGE]){
											alert(arrContent[ID_CONTENT_MESSAGE]);
										}
									}
								}
							}
						}
					}
				}
			}
		}

		function AddRelIssue()
		{
		
			var lngIssueNumber=GetIssueNumber();
			if(lngIssueNumber>0){
				if(m_objRef){
					if(m_objRef.objFrames){
						var winRecord=m_objRef.objFrames.GetFrameWindow(m_objRef.RECORD_FRAME_ID);
						if (winRecord){
							var objParentList=eval("winRecord.m_oRRLst" + m_strFieldID);
							if(objParentList){
								if(objRequest){
									var strSrc1=objRelIssue.GetSource1();
									var strSrc2=objRelIssue.GetSource2();
									var strLinkedIssueQS=objRelIssue.GetLinkedIssueQSParam();
									var strSourceIssueQS=objRelIssue.GetSourceIssueQSParam();
									var strTable=objRelIssue.GetRelTableName();
									var lngDSType=objRelIssue.GetRelTableDSType();
									var co = objRequest.Get(mstrCurrentLocation + "wcMailInt.ASP?WCI=wciAddRelIssue&" + strSourceIssueQS+ "=" + m_lngIssueID + "&" + 
																strLinkedIssueQS + "=" + lngIssueNumber + "&src1=" + strSrc1 + "&src2=" + strSrc2 +
																"&tbl=" + strTable + "&DSType=" + lngDSType);
									if (co!=objRequest.CANCEL_PROCESS){
										
										var objResponse=objRequest.Response(co);
							
										if (objResponse){
											if (objResponse.HasErrors()){
												objResponse.ProcessErrors("",true,window);
											}else{
												objParentList.Load(null,null,null,null,500);
												CloseWindow();
											}
										}
									}
								}
							}else{
								var objParentList=eval("winRecord.m_o1tMLst" + m_strFieldID);
								if(objParentList){
									objParentList.SetComboOrListValue(m_strFieldID, Array(lngIssueNumber), null, null, null);
									CloseWindow();
								}
							}
						}
					}
				}
			}
		}

		function UpdateCallerCtrl(strID, strChildRecordID, strWarningMsg)
		{	
			var objCtrl;
			var objRef=window.opener;
			
	      	if (objRef && strID){
				if (objRef.Record){
					objRef=objRef.Record;		
					eval("objCtrl=objRef.m_oRRLst" + strID);
						
					if (objCtrl){
							if (objCtrl.AddRVal){			
										objCtrl.AddRVal(strChildRecordID);
							}
					}
				}
				
				if(strWarningMsg){
					alert(strWarningMsg);
				}
			}			
		}
		
		function LinkToIssue()
		{
			if(m_lngMode == m_oRelRecS.MODE_LINK_TO_ISSUE){
				LinkEmailToIssue();
			}else{
				if(m_lngMode == m_oRelRecS.MODE_ADD_CHILD_ISSUE){
					LinkChildIssueToParent();
				}else{
					if(m_lngMode == m_oRelRecS.MODE_ADD_REL_ISSUE){
						AddRelIssue();
					}
				}
			}
		}
		
		function FieldIsFilled(strElementName, strRequiredMsg)
		{
			var objTxtCtrl;
			objTxtCtrl=document.getElementById(strElementName);
			
			if(objTxtCtrl){
				if(objTxtCtrl.value.length>0){
					return true;
				}else{
					if(strRequiredMsg.length>0){
						alert(strRequiredMsg);
						objTxtCtrl.focus();
					}
					return false;
				}	
			}
		}
		
		function GetIssueNumber()
		{
			var objRadioBtn1 = document.getElementById("radIssues01");
			var objRadioBtn2 = document.getElementById("radIssues02");
			var objIFrame = document.getElementById("ifrLinkToIssue");
			var lngIssueNumber;
			
			if(objRadioBtn1.checked)
			{
				if(m_lngSelectedIssue>0){
					lngIssueNumber=m_lngSelectedIssue;
				}else{
					alert(MSG_MUST_SELECT_ISSUE);
				}
			}
			else if(objRadioBtn2.checked)
			{
				var objTxtCtrl;
				objTxtCtrl=document.getElementById("txtIssueNum");
			
				if(objTxtCtrl){
					lngIssueNumber=objTxtCtrl.value;
					if(lngIssueNumber.length>0){
						if(isNaN(lngIssueNumber)){
							alert(MSG_ISSUE_NUMBER_MUST_BE_NUMERIC);
							lngIssueNumber=0;
						}
					}else{
						alert(MSG_MUST_ENTER_ISSUE_NUMBER);
						objTxtCtrl.focus();
						lngIssueNumber=0;
					}	
				}
			}
			
			return lngIssueNumber;
		}		
			
			
		
		function GetQueryResults(strParam)
		{
			var objFra=document.getElementById("ifrLinkToIssue");
			
			var objQueryList=document.getElementById("aQueryLst");
			
			var lngQueryID = m_objFormElement.GetValue(false, objQueryList, CTRL_TYPE_MQLIST);
			
			if(objFra){
				if(strParam != null){
					objFra.src=m_oRelRecS.GetGridSrc(lngQueryID, m_lngMode) + "&" + strParam;
				}else{
					objFra.src=m_oRelRecS.GetGridSrc(lngQueryID, m_lngMode);
				}
			}
		}
		
		function LinkEmailToIssue()
		{
			var lngIssueNumber=GetIssueNumber();
			if(lngIssueNumber>0){
				if(objRequest){
					var co = objRequest.Get(mstrCurrentLocation + "WCMailInt.ASP?WCI=wciDoLinkToIssue&EID=" + m_lngEmailID +
													"&IssueID=" + lngIssueNumber + "&CIssueID="+m_lngIssueID);
					if (co!=objRequest.CANCEL_PROCESS){
								
						var objResponse=objRequest.Response(co);
									
						if (objResponse){
							if (objResponse.HasErrors()){
								objResponse.ProcessErrors("",true,window);
								if(m_objRef){
									m_objRef.Refresh(true);
								}
							}else{
									if(co == "True"){
										objString.InitializeString(MSG_EMAIL_LINKED_TO_ISSUE_X);
										alert(objString.FormatStringVar(lngIssueNumber));
										if(m_objRef){
											m_objRef.SetSelectedEmailID(NO_EMAIL_SELECTED);
											m_objRef.Refresh(true);
										}
										window.close();
									}else{
										objString.InitializeString(MSG_EMAIL_NOT_LINKED_TO_ISSUE_X);
										alert(objString.FormatStringVar(lngIssueNumber));
									}
								}
							}
						}
					}
				}
			}
		
		function OnDblClickItem(strRowItemCaption, strRowItemID)
		{
		}
		function OnSortColumn(strSortDetails)
		{	
		}
		function OnSelectRow(strName,strID)
		{
			if(strID > 0){
				m_lngSelectedIssue=strID;
				var objRadioBtn1 = document.getElementById("radIssues01");
				objRadioBtn1.checked = true;
				DisableControls();
			}else{
				m_lngSelectedIssue=0;
			}
		}
		
		function MoveFirst()
		{
			GetQueryResults("Pos=FirstRecord");
		}

		function MoveLast()
		{
			GetQueryResults("Pos=LastRecord");
		}

		function MovePrev()
		{
			GetQueryResults("PN="+(Number(m_lngCurrentPage)-1));
		}

		function MoveNext()
		{
			GetQueryResults("PN="+(Number(m_lngCurrentPage)+1));
		}
		
		function OnListLoaded(lngCurrentPage, lngTotalRecord, lngPageCount)
		{
			SetPageCaption(lngCurrentPage, lngTotalRecord, lngPageCount);
			HandleButtonStates(lngCurrentPage, lngPageCount);
			m_lngCurrentPage=lngCurrentPage;
		}

		function SetPageCaption(lngCurrentPage, lngTotalRecord, lngPageCount)
		{
			var objPageCaption=document.getElementById("PageCaption");

			if (objPageCaption){
				var strPC=GetPageCaption(lngCurrentPage, lngTotalRecord, lngPageCount);
				objPageCaption.innerHTML=strPC;
				objPageCaption.title=strPC;
			}				
		}

		function GetPageCaption(lngCurrentPage, lngTotalRecord, lngPageCount){
			var strReturn;
			if (!lngCurrentPage && !lngTotalRecord){
				strReturn=g_MqRef.RESX["NO_ISSUE_IN_QUERY"];
			}else{	
				strReturn=g_MqRef.MqStr.FormatString( g_MqRef.RESX["DISPLAY_PAGE_NUMBERS"], lngCurrentPage+";"+lngPageCount+";"+lngTotalRecord+";",";"); 
			}
				
			return strReturn;
		}

		function HandleButtonStates(lngCurrentPage, lngPageCount)
		{
			if (lngCurrentPage==1 || lngCurrentPage==0){ 
				m_objMqButton.DisableButton("FirstPage");	
				m_objMqButton.DisableButton("PreviousPage");	
			}else{
				m_objMqButton.EnableButton("FirstPage");
				m_objMqButton.EnableButton("PreviousPage");
			}
			
			if (lngCurrentPage==lngPageCount) {
				m_objMqButton.DisableButton("LastPage");
				m_objMqButton.DisableButton("NextPage");
			}else{
				m_objMqButton.EnableButton("LastPage");
				m_objMqButton.EnableButton("NextPage");
			}
		}

		function ResetFind()
		{
		
		}
		</script>

</head>
<body class="MainBackgroundWizard" onload="Initialize();" >

<div class="StdDlgBox" >
	<input type="radio" name="radIssues" id="radIssues01" onclick="DisableControls()" style="display:none" />		
	<div id="selItemTxt" class="WizardTitle" >
	<script>document.write(g_MqRef.RESX["RELREC.CAPTION"]);</script>
	<a id="aQueryLst" onclick="MqActuator_OnClick(this);" class="actuator" href='#' mqonchange="GetQueryResults();"
	mqvalue='<WC@VIEW_QUERY_ID></WC@VIEW_QUERY_ID>' mqlist="QueryList">
	<WC@VIEW_QUERY_CAPTION></WC@VIEW_QUERY_CAPTION></a>
	
	<span id="AddSQL" style="visibility:hidden;">
		<span id="AddSQLCaption"></span>
		<input type="input" id="AddSearch" onkeypress="GetQueryResults();" onchange="GetQueryResults();" class="AdminTextBoxWidth" >
	</span>
	</div>

<div class="StdDlgBlock1-3">
	<script type="text/javascript">
	document.write(GetIFrameHTML());
	</script>
</div>

<div class="StdDlgBlock2-3" id="pagingCtrl" name="pagingCtrl">
		<table style="width:300px" cellpadding='0' cellspacing='0' border='0' align="center">
		<tr>
			<td align='center' width="30">
				<script type="text/javascript">m_objMqButton.WriteButtonHTML("FirstPage","MoveFirst();","MoveFirst",false,m_objMqButton.STATE_EN,g_MqRef.RESX['BUTTON_FIRST_PAGE'],"","","<i class=\"fa fa-angle-double-left fa-2x\"><\/i>");</script>
			</td>
			<td align='center' width="30">
				<script type="text/javascript">m_objMqButton.WriteButtonHTML("PreviousPage","MovePrev();","PageDown",false,m_objMqButton.STATE_EN,g_MqRef.RESX['BUTTON_PREVIOUS_PAGE'],"","","<i class=\"fa fa-angle-left fa-2x\"><\/i>");</script>
			</td>
			<td>
				<div class='PageNavigation' id='PageCaption' style="text-align:center;padding-left:10px; padding-right:10px; color:#666666 !important"></div>
			</td>
			<td align='center' width="30">
				<script type="text/javascript">m_objMqButton.WriteButtonHTML("NextPage","MoveNext();","PageUp",false,m_objMqButton.STATE_EN,g_MqRef.RESX['BUTTON_NEXT_PAGE'],"","","<i class=\"fa fa-angle-right fa-2x\"><\/i>");</script>
			</td>
			<td align='center' width="30">
				<script type="text/javascript">m_objMqButton.WriteButtonHTML("LastPage","MoveLast();","MoveLast",false,m_objMqButton.STATE_EN,g_MqRef.RESX['BUTTON_LAST_PAGE'],"","","<i class=\"fa fa-angle-double-right fa-2x\"><\/i>");</script>
			</td>
		</tr>
		</table>
</div>

<div class="StdDlgBlock3-3" >
	<input type="radio" name="radIssues" id="radIssues02" onclick="DisableControls()"  style="display:none"/> 
	<span id="enterItemTxt" style="display:none"><script>document.write(g_MqRef.RESX["EML.LINK_TO_RECORD"]);</script>:</span>
	<input type="text" name="txtIssueNum" id="txtIssueNum"  style="display:none"/>
</div>

</div>

<div class="StdDlgButtonBar" >
	<table cellpadding="2" cellspacing="2">
	<tr>
	<td  width="50%" align="right" >
	<script type="text/javascript">
	m_objMqButton.WriteTextButtonHTML("OK", g_MqRef.RESX["BUTTON_OK"], 'LinkToIssue()', "", 32, "", g_MqRef.RESX["BUTTON_OK"], 90);
	</script>	
	</td><td>
	<script type="text/javascript">
	m_objMqButton.WriteTextButtonHTML("Close", g_MqRef.RESX["BUTTON_CLOSE"], 'CloseWindow()', "", 32, "", g_MqRef.RESX["BUTTON_CLOSE"], 90);
	</script>
	</td>
	</tr>
	</table>
</div>

		   <select id="QueryList" class="mqselect" style="font-size:15px"size="3"  
	            onmouseover="m_blnOverMenu=true;" onmouseout="m_blnOverMenu=false;"
	            onclick="m_MqList.OnClick(this)" onkeypress="m_MqList.OnKeyPress(event,this)" 
	            onblur="m_MqList.OnBlur();">
					<WC@QUERY_LIST></WC@QUERY_LIST>
	        </select>
</BODY>
</HTML>