/* Fonctions Javascript */


	// Fonction permettant d'afficher le sous-menu déroulant sous IE6
	sfHover = function() {
        var sfEls = document.getElementById("nav").getElementsByTagName("LI");
        for (var i=0; i<sfEls.length; i++) {
            sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
				voirSelect('hidden');
            }
            sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				voirSelect('visible');
            }
        }
    }
    if (window.attachEvent) window.attachEvent("onload", sfHover);
	
	
	// Permet de cacher les elements de formulaire select quand on passe sur les sous-menu => pour IE6
	function voirSelect(v){
		
		var elem=document.getElementsByTagName('select');
		var detect = navigator.userAgent.toLowerCase();
		var version;
		
		place = detect.indexOf('msie') + 1;
		
		var version = detect.charAt(place + 4);
		
		if(version == 6){
			if(!window.Event){for(i=0;i<elem.length;i++)elem[i ].style.visibility=v;}
		}
		
	}
	

	// Fonction permettant d'afficher l'onglet sur lequel on a cliqué => les engagements
	function display(id) {
		document.getElementsByName('eng'+id)[0].style.display = 'block';;
		document.getElementsByName('onglet_eng'+id)[0].className = 'petit_onglet_vert';
			
		for(var i = 1; i <= 5; i++){
			if (i != id){
				cache(i);
			}
		}
			
	}

	function cache(id) {
		document.getElementsByName('eng'+id)[0].style.display = 'none';
		document.getElementsByName('onglet_eng'+id)[0].className = 'petit_onglet_bleu';
		
	}
	
	
	// Fonction permettant d'affiche le texte de l'article sur lequel on a cliqué => les questions fréquentes
	function clique_article(id){
		
		if(document.getElementById(id).style.display == 'none'){
			document.getElementById(id).style.display = 'block';
		}
		
		else if(document.getElementById(id).style.display == 'block'){
			document.getElementById(id).style.display = 'none';
		}
		
		else {
			document.getElementById(id).style.display = 'block';
		}
	}
	
	
	// fonction permettant d'afficher l'onglet "Produit" sur lequel on a cliqué => Fiche produit, Descriptif produit, Services & garanties
	function displayonglet(id) {
		document.getElementById('produit'+id).style.display = 'block';
		document.getElementById('ongletg_produit'+id).className = 'onglet_produit_vert_gauche';
		document.getElementById('onglet_produit'+id).className = 'onglet_produit_vert_centre';
		document.getElementById('ongletd_produit'+id).className = 'onglet_produit_vert_droit';
			
		for(var i = 1; i <= 6; i++){
			if (i != id){
				cacheonglet(i);
			}
		}	
	}

	function cacheonglet(id) {
		document.getElementById('produit'+id).style.display = 'none';
		document.getElementById('ongletg_produit'+id).className = 'onglet_produit_gris_gauche';
		document.getElementById('onglet_produit'+id).className = 'onglet_produit_gris_centre';
		document.getElementById('ongletd_produit'+id).className = 'onglet_produit_gris_droit';
	}
	
	
	// Fonctions permettant d'afficher ou de cacher un popup
	function showaction(id) {
		document.getElementById("popup"+id).style.visibility = "visible";
	}
	
	function hideaction(id) {
		document.getElementById("popup"+id).style.visibility = "hidden";
	}
	
	
	// 
	function getWindowSize(){

		windowWidth =  window.innerWidth;
		windowWidth = (windowWidth)? windowWidth : document.documentElement.clientWidth;
		windowWidth = (windowWidth)? windowWidth : document.body.clientWidth;
		windowHeight =  window.innerHeight;
		windowHeight = (windowHeight)? windowHeight: document.documentElement.clientHeight;
		windowHeight = (windowHeight)? windowHeight: document.body.clientHeight;  
		return {'width': windowWidth, 'height': windowHeight};
	}
	//
	function getPageSize(){

		var windowSize = getWindowSize()
		var xScroll = document.body.scrollWidth;
		var yScroll = (window.innerHeight && window.scrollMaxY)? window.innerHeight + window.scrollMaxY : document.body.scrollHeight;
		var pageWidth = (xScroll < windowSize.width)? windowSize.width : xScroll;  
		var pageHeight = (yScroll < windowSize.height)? windowSize.height : yScroll;
		return {'width': pageWidth, 'height': pageHeight};
	}
	
	// Ouverture d'un popup centrée
	function popup(page, width, height)
    {
        var windowSize = getWindowSize();
		var pageSize = getPageSize();

		var top = ((windowSize.height - 35 - height) / 2) + 'px';
		var left = ((pageSize.width - 20 - width) / 2) + 'px';

		var win=window.open(page, '', 'width='+width+', height='+width+', top='+width+', left='+left+' toolbar=no, location=no, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=no, dependent=yes, copyhistory=no');
    }
	
	
	// Fonction qui vérifie le passage du panier de commande aux coordonnées : acceptation des Conditions Générales de Vente
	function verifCGV()
	{
		// si la valeur du champ prenom est non vide
		if(document.formCGV.elements['cgv'].checked==false) {
			// sinon on affiche un message
			alert("Veuillez accepter les conditions générales de vente");
			return false;
		}
		else {
			// alors on envoie le formulaire
			document.formCGV.submit();
			return true;
		}

	}
	
	
	// Fonction qui vérifie le passage des coordonnées au récapitulatif de commande
	function verifCoordonnees()
	{
	
	// si la valeur du champ prenom est non vide
		if(document.formLivraison.elements['tel'].value=="") {
			// sinon on affiche un message
			alert("Veuillez inscrire votre numéro de téléphone");
			document.formLivraison.elements['tel'].focus();
			return false;
		}
		else {
			// alors on envoie le formulaire
			document.formLivraison.submit();
			return true;
		}
	
	}

	
	// Fonction permettant d'afficher les photos zoomées
	function affichePhoto(photo)
	{
		var monLayer = document.getElementById('popup');
		monLayer.style.visibility="visible";
		monLayer.style.left="50%";
		monLayer.style.marginLeft="-153px";
		monLayer.style.top="253px";
		monLayer.innerHTML = '<a onClick="javascript:cachePhoto();"><img src="'+photo+'"/></a>';
		
	}
	function cachePhoto(){
		var monLayer = document.getElementById('popup');
		monLayer.style.visibility = "hidden";
	}
	
	
	// Fonction permettant d'afficher des popups
	function affichePopup(popup)
	{
		document.getElementById(popup).style.visibility='visible';
		//var monLayer = document.getElementById(popup);
		//monLayer.style.visibility="visible";
		
		//monLayer.innerHTML = url;
		//monLayer.location.href= url ;
	}
	
	function cachePopup(popup)
	{
	
	}
	
	
	// Fonction permettant d'ajouter un site aux favoris
	function addToFavorites(anchor)
    {
	    if (window.external)
	    {
			window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
	    }
    }
    