function writetag(tag, content) {
	if(document.getElementById(tag)){ 
     document.getElementById(tag).innerHTML = content;
    }//else alert(tag);
}

function createXMLHttpRequest(){
 var xmlhttp;

 if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
   // evite un Bug du navigateur Safari :
   if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType("text/xml");
 }
 else if (window.ActiveXObject){
   try {
   	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  	 } 
  catch (e){   
     try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (e){return false;}
   }
 }
 return xmlhttp; 
}



var xmlhttp_navigation_categorie;
var xmlhttp_mes_articles;
var xmlhttp_titre;
var xmlhttp_localisation;

function navigation_categorie() {
if (xmlhttp_navigation_categorie.readyState==4) {
	  // if "OK"
	  if (xmlhttp_navigation_categorie.status==200) {
		writetag('SousCategorie0', xmlhttp_navigation_categorie.responseText);
	  } else {
		/*alert("Problem retrieving XML data on navigation_categorie(),statut : "+xmlhttp_navigation_categorie.status);*/
	  }
	}
}

function mes_articles() {
if (xmlhttp_mes_articles.readyState==4) {
	  // if "OK"
	  if (xmlhttp_mes_articles.status==200) {
		writetag('MesArticles', xmlhttp_mes_articles.responseText);
	  } else {
		/*alert("Problem retrieving XML data on mes_articles(), statut: "+xmlhttp_mes_articles.status);*/
	  }
	}
}

function verifProd(dispatchUrl) {
	if(dispatchUrl== ""){
		exit();
	}
	else{
		 xmlhttp_mes_articles = createXMLHttpRequest();
		if (xmlhttp_mes_articles!=null) {
		  xmlhttp_mes_articles.onreadystatechange=mes_articles;
		   xmlhttp_mes_articles.open("GET",''+dispatchUrl,true);
		  xmlhttp_mes_articles.send(null);
		}
	}
}

function verifCategorie(idCat) {
if(idCat== 0){
	exit();
}
else{
	    xmlhttp_navigation_categorie = createXMLHttpRequest();
		if (xmlhttp_navigation_categorie!=null) {
		  xmlhttp_navigation_categorie.onreadystatechange=navigation_categorie;
		   xmlhttp_navigation_categorie.open("GET",'?p=2&sp=1&n='+escape(idCat),true);
		  xmlhttp_navigation_categorie.send(null);
		}
	}
}


// RAZ de la zone article - reprendre pr&eacute;cisement le code de la div 'MesArticles'
function InitResult(ok) {
	if(ok == 1){
		document.getElementById('MesArticles').innerHTML = '<img src="/expo/images/expo/un_selectionner-type-produit.gif" alt="S&eacute;l&eacute;ctionnez le type de produit" class="finger" title="S&eacute;l&eacute;ctionnez le type de produit" />';
	}else{
		document.getElementById('MesArticles').innerHTML = '<img src="images/expo/un_selectionner-type-produit.gif" alt="S&eacute;l&eacute;ctionnez le type de produit" class="finger" title="S&eacute;l&eacute;ctionnez le type de produit" />';
	}
}
var activeCat;
var activeSousCat;

function CheckAction(idObject, nbObject, typeColoneCA, classColoneCA) {
document.getElementById('MesArticles').className='coloneArticle';
	if(typeColoneCA=="Categorie") {
		activeCat = typeColoneCA+''+idObject;
	} else {
		activeSousCat = typeColoneCA+idObject;
	}
	var i;
	for(i=0;i<nbObject;i++) {
		if (typeColoneCA+i==activeCat) {
			eval("RollOver("+i+",'"+typeColoneCA+"','"+classColoneCA+"','in')");
			if (i!=idObject) {
				eval("ShowOneHideOther('Liseret',"+i+","+nbObject+",'tiret show')"); // show
			}
		}
		 else {
			eval("RollOver("+i+",'"+typeColoneCA+"','"+classColoneCA+"','out')");
		}
	}
}

function RollOver(idObjectRO, typeColone, classColone, typeAction) {
	if(typeAction=='in') {
	eval("document.getElementById('"+typeColone+""+idObjectRO+"').className='"+classColone+" over'");
	} else {
		if((activeCat==typeColone+idObjectRO) || (activeSousCat==typeColone+idObjectRO)) {
			if(typeAction=='in') {
			eval("document.getElementById('"+typeColone+""+idObjectRO+"').className='"+classColone+" over'");
			}
		} else {
			eval("document.getElementById('"+typeColone+""+idObjectRO+"').className='"+classColone+"'");
		}
	}
}

function Chekonload(index_click,catId,total) {
	CheckAction(index_click,total,'Categorie','categorie');
	document.getElementById('MesArticles').className='coloneArticleH';
	InitResult(); 
	verifCategorie(catId);
}

function Chekonload2(index_click,catId,total,index_click_parent) {
	CheckAction(index_click,total,'SousCategorieLevel','souscategorie');
	RollOver(index_click,'SousCategorieLevel','souscategorie','in')
	RollOver(index_click_parent,'Categorie','categorie','in')
}

function macaronFlash(){
	document.write('<object type="application/x-shockwave-flash" data="images/expo/macaron_verspop.swf" width="176" height="177">	<param name="movie" wmode="transparent" value="images/expo/macaron_verspop.swf" /><param name="wmode" value="transparent" /><p>En savoir plus</p></object>');
}

function macaronFlashAcc(){
	document.write('<object type="application/x-shockwave-flash" data="images/expo/macaron_home.swf"  width="176" height="177">	<param name="movie" value="images/expo/macaron_home.swf" /><param name="wmode" value="opaque"><embed src="images/expo/macaron_home.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="430" height="330" wmode="opaque"></embed></object>');
}

function macaronFlash2(){
	document.write('<object type="application/x-shockwave-flash" data="images/expo/teaser_Expo_b" width="430" height="330">	<param name="movie" value="images/expo/accueil_d.swf" /><param name="wmode" value="opaque"><embed src="images/expo/teaser_Expo_b" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="430" height="330" wmode="opaque"></embed></object>');
}

function macaronFlash3(){
	document.write("<div id='Middle1'>");
	document.write("<script type=text/javascript>");
	document.write("<!--");
	document.write("//OAS_AD('Middle1');");
	document.write("//-->");
	document.write("</script>");
	document.write("</div>");
}
 function fermetureExpo(){
	 document.getElementById('boxBack').className='invisible'; 
	 document.getElementById('flashContainer').className='invisible';
 }
 
 function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
//window.attachEvent("onload", correctPNG);

var ft = true;
function changeCouleurRecherche(recherche) {
	if (ft == true && recherche.value == 'Saisissez votre recherche') {
		ft = false;
		recherche.value = '';
		recherche.className = 'focus';
	}
}
function changeCouleurRechercheGDE(recherche) {
	if (ft == true && recherche.value == 'Saisissez votre recherche') {
		ft = false;
		recherche.value = '';
		recherche.className = 'focusgde';
	}
}
function changeCouleurRechercheGDM(recherche) {
	if (ft == true && recherche.value == 'Saisissez votre recherche') {
		ft = false;
		recherche.value = '';
		recherche.className = 'focusgdm';
	}
}
function changeCouleurRechercheFPE(recherche) {
	if (ft == true && recherche.value == 'Saisissez votre recherche') {
		ft = false;
		recherche.value = '';
		recherche.className = 'focusfpe';
	}
}
function changeCouleurRechercheFGR(recherche) {
	if (ft == true && recherche.value == 'Saisissez votre recherche') {
		ft = false;
		recherche.value = '';
		recherche.className = 'focusfgr';
	}
}
function changeCouleurRechercheFPL(recherche) {
	if (ft == true && recherche.value == 'Saisissez votre recherche') {
		ft = false;
		recherche.value = '';
		recherche.className = 'focusfpl';
	}
}


var alpha = true;
function bravo(emailnewsletter) {
	if (alpha == true && emailnewsletter.value == 'exemple@exemple.com') {
		alpha = false;
		emailnewsletter.value = '';
		emailnewsletter.className = 'focusNewsLetter';

	}
}

function writeTagErrorCatcha(ret) {
	document.getElementById('error_captcha').style.display = 'inline';
	if (ret == '<p>0</p>') {
		writetag('error_captcha', 'Le code de s&eacute;curit&eacute; est incorrect !');
	}
	return true;
}


function reloadCaptcha(code){
	document.getElementById('captcha').src = "/expo/?p=90&sp=1&code="+code.value;
	return true;
}

var xmlhttp_check_captcha ;

function verifCaptcha(code) {
	if (code.value.length == 0) {
		writeTagErrorCatcha(0)
		return false;
	}
	
	writetag('error_captcha', '');
	
	xmlhttp_check_captcha = createXMLHttpRequest();
	
	if (xmlhttp_check_captcha!=null) {
	
		xmlhttp_check_captcha.open("GET",'index.php?p=10&sp=28&code='+escape(code.value),false);
		xmlhttp_check_captcha.send(null);
		var ret = xmlhttp_check_captcha.responseText;
		if (ret == '<p>0</p>') {
			reloadCaptcha(code);
			writeTagErrorCatcha(ret);
			document.getElementById(code.id).value=''; 
			return false;
		}
		else return true;
	}
}

//function urlencode(str) {
//
//    var reg1 = / & /g;
//    var reg2 = / /g;
//    
//  return (str.replace(reg1, '+').replace(reg2, '+'));
//}

function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
 
    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
}

function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var histogram = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF'; 
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
 
    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}


//Vérification du mot de passe
function redirectRecherche(form, root) {
      
      var typeRecherche = '';

      if (form.stand.checked && !form.offre.checked) {
            typeRecherche = '-stand';
      } else if (!form.stand.checked && form.offre.checked) {
    	  typeRecherche = '-produit';
      }
      
      if (form.q.value.length == 0) {
             return;
      }
      else {
            if (form.q.value == 'Saisissez votre recherche') {
                  return;
            }
            else {
                  document.location.href = root + 'recherche' + typeRecherche  + '=' + urlencode(form.q.value);
            }
      }
}
