// JavaScript Document

bien_type_achat = 0;
bien_type_location = 0;
bien_type_neuf = 0;

bien_region_achat = '0;0';
bien_region_location = '0;0';
bien_region_neuf = '0;0';

bien_prix_achat = '0;0';
bien_prix_location = '0;0';
bien_prix_neuf = '0;0';

//Fonction pour mise en cache des images

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

function xml_request(query)

{

	var xhr_object = null;
				
		if(window.XMLHttpRequest) // Firefox
		  xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
		  xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non supporté par le navigateur
		  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		  return;
			}
		
		xhr_object.open("POST", "../config/page_request.php", true);
		
		xhr_object.onreadystatechange = function() {
		  if(xhr_object.readyState == 4)
			 eval(xhr_object.responseText);
		}
		
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

		xhr_object.send(query);

}

function set_bien_type(but, type)

	{
		
		if (but == 'achat') bien_type_achat = type;
		if (but == 'location') bien_type_location = type;
		if (but == 'neuf') bien_type_neuf = type;
		
	}
	
function set_bien_region(but, region)

	{
		
		if (but == 'achat') bien_region_achat = region;
		if (but == 'location') bien_region_location = region;
		if (but == 'neuf') bien_region_neuf = region;
		
	}
	
function set_bien_prix(but, prix)

	{
		
		if (but == 'achat') bien_prix_achat = prix;
		if (but == 'location') bien_prix_location = prix;
		if (but == 'neuf') bien_prix_neuf = prix;
		
	}

function search_biens(but)

	{
		var destination = '';
		
		if (but == 'achat')
		
			{
				
				if (bien_type_achat == 0)
				
					{
						
						alert('Veuillez d\'abord choisir un type de bien!');
						$('#bien_type_achat').focus();
						
						return false;
						
					}

				destination = 'immobilier-a-vendre.html?type='+bien_type_achat+'&region='+bien_region_achat+'&prix='+bien_prix_achat+'';
				
			}
			
		if (but == 'location')
		
			{
				
				if (bien_type_location == 0)
				
					{
						
						alert('Veuillez d\'abord choisir un type de bien!');
						$('#bien_type_location').focus();
						
						return false;
						
					}

				destination = 'immobilier-a-louer.html?type='+bien_type_location+'&region='+bien_region_location+'&prix='+bien_prix_location+'';
				
			}
			
		if (but == 'neuf')
		
			{
				
				if (bien_type_neuf == 0)
				
					{
						
						alert('Veuillez d\'abord choisir un type de bien!');
						$('#bien_type_neuf').focus();
						
						return false;
						
					}

				destination = 'immobilier-neuf.html?type='+bien_type_neuf+'&region='+bien_region_neuf+'&prix='+bien_prix_neuf+'';
				
			}
			
		document.location.href = destination;
		
		return false;
	
	}
	
function refresh_localite(sel_region, type)

	{
		
		var data = "action=refresh_localite&value="+sel_region+"&type="+type;
		xml_request(data);
		
	}
	
function set_limit(limit)

	{
		
		var data = "action=set_limit&new_limit="+limit;
		xml_request(data);
		
	}
	
function next_page(cur_start)

	{
		
		var data = "action=next_page&cur_start="+cur_start;
		xml_request(data);
		
	}
	
function prev_page(cur_start)

	{
		
		var data = "action=prev_page&cur_start="+cur_start;
		xml_request(data);
		
	}
	
function submit_search()

	{
		
		var data = "action=submit_search";
		xml_request(data);
	
	}
	
function set_order(order, sens)

	{
		
		var data = "action=set_order&value="+order+"&sens="+sens;
		xml_request(data);
		
	}
	
function goto_page(e, page)

	{
		
		if (!e) var e = window.event;

		if (e && e.keyCode == 13)
			
			{
			
				var data = "action=goto_page&value="+page;
				xml_request(data);
		
			}
	
		else return true;
		
	}
	
function submit_search_cp(e)

	{
		
		if (!e) var e = window.event;

		if (e && e.keyCode == 13)
			
			{
			
				submit_search();
		
			}
	
		else return true;
		
	}
	
$(document).ready(function(){
						   
	$("#banner_bottom img").mouseenter
	
		(
		
			function()
			
				{

					var img_src = $(this).attr("src");

					if (img_src.indexOf('BW_', 0)) 
					
						{
							
							var new_src = img_src.substr(0, img_src.indexOf('BW_', 0));
							new_src = new_src + 'S_' + img_src.substr((img_src.indexOf('BW_', 0) + 3), img_src.length);
							
							$(this).attr("src", new_src);

						}
					

				}
				
		);
		
	$("#banner_bottom img").mouseleave
	
		(
		
			function()
			
				{

					var img_src = $(this).attr("src");

					if (img_src.indexOf('S_', 0)) 
					
						{
							
							var new_src = img_src.substr(0, img_src.indexOf('S_', 0));
							new_src = new_src + 'BW_' + img_src.substr((img_src.indexOf('S_', 0) + 2), img_src.length);
							
							$(this).attr("src", new_src);	
							
							
						}
					

				}
				
		);

});

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-5572315-5']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
