
function ReturnFalse(e) {

    return false;
}

// Ajoute Bookmark
function AddBookmark(title, url) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else if (document.all) {
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print) {
        return true;
    }
}

function CloseWindow() {
    try {
        if (!window.sidebar) {
            window.close();
        }
    }
    catch (ignore) { }
}

function CloseParentWindow() {
    try {
        if (!window.sidebar) {
            if (window.opener != null) {
                var pWin = window.opener;
                pWin.opener = self;
                if (!pWin.closed) {
                    pWin.close();
                }
            }
        }
    }
    catch (ignore) { }
}

function ResetScrollPosition() {
    var scrollX = document.getElementById('__SCROLLPOSITIONX');
    var scrollY = document.getElementById('__SCROLLPOSITIONY');

    if (scrollX != null && scrollY != null) {
        scrollX.value = 0;
        scrollY.value = 0;
    }
}

// RedirectURL
function RedirectURLDelay(href, delayMiliseconde) {
    window.setTimeout("RedirectURL('" + href + "')", delayMiliseconde);
}

function RedirectURL(href) {
    window.location.href = href;
}

// MagexTextBox
function LimitInput(targetField, sourceEvent, maxLength) {
    var isPermittedKeystroke;
    var enteredKeystroke;
    var maximumFieldLength = parseInt(maxLength);
    var currentFieldLength;
    var inputAllowed = true;
    var selectionLength = parseInt(GetSelectionLength(targetField));

    // Get the current and maximum field length
    currentFieldLength = parseInt(targetField.value.length);

    // Allow non-printing, arrow and delete keys
    enteredKeystroke = window.event ? sourceEvent.keyCode : sourceEvent.which;
    isPermittedKeystroke = (
              (enteredKeystroke < 32)                               // Non printing
            || (enteredKeystroke >= 33 && enteredKeystroke <= 40)   // Page Up, Down, Home, End, Arrow
            || (enteredKeystroke == 46))                            // Delete

    // Decide whether the keystroke is allowed to proceed
    if (!isPermittedKeystroke) {
        if ((currentFieldLength - selectionLength) >= maximumFieldLength) {
            inputAllowed = false;
        }
    }

    // Force a trim of the textarea contents if necessary
    if (currentFieldLength > maximumFieldLength) {
        targetField.value = targetField.value.substring(0, maximumFieldLength)
    }

    sourceEvent.returnValue = inputAllowed;
    return (inputAllowed);
}

function LimitPaste(targetField, sourceEvent, maxLength) {
    var clipboardText;
    var resultantLength;
    var maximumFieldLength = parseInt(maxLength);
    var currentFieldLength;
    var pasteAllowed = true;
    var selectionLength = GetSelectionLength(targetField);

    // Get the current and maximum field length
    currentFieldLength = parseInt(targetField.value.length);
    clipboardText = window.clipboardData.getData("Text");
    resultantLength = currentFieldLength + clipboardText.length - selectionLength;
    if (resultantLength > maximumFieldLength) {
        pasteAllowed = false;
    }

    sourceEvent.returnValue = pasteAllowed;
    return (pasteAllowed);
}

function GetSelectionLength(targetField) {
    if (targetField.selectionStart == undefined) {
        return document.selection.createRange().text.length;
    }
    else {
        return (targetField.selectionEnd - targetField.selectionStart);
    }
}

function HtmlEncode(clientID) {
    var element = document.getElementById(clientID);
    if (element) {
        var value = element.value;

        value = value.replace(/</g, "&lt;");
        value = value.replace(/>/g, "&gt;");

        element.value = value;
    }
} 