<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title></title>

	<!--MqRelPath--><link rel="stylesheet" href="../../js/jquery/jquery.ui.all.css"><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" href="<BASE_VD>/js/jquery/jquery.ui.all.css"></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery-1.7.1.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery-1.7.1.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.bgiframe-2.1.2.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.bgiframe-2.1.2.js"></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.core.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.core.js"></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.widget.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.widget.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.mouse.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.mouse.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.draggable.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.draggable.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.position.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.position.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.resizable.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.resizable.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.dialog.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.dialog.js"></script></MqAbsPath-->

	<!--MqRelPath--><link rel="stylesheet" type="text/css" href="../../theme/css/censusmain.css"/><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" type="text/css" href="<BASE_VD>/theme/css/censusmain.css"/></MqAbsPath-->
	<!--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/window.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/window.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-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/mqformelements.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqformelements.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/cmqlookupitemint.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqlookupitemint.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/initlookupitemint.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/initlookupitemint.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 m_oCenMn=parent;
		var m_objLookupItemInfoColl=new Array();
		
		var m_iFieldID=g_MqRef.MqStr.GetQueryStringValue(document.location.search, "FLD");
		var m_sFieldCaption=g_MqRef.MqStr.GetQueryStringValue(document.location.search, "FC");
		var m_iPurchDatDB=g_MqRef.MqStr.GetQueryStringValue(document.location.search, "PADat");
		var revHistGrid;
		CloseWindowByEscKey(false);
		
		var mstrCurrentLocation = m_oCenMn.mstrCurrentLocation;
		var objRequest = m_oCenMn.objRequest;
		
		function SelectOption(iID)
		{
			$("input[name=radRelPurch][value=" + iID + "]").prop('checked', true);
		}
		
		function OnOK()
		{
			var iVal=$('input[name=radRelPurch]:checked').val();
			
			if(iVal){
				if(iVal==1){
					CreateLineItem(false);
				}else{
					if(iVal==2){
						CreateLineItem(true);
					}else{
						if(iVal==3){
							OpenLineItemsDlg();
						}
					}
				}
			}else{
				alert(g_MqRef.RESX["REL_PURCH.CHOOSE_VALUE"]);
			}
		}
		
		function CreateLineItem(blnSimple)
		{
			if(m_oCenMn){
				if(m_oCenMn.objRecord){
					var strInvNum="";
					var strStatus="";
					var strLicApp="";
					var objFormElement=new m_oCenMn.CMqFormElement();
					
					if(m_oCenMn.m_objViewFields.Exists(873)){
						var objAppNameFld=m_oCenMn.m_objViewFields.Field(873);
	
						if (objAppNameFld){
							objFormElement.Initialize(objAppNameFld.GetBoundControl(),objAppNameFld.GetControlType(),'Record.document');
							strInvNum=objFormElement.GetValue();
						}
					}
					if(m_oCenMn.m_objViewFields.Exists(430)){
						var objAppNameFld=m_oCenMn.m_objViewFields.Field(430);
						if (objAppNameFld){
							objFormElement.Initialize(objAppNameFld.GetBoundControl(),objAppNameFld.GetControlType(),'Record.document');
							strLicApp=objFormElement.GetValue(false,null,null,true);
						}
					}
					if(blnSimple){
						strStatus="&904=2&21=3";						
					}else{
						strStatus="&904=1&21=1";
					}
					var strType="&txtPostData=" + g_MqRef.MqStr.MqEncodeURIComponent("30=" + strLicApp + "&912=1&907=" + m_oCenMn.objRecord.GetRecordId() + "&873=" + strInvNum + strStatus);
					
					OpenModalWindow(m_oCenMn.GetVDURL(m_oCenMn.g_VWS.URL().BaseVDName(), "View=Purchases%26Agreements%2FAdd" + "&SrcFld=333" + strType), 800, 600);
				}
			}
		}
		
		function OnAfterCreateRecord(iPurchID)
		{
			OpenLineItemsDlg(iPurchID);
		}
		
		function OpenLineItemsDlg(iPurchID)
		{ 

			var arrSelectedIDs;
			var arrSelectedValues;
			var blnMultiSelect;
			var fnSetValue=AddRelPurch;
			var strWorkflowValues="";
			var objHTMLElement;
			var strSelValID="";
			if(typeof(iPurchID)!="undefined"){
				strSelValID=iPurchID
			}
						
			var strURL="WCDisplayChoices.asp?WCI=DisplayChoices&Ct=2&TBL=tblDts&DS=" + m_iPurchDatDB + "&CO=0&HTbl=tblInvPartLst&LstID=2&RelTbl=tblLineItem";
			//var strURL2="WCDisplayChoices.asp?WCI=DisplayChoices&TBL=tblDts&DS=" + m_iPurchDatDB + "&CO=0&ID=nID&VAL=tBriefDescription&HTbl=tblInvLst&Cust=<ValOfField>363</ValOfField>&SelVal=<ValOfField>" + m_iFieldID + "</ValOfField>&INV=1&RMA=0&ORD=0&LstID=1";
			var strURL2="WCDisplayChoices.asp?WCI=DisplayChoices&TBL=tblDts&DS=" + m_iPurchDatDB + "&CO=0&ID=nID&VAL=tBriefDescription&HTbl=tblInvLst&Cust=<ValOfField>363</ValOfField>&SelID=" + strSelValID + "&INV=1&RMA=0&ORD=0&LstID=1";
					
			if (m_oCenMn){
				var objMacros=new m_oCenMn.CMqMacros();
				if(objMacros){
					strURL2=objMacros.ResolveFieldMacros(strURL2,m_oCenMn.m_objLoadDataMgr,true,false);
					strURL=objMacros.ResolveFieldMacros(strURL,m_oCenMn.m_objLoadDataMgr,true,false);
				}
			}
					
			var lngFieldID;
					
			//if(blnIsPartField){
			//	lngFieldID=lngPartFieldID;
			//}else{
				lngFieldID=m_iFieldID;
			//}
			
			var WKFLW_ATTRIB="MqWrkFlwVals";			
			var objFormElement=new m_oCenMn.CMqFormElement();
					
			if(m_oCenMn.m_objViewFields.Exists(lngFieldID)){
				var objSrcFld=m_oCenMn.m_objViewFields.Field(lngFieldID);

				if (objSrcFld){
					var objSrcCtrl=m_oCenMn.Record.document.getElementById(objSrcFld.GetBoundControl());
					if(objSrcCtrl){
						if(objSrcCtrl.getAttribute(WKFLW_ATTRIB)) {
							strWorkflowValues=objSrcCtrl.getAttribute(WKFLW_ATTRIB);
							
							if(strWorkflowValues!="" && strSelValID !=""){
								strWorkflowValues+=";"+strSelValID;
								objSrcCtrl.setAttribute(WKFLW_ATTRIB, strWorkflowValues);
							}
						}
					}
				}
			}
			
			InitLookupItemVals(lngFieldID, arrSelectedIDs, arrSelectedValues, fnSetValue, blnMultiSelect, m_sFieldCaption, strWorkflowValues, strURL, null,null,null,null,null,null, strURL2);
		
			var strWinFeatures=GetWinFeaturesToCenter(1024, 600); 
			
			OpenModalWindow("../HTML/TmplPurchDlg.htm?FID="+lngFieldID + "&PADat=" + m_iPurchDatDB, 1024, 600, true);
			
		}
		
		
		function AddRelPurch(lngFieldID, arrSelectedIDs, arrSelectedValues)
		{
			var objLst=eval("m_oCenMn.Record.m_oRRLst" + lngFieldID);
			if(objLst){
				for(var x=0; x<arrSelectedIDs.length; x++){
					objLst.LinkRelPurchItem(arrSelectedIDs[x]);
				}
				CloseWindow();
			}
		}
		
		</script>
</head>

<body class="MainBackgroundPopup">

	<div class="TopToolBarPopup">
		<table width="98%" class="TopToolBarWizard">
			<tr>
				<td>
					<img src="../../theme/images/images/invoices.png" />
				</td>
		        <td valign="top" style="padding-top:15px; padding-left:10px" width="100%">
		            <div class="WizardTitle"><script type="text/javascript">document.write(g_MqRef.RESX["REL_PURCH.TITLE"]);</script></div>
		            <div class="WizardDescription"><script type="text/javascript">document.write(g_MqRef.RESX["REL_PURCH.DESC"]);</script></div>
		        </td>
		    </tr>
		</table>
	</div>

	<table id="tblMain" marginwidth="0" cellspacing="0" cellpadding="0" border="0" style="margin-left:10px;margin-right:10px;width: 97.66%;padding-top:10px" >
		<tr >
			<td style="text-align:right; padding-right:10px" valign="top"><input type="radio" name="radRelPurch" value="1" /></td>
			<td style="padding-bottom:20px; " width="95%" onclick="SelectOption(1)"><b><script type="text/javascript">document.write(g_MqRef.RESX["REL_PURCH.OPT1_TITLE"]);</script></b><br />
			<script type="text/javascript">document.write(g_MqRef.RESX["REL_PURCH.OPT1_DESC"]);</script></td>	
		</tr>
		<tr >
			<td style="text-align:right; padding-right:10px" valign="top"><input type="radio" name="radRelPurch" value="2" /></td>
			<td style="padding-bottom:20px; " width="95%" onclick="SelectOption(2)"><b><script type="text/javascript">document.write(g_MqRef.RESX["REL_PURCH.OPT2_TITLE"]);</script></b><br />
			<script type="text/javascript">document.write(g_MqRef.RESX["REL_PURCH.OPT2_DESC"]);</script></td>	
		</tr>
		<tr >
			<td style="text-align:right; padding-right:10px" valign="top"><input type="radio" name="radRelPurch" value="3" /></td>
			<td style="padding-bottom:20px; " width="95%" onclick="SelectOption(3)"><b><script type="text/javascript">document.write(g_MqRef.RESX["REL_PURCH.OPT3_TITLE"]);</script></b><br />
			<script type="text/javascript">document.write(g_MqRef.RESX["REL_PURCH.OPT3_DESC"]);</script></td>	
		</tr>
		
		<tr>
			<td colspan="2" align=right>
				<table>
					<tr>
						<td>
							<script type="text/javascript">m_objMqButton.WriteTextButtonHTML("OK", g_MqRef.RESX["BUTTON_OK"], 'OnOK()', "", 32, "", g_MqRef.RESX["BUTTON_OK"], 90);</script>
						</td>
						<td>
							<script type="text/javascript">m_objMqButton.WriteTextButtonHTML("Close", g_MqRef.RESX["BUTTON_CANCEL"], 'CloseWindow()', "", 32, "", g_MqRef.RESX["BUTTON_CANCEL"], 90);</script>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		</tbody> 
	</table>
	
	<div style="display: none">
		<div id="dialog-modal" style="width:100%;height:100%;padding:0px;margin:0px;overflow:hidden">
			<iframe id="dialog-modal-url" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="no"></iframe>
		</div>
		<div id="dialog-modal-orig-width" name="dialog-modal-orig-width" style="display:none"></div>
		<div id="dialog-modal-orig-height" name="dialog-modal-orig-height" style="display:none"></div>
	</div>
</body>
</html>