//*****************************************************************
//
// 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.open();

function date ()
{
   var currentTime = new Date();
   var month = currentTime.getMonth() + 1;
   var day = currentTime.getDate();
   var year = currentTime.getFullYear();
   return (month + "/" + day + "/" + year);
   }
   
function time ()
{
   var currentTime = new Date();
   var hours = currentTime.getHours();
   var minutes = currentTime.getMinutes();
   
   if (minutes < 10)
      minutes = "0" + minutes;
   if (hours < 10)
      hours = "0" + hours;
   return (hours + ":" + minutes);
}

function left(str, n)
{
   if (n <= 0)
      return "";
   if (n > String(str).length)
      return str;
   return String(str).substring(0,n);
}
function right(str, n)
{
    if (n <= 0)
       return "";
    if (n > String(str).length)
       return str;
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
}
function instr(i,x,s)
{
    return x.indexOf(s,i)+1;
}
function instr(x,s)
{
    return x.indexOf(s,0)+1;
}
function dpc (x) // Decimal Point is Comma
{
    i = instr(x,".");
    if (i > 0)
       x = left(x,i-1) + "," + right(x,x.length-i);
    return x;
}
function dpp (x) // Decimal Point is Period
{
    i = instr(x,",");
    if (i > 0)
       x = left(x,i-1) + "." + right(x,x.length-i);
    return x;
}
function int100 (x)  // Aceita em dpc ou dpp
{
    i = instr(x,".") + instr(x,",");
    if ((instr(x,".")+instr(x,","))==0)
       x = x + "00";
    else
       x = left(x,i-1) + right(x,x.length-i);
    return parseInt(x);
}
function str100 (y) // Devolve em dpc
{
    x = y+" ";
    x = left(x,x.length-1);
    x = left(x,x.length-2)+","+right(x,2);
    return x;
}
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 nw_goto(url)
   {
   window.open(url,"ta_extra");
   }

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);
        }

function from_where (url)
        {
        //alert (url);

        ork0 = "http://www.orkut.com.br/Profile?uid=1734710726560225307";
        ork1 = "http://www.orkut.com.br/CommMsgs";
        ork2 = "http://www.orkut.com.br/Scrapbook";
        ork3 = "http://www.orkut.com";
        ork4 = "http://docs.www.orkut.com.br";
        
        cfc1 = "http://forum.cifraclub.com.br";
        cfc2 = "http://www.forum.cifraclub.com.br";
        cfc3 = "http://www.cifraclub.com.br";
        cfc4 = "http://cifraclub.com.br";

        if (left(url,ork0.length) != ork0)
           {
           if (left(url,ork1.length) == ork1)
              {
              //par_goto ("http://orkut.com.br");
              location.replace ("http://www.orkut.com.br/Main#Profile?uid=1734710726560225307");
              return false;
              }
           if (left(url,ork2.length) == ork2)
              {
              //par_goto ("http://orkut.com.br");
              location.replace ("http://www.orkut.com.br/Main#Profile?uid=1734710726560225307");
              return false;
              }
           if (left(url,ork3.length) == ork3)
              {
              //par_goto ("http://orkut.com.br");
              // grava referrer para eventual verificação posterior
              location.replace ("http://www.orkut.com.br/Main#Profile?uid=1734710726560225307");
              return false;
              }
           if (left(url,ork4.length) == ork4)
              {
              //par_goto ("http://orkut.com.br");
              // grava referrer para eventual verificação posterior
              // write_data ();
              location.replace ("http://www.orkut.com.br/Main#Profile?uid=1734710726560225307");
              return false;
              }
           //write_data (url);
           }
        //if (left(url,cfc1.length) == cfc1 ||
        //    left(url,cfc2.length) == cfc2 ||
        //    left(url,cfc3.length) == cfc3 ||
        //    left(url,cfc4.length) == cfc4)
        //    {
        //    //par_goto ("antifake.htm");
        //    location.replace ("antifake.htm");
        //    return false;
        //    }
        }
/*
function write_data (url) // PHP (extraído do antigo site da Tubeamps)
{
   arquivo = new File("visitas.txt");
   var linha;
   var ip = '<!--#echo var="REMOTE_ADDR"-->';
   // Primeira vez?------------
   //if (!arquivo.exists())
   //   {
   //   arquivo.open ("w");
   //   arquivo.close();
   //   }
   // -------------------------
   // Grava detalhes da visita---------------------------------
   arquivo.open("a");
   linha = ip + " " + date() + " " + time() + " -> " + url;
   arquivo.write(linha);
   arquivo.flush();
   arquivo.close();
   //----------------------------------------------------------- 
}
*/
// Garante o desvio, se necessário...
window.onload = from_where(document.referrer);
