var m_oAssMgr=new g_VNLibs.VNAssetMgr();

function WriteSidePanel()
{
var blnShowButton=false;
	var strHTML='';
	
	if(parent){
		if(parent.objFrames){
			var winTopTB=parent.objFrames.GetFrameWindow(parent.TOPTOOLBAR_FRAME_ID);
			if (winTopTB){
				blnShowButton=winTopTB.blnHasFeature134;
			}
		}
	}
	
	strHTML+=m_objMqButton.GetTextButtonHTML("AddAssets", g_MqRef.RESX['BUTTON_ADD_BULK_ASSETS'], "AddBulkAssets()", "", 65, "", "", 150);
	
	strHTML+=m_objMqButton.GetTextButtonHTML("MassUpdate", g_MqRef.RESX['SL.MASS_UPDATE_SELECTED_ISSUES'], "OpenBatchUpdateWindow()", "", 65, "", "", 150);
	
	strHTML+=m_objMqButton.GetTextButtonHTML("Reassign", g_MqRef.RESX['BTN_REASSIGN_ASSETS'], "m_oAssMgr.ReassignSelected(mDataGrid,document)", "", 65, "", "", 150);

	strHTML+=m_objMqButton.GetTextButtonHTML("ScrapAssets", g_MqRef.RESX['BTN_SCRAP_ASSETS'], "ScrapAssets()", "", 65, "", "", 150);
	
	strHTML+=m_objMqButton.GetTextButtonHTML("LostAssets", g_MqRef.RESX['BTN_MARK_ASSETS_LOST'], "MarkAssetsAsLost()", "", 65, "", "", 150);

	strHTML+=m_objMqButton.GetTextButtonHTML("RequestStatus", g_MqRef.RESX['BTN_REQUEST_ASSET_STATUS'], "RequestAssetStatus()", "", 65, "padding-bottom:50px;", "", 150);
	
	if(blnShowButton)
	{
		strHTML+=m_objMqButton.GetTextButtonHTML("SYNCChromebooks", g_MqRef.RESX['BUTTON_SYNC_CHROMEBOOKS'], "SyncChromeDevices()", "", 65, "", "", 150);
	}	
	
	if(parent.UserHasAccessToView(20, parent.m_strValidViewIDs)){
		strHTML+=m_objMqButton.GetTextButtonHTML("AssetTypes", g_MqRef.RESX['BUTTON_MANAGE_ASSET_DEFS'], "ManageAssetDefs()", "", 65, "", "", 150, "HTMLTextButtonNavLink", "TextButtonNavLink");
	}
	
	if(parent.UserHasAccessToView(85, parent.m_strValidViewIDs)){
		strHTML+=m_objMqButton.GetTextButtonHTML("EmployeeAssets", g_MqRef.RESX['BUTTON_MANAGE_EMPLOYEE_ASSETS'], "parent.LoadView('View=Users%26Contacts%2FEmployeeAssets')", "", 65, "", "", 150, "HTMLTextButtonNavLink", "TextButtonNavLink");
	}
	
	document.write(strHTML);
}

function AddNewInvoice()
{
	var INV_TYPE_FIELD="912";
	var TYPE_PO=1;
	var strType="&txtPostData=" + g_MqRef.MqStr.MqEncodeURIComponent(INV_TYPE_FIELD + "=" + TYPE_PO);
	
	parent.OpenModalWindow(parent.GetVDURL(parent.g_VWS.URL().BaseVDName(), "View=Purchases%26Agreements%2FAdd" + strType), 1440, 900, true);
}

function EditResInfo(lngID)
{
	parent.LoadRecord(lngID, -1, false);
}

function AddBulkAssets()
{
	parent.OpenModalWindow(parent.GetVDURL(parent.g_VWS.URL().BaseVDName(), "View=Resources%2FAddGrp"), 1440, 900, true);
}

function AddExternal()
{
	parent.LoadView("View=Resources%2FUnmanagedLib");
}

function ManageAssetDefs()
{
	parent.LoadView("View=Resources%2FManage");
}

function ExportDeprec()
{
	if(parent){
		if(parent.m_objReportViewer){
			//parent.m_objReportViewer.setViewerType(1);
			parent.m_objReportViewer.ViewReportByID("3.10");
		}
	}
}

function MarkAssetsAsLost()
{
	if(GetSelectedRows()){
		//var strColVals=m_arrCheckedCols.join("<br />");
		var strColVals=m_arrCheckedCols.join("");
		
		var strMsg = g_MqRef.RESX["MSG_CONFIRM_MARK_LOST"] + "<br \><br \>" + strColVals;
		
		g_MqRef.ConfirmBox.show(g_MqRef.RESX["MSG_TITLE_LOST_ASSET"], strMsg).then(function(res)
		{
			if(res)
			{
				if (parent){
					var strIDs=m_arrCheckedIDs.join(";");
					var co = parent.objRequest.Get(parent.mstrCurrentLocation + "../ASP/SetLost.asp?IDs=" + strIDs);
					if (co!=""){
						if(parent.ToolBar){
							parent.ToolBar.submitinfo(null,true);
						}
					}
				}
			}
		});
	}
}

function ScrapAssets()
{
	if(GetSelectedRows()){
		//var strColVals=m_arrCheckedCols.join("<br />");
		var strColVals=m_arrCheckedCols.join("");
		
		var strMsg = "The following assets will be completely removed from Vizor.<br \><br \>" + strColVals + "<br \><br \>Are you sure you want to continue?";
		
		g_MqRef.ConfirmBox.show(g_MqRef.RESX["MSG_TITLE_SCRAP_ASSET"], strMsg).then(function(res)
		{
			if(res)
			{
				if (parent){
					var strIDs=m_arrCheckedIDs.join(";");
					var co = parent.objRequest.Get(parent.mstrCurrentLocation + "../ASP/SetScrapped.asp?IDs=" + strIDs);
					if (co!=""){
						if(parent.ToolBar){
							parent.ToolBar.submitinfo(null,true);
						}
					}
				}
			}
		});	
	}
}

function RequestAssetStatus()
{
	if(GetSelectedRows()){
		//var strColVals=m_arrCheckedCols.join("<br />");
		var strColVals=m_arrCheckedCols.join("");

		var strMsg = g_MqRef.RESX["MSG_CONFIRM_REQUEST_STATUS"] + "<br \><br \>" + strColVals;
		
		g_MqRef.ConfirmBox.show(g_MqRef.RESX["MSG_TITLE_REQUEST_ASSET_STATUS"], strMsg).then(function(res)
		{
			if(res)
			{
				if (parent){
					var strIDs=m_arrCheckedIDs.join(";");
					var co = parent.objRequest.Get(parent.mstrCurrentLocation + "../ASP/SetStatusRequested.asp?IDs=" + strIDs);
					if (co!=""){
						if(parent.ToolBar){
							parent.ToolBar.submitinfo(null,true);
						}
					}
				}
			}
		});	
	}	
}

var m_arrCheckedIDs = [];
var m_arrCheckedCols = [];


function GetSelectedRows()
{
	m_arrCheckedIDs.length=0;
	m_arrCheckedCols.length=0;
	
	if(mDataGrid){
		var lngLastCol=mDataGrid.getColumnsNum()-1;
		if(mDataGrid.getColType(lngLastCol)=="ch"){
			
			m_arrCheckedCols.push("<table style=\"color:#727272;width:100%;\">");
			mDataGrid.forEachRow(function(id){
				if (mDataGrid.cells(id,lngLastCol).getValue()=="0"){
				}else{
					m_arrCheckedIDs.push(id);
					//m_arrCheckedCols.push(GetGridValue("Serial_Number_", id));
					var col1 = mDataGrid.cells(id,1).getValue().replace(/<(?:.|\n)*?>/gm,"");
					var col2 = mDataGrid.cells(id,2).getValue().replace(/<(?:.|\n)*?>/gm,"");
					var col3 = mDataGrid.cells(id,3).getValue().replace(/<(?:.|\n)*?>/gm,"");
					m_arrCheckedCols.push("<tr><td style=\"font-weight:bold;padding-right:5px;\">" + col1 + "</td><td style=\"padding-left:5px;padding-right:5px;\">" + col2 + "</td><td style=\"padding-left:5px\">" + col3 + "</td></tr>");
				}
			});
			m_arrCheckedCols.push("</table>");
		}
	}	
	return true;
}


function GetGridValue(strTag, lngID)
{
	var strValue="";
	var objCell=document.getElementById(strTag+lngID);
	if(objCell){
		strValue=objCell.innerHTML;
	}
	return strValue;
}



function SyncChromeDevices()
{
	var url =location.protocol + "//" + location.hostname + "/connect/GSuite/ChomeOSDevicesToXML";
	window.open(url,"ChromebooksFrame","toolbar=no,resizable=yes,directories=no"  + parent.GetWinFeaturesToCenter(800, 600),true );
}
