function remplace_mail() {
  for(i=0; i<$$("td.buttonheading a").length;i++) {
    $$("td.buttonheading a")[i].innerHTML="<img src='images/mail_article.png'/>";
  }
}
function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = "";
}
function change_lum(tag) {
  document.getElementById('lum').src = 'http://front-invisu-lumiere.invisu.fr/front_invisu_3/tag/'+tag;
}

function change_lum_pl(tag) {
  document.getElementById('lum').src = 'http://front-invisu-lumiere.invisu.fr/front_invisu_2/'+tag;
}

function deroule(r,id){ 
  if(!Element.visible(id)){
    for(i=0;i<=r.indexOf(r.last()); i++) { 
      var temp = r[i];
      if(Element.visible(temp)) {
	Effect.Fade(temp);
      }
    }
    Effect.Appear(id); 
  }
  else { // sinon on le déroule
    Effect.Fade(id);
  }
}

function text2img(t){
  for(i=0;i<=t.indexOf(t.last()); i++) {
    // trouver le style //
    var trouve=false;var style='none';var transform='';var temp=t[i].ancestors();
    var j=0;
    if(t[i].getStyle('text-transform')!='none'){
      transform='&style='+t[i].getStyle('text-transform');
    }
    else{
      while(trouve==false) {
	if(temp[j].getStyle('text-transform')!='none') {
	  transform='&style='+temp[j].getStyle('text-transform');
	  trouve=true;
	} else {
	  if(temp[j+1].match('body')) {
	    trouve=true;
	  }
	  else {
	    j++;
	  }
	}
      }
    }
    if(t[i].getStyle('font-weight')!='none'){
      style='&font='+t[i].getStyle('font-weight');
    }
    else{
      style='';
      trouve=false;j=0;
      while(trouve==false) {
	if(temp[j].getStyle('font-weight')!='none') {
	  style='&font='+temp[j].getStyle('font-weight');
	  trouve=true;
	} else {
	  if(temp[j+1].match('body')) {
	    trouve=true;
	  }
	  else {
	    j++;
	  }
	}
      }
    }
    // fin//
    width=t[i].getStyle('width');
    if(width.match("[%]","g")){
      trouve=false;var temp=t[i].ancestors();j=0;
      while(trouve==false){
	if(temp[j+1].match('body')) {
	  trouve=true;
	}
	if((temp[j].getStyle('width'))==null) { 
	  width="400px";trouve=true; 
	}
	else if((temp[j].getStyle('width')).match("[%]","g")){
	  j=j+1;
	}
	else{
	  width=temp[j].getStyle('width');
	  trouve=true;
	}
      }
    }          
    width=width.replace("px","");
    width=width.replace("em","");
    if(width.match("[pt]","g")) {
      width=width.replace("pt","");
      width=round((4/3)*width);
    }
    size=((t[i].getStyle('font-size')).replace("px","")).replace("em","");
    pos="&pos="+t[i].getStyle('text-align');
    var str='<img src="http://94.23.31.209/im.php?str='+encodeURIComponent(t[i].innerHTML)+'&color='+encodeURIComponent(t[i].getStyle('color'))+'&width='+width+'&size='+size+style+transform+pos+'"/>';
    t[i].update( str);
  }
}


// New function move to previous
var validWBox = '150';
var validWImg = '150'; 
var size_box_affiche = '900'; 
var numImg = '7';
function moveToNext() {
  var validMove = getMoveStatus('next');
  if(validMove) {
    new Effect.Move('imageBoxInside', { x: (0 - validWBox), y: 0, transition: Effect.Transitions.sinoidal });
  }
}
function moveToPrevious() {
  var validMove = getMoveStatus('prev');
  if(validMove) {
    new Effect.Move('imageBoxInside', { x: validWBox, y: 0, transition: Effect.Transitions.sinoidal });
  }
}
function getMoveStatus(currMove) {
  var nbr_img_total = $$('.cli').length;
  var theLeft = document.getElementById('imageBoxInside').style.left;
  var imgNumComul = numImg * validWImg;
  theLeft = parseInt(theLeft.replace('px',''));
  if(currMove == 'next') {
    theLeft = (theLeft - validWBox);
  } else {
    theLeft = (theLeft + 130);
  }
  if(theLeft == validWBox) {
    return false;
  } else if(theLeft < (0 - (nbr_img_total - numImg) * validWBox)) {
    return false;
  } else if(theLeft > 130 ) {
    return false;
  } else if(theLeft.NaN ) {
    return false;
  } else {
    return true;
  }
}
function change_real(tab_client, id_client, id_tag_lum) {
  if(id_client != "client_selection") {
    deroule(tab_client, 'client_'+id_client);
    change_lum(id_tag_lum);
    var r=$$('div.client');

    var reg=new RegExp("[_,\n, ]+", "g");
    for(i=0;i<=r.indexOf(r.last()); i++) { 
      if(Element.visible(r[i])) {
        var temp=(r[i].id).split(reg)[1];
      }
    }

    var image=$$('img.img-souli');  
    for(i=0;i<=image.indexOf(image.last()); i++) { 
      image[i].style.borderBottom='3px solid #ffffff';
    }
    document.getElementById("img_"+id_client).style.borderBottom='3px solid #ec7527';
  } else {
    deroule(tab_client, 'client_selection');
    change_lum_pl(id_tag_lum);
    var r=$$('div.client');

    var reg=new RegExp("[_,\n, ]+", "g");
    for(i=0;i<=r.indexOf(r.last()); i++) { 
      if(Element.visible(r[i])) {
        var temp=(r[i].id).split(reg)[1];
      }
    }

    var image=$$('img.img-souli');  
    for(i=0;i<=image.indexOf(image.last()); i++) { 
      image[i].style.borderBottom='3px solid #ffffff';
    }
    document.getElementById("img_selection").style.borderBottom='3px solid #ec7527';
  }
}


function baseline(tid,aid,menu)
{
  if (document.getElementById(tid)){
    document.getElementById(tid).innerHTML+=menu;
    document.getElementById(tid).onmouseover = function(){document.getElementById("b"+tid).style.display='inline';}
    document.getElementById(tid).onmouseout = function(){document.getElementById("b"+tid).style.display='none';}	
  }
}

function change_image(image,id) {
  $(id).src=image;
}

function insert_slash() {
var des = $('active_menu-menu').descendants();
$('active_menu-menu').onmouseout = '';
$('active_menu-menu').onmouseover = '';
des[0].src="/images/menu/slash.png";
des[2].src="/images/menu/slash.png";
des[1].src="/images/menu/"+des[1].id+"_h.png";
}

function insert_light(tab) {
  for(i=0; i<tab.length; i++) {
    var a = new Element('a', { 'class': 'cboxelement', href: tab[i].src, rel: 'lightbox[roadtrip]' })
    tab[i].wrap(a);
  }
}
function timer(tim) {
tim = setTimeout("ajoutFlash()",50000);
}

function ajoutFlash() {
var flash= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="opac" align="middle" height="100%" width="100%"><param name="allowScriptAccess" value="sameDomain"></param>	<param name="wmode" value="transparent"></param><param name="allowFullScreen" value="false"></param><param name="movie" value="/flash/opacity.swf"></param><param name="quality" value="high">	</param>	<embed src="flash/opacity.swf" quality="high" name="flashopacity" wmode="transparent" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" align="middle" height="100%" width="100%"></embed>  	<param name="wmode" value="transparent"></param></object>';
$('cache').style.width='100%';
$('cache').style.height='100%';
$('cache').innerHTML=flash;
}

function retireflash() {
$('cache').style.width='0%';
$('cache').style.height='0%';
$('cache').innerHTML='';
timer(tim);
}
