﻿// JScript File

    // Name of IHttpHandler class
    var IHTTPHANDLER_PATH = "/" + document.location.pathname.split('/')[1] + "/CommandsHandler.ashx";

    
   // ======= для работы клиентского скрипта ОБЯЗАТЕЛЬНО нужен jQuery !!! ========

    function windowHeight() {
        var de = document.documentElement;

        return self.innerHeight || ( de && de.clientHeight ) || document.body.clientHeight;
    }
    
    function getInfoWindowTop(clientY, pageY, xOffset)
    {
        var ctrlHeight = $('#ANumberInfo').height();
        if (!ctrlHeight)
            ctrlHeight = 170;
        
        if (windowHeight()-clientY  < ctrlHeight + 10)
            return (pageY - ctrlHeight - 25);
        else
            return (pageY - xOffset);
    }
    

//    // При загрузке страницы
//    window.onload = function()
//        {                                    
//            //align element in the middle of the screen
//            $.fn.alignCenter = function() {
//            //get margin left
//            var marginLeft = Math.max(40, parseInt($(window).width()/2 - $(this).width()/2))  + 'px';
//            
//            //get margin top            
//            var top = ($(this).parent().height() / 2)-100;//(($(this).parent().height() - $(this).height()) / 2);            
//            //var marginTop = 
//            //return updated element
//            return $(this).css({'margin-left':marginLeft, 'top':top + 'px'});
//            };
//                      
//            xOffset = -20;
//            yOffset = -70;

//            ShowHideNumberInfo();
//        };
//    
    function ShowHideNumberInfo()
    {    
            // Всплывающая информация
            $(".ANumberInfo").hover(function(e) {
                if (this.ANumber == null)
                    this.t = $(this).attr("anumber");
                else
                    this.t = this.ANumber;// title;
                
                $("body").append("<div id='ANumberInfo'>" + this.t + "</div>");
                $("#ANumberInfo")
		            .css("top", getInfoWindowTop(e.clientY, e.pageY, xOffset) + "px")
		            .css("left", (e.pageX + yOffset) + "px")
		            .fadeIn("slow");
            },
	        function() {
	            $("#ANumberInfo").remove();
	        });
            $(".ANumberInfo").mousemove(function(e) {
                $("#ANumberInfo")
		            .css("top", getInfoWindowTop(e.clientY, e.pageY, xOffset) + "px")
		            .css("left", (e.pageX + yOffset) + "px")
            });            
    }
    
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    // Выполнение Ajax команд.
    // Параметры:
    //  url - путь к обработчику запросов
    //  options - массив параметров
    //  beforeSendFunc - функция, вызывается перед отправкой
    //  successFunc - функция, возвращает результат
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    function AjaxCommand(url, options, beforeSendFunc, successFunc)
    {    
        var data = "";
        // Формируем строку параметров из массива
        for(i = 0; i < options.length; i++)
        {
            if (i > 0)
                data += "&";
                
            data += options[i][0] + "=" + options[i][1];
        }
        
        // Выполнение команды
        $.ajax(
        {
            url: url,
            type: 'POST',
            data: data,
            beforeSend: beforeSendFunc(),
            success: function (data) {
                successFunc(data)
            },
            error: function (httpRequest, textStatus, errorThrown) {
                alert(httpRequest.responseText);
            }
        });
    }
    
    // Показываем сообщение об ошибке
    function showErrorMessage(error) {
        alert(error);
    }

    // Показываем информационное сообщение
    function showInfoMessage(info) {
        alert(info);
    }

    // Показать окно загрузки / обработки
    function showWaitWindow() {
        $('#divLoading').show();
    }

    // Скрыть окно загрузки / обработки
    function hideWaitWindow() {
        $('#divLoading').hide();
    }
    
