﻿// Scripts appelés par le flash de la master pour se fermer au bout de 7 secondes
function closePubDiv() {
    setTimeout(closeAdds, 7000);
}

function closeAdds() {
    document.getElementById("flashPub").style.display = 'none';
}

// Affichage d'un panel avec overlay
function checkForLigthbox() {
    el = $$("div.Lightbox");
    if (el.length > 0) {
        width = window.getWidth();
        height = window.getScrollHeight();
        // Pour IE, on créé une iframe vide pour que les selects ne soient pas au dessus de tout
        if (window.ie) {
            iframe = new Element('iframe', {
                'id': 'LightBoxIframe',
                'styles': {
                    'width': width + 'px',
                    'height': height + 'px'
                }
            });
            document.body.appendChild(iframe);
        }

        // Creation de la div d'overlay
        overlay = new Element('div', {
            'id': 'LightboxOverlay',
            'styles': {
                'width': width + 'px',
                'height': height + 'px'
            }
        });
        document.body.appendChild(overlay);

        // Positionnement de la div du contenu
        width = window.getWidth();
        height = window.getHeight();
        div = $(el[0]);
        var left = ((width - div.getSize().size.x) / 2).round();
        var top = ((height - $(div).getSize().size.y) / 2).round();
    }
}
window.addEvent("domready", checkForLigthbox);

// Affichage d'un overlay pour les div images
function checkForLigthboxImage() {
    el = $$("div.LightboxImg");

    for (i = 0; i < el.length; i++) {
        if (el[i].getStyle('display') != "none") {
            width = window.getWidth();
            height = window.getScrollHeight();

            // Pour IE, on créé une iframe vide pour que les selects ne soient pas au dessus de tout
            if (window.ie) {
                iframe = new Element('iframe', {
                    'id': 'LightBoxIframe',
                    'styles': {
                        'width': width + 'px',
                        'height': height + 'px'
                    }
                });
                document.body.appendChild(iframe);
            }

            // Création de la div d'overlay
            overlay = new Element('div', {
                'id': 'LightboxOverlay',
                'styles': {
                    'width': width + 'px',
                    'height': height + 'px'
                }
            });

            document.body.appendChild(overlay);

            // Positionnement de la div du contenu
            width = window.getWidth();
            height = window.getHeight();
            div = $(el[i]);

            var left = ((width - div.getSize().size.x) / 2).round();
            var top = ((height - $(div).getSize().size.y) / 2).round();
            if ($(div).getSize().size.y > height) top = 50;
            div.set({
                'styles': {
                    'left': left + 'px',
                    'top': top + 'px'
                }
            });
        }
    }
}
window.addEvent("domready", checkForLigthboxImage);

// Fonction d'ajout aux favoris
function favoris() {
    var url = location.href;
    url = url.substring(0, url.lastIndexOf("/"));
    var title = "Bricoman";
    if (navigator.appName != 'Microsoft Internet Explorer') {
        window.sidebar.addPanel(title, url, "");
    }
    else {
        window.external.AddFavorite(url, title);
    }
}

// Vide et remplit les champs texte pour y afficher un message par défaut
function manageTextbox(currentControl, text) {
    if (currentControl.value == text) {
        currentControl.value = "";
        currentControl.onblur = function() {
            if (this.value == "")
                this.value = text;
        }
    }
}

function verifTextbox(source, arguments) {
    var textBox = document.getElementById(source.controltovalidate);
    if (textBox.value == "" || textBox.value == "champs obligatoire.") {
        textBox.value = "champs obligatoire.";
        textBox.style.color = "#fb7e02";
        arguments.IsValid = false;
    }
}

function PopupCentrer(page, largeur, hauteur, options) {
    var top = (screen.height - hauteur) / 2;
    var left = (screen.width - largeur) / 2;
    window.open(page, "", "top=" + top + ",left=" + left + ",width=" + largeur + ",height=" + hauteur + "," + options);
}

function changePicture() {
    var button = document.getElementById('ctl00_cphMain_iDetail');
    var picture = document.getElementById('ctl00_cphMain_iVilleDetail');

    // On découpe le lien de l'image
    var urlpictureTab = picture.src.split('/');

    // On récupère le nom de l'image
    var nomPicture = urlpictureTab[urlpictureTab.length - 1].split('.');

    var extension = nomPicture[nomPicture.length - 1];
    var namePicture = nomPicture[nomPicture.length - 2];

    if (picture) {
        if (namePicture.substring(namePicture.length - 1, namePicture.length) == '2') {
            var namePicture = namePicture.substring(0, namePicture.length - 1);
            picture.src = "/Images/Plan/" + namePicture + "." + extension;
            button.src = "/images/plan/voir-plan-detaille.gif";
        }
        else {
            picture.src = "/Images/Plan/" + namePicture + "2." + extension;
            button.src = "/images/plan/voir-plan-general.gif";
        }
    }
}