// JavaScript Document

var preloadFlag = false;

var isPausedActu = false;
var curActu = 1;
var zindexActu = 1;


var soundValue = Get_Cookie("sound");

if(soundValue == null) {
soundValue = "on";	
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

	function openWin(theURL,winName,features)
	{
		window.open(theURL,winName,features);
	}

	function MM_jumpMenu(targ,selObj,restore)
	{ //v3.0
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
	}

/* Extension written by David G. Miles (http://www.z3roadster.net/dreamweaver/) 
based in part on code written by Thomas Brattli (http://www.bratta.com)*/
// Courtesy of SimplytheBest.net (http://simplythebest.net/info/dhtml_scripts.html)

function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion 
    this.dom=document.getElementById?1:0 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
    return this 
} 
bw=new verifyCompatibleBrowser() 
  
var speed=50 
var loop, timer 
 
function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.' 
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 
function MoveArea(x,y){ 
    this.x=x;this.y=y 
    this.css.left=this.x 
    this.css.top=this.y 
} 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 
function PerformScroll(speed){ 
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 
function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 
var initialised; 
function InitialiseScrollableArea(){ 
    objContainer=new ConstructObject('divContainer') 
    objScroller=new ConstructObject('divContent','divContainer') 
    objScroller.MoveArea(0,0) 
    objContainer.css.visibility='visible' 
    initialised=true; 
} 

function displayStatusMsg(msgStr) { 
  status=msgStr;
  document.returnValue = true;
}

function preloadImages() { 
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore() { 
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { 
  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=findObj(n,d.layers[i].document); return x;
}

function swapImage() { 
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}

reloadPage(true);

function preloadImages() {
	if (document.images) {
		
		preloadFlag = true;
	}
}

function showhide(nr)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}

function show(nr)
{
	if (document.layers)
	{
		document.layers[nr].display = 'block';
	}
	else if (document.all)
	{
		
		document.all[nr].style.display = 'block';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.display = 'block';
	}
}

function hide(nr)
{
	if (document.layers)
	{
		document.layers[nr].display = 'none';
	}
	else if (document.all)
	{
		document.all[nr].style.display = 'none';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.display = 'none';
	}
}


function winBRopen(theURL, Name, popW, popH, scroll) { // V 1.0
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable=no'
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }

}

function updateListInfos(theObj,theText,isNew,leLien) {
	//alert(xLeft(theObj));
	xHide('infos');
	xWidth('infos', xWidth(theObj));
	xHeight('infos', xHeight(theObj));
	
	var bloc = xGetElementById('infos');
	var lien = xGetElementById('lien');
	
	if(leLien != '') {
	lien.href = leLien;
	} else {
	lien.href = "#";
	}
	//alert(leLien);
	if(isNew) {
	xWidth('new', xWidth(theObj));
	xMoveTo('new',xLeft(theObj), (xTop(theObj)+xHeight(theObj))-10, 200);
	xShow('new');
	//bloc.style.background='transparent url(/img/nouveau.gif) left bottom no-repeat';
	//bloc.style.cursor = "hand";
	} else {
	xHide('new');
	}
	
	var txt = xGetElementById('infosLabel');
	txt.innerHTML = theText.toUpperCase();
	xShow('infos');
	xMoveTo('infos',xLeft(theObj), xTop(theObj), 200);
}

function gotoEN(theUrl) {
	document.location.href = "/EN"+theUrl; // supression de "chazelles2005" temporaire
} 

function gotoFR(theUrl) {
	document.location.href = theUrl.replace("/EN/","/"); // supression de "chazelles2005" temporaire
}

function updateDiv(leDiv,leTxt) {
	var txt = xGetElementById(leDiv);
	txt.innerHTML = leTxt;
}

function menuBar(num) {
	switch(num) {
	case 1:
	hide('menu2');
	show('menu1');
	break;
	
	case 2:
	hide('menu1');
	show('menu2');
	break;
	
	default:
	hide('menu1');
	hide('menu2');
	}
}

function servicesBar(num) {
	switch(num) {
	case 1:
	hide('service2');
	hide('service3');
	hide('service4');
	hide('service5');
	showhide('service1');
	break;
	
	case 2:
	hide('service1');
	hide('service3');
	hide('service4');
	hide('service5');
	showhide('service2');
	break;
	
	case 3:
	hide('service1');
	hide('service2');
	hide('service4');
	hide('service5');
	showhide('service3');
	break;
	
	case 4:
	hide('service1');
	hide('service3');
	hide('service2');
	hide('service5');
	showhide('service4');
	break;
	
	case 5:
	hide('service1');
	hide('service3');
	hide('service4');
	hide('service2');
	showhide('service5');
	break;
	
	default:
	}
}

function showImg(num, dossier) {
	document.getElementById("mainImage").setAttribute("src", "img/"+dossier+"/"+num);
}

function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
return (false)
}


function loadSound(play) {
	
	switch(play) {
		
	case "on":
	if(flash.ver[8]) {
			
			  var so2 = new SWFObject("/swf/son.swf", "sonMovie", "1", "1", "8", "#FFFFFF");
			   so2.addParam("quality", "high");
			   so2.addParam("wmode", "transparent");
			   so2.addParam("salign", "t");
			   
		}
	so2.write("sound");
	document.getElementById("divSound").className = "navItem";
	document.getElementById("picSound").setAttribute("src", "/img/FR/nav6.gif");
	break;
	
	case "off":
	if(flash.ver[8]) {
			
			  var so2 = new SWFObject("/swf/sonoff.swf", "sonMovie", "1", "1", "8", "#FFFFFF");
			   so2.addParam("quality", "high");
			   so2.addParam("wmode", "transparent");
			   so2.addParam("salign", "t");
			   
		}
	so2.write("sound");
	document.getElementById("divSound").className = "navItemGrey";
	document.getElementById("picSound").setAttribute("src", "/img/FR/nav6off.gif");
	break;
	
	default:
	Delete_Cookie("sound","/","");
	}
	
	
}

function switchSound() {
	
	switch(soundValue) {
		
	case "on":
	soundValue = "off";
	loadSound("off");
	//EcrireCookie("sound", "off");
	Set_Cookie( "sound", "off", "", "/", "", "" )
	break;
	
	case "off":
	soundValue = "on";
	loadSound("on");
	//EcrireCookie("sound", "on");
	Set_Cookie( "sound", "on", "", "/", "", "" )
	break;
	}
	
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}				


// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function clientForm() {
alert("Espace client temporairement indisponible.\n\n");	
}

function rotateHomeActus() {
	
	if(curActu > maxActu) { curActu = 1; }
	
	clearTimeout(timerActu);
	
	if(!isPausedActu) {
	xZIndex('actu'+curActu,zindexActu);
	xMoveTo('actu'+curActu,0,0);
	xShow('actu'+curActu);
    xSlideTo('actu'+curActu,0, 0, 1000);
	curActu++;
	zindexActu++;
	timerActu = setTimeout(rotateHomeActus,5000);
	} 
}


function launchActusRotation() {

	timerActu = setTimeout(rotateHomeActus,50);
}


function doPause() { // pause la rotation
	//isPausedPromo = true;
	//curX = xPageX('bien'+curBien);
	//if(curX > 260) { xMoveTo('bien'+curBien,(xClientWidth()/2)-120,230); };
	
}

function doResetActuRotation() {
	clearTimeout(timerActu);
	isPausedActu = false;
	timerActu = setTimeout(rotateHomeActus,1000);
}
