// SELECT PERSONNALISE
function permuteSelect(sSelect) {
  sObject = document.getElementById(sSelect);
  Effect.toggle(sSelect, 'blind', {duration:0.5});
  //sObject.style.display = (sObject.style.display == 'none') ? 'block' : 'none';
}
function colorThis(obj){
  obj.className = 'option-over';
}
function decolorThis(obj){
  obj.className = 'option-out';
}
function validAndCache(sSelect, sDiv, sFormValue, txt2, sNameForm){
  document.getElementById(sNameForm).value = sFormValue;
  Effect.BlindUp(sDiv, {duration:0.5});
  if( sSelect!=""){
    if (document.getElementById(sSelect)){
      document.getElementById(sSelect).innerHTML =txt2;
    }
  }
  //document.getElementById('monForm').submit();
  if (sFormValue == 'bien de prestige' ) {
    actionList = new Array();
    Element.hide('select-type');
    Element.hide('select-montant');
    Element.hide('select-achat');
    Element.show('select-type-prest');
    sNameForm = 'prestige';
    sFormValue = 1;
    document.getElementById('lieu').value = null;
    if (document.getElementById('divSelectLieu')){
      document.getElementById('divSelectLieu').innerHTML = 'Secteur';
      }
    }
  activeListing(sNameForm, sFormValue);
  //window.location.replace("/informations/agences/"+sFormValue.slice(0,sFormValue.indexOf("|"))+"-"+txt2+".htm");
}


var actionList = new Array();
function activeListing(name, value, page) {
  actionList[name] = value;
  Element.update('content-right', '');
  new Ajax.Updater(
    'content-right',
    '/ajax.php',
      {
      method : 'get',
      parameters: {action: 'activeListing', type: actionList['type'], achat: actionList['achat'], prix: actionList['montant'], ville: actionList['lieu'], prestige: actionList['prestige'], transport: actionList['transport'], page: page, name: name, value: value},
      insertion: Insertion.Bottom
      }
    );
  }

function changePage(page, total) {
  for (i=1; i<=total; i++) {
    Element.hide('page_'+i);
    Element.removeClassName('lien_page_'+i, 'lienGras');
    }
  Element.show('page_'+page);
  Element.addClassName('lien_page_'+page, 'lienGras');
  }

function changeLetter(numLettre, NbTotalLettre) {
  for (i=1; i<=NbTotalLettre; i++) {
   // Element.setStyle('LettresLexique'+i, {weight:'normal'});
    Element.removeClassName('LettresLexique'+i, 'nom-lexique');
    }
 // Element.setStyle('LettresLexique'+numLettre, {weight:'bold'});
 Element.addClassName('LettresLexique'+numLettre, 'nom-lexique');
  }

function getByReference(ref) {
  Element.update('content-right', '');
  new Ajax.Updater(
    'content-right',
    '/ajax.php ',
      {
      method : 'get',
      parameters: {action: 'getByReference', reference: ref},
      insertion: Insertion.Bottom
      }
    );
  }

function getByLetter(ltr) {
  Element.update('responseGlossaire', '');
  new Ajax.Updater(
  'responseGlossaire',
  '/ajax.php ',
    {
    method : 'get',
    parameters: {action: 'getByLetter', letter: ltr},
    insertion: Insertion.Bottom
    }
  );
  }

function addComment(com, idSelect) {
  new Ajax.Request(
  '/ajax.php ',
    {
    method : 'get',
    parameters: {action: 'addComment', comment: com, selection: idSelect}
    }
  );
  }

function gestOnglet(div) {
  for (i=1; i<=3; i++) {
    Element.hide('content-'+i);
    Element.removeClassName($('lienContent_'+i).parentNode, 'actif');
    }
  Element.show('content-'+div);
  Element.addClassName($('lienContent_'+div).parentNode, 'actif');
  }

function changeImage(urlImage) {
  $('image-bien').src = "/"+urlImage;
  }

// MENU HORIZONTAL


function montre(id) {
var d = document.getElementById(id);
  for (var i = 1; i<=10; i++) {
    if (document.getElementById('sous-menu-'+i)) {document.getElementById('sous-menu-'+i).style.display='none';}
  }
if (d) {d.style.display='block';}
}

function ShowMenu(sObject) {
  montre();
  Effect.BlindDown(sObject, {duration:0.5});
}




// JavaScript Document



function gestBox ( id, action ) {
  if ( $(id) ) {
    if ( action == 'open')
      Effect.BlindDown(id);
    else
      Element.hide(id);
    }
  }

function gestBoxListe ( e ) {
 // alert($(e).options.length);
  for (i=0; i<$(e).options.length; i++) {
    gestBox ( $(e).options[i].value, 'close' );
    }
  //alert('sdsd');
  gestBox ( Field.getValue(e), 'open' );
  }

function ChangeMenuLeft(sObject) {
  // Variable à modifier selon besoin
  sRacineImage = "menu-bien-";
  sExtention = "jpg";
  sCheminImages = "/images/";

  sImage = document.getElementById(sRacineImage+sObject);
  sImageSrc = sImage.src;

  var iLongueurSrc = sImage.src.length; // Calcul du nbr de caractères dans le chemin

  var iExtension = (sImage.src.lastIndexOf("-")); //Recherche du dernier -
  var sEtat = sImage.src.substring(iExtension+1,iLongueurSrc);

  if (sEtat == "off." + sExtention) {
    sImage.src = sCheminImages + sRacineImage + sObject + "-on." + sExtention;
  }
  else {
    sImage.src = sCheminImages + sRacineImage + sObject + "-off." + sExtention;
  }
}


// AJOUTER AUX FAVORIS
var urlAddress = "";
var pageName = "Titre du site";
function addToFavorites(anchor) {
  if (window.external) {
    window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
  }
}

aTimerID = new Array();
timerID = null;
var active = 0;

function ScrollUp(speed, sDiv)
{
  if(document.getElementById)
  {
    iObject = document.getElementById(sDiv);
    if (iObject)
    {
      if (!iObject.style.left)
        iObject.style.left = 0;

      if (parseInt(iObject.style.left) < 0)
        iObject.style.left = parseInt(iObject.style.left)+speed + "px";

      timerID = setTimeout("ScrollUp("+speed+", '" + sDiv + "')",30);
      aTimerID.push(timerID);
    }
  }
}

function ScrollDown(speed, sDiv)
{
  if(document.getElementById)
  {
    iObject = document.getElementById(sDiv);
    if (iObject)
    {
      if (!iObject.style.left)
        iObject.style.left = 0;

      if (-parseInt(iObject.style.left)  < iObject.offsetWidth-270)
        iObject.style.left = parseInt(iObject.style.left)-speed + "px";

      timerID = setTimeout("ScrollDown("+speed+", '" + sDiv + "')",30);
      aTimerID.push(timerID);
    }
  }
}

function ScrollStop()
{
  for(i=0; i<aTimerID.length; i++)
    clearTimeout(aTimerID[i]);
}

function tipTop(hello) {
  alert(hello);
  }


// ESPACE CLENT
function ShowDetailClien(sDiv) {
  var d = document.getElementById(sDiv);
    for (var i = 1; i<=12; i++) {
      if (document.getElementById('content-client'+i)) {document.getElementById('content-client'+i).style.display='none';}
    }
  if (d) {d.style.display='block';}
}


function showRoomImg() {
  var prtElemTot = 0;
  for ( i = 0; i<aTabImg.length; i++  ) {

    imgElem = $('lienImg_'+aTabImg[i]);
    placeElem = Position.positionedOffset(imgElem);
    largeElem = Element.getWidth(imgElem);
    offsetElem = placeElem[0]-1;

    realPos = largeElem + offsetElem;
    if ( realPos <= 0 ) {
      imgElemEnd = $('lienImg_'+sLastElem);
      placeElemEnd = Position.positionedOffset(imgElemEnd);
      largeElemEnd = Element.getWidth(imgElemEnd);
      offsetElem = placeElemEnd[0] + largeElemEnd + 4;
      //alert(offsetElem);
      sLastElem = aTabImg[i];
      }

    imgElem.setStyle({
      left: offsetElem+'px'
      });
    }
  timer = setTimeout("showRoomImg()",2);
  }

function onImg(urlImg, href) {
  lien = document.getElementById('link-bien');
  lien.href = href;
  imgProd = document.createElement('img');
  imgProd.src = urlImg;
  $('link-bien').replaceChild(imgProd, $('image-bien'));
  imgProd.id = "image-bien";
  }
