function init()
{
	//Gestion image de fond 
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}	
		
	/*VERS ACCUEIL*/
	$('#logo').click(function(){ document.location = fd_PATH == '' ? './' : fd_PATH; });
	$('#accueil').click(function(){ document.location = fd_PATH == '' ? './' : fd_PATH; });
	
	$('#pubObs').click(function(){ document.location = fd_PATH + 'creer-son-entreprise/franchises.htm' });
	fd_ajax('txtHeader','');
	
		
		
	/* MOTEUR DE RECHERCHE */
	if(document.getElementById('moteur'))
	{
		/*$('#poste').val('');
		$('#enseigne').val('');
		$('#lieu').val('');*/
		$('#criteres input[type="checkbox"]').each(function(){
			if(this.checked)
				openRechercheAvancee('quick');
			//this.checked = false;
		});	
		
		
		/*** SELECT */
		$('.selectMoteur').each(function(){
			disableSelect(this);
		});	
		
		/*** INPUT */
		if(document.getElementById('poste')){
			$('#posteTxt').click(function(){
				$(this).val('').css('color','#000');
				$('#poste').val('');
			});
		}
		
		//entete
		$('.selectMoteur div').each(function(){
			$(this).css({ opacity: 0.5 });	
		});									 
											
		$('.selectMoteur ul li').each(function(){
			tmpTab	=	this.id.split('_');
			if(tmpTab[1] == '')
			{
				$(this).css('display','none').css({ opacity: 0.5 }).click(function() {	
					$(this).parent().parent().find('div').html( $(this).html() ).css({ opacity: 0.5 });
				});
			}
		});
		//ouverture - fermeture elements
		$('.selectMoteur').click(function() {	
			if(	$(this).find('ul').css('display') == 'block' )						  
				$('.selectMoteur ul').css('display','none');
			else
				$(this).find('ul').css('display','block');
		});
		
		$('html').click(function(event) {
			testId	=	getClosestId(event.target);
			if( testId == undefined  ||  (testId != 'posteSel' && testId != 'enseigneSel' && testId != 'lieuSel') )
				$('.selectMoteur ul').css('display','none');
		 });
		
		//gestion li
		$('.selectMoteur li').hover(
			function() { $(this).css('background-color','#eee'); }, 
			function() { $(this).css('background-color','#fff'); });
		
		$('.selectMoteur li').click(function() {
			tmpTab		=	$(this).attr('id').split('_');
			type		=	$(this).parent().parent().attr('id').replace('Sel','');
			divParent	=	$(this).parent().parent().find('div');
			typeMaj		=	divParent.html();
			
			//pour bloquer cumule criteres
			
			if(tmpTab[0] == 'lS')
			{
				$('#enseigne').val('');
				$('#poste').val('');
			}
			else if(tmpTab[0] == 'eS')
			{
				$('#lieu').val('');
				$('#poste').val('');
			}
	
			$('#'+type).val(tmpTab[1]);
			$(divParent).html($(this).html());
			
			if( $(this).html() != typeMaj)
				$(divParent).animate({ opacity: 1}, 1500 );
			
			if( $(this).parent().find('li').first().html() == '')
				$(this).parent().find('li').first().html(typeMaj).css('display','block');
				
			//lancer recherche
			/*type		=	$(this).attr('id').substr(0,1);
			url			=	document.location + '';
			url			=	url.replace(/__.*__/g , '');
			tmpTab		=	url.split('.',url);*/
			doSearch();
			//alert($(this).attr('id'));
		});
		
		
		/*** CHECKBOX */
		$('.colCrit').each(function(){
			disableSelect(this);
		});	
		$('.auto_chkbx').each(function(){
			disableSelect(this);
		});	
		$('.auto_chkbx').click(function() {
										
			attrImg		=	$(this).css('background-image');
			if( $(this).css('background-image').indexOf('_on') != -1 )
			{
				$(this).css('background-image',attrImg.replace('_on','_off'));
				$(this).find('input[type="checkbox"]').attr('checked',false);
			}
			else
			{
				$(this).css('background-image',attrImg.replace('_off','_on'));
				$(this).find('input[type="checkbox"]').attr('checked',true);
			}
		});
		$('.auto_chkbx input[type="checkbox"]').each(function(){
			if( $(this).attr('checked') )
			{
				attrImg		=	$(this).parent().css('background-image');
				$(this).parent().css('background-image',attrImg.replace('_off','_on'));
			}
		});
		
		$('#rechercheAvancee').click(function(){
			
			if( $('#rechercheAvancee').html().indexOf('Recherche') != -1 )
			{
				openRechercheAvancee('slow');
			}
			else
			{
				$('#criteres').fadeOut(100);
				$('#centre #moteur').animate({
					backgroundPosition: '0 -76px',					 
					height: '154px'
				}, 700);
	
				$('#rechercheAvancee').animate({
					top: '110px'
				}, 700, function() {
					$('#rechercheAvancee').fadeOut(100, function() {
						$('#rechercheAvancee').html('Recherche avancée');
						$('#rechercheAvancee').css('background-image','url('+ fd_PATH +'images/model/picto_flechebas.gif)');
						$('#rechercheAvancee').fadeIn(100);
					});
				});
			}
		});
		
		$('#btRechercher').click(function(){
			doSearch();
		});									  								  
	}
	
	/*HOME*/
	$('#catInfos li').each(function(){
		$(this).css('cursor','pointer').click(function(){
			document.location = fd_PATH + 'recherche/annonces_c' + $(this).attr('id').replace(/[^0-9]/g,'') + '_.htm#midPage';
		});
	});
	
	/* COL DROITE */
	if(document.getElementById('colR'))
	{
		$('.element .champ input[type=text]').click(function(){
			//$(this).val('');
			$(this).css('color','#000').css('font-size','13px');
		});
		$('.element.newsletter .auto_chkbx').click(function(){
			if( $(this).find('input[type="checkbox"]').attr('id') == 'insNL')
			{
				$('#desinsNL').attr('checked',false);
				$('#insNL').attr('checked',true);
				$('#desinsNL').parent().css('background-image',$(this).css('background-image').replace('_on','_off'));
			}
			else
			{
				$('#desinsNL').attr('checked',true);
				$('#insNL').attr('checked',false);
				$('#insNL').parent().css('background-image',$(this).css('background-image').replace('_on','_off'));		
			}
			
		});													  
	}
	
	
	/*Col Droite Espace Candidat */
	
	$('#creaCompte').click(function(){
		document.location = fd_PATH + 'inscription.htm';
	});								
	
	$('#forgot').click(function(){
		document.location = fd_PATH + 'demande-mot-de-passe.htm';
	});								
		
	$('#colrFormSearch .bt_ok').click(function(){
		$('#colrFormSearch').submit();
	});	

	if(document.getElementById('colrAuto'))
	{
		if($('#colrAuto').val() != '')
		{
			tmpTab	=	$('#colrAuto').val().split('|');
			$('#accescandidat_login').val(tmpTab[0]);
			$('#accescandidat_password').val(tmpTab[1]);
			fdForm_ajax('accescandidat');
		}
	}
	
	/*Col Droite Verbatim*/
	$('.element.verbatim').click(function(){
		document.location = fd_PATH + 'formulaire/contact-colr.htm';
	});	
	
	
	
	/*SLIDER*/
	if(document.getElementById('sLeft'))
	{
		$('#sRight').css('background-image',$('#sRight').css('background-image').replace('_off','_on')).css('cursor','pointer');	
		
		$('#sRight').click(function(){
			$('#sCont').html('').toggleClass('loader');			
			fd_ajax('slider','val=right&path=' + fd_PATH);
		});
		
		
	}
	
	/*RECHERCHE*/
	$('.lnRes').hover(
			function() { $(this).css('background-color','#f8f8f8'); }, 
			function() { $(this).css('background-color','#fff'); });
	
	
	/*DESACTIVE LIEN ET LE MET SUR BLOC*/
	$('.getLnk').each(function(){
		$(this).click(function(){
			document.location = $(this).find('a').attr('href');
		}).css('cursor','pointer').find('a').attr('onclick','return false;');
	});
	
	/*AIDE A LA RECHERCHE D'UNE VILLE VIA CP*/
	$('#ch_cp input').keyup(function(){
		if( $(this).val().length == 5 )
			fd_ajax('getVille','val='+ $(this).val());
		else
		{
			$("select#villeId").css("display","none");
			$("select#villeId").val('');
		}
	});
	
	/*Ajout à ma sélection*/
	if(document.getElementById('adSelection'))
	{
		$("#adSelection").click(function(){
			$.scrollTo( '#colR', 450 , {offset:-30 , onAfter: function(){
				$("#colR .icoMenuPt.selection div").fadeIn(800,  
					 function(){
						 $("#colR .icoMenuPt.selection div").delay(1000).fadeOut();
					 }
				)} 
			} );
			fd_ajax('addUserSel','val='+ $('#idAn').val() + '&id=' + $('#adSelection').attr('class').replace('el',''));
		});
	}
	
	/*Active les boutons pour postuler*/
	$('.btPostuler').each(function(){
		$(this).click(function(){
			if( $('#idAn').val() != '' && parseInt($('#idAn').val()) > 0)
			{
				width	=	657;
				height	=	630;
				if($('#infosUser').html() == null)
				{
					width	=	445;
					height	=	133;
				}
				openShadowbox('../cs/postuler-' + $('#idAn').val() + '.htm','Postuler à l\'annonce n°' + $('#idAn').val(), width, height);
			}
		});
	});					   
	$('.btPostulerPt').each(function(){
		$(this).click(function(){
			id	=	this.id.replace('idAn', '');
			if( parseInt(id) > 0)
				openShadowbox('../cs/postuler-' + id + '.htm','Postuler à l\'annonce n°' + id,645,630);
		});
		
	});	
	
	
	$('#inscriptionrecruteur_existe').change(function(){
		if(this.value != '')
		{
			$('#inscriptionrecruteur_existe').val('');
			$('#inscriptionrecruteur_nom').val('');
			openShadowbox( fd_PATH + 'cs/enseigne_recruteur.htm','Un compte existe déjà pour cette société', 500, 172);
		}
	});
	$('#inscriptionrecruteur_nom').focus(function(){
			$('#inscriptionrecruteur_existe').val('');
	});
	
	$('#annonces_poste').change(function(){
		if(this.value != '')
			$('#annonces_poste_autre').val('');
	});
	$('#annonces_poste_autre').focus(function(){
			$('#annonces_poste').val('');
	});
	
	if(document.getElementById('infosUser'))
	{
		if($('#infosUser').html().indexOf('recruteur') != -1)
			$('#infosUser span').click(function(){document.location = fd_PATH + 'espace-recruteur/accueil.htm'});
		if($('#infosUser').html().indexOf('candidat') != -1)
			$('#infosUser span').click(function(){document.location = fd_PATH + 'espace-candidat/accueil.htm'});
	}
	
	/*PrintCandi*/
	$('#printCandi').click(function(){
			$(this).css('display','none');
			window.print();
	});
	

	/*Isncription NL*/
	$('#colRnewsletter').click(function(){
		if( $('#colRnewsletter').val().indexOf(' votre') != -1)
			$('#colRnewsletter').val('');   
	});						   
	$('#colRNLSub').click(function(){
		if( $('#colRnewsletter').val().indexOf(' votre') != -1)
			$('#colRnewsletter').val('');   
		choix	=	$('#insNL').attr('checked') ? 'ins' : 'desins';
		fd_ajax('registerNL','val='+ $('#colRnewsletter').val() + '&choix=' + choix);
	});
	
	/*Connexion compte Candi*/
	$('#loginColR').click(function(){
		if($(this).val().indexOf('Identifiant') != -1)
			$(this).val('');
	});	
	$('#passwordColR').click(function(){
		if($(this).val().indexOf('Passe') != -1)
			$(this).val('');
	});			
	$('#colrFormSearch .bt_ok').click(function(){
		if($(this).val().indexOf('Identifiant') != -1)
			$(this).val('');
		if($(this).val().indexOf('Passe') != -1)
			$(this).val('');
	});		
	
	/*Liste Ma Sélection*/
	/*$('.champoff').each(function(){
		if(this.id.indexOf('deja') != -1)
		{
			id	=	this.id.replace('deja','');
			$('#bt' + id).attr('class','btPostulerPt');
			
		}
		
	});	*/
	
	
	
}

// Trouve l'element avec un id le plus proche (en remontant le DOM) - limite 10 éléments
function getClosestId(zone)
{
	idFin	=	'';
	if( $(zone).attr('id') != '' )
		idFin	=	$(zone).attr('id');
	else
	{
		countLimit	=	0;
		while(idFin == '' && countLimit < 10)
		{
			idFin	=	$(zone).parent().attr('id');
			countLimit++;
		}
	}
	return idFin;
}

/*Active / désactive sélection sur un élément*/
function disableSelect(el)
{			
	if(el.attachEvent)
		el.attachEvent("onselectstart",disabler);
 	else
		el.addEventListener("mousedown",disabler,"false");
}
 
function enableSelect(el)
{
	if(el.attachEvent)
		el.detachEvent("onselectstart",disabler);
     else
		el.removeEventListener("mousedown",disabler,"false");
}
 
function disabler(e)
{
	if(e.preventDefault)
		e.preventDefault();
    return false;
}

function doSearch()
{
	/****************    liste des criteres     ***********/
	i		=	0;
	crit	=	new Array();

	if( $('#poste').val() != '')
	{
		crit[i]	=	'p' + $('#poste').val();
		i++;
	}
	if( $('#enseigne').val() != '')
	{
		crit[i]	=	'e' + $('#enseigne').val();
		i++;
	}	
	else if( $('#lieu').val() != '')
	{
		crit[i]	=	'l' + $('#lieu').val();
		i++;
	}
	
	//crit avance
	$('#criteres input[type="checkbox"]').each(function(){
		if(this.checked)
		{
			tmpTab	=	this.name.split('_');
			crit[i]	=	tmpTab[0] + $(this).val();
			i++;
		}
	});
	
	
	/****************    construction de l'url     ***********/
	url				=	'';
	for(i = 0 ; i < crit.length ; i++)
		url			+=	'_' + crit[i] + '_';
		
	document.location	=	fd_PATH + 'recherche/annonces' + url + '.htm#midPage';	
}

function openRechercheAvancee(vitesse)
{
	if(vitesse == 'slow')
	{
		$('#centre #moteur').animate({
						backgroundPosition: '0 0',					 
						height: '230px'
					}, 700, function() {
						$('#rechercheAvancee').fadeOut(100, function() {
							$('#rechercheAvancee').html('Fermer la zone de recherche');
							$('#rechercheAvancee').css('background-image','url('+ fd_PATH +'images/model/picto_flechehaut.gif)');
							$('#rechercheAvancee').fadeIn(100);
							$('#criteres').fadeIn(100);
							
						});
					});
			
					$('#rechercheAvancee').animate({
						top: '186px'
					}, 700);
	}
	else
	{
		$('#centre #moteur').css({
						backgroundPosition: '0 0',					 
						height: '230px'
					});
		
		$('#rechercheAvancee').html('Fermer la zone de recherche');
		$('#rechercheAvancee').css('background-image','url('+ fd_PATH +'images/model/picto_flechehaut.gif)');
		$('#criteres').fadeIn(0);

		$('#rechercheAvancee').css('top','186px');
		
	}
}

/*
function showAddSel(){
	$("#colR .icoMenuPt.selection div").fadeIn();
}*/


