function montre(id, sid) {
	var d = document.getElementById(id);
	var s = document.getElementById(sid);
	for (i = 1; i<=10; i++) {
		if(document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
		}
	}
	if (d && s) {
		d.style.display='block';
		s.style.background = '#eee';
		s.style.color = 'black';
	} else {
		if(s) {
			s.style.backgroundImage = 'url(images/fondMenu_'+sid+'.png)';
			s.style.color = 'white';
		}
	}
}
window.onload=montre;

function verifcgv() {
	var d =document.getElementById('checkboxCGV');
	if(d.checked == false) {
		alert('Pour continuer votre commande vous devez accepter nos conditions générales de vente');
	}

	return d.checked;
}

function afficheMail(obj) {
	document.getElementById(obj).innerHTML = Base64.decode('PGEgaHJlZj0ibWFpbHRvOmluZm9zQG5hdGF2ZWEuY29tIj5pbmZvc0BuYXRhdmVhLmNvbTwvYT4=');
}

function afficheAdrLiv() {
	obj = document.getElementById('adresseLivraison');
	if(obj.style.display == 'block') {
		obj.style.display = 'none';
	} else {
		obj.style.display = 'block';
	}
}

function activeBg(page) {
	d = document.getElementById('bg')
	i = document.getElementById('imageWait');
	if(d) {
		//if(document.all) {
			var larg = document.documentElement.scrollWidth;
			var haut = document.documentElement.scrollHeight;
		//} else {
			//var larg = window.innerWidth;
			//var haut = window.innerHeight;
		//}
		d.style.width =larg+'px'
		d.style.height = haut+'px';
		d.style.display = 'block';

		if(i) {
			i.style.display = 'inline';
		}
	}


	afficheFrame(page);

	return false;
}

function afficheFrame(page) {
	xmlHttp = getHTTPObject();
	xmlHttp.open("GET", "fiches/" + page, true);
	xmlHttp.send(null);
}

function fermerFrame() {
	d = document.getElementById('bg');
	f = document.getElementById('fenetre');
	ff = document.getElementById('fermerFenetre');

	if(d && f && ff) {
		d.style.display = 'none';
		f.style.display = 'none';
		ff.style.display = 'none';
	}

	return false;
}


function Zoom(nom) {
	if(!nom) {
		var preview=window.open('', 'preview', 'height=500,width=500,scrollbars=auto');
		preview.document.write('<div align="center"><img src="imagesProduits/zoom/'+ nom +'" alt="" border="0"><br />');
		preview.document.write('<a href="javascript:window.close();">Fermer</a></div>');
	}
}

function ShowMenu(id) {
	var d = document.getElementById('leftMenu_' + id);
	var m = document.getElementById('leftMenuTitre_' + id);
	var obj = document.getElementById('fleche_' + id);
	if(d!= null) {
		if(d.style.display == 'block') {
			//if(obj)
			//	obj.src = 'images/flechedroite.gif';
			d.style.display = 'none';
			m.className = 'divSideBox_famille_';
			//m.style.backgroundImage = "url('images/rayon1.gif')";
			//m.onmouseover =	function onmouseover(event) {
    		//	this.style.backgroundImage = "url(images/rayon2.gif)";
			//}
			//m.onmouseout =	function onmouseout(event) {
    		//	this.style.backgroundImage = "url(images/rayon1.gif)";
			//}
		} else {
			for(var i=0; i<=10; i++) {
				HideMenu(i);
			}
			//if(obj)
			//	obj.src = 'images/flechebas.gif';
			d.style.display = 'block';
			m.className = 'divSideBox_famille_select_';
			//m.style.backgroundImage = "url('images/rayon3.gif')";
			//m.onmouseover =	function onmouseover(event) {}
			//m.onmouseout =	function onmouseout(event) {}
		}
	}
}

function ShowMenuGen(id) {
	var d = document.getElementById(id);
	var m = document.getElementById(id + 'Titre');
	var obj = document.getElementById('fleche_' + id);
	if(d!= null) {
		if(d.style.display == 'block') {
			d.style.display = 'none';
			m.className = 'divSideBox_famille_';
			//m.style.background = "url('images/rayon1.gif')";
			//m.onmouseover =	function onmouseover(event) {
    		//							this.style.backgroundImage = "url(images/rayon2.gif)";
			//						}
			//m.onmouseout =	function onmouseout(event) {
    		//						this.style.backgroundImage = "url(images/rayon1.gif)";
			//					}
			//if(obj)
			//	obj.src = 'images/flechedroite.gif';
		} else {
			d.style.display = 'block';
			m.className = 'divSideBox_famille_select_';
			//m.style.background = "url('images/rayon3.gif')";
			//m.onmouseover =	function onmouseover(event) {}
			//m.onmouseout =	function onmouseout(event) {}
			//if(obj)
			//	obj.src = 'images/flechebas.gif';
		}
	}
}

function HideMenu(id) {
	d = document.getElementById('leftMenu_' + id);
	m = document.getElementById('leftMenuTitre_' + id);
	if(d != null) {
		//var obj = document.getElementById('fleche_' + id);
		//if(obj)
		//	obj.src = 'images/flechedroite.gif';
		d.style.display = 'none';
		m.className = 'divSideBox_famille_';
		//m.style.backgroundImage = "url('images/rayon1.gif')";
		//m.onmouseover =	function onmouseover(event) {
    	//								this.style.backgroundImage = "url(images/rayon2.gif)";
		//							}
		//m.onmouseout =	function onmouseout(event) {
		//						this.style.backgroundImage = "url(images/rayon1.gif)";
		//					}
	}
}

function clearChpRecherche(obj) {
	if(obj.value == 'Recherche') {
		obj.value = '';
	}
}

/****
	Fonction pour le test de corpulance
****/
function Veriftype(champs) {
	var ret = true;
	var car = "";
	var nbrcar = champs.length;
	var goodcar="0123456789";

	for(cnt=0;cnt<nbrcar;cnt++) {
		var car = champs.substr(cnt,1);
		if(goodcar.indexOf(car) >= 0) {
		} else {
			ret = false;
			break;
		}
	}
	return ret;
}

function ValidForm() {
	if (document.MyForm.Ssexe.value==0) {
		alert("Vous devez sélectionner votre sexe !");
		document.MyForm.Ssexe.focus();
	} else if (document.MyForm.Tage.value=="" || !Veriftype(document.MyForm.Tage.value)) {
		if (!Veriftype(document.MyForm.Tage.value)) {
			alert("Format incorrect de votre âge ! (uniquement chiffre-entier)")
		} else {
			alert("Vous devez saisir votre âge !");
		}
		document.MyForm.Tage.focus();
	} else if (document.MyForm.Ttaille.value=="" || !Veriftype(document.MyForm.Ttaille.value)) {
		if (!Veriftype(document.MyForm.Ttaille.value)) {
			alert("Format incorrect de votre taille ! (uniquement chiffre-entier)")
		} else {
			alert("Vous devez saisir votre taille en cm !");
		}
		document.MyForm.Ttaille.focus();
	} else if (document.MyForm.Tpoids.value=="" || !Veriftype(document.MyForm.Tpoids.value)) {
		if (!Veriftype(document.MyForm.Tpoids.value)) {
			alert("Format incorrect de votre poids ! (uniquement chiffre-entier)")
		} else {
			alert("Vous devez saisir votre poids en kg !");
		}
		document.MyForm.Tpoids.focus();
	} else if (document.MyForm.Ssexe.value==1 && document.MyForm.TtourB.value=="" && document.MyForm.BoxBras.checked==0 || !Veriftype(document.MyForm.TtourB.value)) {
		if (!Veriftype(document.MyForm.TtourB.value)) {
			alert("Format incorrect de votre tour de bras ! (uniquement chiffre-entier)")
		} else{
			alert("Vous devez saisir votre tour de bras en cm ou cocher la case 'ne sait pas' !");
		}
		document.MyForm.TtourB.focus();
	} else if (document.MyForm.TtourA.value=="" && document.MyForm.BoxABras.checked==0 || !Veriftype(document.MyForm.TtourA.value)) {
		if (!Veriftype(document.MyForm.TtourA.value)) {
			alert("Format incorrect de votre tour d'avant bras ! (uniquement chiffre-entier)")
		} else {
			alert("Vous devez saisir votre tour d'avant bras en cm ou cocher la case 'ne sait pas' !");
		}
		document.MyForm.TtourA.focus();
	} else if (document.MyForm.Ttourt.value=="" && document.MyForm.BoxTaille.checked==0 || !Veriftype(document.MyForm.Ttourt.value)) {
		if (!Veriftype(document.MyForm.Ttourt.value)) {
			alert("Format incorrect de votre tour de taille ! (uniquement chiffre-entier)")
		} else {
			alert("Vous devez saisir votre tour de taille en cm ou cocher la case 'ne sait pas' !");
		}
		document.MyForm.Ttourt.focus();
	} else if (document.MyForm.Ssexe.value==1 && document.MyForm.TtourF.value=="" && document.MyForm.BoxFesse.checked==0 || !Veriftype(document.MyForm.TtourF.value)) {
		if (!Veriftype(document.MyForm.TtourF.value)) {
			alert("Format incorrect de votre tour de fessier ! (uniquement chiffre-entier)")
		} else {
			alert("Vous devez saisir votre tour de fessier en cm ou cocher la case 'ne sait pas' !");
		}
		document.MyForm.TtourF.focus();
	} else if (document.MyForm.Ssexe.value==2 && document.MyForm.TtourC.value=="" && document.MyForm.BoxCuisse.checked==0 ||!Veriftype(document.MyForm.TtourC.value)) {
		if (!Veriftype(document.MyForm.TtourC.value)) {
			alert("Format incorrect de votre tour de cuisse ! (uniquement chiffre-entier)")
		} else {
			alert("Vous devez saisir votre tour de cuisse en cm ou cocher la case 'ne sait pas' !");
		}
		document.MyForm.TtourC.focus();
	} else if (document.MyForm.Ssexe.value==2 && document.MyForm.TtourM.value=="" && document.MyForm.BoxMollet.checked==0 || !Veriftype(document.MyForm.TtourM.value)) {
		if (!Veriftype(document.MyForm.TtourM.value)) {
			alert("Format incorrect de votre tour de mollet ! (uniquement chiffre-entier)")
		} else {
			alert("Vous devez saisir votre tour de mollet en cm ou cocher la case 'ne sait pas' !");
		}
		document.MyForm.TtourM.focus();
	} else if (document.MyForm.Sactiv.value==0) {
		alert("Vous devez sélectioner votre niveau d'activité !");
		document.MyForm.Sactiv.focus();
	} else {
		return true;
	}

	return false;
}

/****
	Fin des fonctions pour le test de corpulance
****/

/****
	Classe d'encodage en base64
****/

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}


/**
 * Verification du formulaire d'inscription
 */
function verifForm(obj, checkPasswd) {
	var erreur = false;
	var tabChamp = new Array();

	if(!obj.civilite[0].checked && !obj.civilite[1].checked  && !obj.civilite[2].checked) {
		tabChamp.push('Civilité');
		erreur = true;
	}
	if(obj.nom.value.length == 0) {
		tabChamp.push('Votre nom');
		erreur = true;
	}
	if(obj.prenom.value.length == 0) {
		tabChamp.push('Votre prénom');
		erreur = true;
	}
	if(checkPasswd) {
		if(obj.passwd1.value.length == 0 || obj.passwd2.value.length == 0 ) {
			tabChamp.push('Votre mot de passe');
			erreur = true;
		}
	}
	if(obj.email.value.length == 0) {
		tabChamp.push('Votre adresse email');
		erreur = true;
	}
	if(obj.portable.value.length == 0 && obj.fix.value.length == 0 ) {
		tabChamp.push('Téléphone portable ou Téléphone fixe');
		erreur = true;
	}
	if(obj.adresse.value.length == 0) {
		tabChamp.push('Votre adresse');
		erreur = true;
	}
	if(obj.cp.value.length == 0) {
		tabChamp.push('Votre carnet d\'adresse');
		ereur = true;
	}
	if(obj.ville.value.length == 0) {
		tabChamp.push('Votre ville');
		erreur = true;
	}
	if(obj.adresseLivr.checked == false) {
		if(!obj.civiliteLivr[0].checked && !obj.civiliteLivr[1].checked  && !obj.civiliteLivr[2].checked) {
			tabChamp.push('Civilité de livraison');
			erreur = true;
		}
		if(obj.nomLivr.value.length == 0) {
			tabChamp.push('Votre nom de livraison');
			erreur = true;
		}
		if(obj.prenomLivr.value.length == 0) {
			tabChamp.push('Votre prénom de livraison');
			erreur = true;
		}
		if(obj.adrLivr.value.length == 0) {
			tabChamp.push('Votre adresse de livraison');
			erreur = true;
		}
		if(obj.cpLivr.value.length == 0) {
			tabChamp.push('Votre code postal de livraison');
			erreur = true;
		}
		if(obj.villeLivr.value.length == 0) {
			tabChamp.push('Votre ville de livraison');
			erreur = true;
		}
	}

	if(erreur == true) {
		var textAlert = "Merci de remplir le(s) champ(s) suivant(s) : \n";

		for(i=0; i<tabChamp.length; i++)
			textAlert += "\t - " + tabChamp[i] + "\n";

		alert(textAlert);
	}
	return !erreur;
}


/*
function getHTTPObject() {
	var xmlhttp = false;

/* Compilation conditionnelle d'IE */
/*@cc_on
	@if (@_jscript_version >= 5)
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}
	@else
		xmlhttp = false;
	@end @*/

	/* on essaie de créer l'objet si ce n'est pas déjà fait */
	/*if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}

	if (xmlhttp) {
		/* on définit ce qui doit se passer quand la page répondra */
		/*xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState == 4) { // 4 : état "complete"
				if (xmlhttp.status == 200) { // 200 : code HTTP pour OK
					i = document.getElementById('imageWait');
					if(i) {
						i.style.display = 'none';
					}

					f =document.getElementById('fenetre');
					ff =document.getElementById('fermerFenetre');
					if(f && ff) {
						f.innerHTML = xmlhttp.responseText;

						var largeurFrame = parseInt(f.style.width) / 2;
						var largeurFF = parseInt(ff.style.width);
						var hauteurFF = parseInt(ff.style.height);
						var largeurTotal = document.documentElement.scrollWidth / 2;
						var left = largeurTotal - largeurFrame;

						f.style.left = left + 'px';
						f.style.top = '20px';
						f.style.display = 'block';

						ff.style.left = left + 'px';
						//ff.style.left = left + 2 * largeurFrame - largeurFF + 3 + 'px';
						//ff.style.top = parseInt(f.style.top) - hauteurFF - 3 + 'px'
						ff.style.display = 'block';
					}
				}
			}
		}
	}

	return xmlhttp;
}*/


/**
 *	Panier
 */

function switchImagePanier(img, imgDefault) {
	var d = document.getElementById('checkboxCGV');
	var obj = document.getElementById('validePanier');
	if(d && obj)
		if(d.checked)
			obj.src = img;
		else
			obj.src = imgDefault;
}

/**
 * Fiche Article
 */
function afficheDefault() {
	/*
	var obj1 = document.getElementById(currentDiv);
	if(obj1 != null) {
		obj1.style.display = 'block';
	}
	var obj2 = document.getElementById('Titre' + currentDiv);
	if(obj2 != null)
		obj2.style.background = "url('images/fondOnglet2.gif')";
	*/
}
function switchDisplay(id) {
	var tabInfo = ['Desc', 'Conseil', 'Avis', 'Composants'];

	for(var i=0; i<4; i++) {
		document.getElementById(tabInfo[i]).style.display = 'none';
		var obj = document.getElementById('Titre' + tabInfo[i]);
		obj.style.background = "url('images/fondOnglet1.gif')";
		obj.onmouseover =	function onmouseover(event) {
    								this.style.backgroundImage = "url(images/fondOnglet2.gif)";
								}
		obj.onmouseout =	function onmouseout(event) {
									this.style.backgroundImage = "url(images/fondOnglet1.gif)";
								}
	}
	document.getElementById(id).style.display = 'block';
	var obj = document.getElementById('Titre' + id);
	obj.style.background = "url('images/fondOnglet3.gif')";
	obj.onmouseover =	function onmouseover(event) {}
	obj.onmouseout =	function onmouseout(event) {}
	currentDiv = id;
}


var SelectedPort = '-1';
function switchPort(id) {
	document.getElementById(SelectedPort).style.display = 'none';
	document.getElementById(id).style.display = 'inline';

	SelectedPort = id;
}

var imageLst = new Array();
if(document.images) {     // Preloaded images
    for(var i=0; i<5; i++) {
        img = new Image();
        img.src = 'images/port_conseils' + i + '.gif';
        imageLst.push(img);
    }
}

function loopImage(id) {
    if(document.images) {
        document.getElementById('port_conseils').src = imageLst[id].src; //eval();
        id++;
        if(id >= imageLst.length)
            thetimer = setTimeout('loopImage(' + 0 + ')', 3000);
        else
            thetimer = setTimeout('loopImage(' + id + ')', 3000);
    }
}

