$(document).ready(function(){function n(n){$(".btn-document-delete",n).click(function(n,t){t||$("#documentsRows").trigger("documentRemoved",[$(this).closest("[order]").attr("order")]);$(this).parents(".document").remove()})}function i(){return $(Mustache.render($("#documentsRowTemplate").html().trim(),{Index:++t}))}$(".documentPicker").each(function(n,t){var i=$(t);i.documentPicker({documentType:function(){return i.find("button[data-documenttype]").data("documenttype")},uploaded:function(n){if(n!=null&&n.success){var t=i.closest(".form-group").find("input[type=file]");(t==null||t.length<=0)&&(t=i.closest(".form-group").find("p.form-control"));t.replaceWith($("<p class='form-control'>"+n.Name+"<\/p>"))}else i.closest("form").showClientError(n.errors)}})});var t=0;n($(".documents"));$("#btnAddDocument").click(function(){var t=i();t.find(".documentPicker").documentPicker({documentType:function(){return t.find("select[name=DocumentTypes]").val()},uploaded:function(n){n!=null&&n.success?t.replaceWith($(Mustache.render($("#documentsRowViewTemplate").html().trim(),{Name:n.Name,Type:n.DisplayType}))):t.closest("form").showClientError(n.errors)}});n(t);$("#documentsRows").append(t)});$(window).trigger("erecruiter.register.finished")}),function(n){n.fn.dropzone=function(t){function e(t,i){t.addEventListener("dragenter",r,!1);t.addEventListener("dragover",function(i){r(i);n(t).addClass("drop")},!1);t.addEventListener("dragleave",function(){n(t).removeClass("drop")},!1);t.addEventListener("drop",f,!1);i.addEventListener("change",f,!1)}function f(n){var o=document.getElementById("loadingBar"),f,u,e;if(o.classList.remove("display-none"),r(n),f=n.target.files||n.dataTransfer.files,t.complete){for(u=0;e=f[u];u++)t.complete(e);return}i.submit()}function r(n){n.stopPropagation();n.preventDefault()}var u,i;return this.length<=0?this:(u={complete:!1},t=n.extend(u,t),i=this,n(document).ready(function(){window.File&&window.FileReader&&window.FileList&&window.Blob?e(i[0],i.find('input[type="file"]')[0]):i.addClass("no-filesupport");var n=i.find(".browse-files"),t=function(){i.find('input[type="file"]').click()};n.click(t);n.on("keypress",function(n){n.which==13&&t()})}),this)}}(jQuery);$(document).ready(function(){$(".dropzone").dropzone({complete:function(n){var t=new FormData;t.append("file",n);$.ajax({type:"POST",url:"/Register/UploadCv",data:t,dataType:"json",contentType:!1,processData:!1}).always(function(){var n=$(".dropzone").prop("action");n=n.replace("/Cv","").replace("?job=","/");window.location.replace(n)})}})}),function(){if(!window.GoogleDrive){window.GoogleDrive={};var u,f,e=["https://www.googleapis.com/auth/drive.readonly"],t,i=!1,n;GoogleDrive.open=function(e){var s=document.getElementById("googledrive-js");u=s.getAttribute("developer-key");f=s.getAttribute("client-id");(e.success||e.success!=null)&&(t=e.success);n&&i?r():o()};function o(){gapi.load("auth",{callback:s});gapi.load("picker",{callback:h});gapi.client.load("drive","v3")}function s(){window.gapi.auth.authorize({client_id:f,scope:e,immediate:!1},c)}function h(){i=!0;r()}function c(t){t&&!t.error&&(n=t.access_token,r())}function r(){if(i&&n){var t=(new google.picker.PickerBuilder).addView(google.picker.ViewId.DOCS).setOAuthToken(n).setDeveloperKey(u).setCallback(l).build();t.setVisible(!0)}}function l(n){if(n[google.picker.Response.ACTION]==google.picker.Action.PICKED){var i=n[google.picker.Response.DOCUMENTS][0],r=i[google.picker.Document.ID];gapi.client.drive.files.get({fileId:r,alt:"media"}).then(function(n){t&&t({name:i[google.picker.Document.NAME],content:btoa(n.body)})},function(n){console!=null&&console.log("Error: "+n.result.error.message)})}}}}(),function(n){n.fn.documentPicker=function(t){function f(i){var r={Address:i.address,Name:i.name,Type:i.type};n.ajax({type:"POST",url:"/Register/UploadDocument",data:r,dataType:"json"}).done(function(n){t.uploaded&&t.uploaded(n)}).fail(function(){error(i.name)})}var u={documentType:null,picked:f,uploaded:!1,error:!1},i,r;return t=n.extend(u,t),i={dropbox:function(n){n.click(function(){Dropbox.choose({success:function(n){var i=n[0];t.picked&&t.picked({address:i.link,name:i.name,type:t.documentType()})},cancel:function(){},linkType:"direct",multiselect:!1,extensions:null})})},googledrive:function(n){n.click(function(){GoogleDrive.open({success:function(n){t.picked&&t.picked({address:n.content,name:n.name,type:t.documentType()})}})})},onedrive:function(n){n.click(function(){OneDrive.open({success:function(n){var i=n.values[0];t.picked&&t.picked({address:i.link,name:i.fileName,type:t.documentType()})},cancel:function(){},linkType:"downloadLink",multiSelect:!1})})}},r=this,n(document).ready(function(){r.find("a[data-chooser]").each(function(t,r){var u=n(r);i[u.data("chooser")](u)})}),this}}(jQuery),function(n){n.fn.showClientError=function(t){var i=n(".validation-summary-errors"),r;i.length===0&&(i=n("<div class='validation-summary-errors'>"),i.html("<ul><\/ul>"),i.prependTo(n(this)));r=i.find("ul");t.forEach(function(t){r.append(n("<li>").text(t))})}}(jQuery)