/* Javascript - Laforet Immobilier */

/***** Sommaire *****/
// 01 - Variables
// 02 - Methodes
// 05 - Affichage / Masquage layer information
// 10 - Debloquage liste secondaire
// 15 - Diaporama
// 18 - Comparer
// 20 - Navigation
// 25 - Popup
// 30 - Selection region
// 50 - Ajax
// 55 - Module "Trouver une agence"
// 60 - Espace Laforet
// 65 - Controle des formulaires
// 80 - Google Maps
// 99 - onLoad
/***** ******** *****/

/***** 01 - Variables *****/
var actURL  = document.location.href;
var isOpera = (navigator.userAgent.indexOf('Opera') == 55 || navigator.userAgent.indexOf('Opera') == 36 || navigator.userAgent.indexOf('Opera') == 0)? true : false ;

var Xpos;
var Ypos;
var decalY;
var offsetAdd;
var timeInfo;
var tabSearchVilles = new Array();

/***** 02 - Methodes *****/

// Ajoute la fonction trim comme mÃ©thode de l'objet String.
String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function resetFormField (name)
{
  var item = document.getElementById(name);
  
  if (item)
  {
    item.value = '';
    item.disabled = false;
  }
}

/***** 05 - Affichage / Masquage layer information *****/
function showInfo(){
	var layerInfo = document.getElementById('infoLayer');
	layerInfo.style.left = (Xpos+50)+'px';
	if(document.all && !isOpera){
		document.getElementById('flayerinfo').style.left = (Xpos+50)+'px';
		document.getElementById('flayerinfo').style.height = document.getElementById('infoLayer').offsetHeight;
	}
	
	if((document.getElementById('infoLayer').offsetHeight+(Ypos-150)) > document.getElementsByTagName('div')[0].offsetHeight){
		Ypos = document.getElementsByTagName('div')[0].offsetHeight-document.getElementById('infoLayer').offsetHeight;
	} else {
		Ypos = (Ypos-150);
	}
	
	layerInfo.style.top = Ypos+'px';
	if(document.all && !isOpera){
		document.getElementById('flayerinfo').style.top = Ypos+'px';
	}
}

function hideInfo(){
	var layerInfo = document.getElementById('infoLayer');
	layerInfo.style.top = '-999px';
	layerInfo.style.left = '-999px';
	if(document.all && !isOpera){
		document.getElementById('flayerinfo').style.left = '-999px';
		document.getElementById('flayerinfo').style.top = '-999px';
	}
}

/***** 10 - Debloquage liste secondaire *****/
function unlockSList(obj){
	if(obj == "citiesBiens")
	{
		document.FormMaRecherche.villeBiens.selectedIndex = 0;
		document.FormMaRecherche.villeBiens.disabled = (document.FormMaRecherche.regBiens.value != '')? '' : 'disabled' ;
		document.FormMaRecherche.large[0].disabled = 'disabled';
		document.FormMaRecherche.large[1].disabled = 'disabled';
		document.FormMaRecherche.large[2].disabled = 'disabled';
		document.FormMaRecherche.large[3].disabled = 'disabled';
	}
	else if(obj == "agences")
	{
		document.FormTrouverAgence.villeAgences.selectedIndex = 0;
		document.FormTrouverAgence.villeAgences.disabled = (document.FormTrouverAgence.dptAgences.value != '')? '' : 'disabled' ;
	}
	if(obj == "large" || obj == "largeLoad")
	{
          var like = document.FormMaRecherche.libre.value;
          var isville = (like != "" && isNaN(like.substring(0,1)) && like.length >= 4);

		if(isville) {
			document.FormMaRecherche.large[0].disabled = '';
			document.FormMaRecherche.large[1].disabled = '';
			document.FormMaRecherche.large[2].disabled = '';
			document.FormMaRecherche.large[3].disabled = '';
		}
		else {
                  isville = (document.FormMaRecherche.villeBiens.value != '');
			document.FormMaRecherche.large[0].disabled = (isville)? '' : 'disabled';
			document.FormMaRecherche.large[1].disabled = (isville)? '' : 'disabled';
			document.FormMaRecherche.large[2].disabled = (isville)? '' : 'disabled';
			document.FormMaRecherche.large[3].disabled = (isville)? '' : 'disabled';
		}
	}
	else if(obj == "largePop" && opener.document.FormMaRecherche && document.FormMaRecherche)
	{		
                isville = (opener.document.FormMaRecherche.villeBiens.value != '');
		document.FormMaRecherche.large[0].disabled = (isville)? '' : 'disabled';
		document.FormMaRecherche.large[1].disabled = (isville)? '' : 'disabled';
		document.FormMaRecherche.large[2].disabled = (isville)? '' : 'disabled';
		document.FormMaRecherche.large[3].disabled = (isville)? '' : 'disabled';
	}
}

/***** 15 - Diaporama *****/
var curPos = 0;

function scrollUp(id){
	var realID = id.substr(9);
	eval('var curPos = thumbPos'+realID);
	if(curPos < 0){
		curPos += 10;
		document.getElementById('scroll'+realID).getElementsByTagName('div')[0].style.top = curPos+'px';
		eval('thumbPos'+realID+' = '+curPos+';');
	} else {
		document.getElementById('scroll'+realID).getElementsByTagName('div')[0].style.top = '0px';
	}
}

function scrollDown(id){
	var realID = id.substr(9);
	eval('var curPos = thumbPos'+realID);
	if(document.getElementById('scroll'+realID).getElementsByTagName('div')[0].offsetHeight + curPos - document.getElementById('scroll'+realID).offsetHeight > 0){
		curPos -= 10;
		document.getElementById('scroll'+realID).getElementsByTagName('div')[0].style.top = curPos+'px';
		eval('thumbPos'+realID+' = '+curPos+';');
	}
}

function showPreview(monImg,id){
	var i = 0;
	if(document.getElementById('previewImg'+id).getElementsByTagName('img')[0].id == 360) i++;
	newSrc = monImg.src.replace('/tn/102x76','');
	document.getElementById('previewImg'+id).getElementsByTagName('img')[i].src = newSrc;
}

function buildDiapo(){
	// Scan des DIV
	var divTable = document.getElementsByTagName('div');
	var diapoTable = new Array();
	for(i=0; i<divTable.length; i++){
		// Div resultats
		if(divTable[i].className == 'diapo'){ diapoTable[diapoTable.length] = divTable[i]; }
	}
	// 15 - Diaporama
	var timeScroll;
	if(diapoTable.length > 0){
		for(i=0; i<diapoTable.length; i++){
			var divDiapoChilds = diapoTable[i].getElementsByTagName('div');
			for(j=0; j<divDiapoChilds.length; j++){
				if(divDiapoChilds[j].className.indexOf('previewImg') != -1){
					divDiapoChilds[j].id = 'previewImg'+i;
				} else if(divDiapoChilds[j].className.indexOf('scrollTop') != -1){
					divDiapoChilds[j].id = 'scrollTop'+i;
					divDiapoChilds[j].onmouseover = function(){ timeScroll = setInterval("scrollUp(\""+this.id+"\");", 100); }
					divDiapoChilds[j].onmouseout = function(){ clearInterval(timeScroll); }
				} else if(divDiapoChilds[j].className.indexOf('thumbs') != -1){
					eval('thumbPos'+i+' = 0;');
					divDiapoChilds[j].id = 'scroll'+i;
					var thumbTab;
					thumbTab = divDiapoChilds[j].getElementsByTagName('img');
					for(k=0; k<thumbTab.length; k++){
						thumbTab[k].id = i;
						thumbTab[k].onmouseover = function(){ showPreview(this,this.id); }
					}
				} else if(divDiapoChilds[j].className.indexOf('scrollBot') != -1){
					divDiapoChilds[j].id = 'scrollBot'+i;
					divDiapoChilds[j].onmouseover = function(){ timeScroll = setInterval("scrollDown(\""+this.id+"\");", 100); }
					divDiapoChilds[j].onmouseout = function(){ clearInterval(timeScroll); }
				}
			}
		}
	}
}

/***** 18 - Comparer *****/
function buildVoletComp(){

	var tempTab = document.getElementById('compar').getElementsByTagName('div');
	var tempCount = 0;
	for(i=0; i<tempTab.length; i++){
		if(tempTab[i].className == 'link'){ 
			tempTab[i].getElementsByTagName('a')[0].id = 'link'+tempCount;
			tempTab[i].getElementsByTagName('a')[0].href = 'javascript:showDetail('+tempCount+');';
			tempCount ++;
		}
	}
	var tempTab = document.getElementById('compar').getElementsByTagName('td');
	var tempCount = 0;
	for(i=0; i<tempTab.length; i++){
		if(tempTab[i].className == 'detail'){
			tempTab[i].id = 'detail'+tempCount;
			tempTab[i].getElementsByTagName('a')[0].href = 'javascript:hideDetail('+tempCount+');';
			tempCount ++;
		}
	}
		
}

function showDetail(id)
{
  if (id != "" && 
      (texte = file("http://www.laforet.com/immobilier/mon-espace-laforet/popup/getFicheBien.php?propertyId="+escape(id))))
    {
      if (texte != "" && texte.indexOf("::") == -1)
      {
	tabSearchFiche 		= texte.split("|");
	agencyId 		= tabSearchFiche[0];
	transactionBien 	= tabSearchFiche[1];
	propertyId 		= tabSearchFiche[2];
	propertyBien		= tabSearchFiche[3];
	roomsQuantity 		= tabSearchFiche[4];
	city 			= tabSearchFiche[5];
	departementId 		= tabSearchFiche[6];
	description_bien 	= tabSearchFiche[7];
	constructionYear 	= tabSearchFiche[8];
	bathroomsQuantity 	= tabSearchFiche[9];
	waterClosetsQuantity 	= tabSearchFiche[10];
	waterRoomsQuantity 	= tabSearchFiche[11];
	kitchenType 		= tabSearchFiche[12];
	heatingNature		= tabSearchFiche[13];
	cellar			= tabSearchFiche[14];
	parkingInsidesQuantity	= tabSearchFiche[15];
	parkingOutsidesQuantity	= tabSearchFiche[16];
	garagesQuantity		= tabSearchFiche[17];
	surface			= tabSearchFiche[18];
	livingroomSurface	= tabSearchFiche[19];
	groundSurface		= tabSearchFiche[20];
	surfaceUnit		= tabSearchFiche[21];
	sellingPrice		= tabSearchFiche[22];
	privilege		= tabSearchFiche[23];
	fees			= tabSearchFiche[24];
	mainVisu		= tabSearchFiche[25];
	subVisus		= tabSearchFiche[26];
	contratPrivilege2	= tabSearchFiche[27];
	agencyName		= tabSearchFiche[28];
	address1		= tabSearchFiche[29];
	postalCode		= tabSearchFiche[30];
	agencyCity		= tabSearchFiche[31];
	phoneNumber		= tabSearchFiche[32];
	faxNumber		= tabSearchFiche[33];
	mailAddress		= tabSearchFiche[34];
	webURL			= tabSearchFiche[35];
	nbVisus			= tabSearchFiche[36];
	virtualVisitURL		= tabSearchFiche[37];
	disabledPeopleAccess	= tabSearchFiche[38];
	lift			= tabSearchFiche[39];
	bedroomsQuantity	= tabSearchFiche[40];
	basement		= tabSearchFiche[41];
	swimmingPool		= tabSearchFiche[42];
	balcony			= tabSearchFiche[43];
	lotsQuantity		= tabSearchFiche[44];
	googleMaps		= tabSearchFiche[45];
	rcs 			= tabSearchFiche[46];
	terrace 		= tabSearchFiche[47];
			
	document.getElementById("propertyId_"+id).innerHTML = propertyId;
			
        var infosfiche = 
          "<strong>" + sellingPrice + 
          "&nbsp;&euro;</strong>&nbsp;* <strong>   - " + propertyBien;
       if (roomsQuantity != "" && roomsQuantity > 0) 
         infosfiche += " " + roomsQuantity + " pi&egrave;ce(s)";
       if (surface != "" && surface != "-") 
         infosfiche +=  " / " + surface;

       infosfiche += "</strong><br />" + city + " (" + departementId + ")";
       document.getElementById("infosFiche_" + id).innerHTML = infosfiche;

      if (fees != "" && fees != 0)
      {	
        document.getElementById("fees1_" + id).innerHTML = fees;
        document.getElementById("fees_" + id).style.display = "block";
      }

      document.getElementById("descFiche_" + id).innerHTML = description_bien;

      if (contratPrivilege2 == 1) 
        document.getElementById("contratPrivilege_"+id).style.display = "block";
      else 
        document.getElementById("contratPrivilege_"+id).style.display = "none"
			
      if (propertyBien != "Terrain" && propertyBien != "Fonds de commerce" && propertyBien != "Parking")
      {				
        if (propertyBien == "Bureau" || propertyBien == "Local commercial")
        {
	  document.getElementById("type1_"+id).style.display = "";
					
          document.getElementById("surface1_"+id).innerHTML = surface;
          document.getElementById("heatingNature1_"+id).innerHTML = 
            heatingNature;
          document.getElementById("parkingInsidesQuantity1_"+id).innerHTML = 
            parkingInsidesQuantity;
          document.getElementById("parkingOutsidesQuantity1_"+id).innerHTML =
            parkingOutsidesQuantity;
          document.getElementById("garagesQuantity1_"+id).innerHTML = 
            garagesQuantity;
          if (disabledPeopleAccess > 0) 
            document.getElementById("disabledPeopleAccess1_"+id).innerHTML = 
              "Acc&egrave;s handicap&eacute;";
        }
        else if (propertyBien == "Immeuble")
        {
          document.getElementById("type2_"+id).style.display = "";
			  		
          document.getElementById("surface2_"+id).innerHTML = surface;
          document.getElementById("lotsQuantity2_"+id).innerHTML = lotsQuantity;
          if (lift > 0) 
            document.getElementById("lift2_"+id).innerHTML = 
              "Ascenseur";
          document.getElementById("groundSurface2_"+id).innerHTML = 
            groundSurface;
          document.getElementById("parkingInsidesQuantity2_"+id).innerHTML = 
            parkingInsidesQuantity;
          document.getElementById("parkingOutsidesQuantity2_"+id).innerHTML = 
            parkingOutsidesQuantity;
          document.getElementById("garagesQuantity2_"+id).innerHTML = 
            garagesQuantity;
          document.getElementById("cellar2_"+id).innerHTML = cellar;
          document.getElementById("constructionYear2_"+id).innerHTML = 
            constructionYear;
          document.getElementById("heatingNature2_"+id).innerHTML = 
            heatingNature;
          if (disabledPeopleAccess > 0) 
            document.getElementById("disabledPeopleAccess2_"+id).innerHTML = 
              "Acc&egrave;s handicap&eacute;";
        }
        else if (propertyBien == "Maison" || propertyBien == "Appartement")
        {
          document.getElementById("type3_"+id).style.display = "";
					
          document.getElementById("livingroomSurface3_"+id).innerHTML = 
            livingroomSurface;
          document.getElementById("kitchenType3_"+id).innerHTML = kitchenType;
          document.getElementById("bedroomsQuantity3_"+id).innerHTML = 
            bedroomsQuantity;
          document.getElementById("groundSurface3_"+id).innerHTML = 
            groundSurface;
          document.getElementById("bathroomsQuantity3_"+id).innerHTML = 
            bathroomsQuantity;
          document.getElementById("waterRoomsQuantity3_"+id).innerHTML = 
            waterRoomsQuantity;
          document.getElementById("heatingNature3_"+id).innerHTML = 
            heatingNature;
          document.getElementById("constructionYear3_"+id).innerHTML = 
            constructionYear;
          document.getElementById("parkingInsidesQuantity3_"+id).innerHTML = 
            parkingInsidesQuantity;
          document.getElementById("parkingOutsidesQuantity3_"+id).innerHTML = 
            parkingOutsidesQuantity;
          document.getElementById("cellar3_"+id).innerHTML = cellar;
          document.getElementById("garagesQuantity3_"+id).innerHTML = 
            garagesQuantity;
					
          if (propertyBien == "Maison")
          {
            document.getElementById("sstype3_1_"+id).style.display = "";
						
            if (basement > 0) 
              document.getElementById("basement3_"+id).innerHTML = 
                "Sous-sol";
            if (swimmingPool > 0) 
              document.getElementById("swimmingPool3_"+id).innerHTML = 
                "Piscine";
          }
          else if (propertyBien == "Appartement")
          {
            document.getElementById("sstype3_2_"+id).style.display = "";
						
            document.getElementById("balcony3_"+id).innerHTML = 
              balcony+"/"+terrace;
            if (lift > 0) 
              document.getElementById("lift3_"+id).innerHTML = 
                "Ascenseur";
          }
					
          if (disabledPeopleAccess > 0) 
            document.getElementById("disabledPeopleAccess3_"+id).innerHTML = 
              "Acc&egrave;s handicap&eacute;";
        }
      }
      else document.getElementById("produitDesc").style.display = "none";
			
      /* Visuels */
      if (virtualVisitURL != "") 
        document.getElementById("virtualVisitURL_"+id).innerHTML = 
          "<a href='"+virtualVisitURL+"' target='_blank'><img id='360' src='/img/anim_360.gif' alt='Visite virtuelle' /></a>";
      if (mainVisu != "") 
        document.getElementById("mainVisu_"+id).innerHTML = mainVisu;
      if (subVisus != "") 
        document.getElementById("subVisus_"+id).innerHTML = subVisus;
			
      if (nbVisus > 4)
      {
        document.getElementById("infosScrollTop_"+id).style.display = "block";
        document.getElementById("infosScrollBot_"+id).style.display = "block";
      }
			
      agenceInfos = agencyName+"<br />";
      if (rcs != "") 
        agenceInfos += rcs+"<br />";
      agenceInfos += address1+"<br />"+postalCode+" "+agencyCity;
      document.getElementById("agenceInfos_"+id).innerHTML = agenceInfos;
      if (googleMaps == 1) 
        document.getElementById("agenceGoogle_"+id).innerHTML = 
          "<a class=google href=javascript:openWin('http://www.laforet.com/maps/geoZoom.php?agencyId="+agencyId+"') class=lien>> Localiser avec Google Maps</a>";
			
      if (phoneNumber != "") 
        phoneNumber += "<br />";
      else 
        phoneNumber = "-<br />";
			
      if (faxNumber != "") 
        faxNumber += "<br />";
      else 
        faxNumber = "-<br />";
			
      if (mailAddress != "") 
        mailAddress = 
          "<a href=\"mailto:"+mailAddress+"\">"+mailAddress+"</a><br />";
      else 
        mailAddress = "-<br />";
			
      if (webURL != "") 
        webURL = 
          "<a href=\"http://"+webURL+"\" target=\"_blank\">"+webURL+
          "</a><br />";
      else 
        webURL = "-<br />";
			
      document.getElementById("phoneNumber_"+id).innerHTML = phoneNumber;
      document.getElementById("faxNumber_"+id).innerHTML = faxNumber;
      document.getElementById("mailAddress_"+id).innerHTML = mailAddress;
      document.getElementById("webURL_"+id).innerHTML = webURL;		
			
      document.getElementById("agenceRdv_"+id).href = 
        "javascript:openPopup('http://www.laforet.com/immobilier/popup/rendez-vous.php?agence="+agencyId+"&bien="+propertyId+"','form',560,630,'scrollbars=yes');";
      document.getElementById("agenceEcrire_"+id).href = 
        "javascript:openPopup('http://www.laforet.com/immobilier/popup/ecrire-agence.php?agence="+agencyId+"&bien="+propertyId+"','form',560,600,'scrollbars=yes');";
			
      document.getElementById("agenceSelect_"+id).href = 
        "javascript: openPopup('http://www.laforet.com/immobilier/popup/selection.php?id="+propertyId+"&type="+transactionBien+"','selection',330,370);";
      document.getElementById("agenceAmi_"+id).href = 
        "javascript:openPopup('http://www.laforet.com/immobilier/popup/envoi-ami.php?id="+propertyId+"','ami',560,400,'scrollbars=yes');";
			
      document.getElementById('detail'+id).style.display = '';
      document.getElementById('link'+id).style.display = 'none';
    }
  }
}

function hideDetail(id){
	document.getElementById('detail'+id).style.display = 'none';
	document.getElementById('link'+id).style.display = '';
}


/***** 20 - Navigation *****/
var lastNav = '';
function showMenu(id){
	if(lastNav != ''){
		hideMenu(lastNav);
	}
	document.getElementById(id).className += ' hover';
	lastNav = id;
}

function hideMenu(id){
	document.getElementById(id).className = document.getElementById(id).className.substring(0,document.getElementById(id).className.length-6);
	lastNav = '';
}

/***** 25 - Popup *****/
function openPopup(url,name,w,h,o){
	window.open(url,name,'width='+w+',height='+h+',resizable=0,'+o);
}

/***** 30 - Selection region *****/
var regionFind = false;
function selectRegion(id,n){
	var optionTab = opener.document.getElementById(id).getElementsByTagName('option');
	for(i=0; i<optionTab.length; i++){
		if(optionTab[i].value == n){
			optionTab[i].selected = true;
			opener.unlockSList();
			regionFind = true;
			region = optionTab[i].value;
		}
	}

	if(regionFind == true && (id == "mySearchList" || id == "advancedSearchList"))
	{
		getVille(region,'citiesBiensPop');
		window.close();
	}
	else if(regionFind == true && id == "cibleSearchList")
	{
		window.close();
	}
	else
	{
		if (!confirm("Aucun bien n'a Ã©tÃ© trouvÃ© dans cette rÃ©gion. Voulez-vous chercher dans une autre ?")) {
			window.close();
		}
	}
}

/***** Selection departement *****/
function selectDept(id,n,dept){
	var optionTab = opener.document.getElementById(id).getElementsByTagName('option');
	for(i=0; i<optionTab.length; i++){
		if(optionTab[i].value == n){
			optionTab[i].selected = true;
			opener.unlockSList();
			region = optionTab[i].value;
		}
	}

	getVille(region,'citiesBiensPop',dept);
	window.close();
}
function selectList (obj,loc)
{
if (!document.getElementById(obj))
  return;

	var arrOptions = document.getElementById(obj).getElementsByTagName('option');
	for(i=0; i<arrOptions.length; i++){
		if(arrOptions[i].value == loc){
			arrOptions[i].selected = true;
		}
	}
}

/***** 50 - Ajax *****/
function stats(p)
{
	if(window.XMLHttpRequest) { // FIREFOX
		xhr_object = new XMLHttpRequest();
	} else if(window.ActiveXObject) { // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return(false);
	}
	xhr_object.open("POST", 'http://www.laforet.com/includes/php/statistics.php', true);
        xhr_object.setRequestHeader('Content-Type', 
          'application/x-www-form-urlencoded; charset=UTF-8');
	xhr_object.send(p);

}
function file(fichier)
{
	if(window.XMLHttpRequest) { // FIREFOX
		xhr_object = new XMLHttpRequest();
	} else if(window.ActiveXObject) { // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return(false);
	}
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) {
		return(xhr_object.responseText);
	} else {
		return(false);
	}
}

function writediv(texte,obj) {
	if(obj == "agences") document.getElementById("citiesAgences").innerHTML = texte;
	else if(obj == "citiesBiens" || obj == "citiesBiensLoad") {
		document.getElementById("citiesBiens").innerHTML = texte;
		if (obj != "citiesBiensLoad") unlockSList("large");
	}
	else if(obj == "citiesBiensPop") {
		opener.document.getElementById("citiesBiens").innerHTML = texte;
		unlockSList("largePop");
	}
	else if(obj == "regionsBiens" || obj == "regionsBiensLoad" || obj == "regionsBiensAvance" || obj == "regionsBiensAvanceLoad") {
		document.getElementById("regionsBiens").innerHTML = texte;
		if(obj != "regionsBiensLoad" && obj != "regionsBiensAvanceLoad") unlockSList("citiesBiens");
	}
	else if(obj == "search") {
		document.getElementById("searchbox").style.visibility = "visible";
		document.getElementById("searchbox").style.display = "block";
		document.getElementById("searchbox").innerHTML = texte;
		var helpDiv = document.getElementById('searchbox');
		if(!isOpera && document.all){
			if(!document.getElementById('helpSyntax')){
				document.getElementById('autosearch').innerHTML = '\n<iframe id="helpSyntax" frameborder="0" style="display:none;z-index:15;position:absolute;width:'+helpDiv.offsetWidth+'px;height:'+helpDiv.offsetHeight+'px;"></iframe>\n';
			}
			document.getElementById('helpSyntax').style.display = '';
			document.getElementById('helpSyntax').style.visibility = 'visible';
		}
	}
}

function getReg(obj) {

	if(document.FormMaRecherche.transactionType[0].checked) transaction_type = document.FormMaRecherche.transactionType[0].value;
	else if(document.FormMaRecherche.transactionType[1].checked) transaction_type = document.FormMaRecherche.transactionType[1].value;
	
	if (obj == "regionsBiensAvance" || obj == "regionsBiensAvanceLoad")
	{	
		arr_property = new Array();
		if(document.FormMaRecherche.maison.checked) arr_property.push(1);
		if(document.FormMaRecherche.appartement.checked) arr_property.push(2);
		if(document.FormMaRecherche.terrain.checked) arr_property.push(4);
		if(document.FormMaRecherche.immeuble.checked) arr_property.push(3);
		if(document.FormMaRecherche.bureau.checked) arr_property.push(5);
		if(document.FormMaRecherche.local.checked) arr_property.push(6);
		if(document.FormMaRecherche.commerce.checked) arr_property.push(7);
		if(document.FormMaRecherche.parkinggaragebox.checked) arr_property.push(8);

		property_type = arr_property.join();
		urlReg = "http://www.laforet.com/includes/modules/rechercheBiens/getRegionsBiens.php?type="+transaction_type+"&property="+property_type+"&recherche=avance";
	}
	else
	{
		arr_property = new Array();
		if(document.FormMaRecherche.maison.checked) arr_property.push(1);
		if(document.FormMaRecherche.appartement.checked) arr_property.push(2);

		property_type = arr_property.join();
		urlReg = "http://www.laforet.com/includes/modules/rechercheBiens/getRegionsBiens.php?type="+transaction_type+"&property="+property_type+"&recherche=normal";
	}
	
	if(texte = file(urlReg)) {
		if(texte != "")	{
			writediv(texte,obj);
		}
	}
}

function getVille(loc,obj,dept) {
	if(loc != "") {
		if(obj == "agences") {
			url  = "http://www.laforet.com/trouverAgence/getVillesAgences.php";
			url2 = "";
		}
		else if(obj == "citiesBiens" || obj == "citiesBiensLoad") {
			if(obj != "citiesBiensLoad") {
				document.FormMaRecherche.libreCP.value = "";
				document.FormMaRecherche.libre.value = "";
			}
			
			if(document.FormMaRecherche.transactionType[0].checked) transaction_type = document.FormMaRecherche.transactionType[0].value;
			else if(document.FormMaRecherche.transactionType[1].checked) transaction_type = document.FormMaRecherche.transactionType[1].value;
			
			arr_property = new Array();

			if(document.FormMaRecherche.maison.checked) arr_property.push(1);
			if(document.FormMaRecherche.appartement.checked) arr_property.push(2);
			
			if (document.FormMaRecherche.terrain)
			{
			  if(document.FormMaRecherche.terrain.checked) arr_property.push(4);
			  if(document.FormMaRecherche.immeuble.checked) arr_property.push(3);
			  if(document.FormMaRecherche.bureau.checked) arr_property.push(5);
			  if(document.FormMaRecherche.local.checked) arr_property.push(6);
			  if(document.FormMaRecherche.commerce.checked) arr_property.push(7);
			  if(document.FormMaRecherche.parkinggaragebox.checked) arr_property.push(8);
			}

			property_type = arr_property.join();
			
			url  = "http://www.laforet.com/rechercheBiens/getVillesBiens.php";
			url2 = "&type="+transaction_type+"&property="+property_type;
		}
		else if(obj == "citiesBiensPop") {
			opener.document.FormMaRecherche.libreCP.value = "";
			opener.document.FormMaRecherche.libre.value = "";
		
			if(opener.document.FormMaRecherche.transactionType[0].checked) transaction_type = opener.document.FormMaRecherche.transactionType[0].value;
			else if(opener.document.FormMaRecherche.transactionType[1].checked) transaction_type = opener.document.FormMaRecherche.transactionType[1].value;
			
			if (opener.document.FormMaRecherche.maison || opener.document.FormMaRecherche.appartement)
			{
				arr_property = new Array();
				if(opener.document.FormMaRecherche.maison.checked) arr_property.push(1);
				if(opener.document.FormMaRecherche.appartement.checked) arr_property.push(2);
				
				property_type = arr_property.join();
			}
			else
			{
				arr_property = new Array();
				if(document.FormMaRecherche.maison.checked) arr_property.push(1);
				if(document.FormMaRecherche.appartement.checked) arr_property.push(2);
				if(document.FormMaRecherche.terrain.checked) arr_property.push(4);
				if(document.FormMaRecherche.immeuble.checked) arr_property.push(3);
				if(document.FormMaRecherche.bureau.checked) arr_property.push(5);
				if(document.FormMaRecherche.local.checked) arr_property.push(6);
				if(document.FormMaRecherche.commerce.checked) arr_property.push(7);
				if(document.FormMaRecherche.parkinggaragebox.checked) arr_property.push(8);
				
				property_type = arr_property.join();
			}
			
			url  = "http://www.laforet.com/rechercheBiens/getVillesBiens.php";
			url2 = "&type="+transaction_type+"&property="+property_type+ ((dept != undefined) ? "&dept="+dept : '');
		}
		if(texte = file("http://www.laforet.com//includes/modules/"+url+"?loc="+escape(loc)+url2)) {
			if(texte != "")	{
				writediv(texte,obj);
			}
		}
	}
	else {
		unlockSList(obj);
	}
}

function searchPreview(like,nbCaracteresMin) {

	document.FormMaRecherche.regBiens.value = "";

	if(like != "" && isNaN(like.substring(0,1)) && like.length >= nbCaracteresMin) {
		
	unlockSList("citiesBiens");
          document.FormMaRecherche.large[0].disabled = '';
	  document.FormMaRecherche.large[1].disabled = '';
	  document.FormMaRecherche.large[2].disabled = '';
	  document.FormMaRecherche.large[3].disabled = '';

		like = like.toLowerCase();
		
		document.getElementById("searchbox").style.visibility = "hidden";
		document.getElementById("searchbox").style.display = "none";	
		document.getElementById("searchbox").innerHTML = "";
		
		/* On cherche la chaine dans le tableau javascript s'il existe */
		if(tabSearchVilles != "" && tabSearchVilles[0].length > 1 && tabSearchVilles[0].substring(0,1) != '_' && like.length > nbCaracteresMin) {
			if(tabSearchVilles[0].indexOf("::") == -1) {
				
				if(like.indexOf("(") > 0) like = like.substring(0,like.indexOf("(")-1)
				like = like.trim ();
				
				cpt = 0;
				texthtml  = "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
				var trouve = false;
				for(keyVar in tabSearchVilles) {
				
					tmp = tabSearchVilles[keyVar].split("_");
					if(tmp[1].substring(0,like.length) == getNormalizedCity(like)) {
					   	dpt 	= tmp[0];
					   	city 	= tmp[1];
					   
						if ((cpt%2) == 0) rowcls = "gris";
						else rowcls = "blanc";
						
						texthtml += "<tr class='txt11 "+rowcls+"'><td style='padding-left:5px;'><a href=\"#0\" onclick=\"setSearch('"+dpt+"','"+city+"');unlockSList('large');\" class='txt11'>"+city+" ("+dpt+")</a></td></tr>";
						trouve = true;
						cpt++;
					}
				}
				if(trouve == false) texthtml = "<a href=\"#0\" onclick=\"setSearch('','')\" class='txt11'>Aucun element ne correspond a la demande.</a>";
				texthtml += "</table>\n";
			}
			else {
				texthtml = "<a href=\"#0\" onclick=\"setSearch('','')\" class='txt11'>"+tabSearchVilles[0].replace("::","")+"</a>";
			}
			writediv(texthtml,"search");
		}
		else if(texte = file("http://www.laforet.com/includes/modules/rechercheBiens/getVillesSearch.php?search="+escape(like))) {
		/* On execute sinon le script pour recuperer un tableau des villes commencant par la chaine recherchee */
			if(texte != "")	{
				if(texte.indexOf("::") == -1) {
					cpt = 0;
					tabSearchVilles = texte.split(",");
					
					texthtml  = "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
					for(keyVar in tabSearchVilles) {
						
						tmp 	= tabSearchVilles[keyVar].split("_");
					   	dpt	= tmp[0];
					   	city 	= tmp[1];
					   
						if ((cpt%2) == 0) rowcls = "gris";
						else rowcls = "blanc";
						
						texthtml += "<tr class='txt11 "+rowcls+"'><td style='padding-left:5px;'><a href=\"#0\" onclick=\"setSearch('"+dpt+"','"+city+"');unlockSList('large');\" class='txt11'>"+city+" ("+dpt+")</a></td></tr>";
						cpt++;
					}
					texthtml += "</table>\n";
				}
				else {
					tabSearchVilles = texte.split(",");
					texthtml = "<a href=\"#0\" onclick=\"setSearch('','')\" class='txt11'>"+texte.replace("::","")+"</a>";
				}
				writediv(texthtml,"search");
			}
		}
	}
	else if(like.length < nbCaracteresMin) {
          document.FormMaRecherche.large[0].disabled = 'disabled';
	  document.FormMaRecherche.large[1].disabled = 'disabled';
	  document.FormMaRecherche.large[2].disabled = 'disabled';
	  document.FormMaRecherche.large[3].disabled = 'disabled';

		document.getElementById("searchbox").style.visibility = "hidden";
		document.getElementById("searchbox").style.display = "none";	
		document.getElementById("searchbox").innerHTML = "";
		if(!isOpera && document.all){
			if(document.getElementById('helpSyntax')){
				document.getElementById('helpSyntax').style.display = 'none';
				document.getElementById('helpSyntax').style.visibility = 'hidden';
			}
		}
		document.FormMaRecherche.libreCP.value = "";
	}
	else document.FormMaRecherche.libreCP.value = "";

}

function searchPreviewMultiple(obj,nbCaracteresMin) {
	
	like = obj.value;

	if(like != "" && isNaN(like.substring(0,1)) && like.length >= nbCaracteresMin) {
		
		like = like.toLowerCase();
		document.getElementById("searchbox").style.visibility = "hidden";
		document.getElementById("searchbox").style.display = "none";	
		document.getElementById("searchbox").innerHTML = "";
		
		/* On cherche la chaine dans le tableau javascript s'il existe */
		if(tabSearchVilles != "" && like.length > nbCaracteresMin) {
			if(tabSearchVilles[0].indexOf("::") == -1) {
				
				if(like.indexOf("(") > 0) like = like.substring(0,like.indexOf("(")-1)
				like = like.trim ();
				
				cpt = 0;
				texthtml  = "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
				var trouve = false;
				for(keyVar in tabSearchVilles) {
				
					tmp = tabSearchVilles[keyVar].split("_");
					if(tmp[1].substring(0,like.length) == getNormalizedCity(like)) {
					   	dpt 	= tmp[0];
					   	city 	= tmp[1];
					   
						if ((cpt%2) == 0) rowcls = "gris";
						else rowcls = "blanc";
						
						texthtml += "<tr class='txt11 "+rowcls+"'><td style='padding-left:5px;'><a href=\"#0\" onclick=\"setSearchMultiple('"+obj.id+"','"+dpt+"','"+city+"');\" class='txt11'>"+city+" ("+dpt+")</a></td></tr>";
						trouve = true;
						cpt++;
					}
				}
				if(trouve == false) texthtml = "<a href=\"#0\" onclick=\"setSearchMultiple('"+obj.id+"','','')\" class='txt11'>Aucun element ne correspond a la demande.</a>";
				texthtml += "</table>\n";
			}
			else {
				texthtml = "<a href=\"#0\" onclick=\"setSearchMultiple('"+obj.id+"','','')\" class='txt11'>"+tabSearchVilles[0].replace("::","")+"</a>";
			}
			writediv(texthtml,"search");
		}
		else if(texte = file("http://www.laforet.com/includes/modules/rechercheBiens/getVillesSearch.php?search="+escape(like))) {
		/* On execute sinon le script pour recuperer un tableau des villes commencant par la chaine recherchee */
			if(texte != "")	{
				if(texte.indexOf("::") == -1) {
					cpt = 0;
					tabSearchVilles = texte.split(",");
					
					texthtml  = "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
					for(keyVar in tabSearchVilles) {
						
						tmp 	= tabSearchVilles[keyVar].split("_");
					   	dpt	= tmp[0];
					   	city 	= tmp[1];
					   
						if ((cpt%2) == 0) rowcls = "gris";
						else rowcls = "blanc";
						
						texthtml += "<tr class='txt11 "+rowcls+"'><td style='padding-left:5px;'><a href=\"#0\" onclick=\"setSearchMultiple('"+obj.id+"','"+dpt+"','"+city+"');\" class='txt11'>"+city+" ("+dpt+")</a></td></tr>";
						cpt++;
					}
					texthtml += "</table>\n";
				}
				else {
					tabSearchVilles = texte.split(",");
					texthtml = "<a href=\"#0\" onclick=\"setSearchMultiple('"+obj.id+"','','')\" class='txt11'>"+texte.replace("::","")+"</a>";
				}
				writediv(texthtml,"search");
			}
		}
		
	}
	else if(like.length < nbCaracteresMin) {
		document.getElementById("searchbox").style.visibility = "hidden";
		document.getElementById("searchbox").style.display = "none";	
		document.getElementById("searchbox").innerHTML = "";
		if(!isOpera && document.all){
			if(document.getElementById('helpSyntax')){
				document.getElementById('helpSyntax').style.display = 'none';
				document.getElementById('helpSyntax').style.visibility = 'hidden';
			}
		}
	}

}

function reg_replace(chaine,char1,char2) {
	var reg = new RegExp(char1, "ig");
	nouv_chaine  = chaine.replace(reg,char2);
	return nouv_chaine;
}

function getNormalizedCity(chaine) {
	/* Remplacement des apostrophes par des espaces */
	chaine = reg_replace(chaine,"'"," ");
	
	/* Remplacement des tirets par des espaces */
	chaine = reg_replace(chaine,"-"," ");
	
	/* Convertion des caracteres accentues en leur equivalent ASCII */
	chaine = reg_replace(chaine,"['Ã Ã¢Ã¤']","a");
	chaine = reg_replace(chaine,"['Ã©Ã¨ÃªÃ«']","e");
	chaine = reg_replace(chaine,"['Ã®Ã¯']","i");
	chaine = reg_replace(chaine,"['Ã´Ã¶']","o");
	chaine = reg_replace(chaine,"['Ã¹Ã»Ã¼']","u");
	
	/* Mise en majuscule de toutes les premieres lettres de la chaine */
	var elements 	= chaine.split(" ");
	for(key in elements) {
		elements[key] = elements[key].substring(0,1).toUpperCase() + elements[key].substring(1,elements[key].length);
	}
	chaine = elements.join(" ");
	return chaine;
}

function setSearch(str1,str2) {

	if(str1 != "" && str2 != "")
	{
		document.FormMaRecherche.regBiens.value = "";
		
	}
	unlockSList("citiesBiens");

	document.forms.FormMaRecherche.libreCP.value = str1;
	document.forms.FormMaRecherche.libre.value   = str2;
	if(str1 != "") document.forms.FormMaRecherche.libre.value += " ("+str1+")";

	document.getElementById("searchbox").style.visibility = "hidden";
	document.getElementById("searchbox").style.display = "none";	
	document.getElementById("searchbox").innerHTML = "";
	if(!isOpera && document.all){
		document.getElementById('helpSyntax').style.display = 'none';
		document.getElementById('helpSyntax').style.visibility = 'hidden';
	}
}

function setSearchMultiple(obj,str1,str2) {

	eval("document.getElementById('"+obj+"CP').value = '"+str1+"'");
	eval("document.getElementById('"+obj+"').value = '"+str2+"'");
	
	if(str1 != "") eval("document.getElementById('"+obj+"').value += '("+str1+")'");

	document.getElementById("searchbox").style.visibility = "hidden";
	document.getElementById("searchbox").style.display = "none";	
	document.getElementById("searchbox").innerHTML = "";
	if(!isOpera && document.all){
		document.getElementById('helpSyntax').style.display = 'none';
		document.getElementById('helpSyntax').style.visibility = 'hidden';
	}
}

function rempliMultiple(type)
{
	ch1 = "";
	ch2 = "";
	
	libre1 		= document.getElementById("libre1").value;
	libre1CP 	= document.getElementById("libre1CP").value;
	libre2 		= document.getElementById("libre2").value;
	libre2CP 	= document.getElementById("libre2CP").value;
	libre3 		= document.getElementById("libre3").value;
	libre3CP 	= document.getElementById("libre3CP").value;
	libre4 		= document.getElementById("libre4").value;
	libre4CP 	= document.getElementById("libre4CP").value;
	
	/* Noms des villes */
	if(libre1 != "") ch1  = libre1;
	else document.getElementById("libre1CP").value = "";
	if(libre2 != "")
	{
		if(libre2 != libre1)
		{
			if(ch1 != "") ch1 += ", ";
			ch1 += libre2;
		}
	}
	else document.getElementById("libre2CP").value = "";
	if(libre3 != "")
	{
		if(libre3 != libre2 && libre3 != libre1)
		{
			if(ch1 != "") ch1 += ", ";
			ch1 += libre3;
		}
	}
	else document.getElementById("libre3CP").value = "";
	if(libre4 != "")
	{
		if(libre4 != libre3 && libre4 != libre2 && libre4 != libre1)
		{
			if(ch1 != "") ch1 += ", ";
			ch1 += libre4;
		}
	}
	else document.getElementById("libre4CP").value = "";
	
	libre1CP 	= document.getElementById("libre1CP").value;
	libre2CP 	= document.getElementById("libre2CP").value;
	libre3CP 	= document.getElementById("libre3CP").value;
	libre4CP 	= document.getElementById("libre4CP").value;
	
	/* CP des villes */
	if(libre1CP != "")
	{
		ch2  = libre1CP;
	}
	else if (libre1 != "") ch2 = "0";
	if(libre2CP != "" && libre2 != libre1)
	{
		if(ch2 != "") ch2 += ",";
		ch2 += libre2CP;
	}
	else if (libre2 != "")
	{
		if(ch2 != "") ch2 += ",";
		ch2 += "0";
	}
	if(libre3CP != "" && libre3 != libre2 && libre3 != libre1)
	{
		if(ch2 != "") ch2 += ",";
		ch2 += libre3CP;
	}
	else if (libre3 != "")
	{
		if(ch2 != "") ch2 += ",";
		ch2 += "0";
	}
	if(libre4CP != "" && libre4 != libre3 && libre4 != libre2 && libre4 != libre1)
	{
		if(ch2 != "") ch2 += ",";
		ch2 += libre4CP;
	}
	else if (libre4 != "")
	{
		if(ch2 != "") ch2 += ",";
		ch2 += "0";
	}

	opener.document.getElementById("libre").value = ch1;
	opener.document.getElementById("libreCP").value = ch2;
	opener.document.getElementById(type).options[0].selected = 'selected';
        opener.getVille(opener.document.getElementById(type).value,'citiesBiens');
	
	window.close();
}

function showFiche(obj,propertyId,nav,cpt)
{
  if (document.all && 
      !isOpera && document.getElementById('flayerinfo') || 
      !document.all || 
      isOpera)
  {
    hideInfo ();
		
    Xpos = obj.offsetParent.offsetLeft;
    Ypos = obj.offsetParent.offsetTop;
    if (propertyId != "" && 
        (texte = file("http://www.laforet.com/immobilier/annonces-immobilieres/getFicheSearch.php?search="+escape(propertyId)+"&nav="+nav+"&cpt="+cpt)))
    {
      if (texte != "")
      {
        tabSearchFiche = texte.split("|");
        transactionType = tabSearchFiche[0];
        propertyType = tabSearchFiche[1];
        city = tabSearchFiche[2];
        contratPrivilege2 = tabSearchFiche[3];
        sellingPrice = tabSearchFiche[4];
        roomsQuantity = tabSearchFiche[5];
        surface = tabSearchFiche[6];
        surfaceUnit = tabSearchFiche[7];
        departementId = tabSearchFiche[8];
        desc = tabSearchFiche[9];
        groundSurface = tabSearchFiche[10];
        bedroomsQuantity = tabSearchFiche[11];
        floorsQuantity = tabSearchFiche[12];
        mainVisu = tabSearchFiche[13];
        subVisus = tabSearchFiche[14];
        fees =  tabSearchFiche[15];
        deposit =  tabSearchFiche[16];
        cession =  tabSearchFiche[17];
        internetLocation = tabSearchFiche[18];
        				
        var infoLoc1 = '';
        var infoLoc2 = '';
        var infoLoc3 = '';

        if (transactionType == '2')
        {
          var localBureau = (propertyType == "Local commercial" || 
                             propertyType == "Bureau");
          infoLoc1 = (localBureau) ? 
            " annuel HT HC" : 
            " mensuel CC";
          if (fees != '0')
          {
            infoLoc2 = 
              '<br />Honoraires en sus : ' + fees +  
              '&nbsp;&euro;&nbsp;' + 
              ((localBureau) ? 'HC' : 'TTC');
          }

          if (deposit != '0')
          {
            infoLoc3 += 
              '<br />DÃ©pÃ´t de garantie : ' + 
              deposit + '&nbsp;&euro;&nbsp;' + 'TTC';
          }

          if (localBureau)
            infoLoc3 += 
              '<br />Cession de bail : ' + 
              cession + '&nbsp;&euro;&nbsp;' + 'HT' + '*';
        }

        var infosfiche = 
          "<strong>"+sellingPrice+" &euro; " + infoLoc1 + 
          "</strong> * <strong> - "+
          propertyType;
        if (roomsQuantity != "" && roomsQuantity > 0) 
          infosfiche += " "+roomsQuantity+" pi&egrave;ce(s)";
        if (surface != "") 
          infosfiche +=  "<br />"+surface+" "+surfaceUnit + '&nbsp;' + 
            'environ';
        infosfiche += "</strong><br /><b>" + 
          ((internetLocation == 1) ? "Aux alentours de " : "") +
          city + " (" + departementId + ")</b>";
        infosfiche += infoLoc2 + infoLoc3;
        document.getElementById("infosFiche").innerHTML = infosfiche;
        document.getElementById("descFiche").innerHTML = desc;

        if (contratPrivilege2 == 1) 
          document.getElementById("contratPrivilege").style.display = "block";
        else 
          document.getElementById("contratPrivilege").style.display = "none";

         /* Visuels */
        if (mainVisu != "") 
          document.getElementById("visuFiche").innerHTML = mainVisu;
        if (subVisus != "") 
          document.getElementById("thumbFiche").innerHTML = 
            subVisus+"\n<div class=\"clear\"></div>\n";
				
        // Clear & appel
        clearTimeout(timeInfo);
        timeInfo = 
          setTimeout("showInfo('',"+obj.offsetTop+","+obj.offsetLeft+");",500);
      }
    }
    buildDiapo();
  }
}

function getForm(nb)
{
  var err = '';
  var civ1 = document.FormSubscribtion.civilite[0].checked;
  var civ2 = document.FormSubscribtion.civilite[1].checked;
  var civ3 = document.FormSubscribtion.civilite[2].checked;
  var civ4 = document.FormSubscribtion.civilite[3].checked;
  var cprenom = document.FormSubscribtion.cprenom.value;
  var cnom = document.FormSubscribtion.cnom.value;
  var ccp = document.FormSubscribtion.cCP.value;
  var cemail = document.FormSubscribtion.cemail.value;
  var pswd1 = document.FormSubscribtion.pswd1.value;
  var pswd2 = document.FormSubscribtion.pswd2.value;
  var show = 1;
	
  document.getElementById('alertForm2').innerHTML = '';
  document.getElementById('alertFormV').innerHTML = '';

  if (cemail == '' || pswd1 == '' || pswd2 == '')
  {
    err = "Veuillez remplir les champs suivants&nbsp:<br />";
    if (cemail == '') 
      err += "- E-Mail<br />";
    if (pswd1 == '') 
      err += "- Mot de passe<br/>";
    if (pswd2 == '') 
      err += "- Confirmation du mot de passe";

    document.getElementById('alertForm2').innerHTML = err;

    if (ccp == '')
      return;
  }

  if (ccp != '' && ((civ1 == '' && civ2 == '' && civ3 == '' && civ4 == '') || (cprenom == '' || cnom == '')))
  {
    err = "Veuillez remplir les champs suivants&nbsp:<br />";
    if (civ1 == '' && civ2 == '' && civ3 == '' && civ4 == '') 
      err += "- CivilitÃ©<br />";
    if (cprenom == '') 
      err += "- PrÃ©nom<br />";
    if (cnom == '') 
      err += "- Nom";

    document.getElementById('alertFormV').innerHTML = err;
    return;
  }
  else if (nb == 1 && ccp == '')
  {
    show = 0;
    document.FormSubscribtion.submit ();
  }

  if ((cprenom != '' && cnom != '' && ccp != '') && 
      (texte = file("http://www.laforet.com/immobilier/mon-espace-laforet/getForm.php?cnom=" + 
        escape (cnom) + '&cprenom=' + escape (cprenom) + '&ccp=' + 
	ccp + '&cemail=' + escape (cemail))))
  {
    if (texte != '')
    {
      if (texte == '0')
      {
        err = "Aucun bien en vente n'est liÃ© aux nom, prÃ©nom et numÃ©ro saisis. Pour accÃ©der Ã  l'isuivi, vous devez les modifier et cliquer sur <i>Corriger</i>.<br>Si vous souhaitez simplement mÃ©moriser une recherche, veuillez effacer les donnÃ©es saisies dans le cadre rÃ©servÃ© aux vendeurs.";
	document.getElementById('alertFormV').innerHTML = err;
	show = 1;
        document.getElementById('vendorRetry').style.visibility = 'visible';
      }
      else if (texte.indexOf('::') == -1)
      {
        tabForm = texte.split ('|');
			
        civ = tabForm[0];
        //cprenom = tabForm[1];
        ccp2 = tabForm[2];
        cnum2 = tabForm[3];
        adresse1 = tabForm[4];
        adresse2 = tabForm[5];
        cp = tabForm[6];
        country = tabForm[7];
        ville = tabForm[8];
        tel = tabForm[9];
				
        if (nb == 1)
        {
          if (civ == "m") 
	    document.FormSubscribtion.civilite[0].checked = true;
          else if (civ == "mme") 
	    document.FormSubscribtion.civilite[1].checked = true;
          else if (civ == "mlle") 
	    document.FormSubscribtion.civilite[2].checked = true;
					
          if(ccp == '' && ccp2 != '')
          {
            show = 0;
            openPopup (
	      'http://www.laforet.com/immobilier/mon-espace-laforet/popup/' +
	      'http://www.laforet.com/profil-contrat-privilege.php', 'contrat', 541, 300);
          }
          else 
	    document.FormSubscribtion.cCP.value = ccp2;
					
          document.FormSubscribtion.cadrs.value = adresse1;
          document.FormSubscribtion.cadrs2.value = adresse2;
          document.FormSubscribtion.cp.value = cp;
          document.FormSubscribtion.ccountry.value = country;
          document.FormSubscribtion.cville.value = ville;
          document.FormSubscribtion.ctel.value = tel;
        }
				
        var arrDisabledFields = new Array ();
	arrDisabledFields['civilite'] = 1;
	arrDisabledFields['cprenom'] = 1;
	arrDisabledFields['cnom'] = 1;
	arrDisabledFields['cCP'] = 1;
	arrDisabledFields['cadrs'] = 1;
	arrDisabledFields['cadrs2'] = 1;
	arrDisabledFields['cp'] = 1;
	arrDisabledFields['ccountry'] = 1;
	arrDisabledFields['cville'] = 1;
	arrDisabledFields['ctel'] = 1;
				
        if (nb == 2)
        {
          var arrPericlesFields = new Array ();					
          periclesFields = document.FormSubscribtion.periclesFields.value;
          arrPericlesFields = periclesFields.split(',');
					
          arrDisabledFields['civilite'] = 0;
          arrDisabledFields['cprenom'] = 0;
          arrDisabledFields['cnom'] = 0;
          //arrDisabledFields['cCP'] = 0;
          arrDisabledFields['cadrs'] = 0;
          arrDisabledFields['cadrs2'] = 0;
          arrDisabledFields['cp'] = 0;
          arrDisabledFields['ccountry'] = 0;
          arrDisabledFields['cville'] = 0;
          arrDisabledFields['ctel'] = 0;
					
          for (i = 0; i < arrPericlesFields.length; i++)
          {
            if (arrPericlesFields[i] == "civilite") 
	      arrDisabledFields['civilite'] = 1;
            if (arrPericlesFields[i] == "cprenom")
	      arrDisabledFields['cprenom'] = 1;
            if (arrPericlesFields[i] == "cnom")
	      arrDisabledFields['cnom'] = 1;
            if (arrPericlesFields[i] == "cCP") 	
	      arrDisabledFields['cCP'] = 1;
            if (arrPericlesFields[i] == "cadrs")
	      arrDisabledFields['cadrs'] = 1;
            if (arrPericlesFields[i] == "cadrs2")
	      arrDisabledFields['cadrs2'] = 1;
            if (arrPericlesFields[i] == "cp")
	      arrDisabledFields['cp'] = 1;
            if (arrPericlesFields[i] == "ccountry")
	      arrDisabledFields['ccountry'] = 1;
            if (arrPericlesFields[i] == "cville")
	      arrDisabledFields['cville'] = 1;
            if (arrPericlesFields[i] == "ctel")
	      arrDisabledFields['ctel'] = 1;
          }
        }
				
        if ((document.FormSubscribtion.civilite[0].checked || 
	     document.FormSubscribtion.civilite[1].checked || 
	     document.FormSubscribtion.civilite[2].checked) && 
	     arrDisabledFields['civilite'] == 1)
        {
          document.FormSubscribtion.civilite[0].disabled = "disabled";
          document.FormSubscribtion.civilite[1].disabled = "disabled";
          document.FormSubscribtion.civilite[2].disabled = "disabled";
        }
	
        if (document.FormSubscribtion.cprenom.value != '' && 
	    arrDisabledFields['cprenom'] == 1) 
	  document.FormSubscribtion.cprenom.disabled = 'disabled';
	  
        if (document.FormSubscribtion.cnom.value != '' && 
	    arrDisabledFields['cnom'] == 1) 
	  document.FormSubscribtion.cnom.disabled = 'disabled';
	  
        if (document.FormSubscribtion.cCP.value != '' && 
	    arrDisabledFields['cCP'] == 1)
	  document.FormSubscribtion.cCP.disabled = 'disabled';

        if (document.FormSubscribtion.cadrs.value != '' && 
	    arrDisabledFields['cadrs'] == 1)
	  document.FormSubscribtion.cadrs.disabled = 'disabled';
	  
        if (document.FormSubscribtion.cadrs2.value != '' && 
	    arrDisabledFields['cadrs2'] == 1)
	  document.FormSubscribtion.cadrs2.disabled = 'disabled';
	  
        if (document.FormSubscribtion.cp.value != '' && 
	    arrDisabledFields['cp'] == 1)
	  document.FormSubscribtion.cp.disabled = 'disabled';
	  
        if (document.FormSubscribtion.ccountry.value != '' && 
	    arrDisabledFields['ccountry'] == 1)
	  document.FormSubscribtion.ccountry.disabled = 'disabled';

        if (document.FormSubscribtion.cville.value != '' && 
	    arrDisabledFields['cville'] == 1)
	  document.FormSubscribtion.cville.disabled = 'disabled';
	  
        if (document.FormSubscribtion.ctel.value != '' && 
	    arrDisabledFields['ctel'] == 1)
	  document.FormSubscribtion.ctel.disabled = 'disabled';
      }
      else
      {
        show = 0;
	err = 'yes';
        document.getElementById('alertFormV').innerHTML = 
          texte.replace ('::', '');
      }
    }
  }

  if (show == 1)
  {
    for (i = 0;i <= 10; i++)
    {
      document.getElementById('formLine' + i).style.display = '';
    }
    document.getElementById('btn2').style.visibility  = 'hidden';
    document.getElementById('vendorRetry').style.visibility = 'visible';
    location.href = '#suite';
  }

  if (err == '' && document.getElementById('fmkError').value != '1')
    document.getElementById('alertForm2').innerHTML = '';
}

function alerteMail(recherche,val)
{
	if(val == 0 || val == 1)
	{
		texte = file("http://www.laforet.com/immobilier/mon-espace-laforet/getFonctions.php?fonction=alerteMail&recherche="+recherche+"&val="+val);
		
		if (val == 0)
		{
			document.getElementById('alerte'+recherche+'_1').style.display = "none";
			document.getElementById('alerte'+recherche+'_0').style.display = "";
		}
		else
		{
			document.getElementById('alerte'+recherche+'_0').style.display = "none";
			document.getElementById('alerte'+recherche+'_1').style.display = "";
		}
	}
}

/***** 60 - Espace Laforet *****/
function afficheForm(val)
{
	if(val == 1)
	{
		for(i=0;i<=10;i++){
			opener.document.getElementById('formLine'+i).style.display = "";
		}
		opener.document.getElementById("btn2").style.visibility = "hidden";
	}
	else if (val == 2)
	{
          opener.document.location.href = 'http://www.laforet.com/immobilier/mon-espace-laforet/profil.php';
	}
	window.close();	
}

function submitIdentification (obj)
{
	// Scan des INPUT
	var inputTable = document.getElementsByTagName('input');
	var resultTable = new Array();
	j = 0;
	for(i=0; i<inputTable.length; i++){
	
		// Inputs resultats
		if (inputTable[i].name != "" && eval("obj."+(inputTable[i].name)))
		{
			if(inputTable[i].disabled){ 
				inputTable[i].disabled = '';
				resultTable[j] = inputTable[i].name;
				j++;
			}
		}
	}
	document.FormSubscribtion.periclesFields.value = resultTable.join ();
	obj.submit();
}

function saisiePassword (obj,action)
{
	if (action == 1 && obj.value == "****") obj.value = "";
	else if (action == 2 && obj.value == "") obj.value = "****";
}

/***** 55 - Module "Trouver une agence" *****/
function testListeAgences()
{
	if(document.FormTrouverAgence.dptAgences.selectedIndex <= 0) return;
	else {
		indexDpt   = document.FormTrouverAgence.dptAgences.selectedIndex;
		indexVille = document.FormTrouverAgence.villeAgences.selectedIndex;
		dpt	   = document.FormTrouverAgence.dptAgences[document.FormTrouverAgence.dptAgences.selectedIndex].value;
		ville	   = document.FormTrouverAgence.villeAgences[document.FormTrouverAgence.villeAgences.selectedIndex].value;

		url = document.FormTrouverAgence.action+"?dpt="+dpt+"&indexDpt="+indexDpt;
		if(indexVille > 0) {
			url += "&ville="+ville+"&indexVille="+indexVille;
		}
		document.location = url;
	}
}

function changePage(objForm,currentpage)
{
	eval("document."+objForm+".currentpage.value = "+currentpage+";");
	eval("document."+objForm+".submit();");
}

function chargeFiche(agence)
{
	document.FormFicheAgence.agence.value = agence;
	document.FormFicheAgence.submit();
}

/***** 65 - Controle des formulaires *****/
function checkEmail(email)
{
	var re = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,3}");
	var test = email.search(re);
	if(test != -1) return true;
	else {
		alert("Adresse email incorrecte");
		return false;
	}
}

function testFormHeader()
{
	var cp 	= document.FormHeaderTrouverAgence.ville.value;
	var reg = /^\d{0,5}$/;
	if(!reg.test(cp))
	{
		document.location = document.FormHeaderTrouverAgence.action + "?search=nok";
		return false;
	}
	else return true;
}

function testReference()
{
	if(document.FormReference.id.value == "") return false;
}

function testMaRecherche()
{
	if(!document.FormMaRecherche.maison.checked && !document.FormMaRecherche.appartement.checked && !document.FormMaRecherche.terrain.checked && !document.FormMaRecherche.immeuble.checked && !document.FormMaRecherche.bureau.checked && !document.FormMaRecherche.local.checked && !document.FormMaRecherche.commerce.checked && !document.FormMaRecherche.parkinggaragebox.checked)
	{
		document.getElementById('alertForm').innerHTML = "Veuillez choisir au moins un type de bien pour votre recherche";
		document.getElementById('alertForm').style.display = "block";
		return false;
	}
	else
	{
		document.getElementById('alertForm').innerHTML = "";
		document.getElementById('alertForm').style.display = "none";
	}
}

function testMaRecherche2()
{
	if(!document.FormMaRecherche.maison.checked && !document.FormMaRecherche.appartement.checked)
	{
		alert("Veuillez choisir au moins un type de bien pour votre recherche");
		return false;
	}
}

function testTri (page,query,tri)
{
	if (tri != 00)
	{
		var pos = query.indexOf('&tri=');
		if (pos > -1) location.href = page + "?" + query.substr(0,pos) + "&tri=" + tri;
		else location.href = page + "?" + query + "&tri=" + tri;
		
	}
}

function plusCriteres (obj)
{
	if (obj == "FormMaRecherche") {
		document.FormMaRecherche.action = "http://www.laforet.com/immobilier/annonces-immobilieres/annonce-immobilier.php";
		document.FormMaRecherche.submit ();
	} 
	else if (obj == "FormRechercheCiblee") {
		document.FormRechercheCiblee.action = "http://www.laforet.com/immobilier/annonces-immobilieres/annonce-immobilier.php";
		document.FormRechercheCiblee.submit ();
	}
}

/***** 80- Google Maps *****/
function openWin(url)   
{     
	googlemap = window.open(url,'googlemap','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=650,height=450');
}

/***** 99 - onLoad *****/
window.onload = function(){
	
	// 05 - Affichage / Masquage layer information
	if(document.getElementById('infoLayer')){
		document.getElementById('infoLayer').onmouseover = function(){ clearTimeout(timeInfo); }
		document.getElementById('infoLayer').onmousemove = function(){ clearTimeout(timeInfo); }
		document.getElementById('infoLayer').onmouseout = function(){ clearTimeout(timeInfo);  timeInfo = setTimeout("hideInfo();",500); }
		//ajout de l'iframe pour IE
		if(document.all && !isOpera){
			document.getElementById('resultats').innerHTML += '\n<iframe frameborder="0" id="flayerinfo" style="z-index:40;position:absolute;top:-999px;left:-999px;width:210px;height:150px;"></iframe>\n';
		}
	}
	
	// Scan des DIV
	var divTable = document.getElementsByTagName('div');
	var resultTable = new Array();
	diapoTable = new Array();
	for(i=0; i<divTable.length; i++){
		// Div resultats
		if(divTable[i].className == 'result'){ resultTable[resultTable.length] = divTable[i]; }
		if(divTable[i].className == 'diapo'){ diapoTable[diapoTable.length] = divTable[i]; }
	}
	
	var eventElem;
	for(i=0; i<resultTable.length; i++){
		eventElem = (resultTable[i].getElementsByTagName('div')[0].className == 'visu')? resultTable[i].getElementsByTagName('div')[0] : resultTable[i].getElementsByTagName('div')[1] ;
		eventElem.onmouseout = function(){ clearTimeout(timeInfo);  timeInfo = setTimeout("hideInfo();",500); }
	}
	
	// 15 - Diaporama
	buildDiapo();
	
	// 20 - Navigation
	var listTab = new Array();
	var sMenuTab = new Array();
	var timeMenu;
	if(document.getElementById('navtop')){
		listTab = document.getElementById('navtop').getElementsByTagName('li');
		for(i=0; i<listTab.length; i++){
			if(listTab[i].getElementsByTagName('div').length != 0){
				sMenuTab[sMenuTab.length] = listTab[i];
			}
		}
		
		for(i=0; i<sMenuTab.length; i++){
			//Attribution des ID
			sMenuTab[i].id = 'menu'+i;
			//Evenement
			sMenuTab[i].onmouseover = function(){ showMenu(this.id); }
			sMenuTab[i].onmouseout = function(){ timeMenu = setTimeout('hideMenu(\''+this.id+'\');',50); }
			sMenuTab[i].onmousemove = function(){ clearTimeout(timeMenu); }
		}
		//ajout de l'iframe pour IE
		if(document.all && !isOpera){
			for(i=0; i<sMenuTab.length; i++){
				reactDiv = sMenuTab[i].getElementsByTagName('div')[0];
				document.getElementById('menu'+i).innerHTML += '\n<iframe frameborder="0" id="fmen'+i+'" style="z-index:50;position:absolute;top:'+(reactDiv.offsetTop)+'px;left:'+reactDiv.offsetLeft+'px;width:'+reactDiv.offsetWidth+'px;height:'+(reactDiv.offsetHeight)+'px;"></iframe>\n';
			}
		}
	}
	
	if(document.getElementById("searchbox"))
	{
		document.getElementById("searchbox").onclick = function (){
				
			document.getElementById("searchbox").style.visibility = "hidden";
			document.getElementById("searchbox").style.display = "none";	
			document.getElementById("searchbox").innerHTML = "";
			if(!isOpera && document.all){
				if(document.getElementById('helpSyntax'))
				{
					document.getElementById('helpSyntax').style.display = 'none';
					document.getElementById('helpSyntax').style.visibility = 'hidden';
				}
			}
		}
	}
	
	// Affichage du bandeau pub
	if(document.getElementById("banner")) document.getElementById("banner").innerHTML = "<a href='#'><img src='http://stockage.laforet.com/regie//APGB/default.gif' width='468' height='60' alt='Pub' /></a>";
	
}

function show_hide (n, v)
{
  if (document.layers)
    document.layers[n].display = v;
  else if (document.all)
    document.all[n].style.display = v;
  else (document.getElementById)
    document.getElementById(n).style.display = v;
}
