
var ControlKey=false ;
var ShiftKey=false ;

document.onmousedown=OverMouseDown ;

function OverMouseDown(evt)
{
  evt=evt ||window.event ;
  if (evt.ctrlKey)
    ControlKey=true ;
  else
    ControlKey=false ;
  if (evt.shiftKey)
    ShiftKey=true ;
  else
    ShiftKey=false ;
}

function GetAjax(method, url, data)
{
  var xhr=CreateAjaxObject() ;
  if (!xhr)
  {
    alert('Pas de support Ajax') ;
    return('') ;
  }
  xhr.open(method, url, false) ;
//  alert(url+' param: '+data) ;
  if (method=='POST')
  {
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') ;
    xhr.setRequestHeader('Charset', 'UTF-8') ;
  }
  xhr.send(data) ;
//  alert(xhr.responseText) ;
  return(xhr.responseText) ;
}


function CreateAjaxObject()
{
  var xhr ;
  try
  {
    xhr=new ActiveXObject('Msxml2.XMLHTTP') ;
  }
  catch (e)
  {
    try 
    {
      xhr=new ActiveXObject('Microsoft.XMLHTTP') ;
    }
    catch (e2)
    {
      try
      {
        xhr=new XMLHttpRequest() ;
      }
      catch (e3)
      {
        xhr=false ;
      }
    }
  }
  if (typeof(geaTickAutoClose)=='function')
    geaTickAutoClose() ;
  return(xhr) ;
}

function _(x) { var v=document.getElementById(x) ; /*if (!v) alert('No element with id '+x) ; else */return(v) ; }

var GeaOpenMenuBtn=false ;
var GeaOpenMenuBtnClassName='' ;
var GeaOpenMenuSpnClassName='' ;
var GeaOpenMenuTmt=false ;


function StartGeaCloseMenu(from)
{
  GeaOpenMenuTmt=setTimeout("GeaOpenMenuCloseMenu('"+from+"')", 325) ;
}

function StartGeaOpenMenu(from, tposi)
{
  var btn=_('a'+from) ;
  var spn=_('s'+from) ;
  var dv=_('div_'+from) ;
  
  if (dv.style.display=='')
  {
    GeaOpenMenuCloseMenu(from) ;
  }
  else
  {
    if (GeaOpenMenuBtn) { GeaOpenMenuNoClose(from) ; GeaOpenMenuCloseMenu(from) ; }
    var x=btn.offsetLeft ;
    var y=btn.offsetTop ;
    switch (tposi)
    {
      case 'bottom' : y+=btn.offsetHeight ; break ;
      case 'right' : x+=btn.offsetWidth ; break ;
      case 'bottom-right' : x+=btn.offsetWidth-dv.offsetWidth ; y+=btn.offsetHeight ; break ;
    } 
    dv.style.display='' ;
    dv.style.left=x+'px' ;
    dv.style.top=y+'px' ;
    dv.style.zIndex=901 ;
    if (btn)
    {
      GeaOpenMenuBtnClassName=btn.className ;
      btn.className=GeaOpenMenuBtnClassName+'Over' ;
    }
    if (spn)
    {
      GeaOpenMenuSpnClassName=spn.className ;
      spn.className=GeaOpenMenuSpnClassName+'Over' ;
    }
    GeaOpenMenuBtn=from ;
  }
}

function GeaOpenMenuCloseMenu(from)
{
  var btn=_('a'+GeaOpenMenuBtn) ;
  var spn=_('s'+GeaOpenMenuBtn) ;
  if (btn)
    btn.className=GeaOpenMenuBtnClassName ;
  if (spn)
    spn.className=GeaOpenMenuSpnClassName ;
  var dv=_('div_'+GeaOpenMenuBtn) ;
  if (dv)
    dv.style.display='none' ;
  GeaOpenMenuBtn=false ;
}

function GeaOpenMenuNoClose(from)
{
  if (GeaOpenMenuTmt)
  {
    clearTimeout(GeaOpenMenuTmt) ;
    GeaOpenMenuTmt=0 ;
  }
}


function AutoImageChanger(name, id, tab, tempo, mtempo)
{
  this.ID=id ;
  this.ImgsSrcs=tab ;
  this.Imgs=new Array() ;
  this.objName=name ;
  this.Icurrent=0 ;
  this.nTick=0 ;
  this.mTempo=mtempo ;
  this.pct=0 ;
  this.ImageLoaded=function(i)
  {
//    document.getElementById(this.ID).src=this.Imgs[i].src ;
    this.AnimateToNext() ;
    this.ACItmt=setTimeout(this.objName+".Tick()", this.tempo) ;
  }
  for (i=0;i<this.ImgsSrcs.length;i++)
  {
    var lImage=new Image() ;
    lImage.aci=this ;
    lImage.indx=i ;
    lImage.onload=function()
    {
      this.aci.ImageLoaded(this.indx) ;
    }
    this.Imgs[i]=lImage ;
  }
  this.tempo=tempo ;
  this.Start=function()
  {
    this.ACItmt=setTimeout(this.objName+".Tick()", this.tempo) ;
  }
  this.Tick=function()
  {
    this.nTick++ ;
//    if (this.nTick>60) return ;
    // passage au suivant
    this.Icurrent=(this.Icurrent+1)%this.Imgs.length ;
    i=this.Icurrent ;
    if (typeof this.Imgs[i].src=='undefined' || this.Imgs[i].src=='')
    {
      this.Imgs[i].src=this.ImgsSrcs[i] ;
    }
    else
    {
      this.AnimateToNext() ;
//      document.getElementById(this.ID).src=this.Imgs[i].src ;
      this.ACItmt=setTimeout(this.objName+".Tick()", this.tempo) ;
    }
  }
  this.AnimateToNext=function()
  {
    var lb=document.getElementById('lbody') ;
    if (lb)
      lb.style.background='black' ;
    this.ACIani=setTimeout(this.objName+".AniToNext(0)", this.mTempo) ;
  }
  this.AniToNext=function(i)
  {
    if (i<100)
    {
      if (document.all)
        document.getElementById(this.ID).style.filter='alpha(opacity:'+(100-i)+')' ;
      else
        document.getElementById(this.ID).style.opacity=(0.1*(100-i)) ;
    }
    else if (i>=100)
    {
      if (i==100) document.getElementById(this.ID).src=this.Imgs[this.Icurrent].src ;
      if (document.all)
        document.getElementById(this.ID).style.filter='alpha(opacity:'+(i-100)+')' ;
      else
        document.getElementById(this.ID).style.opacity=(0.1*(i-100)) ;
    }
    i+=5 ;
    if (i<=200)
      this.ACIani=setTimeout(this.objName+".AniToNext("+i+")", this.mTempo) ;
  }
}


function getDisplaySize()
{
  if (typeof(window.innerWidth) == 'number')
  {
    //Non-IE
    dspWidth = window.innerWidth;
    dspHeight = window.innerHeight;
  } 
  else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
  {
    //IE 6+ in 'standards compliant mode'
    dspWidth = document.documentElement.clientWidth;
    dspHeight = document.documentElement.clientHeight;
  }
  else if (document.body && ( document.body.clientWidth || document.body.clientHeight)) 
  {
    //IE 4 compatible
    dspWidth = document.body.clientWidth;
    dspHeight = document.body.clientHeight;
  }
}

function geaMosaicImage(url)
{
  document.body.style.background="url('"+url+"')" ;
}

function geaAdjustImage(did, id, wim, him)
{
  getDisplaySize() ;
  if (document.getElementById('iManager'))
  {
    dspWidth-=8 ;
    dspHeight-=124 ;
  }
  var im=document.getElementById(id) ;
  var rx=1.0*dspWidth/wim ;
  var ry=1.0*dspHeight/him ;
  if (ry>rx) rx=ry ;
  var ww=wim*rx ;
  var hh=him*rx ;
  var lf=1.0*dspWidth/2-1.0*ww/2 ;
  var tp=1.0*dspHeight/2-1.0*hh/2 ;
  im.style.width=''+ww+'px' ;
  im.style.height=''+hh+'px' ;
  im.style.left=''+lf+'px' ;
  im.style.top=''+tp+'px' ;
  im.style.display='' ;
  var dv=document.getElementById(did) ;
  dv.style.width=''+(dspWidth-0)+'px' ;
  dv.style.height=''+(dspHeight-0)+'px' ;
  dv.style.left=''+0+'px' ;
  dv.style.top=''+0+'px' ;
}

function geaFilledImage(id)
{
  getDisplaySize() ;
  var im=document.getElementById(id) ;
  im.style.width=''+(dspWidth-0)+'px' ;
  im.style.height=''+(dspHeight-0)+'px' ;
  im.style.left=''+0+'px' ;
  im.style.top=''+0+'px' ;
  im.style.display='' ;
}
 
sprintfWrapper = {
 
  init : function () {
 
    if (typeof arguments == "undefined") { return null; }
    if (arguments.length < 1) { return null; }
    if (typeof arguments[0] != "string") { return null; }
    if (typeof RegExp == "undefined") { return null; }
 
    var string = arguments[0];
    var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g);
    var matches = new Array();
    var strings = new Array();
    var convCount = 0;
    var stringPosStart = 0;
    var stringPosEnd = 0;
    var matchPosEnd = 0;
    var newString = '';
    var match = null;
 
    while (match = exp.exec(string)) {
      if (match[9]) { convCount += 1; }
 
      stringPosStart = matchPosEnd;
      stringPosEnd = exp.lastIndex - match[0].length;
      strings[strings.length] = string.substring(stringPosStart, stringPosEnd);
 
      matchPosEnd = exp.lastIndex;
      matches[matches.length] = {
        match: match[0],
        left: match[3] ? true : false,
        sign: match[4] || '',
        pad: match[5] || ' ',
        min: match[6] || 0,
        precision: match[8],
        code: match[9] || '%',
        negative: parseInt(arguments[convCount]) < 0 ? true : false,
        argument: String(arguments[convCount])
      };
    }
    strings[strings.length] = string.substring(matchPosEnd);
 
    if (matches.length == 0) { return string; }
    if ((arguments.length - 1) < convCount) { return null; }
 
    var code = null;
    var match = null;
    var i = null;
 
    for (i=0; i<matches.length; i++) {
 
      if (matches[i].code == '%') { substitution = '%' }
      else if (matches[i].code == 'b') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(2));
        substitution = sprintfWrapper.convert(matches[i], true);
      }
      else if (matches[i].code == 'c') {
        matches[i].argument = String(String.fromCharCode(parseInt(Math.abs(parseInt(matches[i].argument)))));
        substitution = sprintfWrapper.convert(matches[i], true);
      }
      else if (matches[i].code == 'd') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)));
        substitution = sprintfWrapper.convert(matches[i]);
      }
      else if (matches[i].code == 'f') {
        matches[i].argument = String(Math.abs(parseFloat(matches[i].argument)).toFixed(matches[i].precision ? matches[i].precision : 6));
        substitution = sprintfWrapper.convert(matches[i]);
      }
      else if (matches[i].code == 'o') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(8));
        substitution = sprintfWrapper.convert(matches[i]);
      }
      else if (matches[i].code == 's') {
        matches[i].argument = matches[i].argument.substring(0, matches[i].precision ? matches[i].precision : matches[i].argument.length)
        substitution = sprintfWrapper.convert(matches[i], true);
      }
      else if (matches[i].code == 'x') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
        substitution = sprintfWrapper.convert(matches[i]);
      }
      else if (matches[i].code == 'X') {
        matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
        substitution = sprintfWrapper.convert(matches[i]).toUpperCase();
      }
      else {
        substitution = matches[i].match;
      }
 
      newString += strings[i];
      newString += substitution;
 
    }
    newString += strings[i];
 
    return newString;
 
  },
 
  convert : function(match, nosign){
    if (nosign) {
      match.sign = '';
    } else {
      match.sign = match.negative ? '-' : match.sign;
    }
    var l = match.min - match.argument.length + 1 - match.sign.length;
    var pad = new Array(l < 0 ? 0 : l).join(match.pad);
    if (!match.left) {
      if (match.pad == "0" || nosign) {
        return match.sign + pad + match.argument;
      } else {
        return pad + match.sign + match.argument;
      }
    } else {
      if (match.pad == "0" || nosign) {
        return match.sign + match.argument + pad.replace(/0/g, ' ');
      } else {
        return match.sign + match.argument + pad;
      }
    }
  }
}
 
sprintf = sprintfWrapper.init;
