﻿/// <reference path="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" />

/// <summary>
/// © XTRA | Estetica e tecnologia
/// Email: info@xtra.it
/// </summary>

// Page: Ready
$(document).ready(function () {

    // Verifica: Valore del cookie
    if ($.cookie("MectronicMedicale_IsProfessionalProfile") != "True") {
        var $TagBody = $("body");
        var $PopUpContents = $("#PopUpContents");
        var $PopUpContents_Request = $("#PopUpContents_Request");
        var $PopUpContents_NoProfessional = $("#PopUpContents_NoProfessional");
        var $PopUpBackground = $('#PopUpBackground');
        var WindowWidth;
        var WindowHeight;

        // Disattiva: Messaggio per i non professionisti
        $PopUpContents_NoProfessional.hide();
        $PopUpContents_NoProfessional.removeClass("Hidden");

        // Disattiva: ScrollBars
        $TagBody.css("overflow", "hidden");

        // Init: Oggetti
        $PopUpContents.show();
        $PopUpBackground.fadeTo(0, 0.8);

        // Imposta: Posizione e dimensione degli oggetti
        WindowWidth = $(window).width();
        WindowHeight = $(window).height();

        $PopUpBackground.css({ 'width': WindowWidth, 'height': WindowHeight });
        $PopUpContents.css('top', (WindowHeight - $PopUpContents.height()) / 2);
        $PopUpContents.css('left', (WindowWidth - $PopUpContents.width()) / 2);

        //: Ridimensionamento del Browser
        $(window).resize(function () {
            // Imposta: Posizione e dimensione degli oggetti
            SetObjectPosition();
        });

        // Imposta: Posizione e dimensione degli oggetti
        function SetObjectPosition() {
            WindowWidth = $(window).width();
            WindowHeight = $(window).height();

            $PopUpBackground.css({ 'width': WindowWidth, 'height': WindowHeight });
            $PopUpContents.css('top', (WindowHeight - $PopUpContents.height()) / 2);
            $PopUpContents.css('left', (WindowWidth - $PopUpContents.width()) / 2);
        }

        $(".PopUpButton_Profesional").click(function () {
            $PopUpBackground.hide();
            $PopUpContents.hide();

            // Attiva: ScrollBars
            $TagBody.css("overflow", "visible");

            $.cookie("MectronicMedicale_IsProfessionalProfile", "True", { path: '/' });
        });

        $(".PopUpButton_NoProfesional").click(function () {
            $PopUpContents_Request.hide();
            $PopUpContents_NoProfessional.show();
        });
    }
});

// Imposta: Cookie
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
