// JavaScript Document

var xhr = null;

var good = "true";

 

// Fonction de creation de l'objet XMLHttpRequest qui resservira pour chaques fonctions AJAX

function getXhr()

 {

  if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 

  else if(window.ActiveXObject)

   {  

    try

     {

      xhr = new ActiveXObject("Msxml2.XMLHTTP");

     }

    catch (e)

     {

      xhr = new ActiveXObject("Microsoft.XMLHTTP");

     }

   }

  else 

   { 

    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour"); 

    xhr = false; 

   } 

 }

 

 

 function ajaxSortAdress(section)

 {

	getXhr();

	xhr.onreadystatechange = function()

	{

		if(xhr.readyState == 4 && xhr.status == 200)

		{

			var fois=0;

			var reponse = xhr.responseText;

			var block = reponse.split("<BLOCK>");

			var etbl = [];

			var etbl1 = [];

			

			for(z=1;z<block.length;z++)

			{

				var balise = "";

				var balise = block[z].split("<BALISE>");

				

				etbl[z]=[balise[5],balise[2]];

				etbl1[z]=[balise[6]];

			}

			

			if(section == "mapBig")

				recupereArray2(etbl,etbl1);

			else

				recupereArray(etbl,etbl1);

		}

	}

	

	xhr.open("POST",'includes/js/ajax.php',true);

    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

  

    xhr.send("action=sortAdress");

 }

 

 function createMarkerAlone()

 {

	getXhr();

	xhr.onreadystatechange = function()

	{

		if(xhr.readyState == 4 && xhr.status == 200)

		{

			var fois=0;

			var reponse = xhr.responseText;

			var block = reponse.split("<BLOCK>");

			geocoder.getLatLng(block[1],function(point) {

				if (point)

				{
					if(point == "(45.516735, -73.332545)")
					{
						point= new GLatLng(48.4753681, -71.6478109);
					}
					
					if(point == "(45.5167957, -73.332562)")
					{
						point= new GLatLng(48.4753681, -71.6478109);
					}
					

					good="true";

					map.setCenter(point, 9);

					var baseIcon      = new GIcon(G_DEFAULT_ICON);

						

					baseIcon.image      = "icon-home.png";

						

					baseIcon.iconSize   = new GSize(20, 19);

					baseIcon.iconAnchor = new GPoint(10,10);

					baseIcon.shadow     = "";

					var markerOptions = { icon:baseIcon };

					var marker=new GMarker(point, markerOptions);

					

					map.addOverlay(marker);

				}

				else

				{

					withAdress(block[0],"oui",1);

				}

			});

		}

	}

	

	xhr.open("POST",'includes/js/ajax.php',true);

    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

	var id = $('map2').className;

  

    xhr.send("action=sortAdressAlone&id="+id);

 }

 

 

 function proprieteVedetteChange()

 {

  getXhr();

  xhr.onreadystatechange = function()

   {

    if(xhr.readyState == 4 && xhr.status == 200)

     {

		var reponse = xhr.responseText;

		var block = reponse.split("<BLOCK>");

		

		for(x=1;x<block.length;x++)

		{

			var balise = block[x].split("<BALISE>");

			$('blockVedetteCtn'+x).innerHTML = '<p class="image"><img src="reception/data/SIA/'+balise[1]+'" width="140" alt="'+balise[3]+'" /></p>' +

				'<p>'+balise[2]+'</p>' +

                '<p>'+balise[3]+', Qc</p>' +

                '<p class="btnInfo"><a href="?ref=fiche.php&id='+balise[4]+'" class="btnInfo">' +

                    '<span class="btnLeft"></span>' +

                    '<span class="btn">+ INFOS</span>' +

                    '<span class="pictoInfo"></span>' +

                '</a></p>';

		}

		

		proprieteVedetteShow(1);

     }

   }

   

  xhr.open("POST",'includes/js/ajax.php',true);

  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

  

  xhr.send("action=proprieteVedetteChange");

 }

 

 function getCtn(section)

 {

	getXhr();

	xhr.onreadystatechange = function()

	{

		if(xhr.readyState == 4 && xhr.status == 200)

		{

			$('lightbox').innerHTML = xhr.responseText;

		}

	}

	

	xhr.open("POST",'includes/js/ajax.php',true);

    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

  

    xhr.send("action=getCtn&section="+section);

 }

 

 function getCtn2(section,id)

 {

	getXhr();

	xhr.onreadystatechange = function()

	{

		if(xhr.readyState == 4 && xhr.status == 200)

		{

			$('lightbox2').innerHTML = xhr.responseText;

		}

	}

	

	xhr.open("POST",'includes/js/ajax.php',true);

    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

  

    xhr.send("action=getCtn&section="+section+"&id="+id);

 }