function Converter(val_cookie){

  val = '';
  num = 0x00;
  re = /%/;
  novo_val = '';
  
  pos = val_cookie.indexOf('%')

  if (pos==-1)
  {
    return val_cookie;
  }

  val = val_cookie.substr(pos, 3);
  num = parseInt(val.replace(re, '0x'));

  novo_val = val_cookie.substr(0,pos) + String.fromCharCode(num) + val_cookie.substr(pos+3,val_cookie.length);

  return novo_val;

}

function readCookie(name) 
{
	 nameEQ = name + "=";
	 ca = document.cookie.split(';');
	 for(var i=0;i < ca.length;i++) 
	 {
	  	c = ca[i];
	  	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	  	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	 }
	 return null;
}

function Personalizacao_Nome()
{
	Data  = FormataDataAtual();
	document.getElementById("DataPersoSite").innerHTML = Data;
	ckNome = readCookie("LNCNM");
	msg = "";

	if(ckNome != null)
	{
		arrayNome = ckNome.split("+");
		Nome = Converter(arrayNome[0]);
		
		Hora = FormataHoraAtual();
		msg = Nome + Hora;
		
		msg = msg + "&nbsp;(<a href='cadastro/ctl_login.asp'>Mudar login</a> )"

	} else {
		msg = "&nbsp;<a href='cadastro/ctl_login.asp'>Login</a>";
	}

	document.getElementById("MsgPersoSite").innerHTML = msg;
}	

function Personalizacao_Nome_Minuto()
{
	ckNome = readCookie("LNCNM");
	
	if(ckNome != null)
	{
		arrayNome = ckNome.split("+");
		Nome = Converter(arrayNome[0]);
		
	    document.getElementById("MsgPersoMin").innerHTML = Nome;
	}	
}
				
function FormataDataAtual()
{
	hoje = new Date();
	dia = hoje.getDate();
	mes = hoje.getMonth();
	ano = hoje.getYear();
	
	if (ano < 1900)
	{
		ano += 1900;
	}

	if (dia < 10)
	{
		dia = "0" + dia;
	}	
		
	NomeMes = new CriaArray(12)
	NomeMes[0] = "01"
	NomeMes[1] = "02"
	NomeMes[2] = "03"
	NomeMes[3] = "04"
	NomeMes[4] = "05"
	NomeMes[5] = "06"
	NomeMes[6] = "07"
	NomeMes[7] = "08"
	NomeMes[8] = "09"
	NomeMes[9] = "10"
	NomeMes[10] = "11"
	NomeMes[11] = "12"
	
	DataAtual = dia + "." + NomeMes[mes] + "." + ano;
	
	return DataAtual;
}	

function CriaArray (n)
{
	this.length = n
}

function FormataHoraAtual()
{
	hoje = new Date();
	hora = hoje.getHours();
	var NomeHora
	
	if(hora<=12)
	{
		NomeHora=", bom dia!";
	}
	
	if((hora>12)&&(hora<18))
	{
		NomeHora=", boa tarde!";
	}
	
	if(hora>=18)
	{
		NomeHora=", boa noite!";
	}
		
	return NomeHora ;
	
}	
	
function Personalizacao_Minuto()
{
	var ckSigla = readCookie("LNCTMSIGLA");

	var html
	
	if(ckSigla != null)
	{
		html = '<iframe src="/noticias/minuto/' + ckSigla + '.htm" scrolling="no" frameborder="0"></iframe>'
	}	
	else
	{
		html = '<div class="minuto_header"><h3><span>minuto L</span></h3></div>'
	}
	
	document.getElementById("MinutoPersoSite").innerHTML = html
}

function MarcaEsportes()
{
	ckEsportes = readCookie("LNCESPSIGLA");
	if(ckEsportes != null)
	{
		arrayEsportes = ckEsportes.split("%2C");
		ul = document.getElementById("EsportePersoSite")

		if (ul.children == null)
		{
			return;
		}
		
		for(i=0;i<ul.children.length;i++)
		{
			if((ul.children[i].getAttribute("value")!= 'FUT') && (ul.children[i].getAttribute("value")!= '-'))	
			{
				for(j=0;j<arrayEsportes.length;j++)
				{
					if(arrayEsportes[j]== ul.children[i].getAttribute("value"))
					{
							ul.children[i].className='usuario'
					}		
				}	 
			}	
			
		}	
	}	
	
}


function Personalizacao_LanceClic()
{
	alias = document.frmLanceClic.AliasLanceClic.value;
	if(alias=='HomeRJ')
	{
		document.getElementById("ed_RJ").style.display = 'block';
	}
	if(alias=='HomeSP')
	{
		document.getElementById("ed_SP").style.display = 'block';
	}
	if(alias=='HomeMG')
	{
		document.getElementById("ed_MG").style.display = 'block';
	}
	if(alias=='HomeSUL')
	{
		document.getElementById("ed_SP").style.display = 'block';
	}
	if(alias=='HomeNE')
	{
		document.getElementById("ed_RJ").style.display = 'block';
	}
	
}	

function Personalizacao_Barra()
{
	
	hoje = new Date();
	hora = hoje.getHours();
	
	if(hora<=12)
	{
		document.write('<link rel="stylesheet" type="text/css" href="/inc/topo_manha.css" media="screen">');
	
	}
	
	if((hora>12)&&(hora<18))
	{
		document.write('<link rel="stylesheet" type="text/css" href="/inc/topo_tarde.css" media="screen">');
	}
	
	if(hora>=18)
	{
		document.write('<link rel="stylesheet" type="text/css" href="/inc/topo_noite.css" media="screen">');
	}
}	
