var a;
var enablepersist="off" 
var collapseprevious="yes" 
var sBaseUrlImage = "/shared/images/produits_NF_V2/"

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:block;display:none;margin-left:0px!important;margin-left:13px;width:160px;text-align:left;}')
document.write('</style>')
} 

function getElementbyClass(classname){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
ccollect[inc++]=alltags[i]
}}
function contractcontent(omit){ 
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit) 
ccollect[inc].style.display="none"
inc++ 
}}
function expandcontent(cid){
if(document.getElementById(cid).style.display == 'none' || document.getElementById(cid).style.display == '')
{
    document.getElementById(cid).style.display = 'block';
    document.getElementById('a'+cid).className = 'info actif';
}
else
{
    document.getElementById(cid).style.display = 'none';
    document.getElementById('a'+cid).className = 'info inactif';
}
} 
function expandcontentR(cid){
if(document.getElementById(cid).style.display == 'none' || document.getElementById(cid).style.display == '')
{
    document.getElementById(cid).style.display = 'block';
    document.getElementById('a'+cid).className = 'info actif_R';
}
else
{
    document.getElementById(cid).style.display = 'none';
    document.getElementById('a'+cid).className = 'info inactif_R';
}
}


function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
} 
function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}}
return returnvalue;
} 
function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
} 
function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
} 
document.cookie=window.location.pathname+"="+selectedItem
} 
function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
getElementbyClass("switchcontent")
if (enablepersist=="on" && typeof ccollect!="undefined"){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 
if (!firsttimeload)
revivecontent()
}} 
if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate


var req, image, warning, imagepath; 
function d(o){return document.getElementById(o);} 	
function loadimage(_imagepath,_imageid) {	
image = d(_imageid);	 
imagepath = _imagepath; 	
req = getreq();	
req.onreadystatechange = imagexists;	
req.open("get", imagepath, true);	
req.send(null);		} 

function imagexists() {	
	if(req.readyState == 4)	{		
			if(req.status == 200)		
			{			
			image.src = imagepath;	
			}	
	else		
			{		
		 	image.src = "PageListe_fichiers/1ptrans.gif";
		 	}	
		}
	} 
		
function getreq()
{	
	if(window.XMLHttpRequest)		
	return new XMLHttpRequest();	
	else if(window.ActiveXObject)		
	return new ActiveXObject("Microsoft.XMLHTTP");
}
function vuededos(affichage) {	
	if(document.getElementById(affichage+"_ID") != null){
		var aff_id = eval('document.getElementById("'+affichage+'_ID").value');	
		var sUrlimg = GetImgUrl(aff_id,"dos");
		if(sUrlimg != "false")
		{
			eval('loadimage(\''+ sUrlimg +'\',\''+affichage+'\')');
		}
	}
}	
function vuedeface(affichage) {
	if(document.getElementById(affichage+"_ID") != null) {
		var aff_id = eval('document.getElementById("'+affichage+'_ID").value');	
		if(aff_id!="AA000_0_00_0")
		{
			var sUrlImage = GetImgUrl(aff_id,"face");
			var ObjDivImgIndispo = document.getElementById('divimageindispo_'+affichage.replace('affichage',''));
			eval('document.getElementById("'+affichage+'").src="' + sUrlImage +'";');
			ObjDivImgIndispo.style.display = 'none';
		}
	}
}
function changevue(affichage,vue_id,nomColori,iProduitId,iRayonId,iNumColoris) {	
eval('document.getElementById("'+affichage+'_ID").value=eval("vue_id")');
var sUrlimg = GetImgUrl(vue_id,"face");
var numProd = affichage.replace('affichage','');
var ObjDivImgIndispo = document.getElementById('divimageindispo_'+numProd);
if(document.getElementById("ImgAchatExpress_"+iProduitId)){
document.getElementById("ImgAchatExpress_"+iProduitId).onclick  = function(){modAchatExpress(iProduitId,iRayonId,iNumColoris);}}
    if(sUrlimg == 'false')
    {
       eval('document.getElementById("'+affichage+'").style.display = "none";');
       ObjDivImgIndispo.innerHTML = '<table style="cursor: pointer" onclick="window.location=document.getElementById(\'a_LibelleProduit_'+numProd+'\').href" height="100%" width="100%"><tr valign="middle" align="center"><td>'+sMsgImgColoriIndidpo+' <br/> en '+nomColori + '</td></tr></table>';
       ObjDivImgIndispo.style.display = 'inline';
    }
    else
    {
       eval('document.getElementById("'+affichage+'").style.visibility = "hidden";');
	   var monImage = new Image;
	   monImage.onload = function()
	   {
		   changeStyle(vue_id,document.getElementById(affichage));
		   eval('document.getElementById("'+affichage+'").src="'+ sUrlimg +'";');
		   eval('document.getElementById("'+affichage+'").style.visibility = "visible";'); 
	   }
	   monImage.src = sUrlimg;
       eval('document.getElementById("'+affichage+'").style.visibility = "visible";');
	   eval('document.getElementById("'+affichage+'").style.display = "inline";');
       ObjDivImgIndispo.style.display = 'none';
    }
}	

function changeStyle(f_aff_id, element)
{
var TypeImage;
maReg = new RegExp('([0-9|a-z|A-Z\-]*)_([0-9|g\-]*)_([a-z\-]*)([0-9\-]*)_([0-9\-]*)');
maReg.exec(f_aff_id);
TypeImage = RegExp.$3;

if(TypeImage == "pr")
{
	element.style.height = "250px"; 
	element.style.marginTop = "0"; 
	element.style.marginBottom = "3px"; 
}
else
{
	if(element.height == "250" || element.style.height == "250px")
	{
		element.style.marginTop = "30px"; 
		element.style.marginBottom = "33px";  
		element.style.height = "190px";
	}
}
}

function changeprix(num_produit,pxr,pxa,nbcpd,sticker) {
		sticker=sticker.toLowerCase();
	if(sticker.indexOf("solde") != -1){
		remiseO=Math.floor((((pxr-pxa)/pxr)*100)/1.0);
		remise = Math.floor((((pxr-pxa)/pxr)*100)/5.0);
		remise=remise*5;
		if(remise>0){
			document.getElementById("sticker_"+num_produit).src = "/images/020-RAYONS/onglet_Soldes_"+remise+"b.gif";
			document.getElementById("sticker_"+num_produit).style.display  = "block";
			document.getElementById("sti_pro_"+num_produit).innerHTML="-"+remiseO+"%";
		}else{
			document.getElementById("sticker_"+num_produit).style.display = "none";
			document.getElementById("sti_pro_"+num_produit).innerHTML="";
		}
	}else {
		if(sticker.indexOf("promotion") != -1)
		{
					remise = Math.floor((((pxr-pxa)/pxr)*100)/1.0);
					remise=remise*1;
					if(remise>=1){
					document.getElementById("sti_pro_"+num_produit).innerHTML="-"+remise+"%";
					document.getElementById("sti_pro_"+num_produit).style.display = "block";
					}
					else{
					document.getElementById("sti_pro_"+num_produit).style.display = "none";
					}
		}
	}
	prixRef = new Array();
	prixRef[0] = pxr.substring(0,pxr.length-2);
	if (prixRef[0] == "") prixRef[0]=0;
	prixRef[1] = pxr.substring(pxr.length-2,pxr.length);
	prixAct = new Array();
	prixAct[0] = pxa.substring(0,pxa.length-2);
	if (prixAct[0] == "") prixAct[0]=0;
	prixAct[1] = pxa.substring(pxa.length-2,pxa.length);
	if(parseInt(pxr) <= parseInt(pxa))
	{
		document.getElementById("euro_"+num_produit).removeChild(document.getElementById("euro_"+num_produit).firstChild);
		document.getElementById("euro_"+num_produit).appendChild(document.createTextNode(prixAct[0]));
		document.getElementById("cents_"+num_produit).removeChild(document.getElementById("cents_"+num_produit).firstChild);
		document.getElementById("cents_"+num_produit).appendChild(document.createTextNode("€"+prixAct[1]+"")); 
		document.getElementById("prix_barre_"+num_produit).style.display = "none"; 
		document.getElementById("a_prix_"+num_produit).className = "prix";
	}
	else
	{
		document.getElementById("euro_"+num_produit).removeChild(document.getElementById("euro_"+num_produit).firstChild);
		document.getElementById("euro_"+num_produit).appendChild(document.createTextNode(prixAct[0]));
		document.getElementById("cents_"+num_produit).removeChild(document.getElementById("cents_"+num_produit).firstChild);
		document.getElementById("cents_"+num_produit).appendChild(document.createTextNode("€"+prixAct[1]+"*"));
		document.getElementById("euro_barre_"+num_produit).removeChild(document.getElementById("euro_barre_"+num_produit).firstChild);
		document.getElementById("euro_barre_"+num_produit).appendChild(document.createTextNode(prixRef[0]));
		document.getElementById("cents_barre_"+num_produit).removeChild(document.getElementById("cents_barre_"+num_produit).firstChild);
		document.getElementById("cents_barre_"+num_produit).appendChild(document.createTextNode("€"+prixRef[1]));
		document.getElementById("prix_barre_"+num_produit).style.display = "inline";
		document.getElementById("a_prix_"+num_produit).className = "prix_minore";
	}
}	

function divcouleur(divcouleur,nom,tailles) {	
if (nom && tailles) {

var ihauteurImage = document.getElementById("affichage"+divcouleur).height; 
eval('document.getElementById("div_couleurs'+divcouleur+'").style.background="white"');


eval('document.getElementById("div_couleurs'+divcouleur+'").innerHTML="'+nom+' : '+tailles+'"');	
	}
else
	{
eval('document.getElementById("div_couleurs'+divcouleur+'").style.background="none"');	
eval('document.getElementById("div_couleurs'+divcouleur+'").innerHTML=""');	
	}	
}
var Reference;
var NumColoris;
var TypeImage;
var NumVue;
var NumVueDos;
function GetImgUrl(f_aff_id,TypeVue)
{
var maReg = new RegExp('([0-9|a-z|A-Z\-]*)_([0-9|g\-]*)_([a-z\-]*)([0-9\-]*)_([0-9\-]*)');
maReg.exec(f_aff_id);
Reference = RegExp.$1;
NumColoris='';
NumColoris = RegExp.$2;
TypeImage = RegExp.$3;
NumVue=0;
NumVue = RegExp.$4;
NumVueDos=0;
NumVueDos = RegExp.$5;
maReg=null;
if(((NumVueDos == 0 || NumVueDos == "") && TypeVue=="dos") || (NumVue == 0 && NumColoris != 'g'))
{
   return "false";
}
else
{
    if (NumVue == 0) NumVue = '1';
    if(TypeVue=="face")
    {
        return sBaseUrlImage + TypeImage + NumVue+'/'+ Reference.substring(0,2) + '/'+ NumColoris +'/'+ Reference +'_'+ NumColoris +'_'+TypeImage+NumVue+'.jpg';
    }
    else
    {
        return sBaseUrlImage + TypeImage + NumVueDos+'/'+ Reference.substring(0,2) + '/'+ NumColoris +'/'+ Reference +'_'+ NumColoris +'_'+TypeImage+NumVueDos+'.jpg';
    }
}
}


function changeUrlProduit(f_iNumProduit)
{
    RewriteUrl(f_iNumProduit,'a_prix_minore_');
    RewriteUrl(f_iNumProduit,'a_prix_');
    RewriteUrl(f_iNumProduit,'a_ImgProduitPL_');
    RewriteUrl(f_iNumProduit,'a_LibelleProduit_');
}

function RewriteUrl(f_iNumProduit,f_sObjId)
{
    if(NumColoris != 'g')
    {
        var Obj;
        if(document.getElementById(f_sObjId+f_iNumProduit))
        {
            Obj  = document.getElementById(f_sObjId+f_iNumProduit);
            if(Obj.href.indexOf('/C') == -1)
            {
				if(Obj.href.indexOf('ProduitID') != -1)
				Obj.href = Obj.href + '/C/' + NumColoris;
				else
                Obj.href = Obj.href + '/C' + NumColoris;
            }
            else
            {
				if(Obj.href.indexOf('ProduitID') != -1){
                var maReg = new RegExp('.*.(/C/[0-9\-]*)');
                maReg.exec(Obj.href);
                var sUrlColori = new String(RegExp.$1);
				if(sUrlColori!="")
					Obj.href = Obj.href.replace(sUrlColori,'/C/'+NumColoris);
				else
					Obj.href = Obj.href+'/C/'+NumColoris;
				}else{
                var maReg = new RegExp('.*.(/C[0-9\-]*)');
                maReg.exec(Obj.href);
                var sUrlColori = new String(RegExp.$1);
				if(sUrlColori!="")
					Obj.href = Obj.href.replace(sUrlColori,'/C'+NumColoris);
				else
					Obj.href = Obj.href+'/C'+NumColoris;
				}
            }
        }
    }
}


