DOM= document.getElementById && !document.all;
IE4= document.all;
var currentSousrub="";
function displayMenu(nomlayer,lien_focus) {
	/*if(lien_focus!=''){
		lien_focus.blur();
	}*/
	if(currentSousrub==nomlayer){nomlayer="";}
	if (IE4) {
		if (currentSousrub!="") {document.all[currentSousrub].style.display="none";}
		currentSousrub = nomlayer;
		if (nomlayer!="") {document.all[currentSousrub].style.display="";}
	}
	if(DOM){
		if (currentSousrub!="") {document.getElementById(currentSousrub).style.display="none";}
		currentSousrub=nomlayer;
		if (nomlayer!="") {document.getElementById(currentSousrub).style.display="";}
	}
}
function popCentre (pFichier, pNom, pLargeur, pHauteur, pFeature){
	var posX = (screen.width / 2) - (pLargeur / 2);
	var posY = (screen.height / 2) - (pHauteur / 2);
	if(pFeature!=''){pFeature=','+pFeature;}
	fen=window.open(pFichier,pNom,"width = " + pLargeur + ", height = " + pHauteur + ", left = " + posX + ", top = " + posY + pFeature);
	fen.focus();
}
function popup(theURL,winName,features,w,h) { //v2.0
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 100;
  TopPosition = (screen.height) ? (screen.height-h)/2 : 100; 
  features = features+',width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition;
  var fen=window.open(theURL,winName,features);
  if(!fen){
	alert('Vous devez autoriser l\'ouverture de popup dans votre navigateur, pour utiliser cette commande');  
  }else{
  	fen.focus();
  }
}
function clicMenu(id) { 
  if (DOM){ var lediv = document.getElementById(id);}
  if (IE4){ var lediv = document.all[id];}
  if (lediv.style.display == "none"){
    lediv.style.display = "";
  } else {
    lediv.style.display = "none";
  }   
}
function fermer_pop(){
	if(window.fen){
		fen.close();
	}else{
		return false;		
	}
}
function display_style(classe,elemt){
	elemt.attributes['class'].nodeValue=classe;//alert(classe);
}
function actu_select(cible,source) {
	for(i=cible.length-1;i>=0;i--){
 		cible.options[i]=null;
	}
	for(i=0;i<source.length;i++){
		cible.options[i] = new Option(source.options[i].text,source.options[i].value)
	}
}

function format_num(valeur,champ,minimum){
	//alert(valeur);
	//valeur='2';
	var nombre = valeur.replace(/\s+/g,"");
	if(isNaN(nombre)){
		var longueur = nombre.length-1;
		nombre = nombre.substring(0,longueur);
	}
	nombre = parseInt(nombre);
	if(isNaN(nombre) || nombre==0){
		nombre = minimum;
	}
	//document.forms[0][champ].value = nombre;
	champ.value = nombre;
}


function ajoutPanier(id_article,chemin)
{
	var chqte = 'qte'+id_article;
	var param = 'id_article='+id_article+'&qte='+document.getElementById(chqte).value;
	var page = 'ajout_panier.php';//alert(page);
	if(document.all){
		//Internet Explorer
		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
	}
	else{
		//Mozilla
		var XhrObj = new XMLHttpRequest();
	}
	//définition de l'endroit d'affichage:
	var content1 = document.getElementById('nb_panier');
	
	XhrObj.open("POST", page);

	//Ok pour la page cible
	XhrObj.onreadystatechange = function(){
		if (XhrObj.readyState == 4 && XhrObj.status == 200){
			var reponse = XhrObj.responseText;
			content1.innerHTML = 'Vous avez '+reponse+' dans <a href="'+chemin+'panier.php" class="normal">votre panier</a>';
			alert('Cet article a été ajouté à votre sélection');
		}
	}

	XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	XhrObj.send(param);
}
function supprArticlePanier(formulaire,id){
	document.getElementById('suppression').value=id;
	document.getElementById(formulaire).submit();
}
function supprAboPanier(formulaire,id){
	document.getElementById(id).value='';
	document.getElementById(formulaire).submit();
}

function recalculeRemises(formulaire,cible){
	formulaire.action=cible;
	formulaire.submit();	
}
function checkEmailNews(formulaire){
	var good=1;
	var strTexte='';
	var EmailValue = formulaire.email_news.value;
	if(EmailValue ==''){
		strTexte+='Vous devez saisir votre email \n';
		good=0;
	}
	if(EmailValue!=""){
		testm = false ;
		for (var j=1 ; j<(EmailValue.length) ; j++) {
			if (EmailValue.charAt(j)=='@') {
				if (j<(EmailValue.length-4)){
					for (var k=j ; k<(EmailValue.length-2) ; k++) {
						if (EmailValue.charAt(k)=='.') testm = true;
		}	}	}	}
		if (testm==false){
			strTexte+='Cet email n\'est pas valide\n';
			good="0";
		}
	}
	if (good==0){
		alert(strTexte);
		return false;
	}else{
		return true;
	}
}
function masquer(leDiv,etat) {
  DOM= document.getElementById;
  IE4= document.all && !document.getElementById; 
  if (DOM){ 
  	var leDiv1 = document.getElementById(leDiv);
  }
  if (IE4){
   var leDiv1 = document.all[leDiv];
  }
  leDiv1.style.display = etat;
}
/*** menu visuels ***/
function homeUnivers(param) {	
	var etat;var classe;
	for(var i=1;i<=7;i++){
		if(document.getElementById('visuel'+i)){
			if(i==param){
				etat = 'block';
				classe = 'actif'; 
			}else{
				etat = 'none';
				classe = ''; 
			}
			document.getElementById('visuel'+i).style.display=etat;
			document.getElementById('mv'+i).attributes['class'].nodeValue=classe;
		}
	}
	document.getElementById('visuel'+param).style.display="block";
	if (homeTimer) {
		clearTimeout(homeTimer);
	}
}	
var homeTimer = 0;
var homeIndex = 7;
var tabUniv = new Array(1,2,3,4,5,6,7);
function loadUnivers(){
	homeIndex ++;
	if(homeIndex > 6){
		homeIndex = 0;
	}
	//alert(tabUniv[homeIndex]);
	homeUnivers(tabUniv[homeIndex]);
	homeTimer = window.setTimeout("loadUnivers()",5000);
}

function continueUnivers(){
	homeUnivers(tabUniv[homeIndex]);
	homeTimer = window.setTimeout("loadUnivers()",5000);	
}

function initUnivers(){
	for(var i=1;i<=7;i++){
		document.getElementById('mv'+i).onmouseover = function(){
			var idElt = this.id;
			var ind = idElt.replace(/mv/,'');
			homeUnivers(ind);
		}
		document.getElementById('mv'+i).onmouseout = function(){
			var idElt = this.id;
			var ind = idElt.replace(/mv/,'')
			continueUnivers();
		}
	}
	loadUnivers();
}   

/*** menu visuels ***/

function upd_qte(valeur,elt){
	var nombre = String(parseInt(document.getElementById(elt).value) + valeur);
	format_num(nombre,document.getElementById(elt),1);
}
function submitMarque(formulaire, id_marque){
	if(id_marque!=''){
		formulaire.action = formulaire.action + 'searchmarque-'+id_marque+'.php';
	}
	formulaire.submit();
}	
isDom = (document.getElementById);	
function affichermasquer(idniveau,wclass){
	if (isDom) {
		ligne = document.getElementById(idniveau);
	}
	if(wclass){		
		ligne.attributes['class'].nodeValue=wclass;
	}else{
		if(ligne.attributes['class'].nodeValue=="displayyes"){
			ligne.attributes['class'].nodeValue="displaynone";
		}else{
			ligne.attributes['class'].nodeValue="displayyes";
		}	
	}
}
function display_photo(img){
	for(i=1;i<=4;i++){
		if(document.getElementById('im'+i)){
			if(i==img){
				document.getElementById('im'+i).style.display='';
			}else{
				document.getElementById('im'+i).style.display='none';
			}
		}
	}
}
