﻿
var loaded=false;
var entite="";
var valeur="";


function inject(params, dest){
    var xmlhttp = new XMLHttpRequest();    
    xmlhttp.open("POST", "./PageLoader.aspx", false);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(params);    
    document.getElementById(dest).innerHTML=xmlhttp.responseText;
}

//bug inexpliqué (inexpliquable ?) de IE
window.onresize = function(){
    document.getElementById("block_legende").style.display="none";
    document.getElementById("block_legende").style.display="block";
}


  
//affectation d'un cookie      
function EcrireCookie(nom, valeur)
{
    var argv=EcrireCookie.arguments;
    var argc=EcrireCookie.arguments.length;
    var expires=(argc > 2) ? argv[2] : null;
    var path=(argc > 3) ? argv[3] : null;
    var domain=(argc > 4) ? argv[4] : null;
    var secure=(argc > 5) ? argv[5] : false;
    document.cookie=nom+"="+escape(valeur)+
            ((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
            ((path==null) ? "" : ("; path="+path))+
            ((domain==null) ? "" : ("; domain="+domain))+
            ((secure==true) ? "; secure" : "");
}

//lecture d'un cookie
function getCookieVal(offset)
{
    var endstr=document.cookie.indexOf (";", offset);
    if (endstr==-1) endstr=document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function LireCookie(nom)
{
    var arg=nom+"=";
    var alen=arg.length;
    var clen=document.cookie.length;
    var i=0;
    while (i<clen)
    {
        var j=i+alen;
        if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
        i=document.cookie.indexOf(" ",i)+1;
        if (i==0) break;

    }
    return null;
}

//inversion du contenu de 2 tr identiques structurellment
// marche pas direct avec ie
function switch_tr(tr1,tr2){
    try{
        for (var i=0;i<tr1.childNodes.length;i++){
            var tmp = tr1.childNodes[i].innerHTML;
            tr1.childNodes[i].innerHTML=tr2.childNodes[i].innerHTML;
            tr2.childNodes[i].innerHTML=tmp;
        }
    } catch(e){}
}


//opacity selector

var ie=document.all;
var nn6=!ie;//document.getElementById&&!document.all;
var isdrag=false;
var x,y,nx=0,ny=0;
var dobj;
var inter;
var mouse;

function movemouse(e)

{
  if (isdrag)
  {
      mouse = new Array(nn6 ? tx + e.clientX - x : tx + event.clientX - x, nn6 ? ty + e.clientY - y : ty + event.clientY - y);
      move();//if (!inter) inter = setInterval(move,12);
  }
 }
  
function move(){
var k=1;
nx = ((1-k)*nx+k*mouse[0]);
ny = ((1-k)*ny+k*mouse[1]);
if (!isdrag && nx==mouse[0] && ny==mouse[1])
    clearInterval(inter);

  if (dobj.id.indexOf("opacityCursor_")>0){
      if (nx>72)
        nx=72;
      if (nx<0)
        nx=0;
        nx = (nx+parseInt(dobj.style.left.split("px")[0]))/2;
        ny = (ny+parseInt(dobj.style.top.split("px")[0]))/2;
      dobj.style.left = nx+'px';
      var pcent = 100*nx/72+"";
      pcent = pcent.split(".")[0];
      dobj.title = pcent + "%";
      config.objects.mainMap.changeOpacity(dobj.id.substring(22),nx/72);
  }
  else{
    if (dobj.id.indexOf("movable_header_")>=0){
        dobj.parentNode.style.left = nx+'px';
        dobj.parentNode.style.top = ny+'px';
    }
    else{
        dobj.style.left = nx+'px';
        dobj.style.top = ny+'px';
    }
  }
    return false;
  
}

function selectmouse(e)
{    
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";
  if (fobj.id.indexOf("close")>=0)
    return;
    try{
      while (fobj.tagName != topelement && fobj.id.indexOf("movable_")<0)
      {
        fobj = nn6 ? fobj.parentNode : fobj.parentElement;
      }
    }catch(ev){
        return;
    }
  if (fobj.id.indexOf("movable_")==0)
  {    
    isdrag = true;
    dobj = fobj;
     if (dobj.id.indexOf("movable_header_")>=0){
        tx = parseInt(dobj.parentNode.style.left+0);
        ty = parseInt(dobj.parentNode.style.top+0);
        var div = document.createElement("div");
        div.style.position = "absolute";
        div.id = "blocker";
        var h = window.pageYOffset;
        if (!h)
            h = document.body.scrollTop;    
        div.style.top=h+"px";
        var w = window.pageXOffset;
        if (!w)
            w = document.body.scrollLeft;    
        div.style.left=w+"px";
        div.style.zIndex="1000000";
        div.style.border="0px";
        h = window.innerHeight
        if (!h)
            h = document.body.clientHeight;    
        div.style.height=h+"px";
        var w = window.innerWidth;
        if (!w)
            w = document.body.clientWidth;    
        div.style.width=w+"px";
        div.style.filter="alpha(opacity=0)";
        div.style.opacity="0";
        div.style.backgroundColor="blue";
        document.body.appendChild(div);
    }
    else{
        tx = parseInt(dobj.style.left+0);
        ty = parseInt(dobj.style.top+0);        
    }    
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    
    document.onmousemove=movemouse;
    return false;
  }
}

document.onmousedown=selectmouse;
document.onmouseup= function(){
if (isdrag){
    isdrag=false;
    var blocker = document.body.lastChild;
    if (blocker.id=="blocker")
        document.body.removeChild(blocker);
    }
};