function getCookieVal(offset)
{
    var endstr = document.cookie.indexOf(";", offset);

    if (endstr == -1)
	endstr = document.cookie.length;

    var str = document.cookie.substring(offset, endstr);
    var ret = '';

    for (i = 0; i < str.length; i++)
    {
	if (str.substring(i, i + 1) == '+')
	    ret = ret + ' ';
	else
	    ret = ret + str.substring(i, i + 1);
    }

    return unescape(ret);
}

function GetCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen)
    {
	var j = i + alen;

	if (document.cookie.substring(i, j) == arg)
	    return getCookieVal(j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0)
	    break;
    }
    return 0;
}

function POP_AD(zoneid)
{
	var m3_u = (location.protocol=='https:'?'https://ad.pop.com.br/www/delivery/ajs.php':'http://ad.pop.com.br/www/delivery/ajs.php');
	var m3_r = Math.floor(Math.random()*99999999999);
	if (!document.MAX_used) document.MAX_used = ',';
	document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
	document.write ("?zoneid=" + zoneid);
	document.write ('&amp;cb=' + m3_r);
	if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
	document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
	document.write ("&amp;loc=" + escape(window.location));
	if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
	if (document.context) document.write ("&context=" + escape(document.context));
	if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
	document.write ("'><\/scr"+"ipt>");
}

function POP_SHOPPING_AD(zoneid)
{
   var m3_u = (location.protocol=='https:'?'https://ad.pop.com.br/www/delivery/ajs.php':'http://ad.pop.com.br/www/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid=68&amp;target=_blank&amp;block=1");
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
   document.write ("&amp;loc=" + escape(window.location));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   document.write ("'><\/scr"+"ipt>");
}



function phpads_deliverActiveX(content)
{
        document.write(content);
}

function banner_direita()
{
	if (screen.width >= 1024)
		banner(29);
	else
	{
		var bd = document.all? document.all['bnrd'] : document.getElementById('bnrd');
		bd.style.visibility='hidden';
		bd.style.display='none';
	}
}

function banner_area(num,area)
{
	// editorias

	if (area == 'brasil')
	{
		if (num == 1)
			banner(57);
		if (num == 2)
			banner(55);
		if (num == 3)
			banner(56);
	}
        else if (area == 'cultura')
        {
                if (num == 1)
                        banner(60);  
                if (num == 2)
                        banner(58);  
                if (num == 3)
                        banner(59);  
        }
        else if (area == 'economia')
        {
                if (num == 1)
                        banner(63);  
                if (num == 2)
                        banner(61);  
                if (num == 3)
                        banner(62);  
        }
        else if (area == 'esportes')      
        {
                if (num == 1)
                        banner(66);  
                if (num == 2)
                        banner(64);  
                if (num == 3)
                        banner(65);  
        }
        else if (area == 'mulher')      
        {
                if (num == 1)
                        banner(69);  
                if (num == 2)
                        banner(67);  
                if (num == 3)
                        banner(68);  
        }
        else if (area == 'politica')      
        {
                if (num == 1)
                        banner(72);  
                if (num == 2)
                        banner(70);  
                if (num == 3)
                        banner(71);  
        }
        else if (area == 'saude')
        {
                if (num == 1)
                        banner(75);  
                if (num == 2)
                        banner(73);  
                if (num == 3)
                        banner(74);  
        }
        else if (area == 'mundo')
        {
                if (num == 1)
                        banner(121);  
                if (num == 2)
                        banner(119);  
                if (num == 3)
                        banner(120);  
        }
        else if (area == 'suporte')
        {
                if (num == 1)
                        banner(139);
                if (num == 2)
                        banner(140);
        }


	// ferramentas

        else if (area == 'discador')
        {
                if (num == 1)
                        banner(103);  
                if (num == 2)
                        banner(104);  
	}
        else if (area == 'concentrador')
        {
                if (num == 1)
                        banner(105);
                if (num == 2)
                        banner(106);  
	}
        else if (area == 'popblog')
        {
                if (num == 1)
                        banner(112);
                if (num == 2)
                        banner(110);  
                if (num == 3)
                        banner(111);  
	}
        else if (area == 'download')
        {
                if (num == 1)
                        banner(116);
                if (num == 2)
                        banner(117);  
	}
        else if (area == 'popmovies')
        {
                if (num == 1)
                        banner(109);
                if (num == 2)
                        banner(132);
	}
        else if (area == 'busca')
        {
                if (num == 1)
                        banner(137);
                if (num == 2)
                        banner(138);
	}

	// canais

        else if (area == 'popcolunistas')
        {
                if (num == 1)
                        banner(84);
                if (num == 2)
                        banner(82);
                if (num == 3)
                        banner(83);
	}
        else if (area == 'popwallpapers')
        {
                if (num == 1)
                        banner(93);
                if (num == 2)
                        banner(91);
                if (num == 3)
                        banner(92);
	}

	// outros / popnews

        else
        {
                if (num == 1)
                        banner(78);
                if (num == 2)
                        banner(76);  
                if (num == 3)
                        banner(77);  
        }
}

/* Banners Realad */

OAS_url ='http://oas.pop.com.br/RealMedia/ads/';
OAS_listpos = '';
OAS_query = '';
OAS_sitepage = '';

function realad_set(pagina,pos)
{
	OAS_listpos = pos;
	OAS_sitepage = pagina;

	if (navigator.userAgent.indexOf('Mozilla/3') != -1)
		OAS_version = 10;
	else
		OAS_version = 11;

	OAS_rn = new String (Math.random());
	OAS_rns = OAS_rn.substring (2, 11);

	if (OAS_version >= 11)
		document.write('<SCR' + 'IPT LANGUAGE=JavaScript1.1 SRC="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + OAS_query + '"></SC'+'RIPT>');
}

function OAS_NORMAL(pos)
{
	document.write('<A HREF="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos +  OAS_query + '" TARGET=_top>');
	document.write('<IMG SRC="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + OAS_query + '" BORDER=0></A>');
}

function OAS_AD(pos)
{
        if (OAS_version >= 11)
                OAS_RICH(pos);
        else
                OAS_NORMAL(pos);
}


/* /Banners Realad */

function banner(num)
{
    if (!document.phpAds_used)
	document.phpAds_used = ',';
    phpAds_random = new String(Math.random());
    phpAds_random = phpAds_random.substring(2, 11);
    document.write("<" + "script language='JavaScript' type='text/javascript' src='");
    document.write("http://ad2.pop.com.br/adjs.php?n=" + phpAds_random);
//    document.write("http://adserver.midiaweb.com.br/adjs.php?n=" + phpAds_random);
    document.write("&amp;what=zone:" + num + "&amp;block=1");
    document.write("&amp;exclude=" + document.phpAds_used);
    if (document.referer)
	document.write("&amp;referer=" + escape(document.referer));
    document.write("'><" + "/script>");
}


function banner_principal(num)
{
    if (!document.phpAds_used)
        document.phpAds_used = ',';
    phpAds_random = new String(Math.random());
    phpAds_random = phpAds_random.substring(2, 11);
    document.write("<" + "script language='JavaScript' type='text/javascript' src='");
    document.write("http://ad2.pop.com.br/adjs.php?n=" + phpAds_random);
    document.write("&amp;what=zone:" + num + "&amp;block=1");
    document.write("&amp;source=principal");
    document.write("&amp;exclude=" + document.phpAds_used);
    if (document.referer)
        document.write("&amp;referer=" + escape(document.referer));
    document.write("'><" + "/script>");
}


function capa()
{
    var url = new String(window.location);
    var partes = url.split('/');

    window.location = 'http://' + partes[2] + '/' + partes[3] + '/';
}

function senha()
{
    window.open('http://servlet.pop.com.br/App/servlet/EsqueciSenha', 'senha',
		'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=100,top=100,width=475,height=304');
}

function popup(url, nome, w, h)
{

    window.open(url, nome,
		'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,left=100,top=100,width='
		+ w + ',height=' + h);
}

function mapa()
{
	top.location = '/mapadosite/';
}

function contato()
{

    window.open('/contato/', 'contato',
		'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,left=100,top=100,width=448,height=378');
}

function quemsomos()
{

    window.open('/quemsomos/', 'quemsomos',
		'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=100,top=50,width=465,height=490');
}

function cadastro()
{
   top.location = 'http://www.pop.com.br/cadastro';
}

function blog()
{
	popup('http://www.pop.com.br/popblog/', 'popblog', '673', '500')
}

function desbloqueio()
{

    window.open('http://seguro.pop.com.br/desbloqueio/novo/', 'cadastro',
		'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=100,top=100,width=475,height=354');
}

parent.name = "pai";

function muda_pagina()
{
    if (document.combos.ferramentas.value != '')
    {
	var lnk = document.combos.ferramentas.value.split('|');

	if (lnk[1] == '_blank')
	{
	    window.open(lnk[0]);
	}
	else
	{
	    top.location = lnk[0];
	}
    }

    if (document.combos.canais.value != '')
    {
	var lnk = document.combos.canais.value.split('|');

	if (lnk[0] == 'javascript:quemsomos()')
	{
	    quemsomos();
	}
	else if (lnk[1] == '_blank')
	{
	    window.open(lnk[0]);
	}
	else
	{
	    top.location = lnk[0];
	}
    }

    if (document.combos.parceiros.value != '')
    {
	var lnk = document.combos.parceiros.value.split('|');

	if (lnk[1] == '_blank')
	{
	    window.open(lnk[0]);
	}
	else
	{
	    top.location = lnk[0];
	}
    }
}

// Remover sessao se nao estiver na central

if (GetCookie('pop_usuario') != '0')
{
	var area = new String(window.location);

	area = area.split('/');

	if (area[3] != 'centraldousuario')
	{
		top.location = '/logout.php?url='+window.location;
	}
}

function SetCookie(name, value, expires)
{
        document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

