var w = function () { document.write(arguments[0]); return 0; }
var $ = function () { return document.getElementById(arguments[0]); }

// Argumentos:
//  1°) N° total de notícias
//  2°) Qtdade de notíicas por página
//  3°) Página atual
//  4°) Nome da classe css para o div
function Paginacao()
{
  if(typeof(arguments[0]) != "undefined" && typeof(arguments[1]) != "undefined")
  {
    var ClassName   = typeof(arguments[3]) != "undefined" && arguments[3] != "" ? (" " + arguments[3]) : '' ;
    var NameRSS     = typeof(arguments[4]) != "undefined" ? arguments[4] : '' ;
    var ThisPage    = typeof(arguments[2]) != "undefined" && arguments[2] != "" ? parseInt(arguments[2]) : 0;
    var QtdNoticias = parseInt(arguments[0]);
    var QtdNotPages = parseInt(arguments[1]);

    // Qtdade de páginas necessárias
    var QtdPages    = Math.ceil(QtdNoticias / QtdNotPages);
    QtdPages = QtdPages > 10 ? 10 : QtdPages;

    if(QtdPages > 1)
    {
      if(ClassName == "")
        w('<div class="paginacao">');
  
        if(NameRSS != "")
          w('<cite class="rss"><a href="http://rss.bol.uol.com.br/noticias/' + NameRSS + '.xml"><img src="http://rss.i.uol.com.br/xml2.gif" border="0" /></a> <a href="http://ajuda.bol.com.br/rss.htm">O que é isto?</a></cite>');
  
        // div das páginas
        w('<div class="paginas' + ClassName + '">');
  
        // Link Anterior
        if(ThisPage > 0)
          w('<a href="index' + (ThisPage-1 == 0 ? '' : (ThisPage-1)) + '.jhtm" class="nav ant">&nbsp;Anterior&nbsp;</a>');
  
          // Números
          if(ThisPage == 1 || ThisPage < 3)
          {
            for(var i = 1; i <= 5; i++)
              if(i <= QtdPages)
                w('<a href="index' + (i == 1 ? '' : (i-1)) + '.jhtm"' + (i-1 == ThisPage ? 'class="clicado"' : '') + '>&nbsp;' + i + '&nbsp;</a>');
          }
          else
          {
            for(var i = (ThisPage > QtdPages - 3 ? (QtdPages - 3 == 1 ? 1 : QtdPages - 4) : ThisPage-1); i <= (ThisPage > QtdPages - 3 ? QtdPages : ThisPage+3); i++)
              if(i <= QtdPages)
                w('<a href="index' + (i == 1 ? '' : (i-1)) + '.jhtm"' + (i-1 == ThisPage ? 'class="clicado"' : '') + '.jhtm">&nbsp;' + i + '&nbsp;</a>');
          }
          // /Números

        // Link Próximo
        if(ThisPage < QtdPages-1)
          w('<a href="index' + (ThisPage == "" ? 1 : ThisPage+1) + '.jhtm" class="nav prox">&nbsp;Próximo&nbsp;</a>');

        if(ClassName == "")
          w('</div>');

      w('</div>');
      // /div das páginas
    }
  }
}


function abreSigno(obj)
{
	s1 = obj.s1.value
	s2 = obj.s2.value

	if(s1 != '' && s2 != '' )
	{
		destino = '/astral/index'+s1+'.jhtm?signo='+s2
		window.location = destino;
	}
	else
	{
		if(s1 == '' && s2 == '' )
			alert('Escolha o seu signo e o signo dela(e)...')
		else if(s1 == '')
			alert('Escolha o seu signo...')
		else
			alert('Escolha o signo dela(e)...')
	}
	return false;
}


function redirBP()
{
	var objSel = $("selSalaBP");
	if(objSel.value == "")
		window.location = "http://batepapo.bol.com.br/";
	else
		window.location = "http://bpbol.uol.com.br/bytheme.html?nodeid="+objSel.value;
}

function SetCookie() {
	var today  = new Date();
	var expire = new Date();
	document.cookie = "entradaSexoBOL"+"="+escape("aprovado");
}


function ReadCookie() {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf("entradaSexoBOL");
 if (ind==-1 || "entradaSexoBOL"=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+"entradaSexoBOL".length+1,ind1));
}

/* verifica se o usuário passou pela porta de entrada */
if(ReadCookie() != "aprovado")
{
	if(location.href.indexOf("porteira.jhtm") == -1)
		window.location = "http://sexo.bol.uol.com.br/porteira.jhtm?url="+location.href;
}
