/*

  Popups.js v1.0
  Ale Muñoz <ale.munoz@the-cocktail.com>

  Based in ideas from Lightbox, but totally unrelated code
  Uses Really Simple Ajax™ from sofanaranja.com

  TODO: Fix flash content

*/

popWidth = 711;
imageDir = "images/";

function openPop (id_capa) {
  var pop = createPop(id_capa);
  var popup = document.getElementById(id_capa);
  
  popup.style.width = popWidth+"px";
  popup.style.height = "auto";
  popup.style.minHeight = "200px";
  popup.style.left = document.body.clientWidth/2 - popWidth/2 + "px";
  popup.style.top = "100px";
  popup.style.background = "#fff";
  popup.style.zIndex = "3";
  popup.style.display = "block";
}
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
  var xScroll, yScroll;
  if (window.innerHeight && window.scrollMaxY) {	
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight; 
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }
  var windowWidth, windowHeight;
  if (self.innerHeight) {	// all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
    /********************/
    cual=document.getElementsByClassName('client-box');
    if ((cual) && (cual.length>0))
    {
        if(windowHeight < cual[0].offsetHeight) windowHeight=cual[0].offsetHeight+30;
	}
	/********************/
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else { 
    pageHeight = yScroll;
  }
  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }
  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
  return arrayPageSize;
}
function createPop (id_capa) {
  var popDiv = document.getElementById("nxpop");
  var size = getPageSize();
  popDiv.style.width = (size[0] + 'px');
  popDiv.style.height = (size[1] + 'px');
  popDiv.style.display = "block";
  popDiv.style.background = "url("+imageDir+"semitransp.gif)";
  popDiv.style.textAlign = "center";
  popDiv.style.position = "absolute";
  popDiv.style.top = "0";
  popDiv.style.left = "0";
  popDiv.style.zIndex = "2";
  
  document.body.onresize=function()
  {
      var popDiv = document.getElementById("nxpop");
      if (popDiv)
      {
          var size = getPageSize();
          popDiv.style.width = (size[0] + 'px');
      }
  }
  
  return popDiv;
}