function flipflap(idafficher){
	var div1=document.getElementById("div1");
	var div2=document.getElementById("div2");
	var div3=document.getElementById("div3");
	var div4=document.getElementById("div4");
	var div5=document.getElementById("div5");
	var mondiv=document.getElementById(idafficher);
	
	if(div1.style.display=="block"){
		div1.style.display="none";		
	}
	if(div2.style.display=="block"){
		div2.style.display="none";		
	}
	if(div3.style.display=="block"){
		div3.style.display="none";		
	}
	if(div4.style.display=="block"){
		div4.style.display="none";		
	}
	if(div5.style.display=="block"){
		div5.style.display="none";		
	}
	mondiv.style.display="block";
}

function verif_identification(){
	if(document.identification.Email.value!='' && document.identification.Password.value!=''){
		if((document.identification.Email.value).indexOf(" ")!=-1){
			alert("Votre code contient un espace, merci de modifier la saisie");
			document.identification.Email.focus();
		}else{
			var email=document.identification.Email.value;
			var password=document.identification.Password.value;
			document.location.href='http://www.ultravantages.com/Login.aspx?email='+email+'&password='+password+'&goUrl=/';
			/*document.identification.submit();*/
		}
	 }
	if(document.identification.Email.value=='' ){alert("Merci de renseigner votre Code");}	
	if(document.identification.Password.value==''){alert("Merci de renseigner votre mot de passe");}	
}
function envoie_password(){
	if(document.getElementById('email_oublie').value!=''){
		 if(document.getElementById('email_oublie').value!=''){
			document.getElementById('optool').src='http://www.ultravantages.com/PwdOublie.aspx?email='+document.getElementById('email_oublie').value;
		}
	}else{
		 if(document.identification.Email.value!=''){
			document.getElementById('optool').src='http://www.ultravantages.com/PwdOublie.aspx?email='+identification.Email.value;
		}else{
			alert('Merci de renseigner votre email');
		}
	}
}
function fermerdiv(nomdiv){
	if(document.getElementById(nomdiv)){
		document.getElementById(nomdiv).style.display="none";
	}
}
function ouvrirdivpass(nomdiv){
	if(document.getElementById(nomdiv)){
		document.getElementById(nomdiv).style.display="block";
	}
}
function fermerdivpass(nomdiv){
	if(document.getElementById(nomdiv)){
		document.getElementById(nomdiv).style.display="none";
	}
}
function verif_contact(){
	var chainealerte="";
	
	if(document.forms["contact"].nom.value==""){
		chainealerte+="- Le champ nom est obligatoire\n";
	}
	if(document.forms["contact"].prenom.value==""){
		chainealerte+="- Le champ prenom est obligatoire\n";
	}
	if(document.forms["contact"].mail.value==""){
		chainealerte+="- Le champ mail est obligatoire\n";
	}
	
	if(chainealerte==""){		
		document.forms["contact"].submit();
	}else{
		alert(chainealerte);
	}
}

function format(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

function pourcentage_reduc_affcourt(prixvente,prixbarre){
	prixvente=parseFloat(prixvente.replace(/%A0/g, '')); //REMPLACE ESPACE PAR RIEN
	prixbarre=parseFloat(prixbarre.replace(/%A0/g, '')); //REMPLACE ESPACE PAR RIEN
	var dif="";
	var difPourcent="";
	if(prixvente<prixbarre){
		dif=prixbarre-prixvente;
		dif=Math.round(dif*100)/100;
		difPourcent= (dif * 100) / prixbarre;
		document.write("-"+format(difPourcent,0," ")+"&#37;");
   }else{
	   document.write("&nbsp;");
   }
}

function calcul_hauteur_div_affcourt(hauteur1,hauteur2){
	if(document.getElementById(hauteur2).clientHeight!=0){
		var hauteur= 0;
		hauteur = document.getElementById(hauteur2).clientHeight;
		if(hauteur >= 152){
			document.getElementById(hauteur1).style.height=document.getElementById(hauteur2).clientHeight+'px';
		}else{
			document.getElementById(hauteur1).style.height='152px';
		}
		
	}
}
function calcul_hauteur_div(div,cellule,nompage){
	if(document.getElementById(cellule).clientHeight!=0){
		var hauteur= 0;
		hauteur = document.getElementById(cellule).clientHeight;
		if(nompage=="panier"){
			document.getElementById(div).style.height=document.getElementById(cellule).clientHeight+'px';
		}
	}
}
function cacheDivAffpod(id){
	for( var i=1; i<=4; i++){
		if(document.getElementById('div_affprod'+i)){
			if(id==i){
				if(document.getElementById('div_affprod'+id)){
					document.getElementById('div_affprod'+id).style.display='block';
					document.getElementById('div_affprod'+id).style.visibility='visible';
					document.getElementById('nav_affprod'+id).className='nav_affprod1';
				}
			}else{
				if(document.getElementById('div_affprod'+id)){
					document.getElementById('div_affprod'+i).style.display='none';
					document.getElementById('div_affprod'+i).style.visibility='hidden';
					document.getElementById('nav_affprod'+i).className='nav_affprod2';					
				}
			}
		}
	}
}
function remplir_texte_legal(id){
	if(document.getElementById(id)){
		var idremplir=document.getElementById(id);
		idremplir.innerHTML="Ultravantages est une marque du groupe Initiatives & D&#233;veloppements<br/>Initiatives & D&#233;veloppements - BP 90437 - 69655 VILLEFRANCHE S/ SAONE CEDEX France<br/>SA au capital de 15 019 604.50 &euro; - Siret 444 247 936 00057 - RCS Nanterre <br/>TVA intracommunautaire FR 01 444 247 936 - APE 526 A<br/>";
	}
}
function testsearch(value){
document.location.href='/23/recherche.htm?keywords='+value;
}
function filtre_omikron(montype){
	valeur=document.getElementById(montype).options[document.getElementById(montype).selectedIndex].value;
	document.location.href=valeur;
}
function getPageSize(){
	var xScroll, yScroll;
		
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}
function ajoute_panier(id_produit, id_secteur, id_famille, nom, ref)
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
						
						document.getElementById('panierdetail').style.top = lightboxTop+'px';
						document.getElementById('panierdetail').style.marginLeft = (((arrayPageSize[0])/2)-250)+'px';
	if (window.XMLHttpRequest)   
	{ 
		xhr = new XMLHttpRequest();   
	} 
	else 
	if (window.ActiveXObject)              
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");  
   }
   xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200){
                 //window.alert('Le panier a ete modifie');
				 
					if(document.getElementById('panierdetail')){
						
						document.getElementById('panierdetailData').innerHTML ="<span class='textepanier_lightbox'>Le produit suivant a &#233;t&#233; ajout&#233; &#224; votre panier:</span><br /><span class='produitpanier_lightbox'>"+nom+"</span><br/><a href='#' onclick='document.location.href=document.location.href;'><img src='/img/ultravantages/template/btn_continuerlightbox.jpg' border='0' /></a><a href='#' onclick='document.location.href=\"/"+id_secteur+"/panierVisu.htm\";'><img src='/img/ultravantages/template/btn_terminerlightbox.jpg' border='0' /></a><br/><a href='#' onclick='document.location.href=document.location.href;'><img src='/img/ultravantages/template/btn_fermerlightbox.jpg' border='0' /></a>";
						//document.getElementById('panierdetailData').innerHTML +="<a href='/"+id_secteur+"/panierVisu.htm'>Visualiser le panier</a>";
						document.getElementById('overlay').style.visibility='visible';
						document.getElementById('overlay').style.display='block';
						
						
							//objLightboxAchat.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
							
					}
					//setTimeout("panierok()",1000);
					
				}
         }
    } 
    var url;
/*    if (document.getElementById('chk'+id_produit).checked){
*/		 url="/Panier_In.aspx?id_produit="+id_produit+"&id_secteur="+id_secteur+"&id_famille="+id_famille+"&Qte=1";
		
/*	}else{
		 url="/Panier_In.aspx?id_produit="+id_produit+"&#38;id_secteur="+id_secteur+"&#38;id_famille="+id_famille+"&#38;Qte=0";
		 document.getElementById("bouton_panier"+id_produit).style.visibility='visible';
    }
*/	xhr.open('GET', url,  true); 
   xhr.send(null); 
}
function PrixVente(prixcalc){	
	prix_preload=FormatPrixPreload(prixcalc); //TYPAGE EN FLOAT
	if(prix_preload!=0){
		document.write(format(prix_preload,2," ")+"&#8364;");
	}
}

function PrixBarre(barre,prixcalc){
	
	prix_preload=FormatPrixPreload(prixcalc); //TYPAGE EN FLOAT
	prix_preload_barre=FormatPrixPreload(barre); //TYPAGE EN FLOAT
	//alert(barre+" | "+prixcalc+"\n"+prix_preload+" | "+prix_preload_barre);
  	 if(prix_preload_barre != 0 && prix_preload_barre !="" && prix_preload_barre>prix_preload && prix_preload!=0 ){
		document.write("au lieu de&nbsp;"+format(prix_preload_barre,2," ")+"&#8364;");
	}
}
function EcoPart(ecopart){	
	prix_ecopart=FormatPrixPreload(ecopart);
	if(prix_ecopart!=0 && prix_ecopart !=""){
		document.write('dont '+format(prix_ecopart,2," ")+"&#8364; d\'&#233;copart");
	}
}
function Pourcentage(barre,prixcalc){
	prix_preload = FormatPrixPreload(prixcalc);
	prix_preload_barre = FormatPrixPreload(barre);
	if(prix_preload<prix_preload_barre){
		var dif=prix_preload_barre-prix_preload;
		dif=Math.round(dif*100)/100;
		var difPourcent= (dif * 100) / prix_preload_barre;
		document.write("soit&nbsp;"+format(difPourcent,0," ")+"&#37;");
	}else{
		document.write("&nbsp;");
	}
}
function FormatPrixPreload(prixcalc){
	prix_pre=0;
	prix_pre=prixcalc;
	pos=prix_pre.indexOf("&"); //POS CAR &
	prix_pre=prix_pre.substring(0,pos-1); //CHAINE DE POS 0 A POS
	prix_pre=escape(prix_pre);
	prix_pre=prix_pre.replace(/%2C/g,'.'); //REMPLACE , PAR . AVEC REG
	prix_pre=prix_pre.replace(/%A0/g, ''); //REMPLACE ESPACE PAR RIEN
	return parseFloat(prix_pre); //TYPAGE EN FLOAT
}