var Inscription = function() {
};
Inscription.prototype.changeRegion = function(idPays) {
	appelAjax('inscription/change-region', 'pays=' + idPays, 2,
			inscription.changeRegionSuccess, [ idPays ]);
}
Inscription.prototype.changeRegionSuccess = function(xhr, idPays) {
	$('inscription_region_div').innerHTML = xhr.responseText;
	$('departement').value=0;
	masque('departement_div');
}
Inscription.prototype.changeDepartement = function(idPays, idRegion) {
	var param = 'pays=' + idPays + '&region=' + idRegion;
	appelAjax('inscription/change-departement', param, 2,
			inscription.changeDepartementSuccess);
}
Inscription.prototype.changeDepartementSuccess = function(xhr) {
	if (xhr.responseText != '') {
		$('inscription_departement_div').innerHTML = xhr.responseText;
		if ($('departement').length != 1) {
			afficheSimple('departement_div', 'block');
		} else {
			masque('departement_div');
		}
	}
}
Inscription.prototype.verifiePseudo = function() {
	if (_('inscription_pseudo').value != '') {
		var param = 'pseudo=' + _('inscription_pseudo').value;
		appelAjax('inscription/verifie-pseudo', param, 2,
				inscription.verifiePseudoSuccess);
	}
}
Inscription.prototype.verifiePseudoSuccess = function(xhr) {
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		var descriptionStatut = reponseXML.getElementsByTagName(
				'descriptionStatut').item(0).firstChild.nodeValue;
		var zone = 'pseudo';
		if (statut == 'KO') {
			_('info_inscription_' + zone).innerHTML = '';
			_('erreur_inscription_' + zone).innerHTML = descriptionStatut;
		} else if (statut == 'OK') {
			_('erreur_inscription_' + zone).innerHTML = '';
			_('info_inscription_' + zone).innerHTML = descriptionStatut;
		}
	} else {
		erreur.envoyer(xhr.responseText);
	}
}
var inscription = new Inscription();

var m_localisationDirectSuccess = 0;
var Depot = function() {
};
Depot.prototype.changeRegion = function(idPays) {
	if (idPays !=0) {
		appelAjax('depot/change-region', 'pays=' + idPays, 2,
			depot.changeRegionSuccess, [ idPays ]);
	} else {
		$('depot_region').value = 0;
		$('depot_departement').value = 0;
		$('erreur_depot_region').innerHTML = '';
		$('erreur_depot_departement').innerHTML = '';
		masque('region');
		masque('regionError');
		masque('departement');
		masque('departementError');
	}
}
Depot.prototype.changeRegionSuccess = function(xhr, idPays) {
	if (xhr.responseText != '') {
		_('depot_region_div').innerHTML = xhr.responseText;
		afficheSimple('region','block');
		masque('depot_departement');
	}
}
Depot.prototype.changeDepartement = function(idPays, idRegion) {
	if (idPays !=0 && idRegion !=0) {
		var param = 'pays=' + idPays + '&region=' + idRegion;
		appelAjax('depot/change-departement', param, 2,
			depot.changeDepartementSuccess);
	} else {
		$('depot_departement').value = 0;
		$('erreur_depot_departement').innerHTML = '';
		masque('departement');
		masque('departementError');
	}
}
Depot.prototype.changeDepartementSuccess = function(xhr) {
	if (xhr.responseText != '') {
		_('depot_departement_div').innerHTML = xhr.responseText;
		if (_('depot_departement').length != 1) {
			afficheSimple('departement', 'block');
		} else {
			masque('departement');
		}
	}
}
Depot.prototype.changeSousCategorie = function(idCategorie) {
	var param = 'type='+ _('depot_type').value + '&categorie=' + idCategorie;
	appelAjax('depot/change-sous-categorie', param, 2,
			depot.changeSousCategorieSuccess);
}
Depot.prototype.changeSousCategorieSuccess = function(xhr) {
	
	if (xhr.responseText != '') {
		var div_sousCategorie = _('depot_souscategorie_div');
		div_sousCategorie.innerHTML = xhr.responseText;
	} else {
		masque('depot_souscategorie_div');
	}
}
Depot.prototype.supprimePhoto = function(idUpload) {
	if ($('depot_modif').value == 'true') {
		var param = 'pays=' + $('depot_pays').value + '&idupload=' + idUpload + '&modif=true' + '&cle='
				+ $('depot_clemodif').value;
	} else {
		var param = 'pays=' + $('depot_pays').value + '&idupload=' + idUpload + '&modif=false';
	}
	$('depot_principal').className = 'cursorLoad';
	stopObserveDepot();
	appelAjax('depot/supprime-upload', param, 2, depot.supprimePhotoSuccess,
			[ idUpload ]);
}
Depot.prototype.supprimePhotoSuccess = function(xhr, idUpload) {
	_('depot_principal').className = 'cursorNormal';
	observeDepot();
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		if (statut == 'OK') {
			masque('depot_photo' + idUpload);
			m_idUploadSupprime[m_idUploadSupprime.length] = idUpload;
			m_idUploadSupprime.sort();
		}
	} else {
		erreur.envoyer(xhr.responseText);
	}
}
Depot.prototype.rotatePhoto = function(idUpload,sens) {
	if ($('depot_modif').value == 'true') {
		var param = 'pays=' + $('depot_pays').value + '&idupload=' + idUpload + '&sens=' + sens + '&modif=true' + '&cle='
				+ $('depot_clemodif').value;
	} else {
		var param = 'pays=' + $('depot_pays').value + '&idupload=' + idUpload + '&sens=' + sens + '&modif=false';
	}
	$('depot_principal').className = 'cursorLoad';
	stopObserveDepot();
	appelAjax('depot/rotate-upload', param, 2, depot.rotatePhotoSuccess,
			[ idUpload ]);
}
Depot.prototype.rotatePhotoSuccess = function(xhr, idUpload) {
	_('depot_principal').className = 'cursorNormal';
	observeDepot();
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		if (statut == 'OK') {
			// Pour changer le timestamp de la photo
			_('depot_miniature' + idUpload).src = _('depot_miniature' + idUpload).src + '?c';
		}
	} else {
		erreur.envoyer(xhr.responseText);
	}
}
Depot.prototype.trouveAdresse = function() {
	stopObserveDepot();
		// Si une des valeurs a changé, on prépare l'adresse
		if ((_('depot_rue').value != _('depot_rue_depart').value)
				|| (_('depot_ville').value != _('depot_ville_depart').value)
				|| (_('depot_codepostal').value != _('depot_codepostal_depart').value)) {
			depot.prepareAdress('direct');
		} else {
			document.forms['depot_principal'].submit();
		}
}
Depot.prototype.prepareAdress = function(mode) {
	var param = 'pays=' + Url.encode(_('depot_pays').value) + '&'
			+ 'codepostal=' + Url.encode(_('depot_codepostal').value) + '&'
			+ 'ville=' + Url.encode(_('depot_ville').value) + '&' + 'rue='
			+ Url.encode(_('depot_rue').value);
	appelAjax('depot/prepare-adress', param, 2, depot.prepareAdressSuccess,
			[ mode ]);
}
Depot.prototype.prepareAdressSansRue = function(mode) {
	var param = 'pays=' + Url.encode(_('depot_pays').value) + '&'
			+ 'codepostal=' + Url.encode(_('depot_codepostal').value) + '&'
			+ 'ville=' + Url.encode(_('depot_ville').value) + '&' + 'rue=';
	appelAjax('depot/prepare-adress', param, 2, depot.prepareAdressSuccess,
			[ mode ]);
}
Depot.prototype.prepareAdressSansVille = function(mode) {
	var param = 'pays=' + Url.encode(_('depot_pays').value) + '&'
			+ 'codepostal=' + Url.encode(_('depot_codepostal').value) + '&'
			+ 'ville=' + '&' + 'rue=';
	appelAjax('depot/prepare-adress', param, 2, depot.prepareAdressSuccess,
			[ mode ]);
}
Depot.prototype.prepareAdressSuccess = function(xhr, mode) {
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('adress').item(0);
		if (element) {
			var address = element.firstChild.nodeValue;
			if (mode == 'direct') {
				depot.geolocaliseDirect(address);
			} else {
				depot.geolocalise(address);
			}
		}
	} else {
		erreur.envoyer(xhr.responseText);
		return false;
	}
}
// Géolocalise l'adresse directement sans afficher la carte
Depot.prototype.geolocaliseDirect = function(address) {
	if (GBrowserIsCompatible()) {
		var geocoder = new GClientGeocoder();
		if (geocoder) {
			geocoder.getLocations(address, depot.geolocalisationDirectSuccess);
		}
	}
}
Depot.prototype.geolocalisationDirectSuccess = function(response) {
	if (!response || response.Status.code != 200) {
		m_localisationDirectSuccess += 1;
		if (m_localisationDirectSuccess == 1) {
			// Localisation non trouvée, on recherche sans la rue
			depot.prepareAdressSansRue('direct');
			return false;
		} else if (m_localisationDirectSuccess == 2) {
			// Encore non trouvé, on recherche sans la rue ni la ville
			depot.prepareAdressSansVille('direct');
			return false;
		} else {
			// On poste qd même le formulaire
			document.forms['depot_principal'].submit();
		}
	} else if (response && response.Status.code == 200) {
		var place = response.Placemark[0];
		_("depot_longitude").value = place.Point.coordinates[0];
		_("depot_latitude").value = place.Point.coordinates[1];
		_("depot_adressePropre").value = place.address;
		_("depot_zoomCarte").value = zoomCarte;
		m_localisationDirectSuccess = 0;
		// On poste le formulaire
		// le faire avant pour le cas où ne trouve vraiment rien
		document.forms['depot_principal'].submit();
	} else {
		// On poste qd même le formulaire
		document.forms['depot_principal'].submit();
	}
}
Depot.prototype.geolocalise = function(address) {
	if (GBrowserIsCompatible()) {
		var geocoder = new GClientGeocoder();
		if (geocoder) {
			geocoder.getLocations(address, depot.geolocalisationSuccess);
		}
	}
}
Depot.prototype.geolocalisationSuccess = function(response) {
	if (!response || response.Status.code != 200) {
		alert(m_adresse_nontrouve);
	} else if (response && response.Status.code == 200) {
		affichePosition('carteAnnonce', 'visible', decalageTop1);
		map = new GMap2(_('mapAnnonce'));
		map.addControl(new GOverviewMapControl());
		map.addControl(new GLargeMapControl());
		map.clearOverlays();

		var place = response.Placemark[0];
		_("depot_longitude").value = place.Point.coordinates[0];
		_("depot_latitude").value = place.Point.coordinates[1];
		_("depot_adressePropre").value = place.address;
		_("depot_adressePropreLibelle").innerHTML = place.address;
		_('depot_modifierAdresseLien').className = '';
		_("depot_zoomCarte").value = zoomCarte;

		var point = new GLatLng(place.Point.coordinates[1],
				place.Point.coordinates[0]);
		map.setCenter(point, zoomCarte);
		var marker = new GMarker(point, {
			draggable :true
		});
		map.addOverlay(marker);

		marker.openInfoWindowHtml('<span class="infoMap">'
				+ place.address
				+ '</span>');

		GEvent.addListener(map, "click", function(overlay, latlng) {
			if (latlng) {
				// var myHtml = "The GPoint value is: " +
				// map.fromLatLngToDivPixel(latlng) + " at zoom level " +
				// map.getZoom();
				// map.openInfoWindow(latlng, myHtml);

				map.clearOverlays();
				marker = new GMarker(latlng, {
					draggable :true
				});
				map.addOverlay(marker);

				GEvent.addListener(marker, 'dragend', function(point) {
					position = marker.getPoint();
					latitudeCarteClick = position.lat();
					longitudeCarteClick = position.lng();
					_("depot_latitude").value = latitudeCarteClick;
					_("depot_longitude").value = longitudeCarteClick;
					_("depot_zoomCarte").value = map.getZoom();
					recentrerCarte(latitudeCarteClick, longitudeCarteClick);
				});

				_("depot_latitude").value = marker.getPoint().lat();
				_("depot_longitude").value = marker.getPoint().lng();
				_("depot_zoomCarte").value = map.getZoom();
			}
		});

		GEvent.addListener(marker, 'dragend', function(point) {
			position = marker.getPoint();
			latitudeCarteClick = position.lat();
			longitudeCarteClick = position.lng();
			_("depot_latitude").value = latitudeCarteClick;
			_("depot_longitude").value = longitudeCarteClick;
			_("depot_zoomCarte").value = map.getZoom();
			recentrerCarte(latitudeCarteClick, longitudeCarteClick);
		});

		GEvent.addListener(map, 'zoomend', function(point) {
			_("depot_zoomCarte").value = map.getZoom();
		});

	} else {
		masque('carteAnnonce');
	}
} 
var depot = new Depot();

var Recherche = function() {
};
Recherche.prototype.changeCategorie = function (p_idCategorie) {
	if (p_idCategorie !=0) {
		
	}
}
Recherche.prototype.changeDepartement = function(p_idPays, p_idRegion) {
	if (p_idRegion !=0) {
		var param = 'pays=' + p_idPays + '&region=' + p_idRegion;
		appelAjax('recherche/change-departement', param, 2,
			recherche.changeDepartementSuccess);
	} else {
		masque('recherche_departement_div');
		masque('recherche_codepostal_div');
		if (_('departement')) _('departement').value = 0;
		if (_('codepostal')) _('codepostal').value = '';
	}
}
Recherche.prototype.changeDepartementSuccess = function(xhr) {
	if (xhr.responseText != '') {
		_('recherche_departement_div').innerHTML = xhr.responseText;
		afficheSimple('recherche_departement_div','inline');
	}
	focus('mots');
}
Recherche.prototype.afficheCodePostal = function (p_idDepartement) {
	if (p_idDepartement!=0) {
		afficheSimple('recherche_codepostal_div','inline');
	} else {
		masque('recherche_codepostal_div');
	}
	focus('mots');
}
Recherche.prototype.changePage = function(idPage) {
	_('page').value = idPage;
	document.forms['recherche'].submit();
}
var recherche = new Recherche();

var Alerte = function() {
};
Alerte.prototype.changeCategorie = function (p_type) {
	if (_('categorie')) {
		_('categorie').value = 0;
	}
	if (_('souscategorie')) {
		_('souscategorie').value = 0;
	}
	if (p_type !=0) {
		masque('alerte_sous_categorie_div');
		var param = 'type=' + p_type;
		appelAjax('moncompte/change-categorie', param, 2,
			alerte.changeCategorieSuccess);
	} else {
		masque('categorie_tr');
	}
}
Alerte.prototype.changeCategorieSuccess = function (xhr) {
	if (xhr.responseText != '') {
		_('alerte_categorie_div').innerHTML = xhr.responseText;
		afficheSimple('categorie_tr','table-row');
	} else {
		//rien
	}
}
Alerte.prototype.changeSousCategorie = function (p_idCategorie) {
	if (p_idCategorie !=0) {
		var param = 'type=' + _('type').value + '&categorie=' + p_idCategorie;
		appelAjax('moncompte/change-sous-categorie', param, 2,
			alerte.changeSousCategorieSuccess);
	} else {
		_('souscategorie').value = 0;
		masque('alerte_sous_categorie_div');
	}
}
Alerte.prototype.changeSousCategorieSuccess = function (xhr) {
	if (xhr.responseText != '') {
		_('alerte_sous_categorie_div').innerHTML = xhr.responseText;
		afficheSimple('alerte_sous_categorie_div','inline');
	} else {
		masque('alerte_sous_categorie_div');
	}
}
Alerte.prototype.changeRegion = function(idPays) {
	appelAjax('moncompte/change-region', 'pays=' + idPays, 2,
			alerte.changeRegionSuccess);
}
Alerte.prototype.changeRegionSuccess = function(xhr) {
	if (xhr.responseText != '') {
		_('alerte_region_div').innerHTML = xhr.responseText;
		afficheSimple('alerte_region_tr','table-row');
		masque('departement_tr');
		_('departement').value=0;
	} else {
		//
	}
}
Alerte.prototype.changeDepartement = function(p_idPays, p_idRegion) {
	if (p_idRegion !=0) {
		var param = 'pays=' + p_idPays + '&region=' + p_idRegion;
		appelAjax('moncompte/change-departement', param, 2,
			alerte.changeDepartementSuccess);
	} else {
		_('departement').value = 0;
		_('codepostal').value = '';
		masque('departement');
		masque('codepostal_div');
	}
}
Alerte.prototype.changeDepartementSuccess = function(xhr) {
	if (xhr.responseText != '') {
		_('alerte_departement_div').innerHTML = xhr.responseText;
		afficheSimple('alerte_departement_div','inline');
		afficheSimple('departement_tr','table-row');
	}
}
Alerte.prototype.afficheCodePostal = function (p_idDepartement) {
	if (p_idDepartement!=0) {
		afficheSimple('codepostal_tr','table-row');
	} else {
		masque('codepostal_tr');
	}
}
var alerte = new Alerte();

var Login = function() {
};
Login.prototype.logout = function() {
	appelAjax('login/logout', '', 2, login.logoutSuccess);
}
Login.prototype.logoutSuccess = function() {
	window.location='/';
}
var login = new Login();

var Contactvendeur = function() {
};
Contactvendeur.prototype.init = function() {
	this.nettoie();
	this.nettoieErreur();
	_('popup_destinataire').innerHTML = _('destinataire').innerHTML;
	affichePosition('contactvendeur', 'visible', decalageTop1);
	focus('contactvendeur_nom');
}
Contactvendeur.prototype.nettoie = function() {
	_('contactvendeur_message').value = '';
}
Contactvendeur.prototype.nettoieErreur = function() {
	_('erreur_contactvendeur_message').innerHTML = '';
	_('erreur_contactvendeur_email').innerHTML = '';
}
Contactvendeur.prototype.envoyer = function() {
	this.nettoieErreur();
	var copie;
	if (_('contactvendeur_copiemail').checked == true) {
		copie = 'true';
	} else  {
		copie = 'false';
	}
	var param = 'pays=' + _('annonce_pays').value + '&cle=' + _('annonce_cle').value + '&' + 'message='
		+ Url.encode(_('contactvendeur_message').value) + '&' + 'email='
		+ _('contactvendeur_email').value + '&copie=' + copie;
	appelAjax('contact/contactvendeur', param, 2, contactvendeur.envoyerSuccess);
}
Contactvendeur.prototype.envoyerSuccess = function(xhr) {
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		var descriptionStatut = reponseXML.getElementsByTagName(
				'descriptionStatut').item(0).firstChild.nodeValue;
		if (statut == 'OK') {
			cache('contactvendeur');
			_('texteMessage').innerHTML = descriptionStatut;
			affichePosition('message', 'block', decalageTop2);
		} else if (statut == 'KO') {
			var erreurs = reponseXML.getElementsByTagName('erreur');
			for (i = 0; i < erreurs.length; i++) {
				var zone = erreurs[i].getElementsByTagName('zone').item(0).firstChild.nodeValue;
				var description = erreurs[i]
						.getElementsByTagName('description').item(0).firstChild.nodeValue;
				_('erreur_contactvendeur_' + zone).innerHTML = description;
			}

		}
	} else {
		erreur.envoyer(xhr.responseText);
	}
}
var contactvendeur = new Contactvendeur();

// Conseille le site aux amis
var Contactami = function() {
};
Contactami.prototype.init = function() {
	_('contactami_email').value = '';
	_('erreur_contactami_email').innerHTML = '';
	//afficheOverlay();
	affichePosition('contactami', 'visible', decalageTop2);
	focus('contactami_email');
}
Contactami.prototype.envoyer = function() {
	_('erreur_contactami_email').innerHTML = '';
	var param = 'email=' + _('contactami_email').value;
	appelAjax('contact/contactami', param, 2, contactami.envoyerSuccess);
}
Contactami.prototype.envoyerSuccess = function(xhr) {
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		var descriptionStatut = reponseXML.getElementsByTagName(
				'descriptionStatut').item(0).firstChild.nodeValue;
		if (statut == 'OK') {
			cache('contactami');
			masqueOverlay();
			_('texteMessage').innerHTML = descriptionStatut;
			affichePosition('message', 'block', decalageTop2);
		} else if (statut == 'KO') {
			var erreurs = reponseXML.getElementsByTagName('erreur');
			for (i = 0; i < erreurs.length; i++) {
				var zone = erreurs[i].getElementsByTagName('zone').item(0).firstChild.nodeValue;
				var description = erreurs[i]
						.getElementsByTagName('description').item(0).firstChild.nodeValue;
				_('erreur_contactami_' + zone).innerHTML = description;
			}

		}
	} else {
		erreur.envoyer(xhr.responseText);
	}
}
var contactami = new Contactami();

// Conseille une annonce à un ami
var Conseilleami = function() {
};
Conseilleami.prototype.init = function() {
	this.nettoie();
	this.nettoieErreur();
	affichePosition('conseilleami', 'visible', decalageTop1);
	focus('conseilleami_ami');
}
Conseilleami.prototype.nettoie = function() {
	_('conseilleami_email').value = '';
}
Conseilleami.prototype.nettoieErreur = function() {
	_('erreur_conseilleami_message').innerHTML = '';
	_('erreur_conseilleami_ami').innerHTML = '';
	_('erreur_conseilleami_email').innerHTML = '';
}
Conseilleami.prototype.envoyer = function() {
	this.nettoieErreur();
	var param = 'pays=' + _('annonce_pays').value + '&cle=' + _('annonce_cle').value + '&' + 'message='
		+ Url.encode(_('conseilleami_message').value) + '&' + 'ami='
		+ Url.encode(_('conseilleami_ami').value) + '&' + 'email='
		+ _('conseilleami_email').value;
	appelAjax('contact/conseilleami', param, 2, conseilleami.envoyerSuccess);
}
Conseilleami.prototype.envoyerSuccess = function(xhr) {
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		var descriptionStatut = reponseXML.getElementsByTagName(
				'descriptionStatut').item(0).firstChild.nodeValue;
		if (statut == 'OK') {
			cache('conseilleami');
			_('texteMessage').innerHTML = descriptionStatut;
			affichePosition('message', 'block', decalageTop2);
		} else if (statut == 'KO') {
			var erreurs = reponseXML.getElementsByTagName('erreur');
			for (i = 0; i < erreurs.length; i++) {
				var zone = erreurs[i].getElementsByTagName('zone').item(0).firstChild.nodeValue;
				var description = erreurs[i]
						.getElementsByTagName('description').item(0).firstChild.nodeValue;
				_('erreur_conseilleami_' + zone).innerHTML = description;
			}

		}
	} else {
		erreur.envoyer(xhr.responseText);
	}
}
var conseilleami = new Conseilleami();

var Contenuabusif = function() {
};
Contenuabusif.prototype.init = function() {
	this.nettoie();
	this.nettoieErreur();
	affichePosition('contenuabusif', 'visible', decalageTop1);
	focus('contenuabusif_nom');
}
Contenuabusif.prototype.nettoie = function() {
	_('contenuabusif_message').value = '';
	_('contenuabusif_email').value = '';
}
Contenuabusif.prototype.nettoieErreur = function() {
	_('erreur_contenuabusif_message').innerHTML = '';
	_('erreur_contenuabusif_email').innerHTML = '';
}
Contenuabusif.prototype.envoyer = function() {
	this.nettoieErreur();
	var param = 'pays=' + _('annonce_pays').value + '&cle=' + _('annonce_cle').value + '&' + 'message='
		+ Url.encode(_('contenuabusif_message').value) + '&' + 'email='
		+ _('contenuabusif_email').value;
	appelAjax('contact/contenuabusif', param, 2, contenuabusif.envoyerSuccess);
}
Contenuabusif.prototype.envoyerSuccess = function(xhr) {
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		var descriptionStatut = reponseXML.getElementsByTagName(
				'descriptionStatut').item(0).firstChild.nodeValue;
		if (statut == 'OK') {
			cache('contenuabusif');
			_('texteMessage').innerHTML = descriptionStatut;
			affichePosition('message', 'block', decalageTop2);
		} else if (statut == 'KO') {
			var erreurs = reponseXML.getElementsByTagName('erreur');
			for (i = 0; i < erreurs.length; i++) {
				var zone = erreurs[i].getElementsByTagName('zone').item(0).firstChild.nodeValue;
				var description = erreurs[i]
						.getElementsByTagName('description').item(0).firstChild.nodeValue;
				_('erreur_contenuabusif_' + zone).innerHTML = description;
			}

		}
	} else {
		erreur.envoyer(xhr.responseText);
	}
}
var contenuabusif = new Contenuabusif();

var Annonce = function() {
};
Annonce.prototype.afficheMiniature = function(event,pays,idAnnonce, idPhoto,
		extensionMiniature) {
	masque('miniatureAnnonce');
	var miniatureAnnonce = $('miniatureAnnonce');
	if (miniatureAnnonce && event) {
		$('imageMiniature').src = url_base + '/images_' + pays + '/' + idAnnonce
				+ '/bigminiature' + idPhoto + '.' + extensionMiniature;
		var X = Event.pointerX(event);
		var Y = Event.pointerY(event);
		miniatureAnnonce.style.left = X + 10 + 'px';
		miniatureAnnonce.style.top = Y - 100 + 'px';
		afficheSimple('miniatureAnnonce', 'block');
	}
}
Annonce.prototype.masqueMiniature = function() {
	if (_('imageMiniature')) {
		_('imageMiniature').src = url_base + '/images/pixel.gif';
	}
	masque('miniatureAnnonce');
}
Annonce.prototype.photoSuivante = function() {
	if (!($('cheminPhoto' + counter))) {
		counter = 0;
	}
	annonce.changePhoto(counter);
}
Annonce.prototype.photoPrecedente = function() {
	if (!($('cheminPhoto' + counter))) {
		counter = 0;
	}
	annonce.changePhoto(counter);
}
Annonce.prototype.changePhoto = function(id) {
	var cheminPhoto = _('cheminPhoto' + id).innerHTML;
	var photoPrincipale = _('photoPrincipale');
	if (navigator.userAgent.toLowerCase().indexOf('safari') > 0) {
		var next_image = new Image;
		next_image.src = cheminPhoto;
		photoPrincipale.src = next_image.src;
	} else {
		photoPrincipale.src = cheminPhoto;
	}
	var oldActiveMiniature = _('miniature' + oldActive);
	if (oldActiveMiniature) {
		oldActiveMiniature.className = "";
	}
	var activeMiniature = _('miniature' + id);
	if (activeMiniature) {
		activeMiniature.className = "active";
	}
	oldActive = id;
}
Annonce.prototype.afficheCarte = function() {
	try {
		if (GBrowserIsCompatible()) {
			affichePosition('carteAnnonce', 'visible', decalageTop1);
			map = new GMap2($('mapAnnonce'));
			map.addControl(new GOverviewMapControl());
			//map.addControl(new GLargeMapControl());
			map.addControl(new google.maps.LargeMapControl3D());
			// map2.clearOverlays();
			var description_latitude = $('description_latitude').value;
			var description_longitude = $('description_longitude').value;
			var description_zoomCarte = parseInt($('description_zoomCarte').value);
			var description_adressepropre = $('description_adressepropre').value;
			var point = new GLatLng(description_latitude, description_longitude);
			map.setCenter(point, description_zoomCarte);
			marker = new GMarker(point);
			map.addOverlay(marker);
			marker.openInfoWindowHtml('<span class="infoMap">' + description_adressepropre + '</span>');
		} else {
			alert('Your navigator is too old to display a map');
		}
	} catch (err) {
		alert('It is impossible to display map now');
	}
}
Annonce.prototype.memorise = function(pays,cleAnnonce) {
		var param = 'pays=' + pays + '&cle=' + cleAnnonce;
		appelAjax('annonce/memoriser-annonce', param, 2,
				annonce.memoriseSuccess);
}
Annonce.prototype.memoriseSuccess = function(xhr) {
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		var descriptionStatut = reponseXML.getElementsByTagName(
				'descriptionStatut').item(0).firstChild.nodeValue;
		affichePosition('message', 'block', decalageTop2);
		_('texteMessage').innerHTML = descriptionStatut;
	}
}
Annonce.prototype.supprimerfavori = function(pays,cleAnnonce) {
	var param = 'pays=' + pays + '&cle=' + cleAnnonce;
	appelAjax('annonce/supprimer-favori', param, 2,
			annonce.supprimerfavoriSuccess, [ cleAnnonce ]);
}
Annonce.prototype.supprimerfavoriSuccess = function(xhr, cleAnnonce) {
	var reponseXML = valideRetourXML(xhr);
	if (reponseXML) {
		var element = reponseXML.getElementsByTagName('statut').item(0);
		var statut = element.firstChild.nodeValue;
		var descriptionStatut = reponseXML.getElementsByTagName(
				'descriptionStatut').item(0).firstChild.nodeValue;
		affichePosition('message', 'block', decalageTop2);
		_('texteMessage').innerHTML = descriptionStatut;

		// On enléve la ligne du tableau
		masque('ligneAnnonce_' + cleAnnonce);
	}
}
var annonce = new Annonce();

var Rss = function() {
};
Rss.prototype.init = function() {
	// Pour charger l'URL du flux
	_('linkrss').value = _('lienFluxRSS').value;
	afficheOverlay();
	affichePosition('fluxRSS', 'visible', decalageTop2);
}
var rss = new Rss();

var Temoignage = function() {
};
Temoignage.prototype.suivant = function(idtemoignage) {
	var param = 'idtemoignage=' + idtemoignage;
	appelAjax('temoignage/suivant', param, 2,temoignage.suivantSuccess);
}
Temoignage.prototype.suivantSuccess = function(xhr) {
	if (xhr.responseText) {
		_('temoignage').innerHTML = xhr.responseText;
	}
}
var temoignage = new Temoignage();

var Erreur = function() {
};
Erreur.prototype.envoyer = function(erreur) {
	var param = 'erreur=' + Url.encode(erreur);
	appelAjax('error/envoyer', param, 2);
	masqueOverlay();
	afficheCentrer('messageBIG', 'block');
	_('texteMessageBIG').innerHTML = m_message_erreur;
}
var erreur = new Erreur();