// JavaScript Document





	// Path for IE 6 Web client
	//
	if( Prototype && Prototype.Browser && Prototype.Browser.IE ){
		document.write('<!--[if IE 6]>');
		document.write('<link href="/css/path_ie6.css" type="text/css" rel="stylesheet" />');
		document.write('<![endif]-->');
	}





	// Document initialisation.
	//
	// Do some stuffs at on load
	Event.observe(window, 'load', function() {
		
		
		
		// Hide tha ajax indicator used for anti-decnx process.
		if($('AjaxIndicator')) $('AjaxIndicator').hide();
		
		
		
		// Event declaration for the search field.
		if($('search')){
		Event.observe($('search'), 'focus', focusSearchField);
		Event.observe($('search'), 'blur', blurSearchField);
		
		if( $('search').value!='Rechercher...' && $('search').value!='' ){ focusSearchField(); }
		}
		
		
		
		// Realtime element.
		if($('dateBlocInfo')) writeTimeIn('dateBlocInfo');
		
		
		
		// Apply popFrame / PlopBox  effect on each links have .ctkPopFrame or .plopBox className...
		$$('.PlopBox').each(function(item,index){
		
			var Params={};
			if( item.readAttribute('target') !="" ){
				Params = item.readAttribute('target').evalJSON(); 
			}
			Params.url = item.readAttribute('href');
			Params.title = item.readAttribute('title') || '';

			//	alert( Params.url +"\n"+ Params.title +"\n"+ Params.width +"\n"+ Params.height );
			Event.observe(item, 'click', function(event) {
				Event.stop(event);
				ctkPopFrame.open( $('PopFrame'), Params );
				return false;
			});
		/*	
			item.observe( 'click', function(event) {
				ctkPopFrame.open( $('PopFrame'), Params );
				return false;
			});
		/**/
		
		});
		
		
		
		//  Apply a fade of effect on each results' box.
		$$('.boxResults .btncloseresults').each(function(item,index){
			
			item.setStyle({cursor:'pointer'});
			item.setAttribute('name','on');
			Event.observe(item, 'click', function(event) {
				var box = item.up(0);
				new Effect.Opacity(box, {duration:0.3,from:1.0,to:0.2, afterFinish:function(){ item.hide(); }});
				
			});

		});
		
		
		
		//  Apply a roll over effect for each link image 'Lire la suite'
		var _imagesCollector = Array();
		_imagesCollector['mouseout'] = new Image();
		_imagesCollector['mouseover'] = new Image();
		_imagesCollector['mouseout'].src = "/img/suite_article.gif";
		_imagesCollector['mouseover'].src = "/img/suite_article_over.gif";
		$$('.linkToDocument img').each(function(item,index){
			
			Event.observe(item, 'mouseout', function(event) {
				item.setAttribute('src', _imagesCollector['mouseout'].src);
			});
			
			Event.observe(item, 'mouseover', function(event) {
				item.setAttribute('src', _imagesCollector['mouseover'].src);
			});

		});
		
		
		
		// 
		$$('div.resultsentry .resultsentrytools').each(function(item,index){
			
			item.setStyle({cursor:'pointer'});
			item.setAttribute('name','on');
			Event.observe(item, 'click', function(event) {
				
				if(item.readAttribute('name')=='on'){
					item.setAttribute('name','off');
					new Effect.Opacity(item.up(0), {duration:0.4,from:1.0,to:0.2, afterFinish:function(){ item.setAttribute('src','/img/bullet_cross.gif')}});
				}else{
					item.setAttribute('name','on');
					new Effect.Opacity(item.up(0), {duration:0.3,from:0.5,to:1.0, afterFinish:function(){ item.setAttribute('src','/img/bullet_mark.gif')}});
				}
				
			});

		});
		
		
		
		// 
		$$('.highlighted').each(function(item,index){
			
			Event.observe(item, 'mouseover', function(event) {
				
				Event.stop(event);
				new Effect.Opacity(item, {duration:0.1,from:1.0,to:0.6});
				
			});
			
			Event.observe(item, 'mouseout', function(event) {
				
				Event.stop(event);
				new Effect.Opacity(item, {duration:0.1,from:0.5,to:1.0});
				
			});

		});
		
		
		
		// 
		if($('FCKeditor_PreComment') && $('FCKeditor_Comment')){
			// Automatically calculates the editor base path based on the _samples directory.
			// This is usefull only for these samples. A real application should use something like this:
			// oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
			var sBasePath = '/js/fckeditor/';
	
			var oFCKeditor1 = new FCKeditor( 'FCKeditor_PreComment' , '500', '70' , 'SmallEditor' ) ;
			oFCKeditor1.BasePath	= sBasePath ;
			oFCKeditor1.ReplaceTextarea() ;
			
			var oFCKeditor2 = new FCKeditor( 'FCKeditor_Comment' , '500', '250' , 'SimpleEditor' ) ;
			oFCKeditor2.BasePath	= sBasePath ;
			oFCKeditor2.ReplaceTextarea() ;

		}
		
		
	});





	// Events and behaviors for the search field.
	// - events declared at onLoad - only methods for bahavior here.
	//
	// on:focus
	var focusSearchField = function(){
		$('search').setStyle({
			backgroundColor:'#f4f4f2',
			color:'#70833A',
			border:'0 none'
		});
		if( $('search').value=='Rechercher...' ){ $('search').value=''; }
	}
	// on:blur
	var blurSearchField = function(){
		$('search').setStyle({
			backgroundColor:'#edeee9',
			color:'#dadcd0',
			border:'0 none'
		});
		if( $('search').value=='' ){ $('search').value='Rechercher...'; }
	}




	// Sets up PopFrame parameters to simulate a loader effect.
	//
	// Used in each pages where there embed ctkPopFrame script library.
	var reloadpage = function(){
		window.location.reload();
	}





	// Sets up PopFrame parameters to simulate a loader effect.
	//
	// Used in each pages where there embed ctkPopFrame script library.
	if( typeof ctkPopFrame!='undefined' ){
	
		// Configure options
		ctkPopFrame.configure({
			headbarHeight: 18,
			headbarBGColor: '#939C7B',
			headbarBGUrl: '/img/1pxtransp.gif',
			headbarCloseBtnUrl: '/img/popframe_btnclose.gif',
			popFrmBorderColor: '#939C7B',
			popFrmBorderSize: 5,
			popFrmBGColor: '#FFFFFF',
			titleFontFamily: 'Verdana',
			titleColor: '#ECEEDE',
			titleFontSize: '10px',
			titleFontWeight: 'normal',
			titleFontStyle: 'normal',
			allowNativeClose: true,
			persistentClosable:true,
			useHead: true
		});
				
		ctkPopFrame.setoverlay('PopFrameOverlay','#202020'); // Define the bgcolor of the overlay
			
		// Use this as:
		// ctkPopFrame.open( 'PopFrame',Params );
		// - See more details on http://www.tocra.org
	}





	// Ajax Connector anti disconnection and activity logger (session will be never deconnected).
	// 
	// 
	var ajaxPersistentCnxId = window.setTimeout( 'checkActivity()', 60000*5 );
	
	function checkActivity(){
		
		$('AjaxIndicator').show();
		
		var url = '/checkActivity.php';
		new Ajax.Request(url, {
			onSuccess: function(transport) {
				if (transport.responseText == 'connected' ){
					$('AjaxIndicator').setStyle({opacity: 0}); 
					$('AjaxIndicator').replace('<img src="/img/ani_snake.gif" id="AjaxIndicator" />');
					$('AjaxIndicator').hide();
					var ajaxPersistentCnxId = window.setTimeout( 'checkActivity()', 60000*5 );
				}else{
					$('AjaxIndicator').setStyle({opacity: 0.7}); 
					$('AjaxIndicator').replace('<a id="AjaxIndicator" href="/lost_cnx.php" style="background:url(/img/ani_snake.gif) center left no-repeat; padding-left:20px;">Session perdue !</a>');
					var ajaxPersistentCnxId = window.setTimeout( 'checkActivity()', 20000 );
				}
				// Looping
			},
			onFailure: function(transport) {
				$('AjaxIndicator').setStyle({opacity: 0.5}); 
				$('AjaxIndicator').replace('<a id="AjaxIndicator" href="/lost_cnx.php" style="background:url(/img/ani_snake.gif) center left no-repeat; padding-left:20px;">Perte de connexion internet !</a>');
	
				// Looping
				var ajaxPersistentCnxId = window.setTimeout( 'checkActivity()', 60000 );
			}
		});
	
	}





	// Macromedia form validation (old method !)
	//
	// 
	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	// 
	function MM_validateForm() { //v4.0
	  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
		if (val) { nm=val.name; if ((val=val.value)!="") {
		  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
			if (p<1 || p==(val.length-1)) errors+=' - '+nm+' doit être une adresse mail valide pour vous contacter!\n';
		  } else if (test!='R') { num = parseFloat(val);
			if (isNaN(val)) errors+=' - '+nm+' est un champ devant contenir une valeur numérique...\n';
			if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
			  min=test.substring(8,p); max=test.substring(p+1);
			  if (num<min || max<num) errors+=' - '+nm+' doit être un nombre compris entre '+min+' et '+max+'.\n';
		} } } else if (test.charAt(0) == 'R') errors += ' - '+nm+' est un champ requis.\n'; }
	  } if (errors) alert('Les erreurs suivantes sont apparues:\n'+errors+'\n(La demande n\'a pas été traitée.)');
	  document.MM_returnValue = (errors == '');
	}
