var NGmesSearchEmpty="Please, fill at least one field in.";

function showPhoto(mydiv)
{
	thediv = $(mydiv) ;
	thediv.down('span.photoTitle').show();
	thediv.down('a').down('span.photoCadre').addClassName('photoOver');
} 
function hidePhoto(mydiv)
{
	thediv = $(mydiv) ;
	thediv.down('span.photoTitle').hide();
	thediv.down('a').down('span.photoCadre').removeClassName('photoOver');
} 

function showMenu(mydiv)
{
	$(mydiv).src = getlstMenus($(mydiv).id,"on") ;
} 
function hideMenu(mydiv)
{
	$(mydiv).src = getlstMenus($(mydiv).id,"off");
} 
function getlstMenus( id, etat )
{
	if ( lstMenus != null )
	{
		var pos = ( etat == "off" ? 1 : 2 ) ;
		for ( var i = 0 ; i < lstMenus.length ; i++ )
		{
			if ( lstMenus[i][0] == id ) return lstMenus[i][pos];
		}
	}
	return null ;
}

var timeTetiere = 8000;
var current_imageTetiere = 0;
var next_imageTetiere = 1;
var imageTetiere = new Array();
function initTetiere() {
	imageTetiere = $$("img.imageTetiere");
	if( $('fondTetiere').visible() && imageTetiere ) {
	for(i=1; i < imageTetiere.length; i++) {
			imageTetiere[i].style.display = "none";
		}
		if(imageTetiere.length > 1) galerie(800);
	}	
}
function galerie(time) {
	self.setTimeout("nextimageTetiere()",time);	
}
function nextimageTetiere() {
	new Effect.Fade(imageTetiere[current_imageTetiere],{ duration: 6.0, from:1.0, to:0 }); 
	new Effect.Appear(imageTetiere[next_imageTetiere],{ duration: 6.0, from:0, to:1.0 });
	
	if(next_imageTetiere == (imageTetiere.length-1)) {
		current_imageTetiere = next_imageTetiere;
		next_imageTetiere = 0;
	} else {
		current_imageTetiere = next_imageTetiere;
		next_imageTetiere++;
	}
	galerie(timeTetiere);
}

function aleaCabinet()
{
	var nbcabinet_accueil_photos = 6 ;
	var alea = Math.floor ( Math.random ( ) * nbcabinet_accueil_photos );
	var photo = '../../images/cabinet/cabinet_accueil'+ alea + '.jpg' ;
	$('colhome23').style.background='url('+photo+') no-repeat left bottom';
}

function aleaEquipe(imageLevel)
{
	lstfiches = lstEquipes ;
	if ( !lstfiches ) return ;
	var nbfiches = lstfiches.length ;
	if ( !nbfiches ) return ;
	var alea = Math.floor ( Math.random ( ) * nbfiches );
	if ( alea >= nbfiches || alea < 0 ) return ;
	var fiche = lstfiches[alea] ;
	var nbitems = fiche.length ;
	var image = fiche[0] ;
	var titre = fiche[1] ;
	var url = fiche[2] ;
	var catcher = fiche[3] ;
	
	var mydiv = $('equipe');
	if ( !mydiv ) return ;

	var h1 = mydiv.getElementsByTagName('h1');
	for (var i = 0; i < h1.length; i++)
		h1[i].innerHTML = titre;

	var p = mydiv.getElementsByTagName('p');
	for (var i = 0; i < p.length; i++)
		p[i].innerHTML = catcher+"&raquo;";

	/*var div = mydiv.getElementsByTagName('div');
	for (var i = 0; i < div.length; i++)
	{
		var thediv = $(div[i]) ;
		if ( thediv.hasClassName( "catcher" ) ) 
		{
			thediv.style.background = 'url('+image+') no-repeat';
		}
	}*/
	var img = mydiv.getElementsByTagName('img');
	for (var i = 0; i < img.length; i++)
	{
		var thediv = $(img[i]) ;
		if ( thediv.hasClassName( "photo" ) ) 
			img[i].src = image;
	}
	
	var a = mydiv.getElementsByTagName('a');
	for (var i = 0; i < a.length; i++)
	{
		a[i].href=url ;
	}
}
function aleaSolution(imageLevel)
{
	lstfiches = lstSolutions ;
	if ( !lstfiches ) return ;
	var nbfiches = lstfiches.length ;
	if ( !nbfiches ) return ;
	var alea = Math.floor ( Math.random ( ) * nbfiches );
	if ( alea >= nbfiches || alea < 0 ) return ;
	var fiche = lstfiches[alea] ;
	var nbitems = fiche.length ;
	var titre = fiche[0] ;
	var url = fiche[1] ;
	var secteur = fiche[2] ;
	var type = fiche[3] ;
	var mydiv = $('cas');
	if ( !mydiv ) return ;
	var h1 = mydiv.getElementsByTagName('h1');
	for (var i = 0; i < h1.length; i++)
		h1[i].innerHTML = titre;

	anim_motimage(secteur,type);		
	/*var a = mydiv.getElementsByTagName('a');
	for (var i = 0; i < a.length; i++)
	{
		a[i].href=url ;
	}*/
}

function anim_motimage(secteur,type)
{
	if ( !$('motimage') || !$('motimage').visible() ) return ;
	var divSecteur = $('motimage_secteur') ;
	divSecteur.setStyle("font-size:" + calculSize(secteur) + "%;");
	divSecteur.innerHTML=secteur;

	var divType = $('motimage_type') ;
	divType.setStyle("font-size:" + calculSize(type) + "%;");
	divType.innerHTML=type;
	
	divSecteur.appear({duration:0.5});
	new Effect.Move(divSecteur, { y: -55, duration:1, delay: 1});

	divType.appear({ duration: 3, delay: 2 });		
}	
function calculSize(s){
	var lg = s.length ;
	if ( lg < 8 ) return 420;
	if ( lg < 15 ) return 360;
	if ( lg < 20 ) return 300;
	if ( lg >= 20 ) return 240;	
}

function printWindow(){
	var scrollinner= $$('.scroll-innerBox').first();
	if ( scrollinner ){
		Element.setStyle(scrollinner,{width: "auto"});
	}
	var scroll= $$('.scroll-track').first();
	if ( scroll && scroll.getStyle('display') != "none" )
	{
		scroll.hide();		
		Element.setStyle(scrollinner,{height: "auto"});
		Element.setStyle($('page'),{height: "auto"});
		Element.setStyle($$('.colmenu').first(),{height: "auto"});
		Element.setStyle($$('.cxlarge').first(),{height: "auto"});
		Element.setStyle($$('.makeScroll').first(),{height: "auto"});
		$$('.scroll-track-top').first().hide();
		$$('.scroll-track-bot').first().hide();
    }
    window.print();
}

function sendPage(libelle)
{
  var mail_str = "mailto:?subject=" + document.title;
  mail_str += "&body=" + libelle;
  mail_str += '%0A%0A' +self.location; 
  location.href = mail_str;
}

function openExtWindow( dest, h, w, n )
{
	var hauteur,largeur ;
	if ( !h )
		hauteur = 500 ;
	else
		hauteur = h ;
	if ( !w )
		largeur = 640 ;
	else
		largeur = w ;
	if ( !n )
		nom = 'fenetre' ;
	else
		nom = n ;
	var _w = window.open( dest, nom, 'toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width='+largeur+',height='+hauteur ) ;
	_w.focus() ;	
}

function quitter()
{
  if ( ( top.opener ) && ( history.length <= 1 ) )
  {
      top.close();
  }
  else
  {
      history.back();
  }
}

function getKey( keyStroke ) 
{
    var navigatorName = navigator.appName ;
	var eventChooser = ( navigatorName == "Netscape" ) ? keyStroke.which : event.keyCode ;
	var currLetter = String.fromCharCode( eventChooser ).toLowerCase() ;
	if ( currIndex != -1 )
	{
		if ( currLetter == wordList[currIndex].charAt( currLetterList[currIndex] ) ) 
		{
			currLetterList[currIndex]++ ;
			if ( currLetterList[currIndex] == wordList[currIndex].length && urlList[currIndex] != "" )
				window.location = urlList[currIndex] ;
			return ;
		}
		else
		{
			currLetterList[currIndex] = 0 ;
			currIndex = -1 ;
		}
	}
	var nbw = currLetterList.length ;
	for ( var i = 0 ; i < nbw ; i++ )
	{
		if ( currLetter == wordList[i].charAt( currLetterList[i] ) ) 
		{
			currIndex = i ;
			currLetterList[i]++ ;
			if ( currLetterList[i] == wordList[i].length && urlList[i] != "" )
				openExtWindow( urlList[i], 400, 680,"backoffice");
			return ;
		}
	}
}


function getCookieVal (offset) 
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) 
{
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime (date.getTime() - skew);
}

function GetCookie (name) 
{
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function SetCookie (name,value,expires,path,domain,secure) 
{
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) 
{
  if (GetCookie(name)) 
  {
   	document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function get_value (CookieCode, ElementName)
{
	Paire = new Array;
	var Cookie = "";
	if (GetCookie(CookieCode)) Cookie = GetCookie(CookieCode); 
	else return ("null");
	if (Cookie.indexOf(ElementName) >= 0)
	{
		ScoreArray = Cookie.split("&");
		for (var i = 0; i < ScoreArray.length; i++)
		{
			Paire[i] = ScoreArray[i].split("=");
			if (unescape(Paire[i][0]) == ElementName)
				return (Paire[i][1]) ;
		}
	}
	else
		return ("null")
}

function update_value (CookieCode, ElementName, ElementValue, path)
{
	Paire = new Array;
	var Cookie = "";
	if (GetCookie(CookieCode)) 
			Cookie = GetCookie(CookieCode);
	else
			SetCookie (CookieCode,Cookie, null, path);
	if (Cookie.indexOf(ElementName) >= 0)
	{
		ScoreArray = Cookie.split("&");
		Cookie = "";
		for (var i = 0; i < ScoreArray.length; i++)
		{
			Paire[i] = ScoreArray[i].split("=");
			if ((Paire[i][0]) == ElementName)
				ScoreArray[i] = (ElementName) + "=" + (ElementValue) ;
			if ( i > 0) Cookie += "&";
			Cookie += ScoreArray[i];
		}
	}
	else
	{
		if (Cookie == "")
				Cookie = (ElementName) + "=" + (ElementValue);
		else
				Cookie = Cookie + "&" + (ElementName) + "=" + (ElementValue);
	}
	SetCookie (CookieCode, Cookie, null, path);
}

function getBuildSearchQueryValue (field)
{
	if (field)
	{
	  if (field.type.indexOf('select') < 0 )
   		{
  			return ((field.value == "") ? null : eval(field.value));
   		}
   		else 
   		{
   			return ((field.options[field.options.selectedIndex].value == "") ? null : eval(field.options[field.options.selectedIndex].value));
    	}
   	}
   	else 
   	return (false);
}

function BuildSearchQuery (f)
{
	var prompt = "" ;
	var flag = 0;
	var cadre='"';
	if ( f.fulltext && ( f.fulltext.value.indexOf('"') > -1) ) cadre="";
	if ( f.fulltext && ( f.fulltext.value.length > 0 ) )
	{
		if (f.fulltextscope && ( f.fulltextscope.value.length > 0 ))
		{
			tmpFtsArray = f.fulltextscope.value.split(",") ;
			f.query.value += "( " ;
			for (var i=0; i<tmpFtsArray.length; i++)
			{
				if ( i > 0 ) f.query.value += " OR " ;
				f.query.value  += ( "( " + tmpFtsArray[i]  + ":" + cadre+f.fulltext.value+cadre + " )" ) ;
			}
			f.query.value += " )" ;
		}
		else
		{
				 f.query.value = '(('+f.fulltext.value+') OR (title:'+cadre+f.fulltext.value+cadre+') OR (description:'+cadre+f.fulltext.value+cadre+'))';

		}
	}
	else f.query.value = "";
	if ( f.fields && f.fields.value )
	{
		tmpArray = f.fields.value.split(",");
		defaultArray = "" ;
		if ( f.fieldsdefault && f.fieldsdefault.value ) 
			defaultArray = f.fieldsdefault.value.split(",");
		for (var i=0; i<tmpArray.length; i++)
		{
			
          	var name = tmpArray[i];
          	var isWildcard = true ;
          	if ( name.indexOf("*") == 0 )
          		name = name.substr( 1 ) ;
          	else
          		isWildcard = false ;
         	var n = eval( "f." + name ) ;
			var ndefault = defaultArray[i] ;
			var value = "" ;
			if (n)
          	{
				if (n.type.indexOf("select") > -1 )
           		{
            		if (n.options[n.options.selectedIndex].value.length > 0 )
            			{
            			value = n.options[n.options.selectedIndex].value ;
            			prompt =  n.options[n.options.selectedIndex].text ;
            			}
            	}
            	else
            	{
            		if ( n.value.length > 0 )
            			{           			
            				value = n.value ;
            				if ( n.type == "text" ) prompt =  n.value ;
            				else prompt = "" ;
            			}
            	}
            	if ( value != "" && value != ndefault )
            	{
            		if (f.query.value.length > 0 ) f.query.value += " AND ";
           	    	if ( isWildcard )f.query.value += (name + ':' + value + '* OR ') + (name + ':"' + value + '"');  
           	    	else f.query.value += (name + ':"' + value + '"');
           	    	if ( f.prompt && ( prompt.length > 0)  )
           	    	{ 
	            		if (f.prompt.value.length > 0 ) f.prompt.value += " + " ;
           	    			f.prompt.value += prompt ;
           	    	}
				}
			}
		}
   }
   if (f.from && f.fromyear && f.frommonth && f.fromday)
   {
   		flag=1;	
    	if ((m = getBuildSearchQueryValue(f.frommonth)) && (y = getBuildSearchQueryValue(f.fromyear)) && (d = getBuildSearchQueryValue(f.fromday)))
		f.from.value = y + ((m < 10) ? "-0" : "-") + m.toString() + ((d < 10) ? "-0" : "-") + d.toString();
   }
   if (f.to && f.toyear && f.tomonth && f.today)
   {	
   		flag=1;	
    	if ((m = getBuildSearchQueryValue(f.tomonth)) && (y = getBuildSearchQueryValue(f.toyear)) && (d = getBuildSearchQueryValue(f.today)))
		f.to.value = y + ((m < 10) ? "-0" : "-") + m.toString() + ((d < 10) ? "-0" : "-") + d.toString();
   }
   if ((f.more) && (f.more.value.length >0))
   {
	  	if (f.query.value.length > 0 ) f.query.value += " AND ";
    	f.query.value += f.more.value;
   }
   if ( f.prompt && f.fulltext && ( f.fulltext.value.length > 0)  )
   { 
	    if (f.fulltext.value.length > 0 ) f.prompt.value += " + " ;
        f.prompt.value += f.fulltext.value ;
   }
   if ((f.query.value.length > 0) || (flag=1 >0))
   {
         f.submit();
   }
   else
   {
   		  alert(NGmesSearchEmpty);
   }
}

// onload add & init
var onload_actions = new Array();

function onload_handler()
{
	for(i=0;i<onload_actions.length;i++)
		eval(onload_actions[i]);
}

function onload_add_action(f)
{
	onload_actions[onload_actions.length] = f;
}

//on resize add
var onresize_actions = new Array();

function onresize_handler()
{
	for(i=0;i<onresize_actions.length;i++)
		eval(onresize_actions[i]);
}

function onresize_add_action(f)
{
	onresize_actions[onresize_actions.length] = f;
}

var lastFlip = null ;
function flipDiv(whichEl)
{
	theLayer = $( whichEl ).style ;
	if ( theLayer )
	{
		if (theLayer.display == "none" )
		{
			if ( lastFlip )
			{
				lastFlip.display = "none" ;
			}
			theLayer.display = "" ;
			lastFlip = theLayer ;
		}
		else
		{
			theLayer.display = "none" ;
		}
		Scroller.updateAll();
	}
}


