/*---- AjaxDotNetErrorHandler.js ----*/

function AjaxDotNetErrorHandler() {}

AjaxDotNetErrorHandler.prototype.Init = function() {
	$(document).ready(function() {
		Sys.Application.add_load(AjaxDotNetErrorHandler.AppLoad);
	});
}

AjaxDotNetErrorHandler.CloseError = function() {
	$('#AjaxErrorPopUp').hide();
}

AjaxDotNetErrorHandler.AppLoad = function() {
	var instance = Sys.WebForms.PageRequestManager.getInstance();
	instance.add_endRequest(AjaxDotNetErrorHandler.EndRequest);
	instance.add_beginRequest(AjaxDotNetErrorHandler.BeginRequest);
}

AjaxDotNetErrorHandler.BeginRequest = function(sender, args) {
	if ($('#AjaxErrorPopUp').css('display') == 'none') {
		AjaxDotNetErrorHandler.CloseError(); 
	}
}

AjaxDotNetErrorHandler.EndRequest = function(sender, args) {
	// Check to see if there's an error on this request.
	var error = args.get_error()

	if (error != undefined) {
		// If there is, show the custom error.
		$('#AjaxErrorPopUp').show();
		$('#AjaxErrorPopUp .message').html(error.message);
		// Let the framework know that the error is handled, 
		//  so it doesn't throw the JavaScript alert.
		args.set_errorHandled(true);
	}
}

/*---- JSforAJAX.js ----*/

windowOnscroll = function() {
	l__scrollTop = (document.body.scrollTop == 0) ? document.documentElement.scrollTop : document.body.scrollTop;

	if (getObj('divUpdateProgressCenter')) {
		if (!ie) {
			getObj('divUpdateProgressCenter').style.position = "fixed";
		}
		else {
			SetToXY('divUpdateProgressCenter', 0, l__scrollTop);
		}
	}


	if (getObj('divUpdateProgressCenterZapette')) {
		if (!ie) {
			getObj('divUpdateProgressCenterZapette').style.position = "fixed";
		}
		else {
			SetToXY('divUpdateProgressCenterZapette', 0, l__scrollTop);
		}
	}
}



/********************
* Functions used by
*    Flash map
********************/
var g__totalFlash = -1;
var g__totalZapette = -1;
function TotalAnnoncesFromFlash(i__nb) {
	g__totalFlash = i__nb;
}

function TotalAnnoncesFromZapette(i__nb) {
	try {
		var l__span = getObj("span_AlerteNbAnnonces");
		if (l__span == null)
			return;
	}
	catch (ex) {
		//if we are not in map mode
		return;
	}
	g__totalZapette = i__nb;
	if (g__totalZapette > g__totalFlash && g__totalFlash != -1) {
		if (g__totalZapette - g__totalFlash > 1)
			getObj("span_NbAnnoncesSurplus").innerHTML = "les " + (g__totalZapette - g__totalFlash) + " biens non localis&eacute;s";
		else
			getObj("span_NbAnnoncesSurplus").innerHTML = "le bien non localis&eacute;";
		getObj("span_AlerteNbAnnonces").style.display = "inline";
	}
	else {
		getObj("span_AlerteNbAnnonces").style.display = "none";
	}
}

function detectFlashForCarto() {
	if (!DetectFlashVer(6, 0, 65)) {
		AlertPjpa('Version obsol&egrave;te du plugin Flash', 'FlashVersionDetail', 150, 200);
	}
}

function ShowCarteAnnuaire() {
	getObj("div_CarteAnnuaire").style.visibility = "";
	getObj("div_ListRegionsDepartements").style.display = "none";
}

function ShowVideoConseil() {
	if (getObj("div_VideoConseil") != null) {
		getObj("div_VideoConseil").style.visibility = "";
	}
	if (getObj("div_VideoConseilTranscription") != null) {
		getObj("div_VideoConseilTranscription").style.display = "none";
	}
}

function detectFlashForVideoConseil() {
	if (DetectFlashVer(6, 0, 65)) {
		window.parent.ShowVideoConseil();
	}
	else {
		getObj("div_VideoConseilFlashError").style.display = "";
		getObj("div_VideoConseilFlash").style.display = "none";
	}
}

function detectFlashForCarteAnnuaire() {
	if (DetectFlashVer(6, 0, 65)) {
		window.parent.ShowCarteAnnuaire();
	}
	else {
		getObj("div_CarteSectorielleFlashError").style.display = "";
		getObj("div_CarteSectorielleFlash").style.display = "none";
	}
}

function detectFlashForCarteSectorielle() {
	if (DetectFlashVer(6, 0, 65)) {
		window.parent.ShowCarteAnnuaire();
	}
	else {
		getObj("div_CarteSectorielleFlashError").style.display = "";
		getObj("div_CarteSectorielleFlash").style.display = "none";
	}
}
function detectFlashForLocalisezAgence() {
	if (!DetectFlashVer(6, 0, 65)) {
		getObj("div_LocalisezAgenceFlashError").style.display = "";
		getObj("div_LocalisezAgenceFlash").style.display = "none";
	}
}
function detectFlashForPlanDesEnviron() {
	if (!DetectFlashVer(6, 0, 65)) {
		getObj("div_PlanDesEnvironFlashError").style.display = "";
		getObj("div_PlanDesEnvironFlash").style.display = "none";
	}
}

function FlashViewFicheSemidetailInParentPage(i__id) {
	window.parent.FlashViewFicheSemidetail(i__id);
}

var repeatSemidet = "";
function FlashViewFicheSemidetail(i__id) {
	WriteDebugText("FlashViewFicheSemidetail");

	var div_BarreRightSemidet = getObj("div_BarreRightSemidet");
	var div_ColDroite = getObj("div_ColDroite");
	var start_footer = getObj("start_footer");

	if (!start_footer || !div_BarreRightSemidet || !div_ColDroite) {
		window.clearTimeout(repeatSemidet);
		repeatSemidet = window.setTimeout("FlashViewFicheSemidetail('" + i__id + "')", 100);
	}
	else {
		var l__SuppLeft = 34;
		l__fleche = getObj("fleche_" + i__id);
		if (!l__fleche) {
			l__fleche = getObj("divfleche_gondole");
			l__SuppLeft += 60;
		}
		l__fleche.style.visibility = "visible";

		//content
		FillTemplateSemiDet(i__id);

		//position
		var l__semidetheight = getObj("contener_semi_detaillee").clientHeight;
		var l__top = Math.min(getTop(l__fleche) - l__semidetheight / 3, getTop(start_footer) - l__semidetheight);
		SetToXY("div_BarreRightSemidet", getLeft(l__fleche) + l__SuppLeft, l__top);

		// Display Content
		div_BarreRightSemidet.style.display = "block";
	}
}

function FlashViewFicheDetailInParentPage(i__id) {
	window.parent.FlashViewFicheDetail(i__id)
}

function FlashViewFicheDetail(i__id) {
	var l__div = getObj("contener_semi_detaillee");
	var l__linkList = (l__div) ? l__div.getElementsByTagName("a") : null;
	for (i in l__linkList) {
		if (l__linkList[i].id != null && l__linkList[i].id.indexOf("LinkButton_Prix") != -1)
			eval(l__linkList[i].href);
	}
}

function FlashAddToSelection(i__id) {
	var l__div = getObj("SemiDet_" + i__id);
	if (!l__div) {
		window.setTimeout("FlashAddToSelection('" + i__id + "')", 50);
		return;
	}
	var l__linkList = l__div.getElementsByTagName("a");
	if (l__linkList != null) {
		for (i in l__linkList) {
			if (l__linkList[i].id != null && l__linkList[i].id.indexOf("m__LBAjouterSelection") != -1) {
				eval(l__linkList[i].href);
			}
		}
	}
}

function AlertFlashVersion() {
	AlertPjpa('Version obsol&egrave;te du plugin Flash', 'FlashVersion', 260, 320);
	__doPostBack('ctl00$ContentPlaceHolder1$UCLRImmo$LButton_ToListe', '');
}

function AlertFlashVersionFicheDet() {
	AlertPjpa('Version obsol&egrave;te du plugin Flash', 'FlashVersionDetail', 260, 320);
	scroll(0, 0);
	getObj("pasClicFlash").style.display = "none";
}

//Called by the map of France
function LoadDepartementMappy(i__lat, i__long, i__radius, i__ndept) {
	window.parent.LoadDepartementMappyInParentPage(i__lat, i__long, i__radius, i__ndept);
}

function LoadDepartementMappyInParentPage(i__lat, i__long, i__radius, i__ndept) {
	DisplayWaitDepartement();

	//if url rewriting (last char is a /)
	var l__HRef = document.location.href;
	if (!document.location.search.match(/.*&Quoi=([^&?]*)/i) && !document.location.search.match(/.*&Combien=([^&?]*)/i)) {
		var hidden = document.getElementById(ID_HiddenField__SectorielleImmo);
		hidden.value = i__ndept;
		document.forms.item(0).submit();
	}
	else {
		quoi = ""; combien = "";
		if (document.location.search.match(/.*Quoi=([^&?]*)/i))
			quoi = document.location.search.match(/.*Quoi=([^&?]*)/i)[1];
		if (document.location.search.match(/.*Combien=([^&?]*)/i))
			combien = document.location.search.match(/.*Combien=([^&?]*)/i)[1];
		document.location.href = "/Immobilier/Liste.aspx?Quoi=" + quoi + "&Ou=" + encodeURI(i__ndept) + "&Combien=" + combien;
	}

}

function DisplayWaitDepartement() {
	hideSelects();
	if (document.getElementById('div_CarteAnnuaire') != undefined && document.getElementById('div_CarteAnnuaireImg') != undefined) {
		document.getElementById('div_CarteAnnuaire').style.display = 'none';
		document.getElementById('div_CarteAnnuaireImg').style.display = 'block';
	}

	document.getElementById('wait2').style.display = 'block';
	document.getElementById('wait').style.display = 'block';
}


function OuvrirFicheDetaillee(i__HTMLElement) {
	if (i__HTMLElement.className != 'photo') {
		var l__LinkButton = i__HTMLElement.getElementsByTagName('a')[0]
		if (l__LinkButton != null) {
			window.open(i__HTMLElement.getElementsByTagName('a')[0].href);
		}
	}
}

function OuvrirMessage(i__HTMLElement) {
	eval(i__HTMLElement.getElementsByTagName('a')[0].href);
}

/********************
* Autocomplete of
* Localite
********************/

var _pjpaPage = "";

function LaunchInstallAC(e, page) {

	if (page != undefined) {
		_pjpaPage = page;
	} else {
		_pjpaPage = "";
	}


	if (!getParam(e.name)) {
		InstallAC(getObj('aspnetForm'), e, getObj('aspnetForm').btnG, 'search', 'en', page);
	}
}

/********************
* Refresh functions
* (Ajaxification)
********************/

function RefreshUserZones() {
	__doPostBack("ctl00_GlobalTop1_MonEspace1_Button_DummyForJS", "");
}

function RefreshMaSelection() {
	if (getObj("conteneur_liens_agents"))
		__doPostBack('ctl00$ContentPlaceHolder1$m__LBDummyForJS', '');
}

/********************
* Xiti
********************/

function xt_med_2(type, section, page, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) {
	xt_img = new Image();
	var xtdmed = new Date();
	xt_ajout = (type == 'F') ? '&x1=' + x1 + '&x2=' + x2 + '&x3=' + x3 + '&x4=' + x4 + '&x5=' + x5 + '&x6=' + x6 + '&x7=' + x7 + '&x8=' + x8 + '&x9=' + x9 + '&x10=' + x10 : '';
	Xt_im = xtsd + '.xiti.com/hit.xiti?s=' + xtsite + '&s2=' + section;
	Xt_im += '&p=' + page + xt_ajout + '&hl=' + xtdmed.getHours() + 'x' + xtdmed.getMinutes() + 'x' + xtdmed.getSeconds();
	if (parseFloat(navigator.appVersion) >= 4)
	{ Xt_im += '&r=' + xts.width + 'x' + xts.height + 'x' + xts.pixelDepth + 'x' + xts.colorDepth; }
	xt_img.src = Xt_im;
	return;
}


/********************
* Zapette V2
********************/

//called first : sets maximum height of each panel and close it
function setHeightsAndClose() {
	l__divs = getObj("div_zapette").getElementsByTagName("div");
	for (i = 0; i < l__divs.length; i++) {
		if (l__divs[i].className == "contenu_fieldset_zapette") {
			l__divs[i]._originalHeight = l__divs[i].offsetHeight;
			if (l__divs[i].parentNode.className != "ouvert dontclose") {
				l__divs[i].style.height = "1px";
				l__divs[i].parentNode.className = "ferme";
			}
		}
	}
}

//toggle a panel open/closed
function toggleBlock(sender) {
	if (sender.parentNode.className.indexOf("ouvert") != -1) {
		l__divs = sender.parentNode.getElementsByTagName("div");
		for (i = 0; i < l__divs.length; i++) {
			if (l__divs[i].className == "contenu_fieldset_zapette") {
				l__animation = new AjaxControlToolkit.Animation.ResizeAnimation(l__divs[i], .2, 10, null, 0, 'px');
				if (ie)
					l__divs[i].parentNode.className = "ferme";
				else
					l__animation.play();
				l__animation._target = l__divs[i];
				l__animation.onEnd = function() {
					this._target.parentNode.className = "ferme";
				}
				return 0;
			}
		}
	}
	else {
		l__divs = sender.parentNode.getElementsByTagName("div");
		for (i = 0; i < l__divs.length; i++) {
			if (l__divs[i].className == "contenu_fieldset_zapette") {
				sender.parentNode.className = "ouvert";
				l__divs[i].style.height = "1px";
				l__animationClose = new AjaxControlToolkit.Animation.ResizeAnimation(l__divs[i], .2, 10, null, l__divs[i]._originalHeight, 'px');
				if (!ie)
					l__animationClose.play();
				else
					l__divs[i].style.height = l__divs[i]._originalHeight + "px";
				return 0;
			}
		}
	}
}


//unfold a panel containing the given control
function openParentFieldset(senderId) {
	var l__htmlNode = getObj(senderId);
	while (l__htmlNode.tagName != "FIELDSET") {
		l__htmlNode = l__htmlNode.parentNode;
		if (l__htmlNode == document.body)
			return;
	}
	l__htmlNode.className = "ouvert dontclose";
	l__divs = l__htmlNode.getElementsByTagName("div");
	for (i = 0; i < l__divs.length; i++) {
		if (l__divs[i].className == "contenu_fieldset_zapette" && typeof (l__divs[i]._originalHeight) != "undefined") {
			l__divs[i].style.height = l__divs[i]._originalHeight + "px";
			l__divs[i].parentNode.className = "ouvert dontclose";
			return;
		}
	}

}

function ButtonOnMouseOver(e) {
	if (e != undefined)
		e.src = e.src.toLowerCase().replace("off.", "on.");
}

function ButtonOnMouseOut(e) {
	if (e != undefined)
		e.src = e.src.toLowerCase().replace("on.", "off.");
}

function ButtonOnMouseOverClass(e) {
	if (e != undefined) {
		e.className = e.className.replace("_off", "_on");
	}
}

function ButtonOnMouseOutClass(e) {
	if (e != undefined) {
		e.className = e.className.replace("_on", "_off");
	}
}

function RollOnglet(e) {
	if (e != undefined) {
		if (e.src.indexOf('off') != -1) {
			e.src = e.src.replace('off', 'roll');
		} else {
			e.src = e.src.replace('roll', 'off');
		}
	}
}

function RollOngletClass(e) {
	if (e != undefined) {
		if (e.className.indexOf('_roll') != -1) {
			e.className = e.className.replace('_roll', '');
		} else {
			e.className = e.className + '_roll';
		}
	}
}

/****************************
** Lib RollOngletClass
****************************/
function RollClass() {
	this.getLibName = function() { return "lib_RollClass"; }

	this.RollOnElt = function(elt) {
		elt.className = elt.className + '_roll';
	}

	this.RollOutElt = function(elt) {
		elt.className = elt.className.replace('_roll', '');
	}

	this.RollOn = function(id) {
		var elt = document.getElementById(id);
		this.RollOnElt(elt);
	}

	this.RollOut = function(id) {
		var elt = document.getElementById(id);
		this.RollOutElt(elt);
	}

	this.TimerRollOn = function(sender) {
		lib_TimerRoll.RollOn(sender, this);
	}

	this.TimerRollOut = function(sender) {
		lib_TimerRoll.RollOut(sender, this);
	}
}
var lib_RollClass = new RollClass();

/****************************
** Lib TimerRoll
****************************/
function TimerRoll() {
	this.TimerRollIdElement = "";
	this.TimerRoll = "";

	this.getLibName = function() { return "lib_TimerRoll"; }

	this.RollOn = function(sender, lib_Roll) {
		var id = sender.id;

		window.clearTimeout(this.TimerRoll);
		if (id != this.TimerRollIdElement) {
			if (this.TimerRollIdElement != "") {
				lib_Roll.RollOut(this.TimerRollIdElement);
				this.TimerRollIdElement = "";
			}
			lib_Roll.RollOn(id);
		}
	}

	this.RollOut = function(sender, lib_Roll) {
		var id = sender.id;
		var name = lib_Roll.getLibName();

		this.TimerRollIdElement = id;
		this.TimerRoll = setTimeout(name + ".RollOut('" + id + "');" + this.getLibName() + ".TimerRollIdElement=\"\";", 50);
	}
}
var lib_TimerRoll = new TimerRoll();

/**************************/

function rollOnVignette(sender) {
	LRVignetteMouseOver(sender);

	sender.className = "gondole_on";
}

function rollOutVignette(sender) {
	LRVignetteMouseOut(sender);

	sender.className = "";
}

function FlashRefreshSemiDetDataInParentPage(QueryString) {
	window.parent.FlashRefreshSemiDetData(QueryString);
}

function FlashRefreshSemiDetData(QueryString) {
	__doPostBack(IdButtonRefreshSemiDetData, QueryString);
}

/********************
* Functions used by
* Liste de resultats
********************/
function EtoileSelectionRollOn(i__id) {
	var l__img = getObj("etoile_selection_" + i__id);
	if (l__img)
		l__img.src = l__img.src.replace('off', 'roll');
}

function EtoileSelectionRollOff(i__id) {
	var l__img = getObj("etoile_selection_" + i__id);
	if (l__img)
		l__img.src = l__img.src.replace('roll', 'off');
}

function ShowButtonPlusdInfo(i__id) {
	var l__divGris = getObj("divPlusdInfoGris_" + i__id);
	var l__divViolet = getObj("divPlusdInfoViolet_" + i__id);
	if (l__divGris)
		l__divGris.style.display = "none";
	if (l__divViolet)
		l__divViolet.style.display = "";
}

function HideButtonPlusdInfo(i__id) {
	var l__divGris = getObj("divPlusdInfoGris_" + i__id);
	var l__divViolet = getObj("divPlusdInfoViolet_" + i__id);
	if (l__divGris)
		l__divGris.style.display = "";
	if (l__divViolet)
		l__divViolet.style.display = "none";
}

TimerSemiDetToPub = "";
function BarreRightFadeOut() {
	if (getObj("div_BarreRightSemidet") != null && getObj("div_BarreRightSemidet").style != null)
		getObj("div_BarreRightSemidet").style.display = "block";
}

function ActiveResultListAnnonceClick() {
	ResultListAnnonceClickActif = true;
}

function DesactiveResultListAnnonceClick() {
	ResultListAnnonceClickActif = false;
}

ResultListAnnonceClickActif = true;
function ResultListAnnonceClick(i__HTMLElement) {

	// alert(ResultListAnnonceClickActif);
	if (ResultListAnnonceClickActif == true) {
		PopUpORPIClick(i__HTMLElement);
	}
	var l__LinkButton = '';

	for (l__Index = 0; l__Index < i__HTMLElement.getElementsByTagName('a').length; l__Index++) {
		if (i__HTMLElement.getElementsByTagName('a')[l__Index].id.indexOf('m__LBAnnonce') != -1) {
			l__LinkButton = i__HTMLElement.getElementsByTagName('a')[l__Index];
			break;
		}
	}

	l__Utility.LinkButtonClickHref(l__LinkButton.id);

	//        eval(l__LinkButton.href);

}
function PopUpORPIClick(i__HTMLElement) {

	var URL = '-1';
	var elts = i__HTMLElement.getElementsByTagName('input');
	for (l__Index = 0; l__Index < elts.length; l__Index++) {
		if (elts[l__Index].id.indexOf('UrlSiteOrpi') != -1) {
			// var elt = document.getElementById(elt[l__Index].id);
			URL = elts[l__Index].value;
			break;
		}
	}

	if (URL != '-1') {
		// Lancer le tag xiti
		TagClick('C', '2', '� Partenaires::Orpi::Orpi_LR_mise_en_relief', 'N');
		var externalPopup = window.open(URL, 'ORPI', 'width=668, height=500, menubar=yes, status=yes, toolbar=yes, location=yes, scrollbars=yes, resizable=yes');
		externalPopup.blur();
		window.focus();
		// mna('*slh', 'annonces', '*trt', 'immobilieres', '*slh', 'detail+pro', '*trt', '6568669+vente+appartement+4', '*trt', 'pieces+antony+92', '*dt', 'aspx');
	}
}

function ChangeLRClassName(id, ToOn) {
	var l__line = getObj("tbodyAnnonce_" + id)
	if (ToOn) {
		if (l__line.className == "normal")
			l__line.className = "normal_on";
		else if (l__line.className == "normal_pyjama")
			l__line.className = "normal_pyjama_on";
		else if (l__line.className == "relief")
			l__line.className = "relief_on";
	}
	else {
		if (l__line.className == "normal_on")
			l__line.className = "normal";
		else if (l__line.className == "normal_pyjama_on")
			l__line.className = "normal_pyjama";
		else if (l__line.className == "relief_on")
			l__line.className = "relief";
	}
}

//launched when the mouse rolls over a line of the LR
function LRLineMouseOver(id) {
	BarreRightFadeOut();
	ChangeLRClassName(id, true);
	ShowButtonPlusdInfo(id);
	EtoileSelectionRollOn(id);
	FlashViewFicheSemidetail(id);
	windowOnscroll(); //refresh semidet position because its height may have changed*/
}

//launched when the mouse quits a line of the LR
function LRLineMouseOut(id) {
	ChangeLRClassName(id, false);

	EtoileSelectionRollOff(id);
	HideButtonPlusdInfo(id);
	var fleche = getObj("fleche_" + id);
	if (fleche)
		fleche.style.visibility = "hidden";
	TimerRollOut_IdAnnonce = "";
}

function SemiDetToPub() {
	getObj("div_BarreRightSemidet").style.display = "none";
	/*getObj("div_ColDroite").className = "col_droite";*/
}

function div_FicheSemiDet_mouseover() {
	window.clearTimeout(TimerRollOutLRLine);
	window.clearTimeout(TimerSemiDetToPub);
}

function div_FicheSemiDet_mouseout() {
	TimerRollOutLRLineSemidet(TimerRollOut_IdAnnonce);
}

var TimerRollOut_IdAnnonce = "";
var TimerRollOutLRLine = "";
function rollOn(sender) {
	var id = sender.id.replace(/tbodyAnnonce_/, "");

	window.clearTimeout(TimerRollOutLRLine);
	window.clearTimeout(TimerSemiDetToPub);

	if (TimerRollOut_IdAnnonce != id) {
		if (TimerRollOut_IdAnnonce != "")
			LRLineMouseOut(TimerRollOut_IdAnnonce);
		LRLineMouseOver(id);
	}
}

function rollOut(sender) {
	var id = sender.id.replace(/tbodyAnnonce_/, "");

	TimerRollOut_IdAnnonce = id;
	TimerRollOutLRLineSemidet(id);
}

function TimerRollOutLRLineSemidet(id) {
	TimerRollOutLRLine = setTimeout("LRLineMouseOut('" + id + "')", 50);
	TimerSemiDetToPub = setTimeout("SemiDetToPub();", 50);
}


var _PopUpPhoto;

function PopUpPhoto(i__MaxIndiceImage, i__ListImageUrl) {

	//_PopUpPhoto = this;

	this.MaxIndiceImage = i__MaxIndiceImage;
	this.ListImageUrl = i__ListImageUrl;
	this.ZoomImageSelected = 1;
	this.tab_zoom_img = new Array();

	this.IdImageVisualiser;
	this.IdHiddenFieldImageSelected;
	this.IdButtonLaunchModal;
	this.IdImageAgrandie;
	this.IdLienNext;
	this.IdLienPrevious;

	this.Open = function() {
		var hidden = document.getElementById(this.IdHiddenFieldImageSelected);
		this.ZoomImageSelected = Number(hidden.value);

		var Image = document.getElementById(this.IdImageVisualiser);
		if (Image.title != "Photo non disponible") {
			l__Utility.LinkButtonClick(this.IdButtonLaunchModal);
		}
	}

	this.ChangeImgDetaillee = function(img, num) {
		var Image = document.getElementById(this.IdImageVisualiser);
		var src = img.src.replace("_Detaillee", "_Zoom");
		Image.src = src;
		Image.title = img.title;
		Image.alt = img.alt;

		var hidden = document.getElementById(this.IdHiddenFieldImageSelected);
		hidden.value = num;
	}

	this.SelectZoomImage = function(num, hidePreviousNext) {
		var lien;
		var span;
		var idlien;
		var idspan;

		this.ZoomImageSelected = num;
		for (var i = 1; i <= this.MaxIndiceImage; i++) {
			idlien = "LienImage" + i;
			lien = document.getElementById(idlien);
			idspan = "SpanImage" + i;
			span = document.getElementById(idspan);

			if (i == num) {
				if (lien != null)
					lien.style.display = "none";
				if (span != null)
					span.style.display = "";
			}
			else {
				if (lien != null)
					lien.style.display = "";
				if (span != null)
					span.style.display = "none";
			}
		}

		if (document.getElementById("photo_legend_num") != undefined) {
			document.getElementById("photo_legend_num").innerHTML = " - Photo n&deg;" + num;
		}

		if (hidePreviousNext) {
			this.HideHyperLink(num);
		}
	}

	this.LoadZoomImage = function(num, idPhotoZoom, idEmailAlert) {
		var hidePreviousNext = true;

		if (idPhotoZoom != undefined) {
			hidePreviousNext = false;
			$("#" + idPhotoZoom).show();
			$("#" + idEmailAlert).hide();
		}

		this.SelectZoomImage(num, hidePreviousNext);
		this.FillImgZoom(num);
	}

	this.DisplayEmailAlert = function(num, idPhotoZoom, idEmailAlert) {
		$("#" + idPhotoZoom).hide();
		$("#" + idEmailAlert).show();

		this.SelectZoomImage(num);
	}

	this.HideHyperLink = function(num) {
		var aNext = document.getElementById(this.IdLienNext);
		var aPrevious = document.getElementById(this.IdLienPrevious);
		aNext.style.visibility = "";
		aPrevious.style.visibility = "";

		if (num == 1) {
			aPrevious.style.visibility = "hidden";
		}
		if (num == this.MaxIndiceImage) {
			aNext.style.visibility = "hidden";
		}
	}

	this.FillImgZoom = function(num) {
		//        var ImageZoom = document.getElementById(this.IdImageAgrandie);
		//        if (this.ListImageUrl[num - 1] != "undefined")
		//            ImageZoom.src = this.ListImageUrl[num - 1];
		//        else
		//            ImageZoom.src = "/_Images/pix.gif";

		var i = num - 1;
		var imgurl;
		if (this.ListImageUrl[i] != "undefined")
			imgurl = this.ListImageUrl[i];
		else
			imgurl = "/_Images/pix.gif";

		var img = document.getElementById(this.IdImageAgrandie);
		img.src = "/_Images/ListeResultats/loading.gif";

		if (typeof this.tab_zoom_img[i] == "undefined") {
			this.tab_zoom_img[i] = new Image();
			this.tab_zoom_img[i].onload = function() { PopUpPhoto.SetImgSrc(img, imgurl); }
			PopUpPhoto.SetImgSrc(this.tab_zoom_img[i], imgurl);
		}
		if (this.tab_zoom_img[i].complete) {
			PopUpPhoto.SetImgSrc(img, this.tab_zoom_img[i].src);
		}
	}

	this.NextImage = function() {
		var i = eval(this.ZoomImageSelected + " + 1");
		this.LoadZoomImage(i, undefined, undefined);
	}

	this.PreviousImage = function() {
		var i = eval(this.ZoomImageSelected + " - 1");
		this.LoadZoomImage(i, undefined, undefined);
	}

	this.NextElem = function(idPhotoZoom, idEmailAlert) {
		var i = eval(this.ZoomImageSelected + " + 1");

		if (i > this.MaxIndiceImage) {
			i = 1;
		}

		this.FotoOrAlert(i, idPhotoZoom, idEmailAlert);
	}

	this.PreviousElem = function(idPhotoZoom, idEmailAlert) {
		var i = eval(this.ZoomImageSelected + " - 1");

		if (i < 1) {
			i = this.MaxIndiceImage;
		}

		this.FotoOrAlert(i, idPhotoZoom, idEmailAlert);
	}

	this.FotoOrAlert = function(i, idPhotoZoom, idEmailAlert) {
		if (i < this.MaxIndiceImage) {
			this.LoadZoomImage(i, idPhotoZoom, idEmailAlert);
		}
		else {
			this.DisplayEmailAlert(i, idPhotoZoom, idEmailAlert);
		}
	}
}

PopUpPhoto.SetImgSrc = function(img, src) {
	img.src = src;
}

function Utility() {
	this.ButtonClick = function(id) {
		document.getElementById(id).click();
	}

	this.LinkButtonClick = function(id) {
		__doPostBack(id, '');
	}

	this.LinkButtonClickHref = function(id) {
		var anchor = document.getElementById(id);
		var s = anchor.href;
		s = JSReplace(s, '%20', ' ');
		s = JSReplace(s, '&quot;', '"');
		s = JSReplace(s, '%22', '"');
		eval(s);
	}
}
var l__Utility = new Utility();

function JSReplace(s, oldMotif, newMotif) {
	while (s.indexOf(oldMotif) > 0) {
		s = s.replace(oldMotif, newMotif);
	};
	return s;
};

/********************
* Register in Ajax
********************/
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();



