﻿if (!window.CP) {
    var cpSSL = new Image(100, 25);
    cpSSL.src = "https://app.careerpassport.eu/Content/images/web/cplogo.gif";

    CP = {
        _testMode: false,
        _apiKey: null,
        _apiQuery: "",
        _hashedSecret: null,
        _popup: null,
        _popupWidth: 550,
        _popupHeight: 350,
        _popupFeatures: 'status=0, scrollbars=0, toolbar=0, resizable=0',
        _largePopupWidth: 1020,
        _largePopupHeight: 650,
        _largePopupFeatures: 'status=0, scrollbars=1, toolbar=0, resizable=0',
        getUrl: function (employer) {
            if (!this._testMode) {
                if (employer == true) {
                    return "https://cpanel.careerpassport.eu";
                }
                else {
                    return "https://app.careerpassport.eu";
                }
            }
            else {
                return "http://cp.local";
            }
        },
        getImagesPath: function () { return this.getUrl() + '/Content/images/connect/' },
        init: function (apikey, hashedsecret) {
            this._apiKey = apikey;
            this._hashedSecret = hashedsecret;
            if (this._apiKey) {
                this._apiQuery = "?apikey=" + this._apiKey + "&h=" + this._hashedSecret;
            }
            this._popupFeatures += ", width=" + this._popupWidth + ", height=" + this._popupHeight;
            this._popupFeatures += ", left=" + ((window.screen.width - this._popupWidth) / 2) + ",top=" + ((window.screen.height - this._popupHeight) / 2);
            this._largePopupFeatures += ", width=" + this._largePopupWidth + ", height=" + this._largePopupHeight;
            this._largePopupFeatures += ", left=" + ((window.screen.width - this._largePopupWidth) / 2) + ",top=" + ((window.screen.height - this._largePopupHeight) / 2);
        },
        getMyProfileButton: function () {
            return '<a href="#" class="cp_button_myprofile" onclick="CP.openMyProfile(); return false;"><img src="'
                + this.getImagesPath() + 'my-profile.png" alt="My profile" align="absmiddle" /></a>'
        },
        getRegisterButton: function () {
            return '<a href="#" class="cp_button_myprofile" onclick="CP.register(); return false;"><img src="'
                + this.getImagesPath() + 'createprofile.png" alt="Register" align="absmiddle" /></a>'
        },
        getSignInButton: function () {
            return '<a href="#" class="cp_button_signin" onclick="CP.signIn(); return false;"><img src="'
                + this.getImagesPath() + 'signin.png" alt="Sign in" align="absmiddle" /></a>'
        },
        getApplyButton: function (id) {
            return '<a href="#" class="cp_button_apply" onclick="CP.apply(' + id + '); return false;"><img src="'
                + this.getImagesPath() + 'apply.png" alt="Submit your application" align="absmiddle" /></a>'
        },
        getPostVacancyButton: function () {
            return '<a href="#" class="cp_button_apply" onclick="CP.employerLogin(); return false;"><img src="'
                + this.getImagesPath() + 'postvacancy.png" alt="Post a vacancy" align="absmiddle" /></a>'
        },
        openMyProfile: function () {
            var popupLink = this.getUrl() + "/profile" + this._apiQuery;
            this._popup = window.open(popupLink, "myprofile", this._largePopupFeatures);
            this._popup.window.focus();
        },
        signIn: function () {
            var popupLink = this.getUrl() + "/profile" + this._apiQuery;
            this._popup = window.open(popupLink, "myprofile", this._largePopupFeatures);
            this._popup.window.focus();
        },
        register: function () {
            var popupLink = this.getUrl() + "/identity/register" + this._apiQuery;
            this._popup = window.open(popupLink, "myprofile", this._largePopupFeatures);
            this._popup.window.focus();
        },
        apply: function (project) {
            var popupLink = this.getUrl() + "/profile/applications/apply/" + project + this._apiQuery;
            this._popup = window.open(popupLink, "myprofile", this._largePopupFeatures);
            this._popup.window.focus();
        },
        employerLogin: function () {
            var popupLink = this.getUrl(true) + this._apiQuery;
            this._popup = window.open(popupLink, "myprofile", this._largePopupFeatures);
            this._popup.window.focus();
        },
        employerRegister: function () {
            var popupLink = this.getUrl(true) + "/client/register" + this._apiQuery;
            this._popup = window.open(popupLink, "myprofile", this._largePopupFeatures);
            this._popup.window.focus();
        }
    }

    var cpSSL = new Image(100, 25);
    cpSSL.src = CP.getImagesPath() + "my-profile.png";
}

