﻿// change image lors du clic - ex sur les notes de la page content Mag
function changeimg(monimage) {
    monimage.src = (monimage.src == "../Images/note00.gif") ? "../Images/note00.gif" : "../Images/note02.gif";
}

// gestion de l'affichage du contenu des onglets au clic
function multiClass(eltId) {
    arrLinkId = new Array('_0', '_1');
    intNbLinkElt = new Number(arrLinkId.length);
    arrClassLink = new Array('active', 'inactive');
    strContent = new String()
    for (i = 0; i < intNbLinkElt; i++) {
        strContent = "menu" + arrLinkId[i];
        if (arrLinkId[i] == eltId) {
            document.getElementById(arrLinkId[i]).className = arrClassLink[0];
            document.getElementById(strContent).className = 'on';
        } else {
            document.getElementById(arrLinkId[i]).className = arrClassLink[1];
            document.getElementById(strContent).className = 'off';
        }
    }
}

/* POPUP **********************************************************************************************************************/
function getPageScroll() {
    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array('', yScroll);
    return arrayPageScroll;
}

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}

function Overlay() {
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

    var objOverlay = document.getElementById('Loader');
//    objOverlay.style.top = 0 + 'px';
//    objOverlay.style.left = 0 + 'px';
//    objOverlay.style.position = 'absolute';
//    objOverlay.style.width = (arrayPageSize[2] + 'px');
//    objOverlay.style.height = (arrayPageSize[3] + 'px');
    objOverlay.style.display = 'block';


    var objOverlayImg = document.getElementById('OverlayImg');
        objOverlayImg.onload = function() {
        objOverlayImg.style.position = 'absolute';
        objOverlayImg.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objOverlayImg.offsetHeight) / 2) + 'px');
        objOverlayImg.style.left = (((arrayPageSize[0] - 20 - objOverlayImg.offsetWidth) / 2) + 'px');
        objOverlayImg.style.display = 'block';
    }
}

/* POPUP centree */
function PopupCentrer(l, h, url) {
    hauteur = Math.round((screen.availHeight - h) / 2);
    largeur = Math.round((screen.availWidth - l) / 2);
    window.open(url, "site", "toolbar=0,location=0,directories=0,status=0, scrollbars=yes,resizable=1,menubar=0,top=" + hauteur + ",left=" + largeur + ",width=" + l + ",height=" + h);
}
function PopupCentrerTracker(l, h, url) {
    hauteur = Math.round((screen.availHeight - h) / 2);
    largeur = Math.round((screen.availWidth - l) / 2);
    window.open(pageTracker._getLinkerUrl(url), "site", "toolbar=0,location=0,directories=0,status=0, scrollbars=yes,resizable=1,menubar=0,top=" + hauteur + ",left=" + largeur + ",width=" + l + ",height=" + h);
}
/* FIN POPUP **********************************************************************************************************************/

/* Sur l'écran LIVRAISON, sert à afficher/cacher le message joint à un l'envoi d'un produit interflora */
function ShowHideMsgLivraison(box, controlID) {
    var elm = document.getElementById(controlID);
    elm.style.display = box.checked ? "block" : "none";
}

/* Sur l'écran CHRONOPOSTSTEP2, sert à vider le champ de saisie d'assurance */
function ShowHideAssurance(box, controlID, labelID) {
    var elm = document.getElementById(controlID);
    elm.style.display = box.checked ? "block" : "none";

    var elm2 = document.getElementById(labelID);
    elm2.innerHTML = box.checked ? "Valeur à assurer : " : "Assurance";
}

/* Sur l'écran CHRONOPOSTSTEP2, sert à vider le champ de saisie d'assurance et de date */
function ViderTextbox(textbox, texteParDefaut) {
    //if (textbox.value == "Valeur à assurer...") {
    if (textbox.value == texteParDefaut) {
        textbox.value = "";
    }
}

/* Sur l'écran CHRONOPOSTSTEP2, sert à afficher le champ de saisie d'assurance et de date*/
function InitTextbox(textbox, texteParDefaut) {
    if (textbox.value == "") {
        textbox.value = texteParDefaut;
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/********************************* affiche contenu au clic du lien dans un menu - ex : FAQ *********************************/
// Recherche de la balise avec id "hoverLiensFaq"
window.onload = function() {
if (document.getElementById('tabs-faq')) {
    var $tabs = $('#tabs-faq').tabs();
    $tabs.tabs('select', 0);
    }
}
/************ FIN ************/


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//recuperation valeur des input sur le focus quand aucun texte n'est tape
function make_blank(textbox) {
    textbox.value = "";
}

function init(textbox) {
    textbox.value = "Ecrivez ici votre question...";
}
function init2(textbox) {
    textbox.value = "Votre adresse e-mail...";
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// limiteur caracteres
function compter(f,nbcar) {
    var max = 1000;
    var txt = f.value + 1;
    var nb = txt.length;
    var reste = max - nb;
    if (nb > max) {
        alert("Vous avez dépassé le nombre maximal de caractères qui est de " + max + ".");
        f.value = txt.substring(0, max);
        nb = max;
    }
    var totalCar = document.getElementById(nbcar);
    totalCar.value = reste;
}

function codeTouche(evenement) {
    for (prop in evenement) {
        if (prop == 'which') return (evenement.which);
    }
    return (evenement.keyCode);
}

function scanTouche(evenement) {
    
    var reCarSpeciaux = /[\x00\x08\x0D\x03\x16\x18\x1A]/;
    var reCarValides = /[\d\w\séçàèê'ôîêâû-]/;

    var codeDecimal = codeTouche(evenement);
    var car = String.fromCharCode(codeDecimal);
    var autorisation = reCarValides.test(car) || reCarSpeciaux.test(car) || pressePapierNS6(evenement, car);

    

    return autorisation;
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


/* Jquery */
jQuery(document).ready(function() {
    if (document.getElementById("mycarousel")) {
        jQuery('#mycarousel').jcarousel({
            scroll: 1,
            auto: 3,
            wrap: 'last',
            initCallback: mycarousel_initCallback 
        });
    }
});


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// tracking

function UploadDocType(location, name) {
    pageTracker._trackEvent('Documents Types', location, name);
}