<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC >
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title translate="yes" data-res="EMLQUEUE.TITLE"></title>
	<script type="text/javascript">
		document.write("<link rel='stylesheet' type='text/css' href='" + opener.m_strTheme + "' />");
	</script>
	<script type="text/javascript" src="../../js/jquery/jquery-1.11.1.min.js"></script>	
	<!--MqRelPath--><script type="text/javascript" src="../../js/mqsysutils.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqsysutils.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/cmqstring.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqstring.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../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/tmplemaillistshared.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/tmplemaillistshared.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/cmqsysmsg.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqsysmsg.js"></script></MqAbsPath-->
		<script type="text/javascript">
			// always define this object for the system messages
			var objSysMsg = new CMqSysMsg;	
			var m_objMqButton=new MqButton();
			var objRequest = opener.objRequest;
			var mstrCurrentLocation = opener.mstrCurrentLocation;
			var m_lngSelectedEmailID;
			var m_lngIssueID = opener.objRecord.GetRecordId();
			var m_arrSelectedEmails = new Array();
			var m_lngSelectedEmailsIndex = 0;
			var m_lngCurrentPage = 1;
			var m_lngTotalPages = 1;
			var m_lngCurrentSortColID = 5;
			var m_strCurrentSortDirection = "D";
			var m_strSearchQuery = "";
			var m_lngMessageIDToFind;
			var objString = new CMqString();
			var m_objRef = opener;
			var BUTTON_WIDTH=130;

			// Load the localization file within the view
			g_MqRef.ResMgr.LoadViewRes("/" + m_objRef.parent.mstrCurrentVDName + "/" + m_objRef.parent.mstrCurrentViewFolder);
			
			var MSG_CONFIRM_DELETE_EMAIL =g_MqRef.RESX["EML.MSG_CONFIRM_DELETE"];
			var MSG_CONFIRM_DELETE_X_EMAILS = g_MqRef.RESX["EML.MSG_CONFIRM_DELETE_X_EMAILS"];
			var MSG_CONFIRM_CREATE_ISSUE = 	g_MqRef.RESX["EML.MSG_CONFIRM_CREATE_ISSUE"];
			var MSG_ISSUE_NUM_X_CREATED = g_MqRef.RESX["EML.MSG_ISSUE_NUM_X_CREATED"];
			
			var FRAME_PREVIEW_PANE = "fraPreviewPane";
			var FRAME_EMAIL_LIST = "fraEmails";
			var IFRAME_EMAIL_QUEUE = "ifrEmailQueue";
			var QS_AUTO_REFRESH = "ATO";
			var SORT_COL_ID = 1;
			var SORT_ORDER = 0;
			var NO_EMAIL_SELECTED = 0;
			var DELIM_SEMI_COLON = ";";
			
		
		function GetFrameHTML()
		{
			var strExtraCSS = "";
			var strHeight = "450px";
			if(g_MqRef.MqBrowser.nn){
				strExtraCSS = "";
				strHeight = "100%";
			}
			var strHTML='<iframe  name="ifrEmailQueue" id="ifrEmailQueue"' +
										' style="width:100%;height:' + strHeight + ";" + strExtraCSS +';border: #A9B4C4 1px solid;" ' +
										' frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="' + GetFrameSRC() + '"></iframe>';

			return strHTML;
		}
		
		function GetFrameSRC()
		{
			return "TmplEmailQueueFrame.htm";	
		}
		
		function GetEmailListIFrameSRC(strParam)
		{
			var strSelectedEmailID = GetSelectedEmailID();
			var strPagingQS = "";
			var strEmailQS = "";
			var arrParam;

			if(strParam == null){
				strParam = "";
			}
			
			//if we have an e-mail to auto-select...
			if(strSelectedEmailID != null && strSelectedEmailID > 0){
				//if the user is moving across(valid) pages, we obviously don't want to select an e-mail for them.
				if(strParam == "" || strParam == "PN=-1"){
					strEmailQS = "&EID=" + strSelectedEmailID;
				}
			//if we don't have an e-mail to select...
			}else{
				//if the page string is empty... we make them appear on the current page.
				if(strParam == ""){
					strParam = "PN=" + m_lngCurrentPage;
				}
			}
			
			if(strParam){
				if(strParam == "PN=-1"){
					strParam = "PN=1";
				}
				
				strPagingQS = "&" + strParam;
			}
			
			m_lngMessageIDToFind = strSelectedEmailID;
			
			return "WCMailInt.asp?WCI=wciGetMailQueue&SC=" + m_lngCurrentSortColID + "&SO=" + m_strCurrentSortDirection + strEmailQS + strPagingQS + "&QS=" +g_MqRef.MqStr.MqEncodeURIComponent(m_strSearchQuery);	
		}
		
		function LoadEmailInPreviewPane(blnAutoRefreshed)
		{
			var objPreviewPane = window.frames[IFRAME_EMAIL_QUEUE];
			var objPreviewPaneFrame;
			var strEmailID;

			if(objPreviewPane){
				if(objPreviewPane.window){
					if(objPreviewPane.window.frames[FRAME_PREVIEW_PANE]){
						objPreviewPaneFrame = objPreviewPane.window.frames[FRAME_PREVIEW_PANE];
					}
				}
				
				strEmailID = GetSelectedEmailID();
			
				if(strEmailID == null){
					strEmailID = 0;
				}
				
				if(objPreviewPaneFrame){
					if(objPreviewPaneFrame.m_lngEmailID != strEmailID){
						if(objPreviewPane.ChangeFrameSRC){
					
							objPreviewPane.ChangeFrameSRC(FRAME_PREVIEW_PANE,GetPreviewIFrameSRC(true, null, blnAutoRefreshed));
						}
					}
				}
			}
		}
		
		function PrintPreviewPane()
		{
			var objEmailQueueFrame = window.frames[IFRAME_EMAIL_QUEUE];
			if(objEmailQueueFrame){
				if(objEmailQueueFrame.PrintPreviewPane){
					objEmailQueueFrame.PrintPreviewPane();
				}
			}
		}

		function Refresh(blnPreserveCurrentPage, blnAutoRefreshed)
		{
			var strPageQS = "";
			var strAutoRefreshQSExtension = "";
			
			if(m_strSearchQuery == null){
				m_strSearchQuery = "";
			}
			
			var objIFrame = document.getElementById(IFRAME_EMAIL_QUEUE);
			var objEmailQueueFrame =window.frames[IFRAME_EMAIL_QUEUE];
			
			if(blnPreserveCurrentPage){
				strPageQS = "PN="+ (Number(m_lngCurrentPage));
			}
			
			if(blnAutoRefreshed){
				strAutoRefreshQSExtension = "&" + QS_AUTO_REFRESH + "=1";
			}
			
			RefreshEmailQueueFrame(GetEmailListIFrameSRC(strPageQS) + strAutoRefreshQSExtension);
			
		}
		
		function RefreshEmailQueueFrame(strNewSrc){
			if(strNewSrc != "" && strNewSrc != null){
				var objEmailQueueFrame =window.frames[IFRAME_EMAIL_QUEUE];
			
				if(objEmailQueueFrame){
					if(objEmailQueueFrame.ChangeFrameSRC){
						objEmailQueueFrame.ChangeFrameSRC(FRAME_EMAIL_LIST, strNewSrc);
					}
				}
			}
		}
		
		function MoveFirst()
		{
			RefreshEmailQueueFrame(GetEmailListIFrameSRC("Pos=FirstRecord"));
			m_lngCurrentPage = 1;
		}

		function MoveLast()
		{
			RefreshEmailQueueFrame(GetEmailListIFrameSRC("Pos=LastRecord"));
			m_lngCurrentPage = m_lngTotalPages;
		}

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

		function MoveNext()
		{
			RefreshEmailQueueFrame(GetEmailListIFrameSRC("PN="+(Number(m_lngCurrentPage)+1)));
			m_lngCurrentPage++;
		}
		
		function HandleButtonStates(lngCurrentPage, lngPageCount)
		{
			var lngEmailID = GetSelectedEmailID();

			if (lngCurrentPage==1){ 
				m_objMqButton.DisableButton("FirstPage");	
				m_objMqButton.DisableButton("PreviousPage");
			}else if(lngCurrentPage == -1){
				m_objMqButton.DisableButton("FirstPage");	
				m_objMqButton.DisableButton("NextPage");	
				m_objMqButton.DisableButton("PreviousPage");	
				m_objMqButton.DisableButton("LastPage");	
			}else{
				m_objMqButton.EnableButton("FirstPage");
				m_objMqButton.EnableButton("PreviousPage");
			}
			
			if (lngCurrentPage==m_lngTotalPages || m_lngTotalPages == 0) {
				m_objMqButton.DisableButton("LastPage");
				m_objMqButton.DisableButton("NextPage");	
			}else{
				m_objMqButton.EnableButton("LastPage");
				m_objMqButton.EnableButton("NextPage");
			}
		
			if(lngEmailID>0){
				m_objMqButton.EnableButton("LinkToIssue");
				m_objMqButton.EnableButton("Reply");
				m_objMqButton.EnableButton("CreateIssue");
				m_objMqButton.EnableButton("Forward");
				m_objMqButton.EnableButton("ReplyAll");
				m_objMqButton.EnableButton("Delete");
			}else{
				m_objMqButton.EnableButton("Refresh");
				m_objMqButton.EnableButton("ComposeNew");
				m_objMqButton.DisableButton("LinkToIssue");
				m_objMqButton.DisableButton("CreateIssue");
				m_objMqButton.DisableButton("Reply");
				m_objMqButton.DisableButton("Forward");
				m_objMqButton.DisableButton("ReplyAll");
				m_objMqButton.DisableButton("Delete");
			}
			
			if(m_arrSelectedEmails.length>1){
				m_objMqButton.DisableButton("CreateIssue");
				m_objMqButton.DisableButton("Reply");
				m_objMqButton.DisableButton("Forward");
				m_objMqButton.DisableButton("ReplyAll");
				m_objMqButton.EnableButton("Delete");
				m_objMqButton.DisableButton("LinkToIssue");
				m_objMqButton.EnableButton("Refresh");
			}else if(m_arrSelectedEmails.length == 0){
				m_objMqButton.EnableButton("Refresh");
				m_objMqButton.EnableButton("ComposeNew");
				m_objMqButton.DisableButton("LinkToIssue");
				m_objMqButton.DisableButton("CreateIssue");
				m_objMqButton.DisableButton("Reply");
				m_objMqButton.DisableButton("Forward");
				m_objMqButton.DisableButton("ReplyAll");
				m_objMqButton.DisableButton("Delete");
			}
		}
		
		function Initialize()
		{
			g_MqRef.ResMgr.ProcessAll(document);

			HandleButtonStates(m_lngCurrentPage, m_lngTotalPages);
			
			
		}
		
		function OnGridLoad()
		{
			m_arrSelectedEmails = new Array();
			var objEmailListFrame = window.frames[IFRAME_EMAIL_QUEUE].window.frames[FRAME_EMAIL_LIST];

			if(objEmailListFrame){
				if(m_lngMessageIDToFind != null && m_lngMessageIDToFind != 0){
					//can't use scroll into view, it can potentially hide the header
					if(objEmailListFrame.DoSelectRow){
						objEmailListFrame.DoSelectRow(0, true,m_lngMessageIDToFind, 0, true, false);

						var strAutoRefresh=g_MqRef.MqStr.GetQueryStringValue(objEmailListFrame.location.search,QS_AUTO_REFRESH);

						if(strAutoRefresh == "1"){
							var blnAutoRefresh = true;
						}
						
						LoadEmailInPreviewPane(blnAutoRefresh);
					}
				}else{
					if(objEmailListFrame.SelectRow){
						objEmailListFrame.SelectRow(0);
						LoadEmailInPreviewPane();
					}
				}
				
				HandleButtonStates(m_lngCurrentPage, m_lngTotalPages);
			}
		}
		
		function OnGridResize()
		{
				var objEmailListFrame = window.frames[IFRAME_EMAIL_QUEUE].window.frames[FRAME_EMAIL_LIST];
				var strResizeBarPixels;
				
				if(objEmailListFrame){
				
					if (document.all){
					    if (objEmailListFrame.document.documentElement && objEmailListFrame.document.documentElement.offsetHeight){
							lngBodyHeight = objEmailListFrame.document.documentElement.offsetHeight;
						}else{
							lngBodyHeight = objEmailListFrame.document.body.offsetHeight;
						}
					}else{
					    lngBodyHeight = objEmailListFrame.window.innerHeight;
					}
				
					var objGridBody = objEmailListFrame.document.getElementById("bdyGrid");
					var objGridHeader = objEmailListFrame.document.getElementById("GridHeader");
					var objGridContents = objEmailListFrame.document.getElementById("GridContents");
					
					if(objGridBody && objGridHeader && objGridContents){
						var lngBodyHeight = objGridBody.clientHeight;
						var lngHeaderHeight = objGridHeader.offsetHeight;
						
						var lngGridContentsHeight = lngBodyHeight - lngHeaderHeight;
						objGridContents.style.height = (lngGridContentsHeight) + "px";
					}

				
				}


		}
		
		function OpenEmailEditor(lngEmailID, lngType, strAttachFolder)
		{
			var strTitle=g_MqRef.MqStr.MqEncodeURIComponent(g_MqRef.RESX["EML.TITLE"]);
			var strCaption=g_MqRef.MqStr.MqEncodeURIComponent(g_MqRef.RESX["EML.DLG_CAPTION"]);
			
			if(strAttachFolder){
				strAttachFolder = g_MqRef.MqStr.MqEncodeURIComponent(strAttachFolder);
			}else{
				strAttachFolder="";
			}	
			
			if(lngType <= 0){
				OpenChildWindow("../../HTML/EmailEditor/WCMqEmailEditor.ASP?WCI=wciEmailContentEditor&Fld=txtHiddenEmailSrc_Conversation&Mode=471044&Type=3&Title=" +
											strTitle + "&Caption=&MT=0&Macro=2", "EmailTemplate", 
											"toolbar=no,directories=no,resizable=yes,scrollbars=yes,width=1000,height=700", true, 1000, 700);
			}
			else{
				GetEmailContents(lngType);

				OpenChildWindow("../../HTML/EmailEditor/WCMqEmailEditor.ASP?WCI=wciEmailContentEditor&Fld=txtHiddenEmailSrc_Conversation&Mode=471044&Type=3&Title=" +
											strTitle + "&Caption=&MT=" + lngType + "&Macro=2&AttachID=" + strAttachFolder, "EmailTemplate", 
											"toolbar=no,directories=no,resizable=yes,scrollbars=yes,width=1000,height=700", true, 1000, 700);
 
			}

		}
		
		function GetEmailContents(lngType)
		{
			var lngEmailID = GetSelectedEmailID();
			var objConversationTextbox = document.getElementById("txtHiddenEmailSrc_Conversation");
			var strMsg;
			
			var co = objRequest.Get(mstrCurrentLocation + "../../HTML/EmailEditor/WCMqEmailEditor.ASP?WCI=wciGetEmailContentsToDisplay&UserTmpl=1&Src=1&MT=" + lngType + "&EID=" + lngEmailID+"&CIssueID=" + m_lngIssueID);
			if (co!=objRequest.CANCEL_PROCESS){
				
				var objResponse=objRequest.Response(co);
					
				if (objResponse){
					if (objResponse.HasErrors()){
						objResponse.ProcessErrors("",true,window);
					}else{
						var objConversationTextbox = document.getElementById("txtHiddenEmailSrc_Conversation");
						
						if(objConversationTextbox){
							objConversationTextbox.value = co;
						}
					}
				}
			}
		}
		
		function SetListHeight()
		{
			if(!g_MqRef.MqBrowser.nn){
			   var intBodyHeight;
			   var LST_HEIGHT=160;

			    if (document.all){
			        if (document.documentElement && document.documentElement.offsetHeight){
					intBodyHeight=document.documentElement.offsetHeight;
				}else{
					intBodyHeight=document.body.offsetHeight;
				}
			    }else{
			        intBodyHeight=window.innerHeight;
			    }
			    var strNewHeight=(intBodyHeight-LST_HEIGHT) + "px";
				var objEmailQueueFrame = document.getElementById(IFRAME_EMAIL_QUEUE);
				if(objEmailQueueFrame){
					if (intBodyHeight>LST_HEIGHT*2){
						objEmailQueueFrame.style.height=strNewHeight;
					}	
				}
			}
		}
		</script>

</head>
<body marginheight="0" marginwidth="0" topmargin="10" leftmargin="0" onload="Initialize()" onunload="OnUnload_Form()" class="ToolbarBody" onresize="SetListHeight();">

<table class="NormalText" style="width: 99%;height:99%;margin:5px" border="0" cellpadding="2px">
	<tr>
		<td style="widt-h: 75%;" >
			<input id="QS" type="text" onmouseout="this.className='SrchFld';" onmouseover="this.className='SrchFld ControlHover';" class="SrchFld" 
			 s-tyle="width: 98%;" onkeypress="OnKeyPress_Search(event)" >      
		</td>
		<td  style="width: 10%;text-align: right" >
			<script type="text/javascript">
			m_objMqButton.WriteTextButtonHTML("Go", g_MqRef.RESX["SQE.SEARCH_FOR_LBL"], "Search(document.getElementById('QS').value);", "", 32, "padding-bottom:0px", 
				g_MqRef.RESX["SQE.SEARCH_FOR_LBL"], BUTTON_WIDTH);
			</script>
		</td>
	</tr>
	<tr>
		<td width="90%" valign="top" rowspan="2">
			<div style="height:98%; width: 100%; margin-left:0px; margin-top:3px;padding:0px;" >
			 <script type="text/javascript">
				<!--
					document.write(GetFrameHTML());
				//-->
			</script>
			 </div>
		</td>
	 	<td rowspan="1" width="10%" valign="top">
		<script type="text/javascript">
		m_objMqButton.WriteTextButtonHTML("Refresh", g_MqRef.RESX["EML.REFRESH"], "Refresh(true);", "", 32, "", g_MqRef.RESX["EML.REFRESH"],BUTTON_WIDTH);
		m_objMqButton.WriteTextButtonHTML("ComposeNew", g_MqRef.RESX["EML.NEW_EMAIL"], "Compose();", "", 32, "", g_MqRef.RESX["EML.NEW_EMAIL"], BUTTON_WIDTH);
		m_objMqButton.WriteTextButtonHTML("Reply", g_MqRef.RESX["EML.REPLY"], "Reply();", "", 32, "", g_MqRef.RESX["EML.REPLY"], BUTTON_WIDTH);
		m_objMqButton.WriteTextButtonHTML("ReplyAll", g_MqRef.RESX["EML.REPLY_ALL"], "ReplyAll();", "", 32, "", g_MqRef.RESX["EML.REPLY_ALL"], BUTTON_WIDTH);					
		m_objMqButton.WriteTextButtonHTML("Forward", g_MqRef.RESX["EML.FORWARD"], "Forward();", "", 32, "", g_MqRef.RESX["EML.FORWARD"], BUTTON_WIDTH);
		m_objMqButton.WriteTextButtonHTML("Delete", g_MqRef.RESX["BUTTON.DELETE"], "DeleteEmail();", "", 32, "", g_MqRef.RESX["BUTTON.DELETE"], BUTTON_WIDTH);
		m_objMqButton.WriteTextButtonHTML("LinkToIssue", g_MqRef.RESX["EML.LINK_TO_RECORD"], "LinkToIssue(0);", "", 32, "", g_MqRef.RESX["EML.LINK_TO_RECORD"], BUTTON_WIDTH);
		m_objMqButton.WriteTextButtonHTML("CreateIssue", g_MqRef.RESX["EML.CREATE_RECORD_FROM_EMAIL"], "CreateIssue();", "", 32, "", g_MqRef.RESX["EML.CREATE_RECORD_FROM_EMAIL"], BUTTON_WIDTH);
		</script>
		</td>
	</tr>
	<tr>
				 <td rowspan="1" width="10%" valign="bottom" style="padding-bottom: 1px">
					<script type="text/javascript">m_objMqButton.WriteButtonHTML("Print","PrintPreviewPane();","Print",false,m_objMqButton.STATE_EN,"Print this e-mail");</script>
				 </td>
			</tr>
						<tr>
						<td colspan="3">
							<table 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,"First Page");</script>
									</td>
									<td align='center' width="30">
										<script type="text/javascript">m_objMqButton.WriteButtonHTML("PreviousPage","MovePrev();","PageDown",false,m_objMqButton.STATE_EN,"Previous Page");</script>
									</td>
									<td>
										<div class='PageNavigation' id='PageCaption' style="padding-left:10px; padding-right:10px"></div>
									</td>
									<td align='center' width="30">
										<script type="text/javascript">m_objMqButton.WriteButtonHTML("NextPage","MoveNext();","PageUp",false,m_objMqButton.STATE_EN,"Next Page");</script>
									</td>
									<td align='center' width="30">
										<script type="text/javascript">m_objMqButton.WriteButtonHTML("LastPage","MoveLast();","MoveLast",false,m_objMqButton.STATE_EN,"Last Page");</script>
									</td>
								</tr>
							</table>
						</td>
					</tr>	

	<tr >
		<td colspan=3 valign="top" align=right height="30">
			<script type="text/javascript">
			m_objMqButton.WriteTextButtonHTML("Close", g_MqRef.RESX["BUTTON_CLOSE"], 'window.close();', "", 32, "", g_MqRef.RESX["BUTTON_CLOSE"], BUTTON_WIDTH);
			</script>
		</td>
	</tr>
		
 </table>
<input type="hidden" id="txtHiddenEmailSrc_Conversation" />

</BODY>
</HTML>
