
function P (p,t,v,b,r,ca,cp,q,rf) { //fonction Produit1
this.p = p;
this.t = t; // libellé de la taille
this.v = v; //prix (avec un POINT pour les centimes
this.b = b; //prix barré (avec un POINT pour les centimes
this.r = r; // remise pourcentage
this.ca = ca;	//code article
this.cp = cp; //reference produit
this.q = q; /* Indisponibilite //quantité de stock*/ }

var sSelectReference = '';
var sSelectCodeVente = '';
var sTaillePrecedent = 0;
var sObjTailleIdPrecedent = '';
var ProduitIdPrecedent = 0;

function ATC(p,tDivS,iCol) { //fonction Affiche/Taille/Couleur

if (iCol >= 0) { 			 
	var sTaille = ""; //stocke le HTML d'affichage des tailles
	var dcID = ""; 
	var addon = ""; //addon1= permet d'afficher la class+select
	var z = "";	//compteur qui prend chaqque taille présente dans le tableau, dipo ou non
	var bTailleSelect = false;
	if(TP[p][iCol].length == 1) addon = "select";
	for (z=0 ; z<TP[p][iCol].length ; z++) {	
	if (TP[p][iCol][z].q==1) // SI STOCK PAS DISPO ALORS NON CLIQUABLE
		{sTaille = sTaille + "<div id='dc"+p+z+"' class='pasdispo"+addon+"'><a class=info style='background:none'>" + TP[p][iCol][z].t + "<span class=colori>Non disponible</span></a></div>";
		 sTaille = sTaille + "<div class='t_sep'>&nbsp;</div>";		
		 if(addon=="select") {hidebouton(p);} // si taille non dispo ajout au panier non cliquable.
		 addon="";	// on vide le addon1 (il n'y a qu'une taille indisponible selectionnée) 	
	} else { /* SI STOCK DISPO ALORS CLIQUABLE */
	   //alert(sTaillePrecedent +' | '+ TP[p][iCol][z].t);
		//alert(sTaillePrecedent);
	    if(sTaillePrecedent == TP[p][iCol][z].t)
	    {
	    sObjTailleIdPrecedent = 'dc'+p+z
	    addon = "select";
	    }
		if (TP[p][iCol][z].t.length >=6){
		sTaille = sTaille +  "<div onclick=\"ST("+p+",this,\'"+TP[p][iCol][z].v+"\',\'"+TP[p][iCol][z].b+"\',\'"+TP[p][iCol][z].r+"\','dc"+p+z+"','"+TP[p][iCol][z].ca+"','"+TP[p][iCol][z].cp+"','"+z+"','"+TP[p][iCol][z].t+"');\" style='cursor:pointer;' id='dc"+p+z+"' class='dispo"+addon+"2' onmouseover=func_OnMouseOverTaille2('"+p+"','"+z+"'); onmouseout=func_OnMouseOutTaille2('"+p+"','"+z+"');>" +TP[p][iCol][z].t + "</div><div class='t_sep'>&nbsp;</div>" ;				
		}
		else
		{
		sTaille = sTaille +  "<div onclick=\"ST("+p+",this,\'"+TP[p][iCol][z].v+"\',\'"+TP[p][iCol][z].b+"\',\'"+TP[p][iCol][z].r+"\','dc"+p+z+"','"+TP[p][iCol][z].ca+"','"+TP[p][iCol][z].cp+"','"+z+"','"+TP[p][iCol][z].t+"');\" style='cursor:pointer;' id='dc"+p+z+"' class='dispo"+addon+"' onmouseover=func_OnMouseOverTaille('"+p+"','"+z+"'); onmouseout=func_OnMouseOutTaille('"+p+"','"+z+"');>" +TP[p][iCol][z].t + "</div><div class='t_sep'>&nbsp;</div>" ;				
		}
	}
	if(z == 6)
	{
	    sTaille = sTaille + '<br><br>';
	}	

	if(addon=="select") // si taille dispo ajout au panier cliquable.
	{
	    //alert(p+' | '+iCol+' | '+z);

	    ST(p,'dc'+p+z,TP[p][iCol][z].v,TP[p][iCol][z].b,TP[p][iCol][z].r,'dc'+p+z,TP[p][iCol][z].ca,TP[p][iCol][z].cp,z,TP[p][iCol][z].t);
	    showbouton(p);
	    bTailleSelect = true;
	}
	addon="";	// on vide le addon1 (il n'y a qu'une taille disponible selectionnée) 
	} /* met à jour l'affichage des tailles*/ 
	
	if(!bTailleSelect && HaveMultiPrix)
	{
	    SelectColori(p,TP_LBL_COL[1][iCol]['prxa'],TP_LBL_COL[1][iCol]["prxr"],TP_LBL_COL[1][iCol]["tr"],TP[p][iCol][1].cp,TP_LBL_COL[1][iCol]["nbcpd"]);
	}
	
	sTaille = sTaille + "<a href='#AT' onclick=PopupScroll('"+eval('UrlAssistantTaille'+p)+"','assistant',640,655); class=assistanttaille>"+MessageAssistantTaille+"</a>";
    document.getElementById('affichagedestailles'+p).innerHTML = sTaille
	if (eval('document.getElementById("mytaille'+p+'").value=="dc'+p+z+'"')) {addon="select";	 // selectionne la taille
	ST(p,'dc'+p+z,TP[p][iCol][z].v,TP[p][iCol][z].b,TP[p][iCol][z].r,'dc'+p+z,TP[p][iCol][z].ca,TP[p][iCol][z].cp,z,TP[p][iCol][z].t); }// met à jour prix, prix barré et remise	
	else{addon="";}// sinon, pas de +select		
}}

var sSClass ='dispo' ;	

function SelectColori(p,prix,barre,remise,reference,nbcoupleprixdiff)
{
var tab1 = prix.split("."); //separe le prix en 2 (euros/centimes)
var tab2 = barre.split("."); //separe le prix en 2 (euros/centimes)

 if(document.getElementById('prixeuro'+p))    document.getElementById('prixeuro'+p).innerHTML=tab1[0]; //affiche les euros
 if(document.getElementById('prixcents'+p))   
 {  
    if(tab1[1]) document.getElementById('prixcents'+p).innerHTML=tab1[1]; //affiche les centimes
 }
 
 if(document.getElementById('prixbarreeuro'+p) && tab2[0] != 0) 
{ 
document.getElementById('prixbarreeuro'+p).innerHTML=tab2[0]; //affiche le prix barré euros
document.getElementById('prixbarreFP'+p).style.display = 'block';
document.getElementById('DivInfoPrix'+p).className = 'prixFPAvecBarre';
}
else
{
if(document.getElementById('prixbarreFP'+p))document.getElementById('prixbarreFP'+p).style.display = 'none';
document.getElementById('DivInfoPrix'+p).className = 'prixFPSansBarre';
}
 if(document.getElementById('prixbarrecents'+p))   
 {
    if(tab2[1]) document.getElementById('prixbarrecents'+p).innerHTML=tab2[1]; //affiche le prix barré centimes
 } 

 if(nbcoupleprixdiff > 1) {
 if(document.getElementById('MsgDepuis'+p)) document.getElementById('MsgDepuis'+p).style.display = 'block';
 }
 else
 {

 if(document.getElementById('MsgDepuis'+p)) document.getElementById('MsgDepuis'+p).style.display = 'none';
 }
 
if(document.getElementById('remise'+p) && remise != 0) 
{
  document.getElementById('remise'+p).innerHTML=remise; //affiche la remise
  document.getElementById('DivPorcentageRemise'+p).style.display = 'block';
}
else
{
  document.getElementById('DivPorcentageRemise'+p).style.display = 'none';
}

if(document.getElementById('Divprixasterisque'+p)) document.getElementById('Divprixasterisque'+p).style.display = 'block';

if(document.getElementById('sticker_remise'))
if(remise != 0)
{
	if (document.getElementById('ImageOnglet_'+reference))
	{
		document.getElementById('ImageOnglet_'+reference).style.display='block';
		if(bSoldes == 'true')SetStickerSolde(reference,remise);
	}
document.getElementById('remise_'+reference).style.display="block";
document.getElementById('sticker_remise').innerHTML="-"+remise+"%"; 
}
else{
	if (document.getElementById('ImageOnglet_'+reference))
	{
		document.getElementById('ImageOnglet_'+reference).style.display='none';
	}
document.getElementById('sticker_remise').innerHTML="";
document.getElementById('remise_'+reference).style.display="none";
}

}

function ST(p,oDivS,prix,barre,remise,numId,CodeVente,Reference,z,taille) { 
    // Des qu une taille est selectionne on supprime le message - depuis - si il existe
    if(document.getElementById('MsgDepuis'+p)) document.getElementById('MsgDepuis'+p).style.display = 'none';
    // pour les deselectionner la taille selectionne pour un autre coloris
 /*   if(sObjTailleIdPrecedent != '')
	    {
		if (taille.length>=6){
		document.getElementById(sObjTailleIdPrecedent).className = 'dispoOff2';
		}
		else
		{
	        document.getElementById(sObjTailleIdPrecedent).className = 'dispoOff';
	    } 
	}*/
    sTaillePrecedent = taille;
    document.getElementById('mytaille'+p).value=numId;	//stocke l'ID couleur
	var tab1 = prix.split("."); //separe le prix en 2 (euros/centimes)
	var tab2 = barre.split("."); //separe le prix en 2 (euros/centimes)
    eval("TailleEnCours"+p+" = '"+z+"';")
    if(document.getElementById(numId))document.getElementById(numId).className = 'dispoOn'; 
	 if(document.getElementById('prixeuro'+p))    document.getElementById('prixeuro'+p).innerHTML=tab1[0]; //affiche les euros
	 if(document.getElementById('prixcents'+p))   
	 {  
	    if(tab1[1]) document.getElementById('prixcents'+p).innerHTML=tab1[1]; //affiche les centimes
	 }
	 if(document.getElementById('prixbarreeuro'+p) && tab2[0] != 0)  
	 {
		document.getElementById('prixbarreeuro'+p).innerHTML=tab2[0]; //affiche le prix barré euros 
		if(document.getElementById('prixbarreFP'+p)) document.getElementById('prixbarreFP'+p).style.display = 'block';
		if(document.getElementById('DivInfoPrix'+p)) document.getElementById('DivInfoPrix'+p).className = 'prixFPAvecBarre';
	 }
	 else
	 {
		if(document.getElementById('prixbarreFP'+p)) document.getElementById('prixbarreFP'+p).style.display = 'none';
		if(document.getElementById('DivInfoPrix'+p)) document.getElementById('DivInfoPrix'+p).className = 'prixFPSansBarre';
	 }

	 if(document.getElementById('Divprixasterisque'+p)) document.getElementById('Divprixasterisque'+p).style.display = 'none';
	 
	 if(document.getElementById('prixbarrecents'+p))   
	 {
	    if(tab2[1]) document.getElementById('prixbarrecents'+p).innerHTML=tab2[1]; //affiche le prix barré centimes
	 } 
	if(document.getElementById('remise'+p) && remise != 0)
	{
		document.getElementById('remise'+p).innerHTML=remise; //affiche la remise
		if(document.getElementById('DivPorcentageRemise'+p)) document.getElementById('DivPorcentageRemise'+p).style.display = 'block';
	}
	else
	{
		if(document.getElementById('DivPorcentageRemise'+p)) document.getElementById('DivPorcentageRemise'+p).style.display = 'none';
	}
	
	if(document.getElementById('sticker_remise'))   
	if(remise != 0)
	{
	if (document.getElementById('ImageOnglet_'+Reference))
	{
		document.getElementById('ImageOnglet_'+Reference).style.display='block';
		if(bSoldes == 'true')SetStickerSolde(Reference,remise);
	}
	document.getElementById('remise_'+Reference).style.display="block";
	document.getElementById('sticker_remise').innerHTML="-"+remise+"%"; 
	}
	else
	{
		if (document.getElementById('ImageOnglet_'+Reference))
	{
		document.getElementById('ImageOnglet_'+Reference).style.display='none';
	}
	document.getElementById('sticker_remise').innerHTML="";
	document.getElementById('remise_'+Reference).style.display="none";
	}
	
	oDiv=document.getElementById('dc'+p+'0');
	for (i=1; oDiv; i++) { //checke tous les id=dc1...	
	if (taille.length>=6){
		if (oDiv.className=='dispo2'){oDiv.className='dispo2';}	//met à jour tous les styles
		if (oDiv.className=='pasdispo2'){oDiv.className='pasdispo2';} //met à jour tous les styles
		if (oDiv.className=='disposelect2'){oDiv.className='dispo2';}//met à jour tous les styles
		if (oDiv.className=='pasdisposelect2'){oDiv.className='pasdispo2';}//met à jour tous les styles
	}
	else
	{
	if (oDiv.className=='dispo'){oDiv.className='dispo';}	//met à jour tous les styles
	if (oDiv.className=='pasdispo'){oDiv.className='pasdispo';} //met à jour tous les styles
	if (oDiv.className=='disposelect'){oDiv.className='dispo';}//met à jour tous les styles
	if (oDiv.className=='pasdisposelect'){oDiv.className='pasdispo';}//met à jour tous les styles
	}
		
	oDiv=document.getElementById('dc'+ p + i);/*incrémente la boucle*/}
 
 if (taille.length>=6){
	sSClass='disposelect2'; 
 }
 else
 {
 sSClass='disposelect'; // highlighte la taille sélectionnée
 }
 
 oDivS.className=sSClass; /*déshighlighte les autres tailles*/
 TB_Panier[p]['CV'] = CodeVente;
 TB_Panier[p]['REF'] = Reference;
 TB_Panier[p]['IdObjTaille'] = numId;
 TB_Panier[p]['TailleLibelle'] = taille;
 showbouton(p); /*permet de cliquer sur ajouter au panier*/}
 function showbouton (p){  document.getElementById("oksubmit"+p).style.display="block"; //affiche bouton ajoutpanier
 document.getElementById("nosubmit"+p).style.display="none"; }
 function hidebouton (p){  
 document.getElementById("oksubmit"+p).style.display="none"; //affiche pas bouton ajoutpanier
 document.getElementById("nosubmit"+p).style.display="block"; }
 function btClickContinueShopping(p)
 {
     document.getElementById("cachepage").style.display="none";
     document.getElementById("confirm"+p).style.display="none";
	 $(".modachatexpress").remove();
	 $("#cachepage").hide();
 } 
 
 function btClickContinueShoppingRuptureStock(p)
 {
     document.getElementById("cachepage").style.display="none";
     document.getElementById("confirmRuptureStock"+p).style.display="none";
 } 
 
 function btClickContinueShoppingErreur(p)
 {
     document.getElementById("cachepage").style.display="none";
     document.getElementById("confirmErreur"+p).style.display="none";
 } 
 
function SetStickerSolde(Reference,Remise)
{

var RemiseCalculee
Remise = Math.floor(((Remise))/5.0);
RemiseCalculee = Remise * 5;

if(RemiseCalculee && document.getElementById("ImageOnglet_"+Reference))
document.getElementById("ImageOnglet_"+Reference).src = '/images/020-RAYONS/onglet_Soldes_'+RemiseCalculee + '.gif';
else if (document.getElementById("ImageOnglet_"+Reference))
document.getElementById("ImageOnglet_"+Reference).src = '/images/1ptrans.gif';

}
 
var http_request = false;
var Get_http_response;
var bAjoutPanier = false;
var NumProduitAjout = 0;
var sCodeVente = '';
 function miseaupanier(p,org) { //affichage layer ajout au panier + articles complémentaires
 {
 	NumProduitAjout = p;
 	sCodeVente = '';
    //document.getElementById("cachepage").style.display="block";
	//document.getElementById("confirm"+p).style.display="block";
	//alert(document.getElementById("cachepage").style.zIndex);
	try
	{   var i = 1 

	    while(TB_Panier[i]['CV'])
	    {
		if(TB_Panier[i]['REF'] != '')
		{
			sSelectReference +=  TB_Panier[i]['REF'] + ','; 
		}
		if(TB_Panier[i]['CV'] != '')
		{
		    sCodeVente = TB_Panier[i]['CV'];
			sSelectCodeVente += TB_Panier[i]['CV'] + ',';  
		}
        TB_Panier[i]['REF'] = 'Vide';
        TB_Panier[i]['CV'] = 'Vide';
	        i++;}
	}catch(e){}

    var UrlAjoutPanier =  '/030-COMMANDE/50-10_misepanier_v2.asp?MyAction=AjouterPanier&Reference=' + sSelectReference + '&CV=' + sSelectCodeVente + '&OpeId=' + iOpeId + '&SilhouetteId=' + iSilhouetteId + "&origine="+org
  //  document.write(UrlAjoutPanier);
  //alert(UrlAjoutPanier);
    sSelectReference = '';
    sSelectCodeVente = '';
 
    //alert(UrlAjoutPanier);
    http_request = false;
    
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
        http_request.overrideMimeType('text/xml');
    }
    } else if (window.ActiveXObject) { // IE
        try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    
    if (!http_request) {
        alert("Cannot create an XMLHTTP instance");
       return false;
    }
    http_request.onreadystatechange = alertContents;
    http_request.open('get', UrlAjoutPanier, true);
    http_request.send(null);
    return true;
 }

function alertContents() {
    if (http_request.readyState == 4) {
		//alert(http_request.status);
        if (http_request.status == 200) {
             
             var TabReponse = http_request.responseText.split(';');
             var sResult =  TabReponse[0];
             var iNbArticleAjoute = TabReponse[1];
             var iNbArticleAjouteLot = TabReponse[2]; 
             var iOperationCompId = TabReponse[3]; 
             var iPanierId = TabReponse[4]; 

             if(iOperationCompId != "0" && iPanierId != "0")RqtAjaxTestOpeComp('/030-COMMANDE/MoteurOpe/Controller.aspx','Action=TEST_OPE_COMP_FP&OperationId='+iOperationCompId+'&PanierId='+iPanierId,'post');
             
             
			 if(sResult == '1')
			 {  
			     // Si on se trouve sur la borne, on est redirigé automatiquement sur le panier aprés ajout
			     try {
			         if(window.parent.document.getElementById('BodyBorne'))
			         {
			          window.location = "/030-COMMANDE/10-10_panier.asp";
			          return false;
			         } }
			            catch(e){}
			           
			     
		         document.getElementById("cachepage").style.display="block";
		         if(NombreProduitLotTotal > 0)
		         {
		            if (iNbArticleAjouteLot >= NombreProduitLotTotal)
		            { 
		                document.getElementById("MessageLot"+NumProduitAjout).innerHTML = MessageLot2;
		            }
		            else
		            {
		                document.getElementById("MessageLot"+NumProduitAjout).innerHTML = MessageLot1.replace('{1}',NombreProduitLotTotal-iNbArticleAjouteLot)
		            }
		            document.getElementById("confirm"+NumProduitAjout).style.display="block";
		         }
		         else
		         {
				    //document.getElementById("confirm"+NumProduitAjout).style.display="block";				 
					$("#confirm1").appendTo("body");
					$('.modachatexpress').fadeOut("fast");
					//Calcul pour le centre
					var top = $(window).scrollTop()+($(window).height()/2)-($("#confirm1").height()/2);
					var left = ($(window).width()/2)-($("#confirm1").width()/2)-500;
					$("#confirm1").css({
			    		top : top+"px",
				    	left : left+"px"
	    			});
				
					$("#confirm1").css({
			    		top : top+"px",
				    	left : left+"px"
	    			});
					document.getElementById("confirm1").style.display="block";
                 }
                 EcrireCookie('NombreArticlesPanier',iNbArticleAjoute);
			     maj_Panier();
			     
			    try
	            {   var i = 1 
	                while(TB_Panier[i]['IdObjTaille'])
	                {
	                    if(TB_Panier[i]['IdObjTaille'] != '')
	                    {
						var rtaille=TB_Panier[i]['TailleLibelle'];
						   	if  (rtaille.length >=6)
							{
							//alerte(TB_Panier[p]['TailleLibelle'].length)
                            if(document.getElementById(TB_Panier[i]['IdObjTaille'])) document.getElementById(TB_Panier[i]['IdObjTaille']).className = 'dispo';
                            hidebouton(i);
                            TB_Panier[i]['IdObjTaille'] = 'Vide';
							}
							else
							{
							if(document.getElementById(TB_Panier[i]['IdObjTaille'])) document.getElementById(TB_Panier[i]['IdObjTaille']).className = 'dispo';
							hidebouton(i);
                            TB_Panier[i]['IdObjTaille'] = 'Vide';
							}
							
                        }
	                    i++;}
	            }catch(e){}
             }
             else
             {
                //alert('Le produit n es pas ajoute');
				document.getElementById("cachepage").style.display="block";
				document.getElementById("confirmRuptureStock"+NumProduitAjout).style.display="block";
             }
        } else {
            // alert('Erreur');
			document.getElementById("cachepage").style.display="block";
			document.getElementById("confirmErreur"+NumProduitAjout).style.display="block";
        }
    }
}
}


function RqtAjaxTestOpeComp(sUrl,sParamUrl,sHttpType)
{
    if(sHttpType.toLowerCase() == 'get')
    {
        sUrl += "?" + sParamUrl;
        sParamUrl = null;
    }
    http_request = false;
    
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
        http_request.overrideMimeType('text/xml');
    }
    } else if (window.ActiveXObject) { // IE
        try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    
    if (!http_request) {
        alert("Cannot create an XMLHTTP instance");
       return false;
    }
    http_request.onreadystatechange = alertContentsOpeComp;
    http_request.open(sHttpType, sUrl, true);
    http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    http_request.send(sParamUrl);
    return true;
}

function alertContentsOpeComp()
{
    if (http_request.readyState == 4) {
		
        if (http_request.status == 200) {
    
           var Xml_http_response = http_request.responseXML;
           if(Xml_http_response.getElementsByTagName("Action")[0].getAttribute("type") == "TestOpeComp")
           {
                if(Xml_http_response.getElementsByTagName("Action")[0].getAttribute("value") != 'true')
                {
                    document.getElementById("modal").innerHTML = document.getElementById("modal").innerHTML.replace("{1}",Xml_http_response.getElementsByTagName("Action")[0].getAttribute("value"));
                    showmodal();
                    //setTimeout('killmodal()',3000);
                }
           }
             
        }
             
    }

}

/* Ajouté par KS, le 09/09*/

function whereIs(myNode)
{
 originalNode = myNode;
 x = 0;
 y = 0;
 while (myNode.tagName != 'BODY')
 {
  x += myNode.offsetLeft;
  y += myNode.offsetTop;
  myNode = myNode.offsetParent;
 }
 originalNode.magicPositionX = x;
 originalNode.magicPositionY = y;
}
function getLeft(l)
{
  if (l.offsetParent) return (l.offsetLeft + getLeft(l.offsetParent));
  else return (l.offsetLeft);
}
function getTop(l)
{
  if (l.offsetParent) return (l.offsetTop + getTop(l.offsetParent));
  else return (l.offsetTop);
}

function positionnementConfirm(p)
{
	var posPanierT = document.getElementById("blocpanierlot"+p).offsetTop;
	var posPanierL = document.getElementById("blocpanierlot"+p).offsetLeft;
	document.getElementById("confirm"+p).style.top = posPanierT;
	document.getElementById("confirm"+p).style.left = posPanierL;
	document.getElementById("confirmRuptureStock"+p).style.top = posPanierT;
	document.getElementById("confirmRuptureStock"+p).style.left = posPanierL;
}
var oOldObjImage = false;
function VgComplementaireClick(f_oObjImage,f_sReference,f_iNumeroColoris,f_iNumeroVue,f_iNumProduit,f_sTypeImage)
{
    if(!oOldObjImage)oOldObjImage = document.getElementById("ImgVc_"+eval("ColoriImageEnCours1")+"_1");
    if(oOldObjImage)oOldObjImage.className = 'VG';
    oOldObjImage = f_oObjImage;
    f_oObjImage.className = 'VGon';
    eval("ColoriImageEnCours" + f_iNumProduit + " = '"+f_iNumeroColoris+"';");
    VueEnCours = f_iNumeroVue;
	document.getElementById("imageduproduit_"+f_iNumProduit).style.visibility = "hidden";
	var monImage = new Image;
	   monImage.onload = function()
	{
	   if (f_sTypeImage == "fr")
		{
			document.getElementById("imageduproduit_"+f_iNumProduit).className = "FP_R";
			document.getElementById("imageduproduit_"+f_iNumProduit).style.marginTop = 0; 
			document.getElementById("imageduproduit_"+f_iNumProduit).style.marginBottom = 0; 
		}else{
			if(document.getElementById("imageduproduit_"+f_iNumProduit).className == "FP_R")
				document.getElementById("imageduproduit_"+f_iNumProduit).style.marginTop = 55; 
			//document.getElementById("imageduproduit_"+f_iNumProduit).style.paddingBottom = 56; 
			document.getElementById("imageduproduit_"+f_iNumProduit).className = "FP";
		}
	   document.getElementById("imageduproduit_"+f_iNumProduit).src = GetUrlImage(f_iNumeroVue,f_iNumeroColoris,f_sTypeImage,f_sReference,"jpg");
	}
	   monImage.src = GetUrlImage(f_iNumeroVue,f_iNumeroColoris,f_sTypeImage,f_sReference,"jpg");
    
	document.getElementById("imageduproduit_"+f_iNumProduit).style.visibility = "visible";
	
    sUrlImgInitZoom = GetUrlImage(f_iNumeroVue,f_iNumeroColoris,f_sTypeImage,f_sReference,"jpg");
    if(TP_LBL_COL[1][f_iNumeroColoris]['lc'] != '')
    {
        document.getElementById("txtCouleur_"+f_iNumProduit).innerHTML = "- "+TP_LBL_COL[1][f_iNumeroColoris]['lc']+" -";
    }
    else
    {
        document.getElementById("txtCouleur_"+f_iNumProduit).innerHTML = "";
    }
    SetZoomHD(f_iNumProduit,f_iNumeroColoris,f_iNumeroVue,f_sReference);

}

function CPC(f_sReference,f_iNumProduit,f_iNumeroColoris,f_sTypeImage,f_iNumVue)
{
//le colori demande en cours n est pas forcement le colori affiche 
var ColoriDemande = f_iNumeroColoris;
var bImgIndispo = false;

if(!TP_IMG[f_iNumProduit][f_iNumeroColoris][f_sTypeImage])
{
    try
    {
        if(TP_IMG[f_iNumProduit]['g'][f_sTypeImage])
        {
            f_iNumeroColoris = 'g';
        }
    }
    catch(e){bImgIndispo = true;}
}

document.getElementById("Img_"+f_iNumProduit+"_"+eval('ColorisEnCours'+f_iNumProduit)).className = "couleurdroite_off";
document.getElementById("Img_"+f_iNumProduit+"_"+ColoriDemande).className = "couleurdroite_on";
eval("ColorisEnCours"+f_iNumProduit+" = '"+ColoriDemande+"';");
eval("ColoriImageEnCours"+f_iNumProduit+" = '"+f_iNumeroColoris+"';");

if(!bImgIndispo)
{
    sUrlImgInitZoom = GetUrlImage(f_iNumVue,f_iNumeroColoris,f_sTypeImage,f_sReference,"jpg");
	if(document.getElementById("imageduproduit_"+f_iNumProduit).className == "FP" || document.getElementById("imageduproduit_"+f_iNumProduit).className == "FP_R"){
	var monImage = new Image;
	document.getElementById("imageduproduit_"+f_iNumProduit).style.visibility = "hidden";
	   monImage.onload = function(){
		if(f_sTypeImage == "fr" )
				{
					document.getElementById("imageduproduit_"+f_iNumProduit).style.marginTop = 0; 
					document.getElementById("imageduproduit_"+f_iNumProduit).style.marginBottom = 0; 
					document.getElementById("imageduproduit_"+f_iNumProduit).src = GetUrlImage(f_iNumVue,f_iNumeroColoris,f_sTypeImage,f_sReference,"jpg");
					document.getElementById("imageduproduit_"+f_iNumProduit).className = "FP_R";
				}else{
					if (document.getElementById("imageduproduit_"+f_iNumProduit).className == "FP_R")
					{
						document.getElementById("imageduproduit_"+f_iNumProduit).style.marginTop = 55; 
						document.getElementById("imageduproduit_"+f_iNumProduit).style.marginBottom = 56; 
					}
					document.getElementById("imageduproduit_"+f_iNumProduit).src = GetUrlImage(f_iNumVue,f_iNumeroColoris,f_sTypeImage,f_sReference,"jpg");
					document.getElementById("imageduproduit_"+f_iNumProduit).className = "FP";
				}
			document.getElementById("imageduproduit_"+f_iNumProduit).style.visibility = "visible";
	   }
	   monImage.src = GetUrlImage(f_iNumVue,f_iNumeroColoris,f_sTypeImage,f_sReference,"jpg");
		
	}else{
		document.getElementById("imageduproduit_"+f_iNumProduit).src = GetUrlImage(f_iNumVue,f_iNumeroColoris,f_sTypeImage,f_sReference,"jpg");
		document.getElementById("imageduproduit_"+f_iNumProduit).style.display = 'block';
	}
    document.getElementById("divimageindispo_"+f_iNumProduit).style.display = 'none';
    document.getElementById("imageduproduit_"+f_iNumProduit).style.display = 'block';
}
else
{   
    //if(iOpeId == 0 && iSilhouetteId ==0)
   // {
	    //document.getElementById("imageduproduit_"+f_iNumProduit).src = '/images/020-RAYONS/Image_FP_Indispo.gif';
		if(f_sTypeImage == "fr" )
				document.getElementById("divimageindispo_"+f_iNumProduit).style.marginTop = 55; 
	    document.getElementById("imageduproduit_"+f_iNumProduit).style.display = 'none';
	    document.getElementById("divimageindispo_"+f_iNumProduit).style.display = 'block';
	    document.getElementById("divimageindispo_"+f_iNumProduit).innerHTML = '<table height="100%" width="100%"><tr valign="middle" align="center"><td>'+sMsgImgColoriIndidpo+' <br/>' + TP_LBL_COL[f_iNumProduit][f_iNumeroColoris]['lc']+'</td></tr></table>';//<div style="color:red;color:red;float:left;margin-bottom:0pt;margin-left:-50px;margin-top:150px;position:absolute;vertical-align:middle;">Cet article existe aussi en <br/>' + TP_LBL_COL[f_iNumProduit][f_iNumeroColoris]['lc']+'</div>';
	//}
	//else
	//{
	    //document.getElementById("imageduproduit_"+f_iNumProduit).src = '/images/020-RAYONS/Image_FPM_Indispo.gif';	
	//}
}

//SetZoomHD(f_iNumProduit,f_iNumeroColoris,f_iNumVue,f_sReference);

if(TP_LBL_COL[f_iNumProduit][f_iNumeroColoris]['lc'] != '')
{
   if(document.getElementById("txtCouleur_"+f_iNumProduit))document.getElementById("txtCouleur_"+f_iNumProduit).innerHTML = "- "+TP_LBL_COL[f_iNumProduit][f_iNumeroColoris]['lc']+" -";
   if(document.getElementById("txtCouleurM_"+f_iNumProduit))document.getElementById("txtCouleurM_"+f_iNumProduit).innerHTML = "- "+TP_LBL_COL[f_iNumProduit][f_iNumeroColoris]['lc']+" -";
}
else
{
    if(document.getElementById("txtCouleur_"+f_iNumProduit))document.getElementById("txtCouleur_"+f_iNumProduit).innerHTML = "";
    if(document.getElementById("txtCouleurM_"+f_iNumProduit))document.getElementById("txtCouleurM_"+f_iNumProduit).innerHTML = "";
}
    
}

function AutresVuesClick(f_oObjImage,f_iNumProduit,f_sReference,f_sTypeImage)
{
    if(!oOldObjImage)oOldObjImage = document.getElementById("ImgVc_"+eval("ColoriImageEnCours1")+"_1");
    var bBouble = true;
    for(var i=0;i < TabListNumeroColoris.length;i++)
    {   
		try
		{
			if(TP_IMG[f_iNumProduit][TabListNumeroColoris[i]][f_sTypeImage])
			{
            var ListVue = TP_IMG[f_iNumProduit][TabListNumeroColoris[i]][f_sTypeImage].split(';');
            
				if(ListVue.length > 1)
				{

                for(var j=0;j<ListVue.length;j++)
					{
                    //alert('('+TabListNumeroColoris[i] +' != ColoriEnCours:'+ eval('ColoriImageEnCours' + f_iNumProduit) +' || vueencours:'+ eval('VueEnCours'+f_iNumProduit) +' != '+ ListVue[j] +' && bBoucle:'+ bBouble  +' ) && '+ i +' != '+ TabListNumeroColoris.length + ' && (' + j + ' >= IndexEnCours:' + eval('IndexEnCours'+f_iNumProduit) + ' || ' + TabListNumeroColoris[i] + ' != ' + eval('ColoriImageEnCours' + f_iNumProduit)+')');
					
	                    if(((TabListNumeroColoris[i] != eval('ColoriImageEnCours' + f_iNumProduit) || eval('VueEnCours'+f_iNumProduit) != ListVue[j]) && bBouble) && i != TabListNumeroColoris.length && (j >= eval('IndexEnCours'+f_iNumProduit) || TabListNumeroColoris[i] != eval('ColoriImageEnCours' + f_iNumProduit)))
						{
	                       // if(TP_IMG[f_iNumProduit][TabListNumeroColoris[i]]['fp'])
	                       // {
	                       //     if(TP_IMG[f_iNumProduit][TabListNumeroColoris[i]]['fp'].indexOf(ListVue[j]) > 0)
	                       //     {
	                                bBouble = false;
	                                eval("IndexEnCours"+f_iNumProduit+" = "+j+";");
	                                eval("VueEnCours"+f_iNumProduit+" = "+ ListVue[j]+";");
	                                eval("ColoriImageEnCours" + f_iNumProduit + " = '" + TabListNumeroColoris[i]+"';");
	                                if(oOldObjImage)oOldObjImage.className = 'VG';
	                                oOldObjImage = document.getElementById("ImgVc_"+TabListNumeroColoris[i]+"_"+ListVue[j]);
	                                if(document.getElementById("ImgVc_"+TabListNumeroColoris[i]+"_"+ListVue[j]))document.getElementById("ImgVc_"+TabListNumeroColoris[i]+"_"+ListVue[j]).className = 'VGon';
	                                document.getElementById("imageduproduit_"+f_iNumProduit).src = GetUrlImage(eval('VueEnCours'+f_iNumProduit),eval('ColoriImageEnCours' + f_iNumProduit),f_sTypeImage,f_sReference,"jpg");
	                                sUrlImgInitZoom = GetUrlImage(eval('VueEnCours'+f_iNumProduit),eval('ColoriImageEnCours' + f_iNumProduit),f_sTypeImage,f_sReference,"jpg");
	                                SetZoomHD(f_iNumProduit,TabListNumeroColoris[i],ListVue[j],f_sReference);
									
	                                
	                           // }
	                       // }
						}
					}
				}
			}
		}
		catch(e)
		{
			//alert(e);
		}
    }
    if(bBouble)
    {    
           eval("ColoriImageEnCours" + f_iNumProduit+" = '"+TabListNumeroColoris[0]+"';");
           eval('VueEnCours'+f_iNumProduit+' = 1;');
           eval('IndexEnCours'+f_iNumProduit+' = 0');
           if(oOldObjImage)oOldObjImage.className = 'VG';
           oOldObjImage = document.getElementById("ImgVc_"+TabListNumeroColoris[0]+"_1");
           if(document.getElementById("ImgVc_"+TabListNumeroColoris[0]+"_1"))document.getElementById("ImgVc_"+TabListNumeroColoris[0]+"_1").className = 'VGon';
           document.getElementById("imageduproduit_"+f_iNumProduit).src = GetUrlImage(eval('VueEnCours'+f_iNumProduit),eval('ColoriImageEnCours' + f_iNumProduit),f_sTypeImage,f_sReference,"jpg");
           SetZoomHD(f_iNumProduit,TabListNumeroColoris[0],1,f_sReference);
    }  
}

function SetZoomHD(f_iNumProduit,f_iNumeroColoris,f_iNumeroVue,f_sReference)
{
    if ((TP_IMG[f_iNumProduit][f_iNumeroColoris]['zc'] && f_iNumeroVue > 0) || (TP_IMG[f_iNumProduit][f_iNumeroColoris]['zcm'] && f_iNumeroVue == 0))
    {
	
      /*  document.getElementById("imageduproduit_"+f_iNumProduit).onclick = function() 
        {
            PopEx('imageduproduit_'+f_iNumProduit,'0A','0A',0,null,80,'PopBoxImageLarge');
        }*/
	    sUrlImgZomHD = GetUrlImage(f_iNumeroVue,f_iNumeroColoris,'zc',f_sReference,"jpg");
	    document.getElementById("imageduproduit_"+f_iNumProduit).pbsrc = sUrlImgZomHD;
	    document.getElementById("imageduproduit_"+f_iNumProduit).setAttribute('pbsrc',sUrlImgZomHD);
	    InitPbSrc();
	    if(document.getElementById("PictoZoom"+f_iNumProduit))document.getElementById("PictoZoom"+f_iNumProduit).style.display = "block";
	    if(document.getElementById("pictozoomM"+f_iNumProduit))document.getElementById("pictozoomM"+f_iNumProduit).style.display = "block";
		document.getElementById("imageduproduit_"+f_iNumProduit).style.cursor = "pointer";
    }
    else
    {
		document.getElementById("imageduproduit_"+f_iNumProduit).style.cursor = "default";
        document.getElementById("imageduproduit_"+f_iNumProduit).onclick = '';
		document.getElementById("imageduproduit_"+f_iNumProduit).setAttribute('onclick','');
        if(document.getElementById("PictoZoom"+f_iNumProduit))document.getElementById("PictoZoom"+f_iNumProduit).style.display = "none";
        if(document.getElementById("pictozoomM"+f_iNumProduit))document.getElementById("pictozoomM"+f_iNumProduit).style.display = "none";
		
    }
}

//  {1} Numero Vue
//  {2} Numero Coloris
//  {3} Type Image
//  {4} Reference
//  {5} 2 premiers cractére référence
//  {6} Extension

var sMatriceUrlImage = '/Shared/Images/Produits_NF_V2/{3}{1}/{5}/{2}/{4}_{2}_{3}{1}.{6}';
function GetUrlImage(f_NumVue,f_NumColoris,f_TypeImage,f_Reference,f_Extension)
{
var sUrlImage = sMatriceUrlImage;
//Le probleme du replace Javascript, c'est qu'il ne remplace qu'une seule occurence dans le string, d'ou les répétitions

if(f_NumVue == 0 && (f_TypeImage == 'vc' || f_TypeImage=='fc' || f_TypeImage=='zc' || f_TypeImage == 'vr' || f_TypeImage=='fr' || f_TypeImage=='zr' )) 
{
f_NumVue = '';
f_TypeImage = f_TypeImage + 'm';
}

sUrlImage = sUrlImage.replace('{1}',f_NumVue)
sUrlImage = sUrlImage.replace('{1}',f_NumVue)

sUrlImage = sUrlImage.replace('{2}',f_NumColoris)
sUrlImage = sUrlImage.replace('{2}',f_NumColoris)

sUrlImage = sUrlImage.replace('{3}',f_TypeImage)
sUrlImage = sUrlImage.replace('{3}',f_TypeImage)

sUrlImage = sUrlImage.replace('{4}',f_Reference)
sUrlImage = sUrlImage.replace('{5}',f_Reference.substring(0,2))
sUrlImage = sUrlImage.replace('{6}',f_Extension)

return sUrlImage;
}

/*
function VgColoriLotClick(f_sReference,f_iNumProduit,f_iNumeroColoris)
{
var bChangementImg = true;
if(!TP_IMG[f_iNumProduit][f_iNumeroColoris]['l'])
{
    if(TP_IMG[f_iNumProduit]['g']['l'])
    {
        f_iNumeroColoris = 'g';
    }
    else
    {
        bChangementImg = false;
    }
}
    if(bChangementImg)
    {
        eval('ColoriImageEnCours' + f_iNumProduit+' = '+f_iNumeroColoris+';');
        document.getElementById("imageduproduit_"+f_iNumProduit).src = GetUrlImage("1",f_iNumeroColoris,"fp",f_sReference,"jpg");
    }
}
*/

var sReference = '';
var iNumProduit = 0;
function InitZoom(f_sReference,f_iNumProduit)
{
sReference = f_sReference;
iNumProduit = f_iNumProduit;
}

function func_OnMouseOver(f_iNumProduit,f_iNumeroColoris)
{
    if(f_iNumeroColoris != eval('ColorisEnCours'+f_iNumProduit))
    {
        document.getElementById('Img_'+f_iNumProduit+'_'+f_iNumeroColoris).className = 'couleurdroite_over';
    }
}

function func_OnMouseOut(f_iNumProduit,f_iNumeroColoris)
{
    if(f_iNumeroColoris != eval('ColorisEnCours'+f_iNumProduit))
    {
        document.getElementById('Img_'+f_iNumProduit+'_'+f_iNumeroColoris).className = 'couleurdroite_off';
    }
}


function func_OnMouseOverTaille(f_iNumProduit,f_iNumeroTaille)
{
    if(f_iNumeroTaille != eval('TailleEnCours'+f_iNumProduit))
    {
        document.getElementById('dc'+f_iNumProduit+f_iNumeroTaille).className = 'dispoOver';
    }
}

function func_OnMouseOutTaille(f_iNumProduit,f_iNumeroTaille)
{
    if(f_iNumeroTaille != eval('TailleEnCours'+f_iNumProduit))
    {   
        document.getElementById('dc'+f_iNumProduit+f_iNumeroTaille).className = 'dispoOff';
    }   
}

function func_OnMouseOverTaille2(f_iNumProduit,f_iNumeroTaille)
{
    if(f_iNumeroTaille != eval('TailleEnCours'+f_iNumProduit))
    {
        document.getElementById('dc'+f_iNumProduit+f_iNumeroTaille).className = 'dispoOver2';
    }
}

function func_OnMouseOutTaille2(f_iNumProduit,f_iNumeroTaille)
{
    if(f_iNumeroTaille != eval('TailleEnCours'+f_iNumProduit))
    {   
        document.getElementById('dc'+f_iNumProduit+f_iNumeroTaille).className = 'dispoOff2';
    }   
}



function showmodal()
{
//on rend le bouton close actif
// $(".modal_close").click(killmodal);
//On calcul pour positionner la modal au milieu de la page
var top = $(window).scrollTop()+($(window).height()/2)-(120)-($(".modal").height()/2);
var left = ($(window).width()/2)-($(".modal").width()/2);
//alert ("hauteur"+top);
//alert ("largeur"+left);
//$(".modal").bgiframe();
$(".modal").css({
  top : top+"px",
  left : left+"px"
});

//On cree la black box, on l'insere dans le body, on fade, puis on fade la modale
$('<div class="black_box" style="filter: alpha(opacity=40);"></div>').css({zIndex:1002,width: $(window).width(), height: $(document).height()}).appendTo(document.body).fadeIn("slow",function(){$(".modal").fadeIn("slow");});
//$(".modal, black_box").bgiframe();
}

//Fermeture de la modal
function killmodal()
{
//Fondu de la black box puis de la modal et on detruit la black box
$('.modal').fadeOut("slow",function(){$(".black_box").fadeOut("slow",function(){$('.black_box').remove()})});
}	

/*function AutresVuesClickLot(f_iNumProduit,f_sReference)
{
    var bBouble = true;
    for(var i=0;i < TabListNumeroColoris.length;i++)
    {   
        if(TP_IMG[f_iNumProduit][TabListNumeroColoris[i]]['vg'])
        {
            var ListVue = TP_IMG[f_iNumProduit][TabListNumeroColoris[i]]['vg'].split(';');
            if(ListVue.length > 1)
            {
                for(var j=0;j<ListVue.length;j++)
                {
                    //alert(TabListNumeroColoris[i] +' | '+ eval('ColoriImageEnCours' + f_iNumProduit) +' | '+ VueEnCours +' | '+ ListVue[j] +' | '+ bBouble  +' | '+ i +' | '+ TabListNumeroColoris.length);
                    if((TabListNumeroColoris[i] != eval('ColoriImageEnCours' + f_iNumProduit) || VueEnCours != ListVue[j] && bBouble) && i != TabListNumeroColoris.length && j >= IndexEnCours)
                    {
                        bBouble = false;
                        IndexEnCours = j;
                        VueEnCours = ListVue[j];
                        eval('ColoriImageEnCours' + f_iNumProduit+' = '+TabListNumeroColoris[i]+';');
                        document.getElementById("ImgMiniFp_"+f_iNumProduit+"_"+f_sReference).src = GetUrlImage(VueEnCours,eval('ColoriImageEnCours' + f_iNumProduit),"fp",f_sReference,"jpg");
                    }
                }
            }
        }
    }
    if(bBouble)
    {    
           eval('ColoriImageEnCours' + f_iNumProduit+' = ' + TabListNumeroColoris[0]+';');
           VueEnCours = 1;
           IndexEnCours = 0;
           document.getElementById("ImgMiniFp_"+f_iNumProduit+"_"+f_sReference).src = GetUrlImage(VueEnCours,eval('ColoriImageEnCours' + f_iNumProduit),"fp",f_sReference,"jpg");
    }  
}*/