function Menueur(ladiv) {
	Fermens(ladiv);
	if(document.getElementById(ladiv).style.visibility=="hidden") {
		document.getElementById(ladiv).style.visibility='visible';
		document.getElementById(ladiv).style.position='relative';
	} else {
		document.getElementById(ladiv).style.visibility='hidden';
		document.getElementById(ladiv).style.position='absolute';
	}
}

function Fermens(ladiv) {
	if(ladiv!="SMen1") {
		document.getElementById("SMen1").style.visibility='hidden';
		document.getElementById("SMen1").style.position='absolute';
	}
	if(ladiv!="SMen2") {
		document.getElementById("SMen2").style.visibility='hidden';
		document.getElementById("SMen2").style.position='absolute';
	}
	if(ladiv!="SMen3") {
		document.getElementById("SMen3").style.visibility='hidden';
		document.getElementById("SMen3").style.position='absolute';
	}
	if(ladiv!="SMen4") {
		document.getElementById("SMen4").style.visibility='hidden';
		document.getElementById("SMen4").style.position='absolute';
	}
	if(ladiv!="SMen5") {
		document.getElementById("SMen5").style.visibility='hidden';
		document.getElementById("SMen5").style.position='absolute';
	}
}

function VeriformRecherche(categorie) {
	criteres=0;
	chxtb=document.leform.elements["chxtb[]"];
	cocheestb=0;
	if(document.leform.elements["chxchrch"].value!="") criteres++;
	for (i = 0; i < chxtb.length; i++) {
		if (chxtb[i].checked) {
			cocheestb++;
		}
	}
	if(cocheestb>0) criteres++;
	if(categorie=="particuliers") {
		chxnbpieces=document.leform.elements["chxnbpieces[]"];
		cocheesnbp=0;
		for (i = 0; i < chxnbpieces.length; i++) {
			if (chxnbpieces[i].checked) {
				cocheesnbp++;
			}
		}
		if(cocheesnbp>0) criteres++;
	}

	if(document.leform.elements["chxlieu"].value!="") criteres++;
	if(document.leform.elements["chxbudgmin"].value!="" || document.leform.elements["chxbudgmax"].value!="") criteres++;
	if(document.leform.elements["chxsurfmin"].value!="" || document.leform.elements["chxsurfmax"].value!="") criteres++;
	if(cocheestb==0) {
		alert("Veuillez saisir au moins un type de bien s'il vous plait.");
	} else {
		document.leform.submit();
	}
}

var map;
var i;
function initialiser(ladiv,x,y,z) {
	if (GBrowserIsCompatible()) {
		this.i=1;
		var map = new GMap2(document.getElementById(ladiv),{ size: new GSize(500,400) } );
		map.addControl(new GLargeMapControl());
		map.removeMapType(G_HYBRID_MAP);
		map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();
		map.disableDoubleClickZoom();
		map.setCenter(new GLatLng(x,y),z);
		this.map=map;
	}
}

function recentrer(x,y,z) {
	map=this.map;
	map.setCenter(new GLatLng(x,y),z);
}

function glissesur(oux,ouy) {
	map=this.map;
	map.panTo(new GLatLng(oux,ouy));
}

function metpoint(oux,ouy,contenu) {
	map=this.map;
	point=new GLatLng(oux,ouy);
	marker = new GMarker(point,{draggable:false});
	map.addOverlay(marker);
}

function metpointdraggable() {
	map=this.map;
	var point = map.getCenter();
	marker = new GMarker(point,{draggable:true});
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("Point mobile");
	});
	GEvent.addListener(marker, "dragstart", function() {
		marker.closeInfoWindow();
	});
	map.addOverlay(marker);
}

function Deplieur(keldiv) {
	document.getElementById(keldiv).style.visibility='visible';
}

function Decouvre(keldiv) {
	document.getElementById(keldiv).style.visibility='visible';
	document.getElementById(keldiv).style.position='relative';
}

function Cache(keldiv) {
	document.getElementById(keldiv).style.visibility='hidden';
	document.getElementById(keldiv).style.position='absolute';
}

function PopImage(adresse) {
	document.getElementById('PopImage').innerHTML="<img border=\"0\" src=\"./drop/"+adresse+"\">";
}

function retaille() {
	if(this.i==1) {
		map=this.map;
		if (document.body) {
			var larg = (document.body.clientWidth);
			var haut = (document.body.clientHeight);
		} else {
			var larg = (window.innerWidth);
			var haut = (window.innerHeight);
		}
		document.getElementById('carte').style.width=larg-235;
		document.getElementById('carte').style.height=haut-70;
		map.checkResize();
	}
}

function itineraire(div) {
	document.getElementById(div).innerHTML='';
	map=this.map;
	directionsPanel = document.getElementById(div);
	directions = new GDirections(map, directionsPanel);
	directions.load("from: "+document.getElementById('adresse').value+" "+document.getElementById('ville').value+" "+document.getElementById('cp').value+" France to: 21, rue de Lyon 29200 Brest France");
}

function itineraireload() {
	alert('chargez');
}

function itineraireerreur() {
	alert('');
}

function favoris(ladresse) {
	if ( navigator.appName != 'Microsoft Internet Explorer' ) {
		window.sidebar.addPanel(ladresse,"");
	} else {
		window.external.AddFavorite(ladresse);
	}
}

function SaisiePJ() {
	document.getElementById('LesPJ').style.padding="5px;";
	if(document.getElementById('LesPJ').innerHTML=="") {
		this.npj=0;
		document.getElementById('LesPJ').innerHTML+="<ul><li>Documents de 200ko maximum</li><li>Cocher la vignette</li><li>Sp&eacute;cifier le type</li></ul>";
	}
	this.npj++;
	document.getElementById('LesPJ').innerHTML+="<p><input type='radio' name='vignette' value='"+this.npj+"'> <input type='file' name='pj[]'> <select name='typedoc[]'><option value='1'>Photo</option><option value='2'>Plan</option><option value='3'>T&eacute;l&eacute;chargement</option></select></p>";
}

function SaisiePJProg() {
	document.getElementById('LesPJ').style.padding="5px;";
	if(document.getElementById('LesPJ').innerHTML=="") {
		this.npj=0;
		document.getElementById('LesPJ').innerHTML+="<ul><li>Saisir l'intitul&eacute;</li><li>Documents de 200ko maximum</li><li>Sp&eacute;cifier le type</li></ul>";
	}
	this.npj++;
	document.getElementById('LesPJ').innerHTML+="<p><strong>Intitul&eacute; :</strong> <input size='40' type='text' name='intitule[]'><br /><input type='file' name='pj[]'> <select name='typedoc[]'><option value='1'>Photo</option><option value='2'>Plan</option><option value='3'>T&eacute;l&eacute;chargement</option></select></p>";
}

function PopUp(ledoc,larg,haut) {
	window.open(ledoc,'','width='+larg+' ,height='+haut);
}

function favoris(adresse,libelle) {
	if ( navigator.appName != 'Microsoft Internet Explorer' ) {
		window.sidebar.addPanel(libelle,adresse,"");
	} else {
		window.external.AddFavorite(adresse,libelle);
	}
}

function calculer() {
	montant = document.getElementById('mttprojet').value;
	nature  = document.getElementById('natprojet').value;
	//-- Calcul
	fraisnotaire = frais_de_notaire(montant,nature);
	//-- Affichage résultat
	if(fraisnotaire>0) {
		document.getElementById('leresfn').innerHTML="Montant estim&eacute; de vos frais de notaire :<br />"+fraisnotaire+" &euro;";
	} else {
		document.getElementById('leresfn').innerHTML="";
	}
}

function frais_de_notaire(montant_achatnet,nature) {
	//-- Vérifications
	if (( isNaN(parseInt(montant_achatnet,10))) || (montant_achatnet==0)){
		return(0);
	}
	if (nature == 7) return(0);
	//-- Initialisation
	var montant,natbien,honoraires,taxes,fraisnotaire,taux,ajout,nbTranche;
	honoraires = 0;
	montant    = parseInt(montant_achatnet,10);
	if (nature == 1 || nature == 3 || nature == 8 || nature == 9) natbien = "neuf";
	if (nature == 2 || nature == 4 ) natbien = "ancien";
	if (nature == 5 || nature == 6 ) natbien = "batir";
	/* tab_ref famille : immo_nature
	1 - Maison particulière - neuf
	2 - Maison particulière - ancien
	3 - Appartement - neuf
	4 - Appartement - ancien
	5 - Terrain + Construction
	6 - Terrain seul
	7 - Construction Seule
	8 - VEFA - Maison particulière
	9 - VEFA - Appartement
	*/
	//-- Tableau des tranches de taux pour honoraires
	nbTranche = 4;
	trancheD  = new Array(    0,  3051,   6101,   16771 );
	trancheF  = new Array( 3050,  6100,  16770, 99999999);
	taux_0    = new Array(    5,   3.3,   1.65,    0.825);
	ajout_0   = new Array(    0, 51.85,  152.5,   290.85);

	//-- Taux des taxes
	tauxAnc  = 5.09;
	tauxNeu  = 0.715;
	tauxBat  = 5.09;
	tauxTVA  = 19.6;

	//-- Calcul des honoraires
	montant = Math.round(montant);
	for (i=0; i < nbTranche ;i++) {
	if(trancheD[i]<montant && montant<trancheF[i]) {
	taux  = taux_0[i];
	ajout = ajout_0[i];
	break;
	}
	}
	honoraires = (montant*taux/100+ajout)*(1+tauxTVA/100);

	//-- Calcul des taxes
	//if (natbien=="neuf") 	  taxes = montant/(1+tauxTVA/100) * tauxNeu/100;
	if (natbien=="neuf") 		taxes = montant * tauxNeu/100;
	if (natbien=="ancien") 	taxes = montant * tauxAnc/100;
	if (natbien=="batir") 	taxes = montant * tauxBat/100;

	//-- Calcul des Frais divers
	fraisdivers = 1007 + montant/1000;

	//-- Frais de notaire arrondi à la centaine
	fraisnotaire = honoraires + fraisdivers + taxes ;
	fraisnotaire = Math.round(fraisnotaire/100)*100;

	return(fraisnotaire);
}
