<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	
	<!--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/jquery/jquery-1.11.1.min.js"></script>	<!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery-1.11.1.min.js"></script></MqAbsPath-->		
	<!--MqRelPath--><script type="text/javascript" src="../../js/frameconstants.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/frameconstants.js"></script></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/cmqsysmsg.js" ></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqsysmsg.js" ></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/VNHTMLDocInit.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/VNHTMLDocInit.js"></script></MqAbsPath-->    	
	<!--MqRelPath--><script type="text/javascript" src="../../js/keylistener.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/keylistener.js" ></script></MqAbsPath-->

	<script type="text/javascript">
		var m_objRef = parent;
		var m_objMqButton=new MqButton();
		var mlngNumRetries=0;
		var BTN_NAME_BACK="Back";
		var BTN_NAME_NEXT="Next";
		var BTN_NAME_APPLY="Apply";
		var BTN_NAME_OK="OK";
					
		function OnLoad()
		{

			loaded=true;
			initialized=true;
			m_objRef.objControlsUi.disableControlButtons();
			
			var strStatusControl="CommandBar.document.getElementById('divStatusTxt')";
			
			m_objRef.objStatus.initialize("CommandBar","CommandBar.document.imgBeginStatusImg",
						strStatusControl,"CommandBar.document.imgEndStatusImg","../../theme/images/images/");
			
			HandleWizardButtonStates();
			
			AddTabWizardButtonHandler();
			
			if (g_VWS.CommandBar().CustomOnLoad)
			{
				g_VWS.CommandBar().CustomOnLoad();
			}
			g_MqRef.ResMgr.ProcessAll(document);
		}						
				
		function ShowDefaultsButton()
		{
			var blnRetry=false;
			
			if(parent){
				if(parent.objFrames){
					var objTopToolbarFrame=parent.objFrames.GetFrameWindow(parent.TOPTOOLBAR_FRAME_ID);
					if (objTopToolbarFrame){
						if(!objTopToolbarFrame.loaded){
							blnRetry=true;
						}else{
							var objDefValsButton=objTopToolbarFrame.document.getElementById("div_DefVals_button");
							var objDefValsCaption=objTopToolbarFrame.document.getElementById("div_DefVals_caption");
							
							if(objDefValsButton && objDefValsCaption){
								objDefValsButton.style.display="";
								objDefValsCaption.style.display="";
							}
						}
					}else{
						blnRetry=true;
					}
				}
			}
			
			if(blnRetry){
				if(mlngNumRetries<10){
					mlngNumRetries++;
					window.setTimeout("ShowDefaultsButton()", 100);
				}
			}
		}
		
		function OnClickBack()
		{
			if(m_objRef){
				if(m_objRef.objTabsMgr){
					var lngCurrentTab=m_objRef.objTabsMgr.GetSelectedTabID();
					m_objRef.objTabsMgr.ClickPrevTab(lngCurrentTab);
					HandleWizardButtonStates();
				}
			}
		}
		
		function OnClickNext()
		{
			if(m_objRef){
				if(m_objRef.objTabsMgr){
					var lngCurrentTab=m_objRef.objTabsMgr.GetSelectedTabID();
					m_objRef.objTabsMgr.ClickNextTab(lngCurrentTab);
					this.HandleWizardButtonStates();
				}
			}
		}
		
		function OnClickSave(strSaveCmd, strAfterSave)
		{
			m_objMqButton.DisableButton(BTN_NAME_APPLY);
			m_objMqButton.DisableButton(BTN_NAME_OK);
			parent.objRecord.ShowLoadingUI(true, true);
			window.setTimeout("if(parent.onClickControls('" + strSaveCmd + "')=='-3'){" + strAfterSave + ";parent.objRecord.ShowLoadingUI(false);}else{parent.objRecord.ShowLoadingUI(true)}; m_objMqButton.EnableButton('" + BTN_NAME_APPLY + "'); m_objMqButton.EnableButton('" + BTN_NAME_OK + "');", 10);
			  
		}
		function OnClickClose(blnSilent)
		{

			var blnClose=true;

			if(!blnSilent){
				if(g_VWS.LoadDataMgr()){
					if(g_VWS.LoadDataMgr().FieldsAreChanged() || g_VWS.RecordMgr().CurrentRecord().IsNewRecord()){
						if(window.confirm(g_MqRef.RESX["CANCEL_CHANGES_TO_ISSUE"])){
							m_objRef.onClickControls('Cancel');
						}else{
							blnClose=false;
						}
					}else
					{
						m_objRef.onClickControls('Cancel');
					}
				}
			}
			
			if(blnClose){
				
				if(m_objRef){
					if(m_objRef.objFeatures.getFeature(m_objRef.FEATURE_WIZARD_VIEW)){

						if(g_VWS.MainWindow().IsModal())
						{
							var objIframe = m_objRef.parent.CreateEscapeIframe(parent.parent.window);
							
							if(objIframe){
								m_objRef.objControlsSs.SetExitTarget(objIframe);
							}
							
							m_objRef.objControlsSs.exit();
							m_objRef.parent.CloseModalWindow();	
						}
					}
					m_objRef.objRecord.Hide();
					
				}
			}
		}
		
		function HandleWizardButtonStates(lngTabID)
		{
		
					
		
			if(m_objRef){
				if(m_objRef.objTabsMgr){
				

				
					var lngCurrentTab=m_objRef.objTabsMgr.GetSelectedTabID();
					if(lngTabID!=undefined){
						lngCurrentTab=lngTabID;
					}
					var lngCurrentTabIdx=m_objRef.objTabsMgr.GetTabIndexByID(lngCurrentTab);
					
					if(lngCurrentTabIdx==m_objRef.objTabsMgr.LastTabIdx()){
						m_objMqButton.DisableButton(BTN_NAME_NEXT);
					}else{
						m_objMqButton.EnableButton(BTN_NAME_NEXT);
					}
					if(lngCurrentTabIdx==m_objRef.objTabsMgr.FirstTabIdx()){
						m_objMqButton.DisableButton(BTN_NAME_BACK);
					}else{
						m_objMqButton.EnableButton(BTN_NAME_BACK);
					}

					btnToggle(BTN_NAME_APPLY,lngCurrentTabIdx);
					btnToggle(BTN_NAME_OK,lngCurrentTabIdx);
					
					//always hide the Apply button for new records
					if(	g_VWS.CommandBar().EnableApplyInNewRec || 
						!g_VWS.RecordMgr().CurrentRecord().IsNewRecord()){

						m_objMqButton.ShowHideButton(BTN_NAME_APPLY, true);
					}else{
						m_objMqButton.ShowHideButton(BTN_NAME_APPLY, false);
					}

				}else{
					window.setTimeout("HandleWizardButtonStates(lngTabID)", 50);
				}
			}
		}
		function btnToggle(strBtnName,lngCurrentTabIdx)
		{
			if(!parent.objFeatures.getFeature(parent.FEATURE_SURVEY_VIEW)){
				if(g_MqRef.MqStr.GetQueryStringValue(m_objRef.document.location.search,"RO")=="1"){
				
					m_objMqButton.DisableButton(strBtnName);
					}else{
						if(g_VWS.CommandBar().EnableSaveOnlyLastTab==true){
							if(lngCurrentTabIdx!=m_objRef.objTabsMgr.LastTabIdx()){
								m_objMqButton.DisableButton(strBtnName);
								}else{
									m_objMqButton.EnableButton(strBtnName);
								}
						}else{
							m_objMqButton.EnableButton(strBtnName);
						}
					}
			}else{
				m_objMqButton.EnableButton(strBtnName);
			}
		}
			
		function AddTabWizardButtonHandler()
		{
			if(m_objRef){
				if(m_objRef.objFrames){
					var objRecordFrame=m_objRef.objFrames.GetFrameWindow(m_objRef.RECORD_FRAME_ID);
					if(objRecordFrame){
						if(m_objRef.objTabsMgr){
							var arrTabs=m_objRef.objTabsMgr.GetAllTabs();
							for(i=0; i<arrTabs.length; i++){
								objTab=arrTabs[i];
								if(objTab){
									objTab.SetOnClick("if(objFrames){var winCB=objFrames.GetFrameWindow(COMMANDBAR_FRAME_ID);if (winCB){winCB.HandleWizardButtonStates(" + objTab.GetID() + ");}}");														
								}
							}
						}
					}else{
						window.setTimeout("AddTabWizardButtonHandler()", 50);
					}
				}
			}
		}

	</script>		
</head>
<body onload="OnLoad();" 
		leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" 
		marginwidth="0" marginheight="0" class="CommandBarBody">
	<!-- Begin controls section -->
	<form id="CodeForm" name="CodeForm" action="#"  onsubmit="onSubmitCommandBar();return false;">
	<table width="100%" cellpadding="0" cellspacing="0" border="0" style="height: 20px">
		<tr>
			<script type="text/javascript">
				document.write('<td width="14" >&nbsp;</td>');
			</script>
			<td align="center">
				
				<table width="100%" height="2" cellpadding="0" cellspacing="0" border="0">
					<tr>
						
							<script type="text/javascript">
									parent.SetState(COMMANDBAR_FRAME_ID, parent.IDLE_STATE);
									document.write("<td>");
									parent.objRequest.WriteAppletHTML("../../applets/",document);
									document.write("</td>");
							</script>						
					</tr>
				</table>
				<table width="100%" height="30" cellpadding="0" cellspacing="0" border="0">
					<tr>
						<td width="60%" style="text-align:left" >
						<span id="MsgReqFld">
							<span class="requiredfield" style="font-size:9pt;" translate="yes" data-res="REC_DETAIL.THIS_COLOR_MSG">this</span> 
							<span class="normalfield" style="font-size:9pt;padding-left:0px; color:#727272 !important;" translate="yes" data-res="REC_DETAIL.IS_REQUIRED_FLD_MSG">is require</span>
						</span>
						<input name="txtRecordDisplay" id="txtRecordDisplay" type="hidden" value="">
						<input type="hidden" name="txtStrValue" value="">
						<input type="hidden" name="txtNavBtn" value="">
						<input type="hidden" name="txtUploadDir" value="">
						
						<script type="text/javascript">
						if (parent.objControlsUi.getReadOnly())
						{
							document.getElementById("MsgReqFld").style.display="none";
						}
						</script>
						</td>
						<td width="30%" valign="top">
							<table width="100%" height="25" cellpadding="0" cellspacing="0" border="0">
								<tr>
								<td class="controls" width="24"><img src="../../theme/images/spacer.gif" width="24" height="24" border="0"></td>
									<script type="text/javascript">
										strOutput="";
										var strBack="";
										if (g_VWS.CommandBar().BackButtonCaption!="")
										{
											strBack="<td style='padding-right:2px'>" + 
														m_objMqButton.GetTextButtonHTML(BTN_NAME_BACK,g_VWS.CommandBar().BackButtonCaption, 
																"OnClickBack();", "", null, "", g_MqRef.RESX['BUTTON_BACK_TT']); + "</td>";
										}
										var strNext="";
										if (g_VWS.CommandBar().NextButtonCaption!="")
										{
										
											strNext="<td style='padding-right:2px'>" + 
														m_objMqButton.GetTextButtonHTML(BTN_NAME_NEXT,g_VWS.CommandBar().NextButtonCaption,
																"OnClickNext();","", null, "", g_MqRef.RESX['BUTTON_NEXT_TT']); + "</td>";
										}
								
										var strClose="<td id='btnClose' name='btnClose' style='padding-right:2px'>" + 
															m_objMqButton.GetTextButtonHTML("Cancel",g_VWS.CommandBar().CloseButtonCaption,
																	"OnClickClose(false);","", null, "", g_VWS.CommandBar().CloseButtonCaption); + "</td>";
																
										var strSaveCmd="Save";
										var strAfterSave="OnClickClose(true);";
										if(m_objRef){
											if(m_objRef.objFeatures.getFeature(m_objRef.FEATURE_WIZARD_VIEW) || m_objRef.objFeatures.getFeature(m_objRef.FEATURE_SURVEY_VIEW)){
												strSaveCmd="Submit";
												strAfterSave="";
											}
										}
										var strApply="";
										if (g_VWS.CommandBar().ApplyButtonCaption!="")
										{
											strApply="<td id='btnApply' name='btnApply' style='padding-right:2px'>" + 
																	m_objMqButton.GetTextButtonHTML(BTN_NAME_APPLY,g_VWS.CommandBar().ApplyButtonCaption,
																			"OnClickSave('" + strSaveCmd + "', '"+ null +"');","", null, "", 
																			g_VWS.CommandBar().ApplyButtonTooltip); + "</td>";										
										}

																		
									   var strOk="<td id='btnOk' name='btnOk' style='padding-right:2px'>" + 
																m_objMqButton.GetTextButtonHTML(BTN_NAME_OK,g_VWS.CommandBar().SaveButtonCaption,
																		"OnClickSave('" + strSaveCmd + "', '" + strAfterSave + "');","", null, "", 
																		g_VWS.CommandBar().SaveButtonTooltip); + "</td>";
																		
										if (!m_objRef.objControlsUi.getReadOnly()){
										
										
											if(!m_objRef.objFeatures.getFeature(m_objRef.FEATURE_SURVEY_VIEW)){
											
												var blnAddNew=false;
												var blnAddCopy=false;
												var blnAddCopyChild=false;
												var blnAddSave=false;
												var blnAddDelete=false;
												var blnAddPrint=true;
												var strOutput='<td align="right">';
												strOutput+='<table cellpadding="2" cellspacing="0" border="0" ';
												
												strOutput+='><tr>';
										
												<WC@SECURED_FEATURE_104>
													blnAddNew=true;
													blnAddSave=true;
												</WC@SECURED_FEATURE_104>

												<WC@SECURED_FEATURE_105>
													blnAddCopy=true;
													blnAddSave=true;
												</WC@SECURED_FEATURE_105>
												
												<WC@SECURED_FEATURE_106>
													blnAddSave=true;
												</WC@SECURED_FEATURE_106>
												
												<WC@SECURED_FEATURE_107>
													blnAddDelete=true;
												</WC@SECURED_FEATURE_107>
												
												<WC@SECURED_FEATURE_120>
													blnAddCopyChild=true;
												</WC@SECURED_FEATURE_120>

												var ATTRIB_VAL_NO="no";
												
												if("<Mq_WVA_30>"==ATTRIB_VAL_NO){
													blnAddNew=false;
												}
												
												if("<Mq_WVA_31>"==ATTRIB_VAL_NO){
													blnAddCopy=false;
												}
												
												if("<Mq_WVA_32>"==ATTRIB_VAL_NO){
													blnAddCopyChild=false;
												}
												
												if("<Mq_WVA_33>"==ATTRIB_VAL_NO){
													blnAddDelete=false;
												}
												
												if("<Mq_WVA_34>"==ATTRIB_VAL_NO){
													blnAddPrint=false;
												}
												
												strOutput+=strBack;								
												strOutput+=strNext;
												strOutput+=strOk;
												
												if(!m_objRef.objFeatures.getFeature(m_objRef.FEATURE_SUBMIT)){
													strOutput+=strApply;
												}
												
												strOutput+=strClose;
											}else{
												strOutput+=strOk;
												
											}
										}else{
											var strOutput='<td align="right">';
											
											strOutput+='<table cellpadding="2" cellspacing="0" border="0"><tr>';
									
											if(!m_objRef.objFeatures.getFeature(m_objRef.FEATURE_SUBMIT)){
												if(blnAddPrint){
													strOutput +=m_objRef.objControlsUi.addControl(parent.CONTROL_PRINT, false);
												}
											}

											if(!m_objRef.objFeatures.getFeature(m_objRef.FEATURE_KB_VIEW)){
												strOutput+=strBack;	
												strOutput+=strNext;	
											}
											strOutput+=strClose;
										}
										
										strOutput+='<\/tr><\/table>';
										strOutput+='<\/td>';
										document.write(strOutput);
										
								</script>
							</tr>
							</table>
						</td>
						
					</tr>
				</table>
			</td>
			
			<td style="display:none">
				<input name="txtID" id="txtID" value="-1" type="hidden">
			</td>
			
			<script type="text/javascript"> parent.objRecord.Initialize(document.getElementById("txtID"),document.getElementById("txtRecordDisplay"));</script>

		</tr>
		
	</table>
	</form>
	<script type="text/javascript">
		var objSysMsg = new CMqSysMsg;
		
		function onSubmitCommandBar()
		{
			if (parent.objRecord) {
				parent.OnBeforeNavigate(parent.CLOSE_SCENARIO_USER_LEAVES_ISSUE_CONTEXT);
				parent.objRecord.SynchronizeWithVisible();
			}
			parent.onClickControls('View');
			
		}
		
		function onCurrentRecordBlur()
		{
			var objRec=parent.objRecord;
			
			if (objRec){
				if (objRec.GetRecordId()!=objRec.GetVisibleRecordId()){
					onSubmitCommandBar();
				}
			}
		}
	</script>
			
</body>
</html>
