///////////////////////////////////////////////////////////////////////////////
// Inits
///////////////////////////////////////////////////////////////////////////////

document.write('<LINK href="XWebDesignor.css" type=text/css rel=stylesheet>');

///////////////////////////////////////////////////////////////////////////////
// Speciales routines
///////////////////////////////////////////////////////////////////////////////

//trim n'est pas supporté dans IE8

String.prototype.trim = function()
{
  return this.replace(/(^\s*)|(\s*$)/g,'');
}

///////////////////////////////////////////////////////////////////////////////
// Globales routines
///////////////////////////////////////////////////////////////////////////////


function getQueryField(fieldName)
{
  var s=document.location.search;
  var s=s.substr(1);
  var fields=s.split("&");
  for (var i=0;i<fields.length;i++)
  {
    var field=fields[i];
    var p=field.indexOf("=");
    var name=field.substr(0,p);
    if (name==fieldName)
      return unescape(field.substr(p+1));
  }
  return "";
}

function urlDecode(str)
{
  str=str.replace(new RegExp('\\+','g'),' ');
  return unescape(str);
}

function urlEncode(str)
{
  str=escape(str);
  str=str.replace(new RegExp('\\+','g'),'%2B');
  return str.replace(new RegExp('%20','g'),'+');
}

///////////////////////////////////////////////////////////////////////////////
// Cookies routines
///////////////////////////////////////////////////////////////////////////////

function setCookie (name, value)
{
  var argv = setCookie.arguments;
  var argc = setCookie.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 = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset)
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name)
{
  var arg = name + "=";
  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;
}


///////////////////////////////////////////////////////////////////////////////
// Base64 routines
///////////////////////////////////////////////////////////////////////////////

var Base64 =
{

  // private property
  _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

  // public method for encoding
  encode : function (input)
  {
    var output = "";
    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
    var i = 0;

    input = Base64._utf8_encode(input);

    while (i <input.length) {

      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
        enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
        enc4 = 64;
      }

      output = output +
      this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
      this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

    }

    return output;
  },

  // public method for decoding
  decode : function (input)
  {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    while (i <input.length) {

      enc1 = this._keyStr.indexOf(input.charAt(i++));
      enc2 = this._keyStr.indexOf(input.charAt(i++));
      enc3 = this._keyStr.indexOf(input.charAt(i++));
      enc4 = this._keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
        output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
        output = output + String.fromCharCode(chr3);
      }

    }

    output = Base64._utf8_decode(output);

    var s=output;
    output='';
    for (var i=0;i<s.length;i++)
      if (s.charCodeAt(i)!=0)
        output+=s.charAt(i);
    return output;
  },

  // private method for UTF-8 encoding
  _utf8_encode : function (str) {

    str = str.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n <str.length; n++) {

      var c = str.charCodeAt(n);

      if (c <128) {
        utftext += String.fromCharCode(c);
      }
      else if((c > 127) && (c <2048)) {
        utftext += String.fromCharCode((c >> 6) | 192);
        utftext += String.fromCharCode((c & 63) | 128);
      }
      else {
        utftext += String.fromCharCode((c >> 12) | 224);
        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
        utftext += String.fromCharCode((c & 63) | 128);
      }
    }
    return utftext;
  },

  // private method for UTF-8 decoding
  _utf8_decode : function (utftext) {
    var str = "";
    var i = 0;
    var c = c1 = c2 = 0;

    while ( i <utftext.length ) {

      c = utftext.charCodeAt(i);

      if (c <128) {
        str += String.fromCharCode(c);
        i++;
      }
      else if((c > 191) && (c <224)) {
        c2 = utftext.charCodeAt(i+1);
        str += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
        i += 2;
      }
      else {
        c2 = utftext.charCodeAt(i+1);
        c3 = utftext.charCodeAt(i+2);
        str += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
        i += 3;
      }
    }
    return str;
  }
}


///////////////////////////////////////////////////////////////////////////////
// XWD Object
///////////////////////////////////////////////////////////////////////////////

XWD = function()
{
  this.modalWinU=null;
  this.modalWin=null;
  this.scrollContentTimer=null;
}

XWD.prototype.isLocalMode = function(showMessage)
{
  var localMode=(location.href.substr(0,4)=="file");
  if (localMode && showMessage)
    this.alert("Accès impossible en prévisualisation.<br>Vous devez publier votre site pour utiliser cette fonctionnalité.");
  return localMode;
}

XWD.prototype.isNumeric = function(sText)
{
  var validChars = '0123456789.';
  var char;

  for (i = 0; i <sText.length; i++)
  {
    char = sText.charAt(i);
    if (validChars.indexOf(char) == -1)
      return false;
  }
  return true;
}

XWD.prototype.isGoodValue = function(type,value,showMessage) // type:email,numeric
{
  var emailC= /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/ ;
  var ok=false;
  if (type=="email")
  {
    var ok=emailC.test(value);
    if (!ok)
    {
      if (showMessage)
        this.alert("Adresse Email incorrecte","");
      return false;
    }
  }
  else if (type=="numeric")
  {
    if (!this.isNumeric(value))
    {
      if (showMessage)
        this.alert("Valeur non numérique","Erreur");
      return false;
    }
  }
  return true;
}

XWD.prototype.getURLTimeStamp = function ()
{
  var date = new Date();
  var time = date.getHours()+'/'+date.getMinutes()+'/'+date.getSeconds();
  return "&time="+escape(time);
}

XWD.prototype.getDataFromWeb = function (url)
{
  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("GET", url, false);
  try
  {
    xhr_object.send(null);
  }
  catch(e){}
  if(xhr_object.readyState == 4)
    return xhr_object.responseText;
  else
    return "";
}

XWD.prototype.open = function(url,title,width,height)
{
  if (this.modalWinU == null)
    this.modalWinU = new DialogBox(true);
  if (typeof(title)=="undefined")
    title=url;
  if (typeof(width)!="undefined")
    this.modalWinU.setWidth(width);
  this.modalWinU.setTitle(title);
  if (typeof(height)!="undefined")
    this.modalWinU.setUrl(url,height);
  else
    this.modalWinU.setUrl(url);
  this.modalWinU.show();
  this.modalWinU.moveTo(-1,-1);
}

XWD.prototype.openForm = function(formId,title)
{
  var frm=document.getElementById(formId);
  if (frm==null)
  {
    alert('openForm error : "'+formId+'" not found');
    return;
  }
  if (this.modalWinU == null)
    this.modalWinU = new DialogBox(true);
  if (typeof(title)=="undefined")
    title="Information";
  this.modalWinU.setTitle(title);
  var url=frm.action+"?";
  for (var i=0;i<frm.length;i++)
    url+=frm.elements[i].name+"="+escape(frm.elements[i].value)+"&";
  this.modalWinU.setUrl(url);
  this.modalWinU.show();
  this.modalWinU.moveTo(-1,-1);
}

XWD.prototype.show = function(text,title)
{
  if (this.modalWin == null)
    this.modalWin = new DialogBox(true);
  if (typeof(title)=="undefined")
    title="";
  this.modalWin.setTitle(title);
  this.modalWin.setContent(text);
  this.modalWin.show();
  this.modalWin.moveTo(-1,-1);
}

XWD.prototype.hide = function()
{
  if (this.modalWin != null)
    this.modalWin.hide(true);
  if (this.modalWinU != null)
    this.modalWinU.hide(true);
}

var xwdtmp=null;
XWD.prototype.alert = function(text,title)
{
  if (typeof(title)=="undefined")
    title="Information";
  xwdtmp=this;
  text+='<br><br><center><form><input id="btnClose" type="button" onclick="xwdtmp.hide()" value="  Ok  "></form></center>';
  this.show(text,title);
}


XWD.prototype.showBackDiv = function()
{
  if (this.modalWin == null)
    this.modalWin = new DialogBox(true);
  this.modalWin.backDiv.style.display = "block";

}

XWD.prototype.hideBackDiv = function()
{
  if (this.modalWin != null)
    this.modalWin.backDiv.style.display = "none";
}

///////////////////////////////////////////////////////////////////////////////
// XWD object scrollbar
///////////////////////////////////////////////////////////////////////////////

//Private
XWD.prototype.verticalScrollContent = function(step,direction,containerId)
{
  var container=document.getElementById(containerId);
  var content=document.getElementById('_'+containerId+'Content');
  var imgUp=document.getElementById('_'+containerId+'Up');
  var imgDown=document.getElementById('_'+containerId+'Down');
  var top=parseInt(content.style.top);
  if (top + (step*direction)>0)
  {
    imgUp.style.display='none';
    imgDown.style.display='';
    this.stopAutoScrollContent();
    content.style.top=0;
  }
  else if (top + (step*direction)<-(content.offsetHeight-container.offsetHeight))
  {
    imgUp.style.display='';
    imgDown.style.display='none';
    this.stopAutoScrollContent();
    content.style.top=-(content.offsetHeight-container.offsetHeight);
  }
  else
  {
    imgUp.style.display='';
    imgDown.style.display='';
    content.style.top = (top + (step*direction)) + "px";
  }
}

//Private
XWD.prototype.stopAutoScrollContent = function()
{
  clearTimeout(this.scrollContentTimer);
}

//Private
XWD.prototype.verticalAutoScrollContent = function(step,direction,containerId)
{
  this.verticalScrollContent(step,direction,containerId);
  this.scrollContentTimer = setTimeout('xwd.verticalAutoScrollContent(' + step + ',' + direction + ',"'+containerId+'");', 30);
}

//Public
XWD.prototype.addVerticalScroll = function(containerId,imgUp,imgDown)
{
  var contentId='_'+containerId+'Content';
  if (document.getElementById(contentId)!=null)
    return;
  var container=document.getElementById(containerId);
  var content=container.innerHTML;
  container.innerHTML='';

  var contentDiv = document.createElement('div');
  container.appendChild(contentDiv);
  contentDiv.id=contentId;
  contentDiv.style.position='absolute';
  contentDiv.style.top=0;
  contentDiv.style.width=container.offsetWidth+'px';
  contentDiv.innerHTML=content;

  if (container.offsetHeight<contentDiv.offsetHeight)
  {
    var step=container.offsetHeight/2;
    container.style.overflow='hidden';

    var sbDiv = document.createElement('div');
    container.appendChild(sbDiv);
    sbDiv.style.height='100%';
    sbDiv.style.position='absolute';
    sbDiv.style.right=0;

    var img = document.createElement('img');
    sbDiv.appendChild(img);
    img.id='_'+containerId+'Up';
    img.src=imgUp;
    img.style.cursor='pointer';
    img.style.position='absolute';
    img.style.right='0pt';
    img.style.bottom='18pt';
    img.style.display='none';
    img.onclick=function(){xwd.stopAutoScrollContent();xwd.verticalScrollContent(step,1,containerId);};
    img.onmouseover=function(){xwd.verticalAutoScrollContent(3,1,containerId);};
    img.onmouseout=function(){xwd.stopAutoScrollContent();};

    img = document.createElement('img');
    sbDiv.appendChild(img);
    img.id='_'+containerId+'Down';
    img.src=imgDown;
    img.style.cursor='pointer';
    img.style.position='absolute';
    img.style.right='0pt';
    img.style.bottom='0pt';
    img.onclick=function(){xwd.stopAutoScrollContent();xwd.verticalScrollContent(step,-1,containerId)};
    img.onmouseover=function(){xwd.verticalAutoScrollContent(3,-1,containerId);};
    img.onmouseout=function(){xwd.stopAutoScrollContent();};
  }
}

///////////////////////////////////////////////////////////////////////////////
// Glossary routines
///////////////////////////////////////////////////////////////////////////////

var timerHideGlossary=null;
var glossaryTips=null;

function findPos(obj)
{
  var curleft = curtop = 0;
  if (obj.offsetParent)
  {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent)
    {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
   }
   return [curleft,curtop];
}

function hideGlossary()
{
  glossaryTips.style.display="none";
}

function showGlossary(n)
{
  var sender=this;

  var key=sender.innerHTML.toUpperCase().trim();
  var txt="";
  for (var i=0;i<glossaryDic.length;i++)
  {
    if (glossaryDic[i][0]==key)
    {
      txt=glossaryDic[i][1];
      break;
    }
  }
  if (glossaryTips==null)
  {
    glossaryTips=document.createElement("div");
    glossaryTips.id="glossaryTips";
    glossaryTips.style.display="none";
    glossaryTips.style.zIndex=99999;
    document.body.appendChild(glossaryTips);
  }
  if (txt!="")
  {
    pos=findPos(sender);
    glossaryTips.style.left=pos[0]+20;
    glossaryTips.style.top=pos[1]+30;
    glossaryTips.innerHTML=txt;
    glossaryTips.style.display="inline";
    if (timerHideGlossary!=null)
      clearTimeout(timerHideGlossary);
    timerHideGlossary=setTimeout("hideGlossary()",5000);
  }
}

function initGlossary()
{
  var spans=document.getElementsByTagName("span");
  for (i=0;i<spans.length;i++)
  {
    if (spans[i].className=="glossary")
    {
      spans[i].onmouseover=showGlossary;
      spans[i].onmouseout=hideGlossary;
    }
  }
}

///////////////////////////////////////////////////////////////////////////////

var xwd=new XWD();
if (!xwd.isLocalMode(false) && 'WEB'=='LOCAL')
  alert('ATTENTION ce site a été construit en MODE LOCAL.Veuillez le publier correctement');
document.oncontextmenu = null;


///////////////////////////////////////////////////////////////////////////////
// Speciales routines
///////////////////////////////////////////////////////////////////////////////

function writeHTMLPage(txt)
{
  txt=unescape(txt)
  document.write(txt);
// document.write(unescape(s)); => est détecté comme virus HEUR/HTML.Malware par Avira
}

function disableRightClick()
{
  return(false);
}


var accounts=[];
var pwds=[];
var autorisedUsers="";

function showHTMLPage()
{
  document.getElementById('protectionPageDiv').style.visibility = 'visible';
}

function verifyLogon(_autorisedUsers)
{
  var ok=false;
  if (accounts.length==0)
    ok=true;
  else
  {
    autorisedUsers=_autorisedUsers;
    var account=getCookie('account');
    var pwd=getCookie('pwd');
    s=Base64.decode(autorisedUsers);
    if (s=='')
      return;
    ok=(account!=null);
    if (ok)
    {
      ok=false;
      var users=s.split('|');
      for (i=0;i<users.length;i++)
      {
        if (users[i]==Base64.decode(account))
          ok=true;
      }
      if (ok)
      {
        ok=false;
        for (i=0;i<accounts.length;i++)
          if (accounts[i]==account && pwds[i]==pwd)
            ok=true;
      }
    }
  }
  if (!ok)
    showLogon();
  else
    setTimeout('showHTMLPage();',100);
}

function logon()
{
  setCookie('account','');
  setCookie('pwd','');
  var account=document.getElementById('account');
  var pwd=document.getElementById('pwd');
  var msg=document.getElementById('msg');
  if (account.value=='')
  {
    msg.innerHTML='Compte obligatoire';
    account.focus();
    return;
  }
  var ok=false;
  for (i=0;i<accounts.length;i++)
   if (Base64.decode(accounts[i])==account.value)
     ok=true;
  if (!ok)
  {
    msg.innerHTML='Compte inconnu';
    account.focus();
    return;
  }
  s=Base64.decode(autorisedUsers);
  if (s!='')
  {
    users=s.split('|');
    ok=false;

    for (i=0;i<users.length;i++)
    {
      if (users[i]==account.value)
        ok=true;
    }
    if (!ok)
    {
      msg.innerHTML='Compte non autorisé dans cette page';
      account.focus();
      return;
    }
  }
  for (i=0;i<accounts.length;i++)
  {
    if (Base64.decode(accounts[i])==account.value
        && Base64.decode(Base64.decode(pwds[i]))==pwd.value)
    {
      setCookie('account',accounts[i]);
      setCookie('pwd',pwds[i]);
      location.reload();
      return;
    }
  }
  msg.innerHTML='Mot de passe incorrect';
  pwd.focus();
}

function showLogon()
{
  document.clear();
  document.write('<table width="100%" height="100%">');
  document.write('  <tr align="center" valign="center"><td>');
  document.write('    <form action="javascript:logon()">');
  document.write('      <table width="300" bgcolor="silver" style="border-style:solid">');
  document.write('      <tr>');
  document.write('        <td colspan="2" align="center"><b></b></td>');
  document.write('      </tr>');
  document.write('      <tr >');
  document.write('        <td colspan="2" align="center"><b><p id="msg" style="color:red"></p></b></td>');
  document.write('      </tr>');
  document.write('      <tr>');
  document.write('       <td align="right">Compte : </td><td><input id="account" type="text"></td>');
  document.write('      </tr>');
  document.write('      <tr>');
  document.write('        <td align="right">Mot de passe : </td><td><input id="pwd" type="password"></td>');
  document.write('      </tr>');
  document.write('      <tr height="50">');
  document.write('        <td colspan="2" align="center"><input type="submit" value="Connecter"></td>');
  document.write('      </tr>');
  document.write('    </table>');
  document.write('   </form>');
  document.write('</td></tr>');
  document.write('</table>');
  document.close();
  document.getElementById('account').focus();
}



function initXWD()
{
  verifyFilesIntegrity();
  setTimeout("verifyFilesIntegrity()",15000);
}

function verifyFilesIntegrity()
{
  var s;
  if (typeof(document.documentElement.outerHTML)!="undefined")
    s=document.documentElement.outerHTML;
  else
    s=document.all[0].innerHTML;
  var p=s.toLowerCase().indexOf("<"+"/script>");
  var msgError="The integrity of NeutSSoftware copyrighted files is corrupt";
  if (p<0)
    alert(msgError);
  else
  {
    s=s.substr(0,p);
    if (s.indexOf('XWebDesignor.js"')<0)
      alert(msgError);
    else if (s.indexOf('trackingcode')<0)
      alert(msgError);
    else
      document.getElementById("mainContainer").style.visibility='visible';
  }
}

///////////////////////////////////////////////////////////////////////////////
// Drag Object
///////////////////////////////////////////////////////////////////////////////

var Drag =
{
  obj: null,
  init: function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
  {
    o.onmousedown = Drag.start;

    o.hmode = bSwapHorzRef ? false : true;
    o.vmode = bSwapVertRef ? false : true;

    o.root = oRoot && oRoot != null ? oRoot : o;

    if (o.hmode && isNaN(parseInt(o.root.style.left)))
      o.root.style.left = "0px";

    if (o.vmode && isNaN(parseInt(o.root.style.top)))
      o.root.style.top = "0px";

    if (!o.hmode && isNaN(parseInt(o.root.style.right)))
      o.root.style.right = "0px";

    if (!o.vmode && isNaN(parseInt(o.root.style.bottom)))
      o.root.style.bottom = "0px";

    o.minX = typeof minX != 'undefined' ? minX : null;
    o.minY = typeof minY != 'undefined' ? minY : null;
    o.maxX = typeof maxX != 'undefined' ? maxX : null;
    o.maxY = typeof maxY != 'undefined' ? maxY : null;

    o.xMapper = fXMapper ? fXMapper : null;
    o.yMapper = fYMapper ? fYMapper : null;

    o.root.onDragStart = new Function();
    o.root.onDragEnd = new Function();
    o.root.onDrag = new Function();
  },
  start: function(e)
  {
    var o = Drag.obj = this;
    e = Drag.fixE(e);
    var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
    var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
    o.root.onDragStart(x, y);

    o.lastMouseX = e.clientX;
    o.lastMouseY = e.clientY;

    if (o.hmode)
    {
      if (o.minX != null)
        o.minMouseX = e.clientX - x + o.minX;

      if (o.maxX != null)
        o.maxMouseX = o.minMouseX + o.maxX - o.minX;
    }
    else
    {
      if (o.minX != null)
        o.maxMouseX = -o.minX + e.clientX + x;

      if (o.maxX != null)
        o.minMouseX = -o.maxX + e.clientX + x;
    }

    if (o.vmode)
    {
      if (o.minY != null)
        o.minMouseY = e.clientY - y + o.minY;

      if (o.maxY != null)
        o.maxMouseY = o.minMouseY + o.maxY - o.minY;
    }
    else
    {
      if (o.minY != null)
        o.maxMouseY = -o.minY + e.clientY + y;

      if (o.maxY != null)
        o.minMouseY = -o.maxY + e.clientY + y;
    }

    document.onmousemove = Drag.drag;
    document.onmouseup = Drag.end;

    return false;
  },
  drag: function(e)
  {
    e = Drag.fixE(e);
    var o = Drag.obj;

    var ey = e.clientY;
    var ex = e.clientX;
    var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
    var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
    var nx, ny;

    if (o.minX != null)
      ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);

    if (o.maxX != null)
      ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);

    if (o.minY != null)
      ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);

    if (o.maxY != null)
      ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

    nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
    ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

    if (o.xMapper)
      nx = o.xMapper(y)
    else if (o.yMapper)
      ny = o.yMapper(x)

    Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
    Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
    Drag.obj.lastMouseX = ex;
    Drag.obj.lastMouseY = ey;

    Drag.obj.root.onDrag(nx, ny);
    return false;
  },
  end: function()
  {
    document.onmousemove = null;
    document.onmouseup = null;
    Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
        parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
    Drag.obj = null;
  },
  fixE: function(e)
  {
    if (typeof e == 'undefined')
      e = window.event;

    if (typeof e.layerX == 'undefined')
      e.layerX = e.offsetX;

    if (typeof e.layerY == 'undefined')
      e.layerY = e.offsetY;
    return e;
  }
};

///////////////////////////////////////////////////////////////////////////////
// DialogBox Object
///////////////////////////////////////////////////////////////////////////////

var backDivLevel=0;
DialogBox = function(isModal)
{
  if (arguments.length == 0)
    return;

  this.backDiv = document.getElementById("backDiv"+backDivLevel);

  if (this.backDiv == null)
  {
    DialogBox.createBackDiv();
    this.backDiv = document.getElementById("backDiv"+backDivLevel);
  }
  backDivLevel++;

  this.isModal = isModal;

  this.container = document.createElement('div');
  this.container.className = DialogBox.className;
  this.container.style.zIndex=(99999+backDivLevel);
  this.container.dialogBox = this;

  var mainTable = document.createElement('table');
  mainTable.setAttribute('cellSpacing', '0');
  mainTable.setAttribute('cellPadding', '0');
  mainTable.setAttribute('border', '0');

  var tBodyM = document.createElement('tbody');
  var rowM = document.createElement('tr');
  var cellM = document.createElement('td');

  ////////////* BEGIN Title TABLE //////////*
  var titleTable = document.createElement('table');
  titleTable.setAttribute('cellSpacing', '0');
  titleTable.setAttribute('cellPadding', '0');
  titleTable.setAttribute('border', '0');
  titleTable.setAttribute('width', '100%');

  var tBodyT = document.createElement('tbody');
  var rowT = document.createElement('tr');
  var cellT = document.createElement('td');
  cellT.className = "tbLeft";
  rowT.appendChild(cellT);

  this.titleCell = document.createElement('td');
  this.titleCell.className = "Title";
  rowT.appendChild(this.titleCell);

  cellT = document.createElement('td');
  cellT.className = "tbRight";

  DialogBox.initCloseIcon();
  var closeIcon = document.createElement('img');
  closeIcon.src = DialogBox.closeIcon.src;
  closeIcon.alt = "Fermer";
  closeIcon.setAttribute('border', '0');
  closeIcon.dialogBox = this;

  var aLink = document.createElement('A');
  aLink.setAttribute('href', '#');
  aLink.appendChild(closeIcon);
  aLink.onclick = DialogBox.closeBox;

  cellT.appendChild(aLink);
  rowT.appendChild(cellT);

  tBodyT.appendChild(rowT);
  titleTable.appendChild(tBodyT);
  ////////////* END Title TABLE //////////*

  cellM.appendChild(titleTable);
  rowM.appendChild(cellM);
  tBodyM.appendChild(rowM);

  rowM = document.createElement('tr');
  cellM = document.createElement('td');
  cellM.className = "MainPanel";

  this.contentArea = document.createElement('div');
  this.contentArea.className = "ContentArea";
  cellM.appendChild(this.contentArea);

  rowM.appendChild(cellM);
  tBodyM.appendChild(rowM);
  mainTable.appendChild(tBodyM);
  this.container.appendChild(mainTable);
  document.body.appendChild(this.container);
  Drag.init(this.titleCell, this.container, 0, null, 0);
}

////////////// BEGIN: Public Methods /////////////

DialogBox.prototype.show = function()
{
  this.container.style.display = "block";
  this.backDiv.style.display = "block";
}

DialogBox.prototype.hide = function(ok)
{
  this.backDiv.style.display = "none";
  this.container.style.display = "none";
  if (ok)
  {
    if (this.callOK)
      if (this.returnData)
        this.callOK(this.returnData);
      else
        this.callOK();
  }
  else if (this.callCancel)
    this.callCancel();
}

DialogBox.prototype.moveTo = function(x, y)
{
  if (x == -1)
    x = Math.round((document.body.clientWidth - this.container.offsetWidth) / 2);

  if (y == -1)
    y = Math.round((document.body.clientHeight - this.container.offsetHeight) / 2) + document.body.scrollTop;
  this.container.style.left = x + "px";
  this.container.style.top = y + "px";
}

DialogBox.prototype.setTitle = function(title)
{
  this.titleCell.innerHTML = title;
}

DialogBox.prototype.setUrl = function(url, height)
{
  if (!this.iframe)
  {
    this.iframe = document.createElement('IFRAME');
    this.iframe.setAttribute('frameBorder', 'no');
    this.iframe.style.width = "100%";
    if (height)
      this.iframe.style.height = height;
    this.contentArea.parentNode.insertBefore(this.iframe, this.contentArea);
  }
  this.iframe.src = url;
  this.contentArea.style.height="0px";
}

DialogBox.prototype.getUrl = function()
{
  if (this.iframe)
  {
    var url = this.iframe.src;
    if (this.iframe.contentWindow)
    {
      try
      {
        url = this.iframe.contentWindow.location.href;
      }
      catch (e)
      {
      }
    }
    return url;
  }
}

DialogBox.prototype.setContent = function(htmlContent)
{
  this.contentArea.innerHTML = htmlContent;
}

DialogBox.prototype.setWidth = function(width)
{
  this.contentArea.style.width = (width-25) + "px";
}

DialogBox.prototype.setCallOK = function(callOK)
{
  this.callOK = callOK;
}

DialogBox.prototype.setCallCancel = function(callCancel)
{
  this.callCancel = callCancel;
}

DialogBox.prototype.getContentNode = function()
{
  return this.contentArea;
}
////////////// END: Public Methods /////////////


////////////// BEGIN: Private Methods /////////////
DialogBox.className = "DialogBox";
DialogBox.closeIcon = null;
DialogBox.maxDepth = 5;

DialogBox.initCloseIcon = function()
{
  if (DialogBox.closeIcon == null)
  {
    DialogBox.closeIcon = new Image();
    DialogBox.closeIcon.src = "close.gif";
  }
}

DialogBox.closeBox = function(e)
{
  if (!e)
    e = window.event;
  var node = e.target ? e.target : e.srcElement;
  var count = 0;

  while ((node != null) && (count <DialogBox.maxDepth))
  {
    if (node.dialogBox)
    {
      node.dialogBox.hide();
      return false;
    }
    node = node.parentNode;
    count++;
  }
  return false;
}

DialogBox.createBackDiv = function(e)
{
  var backDiv = document.createElement("div");
  backDiv.id = "backDiv"+backDivLevel;
  backDiv.style.position = "absolute";
  backDiv.style.top = 0;
  backDiv.style.left = 0;
  backDiv.style.width = "100%";
  backDiv.style.height = "100%";
  backDiv.style.display = "none";
  backDiv.style.background = "black";
  var opacity = 20;
  backDiv.style.MozOpacity = (opacity / 100); //FireFox
  backDiv.style.opacity = (opacity / 100);    //Opera
  backDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")"; //IE
  document.body.appendChild(backDiv);
  backDiv.style.zIndex = (99999+backDivLevel);
}


