﻿function go(typerubrique,rubriqueid,elementid,offset,nbrec,firstrec) {
  document.submitor.target = "";
  document.submitor.typerubrique.value = typerubrique;
  document.submitor.rubriqueid.value = rubriqueid;
  document.submitor.elementid.value = elementid;
  document.submitor.offset.value = offset;
  document.submitor.nbrec.value = nbrec;
  document.submitor.firstrec.value = firstrec;
  document.submitor.submit();
}

function setBloc(){  
  
  var left=document.getElementById("idPartieGauche"); 
  var right=document.getElementById("idPartieDroite"); 
  
  //Le gauche est plus grand
  if(right.offsetHeight<=(left.offsetHeight)){
    right.style.height=(left.offsetHeight)+'px';    
    return;
  }    
}

function recherche(root) {
  if(isInt(document.submitor.rec3,'Ce champ n\'est pas un entier') && isInt(document.submitor.rec4,'Ce champs n\'est pas un entier')) {
    document.location.href = root+'recherche/_'+urlise(document.submitor.rec2.options[document.submitor.rec2.selectedIndex].value)+'/_'+document.submitor.rec3.value+'/_'+document.submitor.rec4.value+'/_'+document.submitor.rec5.value+'/_'+document.submitor.rec6.value+'/1/index.htm';
  }
}

var corr = new Array ('_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','*','_','_','-','_','_','0','1','2','3','4','5','6','7','8','9','_','_','_','_','_','_','_','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','_','_','_','_','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','-','_','_','_','_','_','o','_','_','Y','_','i','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','A','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I','D','N','O','O','O','O','O','_','O','U','U','U','U','Y','_','B','a','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','o','n','o','o','o','o','o','_','_','u','u','u','u','y','_','y');

function urlise(s) {
  result = "";
  for(var i=0;i<s.length;i++) {
    result = result + corr[s.charCodeAt(i)];
  }
  return result;
}

function setEnr(enregistrementid,firstenr,nbenr) {

  document.submitor.enregistrementid.value = enregistrementid;
  document.submitor.nbenr.value = nbenr;
  document.submitor.firstenr.value = firstenr;
}
function notgood(field,msg) {
  field.focus();
  alert(msg);
  return false;
}

function isFull(field,msg){
  if (field.value=='') {return notgood(field,msg);}
  return true;
}

function isDigit(field,msg) {
  i = field.value.charCodeAt(0);
  if (!((47<i)&&(i<58))){return notgood(field,msg);}
  return true;
}

function isFloat(field,msg) {
  if (isNaN(field.value.replace(',','.'))){return notgood(field,msg);}
  return true;
}

function isInt(field,msg) {
  if (isNaN(field.value.replace(',','.'))){return notgood(field,msg);}
  if (Math.round(field.value)!=field.value){return notgood(field,msg);}
  return true;
}

function isEqual(field1,field2,msg1,msg2){
  if (!isFull(field1,msg1)) return false;
  if (!isFull(field2,msg1)) return false;
  if (field1.value!=field2.value) {return notgood(field1,msg2);}
  return true;
}

function isSelect(field,msg){
  if (field.selectedIndex==0 && field.options[0].value=="") {return notgood(field,msg);}
  return true;
}

function isMail(field,msg) {
  email=field.value;
  arobase=email.indexOf('@');
  point=email.indexOf('.',arobase);
  longueur=email.length;
  if(arobase<=0||point<=arobase+1||longueur<=point+1) {return notgood(field,msg);}
  return true;
}

function gomailer(root,typerubrique,rubriqueid,elementid,offset,nbrec,firstrec) {
  document.submitor.target = "";
  document.submitor.action=root+'mailer.aspx';
  document.submitor.typerubrique.value = typerubrique;
  document.submitor.rubriqueid.value = rubriqueid;
  document.submitor.elementid.value = elementid;
  document.submitor.offset.value = offset;
  document.submitor.nbrec.value = nbrec;
  document.submitor.firstrec.value = firstrec;
  document.submitor.submit();
}


function changePic(Id){
  document.getElementById('grandePhoto').src=eval('grandePhoto'+Id)   
  clearInterval(wait);
}

//On parcours le tableau jusqu'a trouver l'image en cours, et on prend la suivante.
//Si c'est la dernière on reprend la première
function changePicAuto(){
  var iloop=0;
  var exit=false;
  
  while(iloop<=(tabIds.length-2) && exit==false){      
    if(tabIds[iloop]==curId){
      iloop++;
      exit=true;
    }
    else{
      iloop++;
    }      
    if(iloop>tabIds.length-2){
      iloop=0;
      exit==true;    
    }
  }
  document.getElementById('grandePhoto').src=eval('grandePhoto'+tabIds[iloop])
  curId = tabIds[iloop];
}

function launchSlide(){
  wait=(setInterval("changePicAuto()",3000));
}

function inf(val1, val2){
  return (val1<val2);
}

function sendmail(root){
  next=true;
  if(document.submitor.nom.value=='') {
    alert('Veuillez saisir votre nom.');
    document.submitor.nom.focus();
    next=false;
  }
  if(next && document.submitor.prenom.value=='') {
    alert('Veuillez saisir votre prénom.');
    document.submitor.prenom.focus();
    next=false;
  }
  if(next && document.submitor.tel.value=='') {
    alert('Veuillez saisir votre numéro de téléphone.');
    document.submitor.tel.focus();
    next=false;
  }
  if(next && document.submitor.villebien.value=='') {
    alert('Veuillez saisir la localité du bien.');
    document.submitor.villebien.focus();
    next=false;
  }
  if(next && document.submitor.typebien.selectedIndex==0) {
    alert('Veuillez sélectionner le type de bien.');
    document.submitor.typebien.focus();
    next=false;
  }
  if(next && document.submitor.email.value=='') {
    alert('Veuillez saisir votre email.');
    document.submitor.email.focus();
    next=false;
  }
  if(next && isMail(document.submitor.email,'Veuillez saisir votre email.')) {
    gomailer(root,1,7,'','','','');  
  }
}