// LAHOVARY.RO POPUP.JS
// (C) Dan Mirescu


 /*var lista = document.getElementById('lista');
 var lista_tr = lista.getElementsByTagName('tr');
 
 var selected_tr = -1;*/
 
 function winSize()
{
  var myWidth = 0, myHeight = 0;
  //myHeight = document.body.clientHeight > window.innerHeight ? document.body.clientHeight : window.innerHeight;
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  /*if(typeof( window.innerWidth ) == 'number' && document.body && document.body.clientHeight)
  {
    myHeight = document.body.clientHeight > window.innerHeight ? document.body.clientHeight : window.innerHeight;
  }
  /*window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );*/
  var size = new Array();
  size[1] = myWidth;
  size[2] = myHeight;
  //alert(size[1] + ',' + size[2]);
  return size;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function scrollTop()
{
  return getScrollXY()[1];
}

var popup_opened = false;
 
 function pop_in(file_call,vars)
 {
    var i;
    var s = winSize();
    //alert(s);
    var w = s[1];
    var h = s[2] + 120;
    var bg = document.getElementById('bg');
    
    bg.style.top = (scrollTop() - 50) + 'px';
    bg.style.width = w + 'px';
    bg.style.height = h + 'px';
    bg.style.display = 'block';
    
    var msg = document.getElementById('msg');
    msg.style.top = ((h - 320) / 2) + 'px';
    msg.style.left = ((w - 100) / 2) + 'px';
    msg.style.display = 'block';
    
    var popup = document.getElementById('popup');
    // calculam pozitionarea la centru
    //popup.style.top = (300 + this.nr * 18) + 'px';

    //ajax_loadContent('popup',file_call,method,params);
    
    popup.style.visibility = 'hidden';
    popup.style.display = 'block';
    update_res_popup();
        
    var ajax = new sack();
    ajax.requestFile = file_call;
    ajax.element = 'popup';
    //ajax.onLoading = function () { document.getElementById('popup').innerHTML = "Încărcare..."; };
    ajax.onCompletion = function() { setTimeout("update_res_popup();" +
                                                "document.getElementById('msg').style.display = 'none';" +
                                                "document.getElementById('popup').style.visibility = 'visible';" +
                                                "popup_opened = true;",500);
                                   };
    if(vars)
      for(key in vars)
        ajax.setVar(key,vars[key]);
        
    ajax.runAJAX();
    
    //popup.style.display = 'block';
    
    //popup.style.left = ((w - parseInt(popup.offsetWidth)) / 2) + 'px';
    
    //alert(popup.offsetWidth);
    
    //window.scroll(0,scroll_offset);
    window.onscroll = update_scr_popup;
    window.onresize = update_res_popup;
 }
 
 function pop_out()
 {
    var popup = document.getElementById('popup');
    popup.style.display = 'none';
    popup.innerHTML = '';
    var bg = document.getElementById('bg');
    bg.style.display = 'none';
    selected_tr = -1;
    popup_opened = false;
 }
 
 /*for(i=1;i<lista_tr.length;i++)
 {
  if(lista_tr[i].id != 'no_fx')
  {
    lista_tr[i].nr = i;
    lista_tr[i].onclick = pop_in;
    lista_tr[i].onmouseover = function() { this.style.backgroundColor = '#DFD4C2'; };
    lista_tr[i].onmouseout = function() { if(this.nr != selected_tr) this.style.background = 'none'; };
  }
 }*/
 
 function update_scr_popup()
 {
    var bg = document.getElementById('bg');
    
    if(bg.style.display == 'block')
    {
      //alert(scrollTop());
      bg.style.top = (scrollTop() - 100) + 'px';
    }
 }
 
 function update_res_popup()
 {
    var bg = document.getElementById('bg');
    
    if(bg.style.display == 'block')
    {
      var s = winSize();
      var w = s[1];
      var h = s[2] + 200;
      bg.style.width = w + 'px';
      bg.style.height = h + 'px';
      // repozitionare popup
      var popup = document.getElementById('popup');
      popup.style.left = ((w - parseInt(popup.offsetWidth)) / 2) + 'px';
      popup.style.top = ((h - 200 - parseInt(popup.offsetHeight)) / 2) + 'px';
      //popup.style.top = (300 + this.nr * 18) + 'px';
    }
 }
 
window.onscroll = window.onresize = function() {};

