// source --> https://www.medi-karriere.ch/wp-content/themes/jobengine/js/job_engine.js?ver=1774355026 
var JobEngine = JobEngine || {};
JobEngine.Models = JobEngine.Models || {}, JobEngine.Collections = JobEngine.Collections || {}, JobEngine.Views = JobEngine.Views || {}, JobEngine.Routers =
  JobEngine.Routers || {}, JobEngine.pubsub = JobEngine.pubsub || {}, _.extend(JobEngine.pubsub, Backbone.Events);
var pubsub = pubsub || JobEngine.pubsub;
JobEngine.ajaxParams = {
  type: "POST"
  , dataType: "json"
  , url: et_globals.ajaxURL
  , contentType: "application/x-www-form-urlencoded;charset=UTF-8"
};
var ajaxParams = JobEngine.ajaxParams;
! function (e) {
  JobEngine.Models.Job = Backbone.Model.extend({
    author: {}
    , action: "et_job_sync"
    , initialize: function () {
		// PO-1709
      _.bindAll(this, 'updateJobAuthor');
	  // -/ PO-1709
	  this.has("author_id") ? this.author = new JobEngine.Models.Company({
        id: this.get("author_id")
      }) : this.author = new JobEngine.Models.Company, this.author.on("change", this.updateJobAuthor, this)
    }
    , updateJobAuthor: function () {
      (this.author.hasChanged("id") || !this.has("author_id")) && this.set("author_id", this.author.id, {
        silent: !0
      }), this.set("author_data", {
        user_url: this.author.get("user_url")
        , display_name: this.author.get("display_name")
        , user_logo: this.author.get("user_logo")
        , post_url: this.author.get("post_url")
      }, {
        silent: !0
      })
    }
    , parse: function (e) {
      return e.success ? "create" === e.method ? (this.set("id", e.data.job.id, {
        silent: !0
      }), {}) : (pubsub.trigger("je:notification", {
        msg: e.msg
        , notice_type: "success"
      }), "author" in e.data && (this.author.set(e.data.author, {
        silent: !0
      }), this.set("author_data", {
        user_url: this.author.get("user_url")
        , display_name: this.author.get("display_name")
        , user_logo: this.author.get("user_logo")
        , post_url: this.author.get("post_url")
        , recent_location: this.author.get("recent_location")
      }, {
        silent: !0
      })), e.data.job) : (pubsub.trigger("je:notification", {
        msg: e.msg
        , notice_type: "error"
      }), {})
    }
    /*PO-1760*/
    /* sync: function(e, t, n) {
        var i, o = _.extend({
            type: "POST",
            dataType: "json",
            url: et_globals.ajaxURL,
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            author_sync: !1
        }, n || {});
        console.log(e);
        console.log(t);
        console.log(n);
        return e = n && n.method ? n.method : e, "read" === e && (o.type = "GET", o.data = {
            id: t.id
        }), o.data || !t || "create" !== e && "update" !== e && "delete" !== e || (i = _.clone(t.attributes), o.author_sync || delete i.author_data, "author_data" in i && "user_logo" in i.author_data && delete i.author_data.user_logo, o.data = i), o.data = jQuery.param({
            action: t.action,
            method: e,
            content: o.data
        }), jQuery.ajax(o)
    }, */
    , sync: function(e, t, n) {
        var i, o = _.extend({
            type: "POST",
            dataType: "json",
            url: et_globals.ajaxURL,
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            author_sync: !1
        }, n || {});

        e = n && n.method ? n.method : e;
        if (e === "read") {
            o.type = "GET";
            o.data = { id: t.id };
        } else if (["create", "update", "delete"].includes(e)) {
            i = _.clone(t.attributes);
            if (!o.author_sync) delete i.author_data;
            if (i.author_data && i.author_data.user_logo) delete i.author_data.user_logo;
            o.data = i;
        }

        o.data = jQuery.param({
            action: t.action,
            method: e,
            content: o.data
        });

        return jQuery.ajax(o).done(function(response) {
            if (response.success && response.data && response.data.job) {
                $('#job_id').val(response.data.job.ID);
                //console.log("Job ID:", response.data.job.ID);
            } else {
                //console.log("Failed to retrieve job ID");
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            console.error("AJAX request failed:", textStatus, errorThrown);
        });
    },
    /* -/ PO-1760*/
    reviewJob: function (e, t) {
      t = t || {}, this.set("status", e, {
        silent: !0
      }), t.data = _.extend("data" in t ? t.data : {}, {
        id: this.get("id")
        , status: e
        , method: "reviewJob"
      }), t.method = "reviewJob", this.save({
        status: e
        , method: "reviewJob"
      }, t)
    }
    , approve: function (e) {
      e = e || {};
      var t = e && "function" == typeof e.success ? e.success : !1;
      e.success = function (e, n) {
        pubsub.trigger("je:job:afterApproveJob", e, n), t && t(e, n)
      }, e.wait = !0, this.reviewJob("publish", e)
    }
    , reject: function (e) {
      e = e || {};
      var t = e && "function" == typeof e.beforeSend ? e.beforeSend : !1
        , n = e && "function" == typeof e.success ? e.success : !1;
      e.beforeSend = function () {
        pubsub.trigger("je:request:waiting"), t && t()
      }, e.success = function (e, t) {
        pubsub.trigger("je:job:afterRejectJob", e, t), n && n(e, t)
      }, this.reviewJob("reject", e)
    }
    , archive: function (e) {
      e = e || {};
      var t = this.get("status")
        , n = "function" == typeof e.success ? e.success : !1;
      e.success = function (e, i) {
        pubsub.trigger("je:job:afterArchiveJob", e, i, t), n && n(e, i)
      }, this.reviewJob("trash", e)
    }
    , remove: function (e) {
      e = e || {};
      this.get("status"), "function" == typeof e.success ? e.success : !1;
      this.sync("delete", this, e)
    }
  }), JobEngine.Models.Auth = Backbone.Model.extend({
    params: {
      type: "POST"
      , dataType: "json"
      , url: et_globals.ajaxURL
      , contentType: "application/x-www-form-urlencoded;charset=UTF-8"
    }
    , setUserName: function (e) {
      this.set({
        user_name: e
      }, {
        silent: !0
      })
    }
    , setEmail: function (e) {
      this.set({
        user_email: e
      }, {
        silent: !0
      })
    }
    , setPass: function (e) {
      this.set({
        user_pass: e
      }, {
        silent: !0
      })
    }
    , setUserKey: function (e) {
      this.set({
        user_key: e
      }, {
        silent: !0
      })
    }
    , changePassword: function (e) {
      var t = _.extend({
        data: {
          action: "et_change_pass"
          , user_old_pass: this.get("user_old_pass")
          , user_pass: this.get("user_pass")
          , user_pass_again: this.get("user_pass_again")
        }
      }, this.params, e || {});
      return t.beforeSend = function () {
        pubsub.trigger("je:request:waiting"), e && "function" == typeof e.beforeSend && e.beforeSend()
      }, t.success = function (t, n, i) {
        pubsub.trigger("je:response:changePassword", t, n, i), e && "function" == typeof e.success && e.success(t, n, i)
      }, t.error = function (t, n, i) {
        pubsub.trigger("je:notification", {
          msg: n
          , notice_type: "error"
        }), e && "function" == typeof e.error && e.error(t, n, i)
      }, jQuery.ajax(t)
    }
    , doAuth: function (e, t) {
      var n;
      if ("login" === e) this.unset("user_pass_again", {
        silent: !0
      }), e = "et_login";
      else {
        if ("register" !== e) return !1;
        e = "et_register"
      }
      return n = _.extend({
        data: {
          action: e
          , user_email: this.get("user_email")
          , user_pass: this.get("user_pass")
          , user_name: this.get("user_name")
        }
      }, this.params, t || {}), n.data = _.extend(n.data, t), n.beforeSend = function () {
        pubsub.trigger("je:request:waiting"), t && "function" == typeof t.beforeSend && t.beforeSend()
      }, n.success = function (e, n, i) {
        pubsub.trigger("je:response:auth", e, n, i), t && "function" == typeof t.success && t.success(e, n, i)
      }, n.error = function (e, n, i) {
        pubsub.trigger("je:notification", {
          msg: n
          , notice_type: "error"
        }), t && "function" == typeof t.error && t.error(e, n, i)
      }, jQuery.ajax(n)
    }
    , doLogout: function (e) {
      var t = _.extend({
        data: {
          action: "et_logout"
        }
      }, this.params, e || {});
      return e && "function" == typeof e.beforeSend && (t.beforeSend = e.beforeSend), t.success = function (t, n, i) {
        pubsub.trigger("je:response:logout", t, n, i), e && "function" == typeof e.success && e.success(t, n, i)
      }, jQuery.ajax(t)
    }
    , doResetPassword: function (e) {
      var t = _.extend({
        data: {
          action: "et_reset_password"
          , user_login: this.get("user_name")
          , user_pass: this.get("user_pass")
          , user_key: this.get("user_key")
        }
      }, this.params, e || {});
      return t.beforeSend = function () {
        pubsub.trigger("je:request:waiting"), e && "function" == typeof e.beforeSend && e.beforeSend()
      }, t.success = function (t, n, i) {
        pubsub.trigger("je:response:reset_password", t, n, i), e && "function" == typeof e.success && e.success(t, n, i)
      }, jQuery.ajax(t)
    }
    , doRequestResetPassword: function (e) {
      var t = _.extend({
        data: {
          action: "et_request_reset_password"
          , user_login: this.get("user_email")
        }
      }, this.params, e || {});
      return t.beforeSend = function () {
        pubsub.trigger("je:request:requestResetPassWaiting"), e && "function" == typeof e.beforeSend && e.beforeSend()
      }, t.success = function (t, n, i) {
        pubsub.trigger("je:response:request_reset_password", t, n, i), e && "function" == typeof e.success && e.success(t, n, i)
      }, jQuery.ajax(t)
    }
  }), JobEngine.Models.Company = JobEngine.Models.Auth.extend({
    defaults: {
      display_name: ""
      , user_url: ""
      , post_url: ""
      , recent_location: ""
    }
    , action: "et_company_sync"
    , role: "company"
    , initialize: function () {
		// PO-1709
      _.bindAll(this, 'parse', 'renderListItem', 'setName', 'getName', 'setUrl', 'getUrl', 'setLocation', 'getLocation', 'getApplyMethod', 'getApplyEmail', 'getApplicantDetail', 'setApplyMethod', 'setApplyEmail', 'setApplicantDetail', 'sync');
	  // -/ PO-1709
	  JobEngine.Models.Auth.prototype.initialize.call()
    }
    , parse: function (e) {
      return e.success ? e.data : (pubsub.trigger("je:error:user_sync", e), {})
    }
    , renderListItem: function () {
      return this.itemTemplate(this.toJSON)
    }
    , setName: function (e) {
      this.set({
        display_name: e
      }, {
        silent: !0
      })
    }
    , getName: function () {
      return this.get("display_name")
    }
    , setUrl: function (e) {
      this.set({
        user_url: e
      }, {
        silent: !0
      })
    }
    , getUrl: function () {
      return this.get("user_url")
    }
    , setLocation: function (e) {
      this.set({
        recent_location: e
      }, {
        silent: !0
      })
    }
    , getLocation: function () {
      return this.get("recent_location")
    }
    , getApplyMethod: function () {
      return this.get("apply_method")
    }
    , getApplyEmail: function () {
      return this.get("apply_email")
    }
    , getApplicantDetail: function () {
      return this.get("applicant_detail")
    }
    , setApplyMethod: function (e) {
      this.set({
        apply_method: e
      }, {
        silent: !0
      })
    }
    , setApplyEmail: function (e) {
      this.set({
        apply_email: e
      }, {
        silent: !0
      })
    }
    , setApplicantDetail: function (e) {
      this.set({
        applicant_detail: e
      }, {
        silent: !0
      })
    }
    , sync: function (e, t, n) {
      var i = _.extend({
        type: "POST"
        , dataType: "json"
        , url: et_globals.ajaxURL
        , contentType: "application/x-www-form-urlencoded;charset=UTF-8"
      }, n || {});
      return "read" == e && (i.type = "GET", i.action = t.action, i.data = {
        id: t.id ? t.id : ""
        , login_name: t.login_name ? t.login_name : ""
      }), i.data || !t || "create" != e && "update" != e && "delete" != e || (i.action = t.action, i.data = t.toJSON()), "GET" !== i.type && (i
        .processData = !1), i.data = jQuery.param({
        action: i.action
        , method: e
        , content: i.data
      }), jQuery.ajax(i)
    }
  }), JobEngine.Collections.Jobs = Backbone.Collection.extend({
    model: JobEngine.Models.Job
    , list_title: ""
    , fetchData: {
      paged: 1
      , job_type: ""
      , job_category: ""
      , s: ""
      , location: ""
      , search_ambulances: ""
      , search_hospitals: ""
    }
    , action: "et_fetch_jobs"
    , paginateData: {}
    , comparator: function (e) {
      var t = new Date(e.get("post_date"));
      return -parseInt(e.get("featured") + "" + t.getTime(), 10)
    }
    , setData: function (e) {
      return this.fetchData = e, "paged" in this.fetchData || (this.fetchData.paged = 1), this
    }
    , nextPage: function (e) {
      var t, n = this;
      "paged" in this.fetchData ? this.fetchData.paged++ : this.fetchData.paged = 2;
      var t = _.extend({
        data: this.fetchData
        , add: !0
      }, e || {});
      t.beforeSend = function () {
        n.trigger("nextPageBeforeSend"), e && "function" == typeof e.beforeSend && e.beforeSend()
      }, t.success = function (t, i) {
        n.trigger("nextPageSuccess"), e && "function" == typeof e.success && e.success(t, i)
      }, this.fetch(t)
    }
    , filter: function (e) {
      var t = this
        , n = _.extend({
          data: _.extend({
            paged: 1
          }, this.fetchData)
        }, e || {});
      n.beforeSend = function () {
        t.trigger("filterBeforeSend"), e && "function" == typeof e.beforeSend && e.beforeSend()
      }, n.success = function (n, i) {
        t.trigger("filterSuccess"), e && "function" == typeof e.success && e.success(n, i)
      }, this.fetch(n)
    }
    , parse: function (e) {
      return e.data ? ("list_title" in e.data && (this.list_title = e.data.list_title), this.paginateData = _.clone(e.data), delete this.paginateData
        .jobs, _.map(e.data.jobs, function (t) {
          var n = new JobEngine.Models.Job(t);
          return t.author_id in e.data.authors && (n.author.set(e.data.authors[t.author_id], {
            silent: !0
          }), n.updateJobAuthor()), n
        })) : void 0
    }
    , sync: function (e, t, n) {
      var i = _.extend({
        type: "POST"
        , dataType: "json"
        , url: et_globals.ajaxURL
        , contentType: "application/x-www-form-urlencoded;charset=UTF-8"
      }, n || {});
      return "read" == e && (i.type = "GET", i.data = _.extend(i.data, t.JSON)), i.data || !t || "create" != e && "update" != e && "delete" != e || (i
        .data = t.toJSON()), "GET" !== i.type && (i.processData = !1), i.action = t.action, i.data = jQuery.param({
        action: i.action
        , method: e
        , content: i.data
      }), jQuery.ajax(i)
    }
  }), JobEngine.Collections.Companies = Backbone.Collection.extend({
    model: JobEngine.Models.Company
    , initialize: function () {}
  }), JobEngine.Views.File_Uploader = Backbone.View.extend({
    initialize: function () {
      if (_.bindAll(this, 'onFileAdded', 'onFileUploaded', 'updateThumbnail', 'insertThumb', 'onFilesBeforeSend', 'onUploadComplete'), this.uploaderID =
        this.options.uploaderID ? this.options.uploaderID : "et_uploader", this.delete_button = this.options.delete_button ? this.options.delete_button :
        !1, this.delete_button) {
        jQuery(this.el)
          .append('<div class="delete-image-button icon" data-icon="D" title="Delete"></div>');
        var t = this.delete_action;
        jQuery(this.el)
          .find("delete-image-button")
          .on("click", function (e) {
            jQuery.ajax({
                type: "POST"
                , dataType: "html"
                , url: et_globals.ajaxURL
                , data: {
                  action: t
                }
              })
              .done(function (e) {
                console.log("ok")
              })
          })
      }
      this.config = {
        runtimes: "gears,html5,flash,silverlight,browserplus,html4"
        , multiple_queues: !0
        , multipart: !0
        , urlstream_upload: !0
        , multi_selection: !1
        , upload_later: !1
        , container: this.uploaderID + "_container"
        , browse_button: this.uploaderID + "_browse_button"
        , thumbnail: this.uploaderID + "_thumbnail"
        , thumbsize: "thumbnail"
        , file_data_name: this.uploaderID
        , max_file_size: "1mb"
        , filters: [{
          title: "Image Files"
          , extensions: "jpg,jpeg,gif,png,svg"
        }]
        , multipart_params: {
          fileID: this.uploaderID
        }
      }, jQuery.extend(!0, this.config, et_globals.plupload_config, this.options);
      var n = e("#job_list_container div.button-more #acction")
        .val();
      "company" != n && (this.controller = new plupload.Uploader(this.config), this.controller.init(), this.controller.bind("FileUploaded", this
          .onFileUploaded), this.controller.bind("FilesAdded", this.onFileAdded), this.controller.bind("BeforeUpload", this.onFilesBeforeSend), this
        .bind("UploadSuccessfully", this.onUploadComplete), "function" == typeof this.controller.settings.onProgress && this.controller.bind(
          "UploadProgress", this.controller.settings.onProgress), "function" == typeof this.controller.settings.onError && this.controller.bind("Error",
          this.controller.settings.onError), "function" == typeof this.controller.settings.cbRemoved && this.controller.bind("FilesRemoved", this
          .controller.settings.cbRemoved))
    }
    , onFileAdded: function (e, t) {
      "function" == typeof this.controller.settings.cbAdded && this.controller.settings.cbAdded(e, t), this.controller.settings.upload_later || (e
        .refresh(), e.start())
    }
    , onFileUploaded: function (t, n, i) {
      i = e.parseJSON(i.response), "function" == typeof this.controller.settings.cbUploaded && this.controller.settings.cbUploaded(t, n, i), i.success &&
        (this.updateThumbnail(i.data), this.trigger("UploadSuccessfully", i))
    }
    , updateThumbnail: function (e) {
      var t, n, i = this
        , o = this.$("#" + this.controller.settings.thumbnail);
      o.length > 0 && (t = o.find("img"), n = this.controller.settings.thumbsize, t.length > 0 ? t.fadeOut(100, function () {
        t.remove(), _.isArray(e[n]) && i.insertThumb(e[n][0], o)
      }) : _.isArray(e[n]) && this.insertThumb(e[n][0], o))
    }
    , insertThumb: function (e, t) {
      jQuery("<img>")
        .attr({
          id: this.uploaderID + "_thumb"
          , src: e
        })
        .appendTo(t)
        .fadeIn(300)
    }
    , updateConfig: function (t) {
      "updateThumbnail" in t && "data" in t && this.updateThumbnail(t.data), e.extend(!0, this.controller.settings, t), this.controller.refresh()
    }
    , onFilesBeforeSend: function () {
      "beforeSend" in this.options && "function" == typeof this.options.beforeSend && this.options.beforeSend(this.$el)
    }
    , onUploadComplete: function (e) {
      "success" in this.options && "function" == typeof this.options.success && this.options.success(e)
    }
  }), JobEngine.Views.Modal_Box = Backbone.View.extend({
    defaults: {
      top: 100
      , overlay: .5
    }
    , $overlay: null
    , initialize: function () {
		// PO-1709
      _.bindAll(this, 'openModal', 'closeModal');
	  // -/ PO-1709

	  this.options = jQuery.extend(this.defaults, this.options), this.$overlay = jQuery("#lean_overlay"), this.$overlay.length <= 0 && (
        this.$overlay = jQuery("<div id='lean_overlay'></div>")
        .appendTo("body"))
    }
    , openModal: function () {
      var t = this;
      this.$overlay.css({
          display: "block"
          , opacity: 0
        })
        .fadeTo(200, this.options.overlay), this.$el.css({
          display: "block"
          , position: "absolute"
          , opacity: 0
          , "z-index": 11e3
          , left: "50%"
          , "margin-left": -(this.$el.outerWidth() / 2) + "px"
          , top: e(window)
            .scrollTop() + this.options.top + "px"
          , width: this.options.width
          , height: this.options.height
        })
        .fadeTo(200, 1, function () {
          t.$el.find("input[type=text]:first")
            .focus()
        })
    }
    , closeModal: function (e, t) {
      var n = this;
      return e = e || 200, this.$overlay.fadeOut(200, function () {
        n.$el.hide(), "function" == typeof t && t()
      }), !1
    }
  }), JobEngine.Views.ModalReject = JobEngine.Views.Modal_Box.extend({
    el: "#modal-reject-job"
    , events: {
      "click div.modal-close": "closeModal"
      , "click a.cancel-modal": "closeModal"
      , "click #btn-reject": "reject"
    }
    , initialize: function () {
      JobEngine.Views.Modal_Box.prototype.initialize.apply(this, arguments), this.options = _.extend(this.options, this.defaults), pubsub.on(
          "je:job:afterRejectJob", this.afterRejectJob, this), pubsub.on("je:resume:afterRejectResume", this.afterRejectJob, this), this.loadingBtn =
        new JobEngine.Views.LoadingButton({
          el: this.$("input#btn-reject")
        })
    }
    , onReject: function (e) {
      this.model = e.model, this.$el.find("#job_title")
        .html(this.model.get("title"))
        .end()
        .find("#company_name")
        .html(this.model.get("author")), this.openModal()
    }
    , reject: function (e) {
      e.preventDefault(), this.loadingBtn.loading(), this.message = this.$el.find("textarea[name=reason]")
        .val(), this.refund = this.$el.find("input[name=refund]")
        .val();
      var t = this;
      this.model.reject({
        data: {
          reason: t.message
          , refund: t.refund
        }
        , silent: !0
      })
    }
    , afterRejectJob: function () {
      this.loadingBtn.finish(), this.closeModal()
    }
  }), JobEngine.Views.LoadingEffect = Backbone.View.extend({
    initialize: function () {}
    , render: function () {
      return this.$el.html(et_views.loadingImg), this
    }
    , finish: function () {
      this.$el.html(et_views.loadingFinish);
      var t = this;
      setTimeout(function () {
        t.$el.fadeOut(500, function () {
          e(this)
            .remove()
        })
      }, 1e3)
    }
    , remove: function () {
      view.$el.remove()
    }
  }), JobEngine.Views.BlockUi = Backbone.View.extend({
    defaults: {
      image: et_globals.imgURL + "/loading.gif"
      , opacity: "0.5"
      , background_position: "center center"
      , background_color: "#ffffff"
    }
    , isLoading: !1
    , initialize: function (t) {
      t = _.extend(_.clone(this.defaults), t);
      t.image;
      this.overlay = e('<div class="loading-blur loading"><div class="loading-overlay"></div><div class="loading-img"></div></div>'), this.overlay.find(
          ".loading-img")
        .css({
          "background-image": "url(" + t.image + ")"
          , "background-position": t.background_position
        }), this.overlay.find(".loading-overlay")
        .css({
          opacity: t.opacity
          , filter: "alpha(opacity=" + 100 * t.opacity + ")"
          , "background-color": t.background_color
        }), this.$el.html(this.overlay), this.isLoading = !1
    }
    , render: function () {
      return this.$el.html(this.overlay), this
    }
    , block: function (t) {
      var n = e(t);
      this.overlay.css({
          position: "absolute"
          , top: n.offset()
            .top
          , left: n.offset()
            .left
          , width: n.outerWidth()
          , height: n.outerHeight()
        }), this.isLoading = !0, this.render()
        .$el.show()
        .appendTo(e("body"))
    }
    , unblock: function () {
      this.$el.remove(), this.isLoading = !1
    }
    , finish: function () {
      this.$el.fadeOut(500, function () {
        e(this)
          .remove()
      }), this.isLoading = !1
    }
  }), JobEngine.Views.LoadingButton = Backbone.View.extend({
    dotCount: 3
    , isLoading: !1
    , initialize: function () {
      if (this.$el.length <= 0) return !1;
      this.$el[0];
      "INPUT" == this.$el[0].tagName ? this.title = this.$el.val() : this.title = this.$el.html(), this.isLoading = !1
    }
    , loopFunc: function (e) {
      var t = "";
      for (i = 0; i < e.dotCount; i++) t += ".";
      e.dotCount = (e.dotCount + 1) % 3, e.setTitle(et_globals.loading + t)
    }
    , setTitle: function (e) {
      "undefined" != typeof this.$el[0] && ("INPUT" === this.$el[0].tagName ? this.$el.val(e) : this.$el.html(e))
    }
    , loading: function () {
      this.setTitle(et_globals.loading), this.$el.addClass("disabled"), this.$el.attr("disabled", "disabled");
      var e = this;
      e.isLoading = !0, e.dots = "...", e.setTitle(et_globals.loading + e.dots), this.loop = setInterval(function () {
        "..." === e.dots ? e.dots = "" : ".." === e.dots ? e.dots = "..." : "." === e.dots ? e.dots = ".." : e.dots = ".", e.setTitle(et_globals
          .loading + e.dots)
      }, 500)
    }
    , finish: function () {
      this.$el[0];
      this.isLoading = !1, clearInterval(this.loop), this.setTitle(this.title), this.$el.removeClass("disabled"), this.$el.removeAttr("disabled",
        "disabled")
    }
  }), JobEngine.TaxFactory = function () {
    var e = {}
      , t = {};
    return {
      getTaxModel: function (t, n) {
        var i = e[t];
        return i ? new i(n) : null
      }
      , registerTaxModel: function (t, n) {
        return e[t] = n, JobEngine.TaxFactory
      }
      , getTaxItem: function (e, n) {
        var i = t[e];
        return i ? new i(n) : null
      }
      , registerTaxItem: function (e, n) {
        return t[e] = n, JobEngine.TaxFactory
      }
    }
  }(), JobEngine.Models.Tax = Backbone.Model.extend({
    initialize: function () {
      this.action = ""
    }
    , parse: function (e) {
      return e.data ? e.data : void 0
    }
    , remove: function (e) {
      var t = _.extend(ajaxParams, e)
        , n = this.action;
      return t.data = _.extend(t.data, this.toJSON()), t.data = jQuery.param({
        method: "delete"
        , action: n
        , content: t.data
      }), jQuery.ajax(t)
    }
    , sync: function (e, t, n) {
      var i = _.extend(ajaxParams, n)
        , o = this.action;
      return i.data = t.toJSON(), i.data = jQuery.param({
        method: e
        , action: o
        , content: i.data
      }), jQuery.ajax(i)
    }
  }), JobEngine.Views.TaxItem = Backbone.View.extend({
    tagName: "li"
    , events: {
      "click a.act-del": "displayReplaceList"
      , "click a.act-open-form": "openForm"
      , "submit .form-sub-tax": "addSubTax"
      , "click .form-sub-tax a.act-add-sub": "addSubTax"
      , "keyup .form-sub-tax a.act-add-sub": "keyupSubTax"
      , "change input.tax-name": "updateName"
      , "keyup .new-tax": "cancelAddition"
    }
    , template: _.template(
      '<div class="container"> 						<div class="sort-handle"></div> 					<div class="controls controls-2"> 						<a class="button act-open-form" rel="<%= id %>" title=""> 							<span class="icon" data-icon="+"></span> 						</a> 						<a class="button act-del" rel="<%= id %>"> 							<span class="icon" data-icon="*"></span> 						</a> 					</div> 					<div class="input-form input-form-2"> 						<input class="bg-grey-input tax-name" rel="<%= id %>" type="text" value="<%= name %>"> 					</div> 				</div>'
      )
    , sub_template: _.template(
      '<li class="form-sub-tax disable-sort" id="tax_<%= id %>"> 					<div class="container">						<!--	<div class="sort-handle"></div>  --> 						<div class="controls controls-2">							<a class="button act-add-sub" title=""> 								<span class="icon" data-icon="+"></span> 							</a>						</div>						<div class="input-form input-form-2"> 							<form action="" class="" data-tax="' +
      this.tax_name +
      '">								<input type="hidden" name="parent" value="<%=id%>">								<input class="bg-grey-input new-tax" name="name" type="text" placeholder="Enter category name"> 							</form> 						</div> 					</div>				</li>'
      )
    , initialize: function () {}
    , render: function () {
      return this.$el.append(this.template(this.model.toJSON()))
        .addClass("tax-item")
        .attr("id", "tax_" + this.model.get("id")), this
    }
    , openForm: function (t) {
      var n = this
        , i = e(t.currentTarget)
        .attr("rel");
      this.model.get("id") == i && ($html = this.sub_template({
          id: i
        }), 0 == n.$el.find("ul")
        .length && n.$el.append("<ul>"), n.$el.children("ul")
        .append($html), n.$el.children("ul")
        .find(".new-tax")
        .focus())
    }
    , keyupSubTax: function (e) {
      return e.preventDefault(), 13 == keyup.which && this.addSubTax(e), !1
    }
    , addSubTax: function (t) {
      t.stopPropagation(), t.preventDefault();
      var n = this
        , i = n.$el.children("ul")
        .children("li.form-sub-tax")
        , o = i.find("form")
        , a = new JobEngine.Views.LoadingEffect;
      if ("" == o.find("input[name=name]")
        .val()) return !1;
      var s = JobEngine.TaxFactory.getTaxModel(o.attr("data-tax"), {
        parent: o.find("input[name=parent]")
          .val()
        , name: o.find("input[name=name]")
          .val()
      });
      s.save(s.toJSON(), {
        beforeSend: function () {
          a.render()
            .$el.appendTo(i.find(".controls"))
        }
        , success: function (t, s) {
          if (s.success) {
            a.finish();
            var r = JobEngine.TaxFactory.getTaxItem(o.attr("data-tax"), {
              model: t
            });
            e(r.render()
                .el)
              .insertBefore(n.$el.children("ul")
                .find("li:last")), i.remove()
          }
        }
      })
    }
    , updateName: function (t) {
      var n = e(t.currentTarget)
        , i = n.attr("rel")
        , o = n.val()
        , a = new JobEngine.Views.LoadingEffect
        , s = this;
      i == this.model.get("id") && (this.model.set("name", o), this.model.save(this.model.toJSON(), {
        beforeSend: function () {
          a.render()
            .$el.appendTo(s.$el.children(".container")
              .find(".controls"))
        }
        , success: function (e, t) {
          a.finish()
        }
      }))
    }
    , displayReplaceList: function (t) {
      t.stopPropagation();
      var n = e(e("#" + this.confirm_html)
          .html())
        , i = this.$el.children(".container")
        , o = this
        , a = this.$el.parents("ul.list-tax")
        .find("li");
      return n.find("select")
        .html(""), _.each(a, function (t, i) {
          n.find("select")
            .append('<option value="' + e(t)
              .find("input")
              .attr("rel") + '" >' + e(t)
              .find("input")
              .val() + "</option>")
        }), this.$el.find("ul > li")
        .length > 0 ? (alert(et_setting.del_parent_cat_msg), !1) : void i.fadeOut("normal", function () {
          n.insertAfter(i)
            .hide()
            .fadeIn("normal", function () {
              n.find("button.accept-btn")
                .bind("click", function (e) {
                  var t = n.find("select")
                    .val();
                  o.deleteTax(t)
                }), n.find("a.cancel-del")
                .bind("click", function (e) {
                  n.fadeOut("normal", function () {
                    i.fadeIn()
                  })
                }), n.bind("keyup", function (e) {
                  27 == e.which && n.fadeOut("normal", function () {
                    i.fadeIn()
                  })
                })
            }), n.find("option[value=" + o.model.get("id") + "]")
            .remove(), o.styleSelect()
        })
    }
    , deleteTax: function (t) {
      var n = this
        , i = new JobEngine.Views.BlockUi;
      new JobEngine.Views.LoadingEffect;
      this.model.remove({
        data: {
          default_cat: t
        }
        , beforeSend: function () {
          i.block(n.$el.find(".moved-tax"))
        }
        , success: function (t) {
          i.unblock(), t.success && n.$el.fadeOut("normal", function () {
            e(this)
              .remove()
          })
        }
      })
    }
    , cancelAddition: function (e) {
      27 == e.keyCode && this.closeForm()
    }
    , closeForm: function (e) {
      this.$el.children("ul")
        .children("li.form-sub-tax")
        .remove(), 0 == this.$el.children("ul")
        .find("li")
        .length && this.$el.children("ul")
        .remove()
    }
    , styleSelect: function () {
      this.$(".select-style select")
        .each(function () {
          var t = e(this)
            .find("option:selected")
            .html()
            , n = "";
          void 0 !== e(".select-style select")
            .attr("arrow") && (n = " " + e(".select-style select")
              .attr("arrow")), "" != e("option:selected", this)
            .val() && (t = e("option:selected", this)
              .text() + n), e(this)
            .css({
              "z-index": 10
              , opacity: 0
              , "-khtml-appearance": "none"
            })
            .after('<span class="select">' + t + n + "</span>")
            .change(function () {
              val = e("option:selected", this)
                .text() + n, e(this)
                .next()
                .text(val)
            })
        })
    }
  }), JobEngine.Views.BackendTax = Backbone.View.extend({
    events: {
      "submit form.new_tax": "addTax"
      , "click form.new_tax .button": "addTax"
      , "click .input-form .bar-flag div": "triggerChangeColor"
    }
    , initialize: function () {
      this.initTax(), this.initView()
    }
    , initView: function () {
      return !1
    }
    , initTax: function () {
      return !1
    }
    , sortTax: function (t, n, i) {
      var o = e(n.item)
        .attr("id")
        .replace(/\D/g, "")
        , a = e(n.item)
        .parents("li")
        .length > 0 ? e(n.item)
        .parents("li")
        .attr("id")
        .replace(/\D/g, "") : "0"
        , s = this.$el.find(".tax-sortable")
        .nestedSortable("toArray", {
          startDepthCount: 0
        })
        , r = this
        , l = new JobEngine.Views.BlockUi
        , c = {
          url: et_globals.ajaxURL
          , type: "post"
          , data: {
            action: i
            , content: {
              order: s
              , id: o
              , parent: a
            }
          }
          , beforeSend: function () {
            l.block(r.$el.find(".list-tax"))
          }
          , success: function (e) {
            l.unblock()
          }
        };
      e.ajax(c)
    }
    , addTax: function (t) {
      t.preventDefault();
      var n = this.$el.find("form.new_tax")
        , i = this
        , o = new JobEngine.Views.LoadingEffect
        , a = i.$el.find(".list-tax");
      if (n.hasClass("disabled") || "" == n.find("input[type=text]")
        .val()) return !1;
      var s = JobEngine.TaxFactory.getTaxModel(n.attr("data-tax"), {
        color: n.find("div.cursor")
          .attr("data") ? n.find("div.cursor")
          .attr("data") : 0
        , name: n.find("input[type=text]")
          .val()
      });
      s.save(s.toJSON(), {
        beforeSend: function () {
          n.addClass("disabled"), o.render()
            .$el.appendTo(n.find(".controls"))
        }
        , success: function (t, i) {
          n.removeClass("disabled"), o.finish();
          var s = JobEngine.TaxFactory.getTaxItem(n.attr("data-tax"), {
            model: t
          });
          e(s.render()
              .el)
            .hide()
            .appendTo(a)
            .fadeIn(), n.find("input[type=text]")
            .val("")
        }
      })
    }
    , submitForm: function (t) {
      var n = e(t.target)
        .parents("form");
      n.submit()
    }
    , triggerChangeColor: function (t) {
      var n = jQuery(t.currentTarget)
        , i = jQuery(t.currentTarget)
        .attr("class")
        , i = i.replace(" active", "")
        , o = this
        , a = n.attr("data")
        , s = n.parents(".input-form")
        .attr("data-action");
      if (n.parent()
        .parent()
        .find(".cursor")
        .removeAttr("class")
        .addClass("cursor")
        .addClass(i)
        .attr("data", a), n.parent()
        .parent()
        .find("input")
        .removeAttr("class")
        .addClass("bg-grey-input")
        .addClass(i), n.parent()
        .remove(), e(".current-job-type")
        .length > 0) {
        var r = e(".current-job-type")
          .attr("data");
        o.changeJobTypeColor(r, a, s)
      }
    }
    , changeJobTypeColor: function (t, n, i) {
      if ("undefined" != i) {
        var o = ajaxParams
          , a = this
          , s = new JobEngine.Views.BlockUi;
        o.data = {
          action: i
          , content: {
            term_id: t
            , color: n
          }
        }, o.beforeSend = function () {
          s.block(a.$el.find(".list-tax"))
        }, o.success = function (e) {
          s.unblock()
        }, e.ajax(o)
      }
    }
  }), jQuery.fn.buttonLoading = function () {
    e(this)
      .html(et_globals.loading)
  }
}(jQuery);