function debugInfo(message) {
    debugPane = document.createElement("div");
    debugPane.style.zIndex = "3";
    document.body.appendChild(debugPane);
    debugPane.innerHTML += '\n' + message;
}

function MM_preloadImages() { //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x;
    if (!d) d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n);
    return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3)
        if (
                (x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) x.oSrc = x.src;
            x.src = a[i + 2];
        }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function selectMenu(menu, sous_menu) {
    var attribute = 'class';
    if (navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent.indexOf('Opera') < 0) attribute = 'className';
    var li = document.getElementById(menu);
    if (li)li.setAttribute(attribute, 'actif');
    var elements = document.getElementsByTagName('li');
    for (var i = 0; i < elements.length; i++) {
        var e = elements[i];
        if (e.parentNode.parentNode.nodeName == 'DIV') {
            if (e.getAttribute(attribute) == sous_menu) e.setAttribute(attribute, 'actif');
        }
    }
}

function checkNumber(input, label, decimal) {
    var position = input.value.indexOf(",");
    if (position > -1) {
        input.value = input.value.substr(0, position) + '.' + input.value.substr(position + 1);
    }
    if (!input.value.length) {
        input.value = "0";
    }
    if (isNaN(input.value)) {
        alert("Attention, la valeur " + label + " est incorrecte !");
        input.focus();
        return false;
    }
    if (input.value < 0) {
        alert("Attention, la valeur " + label + " ne peut �tre n�gative!!!");
        input.focus();
        return false;
    }
    input.value = dr(input.value, decimal);
    return true;
}

function dr(v, dc) {
    var d = 0.500001;
    var i = dc;
    while (i > 0) {
        d /= 10;
        i--;
    }
    var f = parseFloat(v.toString()) + d;
    f = f.toString();
    f = f.substr(0, f.indexOf(".") + 1 + dc);
    return f;
}

function charactersLeft(maxSize, form, textArea, indicator) {
    var textArea = document.getElementById(form + ':' + textArea);
    var indicator = document.getElementById(form + ':' + indicator);
    indicator.value = new Number(maxSize - textArea.value.length);
    if (indicator.value <= 0) {
        textArea.value = textArea.value.substr(0, maxSize);
        indicator.value = new Number(maxSize - textArea.value.length);
    }
}

function setEnd(form, heuDeb, heuFin) {
    var end = document.getElementById(form + ':' + heuDeb).options.selectedIndex + 2;
    if (end > 23) {
        end = end - 24;
    }
    document.getElementById(form + ':' + heuFin).options.selectedIndex = end;
}

function getCGV(form, select) {
    var serArray = document.getElementById(form + ':' + select).options;
    var service;
    for (var i = 0; i < serArray.length; i++) {
        if (serArray[i].selected) {
            service = serArray[i].value;
            break;
        }
    }
    //var w = window.open(page, "CGV", "width=800,height=600,status=no,resizable=yes");
    //w.focus();
    window.open("cgv.jsf", "CGV", "width=800,height=600,status=no,scrollbars=yes,resizable=yes").focus();
}

function sessionExpired() {
    setTimeout("window.location = 'http://www.google.fr/';", 900000); // 900000 ms == 15 min
}

function erreur() {
    setTimeout("window.history.go(-1);", 4000);
    //setTimeout("window.location = 'http://www.scenedemenage.com/';", 000);
}

function paiement() {
    var w = window.open('', 'SPPLUS', 'width=750,height=560,status=1');
    w.focus();
}

function submitOnlyWithButton() {
    var inputArray = document.getElementsByTagName("input");
    for (var i = 0; i < inputArray.length; i++) {
        if (inputArray[i].type == "text") {
            inputArray[i].onkeypress = function(inEvent) {
                if (!inEvent) {
                    inEvent = window.event;
                }
                return !(inEvent && inEvent.keyCode == 13);
            }
        }
    }
}

function affectationListener(form, checkbox) {
    currentAffectationStatus = document.getElementById(form + ':' + checkbox).checked;
}

function controlAffectationButton(form, button, checkbox) {
    var affectationButton = document.getElementById(form + ':' + button);
    if (affectationButton) {
        if (document.getElementById(form + ':' + checkbox).checked == currentAffectationStatus) {
            affectationButton.setAttribute("disabled", "disabled");
        }
        else {
            affectationButton.removeAttribute("disabled");
        }
    }
}

