﻿$(function() {    
        $("input[id$=tbGlobalSearch]").focus(function() {
            $(".search-box").addClass('active');
            if ($(this).val() == "Поиск") {
                $(this).val("");
            }
        }).blur(function() {
            $(".search-box").removeClass('active');
            if ($(this).val() == "") {
                $(this).val("Поиск");
            }
        });

        $(".more").unbind("click").click(function () {
            $("#pMoreInfo").removeClass("more-info");
            $(this).remove();
        });
});

function AddCallMe() {
    var name = $("#divCallMe #tbName").val();
    var phone = $("#divCallMe #tbPhone").val();
    var comment = $("#divCallMe #tbComment").val();
    if (name != '' && phone != '') {
        $.ajax({
            type: "POST",
            url: "/jQueryAjaxRequest.aspx/AddCallMe",
            data: "{name: '" + name + "', phone: '" + phone + "', comment: '" + comment + "', url: '" + top.location + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(response) {
            $('#divCallMe').hide(); 
            $("#lock").hide(); $.notifier("Ваш номер добавлен.", "success"); },
            error: function() { $('#divCallMe').fadeOut(); $("#lock").hide(); $.notifier("Ошибка. Попробуйте еще раз.", "error"); }
        });
    }
    else {
        $.notifier("Ошибка. Поля заполнены неверно", "error");
    }
}
function CloseCallMe() {
    $("#lock").hide();
    $('#divCallMe').hide();
    //e.stopPropagation();
}

function ShowCallMe() {
    $("#lock").show();
    $('#divCallMe').show();
}
/* -------------------NOTIFIER -----------------*/
(function($) {    
    $.notifier = function(message, type) { notify(message, type); }

    function notify(message, type) {
        var instance = $(document.getElementById('divNoticeContainer'));
        var html = jQuery.notifier.settings.noticeTemplate;
        html = html.replace('%Message%', message);

        if (type == "success")
            html = html.replace('%CssClass%', 'b-notif-success');
        else if (type == "error")
            html = html.replace('%CssClass%', 'b-notif-error');

        var notice = $(html).hide().fadeIn(jQuery.notifier.settings.noticeFadeTimeout);

        $.notifier.settings.noticeDisplay(notice);
        instance.append(notice);

        if ($.notifier.settings.displayTimeout > 0) {
            setTimeout(function() {
                jQuery.notifier.settings.noticeRemove(notice, function() {
                    notice.remove();
                });
            }, jQuery.notifier.settings.displayTimeout);
        }
    };

    $.notifier.settings = {
        noticeTemplate: '<div class="%CssClass%">%Message%</div>',
        noticeDisplay: function(notice) {
            notice.fadeIn(jQuery.notifier.settings.noticeFadeTimeout);
        },
        noticeRemove: function(notice, callback) {
            notice.animate({ opacity: '0', height: '0px' }, { duration: jQuery.notifier.settings.noticeFadeTimeout, complete: callback });
        },
        noticeFadeTimeout: 'slow',
        displayTimeout: 5000
    };
})(jQuery);

//function pageLoad(sender, args) {
//    if (args.get_isPartialLoad()) {
//        completeNotify();
//    }
//}

function completeNotify() {
    var inputs = $("input[id*=hCommandStatusMessage]");
    for (var i = 0; i < inputs.length; i++) {
        var message = inputs[i].value;
        if (message) {
            $.notifier(message);
            inputs[i].value = '';
        }
    }
}
