var pathAjaxScript 		= 'index.php?DM=ajax'
var poll 				= ''

$(jqInit)

/**
 *	Méthode d'nitialisation du script javascript
 *
 */ 
function jqInit(){
	

	setAjax()
				
	// Handle divers
	$('.linkSubmit').click(handleEvent);

	$('button').click(handleEvent);
	
	/***************************************************************************/
	if(SYS_POLLING_SESSION)setPolling()	
	
	/***************************************************************************/
	//	SCROLLER DE TEXTE (entete)
	
	$jScroller.add("#head-scroller","#scroller","left",5);
	$jScroller.start();
	
	/***************************************************************************/
	//	Bulles legendes sur les images portant la class "legend-bubble" et un alt 
	//	Attention ces images doivent impérativement etre encapsulés dans une  balise '<a>'
	
	$('.legend-bubble').each(function (i) {
		legendBubbleAlt			=	$(this).attr('alt');
		if(legendBubbleAlt.length){
			bubbleHTML			=	'<div class="bubble-zone">'+legendBubbleAlt+'</div>';
			$(this).parent().parent().append(bubbleHTML);
			bubbleZoneHeight	=	$('.bubble-zone').height()
			$('.bubble-zone').css({'width':$(this).width(),'margin-top':-bubbleZoneHeight,'opacity':0.8})
		}
	});
	
	//	calendrier simple
	$('.date').datepicker()			
	
	//	calendrier pour date de naissance
	now			=	new Date();
	yearNow		=	now.getFullYear();
	yearFrom	=	yearNow-100;
	$('.dateNaissance').datepicker({ changeYear: true,yearRange: yearFrom+':'+yearNow})
	/***************************************************************************/
	//	Rollover sur les compétitions (tableau)
	
	$('div.competitionMouseOn').mouseover(handleEvent);
	$('div.competitionMouseOn').mouseout(handleEvent);
	
	/***************************************************************************/
	//	Rollover sur les onglets labels (compétitions)
	
	$('div.discipline-item').mouseover(handleEventOnglets);
	$('div.discipline-item').mouseout(handleEventOnglets);
	
	
	/***************************************************************************/
	//	Clic sur les compétitions du calendrier
	
	$('A.competitionLinks').click(handleEvent);
	$('IMG.competitionLinks').click(handleEvent);
	
	$('DIV.ajaxEditor').dblclick(handleEvent);	
	
	if($('.uaCriteriaZone').length)setUaSection()		
	
	$('#head-banner-zone').css({'display':'block'});
	$('#head-banner-zone').cycle();
	
	
}

/***************************************************************************/
// Définition Ajax
function setAjax(){
	
	// Ajout d'une zone HTML pour les traitements AJAX en tâche de fond
	$.ajaxSetup	({
					cache:false,
					async:false						
				})		
				
	if($('#ajaxBox').length)return

	$('body').append('<div id="ajaxBox" style="width:100%;height:100px;border:1px solid red;display:none;"></div>')
}

/***************************************************************************/
// Polling des sessions
function setPolling(){
	interval = (SYS_POLLING_SESSION<5)?5:SYS_POLLING_SESSION
	hP = setInterval(doPolling,interval*1000)
}

function doPolling(){
	data 		= {TASK:'polling',SUBTASK:'get-session'}
	$('#ajaxBox').load(pathAjaxScript,data)
	if(poll.length){
		if(session!=poll)window.location.href = 'http://'+DOMAIN
	} else{
		poll = session
	}
}

/***************************************************************************/
//	Actions sur les evenements de certains objets

function handleEvent(e){
	o = e.target
	t = e.type
	switch(t){
		case 'mouseover':	
			if($(o).parent().hasClass("competitionMouseOn")){
				$(o).parent().addClass("table-container-line-over");
				//$(o).parent().children('.column-1').html('<img src="/img/arrow-competitions.png" alt="arrow" />');
			}
		break;
		case 'mouseout':	
			if($(o).parent().hasClass("competitionMouseOn")){
				$(o).parent().removeClass("table-container-line-over");
				//$(o).parent().children('.column-1').html('');
			}
		break;
		case 'click':
			// - capture d'evenements provenant d'objet identifies par une classe ----------------------------------------------
			if($(o).hasClass('competitionDetailsLinks')){
				return false
			}
			if($(o).hasClass('competitionLinks')){
				fctDisplayCompetitionDetails(o)
				return false
			}
			switch(o.id){
				// Le visiteur valide son email pour obtenir son mot de passe
				case 'idButLostPassword':
					if(!checkForm($('#idFormLostPassword')))return false
					$('#idFormLostPassword').submit()
					break;
				// Le visiteur rafraichi le code de securité
				case 'idButRefreshCodeCaptcha':
					//prompt('url','http://'+DOMAIN+'/index.php?'+$(o).attr('jsParam')+'&sid='+Math.random())
					$('#idImgCodeCaptcha').attr('src','http://'+DOMAIN+'/index.php?'+$(o).attr('jsParam')+'&sid='+Math.random())
					break;
				// Le visiteur clique sur le lien Mot de Passe oublié
				case 'idLinkLostPassword':
					//alert($('#idLinkLostPassword').attr('href'))
					$('#idFormLogin').attr('action',$('#idLinkLostPassword').attr('href'))
					$('#idButtonLoginSubmit').click()  
					return false;
					break;

			}
			
		break;
		case 'dblclick':			
			if($(o).hasClass('ajaxEditor')){
				o_val			=	$(o).html();
				recordID		=	$(o).attr('jqParam');
				builder_data 	=	{'objet':o.id,'step':'1','fld_val':o_val,'recordID':recordID}
				$(o).load(pathAjaxScript+'&TASK=utilities&SUBTASK=loadLicence',builder_data);
			}
		break;
	}
}

function  fctDisplayCompetitionDetails(o){

	objData		=	$(o).attr('jqParam');
	expData		=	objData.split('|')
	if(expData.length	==	1){
		expData[1]		=	1
	}
	data		=	{'competitionID':expData[0],'thumbnail':expData[1]}
	
	if($('.competionDetails-box').css('display')	==	'block'){
		$('.competionDetails-box').fadeOut(250)
	}
	$('.table-container-content-main').fadeOut(250,function(){
		$('.competionDetails-box').load(pathAjaxScript+'&TASK=competition&SUBTASK=view',data);
		$('.competionDetails-box').fadeIn(250)
		
		/***************************************************************************/
		//	Clic sur les onglets des compétitions en mode détails
		$('A.competitionLinks').click(handleEvent);
		/***************************************************************************/
		// Initialisation de la phase d'inscription lorsque la classe 
		// competitionBooking-Box est detectee
		if($('.competitionBooking-Box').length)setBooking()	
	})
	

		
}


/***************************************************************************/
//	Actions sur les evenements des onglets

function handleEventOnglets(e){
	o = e.target
	t = e.type

	switch(t){
		case 'mouseover':	
			if($(o).hasClass("discipline-item")){
				$(o).addClass("discipline-item-hover");
			}else{
				$(o).parent().addClass("discipline-item-hover");
			}	
		break;
		case 'mouseout':	
			if($(o).hasClass("discipline-item")){
				$(o).removeClass("discipline-item-hover");
			}else{
				$(o).parent().removeClass("discipline-item-hover");
			}	
		break;
	}
}



/***************************************************************************/
// Méthode d'analyse des formulaires pour contrôle des données saisies
/***************************************************************************/
function checkForm(oForm,displayError,autoSubmit){
	// On balaye les champs du formulaire (objet jquery) passé en param?tre
	
	displayError 	= (displayError)?displayError:true
	autoSubmit 		= (autoSubmit)?autoSubmit:true
	
	typeData 		= ['alphanum','captcha','email','radio']
	modeInput 		= ['required']
	
	reType 			= new RegExp(typeData.join('|'),'gi')
	reMode 			= new RegExp(modeInput.join('|'),'gi')
	
	msErr			= []
	msEnlightOn		= []
	
	check			= true
	
	aFieldProcessed = []
	
	$(':input',$(oForm)).each(
								function(){
									data = $(this).attr('jqData')										// recherche tous les champs contenant l'attribut 
									if(!data)return
									val 		=  $(this).val()
									hType 		= data.match(reType)
									if(data.match(reMode)==null){
										hMode = ['']	
									} else {
										hMode = data.match(reMode)
									}
									required	= hMode[0]=='required'?true:false 
									enlightField(this,true)
									$('input[name='+$(this).attr('name')+']').each(function(){enlightField(this,true)})
									if(in_array($(this).attr('name'),aFieldProcessed))return
									aFieldProcessed[aFieldProcessed.length] = $(this).attr('name');
									switch(hType[0]){
										// ---------------------------------------------------------------------------------------------------------------										
										// Test syntaxique de validite de la saisie d'une chaîne alphanumérique
										// ---------------------------------------------------------------------------------------------------------------	
										case 'alphanum':
											reCaptcha =  new RegExp('.+','gi')
											//alert(val.match(reCaptcha))
											hString = val.match(reCaptcha)
											if((required&&hString==null)||(!required&&val.length&&hString==null)){
												check = false
												msErr[msErr.length] 					=   replaceTagMsg(this,KEY_FORM_WRONG_ALPHANUM_INPUT)
												enlightField(this,false)
											}
																			
											break																			
										// ---------------------------------------------------------------------------------------------------------------										
										// Test syntaxique de validite de la saisie d'un captcha
										// ---------------------------------------------------------------------------------------------------------------										
										case 'captcha':
											reCaptcha =  new RegExp('['+CAPTCHA_CHARSET+']+','gi')
											//alert(val.match(reCaptcha))
											hString = val.match(reCaptcha)
											if(hString==null){
												check = false
												msErr[msErr.length] 		=   replaceTagMsg(this,KEY_FORM_WRONG_CAPTCHA_INPUT)
												enlightField(this,false)
											}
																			
											break
										// ---------------------------------------------------------------------------------------------------------------										
										// Test de la syntaxe d'un email
										// ---------------------------------------------------------------------------------------------------------------										
										case 'email':
											reMail = /^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d- ]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi
											hString = val.match(reMail)
											// Si requis ET non correct OU non requis ET renseigné ET non correct
											//		=> on check l'erreur de saisie
											if((required&&hString==null)||(!required&&val.length&&hString==null)){
												check = false
												msErr[msErr.length] 		=   replaceTagMsg(this,KEY_FORM_WRONG_EMAIL_INPUT)
												enlightField(this,false)
											}
											break						
										// ---------------------------------------------------------------------------------------------------------------										
										// Test si au moins un champ radio sur un groupe est selectionne
										// ---------------------------------------------------------------------------------------------------------------										
										case 'radio':
											if(required&&!$('input[name='+$(this).attr('name')+']:checked').length){
												check = false													
												msErr[msErr.length] 	=   replaceTagMsg($('input[name='+$(this).attr('name')+']').eq(0),KEY_FORM_WRONG_RADIO_INPUT)
												$('input[name='+$(this).attr('name')+']').each(function(){enlightField(this,false)})
											}
											break;
									}
									
									
									
								}
							)	
							
	if(displayError&&msErr.length){
		
		msErr = msErr.join('\n')
		
		alert(msErr)

	}
	
	
	return check
}


function replaceTagMsg(obj,msg){
	re = /\|FIELD\|/
	//alert($(obj).attr('name'))
	msg = msg.replace(re,$(obj).attr('name'))
	return msg
}


// Méthode utilisé par checkForm pour metter en valeur les champs présentant une erreur de saisie
function enlightField(o,initColor){

	errColor 	= FORM_WRONG_CONTENT_COLOR
	errBgColor	= FORM_WRONG_CONTENT_BACKGROUND
	
	if($(o).css('backgroundColor')==errColor||initColor){
		if($(o).data('backgroundColor'))$(o).css({'backgroundColor':$(o).data('backgroundColor'),'color':$(o).data( 'color')})
	} else {
		$(o).data( 'backgroundColor',$(o).css('backgroundColor'))
		$(o).data( 'color',$(o).css('color'))
		$(o).css({'backgroundColor':errBgColor,'color':errColor})
	}
													
	
}



/***************************************************************************/
//	Resizeur de texte, 
// 	agrandir ou diminuer la taille des caractères
//	pour les objets en class '.textSizer'

function textResizer(s){	
	minSize								=	8;
	maxSize								=	18;
			
	$('.textSizer').each(function(i) {
		tSize							=	$(this).css('font-size').replace('px','')*1;
		switch(s){
			case '+':
				if(tSize	<	maxSize){
					newTSize			=	tSize+1+'px';
				}
			break;
			case '-':
				if(tSize 	>	minSize){
					newTSize			=	tSize-1+'px';
				}				
			break;
		}	
		$(this).css({'font-size':newTSize})		
	});
	
	$('.textSizer *').each(function(i) {
		$(this).css({'font-size':newTSize})		
	});
}


/***************************************************************************/
//	Menu déroulant accordéon
// 	Permet d'afficher ou de cacher les éventuels sous élément d'un item
//	dans le sommaire de gauche

function accordionMenu(itemsClass,itemId){
	
	totalItemHeight			=	0;
	$('#'+itemId+' > span').each(function (i) {
		thisItemHeight	=	$(this).css('height').replace('px','')*1.2
		totalItemHeight	+=	thisItemHeight;	
	});
	
	$('.'+itemsClass).each(function (i) {
		if($(this).attr('id')	!=	itemId){
			if($(this).css('display')	==	'block'){
				$(this).animate({height:0,opacity:0},250,function(){
					$(this).css({display:'none'})
				});
			}
		}
	});
	
	if($('#'+itemId).css('display')	==	'block'){
		$('#'+itemId).animate({height:0,opacity:0},250,function(){
			$('#'+itemId).css({display:'none'})
		});
	}else{
		$('#'+itemId).css({display:'block',opacity:0,height:0})
		$('#'+itemId).children().css({display:'block'})
		$('#'+itemId).animate({opacity:1,height:totalItemHeight},250)
	}	
}			


// ----------------------------------------------------------------------------------------------------------------------------
//  Méthodes collectant les criteres et retournant un objet
// ----------------------------------------------------------------------------------------------------------------------------
function fScan(oJq,oForm){
	aObj = []
	re = new RegExp(String.fromCharCode(10))
	oJq.each(
				function(){
					
							
							switch(this.type){
								case 'radio':
								case 'checkbox':
									objProperty = $(this).attr('name');
									val = $('[name='+$(this).attr('name')+']:checked').val()
									objvalue	= (typeof(val)=='undefined')?'':val
									break;
								default:
									objProperty = $(this).attr('name');
									objvalue	= $(this).val()
									//alert(objProperty+' '+objvalue)
									
									break;
							}
							
							//alert(objvalue+' '+objvalue.fromCharCode(13))
							//alert(objvalue.match(re))
							//objvalue = objvalue.replace()
							//alert(objvalue+' '+objvalue.match(re)+' ['+objvalue.replace(re,'<br />')+']')
							//objvalue = objvalue.replace(re,'<br />')
							//objvalue = objvalue.replace(re,'<br />')
							objvalue = replaceNewLine(objvalue)
							//alert(objProperty+' '+objvalue)
							aObj[aObj.length] = '"'+objProperty+'":"'+objvalue+'"'
							//alert(aObj[aObj.length])
						}
			)
	
	//prompt('code',aObj.join(','))		
	eval('obj = {'+aObj.join(',')+'}')	
	
	return obj
}

function replaceNewLine(string){
	
	var str = string.split(String.fromCharCode(10))

	if(str.length>1){
		
		string = str.join('<br />')
		
	}
	
	return string
}


/***************************************************************************/
// Méthode d'initialisation de la phase de booking (reservation)
function setBooking(){
	$.getScript('http://'+DOMAIN+'/js/booking.js')
	bookInit()
}
function setUaSection(){
	$.getScript('http://'+DOMAIN+'/js/uaSection.js')
	uaInit()
}



/***************************************************************************/
// 	Méthode de navigation entre les étapes de la creation (modification)
//	de la fiche tireur
function loadAjaxContent(stepping,recordID,subtask,sendedData){
	if(!subtask){
		subtask	=	'view'
	}else{
		subtask	=	subtask
	}
	if(!sendedData){
		data		=	{'shooter-card-step':stepping,'recordID':recordID}	
	}else{
		data		=	sendedData;
	}
	$('.links-stepping').each(function(){
		if($(this).hasClass('stepping-onglets-selected')){
			$(this).removeClass('stepping-onglets-selected');
			$(this).addClass('stepping-onglets')
		}		
	});
	$('#link-target-'+stepping).attr('class','links-stepping stepping-onglets-selected');
	
	//data		=	{'shooter-card-step':stepping,'recordID':recordID}	
	if($('.shooter-card-box-content').css('display')	==	'block'){
		$('.shooter-card-box-content').fadeOut(250,function(){
			$('.shooter-card-box-content').load(pathAjaxScript+'&TASK=shooter-card&SUBTASK='+subtask,data,function(){
				$('.shooter-card-box-content').fadeIn(250)
			});
		})
	}
}

function refreshAjaxContent(stepping,recordID){
	$('.links-stepping').each(function(){
		if($(this).hasClass('stepping-onglets-selected')){
			$(this).removeClass('stepping-onglets-selected');
			$(this).addClass('stepping-onglets')
		}		
	});
	$('#link-target-'+stepping).attr('class','links-stepping stepping-onglets-selected');
	
	if($('.shooter-card-box-content').css('display')	==	'block'){
		$('.shooter-card-box-content').fadeOut(250,function(){
			$('.shooter-card-box-content').fadeIn(250)
		})
	}
}

// Méthode in_array()
function in_array (needle, haystack, argStrict) {
   var key = '', strict = !!argStrict;
   if (strict) {
       for (key in haystack) {
           if (haystack[key] === needle) {
               return true;
           }
       }
   } else {
       for (key in haystack) {
           if (haystack[key] == needle) {
              return true;
           }
       }
   }
   return false;
}

function registeringForm(typeForm,targetStep,recordID,formFields){
	switch(typeForm){
		case 'stepper-form':
		case 'identification':
		case 'coordonnees':
		case 'federation':
		case 'weapon-form':
			/*
			if(checkForm($('#identification-form'))){
				loadAjaxContent((targetStep-1),recordID)
			}
			*/
			if(!formFields){
				classFields	=	'registerFld';
			}else{
				classFields	=	formFields;
			}
			builder_data 	= 	$("."+classFields).serializeArray();
			loadAjaxContent(targetStep,recordID,'save',builder_data)
		break;
		case 'weapon-load':
			builder_data 	= 	{'shooter-card-step':targetStep,'recordID':recordID};
			loadAjaxContent(targetStep,recordID,'view',builder_data)
		break;
	}
}

// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Méthode pour fusionner les objets
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function mergeObject(){
     var tF = new Array()
     for(v=0;v<arguments.length;v++){
          for(i in arguments[v]){
               tF[tF.length] = i+':\"'+arguments[v][i]+'\"'
           }        
     }
     eval('oF = {'+tF.join(',')+'}')
     return oF
}

// affichage des checkbox pour disciplines
function displayDiscipline(boxId,stepping,recordID,federationID,row){	
	data		=	{'shooter-card-step':stepping,'recordID':recordID,'federationID':federationID,'row':row}
	$('#'+boxId).fadeOut(250,function(){
		$('#'+boxId).load(pathAjaxScript+'&TASK=shooter-card&SUBTASK=disciplineLoader',data,function(){
			$('#'+boxId).fadeIn(250)
		});
	})
}

function deleteFederation(divID,recordID){
	expFederation 	= 	divID.split('-');
	federationID	=	expFederation[2];
	if(confirm('Etes vous sur ?')){
		$('#'+divID).animate({opacity:0,height:0},500,function(){
			$('#'+divID).css({display:'none'})
			builder_data 	=	{'federationID':federationID,'recordID':recordID}
			$('#'+divID).load(pathAjaxScript+'&TASK=utilities&SUBTASK=deleteFederation',builder_data);
			loadAjaxContent('3',recordID)
		})
	}
}

function uptUserDiscipline(divID,disciplineID,federationID,recordID,type){
	builder_data 	=	{'federationID':federationID,'recordID':recordID,'disciplineID':disciplineID,'type':type}
	$('#'+divID).load(pathAjaxScript+'&TASK=utilities&SUBTASK=updateDiscipline',builder_data);
}

function dspCupCompet(boxID,mouseAction){
	switch(mouseAction){
		case 'on':
			$('#'+boxID).fadeIn(350)
		break;
		case 'off':
			$('#'+boxID).fadeOut(100)
		break;
	}
}

function printShooterCard(f){
	oForm =	document.forms[f]
	window.open(oForm.action, "popup");
	oForm.target = "popup";
	oForm.submit();
}

/***************************************************************************/
// 	Méthode de navigation entre les articles d'une même rubrique
function loadAjaxHtmlContent(onglet,recordID){
	$('.links-stepping').each(function(){
		if($(this).hasClass('stepping-onglets-selected')){
			$(this).removeClass('stepping-onglets-selected');
			$(this).addClass('stepping-onglets')
		}		
	});
	$('#link-target-'+onglet).attr('class','links-stepping stepping-onglets-selected');
	
	data		=	{'recordID':recordID}	
	if($('.html-box-content').css('display')	==	'block'){
		$('.html-box-content').fadeOut(250,function(){
			$('.html-box-content').load(pathAjaxScript+'&TASK=html-content&SUBTASK=html',data,function(){
				$('.html-box-content').fadeIn(250)
			});
		})
	}
}

/***************************************************************************/
// 	Méthode d'affichage de la carte SWF
function appMap(){
	floaterDSP					=	$('#floater').css('display')
	htmlCode					=	'<object type="application/x-shockwave-flash" data="/swf/carte.swf" width="1000" height="830"><param name=quality value=high><param name="wmode" value="transparent"><param name="movie" value="/swf/carte.swf" /></object>';
	switch(floaterDSP){
		case 'block':
			$('#floater').fadeOut(250,function(){
				$('#floater').html('');
			})
		break;
		case 'none':
			$('#floater').html(htmlCode);
			$('#floater').fadeIn(250)
		break;
	}
}
/***************************************************************************/
// 	Méthode d'affichage des pdf
function pdfDisplay(boxId,boxClass){
	
	$('.'+boxClass).each(function(){
		$(this).fadeOut(250);
	})
	switch($('#'+boxId).css('display')){
		case 'none':
			$('#'+boxId).fadeIn(250);
		break;
		case 'block':
			$('#'+boxId).fadeOut(250);
		break;
	}
	
}

/***************************************************************************/
// 	Méthode de connexion ajax
function connectAjaxUser(classBox){
	userLogin	=	$('.'+classBox+':eq(0)').html()
	userMdp		=	$('.'+classBox+':eq(1)').html()
	data		=	{'userLogin':userLogin,'userMdp':userMdp}	
	$('#connectingBox').load(pathAjaxScript+'&TASK=login',data);
}

/***************************************************************************/
// 	Méthode d'affichage des informations des fédérations
function dspFederationInformation(federationId,federationBox,recordID){
	$('.'+federationBox).each(function(){
		$(this).fadeOut(250);
	})
	data		=	{'recordID':recordID}	
	if($('#'+federationId).css('display')	==	'none'){
		$('#'+federationId).load(pathAjaxScript+'&TASK=html-content&SUBTASK=federation-informations',data,function(){
			$('#'+federationId).fadeIn(250);
		});
	}
}

// Méthode mémorisant la valeur des champs crit?res pour rappel ultérieur
function setCriteriaDefValue(cName){
	//if(typeof(flagData)=='undefined')flagData = new Array()
	//if(typeof(flagData[cName])!='undefined')return
	//flagData[cName] = true;
	
	$(cName).each(
							function(){
								$(this).data('critDefVal',$(this).val())
							}
					)
}

function initCritDefValue(cName){
	$(cName).each(
							function(){
								//alert(this.type)
								cur = this
								switch(cur.type){
									case 'select-one':
										$('option',$(cur)).each(
																	function(){
																		if($(this).attr('value')==$(cur).data('critDefVal'))$(this).attr('selected',true)
																	}
																)
										break;
									case 'text':
										$(this).val($(this).data('critDefVal'))
										break;
								}
							}
					)
	setCriteriaDefValue()	
}


function scrollTop() {
	$('html').animate({scrollTop:0}, 100); 
}


function scrollTopSample() {
	$('a[href*=#]').click(function() {
		var $target = $(this.hash);
		$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		$('html,body').animate({ scrollTop: $target.offset().top }, 1000, "easeinout");
		return false;
	})
}

function boxCheckerAll(th,checkBoxClass,field,boxToLoad,ajaxLoad){
	$('.'+checkBoxClass).each(function(){
		$(this).attr({'checked':th.checked});
		if($(this).attr('checked')	==	true){
			
		}
	});
	if(ajaxLoad	==	true){
		getCheckboxValToObjet(th,checkBoxClass,field,boxToLoad,ajaxLoad)
	}
}

function getCheckboxValToObjet(th,checkBoxClass,field,boxToLoad,ajaxLoad){
	aObj = []
	$('.'+checkBoxClass).each(function(){
		if($(this).attr('checked')	==	true){
			aObj[aObj.length] = $(this).val();
		}
	});
	datas		=	{'typeData':field,'year':$('#slt-year').val(),'field[]':aObj}	
	
	if(ajaxLoad	==	true){
		$('#'+boxToLoad).load(pathAjaxScript+'&TASK=filters&SUBTASK=toto',datas,function(){
			$('#'+boxToLoad).fadeIn(350);
		});
	}
}

function fieldsFormConcat(f){
	fieldClass	=	new Array	(
									'radio-type',
									'slt-year-filter',
									'checkBox-nat',
									'checkBox-fed',
									'checkBox-dis',
									'checkBox-compet',
									'checkBox-riffle',
									'checkBox-rCalibre',
									'checkBox-length',
									'checkBox-rCartridge',
									'checkBox-carabin',
									'checkBox-cCalibre',
									'checkBox-cCartridge',
									'checkBox-optique'
								);
	for(i=0;i<fieldClass.length;i++){
		aObj	=	[]
		$('.'+fieldClass[i]).each(function(){
			if($(this).attr('type')	==	'select-one'){
				aObj[aObj.length] = $(this).val();
			}
			if($(this).attr('checked')	==	true){
				aObj[aObj.length] = $(this).val();
			}
		});
		$('#'+fieldClass[i]).val(aObj)
	}
	document.forms[f].submit()
}

function refreshResults(thValue,competitionID,sort){
	data	=	{'competitionID':competitionID,'categorieID':thValue,'sort':sort}
	$('#results-competition-loader').fadeOut(250,function(){
		$('#results-competition-loader').load(pathAjaxScript+'&TASK=results&SUBTASK=view',data);
		$('#results-competition-loader').fadeIn(250)
	})
}
