var BrowseTable = Class.create();

/**
 *  Objet browse Table
 * 	@param searchForm : formulaire d'ou proviennent les informations de recherche
 *  @param langage : langue de la table
 *  @param nbPerPage : nombre d'éléments affichés par page
 *  @param lineTemplate : template PHP d'affichage d'un résultat
 *  @param noresultTemplate : template PHP dans le cas d'aucun résultat pour la recherche
 *  @param resultTemplate : template PHP pour la zone d'affichage du nombre de résultats
 *  @param loaderUrl : url de l'image du loader
 *  @param sort : active le tri dans la table
 *  @param sortSensDefault : active le sens par défaut du tri
 *  @param loadDataUrl : url permettant de charger les résultats
 *  @param loadParamsUrl : url permettant de charger les paramètres et le tri
 *  @param loadDataCountUrl : url permettant de charger le nombre de résultats
 */

Object.extend(BrowseTable.prototype, {
 initialize: function(element,options){
 		this.opts = {
 					useCookies: false,
 					searchForm:'',
					language:'en',
					nbPerPage: 5,
					nbPageNav: 9,
					lineTemplate: '',
					noresultTemplate: '',
					resultTemplate: '',
					loaderUrl:'/images/ajax.gif',
					sort: false,
					sortSensDefault: 'ASC',
					loadDataUrl: '',
					loadParamsUrl: '',
					loadDataCountUrl: ''
					};
		Object.extend(this.opts, options);
		
		this.mainDiv = $(element);
		this.ajaxLoad = new Element('img');
		$(this.ajaxLoad).addClassName("ajaxLoad");
 		this.ajaxLoad.src = this.opts.loaderUrl;
 		this.firstLoad = true;
 		
 		this.timeStartComponent = (new Date).getTime();
 		this.timeStartLoading = null;
 		this.timeEndLoading = null;
 		this.timeEndComponent = null; 
		this.form = null;
		this.data = null;
		this.dataCount = 0;
		this.columns = null;
		this.nbTotalPage = null;
		this.registeredLinks = new Array();
		this.sorts = null;
		this.sortsWays = new Array(2);  //dans l'ordre  sort_sens et old_sort_sens
		this.noresultTemplate = $(this.opts.noresultTemplate).innerHTML;
		this.resultTemplate = $(this.opts.resultTemplate).innerHTML;
		this.lineTemplate = $(this.opts.lineTemplate).innerHTML;
		this.initSearchForm();
		this.initCanvas();
		this.loadSort(); 
 },
 showTime: function(){
 	var cpt2 = (this.timeEndLoading-this.timeStartLoading)/1000;
 	var cpt3 = (this.timeEndComponent-this.timeEndLoading)/1000;
 	var str = "Temps de chargement des données: "+ cpt2 +" s.";
 	str += "&nbsp;&nbsp;&nbsp;Temps d'affichage: "+ cpt3 +" s.";
 	$(this.debugBar).update(str);
 	delete str;
 	delete cpt2;
 	delete cpt3;
 },
 setCookiePage: function(){
 	var currentCookiePage = parseInt(readCookie('currentPageBrowse_GameConnection_'+this.opts.dataSearched+'_'+this.opts.con_id));
 	var currentCookieFilters = readCookie('currentFiltersBrowse_GameConnection2_'+this.opts.dataSearched+'_'+this.opts.con_id);
 	this.pageSelected = isNaN(currentCookiePage) ? 1 : (currentCookiePage>this.nbTotalPage ? 1 :currentCookiePage);
 	
//	this.pageSelected = 1;
 },
 initSearchForm: function(){
 	if(this.opts.searchForm!='')
 	{
 		this.form= $(this.opts.searchForm);
 		$(this.form).stopObserving();
 		$(this.form).observe('submit',this.loadDataCount.bindAsEventListener(this));
 	}
 },
 initCanvas: function(){
 		this.topBar= $$("div.topBar")[0];
 		this.topMiddleBar= $$("div.topMiddleBar")[0];
 		this.alphaBar= $$("div.alphaBar")[0];
 		this.middleBar= $$("div.middleBar")[0];
 		this.bottomBar= $$("div.bottomBar")[0];
 		this.debugBar= $$("div.debugBar")[0];
 },
 loadAlphaFilterRequest: function(e){
 		$$(".alpha").each(function(c){
 			if(c.hasClassName("selected"))
 			{ 
 				c.removeClassName("selected");
 			}
 		});
 		var obj = Event.element(e);
 		$('onlyTag').value = true;
 		$('searchTag').value = obj.id;
 		this.loadDataCount();
 		obj.addClassName("selected")
 },
 initNavigation: function(){
 		if($(this.navDiv))
 		{
 			 removeChildren($(this.navDiv));
 		}
 		
 		// création des liens du haut
 		this.navDivTop= new Element("div");
 		
 		if(this.nbTotalPage>1)
 		{
	 		// création du link firstPage
	 		this.linkFirstTop = new Element("a");
			this.linkFirstTop.id="link_first_top";
			$(this.linkFirstTop).addClassName('navLink');
			this.linkFirstTop.update("&nbsp;<<&nbsp;");
	 		$(this.navDivTop).appendChild($(this.linkFirstTop));
	 		this.linkFirstTop.hide();
	 		this.registeredLinks.push(this.linkFirstTop);
	 		
	 		// création du link previousPage
	 		this.linkPreviousTop = new Element("a");
			this.linkPreviousTop.id="link_previous_top";
			$(this.linkPreviousTop).addClassName('navLink');
			this.linkPreviousTop.update("&nbsp;<&nbsp;");
	 		$(this.navDivTop).appendChild($(this.linkPreviousTop));
	 		this.linkPreviousTop.hide();
	 		this.registeredLinks.push(this.linkPreviousTop);
 		}
 		
 		//creation des links de chaque page
 		for(var i=1; i<=this.nbTotalPage;i++)
 		{
 			var link = new Element("a");
 			link.id="link"+i+"_top";
 			$(link).addClassName('navLink');
 			link.update(i);
 			$(this.navDivTop).appendChild($(link));
 			link.hide();
 			this.registeredLinks.push(link);
 		}
 		
 		if(this.nbTotalPage>1)
 		{
	 		// création du link nextPage
	 		this.linkNextTop = new Element("a");
			this.linkNextTop.id="link_next_top";
			$(this.linkNextTop).addClassName('navLink');
			this.linkNextTop.update(">");
	 		$(this.navDivTop).appendChild($(this.linkNextTop));
	 		this.linkNextTop.hide();
	 		this.registeredLinks.push(this.linkNextTop);
	 		
	 		// création du link lastPage
	 		this.linkLastTop = new Element("a");
			this.linkLastTop.id="link_last_top";
			$(this.linkLastTop).addClassName('navLink');
			this.linkLastTop.update("&nbsp;>>&nbsp;");
	 		$(this.navDivTop).appendChild($(this.linkLastTop));
	 		this.linkLastTop.hide();
	 		this.registeredLinks.push(this.linkLastTop);
 		}
 		
 		//création des liens du bas
 		this.navDivBottom= new Element("div");
 		
 		if(this.nbTotalPage>1)
 		{
	 		// création du link firstPage
	 		this.linkFirstBottom = new Element("a");
			this.linkFirstBottom.id="link_first_bottom";
			$(this.linkFirstBottom).addClassName('navLink');
			this.linkFirstBottom.update("&nbsp;<<&nbsp;");
	 		$(this.navDivBottom).appendChild($(this.linkFirstBottom));
	 		this.linkFirstBottom.hide();
	 		this.registeredLinks.push(this.linkFirstBottom);
	 		
	 		// création du link previousPage
	 		this.linkPreviousBottom = new Element("a");
			this.linkPreviousBottom.id="link_previous_bottom";
			$(this.linkPreviousBottom).addClassName('navLink');
			this.linkPreviousBottom.update("&nbsp;<&nbsp;");
	 		$(this.navDivBottom).appendChild($(this.linkPreviousBottom));
	 		this.linkPreviousBottom.hide();
	 		this.registeredLinks.push(this.linkPreviousBottom);
 		}
 		
 		//creation des links de chaque page
 		for(var i=1; i<=this.nbTotalPage;i++)
 		{
 			var link = new Element("a");
 			link.id="link"+i+"_bottom";
 			$(link).addClassName('navLink');
 			link.update(i);
 			$(this.navDivBottom).appendChild($(link));
 			link.hide();
 			this.registeredLinks.push(link);
 		}
 		
 		if(this.nbTotalPage>1)
 		{
	 		// création du link nextPage
	 		this.linkNextBottom = new Element("a");
			this.linkNextBottom.id="link_next_bottom";
			$(this.linkNextBottom).addClassName('navLink');
			this.linkNextBottom.update("&nbsp;>&nbsp;");
	 		$(this.navDivBottom).appendChild($(this.linkNextBottom));
	 		this.linkNextBottom.hide();
	 		this.registeredLinks.push(this.linkNextBottom);
	 		
	 		// création du link lastPage
	 		this.linkLastBottom = new Element("a");
			this.linkLastBottom.id="link_last_bottom";
			$(this.linkLastBottom).addClassName('navLink');
			this.linkLastBottom.update("&nbsp;>>&nbsp;");
	 		$(this.navDivBottom).appendChild($(this.linkLastBottom));
	 		this.linkLastBottom.hide();
	 		this.registeredLinks.push(this.linkLastBottom);
 		}
 		
 		//insertion des liens en haut et en bas de la liste
 		removeChildren(this.topMiddleBar);
 		removeChildren(this.bottomBar);
 		$(this.topMiddleBar).appendChild($(this.navDivTop));
 		$(this.bottomBar).appendChild($(this.navDivBottom));
 		
 		//rendu des liens visibles - cette opération est faite à chaque affichage d'une page
 		this.setVisibleLinks();
 		
 		delete link;
 		
 },
 setVisibleLinks: function(){
 		for(var i=0; i<this.registeredLinks.length;i++){
 			var link = this.registeredLinks[i];
 			if($(link)){
 				$(link).hide();
 				$(link).removeClassName("selected");
 			}
 		}
 		
 		this.links= new Array();
 		this.linksPage= new Array();
 		this.linksSpecs= new Array();
 		if(this.pageSelected == 1 && this.nbTotalPage >this.opts.nbPageNav){ // dans le cas de la première page s'il y a plus de 2 pages
 			for(var i=1; i<=this.opts.nbPageNav;i++)
	 		{
	 			this.links.push(i+"_top");
	 			this.links.push(i+"_bottom");
	 			this.linksPage.push(i);
	 		}
 			this.linksSpecs.push(new Array("_next_top",this.showPage.bindAsEventListener(this,this.pageSelected+1)));
	 		this.linksSpecs.push(new Array("_next_bottom",this.showPage.bindAsEventListener(this,this.pageSelected+1)));
	 		this.linksSpecs.push(new Array("_last_top",this.showPage.bindAsEventListener(this,this.nbTotalPage)));
	 		this.linksSpecs.push(new Array("_last_bottom",this.showPage.bindAsEventListener(this,this.nbTotalPage)));
	 	}else if(this.pageSelected==1 && this.nbTotalPage< this.opts.nbPageNav){ //dans le cas où il n'y a 1 à - de 10 pages
 			for(var i=1; i<=this.nbTotalPage;i++)
	 		{
	 			this.links.push(i+"_top");
	 			this.links.push(i+"_bottom");
	 			this.linksPage.push(i);
	 		}
	 		this.linksSpecs.push(new Array("_next_top",this.showPage.bindAsEventListener(this,this.pageSelected+1)));
	 		this.linksSpecs.push(new Array("_next_bottom",this.showPage.bindAsEventListener(this,this.pageSelected+1)));
	 		this.linksSpecs.push(new Array("_last_top",this.showPage.bindAsEventListener(this,this.nbTotalPage)));
	 		this.linksSpecs.push(new Array("_last_bottom",this.showPage.bindAsEventListener(this,this.nbTotalPage)));
	 	}else if(this.pageSelected == this.nbTotalPage && this.nbTotalPage>1){  // dans le cas des dernières pages
 			this.linksSpecs.push(new Array("_first_top",this.showPage.bindAsEventListener(this,1)));
	 		this.linksSpecs.push(new Array("_first_bottom",this.showPage.bindAsEventListener(this,1)));
	 		this.linksSpecs.push(new Array("_previous_top",this.showPage.bindAsEventListener(this,this.pageSelected-1)));
	 		this.linksSpecs.push(new Array("_previous_bottom",this.showPage.bindAsEventListener(this,this.pageSelected-1)));
	 		for(var i=this.nbTotalPage; i>=this.nbTotalPage-this.opts.nbPageNav+1;i--)
	 		{
	 			this.links.push(i+"_top");
	 			this.links.push(i+"_bottom");
	 			this.linksPage.push(i);
	 		}	
 		}else{ //dans le cas général, il y a des pages précédentes et suivantes
 			this.linksSpecs.push(new Array("_first_top",this.showPage.bindAsEventListener(this,1)));
	 		this.linksSpecs.push(new Array("_first_bottom",this.showPage.bindAsEventListener(this,1)));
	 		this.linksSpecs.push(new Array("_previous_top",this.showPage.bindAsEventListener(this,this.pageSelected-1)));
	 		this.linksSpecs.push(new Array("_previous_bottom",this.showPage.bindAsEventListener(this,this.pageSelected-1)));
	 		var pageLeft = (this.opts.nbPageNav - this.opts.nbPageNav%2)/2;
 			if(this.pageSelected <= pageLeft){
 				var start = 1;
 				var end = this.opts.nbPageNav;
 			}else{
 				var start = this.pageSelected-pageLeft;
 				var end = this.pageSelected+pageLeft;
 			}
 			for(var i=start; i<=end;i++)
	 		{
	 			this.links.push(i+"_top");
	 			this.links.push(i+"_bottom");
	 			this.linksPage.push(i);
	 		}
	 		this.linksSpecs.push(new Array("_next_top",this.showPage.bindAsEventListener(this,this.pageSelected+1)));
	 		this.linksSpecs.push(new Array("_next_bottom",this.showPage.bindAsEventListener(this,this.pageSelected+1)));
	 		this.linksSpecs.push(new Array("_last_top",this.showPage.bindAsEventListener(this,this.nbTotalPage)));
	 		this.linksSpecs.push(new Array("_last_bottom",this.showPage.bindAsEventListener(this,this.nbTotalPage)));
 		}
 		
 		for(var i=0; i<this.links.length;i++){
 			var tmp = "link"+this.links[i];
 			if($(tmp)){
 				$(tmp).show();
 			}
 			delete mp;
 		}
 		
 		for(var i=0; i<this.linksPage.length;i++){
 			if(this.linksPage[i]!=this.pageSelected){
	 			if($("link"+this.linksPage[i]+"_top")){
	 				$("link"+this.linksPage[i]+"_top").stopObserving();
	 				$("link"+this.linksPage[i]+"_top").observe('click', this.showPage.bindAsEventListener(this,this.linksPage[i]));
	 			}
	 			if($("link"+this.linksPage[i]+"_bottom")){
	 				$("link"+this.linksPage[i]+"_bottom").stopObserving();
	 				$("link"+this.linksPage[i]+"_bottom").observe('click', this.showPage.bindAsEventListener(this,this.linksPage[i]));
	 			}
 			}else{
 				$("link"+this.linksPage[i]+"_top").addClassName("selected");
 				$("link"+this.linksPage[i]+"_bottom").addClassName("selected");
 			}
 		}
 		
 		for(var i=0; i<this.linksSpecs.length;i++){
 			if($("link"+this.linksSpecs[i][0])){
 				$("link"+this.linksSpecs[i][0]).show();
 				$("link"+this.linksSpecs[i][0]).stopObserving();
 				$("link"+this.linksSpecs[i][0]).observe('click', this.linksSpecs[i][1]);
 			}
 		}
 		
 		
 		this.initSearchForm();
 		this.initEventsSort();
 		delete this.links;
 		delete this.linksPage;
 },
 initSort: function(){
 		var that = this;
 		if(this.opts.sort){
 			var span = new Element("span",{style:'float:left;'});
 			var col = new Element("span");
			$(col).addClassName("sortTitle");
			col.id = "sort_title";
			col.update(messageRessources["Sort by"]+" :");
			span.appendChild($(col));
 				
			this.columns.each(function(tmp)
			{
				var col = new Element("span");
				$(col).addClassName("sortLink");
 				col.id = 'sort_'+tmp[0];
 				var content = "";
 				if(tmp[3]!=null && tmp[3]!="")	content +="<img id='sort_img_"+tmp[0]+"' src='/images/"+tmp[3]+"' style='margin-bottom:-2pt;'/>  ";
 				content +=tmp[0];
 				col.update(content);
 				delete content;
 				span.appendChild($(col));
			})
			
			$(this.topBar).appendChild(span);
			
			var col = new Element("span");
			$(col).addClassName("sortResult");
			col.id = "sort_results";
			$(this.topBar).appendChild($(col));
			delete col;
 			delete tmp;	
 		}
 		
 },
 initEventsSort: function(){
 		for(var i=0; i<this.columns.length;i++){
 				if($('sort_'+this.columns[i][0])){
 					$('sort_'+this.columns[i][0]).stopObserving();
	 				$('sort_'+this.columns[i][0]).observe('click',this.sort.bindAsEventListener(this,this.columns[i]));
 				}
 		}
 },
 initSortingValues: function(){
 		var that = this;
 		if(this.opts.sort){
 			for(var i=0;i<this.sorts.length;i++)
 			{
 				var tmp = this.sorts[i].split(' ');
 				this.sorts[i] = tmp[0];
 				this.sortsWays[i] = tmp[1];
 				
 				delete tmp;
 			}
 			this.columns.each(function(tmp)
			{
	 			if(that.sorts.indexOf(tmp[1])!=-1)
	 			{
						$('sort_'+tmp[0]).addClassName("selected");
						$('sort_'+tmp[0]).innerHTML +="";
						if(tmp[2]!="" && tmp[3]!=""){
							$('sort_img_'+tmp[0]).src = "/images/"+tmp[2];
						}
				}else{
					if($('sort_'+tmp[0]).hasClassName("selected"))
					{
						$('sort_'+tmp[0]).removeClassName("selected")
						if(tmp[2]!="" && tmp[3]!=""){
							$('sort_img_'+tmp[0]).src = "/images/"+tmp[3];
						}
					}
				}
 			});
 		}
 },
 sort: function(e){
 		//puis on lance le raffraichissement avec le sorting
 		var obj = Event.element(e);
 		var data = $A(arguments);
 		var column = data[1];
 		var form = $(this.opts.searchForm);
 		
 		if($F(form['old_sort'])==column[1])
 		{
 			if($F(form['old_sort_sens'])=='ASC')
 			{
 				$(form['old_sort_sens']).value='DESC';
 			}else{
 				$(form['old_sort_sens']).value='ASC';
 			}
 		}else if($F(form['sort'])==column[1])
 		{
 			if($F(form['sort_sens'])=='ASC')
 			{
 				$(form['sort_sens']).value='DESC';
 			}else{
 				$(form['sort_sens']).value='ASC';
 			}
 		}else{
 			$(form['old_sort_sens']).value = $F(form['sort_sens']);
 			$(form['old_sort']).value = $F(form['sort']);
 			if(column[4]!="")
 			{
 				$(form['sort_sens']).value = column[4];
 			}else{
 				$(form['sort_sens']).value = this.opts.sortSensDefault;
 			}
 			$(form['sort']).value = column[1];
 		}
 		this.loadDataCount();
 		delete form;	 
 },
 loadDataCount: function(){
 		var that = this;
 		this.timeStartLoading = (new Date).getTime();
 		var params = null;
 		if(this.form!=null)  //serialization des paramètres du formulaire
 		{
 			params = this.form.serialize(true);
 		}
 		if(this.firstLoad && this.opts.useCookies && readCookie('currentFiltersBrowse_GameConnection2_'+this.opts.dataSearched+'_'+this.opts.con_id)!="" && readCookie('currentFiltersBrowse_GameConnection2_'+this.opts.dataSearched+'_'+this.opts.con_id)!=null)
		{
			try{
				params = readCookie('currentFiltersBrowse_GameConnection2_'+this.opts.dataSearched+'_'+this.opts.con_id).toQueryParams();
				//pour le premier chargement on réécrit les valeurs dans le formulaire
				this.form.sort.value = params.sort;
				this.form.sort_sens.value = params.sort_sens;
				this.form.old_sort.value = params.old_sort;
				this.form.old_sort_sens.value = params.old_sort_sens;
				if(params.searchTag && this.form.searchTag) this.form.searchTag.value = params.searchTag;
				if(params.profilTag && this.form.profilTag){
					this.form.profilTag.value = params.profilTag;
					$("profil_content").update($("profil_"+params.profilTag).innerHTML);
				}
			}catch(e){ }
		}
		if(this.opts.useCookies)
		{
			createCookie('currentFiltersBrowse_GameConnection2_'+this.opts.dataSearched+'_'+this.opts.con_id,Object.toQueryString(params),0);
		}
 		new Ajax.Request(this.opts.loadDataCountUrl,{
 			asynchronous: true,
 			parameters: params,
 			onComplete: function(transport){
 				that.timeEndLoading = (new Date).getTime();
 				var json = eval(transport.responseText);
 				that.dataCount = json.count;
 				if(that.dataCount[0]==0){
		 			$(that.middleBar).update(that.noresultTemplate);
		 			that.nbTotalPage = 0;
		 			that.setCookiePage();
		 		}else{
			 		that.nbTotalPage = Math.ceil(that.dataCount[0]/that.opts.nbPerPage);
			 		that.setCookiePage();
//			 		that.pageSelected = 1;
			 		that.expandData();
		 		}
		 		$('sort_results').update(render(that.resultTemplate,that.dataCount));
		 		that.initNavigation();
		 		that.timeEndComponent = (new Date).getTime();
		 		that.showTime();
 			}
 		});
 },
 loadSort: function(){
 		var that = this;
 		var params = null;
 		if(this.form!=null)  //serialization des paramètres du formulaire
 		{
 			params = this.form.serialize(true);
 		}
 		this.type = this.form['type'].value;
 		new Ajax.Request(this.opts.loadParamsUrl,{
 			parameters: params,
 			asynchronous: true,
 			onComplete: function(transport){
 				var json = eval(transport.responseText);
 				if(json.columns.length>0)
 				{
	 				that.columns = json.columns;
	 				that.initSort();
	 				that.loadDataCount();
 				}
 			}
 		});
 },
 expandData: function(){
 		//costruction de la page
 		var div = new Element("div");
 		div.id = 'rPage'+ this.pageSelected;
 		$(div).setStyle({width:'100%'});
 		var ul = new Element("ul",{style :'display:table;width:100%'});
 		var start = 0+((this.pageSelected-1)*this.opts.nbPerPage);
 		var that = this;
 		var params = null;
 		if(this.form!=null)  //serialization des paramètres du formulaire
 		{
 			params = this.form.serialize(true);
 		}
 		if(this.firstLoad && this.opts.useCookies && readCookie('currentFiltersBrowse_GameConnection2_'+this.opts.dataSearched+'_'+this.opts.con_id)!="" && readCookie('currentFiltersBrowse_GameConnection2_'+this.opts.dataSearched+'_'+this.opts.con_id)!=null)
		{
			try{
				params = readCookie('currentFiltersBrowse_GameConnection2_'+this.opts.dataSearched+'_'+this.opts.con_id).toQueryParams();
			}catch(e){ }
			this.firstLoad = false;
		}
 		//chargement des données // PD data loading
 		new Ajax.Request(this.opts.loadDataUrl+'?start='+start+'&nbr='+this.opts.nbPerPage,{
 			asynchronous: true,
 			parameters: params,
 			onCreate: this.showIndicator.bindAsEventListener(this),
 			onComplete: function(transport){
// 				$('onlyTag').value = false;
 				var json = eval(transport.responseText);
 				if(json.bindings.length>0)
 				{
	 				that.data = json.bindings;
	 				that.sorts = json.sorts;
	 				that.initSortingValues();
	 				//on insère les résultats dans la page	
			 		for(var i=0; i< that.data.length;i++)
			 		{
			 			var li = new Element("li",{style :'display:table-row;width:100%'});
			 			li.innerHTML = render(that.lineTemplate,that.data[i]);
			 			ul.appendChild(li);
			 		}
			 		div.appendChild(ul);
			 		that.hideIndicator(that);
			 		$(that.middleBar).appendChild($(div));
 				}else{
 					$(that.middleBar).update(that.noresultTemplate);
		 			that.nbTotalPage = 0;
 				}
 			}
 		});
 },
 showPage: function(e){
 		
 		//  on récupère les différents objets
 		var obj = Event.element(e);
 		var data = $A(arguments);

 		// on cache l'ancienne page
 		$('link'+this.pageSelected+"_top").removeClassName("selected");
 		$('link'+this.pageSelected+"_bottom").removeClassName("selected");
 		this.pageSelected = data[1];
 		
 		if(this.opts.useCookies)
		{
			createCookie('currentPageBrowse_GameConnection_'+this.opts.dataSearched+'_'+this.opts.con_id,this.pageSelected,0);
		}
 		//on supprime tous les événements de navigation
 		Event.unloadCache();

 		//on charge les données
 		this.expandData();
 		
 		this.setVisibleLinks();
 		
 },
 showIndicator: function(e){
 		removeChildren(this.middleBar);
 		$(this.middleBar).appendChild($(this.ajaxLoad));
 },
 hideIndicator: function(e){
 		removeChildren(this.middleBar);
 }
});


function render(template,data){
	if(template!="")
	{
		var html= new String(template);
		for(i=0; i<data.length;i++){
			if(data[i]==null)
			{
				data[i] = "";
			}
			html = html.replace(new RegExp("(x"+i+"x)","g"),data[i]);
		}
		return html;
	}else{
		return "Template doesn't exist, please contact administrator";
	}
}

function removeChildren(element){
	while ($(element).firstChild) {
  	$(element).removeChild($(element).firstChild);
	}
}

// fonctions permettant le scroll de la bar alphanumérique
var scrollInt  = null;
function startScrolling(element, x_scroll, y_scroll){
  scrollBT(element,x_scroll,y_scroll);
}

function scrollBT(element, x_scroll, y_scroll){
	new Effect.Move($(element),{x: (-x_scroll), y: (-y_scroll), mode:'relative'});
	scrollInt = setTimeout(function (){ scrollBT(element,x_scroll,y_scroll); },10);
}

function stopScrolling(){
	clearInterval(scrollInt);
}

