﻿function initInputInlineTitle(titleText, inputId, cssFocus, cssBlur, fakeInputId) {
    if (fakeInputId == null || fakeInputId == "") {
        $("#" + inputId).bind("focus",
                function(e, o) {
                    if (this.value == titleText) this.value = "";
                    if (this.className != cssFocus) this.className = cssFocus;
                }
            );
        $("#" + inputId).bind("blur",
                function(e, o) {
                    if (this.value == "") {
                        this.value = titleText;
                        this.className = cssBlur;
                    }
                }
            );
    } else {
        $("#" + fakeInputId).bind("focus",
                function(e, o) {
                    $(this).hide();
                    $("#" + inputId).show().focus();
                }
            );
        $("#" + inputId).bind("blur",
                function(e, o) {
                    if (this.value == "") {
                        $(this).hide();
                        $("#" + fakeInputId).show().val(titleText);
                    }
                }
            );
    }
    $("#" + inputId).blur();
}

function initOnEnter(inputId, callback) {
    $("#" + inputId).keypress(
            function(e) {
                if (e.which == 13 || e.which == 10) {
                    if (callback) callback(inputId);
                    return false;
                }
                return true;
            }
        );
}

var userPing_timer = null;

function userPing(url) {
    if (userPing_timer != null) window.clearTimeout(userPing_timer);
    $.ajax({
        type: "GET",
        url: url + 'Actions/HomeAction.aspx',
        data: { "do": "pingUser", "rr": Math.random() },
        //dataType: "json",
        cache: false,
        success: function(data) {
            var pingInterval = 10 * 1000;
            if (data != null) {
                pingInterval = data; //data.pingInterval;
            }
            userPing_timer = window.setTimeout('userPing("' + url + '")', pingInterval);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
        }
    });
}

