<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Load Data</title>
		<!--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-->

		<script type="text/javascript">
			// always define this object for the system messages
			var objSysMsg = new CMqSysMsg;
		</script>

	</head>
	<body  onload="OnLoadForm();">
		<!------- BEGIN LOAD DATA ---------->
		<script type="text/javascript"><!--
			var lngCurrentId=<WC@CURRENTRECORDID></WC@CURRENTRECORDID>;
			var blnNewRecord=parseInt("<WC@NEWREC></WC@NEWREC>");	
			var INIT_REVISION_NUMBER ="-1";
			var REV_NUM_NEW_REC =0;
			var m_bSOV=parent.objFeatures.getFeature(parent.FEATURE_SUBMIT);
			var m_MainWin=parent;
			
			function updateCommandBar(){
				if (parent.CommandBar.loaded){
					if (parent.g_VWS.RecordMgr().CurrentRecord().GetRevisionNumber()!=0){
						if (parent.objRecord.GetRecordId()>0){
							if (parent.objRecord.GetRecordId()!=lngCurrentId){
									alert(g_MqRef.RESX["MSG_CANT_FIND_ISSUE"]);
							}else{
									parent.objControlsUi.enableControlButtons();
							}
						}else{
							parent.g_VWS.RecordMgr().CurrentRecord().SetRevisionNumber(INIT_REVISION_NUMBER);
						}
												
					}else{
						parent.g_VWS.RecordMgr().CurrentRecord().SetRevisionNumber(INIT_REVISION_NUMBER);
					}
						
				}else{
					var tim=setTimeout("updateCommandBar()",200);
				}
			}
			updateCommandBar();
			
		

		
			function initializeRecordVariables(){
				var strEmptyDir = "INIT";
				parent.SetHiddenAttachFields("txtUploadDir", strEmptyDir);
			}
		

		
			function initializeSCC(){
				var strSCCFiles;
				strSCCFiles="<WC@GETFILESSCC></WC@GETFILESSCC>";
				if (strSCCFiles!="-1") {
					var objRecordDoc=parent.Record.document;
					var SCC_APPLET_NAME="scc_1_Files";
					if (objRecordDoc.applets[SCC_APPLET_NAME]){
						parent.objScc.getObject("MqSccFiles").appTable=objRecordDoc.applets[SCC_APPLET_NAME];
						parent.objScc.getObject('MqSccFiles').loadSCCApplet(strSCCFiles);
					}
				}
			}
			
			function LoadData()
			{
				WriteConsole("[LoadData] Loading DTS Rec:" + lngCurrentId);
									
				var blnDisableAll=<WC@ISRECORDDISABLED></WC@ISRECORDDISABLED>;					
				var strXMLFieldValues="<WC@LOADDATA></WC@LOADDATA>";
				var oFieldValuesRs;
				var objLoadDataMgr=parent.m_objLoadDataMgr;
				var objDefVals=parent.m_objDefVals;
				var objCustomSetVals=parent.m_objCustomSetVals;
				var oViewFields=parent.m_objViewFields;
				var lngTabToShowID=g_MqRef.MqStr.GetQueryStringValue(location.search, "Tab");
				if (strXMLFieldValues.length>0){
					if (oViewFields){	
						oFieldValuesRs=new parent.CMqRecordset(strXMLFieldValues,oViewFields.GetFieldIDName());	
						
						if(m_bSOV && objDefVals && lngCurrentId<=0){
							objDefVals.FillRS(oFieldValuesRs);
						}
					}
				}else{
					if (m_bSOV && objDefVals && oViewFields){
						oFieldValuesRs=objDefVals.GetDefVals();
						oFieldValuesRs[oViewFields.GetRevisionHistoryFieldID()]=REV_NUM_NEW_REC;
					}
   	        	}
				if  (objLoadDataMgr){
					if (parent.m_objWorkFlow){
						parent.m_objWorkFlow.SetOrigFldValues(oFieldValuesRs);
					}		
					if(objCustomSetVals){
						if (objCustomSetVals.GetApplyDefVals()){
							var arrTemp=objCustomSetVals.GetDefVals();
							objCustomSetVals.FillRS(oFieldValuesRs); 
							objCustomSetVals.SetApplyDefVals(false);
						}
					}
					if (objDefVals){
                    	if (!m_bSOV || (m_bSOV && lngCurrentId>0)){
							if (objDefVals.GetApplyDefVals()){
						    	objDefVals.FillRS(oFieldValuesRs);
						    	objDefVals.SetApplyDefVals(false);
                        	}
						}
					}
					var lngMode;
					if (blnDisableAll){
						lngMode=0;
					}else{
						if (blnNewRecord){
							lngMode=2;
						}else{
							lngMode=1;
						}
					}
					objLoadDataMgr.Load(oFieldValuesRs,lngMode,parent.m_objDisplayElements,parent.objControlsSs, lngTabToShowID, null, lngCurrentId, parent.g_VWS.RecordMgr().CurrentRecord());
					
					WriteConsole("[LoadData] Finished loading Rec:" + lngCurrentId);
					//parent.FixTabs(oFieldValuesRs);
				}
			 }			
			
			function setUI(){
				
					if (parent.g_VWS.RecordMgr().CurrentRecord().GetRevisionNumber()!=0){					
						parent.objRecord.SetRecordId(lngCurrentId);
						parent.SetIdleStatus();
						parent.objControlsUi.enableControlButtons();
					}else{ 
						if (!m_bSOV){
							parent.objRecord.SetRecordId(lngCurrentId);
							parent.SetState(parent.COMMANDBAR_FRAME_ID, parent.IDLE_STATE); 
							parent.objStatus.setStatus(parent.STATUS_NEWRECORD);
						}
						parent.objControlsUi.disableControlButtons();
					}
					
					parent.HideClickBlocker("Record");
					parent.SetState(parent.LOADDATA_FRAME_ID,parent.IDLE_STATE);
					parent.SetDocumentCursor("");
			}
			
			function loadDataFrame(lngRetryTime)
			{
				var blnCallRetry=true;
				var blnLoadData=false;
				var objAppRequest;
				
				if (!lngRetryTime){
					lngRetryTime=1500
				}
				
				//strTempID=g_MqRef.MqStr.GetQueryStringValue(location.search, "nId");
				if(lngCurrentId >= 0)
				{
					if(m_MainWin.objRecord)
					{
						if(m_MainWin.m_blnIsMobile)
						{
							m_MainWin.objRecord.Show(m_MainWin.m_blnIsMobile, m_MainWin.objFrames.Item(m_MainWin.RECORD_FRAME_ID), m_MainWin.objFrames.Item(m_MainWin.SUMMARY_LIST_FRAME_ID));
						}
					}
					
				}
				
				if (parent.objFrames.IsFrameLoaded(parent.RECORD_FRAME_ID)){
					
					objAppRequest=parent.objRequest.GetAppRequest();
					if (parent.objRequest.IsJavaEnabled(objAppRequest)){
						if(parent.objRequest.IsAppletLoaded(objAppRequest)){
							blnLoadData=true;
						}
					}else{
						blnLoadData=true;
					}	
					
					if(blnLoadData){
						blnCallRetry=false;				
						LoadData();
						initializeSCC();					
						initializeRecordVariables();
						setUI();							
						RegenerateSumList(<WC@RegenerateSumList></WC@RegenerateSumList>,<WC@SQEFieldID></WC@SQEFieldID>, true);							
					}
				}
				
				if(blnCallRetry){
					var timerId;
					timerId=setTimeout("loadDataFrame("+lngRetryTime+")", lngRetryTime);	
			    }
			}
			
			
			
			
					
			function RegenerateSumList(blnRegenerate,lngSQEFieldID, blnAutoRefreshMode){
				if (blnRegenerate || parent.mblnForceSLRefresh){
					var blnGenSL=true;
					
					if(parent.m_objSLDD){
						if(parent.m_objSLDD.DDIsEnabled()){
							if(SearchSQESimple(parent.m_objSLInput)==false){
								parent.m_objSLDD.RefreshToCurrentDD();
								blnGenSL=false;
							}
						}
					}
					
					if(blnGenSL){
						if (parent.ToolBar){
							parent.ToolBar.submitinfo(blnAutoRefreshMode);
						}
					}
					parent.mblnForceSLRefresh=false;
				}
			}
			
			function SearchSQESimple(objSummaryListInput)
			{
				var strValue="";
				if(objSummaryListInput){
					strValue=objSummaryListInput.GetTextSearchValue();
				}
				return (strValue!="");
			}
			
			function OnLoadForm(){
				loaded=true;
				initialized=true;
				loadDataFrame();
			}
		</script>
		
	</body>
</html>
