﻿function igwsValidation(data, url) {
    var result;
    $.ajax(
      {
          type: 'POST',
          url: url,
          cache: false,
          async: false,
          data: data,
          dataType: 'json',
          contentType: 'application/json',
          success: function(response) {
              result = response.d;
          }
      });
    return result;
}

function igwsValidationErrorMessage(message) {
    $(function() {
        var div = $('<p>' + message + '</p>').appendTo('body');
        div.dialog({
            bgiframe: true,
            modal: true,
            resizable: false,
            buttons: {
                Ok: function() {
                    $(this).dialog('close');
                }
            }


        });
    });
}

function igwsValidateSummary(source, args) {
    var container = document.getElementById('messageContainer');
    if (container != null) {
        container.appendChild(source);
        var message = document.getElementById('messageText');
        if (message != null) { container.removeChild(message) };
        ShowMessage();
    }

    args.IsValid = true;
    for (i = 0; i < Page_Validators.length; i++) {
        if (source != Page_Validators[i]) {
            if (!Page_Validators[i].isvalid) {
                args.IsValid = false;
                return;
            }
        }
    }
}

function CountTextChars(inputId, reminderId, reminderExpression, maxLength) {
    var input = document.getElementById(inputId);
    var reminder = document.getElementById(reminderId);

    if (input.value.length > maxLength) {
        input.value = input.value.substring(0, maxLength);
    }
    else {
        var curLength = input.value.length;
        reminder.innerHTML = reminderExpression.replace('{0}', curLength).replace('{1}', maxLength);
    }
}

function ShowMessage() {
    var container = document.getElementById('messageContainer');
    if (container != null) {
        if (container.innerHTML != '') {
            window.setTimeout("$('.infoMessage').fadeOut(1000);", 10000);
            window.setTimeout("$('.infoMessage').html('')", 11000);
            window.setTimeout("$('.infoMessage').fadeIn(1);", 11000);
        }
    }
}


function ShowMousePopUp(e, date, dateFormated) {
    var tempX = e.clientX + document.documentElement.scrollLeft;
    var tempY = e.clientY + document.documentElement.scrollTop;
    var height = $('#calendarPopup').height();
    var width = $('#calendarPopup').width();
    leftVal = tempX - (width / 2) + 5 + 'px';
    topVal = tempY - 17 + 'px';
    $.ajax({ type: "POST",
        url: "/Services/IgwsElementServices.svc/GetIgwsEventsByDate",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: '{"date" : "' + date + '"}',
        success: function(data) {
            var render = "<ul>";
            for (var i=0; i<data.d.length; i++)
            {
                render = render + "<li><a href=\"" + data.d[i].Url + "\">" + data.d[i].DisplayText + "</a></li>";
            }
            render = render + "</ul>";
            $('#calendarPopupTitle').html("Evénements du : " + dateFormated);
            $('#calendarPopupContent').html(render);

            $('#calendarPopup').css({ left: leftVal, top: topVal }).show();
        }
    });
}

function HideMousePopUp() {
    $('#calendarPopup').hide();
}

function HideMousePopUpWithDelay(delay) {
    $('#calendarPopup').delay(delay).hide(0);
}
