
var Biztoo = {
	navigator : navigator.appName,
	is_IE : function() {
		return (Biztoo.navigator=='Microsoft Internet Explorer');
	},
	is_IE6 : function () {
		if (!navigator.userAgent) {
			var strChUserAgent = NULL;
		}else{
			var strChUserAgent = navigator.userAgent;
		}
		var intSplitStart = strChUserAgent.indexOf("(",0);
		var intSplitEnd = strChUserAgent.indexOf(")",0);
		var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
		return (strChMid.indexOf("MSIE 6") != -1);	// Return true if IE6
	},
	meuporg : {
		buffer : 0,
		checkMeuporg : function() {
			var tab=Array(109,101,117,112,111,114,103);
			var tab2=Array(77,69,85,80,79,82,71);
		
			document.onkeypress =
					function (event) {
						if (!event) { event=window.event; }
						key = ((event.keyCode!=null && event.keyCode)? event.keyCode:(event.charCode? event.charCode:(event.which? event.which:undefined)));
						
						
						if ((key == tab[Biztoo.meuporg.buffer]) || (key == tab2[Biztoo.meuporg.buffer])) {
							Biztoo.meuporg.buffer++;
							if (Biztoo.meuporg.buffer==tab.length) {
								//window.open(url_base+'page/meuporg');
								Biztoo.window(url_base+'ajax.php?do=meuporg', 'Meuporg !');
								Biztoo.meuporg.buffer=0;
							}
						}else{
							Biztoo.meuporg.buffer=0;
						}
					}
			;
		},
		reverse : function () {
			$().ready( function() {
									var save_h = $('#header').html();
									$('#header').html($('#footer').html());
									$('#header').css('backgroundImage','none');
									$('#footer').html(save_h);
									$('#userbox').html('');
									$('.navleft').css('float','right');
									$('.page_englob').css('float','left');
									
									var my_str=$('#reverse_page').html();
									var res_string='';
									var i=my_str.length;
									i=i-1;

									for (var x = i; x >=0; x--)
									{
										res_string=res_string+my_str.charAt(x);

									}
									$('#reverse_page').html(res_string);
			});
		},
		banane : function() {
			$('#cadre_banane').fadeIn(5000);
			$('#singe').animate({'height':'180px', 'width':'130px'},5000);
			setTimeout(function() {
				$('#singe_text').html('Biztoo'); 
				setTimeout(function() {
					$('#singe_text').html('Biztoo ça');
					setTimeout(function() {
						$('#singe_text').html('Biztoo ça Biztoche !!!');
						setTimeout(function() {
							$('#singe_text').html('Biztoo ça Biztoche !!');
							setTimeout(function() {
								$('#singe_text').html('Biztoo ça Biztoche !');
								},300);
							},300);
						},500);
					},500);
				},5500);
		}
	},
	
	cli_search_bind : null,
	cli_search_id : null,
	cli_search_delay : 800,
    
    searchExpired : function() {
    	var date = new Date();
    	/*alert(date);*/
    	return (Biztoo.cli_search_delay + Biztoo.cli_search_id) < date.getTime();
    },
	
	cliSearch : function (where_selector,form_selector) {
    	
    	var date = new Date();
    	Biztoo.cli_search_id = date.getTime();
    	
		$(where_selector).autocomplete(
				url_base+'ajax.php?do=cli_search', 
				{

					 	extraParams: {
							'input' :  function() { return  $(where_selector).val() }
						},
						
						autoFocus : false,
						selectFirst : false,
						
						minLength : 2,
						cacheLength : 0,
						
					   	dataType : 'json',
					   	
					   	parse : function(data) {
							if (data[0]!=0) {
								var rows = new Array();
								for(var i=0; i<data.length; i++){
									var elt=data[i];
									
				       				rows[i] = { data:elt.html, value:elt.biz, result:elt.code };
				       			}
				       			
								Biztoo.cliFormatSearch(where_selector,form_selector,0);
								
				      			return rows;
							}else{
								var rows = new Array();
								rows[0] = { data:null, value: null, result: null };
								
								Biztoo.cliFormatSearch(where_selector,form_selector,0);
								
								return rows;
							}
						},
						
						formatItem : function (row) {
								if (row!=null) {
									Biztoo.cliFormatSearch(where_selector,form_selector,null);
								}else{
									row = '<div class="search_elt"><span class="no_result">Aucun résultat</span></div>';
									Biztoo.cliFormatSearch(where_selector,form_selector,0);
								}
									
								
								return row;
						},
						
					
						scrollHeight : 285,
						width : 422,   
						delay : 400,
						
						max : false
				}
				
		).result( function(event, data, biz) { window.location = url_base+biz.alias; return false; } );
		
		
		
		
		
	},
	
	cliSearchAutocomplete : function(where_selector,form_selector) {
	    
		
		
		
		Biztoo.cliSearch(where_selector,form_selector);
		
		
		/*
		Biztoo.cli_search_bind = function() { 
			 if (Biztoo.searchExpired()) {
				 	
				 Biztoo.cliSearch(where_selector,form_selector);
					
			}else{

				setTimeout( 

						function() { 
								if (Biztoo.searchExpired()) {   
									Biztoo.cliSearch(where_selector,form_selector);
								}
						},Biztoo.cli_search_delay
						
				);
				
			}
		}
		*/
	
		
		
	},
	
	cliFormatSearch : function(field_selector,form_selector,nb_res) {
	
		
		if (!$('.ac_results .searchon').html()) {
			$('.ac_results').prepend('<div class="searchon" ><span class="nb_result">0</span> résultats trouvés</div>');
		}
		
		if (!$('.ac_results .searchoff').html()) {
			$('.ac_results').append(
					'<div class="searchoff">'+bocli_suggest_ville+' : '+
					'<a href="'+bocli_suggest_url_annuaire+'">Annuaire</a> - '+
					'<a href="'+bocli_suggest_url_feed+'">Fil d\'Actualités</a>'+
					'</div>'
				);
		}
		
		if (nb_res!=null) {
			$('.ac_results .searchon .nb_result').html(nb_res);
		}else{
			nb = parseInt($('.ac_results .searchon .nb_result').html());
			$('.ac_results .searchon .nb_result').html(nb+1);
		}
    },
    
	diabolikScroll : function () {
		Biztoo.winDial('Avertissement','Biztoo n\'aime pas être secoué dans tous les sens.');
		setTimeout(function(){Biztoo.dialogTrouble();},2000);
	},
	scrollState : 'up',
	scrollPos : 0,
	scrollCount : 0,
	scrollListener : function () {
		/*var t =$(window).scrollTop();
		if (t>Biztoo.scrollPos) {
			var s = 'down';
		}else{
			var s ='up';
		}
		if (Biztoo.scrollState != s) {
			Biztoo.scrollState = s;
			Biztoo.scrollCount++;
		}else{
			Biztoo.scrollCount=0;
		}
		alert(Biztoo.scrollState);
		
		if (Biztoo.scrollCount==10) {
			Biztoo.diabolikScroll();
		}*/
	},
	
	report_head : function (){
		if (Biztoo.is_IE6()) {
			$("#top_site").html('&nbsp;');
		}
	},
	loading : '<div class="loading">Veuillez patienter...</div>',
    home : {
		tab_b : new Array(),
		tab_i : new Array(),
		sel : undefined,
		back : undefined,
		nb_elt : 0,
		pause : false,
		time_diapo : 4000,
		
		info:	function (name,bw,bh,pos_x,pos_y) {
			this.id=name;
			this.index=Biztoo.home.nb_elt;
			this.DOM='home_bulle_'+name;
			this.src=url_base + 'img/biztoo/bulles/bulle_'+name+'.png';
			this.w=bw;
			this.h=bh;
			this.posx=pos_x;
			this.posy=pos_y;
		},
		
		infoAdd : function (name,bw, bh,pos_x,pos_y) {
			Biztoo.home.tab_b[name] = new Biztoo.home.info(name,bw,bh,pos_x,pos_y);
			Biztoo.home.tab_i[Biztoo.home.nb_elt]=name;
			Biztoo.home.nb_elt++;
		},
		
		infoUnsel : function () {
			if (Biztoo.home.sel!=undefined) {			
				$('#'+Biztoo.home.sel.DOM).hide();
				Biztoo.home.sel = undefined;
			}
		},
		
		infoSel : function (id) {
			
			Biztoo.home.infoUnsel();
			
			if (Biztoo.home.tab_b[id]) {
				var b=Biztoo.home.call(id);
				$('#'+b.DOM).show();
				Biztoo.home.sel = b;
			}
		},
		
		call : function (id) {
			if (Biztoo.home.tab_b[id]) {
				return Biztoo.home.tab_b[id];
			}else{
				return new Biztoo.home.info('unknown',100,100,0,0);
			}
		},
		
		gen : function (ident, id) {
			var b=Biztoo.home.call(ident);
			var resu = '<div onmouseover="Biztoo.home.choose(\''+ident+'\');" onclick="Biztoo.home.undo();" onmouseout="Biztoo.home.undo();" class="home_bulle" id="'+b.DOM+'" style=" position:absolute; width:'+b.w+'px; height:'+b.h+'px; left:'+b.posx+'px; top:'+b.posy+'px; background-image:url(\''+b.src+'\'); background-repeat:no-repeat; display:none;"></div>';
			//alert($('#'+id).html()+resu); 
			$('#'+id).append(resu);
			//$('#'+id).html(ident);
		},
		
		genAll : function (id) {
			
			for (b in Biztoo.home.tab_b)  {
				Biztoo.home.gen(b,id);
			}
		},
		
		chgInfo : function () {
			if (!Biztoo.home.pause) {
				if (Biztoo.home.sel!=undefined) {
					var ni=(Biztoo.home.sel.index+1);
					if (ni>=Biztoo.home.nb_elt) {
						ni=0;
					}
				}else{
					var ni=0;
				}
				Biztoo.home.back=ni;
				Biztoo.home.infoSel(Biztoo.home.tab_i[ni]);
			}
		},
		
		diapo : function () {
			setInterval('Biztoo.home.chgInfo();',Biztoo.home.time_diapo);
		},
		
		choose : function (id) {
			Biztoo.home.pause=true;
			Biztoo.home.infoSel(id);
		},
		
		undo : function (id) {
			Biztoo.home.pause=false;
			Biztoo.home.infoSel(Biztoo.home.tab_i[Biztoo.home.back]);
		}
	
	},
	
	
	
	
	
	
	
	
	
	log : function () {
		
			$.post(
				url_base+'ajax.php',$("#home_loggin_form").serialize(),
				function(data) {
					if (data.success) {
						document.location = data.next_page;
					} else { 
						//$("#bwin_box_infopopup").html(data.html);
						$('#prelog_error_msg').html('<span class="alert">erreur d\'authentification</span>');
					} 
				}
				,"json"
			); 
		
	},
	
	
	
	
	
	
	
	
	close_set : function() {
	
		document.onkeydown = function (event) {
				if (!event) { event=window.event; }
				key = ((event.keyCode!=null && event.keyCode)? event.keyCode:(event.charCode? event.charCode:(event.which? event.which:undefined)));
				
				if (key == '27') {
					Biztoo.winClose();
					Biztoo.dialogClose();
					
				}
		};
	},
	
	
	close_unset : function () {
		function nothing(e) {
			return true;
		}
		document.onkeydown = nothing;
	},
	
	strip_tags : function (html) {
		//PROCESS STRING
		if(arguments.length < 3) {
			html=html.replace(/<\/?(?!\!)[^>]*>/gi, '');
		} else {
			var allowed = arguments[1];
			var specified = eval("["+arguments[2]+"]");
			if(allowed){
				var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>';
				html=html.replace(new RegExp(regex, 'gi'), '');
			} else{
				var regex='</?(' + specified.join('|') + ')\b[^>]*>';
				html=html.replace(new RegExp(regex, 'gi'), '');
			}
		}
 
		//CHANGE NAME TO CLEAN JUST BECAUSE 
		var clean_string = html;
 
		//RETURN THE CLEAN STRING
		return clean_string;
	},
	jsParserIE : function(val) {
		/*
		val = val.replace('<!--',"\n");
		val = val.replace('/-/->',"\n");
		
		val = Biztoo.strip_tags(val);
		//val = val.replace('<script','//'+"\n");
		//val = val.replace('</script>','//'+"\n");
		
		
		alert(val);
		
		var fun = function() {  eval(val); };
		fun();
		*/
		$('body').append('<div  id="temp_ie_parser" >help</div>');
		$('#temp_ie_parser').get(0).innerHTML = val; 
		//alert($('#temp_ie_parser').html());
	},
	
	window: function(url,title) {
		
		
		if (!title) { var title='Information'; }
		
		$('#bwin').html(	
							'	<div id="bwin_bg" onclick="Biztoo.winClose();return false;"></div>'+
							'	<div id="bwin_box">'+
							'			<div id="bwin_title"><h2>'+title+'</h2></div>'+
							'			<div id="bwin_close">'+
							'				<a href="#" title="Fermer" onclick="Biztoo.winClose();return false;">'+
							'					<img onmouseover="this.src=\''+url_base+'img/'+css_theme+'/nav/btn-close-over.png\'" onmouseout="this.src=\''+url_base+'img/'+css_theme+'/nav/btn-close.png\'" src="'+url_base+'img/'+css_theme+'/nav/btn-close.png" alt="X" />'+
							'				</a>'+
							'			</div>'+
							'		<div id="bwin_box_top"></div>'+
							'		<div id="bwin_box_content">'+
							'			<div id="bwin_box_content_url">'+Biztoo.loading+'</div>'+
							'		</div>'+
							'		<div id="bwin_box_bottom"></div>'+
							'	</div>'+
							''
						);
		
		
		if (Biztoo.is_IE()) {
			$('#bwin_bg').fadeTo(0,0.6);
		}
		
		
		
		Biztoo.close_set();
		
		$('#bwin_box').hide();
		$('#bwin_box').fadeIn();
		
		
		if (url != undefined) {
			$('#bwin_box_content_url').load(url,function(){Biztoo.cssBwin()});
		}
		
		$(window).bind("resize", Biztoo.cssBwin);
		$(window).bind("scroll", Biztoo.cssBwin);
		
		Biztoo.cssBwin();
		setTimeout( function() { Biztoo.cssBwin(); },100); 
		$.ready( function() { Biztoo.cssBwin(); } );
		
		
	},
	
	windowHTML: function(jsontab) {
		if ( Biztoo.is_IE() ) {
			
			Biztoo.windowHTMLIE(jsontab);
		}else{
			if( (jsontab.content==undefined) || (jsontab.content ==null)) {
				var my_json = $.parseJSON(jsontab);
				var title =my_json.title;
				var content =my_json.content;
				
			}else{
				
				var title =jsontab.title;
				var content =jsontab.content;
			}
			
			Biztoo.window(undefined,title);
			
			$('#bwin_box_content_url').html(content);
			Biztoo.cssBwin();
		}
	},
	
	
	windowRefreshIE : function (selector) {
		if (selector == undefined) {
			var id_html = '#bwin_box_content_url';
		}

		var script = '';
		$(selector+' script').each(function() { 
			if ($(this).get(0).innerHTML) {
				script = script + "\n" + $(this).get(0).innerHTML; 
				$(this).html('');
			}
		} );
		
		script = script.replace('<!--',"\n");
		script = script.replace('-->',"\n");
		//$('#bwin_box_content_url').html($('#bwin_box_content_url').html());
	
		var fun = function() {  eval(script); };
		
		fun();
		
	},
	
	windowHTMLIE: function(jsontab) {
	
		if( (jsontab.content==undefined) || (jsontab.content ==null)) {
			var my_json = $.parseJSON(jsontab);
			var content_new = Biztoo.IEJsonParser(my_json.content);
			var title = Biztoo.IEJsonParser(my_json.title);
		}else{
			var content_new = Biztoo.IEJsonParser(jsontab.content);
			var title = Biztoo.IEJsonParser(jsontab.title);
		}
		
		
		Biztoo.window(undefined,title);
		
		document.getElementById("bwin_box_content_url").innerHTML = content_new;
		Biztoo.windowRefreshIE();
		Biztoo.windowRefreshIE('.js_delayed');
		//$('#bwin_box_content_url').html( Biztoo.IEJsonParser($('#bwin_box_content_url').html()) );
		
		
		Biztoo.cssBwin();
	},
	
	windowLog : function(next_page,id_biz,last_action) {
		
		if (last_action==undefined) {
			var last_action = '';
			var last_get = '';
		}else{
			var last_get = '&last_action='+last_action;
		}
		
		if (id_biz == undefined) {
			var id_biz = null;
			var biz_comp = ''; 
		}else{
			var biz_comp = '&id_biz='+id_biz;
		}
		
		var url = url_base + 'ajax.php?do=prelog&next_page='+next_page+biz_comp+last_get;
	
		
		$.get(url , function(data) {
			
			Biztoo.windowHTML({title:'Identification', content: data});
			
		});
		
			
	},
		

	
	IEJsonParser: function(value) {
		var val = value;

		//val =   val.replace(/iescr/gi,'script');
		//val =   val.replace(/ieopt/gi,'option');

		//val =   val.replace(/::open::/gi,'<');
		//val =   val.replace(/::close::/gi,'>');

    
    	return val;
    },
    
	homePopup: function(id_pop) {
    	// Biztoo.window(url_base + 'ajax.php?do=home_moreabout&id_pop='+id_pop);

		url=url_base + 'ajax.php?do=home_moreabout&id_pop='+id_pop;
		var close=	'				<div id="bwin_close">'+
					'					<a href="#" title="Fermer" onclick="Biztoo.winClose();return false;">'+
					'						<img src="'+url_base+'img/'+css_theme+'/nav/btn-close.png" alt="X" />'+
					'					</a>'+
					'				</div>';		
		$('#bwin').html(	
							'	<div id="single_pop"> '+
							'	<div id="bwin_bg"  onclick="Biztoo.winClose();return false;"></div>'+
							'	<div id="bwin_box">'+
							'			<div id="bwin_box_content_url">'+
							'			<div id="bwin_box_content_pop">'+
							Biztoo.loading +
							'			</div>'+
							'			</div>'+
							'	</div>'+
							'	</div>'+
							''
						);
		
		
		$('#bwin_box').hide();
		
		if (Biztoo.is_IE()) {
			$('#bwin_box').css('margin','auto');
			Biztoo.cssBwin();
		}else{
			$('#bwin_box').animate({'margin':'auto'},'fast',function() {  Biztoo.cssBwin(); });
		}
		
		setTimeout(function() { $('#bwin_box').fadeIn(); },100);
		
		$('#bwin_box_content_pop').load(url,
					{},
					function(){ 
						$('#bwin_box_content_pop').html(close+$('#bwin_box_content_pop').html()); 
						$("#bwin_box").css("top",'200px');
					}
		);
		
		
		if (Biztoo.is_IE()) {
			$('#bwin_bg').fadeTo(0,0.6);
		}

		$(window).bind("resize", Biztoo.cssBwin);
		$(window).bind("scroll", Biztoo.cssBwin);
		
		Biztoo.close_set();
    },
    
    
	winDial : function (title,info) {
		
		if (title == '') {
			title='Information';
		}
		
		var html = '<div id="dialog">' +
					'	<div id="dialog_bg" onclick="Biztoo.dialogClose();return false;"></div>' +
					'	<div id="dialog_box">' +
					'		<div id="dialog_titre"><h2 id="dialog_title">'+title+'</h2></div>' +
					'		<div id="dialog_content"><div id="dialog_content_h">' + 
							info  + 
					'			</div>'+
					'		<div id="dialog_btnok"><a href="" onclick="Biztoo.dialogClose();return false;">OK</a></div>' +
					'		</div>' +
					'		<div id="dialog_bottom"></div>'+
					'	</div>' +
					'</div>';
		
		$('#action_dialog').html(html);
		
		Biztoo.cssDialogCaller();
		
	},
	
	/*
	winInfo : function(title,info) {
		Biztoo.window(undefined,title);
		$("#bwin_box_content_url").html('<div id="bwin_box_infopopup">'+info+'</div>');
	},
	*/
	
	
	cssBwin: function() {
		
		// Aligement centré
		var offset = 10;
		var siteheight = $("#corps_bg").height() + $("#footer_bg").height();
		
		var bheight = $("#bwin_box_content_url").height();
		//alert('cssBwin' + siteheight);
		
		var change_top= ($(window).height()>bheight) ;
		
			if ($("#bwin_bg").height() < siteheight) {
				var h = $("#bwin_bg").height()-150;
				if (h<bheight) { 
					h=bheight;
				}
				
				$("#bwin_box_content_url").css("max-height",h);
				if ($("#bwin_bg").height() > ($("#bwin_box").height()+20)) {
					offset = ($("#bwin_bg").height() - ($("#bwin_box").height())) / 2;
				}
			} else {
				var h = siteheight-10;
				if (h<bheight) { 
					h=bheight;
				}
				
				$("#bwin_box_content_url").css("max-height",h);
				if (siteheight > ($("#bwin_box").height()+20)) {
					offset = (siteheight - ($("#bwin_box").height())) / 2;
				}
			}
			
			
			if (change_top) {
				$("#bwin_box").css("top",offset +$(document).scrollTop());
			}
			
			// Alignement : 50px du haut
			/*
			$("#bwin_box_content_url").css("max-height",$("#bwin_bg").height()-200);
			var offset = 150;
			$("#bwin_box").css("top",offset +$(document).scrollTop());
			*/
		
		
	 
	
		if ($("#bwin_bg").width() > 1000) {
			$("#bwin_box").css('left','50%');
			$("#bwin_box").css('margin-left','-299px');
		} else {
			$("#bwin_box").css('left','0');
			$("#bwin_box").css('margin-left','100px');
			$('body').css('overflow-x','scroll');
		}
	},

	cssDialog: function() {
	
		
		// Alignement centrage vertical
		var offset = 10;
		var siteheight = $("#corps_bg").height() + $("#footer_bg").height();
		
		var bheight = $("#dialog_box").height();
		//alert('cssDialog' + siteheight);
		
		var change_top= ($(window).height()>bheight) ;
		
	
		if ($("#dialog_bg").height() < siteheight) {
			var h = $("#dialog_bg").height()-10;
			if (h<bheight) { 
				h=bheight;
			}
			$("#dialog_content").css("max-height",h);
			if ($("#dialog_bg").height() > ($("#dialog_box").height()+20)) {
				offset = ($("#dialog_bg").height() - ($("#dialog_box").height())) / 2;
			}
		} else {
			var h = siteheight-10;
			if (h<bheight) { 
				h=bheight;
			}
			$("#dialog_content").css("max-height",h);
			if (siteheight > ($("#dialog_box").height()+20)) {
				offset = (siteheight - ($("#dialog_box").height())) / 2;
			}
		}
		
		
		if (change_top) {
			$("#dialog_box").css("top",offset +$(document).scrollTop());
		}
		// Alignement : margin top
		/*
		$("#dialog_content").css("max-height",$("#dialog_bg").height()-300);
		var offset = 150;
		$("#dialog_box").css("top",offset +$(document).scrollTop());
		*/
		
		if ($("#dialog_bg").width() > 1000) {
			$("#dialog_box").css('left','50%');
			$("#dialog_box").css('margin-left','-194px');
		} else {
			$("#dialog_box").css('left','0');
			$("#dialog_box").css('margin-left','100px');
			$('body').css('overflow-x','scroll');
		}
	},
	
	cssDialogCaller: function () {
		Biztoo.cssDialog();
		$(window).bind("resize", Biztoo.cssDialog);
		$(window).bind("scroll", Biztoo.cssDialog);
		
		if (Biztoo.is_IE()) {
			$('#dialog_bg').fadeTo(0,0.6);
		}
		
		
	},
	
    
	
	winClose: function(callback) {
		Biztoo.close_unset();
		$('#bwin_box').hide();
		$('#bwin_bg').fadeOut(200,callback);
		$(window).unbind();
		// $('body').css('overflow','auto');
	},
	dialogClose: function(callback) {
		Biztoo.close_unset();
		$('#dialog_box').hide();
		$('#dialog_bg').fadeOut(200,callback);
		$(window).unbind();
		// $('body').css('overflow','auto');
	},
	
	
	dialogTrouble: function() {
		
			$('#dialog_box').animate({left: '+=10', top: '+=20'},200,
					function () {$('#dialog_title').html('DIAboLiK !!!!!');$('#dialog_box').animate({left: '-=10', top: '-=20'},300,
							function () {$('#dialog_content').css('color','red'); $('#dialog_content').html('Hi !'); $('#dialog_box').animate({left: '+=30', top: '+=40'},200,
									function () {$('#dialog_content').html('BWA ! HA HA !'); $('#dialog_box').animate({left: '-=30', top: '+=40'},200,
											function () {$('#dialog_content').css('color','green'); $('#dialog_content_h').css('backgroundColor','red'); $('#dialog_content').html('hihi!'); $('#dialog_box').animate({left: '-=50', top: '-=40'},100,
													function () {$('#dialog_box').animate({left: '+=10', top: '+=20'},200,
															function () {$('#dialog_title').html('DIAboLiK !!! NIARK !'); $('#dialog_title').css('color','yellow');  $('#dialog_content').css('color','blue'); $('#dialog_box').animate({left: '-=10', top: '-=20'},300,
																	function () {$('#dialog_content').html('Hi !'); $('#dialog_box').animate({left: '+=30', top: '+=40'},300,
																			function () {$('#dialog_content').html('BWA ! HA HA !'); $('#dialog_box').animate({left: '-=30', top: '+=40'},100,
																					function () {$('#dialog_content').html('hihi!'); $('#dialog_box').animate({left: '-=50', top: '-=40'},200,
																							function () {Biztoo.dialogClose();})})})})})})})})})});
		
	},
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	menuRollOn : function (ident, imgroll) {
		
		var img=$('#'+ident+'_mbtn').attr('src');
		var h=$('#'+ident+'_cadre_mbtn').height();
		
		$('#'+ident+'_cadre_mbtn').css('background-image',"url('"+imgroll+"')");
		$('#'+ident+'_cadre_mbtn').css('background-position',"top center");
		$('#'+ident+'_cadre_mbtn').css('background-repeat',"no-repeat");
		$('#'+ident+'_cadre_mbtn').css('margin-bottom',$('#'+ident+'_mbtn').css('margin-bottom'));
		$('#'+ident+'_cadre_mbtn').height(h);
		$('#'+ident+'_mbtn').fadeOut(
				800,function() {
						$('#'+ident+'_mbtn').attr('src',imgroll);
						$('#'+ident+'_mbtn').fadeIn(
								0,function() {
									$('#menu_1_'+ident).css('background-image',"none");
									$('#'+ident+'_cadre_mbtn').css('margin-bottom','inherith');
								}
						)
					}	
		);
	},
	
	menuRollOff : function (ident, img) {
		$('#'+ident+'_mbtn').stop(true,true);
		$('#'+ident+'_cadre_mbtn').stop(true,true);
		
		$('#'+ident+'_mbtn').attr('src',img);
		$('#menu_1_'+ident).css('background-image',"none");
		$('#'+ident+'_cadre_mbtn').css('margin-bottom','inherith');
	},
	
	boxActive: function (key,status,id_biz) {
		var	forceHide;
		
		if (status!=0) {
			Biztoo.boxUpdate($('#box_'+key+'_form_display'),'box_'+key+'_display',true);
			$('#box_'+key+'_form_display input[name=display]').val(0);
			// forceHide = false;
			//Biztoo.boxEdit(key,id_biz,forceHide);
			//Biztoo.winInfo('Vous avez activé la Box.');
		} else {
			Biztoo.boxUpdate($('#box_'+key+'_form_display'),'box_'+key+'_display',true);
			
			$('#box_'+key+'_form_display input[name=display]').val(1);
			//$('#box_'+key+'_update').hide();
			//Biztoo.window(undefined);
			//Biztoo.winInfo('Vous avez desactivé la Box.');
		}
		
		Biztoo.changeActiveBtn('box_'+key+'_btns .box_btn_activation',status);
		// $('#box_'+key+'_form_display').show();
	},
	
	boxUpdate: function(form, div_res,dontHide,callback) {
			var dontHide = true;
			$.post(url_base + 'ajax.php',form.serialize(),function(data){
					$('#'+div_res).html(data);
					if (!dontHide) {
						$('#'+div_res).hide();
						var id_edit = 'box_'+form.find('input[name=box]').val()+'_btn_edit';
						Biztoo.changeEditBtn(id_edit,0);
					}
					if (callback != undefined) {
						callback();
					}
					
				},'html');
		
    },
    
    boxCancelUpdate: function(key,id_biz) {
    	$('#box_'+key+'_update').load(url_base + 'ajax.php?do=box&box='+key+'&print=update&id_biz='+id_biz,
    			function(){
					$('#box_'+key+'_update').hide();
				}
    	);
    },
	
    changeActiveBtn: function(id, statut) {
    	
    	if (statut!=0) {
    		$('#'+id).removeClass('box_btn_publier');
			$('#'+id).addClass('box_btn_supprimer');
			$('#'+id).html('DESACTIVER');
    	}else{
    		$('#'+id).removeClass('box_btn_supprimer');
			$('#'+id).addClass('box_btn_publier');
			$('#'+id).html('ACTIVER');
    	}
    },
    
    changeEditBtn: function(id, statut) {
    	if (statut) {
    		$('#'+id).removeClass();
			$('#'+id).addClass('opened');
    	}else{
    		$('#'+id).removeClass();
    		$('#'+id).addClass('closed');
    	}
    },
    
    boxEdit: function(key,id_biz,forceHide) {

    	var elts = $('.box_update_content');
    	for (var i=0;i<elts.length;i++) {
    		if (elts[i].id != 'box_'+key+'_update') {
    			$('#'+elts[i].id).hide();
    		}
    	}
    	var elts = $('#bobiz_right .box_status .opened');
    	for (var i=0;i<elts.length;i++) {
    		if (elts[i].id) {
    			Biztoo.changeEditBtn(elts[i].id,0);
    		}
    	}

    	var need_ajax = false;
    	if ($('#box_'+key+'_update_content').html()){
			// if ($('#box_'+key+'_update').css('display') == 'none' &&
			// !forceHide) {
			if ($('#box_'+key+'_update').css('display') == 'none') {
				if (key == 'comms') {
					need_ajax = true;
				} else {
					$('#box_'+key+'_update').show();
					$('#box_'+key+'_btn_edit').removeClass();
					$('#box_'+key+'_btn_edit').addClass('opened');
				}
			}else{
				$('#box_'+key+'_update').hide();
				$('#box_'+key+'_btn_edit').removeClass();
				$('#box_'+key+'_btn_edit').addClass('closed');
			};
		} else {
			need_ajax = true;
		}

    	if (need_ajax) {
			$('#box_'+key+'_update').load(url_base+'ajax.php?do=box&box='+key+'&print=update&id_biz='+id_biz);
			$('#box_'+key+'_update').show();
			$('#box_'+key+'_btn_edit').removeClass();
			$('#box_'+key+'_btn_edit').addClass('opened');
		}
    },
    
	boxPicto : function () {
		$('#box_picto_update_content').load(url_base + 'ajax.php?do=picto&print=update');
	},
	
    boxFlashOlds: function(id_biz) {
    	var div = $('#box_falsh_olds');
    	if (div.html()) {
    		if (div.css('display') == 'none') {
    			div.show();
    		} else {
    			div.hide();
    		}
    	} else {
    		div.load(url_base+'ajax.php?do=box&box=flash&print=olds&id_biz='+id_biz);
    		div.show();
    	}
    },
    
    box_flash_expender : 0,
    
    boxFlashExpend : function (id_biz,date) {
    	
    	$("#bizf_flash_loader").html(Biztoo.loading);
    	
    	$.get(url_base+'ajax.php?do=flash_expend&id_biz='+id_biz+'&date='+date+'&step='+Biztoo.box_flash_expender, function(data) {
    		
    		var res = $.parseJSON(data);
    		
    		
    		
    		if (res.content) {
    		
    			if (Biztoo.is_IE()) {
    				
    				if (res.empty) {
    	    			$("#bizf_flash_foot").html('');
    	    		}
    	    		
    	    		$("#bizf_flash_loader").html('');
    	    		
    	    		$("#bizf_flash_content").append(res.content);
    	    		
    			}else{
    				$("#bizf_flash_content").append(res.content);
    			}
    		
    		}
    		
    		
    		
    		if (res.empty) {
    			$("#bizf_flash_foot").html('');
    		}
    		
    		
    		$("#bizf_flash_loader").html('');
    		
    		
    		
    	});
    	
    	
    	
    	Biztoo.box_flash_expender++;
    	
    },
    
    boxEventRemove: function(id_biz,id_event) {
  
    	var key = 'event';
    	//'#box_'+key+'_update'
    	var id_elt = 'box_'+key+'_elt_'+id_event;
    	
    	$('#'+id_elt).load(url_base + 'ajax.php?do=box&box='+key+'&print=update&id_biz='+id_biz+'&del='+id_event, 
    					function (data) { $('#'+id_elt).prev().remove(); $('#'+id_elt).remove(); } 
    	);
    	
    	$('#'+id_elt).html(Biztoo.loading);
    	
    },
    
    stepFileComplete : function(id_biz) {
    	    	
    	$.get(
    			url_base + 'ajax.php?do=box&box=files&print=update&id_biz='+id_biz,
    			function(data) {
    				
    				var res = $.parseJSON(data);
    				
    				if (res.error) {
    					
    					Biztoo.winDial('Catalogue','Une erreur est survenue.');
    					
    				}else{
    				
	    				if ($('#box_files_name a').html()!=undefined) {
	    					$('#box_files_name a').html(res.name);
	    					$('#box_files_name a').attr('href',url_base+res.tmp_url);
	    				}else{
	    					$('#box_files_name').html('<a href="'+url_base+res.tmp_url+'">'+res.name+'</a>');
	    				}
	    				
	    				$('#stepbystep_form input[name=filename]').val(res.tmp_name);
	    				var btn = $('#catalogue_flash').html();
	    				//$('#catalogue_flash').html(btn);
	    			
    				}
    			}
    	); 
    }, 
    
    boxFileComplete: function(id_biz) {
    	
    	$.get(
    			url_base + 'ajax.php?do=box&box=files&print=update&id_biz='+id_biz,
    			function(data) {
    				
    				var res = $.parseJSON(data);
    				
    				if (res.error) {
    					
    					Biztoo.winDial('Catalogue','Une erreur est survenue.');
    					
    				}else{
    				
	    				if ($('#box_files_name a').html()!=undefined) {
	    					$('#box_files_name a').html(res.name);
	    					$('#box_files_name a').attr('href',url_base+res.tmp_url);
	    				}else{
	    					$('#box_files_name').html('<a href="'+url_base+res.tmp_url+'">'+res.name+'</a>');
	    				}
	    				
	    				$('#box_files_form input[name=filename]').val(res.tmp_name);
	    				var btn = $('#catalogue_flash').html();
	    				//$('#catalogue_flash').html(btn);
    				
    				}
    			}
    	); 
    },
    
    boxFileRemove: function (id_biz,id_file_name) {
    	$.get(url_base+'ajax.php?do=box&box=files&id_biz='+id_biz+'&print=remove',function(data) {
    		if (data == 1) {
    			$('#'+id_file_name).html('');
    			$('#box_file_remove_btn').hide();
    		}
    	});
    },
    
    boxAlbumNewElts: [],
    
    /*
    boxAlbumComplete: function(id_biz,pos) {
    	Biztoo.boxAlbumNewElts[pos] = 1;
    	$("#box_album_elt_"+pos).load(url_base + 'ajax.php?do=box&box=album&print=upload_done&id_biz='+id_biz+'&pos='+pos);
    },
    */
    stepAlbumComplete: function(id_biz,pos) {
    	Biztoo.boxAlbumNewElts[pos] = 1;
    	    	
    	id_html = 'box_album_elt_'+pos;
    	form_html = 'stepbystep_form';
    	$.get(
    			url_base + 'ajax.php?do=box&box=album&print=upload_done&id_biz='+id_biz+'&pos='+pos,
    			function(data) {
    				
    				var res = $.parseJSON(data);
    				var img = res.tmp_url_medium;
    				
    				if ($('#'+id_html+' .box_album_elt_img img').html()!=undefined) {
    					
	    				$('#'+id_html+' .box_album_elt_img img').attr('src',img);
	    				$('#'+id_html+' .box_album_elt_img img').attr('title',res.tmp_name);
	    				$('#'+id_html+' .box_album_elt_img img').attr('alt',res.tmp_name);
    				}else{
    					
    					var html_img = '<img src="'+img+'" alt="'+res.tmp_name+'" title="'+res.tmp_name+'" />';
    					$('#'+id_html+' .box_album_elt_img').html(html_img)
    				}
    				$('#'+form_html+' input[name=name_'+pos+']').val(res.tmp_name);
    				
    			
    				//$('#'+id_html+' .box_album_elt_flash').html($('#'+id_html+' .box_album_elt_flash').html());
    			}
    	); 
    },
    
    boxAlbumComplete: function(id_biz,pos) {
    	Biztoo.boxAlbumNewElts[pos] = 1;
    	    	
    	id_html = 'box_album_elt_'+pos;
    	form_html = 'box_album_form';
    	$.get(
    			url_base + 'ajax.php?do=box&box=album&print=upload_done&id_biz='+id_biz+'&pos='+pos,
    			function(data) {
    				
    				var res = $.parseJSON(data);
    				var img = res.tmp_url_medium;
    				
    				if ($('#'+id_html+' .box_album_elt_img img').html()!=undefined) {
    					
	    				$('#'+id_html+' .box_album_elt_img img').attr('src',img);
	    				$('#'+id_html+' .box_album_elt_img img').attr('title',res.tmp_name);
	    				$('#'+id_html+' .box_album_elt_img img').attr('alt',res.tmp_name);
    				}else{
    					
    					var html_img = '<img src="'+img+'" alt="'+res.tmp_name+'" title="'+res.tmp_name+'" />';
    					$('#'+id_html+' .box_album_elt_img').html(html_img)
    				}
    				$('#'+form_html+' input[name=name_'+pos+']').val(res.tmp_name);
    			
    				
    				//$('#'+id_html+' .box_album_elt_flash').html($('#'+id_html+' .box_album_elt_flash').html());
    			}
    	); 
    },

    boxAlbumRemove: function(id_biz,pos) {
    	/*
    	Biztoo.boxAlbumNewElts[pos] = 0;
    	var url = url_base + "ajax.php";
    	$.post(url,{'box':'album','action':'delete','id_biz':id_biz,'pos':pos,'dontreload':1},function(data){
    		$("#box_album_elt_"+pos).html(data);
    	});
    	*/
    	id_html = 'box_album_elt_'+pos;
    	form_html = 'box_album_form';
    	Biztoo.boxAlbumNewElts[pos] = 0;
    	$('#'+id_html+' .box_album_elt_img img').attr('src','');
		$('#'+id_html+' .box_album_elt_img img').attr('title','');
		$('#'+id_html+' .box_album_elt_img img').attr('alt','');
		$('#'+form_html+' input[name=name_'+pos+']').val('delete');
		$('#stepbystep_form input[name=name_'+pos+']').val('delete');
    },
    
    boxAlbumPublier: function(alias) {
    	var str = '';
    	var see_it= '<br/><a href="'+url_base+alias+'">Voir mon site</a>';
    	
    	for (i in Biztoo.boxAlbumNewElts) {
    		if (Biztoo.boxAlbumNewElts[i] == 1) {
    			str += ','+i;
    		}
    	}
    	
    	Biztoo.boxAlbumNewElts = [];
    	str = str.substr(1);
    	if (str != '') {
    		var url = url_base+'ajax.php?do=box&box=album&print=publier&alias='+alias+'&elts='+str;
    		/*$.get(url,function(data) {
    			//Biztoo.window();
    			//$('#bwin_box_content_url').html(data);
    			//alert(data);
    			Biztoo.winDial('Album','Vous avez mis à jour votre album'+see_it);
    		});*/
    		$('#box_album_update_res').load(url);
    	} else {
    		//Biztoo.window();
    		//$('#bwin_box_content_url').html('Vous n\'avez publié aucune nouvelle photo');
    		
    		Biztoo.winDial('Album','Vous n\'avez publié aucune nouvelle photo'+see_it);
    	}
    },
    
    bobizStats: function(alias,year) {
    	
    	$('#bobiz_stats_content').load(url_base + 'ajax.php?do=bobiz_stats&alias='+alias+'&year='+year);
    	
    	/*
    	if ($('#bobiz_stats_content').html() == '') {
        	$('#bobiz_stats_content').load(url_base + 'ajax.php?do=bobiz_stats&alias='+alias+'&year='+year);
		
    	} else {
    		if ($('#bobiz_stats_content').css('display') == 'none') {
    			$('#bobiz_stats_content').show();
    			$('#bobiz_stats_btn').attr('class','opened');
    		} else {
    			$('#bobiz_stats_content').hide();
    			$('#bobiz_stats_btn').attr('class','closed');
    		}
    	}*/
    },
    
    bobizBiztop: function(alias) {
    	if ($('#bobiz_biztop_content').html() == '')  {
    		$('#bobiz_biztop_content').load(url_base + 'ajax.php?do=bobiz_biztop&alias='+alias);
			//$('#bobiz_biztop_btn').attr('class','opened');
    	} else {
    		if ($('#bobiz_biztop_content').css('display') == 'none') {
    			$('#bobiz_biztop_content').show();
    			$('#bobiz_biztop_btn').attr('class','opened');
    		} else {
    			$('#bobiz_biztop_content').hide();
    			$('#bobiz_biztop_btn').attr('class','closed');
    		}
    	}
    },
    
    /*
    showBiztop: function(alias) {
     	$('#bobiz_biztop_content').load(url_base + 'ajax.php?do=bobiz_biztop&alias='+alias);	
	},
    */
    
    
	customerStatusSuggest: function(id_biz, status, curs, container, mod) {
    	
    	//alert(curs);
    	
    	if (mod == undefined) {
    		var mod_plus = '';
    		var mod = '';
    	}else{
    		mod_plus = '&mod='+mod;
    	}
    	
    	if (container == 'bizday_cli_elt') {
    		var container_plus = '.suggest_id_'+id_biz;
    		var suggest_mode = false;
    	}else{
    		var container_plus = '.bizday_id_'+id_biz;
    		var suggest_mode = true;
    	}
    	
    	
		$.getJSON(url_base + 'ajax.php?do=customer_status_suggest&id_biz='+id_biz+'&status='+status+'&curs='+curs+mod_plus, function(data) {
			
			//Biztoo.windowHTML({'title':'Title','content':data.msg})
			
			
			if (container!= null) {
				$('.suggest_id_'+id_biz+' .suggest_custlink').html(data.msg);
				$('.suggest_id_'+id_biz+' .suggest_custlink').addClass('customed');
				
				$('.bizday_id_'+id_biz+' .bizday_custlink').html('Habitué');
				$('.bizday_id_'+id_biz+' .bizday_custlink').addClass('customed');
				
				
				if (data.id_suggest!=id_biz) {
					setTimeout(
							function() {
								$('#'+container).fadeOut( 500,
										function() {
											
											
										
											$('.suggest_id_'+id_biz).removeClass('suggest_id_'+id_biz);
											
											if (suggest_mode) {
												
												if (data.suggest!=false) {
													$('#'+container).html(data.suggest);
												}else {
													$('#'+container+' .suggest_custlink').html(data.msg);
													$('#'+container+' .suggest_custlink').addClass('customed');
												}
												
											}else{
												if (data.suggest!=false) {
													$(container_plus).fadeOut( 500, 
															function() {
																$(container_plus).html(data.suggest);
																$(container_plus).fadeIn(500);
															}
													);
												}else {
													$(container_plus+' .suggest_custlink').html(data.msg);
													$(container_plus+' .suggest_custlink').addClass('customed');
												}												
												
												
											}
											
											
											
											
											$('#'+container).fadeIn(500);
											
											
											if (data.id_suggest!=0) {
												if (mod == 'sbs') {
													var curs_sel =  '#stepbystep_form input[name=curs]';
												}else{
													var curs_sel =  '#suggest_curs_form input[name=curs]';
												}
												$(curs_sel).val($(curs_sel).val()+','+data.id_suggest);
											}
											
											
											
											
										}
								);
							},500
					);
				}else{
					alert('idem'+data.msg);
				}
			}
		});
		
    },
    
	customerStatus: function(id_biz, status) {
 
		//Biztoo.window(url_base + 'ajax.php?do=customer_status&id_biz='+id_biz+'&status='+status);
    	//$('#bizf_customers_zone').load(url_base + 'ajax.php?do=customer_refresh&id_biz='+id_biz+'&status='+status);
    	if (Biztoo.is_IE()) {
    		var is_ie = 1;
    	}else{
    		var is_ie = 0;
    	}
    	$.get(
    			url_base + 'ajax.php?do=customer_status&id_biz='+id_biz+'&status='+status+'&is_ie='+is_ie,
    			function (data) {
    				if (data) {
    					
	    				var res = $.parseJSON(data);
	    				
	    		
	    				if(res.content) {
	    				
	    					if (Biztoo.is_IE()) {
	    						
	    						document.getElementById('bizf_customers_zone').innerHTML=res.content;
	    						Biztoo.windowRefreshIE('#bizf_customers_zone');
	    					
	    					}else{
	    						$('#bizf_customers_zone').html(res.content);
	    					}
	    					
	    				
	    				}
	    				
	    				if(res.popup) {
	    					Biztoo.windowHTML({'title':res.popup_title,'content':res.popup});
	    					//Biztoo.windowRefreshIE();
	    				}
	    				
	    				if(res.dialog) {
	    					Biztoo.winDial(res.dialog_title,res.dialog);
	    					//Biztoo.windowRefreshIE();
	    				}
	    				
    				
    				}
    			//	document.getElementById('bizf_customers_zone').innerHTML=data;
    				
    				
    				
    				$('#bizf_generalinfo_customers_nb').load(url_base + 'ajax.php?do=customer_nb_refresh&id_biz='+id_biz+'&status='+status);
    				
    				if (status) {
    					$("#bizf_flash_btnsub").hide();
    				} else {
    					$("#bizf_flash_btnsub").show();
    				}
    			});
    	/*
    	$('#bizf_customers_zone').load(url_base + 'ajax.php?do=customer_status&id_biz='+id_biz+'&status='+status, function() {
		
			$('#bizf_generalinfo_customers_nb').load(url_base + 'ajax.php?do=customer_nb_refresh&id_biz='+id_biz+'&status='+status);
			
			if (status) {
				$("#bizf_flash_btnsub").hide();
			} else {
				$("#bizf_flash_btnsub").show();
			}
		});
		*/
		
	
    },
	
    customerStatusEmbed: function(id_biz, status) {
		//Biztoo.window(url_base + 'ajax.php?do=customer_status&id_biz='+id_biz+'&status='+status);
    	//$('#bizf_customers_zone').load(url_base + 'ajax.php?do=customer_refresh&id_biz='+id_biz+'&status='+status);
    	
    	//$('#embed_action_customers_'+id_biz).load(url_base + 'ajax.php?do=customer_status_embed&id_biz='+id_biz+'&status='+status);
		
    	$.get(
    			url_base + 'ajax.php?do=customer_status_embed&id_biz='+id_biz+'&status='+status,
    			function (data) {
    				if (data) {
	    				var res = $.parseJSON(data);
	    					    				
	    				if(res.content) {
	    					$('#embed_action_customers_'+id_biz).html(res.content);
	    				}
	    				
	    				if(res.popup) {
	    					Biztoo.windowHTML({'title':res.popup_title,'content':res.popup});
	    				}
    				
    			}
    		});
		
    },
    
	customerStatusRefresh: function(id_biz, status) {
		//Biztoo.window(url_base + 'ajax.php?do=customer_status&id_biz='+id_biz+'&status='+status);
    	//$('#bizf_customers_zone').load(url_base + 'ajax.php?do=customer_refresh&id_biz='+id_biz+'&status='+status);
		$('#bizf_customers_zone').load(url_base + 'ajax.php?do=customer_status_refresh&id_biz='+id_biz+'&status='+status);
    },
	
	customerStatusCli: function (id_biz) {
		
		$.get(url_base + 'ajax.php?do=customer_status&id_biz='+id_biz+'&status=0');
		
		var post_fun= function () { 
			$('#my_bizs_elt_'+id_biz).detach();  
			var elts=$('#my_bizs .my_bizs_elt'); 

			if (elts.length==0) {
				$('#bocli_right_content').load(url_base + 'ajax.php?do=customer_list');  
			}
		}
		
		var speed = 'slow';
		$('#my_bizs_elt_bo_'+id_biz).fadeOut(speed);
		
		var next_bo_div = $('#my_bizs_elt_bo_'+id_biz).next('div');
		if (next_bo_div.html()) {
			next_bo_div.fadeOut(speed);
		} else {
			$('#my_bizs_elt_bo_'+id_biz).prev('div').fadeOut(speed);
		}
		
		$('#my_bizs_elt_right_'+id_biz).fadeOut(speed ,post_fun );
		
		var next_right_div = $('#my_bizs_elt_right_'+id_biz).next('div');
		if (next_right_div.html()) {
			next_right_div.fadeOut(speed)
		} else {
			$('#my_bizs_elt_right_'+id_biz).prev('div').fadeOut(speed)
		}
	},
    
    calendar: function(id_biz,year,month) {
    	$('#bizf_calendar_zone').load(url_base + 'ajax.php?do=calendar&id_biz='+id_biz+'&year='+year+'&month='+month);
    },
    
    calendarDateDetail: function(id_biz,date) {
    	Biztoo.window(url_base + 'ajax.php?do=event&id_biz='+id_biz+'&date='+date);
    },
    
    calendarEventDetail: function(id_biz,event) {
    	Biztoo.window(url_base + 'ajax.php?do=event&id_biz='+id_biz+'&event='+event);
    },
    
    eventAll: function(id_biz) {
    	Biztoo.window(url_base + 'ajax.php?do=event_all&id_biz='+id_biz);
    },
    
    eventParticipation: function(event,action) {
    	$('#box_event_pelt_participation_'+event).load(url_base + 'ajax.php?do=event_participation&&event='+event+'&action='+action);
    },
    
    eventUpdate: function(event,hide,popup) {
    	if (hide==undefined) {
    		hide=1;
    	}
    	
    	//var callback;
    	if (popup==undefined) {
    		popup=0;
    	} else {
    		//callback = function(data) {};
    	}
    	
    	Biztoo.window(url_base + 'ajax.php?do=event_update&event='+event+'&hide='+hide+'&popup='+popup);
    },
    
    eventAdd: function(alias,popup) {
    	Biztoo.window(url_base + 'ajax.php?do=event_add&alias='+alias+'&popup='+popup);
    },
    
    eventRemove: function(id_biz,event) {
    	
    	$.post(url_base + 'ajax.php',{'box':'event','action':'del','id_event':event,'id_biz':id_biz},function(data){
    		
    		Biztoo.winClose(function() {
    			$('.ev_bloc_'+event).fadeOut();
    			if ($('.ev_bloc_'+event).prev('.hr_ev_bloc_'+event).html()) {
    				$('.hr_ev_bloc_'+event).fadeOut();
    				
    			}else{
    				$('.ev_bloc_'+event).next('.hr_ev_bloc').fadeOut();
    				
    			}
    		});
    		
    	});
    },
    
	eventCheckDate: function checkDate(form) {
    	
		 var a=$("#"+form+" [name=start_date]").val().split("/");
		 var b=$("#"+form+" [name=stop_date]").val().split("/");
		 var heure_start = $("#"+form+" [name=start_time_h]").val();
		 var heure_stop = $("#"+form+" [name=stop_time_h]").val();
		 var min_start = $("#"+form+" [name=start_time_i]").val();
		 var min_stop = $("#"+form+" [name=stop_time_i]").val();
		if (a[2]==b[2]) {
			if (a[1]==b[1]) {
				if (a[0]==b[0]) {
					if (heure_start==heure_stop) {
						return (min_start<=min_stop);
					}else{
						return (heure_start<heure_stop);
					}
				}else{
					return (a[0]<b[0]);
				}
			}else{
				return (a[1]<b[1]);
			}
		}else{
			return (a[2]<b[2]);
		}
		 
	},
	
	eventCheckDateMsg : function() {
		Biztoo.winDial('','Un évènement ne peut pas durer plus de 31 jours.<br />Votre saisie a été modifiée.');
	},
	
    report: function(id_biz) {
    	Biztoo.window(url_base + 'ajax.php?do=report&id_biz='+id_biz);
    },
	
    
    
    avatarUploaded: function (img_path) {
    	var date = new Date();
    	$('#avatar_preview').attr('src',url_base+img_path+'?time='+date.getTime());
    	$('#biz_left_infos_avatar a img').attr('src',url_base+img_path+'?time='+date.getTime());
    	$('#cli_left_infos_avatar a img').attr('src',url_base+img_path+'?time='+date.getTime());
    	
    	$.getJSON(url_base+'ajax.php?do=avatar_biz_feed',undefined,function(data) {
    		
    		if (data) {
    			
    			Biztoo.windowHTML(data);
    		}
    	}); 
    },
    

    avatarBizRemove: function (id_biz) {
    	$.get(url_base+'ajax.php?do=avatar_biz_remove&id_biz='+id_biz, function(data) {
    		if (data == 1) {
    			$('#avatar_preview').attr('src',url_base+'img/biztoo/biz_m.png');
    		}
    	})
    		
    },
    
    avatarCliRemove: function (id_cli) {
    	$.get(url_base+'ajax.php?do=avatar_cli_remove&id_cli='+id_cli, function(data) {
    		if (data == 1) {
    			$('#avatar_preview').attr('src',url_base+'img/biztoo/cli_m.png');
    		}
    	})
    		
    },
    
    
    keywordUpdate: function(id_biz, key_num, content) {
    	$.getJSON(url_base + 'ajax.php?do=keyword&action=update&id_biz='+id_biz+'&key_num='+key_num+'&content='+encodeURIComponent(content),undefined,
    			function(data) {
    				if(!data.success) {
    					// TODO
    				};
    			}
    	);
    },
    
    customersWindow: function(alias) {
    	Biztoo.window(url_base + 'ajax.php?do=customers&alias='+alias);
    },
    
    commentsWindow: function(id) {
    	Biztoo.window(url_base + 'ajax.php?do=comments&id_biz='+id);
    },

    flashWindow: function(id) {
    	//Biztoo.window(url_base + 'ajax.php?do=flash&id_biz='+id);
    	$.get( url_base + 'ajax.php?do=flash&id_biz='+id , function (data) { 
    		Biztoo.windowHTML({'title':null,'content':data});
    	});
    },
    
    flashOlds: function(id) {
    	Biztoo.window(url_base + 'ajax.php?do=flash_olds&id_biz='+id);
    },
    
    flashRemove: function(id) {
		var response =	$.ajax({
				    		url: url_base + 'ajax.php',
				    		async: false,
				    		data:{'do':'flash_remove','id':id}
				    	}).responseText;
		
		var data = $.parseJSON(response);
		if (data.res == 1) {
			$('#box_flash_old_elt_'+id).fadeOut();
		} else {
			alert('Une erreur est survenue');
		}
    },
    
  
    
    selectCity: function(cp,select_id) {
    	if (cp.length >= 5) {
	    	$.getJSON(url_base + 'ajax.php?do=getcitybycode&postcode='+cp,undefined,
	    			function(data){
	    				var nb = data.zips.length;
	    				var options = '';
	    				if (nb == 0) {
	    					options += '<option value="">-- Code postal inconnu --</option>';
	    				}
	    				if (nb > 1) {
	    					options += '<option value="">-- Choisissez --</option>';
	    				}
	    				for (var i=0;i<nb;i++) {
	    					// options += '<option value="'+data.zips[i].zip+' -
							// '+data.zips[i].city+'">'+data.zips[i].zip+' -
							// '+data.zips[i].city+'</option>';
	    					
	    					//options += '<option value="'+data.zips[i].city+'">'+data.zips[i].zip+' - '+data.zips[i].city+'</option>';
	    					
	    					options += '<option value="'+data.zips[i].city+'">'+data.zips[i].city+'</option>';
	    				}
	    				// options += '<option value="manual">-- Autre
						// --</option>';
	    				$('#'+select_id).html(options);
	    			}
	    	);
    	}
    },
    
    
    mailbox: {
    	checkNewMail : function() {
    		if ($('mailbox_new_form input [name=bdest]').val() == 0) {
    			alert('Veuillez sélectionner un destinataire');
    			return false;
    		} //alert($('mailbox_new_form input [name=bdest]').val());
    		return true;
    	}
    	
    },
    
    
    bdgToggle : function()  {
    	
    	$('.bdg_expend').slideToggle(function() {
    		
    		if ($('.bdg_toggle a').attr('class')=='open') {
        		$(".bdg_toggle a").removeClass("open");
        		$(".bdg_toggle a").addClass("close");
        	//	$(".bdg_toggle a").html('Voir tous ses badges');
        	}else{
        		$(".bdg_toggle a").removeClass("close");
        		$(".bdg_toggle a").addClass("open");
        	//	$(".bdg_toggle a").html('Cacher ses badges');
        	}
    		
    	});
    
    },
    
    flashlike: {
    	add: function (id_flash) {
    		if (Biztoo.is_IE()) {
    			var caller = 0;
    		}else{
    			var caller = 1;
    		}
    		
    		$.getJSON('ajax.php?do=flashlike&id_flash='+id_flash+'&caller='+caller,function(data) {
    			
    			if (data.success) {
    				$('#flashlike_'+id_flash).html(data.adding);
    			} else {
    				
    				if (!data.logged) {
    					
    					Biztoo.windowHTML({title:'Identification',content:data.error});
    					
    				}else if (data.error != '') {
    					Biztoo.windowHTML({title:'Erreur',content:data.error});
    				}
    				
    				
    			}
    		});
    		
    	},
    	
    	likers: function(id_flash) {
    		$.getJSON('ajax.php?do=flashlike_popup&id_flash='+id_flash,function(data) {
    			//Biztoo.window(,'Ils aiment');
    			if (data.success) {
    				Biztoo.windowHTML({title:data.title,content:data.content});
    			}
    		});
    	}
    },
    
    flashcom: {
    	add: function (id_flash) {
    	
    		var l_sel = '#flash_'+id_flash+'_coms_list';
    		var c_sel = '#flashcom_add_'+id_flash+'_form [name=msg]';
    		var content = $(c_sel).val();
    		
    		$(c_sel).val(''); 
    		$(c_sel).blur(); 
    	
    		if (content) {
    		
    			s_content = encodeURI(content);
	    		$.getJSON('ajax.php?do=flashcom&id_flash='+id_flash+'&content='+encodeURIComponent(s_content),function(data) {
	    			if (data) {

		    			if (data.success) {
		    				$(l_sel).append(data.adding);
		    			} else {
		    				
		    				$(c_sel).val(content);
		    				
		    				if (!data.logged) {
		    					Biztoo.windowHTML({title:'Identification',content:data.error});
		    				}else if (data.error != '') {
		    					Biztoo.windowHTML({title:'Erreur',content:data.error});
		    				}
		    			}
	    			}
	    		});
    		}else{
    			Biztoo.windowHTML({title:'Erreur',content:'Votre commentaire est vide'});
    		}
    	},
    	
    	getAll : function(id_flash) {
    		$('#flash_'+id_flash+'_coms_list').html('<div class="flash_field_bottom">'+Biztoo.loading+'</div>');
    		$('#flashcom_'+id_flash+'_see_all').fadeOut();
    		var back = $('#flash_'+id_flash+'_coms_list').html();
    		
    		$.getJSON('ajax.php?do=flashcom_prepend&id_flash='+id_flash,function(data) {
    			if (data) {
	    			if (data.success) {
	    				
	    				$('#flash_'+id_flash+'_coms_list').hide();
	    				$('#flash_'+id_flash+'_coms_list').html(data.adding);
	    				$('#flash_'+id_flash+'_coms_list').fadeIn(800);
	    				
	    			} else {
	    				$('#flash_'+id_flash+'_coms_list').html(back);
	    				$('#flashcom_'+id_flash+'_see_all').fadeIn();
	    				Biztoo.windowHTML({title:'Erreur',content:data.error});
	    				
	    			}
    			}
    		});
    		
    	}
    },
    
    countTitle : function (total_count) {
    	
    	var title = document.title;
		var tab_title = title.split('(');
		if (tab_title.length >1) {
			if (total_count) {
				document.title =  tab_title[0]+' ('+total_count+')';
			}else{
				document.title =  tab_title[0];
			}
		}else if (total_count){
			document.title =  document.title+' ('+total_count+')';
		}
    },
    
   /* 
    feedPopup: function(type,page,create_win) {
    	url = url_base + 'ajax.php?do=feed&type='+type+'&page='+page;
    	if (create_win) {
    		Biztoo.window(url,'Fil d\'actualité');
    	} else {
    		var h1 = $('#bwin_box_content_url').height();
    		$('#bwin_box_content_url').load(url,function() {
    			if (h1 < $('#bwin_box_content_url').height()) {
    				Biztoo.cssBwin();
    			}
    		});
    		$('#bwin_box_content_url').scrollTop(0);
    	}
    },
    */
    feedPublish: function(ident,dt,action) {
    	
   
    	$.get(url_base+'ajax.php?do=feed_publish&ident='+ident+'&dt='+dt+'&action='+action, function(data) {
    		if (data == '1') {
    			//$('#feed_publish_'+ident).fadeOut(function() {
    				$('#feed_publish_'+ident).remove();
    				if ($.trim($('#feed_publish_elts').html()) == '') {
    					//var redir = $("input[@name='feed_public_nextpage']:checked").val();
    					var redir = $("input[name=feed_public_nextpage]").val();
    					if (redir == 1) {
    						Biztoo.winClose();
    						$.get(url_base+'ajax.php?do=feedmail_popup', function (data2) {
    							if (data2) {
    								
    								res2 = $.parseJSON(data2);
    								if (res2!='') {
    									Biztoo.windowHTML(res2);
    								}
    							}
    						});
    					}else{
    						document.location = redir;
						}
    				}
    			//});
    		}
    	});
    	
    },
    
    feedMore: function(type,id,types) {
    	url = url_base + 'ajax.php?do=feed&type='+type+'&id='+id+'&page='+Biztoo.feedPage+'&offset='+Biztoo.feedOffset+'&types='+types;
		
    	$('#feed_loading').show();
    	$.get(url,function(data) {
    		$('#feed_loading').hide();
    		$('#feed .feed_elts').append(data);
    	});
    	
    	Biztoo.feedPage ++;
    },
    
    feedCheckUpdate: function(type,id,types) {
    	//$('#feed').load(url_base + 'ajax.php?do=feed&type='+type+'&action=checkupdate');
    	var url = url_base + 'ajax.php?do=feed&type='+type+'&id='+id+'&action=checkupdate&refresh_date='+Biztoo.refresh_date+'&types='+types;
    	
    	if (type == 'biz') {
    		url += '&fcheck_notif='+Biztoo.fcheck_notif+'&fcheck_users='+Biztoo.fcheck_users;
    	} else if(type == 'cli') {
    		url += '&fcheck_notif='+Biztoo.fcheck_notif+'&fcheck_react='+Biztoo.fcheck_react+'&fcheck_nbizs='+Biztoo.fcheck_nbizs;
    	}
    	
    	
    	$.getJSON(url,function(data){
    		// Counters refresh
    		var total_count = 0;

    		
    		if (data) {
				if (data.counters != undefined) {
					if (data.counters != null) {
		    			for (var id in data.counters) {
		        			
		    				$('#boleft_nb_'+id+' a span.number').remove();
		    				
		    				if (data.counters[id] == 0) {
		        				$('#boleft_nb_'+id+' a').removeClass('boleft_newelts');
		        				$('#boleft_nb_'+id+' a').addClass('boleft_noelts');
		        			} else {
		        				$('#boleft_nb_'+id+' a').removeClass('boleft_noelts');
		        				$('#boleft_nb_'+id+' a').addClass('boleft_newelts');
		        				$('#boleft_nb_'+id+' a').append('<span class="number"><span class="number_left"></span><span class="number_middle">'+data.counters[id]+'</span><span class="number_right"></span></span>');
		        			}
		    				
		    				total_count+= data.counters[id];
		    				
		        		}
					}
					
					
					total_count = data.total_counter;
				}
    		}
    		
			if (!types) {
				Biztoo.countTitle(total_count);
			}
			
		
			// Feed refresh
			if (data) {
	    		if (Biztoo.update_feed && data.nb != 0 && data.nb > Biztoo.feed_last_nb) {
	    			
	    			if (Biztoo.feedLiveDisplay) {
	    				//alert('will display');
	    				
	    				Biztoo.feedUpdate(type,data.alias,types);
	    				
	    				//alert('has updated');
	    				
	    			} else {
	    				if (data.nb > 1) {
		    				$("#feed_new_elts .nb").html(data.nb);
		    				$("#feed_new_elts .nb").show();
		    				$("#feed_new_elts .txt_one").hide();
		    				$("#feed_new_elts .txt_more").show();
		    			} else {
		    				$("#feed_new_elts .nb").hide();
		    				$("#feed_new_elts .txt_one").show();
		    				$("#feed_new_elts .txt_more").hide();
		    			}
		    			
		    			$('#feed_new_elts').slideDown();
		    			Biztoo.feed_last_nb = data.nb;
	    			}
	    		}
			}
    	});
    },
    
    feedUpdate: function(type,id,types) {
    	var url = url_base + 'ajax.php?do=feed&type='+type+'&id='+id+'&action=update&refresh_date='+Biztoo.refresh_date+'&types='+types;
    	
    	$('#feed_new_elts').hide();
    	$('#feed_new_elts_loading').show();
    	
    	
    	$.getJSON(url,function(data) {
    		
    		$('#boleft_nb_'+data.types+' a span.number').remove();
    		Biztoo['fcheck_'+data.types] = data.refresh_date;
    		
    		Biztoo.feedOffset += data.nb;
    		Biztoo.feed_last_nb = 0;
    		
    		$('#feed_new_elts_loading').hide();
    		$('.feed_empty').hide();
    		
    		$('.feed_time').removeClass('feed_time_new');
    		
    		$('#feed .feed_elts').prepend(data.html);
    		Biztoo.refresh_date = data.refresh_date;
    		
    		if ($('#feed .feed_elts h3:eq(0)').html() == $('#feed .feed_elts h3:eq(1)').html()) {
    			$('#feed .feed_elts h3:eq(1)').hide();
    		} else {
    			$('.feed_last_hr').hide();
    		}
    		$('.feed_last_hr').removeClass('feed_last_hr');
    	});
    },

	// BIZ + CLI
    fcheck_notif: null,
    
    // BIZ
    fcheck_users: null,
    //fcheck_histo: null,
    
    // CLI
    fcheck_react: null,
    fcheck_nbizs: null,
    
    update_feed: false,
    feedLiveDisplay : 0,
	
	feedOffset : 0,
	activity : true,
	can_refresh : false,
	feed_last_nb : 0,
	refresh_command : undefined,
	refresh_date : undefined,
	//feedRefreshInterval : 60000,
	feedRefreshInterval : 10000,
	
	sendRefresh : function (type,id,types) {
		if (Biztoo.activity) {
			Biztoo.feedCheckUpdate(type,id,types);
		}else{
			Biztoo.can_refresh=true;
			clearInterval(Biztoo.refresh_command);
		}
	},
	
    feedRefresh: function (type,id,types) {
		$.idleTimer(5000);
		
		$(document).bind("idle.idleTimer", function(){
			//Biztoo.activity=false;
		});
		
		$(document).bind("active.idleTimer", function(){
			Biztoo.activity=true;
			if (Biztoo.can_refresh) {
				Biztoo.sendRefresh(type,id,types);
				Biztoo.can_refresh=false;
				var txt="Biztoo.sendRefresh('"+type+"','"+id+"','"+types+"');";
				Biztoo.refresh_command=setInterval(txt,Biztoo.feedRefreshInterval);
			}
		});
		
		var txt="Biztoo.sendRefresh('"+type+"','"+id+"','"+types+"');";
		Biztoo.refresh_command=setInterval(txt,Biztoo.feedRefreshInterval);
	},
	
	/*
    refreshLeft: function(bo) {
    	//setInterval('Biztoo.refreshLeftAction("'+bo+'")',10000);
    },
    
    refreshLeftAction: function(bo) {
    	var url = url_base + 'ajax.php?do=boleft&action=refresh';
    	
    	
    	$.getJSON(url,function(data){
    		//alert('data ' + data);
    		
    	});
    },
    
	*/
	
	
	
	passwordPopup : function () {
		Biztoo.window(url_base+'ajax.php?do=popupPassword','Modifier mon Mot de Passe');
	},
	
	passwordChange : function () {
		
		$.post(url_base + 'ajax.php?do=changePassword&'+$('#cli_change_password_form').serialize(),{},function(data){
			var save_html = $('#change_password_div').html(); 
			var obj = jQuery.parseJSON(data);
			
			if (obj.res) {
				Biztoo.winClose();
				Biztoo.winDial('Mot de Passe','Votre mot de passe a été modifié.');
			}else{
				$('#change_password_div').html(save_html);
				$('#change_password_dial').html(obj.html);
			}
		
		});
	},
	
    fbShare: function (url, title) {
    	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title),'fb','width=800,height=400,top=100,left=100,toolbar=no, menubar=yes, location=no, resizable=yes, scrollbars=no, status=no');
    	return false;
    },
    
    albumNbElts:0,
    albumMore: function(id_biz,nb_elts,height) {
    	
    	var more = $('#bizf_album_more_content');
    	var elts = $('#bizf_album_content');
    	if (more.html() == '') {
    		more.load(url_base + 'ajax.php?do=box&box=album&print=more&id_biz='+id_biz,function() {
    			elts.find("a").lightBox();
    		});
    		//elts.css('height',(Math.ceil(nb_elts/4)*height)+'px');
    	} else {
    		if (more.css('display') == 'none') {
    			more.css('display','block');
        	//	elts.css('height',(Math.ceil(nb_elts/4)*height)+'px');
        		elts.find("a").lightBox();
    		} else {
    			more.css('display','none');
        		//elts.css('height',height+'px');
        		elts.find("a.firsts").lightBox();
    		}
    	}
    },
    
    
    comAddCallBack : function(append) {
    	
    	
    //	$('#bizf_comms_content').html(append); 
    	
    	if (append) {
    		$('#bizf_comms_content').get(0).innerHTML=append; 
    	}
		//$('#bizf_comms_content').html($('#bizf_comms_content').html());
    	
    },
    
    comAddGest : function( url, append) {
    	$.get(
				url,
				function (data) {
					Biztoo.windowHTML(data);
					Biztoo.comAddCallBack(append);
				}
		);
    },
    
    comAdd: function() {
    	// $('#bizf_comms_add_form');
    	
    	$.post(url_base + 'ajax.php',$('#bizf_comms_add_form').serialize(),function(data){
			
    	
    		var save_html = $('#bizf_comms_content').html(); 
			var save_html = null;
			var obj = jQuery.parseJSON(data);
			
			if (obj.res == 1) {
				
			//	var function_app= function() {$('#bizf_comms_content').append(obj.html); }
				
    			if (obj.must_valid == 1) {
					//en validation
    				//$('#bizf_comms_content').load(url_base + 'ajax.php?do=com_add&confirm=2',function() { 	Biztoo.comAddCallBack(obj.html); /*$('#bizf_comms_content').append(obj.html);*/ });
    				Biztoo.comAddGest(url_base + 'ajax.php?do=com_add&confirm=2', obj.html);
    			} else {
					//activé
    				
    				Biztoo.comAddGest(url_base + 'ajax.php?do=com_add&confirm=1', obj.html);
					//$('#bizf_comms_content').load(url_base + 'ajax.php?do=com_add&confirm=1',function() { 		Biztoo.comAddCallBack(obj.html); /*$('#bizf_comms_content').append(obj.html); */ });
				}
    			
    		} else {
    			
				//var function_app= function() {$('#bizf_comms_content').append(save_html); }
				
				if (obj.res == 2) {
					//unlog
					
					Biztoo.comAddGest(url_base + 'ajax.php?do=prelog&mode=json&prelog_field=comms&vals='+$('#bizf_comms_add_form').serialize(), save_html);
					//$('#bizf_comms_content').load(url_base + 'ajax.php?do=prelog&prelog_field=comms&vals='+$('#bizf_comms_add_form').serialize(), function() {  	Biztoo.comAddCallBack(save_html); /* $('#bizf_comms_content').append(save_html); */  });
				}else{
					//erreur
					Biztoo.comAddGest(url_base + 'ajax.php?do=com_add&confirm=0', save_html);
					//$('#bizf_comms_content').load(url_base + 'ajax.php?do=com_add&confirm=0', function() { 	Biztoo.comAddCallBack(save_html); /* $('#bizf_comms_content').append(save_html); */});
				}
				
    		}
		
		}
		
		);
    },
    
    comUpdate: function(id,action,valid) {
    	if (!Biztoo.is_IE6() ) {
    		
			 var response = $.ajax({
								url: url_base + 'ajax.php',
								async: false,
								data: {'do':action,'id':id}
							}).responseText; 
							
		
			 var data = $.parseJSON(response);
			
    		
			
			if (data.res == '1') {
				$('#box_comms_elt_'+id).fadeOut(function(){
					if (!valid) {
						$('#box_comms_nb_waiting').html($('#box_comms_nb_waiting').html()-1);
					}
				});
				return true;
			}else {
				alert('Une erreur est survenue');
				return false;
			}
		
		}
		
    },
    
    comFeedUpdate: function(id,action,id_feed) {
    	if (!Biztoo.is_IE6() ) {
    		
    		var response = $.ajax({
				url: url_base + 'ajax.php',
				async: false,
				data: {'do':action,'id':id,'id_feed':id_feed}
			}).responseText; 
    		
    		
    		
    		var data = $.parseJSON(response);
    		
    		
    		
    		if (data.res == '1') {
    			
    			$('#feed_elt_'+id_feed+' .feed_comms_actions').hide();
    			var div = $('#feed_elt_'+id_feed+' .feed_comms_actions');
    			div.get(0).innerHTML=data.feed;
    			
    			//$('#feed_elt_'+id_feed+' .feed_comms_actions').html(data.feed);
    			//var div = document.getElementById('feed_elt_'+id_feed);
    			//div.getElementsByClassName('feed_comms_actions').innerHTML='aaa';
    			
    			$('#feed_elt_'+id_feed+' .feed_comms_actions').fadeIn();
    		} else {
				alert('Une erreur est survenue');
				return false;
			}
    	}
    },
    
    comFlashFeedUpdate: function(id,action,id_feed) {
    	if (!Biztoo.is_IE6() ) {
    		var response = $.ajax({
				url: url_base + 'ajax.php',
				async: false,
				data: {'do':action,'id':id,'id_feed':id_feed}
			}).responseText; 
    		
    		var data = $.parseJSON(response);
    		
    		if (data.res == '1') {
    			$('#feed_elt_'+id_feed+' .feed_comms_actions').hide();
    			$('#feed_elt_'+id_feed+' .feed_comms_actions').html(data.feed);
    			$('#feed_elt_'+id_feed+' .feed_comms_actions').fadeIn();
    		} else {
				alert('Une erreur est survenue');
				return false;
			}
    	}
    },
    
    comValidation: function(id_biz,mode) {
    	$('#box_comms_update_automode').load(url_base + 'ajax.php?do=com_validation&id_biz='+id_biz+'&mode='+mode);
    },
    
    offer_nbmax : 6,
    
    offer_nbelts : 0,
    
    offerHide : function(nb) {
    	while (nb<=Biztoo.offer_nbmax) {
    		$("#offer_line_"+(nb-1)).hide();
    		nb++;
    	}
    },
    
    offerAdd : function() {
    		if (Biztoo.offer_nbelts<Biztoo.offer_nbmax) {
    			$("#offer_line_"+(Biztoo.offer_nbelts)).show();
    			Biztoo.offer_nbelts++;
    		}
    },
    
    movieClear : function(form) {
    	$("#"+form+" [name=title]").val('');
    	$("#"+form+" [name=url]").val('');
    },
    linksClear : function(form,ident) {
    	$("#"+form+" [name=name_"+ident+"]").val('');
    	$("#"+form+" [name=url_"+ident+"]").val('');
    },
    userReport: function(form) {
    	if (form.find('textarea[name=text]').val() != '') {
	    	$.post(url_base + 'ajax.php',form.serialize(),function(data){
	    			    		
	    		Biztoo.winClose(function() {
	    			Biztoo.winDial('', 'Votre message a été transmis à l\'administrateur '+data);
	    		});
	    		
	    	});
    	} else {
    		
    		alert('Veuillez saisir le message à envoyer');
    		Biztoo.winClose();
    	}
    },
    
    speech : function () {
		
    	var src =encodeURI(url_base+'img/admin/cest-delicieux.mpga');

		
		var player=
		'<object height="50" width="230" align="middle" id="miniAS3_player" '+
		'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">'+
		'<param value="sameDomain" name="allowScriptAccess">'+
		'<param value="false" name="allowFullScreen">'+
		'<param value="autoplay=yes&amp;my_song='+src+'" name="flashvars">'+
		'<param value="'+url_base+'img/admin/player.swf" name="movie"><param value="high" name="quality"><param value="#ffffff" name="bgcolor">'+
			'<embed height="50" width="230" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" '+
			'type="application/x-shockwave-flash" allowfullscreen="false" allowscriptaccess="sameDomain" '+
			'flashvars="autoplay=yes&amp;my_song='+src+'" name="player" bgcolor="#ffffff" '+
			'quality="high" src="'+url_base+'img/admin/player.swf">'+
		'</object>';
		
		$('body').append(
				'<div id="soundblock" style=" position:absolute;  width:0px; height:0px; border-width:0px; visibility:hidden;" >'+
				player +'</div>'
		);
		
	},
	
	pause: function (time){
		d=new Date();
		diff=0;
		while(diff < time){
		n=new Date();
		diff=n-d;
		} 
	},
    
    gmaps: {
    	displayFromAddr: function(div_id,address) {
	    	var geocoder = new google.maps.Geocoder();
    		if (geocoder) {
				geocoder.geocode({"address": address}, function(results,status) {
					if (status == google.maps.GeocoderStatus.OK) {
						var latlng = new google.maps.LatLng(-34.397, 150.644);
						var myOptions = {
						    zoom: 14,
						    center: latlng,
						    mapTypeId: google.maps.MapTypeId.ROADMAP
					    }
						var map = new google.maps.Map(document.getElementById(div_id), myOptions);
						
						map.setCenter(results[0].geometry.location);
						var marker = new google.maps.Marker({
							map: map,
							position: results[0].geometry.location
						});
					}
				});
			}
    	},
    	
    	annuaireAddrs: function(div_id,near,addresses) {
    		var myLatlng = new google.maps.LatLng(-34.397, 150.644);
    		var myOptions = {
    		  zoom: 14,
    		  center: myLatlng,
    		  mapTypeId: google.maps.MapTypeId.ROADMAP
    		}
    		
    		var map = new google.maps.Map(document.getElementById("annuaire_city_map"), myOptions);
    		
    		var geocoder = new google.maps.Geocoder();
    		geocoder.geocode( { 'address': near}, function(results, status) {
    			if (status == google.maps.GeocoderStatus.OK) {
    				map.setCenter(results[0].geometry.location);
    			}
    		});
    		
    		var address;
    		var geocoderCity = new Array();
    		for (var i in addresses) {
    			//infos = addresses[i];
    			//alert(infos.address);
    			//alert(i);
    			geocoderCity[i] = new google.maps.Geocoder();
    			//geocoderCity[i].id = i;
    			geocoderCity[i].geocode( { 'address': addresses[i].address}, function(results, status) {
        			//alert(results.length);
    				if (status == google.maps.GeocoderStatus.OK) {
        				var marker = new google.maps.Marker({
        		            map: map, 
        		            position: results[0].geometry.location,
							title : addresses[i].enseigne,
							icon : url_base + 'img/biztoo/pictos/picto-gmap-puce-'+(parseInt(i)+1)+'.png'
        		        });
        				
        				var myInfoWindow = new google.maps.InfoWindow({content : addresses[i].content});
        				google.maps.event.addListener(marker, 'click', function() {
        					myInfoWindow.open(map,marker);
        				});
        			}
        		});
    		}
    	},
    	
    	
    	
    	largerMap: function(address) {
    		Biztoo.window(undefined,'Plan d\'accès');
    		$('#bwin_box_content_url').html('<div style="width:548px; height:400px;" id="bizf_gmaps_large">'+Biztoo.loading+'</div>');
    		Biztoo.cssBwin();
    		Biztoo.gmaps.displayFromAddr('bizf_gmaps_large', address);
    	}
    },
	
    inviteWebmailSelectType: function(type) {
    	if (type !== '') {
    		$('#invit_webmail_type_input').val(type);
    		$('.invit_webmail_type a').removeClass("selected");
    		$('.invit_webmail_type a').addClass("unselected");
    		
    		$('#invit_webmail_type_'+type).removeClass("unselected");
    		$('#invit_webmail_type_'+type).addClass("selected");
    	} else {
    		$('.invit_webmail_type a').removeClass("selected");
    		$('.invit_webmail_type a').removeClass("unselected");
    	}
    },
    
    inviteWebmailAutoSelectType: function(obj) {
    	var email = obj.val();
    	var provider = email.substr(email.indexOf('@')+1);
    	var type = '';
    	switch(provider) {
    		case 'gmail.com' : 
    			type = 'gmail';
    		break;
    		

    		case 'live.com' : 
        	case 'live.fr' : 
    		case 'hotmail.com' : 
        	case 'hotmail.fr' : 
    			type = 'hotmail';
    		break;
    		
        	case 'yahoo.fr' : 
        		type = 'yahoo';
        	break;
    		
    	}
    	Biztoo.inviteWebmailSelectType(type);
    },
    
    inviteWebmailCheckSubmit: function(form) {
    	var error = false;
    	
    	if ($('#invit_webmail_type_input').val() == '') {
    		Biztoo.windowHTML({'title':'Erreur','content':'Veuillez sélectionner votre type de compte (hotmail, gmail, yahoo), en cliquant sur l\'image du logo'});
    		error = true;
    	}
    	
    	if (form.find('input[name=webmail_login]').val() == '') {
    		Biztoo.windowHTML({'title':'Erreur','content':'Veuillez saisir votre adresse e-mail'});
    		error = true;
    	} else if (form.find('input[name=webmail_login]').val().indexOf('@') == -1){
    		Biztoo.windowHTML({'title':'Erreur','content':'Veuillez saisir votre adresse e-mail complète'});
    		error = true;
    	}
    	
    	if (form.find('input[name=webmail_password]').val() == '') {
    		Biztoo.windowHTML({'title':'Erreur','content':'Veuillez saisir le mot de passe de votre messagerie'});
    		error = true;
    	}
    	
    	if (!error) {
    		$('#webmail_loading').show();
    	}
    	
    	return (!error);
    	
    },
    
    sendInviteMail: function (mails) {
    	//	$('#invite_cli_returner').load(url_base + 'ajax.php?do=send_invite_mail&mails='+mails);
    	//alert(mails);
    	if ($('#form_inviter input[name=id_biz]')!=undefined) {
    		var add_biz="&id_biz="+$('#form_inviter input[name=id_biz]').val();
    	}else{
    		var add_biz='';
    	}
    	
    	$('#invite_background').load(url_base + 'ajax.php?do=send_invite_mail&mails='+mails+'&section='+$('#form_inviter input[name=section]').val()+add_biz);
	},
	sendInviteFacebook: function (list) {
    	//	$('#invite_cli_returner').load(url_base + 'ajax.php?do=send_invite_mail&mails='+mails);
    	//alert(mails);
    	$('#invite_background').load(url_base + 'ajax.php?do=send_invite_mail_facebook&list='+list+'&section='+$('#form_inviter input[name=section]').val());
	},
	seeInviteMail: function (section,id_biz) {
		if (id_biz==undefined) {
			var plus ='';
		}else{
			var plus='&id_biz='+id_biz;
		}
		Biztoo.window(url_base + 'ajax.php?do=see_invite_mail&section='+section+plus);
	},
	
	bsubSecteurs: function (val) {
		$.get( 
			url_base + 'ajax.php?do=secteurs_choice&cible=secteur&val='+val, 
			function(data) {	
				Biztoo.windowHTML({title:'Votre secteur d\'activité',content:data});
			}
		);
		//Biztoo.window(,'Votre secteur d\'activité');
    },
	
    select_secteur : function (cible,value,title) {
		$("#subleft_input_"+cible).attr('value',value);
		$("#cadre_left_"+cible+"_name").html(title);
		Biztoo.winClose();
	},
	
    back_input : new Array(),
    areaToInput : function (cont,ident) {
    	value=document.getElementById(ident).value;
    	$('#'+cont).html(Biztoo.back_input[ident]);
    	
    	if (value) {
    		document.getElementById(ident).value=value;
    	}
    },
    inputToArea : function (cont,ident,classname,rows,cols,maxlength) {
    	if (!rows) {rows=2;}
    	if (!cols) {cols=80;}
    	var maxlength_str = (maxlength !== undefined) ? ' maxlength="'+maxlength+'"' : '';
    	
		Biztoo.back_input[ident]=$('#'+cont).html(); 
		var value=document.getElementById(ident).value; 
		var name=document.getElementById(ident).name; 
		
		
		
		var area='<textarea onblur="if (this.value==\'\') { Biztoo.areaToInput(\''+cont+'\',\''+ident+'\'); }" '+
		'rows="'+rows+'"  cols="'+cols+'"  class="'+classname+'" id="'+ident+'" name="'+name+'"'+maxlength_str+' >'+value+'</textarea>';  
		
		$('#'+cont).html(area);
		
		
		
		if (Biztoo.is_IE()) {
			setTimeout(function() {document.getElementById(ident).focus();},300);
		}else{
			$('#'+ident).focus();
		}
		
		
	},
	
	checkForm : function (form,vals,f_true,f_false){
		var res=true;
		var i=0;
		while (i<vals.length) {
			if ($("#"+form+" [name="+vals[i]+"]").val()=='') {
				res=false;
			}
			i++;
		}
		
		if (res) {
			return f_true();
		}else{
			return f_false();
		}
	},
	
	// From tinyMCE BBCodePlugin
	// HTML -> BBCode in PunBB dialect
	punbb_html2bbcode : function(s) {
		s = tinymce.trim(s);
		//alert(s);
		
		function rep(re, str) {
			s = s.replace(re, str);
		};
		
		
		rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
		rep(/<\/(strong|b)>/gi,"[/b]");
		rep(/<(strong|b)>/gi,"[b]");
		rep(/<\/(em|i)>/gi,"[/i]");
		rep(/<(em|i)>/gi,"[i]");
		rep(/<\/u>/gi,"[/u]");
		rep(/<span style=\"text-decoration: ?underline[^>]*>(.*?)<\/span>/gi,"[u]$1[/u]");
		rep(/<u>/gi,"[u]");
		rep(/<p>/gi,"");
		rep(/<\/p>/gi,"\n");
		rep(/&nbsp;/gi," ");
		rep(/&quot;/gi,"\"");
		rep(/&lt;/gi,"<");
		rep(/&gt;/gi,">");
		rep(/&amp;/gi,"&");
		
		rep(/ _mce_style="[^"]*"/,"");
		rep(/<br _mce_bogus=\"1\">/gi,"");
		
		//alert(s);

		if (s.indexOf('<div>') !== -1) {
			rep(/<div>( )*<br>( )*<\/div>/gi,"\n");
			rep(/<div>/gi,"\n");
			rep(/<\/div>/gi,"");
		}
		
		rep(/<br \/>/gi,"\n");
		rep(/<br\/>/gi,"\n");
		rep(/<br>/gi,"\n");
		
		rep(/\[b\] ?\[\/b\]/gi,"");
		rep(/\[i\] ?\[\/i\]/gi,"");
		rep(/\[u\] ?\[\/u\]/gi,"");
		
		rep(/<span\s* style=\"?color: ?(.*?);?\"?>/gi,"[color=$1]");
		rep(/<font color=\"?(.*?)\"?>/gi,"[color=$1]");
		
		rep(/<\/span>/gi,"[/color]");
		rep(/<\/font>/gi,"[/color]");
		
		
		//rep(/\[\/color\]\[\/color\]/gi,"[/color]");
		//rep(/(\[color=#[0-9a-f-A-F]{6}\])\[color=#[0-9a-f-A-F]{6}\]/gi,"$1");
		
		//alert(s);
		
		
		// Thx to http://stackoverflow.com/questions/638948/background-color-hex-to-javascript-variable-jquery/639030#639030
		var colorDec2Hex = function (str) {
			rgbString = str.substring(7,str.length-1);
			var parts = rgbString.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
			if (parts) {
				delete (parts[0]);
				for (var i = 1; i <= 3; ++i) {
				    parts[i] = parseInt(parts[i]).toString(16);
				    if (parts[i].length == 1) parts[i] = '0' + parts[i];
				}
				return "[color=#" + parts.join('')+"]";
			} else {
				return str;
			}
		}
		
		
		
		var start = -1;
		var stop = -1;
		var i = 0;
		do {
			start = s.indexOf('[color=rgb');
			if (start != -1) {
				stop = s.indexOf(']',start)+1;
				s = s.substring(0,start)+colorDec2Hex(s.substring(start,stop))+s.substring(stop);
			}
			i++;
		} while (i < 1000 && start != -1);
		
		
		
		return s; 
	},
	
	cliSwitch : function (anode) {
		if ($('#subscribe_popup_forms').hasClass('selected')) {
			$('#subscribe_popup_form input[name=csub]').val('prelog');
			$('#subscribe_popup_forms').removeClass('selected');
			$('#log_popup_forms').addClass('selected');
			var val='S\'inscrire';
		}else{
			$('#subscribe_popup_form input[name=csub]').val('presub');
			$('#log_popup_forms').removeClass('selected');
			$('#subscribe_popup_forms').addClass('selected');
			var val='Déjà membre ?';
		}
		
		anode.html(val);
		$('.switch_form.selected').fadeOut(500,function() {
			
			$('.switch_form').hide();
			$('.switch_form.selected').fadeIn(500);
			
		});
	
	},
	
	cliSub : function () {
		
		var form_selector = '#subscribe_popup form';
		var loading_id = '#subscribe_popup_errors';
		var mode = $(form_selector+' input[name=csub]').val();
		var next_page = $(form_selector+' input[name=next_page]').val();
		if (next_page == undefined) {
			var next_page = null;
		}
		
		$(loading_id).html(Biztoo.loading);
		
		$.post(url_base+'ajax.php',$(form_selector).serialize(),function(data) {
			var vals = $.parseJSON(data);
			
			
			if (vals['success']==true) {
				
				if (mode=='prelog') {
					if (vals['next_page']==undefined) {
						vals['next_page'] = null;
					}
					
					if (vals['next_page']) {
						window.location=vals['next_page'];
					}else{
						if (next_page) {
							window.location=next_page;
						}else{
							window.location=window.location;
						}
					}
				}else{
					$(loading_id).html('');
					Biztoo.winClose();
					Biztoo.windowHTML(vals);
				}
				
			}else{
				$(loading_id).html(vals['content']);
			}
			
		});
		
		return true;

	}
	
}




