﻿$(document).ready(function() {

    AddTooltips($(".helpme"));

    AddPassportTooltips($(".helpmep"));
    AddPassportTooltipsF($(".helpmepf"));
});

function AddTooltips1(elems) {
    elems.simpletip({
        persistent: true,
        onBeforeShow: function() {
            this.update('Загрузка...');
            var tt = this;
            var hash = Math.random(); // чтоб ответ не кэшировалс

            $.ajax({
                async: false,
                type: "GET",
                contentType: "application/x-www-form-urlencoded",
                url: "/Help/HelpMe/" + $(this.getParent()).attr("ttid"),
                dataType: "html",
                data: { hash: hash },
                success: function(data) {
                    tt.update(
                        '<div class="tooltipInner">' +
                        data +
                        '</div>');
                }
            });
        }
    });
}

function AddTooltips(elems) {
        elems.qtip({
            content: 'smile',
            show: {
                delay: 10,
                when: { event: 'click' }, 
                effect: { type: 'none' }
            },
            hide: {
                when: { event: 'unfocus' },
                effect: { type: 'none' }
                },
            position: {
                corner: {
                    target: 'bottomRight',
                    tooltip: 'topRight'
                },
                adjust: { x: -5, y: 0 }
            },
            style: {
                name: 'cream', // Inherit from preset style
                tip: 'topRight',
                width: 500 
            },
            api: {
                beforeShow: function () {
                    this.updateContent('Загрузка...');
                    var tt = this;
                    var hash = Math.random(); // чтоб ответ не кэшировалс

                    $.ajax({
                        async: false,
                        type: "GET",
                        contentType: "application/x-www-form-urlencoded",
                        url: "/Help/HelpMe/" + $(this.elements.target).attr("ttid"),
                        dataType: "html",
                        data: { hash: hash },
                        success: function(data) {
                            tt.updateContent(
                                '<div class="tooltipInner">' +
                                data +
                                '</div>');
                        }
                    });
                }
            }
//            {
//                url: '/Help/HelpMe',
//                data: { id: 5 },
//                method: 'get'
//            }
        });
}


function AddPassportTooltips(elems) {
    elems.qtip({
        content: '<div class="helppassport">'
		 + '<img id="b01" src="/Content/images/passport01.gif" class="hiddenz"/>'
		 + '<img id="b02" src="/Content/images/passport02.gif" class="hiddenz"/>'
		 + '<img id="b03" src="/Content/images/passport03.gif" class="hiddenz"/>'
		 + '<img id="b04" src="/Content/images/passport04.gif" class="hiddenz"/>'
		 + '<img id="b05" src="/Content/images/passport05.gif" class="hiddenz"/>'
		 + '<img id="b06" src="/Content/images/passport06.gif" class="hiddenz"/>'
		 + '<img id="b07" src="/Content/images/passport07.gif" class="hiddenz"/>'
		 + '<img id="b08" src="/Content/images/passport08.gif" class="hiddenz"/>'
		 + '<img id="b09" src="/Content/images/passport09.gif" class="hiddenz"/>'
		 + '<img id="b10" src="/Content/images/passport10.gif" class="hiddenz"/>'
	     + '</div>',
        show: {
            delay: 10,
            when: { event: 'click' }
        },
        hide: { when: { event: 'unfocus'} },
        position: {
            corner: {
                target: 'topMiddle',
                tooltip: 'topMiddle'
            },
            adjust: { x: 0, y: 10 }
        },
        style: {
            name: 'cream', // Inherit from preset style
            tip: 'topMiddle',
            width: 820,
            height: 413
        },
        api: {
            beforeShow: function() {
                var hid = $(this.elements.target).attr("hid");
                var tt = $(this.elements.tooltip);
                var img = tt.find("#b" + hid);
                img.removeClass("hiddenz");
                img.addClass("visiblez");
            }
        }
    });
}

function AddPassportTooltipsF(elems) {
    elems.qtip({
        content: '<div class="helppassportf">'
		 + '<img id="b01" src="/Content/images/passportf01.gif" class="hiddenz"/>'
		 + '<img id="b02" src="/Content/images/passportf02.gif" class="hiddenz"/>'
		 + '<img id="b03" src="/Content/images/passportf03.gif" class="hiddenz"/>'
		 + '<img id="b04" src="/Content/images/passportf04.gif" class="hiddenz"/>'
		 + '<img id="b05" src="/Content/images/passportf05.gif" class="hiddenz"/>'
		 + '<img id="b06" src="/Content/images/passportf06.gif" class="hiddenz"/>'
		 + '<img id="b07" src="/Content/images/passportf07.gif" class="hiddenz"/>'
		 + '<img id="b08" src="/Content/images/passportf08.gif" class="hiddenz"/>'
	     + '</div>',
        show: {
            delay: 10,
            when: { event: 'click' }
        },
        hide: { when: { event: 'unfocus'} },
        position: {
            corner: {
                target: 'topMiddle',
                tooltip: 'topMiddle'
            },
            adjust: { x: 0, y: 10 }
        },
        style: {
            name: 'cream', // Inherit from preset style
            tip: 'topMiddle',
            width: 820,
            height: 413
        },
        api: {
            beforeShow: function() {
                var hid = $(this.elements.target).attr("hid");
                var tt = $(this.elements.tooltip);
                var img = tt.find("#b" + hid);
                img.removeClass("hiddenz");
                img.addClass("visiblez");
            }
        }
    });
}

function ShowHelpDialog(id) {
    var dlg = $("#okvedHelpDialog");
    dlg.dialog({
        position: "center",
        modal: true,
        width: 950,
        height: 500
    });
    var hash = Math.random();
    $.ajax({
        async: false,
        type: "GET",
        contentType: "application/x-www-form-urlencoded",
        url: "/Help/HelpMe/" + id,
        dataType: "html",
        data: { hash: hash },
        success: function(data) {
            dlg.html(data);
        }
    });


}
