function SwitchImg(img, img_zoom, p_img) {
    document.getElementById("zoom1").src = '../images/stores_standards/store_ext/gallerie/'+img;
    // Définition du lien de l'image de zoom correspondant à la 1ère miniature
    document.getElementById("lienZoom").href = '../images/stores_standards/store_ext/gallerie/'+ img_zoom;
    document.getElementById("mini_img_caddie").src = '../images/stores_standards/store_ext/gallerie/'+p_img;
}

// Lightbox
$(function() {
    $('#gallery a').lightBox({
        fixedNavigation:true
    });
    $('#gallery2 a').lightBox({
        fixedNavigation:true
    });
    $('#gallery3 a').lightBox({
        fixedNavigation:true
    });
});

function ChangeBoisTisse() {
    var i = document.getElementById("listeBoisTisse").selectedIndex;
    var url = document.getElementById("listeBoisTisse").options[i].value;
    window.location.href= "store_exterieur.php?type="+url;
}

function ChangeFinition(finition,liste_type) {
    ChangeStBateau(finition,liste_type);
//document.getElementById('liste_st_bateau').value.selected=finition;
}

function ChangeDim() {
    var i = document.getElementById("listeDim").selectedIndex;
    var dim = document.getElementById("listeDim").options[i].value;
    document.getElementById("dim").value = dim;
    calculPrix();
}
save='';
function ChangeColoris(coloris,liste_img, liste_coloris) {
    document.getElementById('couleur').value=coloris;
    tabImgGal=liste_img.split('|');

    //alert($('#SMB3630').text())
    if(coloris=='venise')
    {
        $('#select_dim_SSM').show();
        $('#select_dim_SSM_venise').hide();
        ChangeRefBanne('SSM5930', 'SSM');
        $('#select_dim_SSM').val('SSM5930');
    }
    /*else if(coloris=='milano')
				{
				    $('#select_dim_SMB').hide();
				    $('#select_dim_SMB_milano').show();
				    ChangeRefBanne('SMB3025', 'SMB');
				    $('#select_dim_SMB_milano').val('SSM3025');
				}*/
    else
    {
        if(coloris=='capri')
        {
            $('#select_dim_SSM').hide();
            $('#select_dim_SSM_venise').show();
            ChangeRefBanne('SSM5930', 'SSM');

        }
    /* else if(coloris=='pesaro')
				    {
					$('#select_dim_SMB').show();
					$('#select_dim_SMB_milano').hide();
					ChangeRefBanne('SMB3025', 'SMB');
					$('#select_dim_SMB').val('SSM3025');
				    }*/
    //$('#select_dim_SSM').show();
    //$('#SMB3630').show();
    }

    if(liste_coloris!='none')
    {
        tabColoris=liste_coloris.split('|');

        for(id in tabColoris)
        {
            if(coloris!=tabColoris[id])
            {
                document.getElementById('coloris_'+tabColoris[id]).src='../images/stores_standards/store_ext/coloris/bt_'+ tabColoris[id] +'_off.jpg';
            }
            else
            {
                document.getElementById('coloris_'+tabColoris[id]).src='../images/stores_standards/store_ext/coloris/bt_'+ tabColoris[id] +'_on.jpg';
            }
        }

        var mini_gal='';
        for(id in tabImgGal)
        {
            if(id==0)
            {
                document.getElementById("zoom1").src = '../images/stores_standards/store_ext/gallerie/'+ coloris +'/m_'+ tabImgGal[id];
                // Définition du lien de l'image de zoom correspondant à la 1ère miniature
                document.getElementById("lienZoom").href = '../images/stores_standards/store_ext/gallerie/'+ coloris +'/g_'+ tabImgGal[id];
            }
            mini_gal=mini_gal+'<img class="imgmini" src="../images/stores_standards/store_ext/gallerie/'+ coloris +'/p_'+ tabImgGal[id] +'"  onclick="SwitchImg(\''+ coloris +'/m_'+ tabImgGal[id] +'\',\''+ coloris +'/g_'+ tabImgGal[id] +'\', \''+ coloris +'/p_'+ tabImgGal[id] +'\')" style="cursor:pointer;">';
        }

        document.getElementById('echo_mini').innerHTML=mini_gal;
    }
    else
    {
        var mini_gal='';
        coloris='pesaro';
        for(id in tabImgGal)
        {
            if(id==0)
            {
                document.getElementById("zoom1").src = '../images/stores_standards/store_ext/gallerie/'+ coloris +'/m_'+ tabImgGal[id];
                // Définition du lien de l'image de zoom correspondant à la 1ère miniature
                document.getElementById("lienZoom").href = '../images/stores_standards/store_ext/gallerie/'+ coloris +'/g_'+ tabImgGal[id];
            }
            mini_gal=mini_gal+'<img class="imgmini" src="../images/stores_standards/store_ext/gallerie/'+ coloris +'/p_'+ tabImgGal[id] +'"  onclick="SwitchImg(\''+ coloris +'/m_'+ tabImgGal[id] +'\',\''+ coloris +'/g_'+ tabImgGal[id] +'\', \''+ coloris +'/p_'+ tabImgGal[id] +'\')" style="cursor:pointer;">';
        }

        document.getElementById('echo_mini').innerHTML=mini_gal;
    }



}

function ChangeQte(iDQte,ope) {
    if(ope == "plus") {
        document.getElementById(iDQte).value++;
        document.getElementById('qtpopup').value++;
    }
    else {
        if(document.getElementById(iDQte).value > 1) {
            document.getElementById(iDQte).value--;
            document.getElementById('qtpopup').value--;
        }
    }
    calculPrix();
}

function calculPrix() {
    var ref_choose = document.getElementById('ref_st_choose').value;
    var nbr_produit= $('#qtBT').val();
    //on va recuperer grace a l'ajax le prix
    //alert('ref='+ref_choose+'&nbr_prod='+nbr_produit);
    response=AjaxRequest('ajax_ext/calculprix.php','ref='+ref_choose+'&nbr_prod='+nbr_produit);
    TabInf=response.split('|');
    var totalHT=parseFloat(TabInf['0']);
    var totalHTUNI=parseFloat(TabInf['1']);
    var promo = document.getElementById("promoBT").value;
    //alert(TabInf['3']);
    var promo_prod=parseFloat(TabInf['3']);
    //alert(promo_prod)
    //alert(promo);
    if(promo != 0)
    {
        var prixPromo = totalHT - (totalHT * promo/100);
        var prixPromoUNI = totalHTUNI - (totalHTUNI * promo/100);
        //document.getElementById("prixVpromo").value = Math.round((prixPromo)*100)/100;
        var puhtpromo = prix - (prix*promo/100);
        document.getElementById("puhtpromo").value = puhtpromo;
        var prixTTCPromo = prixPromo+(prixPromo*0.196);
        //document.getElementbyId('labelPrix').value=Math.round((prixPromo)*100)/100;
        //document.getElementbyId('labelPrix').value=Math.round((prixPromo)*100)/100;
        document.getElementById("prixTTC").value = Math.round((prixTTCPromo)*100)/100;
        document.getElementById("ttcpopup").value = Math.round((prixTTCPromo)*100)/100;
    //$('#')
    }
    else if(promo_prod!=0) {
        totalHT=totalHT-(totalHT * promo_prod)/100;
        var prixTTC = totalHT + (totalHT * 0.196);
        //alert(response);
        //alert((totalHT * 0.196));

        document.getElementById('prix1').value=Math.round((totalHTUNI)*100)/100;
        document.getElementById('prixHT').value=Math.round((totalHT)*100)/100;
        document.getElementById("prixTTC").value = Math.round((prixTTC)*100)/100;

        calcul_promo_UNI=Math.round((totalHTUNI-((promo_prod*totalHTUNI)/100))*100)/100;
        $('#val_promo_unitaire').html(calcul_promo_UNI);
        $('#puhtpromo').val(calcul_promo_UNI);
        document.getElementById("ttcpopup").value = Math.round((prixTTC)*100)/100;
    }
    else {
        var prixTTC = totalHT + (totalHT * 0.196);
        //alert(response);
        //alert((totalHT * 0.196));
        $('#prix1').val(Math.round((totalHTUNI)*100)/100);
        $('#prixHT').val(Math.round((totalHT)*100)/100);
        $("#prixTTC").val( Math.round((prixTTC)*100)/100 );
        $("#ttcpopup").val(Math.round((prixTTC)*100)/100);
    }
}


// -------------------------------------------------------------------------------------------
// 		Action sur le menu du bas: Descriptif / Utilisation / Caractéristique techniques
// -------------------------------------------------------------------------------------------

function MenuBas(onglet) {
    switch (onglet) {
        case 1 :
            document.getElementById("txtBas1").style.display = 'block';
            document.getElementById("txtBas2").style.display = 'none';
            document.getElementById("txtBas3").style.display = 'none';
            document.getElementById("m_description").style.textDecoration = 'underline';
            document.getElementById("m_utilisation").style.textDecoration = 'none';
            document.getElementById("m_caract").style.textDecoration = 'none';
            break;

        case 2 :
            document.getElementById("txtBas2").style.display = 'block';
            document.getElementById("txtBas1").style.display = 'none';
            document.getElementById("txtBas3").style.display = 'none';
            document.getElementById("m_utilisation").style.textDecoration = 'underline';
            document.getElementById("m_description").style.textDecoration = 'none';
            document.getElementById("m_caract").style.textDecoration = 'none';
            break;

        case 3 :
            document.getElementById("txtBas3").style.display = 'block';
            document.getElementById("txtBas2").style.display = 'none';
            document.getElementById("txtBas1").style.display = 'none';
            document.getElementById("m_caract").style.textDecoration = 'underline';
            document.getElementById("m_description").style.textDecoration = 'none';
            document.getElementById("m_utilisation").style.textDecoration = 'none';
            break;
    }
}


// ------------------------------------------------
// 				Action sur les boutons
// ------------------------------------------------

// Bouton "Ajouter au panier"

// onMouseOver sur le bouton "Ajouter au panier"
function btPanierIn(){
    document.getElementById("btpanier1").src="../images/bois_tisse_std/bt_ajout_panier_on.jpg";
}
// onMouseOut sur le bouton "Ajouter au panier"
function btPanierOut(){
    document.getElementById("btpanier1").src="../images/bois_tisse_std/bt_ajout_panier_off.jpg";
}
// onClick sur le bouton "Ajouter au panier"
function valider(){
    popupPanier();
}

// Bouton "Continuer mes achats" de la popup

// onMouseOver sur le bouton "Continuer mes achats" de la popup
function btpop1In(){
    document.getElementById("btpop1").src="../images/bois_tisse_std/bt_continuez_on.png";
}
// onMouseOut sur le bouton "Continuer mes achats" de la popup
function btpop1Out(){
    document.getElementById("btpop1").src="../images/bois_tisse_std/bt_continuez_off.png";
}
// onClick sur le bouton "Continuer mes achats" de la popup
function killPopup()
{
    document.getElementById('popup_panier').style.display = 'none';
    document.getElementById('popup_panier_ombre').style.display = 'none';
    document.getElementById('text_popup').style.display = 'none';
//    reset();
//    ReloadPage();
}

// onMouseOver sur le bouton "Voir mon panier" de la popup
function btpop2In(){
    document.getElementById("btpop2").src="../images/bois_tisse_std/bt_panier_on.png";
}
// onMouseOut sur le bouton "Voir mon panier" de la popup
function btpop2Out(){
    document.getElementById("btpop2").src="../images/bois_tisse_std/bt_panier_off.png";
}
// onClick sur le bouton "Voir mon panier" de la popup

function BatTissuValid(pop)
{
    if(pop=='panier')window.location.href= "../recapitulatifcaddie.php";
    else
    {
        var store = document.getElementById('type_store').value;
        var ref = document.getElementById('ref_st_choose').value
        var couleur = document.getElementById('couleur').value;
        var quantite = document.getElementById('qtpopup').value;
        var pu = document.getElementById('prix1').value.replace(",",".");
        var ttht = document.getElementById('prixHT').value.replace(",",".");
        var pttc = document.getElementById('prixTTC').value.replace(",",".");
        var valpromo = $('#valpromo').val();
        var select_dim = $('#select_dim_'+ref).val();
        //alert("select_dim : "+ref);
        var puhtpromo = document.getElementById('puhtpromo').value.replace(",",".");
        response2=AjaxRequest('ajax_ext/valider.php','store='+store+'&ref='+ref+'&couleur='+couleur+'&quantite='+quantite+'&pu='+pu+'&ttht='+ttht+'&pttc='+pttc+'&ref='+ref+'&valpromo='+valpromo+'&puhtpromo='+puhtpromo);
    //response=AjaxRequest('ajax_ext/calculprix.php','ref=0&nbr_prod=1');
    //if(pop=='reload')ReloadPage();

    }
}

function reset(){
    window.location.reload(true);
}

function popupPanier()
{

    var alpha = 50;
    document.getElementById('popup_panier').style.display = 'block';
    document.getElementById('popup_panier_ombre').style.display = 'none';
    document.getElementById('text_popup').style.display = 'block';
    document.getElementById('popup_panier').style.opacity = alpha/100;

    /* Test pour notre cher IE */
    if (document.body.filters != undefined)
    {
        document.getElementById('popup_panier').style.filter = 'alpha(opacity:' + alpha + ')';
    }
    BatTissuValid();
}

// ------------------------------------------------
// 			Fin des action sur les boutons
// ------------------------------------------------

// Popup Aide finition
function PlacerDiv(DivId, idimg)
{
    document.getElementById(DivId).style.left = ("25px");
    document.getElementById(DivId).style.top = ("277px");
    document.getElementById(DivId).style.display = 'block';
    if(idimg=="aideFinition"){
        document.getElementById("aideFinition").src = "../images/bois_tisse_std/aide_on.png";
    }
}
function FermerDiv(DivId)
{
    document.getElementById(DivId).style.display = 'none';
    document.getElementById("aideFinition").src = "../images/bois_tisse_std/aide_off.png";
}

function ChangeStBateau(type_select,liste_type)
{
    TabType=liste_type.split('|');

    for(type in TabType)
    {
        document.getElementById('select_dim_'+TabType[type]).style.display='none';
    /*
			document.getElementById('select_dim_'+TabType[type]+'_01').style.display='none';
			document.getElementById('select_dim_'+TabType[type]+'_02').style.display='none';
			document.getElementById('select_dim_'+TabType[type]+'_03').style.display='none';
			document.getElementById('select_dim_'+TabType[type]+'_04').style.display='none';
			*/
    //alert('select_dim_'+TabType[type]+'_01');
    }
    RedirectLink('./store_exterieur.php?type='+type_select);

}

function ChangeRefBanne(ref, listType)
{
    document.getElementById('ref_st_bateau').innerHTML=ref;
    $('#ref_st_choose').val(ref);
    $('#refpopup').val(ref);

    if(typeof(listType)!='undefined' && listType=='PDB')
    {
        //on change la galerie
        $('#PDB3030_carac').hide();
        $('#PDB4040_carac').hide();
        $('#PDB3030_desc').hide();
        $('#PDB4040_desc').hide();
        $('#PDB3030_carac_2').hide();
        $('#PDB4040_carac_2').hide();

        if(ref=='PDB3030')
        {
            $('#coloris_milano').hide();
            $('#coloris_pesaro').hide();
            $('#coloris_salerno').show();
            $('#btpanier1').show();
            $('#btpanier2').hide();
            $('#stock_dispo').show();
            ChangeColoris('salerno','pdb3030_1.jpg','salerno');
        }
        else
        {
            $('#coloris_milano').show();
            $('#coloris_pesaro').show();
            $('#coloris_salerno').hide();
            $('#btpanier1').hide();
            $('#btpanier2').show();
            $('#stock_dispo').hide();
            //ChangeColoris('milano','milano_pdb_2.jpg|milano_pdb_3.jpg|parasoldoublepente_1.jpg','milano|pesaro|salerno');
            ChangeColoris('none','pesaro_pdb_3.jpg|pesaro_pdb_4.jpg|parasoldoublepente_1.jpg','none');
        }
        $('#'+ref+'_carac').show();
        $('#'+ref+'_carac_2').show();
        $('#'+ref+'_desc').show();
    }
    //document.getElementById('ref_st_choose').value=ref;
    //document.getElementById('refpopup').value=ref;

    calculPrix();

    // Alerte si store sup à 300
    if(ref == 'SMB3630' || ref == 'SMB5830'
        || ref == 'PDB4040' || ref == 'SSM5930') {
        //lightBox('<img src="../images/stores_exterieurs/aide-transporteur-store-banne-exterieur.png" /><p><strong>Votre store fait plus de 3 mètres.</strong> En raison de son poids, <strong>il vous sera demandé d’aider le transporteur lors du déchargement du store.</strong><br /><br />Nous vous recommandons d’être accompagné d’une autre personne lors de la livraison.<br /><br />Vous serez contacté par le transporteur afin de fixer l’heure et le jour de livraison.</p>');
        lightBox('<img src="../images/stores_exterieurs/aide-transporteur-store-banne-exterieur.png" />');
    }
}

