﻿var HIRELOCKER;
if (HIRELOCKER == undefined) {
    HIRELOCKER = {};
}

if (!HIRELOCKER.initialized) {

    HIRELOCKER.getId = function (id) {
        return document.getElementById(id);
    };

    HIRELOCKER.hasClassName = function (element, className) {
        var elementClassName = element.className;

        return (elementClassName.length > 0 && (elementClassName == className ||
      new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
    };

    HIRELOCKER.addClassName = function (element, className) {
        if (!HIRELOCKER.hasClassName(element, className))
            element.className += (element.className ? ' ' : '') + className;
        return element;
    };

    HIRELOCKER.removeClassName = function (element, className) {
        var newClass = HIRELOCKER.strip(element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' '));
        element.className = newClass;
        return element;
    };

    HIRELOCKER.strip = function (string) {
        return string.replace(/^\s+/, '').replace(/\s+$/, '');
    };

    HIRELOCKER.add_css = function (css_content) {
        var head = document.getElementsByTagName('head')[0];
        var style = document.createElement('style');
        style.type = 'text/css';

        if (style.styleSheet) {
            style.styleSheet.cssText = css_content;
        } else {
            rules = document.createTextNode(css_content);
            style.appendChild(rules);
        }
        head.appendChild(style);
    }

    HIRELOCKER.initialized = true;
}

HIRELOCKER.jobs_widget = function (options) {
    // Disable all widgets here
    this.widget_disabled = false;

    this.options = options;

    // Display ('overlay' for popups, 'iframe' for in page)
    if (!this.options.display) { this.options.display = "overlay"; }
    // Type used in conjunction with display=overlay ('widget' for tab or 'link' to popup from an exising link)
    if (!this.options.type) { this.options.type = "widget"; }

    // SSL
    this.is_ssl = ("https:" == document.location.protocol);
    if (this.is_ssl) {
        this.jobs_base_url = this.local_ssl_base_url;
        this.asset_base_url = this.s3_ssl_base_url;
    } else {
        this.jobs_base_url = this.local_base_url;
        this.asset_base_url = this.s3_base_url;
    }

    // Create option defaults
    this.options = options ? options : {};
    this.options.placement = this.options.placement ? this.options.placement : 'left';
    this.options.color = this.options.color ? this.options.color : '#222';

    // Set display defaults
    if (this.options.display == 'overlay') {
        // If popup, set defaults
        this.jobs_url = this.jobs_base_url + options.company + "/widget/";
        this.initial_iframe_url = '';
        if (!this.options.width) { this.options.width = "100%"; }
        if (!this.options.height) { this.options.height = "100%"; }
    }
    else {
        // If loaded into page, set defaults
        this.jobs_url = this.jobs_base_url + "public/JobsIFrame/?urlIdentifier=" + options.company + "&urlCallback=" + options.url;
        this.initial_iframe_url = this.jobs_url;
        if (!this.options.width) { this.options.width = "95%"; }
        if (!this.options.height) { this.options.height = "100%"; }
    }

    // Setup html for content
    if (this.widget_disabled) {
        this.iframe_html = '<div id="jobs_iframe" onload="setFocusToTextBox()" style="position:relative; top: 20px; margin:20px;background:orange;color:purple;font-size:72px; padding: 20px;">' +
                       'WIDGETS ARE UNAVAILABLE' +
                       '</div>';
    }
    else {
        this.iframe_html = '<iframe id="jobs_iframe" allowTransparency="true" onload="setFocusToTextBox()" scrolling="no" frameborder="0" style="width:' + this.options.width + '" class="loading"' +
                       (this.initial_iframe_url != '' ? ' src="' + this.initial_iframe_url + '"' : '') + "></iframe>";
    }

    // Setup html for tab and content
    this.tab_html = '<a href="#" id="jobs_tab" class="jobs_tab_' + this.options.placement + '" style="background-color:' + this.options.color + '">jobs</a>';
    this.overlay_html = '<div id="jobs_overlay" style="display:none">' +
                        '<div id="jobs_container">' +
                          '<a href="#" id="jobs_close"></a>' +
                          this.iframe_html +
                        '</div>' +
                        '<div id="jobs_screen"></div>' +
                      '</div>';

    if (this.options.display == 'overlay') {
        // Client wants a popup
        raw_css = "#jobs_overlay {\n  width: 100%;\n  height: 100%;\n  top: 0;\n  left: 0;\n  z-index: 1000000;\n  position: absolute; }\n\n#jobs_screen {\n  top: 0;\n  left: 0;\n  z-index: 1;\n  width: 100%;\n  position: absolute;\n  background-color: black;\n  opacity: 0.85;\n  -moz-opacity: 0.85;\n  filter: alpha(opacity=85); }\n\n#jobs_container {\n  width: 700px;\n  height: 485px;\n  margin: 0 auto;\n  z-index: 2;\n  position: relative; }\n  #jobs_container iframe {\n    width: 658px;\n    height: 515px;\n    margin: 20px;\n    background: transparent; }\n  #jobs_container iframe.loading {\n    background: transparent url(http://login.hirelocker.com/content/images/loading.png) no-repeat; }\n\na#jobs_tab {\n  top: 25%;\n  left: 7px;\n  width: 32px;\n  height: 104px;\n  color: white;\n  cursor: pointer;\n  text-indent: -100000px;\n  overflow: hidden;\n  position: fixed;\n  z-index: 100000;\n  margin-left: -7px;\n background-color: transparent;\n  background-image: url(http://login.hirelocker.com/content/images/trans_tab.png); }\n  a#jobs_tab:hover {\n    margin-left: -4px; }\n\na.jobs_tab_right {\n  right: 0 !important;\n  left: auto !important;\n  margin-right: 0 !important;\n  margin-left: auto !important;\n  width: 35px !important; }\n  a.jobs_tab_right:hover {\n    width: 38px !important;\n    margin-right: 0 !important;\n    margin-left: auto !important; }\n\na.jobs_tab_bottom {\n  top: auto !important;\n  bottom: 0 !important;\n  left: 20% !important;\n  height: 38px !important;\n  width: 102px !important;\n  background-position: 0 -102px !important;\n  margin-bottom: -7px !important;\n  margin-left: auto !important; }\n  a.jobs_tab_bottom:hover {\n    margin-bottom: -4px !important;\n    margin-left: auto !important; }\n\na.jobs_tab_hidden {\n  display: none !important; }\n\na#jobs_close {\n  position: absolute;\n  cursor: pointer;\n  outline: none;\n  top: 20px;\n  right: 26px;\n  z-index: 4;\n  width: 42px;\n  height: 42px;\n  overflow: hidden;\n  background-image: url(http://login.hirelocker.com/content/images/close.png); }\n  a#jobs_close:hover {\n    background-position: -42px 0; }\n\n.jobs_tab_on embed, .jobs_tab_on select, .jobs_tab_on object {\n  visibility: hidden; }\n";


        replacer_regex = new RegExp(this.s3_ssl_base_url, "g");
        translated_css = raw_css.replace(replacer_regex, this.asset_base_url);
        HIRELOCKER.add_css(translated_css);

        if (this.options.type == 'link') {
            // If type=link, client wants popup to appear after clicking on a link on their page
            // Therefore, only output content
            document.write(this.overlay_html);
        } else {
            // Output content and tab
            document.write(this.tab_html);
            document.write(this.overlay_html);
        }

        var jobs_obj = this;

        if (this.options.type == 'link') {
            // Client wants to use an existing link to open popup (has to be id = hirelocker_jobs_link )
            $('#hirelocker_jobs_link').live("click", function () { jobs_obj.show(); return false; });
        } else {
            // Client wants widget...
            HIRELOCKER.getId('jobs_tab').onclick = function () { jobs_obj.show(); return false; }
        }

        // Final setters
        HIRELOCKER.getId('jobs_close').onclick = function () { jobs_obj.hide(); return false; }
        HIRELOCKER.getId('jobs_iframe').removeAttribute("src");

    } else {
        // Client wants an in page iframe
        if (this.options.container) {
            // They have passed in an id, insert content here...
            var container_el = HIRELOCKER.getId(this.options.container);
            container_el.innerHTML = this.iframe_html;
        } else {
            // no id given, output as is...
            document.write(this.iframe_html);

            iFrameResize({
                log: false,
                checkOrigin: false,// Enable console logging
                enablePublicMethods: true,
                resizedCallback: function (messageData) { // Callback fn when resize is received
                    //document.getElementById('jobs_iframe').scrollIntoView();
                }
            });
        }
    }
};

HIRELOCKER.jobs_widget.prototype = {
    local_base_url: "http://login.hirelocker.com/",
    local_ssl_base_url: "https://login.hirelocker.com/",
    s3_base_url: "http://login.hirelocker.com/",
    s3_ssl_base_url: "https://login.hirelocker.com/",

    asset_url: function (asset) {
        return this.asset_base_url + asset;
    },

    set_position: function () {
        this.scroll_top = document.documentElement.scrollTop || document.body.scrollTop;
        this.scroll_height = document.documentElement.scrollHeight;
        this.client_height = window.innerHeight || document.documentElement.clientHeight;

        HIRELOCKER.getId('jobs_screen').style.height = this.scroll_height + "px";
        HIRELOCKER.getId('jobs_container').style.top = this.scroll_top + (this.client_height * 0.1) + "px";
    },

    show: function () {

        // Phone/Tablet detection
        var ismobile = false;

        var ua = navigator.userAgent;
        var checker = {
            iphone: ua.match(/(iPhone|iPod|iPad)/),
            blackberry: ua.match(/BlackBerry/),
            android: ua.match(/Android/)
        };

        // Check for devices...
        if (checker.android || checker.iphone || checker.blackberry) {
            ismobile = true;
        }

        if (ismobile) {
            // if this a mobile device, open jobs in a new page (popups not good in phone/tablets)
            var url_job = this.jobs_url;

            var RegularExpression = new RegExp("widget/");
            var newOutput = url_job.replace(RegularExpression, '');

            newwindow = window.open(newOutput, target = '_blank');
        } else {
            // if normal browser, open popup overlay
            HIRELOCKER.getId('jobs_iframe').setAttribute("src", this.jobs_url);

            if (HIRELOCKER.getId('jobs_iframe').addEventListener) {
                HIRELOCKER.getId('jobs_iframe').addEventListener("load", this.loaded, false);
            } else if (HIRELOCKER.getId('jobs_iframe').attachEvent) {
                HIRELOCKER.getId('jobs_iframe').attachEvent("onload", this.loaded);
            }
            this.set_position();

            HIRELOCKER.addClassName(document.getElementsByTagName('html')[0], 'jobs_tab_on');
            HIRELOCKER.getId('jobs_overlay').style.display = "block";
        }
    },

    hide: function () {
        if (HIRELOCKER.getId('jobs_iframe').addEventListener) {
            HIRELOCKER.getId('jobs_iframe').removeEventListener("load", this.loaded, false);
        } else if (HIRELOCKER.getId('jobs_iframe').attachEvent) {
            HIRELOCKER.getId('jobs_iframe').detachEvent("onload", this.loaded);
        }

        HIRELOCKER.getId('jobs_overlay').style.display = "none";
        HIRELOCKER.getId('jobs_iframe').removeAttribute("src");
        HIRELOCKER.getId('jobs_iframe').className = "loading";

        HIRELOCKER.removeClassName(document.getElementsByTagName('html')[0], 'jobs_tab_on');
    },

    loaded: function () {
        HIRELOCKER.getId('jobs_iframe').className = "loaded";
    },

    get_fastpass_url: function (options) {
        if (options.fastpass) {
            return options.fastpass;
        }
        var script_tags = document.getElementsByTagName('script');
        for (var i = 0; i < script_tags.length; i++) {
            var tag = script_tags[i];
            if (tag.src.match(/\/fastpass/ && tag.src.match(/oauth/))) {
                return tag.src;
            }
        }
    }
}

if (!Array.prototype.forEach) {
    Array.prototype.forEach = function (fun /*, thisArg */) {
        "use strict";
        if (this === void 0 || this === null || typeof fun !== "function") throw new TypeError();

        var
            t = Object(this),
            len = t.length >>> 0,
            thisArg = arguments.length >= 2 ? arguments[1] : void 0;

        for (var i = 0; i < len; i++)
            if (i in t)
                fun.call(thisArg, t[i], i, t);
    };
}

!function () { "use strict"; function a(a, b, c) { "addEventListener" in window ? a.addEventListener(b, c, !1) : "attachEvent" in window && a.attachEvent("on" + b, c) } function b() { var a, b = ["moz", "webkit", "o", "ms"]; for (a = 0; a < b.length && !w; a += 1) w = window[b[a] + "RequestAnimationFrame"]; w || c(" RequestAnimationFrame not supported") } function c(a) { y.log && "object" == typeof console && console.log(s + "[Host page" + u + "]" + a) } function d(a) { function b() { function a() { h(z), f(), y.resizedCallback(z) } i(a, z, "resetPage") } function d(a) { var b = a.id; c(" Removing iFrame: " + b), a.parentNode.removeChild(a), y.closedCallback(b), c(" --") } function e() { var a = x.substr(t).split(":"); return { iframe: document.getElementById(a[0]), id: a[0], height: a[1], width: a[2], type: a[3] } } function j(a) { var b = Number(y["max" + a]), d = Number(y["min" + a]), e = a.toLowerCase(), f = Number(z[e]); if (d > b) throw new Error("Value for min" + a + " can not be greater than max" + a); c(" Checking " + e + " is in range " + d + "-" + b), d > f && (f = d, c(" Set " + e + " to min value")), f > b && (f = b, c(" Set " + e + " to max value")), z[e] = "" + f } function k() { var b = a.origin, d = z.iframe.src.split("/").slice(0, 3).join("/"); if (y.checkOrigin && (c(" Checking connection is from: " + d), "" + b != "null" && b !== d)) throw new Error("Unexpected message received from: " + b + " for " + z.iframe.id + ". Message was: " + a.data + ". This error can be disabled by adding the checkOrigin: false option."); return !0 } function l() { return s === ("" + x).substr(0, t) } function m() { var a = z.type in { "true": 1, "false": 1 }; return a && c(" Ignoring init message from meta parent page"), a } function n() { var a = x.substr(x.indexOf(":") + r + 6); c(" MessageCallback passed: {iframe: " + z.iframe.id + ", message: " + a + "}"), y.messageCallback({ iframe: z.iframe, message: a }), c(" --") } function o() { if (null === z.iframe) throw new Error("iFrame (" + z.id + ") does not exist on " + u); return !0 } function q() { c(" Reposition requested from iFrame"), v = { x: z.width, y: z.height }, f() } function w() { switch (z.type) { case "close": d(z.iframe), y.resizedCallback(z); break; case "message": n(); break; case "scrollTo": q(); break; case "reset": g(z); break; case "init": b(), y.initCallback(z.iframe); break; default: b() } } var x = a.data, z = {}; l() && (c(" Received: " + x), z = e(), j("Height"), j("Width"), !m() && o() && k() && (w(), p = !1)) } function e() { null === v && (v = { x: void 0 !== window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft, y: void 0 !== window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop }, c(" Get position: " + v.x + "," + v.y)) } function f() { null !== v && (window.scrollTo(v.x, v.y), c(" Set position: " + v.x + "," + v.y), v = null) } function g(a) { function b() { h(a), j("reset", "reset", a.iframe) } c(" Size reset requested by " + ("init" === a.type ? "host page" : "iFrame")), e(), i(b, a, "init") } function h(a) { function b(b) { a.iframe.style[b] = a[b] + "px", c(" IFrame (" + a.iframe.id + ") " + b + " set to " + a[b] + "px") } y.sizeHeight && b("height"), y.sizeWidth && b("width") } function i(a, b, d) { d !== b.type && w ? (c(" Requesting animation frame"), w(a)) : a() } function j(a, b, d) { c("[" + a + "] Sending msg to iframe (" + b + ")"), d.contentWindow.postMessage(s + b, "*") } function k() { function b() { function a(a) { 1 / 0 !== y[a] && 0 !== y[a] && (k.style[a] = y[a] + "px", c(" Set " + a + " = " + y[a] + "px")) } a("maxHeight"), a("minHeight"), a("maxWidth"), a("minWidth") } function d(a) { return "" === a && (k.id = a = "iFrameResizer" + o++, c(" Added missing iframe ID: " + a + " (" + k.src + ")")), a } function e() { c(" IFrame scrolling " + (y.scrolling ? "enabled" : "disabled") + " for " + l), k.style.overflow = !1 === y.scrolling ? "hidden" : "auto", k.scrolling = !1 === y.scrolling ? "no" : "yes" } function f() { ("number" == typeof y.bodyMargin || "0" === y.bodyMargin) && (y.bodyMarginV1 = y.bodyMargin, y.bodyMargin = "" + y.bodyMargin + "px") } function h() { return l + ":" + y.bodyMarginV1 + ":" + y.sizeWidth + ":" + y.log + ":" + y.interval + ":" + y.enablePublicMethods + ":" + y.autoResize + ":" + y.bodyMargin + ":" + y.heightCalculationMethod + ":" + y.bodyBackground + ":" + y.bodyPadding + ":" + y.tolerance } function i(b) { a(k, "load", function () { var a = p; j("iFrame.onload", b, k), !a && y.heightCalculationMethod in x && g({ iframe: k, height: 0, width: 0, type: "init" }) }), j("init", b, k) } var k = this, l = d(k.id); e(), b(), f(), i(h()) } function l(a) { if ("object" != typeof a) throw new TypeError("Options is not an object.") } function m() { function a(a) { if ("IFRAME" !== a.tagName.toUpperCase()) throw new TypeError("Expected <IFRAME> tag, found <" + a.tagName + ">."); k.call(a) } function b(a) { a = a || {}, l(a); for (var b in z) z.hasOwnProperty(b) && (y[b] = a.hasOwnProperty(b) ? a[b] : z[b]) } return function (c, d) { b(c), Array.prototype.forEach.call(document.querySelectorAll(d || "iframe"), a) } } function n(a) { a.fn.iFrameResize = function (b) { return b = b || {}, l(b), y = a.extend({}, z, b), this.filter("iframe").each(k).end() } } var o = 0, p = !0, q = "message", r = q.length, s = "[iFrameSizer]", t = s.length, u = "", v = null, w = window.requestAnimationFrame, x = { max: 1, scroll: 1, bodyScroll: 1, documentElementScroll: 1 }, y = {}, z = { autoResize: !0, bodyBackground: null, bodyMargin: null, bodyMarginV1: 8, bodyPadding: null, checkOrigin: !0, enablePublicMethods: !1, heightCalculationMethod: "offset", interval: 32, log: !1, maxHeight: 1 / 0, maxWidth: 1 / 0, minHeight: 0, minWidth: 0, scrolling: !1, sizeHeight: !0, sizeWidth: !1, tolerance: 0, closedCallback: function () { }, initCallback: function () { }, messageCallback: function () { }, resizedCallback: function () { } }; b(), a(window, "message", d), "jQuery" in window && n(jQuery), "function" == typeof define && define.amd ? define(function () { return m() }) : window.iFrameResize = m() }();

function setFocusToTextBox() {
    document.getElementById("FirstName").focus();
}