function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(function(){
	if($('corps_coeur')){
		myupdater();
	}
});

function changeScalePrice(type,obj){
	switch(type){
		case '2': // loc
		var option = '<option value="" selected="selected">    (&euro;)</option>';				
		var j = 0;
		for(var i = 0; i < 10001; i = i + 500){	j = i + 500; option += '<option value="'+i+'-'+j+'">'+i+'-'+j+'</option>';}		
		break;
		default: //vente		
		var option = '<option value="" selected="selected">    (&euro;)</option>';				
		var j = 0;
		for(var i = 0; i < 1000001; i = i + 100000){ j = i + 100000; option += '<option value="'+i+'-'+j+'">'+i+'-'+j+'</option>';}		
	}
	obj.innerHTML  = option;
}
/****************************************** GMAPS *
function load(lat,lng,zoom,prox){
	if (GBrowserIsCompatible()) {
		bounds = new GLatLngBounds();
		checktab= ",";

		var f = $("sidebarDIV");
		var inputs = f.getElementsByTagName("input");
		for(var t = 0;t < inputs.length;t++){
			if(inputs[t].type == "checkbox" && inputs[t].checked == true){
				checktab+=inputs[t].id+',';
			}
		}

		map = new GMap2(document.getElementById("map"));
		mapMarkers = new Array();
		for (var s = 0; s < 500; s++) {
			mapMeservices[s] = new Array();
		}
		for (var s = 0; s < 500; s++) {
			if(checktab.indexOf(",idservice"+s)<0){
				toggleState[s] = 0;
			}
			else{
				toggleState[s] = 1;
			}
		}

		map.addMapType(G_PHYSICAL_MAP);
		map.setMapType(G_PHYSICAL_MAP);
		map.addControl(new GScaleControl());                     
		map.addControl(new ZOOMBoutonControl());
		map.addControl(new PSMBoutonControl());

		map.setCenter(new GLatLng(lat, lng), zoom);

		chargeServices(lat,lng,prox,checktab);
	} else {
		alert("Désolé, les cartes Google ne sont pas compatibles avec votre navigateur");
	} 
}

// SERVICE PANORAMIO //
function PanoramioLayerCallback(json, panoLayer) {
	this.panoLayer = panoLayer;

	var batch = [];
	for (var i = 0; i < json.photos.length; i++) {
		var photo = json.photos[i];
		if (!panoLayer.ids[photo.photo_id]) {
			var marker = this.createMarker(photo, panoLayer.markerIcon);
			panoLayer.mgr.addMarker(marker, 0);
			panoLayer.ids[photo.photo_id] = "exists";
		}
	}
	panoLayer.mgr.addMarkers(batch, panoLayer.map.getZoom());
	panoLayer.mgr.refresh();
}

PanoramioLayerCallback.prototype.formImgUrl = function(photoId, imgType) {
  return 'http://www.panoramio.com/photos/' + imgType + '/' + photoId + '.jpg';
}
 
PanoramioLayerCallback.prototype.formPageUrl = function(photoId) {
  return 'http://www.panoramio.com/photo/' + photoId;
}

PanoramioLayerCallback.prototype.createMarker = function(photo, baseIcon) {
  var me = this;
  var markerIcon = new GIcon(baseIcon);
  markerIcon.image = this.formImgUrl(photo.photo_id, "mini_square");
  var marker = new GMarker(new GLatLng(photo.latitude, photo.longitude), {icon: markerIcon, title: photo.photo_title});

  if (photo.photo_title.length > 33) {
    photo.photo_title = photo.photo_title.substring(0, 33) + "&#8230;";
  }
  var html = "<div id='infowin' style='height:320px; width:240px;'>" +
            "<p><a href='http://www.panoramio.com/' target='_blank'>" + 
             "<img src='http://www.panoramio.com/img/logo-small.gif' border='0' width='119px' height='25px' alt='Panoramio logo' /><\/a></p>" +
             "<a id='photo_infowin' target='_blank' href='" + photo.photo_url + "'>" +                
             "<img border='0' width='" + photo.width + "' height='" + photo.height + "' src='" + photo.photo_file_url + "'/><\/a>" +
             "<div style='overflow: hidden; width: 240px;'>" +
             "<p><a target='_blank' class='photo_title' href='" + photo.photo_url +
             "'><strong>" + photo.photo_title + "<\/strong><\/a></p>" +
             "<p>Posted by <a target='_blank' href='" + photo.owner_url + "'>" +
             photo.owner_name + "<\/a></p><\/div>" +
             "<\/div>";
  marker.html = html;

  GEvent.addListener(marker, "click", function() {
	me.panoLayer.map.openInfoWindow(marker.getLatLng(), marker.html, {noCloseOnClick: true});
  });
 
  return marker;
}


function PanoramioLayer(map, opt_opts) {
	var me = this;
	me.map = map;
	me.ids = {};
	me.mgr = new MarkerManager(map, {maxZoom: 19});

	var icon = new GIcon();
	icon.image = "http://www.panoramio.com/img/panoramio-marker.png"; 
	icon.shadow = "";  
	icon.iconSize = new GSize(24, 24); 
	icon.shadowSize = new GSize(22, 22); 
	icon.iconAnchor = new GPoint(9, 9);  
	icon.infoWindowAnchor = new GPoint(9, 0); 

	me.markerIcon = icon;
	me.enabled = false;

	GEvent.addListener(map, "moveend", function() {
		if (me.enabled) {
			var bounds = map.getBounds();
			var southWest = bounds.getSouthWest();
			var northEast = bounds.getNorthEast();
			me.load(me, {maxy: northEast.lat(), miny: southWest.lat(), maxx: northEast.lng(), minx: southWest.lng()});
		}
	});
}

PanoramioLayer.prototype.enable = function() {
	this.enabled = true;
	GEvent.trigger(map, "moveend");
}

PanoramioLayer.prototype.disable = function() {
	this.enabled = false;
	this.mgr.clearMarkers();
	this.ids = {};
}

PanoramioLayer.prototype.getEnabled = function() {
	return this.enabled;
}

PanoramioLayer.prototype.load = function(panoLayer, userOptions) {
	var options = {
		order: "popularity",
		set: "public",
		from: "0",
		to: "10",
		minx: "-180",
		miny: "-90",
		maxx: "180",
		maxy: "90",
		size: "small"
	};
 
	for (optionName in userOptions) {
		if (userOptions.hasOwnProperty(optionName)) {
			options[optionName] = userOptions[optionName];
		}
	}
 
	var url = "http://www.panoramio.com/map/get_panoramas.php?";
	var uniqueID = "";
 
	for (optionName in options) {
		if (options.hasOwnProperty(optionName)) {
			var optionVal = "" + options[optionName] + "";
			url += optionName + "=" + optionVal + "&";
			uniqueID += optionVal.replace(/[^\w]+/g,"");
		}
	}
	
	var callbackName = "PanoramioLayerCallback.loader" + uniqueID; //ask dion
	eval(callbackName + " = function(json) { var pa = new PanoramioLayerCallback(json, panoLayer);}");
 
	var script = document.createElement('script');
	script.setAttribute('src', url + 'callback=' + callbackName);
	script.setAttribute('id', 'jsonScript');
	script.setAttribute('type', 'text/javascript');
	document.documentElement.firstChild.appendChild(script);
}

// SERVICE PANORAMIO //
function ZOOMBoutonControl() {}
ZOOMBoutonControl.prototype = new GControl();
ZOOMBoutonControl.prototype.initialize = function(MaCarte) {
	var containerZOOM = document.createElement('div');
	containerZOOM.style.backgroundImage = 'url("'+ BASEHREF + '/images/supportgmap.png")';
	containerZOOM.style.backgroundRepeat = 'no-repeat';
	containerZOOM.style.backgroundPosition = 'left';	
	containerZOOM.style.paddingTop = '5px';	
	containerZOOM.style.paddingBottom = '5px';	
	containerZOOM.style.paddingRight = '1px';	
	containerZOOM.style.paddingLeft = '30px';	
	containerZOOM.style.width = '40px';
	
	// Création du bouton [ Zoom + ]
	var boutonZoomPlus = document.createElement('div');
	this.setButtonStyle_Zoom_(boutonZoomPlus);
	containerZOOM.appendChild(boutonZoomPlus);
	boutonZoomPlus.style.backgroundImage = 'url("'+ BASEHREF + '/images/zoom_in.png")';
	GEvent.addDomListener(boutonZoomPlus, 'click', function() {
		MaCarte.zoomIn();
	});
	
	GEvent.addDomListener(boutonZoomPlus, 'mouseover', function() {
	});
	
	GEvent.addDomListener(boutonZoomPlus, 'mouseout', function() {
	});
		
	// Création du bouton [ Zoom - ]
	var boutonZoomMoins = document.createElement('div');
	this.setButtonStyle_Zoom_(boutonZoomMoins);
	containerZOOM.appendChild(boutonZoomMoins);
	boutonZoomMoins.style.backgroundImage = 'url("'+ BASEHREF + '/images/zoom_out.png")';
	GEvent.addDomListener(boutonZoomMoins, 'click', function() {
		MaCarte.zoomOut();
	});

	GEvent.addDomListener(boutonZoomMoins, 'mouseover', function() {});
	GEvent.addDomListener(boutonZoomMoins, 'mouseout', function() {});
		
	MaCarte.getContainer().appendChild(containerZOOM);
	return containerZOOM;
}

// Style des boutons [ Zoom ] de la carte
ZOOMBoutonControl.prototype.setButtonStyle_Zoom_ = function(button) {
	button.style.textAlign = 'center';
	button.style.display = 'block';
	button.style.width = '32px';
	button.style.height = '32px';
	button.style.cursor = 'pointer';
}

// Position des boutons [ Zoom ] de la carte : en haut à droite avec une marge de 0 pixels
ZOOMBoutonControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 7));
}

// Création des boutons [ PLAN ] - [ SATELLITE ] - [ MIXTE ] - [ RELIEF ] - [ PANORAMIO ]
function PSMBoutonControl() {}
PSMBoutonControl.prototype = new GControl();
PSMBoutonControl.prototype.initialize = function(MaCarte) {
	var containerPSM = document.createElement('div');
	// Création du bouton [ Plan ]
	var boutonPlan = document.createElement('div');
	this.setButtonStyle_PSM(boutonPlan);
	containerPSM.appendChild(boutonPlan);
	boutonPlan.appendChild(document.createTextNode('Plan'));
	GEvent.addDomListener(boutonPlan, 'click', function() {
		MaCarte.setMapType(G_NORMAL_MAP);
	});
	
	GEvent.addDomListener(boutonPlan, 'mouseover', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn_hover.png")';
	});
	
	GEvent.addDomListener(boutonPlan, 'mouseout', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn.png")';
	});
		
	// Création du bouton [ Satellite ]
	var boutonSatellite = document.createElement('div');
	this.setButtonStyle_PSM(boutonSatellite);
	containerPSM.appendChild(boutonSatellite);
	boutonSatellite.appendChild(document.createTextNode('Satellite'));
	GEvent.addDomListener(boutonSatellite, 'click', function() {
		MaCarte.setMapType(G_SATELLITE_MAP);
	});

	GEvent.addDomListener(boutonSatellite, 'mouseover', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn_hover.png")';
	});
	
	GEvent.addDomListener(boutonSatellite, 'mouseout', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn.png")';
	});
	
	// Création du bouton [ Mixte ]
	var boutonMixte = document.createElement('div');
	this.setButtonStyle_PSM(boutonMixte);
	containerPSM.appendChild(boutonMixte);
	boutonMixte.appendChild(document.createTextNode('Mixte'));
	GEvent.addDomListener(boutonMixte, 'click', function() {
		MaCarte.setMapType(G_HYBRID_MAP);
	});
	
	GEvent.addDomListener(boutonMixte, 'mouseover', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn_hover.png")';
	});
	
	GEvent.addDomListener(boutonMixte, 'mouseout', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn.png")';
	});
	
	// Création du bouton [ Relief ]
	var boutonRelief = document.createElement('div');
	this.setButtonStyle_PSM(boutonRelief);
	containerPSM.appendChild(boutonRelief);
	boutonRelief.appendChild(document.createTextNode('Relief'));
	GEvent.addDomListener(boutonRelief, 'click', function() {
		MaCarte.setMapType(G_PHYSICAL_MAP);
	});
	GEvent.addDomListener(boutonRelief, 'mouseover', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn_hover.png")';
	});
	GEvent.addDomListener(boutonRelief, 'mouseout', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn.png")';
	});
	
	// Création du bouton [ Panoramio ]
	var boutonMixte = document.createElement('div');
	this.setButtonStyle_PSM(boutonMixte);
	containerPSM.appendChild(boutonMixte);
	boutonMixte.appendChild(document.createTextNode('Panoramio'));
	GEvent.addDomListener(boutonMixte, 'click', function() {
		if (this.panoLayer) {
			if (this.panoLayer.getEnabled()) {
				this.panoLayer.disable();
			} else {
				this.panoLayer.enable();
			}
		} else {
			this.panoLayer = new PanoramioLayer(map);
			this.panoLayer.enable();
		}
	});
	GEvent.addDomListener(boutonMixte, 'mouseover', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn_hover.png")';
	});
	GEvent.addDomListener(boutonMixte, 'mouseout', function() {
		this.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn.png")';
	});

	MaCarte.getContainer().appendChild(containerPSM);
	return containerPSM;
}

// Style des boutons [ Plan ] - [ Satellite ] - [ Mixte ] de la carte
PSMBoutonControl.prototype.setButtonStyle_PSM = function(button) {
	button.style.textDecoration = 'none';
	button.style.color = '#ffffff';
	button.style.font = '13px Arial';
	button.style.padding = '0px';
	button.style.marginBottom = '0px';
	button.style.lineHeight = '24px';
	button.style.textAlign = 'center';
	button.style.width = '100px';
	button.style.height = '24px';
	button.style.cursor = 'pointer';
	button.style.backgroundImage = 'url("'+ BASEHREF + '/images/fondgmap_btn.png")';
	button.style.backgroundRepeat = 'no-repeat';
	button.style.backgroundPosition = 'center';
}
		
// Position des boutons [ Plan ] - [ Satellite ] - [ Mixte ] de la carte : en haut à gauche avec une marge de 7 pixels
PSMBoutonControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}

// Affichage des services dans la zone indiquée
var chargeServices = function (lat,lng,prox,checktab,zoom){
	var script = document.createElement('script');
	script.src = 'http://www.keltoa.com/testg/sites_template_data_cat.php?prox='+prox+'&lat='+lat+'&lng='+lng+'&checktab='+checktab;
	script.type = 'text/javascript';
	document.body.appendChild(script);
	cm_getJSON(lat,lng,prox);
};

var gestionRetour = function (str){
	document.getElementById('sidebarDIV').innerHTML = str;
};

var gestionErreur = function (){
	document.getElementById('sidebarDIV').innerHTML = 'Service indisponible ou défaillant';
};

// Gestion Map
var map, checktab = ',', toggleState = new Array(), marker = null, mapMarkers = [], mapMeservices = new Array(), mapHTMLS = [], bounds = new GLatLngBounds(), togglePano = 0;

function toggleMyPano() {
	if (togglePano == 1) {
		var pano_layer = new PanoramioLayer(map);
		pano_layer.enable(false);
		togglePano = 0;
	} else {
		var pano_layer = new PanoramioLayer(map);
		pano_layer.enable();
		togglePano = 1;
	}
}
	  
var cm_baseIcon = new GIcon();
cm_baseIcon.iconSize = new GSize(34, 34);
cm_baseIcon.iconAnchor = new GPoint(9, 34);
cm_baseIcon.infoWindowAnchor = new GPoint(9, 2);

var param_useSidebar = true;
var param_titleColumn = "title";
var param_descriptionColumn = "description";
var param_latColumn = "latitude";
var param_lngColumn = "longitude";
var param_idserviceColumn = "idservice";

// GALERIE PANORAMIO
function jsonpanoramio(url) {
	var jstag=document.createElement("script");
    jstag.setAttribute("type", "text/javascript");
    jstag.setAttribute("src", url);
    document.getElementsByTagName("head")[0].appendChild(jstag);
}

function traitephotos(datos) {
    var fotos = datos['photos'];
    for(var i=0;i<20;i++) {
		var url = fotos[i]['photo_file_url'];
        var miimagen = new Image();
        miimagen.src = url;
        $('jsonphotospanoramio').appendChild(miimagen);
	}
}

function detail_service(markerNum) {
	mapMarkers[markerNum].openInfoWindowHtml(mapHTMLS[markerNum]);
}

function close_detail_service(markerNum) {
	mapMarkers[markerNum].closeInfoWindow(mapHTMLS[markerNum]);
}

function togglemarkers(idservice) {
	if (toggleState[idservice] == 1) {
		for (var i=mapMeservices[idservice][0]; i<mapMeservices[idservice][0]+mapMeservices[idservice].length; i++) {
			mapMarkers[i].hide();
		}
		toggleState[idservice] = 0;
	} else {
		for (var i=mapMeservices[idservice][0]; i<mapMeservices[idservice][0]+mapMeservices[idservice].length; i++) {
			mapMarkers[i].show();
		}
		toggleState[idservice] = 1;
	}
} 

function cm_loadMapJSON(json) {
	for (var i = 0; i < json.feed.entry.length; i++) {
	var entry = json.feed.entry[i];
		if(entry["gsx$" + param_latColumn]) {
			var lat = parseFloat(entry["gsx$" + param_latColumn].$t);
			var lng = parseFloat(entry["gsx$" + param_lngColumn].$t);
			var point = new GLatLng(lat,lng);
			var html = "<div style='font-size:12px;'>";
			html += "<strong>" + entry["gsx$"+param_titleColumn].$t + "</strong>";
			var label = entry["gsx$"+param_titleColumn].$t;
			var idservice = parseFloat(entry["gsx$idservice"].$t);

			if(entry["gsx$" + param_descriptionColumn]) {
				html += "<br/>" + entry["gsx$"+param_descriptionColumn].$t;
			}
			html += "</div>";
			
			var marker = cm_createMarker(point,label,html,idservice);
			map.addOverlay(marker);
      			mapMarkers[i] = marker;
			mapHTMLS[i] = html;

			bounds.extend(point);

			mapMeservices[idservice].push(i);	
      		if(toggleState[idservice]=="0"){
      			mapMarkers[i].hide();
      		}
		}
	}

	map.setZoom(map.getBoundsZoomLevel(bounds));
	map.setCenter(bounds.getCenter());

	var bounds2 = map.getBounds();
	var southWest = bounds2.getSouthWest();
	var northEast = bounds2.getNorthEast();
	
	var maxy = northEast.lat();
	var miny = southWest.lat();
	var maxx = northEast.lng();
	var minx = southWest.lng();
}

function cm_createMarker(point, title, html, idservice) {
	var label1 = 'D&eacute;tail';
	var markerOpts = {};
	var nIcon = new GIcon(cm_baseIcon);
	
	nIcon.image = "http://www.keltoa.com/testg/markers/"+idservice+".png";
	
	markerOpts.icon = nIcon;
	markerOpts.title = title;		 
	var marker = new GMarker(point, markerOpts);
	
	marker.idservice = idservice;
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,html)]);
	});
	
	return marker;
}

function createMarker_client(point, title, html ) {
	var label1 = 'D&eacute;tail';
	var markerOpts = {};
	var nIcon = new GIcon(cm_baseIcon);
	nIcon.image = "arebat.png";
	markerOpts.icon = nIcon;
	markerOpts.title = title;		 
	var marker = new GMarker(point, markerOpts);
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,html)]);
	});
	return marker;
}

function cm_getJSON(lat,lng,prox) {
	var scriptjson = document.createElement('script');
	scriptjson.setAttribute('src', 'http://www.keltoa.com/testg/sites_clients_data_json.php?lat='+lat+'&lng='+lng+'&prox='+prox);
	scriptjson.setAttribute('id', 'jsonScript');
	scriptjson.setAttribute('type', 'text/javascript');
	document.documentElement.firstChild.appendChild(scriptjson);
}
*/
function roundAt(nombre,decimale){
	var mult = Math.pow(10,parseInt(decimale));
	return Math.floor(nombre*mult)/mult;
}

function addE(e,obj,func){
	if (obj.addEventListener){
		obj.addEventListener(e,func, false);
	} else if (obj.attachEvent) {
		obj.attachEvent('on'+e,func);
	}	
}
		
function format(x,type) {
	if (x==0) {
		return x;
	} else {
		var str = x.toString(), n = str.length;
		if (n <4) {
			return x;
		} else {
			return ((n % 3) ? str.substr(0, n % 3) + ' ' : '') + str.substr(n % 3).match(new RegExp('[0-9]{3}', 'g')).join(' ');
		}
	}
}


// Fonction du menu Newsletters
function ac_villes_alert(){
	new Ajax.Autocompleter('ville-newsletter','ouville',BASEHREF + '/fonctions/ac_villes_alertemail.php',
		{
		method: 'post',
		paramName: 'ville',
		minChars: 2,
		afterUpdateElement: ac_return_ville 
		}
	);
}

function ac_return_ville(field, item){
	var regex = new RegExp('[0123456789]*_optionville', 'i');
	var nomimage = regex.exec($(item).innerHTML);
	id = nomimage[0].replace('_optionville', '');
	field.name = field.name.replace('_ville', '');
	$('idville').value = id;

	var regex = new RegExp('[0123456789]*_cpville', 'i');
	var nomimage = regex.exec($(item).innerHTML);
	cp = nomimage[0].replace('_cpville', '');
	field.name = field.name.replace('_ville', '');

	var j = getAgenceInfos($('idville').value,'agence','agenceprox');
}

function getAgenceInfos(idville,idtou,nametou){
	var url = BASEHREF + '/xmlrpcnet.php';
	var pars = 'mode=agence_infos&idville='+idville;	
	var aj = new Ajax.Request(url, {method:'get', parameters: pars,
		onSuccess: function(transport){
			myJson = transport.responseText.evalJSON();			
			$(idtou).value = myJson.id;
			$(nametou).innerHTML = '<div style="background-color:#eee;">Votre demande va &ecirc;tre transmise &agrave; l\'espace conseil Immo du Particulier <b>'+myJson.name+'</b></div>';
		}
	});		
}


// Fonction du menu Newsletters
function sauve_newsletter(){
	var flag = true;
	if($('email-newsletter').value.length == 0) {
		flag = false;
		alert("Votre adresse email est obligatoire !");
	}
	
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if(!reg.test($('email-newsletter').value) && flag == true) {
		flag = false;
		alert("Votre adresse email est invalide !");
	}

	if(flag){
		var url = BASEHREF + '/xmlrpcnet.php';
		var pars = 'mode=sauve_newsletter&'+Form.serialize('formulaire_newsletter');
		var target = 'sauve_newsletter_ok';	
		var myAjax = new Ajax.Updater(target, url,{
			method: 'get', parameters: pars});
	}
}
 
function chargeannonces(){
	var url = BASEHREF + '/xmlrpcnet.php?mode=chargeannonces';
	var pars =	Form.serialize('recherche_form');
	var target	= 'resultat_recherche';	
	var myAjax = new Ajax.Updater(target, url, {
        onComplete:function(request){
			Effect.Appear(target, {duration:1, from:0.5, to:1.0})
		},
		parameters: pars
	});
}


function chargelocations(){
	var url = BASEHREF + '/xmlrpcnet.php?mode=chargelocations';
	var pars =	Form.serialize('recherche_form');
	var target	= 'sousgauche';	
	var myAjax = new Ajax.Updater(target, url, {
        onComplete:function(request){
			Effect.Appear(target, {duration:1, from:0.5, to:1.0})
		},
		parameters: pars
	});
}

function send_contact(){

	var flag = true;
	if($('nom').value == "" && flag == true) {
		flag = false;
		alert("Votre nom est obligatoire !");
	}

	
	if($('email').value == ""  && flag == true) {
		flag = false;
		alert("Votre adresse email est obligatoire !");
	}
	
	reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if(!reg.test($('email').value) && flag == true) {
		flag = false;
		alert("Votre adresse email est invalide !");
	}
	
	if($('nom').value == "" && flag == true) {
		flag = false;
		alert("Votre nom est obligatoire !");
	}
	
	if($('message').value == "" && flag == true) {
		flag = false;
		alert("Votre message est obligatoire !");
	}
	
	
	if(flag) {
		var url = BASEHREF + '/xmlrpcnet.php';
		var pars =	'mode=send_contact&'+Form.serialize('form_contact');
		var target	= 'espace_contact';	
		var myAjax	= new Ajax.Updater(target, url,	{
			method: 'get', 
			parameters: pars
		});
	}
}

// Fonction du menu Biens
function send_demandedinformations(){
	var flag = true;
	if($('DI_nom').value.length == 0) {
		flag = false;
		alert('Le champ nom est obligatoire');
	}
	var reg = new RegExp('^[0-9 \-]+$', 'i');
	if(!reg.test($('DI_tel').value) && flag == true) {
		flag = false;
		alert('Votre téléphone est invalide');
	}	
	
	reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
	
	if(!reg.test($('DI_email').value) && flag == true) {
		flag = false;
		alert('Votre adresse email est invalide');
	}
	if($('DI_msg').value.length == 0) {
		flag = false;
		alert('Le champ message est obligatoire');
	}
	if(flag) {
		var url = BASEHREF + '/xmlrpcnet.php';
		var pars =	'mode=send_demandedinformations&'+Form.serialize('formulaire_demandedinformations');
		var target	= 'tab_demandedinformations';	
		var myAjax	= new Ajax.Updater(target, url,	{
			method: 'get',
			parameters: pars
		});
	}
}

// Fonction du menu Biens
function send_sefairerappeler(){
	var url = BASEHREF + '/xmlrpcnet.php';
	var pars =	'mode=send_sefairerappeler&'+Form.serialize('formulaire_sefairerappeler');
	var target	= 'tab_sefairerappeler';	
	var myAjax	= new Ajax.Updater(target, url,	{
		method: 'get', 
		parameters: pars
	});
}

// Fonction pour le formulaire
function changeTypeFormulaire() {
var url = BASEHREF + '/xmlrpcnet.php';
	var pars =	'mode=changeTypeFormulaire&'+Form.serialize('recherche_form');
	var target	= 'formulairerecherchebien';	
	var myAjax	= new Ajax.Updater(target, url,	{
		method: 'get', 
		parameters: pars
	});
}

// Fonction du menu Estimation
function send_estimation(){
	var flag = true;
	if($('nom').value == "" && flag == true) {
		flag = false;
		alert("Votre nom est obligatoire !");
	}
	if($('tel').value == "" && flag == true) {
		flag = false;
		alert("Votre téléphone est obligatoire !");
	}
	
	var reg = new RegExp('^[0-9 \-]+$', 'i');
	if(!reg.test($('tel').value) && flag == true) {
		flag = false;
		alert("Votre téléphone est invalide !");
	}
	
	if($('email').value == ""  && flag == true) {
		flag = false;
		alert("Votre adresse email est obligatoire !");
	}
	
	reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if(!reg.test($('email').value) && flag == true) {
		flag = false;
		alert("Votre adresse email est invalide !");
	}
	
	if(flag) {
		var url = BASEHREF + '/xmlrpcnet.php';
		var pars =	'mode=send_estimation&'+Form.serialize('formulaire_estimation');
		var target	= 'tab_estimation';	
		var myAjax	= new Ajax.Updater(target, url,	{
			method: 'get', 
			parameters: pars
		});
	}
}


// Fonction du menu Alerte Mail
function sauve_alertemail(){
	var flag = true;
	
	if($('nomcont').value=="" && flag == true) {
		flag=false;
		alert("Votre nom est obligatoire !");
	}
	
	if($('prenomcont').value=="" && flag == true) {
		flag=false;
		alert("Votre prénom est obligatoire !");
	}
	
	if($('emailcont').value=="" && flag == true) {
		flag=false;
		alert("Votre adresse email est obligatoire !");
	}
	
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if(!reg.test($('emailcont').value) && flag == true) {
		flag = false;
		alert("Votre adresse email est invalide !");
	}
	
	if($('telcont').value=="" && flag == true) {
		flag=false;
		alert("Votre téléphone est obligatoire !");
	}
	
	reg = new RegExp('^[0-9 \-]+$', 'i');
	if(!reg.test($('telcont').value) && flag == true) {
		flag = false;
		alert("Votre téléphone est invalide !");
	}

	if (flag) {
		var url = BASEHREF + '/xmlrpcnet.php';
		var pars = 'mode=sauve_alertemail&'+Form.serialize('formulaire_alertemail');
		var target = 'formalerte';	
		var myAjax = new Ajax.Updater(target, url,{
			method: 'get',
			parameters: pars
		});
	}
}

// Pour la classe Coups de coeur
function updatemyann(id){
	flagCoupsCoeur = false;
	//on remplace par notre loader
	var exc = new Array();
	if($('annc1') != null ) exc[0] = $('annc1').value; else return true;
	var i;
	for(i=2; i<= COUPSCOEUR_NB_IMAGES; i++) {
		if($('annc'+i)) {
			exc[i-1] = $('annc'+i).value;
		}
	}		
	
	if($("coeur"+id)) {
			

		var url = BASEHREF + '/xmlrpcnet.php';		
		var target	= 'coeur'+id;		
		var pars =	'mode=random_ann&num='+id+'&exc='+exc;

		var myAjax	= new Ajax.Request(url, {
			method: 'get',
			parameters: pars, 
			onComplete: function(t){
				flagCoupsCoeur = true; 
				var len = t.responseText.length;
				if(t.responseText.substr(len - 4,4 )!= "none") {
					$(target).innerHTML = t.responseText;
				}
			}
		});
	} else {
		flagCoupsCoeur = true;
	}
}
	
var idcoupscoeur = 1;
	
function myupdater(){
	a = new PeriodicalExecuter(function(){
		if(flagCoupsCoeur) {				
			if(idcoupscoeur > COUPSCOEUR_NB_IMAGES) {
				if( idcoupscoeur > COUPSCOEUR_NB_IMAGES + 1 ) {
					idcoupscoeur = 0;
				}
			} else {
				updatemyann(idcoupscoeur);		
			}
			idcoupscoeur++;
		}
	},5);
}

/*
function send_recorder(){
	var url = BASEHREF + '/xmlrpc.php';
	var pars =	'mode=send_recorder&'+Form.serialize('formulaire_enregistrer');
	var target	= 'tab_enregistrer';	
	var myAjax	= new Ajax.Updater(target, url,	{
		method: 'get',
		parameters: pars
	});
}

function send_contacteznous(){
	var url = BASEHREF + '/xmlrpc.php';
	var pars =	'mode=send_contacteznous&'+Form.serialize('formulaire_contacteznous');
	var target	= 'tab_contacteznous';	
	var myAjax	= new Ajax.Updater(target, url,	{
		method: 'get',
		parameters: pars
	});
}

function chargecarroussel(p){
	var url = BASEHREF + '/xmlrpc.php';
	var pars =	'mode=chargecarroussel&p='+p;
	var target	= 'carroussel';	

	var myAjax = new Ajax.Updater(target, url, {
		onComplete:function(request){
			Effect.Appear('carroussel', {duration:1, from:0.5, to:1.0})
		},
	    method: 'get',
		parameters: pars
	});
}
*/

