
function loadFiche(lang){

	loadPage(lang);
	resizeFiche();
}

function loadPage(lang){
	

	var fo = new SWFObject( 'swf/logo'+lang+'.swf' , "myLogo", "100%", "100%", "8.0", "");
	fo.addParam("scale", "noscale");          
	fo.addParam("wmode", "transparent");  
	
 
	fo.write("logo");

	var fo = new SWFObject( 'swf/info'+lang+'.swf?temp=1' , "myinfo", "100%", "100%", "8.0", "");
	fo.addParam("scale", "noscale");          
	fo.addParam("wmode", "transparent");          

	fo.write("info");
	
}

function resizeFiche(){

	
	var winW = 1000, winH = 520;

	if (document.body && document.body.offsetWidth) {
		
	 winW = document.body.offsetWidth;
	 winH = document.body.offsetHeight;
	}
	
	if (window.innerWidth && window.innerHeight) {
		
	 winW = window.innerWidth;
	 winH = window.innerHeight;
	 
	}

	if( document.getElementById('menuProd')){ 

		//fiche
	
		var obj  = document.getElementById('menuProd');
	
		if(obj.offsetHeight) { objH= obj.offsetHeight ; }
		else if(obj.style.pixelHeight){ objH = obj.style.pixelHeight; }
	
		winH  -=  118;
		winW  -=  320 ;
		
		winW = Math.max( winW , 660 )
		winH = Math.max( winH , Math.max( 400, objH ))
	
		
		document.getElementById('flashcontent').style.height= '' + winH + 'px';
		document.getElementById('flashcontent').style.width= '' + winW + 'px';

	}else if( !document.getElementById('menuTemp')){ 

		//liste

		var nodeClass = getElementsBySelector('div.result');
		
		dispW = winW - 268;

		dispW = Math.max(dispW,722);
	
		col = Math.floor( dispW/234);
	
		marge=  Math.floor(( (dispW%234) )/ ( col + 1 ));

		larg = marge + 462;

		if(document.getElementById('bloc1')){ 

			document.getElementById('bloc1').style.width = larg + 'px'; 
			document.getElementById('bloc1').style.margin = '0 0 0  ' + marge + 'px ';
			document.getElementById('bloc1_spacer').style.width = larg + 'px';
			document.getElementById('bloc1_spacer').style.margin = '0 2px 8px  ' + marge + 'px ';

		}
	
	
		for ( i=0; i<nodeClass.length; i++ ) {
		
			 nodeClass[i].style.margin = '0 2px 8px  ' + marge + 'px ';
	
		} 

	}

}


function ouvre(url,w,h,x,y){
	window.open(url,"_blank","height="+h+",width="+w+",left="+x+",top="+y+",scrollbars=no,resizable=no,menubar=no,status=no,toolbar=no,location=no") ;
}

function setSwf(theselect, selectedCouleur, colorTitre, lang){ 
                    
	var fo = new SWFObject( 'site.swf?lang='+lang+'&select='+theselect+'&selectedCouleur='+selectedCouleur+'&colorTitre='+colorTitre , "myFlash", "100%", "100%", "9.0", "");
	fo.addParam("scale", "noscale");          
	fo.write("flashcontent");

}



/////////////////////////////////////////////////////////////////News


var reste = 0;
var  timer = 0;
var  courrant = 0;


function dep(dir){

	if(reste==0){	

		if(dir==1){
	
			courrant++;
	
			if( courrant == nbre-2 ){ document.getElementById('f_right').style.display='none'; }
			document.getElementById('f_left').style.display='block';

			reste = 345;
			
			timer=setInterval("gotox()", 100);
	
		}else{
	
			courrant--;
	
			if( courrant == 1  ){ document.getElementById('f_left').style.display='none'; }
			document.getElementById('f_right').style.display='block';
	
			reste = -345;
		
			timer=setInterval("gotox()", 100);

	
		}

	}

}

function gotox(){

	reste /=  2;
	
	if( Math.abs(reste)>=2 ){
		
		document.getElementById('scollNews').scrollLeft+=reste;

	}else{
		clearInterval(timer);
		document.getElementById('scollNews').scrollLeft = courrant*345;
		reste = 0; 

	}

}


///////////////////////////////////////////////////Panier 

function ajouteArticle(idArticle, sid, lang){ 

	if(sid == '0' ){ // CREATION SID

		var ajax = new XHR();
		ajax.appendData('action','insert');
		ajax.appendData('ajax','ok');        
		ajax.appendData('idQtite',''+idArticle);
		ajax.appendData('sid',''+sid);
		ajax.appendData('lang',''+lang);
	
		// mise à jour de l'apercu panier
		ajax.send("creation_sid.php");
		ajax.complete = function (xhr)
		{
			newsid = xhr.responseText;
			newsid = newsid.replace(/\s/g, '');
			ajouteArticle2(idArticle, newsid);
	
			afficheBtn(newsid, lang);
			afficheBtn2(newsid, lang);
			afficheMenu(newsid);

 		}

	}else{

		ajouteArticle2(idArticle, sid);

	}

	
	
}

function ajouteArticle2(idArticle, sid){ 


	var ajax = new XHR();
	ajax.appendData('action','insert');
	ajax.appendData('ajax','ok');        
	ajax.appendData('idQtite',''+idArticle);
	ajax.appendData('sid',''+sid);

	// mise à jour de l'apercu panier
	ajax.send("update_panier.php");
	ajax.complete = function (xhr)
	{
		document.getElementById('ajax_panier').innerHTML = xhr.responseText;

	}
	
}


function afficheBtn(sid, lang){ 

	var ajax = new XHR();
	ajax.appendData('sid',''+sid);
	ajax.appendData('lang',''+lang);
	ajax.appendData('ajax','ok');
	// mise à jour de l'apercu panier
	ajax.send("update_btn.php");
	ajax.complete = function (xhr)
	{
		document.getElementById('btn').innerHTML = xhr.responseText;
	}

}
function afficheBtn2(sid, lang){ 

	var ajax = new XHR();
	ajax.appendData('sid',''+sid);
	ajax.appendData('lang',''+lang);
	ajax.appendData('ajax','ok');
	// mise à jour de l'apercu panier
	ajax.send("update_btn2.php");
	ajax.complete = function (xhr)
	{
		document.getElementById('btn2').innerHTML = xhr.responseText;
	}

}


function afficheMenu(sid){ 

	var ajax = new XHR();
	ajax.appendData('action','insert');
	ajax.appendData('sid',''+sid);
	ajax.appendData('ajax','ok');        	
	// mise à jour de l'apercu panier
	ajax.send("update_menu.php");
	ajax.complete = function (xhr)
	{
		document.getElementById('menu').innerHTML = xhr.responseText;
	}

}

function afficheArticle(sid){
	
	var ajax = new XHR();
	ajax.appendData('action','affich');
	ajax.appendData('ajax','ok');        
	ajax.appendData('idQtite','0');
	ajax.appendData('sid',''+sid);

	// mise à jour de l'apercu panier
	ajax.send("update_panier.php");
	ajax.complete = function (xhr)
	{
		document.getElementById('ajax_panier').innerHTML = xhr.responseText;
	}
	
}

function plus(nbre,idArticle,sid){

	var ajax = new XHR();
	ajax.appendData('ajax','ok');        
	ajax.appendData('idQtite',''+idArticle);
	ajax.appendData('sid',''+sid);
	ajax.appendData('nbre',''+nbre);

	// mise à jour de l'apercu panier
	ajax.send("ajouter_panier.php");
	ajax.complete = function (xhr)
	{
		document.getElementById('recap_panier').innerHTML = xhr.responseText;
		afficheArticle(sid);

	}
	
}

function moins(nbre,idArticle,sid){

	var ajax = new XHR();
	ajax.appendData('ajax','ok');        
	ajax.appendData('idQtite',''+idArticle);
	ajax.appendData('sid',''+sid);
	ajax.appendData('nbre',''+nbre);

	// mise à jour de l'apercu panier
	ajax.send("enlever_panier.php");
	ajax.complete = function (xhr)
	{
		document.getElementById('recap_panier').innerHTML = xhr.responseText;
		afficheArticle(sid);

	}
	
}

function supprimer(idArticle,sid){

	var ajax = new XHR();
	ajax.appendData('ajax','ok');        
	ajax.appendData('idQtite',''+idArticle);
	ajax.appendData('sid',''+sid);

	// mise à jour de l'apercu panier
	ajax.send("supprimer_panier.php");
	ajax.complete = function (xhr)
	{
		document.getElementById('recap_panier').innerHTML = xhr.responseText;
		afficheArticle(sid);

	}
	
}


Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

function XHR() {
	this.conn = false;
	this.data = new Array();
	this.autoReset = false;
	this.autoSend = false;
	this.sendMethod = "POST";
	this.url = new String();

	if (window.XMLHttpRequest) {
		try { this.conn = new window.XMLHttpRequest(); }
		catch (e) { return false; }
	} else {
		var msXML = new Array(
			"Msxml2.XMLHTTP.5.0",
			"Msxml2.XMLHTTP.4.0",
			"Msxml2.XMLHTTP.3.0",
			"Msxml2.XMLHTTP",
			"Microsoft.XMLHTTP");
		var nbMsXML = msXML.length;
		for (var i = 0; i < nbMsXML; i++) {
			try {
				this.conn = new ActiveXObject(msXML[i]);
				break;
			} catch (e) { }
		}
		if (!this.conn) { return false; }
	}

	this.conn.onreadystatechange = (function () {
		switch (this.conn.readyState) {
			case 0 : this.uninitialized(this.conn);
				break;

			case 1 : this.loading(this.conn);
				break;

			case 2 : this.loaded(this.conn);
				break;

			case 3 : this.interactive(this.conn);
				break;

			case 4: this.complete(this.conn);
				break;
		}
	}).bind(this);
}

XHR.prototype.uninitialized	= new Function;
XHR.prototype.loading		= new Function;
XHR.prototype.loaded		= new Function;
XHR.prototype.interactive	= new Function;
XHR.prototype.complete		= new Function;

XHR.prototype.autoResetOff = function ()	{ this.autoReset = false; }
XHR.prototype.autoResetOn  = function ()	{ this.autoReset = true;  }
XHR.prototype.autoSendOff  = function ()	{ this.autoSend  = false; }
XHR.prototype.autoSendOn   = function ()	{ this.autoSend  = true;  }

XHR.prototype.setSendMethod = function (method) {
	method = method.toUpperCase();
	switch(method){
		case "GET": this.sendMethod = "GET";
		break;

		case "POST": this.sendMethod = "POST";
		break;

		default: this.sendMethod = "POST";
	}
}

XHR.prototype.switchSendMethod = function() {
	if (this.sendMethod == "POST") this.sendMethod = "GET";
	else this.sendMethod = "POST";
}

XHR.prototype.appendData = function (field, value) {
	for (var i = 0, j = this.data.length; i < j; i++) {
		if (this.data[i]["field"] == field) {
			this.data[i]["value"] = value;
			return (this.autoSend) ? this.send() : true;
		}
	}
	this.data.push(new Array());
	this.data[this.data.length - 1]["field"] = field;
	this.data[this.data.length - 1]["value"] = value;
	return (this.autoSend) ? this.send() : true;
}

XHR.prototype.resetData = function () {
	delete this.data;
	this.data = new Array();
	return true;
}

XHR.prototype.prepareData = function () {
	var prepared = new String();
	for (var i = 0, j = this.data.length; i < j; i++) {
		prepared += encodeURIComponent(this.data[i]["field"])
		if (this.data[i]["value"].length > 0) prepared += "=" + encodeURIComponent(this.data[i]["value"]);
		if (i < j - 1) prepared += "&";
	}
	return prepared;
}

XHR.prototype.setField = function (field, newField) {
	for (var i = 0, j = this.data.length; i < j; i++) {
		if (this.data[i]["field"] == field) {
			this.data[i]["field"] = newField;
			return (this.autoSend) ? this.send() : true;
		}
	}
	return false;
}

XHR.prototype.deleteField = function (field) {
	var newData = new Array();
	var newIndex = 0;
	var deleted = false;
	for (var i = 0, j = this.data.length; i < j; i++) {
		if (this.data[i]["field"] != field) {
			newData.push(new Array());
			newData[newIndex]["field"] = this.data[i]["field"];
			newData[newIndex]["value"] = this.data[i]["value"];
			newIndex ++;
		} else { deleted = true }
	}
	this.data = newData;
	return (deleted) ? ((this.autoSend) ? this.send() : true) : false;
}

XHR.prototype.setValue = function (field, value) {
	for (var i = 0, j = this.data.length; i < j; i++) {
		if (this.data[i]["field"] == field) {
			this.data[i]["value"] = value;
			return (this.autoSend) ? this.send() : true;
		}
	}
	return false;
}

XHR.prototype.deleteValue = function (field) {
	for (var i = 0, j = this.data.length; i < j; i++) {
		if (this.data[i]["field"] == field) {
			this.data[i]["value"] = new String;
			return (this.autoSend) ? this.send() : true;
		}
	}
	return false;
}

XHR.prototype.send = function (url) {
	if (!url && this.url.length == 0) return false;
	if (!url) url = this.url;
	else this.url = url;

	var preparedData = this.prepareData();

	switch(this.sendMethod){
		case "GET":
			try {
				if (preparedData.length > 0) url += url + "?" + data;
				this.conn.open("GET", url, true);
				this.conn.send(null);
			} catch (e) { return e; }
			break;

		case "POST":
			try {
				this.conn.open("POST", url, true);
				this.conn.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				this.conn.send(preparedData);
			} catch (e) { return e; }
			break;
	}

	if(this.autoReset) this.resetData();
	return true;
	
}


function getElementsBySelector(selector){
//Extracted from nifty.js
	var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];
	if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
		s=selector.split(" ");
		var fs=s[0].split("#");
		if(fs.length==1) return(objlist);
		f=document.getElementById(fs[1]);
		if(f) return(f.getElementsByTagName(s[1]));
		return(objlist);
	}
	if(selector.indexOf("#")>0){ //id selector like "tag#id"
		s=selector.split("#");
		tag=s[0];
		selid=s[1];
    }
	if(selid!=""){
		f=document.getElementById(selid);
		if(f) objlist.push(f);
		return(objlist);
    }
	if(selector.indexOf(".")>0){  //class selector like "tag.class"
		s=selector.split(".");
		tag=s[0];
		selclass=s[1];
    }
	var v=document.getElementsByTagName(tag);  // tag selector like "tag"
	if(selclass=="")
		return(v);
	for(i=0;i<v.length;i++){
		if(v[i].className.indexOf(selclass)>=0)
			objlist.push(v[i]);
    }
	return(objlist);
}





function myinfo_DoFSCommand(command, lang){
	
	window.open('condition'+lang+'.php',"_blank","height=800,width=600,left=50,top=50,scrollbars=yes,resizable=no,menubar=no,status=no,toolbar=no,location=no") ;

}



function myLogo_DoFSCommand(command, lang){
	
	if(lang == '_es'){
		document.form2.action='http://www.bcbg-paris.es';
	}else{
		document.form2.action='http://www.bon-clic-bon-genre.fr';
	}
	document.form2.submit(); ;

}




