var Bona={};
var today = new Date();
var taux_rem = {'1':0, '2':10, '3':10, '4':20, '5':20, '6':30, 'defaut':30};
	
///////////////////////////////////////////Extend
Array.prototype.contains = function(arg){
	tmp = -1;
	if(!this instanceof Array) return tmp;  
	for(var i=0;i<this.length;i++){  
				 if(typeof(this[i])=='object' && this[i].equals && this[i].equals(arg)){return i;}
				else if(this instanceof Array && String(this[i]) == String(arg)){return i;}  
	}
	return tmp;
}

String.prototype.padLeft = function(strChar, intLength){
 var str = this + '';
 while (str.length != intLength) {
  str = strChar + str;
 }
 return str;
}
String.prototype.br2nl= function(){return this.split('<\/br>').join('\n')}
String.prototype.delBr= function(){
	return this.split('<br/>').join('');
}
Date.prototype.addDay = function ( dayAdd ){
    return new Date  ( this.getTime() + dayAdd * 24 * 60 * 60 * 1000 );
}
////////////FUNCTIONS UTILES
function props(obj){
	var tmp='';
	for (var p in obj){
		if(typeof(obj[p])=='object')
			tmp += props(obj[p]);
		else
			tmp += p+' = '+obj[p]+'<br/>';			
	}	
	return tmp;
}
function dbug(t){if($.browser.msie && $.browser.version == '6.0') dbugIE(t); else console.debug(t);}
function dbugIE(t){$('#error').show().html($('#error').show().html()+(t)+'<br/>');}

function pressKey(e,k,fn,args){
	var args = args || [];
	var cod =  e.keyCode || e.charCode;
	if(k==cod){
		fn.apply(null,args.concat([e]));
	}
}
function getDataFormToJson(f) {
	var js = {}; 
	$('[@name]',f).each(function(){
		if(!(this.type=='file' && $.trim(this.value)=='')){
			js[this.name]=$.trim(this.value);
		}
	});
	return js;
}

function resetForm(id_f){
	$('#'+id_f+' :input[@name]').each(function(){
		$(this).val('');
	});
}

/*
class permetant d'executer plusieurs fonctions iteralement sur demande ou sur des evenements d'objet
	pas fini, mais fonctionnel pour les fonctions de base = "addFnct",  "addEvent", "exe", "removeFnct"
*/
var Delegate = function(){
		var ar = new Array();
		var evt = new Array();
		
		//ajoute une fonction au delege
		//fnct : la function a executer
		//ar_args :  tableau contenant les arguments de la function (fnct)
		this.addFnct = function(fnct,ar_args){
			if(typeof(fnct)!='function')throw new Error("Delegate : c'est pas une fonction ça!");
			if(ar.contains(fnct)!=-1) return false;
			ar.push((fnct)?fnct:function(){});
			ar.push((ar_args)?ar_args:[]);			
			this.implEvent();
		}		
		//actuelement supprime toutes les fonctions du delege, a revoir pour supprimer une fnct precis
		this.removeFnct = function(fnct){
			if(!fnct){this.implEvent(true);ar.length = 0;return;}
			//if(n = ar.contains(fnct)!=-1)ar.splice(n,2);//a revoir
			//this.implEvent();
		}		
		//ajoute un evenement au delege
		//el : l'element du dom auquel on va ajouter l'evenement
		//ev : l'evenement a ajouter ATTENTION ne pas mettre 'on' devant juste 'click' ou 'focus' ect...
		this.addEvent = function(el,ev){			
			if(el && typeof(el)!='object')throw new Error("Delegate event : c'est pas un object(élément) ça!");
			if(ev && typeof(ev)!='string') return false;
			var n1=evt.contains(el);
			var n2=evt.contains(ev);
			if(n1==n2-1) return false;
			evt.push(el);
			evt.push(ev);	
			this.implEvent();			
		}		
		//actuelement supprime tous les evenements du delege, a revoir pour supprimer un event precis
		this.removeEvent = function(ev){
			if(!ev){this.implEvent(true);evt.length = 0;ar.length = 0;return;}
			//if(n = evt.contains(ev)!=-1)evt.splice(n,2);//a revoir
			//this.implEvent();			
		}
		//implemente toutes les fonction à tous les evenements des elements
		this.implEvent = function(_sup){			
			for(var i=0;i<evt.length;i++){
				var el = evt[i];
				var ev = evt[++i];
				for(var j=0;j<ar.length;j+=2){
					if(el.addEventListener){
						if(!_sup)el.addEventListener(ev, ar[j], false); else{el.removeEventListener(ev, ar[j], false);}
					}else if (el.attachEvent){
						el.detachEvent("on"+ev, ar[j]);						
						if(!_sup){el.attachEvent("on"+ev, ar[j]);}
					}					
				}					
			}
		}
		//executer les fonctions			
		this.exe = function(){
			for(var i=0;i<ar.length;i++){
				ar[i].apply(null,ar[++i]);
			}				
		}
		//trace les fonctions (string)
		this.getContentFnctString = function(){
			var str='';
			for(var i=0;i<ar.length;i+=2){
				str+=ar[i]+"\n";
			}	
			return str;
		}	
		//trace les evenement (string)
		this.getContentEventString = function(){
			var str='';
			for(var i=0;i<evt.length;i+=2){
				str+= evt[i]+" -- "+evt[i+1]+'\n';
			}	
			return str;
		}			
		this.toString = function(){return "contenu fnct:"+(ar.length/2)+"   "+(this.getContentFnctString())+"\n  contenu event:"+(evt.length/2)+"   "+(this.getContentEventString());}
}

////// popup
function popupCenter(add,winName,popup_width,popup_height,features) {
     var fn = window.open(add,winName,'width='+popup_width+',height='+popup_height+',top='+(screen.height-popup_height)/2+',left='+(screen.width-popup_width)/2+','+features+'');
     fn.focus();
}

//////remplace tous les caractères 'str_old' de 'string' par 'str_new'
function replaceAll(string, str_old, str_new){
	var reg = new RegExp(str_old,"g");	
	return string.replace(reg,str_new);
}

//////supprimer les balises html 
function supBaliseHtml(txt){
	var reg=new RegExp('<[^>]*>', "g");
	return txt.replace(reg,'');
}	

//fait defiller un text trop grand dans un div
function defilBand(div1, div2){	
	var g = $('#'+div1)[0];
	var c = $('#'+div2).width();						
	if(g!=null){		
		var m = g.offsetWidth;			
		g.style.left = "0px";			
		if(m > c)setTimeout(function(){meescr_v2(g,c,m,0,true);}, 3000);
	}
}
function meescr_v2(g,c,m,cu,mg) {
	var dist = 0;
	var change = false;		
	if(mg) {
		dist = cu - (c - m);
	} else {
		dist = 0 - cu;
	}
	if(dist < 1)change = true; 	
	dist = Math.sqrt(dist / 5);	
	if(mg) {
		cu -= dist;
		g.style.left = Math.floor(cu) + "px";
	} else {
		cu += dist;
		g.style.left = Math.floor(cu) + "px";
	}	
	if(change) {
		mg = !mg;
		setTimeout(function(){meescr_v2(g,c,m,cu, mg);}, 1500);
	}else{
		setTimeout(function(){meescr_v2(g,c,m,cu, mg);}, 50);
	}
}	
////////class controlent la liste des pages visitees
/*
if(typeof PageVisited=='object'){
	if(xsl=='hp')PageVisited.clear();
	var PV = PageVisited.loadPageVisited();
	if(PageVisited.no_add.contains('meteo')==-1) PV = PageVisited.savePageVisited(PV);
	
}
*/
var PageVisited = {	
		pv : {'lst':new Array('accueil','loadHp()')},
		no_add:new Array('hp'),
		getPageVisited:function () {			
			/*if($.cookie("PV")!=''){
				this.pv =$.parseJSON(decodeURIComponent($.cookie('PV')));
			}*/
			return this.pv;
		},	
		getLastPageVisited:function () {	
			var obj = {};			
			if(this.pv.lst.length>2){
				obj.nom = this.pv.lst[this.pv.lst.length-4];
				obj.val = this.pv.lst[this.pv.lst.length-3];
			}
			return obj;
		},			
		addPageVisited:function (page,fnct_str) {	
			page = page.toLowerCase();
			if(page!='' && fnct_str != ''){							
				var idx = this.pv.lst.contains(page);
				if(idx!=-1)this.pv.lst.splice(idx,2);
				this.pv.lst.push(page);
				this.pv.lst.push(fnct_str);
			}
			$.cookie('PV', ($.toJSON(this.pv)), {expires: 0, path: '/'});		
		},		
		clear:function(){	
			$.cookie('PV', null);
			this.pv.lst.length = 0;
		},
		display:function(){
			if($('#page_retour')[0])$('#page_retour').remove();
			if(this.pv.lst.length<3)return;
			var tmp='<div class="page_retour" id="page_retour">';
			for(var i=0;i<this.pv.lst.length;i++){
				if(i==0 || i>this.pv.lst.length-7){
					var p =  this.pv.lst[i++];
					var u = this.pv.lst[i];
					tmp+= (i!=this.pv.lst.length-1)?'<span class="colorBleu pointer underline nowrap" onclick="'+u+'">'+p+'</span> > ':'<span class="bold colorOrange nowrap" >'+p+'</span>';
				}
			}		
			tmp+='</div>';
			$('#content').prepend(tmp);
		
		}
}
/*creer un picker date sur l'id du champ passé en paramètre*/
function pickerDate(fnct){
 	 $.datepicker.setDefaults({ 
			dateFormat: "dd-mm-yy", 
			showOn: "both", 
			closeText: 'X',
			prevText: '<<',
			currentText: 'aujourd\'hui',
			monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
			monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun','Jul','Aoû','Sep','Oct','Nov','Déc'],
			dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
			dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
			firstDay: 1,
			changeFirstDay: false,
			highlightWeek: true,
			appendText: '',
			buttonText: 'choisissez une date',
			/*altField: '#emp_email', altFormat: 'yy-mm-dd',*/
			/*numberOfMonths: [1, 2], stepMonths: 2,
			rangeSelect: true, rangeSeparator: ' to ',*/
			/*minDate: new Date(),*/
			/*maxDate: '+1m +1w',*/
			/*onSelect: function(dateText){alert(dateText);},*/
			onClose: (fnct)?fnct:function(d){},
			constrainInput: true,
			nextText: '>>',
			mandatory: true,			
			buttonImage: "image/interface/calendar.gif", 
			buttonImageOnly: true 
		}); 
}
/*creer un double picker date date debut a fin sur l'id du champ passé en paramètre*/
function pickerDateFromTo(jq, fcnt){
 	jq.datepicker({ 
		dateFormat: "dd-mm-yy", 
		showOn: "both", 
		closeText: 'X',
		prevText: '<<',
		currentText: 'aujourd\'hui',
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun','Jul','Aoû','Sep','Oct','Nov','Déc'],
		dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
		dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
		firstDay: 1,
		changeFirstDay: false,
		highlightWeek: true,
		appendText: '(dd-mm-yyyy)',
		buttonText: 'choisissez une date',
		//altField: '#emp_email', altFormat: 'yy-mm-dd',
		numberOfMonths: [1, 2], stepMonths: 2,
		rangeSelect: true,
		rangeSeparator: ' au ',
		//minDate: new Date(2008, 10 - 1, 10),
		//maxDate: '+1m +1w',
		//onSelect: function(dateText){alert(dateText);},
		onClose: fcnt,
		constrainInput: true,
		nextText: '>>',
		mandatory: true,			
		buttonImage: "/img/interface/calendar.gif", 
		buttonImageOnly: true 
	});
}
/*hometétie*/
function resizeToFit(i, el_ph, pMaxWidth, pMaxHeight) {
	var _height, _width;	
	el_ph = $('#'+el_ph);
	_height = i.height;
	_width = i.width;	
	var s = caculHomotetie2(_width, _height, pMaxWidth, pMaxHeight);		
	el_ph.width(s.w+'px').height(s.h+'px').show();
	return s;	
}
function caculHomotetie2(w, h, pMaxWidth, pMaxHeight, force_h) {
	var ratio =1;	
	if(w >= h && w > pMaxWidth ){
		ratio =  pMaxWidth/w;
	}	
	if(h > w && h > pMaxHeight){
		ratio = pMaxHeight/h;
	}
	_width_rat = w*ratio;
	_height_rat = h*ratio;		
	if(_width_rat >= pMaxWidth ){
		ratio =  pMaxWidth/_width_rat;
		_width_rat = _width_rat*ratio;
		_height_rat = _height_rat*ratio;
	}
	if(_height_rat > pMaxHeight){
		ratio = pMaxHeight/_height_rat;
		_width_rat = _width_rat*ratio;
		_height_rat = _height_rat*ratio;
	}
	
	return {'w':_width_rat,'h':_height_rat}	
}

function caculHomotetie(w, h, pMaxWidth, pMaxHeight, force_h) {
	var ratio =1;	
	if(w >= pMaxWidth && !force_h){
		ratio =  pMaxWidth/w;
	}else if(h > pMaxHeight){
		ratio = pMaxHeight/h;
	}	
	_width_rat = w*ratio;
	_height_rat = h*ratio;	
	return {'w':((_width_rat>0)?_width_rat:w),'h':((_height_rat)?_height_rat:h)}	
}

/*****DIV de chargement ou masque transparent*********/
function showDivLoad(id_el){	
	if(!$('#'+id_el)[0])return false;	
	var el=$('#'+id_el);
	var h=el.innerHeight();
	var w=el.innerWidth();
	var dl=null;	
	if($('#'+id_el+'_divloader')[0]){
		dl=$('#'+id_el+'_divloader').height(h+"px").width(w+"px").css({'top':el.offset().top,'left':el.offset().left}).show();
		dl.find('#'+id_el+'_divloaderfond').height(h+"px").width(w+"px");
		return true;
	}
	
	/*
	'<object class="logo_loader" width="40" height="40" swmodifyreport="TRUE" menu="FALSE" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">'+
					'<param value="image/swf/loading.swf" name="src"/>'+
					'<param value="always" name="allowScriptAccess"/>'+
					'<param value="autohigh" name="quality"/>'+
					'<param value="true" name="loop"/>'+
					'<param value="true" name="play"/>'+
					'<param value="false" name="menu"/>'+
					'<param value="transparent" name="wmode"/>'+
					'<embed width="40" height="40" allowscriptaccess="always" wmode="transparent" quality="autohigh" loop="true" play="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave" swmodifyreport="TRUE" menu="FALSE" src="/img/swf/loading.swf"/>'+
					'</object>'
	*/
	dl=$('<div id="'+id_el+'_divloader"  class="divloader" >'+
				'<div id="'+id_el+'_divloaderfond" class="divloaderfond"></div>'+
				'<div id="'+id_el+'_divloaderlogo" class="divloaderlogo" >'+
				'<img src="image/interface/load1.gif" />'+
				'</div>'+
		'</div>');	
	pos = el.offset();
	dl.css({'top':pos.top,'left':pos.left,'margin':0,'padding':0});
	$(document.body).append(dl.show());
	if($.browser.msie && $.browser.version == '6.0')$('#'+id_el+'_divloaderfond').height(h+'px').width(w+'px');$('#'+id_el+'_divloader').height(h+'px').width(w+'px');
	return true;
}
function hideDivLoad(id_el){
	if(!$('#'+id_el)[0])return false;		
	$('#'+id_el+'_divloader').hide();
}

function showMask(id_el, add_el){	
	if(!$('#'+id_el)[0])return false;	
	var el = $('#'+id_el);
	var h = el.innerHeight();
	//h -= 10;
	var w = el.innerWidth();
	var dl = null;	
	if($('#'+id_el+'_mask')[0]){
		dl = $('#'+id_el+'_mask').height(h+"px").width(w+"px").css({'top':el.top,'left':el.left}).show();		
		return true;
	}	
	dl = $(add_el+'<div id="'+id_el+'_mask"  class="divloaderfond" ></div>');
	//if(add_el)dl.append($('#'+add_el).show());
	dl.css({'top':0,'left':0,'margin':0,'padding':0});
	el.prepend(dl.show());
	if($.browser.msie && $.browser.version == '6.0')$('#'+id_el+'_mask').height(h+'px').width(w+'px');$('#'+id_el+'_mask').height(h+'px').width(w+'px');
	//alert($('#'+id_el+'_divloaderfond').height());
	return true;
}
function hideMask(id_el){
	if(!$('#'+id_el)[0])return false;		
	$('#'+id_el+'_mask').hide();
}

function openSlide(id,fn){
	var el = $('#'+id);
	if(typeof el.attr('class') == 'undefined' || el.attr('class').indexOf('wait')==-1){
		el.addClass('wait');
		el.animate({width: 'toggle'},"normal", function(){
			el.removeClass('wait');
			if(fn)fn.apply(null,[id]);
		});
	}
}

/***********************/
function displayMenu2(bol,fn){
	$('#menu2').html('');	
	$('#content_body > table td.m2').css({'display':(bol)?'':'none'});		
}	
function colorSelectSwitchLi(li, c_css){
	$(li).parent().find('li span').removeClass(c_css);
	if(li != null && $(li).is('li') && $('span',li)[0])$('span',li).addClass(c_css);
	select_menu2_li_gal = null;
}

function openEmail(type, options) {
	var opt = (options)?'?':'';
	for(var p in options)opt += p+'='+options[p]+'&';
	location.href='mailto:'+type+'@naturesejours.com'+opt;
	return false;
}
function slideToggle(jq, fn) {
	if(jq.attr('class').indexOf('wait')==-1){
		jq.addClass('wait');
		jq.slideToggle('speed',function(){jq.removeClass('wait');if(fn && typeof fn=='function')fn.apply(null,[this]);});
	}
}
function textToggle(jq) {
	if(!jq.attr('sw_txt'))alert('pas de switch texte');
	var tmp = jq.text();
	jq.text(jq.attr('sw_txt'));	
	jq.attr('sw_txt',tmp);
}
function reloadImg(jq){
	jq.each(function(){
		if(this){
			this.src=this.src+'?v='+today.getTime();
		}
	});	
}

function showError(el_cont,mess){	
	if($('#'+el_cont+' .msg')[0])$('#'+el_cont+' .msg').hide();
	$('#'+el_cont+' .error').html(mess).fadeIn(250,function(){
	   var t = this;
	   clearTimeout(tmp_error[t]);
	   tmp_error[t] = setTimeout(function(){$(t).fadeOut(250,function(){$(t).removeAttr('style');}).removeAttr('style');},15000)
	});
}
function showMsg(el_cont,mess){	
	if($('#'+el_cont+' .error')[0])$('#'+el_cont+' .error').hide();
	$('#'+el_cont+' .msg').html(mess).fadeIn(250,function(){
	   var t = this;
	   if(tmp_msg[t])clearTimeout(tmp_msg[t]);
	   tmp_msg[t] = setTimeout(function(){$(t).fadeOut(250,function(){$(t).removeAttr('style');}).removeAttr('style');},15000);
	});
}

function checkPagination(p, total_p){
	if( total_p< 2 || total_p == '')$('#pagination').hide();
	if(p>1)$('#prev').addClass('lien colorBleuT '); else $('#prev').removeClass('lien colorBleuT ' );
	if(p<total_p)$('#next').addClass('lien colorBleuT '); else $('#next').removeClass('lien colorBleuT ');		
}

function checkMoveMenu2(){
	if(document.getElementById('move_menu2')){
		 $('#move_menu2').scrollFollow({
			offset: 20,
			container: 'menu2'
			});
	}else{
		$(window)[0].onscroll = null;
	}
}

function addFavoris() {
	if ($.browser.msie){
		window.external.AddFavorite("http://www.naturesejours.com/","Nature s�jours");
	}else{
		window.sidebar.addPanel("Nature s�jours","http://www.naturesejours.com/","");
	}
} 
/************AJAX**********/
Bona.callBackAways = function(){
	checkMoveMenu2();
}

Bona.reqAjax = function(r){
	if(typeof $('#'+r.el_load)[0].wait == 'undefined' || $('#'+r.el_load)[0].wait==0){
		//$('body > div.divloader').remove();
		showDivLoad(r.el_load);
		try{
			$.ajax({
				dataType: r.data_type,
				type: r.act,
				url: r.url,
				data: r.params,
				password: 'nature',
				beforeSend: function(){$('#'+r.el_load)[0].wait=1;},
				success: function(done){	
					if(r.data_type=='html'){	
						$("#"+r.el_fill).html(done);
					}else{
						//r.call_arg.length=0;
						r.call_arg.unshift(done);									
					}						
				},
				complete: function(rep){
					hideDivLoad(r.el_load);	
					if(typeof r.call == 'function' )r.call.apply(null,r.call_arg);
					if(r.data_type=='html')Bona.callBackAways();
					$('#'+r.el_load)[0].wait=0;
					if(r.data_type=='html' && $.browser.msie && $.browser.version == '6.0' && typeof parseStylesheets!='undefined')parseStylesheets();			
				},
				error: function(rep){
					alert('ajax error');
					dbug(rep.responseText);
					dbug(rep);
					Bona.callBackAways();
					if(r.data_type=='html')$("#"+r.el_fill).html("une erreur est survenue<br/>veuillez recommencer");
					hideDivLoad(r.el_load);
				},
				timeout: function(rep){
					alert('ajax timeout '+rep);
					Bona.callBackAways();
					if(r.data_type=='html')$("#"+r.el_fill).html("timeout<br/>veuillez recommencer");
					hideDivLoad(r.el_load);
				}
			});	
		}catch(e){
			alert(e);	
		}
	}
}

Bona.reqAjaxPostFileUpload = function(r){
	showDivLoad(r.el_load);	
	try{
		$.ajaxFileUpload({						 
			url: r.url,
			secureuri:true,
			old_id_form:(typeof(r.id_form)=='undefined')?'':r.id_form,
			fileElementId:r.params,			
			dataType: 'json',
			success: function(done, status){
				if(typeof r.call == 'function' ){
					//r.call_arg.length=0;
					r.call_arg.unshift(done);		
				}
			 },
			complete: function(rep){
				hideDivLoad(r.el_load);
				if(typeof r.call == 'function')r.call.apply(null,r.call_arg);
			 },
			error: function(done, status, e){
				dbug(done.responseText);
				dbug(status);
				dbug(e);
				alert('ajax file error');
				hideDivLoad(r.el_load);
			 }
		});	
	}catch(e){
		alert(e);	
	}
}

/*****PANIER***/

Bona.Article=function(id_art,ref,color,qte){
	this.id_art=id_art;
	this.qte=(qte)?qte:1;
	this.ref=ref;
	this.color=color;	
	this.hashcode = this.id_art+''+this.ref+''+color;
	this.equals = function(hashcode){
		return (this.hashcode==hashcode);
	}
}
Bona.Panier=function(){
	var refs=new Array();		
	this.add=function(id_art,ref,color){
		var n = refs.contains(id_art+''+ref+''+replaceAll(color, ' ', ''));	
		if(this.totalQte(id_art) >= Bona.panier.nb_exemp)return;
		if(n!=-1){					
			(refs[Number(n)]).qte++; 
		}else{
			refs.push(new Bona.Article(id_art,ref,replaceAll(color, ' ', '')));
		}
		this.setArtCookie();
		
	}	
	this.remove=function(id_art,ref,color){		
		var n = refs.contains(id_art+''+ref+''+replaceAll(color, ' ', ''));
		if(n!=-1)if((refs[Number(n)]).qte==1)refs.splice(n,1); else (refs[Number(n)]).qte--;
		this.setArtCookie();
	}	
	this.removeArt=function(id_art,ref,color){
		var n = refs.contains(id_art+''+ref+''+replaceAll(color, ' ', ''));
		if(n!=-1)refs.splice(n,1);
		this.setArtCookie();
	}	
	this.clear=function(){refs.length=0;$.cookie('pan','',{path: '/'});}
	this.toString=function(){
		$.each(refs,function(i,v){dbug(v);});
	}
	this.getArtCookie=function(){
		if($.cookie('pan')!== null && $.cookie('pan')!='null' && $.cookie('pan')!=''){
			refs.length=0;
			var cook = $.parseJSON(decodeURIComponent($.cookie('pan')));
			$.each(cook, function(k,v){
							refs.push(new Bona.Article(v.id_art,v.ref,v.color,v.qte));
						});
		}	
	}
	this.totalQte=function(id_art){
		tmp = 0;
		$.each(refs,
			 function(i,v){
				 if(typeof id_art == 'undefined')tmp +=v.qte;
				 else if(id_art == v.id_art)tmp += v.qte;
			 });
		return tmp;
	}
	this.setArtCookie=function(){
		//$.cookie('pan', $.toJSON(refs), {expires: 30, path: '/'});
	}
	this.getJson=function(){
		return (refs.length)?$.toJSON(refs):'';
	}
	this.isEmpty=function(){
		return (refs.length==0);
	}
}
Bona.panier = new Bona.Panier();
Bona.panier.getArtCookie();

var sw_photo_time=0;
Bona.swPhoto = function(id_div_img, imgs){
	if(!imgs) return;
	this.id_div_img = $('#'+id_div_img+' img');
	this.nb_img = this.id_div_img.size();
	this.idx = 0;
	this.rd = 0;
	this.arts = new Array();
		
	this.init = function(){
		var t = this;
		this.stop();
		if(imgs.length)
			this.id_div_img.each(function(){
				if(t.idx > imgs.length-1)t.idx=0;
				var img = imgs[t.idx++];
				var id_ar = img.substring(0,img.indexOf('_'));
				t.arts.push(id_ar);
				this.id_art = id_ar;
				this.onclick = function(){t.stop();loadFicheArticle(id_ar);}					
				$(this).attr('src','image/rotation/'+img).fadeIn(250);
			});
			
	}		
	this.next = function(){
		var t = this;
		var id_ar = 0;
		this.id_div_img = $('#'+id_div_img+' img');
		if(this.id_div_img.size()==0){t.stop();return;}
		for(i=0;i<imgs.length;i++){
			if(t.idx > imgs.length-1)t.idx=0;
			img = imgs[t.idx++];
			id = img.substring(0,img.indexOf('_'));
			if(t.arts.contains(id)==-1){
				id_ar = id;
				break;			
			}
		}	
		
		if(id_ar!=0){			
			for(i=0;i<10;i++){
				rand = parseInt(Math.random() * this.nb_img);
				if(this.rd!=rand){
					this.rd = rand;
					break;			
				}
			}		
			$(this.id_div_img[this.rd]).each(function(){			
				this.id_art = id_ar;
				t.arts[t.rd] = id_ar;
				_this = $(this); 		
				$(this).after($(this).clone().hide().attr({'src':'image/rotation/'+img}).fadeIn(250,function(){
					_this.remove();
				}));
				
			});		
		}	
	}	
	this.play = function(time, obj){
		this.stop();	
		sw_photo_time = setInterval(function(){obj.next();},time);	
	}
	this.stop = function(){
		clearInterval(sw_photo_time);	
	}
	this.init();
}
function menu2Init(){
	$('#move_menu2').empty().css('top',0);
	if($('#content_move_menu2')[0]){
		$('#move_menu2').append($('#content_move_menu2').show()).show();
	}else{
		$('#move_menu2').hide();
	}	
	if(typeof select_menu2_li_gal!='undefined' &&  select_menu2_li_gal!=null )colorSelectSwitchLi($('#lst_visu li')[select_menu2_li_gal],'colorBleuC');
}

function smfSelectText(curElement, actOnElement)
{
	// The place we're looking for is one div up, and next door - if it's auto detect.
	if (actOnElement)
		var codeArea = document.getElementById(curElement);
	else
		var codeArea = curElement.parentNode.parentNode.getElementsByTagName('CODE')[0];

	if (!codeArea)
		return false;

	// Start off with my favourite, internet explorer.
	if (document.body.createTextRange)
	{
		var curRange = document.body.createTextRange();
		curRange.moveToElementText(codeArea);
		curRange.select();
	}
	// Firefox at el.
	else if (window.getSelection)
	{
		var curSelection = window.getSelection();
		// Safari is special!
		if (curSelection.setBaseAndExtent)
		{
			curSelection.setBaseAndExtent(codeArea, 0, codeArea, 1);
		}
		else
		{
			var curRange = document.createRange();
			curRange.selectNodeContents(codeArea);

			curSelection.removeAllRanges();
			curSelection.addRange(curRange);
		}
	}

	return false;
}

function parseDate(d1, d2){
	var d_tmp = dat1 = dat2 = new Date();	
	var obj={jour_v_scol:0, jour_h_scol:0, sem_v_scol:0, sem_h_scol:0, total:0, is_weekend: false};
	var tmp_v_scol = new Array(); 
	var tmp_h_scol = new Array();
	var tmp_all_jours = new Array();
	dat1 = d_tmp = $.datepicker.parseDate('dd-mm-yy', d1);
	dat2 = $.datepicker.parseDate('dd-mm-yy', d2);
	var nb_j_consecutif = 0;/*pour definir les semaines */		
	
	while(d_tmp < dat2){
		var bol = false;
		tmp_all_jours.push(d_tmp);			
		for(var o in json_vacances){			
			if(typeof(json_vacances[o])=='object'){
				if(d_tmp.getTime() >= $.datepicker.parseDate('yy-mm-dd', json_vacances[o].DEBUT).getTime() && d_tmp.getTime() < $.datepicker.parseDate('yy-mm-dd', json_vacances[o].FIN).getTime()){
					tmp_v_scol.push(d_tmp);	
					bol = true;				
				}
			}
		}
		if(!bol)tmp_h_scol.push(d_tmp);	
		d_tmp = d_tmp.addDay(1);
	}
	
	/*définition des semaines*/
	var j_suivant = new Date();
	var t = 0; 
	for(var i=0;i<tmp_v_scol.length;i++){			
		if(tmp_v_scol.length > 6){
			
			if(tmp_v_scol[i].getTime() == j_suivant.getTime()){				
				t++;
			}
			if(t==6){
				obj.sem_v_scol++;
				t=0;
				j_suivant = new Date();
			}else{
				j_suivant = tmp_v_scol[i].addDay(1);
			}			
		}
	}	
	obj.jour_v_scol = tmp_v_scol.length - (obj.sem_v_scol * 7);
	
	j_suivant = new Date();
	t = 0; 
	for(var i=0;i<tmp_h_scol.length;i++){			
		if(tmp_h_scol.length > 6){
			
			if(tmp_h_scol[i].getTime() == j_suivant.getTime()){				
				t++;
			}
			if(t==6){
				obj.sem_h_scol++;
				t=0;
				j_suivant = new Date();
			}else{
				j_suivant = tmp_h_scol[i].addDay(1);
			}			
		}
	}	
	obj.jour_h_scol = tmp_h_scol.length - (obj.sem_h_scol * 7);
		
	obj.total = tmp_v_scol.length + tmp_h_scol.length;
	
	/*is weekend*/
	if(tmp_all_jours.length==2 && tmp_all_jours[0].getDay()==5 && tmp_all_jours[1].getDay()==6)obj.is_weekend=true;
	
	/*dbug(obj);*/
	return obj;
}