2024-03-26 15:56:31 +08:00

1 line
140 KiB
JavaScript

function ShowEngineHours(n){var u=[],r,t,i;for(isCalampEH=!1,isPedigreeEH=!1,isOEMDD2EH=!1,primarydatadourcenameEH=undefined,primarydatadourceEH=undefined,r=0;r<n.length;r++){t=n[r];for(i in t)i==="IsPrimary"?t[i]=t[i]===!0?"Yes":"":i==="UOM"?t[i]="Hour":i==="AsofTimeLocal"&&(t[i]={DisplayValue:t.ReceivedDateStr,Value:t[i]});t.Hours={DisplayValue:t.Hours.toFixed(2),Value:t.Hours};t.Corrected={DisplayValue:t.Corrected.toFixed(2),Value:t.Corrected};u.push(t);t.DataSource.toLowerCase()=="calamp"&&t.IsPrimary.toLowerCase()=="yes"?isCalampEH=!0:t.DataSource.toLowerCase()=="pedigree"?(t.IsPrimary.toLowerCase()=="yes"&&t.SubSource.toLowerCase()!="totalenginehours"&&(isPedigreeEH=!0),t.SubSource.toLowerCase()=="totalenginehours"&&(t.DataSourceName="HOS")):t.DataSource.toLowerCase()=="oemdd2"&&t.IsPrimary.toLowerCase()=="yes"&&(isOEMDD2EH=!0);t.IsPrimary.toLowerCase()=="yes"&&(primarydatadourcenameEH=t.DataSourceName,primarydatadourceEH=t.DataSource)}grid_enginehoursdt.sortIndex=0;grid_enginehoursdt.sortDirection=-1;grid_enginehoursdt.setData(u);$("#enginehourslist").css("height",autoheight(grid_enginehoursdt));grid_enginehoursdt&&grid_enginehoursdt.resize();(IsSupperAdmin||isAllowed)&&(isCalampEH||isPedigreeEH||isOEMDD2EH)?($("#btnenginehoursadjust").css("display",""),$("#btnenginehourshistory").css("display","")):($("#btnenginehoursadjust").css("display","none"),$("#btnenginehourshistory").css("display","none"));primarydatadourcenameEH?($("#span_adjustenginehours").text(primarydatadourcenameEH),$("#span_addenginehours").text(primarydatadourcenameEH)):($("#span_adjustenginehours").text(GetTextByKey("P_MA_EMPTY","empty")),$("#span_addenginehours").text(GetTextByKey("P_MA_EMPTY","empty")))}function InitEnginehoursGridData(){var t,r,i,n;grid_enginehoursdt=createGridView("#enginehourslist");t=[{name:"IsPrimary",caption:GetTextByKey("P_MA_ISPRIMARY","Is Primary"),valueIndex:"IsPrimary",css:{width:80,"text-align":"left"}},{name:"DataSourceName",caption:GetTextByKey("P_MA_DATASOURCE","Data Source"),valueIndex:"DataSourceName",css:{width:120,"text-align":"left"}},{name:"Hours",caption:GetTextByKey("P_MA_ENGINEHOURS","Engine Hours"),valueIndex:"Hours",css:{width:90,"text-align":"left"}},{name:"Corrected",caption:GetTextByKey("P_MA_ADJUSTED","Adjusted"),valueIndex:"Corrected",css:{width:75,"text-align":"left"}},{name:"UOM",caption:GetTextByKey("P_MA_UNITS","Units"),valueIndex:"UOM",css:{width:60,"text-align":"left"}},{name:"ReceivedDate",caption:GetTextByKey("P_MA_RECEIVEDDATE","Received Date"),valueIndex:"AsofTimeLocal",css:{width:130,"text-align":"left"}},{name:"SetPrmary",caption:"",css:{width:30,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="SetPrmary"&&(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="key",n.events={onclick:function(){openSetPrimary(1,this)}},n.classFilter=function(){return"icon-col"},n.styleFilter=function(n){return{display:n.IsPrimary==="Yes"||!IsSupperAdmin&&!isAllowed?"none":""}},n.attrs={title:GetTextByKey("P_MA_SETASPRIMARY","Set As Primary")}),r.push(n);grid_enginehoursdt.multiSelect=!1;grid_enginehoursdt.columns=r;grid_enginehoursdt.init()}function InitMostRecentEnginehoursGridData(){var t,r,i,n;grid_enginehoursmostrecentdt=createGridView("#enginehoursmostrecent");t=[{name:"DeviceAirId",caption:GetTextByKey("P_MA_DEVICEAIRID","Device Air ID"),valueIndex:"DeviceAirId",css:{width:140,"text-align":"left"}},{name:"DeviceSN",caption:GetTextByKey("P_MA_DEVICESN","Device SN"),valueIndex:"DeviceSN",css:{width:140,"text-align":"left"}},{name:"SN",caption:GetTextByKey("P_MA_SN","SN"),valueIndex:"SN",css:{width:140,"text-align":"left"}},{name:"AsofTime",caption:GetTextByKey("P_MA_EVENTDATEUTC","Event Date(UTC)"),valueIndex:"EventTimeText",css:{width:130,"text-align":"left"}},{name:"AsofTimeLocal",caption:GetTextByKey("P_MA_EVENTDATE","Event Date"),valueIndex:"EventTimeLocalText",css:{width:130,"text-align":"left"}},{name:"VBUS",caption:GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"),valueIndex:"VBUS",css:{width:110,"text-align":"right"}},{name:"VBUS_Calc",caption:GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"),valueIndex:"VBUS_Calc",css:{width:120,"text-align":"right"}},{name:"Gps",caption:GetTextByKey("P_MA_GPSRAW","GPS(Raw)"),valueIndex:"Gps",css:{width:90,"text-align":"right"}},{name:"Gps_Calc",caption:GetTextByKey("P_MA_GPSCALC","GPS(Calc)"),valueIndex:"Gps_Calc",css:{width:90,"text-align":"right"}},{name:"Raw",caption:GetTextByKey("P_MA_RAW","Raw"),valueIndex:"Raw",css:{width:90,"text-align":"right"}},{name:"Calculated",caption:GetTextByKey("P_MA_CALCULATED","Calculated"),valueIndex:"Calculated",css:{width:90,"text-align":"right"}},{name:"Unit",caption:GetTextByKey("P_MA_UNIT","Unit"),valueIndex:"UOM",css:{width:60,"text-align":"right"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!1,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),r.push(n);grid_enginehoursmostrecentdt.multiSelect=!1;grid_enginehoursmostrecentdt.columns=r;grid_enginehoursmostrecentdt.init()}function InitEnginehoursHisGridData(){var t,r,i,n;grid_enginehourshisdt=createGridView("#enginehourshislist");t=[{name:"DeviceAirId",caption:GetTextByKey("P_MA_DEVICEAIRID","Device Air ID"),valueIndex:"DeviceAirId",css:{width:140,"text-align":"left"}},{name:"DeviceSN",caption:GetTextByKey("P_MA_DEVICESN","Device SN"),valueIndex:"DeviceSN",css:{width:140,"text-align":"left"}},{name:"SN",caption:GetTextByKey("P_MA_SN","SN"),valueIndex:"SN",css:{width:140,"text-align":"left"}},{name:"AsofTime",caption:GetTextByKey("P_MA_EVENTDATEUTC","Event Date(UTC)"),valueIndex:"EventTimeText",css:{width:130,"text-align":"left"}},{name:"AsofTimeLocal",caption:GetTextByKey("P_MA_EVENTDATE","Event Date"),valueIndex:"EventTimeLocalText",css:{width:130,"text-align":"left"}},{name:"VBUS",caption:GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"),valueIndex:"VBUS",css:{width:110,"text-align":"right"}},{name:"VBUS_Calc",caption:GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"),valueIndex:"VBUS_Calc",css:{width:120,"text-align":"right"}},{name:"Gps",caption:GetTextByKey("P_MA_GPSRAW","GPS(Raw)"),valueIndex:"Gps",css:{width:90,"text-align":"right"}},{name:"Gps_Calc",caption:GetTextByKey("P_MA_GPSCALC","GPS(Calc)"),valueIndex:"Gps_Calc",css:{width:90,"text-align":"right"}},{name:"Raw",caption:GetTextByKey("P_MA_RAW","Raw"),valueIndex:"Raw",css:{width:90,"text-align":"right"}},{name:"Calculated",caption:GetTextByKey("P_MA_CALCULATED","Calculated"),valueIndex:"Calculated",css:{width:90,"text-align":"right"}},{name:"Unit",caption:GetTextByKey("P_MA_UNIT","Unit"),valueIndex:"UOM",css:{width:60,"text-align":"right"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!1,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),r.push(n);grid_enginehourshisdt.multiSelect=!1;grid_enginehourshisdt.columns=r;grid_enginehourshisdt.init()}function getEnineHours(){showsubloading("adjustenginehoursmask",!0);grid_enginehoursdt.setData([]);devicerequest("GetAssetCurrentEngineHours",contractorid+String.fromCharCode(170)+machineid,function(n){if(showsubloading("adjustenginehoursmask",!1),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowEngineHours(n)},function(){showsubloading("adjustenginehoursmask",!1)})}function getEngineHoursHis(){var n,t;grid_enginehoursmostrecentdt.setData([]);grid_enginehourshisdt.setData([]);showsubloading("adjustenginehoursmask",!0);n="GetCalampEngineHoursHistory";isPedigreeEH&&(n="GetPedigreeEngineHoursHistory");isOEMDD2EH&&(n="GetOEMDD2EngineHoursHistory");t=$("#dialogadjust_enginehourstimezone").find("option:selected").val();devicerequest(n,contractorid+String.fromCharCode(170)+machineid+String.fromCharCode(170)+htmlencode(t),function(n){if(showsubloading("adjustenginehoursmask",!1),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowMostRecentEngineHours(n)},function(){showsubloading("adjustenginehoursmask",!1)})}function getEngineHoursHisPreview(){var n={CustomerID:contractorid,AssetID:machineid,EngineHours:$("#dialogenginehours_enginehours").val(),EngineHoursDate:$("#dialogenginehours_date").val(),Notes:$("#dialogenginehours_Notes").val()},t=GetTextByKey("P_MA_ADJUSTENGINEHOURS","Adjust Engine Hours"),i=GetTextByKey("P_MA_ENGINEHOURS","Engine Hours"),r,u,f;if(n.EngineHours!==""){if(isNaN(n.EngineHours)){showAlert(GetTextByKey("P_MA_FORMATERROR","{0} format error.").replace("{0}",i),t);return}if(n.EngineHours<=0){showAlert(GetTextByKey("P_MA_MUSTBEGREATERTHAN0","{0} must be greater than 0.").replace("{0}",i),t);return}}else{showAlert(GetTextByKey("P_MA_NOTBEEMPTY","{0} cannot be empty.").replace("{0}",i),t);return}if(n.EngineHoursDate===""){showAlert(GetTextByKey("P_MA_NOTBEEMPTY","{0} cannot be empty.").replace("{0}",i),t);return}r=$("#dialogadjust_enginehourstimezone").find("option:selected").attr("offset");n.OffsetMinute=r;n.TimeZone=$("#dialogadjust_enginehourstimezone").find("option:selected").val();u=$("#dialogenginehours_timehour").val();f=$("#dialogenginehours_timeminute").val();n.EngineHoursDate=n.EngineHoursDate.replace("-","/")+" "+u+":"+f+":00";CheckEngineHourMinimumTime(n,"preview")}function GetCalampEngineHoursHistoryPreview(n){var t,i;grid_enginehourshisdt.setData([]);showsubloading("adjustenginehoursmask",!0);t=JSON.stringify(n);t=htmlencode(t);i="GetCalampEngineHoursHistoryPreview";isPedigreeEH&&(i="GetPedigreeEngineHoursHistoryPreview");isOEMDD2EH&&(i="GetOEMDD2EngineHoursHistoryPreview");devicerequest(i,t,function(n){if(showsubloading("adjustenginehoursmask",!1),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowMostRecentEngineHoursPreview(n);ShowEngineHoursHis(n)},function(){showsubloading("adjustenginehoursmask",!1)})}function ShowMostRecentEngineHours(n){for(var i=[],t=0;t<n.length;t++){mostrecentrecord=n[t];i.push(mostrecentrecord);break}grid_enginehoursmostrecentdt.sortIndex=-1;grid_enginehoursmostrecentdt.sortDirection=-1;grid_enginehoursmostrecentdt.setData(i)}function ShowMostRecentEngineHoursPreview(n){var r,u,i,f,t;if(mostrecentrecord){for(r=0,u=0,i=0;i<n.length;i++){t=n[i];r=t.VBUS-t.VBUS_Calc;u=t.Gps-t.Gps_Calc;break}f=[];t=$.extend(!0,{},mostrecentrecord);n.length>0&&(t.AsofTime=n[0].AsofTime,t.AsofTimeLocal=n[0].AsofTimeLocal,t.EventTimeLocalText=n[0].EventTimeLocalText,t.EventTimeText=n[0].EventTimeText);t.VBUS_Calc=t.VBUS-r;t.VBUS_Calc={DisplayValue:t.VBUS_Calc.toFixed(2),Value:t.VBUS_Calc};t.Gps_Calc=t.Gps-u;t.Gps_Calc={DisplayValue:t.Gps_Calc.toFixed(2),Value:t.Gps_Calc};f.push(t);grid_enginehoursmostrecentdt.sortIndex=-1;grid_enginehoursmostrecentdt.sortDirection=-1;grid_enginehoursmostrecentdt.setData(f)}}function ShowEngineHoursHis(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];t.VBUS={DisplayValue:t.VBUS.toFixed(2),Value:t.VBUS};t.VBUS_Calc={DisplayValue:t.VBUS_Calc.toFixed(2),Value:t.VBUS_Calc};t.Gps={DisplayValue:t.Gps.toFixed(2),Value:t.Gps};t.Gps_Calc={DisplayValue:t.Gps_Calc.toFixed(2),Value:t.Gps_Calc};for(i in t)i==="EventTimeText"&&(t[i]={DisplayValue:t.EventTimeText,Value:t.AsofTime}),i==="EventTimeLocalText"&&(t[i]={DisplayValue:t.EventTimeLocalText,Value:t.AsofTimeLocal});u.push(t)}grid_enginehourshisdt.sortIndex=-1;grid_enginehourshisdt.sortDirection=-1;grid_enginehourshisdt.setData(u)}function openAdjustEngineHours(){grid_enginehoursmostrecentdt.columns[0].visible=isCalampEH;grid_enginehoursmostrecentdt.columns[1].visible=isPedigreeEH;grid_enginehoursmostrecentdt.columns[2].visible=isOEMDD2EH;grid_enginehoursmostrecentdt.columns[5].caption=isCalampEH?GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"):GetTextByKey("P_MA_PEDIGREERAW","Pedigree(Raw)");grid_enginehoursmostrecentdt.columns[6].caption=isCalampEH?GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"):GetTextByKey("P_MA_PEDIGREEADJUSTED","Pedigree(Adjusted)");grid_enginehoursmostrecentdt.columns[5].visible=isCalampEH||isPedigreeEH;grid_enginehoursmostrecentdt.columns[6].visible=isCalampEH||isPedigreeEH;grid_enginehoursmostrecentdt.columns[7].visible=isCalampEH;grid_enginehoursmostrecentdt.columns[8].visible=isCalampEH;grid_enginehoursmostrecentdt.columns[9].visible=isOEMDD2EH;grid_enginehoursmostrecentdt.columns[10].visible=isOEMDD2EH;grid_enginehoursmostrecentdt.init();grid_enginehourshisdt.columns[0].visible=isCalampEH;grid_enginehourshisdt.columns[1].visible=isPedigreeEH;grid_enginehourshisdt.columns[2].visible=isOEMDD2EH;grid_enginehourshisdt.columns[5].caption=isCalampEH?GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"):GetTextByKey("P_MA_PEDIGREERAW","Pedigree(Raw)");grid_enginehourshisdt.columns[6].caption=isCalampEH?GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"):GetTextByKey("P_MA_PEDIGREEADJUSTED","Pedigree(Adjusted)");grid_enginehourshisdt.columns[5].visible=isCalampEH||isPedigreeEH;grid_enginehourshisdt.columns[6].visible=isCalampEH||isPedigreeEH;grid_enginehourshisdt.columns[7].visible=isCalampEH;grid_enginehourshisdt.columns[8].visible=isCalampEH;grid_enginehourshisdt.columns[9].visible=isOEMDD2EH;grid_enginehourshisdt.columns[10].visible=isOEMDD2EH;grid_enginehourshisdt.init();var t=customerdatetime.split(" "),i=t[0],n=t[1].split(":"),r=n[0].length==1?"0"+n[0]:n[0],u=n[1];$("#dialogenginehours_enginehours").val("");$("#dialogadjust_enginehourstimezone").val(customertimezone?customertimezone:"UTC");$("#dialogenginehours_date").val(i);$("#dialogenginehours_timehour").val(r);$("#dialogenginehours_timeminute").val(u);$("#dialogenginehours_Notes").val("");$("#dialog_adjustenginehours .dialog-title span.title").text(GetTextByKey("P_MA_ADJUSTENGINEHOURS","Adjust Engine Hours"));showmaskbg(!0);$("#dialog_adjustenginehours").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_adjustenginehours").height())/3,left:(document.documentElement.clientWidth-$("#dialog_adjustenginehours").width())/2}).showDialogfixed();$("#dialogenginehours_enginehours").focus();getEngineHoursHis()}function OnAdjustEngineHours(){showsubmask("adjustenginehoursmask",!0);var n=GetTextByKey("P_MA_ADJUSTENGINEHOURS","Adjust Engine Hours"),t=GetTextByKey("P_MA_ENGINEHOURS","Engine Hours");showConfirm1(GetTextByKey("P_MA_DOYOUWANTADJUSTHOURS","Do you want to adjust the engine hours?"),n,function(){var i,r,u,f;if(showsubmask("adjustenginehoursmask",!1),i={CustomerID:contractorid,AssetID:machineid,EngineHours:$("#dialogenginehours_enginehours").val(),EngineHoursDate:$("#dialogenginehours_date").val(),Notes:$("#dialogenginehours_Notes").val(),DataSource:primarydatadourceEH},i.EngineHours!==""){if(isNaN(i.EngineHours)){showAlert(GetTextByKey("P_MA_FORMATERROR","{0} format error.").replace("{0}",t),n);showsubmask("adjustenginehoursmask",!1);return}if(i.EngineHours<=0){showAlert(GetTextByKey("P_MA_MUSTBEGREATERTHAN0","{0} must be greater than 0.").replace("{0}",t),n);showsubmask("adjustenginehoursmask",!1);return}}else{showAlert(GetTextByKey("P_MA_NOTBEEMPTY","{0} cannot be empty.").replace("{0}",t),n);showsubmask("adjustenginehoursmask",!1);return}if(i.EngineHoursDate===""){showAlert(GetTextByKey("P_MA_NOTBEEMPTY","{0} cannot be empty.").replace("{0}",t),n);showsubmask("adjustenginehoursmask",!1);return}r=$("#dialogadjust_enginehourstimezone").find("option:selected").attr("offset");i.OffsetMinute=r;i.TimeZone=$("#dialogadjust_enginehourstimezone").find("option:selected").val();u=$("#dialogenginehours_timehour").val();f=$("#dialogenginehours_timeminute").val();i.EngineHoursDate=i.EngineHoursDate.replace("-","/")+" "+u+":"+f+":00";CheckEngineHourMinimumTime(i,"submit")},function(){showsubmask("adjustenginehoursmask",!1)})}function CheckEngineHourMinimumTime(n,t){var i=JSON.stringify(n);i=htmlencode(i);devicerequest("CheckEngineHourMinimumTime",i,function(i){if(showsubmask("adjustenginehoursmask",!1),i>0){i==1?showAlert(GetTextByKey("P_MA_CHECKENGINEHOURSMINNIMUMTIME","The adjustment cannot be completed as provided. The engine hours reading date provided cannot be prior to initial telematic data available for the asset."),GetTextByKey("P_MA_ADJUSTENGINEHOURS","Adjust Engine Hours")):showAlert(GetTextByKey("P_MA_CHECKENGINEHOURSMINNIMUMTIME1","The adjustment cannot be completed as provided. The engine hours reading date provided must be prior to or equal to the latest telematic data available for the asset."),GetTextByKey("P_MA_ADJUSTENGINEHOURS","Adjust Engine Hours"));return}t==="submit"?SaveAdjustEngineHours(n):t==="preview"&&GetCalampEngineHoursHistoryPreview(n)},function(){showsubmask("adjustenginehoursmask",!1)})}function SaveAdjustEngineHours(n){var i,t;showsubloading("adjustenginehoursmask",!0);i=JSON.stringify(n);i=htmlencode(i);showsubloading("adjustenginehoursmask",!0);t=GetTextByKey("P_MA_ADJUSTENGINEHOURS",GetTextByKey("P_MA_ADJUSTENGINEHOURS","Adjust Engine Hours"));devicerequest("SaveAdjustEngineHours",i,function(n){showsubloading("adjustenginehoursmask",!1);n!=="OK"?showAlert(n,t):(getEnineHours(),getMachineInfo(),showAlert(GetTextByKey("P_MA_SUCCESSFULLY","{0} Successfully.").replace("{0}",t),t));$("#dialog_adjustenginehours").hideDialog();showmaskbg(!1)},function(n){console.log(n);showAlert(GetTextByKey("P_MA_FAILEDTO","Failed to {0}.").replace("{0}",t),t);showsubloading("adjustenginehoursmask",!1)})}function OnPreviewEngineHours(){getEngineHoursHisPreview()}function openAddEnginHours(){var t=customerdatetime.split(" "),i=t[0],n=t[1].split(":"),r=n[0].length==1?"0"+n[0]:n[0],u=n[1];$("#dialogaddgenginehours_enginehours").val("");$("#dialogadd_enginehourstimezone").val(customertimezone?customertimezone:"UTC");$("#dialogaddenginehours_date").val(i);$("#dialogaddenginehours_timehour").val(r);$("#dialogaddenginehours_timeminute").val(u);$("#dialogaddenginehours_Notes").val("");$("#dialog_addenginehours .dialog-title span.title").text(GetTextByKey("P_MA_ADDENGINEHOURS","Add Engine Hours"));showmaskbg(!0);$("#dialog_addenginehours").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_addenginehours").height())/3,left:(document.documentElement.clientWidth-$("#dialog_addenginehours").width())/2}).showDialogfixed();$("#dialogaddgenginehours_enginehours").focus()}function OnAddEngineHours(){showsubmask("addenginehoursmask",!0);var n=GetTextByKey("P_MA_ADDENGINEHOURS","Add Engine Hours"),t=GetTextByKey("P_MA_ENGINEHOURS","Engine Hours");showConfirm1(GetTextByKey("P_MA_DOYOUWANTTOADDTHEENGINEHOURS","Do you want to add the engine hours?"),n,function(){var i={CustomerID:contractorid,AssetID:machineid,EngineHours:$("#dialogaddgenginehours_enginehours").val(),EngineHoursDate:$("#dialogaddenginehours_date").val(),Notes:$("#dialogaddenginehours_Notes").val()},u,f,e,r;if(i.EngineHours!==""){if(isNaN(i.EngineHours)){showAlert(GetTextByKey("P_MA_FORMATERROR","{0} format error.").replace("{0}",t),n);showsubmask("addenginehoursmask",!1);return}if(i.EngineHours<=0){showAlert(GetTextByKey("P_MA_MUSTBEGREATERTHAN0","{0} must be greater than 0.").replace("{0}",t),n);showsubmask("addenginehoursmask",!1);return}}else{showAlert(GetTextByKey("P_MA_NOTBEEMPTY","{0} cannot be empty.").replace("{0}",t),n);showsubmask("addenginehoursmask",!1);return}if(i.EngineHoursDate===""){showAlert(GetTextByKey("P_MA_NOTBEEMPTY","{0} cannot be empty.").replace("{0}",t),n);showsubmask("addenginehoursmask",!1);return}u=$("#dialogadd_enginehourstimezone").find("option:selected").attr("offset");i.OffsetMinute=u;i.TimeZone=$("#dialogadd_enginehourstimezone").find("option:selected").val();f=$("#dialogaddenginehours_timehour").val();e=$("#dialogaddenginehours_timeminute").val();i.EngineHoursDate=i.EngineHoursDate.replace("-","/")+" "+f+":"+e+":00";r=JSON.stringify(i);r=htmlencode(r);showsubloading("addenginehoursmask",!0);devicerequest("AddManuallyInputEngineHours",r,function(t){showsubloading("addenginehoursmask",!1);t!=="OK"?(t==="Failed"&&(t=GetTextByKey("P_MA_FAILED","Failed")),showAlert(t,n)):(getEnineHours(),getMachineInfo(),showAlert(GetTextByKey("P_MA_SUCCESSFULLY","{0} Successfully.").replace("{0}",GetTextByKey("P_MA_ADDENGINEHOURS","Add Engine Hours")),n));$("#dialog_addenginehours").hideDialog();showmaskbg(!1)},function(t){console.log(t);showsubloading("addenginehoursmask",!1);showAlert(GetTextByKey("P_MA_FAILEDTO","Failed to {0}.").replace("{0}",GetTextByKey("P_MA_ADDENGINEHOURS","Add Engine Hours")),n)})},function(){showsubmask("addenginehoursmask",!1)})}function openEngineHoursAdjustHistory(){window.open("EngineHoursAdjustHistory.aspx?cid="+contractorid+"&mid="+machineid)}function ShowFuelRemainings(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="IsPrimary"?t[i]=t[i]===!0?"Yes":"":i==="Amount"?t[i]={DisplayValue:t.PercentText,Value:t.Amount}:i==="AsofTimeLocal"&&(t[i]={DisplayValue:t.ReceivedDateStr,Value:t[i]});u.push(t)}grid_fuelremainingdt.sortIndex=-1;grid_fuelremainingdt.sortDirection=-1;grid_fuelremainingdt.setData(u);$("#fuelremaininglist").css("height",autoheight(grid_fuelremainingdt));grid_fuelremainingdt&&grid_fuelremainingdt.resize();IsSupperAdmin&&!1?$("#btnfuelremainingadjust").css("display",""):$("#btnfuelremainingadjust").css("display","none")}function InitFuelRemainingGridData(){var t,r,i,n;grid_fuelremainingdt=createGridView("#fuelremaininglist");t=[{name:"IsPrimary",caption:GetTextByKey("P_MA_ISPRIMARY","Is Primary"),valueIndex:"IsPrimary",css:{width:80,"text-align":"left"}},{name:"DataSourceName",caption:GetTextByKey("P_MA_DATASOURCE","Data Source"),valueIndex:"DataSourceName",css:{width:120,"text-align":"left"}},{name:"Amount",caption:GetTextByKey("P_MA_FUELREMAINING","Fuel Remaining"),valueIndex:"Amount",css:{width:100,"text-align":"left"}},{name:"ReceivedDate",caption:GetTextByKey("P_MA_RECEIVEDDATE","Received Date"),valueIndex:"AsofTimeLocal",css:{width:130,"text-align":"left"}},{name:"SetPrmary",caption:"",css:{width:30,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="SetPrmary"&&(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="key",n.events={onclick:function(){openSetPrimary(5,this)}},n.classFilter=function(){return"icon-col"},n.styleFilter=function(n){return{display:n.IsPrimary==="Yes"?"none":""}},n.attrs={title:GetTextByKey("P_MA_SETASPRIMARY","Set As Primary")},n.visible=IsSupperAdmin),r.push(n);grid_fuelremainingdt.multiSelect=!1;grid_fuelremainingdt.columns=r;grid_fuelremainingdt.init()}function InitFuelRemainingHisGridData(){var t,r,i,n;grid_fuelremaininghisdt=createGridView("#fuelremaininghislist");t=[{name:"DeviceAirId",caption:GetTextByKey("P_MA_DEVICEAIRID","Device Air ID"),valueIndex:"DeviceAirId",css:{width:140,"text-align":"left"}},{name:"AsofTime",caption:GetTextByKey("P_MA_EVENTDATEUTC","Event Date(UTC)"),valueIndex:"EventTimeText",css:{width:130,"text-align":"left"}},{name:"AsofTime_local",caption:GetTextByKey("P_MA_EVENTDATE","Event Date"),valueIndex:"EventTimeLocalText",css:{width:130,"text-align":"left"}},{name:"VBUS",caption:GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"),valueIndex:"VBUS",css:{width:90,"text-align":"right"}},{name:"VBUS_Calc",caption:GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"),valueIndex:"VBUS_Calc",css:{width:90,"text-align":"right"}},{name:"Gps",caption:GetTextByKey("P_MA_GPSRAW","GPS(Raw)"),valueIndex:"Gps",css:{width:90,"text-align":"right"}},{name:"Gps_Calc",caption:GetTextByKey("P_MA_GPSCALC","GPS(Calc)"),valueIndex:"Gps_Calc",css:{width:90,"text-align":"right"}},{name:"Unit",caption:GetTextByKey("P_MA_UNIT","Unit"),valueIndex:"UOM",css:{width:60,"text-align":"right"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),r.push(n);grid_fuelremaininghisdt.multiSelect=!1;grid_fuelremaininghisdt.columns=r;grid_fuelremaininghisdt.init()}function getFuelRemainings(){grid_fuelremainingdt.setData([]);showLoading();devicerequest("GetAssetCurrentFuelRemaining",contractorid+String.fromCharCode(170)+machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowFuelRemainings(n)},function(){hideLoading()})}function getFuelRemainingHis(){grid_fuelremaininghisdt.setData([]);showLoading();devicerequest("GetCalampFuelRemainingHistory",contractorid+String.fromCharCode(170)+machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowFuelRemainingHis(n)},function(){hideLoading()})}function getFuelRemainingHisPreview(){var n={CustomerID:contractorid,AssetID:machineid,FuelRemaining:$("#dialogadjust_fuelremaining").val(),UOM:$("#dialogadjust_sel_fuelremaininguom").val(),FuelRemainingDate:$("#dialogadjust_fuelremainingdate").val(),Notes:$("#dialogadjust_notes").val()},t=GetTextByKey("P_MA_ADJUSTFUELREMAINING","Adjust FuelRemaining"),r,u,f,i;if(n.FuelRemaining!==""){if(isNaN(n.FuelRemaining)){showAlert(GetTextByKey("P_MA_FUELREMAININGFORMATERROR","FuelRemaining format error."),t);$("#adjustodomask").hide();return}if(n.FuelRemaining<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),t);$("#adjustodomask").hide();return}}else{showAlert(GetTextByKey("P_MA_FUELREMAININGCANNOTBEEMPTY","FuelRemaining cannot be empty."),t);$("#adjustodomask").hide();return}if(grid_fuelremaininghisdt.setData([]),showLoading(),n.FuelRemainingDate===""){showAlert(GetTextByKey("P_MA_FUELREMAININGDATACANNOTBEEMPTY","FuelRemaining date cannot be empty."),t);$("#adjustodomask").hide();hideLoading();return}r=$("#dialogadjust_fuelremainingtimezone").find("option:selected").attr("offset");n.OffsetMinute=r;u=$("#dialogadjust_timehour").val();f=$("#dialogadjust_timeminute").val();n.FuelRemainingDate=n.FuelRemainingDate.replace("-","/")+" "+u+":"+f+":00";i=JSON.stringify(n);i=htmlencode(i);devicerequest("GetCalampFuelRemainingHistoryPreview",i,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowFuelRemainingHis(n)},function(){hideLoading()})}function ShowFuelRemainingHis(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="EventTimeText"&&(t[i]={DisplayValue:t.EventTimeText,Value:t.AsofTime}),i==="EventTimeLocalText"&&(t[i]={DisplayValue:t.EventTimeLocalText,Value:t.AsofTime_Local});u.push(t)}grid_fuelremaininghisdt.sortIndex=-1;grid_fuelremaininghisdt.sortDirection=-1;grid_fuelremaininghisdt.setData(u)}function openAdjustFuelRemaining(){$("#dialogadjust_fuelremaining").val("");$("#dialogadjust_sel_fuelremaininguom").val("Mile");$("#dialogadjust_fuelremainingtimezone").val("UTC");$("#dialogadjust_fuelremainingdate").val(currentdate);$("#dialogadjust_timehour").val("00");$("#dialogadjust_timeminute").val("00");$("#dialogadjust_notes").val("");$("#dialog_adjustfuelremaining .dialog-title span.title").text(GetTextByKey("P_MA_ADJUSTFUELREMAINING","Adjust FuelRemaining"));showmaskbg(!0);$("#dialog_adjustfuelremaining").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_adjustfuelremaining").height())/3,left:(document.documentElement.clientWidth-$("#dialog_adjustfuelremaining").width())/2}).showDialog();$("#dialogadjust_fuelremaining").focus();getFuelRemainingHis()}function OnAdjustFuelRemaining(){$("#adjustodomask").show();var n=GetTextByKey("P_MA_ADJUSTFUELREMAINING","Adjust FuelRemaining");showConfirm(GetTextByKey("P_MA_DOYOUWANTTOADJUSTTHEFUELREMAINING","Do you want to adjust the fuelremaining?"),n,function(){var t={CustomerID:contractorid,AssetID:machineid,FuelRemaining:$("#dialogadjust_fuelremaining").val(),UOM:$("#dialogadjust_sel_fuelremaininguom").val(),FuelRemainingDate:$("#dialogadjust_fuelremainingdate").val(),Notes:$("#dialogadjust_notes").val()},r,u,f,i;if(t.FuelRemaining!==""){if(isNaN(t.FuelRemaining)){showAlert(GetTextByKey("P_MA_FUELREMAININGFORMATERROR","FuelRemaining format error."),n);$("#adjustodomask").hide();return}if(t.FuelRemaining<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),n);$("#adjustodomask").hide();return}}else{showAlert(GetTextByKey("P_MA_FUELREMAININGCANNOTBEEMPTY","FuelRemaining cannot be empty."),n);$("#adjustodomask").hide();return}if(t.FuelRemainingDate===""){showAlert(GetTextByKey("P_MA_FUELREMAININGDATACANNOTBEEMPTY","FuelRemaining cannot be empty."),n);$("#adjustodomask").hide();return}r=$("#dialogadjust_fuelremainingtimezone").find("option:selected").attr("offset");t.OffsetMinute=r;u=$("#dialogadjust_timehour").val();f=$("#dialogadjust_timeminute").val();t.FuelRemainingDate=t.FuelRemainingDate.replace("-","/")+" "+u+":"+f+":00";showloading(!0);i=JSON.stringify(t);i=htmlencode(i);devicerequest("SaveAdjustFuelRemaining",i,function(t){showloading(!1);t!=="OK"?showAlert(t,n):(getFuelRemainings(),showAlert(GetTextByKey("P_MA_ADJUSTFUELREMAININGSUCCESSFULLY","Adjust FuelRemaining Successfully."),n));$("#dialog_adjustfuelremaining").hideDialog();$("#adjustodomask").hide()},function(){showloading(!1);showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTFUELREMAINING","Failed to adjust FuelRemaining."),n);$("#adjustodomask").hide()})},function(){$("#adjustodomask").hide()})}function OnPreviewFuelRemaining(){getFuelRemainingHisPreview()}function ShowFueluseds(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="IsPrimary"?t[i]=t[i]===!0?"Yes":"":i==="AsofTimeLocal"&&(t[i]={DisplayValue:t.ReceivedDateStr,Value:t[i]});t.Amount={DisplayValue:t.Amount.toFixed(2),Value:t.Amount};u.push(t)}grid_fueluseddt.sortIndex=-1;grid_fueluseddt.sortDirection=-1;grid_fueluseddt.setData(u);$("#fuelusedlist").css("height",autoheight(grid_fueluseddt));grid_fueluseddt&&grid_fueluseddt.resize();IsSupperAdmin&&!1?$("#btnfuelusedadjust").css("display",""):$("#btnfuelusedadjust").css("display","none")}function InitFuelusedGridData(){var t,r,i,n;grid_fueluseddt=createGridView("#fuelusedlist");t=[{name:"IsPrimary",caption:GetTextByKey("P_MA_ISPRIMARY","Is Primary"),valueIndex:"IsPrimary",css:{width:80,"text-align":"left"}},{name:"DataSourceName",caption:GetTextByKey("P_MA_DATASOURCE","Data Source"),valueIndex:"DataSourceName",css:{width:120,"text-align":"left"}},{name:"Amount",caption:GetTextByKey("P_MA_FUELUSED","Fuel Used"),valueIndex:"Amount",css:{width:100,"text-align":"left"}},{name:"Units",caption:GetTextByKey("P_MA_UNITS","Units"),valueIndex:"UOM",css:{width:80,"text-align":"left"}},{name:"ReceivedDate",caption:GetTextByKey("P_MA_RECEIVEDDATE","Received Date"),valueIndex:"AsofTimeLocal",css:{width:130,"text-align":"left"}},{name:"SetPrmary",caption:"",css:{width:30,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="SetPrmary"&&(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="key",n.events={onclick:function(){openSetPrimary(4,this)}},n.classFilter=function(){return"icon-col"},n.styleFilter=function(n){return{display:n.IsPrimary==="Yes"?"none":""}},n.attrs={title:GetTextByKey("P_MA_SETASPRIMARY","Set As Primary")},n.visible=IsSupperAdmin),r.push(n);grid_fueluseddt.multiSelect=!1;grid_fueluseddt.columns=r;grid_fueluseddt.init()}function InitFuelusedHisGridData(){var t,r,i,n;grid_fuelusedhisdt=createGridView("#fuelusedhislist");t=[{name:"DeviceAirId",caption:GetTextByKey("P_MA_DEVICEAIRID","Device Air ID"),valueIndex:"DeviceAirId",css:{width:140,"text-align":"left"}},{name:"AsofTime",caption:GetTextByKey("P_MA_EVENTDATEUTC","Event Date(UTC)"),valueIndex:"EventTimeText",css:{width:130,"text-align":"left"}},{name:"AsofTime_local",caption:GetTextByKey("P_MA_EVENTDATE","Event Date"),valueIndex:"EventTimeLocalText",css:{width:130,"text-align":"left"}},{name:"VBUS",caption:GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"),valueIndex:"VBUS",css:{width:90,"text-align":"right"}},{name:"VBUS_Calc",caption:GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"),valueIndex:"VBUS_Calc",css:{width:90,"text-align":"right"}},{name:"Gps",caption:GetTextByKey("P_MA_GPSRAW","GPS(Raw)"),valueIndex:"Gps",css:{width:90,"text-align":"right"}},{name:"Gps_Calc",caption:GetTextByKey("P_MA_GPSCALC","GPS(Calc)"),valueIndex:"Gps_Calc",css:{width:90,"text-align":"right"}},{name:"Unit",caption:GetTextByKey("P_MA_UNIT","Unit"),valueIndex:"UOM",css:{width:60,"text-align":"right"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),r.push(n);grid_fuelusedhisdt.multiSelect=!1;grid_fuelusedhisdt.columns=r;grid_fuelusedhisdt.init()}function getFueluseds(){grid_fueluseddt.setData([]);showLoading();devicerequest("GetAssetCurrentFuelused",contractorid+String.fromCharCode(170)+machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowFueluseds(n)},function(){hideLoading()})}function getFuelusedHis(){grid_fuelusedhisdt.setData([]);showLoading();devicerequest("GetCalampFuelusedHistory",contractorid+String.fromCharCode(170)+machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowFuelusedHis(n)},function(){hideLoading()})}function getFuelusedHisPreview(){var n={CustomerID:contractorid,AssetID:machineid,Fuelused:$("#dialogadjust_fuelused").val(),UOM:$("#dialogadjust_sel_fueluseduom").val(),FuelusedDate:$("#dialogadjust_fueluseddate").val(),Notes:$("#dialogadjust_notes").val()},t=GetTextByKey("P_MA_ADJUSTFUELUSED","Adjust Fuelused"),r,u,f,i;if(n.Fuelused!==""){if(isNaN(n.Fuelused)){showAlert(GetTextByKey("P_MA_FUELUSEDFORMATERROR","Fuelused format error."),t);$("#adjustodomask").hide();return}if(n.Fuelused<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),t);$("#adjustodomask").hide();return}}else{showAlert(GetTextByKey("P_MA_FUELUSEDCANNOTBEEMPTY","Fuelused cannot be empty."),t);$("#adjustodomask").hide();return}if(grid_fuelusedhisdt.setData([]),showLoading(),n.FuelusedDate===""){showAlert(GetTextByKey("P_MA_FUELUSEDDATACANNOTBEEMPTY","Fuelused date cannot be empty."),t);$("#adjustodomask").hide();hideLoading();return}r=$("#dialogadjust_fuelusedtimezone").find("option:selected").attr("offset");n.OffsetMinute=r;u=$("#dialogadjust_timehour").val();f=$("#dialogadjust_timeminute").val();n.FuelusedDate=n.FuelusedDate.replace("-","/")+" "+u+":"+f+":00";i=JSON.stringify(n);i=htmlencode(i);devicerequest("GetCalampFuelusedHistoryPreview",i,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowFuelusedHis(n)},function(){hideLoading()})}function ShowFuelusedHis(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="EventTimeText"&&(t[i]={DisplayValue:t.EventTimeText,Value:t.AsofTime}),i==="EventTimeLocalText"&&(t[i]={DisplayValue:t.EventTimeLocalText,Value:t.AsofTime_Local});u.push(t)}grid_fuelusedhisdt.sortIndex=-1;grid_fuelusedhisdt.sortDirection=-1;grid_fuelusedhisdt.setData(u)}function openAdjustFuelused(){$("#dialogadjust_fuelused").val("");$("#dialogadjust_sel_fueluseduom").val("Mile");$("#dialogadjust_fuelusedtimezone").val("UTC");$("#dialogadjust_fueluseddate").val(currentdate);$("#dialogadjust_timehour").val("00");$("#dialogadjust_timeminute").val("00");$("#dialogadjust_notes").val("");$("#dialog_adjustfuelused .dialog-title span.title").text(GetTextByKey("P_MA_ADJUSTFUELUSED","Adjust Fuelused"));showmaskbg(!0);$("#dialog_adjustfuelused").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_adjustfuelused").height())/3,left:(document.documentElement.clientWidth-$("#dialog_adjustfuelused").width())/2}).showDialog();$("#dialogadjust_fuelused").focus();getFuelusedHis()}function OnAdjustFuelused(){$("#adjustodomask").show();var n=GetTextByKey("P_MA_ADJUSTFUELUSED","Adjust Fuelused");showConfirm(GetTextByKey("P_MA_DOYOUWANTTOADJUSTTHEFUELUSED","Do you want to adjust the fuelused?"),n,function(){var t={CustomerID:contractorid,AssetID:machineid,Fuelused:$("#dialogadjust_fuelused").val(),UOM:$("#dialogadjust_sel_fueluseduom").val(),FuelusedDate:$("#dialogadjust_fueluseddate").val(),Notes:$("#dialogadjust_notes").val()},r,u,f,i;if(t.Fuelused!==""){if(isNaN(t.Fuelused)){showAlert(GetTextByKey("P_MA_FUELUSEDFORMATERROR","Fuelused format error."),n);$("#adjustodomask").hide();return}if(t.Fuelused<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),n);$("#adjustodomask").hide();return}}else{showAlert(GetTextByKey("P_MA_FUELUSEDCANNOTBEEMPTY","Fuelused cannot be empty."),n);$("#adjustodomask").hide();return}if(t.FuelusedDate===""){showAlert(GetTextByKey("P_MA_FUELUSEDDATACANNOTBEEMPTY","Fuelused cannot be empty."),n);$("#adjustodomask").hide();return}r=$("#dialogadjust_fuelusedtimezone").find("option:selected").attr("offset");t.OffsetMinute=r;u=$("#dialogadjust_timehour").val();f=$("#dialogadjust_timeminute").val();t.FuelusedDate=t.FuelusedDate.replace("-","/")+" "+u+":"+f+":00";showloading(!0);i=JSON.stringify(t);i=htmlencode(i);devicerequest("SaveAdjustFuelused",i,function(t){showloading(!1);t!=="OK"?showAlert(t,n):(getFueluseds(),showAlert(GetTextByKey("P_MA_ADJUSTFUELUSEDSUCCESSFULLY","Adjust Fuelused Successfully."),n));$("#dialog_adjustfuelused").hideDialog();$("#adjustodomask").hide()},function(){showloading(!1);showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTFUELUSED","Failed to adjust Fuelused."),n);$("#adjustodomask").hide()})},function(){$("#adjustodomask").hide()})}function OnPreviewFuelused(){getFuelusedHisPreview()}function ShowIdlehours(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="IsPrimary"?t[i]=t[i]===!0?"Yes":"":i==="UOM"?t[i]="Hour":i==="AsofTimeLocal"&&(t[i]={DisplayValue:t.ReceivedDateStr,Value:t[i]});t.Hours={DisplayValue:t.Hours.toFixed(2),Value:t.Hours};u.push(t)}grid_idlehourdt.sortIndex=-1;grid_idlehourdt.sortDirection=-1;grid_idlehourdt.setData(u);$("#idlehourlist").css("height",autoheight(grid_idlehourdt));grid_idlehourdt&&grid_idlehourdt.resize();IsSupperAdmin&&!1?$("#btnidlehouradjust").css("display",""):$("#btnidlehouradjust").css("display","none")}function InitIdlehourGridData(){var t,r,i,n;grid_idlehourdt=createGridView("#idlehourlist");t=[{name:"IsPrimary",caption:GetTextByKey("P_MA_ISPRIMARY","Is Primary"),valueIndex:"IsPrimary",css:{width:80,"text-align":"left"}},{name:"DataSourceName",caption:GetTextByKey("P_MA_DATASOURCE","Data Source"),valueIndex:"DataSourceName",css:{width:120,"text-align":"left"}},{name:"Hours",caption:GetTextByKey("P_MA_IDLEHOURS","Idle Hours"),valueIndex:"Hours",css:{width:80,"text-align":"left"}},{name:"Units",caption:GetTextByKey("P_MA_UNITS","Units"),valueIndex:"UOM",css:{width:80,"text-align":"left"}},{name:"ReceivedDate",caption:GetTextByKey("P_MA_RECEIVEDDATE","Received Date"),valueIndex:"AsofTimeLocal",css:{width:130,"text-align":"left"}},{name:"SetPrmary",caption:"",css:{width:30,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="SetPrmary"&&(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="key",n.events={onclick:function(){openSetPrimary(3,this)}},n.classFilter=function(){return"icon-col"},n.styleFilter=function(n){return{display:n.IsPrimary==="Yes"?"none":""}},n.attrs={title:GetTextByKey("P_MA_SETASPRIMARY","Set As Primary")},n.visible=IsSupperAdmin),r.push(n);grid_idlehourdt.multiSelect=!1;grid_idlehourdt.columns=r;grid_idlehourdt.init()}function InitIdlehourHisGridData(){var t,r,i,n;grid_idlehourhisdt=createGridView("#idlehourhislist");t=[{name:"DeviceAirId",caption:GetTextByKey("P_MA_DEVICEAIRID","Device Air ID"),valueIndex:"DeviceAirId",css:{width:140,"text-align":"left"}},{name:"AsofTime",caption:GetTextByKey("P_MA_EVENTDATEUTC","Event Date(UTC)"),valueIndex:"EventTimeText",css:{width:130,"text-align":"left"}},{name:"AsofTime_local",caption:GetTextByKey("P_MA_EVENTDATE","Event Date"),valueIndex:"EventTimeLocalText",css:{width:130,"text-align":"left"}},{name:"VBUS",caption:GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"),valueIndex:"VBUS",css:{width:90,"text-align":"right"}},{name:"VBUS_Calc",caption:GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"),valueIndex:"VBUS_Calc",css:{width:90,"text-align":"right"}},{name:"Gps",caption:GetTextByKey("P_MA_GPSRAW","GPS(Raw)"),valueIndex:"Gps",css:{width:90,"text-align":"right"}},{name:"Gps_Calc",caption:GetTextByKey("P_MA_GPSCALC","GPS(Calc)"),valueIndex:"Gps_Calc",css:{width:90,"text-align":"right"}},{name:"Unit",caption:GetTextByKey("P_MA_UNIT","Unit"),valueIndex:"UOM",css:{width:60,"text-align":"right"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),r.push(n);grid_idlehourhisdt.multiSelect=!1;grid_idlehourhisdt.columns=r;grid_idlehourhisdt.init()}function getIdlehours(){grid_idlehourdt.setData([]);showLoading();devicerequest("GetAssetCurrentIdlehours",contractorid+String.fromCharCode(170)+machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowIdlehours(n)},function(){hideLoading()})}function getIdlehourHis(){grid_idlehourhisdt.setData([]);showLoading();devicerequest("GetCalampIdlehourHistory",contractorid+String.fromCharCode(170)+machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowIdlehourHis(n)},function(){hideLoading()})}function getIdlehourHisPreview(){var n={CustomerID:contractorid,AssetID:machineid,Idlehour:$("#dialogadjust_idlehour").val(),UOM:$("#dialogadjust_sel_idlehouruom").val(),IdlehourDate:$("#dialogadjust_idlehourdate").val(),Notes:$("#dialogadjust_notes").val()},t=GetTextByKey("P_MA_ADJUSTIDLEHOUR","Adjust Idlehour"),r,u,f,i;if(n.Idlehour!==""){if(isNaN(n.Idlehour)){showAlert(GetTextByKey("P_MA_IDLEHOURFORMAERROR","Idlehour format error."),t);$("#adjustodomask").hide();return}if(n.Idlehour<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),t);$("#adjustodomask").hide();return}}else{showAlert(GetTextByKey("P_MA_IDLEHOURCANNOTBEEMPTY","Idlehour cannot be empty."),t);$("#adjustodomask").hide();return}if(grid_idlehourhisdt.setData([]),showLoading(),n.IdlehourDate===""){showAlert(GetTextByKey("P_MA_IDLEHOURDATACANNOTBEEMPTY","Idlehour date cannot be empty."),t);$("#adjustodomask").hide();hideLoading();return}r=$("#dialogadjust_idlehourtimezone").find("option:selected").attr("offset");n.OffsetMinute=r;u=$("#dialogadjust_timehour").val();f=$("#dialogadjust_timeminute").val();n.IdlehourDate=n.IdlehourDate.replace("-","/")+" "+u+":"+f+":00";i=JSON.stringify(n);i=htmlencode(i);devicerequest("GetCalampIdlehourHistoryPreview",i,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowIdlehourHis(n)},function(){hideLoading()})}function ShowIdlehourHis(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="EventTimeText"&&(t[i]={DisplayValue:t.EventTimeText,Value:t.AsofTime}),i==="EventTimeLocalText"&&(t[i]={DisplayValue:t.EventTimeLocalText,Value:t.AsofTime_Local});u.push(t)}grid_idlehourhisdt.sortIndex=-1;grid_idlehourhisdt.sortDirection=-1;grid_idlehourhisdt.setData(u)}function openAdjustIdlehour(){$("#dialogadjust_idlehour").val("");$("#dialogadjust_sel_idlehouruom").val("Mile");$("#dialogadjust_idlehourtimezone").val("UTC");$("#dialogadjust_idlehourdate").val(currentdate);$("#dialogadjust_timehour").val("00");$("#dialogadjust_timeminute").val("00");$("#dialogadjust_notes").val("");$("#dialog_adjustidlehour .dialog-title span.title").text(GetTextByKey("P_MA_ADJUSTIDLEHOUR","Adjust Idlehour"));showmaskbg(!0);$("#dialog_adjustidlehour").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_adjustidlehour").height())/3,left:(document.documentElement.clientWidth-$("#dialog_adjustidlehour").width())/2}).showDialog();$("#dialogadjust_idlehour").focus();getIdlehourHis()}function OnAdjustIdlehour(){var n=GetTextByKey("P_MA_ADJUSTIDLEHOUR","Adjust Idlehour");$("#adjustodomask").show();showConfirm("Do you want to adjust the idlehour?",n,function(){var t={CustomerID:contractorid,AssetID:machineid,Idlehour:$("#dialogadjust_idlehour").val(),UOM:$("#dialogadjust_sel_idlehouruom").val(),IdlehourDate:$("#dialogadjust_idlehourdate").val(),Notes:$("#dialogadjust_notes").val()},r,u,f,i;if(t.Idlehour!==""){if(isNaN(t.Idlehour)){showAlert(GetTextByKey("P_MA_IDLEHOURFORMAERROR","Idlehour format error."),n);$("#adjustodomask").hide();return}if(t.Idlehour<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),n);$("#adjustodomask").hide();return}}else{showAlert(GetTextByKey("P_MA_IDLEHOURCANNOTBEEMPTY","Idlehour cannot be empty."),n);$("#adjustodomask").hide();return}if(t.IdlehourDate===""){showAlert(GetTextByKey("P_MA_IDLEHOURDATACANNOTBEEMPTY","Idlehour date cannot be empty."),n);$("#adjustodomask").hide();return}r=$("#dialogadjust_idlehourtimezone").find("option:selected").attr("offset");t.OffsetMinute=r;u=$("#dialogadjust_timehour").val();f=$("#dialogadjust_timeminute").val();t.IdlehourDate=t.IdlehourDate.replace("-","/")+" "+u+":"+f+":00";showloading(!0);i=JSON.stringify(t);i=htmlencode(i);devicerequest("SaveAdjustIdlehour",i,function(t){showloading(!1);t!=="OK"?showAlert(t,n):(getIdlehours(),showAlert(GetTextByKey("P_MA_ADJUSTIDLEHOURSUCCESSFULLY","Adjust Idlehour Successfully."),n));$("#dialog_adjustidlehour").hideDialog();$("#adjustodomask").hide()},function(){showloading(!1);showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTIDLEHOUR","Failed to adjust Idlehour."),n);$("#adjustodomask").hide()})},function(){$("#adjustodomask").hide()})}function OnPreviewIdlehour(){getIdlehourHisPreview()}function ShowLocations(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="IsPrimary"?t[i]=t[i]===!0?"Yes":"":i==="AsofTimeLocal"&&(t[i]={DisplayValue:t.ReceivedDateStr,Value:t[i]});u.push(t)}grid_locationdt.sortIndex=-1;grid_locationdt.sortDirection=-1;grid_locationdt.setData(u);$("#locationlist").css("height",autoheight(grid_locationdt));grid_locationdt&&grid_locationdt.resize();IsSupperAdmin&&!1?$("#btnlocationadjust").css("display",""):$("#btnlocationadjust").css("display","none")}function InitLocationGridData(){var t,r,i,n;grid_locationdt=createGridView("#locationlist");t=[{name:"IsPrimary",caption:GetTextByKey("P_MA_ISPRIMARY","Is Primary"),valueIndex:"IsPrimary",css:{width:80,"text-align":"left"}},{name:"DataSourceName",caption:GetTextByKey("P_MA_DATASOURCE","Data Source"),valueIndex:"DataSourceName",css:{width:120,"text-align":"left"}},{name:"Longitude",caption:GetTextByKey("P_MA_LONGITUDE","Longitude"),valueIndex:"Longitude",css:{width:90,"text-align":"left"}},{name:"Latitude",caption:GetTextByKey("P_MA_LATITUDE","Latitude"),valueIndex:"Latitude",css:{width:90,"text-align":"left"}},{name:"ReceivedDate",caption:GetTextByKey("P_MA_RECEIVEDDATE","Received Date"),valueIndex:"AsofTimeLocal",css:{width:130,"text-align":"left"}},{name:"SetPrmary",caption:"",css:{width:30,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="SetPrmary"&&(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="key",n.events={onclick:function(){openSetPrimary(2,this)}},n.classFilter=function(){return"icon-col"},n.styleFilter=function(n){return{display:n.IsPrimary==="Yes"?"none":""}},n.attrs={title:GetTextByKey("P_MA_SETASPRIMARY","Set As Primary")},n.visible=IsSupperAdmin),r.push(n);grid_locationdt.multiSelect=!1;grid_locationdt.columns=r;grid_locationdt.init()}function InitLocationHisGridData(){var t,r,i,n;grid_locationhisdt=createGridView("#locationhislist");t=[{name:"DeviceAirId",caption:GetTextByKey("P_MA_DEVICEAIRID","Device Air ID"),valueIndex:"DeviceAirId",css:{width:140,"text-align":"left"}},{name:"AsofTime",caption:GetTextByKey("P_MA_EVENTDATEUTC","Event Date(UTC)"),valueIndex:"EventTimeText",css:{width:130,"text-align":"left"}},{name:"AsofTime_local",caption:GetTextByKey("P_MA_EVENTDATE","Event Date"),valueIndex:"EventTimeLocalText",css:{width:130,"text-align":"left"}},{name:"VBUS",caption:GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"),valueIndex:"VBUS",css:{width:90,"text-align":"right"}},{name:"VBUS_Calc",caption:GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"),valueIndex:"VBUS_Calc",css:{width:90,"text-align":"right"}},{name:"Gps",caption:GetTextByKey("P_MA_GPSRAW","GPS(Raw)"),valueIndex:"Gps",css:{width:90,"text-align":"right"}},{name:"Gps_Calc",caption:GetTextByKey("P_MA_GPSCALC","GPS(Calc)"),valueIndex:"Gps_Calc",css:{width:90,"text-align":"right"}},{name:"Unit",caption:GetTextByKey("P_MA_UNIT","Unit"),valueIndex:"UOM",css:{width:60,"text-align":"right"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),r.push(n);grid_locationhisdt.multiSelect=!1;grid_locationhisdt.columns=r;grid_locationhisdt.init()}function getLocations(){grid_locationdt.setData([]);showLoading();devicerequest("GetAssetCurrentLocation",contractorid+String.fromCharCode(170)+machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowLocations(n)},function(){hideLoading()})}function getLocationHis(){grid_locationhisdt.setData([]);showLoading();devicerequest("GetCalampLocationHistory",contractorid+String.fromCharCode(170)+machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowLocationHis(n)},function(){hideLoading()})}function getLocationHisPreview(){var n={CustomerID:contractorid,AssetID:machineid,Location:$("#dialogadjust_location").val(),UOM:$("#dialogadjust_sel_locationuom").val(),LocationDate:$("#dialogadjust_locationdate").val(),Notes:$("#dialogadjust_notes").val()},t=GetTextByKey("P_MA_ADJUSTLOCATION","Adjust Location"),r,u,f,i;if(n.Location!==""){if(isNaN(n.Location)){showAlert(GetTextByKey("P_MA_LOCATIONFORMAERROR","Location format error."),t);$("#adjustodomask").hide();return}if(n.Location<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),t);$("#adjustodomask").hide();return}}else{showAlert(GetTextByKey("P_MA_LOCATIONCANNOTBEEMPTY","Location cannot be empty."),t);$("#adjustodomask").hide();return}if(grid_locationhisdt.setData([]),showLoading(),n.LocationDate===""){showAlert(GetTextByKey("P_MA_LOCATIONDATACANNOTBEEMPTY","Location date cannot be empty."),t);$("#adjustodomask").hide();hideLoading();return}r=$("#dialogadjust_locationtimezone").find("option:selected").attr("offset");n.OffsetMinute=r;u=$("#dialogadjust_timehour").val();f=$("#dialogadjust_timeminute").val();n.LocationDate=n.LocationDate.replace("-","/")+" "+u+":"+f+":00";i=JSON.stringify(n);i=htmlencode(i);devicerequest("GetCalampLocationHistoryPreview",i,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowLocationHis(n)},function(){hideLoading()})}function ShowLocationHis(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="EventTimeText"&&(t[i]={DisplayValue:t.EventTimeText,Value:t.AsofTime}),i==="EventTimeLocalText"&&(t[i]={DisplayValue:t.EventTimeLocalText,Value:t.AsofTime_Local});u.push(t)}grid_locationhisdt.sortIndex=-1;grid_locationhisdt.sortDirection=-1;grid_locationhisdt.setData(u)}function openAdjustLocation(){$("#dialogadjust_location").val("");$("#dialogadjust_sel_locationuom").val("Mile");$("#dialogadjust_locationtimezone").val("UTC");$("#dialogadjust_locationdate").val(currentdate);$("#dialogadjust_timehour").val("00");$("#dialogadjust_timeminute").val("00");$("#dialogadjust_notes").val("");$("#dialog_adjustlocation .dialog-title span.title").text(GetTextByKey("P_MA_ADJUSTLOCATION","Adjust Location"));showmaskbg(!0);$("#dialog_adjustlocation").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_adjustlocation").height())/3,left:(document.documentElement.clientWidth-$("#dialog_adjustlocation").width())/2}).showDialog();$("#dialogadjust_location").focus();getLocationHis()}function OnAdjustLocation(){$("#adjustodomask").show();var n=GetTextByKey("P_MA_ADJUSTLOCATION","Adjust Location");showConfirm("Do you want to adjust the location?",n,function(){var t={CustomerID:contractorid,AssetID:machineid,Location:$("#dialogadjust_location").val(),UOM:$("#dialogadjust_sel_locationuom").val(),LocationDate:$("#dialogadjust_locationdate").val(),Notes:$("#dialogadjust_notes").val()},r,u,f,i;if(t.Location!==""){if(isNaN(t.Location)){showAlert(GetTextByKey("P_MA_LOCATIONFORMAERROR","Location format error."),n);$("#adjustodomask").hide();return}if(t.Location<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),n);$("#adjustodomask").hide();return}}else{showAlert(GetTextByKey("P_MA_LOCATIONCANNOTBEEMPTY","Location cannot be empty."),n);$("#adjustodomask").hide();return}if(t.LocationDate===""){showAlert(GetTextByKey("P_MA_LOCATIONDATACANNOTBEEMPTY","Location date cannot be empty."),n);$("#adjustodomask").hide();return}r=$("#dialogadjust_locationtimezone").find("option:selected").attr("offset");t.OffsetMinute=r;u=$("#dialogadjust_timehour").val();f=$("#dialogadjust_timeminute").val();t.LocationDate=t.LocationDate.replace("-","/")+" "+u+":"+f+":00";showloading(!0);i=JSON.stringify(t);i=htmlencode(i);devicerequest("SaveAdjustLocation",i,function(t){showloading(!1);t!=="OK"?showAlert(t,n):(getLocations(),showAlert(GetTextByKey("P_MA_ADJUSTLOCATIONSUCCESSFULLY","Adjust Location Successfully."),n));$("#dialog_adjustlocation").hideDialog();$("#adjustodomask").hide()},function(){showloading(!1);showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTLOCATION","Failed to adjust Location."),n);$("#adjustodomask").hide()})},function(){$("#adjustodomask").hide()})}function OnPreviewLocation(){getLocationHisPreview()}function ShowOdometers(n){var u=[],r,t,i;for(isCalampOdo=!1,isPedigreeOdo=!1,isSmartWitness=!1,primarydatadourcenameOdo=undefined,primarydatadourceOdo=undefined,r=0;r<n.length;r++){t=n[r];for(i in t)i==="IsPrimary"?t[i]=t[i]===!0?"Yes":"":i==="AsofTimeLocal"&&(t[i]={DisplayValue:t.ReceivedDateStr,Value:t[i]});t.Odometer={DisplayValue:t.Odometer.toFixed(2),Value:t.Odometer};t.Corrected={DisplayValue:t.Corrected.toFixed(2),Value:t.Corrected};u.push(t);t.DataSource.toLowerCase()=="calamp"&&t.IsPrimary.toLowerCase()=="yes"?isCalampOdo=!0:t.DataSource.toLowerCase()=="pedigree"?(t.IsPrimary.toLowerCase()=="yes"&&t.SubSource.toLowerCase()!="odometer"&&(isPedigreeOdo=!0),t.SubSource.toLowerCase()=="odometer"&&(t.DataSourceName="HOS")):t.DataSource.toLowerCase()=="smartwitness"&&t.IsPrimary.toLowerCase()=="yes"&&(isSmartWitness=!0);t.IsPrimary.toLowerCase()=="yes"&&(primarydatadourcenameOdo=t.DataSourceName,primarydatadourceOdo=t.DataSource)}grid_odometerdt.sortIndex=-1;grid_odometerdt.sortDirection=-1;grid_odometerdt.setData(u);$("#odometerlist").css("height",autoheight(grid_odometerdt));grid_odometerdt&&grid_odometerdt.resize();(IsSupperAdmin||isAllowed)&&(isCalampOdo||isPedigreeOdo||isSmartWitness)?($("#btnodometeradjust").css("display",""),$("#btnodometerhistory").css("display","")):($("#btnodometeradjust").css("display","none"),$("#btnodometerhistory").css("display","none"));primarydatadourcenameOdo?($("#span_adjustodometer").text(primarydatadourcenameOdo),$("#span_addodometer").text(primarydatadourcenameOdo)):($("#span_adjustodometer").text("empty"),$("#span_addodometer").text("empty"))}function InitOdometerGridData(){var t,r,i,n;grid_odometerdt=createGridView("#odometerlist");t=[{name:"IsPrimary",caption:GetTextByKey("P_MA_ISPRIMARY","Is Primary"),valueIndex:"IsPrimary",css:{width:80,"text-align":"left"}},{name:"DataSourceName",caption:GetTextByKey("P_MA_DATASOURCE","Data Source"),valueIndex:"DataSourceName",css:{width:120,"text-align":"left"}},{name:"Odometer",caption:GetTextByKey("P_MA_ODOMETER","Odometer"),valueIndex:"Odometer",css:{width:80,"text-align":"left"}},{name:"Corrected",caption:GetTextByKey("P_MA_ADJUSTED","Adjusted"),valueIndex:"Corrected",css:{width:75,"text-align":"left"}},{name:"UOM",caption:GetTextByKey("P_MA_UNITS","Units"),valueIndex:"UOM",css:{width:60,"text-align":"left"}},{name:"ReceivedDate",caption:GetTextByKey("P_MA_RECEIVEDDATE","Received Date"),valueIndex:"AsofTimeLocal",css:{width:130,"text-align":"left"}},{name:"SetPrmary",caption:"",css:{width:30,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="SetPrmary"&&(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="key",n.events={onclick:function(){openSetPrimary(0,this)}},n.classFilter=function(){return"icon-col"},n.styleFilter=function(n){return{display:n.IsPrimary==="Yes"||!IsSupperAdmin&&!isAllowed?"none":""}},n.attrs={title:GetTextByKey("P_MA_SETASPRIMARY","Set As Primary")}),r.push(n);grid_odometerdt.multiSelect=!1;grid_odometerdt.columns=r;grid_odometerdt.init()}function InitOdometerMostRecentGridData(){var t,r,i,n;grid_odometermostrecentdt=createGridView("#odometermostrecent");t=[{name:"DeviceAirId",caption:GetTextByKey("P_MA_DEVICEAIRID","Device Air ID"),valueIndex:"DeviceAirId",css:{width:140,"text-align":"left"}},{name:"DeviceSN",caption:GetTextByKey("P_MA_DEVICESN","Device SN"),valueIndex:"DeviceSN",css:{width:140,"text-align":"left"}},{name:"AsofTime",caption:GetTextByKey("P_MA_EVENTDATEUTC","Event Date(UTC)"),valueIndex:"EventTimeText",css:{width:130,"text-align":"left"}},{name:"AsofTime_local",caption:GetTextByKey("P_MA_EVENTDATE","Event Date"),valueIndex:"EventTimeLocalText",css:{width:130,"text-align":"left"}},{name:"VBUS",caption:GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"),valueIndex:"VBUS",css:{width:90,"text-align":"right"}},{name:"VBUS_Calc",caption:GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"),valueIndex:"VBUS_Calc",css:{width:110,"text-align":"right"}},{name:"Gps",caption:GetTextByKey("P_MA_GPSRAW","GPS(Raw)"),valueIndex:"Gps",css:{width:110,"text-align":"right"}},{name:"Gps_Calc",caption:GetTextByKey("P_MA_GPSCALC","GPS(Calc)"),valueIndex:"Gps_Calc",css:{width:130,"text-align":"right"}},{name:"Unit",caption:GetTextByKey("P_MA_UNIT","Unit"),valueIndex:"UOM",css:{width:60,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!1,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),r.push(n);grid_odometermostrecentdt.multiSelect=!1;grid_odometermostrecentdt.columns=r;grid_odometermostrecentdt.init()}function InitOdometerHisGridData(){var t,r,i,n;grid_odometerhisdt=createGridView("#odometerhislist");t=[{name:"DeviceAirId",caption:GetTextByKey("P_MA_DEVICEAIRID","Device Air ID"),valueIndex:"DeviceAirId",css:{width:140,"text-align":"left"}},{name:"DeviceSN",caption:GetTextByKey("P_MA_DEVICESN","Device SN"),valueIndex:"DeviceSN",css:{width:140,"text-align":"left"}},{name:"AsofTime",caption:GetTextByKey("P_MA_EVENTDATEUTC","Event Date(UTC)"),valueIndex:"EventTimeText",css:{width:130,"text-align":"left"}},{name:"AsofTime_local",caption:GetTextByKey("P_MA_EVENTDATE","Event Date"),valueIndex:"EventTimeLocalText",css:{width:130,"text-align":"left"}},{name:"VBUS",caption:GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"),valueIndex:"VBUS",css:{width:90,"text-align":"right"}},{name:"VBUS_Calc",caption:GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"),valueIndex:"VBUS_Calc",css:{width:110,"text-align":"right"}},{name:"Gps",caption:GetTextByKey("P_MA_GPSRAW","GPS(Raw)"),valueIndex:"Gps",css:{width:110,"text-align":"right"}},{name:"Gps_Calc",caption:GetTextByKey("P_MA_GPSCALC","GPS(Calc)"),valueIndex:"Gps_Calc",css:{width:130,"text-align":"right"}},{name:"Unit",caption:GetTextByKey("P_MA_UNIT","Unit"),valueIndex:"UOM",css:{width:60,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!1,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),r.push(n);grid_odometerhisdt.multiSelect=!1;grid_odometerhisdt.columns=r;grid_odometerhisdt.init()}function getOdometers(){grid_odometerdt.setData([]);showsubloading("adjustodomask",!0);devicerequest("GetAssetCurrentOdometer",contractorid+String.fromCharCode(170)+machineid,function(n){if(showsubloading("adjustodomask",!1),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowOdometers(n)},function(){showsubloading("adjustodomask",!1)})}function getOdometerHis(){var n,t;grid_odometermostrecentdt.setData([]);grid_odometerhisdt.setData([]);showsubloading("adjustodomask",!0);n="";isCalampOdo?n="GetCalampOdometerHistory":isPedigreeOdo?n="GetPedigreeOdometerHistory":isSmartWitness&&(n="GetSmartWitnessOdometerHistory");t=$("#dialogadjust_enginehourstimezone").find("option:selected").val();devicerequest(n,contractorid+String.fromCharCode(170)+machineid+String.fromCharCode(170)+htmlencode(t),function(n){if(showsubloading("adjustodomask",!1),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowMostRecentOdometer(n)},function(){showsubloading("adjustodomask",!1)})}function getOdometerHisPreview(){var n={CustomerID:contractorid,AssetID:machineid,Odometer:$("#dialogadjust_odometer").val(),UOM:$("#dialogadjust_sel_odometeruom").val(),OdometerDate:$("#dialogadjust_odometerdate").val(),Notes:$("#dialogadjust_notes").val()},t=GetTextByKey("P_MA_ADJUSTODOMETER","Adjust Odometer"),i,r,u;if(n.Odometer!==""){if(isNaN(n.Odometer)){showAlert(GetTextByKey("P_MA_ODOMETERFORMATERROR","Odometer format error."),t);return}if(n.Odometer<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),t);return}}else{showAlert(GetTextByKey("P_MA_ODOMETRCANNOTBEEMPTY","Odometer cannot be empty."),t);return}if(n.OdometerDate===""){showAlert(GetTextByKey("P_MA_ODOMETRDATACANNOTBEEMPTY","Odometer date cannot be empty."),t);hideLoading();return}i=$("#dialogadjust_odometertimezone").find("option:selected").attr("offset");n.OffsetMinute=i;n.TimeZone=$("#dialogadjust_odometertimezone").find("option:selected").val();r=$("#dialogadjust_timehour").val();u=$("#dialogadjust_timeminute").val();n.OdometerDate=n.OdometerDate.replace("-","/")+" "+r+":"+u+":00";CheckOdometerMinnimumTime(n,"preview")}function GetOdometerHistoryPreview(n){grid_odometerhisdt.setData([]);showsubloading("adjustodomask",!0);var t=JSON.stringify(n);t=htmlencode(t);isCalampOdo?methodname="GetCalampOdometerHistoryPreview":isPedigreeOdo?methodname="GetPedigreeOdometerHistoryPreview":isSmartWitness&&(methodname="GetSmartWitnessOdometerHistoryPreview");devicerequest(methodname,t,function(n){if(showsubloading("adjustodomask",!1),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}ShowMostRecentOdometerPreview(n);ShowOdometerHis(n)},function(){showsubloading("adjustodomask",!1)})}function ShowMostRecentOdometer(n){for(var i=[],t=0;t<n.length;t++){mostrecentrecord=n[t];i.push(mostrecentrecord);break}grid_odometermostrecentdt.sortIndex=-1;grid_odometermostrecentdt.sortDirection=-1;grid_odometermostrecentdt.setData(i)}function ShowMostRecentOdometerPreview(n){var r,u,i,f,t;if(mostrecentrecord){for(r=0,u=0,i=0;i<n.length;i++){t=n[i];r=t.VBUS-t.VBUS_Calc;u=t.Gps-t.Gps_Calc;break}f=[];t=$.extend(!0,{},mostrecentrecord);n.length>0&&(t.AsofTime=n[0].AsofTime,t.AsofTimeLocal=n[0].AsofTimeLocal,t.EventTimeLocalText=n[0].EventTimeLocalText,t.EventTimeText=n[0].EventTimeText);t.VBUS_Calc=t.VBUS-r;t.VBUS_Calc={DisplayValue:t.VBUS_Calc.toFixed(2),Value:t.VBUS_Calc};t.Gps_Calc=t.Gps-u;t.Gps_Calc={DisplayValue:t.Gps_Calc.toFixed(2),Value:t.Gps_Calc};f.push(t);grid_odometermostrecentdt.sortIndex=-1;grid_odometermostrecentdt.sortDirection=-1;grid_odometermostrecentdt.setData(f)}}function ShowOdometerHis(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];t.VBUS={DisplayValue:t.VBUS.toFixed(2),Value:t.VBUS};t.VBUS_Calc={DisplayValue:t.VBUS_Calc.toFixed(2),Value:t.VBUS_Calc};t.Gps={DisplayValue:t.Gps.toFixed(2),Value:t.Gps};t.Gps_Calc={DisplayValue:t.Gps_Calc.toFixed(2),Value:t.Gps_Calc};for(i in t)i==="EventTimeText"&&(t[i]={DisplayValue:t.EventTimeText,Value:t.AsofTime}),i==="EventTimeLocalText"&&(t[i]={DisplayValue:t.EventTimeLocalText,Value:t.AsofTime_Local});u.push(t)}grid_odometerhisdt.sortIndex=-1;grid_odometerhisdt.sortDirection=-1;grid_odometerhisdt.setData(u)}function openAdjustOdometer(){grid_odometermostrecentdt.columns[0].visible=isCalampOdo;grid_odometermostrecentdt.columns[1].visible=isPedigreeOdo||isSmartWitness;grid_odometermostrecentdt.columns[4].visible=!isSmartWitness;grid_odometermostrecentdt.columns[4].caption=isCalampOdo?GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"):GetTextByKey("P_MA_RAWRAW","Raw(Raw)");grid_odometermostrecentdt.columns[5].visible=!isSmartWitness;grid_odometermostrecentdt.columns[5].caption=isCalampOdo?GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"):"Raw(Adjusted)";grid_odometermostrecentdt.columns[6].caption=isCalampOdo?"GPS(Raw)":"Odometer(Raw)";grid_odometermostrecentdt.columns[7].caption=isCalampOdo?"GPS(Calc)":"Odometer(Adjusted)";grid_odometermostrecentdt.init();grid_odometerhisdt.columns[0].visible=isCalampOdo;grid_odometerhisdt.columns[1].visible=isPedigreeOdo||isSmartWitness;grid_odometerhisdt.columns[4].visible=!isSmartWitness;grid_odometerhisdt.columns[4].caption=isCalampOdo?GetTextByKey("P_MA_VBUSRAW","VBUS(Raw)"):GetTextByKey("P_MA_RAWRAW","Raw(Raw)");grid_odometerhisdt.columns[5].visible=!isSmartWitness;grid_odometerhisdt.columns[5].caption=isCalampOdo?GetTextByKey("P_MA_VBUSCALC","VBUS(Calc)"):"Raw(Adjusted)";grid_odometerhisdt.columns[6].caption=isCalampOdo?"GPS(Raw)":"Odometer(Raw)";grid_odometerhisdt.columns[7].caption=isCalampOdo?"GPS(Calc)":"Odometer(Adjusted)";grid_odometerhisdt.init();var t=customerdatetime.split(" "),i=t[0],n=t[1].split(":"),r=n[0].length==1?"0"+n[0]:n[0],u=n[1];$("#dialogadjust_odometer").val("");$("#dialogadjust_sel_odometeruom").val(systemunitofodometer);$("#dialogadjust_odometertimezone").val(customertimezone?customertimezone:"UTC");$("#dialogadjust_odometerdate").val(i);$("#dialogadjust_timehour").val(r);$("#dialogadjust_timeminute").val(u);$("#dialogadjust_notes").val("");$("#dialog_adjustodometer .dialog-title span.title").text(GetTextByKey("P_MA_ADJUSTODOMETER","Adjust Odometer"));showmaskbg(!0);$("#dialog_adjustodometer").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_adjustodometer").height())/3,left:(document.documentElement.clientWidth-$("#dialog_adjustodometer").width())/2}).showDialogfixed();$("#dialogadjust_odometer").focus();getOdometerHis()}function OnAdjustOdometer(){showsubmask("adjustodomask",!0);var n=GetTextByKey("P_MA_ADJUSTODOMETER","Adjust Odometer");showConfirm1(GetTextByKey("P_MA_DOYOUWANTTOADJUSTTHEODOMETER","Do you want to adjust the odometer?"),n,function(){var t={CustomerID:contractorid,AssetID:machineid,Odometer:$("#dialogadjust_odometer").val(),UOM:$("#dialogadjust_sel_odometeruom").val(),OdometerDate:$("#dialogadjust_odometerdate").val(),Notes:$("#dialogadjust_notes").val(),DataSource:primarydatadourceOdo},i,r,u;if(t.Odometer!==""){if(isNaN(t.Odometer)){showAlert(GetTextByKey("P_MA_ODOMETERFORMATERROR","Odometer format error."),n);showsubmask("adjustodomask",!1);return}if(t.Odometer<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),n);showsubmask("adjustodomask",!1);return}}else{showAlert(GetTextByKey("P_MA_ODOMETRCANNOTBEEMPTY","Odometer cannot be empty."),n);showsubmask("adjustodomask",!1);return}if(t.OdometerDate===""){showAlert(GetTextByKey("P_MA_ODOMETRDATACANNOTBEEMPTY","Odometer date cannot be empty."),n);showsubmask("adjustodomask",!1);return}i=$("#dialogadjust_odometertimezone").find("option:selected").attr("offset");t.OffsetMinute=i;t.TimeZone=$("#dialogadjust_odometertimezone").find("option:selected").val();r=$("#dialogadjust_timehour").val();u=$("#dialogadjust_timeminute").val();t.OdometerDate=t.OdometerDate.replace("-","/")+" "+r+":"+u+":00";CheckOdometerMinnimumTime(t,"submit")},function(){showsubmask("adjustodomask",!1)})}function CheckOdometerMinnimumTime(n,t){var i=JSON.stringify(n);i=htmlencode(i);devicerequest("CheckOdometerMinnimumTime",i,function(i){if(showsubmask("adjustodomask",!1),i>0){i==1?showAlert(GetTextByKey("P_MA_CHECKODOMETERMINNIMUMTIME1","The adjustment cannot be completed as provided. The odometer reading date provided cannot be prior to initial telematic data available for the asset."),GetTextByKey("P_MA_ADJUSTODOMETER","Adjust Odometer")):showAlert(GetTextByKey("P_MA_CHECKODOMETERMINNIMUMTIME","The adjustment cannot be completed as provided. The odometer reading date provided must be prior to or equal to the latest telematic data available for the asset."),GetTextByKey("P_MA_ADJUSTODOMETER","Adjust Odometer"));return}t==="submit"?SaveAdjustOdometer(n):t==="preview"&&GetOdometerHistoryPreview(n)},function(){showsubmask("adjustodomask",!1)})}function SaveAdjustOdometer(n){showsubloading("adjustodomask",!0);var t=JSON.stringify(n);t=htmlencode(t);devicerequest("SaveAdjustOdometer",t,function(n){showsubloading("adjustodomask",!1);n!=="OK"?showAlert(n,GetTextByKey("P_MA_ADJUSTODOMETER","Adjust Odometer")):(getOdometers(),getMachineInfo(),showAlert(GetTextByKey("P_MA_ADJUSTODOMETERSUCCESSFULLY","Adjust Odometer Successfully."),GetTextByKey("P_MA_ADJUSTODOMETER","Adjust Odometer")));$("#dialog_adjustodometer").hideDialog();showmaskbg(!1)},function(){showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTDOMETER","Failed to adjust Odometer."),GetTextByKey("P_MA_ADJUSTODOMETER","Adjust Odometer"));showsubloading("adjustodomask",!1)})}function OnPreviewOdometer(){getOdometerHisPreview()}function openAddOdometer(){var t=customerdatetime.split(" "),i=t[0],n=t[1].split(":"),r=n[0].length==1?"0"+n[0]:n[0],u=n[1];$("#dialogadd_odometer").val("");$("#dialogadd_sel_odometeruom").val(systemunitofodometer);$("#dialogadd_odometertimezone").val(customertimezone?customertimezone:"UTC");$("#dialogadd_odometerdate").val(i);$("#dialogadd_timehour").val(r);$("#dialogadd_timeminute").val(u);$("#dialogadd_notes").val("");$("#dialog_addodometer .dialog-title span.title").text(GetTextByKey("P_MA_ADDODOMETER","Add Odometer"));showmaskbg(!0);$("#dialog_addodometer").css({top:(document.documentElement.clientHeight-$("#dialog_addodometer").height())/3,left:(document.documentElement.clientWidth-$("#dialog_addodometer").width())/2}).showDialogfixed();$("#dialogadd_odometer").focus()}function OnAddOdometer(){showsubmask("addodomask",!0);var n=GetTextByKey("P_MA_ADDODOMETER","Add Odometer");showConfirm1(GetTextByKey("P_MA_DOYOUWANTTOADDTHEODOMETER","Do you want to add the odometer?"),n,function(){var t={CustomerID:contractorid,AssetID:machineid,Odometer:$("#dialogadd_odometer").val(),UOM:$("#dialogadd_sel_odometeruom").val(),OdometerDate:$("#dialogadd_odometerdate").val(),Notes:$("#dialogadd_notes").val()},r,u,f,i;if(t.Odometer!==""){if(isNaN(t.Odometer)){showAlert(GetTextByKey("P_MA_ODOMETERFORMATERROR","Odometer format error."),n);showsubmask("addodomask",!1);return}if(t.Odometer<=0){showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0","ODOMeter must be greater than 0."),n);showsubmask("addodomask",!1);return}}else{showAlert(GetTextByKey("P_MA_ODOMETRCANNOTBEEMPTY","Odometer cannot be empty."),n);showsubmask("addodomask",!1);return}if(t.OdometerDate===""){showAlert(GetTextByKey("P_MA_ODOMETRDATACANNOTBEEMPTY","Odometer date cannot be empty."),n);showsubmask("addodomask",!1);return}r=$("#dialogadd_odometertimezone").find("option:selected").attr("offset");t.OffsetMinute=r;t.TimeZone=$("#dialogadd_odometertimezone").find("option:selected").val();u=$("#dialogadd_timehour").val();f=$("#dialogadd_timeminute").val();t.OdometerDate=t.OdometerDate.replace("-","/")+" "+u+":"+f+":00";i=JSON.stringify(t);i=htmlencode(i);showsubloading("addodomask",!0);devicerequest("AddManuallyInputOdometer",i,function(t){showsubloading("addodomask",!1);t!=="OK"?showAlert(t,n):(getOdometers(),getMachineInfo(),showAlert("Add Odometer Successfully.",n));$("#dialog_addodometer").hideDialog();showmaskbg(!1)},function(){showAlert("Failed to add Odometer.",n);showsubloading("addodomask",!1)})},function(){showsubloading("addodomask",!1)})}function openOdometerAdjustHistory(){window.open("OdometerAdjustHistory.aspx?cid="+contractorid+"&mid="+machineid)}function auditHide(n){var t=$(n.target),i;t.data("hide")==1?(t.data("hide",0),i=t.parent(),i.next().show(),i.next().next().show(),t.removeClass("plus").addClass("minus")):(t.data("hide",1),i=t.parent(),i.next().hide(),i.next().next().hide(),t.removeClass("minus").addClass("plus"))}function initTime(){for(var t=$("#dialogadjust_timehour"),n=0;n<24;n++)n<10?t.append($("<option><\/option>").val("0"+n).text("0"+n)):t.append($("<option><\/option>").val(n).text(n));for(t=$("#dialogadjust_timeminute"),n=0;n<60;n++)n<10?t.append($("<option><\/option>").val("0"+n).text("0"+n)):t.append($("<option><\/option>").val(n).text(n));for(t=$("#dialogadd_timehour"),n=0;n<24;n++)n<10?t.append($("<option><\/option>").val("0"+n).text("0"+n)):t.append($("<option><\/option>").val(n).text(n));for(t=$("#dialogadd_timeminute"),n=0;n<60;n++)n<10?t.append($("<option><\/option>").val("0"+n).text("0"+n)):t.append($("<option><\/option>").val(n).text(n));for(t=$("#dialogenginehours_timehour"),n=0;n<24;n++)n<10?t.append($("<option><\/option>").val("0"+n).text("0"+n)):t.append($("<option><\/option>").val(n).text(n));for(t=$("#dialogenginehours_timeminute"),n=0;n<60;n++)n<10?t.append($("<option><\/option>").val("0"+n).text("0"+n)):t.append($("<option><\/option>").val(n).text(n));for(t=$("#dialogaddenginehours_timehour"),n=0;n<24;n++)n<10?t.append($("<option><\/option>").val("0"+n).text("0"+n)):t.append($("<option><\/option>").val(n).text(n));for(t=$("#dialogaddenginehours_timeminute"),n=0;n<60;n++)n<10?t.append($("<option><\/option>").val("0"+n).text("0"+n)):t.append($("<option><\/option>").val(n).text(n))}function initTimeZone(){devicerequest("GetTimeZones","",function(n){var i,r,u,f,t;if(n){if(i=$("#dialogadjust_odometertimezone"),i.empty(),r=$("#dialogadjust_enginehourstimezone"),r.empty(),u=$("#dialogadd_odometertimezone"),u.empty(),f=$("#dialogadd_enginehourstimezone"),f.empty(),n&&n.length>0)for(t=0;t<n.length;t++)i.append($("<option><\/option>").val(n[t].Key).text("("+n[t].Value+")"+n[t].Key).attr("offset",n[t].Tag1)),r.append($("<option><\/option>").val(n[t].Key).text("("+n[t].Value+")"+n[t].Key).attr("offset",n[t].Tag1)),u.append($("<option><\/option>").val(n[t].Key).text("("+n[t].Value+")"+n[t].Key).attr("offset",n[t].Tag1)),f.append($("<option><\/option>").val(n[t].Key).text("("+n[t].Value+")"+n[t].Key).attr("offset",n[t].Tag1));i.val("UTC");r.val("UTC");u.val("UTC");f.val("UTC")}},function(){})}function getCustomerTimeZone(){assetrequest("GetCustomerTimeZone",contractorid,function(n){if(n){customertimezone=n.Key;customerdatetime=n.Value;var f=customerdatetime.split(" "),t=f[0],i=f[1].split(":"),r=i[0].length==1?"0"+i[0]:i[0],u=i[1];$("#dialogadjust_odometertimezone").val(customertimezone);$("#dialogadd_odometertimezone").val(customertimezone);$("#dialogadjust_odometerdate").val(t);$("#dialogadjust_timehour").val(r);$("#dialogadjust_timeminute").val(u);$("#dialogadd_odometerdate").val(t);$("#dialogadd_timehour").val(r);$("#dialogadd_timeminute").val(u);$("#dialogadjust_enginehourstimezone").val(customertimezone);$("#dialogadd_enginehourstimezone").val(customertimezone);$("#dialogenginehours_date").val(t);$("#dialogenginehours_timehour").val(r);$("#dialogenginehours_timeminute").val(u);$("#dialogaddenginehours_date").val(t);$("#dialogaddenginehours_timehour").val(r);$("#dialogaddenginehours_timeminute").val(u)}},function(){})}function openSetPrimary(n,t){selectedDataSource=t;selectedType=n;$("#dialogprimary_notes").val("");$("#dialog_setprimary .dialog-title span.title").text(GetTextByKey("P_MA_SETASPRIMARY","Set As Primary"));showmaskbg(!0);$("#dialog_setprimary").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_setprimary").height())/3,left:(document.documentElement.clientWidth-$("#dialog_setprimary").width())/2}).showDialogfixed();$("#dialogprimary_notes").focus()}function OnSetPrimary(){var t,n;selectedDataSource&&(t={Type:selectedType,CustomerID:contractorid,AssetID:machineid,DataSource:selectedDataSource.DataSource,SubSource:selectedDataSource.SubSource,Notes:$("#dialogprimary_notes").val()},showloading(!0),n=JSON.stringify(t),n=htmlencode(n),devicerequest("ChangePrimaryDataSource",n,function(n){showloading(!1);n!=="OK"?showAlert(n,GetTextByKey("P_MA_SETASPRIMARY","Set As Primary")):selectedType==0?(getOdometers(),getMachineInfo()):selectedType==1?(getEnineHours(),getMachineInfo()):selectedType==2?getLocations():selectedType==3?getIdlehours():selectedType==4&&getFueluseds();$("#dialog_setprimary").hideDialog()},function(n){console.log(n);showloading(!1);showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTDOMETERSETASPRIMARY","Failed to set as primary."),GetTextByKey("P_MA_SETASPRIMARY","Set As Primary"))}))}function GetActiveJobsites(){devicerequest("GetActiveJobsites",contractorid,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}n&&n.length>0&&(activejobsitedata=n,SetJobSites(jobsitsata))})}function GetContacts(){devicerequest("GetContacts",contractorid,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}n&&n.length>0&&(contactdata=n,SetContacts(contactids))})}function SetJobSites(n){var r,t,u,i;if(!activejobsitedata){grid_jobsitedt.setData([]);return}for(r=0;r<activejobsitedata.length;r++)if(t=activejobsitedata[r],t.OnSite=!1,t.InJobSite=!1,t.Sugguested=!1,t.StatusText="",n&&n.length>0)for(u=0;u<n.length;u++)if(i=n[u],t.ID==i.JobSiteID){t.OnSite=i.OnSite;t.InJobSite=i.InJobSite;t.Sugguested=i.Sugguested;t.InJobSite&&!t.OnSite&&(t.StatusText="Auto-Assigned");t.OnSite&&(t.StatusText="Manually-Assigned");t.Sugguested&&!t.InJobSite&&(t.StatusText="Current Location");break}ShowActiveJobSites(activejobsitedata)}function SetContacts(n){var t,i,r;if(contactdata){for(t=0;t<contactdata.length;t++)if(i=contactdata[t],i.Assigned=!1,n&&n.length>0)for(r=0;r<n.length;r++)if(i.IID==n[r]){i.Assigned=!0;break}ShowContacts(contactdata)}}function ShowActiveJobSites(n){for(var i,r,u=[],f=[],e=[],o=[],t=0;t<n.length;t++)i=n[t],i.OnSite?u.push(i):i.InJobSite?f.push(i):i.Sugguested?e.push(i):o.push(i);for(r=[],t=0;t<u.length;t++)r.push(u[t]);for(t=0;t<f.length;t++)r.push(f[t]);for(t=0;t<e.length;t++)r.push(e[t]);for(t=0;t<o.length;t++)r.push(o[t]);grid_jobsitedt.sortDirection=-1;grid_jobsitedt.setData(r)}function InitJobSiteGridData(){var t,r,i,n;grid_jobsitedt=createGridView("#jobsitelist");t=[{name:"OnSite",caption:GetTextByKey("P_MA_ONSITE","On Site"),valueIndex:"OnSite",type:3,css:{width:60,"text-align":"center"}},{name:"Name",caption:GetTextByKey("P_MA_JOBSITENAME","Jobsite Name"),valueIndex:"Name",css:{width:150,"text-align":"left"}},{name:"StatusText",caption:GetTextByKey("P_MA_ASSIGNMENT","Assignment"),valueIndex:"StatusText",css:{width:120,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,n.bgFilter=function(n){if(n.OnSite||n.InJobSite||n.Sugguested)return"silver"},t[i].type&&(n.type=t[i].type),n.name==="OnSite"&&(n.events={onchange:function(){inputChanged=!0;this.OnSite&&(jobsiteinputChanged=!0)}},n.tooltip=GetTextByKey("P_MA_ONSITETITLE","The On Site box should only be checked if the asset has a permanent assignment not based on location. Geofence and Jobsite Add/Remove will not be triggered if checked.")),r.push(n);grid_jobsitedt.multiSelect=!0;grid_jobsitedt.columns=r;grid_jobsitedt.init()}function ShowContacts(n){for(var r,i=[],t=0;t<n.length;t++)r=n[t],i.push(r);grid_contactdt.sortIndex=0;grid_contactdt.sortDirection=-1;grid_contactdt.setData(i)}function InitContactGridData(){var t,r,i,n;grid_contactdt=createGridView("#contactlist");t=[{name:"Assigned",caption:GetTextByKey("P_MA_ASSIGNED","Assigned"),valueIndex:"Assigned",type:3,css:{width:75,"text-align":"center"}},{name:"DisplayName",caption:GetTextByKey("P_MA_CONTACTNAME","Contact Name"),valueIndex:"DisplayName",css:{width:150,"text-align":"left"}},{name:"ContactTypeName",caption:GetTextByKey("P_MA_CONTACTTYPE","Contact Type"),valueIndex:"ContactTypeName",css:{width:100,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="Assigned"&&(n.events={onchange:function(){inputChanged=!0}}),r.push(n);grid_contactdt.multiSelect=!1;grid_contactdt.columns=r;grid_contactdt.init()}function reshowgrid(){setTimeout(function(){$("#jobsitelist").css("height",$(window).height()-$("#jobsitelist").offset().top-10);grid_jobsitedt&&grid_jobsitedt.resize();$("#contactlist").css("height",$(window).height()-$("#contactlist").offset().top-10);grid_contactdt&&grid_contactdt.resize()})}function InitAssetGroupGridData(){var t,r,i,n;grid_assetgroups=createGridView("#assetgrouplist");t=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"GroupName",caption:GetTextByKey("P_MA_GROUPNAME","Group Name"),valueIndex:"GroupName",css:{width:300,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="Selected"&&(n.events={onchange:function(){inputChanged=!0}}),r.push(n);grid_assetgroups.multiSelect=!1;grid_assetgroups.columns=r;grid_assetgroups.init()}function GetMachineGroups(){$("#tbodymachinegroup").empty();devicerequest("GetMachineGroups",contractorid+String.fromCharCode(170)+"",function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}n&&n.length>0&&(assetgroups=n,ShowMachineGroups(n))})}function ShowMachineGroups(){for(var t,i=[],n=0;n<assetgroups.length;n++)t=assetgroups[n],t.Selected=!1,i.push(t);grid_assetgroups.setData(i);assetinfo&&SetMachineGroups(assetinfo.MachineGroupIDs)}function SetMachineGroups(n){var t,i,r;if(assetgroups){for(t=0;t<assetgroups.length;t++)if(i=assetgroups[t],i.Selected=!1,n&&n.length>0)for(r=0;r<n.length;r++)if(n[r].toLowerCase()==i.GroupID.toLowerCase()){i.Selected=!0;break}grid_assetgroups.reload()}}function reshowgroupgrid(){setTimeout(function(){$("#assetgrouplist").css("height",$(window).height()-$("#assetgrouplist").offset().top-10);grid_assetgroups&&grid_assetgroups.resize()})}function OnAddMake(){showmaskbg(!0);$("#dialog_addmake").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_addmake").height())/3,left:(document.documentElement.clientWidth-$("#dialog_addmake").width())/2}).showDialog();$("#dialog_makename").focus()}function OnSaveMake(){var n={Name:$.trim($("#dialog_makename").val()),AlterActiveName:$.trim($("#dialog_makename").val())},i=GetTextByKey("P_MA_ADDMAKE","Add Make"),t;if(n.ID=-1,!n.Name||n.Name.length==0){showAlert(GetTextByKey("P_MA_MAKENAMEEMPTY","Make name cannot be empty."),i);$("#dialog_makename").focus();return}$("#addmakemask").show();t=JSON.stringify(n);t=htmlencode(t);devicerequest("SaveMachineMake",t,function(t){t!=="OK"?(showAlert(t,i),$("#addmakemask").hide()):(GetMachineMakes(n.Name),$("#dialog_addmake").hideDialog(),showmaskbg(!1),$("#addmakemask").hide())},function(){showAlert(GetTextByKey("P_MA_FAILEDTOSAVEMAKE","Failed to save Make."),i);$("#addmakemask").hide()})}function OnAddModel(){showmaskbg(!0);$("#dialog_addmodel").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_addmodel").height())/3,left:(document.documentElement.clientWidth-$("#dialog_addmodel").width())/2}).showDialog();$("#dialog_modelname").val("");$("#dialog_modelname").focus();$("#dialog_makeforaddmodel").val($("#dialog_make").val());$("#dialog_typeforaddmodel").dropdownVal("")}function OnSaveModel(){var n={Name:$.trim($("#dialog_modelname").val()),MakeID:$.trim($("#dialog_makeforaddmodel").val()),TypeID:$.trim($("#dialog_typeforaddmodel").dropdownVal())},i="Add Model",t;if(n.ID=-1,!n.Name||n.Name.length==0){showAlert(GetTextByKey("P_MA_MODELNAMECANNOTBEEMPTY","Model name cannot be empty."),i);$("#dialog_modelname").focus();return}$("#addmodelmask").show();t=JSON.stringify(n);t=htmlencode(t);devicerequest("SAVEMACHINEMODEL",t,function(t){t!=="OK"?(showAlert(t,i),$("#addmodelmask").hide()):(GetMachineModels(n.MakeID,n.Name),$("#dialog_addmodel").hideDialog(),$("#addmodelmask").hide(),showmaskbg(!1))},function(){showAlert(GetTextByKey("P_MA_FAILEDTOSAVEMODEL","Failed to save model."),i);$("#addmodelmask").hide()})}function SetAssetItem(n){$("#dialog_pm").data("asset",n)}function showConfirmOKCancel(n,t,i,r){showmaskbg(!0);_dialog.showConfirmOKCancel(n,t,function(n){showmaskbg(!1);typeof i=="function"&&i(n)},function(){r&&r();showmaskbg(!1)})}function InitPMGridData(){var t,r,i,n;grid_pmschedules=createGridView("#pmschedulelist");t=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"PmScheduleName",caption:GetTextByKey("P_MA_SCHEDULENAME","Schedule Name"),valueIndex:"PmScheduleName",css:{width:200,"text-align":"left"}},{name:"StartValue",caption:GetTextByKey("P_MA_INITIALSERVICEVALUE","Initial Service Value"),valueIndex:"StartValue",css:{width:120,"text-align":"right"}},{name:"LastAlertTimeString",caption:GetTextByKey("P_MA_LASTSERVICEDATE","Last Service Date"),valueIndex:"LastAlertTimeString",css:{width:120,"text-align":"left"}},{name:"ServiceName",caption:GetTextByKey("P_MA_LASTSERVICEPERFORMED","Last Service Performed"),valueIndex:"ServiceName",css:{width:140,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,t[i].type&&(n.type=t[i].type),n.name==="Selected"&&(n.events={onchange:function(){var n,t;this.Selected?(showSetPMDialog(this),this.Selected=!1,grid_pmschedules.reload(!0)):(n=this,t=GetTextByKey("P_MA_REMOVEASSETFROMSCHEDULE","Do you want to remove this asset from the schedule?"),n.UnMaintainedAlert&&n.UnMaintainedAlert>0&&(t=GetTextByKey("P_MA_REMOVEASSETFROMSCHEDULE_TIPS","Select OK below will result in the deletion of existing unassigned PM alerts for this asset.<br/> If you do not want those alerts deleted, select CANCEL and assign appropriate alerts to a maintenance record or work order in asset health prior to deletion/removal.")),showConfirmOKCancel(t,GetTextByKey("P_MA_REMOVEASSET","Remove Asset"),function(){removeAssetFromPMSchedule(n)},function(){n.Selected=!0;grid_pmschedules.reload(!0)}))}}),r.push(n);grid_pmschedules.multiSelect=!1;grid_pmschedules.columns=r;grid_pmschedules.init()}function getAssetPMSchedules(){showLoading();assetrequest("GetPMSchedulesByAsset",machineid,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}n&&n.length>0&&(pmschedules=n,ShowPMSchedules(n))},function(){hideLoading()})}function ShowPMSchedules(){for(var n,i=[],t=0;t<pmschedules.length;t++)n=pmschedules[t],n.StartValue=n.PmScheduleType==="HM"||n.PmScheduleType==="PM"?n.StartHours:n.PmScheduleType==="ADM"||n.PmScheduleType==="RDM"?n.StartOdometer:n.StartDateString,i.push(n);grid_pmschedules.setData(i)}function reshowpmgrid(){setTimeout(function(){$("#pmschedulelist").css("height",$(window).height()-$("#pmschedulelist").offset().top-10);grid_pmschedules&&grid_pmschedules.resize()})}function addAssetToPMSchedule(n){showLoading();assetrequest("AddAssetToPMSchedule",JSON.stringify(n),function(n){hideLoading();n==="OK"?($("#dialog_pm").hideDialog(),showmaskbg(!1),getAssetPMSchedules()):showAlert(n,GetTextByKey("P_MA_ERROR","Error"))},function(){hideLoading()})}function removeAssetFromPMSchedule(n){var t=$("#dialog_pm").data("asset").ID,i=n.PmScheduleID;showLoading();assetrequest("RemoveAssetFromPMSchedule",JSON.stringify([t,i]),function(n){hideLoading();n==="OK"?getAssetPMSchedules():showAlert(n,GetTextByKey("P_MA_ERROR","Error"))},function(){hideLoading()})}function showSetPMDialog(n){if(showmaskbg(!0),n){var t=$("#dialog_pm .dialog-content");t.empty();n.PmScheduleType==="PM"||n.PmScheduleType==="ADM"?createAbsoluteContent(t,n):n.PmScheduleType==="HM"||n.PmScheduleType==="RDM"?createRelativeContent(t,n):n.PmScheduleType==="TBM"&&createTBMContent(t,n)}$("#dialog_pm").css({top:(document.documentElement.clientHeight-$("#dialog_adjustenginehours").height())/3,left:(document.documentElement.clientWidth-$("#dialog_adjustenginehours").width())/2}).showDialogfixed()}function createAbsoluteContent(n,t){var r=GetTextByKey("P_MA_WHENWOULDYOULIKETHEFIRSTALERT","When would you like the first alert?"),f,s,u,i,e,o;if(n.append($("<span><\/span><br />").text(r)),f=$("<input type='radio' name='pm' checked='checked' />"),n.append(f),s=hasAvailableIntervals(t),r=s?getFirstLineText(t):GetTextByKey("P_MA_NOAVAILABLEINTERVALS","No available intervals."),n.append($("<span><\/span><br />").text(r)),s){if(u=$("<input type='radio' name='pm' />"),n.append(u),r=GetTextByKey("P_MA_ONEORMORESERVICESWASMISSEDALERTMEFOR","One or more services was missed. Alert me for "),n.append($("<span><\/span>").text(r)),i=$("<select><\/select>").prop("disabled",!0),n.append(i),n.append($("<span> <\/span>").text(GetTextByKey("P_MA_NOW"," now."))),t.Intervals)for(e=0;e<t.Intervals.length;e++)(o=t.Intervals[e],o.Recurring)&&i.append($("<option><\/option>").val(o.PmIntervalID).text(o.ServiceName));f.change(h);u.change(h);function h(){f.prop("checked")?i.prop("disabled",!0):i.prop("disabled",!1)}}$("#btnSetPMSchedule").unbind().click(function(){var f=$("#dialog_pm").data("asset"),n={},e,r;n.AssetID=f.ID;n.PmScheduleID=t.PmScheduleID;t.PmScheduleType==="PM"?n.StartHours=f.EngineHours:(e=t.PmScheduleUom,r=f.Odometer,r>0&&e&&f.OdometerUnits&&e.toLowerCase().charAt(0)!=f.OdometerUnits.toLowerCase().charAt(0)&&(r=e.toLowerCase().startsWith("m")?r*.6213712:r/.6213712),n.StartOdometer=Math.round(r));u&&u.prop("checked")&&(n.SelectedIntervalID=i.val());addAssetToPMSchedule(n)})}function createRelativeContent(n,t){var f=GetTextByKey("P_MA_WHENWOULDYOULIKETHEFIRSTALERT","When would you like the first alert?"),e,s,h,i,r,c,u,l,o,a;if(n.append($("<span><\/span><br />").text(f)),e=$("<input type='radio' name='pm' checked='checked' />"),n.append(e),s=hasAvailableIntervals(t),f=s?getFirstLineText(t):GetTextByKey("P_MA_NOAVAILABLEINTERVALS","No available intervals."),n.append($("<span><\/span><br />").text(f)),s){if(h=$("<input type='radio' name='pm' />"),n.append(h),f=GetTextByKey("P_MA_CALCULATEBASEDUPONLASTSERVICETHE","Calculate based upon last service. The "),n.append($("<span><\/span>").text(f)),i=$("<select><\/select>").prop("disabled",!0),n.append(i),n.append($("<span><\/span>").text(GetTextByKey("P_MA_SERVICEWASPERFORMEDAT"," service was performed at "))),r=$("<input type='text' style='width:80px;' />").prop("disabled",!0),n.append(r),t.AllIntervals)for(c=$("#dialog_pm").data("asset"),u=0,u=t.PmScheduleType==="HM"?Math.round(c.EngineHours):Math.round(c.Odometer),isNaN(u)&&(u=0),l=getIntervalValues(u,t.AllIntervals),o=0;o<l.length;o++)a=l[o],i.append($("<option><\/option>").val(a).text(a));e.change(v);h.change(v);function v(){e.prop("checked")?(r.prop("disabled",!0),i.prop("disabled",!0)):(r.prop("disabled",!1),i.prop("disabled",!1))}}$("#btnSetPMSchedule").unbind().click(function(){var f=$("#dialog_pm").data("asset"),n={},o,u;n.AssetID=f.ID;n.PmScheduleID=t.PmScheduleID;e.prop("checked")?t.PmScheduleType==="HM"?n.StartHours=f.EngineHours:(o=t.PmScheduleUom,u=f.Odometer,u>0&&o&&f.OdometerUnits&&o.toLowerCase().charAt(0)!=f.OdometerUnits.toLowerCase().charAt(0)&&(u=o.toLowerCase().startsWith("m")?u*.6213712:u/.6213712),n.StartOdometer=Math.round(u)):(t.PmScheduleType==="HM"?(n.StartHours=r.val(),(n.StartHours===""||isNaN(n.StartHours))&&(n.StartHours=f.EngineHours)):(n.StartOdometer=r.val(),(n.StartOdometer===""||isNaN(n.StartOdometer))&&(o=t.PmScheduleUom,u=f.Odometer,u>0&&o&&f.OdometerUnits&&o.toLowerCase().charAt(0)!=f.OdometerUnits.toLowerCase().charAt(0)&&(u=o.toLowerCase().startsWith("m")?u*.6213712:u/.6213712),n.StartOdometer=Math.round(u))),n.StartIntervalValue=i.val());addAssetToPMSchedule(n)})}function createTBMContent(n,t){var u=GetTextByKey("P_MA_WHENWOULDYOULIKETHEFIRSTALERT","When would you like the first alert?"),f,o,s,h,i,r,e,c;if(n.append($("<span><\/span><br />").text(u)),f=$("<input type='radio' name='pm' checked='checked' />"),n.append(f),o=hasAvailableIntervals(t),u=o?GetTextByKey("P_MA_TRIGGERANALERTASIFSERVICEISDUETODAY","Trigger an alert as if service is due today."):GetTextByKey("P_MA_NOAVAILABLEINTERVALS","No available intervals."),n.append($("<span><\/span><br />").text(u)),o){if(s=$("<input type='radio' name='pm' />"),n.append(s),u=GetTextByKey("P_MA_CALCULATEBASEDUPONLASTSERVICETHELASTSERVICEDATAWAS","Calculate based upon last service. The last service date was "),n.append($("<span><\/span>").text(u)),h=$("<span><\/span>"),n.append(h),i=$("<input type='text' style='width:80px;' />").prop("disabled",!0),i.datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1}).text(currentdate),h.append(i),n.append($("<span><\/span>").text(GetTextByKey("P_MA_FOR"," for "))),r=$("<select><\/select>").prop("disabled",!0),n.append(r),t.Intervals)for(e=0;e<t.AllIntervals.length;e++)c=t.AllIntervals[e],r.append($("<option><\/option>").val(c).text(c));f.change(l);s.change(l);function l(){f.prop("checked")?(i.prop("disabled",!0),r.prop("disabled",!0)):(i.prop("disabled",!1),r.prop("disabled",!1))}}$("#btnSetPMSchedule").unbind().click(function(){var u=$("#dialog_pm").data("asset"),n={};n.AssetId=u.ID;n.PmScheduleID=t.PmScheduleID;f.prop("checked")?n.StartDate=currentdate:(n.StartDate=i.val(),n.StartIntervalValue=r.val(),n.StartDate==""&&(n.StartDate="1900-01-01"));addAssetToPMSchedule(n)})}function hasAvailableIntervals(n){var t,i;if(!n.Intervals||n.Intervals.length==0)return!1;for(t=0;t<n.Intervals.length;t++)if(i=n.Intervals[t],i.Recurring)return!0;return!1}function getIntervalValues(n,t){var i=[],h,r,u,f,c,s;if(t&&t.length>0){var e=t[t.length-1],o=parseInt(n/e),l=n%e;for(l>0&&o++,h=o+1,r=o-Math.ceil(10/t.length)-1,r<0&&(r=0),u=h;u>=r;u--)for(f=t.length-1;f>=0;f--)if(c=t[f],s=u*e+c,i.push(s),s>=n)i.length>2&&i.splice(0,1);else if(i.length==12)break}return i}function getFirstLineText(n){var e="",s,i,h,r,f;if(n.Intervals&&n.Intervals.length>0){var o=$("#dialog_pm").data("asset"),u="",t=0;for(n.PmScheduleType==="PM"||n.PmScheduleType==="HM"?(u="hours",t=Math.round(o.EngineHours)):(u=n.PmScheduleUom,t=o.Odometer,t>0&&u&&o.OdometerUnits&&u.toLowerCase().charAt(0)!=o.OdometerUnits.toLowerCase().charAt(0)&&(t=u.toLowerCase().startsWith("m")?t*.6213712:t/.6213712,t=Math.round(t))),isNaN(t)&&(t=0),s=null,i=null,h=0;h<n.Intervals.length;h++)if(r=n.Intervals[h],r.Recurring){if(f=0,t==0?f=r.Interval:t%r.Interval>0&&(f=r.Interval-t%r.Interval),!i||f<s){i=r;s=f;continue}f==s&&(r.Priority<i.Priority||r.Priority==i.Priority&&r.Interval>i.Interval)&&(i=r)}i&&(e=GetTextByKey("P_MA_THEFIRSTALERTWILLBE","The first alert will be "),e+=i.NotificationPeriod+" "+u,t!=0&&t%i.Interval==0?parseInt(t/i.Interval)*i.Interval:t=(parseInt(t/i.Interval)+1)*i.Interval,e+=GetTextByKey("P_MA_BEFORETHEASSETREADING"," before the asset reading ")+t+" "+u,e+=GetTextByKey("P_MA_FOR"," for ")+i.ServiceName+".")}return e}function showAttachments(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="VisibleOnWorkOrder"?t[i]={DisplayValue:t.VisibleOnWorkOrder?GetTextByKey("P_UTILITY_YES","Yes"):GetTextByKey("P_UTILITY_NO","No"),Value:t[i]}:i==="VisibleOnMap"?t[i]={DisplayValue:t.VisibleOnMap?GetTextByKey("P_UTILITY_YES","Yes"):GetTextByKey("P_UTILITY_NO","No"),Value:t[i]}:i==="VisibleOnMobile"?t[i]={DisplayValue:t.VisibleOnMobile?GetTextByKey("P_UTILITY_YES","Yes"):GetTextByKey("P_UTILITY_NO","No"),Value:t[i]}:i==="AddedOnLocal"&&(t[i]={DisplayValue:t.AddedOnLocalStr,Value:t[i]});u.push(t)}grid_attachmentdt.setData(u)}function InitAttachmentGridData(){var t,r,i,n;$("#btnEdit").attr("disabled","disabled");grid_attachmentdt=createGridView("#documentlist");t=[{name:"Name",caption:GetTextByKey("P_MA_NAME","Name"),valueIndex:"Name",allowFilter:!0,css:{width:120,"text-align":"left"}},{name:"AddedBy",caption:GetTextByKey("P_MA_UPLOADEDBY","Uploaded By"),valueIndex:"AddedBy",allowFilter:!0,css:{width:100,"text-align":"left"}},{name:"VisibleOnWorkOrder",caption:GetTextByKey("P_MA_VISIBLEONWORKORDER","Visible On Work Order?"),valueIndex:"VisibleOnWorkOrder",allowFilter:!0,css:{width:80,"text-align":"left"}},{name:"VisibleOnMap",caption:GetTextByKey("P_MA_VISIBLEONMAP","Visible On Map?"),valueIndex:"VisibleOnMap",allowFilter:!0,css:{width:80,"text-align":"left"}},{name:"VisibleOnMobile",caption:GetTextByKey("P_MA_VISIBLEONMOBILE","Visible On Mobile?"),valueIndex:"VisibleOnMobile",allowFilter:!0,css:{width:80,"text-align":"left"}},{name:"AddedOnLocal",caption:GetTextByKey("P_MA_ADDEDON","Added On"),valueIndex:"AddedOnLocal",allowFilter:!0,css:{width:80,"text-align":"left"}},{name:"Description",caption:GetTextByKey("P_MA_DESCRIPTION","Desctiption"),valueIndex:"Description",css:{width:200,"text-align":"left"}},{name:"View",caption:"",css:{width:30,"text-align":"center"}},{name:"Edit",caption:"",css:{width:30,"text-align":"center"}},{name:"Delete",caption:"",css:{width:30,"text-align":"center"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,n.allowFilter=t[i].allowFilter,n.name==="View"?(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="eye",n.iconType="fa-light",n.events={onclick:function(){openDocumentUrl()}},n.attrs={title:GetTextByKey("P_CRE_EDIT","Edit")}):n.name==="Edit"?(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="edit",n.iconType="fa-light",n.events={onclick:function(){onEditDocument()}},n.attrs={title:GetTextByKey("P_CRE_EDIT","Edit")}):n.name==="Delete"&&(n.sortable=!1,n.resizable=!1,n.type=GridView.ColumnTypes.Icon,n.text="times",n.iconType="fa-light",n.events={onclick:function(){onDeleteDocument(this)}},n.attrs={title:GetTextByKey("P_CRE_DELETE","Delete")}),r.push(n);grid_attachmentdt.canMultiSelect=!1;grid_attachmentdt.columns=r;grid_attachmentdt.init();grid_attachmentdt.onRowDblClicked=onEditDocument}function setPreviewAttachment(){filedata=undefined;$("#tbAssetAttas").empty();$("#tr_document_file").hide();$("#browseattfile").hide()}function getAttachments(n){n&&(showLoading(),devicerequest("GetAttachments",contractorid+String.fromCharCode(170)+n,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}var t=[];t=n&&n.length>0?n:[];showAttachments(t)},function(){hideLoading()}))}function onEditDocument(){var n=grid_attachmentdt.source[grid_attachmentdt.selectedIndex];n&&openAddDocument(n)}function openDocumentUrl(){var n=grid_attachmentdt.source[grid_attachmentdt.selectedIndex];n&&window.open(n.Url)}function openAddDocument(n){setPreviewAttachment();n?(assetdocumentid=n.Id,$("#tr_document_radio").hide(),$("#dialog_adddoc_name").val(n.Name),$("#dialog_adddoc_desc").val(n.Description),$("#dialog_visibleonwo").prop("checked",n.VisibleOnWorkOrder.Value),$("#dialog_visibleonmap").prop("checked",n.VisibleOnMap.Value),$("#dialog_visibleonmobile").prop("checked",n.VisibleOnMobile.Value),n.FileType.toLowerCase()==="url"?($("#dialog_rdourl").prop("checked",!0),$("#dialog_adddoc_url").val(n.Url),$("#tr_document_url").show()):($("#dialog_rdofile").prop("checked",!0),$("#tr_document_url").hide())):(assetdocumentid=undefined,$("#dialog_adddoc_url").attr("disabled",!1),$("#tr_document_url").show(),$("#tr_document_radio").show(),$("#dialog_adddoc_name").val(""),$("#dialog_adddoc_url").val(""),$("#dialog_adddoc_desc").val(""),$("#dialog_rdourl").prop("checked",!0),$("#dialog_visibleonwo").attr("checked",!1),$("#dialog_visibleonmap").attr("checked",!1),$("#dialog_visibleonmobile").attr("checked",!1));$("#dialog_adddocument .dialog-title span.title").text(GetTextByKey("P_MA_ADDITIONALDOCUMENTATION","Additional Documentation"));showmaskbg(!0);$("#dialog_adddocument").attr("act","add").css({top:(document.documentElement.clientHeight-$("#dialog_adddocument").height())/3,left:(document.documentElement.clientWidth-$("#dialog_adddocument").width())/2}).showDialogfixed();$("#dialog_adddoc_name").focus()}function BrowseAssetDocument(){var n=$('<input type="file" style="display: none;" multiple="multiple" />');n.change(function(){var i=this.files,n=i[0];if(n.size==0)return alert(GetTextByKey("P_MA_DOCUMENTTIPS","Document size is 0kb, uploading failed.")),!1;if(n.size>52428800)return alert(GetTextByKey("P_MA_DOCUMENTTIPS1","Document is too large. Maximum file size is 50 MB.")),!1;filedata=n;$("#dialog_adddoc_name").val()===""&&$("#dialog_adddoc_name").val(n.name);$("#tbAssetAttas").empty();var r=$("<tr><\/tr>").data("file",n),t=$('<td style=""><\/td>'),u=$("<label style='border-bottom: 1px solid;cursor:pointer;word-break: break-all;'><\/label>").text(n.name).click(function(){}),f=$('<span class="sbutton icondelete" style="padding:0;margin-left:5px;" ><\/span>').click(function(){deletePreviewAssetAttachment(this)});t.append(u,f);r.append(t).appendTo($("#tbAssetAttas"))}).click()}function deletePreviewAssetAttachment(n){filedata=undefined;var t=$(n).parent().parent();$(t).remove()}function OnSaveDocument(){if(machineid)assetdocumentid?UpdateAssetDocument():SaveAssetDocument(filedata);else{OnSave(0,!1,function(){SaveAssetDocument(filedata)});return}}function SaveAssetDocument(n){var i,t,u,r;if($("#adddocumentmask").show(),i=GetTextByKey("P_MA_ADDITIONALDOCUMENTATION","Additional Documentation"),t={CustomerID:contractorid,AssetID:machineid,Name:$("#dialog_adddoc_name").val(),VisibleOnWorkOrder:$("#dialog_visibleonwo").is(":checked"),VisibleOnMap:$("#dialog_visibleonmap").is(":checked"),VisibleOnMobile:$("#dialog_visibleonmobile").is(":checked"),Description:$("#dialog_adddoc_desc").val()},t.Name===""){showAlert(GetTextByKey("P_MA_NAMECANNOTBEEMPTY","Name cannot be empty."),i);$("#adddocumentmask").hide();return}if(u=$('input[name="rdoattachmentmode"]:checked').val(),u==="0"){if(t.FileType="URL",t.Url=$("#dialog_adddoc_url").val(),t.Url===""){showAlert(GetTextByKey("P_MA_URLCANNOTBEEMPTY","Url cannot be empty."),i);$("#adddocumentmask").hide();return}}else{if(!n){showAlert(GetTextByKey("P_MA_FILECANNOTBEEMPTY","File cannot be empty."),i);$("#adddocumentmask").hide();return}t.FileType=n.name.substring(n.name.lastIndexOf("."))}showloading(!0);r=new FormData;r.append("iconFile",n);r.append("MethodName","UploadAssetDocument");r.append("ClientData",htmlencode(JSON.stringify(t)));$.ajax({url:"ManageMachines.aspx",type:"POST",dataType:"json",processData:!1,contentType:!1,data:r,"async":!0,success:function(n){showloading(!1);n!=="OK"?showAlert(n,i):getAttachments(machineid);$("#dialog_adddocument").hideDialog();$("#adddocumentmask").hide()},error:function(n){showloading(!1);showAlert(n.statusText,i);$("#adddocumentmask").hide()}})}function UpdateAssetDocument(){var n,i,t;if($("#adddocumentmask").show(),n={Id:assetdocumentid,CustomerID:contractorid,Name:$("#dialog_adddoc_name").val(),VisibleOnWorkOrder:$("#dialog_visibleonwo").is(":checked"),VisibleOnMap:$("#dialog_visibleonmap").is(":checked"),VisibleOnMobile:$("#dialog_visibleonmobile").is(":checked"),Description:$("#dialog_adddoc_desc").val()},n.Name===""){showAlert(GetTextByKey("P_MA_NAMECANNOTBEEMPTY","Name cannot be empty."),alerttitle);$("#adddocumentmask").hide();return}if(i=$('input[name="rdoattachmentmode"]:checked').val(),i==="0"&&(n.FileType="URL",n.Url=$("#dialog_adddoc_url").val(),n.Url==="")){showAlert(GetTextByKey("P_MA_URLCANNOTBEEMPTY","Url cannot be empty."),alerttitle);$("#adddocumentmask").hide();return}showloading(!0);t=JSON.stringify(n);t=htmlencode(t);devicerequest("UpdateAssetDocument",t,function(n){showloading(!1);n!=="OK"?showAlert(n,GetTextByKey("P_MA_ADDITIONALDOCUMENTATION","Additional Documentation")):getAttachments(machineid);$("#dialog_adddocument").hideDialog();$("#adddocumentmask").hide()},function(n){showloading(!1);showAlert(n.statusText,GetTextByKey("P_MA_ADDITIONALDOCUMENTATION","Additional Documentation"));$("#adddocumentmask").hide()})}function onDeleteDocument(){var t=grid_attachmentdt.source[grid_attachmentdt.selectedIndex],n;t&&(n=GetTextByKey("P_MA_DELETEDOCUMENTATION","Delete Documentation"),showConfirm(GetTextByKey("P_MA_DELETEDOCUMENTTTIPS","Are you sure you want to delete the document?"),n,function(){devicerequest("DeleteAttachment",contractorid+String.fromCharCode(170)+t.Id,function(t){t!=="OK"?showAlert(t,n):getAttachments(machineid)},function(){showAlert(GetTextByKey("P_MA_FAILEDDELETEDOCUMENT","Failed to delete this document."),n)})}))}function viewAttachment(n){window.open("../filesvc.ashx?attchid="+n+"&custid="+contractorid+"&sourceType=assetattachment")}function getAssetAttachmentInfo(n){(showAssetAttachmentInfo(null),n)&&(showLoading(),assetrequest("GetAssetAttachmentInfo",contractorid+String.fromCharCode(170)+n,function(n){if(hideLoading(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}showAssetAttachmentInfo(n)},function(){hideLoading()}))}function showAssetAttachmentInfo(n){n?($("#dialog_assettypetoattachto").val(n.AssetTypeToAttachTo),$("#dialog_attachstyle").val(n.Style),$("#dialog_attachcapacitycyd").val(n.Capacity_CYD),$("#dialog_attachcapacityweight").val(n.Capacity_Weight),$("#dialog_attachdimension1").val(n.Dimension1),$("#dialog_attachdimension2").val(n.Dimension2),$("#dialog_attacholdnumber").val(n.OldNumber),$("#dialog_attachtomake").val(n.AttachToMake),$("#dialog_attachtomodel").val(n.AttachToModel),$("#dialog_attachedtoanasset").val(n.AttachedtoAsset?"1":"0"),$("#dialog_attachtoasset").val(n.AttachedtoAssetName).data("AttachedtoAssetId",n.AttachedtoAssetId)):($("#dialog_assettypetoattachto").val(""),$("#dialog_attachstyle").val(""),$("#dialog_attachcapacitycyd").val(""),$("#dialog_attachcapacityweight").val(""),$("#dialog_attachdimension1").val(""),$("#dialog_attachdimension2").val(""),$("#dialog_attacholdnumber").val(""),$("#dialog_attachtomake").val(""),$("#dialog_attachtomodel").val(""),$("#dialog_attachedtoanasset").val(""),$("#dialog_attachtoasset").val("").data("AttachedtoAssetId",null))}function getAssetAttachmentInfoInput(n){var t={},i;return(t.AssetTypeToAttachTo=$("#dialog_assettypetoattachto").val(),t.Style=$("#dialog_attachstyle").val(),t.Capacity_CYD=$("#dialog_attachcapacitycyd").val(),i=GetTextByKey("P_MA_ISNOTFORMATTEDCORRECTLY"," is not formatted correctly."),t.Capacity_CYD!==""&&(isNaN(t.Capacity_CYD)||!IsNumber.test(t.Capacity_CYD)))?(showAlert(GetTextByKey("P_MA_CAPACITYCYD","Capacity (CYD)")+i,n),!1):(t.Capacity_Weight=$("#dialog_attachcapacityweight").val(),t.Capacity_Weight!==""&&(isNaN(t.Capacity_Weight)||!IsNumber.test(t.Capacity_Weight)))?(showAlert(GetTextByKey("P_MA_CAPACITYWEIGHT","Capacity (Weight)")+i,n),!1):(t.Dimension1=$("#dialog_attachdimension1").val(),t.Dimension1!==""&&(isNaN(t.Dimension1)||!IsNumber.test(t.Dimension1)))?(showAlert(GetTextByKey("P_MA_DIMENSION1INCM","Dimension #1 (in/cm)")+i,n),!1):(t.Dimension2=$("#dialog_attachdimension2").val(),t.Dimension2!==""&&(isNaN(t.Dimension2)||!IsNumber.test(t.Dimension2)))?(showAlert(GetTextByKey("P_MA_WIDTH","Width")+i,n),!1):(t.OldNumber=$("#dialog_attacholdnumber").val(),t.OldNumber!==""&&(isNaN(t.OldNumber)||!IsNumber.test(t.OldNumber)))?(showAlert(GetTextByKey("P_MA_OLDNUMBER","Old Number")+i,n),!1):(t.AttachToMake=$("#dialog_attachtomake").val(),t.AttachToModel=$("#dialog_attachtomodel").val(),t.AttachedtoAsset=$("#dialog_attachedtoanasset").val()=="1",t.AttachedtoAssetId=$("#dialog_attachtoasset").data("AttachedtoAssetId"),t)}function GetMachineAttributes(n){contractorid||(contractorid="");assetrequest("GetMachineAttributes",contractorid+String.fromCharCode(170)+n,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}n&&n.length>0?(MachineAttributes=n,ShowMachineAttributes(n)):MachineAttributes=[]})}function ShowMachineAttributes(n){var e,f,b,r,a,h,c,t,u,g,i,l,v,y;$(".divtab").empty();var p=$("#ul_container"),k=$("#tab_pm"),d=$("#li_attachmentinfo");for(e=0;e<n.length;e++)if(f=n[e],f.TabID!=3){var w="category"+e,s="tab"+f.TabID,o=$("#"+s),r=null;if(o.length==0&&(b=$('<li class="li_attribute"><\/li>').text(f.TabName).attr("data-href",s),d.after(b),o=$('<div class="divtab"><\/div>').attr("id",s).attr("data-page",s),k.after(o)),r=o.children().eq(0),r.length==0&&(r=$("<table><\/table>"),o.append(r)),u=$("<tr><\/tr>"),a=$('<td class="categoryname minus" colspan="2"><\/td>').text(" "+f.DisplayText).data("cid",w).data("hide",0),a.click(r,function(n){var t=$(n.target);t.data("hide")==0?(t.data("hide",1),n.data.find("."+t.data("cid")).hide(),t.removeClass("minus").addClass("plus")):(t.data("hide",0),n.data.find("."+t.data("cid")).show(),t.removeClass("plus").addClass("minus"))}),u.append(a),r.append(u),h=f.MachineAttributes,h.length>0)for(c=0;c<h.length;c++){if(t=h[c],u=$("<tr><\/tr>").addClass(w),u.append($('<td class="label"><\/td>').text(t.DisplayText+":").attr("title",t.Description)),g="attributeid_"+t.ID,i=$('<input type="text" />'),t.DataType==0){if(t.Multiline)i=$("<textarea><\/textarea>");else if(t.Dropdown&&(i=$('<select style="width:204px;"><\/select>'),t.DataSource)){l=t.DataSource.split(";");for(v in l)i.append($("<option value='"+l[v]+"'>"+l[v]+"<\/option >"))}}else t.DataType==4?$(i).datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}}):t.DataType==5&&(i=$('<select><option value="Yes">Yes<\/option ><option value="No">No<\/option><\/select>'));$(i).attr("id","attributeid_"+t.ID).attr("maxlength",t.Length);$(i).val(t.Value);$(i).change(function(){inputChanged=!0});y=$("<td><\/td>");y.append(i);u.append(y);r.append(u)}}$("#div_container").data("tabed")||(p.append($('<li style="clear: both;"><\/li>')),$("#div_container").data("tabed",!0),$("#div_container").tab(),$(window).resize(),p.find("li").click(function(n){setRightMask($(n.target).attr("data-href"))}));setRightMask()}function ClearMachineAttributeValue(){var t,n,i,r;if(MachineAttributes)for(t=0;t<MachineAttributes.length;t++)if(n=MachineAttributes[t],n&&n.MachineAttributes)for(i=0;i<n.MachineAttributes.length;i++)r=n.MachineAttributes[i],$("#attributeid_"+r.ID).val("")}function getAttributeInput(n){var e=[],r,f,u,t,i;if(MachineAttributes.length>0)for(r=0;r<MachineAttributes.length;r++)for(f=MachineAttributes[r].MachineAttributes,u=0;u<f.length;u++){if(t=f[u],i=$("#attributeid_"+t.ID).val(),t.DataType==1||t.DataType==2||t.DataType==3){if(i!==""){if(isNaN(i)||!IsNumber.test(i)||t.DataType==1&&i.indexOf(".")!=-1)return showAlert(t.DisplayText+" is not formatted correctly.",n),!1;t.DataType==3&&(i=parseFloat(i).toFixed(t.Precision))}}else if(t.DataType==4)if(i.length>0){if(!checkDate(i))return showAlert(t.DisplayText+" is not formatted correctly.",n),!1}else i="";t.Value=i;e.push(t)}return e}function getDevicePairingLogsByDevice(){if($("#div_attlarge").empty(),deviceid){var n=$("#sel_contractor").val();devicerequest("GetDevicePairingLogsByDevice",JSON.stringify([n,deviceid,""]),function(n){n&&typeof n!="string"&&showDevicePairingLogs(n,0)})}}function getDevicePairingLogsByAsset(){$("#div_attlarge").empty();machineid&&devicerequest("GetDevicePairingLogsByAsset",JSON.stringify([contractorid,machineid,""]),function(n){n&&typeof n!="string"&&showDevicePairingLogs(n,1)})}function OnExpendParingInfo(n){var t=$(n),i=t.attr("target");t.hasClass("iconchevrondown")?(t.removeClass("iconchevrondown").addClass("iconchevronright"),$("#"+i).hide()):(t.removeClass("iconchevronright").addClass("iconchevrondown"),$("#"+i).show(),t.data("loaded")||getPairingAttachments(t))}function showDevicePairingLogs(n,t){var f,r,u,s,h;if($("#div_attlarge").empty(),n&&n.length>0)for(f=0;f<n.length;f++){var i=n[f],o="paringinfo_tr"+i.Id,e=$('<table class="main_table maintenance"><\/table>');$("#div_attlarge").append(e);r=$('<tr style="line-height: 35px;"><\/tr>');e.append(r);u=$('<td class="subtitle"><\/td>');r.append(u);s=$('<span class="sbutton iconchevronright woattafoldicon" target="'+o+'" onclick="OnExpendParingInfo(this)" style="margin-left: 0; padding-right: 5px;"><\/span>').data("log",i).data("type",t);u.append(s);h=$("<span><\/span>").text("Paired to {0} on {1} by {2}".replace("{0}",t===0?i.AssetName:i.SourceName+" "+i.SerialNumber).replace("{1}",i.InstallTime_LocalStr).replace("{2}",i.InstallerName));u.append(h);r=$('<tr id="'+o+'" class="tr_intervals woattafoldtr"><\/tr>').hide();e.append(r);u=$('<td id="paringinfo_td'+i.Id+'"><\/td>');r.append(u)}}function getPairingAttachments(n){var i=$("#sel_contractor").val(),t=$(n).data("log"),r=$(n).data("type");devicerequest("GetPairingAttachments",JSON.stringify([i,t.Id]),function(i){i&&typeof i!="string"&&($(n).data("loaded",!0),showPairingAttachments(t,i,r))})}function arrayBufferToBase64(n){for(var i="",r=new Uint8Array(n),u=r.byteLength,t=0;t<u;t++)i+=String.fromCharCode(r[t]);return window.btoa(i)}function getPairingSignature(n,t){devicerequest("GetPairingSignature",JSON.stringify(n),function(n){var r,i,u,f;n&&n!=null&&n.length>0&&(r=$("<tr><\/tr>"),t.append(r),i=$('<td class="label"><\/td>').text(GetTextByKey("P_MD_SIGNATURE_COLON","Signature: ")),r.append(i),i=$('<td colspan="3"><\/td>'),r.append(i),u=n,typeof n!="string"&&(u=arrayBufferToBase64(n)),f=$('<img style="height: 110px;" />').attr("src","data:image/png;base64,"+u),$(i).append(f))})}function getPairingAttachmentCategory(n){switch(n){case"Odometer":return GetTextByKey("P_MD_ODOMETER","Odometer");case"Engine Hours":return GetTextByKey("P_MD_ENGINEHOURS","Engine Hours");case"Mounting Location":return GetTextByKey("P_MD_MOUNTINGLOCATION","Mounting Location");case"Power Connection":return GetTextByKey("P_MD_POWERCONNECTION","Power Connection");case"Ground Connection":return GetTextByKey("P_MD_GROUNDCONNECTION","Ground Connection");case"Ignition Connection":return GetTextByKey("P_MD_IGNITIONCONNECTION","Ignition Connection");case"Asset Number":return GetTextByKey("P_MD_ASSETNUMBER","Asset Number");case"Left Front of Asset":return GetTextByKey("P_MD_LEFTFRONTOFASSET","Left Front of Asset");case"Right Rear of Asset":return GetTextByKey("P_MD_RIGHTFRONTOFASSET","Right Rear of Asset");case"VIN":return GetTextByKey("P_MD_VIN","VIN");case"ESN of GPS Device":return GetTextByKey("P_MD_ESNOFGPSDEVICE","ESN of GPS Device")}return n}function showPairingAttachments(n,t,i){var c=$("#paringinfo_td"+n.Id),u,r,a,p,e;c.empty();var f=n,y=$('<div class="edit-content"><\/div>'),o=$('<table class="tab_deviceparing"><\/table>');if(y.append(o),u=$("<tr><\/tr>"),o.append(u),r=$('<td class="label" style="width:130px;"><\/td>').text(GetTextByKey("P_MD_DATETIME_COLON","Date Time:")),u.append(r),r=$('<td style="width:300px;"><\/td>').text(f.InstallTime_LocalStr),u.append(r),r=$('<td class="label" style="width:130px;"><\/td>').text(GetTextByKey("P_MD_INSTALLER_COLON","Installer:")),u.append(r),r=$("<td><\/td>").text(f.InstallerName),u.append(r),u=$("<tr><\/tr>"),o.append(u),i==0?(r=$('<td class="label" style="width:130px;"><\/td>').text(GetTextByKey("P_MD_VIN_COLON","VIN:")),u.append(r),r=$("<td><\/td>").text(f.AssetVIN),u.append(r),r=$('<td class="label" style="width:130px;"><\/td>').text(GetTextByKey("P_MD_ASSETNAME_COLON","Asset Name:")),u.append(r),r=$("<td><\/td>").text(f.AssetName),u.append(r)):(r=$('<td class="label" style="width:130px;"><\/td>').text(GetTextByKey("P_MA_DEVICESN_COLON","Device SN:")),u.append(r),r=$("<td><\/td>").text(f.SerialNumber),u.append(r),r=$('<td class="label" style="width:130px;"><\/td>').text(GetTextByKey("P_MD_SOURCE_COLON","Source:")),u.append(r),r=$("<td><\/td>").text(f.SourceName),u.append(r)),u=$("<tr><\/tr>"),o.append(u),r=$('<td class="label"><\/td>').text(GetTextByKey("P_MD_ENGINEHOURS_COLON","Engine Hours: ")),u.append(r),r=$("<td><\/td>").text(f.EngineHours<0?"":f.EngineHours.toLocaleString()),u.append(r),r=$('<td class="label"><\/td>').text(GetTextByKey("P_MD_ODOMETER_COLON","Odometer: ")),u.append(r),r=$("<td><\/td>").text(f.Odometer<0?"":f.Odometer.toLocaleString()+" "+f.OdometerUnit),u.append(r),u=$("<tr><\/tr>"),o.append(u),r=$('<td class="label"><\/td>').text(GetTextByKey("P_MD_MOUNTINGLOCATION_COLON","Mounting Location:")),u.append(r),r=$('<td colspan="3"><\/td>').text(f.MountionLocation),u.append(r),u=$("<tr><\/tr>"),o.append(u),r=$('<td class="label"><\/td>').text(GetTextByKey("P_MD_NOTES_COLON","Notes: ")),u.append(r),r=$('<td colspan="3"><\/td>').text(f.Notes),u.append(r),getPairingSignature(f.Id,o),c.append(y),t&&t.length>0){for(e=0;e<t.length;e++){var s=t[e],l=s.Category.replace(/\s+/g,"").toLowerCase(),h=$("#divatt_"+n.Id+"_"+l);h.length==0&&(h=$('<div id="divatt_'+n.Id+"_"+l+'" style="min-height: 80px; overflow: auto; padding-left: 20px;"><\/div>'),c.append(h),a=$('<div style=" margin-top: 15px;margin-bottom:5px;"><\/div>'),p=$('<span style="font-weight:500;font-size:16px;"><\/span>').text(getPairingAttachmentCategory(s.Category)),a.append(p),h.append(a))}for(e=0;e<t.length;e++){var s=t[e],l=s.Category.replace(/\s+/g,"").toLowerCase(),h=$("#divatt_"+n.Id+"_"+l),v=$('<div class="divattp"><\/div>'),w=createAttaDiv(s,!0),a=$('<div style=" margin-top: 15px;"><\/div>'),g=$('<span class="attadownload"><\/span>').attr("title",GetTextByKey("P_WO_DOWNLOAD","Download")).click(s,function(n){openDownloadFrame(n.data.FullSizeUrl+"&d=1")});w.append(g);v.append(w);var b=s.FileName,k=$('<div style="text-align:center;clear:both;"><\/div>'),d=$('<input type="text" style="width: 196px;height:24px;border:1px solid #fff;" class="inp_name" maxlength="200"/>').attr("data-ori",b).val(b);d.data("attdata",s);k.append(d);v.append(k);h.append(v)}}}function createAttaDiv(n){var t=$('<div class="divatt"><\/div>').attr("title",n.FileName).attr("title",n.Notes===""?n.FileName:n.Notes),i,r;return n.FileType&&n.FileType!=""||(n.FileType=".jpg"),imgTypes.indexOf(n.FileType.toLowerCase())>=0?(i=$('<img class="picture"><\/img>').attr("src",n.ThumbnailUrl),i.click(n,function(n){window.open(n.data.FullSizeUrl,"_blank")}),t.append(i)):(r=$('<img class="picture" />').click(n,function(n){window.open(n.data.FullSizeUrl)}),setAttachemntIcon(n.FileType,r),t.append(r)),t}function openPrintFrame(n,t){var i=$("<iframe style='display:none;'><\/iframe>");$(document.body).after(i);i.attr("src",_network.root+"Print.aspx?pt=3&at="+n+"&id="+t);i.on("load",function(){setTimeout(function(){i.contents().find("body").css("text-align","center");i.contents().find("img").css("max-height","98%").css("max-width","98%");i[0].contentWindow.print()});setTimeout(function(){i.remove()},6e4)})}function openDownloadFrame(n){var t=$("<iframe style='display:none;'><\/iframe>"),i;$(document.body).after(t);t.attr("src",n);i=setInterval(function(){t[0].contentDocument&&(t[0].contentDocument.readyState=="complete"||t[0].contentDocument.readyState==4)&&(t.remove(),clearInterval(i))},5e3)}function GetMachines(){worequest("GetMachines","",function(n){n&&n.length>0&&(allassets=n,editableSelectFromAsset.setEnable(!0),editableSelectToAsset.setEnable(!0),editableSelectFromAsset.datasource=n,editableSelectFromAsset.valuepath="Id",editableSelectFromAsset.displaypath="DisplayName",editableSelectToAsset.datasource=n,editableSelectToAsset.valuepath="Id",editableSelectToAsset.displaypath="DisplayName")},function(){})}function openMergeAssets(){ClearAssetDetail();allassets||GetMachines();showmaskbg(!0);$("#dialog_mergeassets").css({top:(document.documentElement.clientHeight-$("#dialog_mergeassets").height())/3,left:(document.documentElement.clientWidth-$("#dialog_mergeassets").width())/2}).showDialogfixed()}function ClearAssetDetail(){$("#tab_assetinfo").show();$("#tab_mergeassets").hide();$("#btn_mergenext").show();$("#btn_mergeprevious").hide();editableSelectFromAsset.val("");editableSelectToAsset.val("");$("#dialog_newhide").attr("checked",!1);$("#dialog_newonroad").attr("checked",!1);$("#dialog_newtelematics").attr("checked",!1);$("#dialog_newattachment").attr("checked",!1);$("#dialog_newpreloaded").attr("checked",!1);$("#dialog_newsn").text("");$("#dialog_newname").text("");$("#dialog_newname2").text("");$("#dialog_newdevicesn").text("");$("#dialog_newyear").text("");$("#dialog_newmake").text("");$("#dialog_newmodel").text("");$("#dialog_neweqclass").text("");$("#dialog_newtype").text("");$("#dialog_newdescription").val("");$("#dialog_newenginehours").text("");$("#dialog_newodometer").text("");$("#dialog_newaddedon").text("");$("#dialog_newaddedby").text("");$("#dialog_oldhide").attr("checked",!1);$("#dialog_oldonroad").attr("checked",!1);$("#dialog_oldtelematics").attr("checked",!1);$("#dialog_oldAttachment").attr("checked",!1);$("#dialog_oldpreloaded").attr("checked",!1);$("#dialog_oldsn").text("");$("#dialog_oldname").text("");$("#dialog_oldname2").text("");$("#dialog_olddevicesn").text("");$("#dialog_oldyear").text("");$("#dialog_oldmake").text("");$("#dialog_oldmodel").text("");$("#dialog_oldeqclass").text("");$("#dialog_oldtype").text("");$("#dialog_olddescription").val("");$("#dialog_oldenginehours").text("");$("#dialog_oldodometer").text("");$("#dialog_oldaddedon").text("");$("#dialog_oldaddedby").text("");$(".radio_both").prop("checked",!0);$("#dialog_mergenotes").val("")}function showAssetDetail(n,t){var i="";IsDealer&&(i=htmlencode($.trim($("#sel_contractor").val())));assetrequest("GetMachineInfo",i+String.fromCharCode(170)+n,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}var i=n;t===1?($("#dialog_newhide").attr("checked",i.Hidden),$("#dialog_newonroad").attr("checked",i.OnRoad),$("#dialog_newtelematics").attr("checked",i.TelematicsEnabled),$("#dialog_newattachment").attr("checked",i.Attachment),$("#dialog_newpreloaded").attr("checked",i.Preloaded),$("#dialog_newsn").text(i.VIN),$("#dialog_newname").text(i.Name),$("#dialog_newname2").text(i.Name2),$("#dialog_newdevicesn").text(i.PairedDeviceSN),$("#dialog_newyear").text(eval(i.MakeYear)>0?i.MakeYear:""),$("#dialog_newmake").text(i.MakeName),$("#dialog_newmodel").text(i.ModelName),$("#dialog_neweqclass").text(i.EQClass),$("#dialog_newtype").text(i.TypeName),$("#dialog_newdescription").val(i.Description),$("#dialog_newenginehours").text(i.EngineHours?i.EngineHours:""),$("#dialog_newodometer").text(i.Odometer?i.Odometer:""),$("#dialog_newaddedon").text(i.AddedOnStr),$("#dialog_newaddedby").text(i.AddedByUserName)):($("#dialog_oldhide").attr("checked",i.Hidden),$("#dialog_oldonroad").attr("checked",i.OnRoad),$("#dialog_oldtelematics").attr("checked",i.TelematicsEnabled),$("#dialog_oldAttachment").attr("checked",i.Attachment),$("#dialog_oldpreloaded").attr("checked",i.Preloaded),$("#dialog_oldsn").text(i.VIN),$("#dialog_oldname").text(i.Name),$("#dialog_oldname2").text(i.Name2),$("#dialog_olddevicesn").text(i.PairedDeviceSN),$("#dialog_oldyear").text(eval(i.MakeYear)>0?i.MakeYear:""),$("#dialog_oldmake").text(i.MakeName),$("#dialog_oldmodel").text(i.ModelName),$("#dialog_oldeqclass").text(i.EQClass),$("#dialog_oldtype").text(i.TypeName),$("#dialog_olddescription").val(i.Description),$("#dialog_oldenginehours").text(i.EngineHours?i.EngineHours:""),$("#dialog_oldodometer").text(i.Odometer?i.Odometer:""),$("#dialog_oldaddedon").text(i.AddedOnStr),$("#dialog_oldaddedby").text(i.AddedByUserName))},function(){})}function OnNext(){var n=editableSelectFromAsset.selecteditem(),t=editableSelectToAsset.selecteditem(),i;if(!n||!t){showAlert(GetTextByKey("P_MA_SELECTANASSETTOMERGE","Please select two assets to merge."),GetTextByKey("P_MA_MERGEASSET","Merge Asset"));return}i=GetTextByKey("P_MA_MERGEASSETTIPS","Merge asset {0} to asset {1}, please select the data to be retained:").replace("{0}",n.DisplayName).replace("{1}",t.DisplayName);$("#span_mergetips").text(i);$(".span_asseta").text(n.DisplayName);$(".span_assetb").text(t.DisplayName);$("#tab_assetinfo").hide();$("#tab_mergeassets").show();$("#btn_mergenext").hide();$("#btn_mergeprevious").show()}function OnPrevious(){$("#tab_mergeassets").hide();$("#tab_assetinfo").show();$("#btn_mergenext").show();$("#btn_mergeprevious").hide()}function SaveMergeAsset(){var i=editableSelectFromAsset.selecteditem(),r=editableSelectToAsset.selecteditem(),t,u,f;if(!i||!r){showAlert(GetTextByKey("P_MA_SELECTANASSETTOMERGE","Please select two assets to merge."),GetTextByKey("P_MA_MERGEASSET","Merge Asset"));return}t="";IsDealer&&(t=htmlencode($.trim($("#sel_contractor").val())));var e=$("#dialog_mergenotes").val(),o=i.Id,s=r.Id,n=[];n.push({Key:0,Tag:"Odometer",Value:$('input[name="radio_odometer"]:checked').val()});n.push({Key:1,Tag:"Engine Hours",Value:$('input[name="radio_enginehours"]:checked').val()});n.push({Key:2,Tag:"Location",Value:$('input[name="radio_location"]:checked').val()});n.push({Key:3,Tag:"Idle Hours",Value:$('input[name="radio_idlehours"]:checked').val()});n.push({Key:4,Tag:"Fuel Used",Value:$('input[name="radio_fuelused"]:checked').val()});n.push({Key:5,Tag:"Fuel Remaining",Value:$('input[name="radio_fuelremaining"]:checked').val()});n.push({Key:6,Tag:"Attribute",Value:$('input[name="radio_attribute"]:checked').val()});n.push({Key:7,Tag:"Battery",Value:$('input[name="radio_battery"]:checked').val()});n.push({Key:8,Tag:"Preventative Maintenance",Value:$('input[name="radio_pmplans"]:checked').val()});n.push({Key:9,Tag:"Jobsite",Value:$('input[name="radio_jobsite"]:checked').val()});u=[t,o,s,e,JSON.stringify(n)];f=JSON.stringify(u);$("#dialogmask").show();assetrequest("SaveMergeAsset",f,function(n){n===""?showAlert(GetTextByKey("P_MA_MERGESUCCESSFULLY","Merge successfully."),GetTextByKey("P_MA_MERGEASSET","Merge Asset")):showAlert(n,GetTextByKey("P_MA_ERROR","Error"));$("#dialog_mergeassets").hideDialog();showmaskbg(!1);$("#dialogmask").hide()})}function openAssetMergeHistory(){window.open("AssetMergeHistory.aspx")}function OnMergeAsset(){showmaskbg(!0);dialogSelectMergeAssets.exceptShareAsset=!0;dialogSelectMergeAssets.exceptSource=[machineid];dialogSelectMergeAssets.showSelector(3,!0)}function showMergeAsset(){showmaskbg(!0);$("#dialog_mergeasset").css({top:(document.documentElement.clientHeight-$("#dialog_mergeasset").height())/3,left:(document.documentElement.clientWidth-$("#dialog_mergeasset").width())/2}).showDialogfixed();var n=assetinfo;$("#dialog_merge_newhide").attr("checked",n.Hidden);$("#dialog_merge_newonroad").attr("checked",n.OnRoad);$("#dialog_merge_newtelematics").attr("checked",n.TelematicsEnabled);$("#dialog_merge_newattachment").attr("checked",n.Attachment);$("#dialog_merge_newpreloaded").attr("checked",n.Preloaded);$("#dialog_merge_newsn").text(n.VIN);$("#dialog_merge_newname").text(n.Name);$("#dialog_merge_newname2").text(n.Name2);$("#dialog_merge_newdevicesn").text(n.PairedDeviceSN);$("#dialog_merge_newyear").text(eval(n.MakeYear)>0?n.MakeYear:"");$("#dialog_merge_newmake").text(n.MakeName);$("#dialog_merge_newmodel").text(n.ModelName);$("#dialog_merge_neweqclass").text(n.EQClass);$("#dialog_merge_newtype").text($("#dialog_type").find("option:selected").text());$("#dialog_merge_newdescription").val(n.Description);$("#dialog_merge_newenginehours").text(n.EngineHours);$("#dialog_merge_newodometer").text(n.Odometer);$("#dialog_merge_newaddedon").text(n.AddedOnStr);$("#dialog_merge_newaddedby").text(n.AddedByUserName);GetAssetDatasources(n.Id,!1);showMergeOldAsset();GetAssetDatasources(mergeassetid,!0)}function showMergeOldAsset(){$("#mergeassetmask").show();assetrequest("GetMachineInfo",contractorid+String.fromCharCode(170)+mergeassetid,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));$("#mergeassetmask").hide();return}mergeasset=n;var t=mergeasset;$("#dialog_merge_oldhide").attr("checked",t.Hidden);$("#dialog_merge_oldonroad").attr("checked",t.OnRoad);$("#dialog_merge_oldtelematics").attr("checked",t.TelematicsEnabled);$("#dialog_merge_oldAttachment").attr("checked",t.Attachment);$("#dialog_merge_oldpreloaded").attr("checked",t.Preloaded);$("#dialog_merge_oldsn").text(t.VIN);$("#dialog_merge_oldname").text(t.Name);$("#dialog_merge_oldname2").text(t.Name2);$("#dialog_merge_olddevicesn").text(t.PairedDeviceSN);$("#dialog_merge_oldyear").text(eval(t.MakeYear)>0?t.MakeYear:"");$("#dialog_merge_oldmake").text(t.MakeName);$("#dialog_merge_oldmodel").text(t.ModelName);$("#dialog_merge_oldeqclass").text(t.EQClass);$("#dialog_merge_oldtype").text(t.Type);$("#dialog_merge_olddescription").val(t.Description);$("#dialog_merge_oldenginehours").text(t.EngineHours?t.EngineHours:"");$("#dialog_merge_oldodometer").text(t.Odometer?t.Odometer:"");$("#dialog_merge_oldaddedon").text(t.AddedOnStr);$("#dialog_merge_oldaddedby").text(t.AddedByUserName);$("#mergeassetmask").hide()},function(){$("#mergeassetmask").hide()})}function onMergeUseAsset(n){$("#dialog_mergeasset").hideDialog();$("#mergeassetmask").hide();DoMergeAsset(n)}function DoMergeAsset(n){if(n!=-1&&machineid){var t=-1,i=-1,r="",u="";n===0?(t=mergeassetid,i=machineid,u=GetTextByKey("P_MA_MERGEASSET","Merge Asset"),r=GetTextByKey("P_MA_MERGEASSETWARNING","WARNING: The merge process will strictly hide the Orphaned Asset and re-assign telematic data sources to the Master Asset for future incoming data. Existing data within the platform will not be assigned to the Master Asset. Are you sure you want to proceed?")):n===1&&(t=machineid,i=mergeassetid,u=GetTextByKey("P_MA_MERGEASSET","Merge Asset"),r=GetTextByKey("P_MA_MERGEASSETWARNING","WARNING: The merge process will strictly hide the Orphaned Asset and re-assign telematic data sources to the Master Asset for future incoming data. Existing data within the platform will not be assigned to the Master Asset. Are you sure you want to proceed?"));showConfirm(r,u,function(){MergeAsset(t,i,n)})}}function MergeAsset(n,t,i){showmaskbg(!0);assetrequest("MergeAsset",htmlencode(JSON.stringify([contractorid,n,t,""])),function(n){showmaskbg(!1);n!=""?showAlert(n,GetTextByKey("P_MA_ERROR","Error")):(needRefreshDataOnCancel=!0,i===1?OnExit(1):OnEdit())},function(){showmaskbg(!1)})}function OnDeleteAsset(){if(machineid){var n=machineid,t=GetTextByKey("P_MA_DELETEASSET","Delete Asset"),i=GetTextByKey("P_MA_DELETEASSETWARNING","WARNING: This will delete the Asset. Are you sure you want to proceed?");showConfirm(i,t,function(){DeleteAsset(n)})}}function DeleteAsset(n){showmaskbg(!0);assetrequest("DeleteAssets",htmlencode(JSON.stringify([contractorid,JSON.stringify([n]),""])),function(n){showmaskbg(!1);n!=""?showAlert(n,GetTextByKey("P_MA_ERROR","Error")):(needRefreshDataOnCancel=!0,OnExit(1))},function(){showmaskbg(!1)})}function GetAssetDatasources(n,t){assetrequest("GetAssetDatasources",htmlencode(JSON.stringify([contractorid,n])),function(n){var r,i;if(n&&n.length>0)for(r=t?$("#dialog_merge_olddatasource"):$("#dialog_merge_newdatasource"),i=0;i<n.length;i++)r.append($("<div><\/div>").text(n[i]))},function(){})}function SetMachineRental(n){n!=null?($("#tab_rentalconnect").data("rentalid",n.RentalID),$("#dialog_outside").val(n.Outside),$("#dialog_vendor").val(n.Vendor),$("#dialog_rentalrate").val(n.RentalRate),$("#dialog_term").val(n.Term),$("#dialog_termunit").val(n.TermUnit),$("#dialog_rentaldate").val(n.RentalDateStr),$("#dialog_projectreturndate").val(n.ProjectReturnDateStr),$("#dialog_returndate").val(n.ReturnDateStr),$("#dialog_ponumber").val(n.PONumber),$("#dialog_comments").val(n.Comments),$("#dialog_rentaltermbillingdate").val(n.RentalTermBillingDateStr),$("#dialog_billingcycledays").val(n.BillingCycleDays<0?"":n.BillingCycleDays),$("#dialog_insuredvalue").val(n.InsuredValue)):($("#tab_rentalconnect").data("rentalid",""),$("#dialog_outside").val(""),$("#dialog_vendor").val(""),$("#dialog_rentalrate").val(""),$("#dialog_term").val(""),$("#dialog_termunit").val(""),$("#dialog_rentaldate").val(""),$("#dialog_projectreturndate").val(""),$("#dialog_returndate").val(""),$("#dialog_ponumber").val(""),$("#dialog_comments").val(""),$("#dialog_rentaltermbillingdate").val(""),$("#dialog_billingcycledays").val(""),$("#dialog_insuredvalue").val(""))}function getRentalInput(n){var i=$("#tab_rentalconnect").data("rentalid"),t;if(i===""&&(i=-1),t={RentalID:i,MachineID:machineid,Outside:$("#dialog_outside").val(),Vendor:$("#dialog_vendor").val(),RentalRate:$("#dialog_rentalrate").val(),Term:$("#dialog_term").val(),TermUnit:$("#dialog_termunit").val(),RentalDate:$("#dialog_rentaldate").val(),RentalDateStr:$("#dialog_rentaldate").val(),ProjectReturnDate:$("#dialog_projectreturndate").val(),ProjectReturnDateStr:$("#dialog_projectreturndate").val(),ReturnDate:$("#dialog_returndate").val(),ReturnDateStr:$("#dialog_returndate").val(),PONumber:$("#dialog_ponumber").val(),Comments:$("#dialog_comments").val(),RentalTermBillingDate:$("#dialog_rentaltermbillingdate").val(),BillingCycleDays:$("#dialog_billingcycledays").val(),InsuredValue:$("#dialog_insuredvalue").val()},t.RentalRate!==""&&isNaN(t.RentalRate))return showAlert(GetTextByKey("P_MA_RENTALRATEFORMATERROR","Rental Rate format error."),n),!1;if(t.RentalRate===""&&(t.RentalRate=0),t.Term===""&&(t.Term=0),isNaN(t.Term)||!IsInteger.test(t.Term)||eval(t.Term)<0)return showAlert(GetTextByKey("P_MA_RENTALTERMMUSTBEANINTEGEREQUALTOORGREATERTHAN0","Rental Term must be an integer equal to or greater than 0. "),n),!1;if(t.RentalDate.length<=0)return showAlert(GetTextByKey("P_MA_RENTALDATECANNOTBEEMPTY","Rental Date cannot be empty."),n),!1;if(t.BillingCycleDays!==""){if(isNaN(t.BillingCycleDays)||!IsInteger.test(t.BillingCycleDays)||eval(t.BillingCycleDays)<0)return showAlert(GetTextByKey("P_MA_THENUMBEROFDAYSINBILLINGCYCLEMUSTBEANINTEGEREQUALTOORGREATERTHAN0","The Number of Days in Billing Cycle must be an integer equal to or greater than 0."),n),!1}else t.BillingCycleDays=-1;return t.InsuredValue!==""&&isNaN(t.InsuredValue)?(showAlert(GetTextByKey("P_MR_INSUREDVALUEFORMATERROR","Insured Value format error."),n),!1):(t.InsuredValue===""&&(t.InsuredValue=0),t)}function SaveRental(){var n,t,i;if(rentalChanged&&(n="",t=$("#tab_rentalconnect").data("rentalid"),t===""&&(t=-1),n=t>0?GetTextByKey("P_MA_EDITRENTAL","Edit Rental"):GetTextByKey("P_MA_ADDRENTAL","Add Rental"),i=getRentalInput(n),i))if(machineid)DoSaveRental(i,n);else{OnSave(0,!1,function(){getRentals(machineid)});return}}function DoSaveRental(n,t){var r=new Date(n.RentalDate.replace("-","/")),u=new Date(n.ProjectReturnDate.replace("-","/")),f=new Date(n.ReturnDate.replace("-","/")),i;if(r>u)return showAlert(GetTextByKey("P_MA_PROJRETURNDATEMUSTBELATERTHANRENTALDATE","Proj. Return Date must be later than than Rental Date."),t),!1;if(r>f)return showAlert(GetTextByKey("P_MA_RETURNDATEMUSTBELATERTHANRENTALDATE","Return Date must be later than Rental Date."),t),!1;showloading(!0);i=JSON.stringify(n);i=htmlencode(i);devicerequest("SaveRental",contractorid+String.fromCharCode(170)+i,function(t){showloading(!1);typeof t=="string"?(t==="Rental dates entered overlap with another entry. Please adjust the dates."&&(t=GetTextByKey("P_MA_RENTALDATESENTEREDOVERLAPWITHANOTHERENTRY","Rental dates entered overlap with another entry. Please adjust the dates.")),showAlert(t,GetTextByKey("P_MA_SAVERENTAL","Save Rental"))):(rentalChanged=!1,n.RentalID=t,$("#tab_rentalconnect").data("rentalid",n.RentalID),showAlert(GetTextByKey("P_MA_SAVSUCCESSFULLY","Saved successfully."),GetTextByKey("P_MA_SAVERENTAL","Save Rental")),getRentals(machineid))},function(n){console.log(n);showloading(!1);showAlert(GetTextByKey("P_MA_FAILEDTOSAVERENTAL","Failed to save Rental."),GetTextByKey("P_MA_SAVERENTAL","Save Rental"))})}function CancelRental(){SetMachineRental(_selectedRental)}function jumpToAddRental(){window.open("AddRental.aspx?cid="+contractorid+"&mid="+machineid)}function getRentals(n){n&&(_selectedRental=null,$("#rentalListDiv").hide(),showLoading(),devicerequest("SearchRentalsByAsset",JSON.stringify([contractorid,n]),function(n){if($("#tbody_rentals").empty(),typeof n=="string"){showAlert(n,GetTextByKey("P_MA_ERROR","Error"));return}n&&n.length>0?(rentalsdata=n,$("#rentalListDiv").show()):rentalsdata=[];sortTableData($("#tbRentals"),rentalsdata);showRentals(rentalsdata);SetMachineRental(_selectedRental);hideLoading()},function(){hideLoading()}))}function rentalsTrClick(){var n=$(this).data("rental");SetMachineRental(n);_selectedRental=n;$("#tbody_rentals tr").removeClass("selected");$(this).addClass("selected")}function showRentals(n){for(var t,i,u=[],r=0;r<n.length;r++)t=n[r],i=$("<tr><\/tr>").data("rental",t).click(rentalsTrClick),t.Selected&&(_selectedRental=t,i.addClass("selected")),i.append($('<td class="machinetd" style="width: 10%;"><\/td>').text(t.RentalDateStr)),i.append($('<td class="machinetd" style="width: 12%;"><\/td>').text(t.ProjectReturnDateStr)),i.append($('<td class="machinetd" style="width: 12%;"><\/td>').text(t.ReturnDateStr)),i.append($('<td class="machinetd" style="width: 12%;"><\/td>').html(replaceHtmlText(t.Vendor))),i.append($('<td class="machinetd" style="width: 10%;"><\/td>').text(t.RentalRate)),i.append($('<td class="machinetd" style="width: 10%;"><\/td>').text(t.Term)),i.append($('<td class="machinetd" style="width: 10%;"><\/td>').text(getLangTermUnit(t.TermUnit))),u.push(i);$("#tbody_rentals").append(u)}function getLangTermUnit(n){var t=n;return n==="Hourly"?t=GetTextByKey("P_MA_HOURLY","Hourly"):n==="Daily"?t=GetTextByKey("P_MA_DAILY","Daily"):n==="Weekly"?t=GetTextByKey("P_MA_WEEKLY","Weekly"):n==="Monthly"?t=GetTextByKey("P_MA_MONTHLY","Monthly"):n==="Annually"&&(t=GetTextByKey("P_MA_ANNUALLY","Annually")),t}function ManageRentalHistory(){window.open("MachineDeviceManagement.aspx?cid="+contractorid+"&mid="+machineid+"#nav_managrentals")}function AddRental(){showRentalConfirm(GetTextByKey("P_MA_WOULDSAVECHANGES","Would you like to save changes?"),GetTextByKey("P_MA_RENTAL","Rental"),function(){SaveRental()},function(){$("#tab_rentalconnect").data("rentalid","");SaveRental()},null)}var grid_fuelremainingdt,grid_fuelremaininghisdt,grid_fueluseddt,grid_fuelusedhisdt,grid_idlehourdt,grid_idlehourhisdt,grid_locationdt,grid_locationhisdt,grid_odometerdt,grid_odometermostrecentdt,grid_odometerhisdt,isCalampOdo,isPedigreeOdo,primarydatadourcenameOdo,primarydatadourceOdo,mostrecentrecord,selectedDataSource,selectedType,activejobsitedata,contactdata,grid_jobsitedt,grid_contactdt,assetgroups,grid_assetgroups,pmschedules,grid_pmschedules,grid_attachmentdt,assetdocumentid,filedata,dialogAttachToAssets,MachineAttributes,imgTypes,printTypes,allassets,mergeassetid,mergeasset,_selectedRental,IsInteger;$(function(){InitEnginehoursGridData();InitMostRecentEnginehoursGridData();InitEnginehoursHisGridData()});var grid_enginehoursdt,grid_enginehoursmostrecentdt,grid_enginehourshisdt,isCalampEH=!1,isPedigreeEH=!1,isOEMDD2EH=!1,primarydatadourcenameEH,primarydatadourceEH;$(function(){InitFuelRemainingGridData()});$(function(){InitFuelusedGridData()});$(function(){InitIdlehourGridData()});$(function(){InitLocationGridData()});$(function(){InitOdometerGridData();InitOdometerMostRecentGridData();InitOdometerHisGridData()});isCalampOdo=!1;isPedigreeOdo=!1;$(function(){initTime();initTimeZone();$("#dialog_adjustodometer").dialog(function(){showmaskbg(!1)});$("#dialog_addodometer").dialog(function(){showmaskbg(!1)});$("#dialog_adjustenginehours").dialog(function(){showmaskbg(!1)});$("#dialog_addenginehours").dialog(function(){showmaskbg(!1)});$("#dialog_setprimary").dialog(function(){showmaskbg(!1)});$("#dialogadjust_odometerdate").datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});$("#dialogadd_odometerdate").datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});$("#dialogaddenginehours_date").datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});$("#dialogenginehours_date").datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});$("#tdAuditEngineHours").click(auditHide);$("#tdAuditOdometers").click(auditHide);$("#tdAuditLocation").click(auditHide);$("#tdAuditIdlehour").click(auditHide);$("#tdAuditFuelused").click(auditHide);$("#tdAuditFuelRemaining").click(auditHide)});selectedDataSource=undefined;$(function(){InitJobSiteGridData();InitContactGridData();InitAssetGroupGridData();$("#dialog_addmake").dialog(function(){showmaskbg(!1)});$("#dialog_addmodel").dialog(function(){showmaskbg(!1)});$("#dialog_assetduplicates").dialog(function(){showmaskbg(!1)});$("#dialog_mergeasset").dialog(function(){showmaskbg(!1)})});$(function(){InitPMGridData();$("#dialog_pm").dialog(function(){showmaskbg(!1)})});$(function(){InitAttachmentGridData();$("#dialog_adddocument").dialog(function(){showmaskbg(!1)});$(window).resize(function(){$("#documentlist").css("height",$(window).height()-$("#documentlist").offset().top-4);grid_attachmentdt&&grid_attachmentdt.resize()}).resize()});$(function(){dialogAttachToAssets=new $assetselector("dialog_machines");dialogAttachToAssets.forceSingle=!0;dialogAttachToAssets.onDialogClosed=function(){showmaskbg(!1)};dialogAttachToAssets.onOK=function(n,t){var i=null;t>=0&&(i=n[t]);$("#dialog_attachtoasset").val(i.Name).data("AttachedtoAssetId",i.MachineID?i.MachineID:i.Id);inputChanged=!0;showmaskbg(!1)};$("#btnSelectAttachToAsset").click(function(){showmaskbg(!0);dialogAttachToAssets.companyId=contractorid;dialogAttachToAssets.exceptSource=[machineid];dialogAttachToAssets.showSelector(3,!0)});$("#btnUnattach").click(function(){$("#dialog_attachtoasset").val("").data("AttachedtoAssetId",null);inputChanged=!0})});MachineAttributes=[];imgTypes=[".jfif",".jpg",".jpeg",".bmp",".png",".tiff",".gif"];printTypes=[".pdf",".jfif",".jpg",".jpeg",".bmp",".png",".tiff",".gif"];_selectedRental=null;$(function(){$("#dialog_rentaldate").datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});$("#dialog_projectreturndate").datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});$("#dialog_returndate").datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});$("#dialog_rentaltermbillingdate").datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}})});IsInteger=/^[0-9]+$/;