
//**************************************************
//*  		Présence du plugin acrobat reader
//**************************************************
function hasAcrobat() {
    var r = 0;
    for (i = 1; i <= 11; i++) {
        try {
            var o = new ActiveXObject("PDF.PdfCtrl." + i);
        }
        catch (e) {
            r += 1;
        }
    }
    if (r == 11) { return false }
    else { return true; }
} 
 

//********************************************
//*  		Vérif Format Téléphone
//********************************************
function IsTel(controle, Libelle) {
    var valeur = controle.value;
    if (valeur == "") return true;
    var exp = new RegExp("^[0-9]+$", "g");
    if (!exp.test(valeur)) {
        alert(Libelle + "  doit être numérique et sans séparateur !");
        controle.focus();
        return (false);
    }
    if (valeur.length != 10) {
        alert(Libelle + " doit comporter 10 chiffres !");
        controle.focus();
        return (false);
    }
    return (true);
}

//**********************************************
//* 			Formatage N° Tel
//**********************************************	
function Format_Tel(NumTel) {
    var Tel;
    var i = 0;
    while (i < NumTel.length - 1) {
        if ((NumTel.charAt(i) == ".") || (NumTel.charAt(i) == ",") || (NumTel.charAt(i) == "/") || (NumTel.charAt(i) == "-")) {
            Tel = NumTel.substring(0, i) + NumTel.substring(i + 1, NumTel.length);
            NumTel = Tel;
        }
        else {
            i++;
        }
    }
    return (NumTel);
}

//************************************
//* 					Email
//************************************
function isEmail(controle, Libelle) {
    var emailStr = controle.value;
    var validDomain = false;
    var AtPos = emailStr.lastIndexOf("@");
    var FirstAtPos = emailStr.indexOf("@");
    var DotPos = emailStr.lastIndexOf(".");
    var SpacePos = emailStr.lastIndexOf(" ");
    if (isEmpty(emailStr)) {
        validDomain = true;
        return true;
    }

    if (((AtPos > 0) && (DotPos > 0) && (AtPos < DotPos) && (AtPos == FirstAtPos) && (SpacePos < 0))) {
        var domainExtList = 'ac.ad.ae.af.ag.ai.al.am.an.ao.aq.ar.as.at.au.aw.az.ba.bb.bd.be.bf.bg.bh.bi.bj.bm.bn.bo.br.bs.bt.bv.bw.by.bz.ca.cc.cd.cf.cg.ch.ci.ck.cl.cm.cn.co.cr.cs.cu.cv.cx.cy.cz.de.dj.dk.dm.do.dz.ec.ee.eg.eh.er.es.et.eu.fi.fj.fk.fm.fo.fr.fx.ga.gb.gd.ge.gf.gg.gh.gi.gl.gm.gn.gp.gq.gr.gs.gt.gu.gw.gy.hk.hm.hn.hr.ht.hu.id.ie.il.i?????????Au???????m.in.io.iq.ir.is.it.je.jm.jo.jp.ke.kg.kh.ki.km.kn.kp.kr.kw.ky.kz.la.lb.lc.li.lk.lr.ls.lt.lu.lv.ly.ma.mc.md.mg.mh.mk.ml.mm.mn.mo.mp.mq.mr.ms.mt.mu.mv.mw.mx.my.mz.na.nc.ne.nf.ng.ni.nl.no.np.nr.nt.nu.nz.om.pa.pe.pf.pg.ph.pk.pl.pm.pn.pr.ps.pt.pw.py.qa.re.ro.ru.rw.sa.sb.sc.sd.se.sg.sh.si.sj.sk.sl.sm.sn.so.sr.st.su.sv.sy.sz.tc.td.tf.tg.th.tj.tk.tm.tn.to.tp.tr.tt.tv.tw.tz.ua.ug.uk.um.us.uy.uz.va.vc.ve.vg.vi.vn.vu.wf.ws.ye.yt.yu.za.zm.zr.zw.com.edu.gov.int.mil.net.org.biz.pro.info.aero.name.coop.arpa.nato.museum.EoF';
        var domainExt = domainExtList.split(".");
        var emailExt = emailStr.substr(DotPos + 1);
        emailExt = emailExt.toLowerCase();
        for (i = 0; domainExt.length; i++) {
            if (domainExt[i] == 'EoF') { validDomain = false; break; }
            else if (emailExt == domainExt[i]) { validDomain = true; break; }
        }
    }

    if (!validDomain) {
        alert(Libelle + " n'est pas une adresse Email correcte.");
        controle.focus();
    }
    return (validDomain);
}


function pausescroller(content, divId, divClass, delay) {
    this.content = content //message array content
    this.tickerid = divId //ID of ticker div to display information
    this.delay = delay //Delay between msg change, in miliseconds.
    this.mouseoverBol = 0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
    this.hiddendivpointer = 1 //index of message array for hidden div
    document.write('<div id="' + divId + '" class="' + divClass + '" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="' + divId + '1">' + content[0] + '</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="' + divId + '2">' + content[1] + '</div></div>')
    var scrollerinstance = this
    if (window.addEventListener) //run onload in DOM2 browsers
        window.addEventListener("load", function () { scrollerinstance.initialize() }, false)
    else if (window.attachEvent) //run onload in IE5.5+
        window.attachEvent("onload", function () { scrollerinstance.initialize() })
    else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
        setTimeout(function () { scrollerinstance.initialize() }, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize = function () {
    this.tickerdiv = document.getElementById(this.tickerid)
    this.visiblediv = document.getElementById(this.tickerid + "1")
    this.hiddendiv = document.getElementById(this.tickerid + "2")
    this.visibledivtop = parseInt(pausescroller.getCSSpadding(this.tickerdiv))
    //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
    this.visiblediv.style.width = this.hiddendiv.style.width = this.tickerdiv.offsetWidth - (this.visibledivtop * 2) + "px"
    this.getinline(this.visiblediv, this.hiddendiv)
    this.hiddendiv.style.visibility = "visible"
    var scrollerinstance = this
    document.getElementById(this.tickerid).onmouseover = function () { scrollerinstance.mouseoverBol = 1 }
    document.getElementById(this.tickerid).onmouseout = function () { scrollerinstance.mouseoverBol = 0 }
    if (window.attachEvent) //Clean up loose references in IE
        window.attachEvent("onunload", function () { scrollerinstance.tickerdiv.onmouseover = scrollerinstance.tickerdiv.onmouseout = null })
    setTimeout(function () { scrollerinstance.animateup() }, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup = function () {
    var scrollerinstance = this
    if (parseInt(this.hiddendiv.style.top) > (this.visibledivtop + 5)) {
        this.visiblediv.style.top = parseInt(this.visiblediv.style.top) - 5 + "px"
        this.hiddendiv.style.top = parseInt(this.hiddendiv.style.top) - 5 + "px"
        setTimeout(function () { scrollerinstance.animateup() }, 50)
    }
    else {
        this.getinline(this.hiddendiv, this.visiblediv)
        this.swapdivs()
        setTimeout(function () { scrollerinstance.setmessage() }, this.delay)
    }
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs = function () {
    var tempcontainer = this.visiblediv
    this.visiblediv = this.hiddendiv
    this.hiddendiv = tempcontainer
}

pausescroller.prototype.getinline = function (div1, div2) {
    div1.style.top = this.visibledivtop + "px"
    div2.style.top = Math.max(div1.parentNode.offsetHeight, div1.offsetHeight) + "px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage = function () {
    var scrollerinstance = this
    if (this.mouseoverBol == 1) //if mouse is currently over scoller, do nothing (pause it)
        setTimeout(function () { scrollerinstance.setmessage() }, 100)
    else {
        var i = this.hiddendivpointer
        var ceiling = this.content.length
        this.hiddendivpointer = (i + 1 > ceiling - 1) ? 0 : i + 1
        this.hiddendiv.innerHTML = this.content[this.hiddendivpointer]
        this.animateup()
    }
}

pausescroller.getCSSpadding = function (tickerobj) { //get CSS padding value, if any
    if (tickerobj.currentStyle)
        return tickerobj.currentStyle["paddingTop"]
    else if (window.getComputedStyle) //if DOM2
        return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
    else
        return 0
}


//*****************************************************************************
//*                 Gestion des menus déroulants
//*****************************************************************************

// the timeout for the menu
var timeout = 1000;

// not very clean but simple
// the function can be run in the HTML for faster display
// window.onload=initMenu;

// creat timeout variables for list item
// it's for avoid some warning with IE
for (var i = 0; i < 100; i++) {
    eval("var timeoutli" + i + " = false;");
}

// this fonction apply the CSS style and the event
function initMenu() {
    // a test to avoid some browser like IE4, Opera 6, and IE Mac
    if (browser.isDOM1
    && !(browser.isMac && browser.isIE)
    && !(browser.isOpera && browser.versionMajor < 7)
    && !(browser.isIE && browser.versionMajor < 5)) {
        // get some element
        var menu = document.getElementById('menu'); // the root element
        var lis = menu.getElementsByTagName('li'); // all the li

        // change the class name of the menu, 
        // it's usefull for compatibility with old browser
        menu.className = 'menu';

        // i am searching for ul element in li element
        for (var i = 0; i < lis.length; i++) {
            // is there a ul element ?
            if (lis.item(i).getElementsByTagName('ul').length > 0) {
                // improve IE key navigation
                if (browser.isIE) {
                    addAnEvent(lis.item(i), 'keyup', show);
                }
                // link events to list item
                addAnEvent(lis.item(i), 'mouseover', show);
                addAnEvent(lis.item(i), 'mouseout', timeoutHide);
                addAnEvent(lis.item(i), 'blur', timeoutHide);
                addAnEvent(lis.item(i), 'focus', show);

                // add an id to list item
                lis.item(i).setAttribute('id', "li" + i);
            }
        }
    }
}

function addAnEvent(target, eventName, functionName) {
    // apply the method to IE
    if (browser.isIE) {
        //attachEvent dont work properly with this
        eval('target.on' + eventName + '=functionName');
    }
    // apply the method to DOM compliant browsers
    else {
        target.addEventListener(eventName, functionName, true); // true is important for Opera7
    }
}

// hide the first ul element of the current element
function timeoutHide() {
    // start the timeout
    eval("timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );");
}

// hide the ul elements under the element identified by id
function hideUlUnder(id) {
    document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden';
}

// show the first ul element found under this element
function show() {
    // show the sub menu
    this.getElementsByTagName('ul')[0].style['visibility'] = 'visible';
    var currentNode = this;
    while (currentNode) {
        if (currentNode.nodeName == 'LI') {
            currentNode.getElementsByTagName('a')[0].className = 'linkOver';
        }
        currentNode = currentNode.parentNode;
    }
    // clear the timeout
    eval("clearTimeout( timeout" + this.id + ");");
    hideAllOthersUls(this);
}

// hide all ul on the same level of  this list item
function hideAllOthersUls(currentLi) {
    var lis = currentLi.parentNode;
    for (var i = 0; i < lis.childNodes.length; i++) {
        if (lis.childNodes[i].nodeName == 'LI' && lis.childNodes[i].id != currentLi.id) {
            hideUlUnderLi(lis.childNodes[i]);
        }
    }
}

// hide all the ul wich are in the li element
function hideUlUnderLi(li) {
    var as = li.getElementsByTagName('a');
    for (var i = 0; i < as.length; i++) {
        as.item(i).className = "";
    }
    var uls = li.getElementsByTagName('ul');
    for (var i = 0; i < uls.length; i++) {
        uls.item(i).style['visibility'] = 'hidden';
    }
}



//*****************************************************************************
//*                 Détection du navigateur
//*****************************************************************************
function BrowserDetectLite() {
    var ua = navigator.userAgent.toLowerCase();

    // browser name
    this.isGecko = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
    this.isMozilla = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
    this.isNS = ((this.isGecko) ? (ua.indexOf('netscape') != -1) : ((ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1)));
    this.isIE = ((ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1));
    this.isSafari = (ua.indexOf('safari') != -1);
    this.isOpera = (ua.indexOf('opera') != -1);
    this.isKonqueror = (ua.indexOf('konqueror') != -1 && !this.isSafari);
    this.isIcab = (ua.indexOf('icab') != -1);
    this.isAol = (ua.indexOf('aol') != -1);

    // spoofing and compatible browsers
    this.isIECompatible = ((ua.indexOf('msie') != -1) && !this.isIE);
    this.isNSCompatible = ((ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);

    // browser version
    this.versionMinor = parseFloat(navigator.appVersion);

    // correct version number
    if (this.isNS && this.isGecko) {
        this.versionMinor = parseFloat(ua.substring(ua.lastIndexOf('/') + 1));
    }
    else if (this.isIE && this.versionMinor >= 4) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('msie ') + 5));
    }
    else if (this.isMozilla) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('rv:') + 3));
    }
    else if (this.isSafari) {
        this.versionMinor = parseFloat(ua.substring(ua.lastIndexOf('/') + 1));
    }
    else if (this.isOpera) {
        if (ua.indexOf('opera/') != -1) {
            this.versionMinor = parseFloat(ua.substring(ua.indexOf('opera/') + 6));
        }
        else {
            this.versionMinor = parseFloat(ua.substring(ua.indexOf('opera ') + 6));
        }
    }
    else if (this.isKonqueror) {
        this.versionMinor = parseFloat(ua.substring(ua.indexOf('konqueror/') + 10));
    }
    else if (this.isIcab) {
        if (ua.indexOf('icab/') != -1) {
            this.versionMinor = parseFloat(ua.substring(ua.indexOf('icab/') + 6));
        }
        else {
            this.versionMinor = parseFloat(ua.substring(ua.indexOf('icab ') + 6));
        }
    }

    this.versionMajor = parseInt(this.versionMinor);
    this.geckoVersion = ((this.isGecko) ? ua.substring((ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14)) : -1);

    // dom support
    this.isDOM1 = (document.getElementById);
    this.isDOM2Event = (document.addEventListener && document.removeEventListener);

    // css compatibility mode
    this.mode = document.compatMode ? document.compatMode : 'BackCompat';

    // platform
    this.isWin = (ua.indexOf('win') != -1);
    this.isWin32 = (this.isWin && (ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1));
    this.isMac = (ua.indexOf('mac') != -1);
    this.isUnix = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
    this.isLinux = (ua.indexOf('linux') != -1);

    // specific browser shortcuts
    this.isNS4x = (this.isNS && this.versionMajor == 4);
    this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
    this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
    this.isNS4up = (this.isNS && this.versionMinor >= 4);
    this.isNS6x = (this.isNS && this.versionMajor == 6);
    this.isNS6up = (this.isNS && this.versionMajor >= 6);
    this.isNS7x = (this.isNS && this.versionMajor == 7);
    this.isNS7up = (this.isNS && this.versionMajor >= 7);

    this.isIE4x = (this.isIE && this.versionMajor == 4);
    this.isIE4up = (this.isIE && this.versionMajor >= 4);
    this.isIE5x = (this.isIE && this.versionMajor == 5);
    this.isIE55 = (this.isIE && this.versionMinor == 5.5);
    this.isIE5up = (this.isIE && this.versionMajor >= 5);
    this.isIE6x = (this.isIE && this.versionMajor == 6);
    this.isIE6up = (this.isIE && this.versionMajor >= 6);

    this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectLite();

