jQuery,"undefined"==typeof fmRegistrationLookup&&(fmRegistrationLookup={}),$(document).ajaxError((function(e,o,t){if(!(t.url.toLowerCase().indexOf("/foremostmedia/RegistrationLookup/".toLowerCase())<0)){var i,r=JSON.parse(o.responseText);void 0!==r.Url&&(i=function(){window.location=r.Url}),fmRegistrationLookup.alertError(r.ExceptionMessage||r.Message,void 0,i)}})),fmRegistrationLookup.alertError=function(e,o,t){fmRegistrationLookup.alert(e,o,"danger",t)},fmRegistrationLookup.alertSuccess=function(e,o,t){fmRegistrationLookup.alert(e,o,"success",t)},fmRegistrationLookup.alert=function(e,o,t,i){var r="";switch(t){case"success":r="Success!";break;case"danger":r="There was an error!"}(void 0===o||o.length<1)&&(o=e,e=void 0),$.dnnAlert({title:e||r,text:o,callback:i,dialogClass:"dnnFormPopup dnnClear alert alert-"+(t||"default")})},fmRegistrationLookup.sort={generic:function(e){return function(o,t){if(void 0===o)return 0;var i="function"==typeof o[e]?o[e]():o[e],r="function"==typeof t[e]?t[e]():t[e];return void 0===i?0:void 0===r||(i=isNaN(i)?i.toLowerCase():parseFloat(i,10))>(r=isNaN(r)?r.toLowerCase():parseFloat(r,10))?1:-1}}},function(e){function o(o,t,i,r,a){"function"==typeof i&&(a=r,r=i,i={}),e.ajax({type:o,url:fmRegistrationLookup.baseServicepath+t,data:i,beforeSend:fmRegistrationLookup.serviceFramework.setModuleHeaders}).done((function(e){"function"==typeof r&&r(e)})).always((function(e){"function"==typeof a&&a(e)}))}"undefined"==typeof fmRegistrationLookup&&(fmRegistrationLookup={}),fmRegistrationLookup.api={load:function(e,t){o("GET","lookup",e,t)},get:function(e,t,i){o("GET","lookup/"+e,t,i)},getRegistrations:function(o,t,i){!function(o,t,i,r,a){"function"==typeof i&&(a=r,r=i,i={});e.ajax({type:o,url:fmRegistrationLookup.baseServicepath+t,data:i,enctype:"multipart/form-data",contentType:!1,processData:!1,beforeSend:fmRegistrationLookup.serviceFramework.setModuleHeaders}).done((function(e){"function"==typeof r&&r(e)})).always((function(e){"function"==typeof a&&a(e)}))}("POST","import",o,t,i)},getFHWA:function(e,t,i){o("GET","fhwa/"+e,t,i)},deletet:function(e,t,i){o("DELETE","lookup/"+e.id,t,i)},save:function(e,t,i){var r="POST",a="lookup";e.Id>0&&(r="PUT",a+="/"+e.Id);o(r,a,e,t,i)}},fmRegistrationLookup.serviceFramework=e.ServicesFramework(fmRegistrationLookup.moduleId),fmRegistrationLookup.baseServicepath=fmRegistrationLookup.serviceFramework.getServiceRoot("ForemostMedia/RegistrationLookup")}(jQuery),function(e){"undefined"==typeof fmRegistrationLookup&&(fmRegistrationLookup={}),fmRegistrationLookup.LookupViewModel=function(){var o=this;o.errorMessage=ko.observable(""),o.haveValidRegistration=ko.observable(!1),o.remoteApiBaseUrl="https://cpq.stoughtontrailers.com/partssupportservice/api/Pdf/rentals/",o.remoteApiFHWAUrl="https://cpq.stoughtontrailers.com/partssupportservice/api/Pdf/fhwas/",o.zipApiUrl="../Portals/0/ForemostMedia/RegistrationLookup/",o.templateUrl="../Portals/0/ForemostMedia/Templates/",o.trailerNumber=ko.observable(""),o.trailerImportPath=ko.observable(""),o.zipImportPath=ko.observable(""),o.isZip=ko.observable(!1),o.isRegistration=ko.observable(!0),o.init=function(){return o},o.getRegistration=function(){o.validate()&&(o.isRegistration(!0),o.isZip(!1),fmRegistrationLookup.api.get(o.trailerNumber(),o.getRegistrationCallback))},o.getRegistrations=function(){var t=new FormData,i=e("#impFile").get(0).files;for(var r in t.append("importFile",i[0]),t.entries())console.log(r[0]+", "+r[1]);o.isRegistration(!1),o.isZip(!0),fmRegistrationLookup.api.getRegistrations(t,o.getImportCallback)},o.getImportCallback=function(e){e.isValid?(o.haveValidRegistration(!0),o.zipImportPath(e.DownloadUrl)):o.errorMessage("&emsp;No information available for a registration number within the import file.&emsp;")},o.getRegistrationCallback=function(e){e.Result?(o.haveValidRegistration(!0),o.zipImportPath(e.DownloadUrl)):o.errorMessage("&emsp;No information available for this registration number.&emsp;")},o.getFHWA=function(){o.validate()&&(o.isRegistration(!1),o.isZip(!1),fmRegistrationLookup.api.getFHWA(o.trailerNumber(),o.getRegistrationCallback))},o.clearInput=function(){o.trailerNumber(""),o.trailerImportPath(""),o.haveValidRegistration(!1)},o.downloadRegistration=function(){o.isRegistration()&&!o.isZip()?(window.open(o.remoteApiBaseUrl+o.trailerNumber(),"_blank"),window.focus()):o.isRegistration()||o.isZip()?(window.open(o.zipApiUrl+o.zipImportPath(),"_blank"),window.focus()):(window.open(o.remoteApiFHWAUrl+o.trailerNumber(),"_blank"),window.focus())},o.validate=function(){if(""===o.trailerNumber().trim())return o.errorMessage("&emsp;Please enter a trailer number.&emsp;"),!1;return!0},o.getTemplate=function(){window.open(o.templateUrl+"StoughtonTrailerImportTemplate.xlsx","_blank"),window.focus()},e("#trailerSearch").keypress((function(e){if(13===e.keyCode)return o.getRegistration(),!1})),o.haveErrorMessage=ko.computed((function(){return o.errorMessage().length>0&&(setTimeout((function(){o.errorMessage("")}),3e3),!0)}))}}(jQuery);