// COPYRIGHT ARCHITECTE DU LOGICIEL - THIS SOFTWARE IS NOT A FREE SOFTWARE
// ------------------------ ADL PROMPT SCRIPT -----------------------

var adlprompt_tw=new Fx.Tween();

//ADL
// width & height can be undefined, closemessage also
// top&left can be -1 (be careful with page that have flash : with IE7 flash goes above)
function adl_simpleprompt(htmlmessage,width,height,closemessage,top,left)
{
  $('adlprompt_modal').setStyles({'width':'100%','height':'150%'});
  // http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
  var docwidth,docheight;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    docwidth = window.innerWidth;
    docheight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    docwidth = document.documentElement.clientWidth;
    docheight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    docwidth = document.body.clientWidth;
    docheight = document.body.clientHeight;
  }
  if (docwidth==0)
    docwidth=600;
  if (docheight==0)
    docheight=400;
  //alert("found docwidth="+docwidth+" height="+docheight);
  //
  var newwidth=500;
  if (width!=undefined && width>0)
    newwidth=width;
  if (newwidth>docwidth)
    newwidth=docwidth-20;
  var newleft=100;
  if (left!=undefined && left>0)
    newleft=left;
  else
    newleft=docwidth/2-newwidth/2;
  //
  var newheight=300;
  if (height!=undefined && height>0)
    newheight=height;
  if (newheight>docheight)
    newheight=docheight-20;
  var newtop=100;
  if (top!=undefined && top>0)
    newtop=top;
  else
    newtop=docheight/2-newheight/2;
  //
  $('adlprompt_messagecontainer').setStyles({'width':newwidth,'left':newleft,'height':newheight,'top':newtop});
  $('adlprompt_message').set({html:htmlmessage});
  if (closemessage==undefined)
    closemessage="OK";
  $('adlprompt_close').set({html:
    "<a href='#' onclick='return(false)' style='text-decoration:none'>"+
    closemessage+"</a>"});
  //adlprompt_tw.chain(function() {});
  //adlprompt_tw.start('opacity',0,1);
  $('adlprompt_modal').setStyle("opacity","1");
}

//ADL
function adl_simpleprompt_end()
{
  //adlprompt_tw.chain(function() {$('adlprompt_modal').setStyles({'width':'1px','height':'1px'});});
  //adlprompt_tw.start('opacity',1,0);
  $('adlprompt_modal').setStyle("opacity","0");
  $('adlprompt_modal').setStyles({'width':'1px','height':'1px'});
  return(false);
}

//ADL
window.addEvent('domready', 
  function()
  {
    var adlprompt_modal=new Element('div',{id:'adlprompt_modal'});
    adlprompt_modal.inject($(document.body));
    adlprompt_modal.setStyles({position:'absolute',top:'0',left:'0',
      width:'1px',height:'1px',visibility:'hidden','z-index':'1000',
      opacity:'0'});
    //
    adlprompt_tw.initialize(adlprompt_modal);
    //
    var adlprompt_back=new Element('div',{id:'adlprompt_back'});
    adlprompt_back.inject(adlprompt_modal);
    adlprompt_back.setStyles({
      position:'absolute',top:'0px',left:'0px',
      width:'100%',height:'100%',
      'z-index':'1',opacity:'0.5'});
    adlprompt_back.setProperty('class', 'adlprompt_backclass');
    //
    var adlprompt_messagecontainer=new Element('div',{id:'adlprompt_messagecontainer'});
    adlprompt_messagecontainer.inject(adlprompt_modal);
    adlprompt_messagecontainer.setStyles({
      position:'absolute',top:'0px',left:'0px',width:'1px',height:'1px',
      'z-index':'2'});
    //
    var adlprompt_message=new Element('div',{id:'adlprompt_message'});
    adlprompt_message.inject(adlprompt_messagecontainer);
    adlprompt_message.setStyles({
      position:'absolute',top:'0px',left:'0px',
      width:'100%',height:'100%',
      'z-index':'1','padding':'10px','text-align':'center'});
    adlprompt_message.setProperty('class', 'adlprompt_messageclass');
    //
    var adlprompt_close=new Element('div',{id:'adlprompt_close'});
    adlprompt_close.inject(adlprompt_messagecontainer);
    adlprompt_close.setStyles({
      position:'absolute',right:'0px',bottom:'0px',
      width:'100px',height:'18px',
      'z-index':'2','padding':'2px','text-align':'center'});
    adlprompt_close.setProperty('class', 'adlprompt_closeclass');
    adlprompt_close.addEvent('click',adl_simpleprompt_end);
    adlprompt_back.addEvent('click',adl_simpleprompt_end);
  });

