// -- map.js

var mapLIF = -1;
var mapTime = 0;
var mapDoc = '';

function mapInit()
 {
   if (typeof document.onmousedown == 'function')
    {
      currentFunc = document.onmousedown;
      document.onmousedown = function(e) { mapClick(e); return currentFunc(e); }
    }
   else { document.onmousedown = mapClick; }
   
   // -- on ajoute le focus event sur chaque iframe

   iframes = document.getElementsByTagName('iframe');
   for (i=0; i<iframes.length; i++)
    {
      if (typeof iframes[i].onfocus == 'function')
       {
	 currentFunc = iframes[i].onfocus;
	 iframes[i].onfocus = function(e) { mapClick(e); return currentFunc(e); }
       }
      else { iframes[i].onfocus = mapClick; }
    }

   // -- init des variables
    
   mapDoc = document.documentElement != undefined && document.documentElement.clientHeight != 0 ? document.documentElement : document.body;
 
 }

function mapClick(e)
 {
   try
    {
      // -- identification du click
     
      if (e==undefined) { e = window.event; c = e.button; element = e.srcElement; }
      else { c = e.which; element = null; }
      if (c==0) { return true; }
         
      // -- controle de click sur iframe retour popup
     
      if (element != null && element.tagName.toLowerCase() == 'iframe')
       {
         if (element.sourceIndex == mapLIF) { return true; }
  	 mapLIF = element.sourceIndex;
       }
      else { mapLIF = -1; }
      
      // -- initialisation des parametres
     
      var x = e.clientX;
      var y = e.clientY;
      var w = mapDoc.clientWidth != undefined ? mapDoc.clientWidth : window.innerWidth;
      var h = mapDoc.clientHeight != undefined ? mapDoc.clientHeight : window.innerHeight;
      var scrollx = window.pageXOffset == undefined ? mapDoc.scrollLeft : window.pageXOffset;
      var scrolly = window.pageYOffset == undefined ? mapDoc.scrollTop : window.pageYOffset;
     
      // -- controle de zone, temps de reponse (scrollbars)
     
      if (w>780) { x -= (w-780) >> 1; }
      if (x >= w || y >= h || y<0 || x<0) { return true; }
      if (x >= 780) { return true; }
      clickTime = new Date();
      if (clickTime.getTime() - mapTime < 1000) { return true; }
      mapTime = clickTime.getTime();
      
      // -- correcteur de map site MATY (centré 780)
      
      
      params = 'o=homepage&x=' + (x + scrollx) + '&y=' + (y + scrolly);
     
      // -- creation de l'objet xmlhttp
      
      var xmlhttp = false;
      try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
      catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { xmlhttp = null; } }
      if (!xmlhttp && typeof XMLHttpRequest != undefined) xmlhttp = new XMLHttpRequest();
      
      // -- transmission serveur
      
      // alert(params);
      
      if (xmlhttp)
       {
	 xmlhttp.open('GET', 'hit.aspx?' + params, true);
	 xmlhttp.setRequestHeader('Connection', 'close');
	 xmlhttp.send(null);
       }  
      
    }
   catch (ee) { alert(ee.message); return true; }

 }


 // mapInit();