// JavaScript Document
function gotoSrchPage(no, strFilters)
{
	oldElem = document.getElementById("srchPage"+curSrchPage);
	nextElem = document.getElementById("srchPage"+no);
	
	if (nextElem != null)
	{
		var srchResults = document.getElementById("srchResults")

		getInfos(phpself+"?pmAction=gotoSrchPage&id="+no+"&filters="+strFilters,srchResults,function(rAct,container){
					if (rAct.readyState == 4 && rAct.status == 200) {
						if (container == null)
						{
							// Crée un div seulement pour emuler outerHTML avec firefox :@
							container = document.createElement("DIV");
							document.body.appendChild(container);
						}
						container.innerHTML = rAct.responseText;
						
						var propDesc = new Tips($$('a.propDesc'), {
							className: 'tooltip-propDesc'
						});																												 					}
				});
			
		nextElem.style.fontWeight = "bold";
		oldElem.style.fontWeight = "normal";
		
		curSrchPage = no;
	}	
}

function gotoImgsPage(no, sia)
{			
	oldElem = document.getElementById("imgsPage"+curImgsPage);
	nextElem = document.getElementById("imgsPage"+no);
	
	if (nextElem != null)
	{
		var imgsArray = document.getElementById("imgsArray")
		getInfos(phpself+"?pmAction=gotoImgsPage&sia="+sia+"&id="+no,imgsArray,fillContainer);
			
		nextElem.style.fontWeight = "bold";
		oldElem.style.fontWeight = "normal";
		
		curImgsPage = no;
	}		
}
	
function searchProps(srchContainer, forwardTo)
{
	if("undefined" == typeof forwardTo) {forwardTo = null;} 
	
	var city   = findElementById("villeProp", srchContainer).value;
	var sector = findElementById("sectProp", srchContainer).value; 
	var price  = findElementById("prixProp", srchContainer).value;	
	var sia	   = findElementById("siaProp", srchContainer).value;
	
	if (city == null) var city = "tous";		
	if (sector == null) var sector = "tous";
	if (price == null) var price = "tous";
	if (sia == null) var sia = "";

	var query = "proprietes.php?pmAction=search";										
	query = query + "&city="+city + "&sector="+sector + "&price="+price + "&sia="+sia+"&storeFilters=0";

	if (forwardTo == null)
	{
		var srchBox = document.getElementById("srchBox")
		getInfos(query, srchBox, function(rAct,container){
			if (rAct.readyState == 4 && rAct.status == 200) {
				if (container == null)
				{
					// Crée un div seulement pour emuler outerHTML avec firefox :@
					container = document.createElement("DIV");
					document.body.appendChild(container);
				}
				container.innerHTML = rAct.responseText;
				
				var propDesc = new Tips($$('a.propDesc'), {
					className: 'tooltip-propDesc'
				});																												 					}
		});
	}
	else{
		//alert(query);
		getInfos(query+"&delayed=0", null, function(rAct){
			if (rAct.readyState == 4 && rAct.status == 200)
				location.href=forwardTo;});
	}
	
	curSrchPage = 1;
}


//Besoin du module gMaps
function centerPropOnMap(rAct)
{
	if("undefined" == typeof rAct) {rAct = null;} 
	if (rAct == null)
	{
		getInfos(phpself+"?pmAction=getCurMarkerInfos",null,centerPropOnMap);
	}
	else if (rAct.readyState == 4 && rAct.status == 200)					
	{
		arrCoord = rAct.responseText.split(",");
		centerOnPt(arrCoord[1],arrCoord[2]);	

		if (markers.length == 0)
			addAllMarkers(function(){selectMarkerById(arrCoord[0]);});
		else
			selectMarkerById(arrCoord[0]);
	}			
}



//Gere la selection des resultats de recherche et rempli les details d une propriete
function selectProp(sia, imgElem)
{
	if("undefined" == typeof imgElem) {imgElem = null;}  
	
	var imgs = document.getElementById("srchBox").parentNode.parentNode.getElementsByTagName("img");
	for (var i = 0; i < imgs.length; i++) 
	if (imgs[i].name == "selector")			
		imgs[i].style.display = "none"; 			   			
	else if(imgs[i].name == "propImage")			
		 imgs[i].style.border = "";


	if (imgElem != null)
	{		
		imgElem.parentNode.childNodes[0].style.display = "";
		imgElem.style.border = "1px #9E0B0F solid" ;
		
	}							

	var detailsProp = document.getElementById("detailsProp");			
	getInfos(phpself+"?action=showCurDetails&sia="+sia,detailsProp,function(rAct, container){
			if (rAct.readyState == 4 && rAct.status == 200)					
			{
				container.innerHTML = rAct.responseText;
				container.style.display = "";
				
				//Afficher le block de la map
				var bMap = document.getElementById("blockMap");	
				bMap.style.display = "";
				
				if (typeof map != "undefined")
					centerPropOnMap();						
				else
					loadGMap(centerPropOnMap);
			}	
		});
	
	curImgsPage = 1;
	
	var menuProp = document.getElementById('menu-proprietes');
	if(menuProp) {
		menuProp.style.display = 'none';	
	}
}	

function selectImg(imgPath, id)
{		

	var imgViewer = document.getElementById("imgViewer");
	
	if (imgViewer == null)
	{
		var viewBox = document.getElementById("viewBox");	
		viewBox.innerHTML = '<img id="imgViewer" src="'+imgPath+'" style="width:350px;height:235px"/>';
	}
	else
		imgViewer.src = imgPath;
		
	getInfos(phpself+"?pmAction=selectImg&id="+id,null,null);				

}

function fillSectors(city, sector, selectId)
{
	var sectorsSel = document.getElementById(selectId);

	getInfos(phpself+"?pmAction=fillSectors&city="+city+"&sector="+sector,sectorsSel,fillContainer);	
}