<!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=EmulateIE7; IE=EmulateIE9" />

	<script type="text/javascript">
		var mstrPathPrefix=parent.mstrPathPrefix;

		var strRefs='<link rel="stylesheet" href="' + mstrPathPrefix + 'theme/css/censusmain.css" type="text/css">' +
					'<script type="text/javascript" src="' + mstrPathPrefix + 'js/mqsysutils.js"><\/script>' +
					'<script type="text/javascript" src="' + mstrPathPrefix + 'js/window.js"><\/script>' +
					'<script type="text/javascript" src="' + mstrPathPrefix + 'js/htmllistshared.js"><\/script>';

		strRefs+='<link rel="stylesheet" type="text/css" href="../../js/codebasegrid/dhtmlxdataview.css">' +
					'<link rel="stylesheet" type="text/css" href="../../js/codebasegrid/dhtmlxgrid.css">' +
					'<link rel="stylesheet" type="text/css" href="../../js/codebasegrid/skins/dhtmlxgrid_dhx_skyblue.css">' +
					'<script type="text/javascript" src="../../js/codebasegrid/dhtmlxcommon.js"><\/script>' +
					'<script type="text/javascript" src="../../js/codebasegrid/dhtmlxgrid.js"><\/script>' +        
					'<script type="text/javascript" src="../../js/codebasegrid/dhtmlxgridcell.js"><\/script>' +
					'<script type="text/javascript" src="../../js/codebasegrid/ext/dhtmlxgrid_filter.js"><\/script>' +
					'<script type="text/javascript" src="../../js/codebasegrid/ext/dhtmlxgrid_group.js"><\/script>';

		document.write(strRefs);
	</script>
	<script type="text/javascript">
		<!--
			var NUM_COLS=1;
			var mDataGrid;
			var mblnAddFromStock=true;
			var COL_ID_ADD_AS=1;
			var COL_ID_NAME=2;
			var COL_ID_DESC=3;
			var COL_ID_ASSET_TYPE=4;
			var COL_ID_IN_STOCK=5;
			var COL_ID_ASSOC_COST=6;
			var COL_ID_ADD_BTN=7;
			var COL_ID_REQ_VALS=8;
			var m_lngNumRetries=0;
			var m_strSelItemsBefore="";
			
			if(g_MqRef.MqStr.GetQueryStringValue(location.search,"nostock")=="1"){
				mblnAddFromStock = false;
			}
			
			function ScrollToRow(lngRowID)
			{
				var objTable=document.getElementById("tblFullList");
 
				if(objTable){
					var objRows=objTable.rows;
					if(objRows){
						
						var objRow=objTable.rows.item(lngRowID);		
						if(objRow){	
							var objContentDiv = document.getElementById("GridContents");
							if(objContentDiv){
								objContentDiv.scrollTop = objRow.offsetTop;
							}
						}
					}
				}
			}	
			
			function LoadDataList()
			{
				if(!mDataGrid){		
					var lngStockColWidth=15;
					if(!mblnAddFromStock){
						lngStockColWidth=0;
					}
					mDataGrid = new dhtmlXGridObject('gridbox');
					mDataGrid.setImagePath("../../js/codebasegrid/imgs/");
					mDataGrid.setHeader(",,Name,Description,Asset Class,In Stock,Has An Associated Cost,,");
					mDataGrid.setNoHeader(false);
					mDataGrid.setInitWidthsP("6,0,*,40,0," + lngStockColWidth + ",20,10,0");
					mDataGrid.setColAlign("Center,Right,Left,Left,Left,Left,Left,Left,Left");
					mDataGrid.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro");
					mDataGrid.setColSorting("str,str,str,str,str,str,str,str,str");
					mDataGrid.init();
					mDataGrid.setSkin("dhx_skyblue");
				}else{
					mDataGrid.clearAll();
				}
				
				mDataGrid.groupBy(COL_ID_ASSET_TYPE);
				
				mDataGrid.parse(document.getElementById("dataContainerList").value);	
			}
			
			function ResTypeError(sourceImg, altPath)
			{
				sourceImg.src="../../theme/images/images/res_default_small.jpg";
				sourceImg.onerror="";
				return true;
			}
			
			function AddItem(rowID)
			{
				if(!IsRowDisabled(rowID)){
					AddItemToParent(mDataGrid.cells(rowID,COL_ID_NAME).getValue(), rowID);					
				}
			}
						
			function AddItemToParent(strItemToAdd, lngItemID)
			{
				if(parent){
					if(parent.OnDblClickItem){
						SetBeforeItemAdded();
						var objGridContainer=document.getElementById("GridContainer");
						if(objGridContainer){
							objGridContainer.style.opacity=".5";
							objGridContainer.style.filter="Alpha(Opacity=50)";
						}
						
						parent.OnDblClickItem(g_MqRef.MqStr.MqEncodeURIComponent(strItemToAdd), lngItemID, null, null, null, true);
						window.setTimeout("OnAfterItemAdded(true)", 500);
					}
				}
			}
			
			function OnAfterItemAdded(blnResetCounter)
			{
				if(blnResetCounter){
					m_lngNumRetries=0;
				}
				if(m_lngNumRetries<10){
					var arrCurrentSelVals=GetSelectedValuesInList();
					if(arrCurrentSelVals.join(",")!=m_strSelItemsBefore){
						DisableSelectedRows();
					}else{
						m_lngNumRetries++;
						window.setTimeout("OnAfterItemAdded(false)", 500);
					}
				}else{
					DisableSelectedRows();
				}
			}
			
			function SetBeforeItemAdded()
			{
				var arrSelItems=GetSelectedValuesInList();
				if(arrSelItems){
					m_strSelItemsBefore=arrSelItems.join(",");
				}else{
					m_strSelItemsBefore="";
				}
			}
									
			function HasEmptyRequiredFields(lngRowID)
			{
				var blnRet=false;
				
				if(mDataGrid){
					if(mDataGrid.doesRowExist(lngRowID)){
						var strMissingReqFields=mDataGrid.cells(lngRowID, COL_ID_REQ_VALS).getValue();
						
						blnRet = (strMissingReqFields=="True");
					}
				}
				return blnRet;
			}

			var DISABLED_STYLE="rgb(192, 192, 192)";
			
			function DisableSelectedRows()
			{
				var lngNumTimesAdded=0;
				var strAddedText="";
				
				if(parent){
					if(parent.parent){
						if(parent.parent.Record){
							var arrSelectedRowIDs=GetSelectedValuesInList();
							if(arrSelectedRowIDs){
								if(mDataGrid){
									for(x=0;x<arrSelectedRowIDs.length;x++){
										if(arrSelectedRowIDs[x]){
											if(mDataGrid.doesRowExist(arrSelectedRowIDs[x][0])){
												lngNumTimesAdded=arrSelectedRowIDs[x][2];
												if(lngNumTimesAdded!=0){
													strAddedText='Added (' + lngNumTimesAdded + ') <input type="button" value="Request" onclick="AddItem(\'' + arrSelectedRowIDs[x][0] + '\')" />';
												}else{
													strAddedText='Added';
												}
												mDataGrid.cells(arrSelectedRowIDs[x][0], COL_ID_ADD_BTN).setValue('<img src="../../theme/images/images/check.jpg" /> ' + strAddedText);
											}
										}
									}
								}
							}
						}
					}
				}
								
				var objGridContainer=document.getElementById("GridContainer");
				if(objGridContainer){
					objGridContainer.style.opacity="1";
					objGridContainer.style.filter="Alpha(Opacity=100)";
				}
			}
			
			function GetSelectedValuesInList()
			{
				var lngFieldID=g_MqRef.MqStr.GetQueryStringValue(location.search,"MqFID");
				if(parent){
					if(parent.parent){
						if(parent.parent.Record){
							if(parent.parent.Record.window){
								var strFrameName="ifrRel"+lngFieldID;
								if(parent.parent.Record.window.frames[strFrameName]){
									return parent.parent.Record.window.frames[strFrameName].GetValueIDsInList();
								}
							}
						}
					}
				}
			}
			
			function SetRowDisabled(lngRowID)
			{
				if(mDataGrid){
					mDataGrid.cells(lngRowID, COL_ID_ADD_AS).setTextColor(DISABLED_STYLE);
					mDataGrid.cells(lngRowID, COL_ID_NAME).setTextColor(DISABLED_STYLE);
					mDataGrid.cells(lngRowID, COL_ID_IN_STOCK).setTextColor(DISABLED_STYLE);
					mDataGrid.cells(lngRowID, COL_ID_ASSOC_COST).setTextColor(DISABLED_STYLE);
				}
			}
			
			function SetAssociatedCostUI()
			{
				if(mDataGrid){
					mDataGrid.forEachRow(function(id){
						var cellVal=mDataGrid.cells(id, COL_ID_ASSOC_COST).getValue();
						if(cellVal=="1"){
							mDataGrid.cells(id, COL_ID_ASSOC_COST).setValue('<img src="../../theme/images/images/costassoc.jpg" />');
							mDataGrid.cells(id, COL_ID_ASSOC_COST).setAttribute("title", g_MqRef.RESX['LIST_HEADER_RESOURCE_HAS_ASSOCIATED_COST']);
						}else{
							mDataGrid.cells(id, COL_ID_ASSOC_COST).setValue('');
						}
					})
				}
			}
			
			function IsRowDisabled(lngRowID)
			{
				var blnRet=false;
				
				if(mDataGrid){
					if(mDataGrid.doesRowExist(lngRowID)){
						var strCurrentStyle=mDataGrid.cells(lngRowID, COL_ID_ADD_AS).getTextColor();
						blnRet = (strCurrentStyle==DISABLED_STYLE);
					}
				}
				return blnRet;
			}
			
			function ToggleGrid(blnExpand)
			{
				if(mDataGrid){
					if(blnExpand){
						mDataGrid.expandAllGroups();
					}else{
						mDataGrid.collapseAllGroups();
					}
				}
			}
		//-->
	</script>
</head>
<body rightmargin="0" topmargin="0" leftmargin="0" bottommargin="0" width="100%" height="100%" cl-ass="BoxMCenter" 
		style="padding:0px; margin:0px; overflow:hidden" onload="Form_OnLoad();" onresize='HandleGridPadding()' 
		onkeydown="Form_OnKeyDown(event);" onkeyup="Form_OnKeyUp(event);" onselectstart="Form_OnSelectionStart(event)">
		
	<WC@XML_LIST_FORMAT>
		<row id="%1">
			<cell>&amp;lt;img src="viewicon.asp?Rec=%1&amp;amp;Proj=15" width="32" onerror="ResTypeError(this);" /&amp;gt;</cell>
			<cell>MQ_ADD_AS</cell>
			<cell>{tName}</cell>
			<cell>{mDetailedDescription}</cell>
			<cell>{Level_1}</cell>
			<cell>{Total_Available}</cell>
			<cell>{Has_An_Associated_Cost_}</cell>
			<cell>&amp;lt;input type="button" value="Request" onclick="AddItem('%1')" /&amp;gt;</cell>
			<cell></cell>
		</row>
	</WC@XML_LIST_FORMAT>
	
	<div id='GridContainer' >
		<div id="gridbox" style="background-color:white; border:1px solid #666666; border-radius: 4px;width:100%;height:220px"></div>
	</div>	

	<textarea id="dataContainerList" name="dataContainerList" style="display:none">
		<WC@XML_CONTENTS></WC@XML_CONTENTS>
	</textarea>
	
<script type="text/javascript">
	
	m_strTableName="tblFullList";
    m_lngCurrentPage=parseInt("<WC@CURRENT_PAGE></WC@CURRENT_PAGE>");
    m_lngPageCount=parseInt("<WC@PAGE_COUNT></WC@PAGE_COUNT>");
	m_lngTotalRecord=parseInt("<WC@TOT_REC></WC@TOT_REC>");
	m_lngSelectedRow=parseInt("<WC@SEL_ROW></WC@SEL_ROW>");
                
	function Form_OnLoad()
	{
		var HEIGHT_PADDING=5;
		
		var intBodyHeight;
		if (document.all){
			if (document.documentElement && document.documentElement.offsetHeight){
				intBodyHeight=document.documentElement.offsetHeight;
			}else{
				intBodyHeight=document.body.offsetHeight;
			}
		}else{
			intBodyHeight=window.innerHeight;
		}
		document.getElementById("gridbox").style.height=intBodyHeight-HEIGHT_PADDING + "px";
		
		LoadDataList();
		HandleGridPadding();
		if(parent){
			if(parent.ResetFind){
				parent.ResetFind();
				parent.m_lngCurrentPage=m_lngCurrentPage;
				parent.m_lngPageCount=m_lngPageCount;
				parent.m_lngTotalRecord=m_lngTotalRecord;
		
				m_blnMultiSelect=parent.m_objLookupItemInfo.MultiSelect;
		
				var lngRow=m_lngSelectedRow;
				if(lngRow!="-1"){
					ScrollToRow(parseInt(lngRow));
					SelectRow(parseInt(lngRow));
				}
			}
			if(parent.OnListLoaded){
				parent.OnListLoaded();
			}
		}
		
		SetAssociatedCostUI();
		
		DisableSelectedRows();

		ToggleGrid(false);
	}
	
</script>
</body>
</html>