//*****************************************************************
//
// Arquivo ..........: STDLIB.JS
// Contem ...........: funcoes de tratamento de janelas e afins
// Site .............: www.tubeamps.com.br
// Autor ............: Manolo
// Ultima atualizacao: 27/07/2008
//
//*****************************************************************

oldw = null;
var wpop   = window.createPopup();

function windowWidth()
{
  if(navigator.userAgent.indexOf("MSIE") != -1)
  {
    return document.body.clientWidth;
  } else {
    return window.innerWidth;
  }
}

function windowHeight()
{
  if(navigator.userAgent.indexOf("MSIE") != -1)
  {
    return document.body.clientHeight;
  } else {
    return window.innerHeight;
  }
}

function ibr_vp(url)
{
  fotogale     = new Image;
  fotogale.src =(url);

  // Esta função não funciona se a imagem url não estiver no cache do browser.
  // Falha por fornecer fotogale.width e fotogale.height = 0
 
  if (!viewphoto(fotogale,0,0))
     alert ("Não foi possível exibir imagem. Tente novamente");
  
  }

function ibr_vpd(url,hp,vp)
{
  fotogale     = new Image;
  fotogale.src =(url);

  // Esta função é para ser usada quando se conhece fotogale.width e fotogale.height.
  // É o caso de quando se executa via PHP.
 
  viewphoto(fotogale,hp,vp);
  }


function viewphoto (foto,hp,vp)
{
  retorno = 0;
  if (oldw != null)
     if (!oldw.closed)
        oldw.close();

  // executada diretamente, sem conhecimento do tamanho da imagem
  if (hp == 0 || vp == 0)
     {
     hp = foto.width;
     vp = foto.height;
     }
  if (hp == 0 || vp == 0)
     {
     hp = screen.height;
     vp = screen.width;
     }
     
  hpix = hp + 30;
  vpix = vp + 30;
  sh = screen.height-20;
  x = (screen.width  - hpix) / 2;
  y = (          sh  - vpix) / 2;

  toolbar_str   = 'no';
  menubar_str   = 'no';
  statusbar_str = 'no';
  scrollbar_str = 'no';
  resizable_str = 'no';

  if (x < 0 || y < 0)
     {
     x = 0;
     y = 0;
     scrollbar_str = 1;
     hpix = screen.width / 5 * 4;
     vpix =           sh / 5 * 4;
     x = (screen.width - hpix) / 2;
     y = (          sh - vpix) / 2;
     }
  if (hp > 0 && vp > 0)
     {
     oldw= window.open(foto.src,'verfoto','left='+x+',top='+y+',width='+hpix+',height='+vpix+',toolbar=0,menubar=0,status=0,scrollbars='+scrollbar_str+',resizable=0');
     retorno = 1;
     }
       
  return retorno;
}

function ibr_ow(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  if (width==0)
      width = screen.width;
  if (height==0)
      height = screen.height;
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

function ibr_nw(url)
{
  window.open(url,null, 'left=0,top=0,width='+screen.width+',height='+screen.height-20+',toolbar=yes,location=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes');
}

function par_goto(url)
   {
   opener.location.replace(url);
   self.close();
   }

function par_popup(foto,x,y,hpix,vpix)
        {
        var ppbody = wpop.document.body;
        
        ppbody.innerHTML = "<img src = '"+foto+"'>";
        wpop.show(x, y, hpix, vpix, document.body);
        }
