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_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 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_showHideLayers() { //v6.0
    var i,p,v,obj,args=MM_showHideLayers.arguments;
    for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {
        v=args[i+2];
        if (obj.style) {
            obj=obj.style;
            v=(v=='show')?'visible':(v=='hide')?'hidden':v;
        }
        obj.visibility=v;
    }
}

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 raz_menu(menu_actif){
    if(menu_actif!=1)	document.form1.epoque.selectedIndex=0;
    if(menu_actif!=2)	document.form1.categorie.selectedIndex=0;
    if(menu_actif!=3)	document.form1.taille.selectedIndex=0;
}

function change_txt_results(champ,toThis){
    mchamp = MM_findObj(champ);
    mchamp.innerHTML = toThis;
}

function show_hide(champ,toThis)
{
    if (document.getElementById)
    {
        document.getElementById(champ).style.display = toThis;
    }
    else if (document.all)
    {
        document.all[champ].style.display= toThis;
    }
}//test pour page inscription


function noshow_hide(champ,toThis)
{
    if (document.getElementById)
    {
        document.getElementById(champ).style.display = none;
    }
    else if (document.all)
    {
        document.all[champ].style.display= none;
    }
}

function add_panier(id,ref,lang){

    var poststr = "id_a_ajouter="+id+"&ref_a_ajouter="+ref+"&action=addcart" ;
    makePOSTRequest('/panier.php', poststr,"panier");
    maction="";
    confirmUrl('drawCartDivConfirm'+lang+'()');
}

function add_idkdo(id,ref,lang){

    var poststr = "id_a_ajouter="+id+"&ref_a_ajouter="+ref+"&action=addidkdo" ;
    makePOSTRequest('/panier.php', poststr,"panier");
    maction="";
    confirmUrl('drawIdkoDivConfirm'+lang+'()') ;
}

function add_produit_vu(id){

    var poststr = "id_produit_vu="+id;
    makePOSTRequest('/compteur.php', poststr,"compteur");
    maction="";
}

function recalcul(){
    formulaire = "formCaddie";
    if (document.getElementById)
    {
        form = document.getElementById(formulaire);
    }
    else if (document.all)
    {
        form = document.all[formulaire];
    }
	
    total = form.totalref.value;
	
    chaine="";
    for(i=1;i<=total;i++){
        if (form["qte"+i].value==0)
        {
            chaine = chaine + "&qte" +i+"=1";
            chaine = chaine + "&ref"+i+"="+form["ref"+i].value;
        }
        else{
            var absqte=Math.abs(form["qte"+i].value);
            chaine = chaine + "&qte" +i+"="+Math.abs(form["qte"+i].value);
            chaine = chaine + "&ref"+i+"="+form["ref"+i].value;
        }
    }
	
    if(chaine){
        var poststr = "nb_article="+total+"&action=calculCaddie&" + chaine;
        makePOSTRequest('/panier.php', poststr,"panier");
        maction="";
    }

}

function deleteCChkdoRecap(id)
{
    var action = "&action=delcheckcouponrecap&ref="+id;
    makePOSTRequest('/ajax/cheque_recap.php', action ,"recap");
}
function deleteCChkdo(id)
{
    var action = "&action=delcheckcoupon&id="+id;
    makePOSTRequest('/ajax/panier_recap.php', action ,"recap");
}
function deleteFromCaddie(ref){
    if(ref){
        var poststr = "action=deleteFromCaddie&ref=" + ref;
        makePOSTRequest('/panier.php', poststr,"panier");
        maction="";
    }

}
function deleteFromCaddieRecap(ref,idkdo)
{
    if(ref)
    {
        var poststr = "action=deleteFromCaddie&ref=" + ref+"&idkdo="+idkdo;
        makePOSTRequest('/ajax/panier_recap.php', poststr,"recap");
        maction="";
        if (document.getElementById("formCaddieRecap").totalref.value == 1) document.getElementById("p_adresse_acceptation").style.visibility = 'hidden' ;
    }

}
function deleteFromIdKdo(ref){
    if(ref)
    {
        var poststr = "action=deleteFromIdKdo&ref=" + ref;
        makePOSTRequest('/panier.php', poststr,"panier");
        maction="";
    }

}
 
//envoi des informations vers la bdd
var http_request = false;
var mresultat;
 
function makePOSTRequest(url, parameters,todo) 
{
    var xhr_object = null;

    if(window.XMLHttpRequest) // Firefox
        xhr_object = new XMLHttpRequest();
    else if(window.ActiveXObject) // Internet Explorer
        xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    else
    { // XMLHttpRequest non support? par le navigateur
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
        return;
    }
	
    if(todo=="recap")
    {
        xhr_object.onreadystatechange = function alertContents()
        {
            if (xhr_object.readyState == 4)
            {
                if (xhr_object.status == 200)
                {
                    mresultat = unescape(xhr_object.responseText);
                    change_txt_results("formCaddieRecap",mresultat);
                }
                else
                {
                    alert('There was a problem with the ajax request1.');
                }
            }
        }
    }
    else if(todo=="vehicule_marque_div" || todo=="vehicule_modele_div")
    {
        xhr_object.onreadystatechange = function alertContents() {
            if (xhr_object.readyState == 4)
            {
                if (xhr_object.status == 200)
                {
                    mresultat = unescape(xhr_object.responseText);
                    change_txt_results(todo,mresultat);
                }
                else
                    alert('There was a problem with the ajax request2.');
            }
        }
    }
    else
    {
        xhr_object.onreadystatechange = function alertContents() {
            if (xhr_object.readyState == 4) {
                if (xhr_object.status == 200) {
                    mresultat = unescape(xhr_object.responseText);
                    //alert(result);
                    change_txt_results("textepanier",mresultat);
					
                } else {
            //alert('There was a problem with the ajax request3.');
            }
            }
        }
    }
    xhr_object.open('POST', url, true);
    xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
    xhr_object.setRequestHeader("Content-length", parameters.length);
    xhr_object.setRequestHeader("Connection", "close");
    xhr_object.send(parameters);
}
 
function msg(msg){
    alert(msg);
}

function chgMarque(id_select)
{

    // Objet liste déroulante des véhicules
    champ = MM_findObj("vehicule_type");
	
    // Id du type de véhicule
    id = champ[champ.selectedIndex].value;

	
    var poststr = "type="+id+"&id_select="+id_select+"&ddl_name=vehicule_marque";
    makePOSTRequest('/ajax/liste_vehicules.php', poststr,"vehicule_marque_div");
    maction="";
    //on vide modele
    tmp = MM_findObj("vehicule_modele_div");

    tmp.innerHTML ="<select name=\"vehicule_modele\" id=\"vehicule_modele\" size=\"1\"></select>";
	

}

function chgModele(id_select){
    champ = MM_findObj("vehicule_marque");
    id = champ[champ.selectedIndex].value;
    var poststr = "type="+id+"&id_select="+id_select+"&ddl_name=vehicule_modele";

    makePOSTRequest('/ajax/liste_vehicules.php', poststr,"vehicule_modele_div");
    maction="";

}


function verifEmail(email) { // v?rif validit? email par REGEXP
    var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/
    return (reg.exec(email)!=null)
}

function decremente(champ){
    form = MM_findObj("formCaddieRecap");
    if(form[champ].value>0){
        form[champ].value = (1*form[champ].value)-1;
    }
}

function incremente(champ){
    form = MM_findObj("formCaddieRecap");
    form[champ].value = (1*form[champ].value) + 1;
}

function cochecadeau(champ,i,idkdo,nom){
    form = MM_findObj("formCaddieRecap");
    //form[champ](i).value = (1*form[champ](i).value) + 1;
    form[champ][i].checked="checked";
	
    chaine = form[champ][i].value;

    if(chaine){
        var poststr = "ptskdo="+chaine+"&idkdo="+idkdo+"&nom="+nom;
        makePOSTRequest('/ajax/panier_recap.php', poststr,"recap");
        maction="";
    }
	
}

function recalculRecap(idkdo){
    formulaire = "formCaddieRecap";

    form = MM_findObj(formulaire);
	
    total = form.totalref.value;
	
    chaine="";
    for(i=1;i<=total;i++){
        chaine = chaine + "&qte" +i+"="+form["qte"+i].value;
        chaine = chaine + "&ref"+i+"="+form["ref"+i].value;
    }
	

    if(chaine)
    {
        var poststr = "nb_article="+total+"&action=calculCaddie&" + chaine+"&idkdo="+idkdo;
        makePOSTRequest('/ajax/panier_recap.php', poststr,"recap");
        maction="";
    }

}
function checkCouponReduc(value)
{
    var action = "&action=checkcoupon&value="+value;
    makePOSTRequest('/ajax/panier_recap.php', action ,"recap");
}
function affiche(bloc){
    c = document.getElementById(bloc);
    if(c.style.visibility == 'visible'){
        c.style.visibility = 'hidden';
        c.style.display = 'none';
    }else{
        c.style.visibility = 'visible';
        c.style.display = 'block';
    }
}

function toggle(id) 
{
    if (document.getElementById)
    {
        var cdiv = document.getElementById(id);
        if (cdiv)
        {
            if (cdiv.className != 'minimized')
                cdiv.className = 'minimized';
					  
        }
    }
}


function notoggle(id) 
{

    if (document.getElementById)
    {
        var cdiv = document.getElementById(id);
        if (cdiv)
        {
            if (cdiv.className != 'minimized')
                cdiv.className = 'minimized';
            else
                cdiv.className = '';
        }
    }
}

// Supprime les espaces des strings
function trim(s) 
{
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
}



function	benchWriteSwf(url)
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"  width="180"  height="180"  align="center" valign="middle" id="rotateTool"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="swf/rotateTool.swf?path=../objects/'+url+'/" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="transparent" /><param name="scale" value="ShowAll" /><param name="salign" value="lt" /><embed src="swf/rotateTool.swf?path=../objects/'+url+'/" quality="high" scale="ShowAll" salign="lt" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="180" height="180" wmode="transparent" bgcolor="#FFFFFF"></embed></object>');
}

function	bigbenchWriteSwf(url)
{
    document.write('<center><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"  width="400"  height="500"  id="rotateTool"  align="left"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="../swf/rotateTool.swf?path=../objects/'+url+'/" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="transparent" /><embed src="../swf/rotateTool.swf?path=../objects/'+url+'/" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400"  height="500" wmode="transparent" bgcolor="#FFFFFF"></embed></object></center>');
}

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);
}

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
        || this.searchVersion(navigator.appVersion)
        || "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++)	{
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
    {
        string: navigator.userAgent,
        subString: "OmniWeb",
        versionSearch: "OmniWeb/",
        identity: "OmniWeb"
    },
    {
        string: navigator.vendor,
        subString: "Apple",
        identity: "Safari"
    },
    {
        prop: window.opera,
        identity: "Opera"
    },
    {
        string: navigator.vendor,
        subString: "iCab",
        identity: "iCab"
    },
    {
        string: navigator.vendor,
        subString: "KDE",
        identity: "Konqueror"
    },
    {
        string: navigator.userAgent,
        subString: "Firefox",
        identity: "Firefox"
    },
    {
        string: navigator.vendor,
        subString: "Camino",
        identity: "Camino"
    },
    {		// for newer Netscapes (6+)
        string: navigator.userAgent,
        subString: "Netscape",
        identity: "Netscape"
    },
    {
        string: navigator.userAgent,
        subString: "MSIE",
        identity: "Explorer",
        versionSearch: "MSIE"
    },
    {
        string: navigator.userAgent,
        subString: "Gecko",
        identity: "Mozilla",
        versionSearch: "rv"
    },
    { 		// for older Netscapes (4-)
        string: navigator.userAgent,
        subString: "Mozilla",
        identity: "Netscape",
        versionSearch: "Mozilla"
    }
    ],
    dataOS : [
    {
        string: navigator.platform,
        subString: "Win",
        identity: "Windows"
    },
    {
        string: navigator.platform,
        subString: "Mac",
        identity: "Mac"
    },
    {
        string: navigator.platform,
        subString: "Linux",
        identity: "Linux"
    }
    ]

};

function imageAleatoire(rep)
{
    var extention = ".gif" ;
    var nbimage = 3 ;
    var url;
    var alt;
			

    //Génére un nombre aléatoire, pour donner un numéro d'image.
    numimage = Math.round( Math.random() * ( nbimage - 1 ) + 1 );
    // Nom de votre page d'accueil
    // Page = "index_fr.html";

    // Nom du répertoire de vos images.
    //rep = "images/hp_fr";

    // Message info bulle, lors du survole de l'image affichée.
    alt = "BCD MEGASTORE";

    // Assemblage de la chaine pour afficher votre image.
    url = './' + rep + '/' + numimage + extention ;

    // Affiche le numéro d'image généré aléatoirement.
    // document.write( 'Numéro Image : ' + numimage + '<br><br>' );
    // Affiche l'image choisie ainsi que le lien vers votre page d'accueil.
    document.write ('<div align=center><img src="' + url + '" alt="' + alt + '" border=0></div>');
}
var divIsVisible=false; // La variable i nous dit si la bulle est visible ou non
function pageSize() {
    var myWidth = 0, myHeight = 0;
    var arrayPageSize = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    arrayPageSize = new Array(myWidth,myHeight)
    return arrayPageSize;
}

function cache(id) 
{
    if (id)
        var c = document.getElementById(id);
    else
        var c = document.getElementById("curseur");
    m = document.getElementById("masque");
    if (m) {
        m.style.visibility="hidden";
        m.style.display = "none";
    }
    c.style.visibility="hidden"; // Si la bulle est visible on la cache
    c.style.display = "none";
    divIsVisible=false;
}
function drawIdkoDivConfirmFR()
{
    if( document.documentElement && document.documentElement.clientWidth)
        DocRef = document.documentElement;   // Dans ce cas c'est documentElement qui est réfèrence
    else
        DocRef = document.body;
    var _docWidth = document.width || document.body.offsetWidth;
    var c = document.getElementById("curseur");
    c.style.left = ( _docWidth - 350) / 2 + "px";
    c.style.top = (window.screen.height - 500) / 2 + DocRef.scrollTop + "px";
    return ('<form action="" method="post">' +
        '<p style="font-size:14px; font-weight:bold" align="center">Votre produit &agrave; &eacute;t&eacute; ajout&eacute; &agrave; vos ID-KDO !</p>' +
        '<p align="right"><input type="button" onClick="cache(\'curseur\')" value="Ok" /></span></p>' +
        '</form>');
}
function drawCartDivConfirmFR()
{
    if( document.documentElement && document.documentElement.clientWidth)
        DocRef = document.documentElement;   // Dans ce cas c'est documentElement qui est réfèrence
    else
        DocRef = document.body;
    var _docWidth = document.width || document.body.offsetWidth;
    var c = document.getElementById("curseur");
    c.style.left = ( _docWidth - 350) / 2 + "px";
    c.style.top = (window.screen.height - 500) / 2 + DocRef.scrollTop + "px";
    return ('<form action="" method="post">' +
        '<p style="font-size:14px; font-weight:bold" align="center">Votre produit &agrave; &eacute;t&eacute; ajout&eacute; &agrave; votre panier !</p>' +
        '<p align="right"><input type="button" onClick="cache(\'curseur\')" value="Ok" /></span></p>' +
        '</form>');
}
function drawCartDivConfirmEN()
{
    if( document.documentElement && document.documentElement.clientWidth)
        DocRef = document.documentElement;   // Dans ce cas c'est documentElement qui est réfèrence
    else
        DocRef = document.body;
    var _docWidth = document.width || document.body.offsetWidth;
    var c = document.getElementById("curseur");
    c.style.left = ( _docWidth - 350) / 2 + "px";
    c.style.top = (window.screen.height - 500) / 2 + DocRef.scrollTop + "px";
    return ('<form action="" method="post">' +
        '<p style="font-size:14px; font-weight:bold" align="center">Product correctly add to cart !</p>' +
        '<p align="right"><input type="button" onClick="cache(\'curseur\')" value="Ok" /></span></p>' +
        '</form>');
}
function confirmUrl(func)
{
    var pSize = pageSize();
    i = true;
    var c = document.getElementById("curseur");
    c.style.width = 400 + "px";
    c.style.visibility="visible"; // Si il est cacher (la verif n'est qu'une securitÃ©) on le rend visible.
    c.style.display = "block";
    c.innerHTML = eval(func);
}



function page_loaded(evt) {
    var bandeau = $('bando_detail');
    bandeau.set({'styles' : {'opacity' : 0, 'z-index' : '100'}})
    var ids = ['car', 'cyc', 'equ', 'mot'];
    for (var i = 0, max = ids.length; i < max; i++ )
    {
        if (!$('menu_' + ids[i]))
            return ;
        $('menu_' + ids[i]).addEvent('mouseover', function (el, i) {
            var bimg =bandeau.getElement('img');
            var img = this.getElement('img');
            bimg.set({
                'src' : img.get('src').replace('btn', 'bandeau').replace('off', '')
                });
            bandeau.fade(1);
            img.set({
                'src' : img.get('src').replace('off', 'on')
                });
        });
        $('menu_' + ids[i]).addEvent('mouseout', function () {
            bandeau.fade(0);
            var img = this.getElement('img');
            img.set({
                'src' : img.get('src').replace('on', 'off')
                });
        });
    }
}

window.addEvent('domready', function () {
    	new Autocompleter.Request.JSON($('auto-search-input'), '/ajax/query_user.php?SSID='+SSID, {
            'selectMode': 'pick',
            'overflow': true,
		'minLength': 2
	});
    page_loaded();
    if (milkbox != 'undefined')
    milkbox.changeOptions({
        canvasBorderWidth:'5px',
        canvasBorderColor:'#fff',
        canvasPadding:'10px'
    });
});