hoje = new Date()
dia = hoje.getDate()
dias = hoje.getDay()
mes = hoje.getMonth()
ano = hoje.getFullYear()

if (dia < 10)
dia = "0" + dia
if (ano < 2000)
ano = "19" + ano
function CriaArray (n) {
this.length = n }
NomeDia = new CriaArray(7)
NomeDia[0] = "Domingo"
NomeDia[1] = "Segunda-feira"
NomeDia[2] = "Ter&ccedil;a-feira"
NomeDia[3] = "Quarta-feira"
NomeDia[4] = "Quinta-feira"
NomeDia[5] = "Sexta-feira"
NomeDia[6] = "S&aacute;bado"
NomeMes = new CriaArray(12)
NomeMes[0] = "Janeiro"
NomeMes[1] = "Fevereiro"
NomeMes[2] = "Mar&ccedil;o"
NomeMes[3] = "Abril"
NomeMes[4] = "Maio"
NomeMes[5] = "Junho"
NomeMes[6] = "Julho"
NomeMes[7] = "Agosto"
NomeMes[8] = "Setembro"
NomeMes[9] = "Outubro"
NomeMes[10] = "Novembro"
NomeMes[11] = "Dezembro"

function WriteDate() {
document.write ("" + NomeDia[dias] + ", " + dia + " de " + NomeMes[mes] + " de " + ano + "")
}
function getDataAtual() {
	return("" + NomeDia[dias] + ", " + dia + " de " + NomeMes[mes] + " de " + ano + "")
}
function pop_print() {
			window.open( '/inc/pop_print.html', 'pop', 'width=537,height=590,scrollbars=yes');
		}
		
function pop_naoprint() {
			window.open( '/inc/pop_naoprint.html', 'pop', 'width=500,height=590,scrollbars=yes');
		}		
		
// coloca os parametros passado por get, em um array por nomes
var URL = location.href;
var PARAMS = URL.substring(URL.indexOf("?")+1);
var PARAM = new Array();
PARAM = PARAMS.split("&");
var par = new Array();

for(var x=0; x < PARAM.length; x++)
{
	var VALOR = new Array();
	VALOR = PARAM[x].split("=");
	par[VALOR[0]] = VALOR[1];
}

var re = /^\//;
var Path = (document.location.pathname).replace(re,"");
var Paths = new Array;
Paths = Path.split('/');
for(var x=0;x <= 1;x++)
{
	if(Paths[x])
	{
		Path = Paths[x];
	}
}

var re = /result/
if(re.test(Path))
{
	Path = par["cl"]
	var re = /(%2F)/g;
	Path = Path.replace(re,"\/");
	var re = /.*\/(.*)/g;
	Path = Path.replace(re,"$1");
}

function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	   endstr = document.cookie.length;
	   return unescape(document.cookie.substring(offset, endstr));
}

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 null;
}

function PegaNomeUsuario() // Retorna o nome do usuário logado
{
	username = GetCookie('usuario');
	if (username != null)
	{
		var Paths = new Array;
		Paths = username.split(';');
		for(var x=0;x < Paths.length;x++)
		{
			Paths[x] = Paths[x].replace(/\+/gi, " ")
		}
		return Paths[1];
	}
	else return "";
}

function PegaEmailUsuario() // Retorna o email do usuário logado
{
 username = GetCookie('usuario');
 if (username != null)
 {
  var Paths = new Array;
  Paths = username.split(';');
  for(var x=0;x < Paths.length;x++)
  {
   Paths[x] = Paths[x].replace(/\+/gi, " ")
  }
  return Paths[2];
 }
 else return "";
}

function ValidaTicket()
{
	username = GetCookie('usuario');
	ticket = GetCookie('ticket');
	codigo = '';
	
	if (username != null) {
		valores = username.split(';');
		codigo = valores[0];
	}
	
	if ((username == null && ticket == null) || (codigo == '2516185'))
	{
		location.replace('http://passaporte.abril.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=133&COD_RECURSO=194&URL_RETORNO=' + escape(window.location));
		return false;
	}
	return true;
}

function envAmigo() {
	var wEnv = window.open('http://planetasustentavel.abril.com.br/envieamigo/envie_amigo.shtml', 'PopEnviar', 'width=430,height=650,left=0,top=0');
	wEnv.focus();
}

if (URL.indexOf("envAmigo=true") > 0) {
	envAmigo();
}




function indAmigo() {
	
	/*username = GetCookie('usuario');
	ticket = GetCookie('ticket');

	if ((username == null) && (ticket == null))
	{
		location.replace('http://passaporte.abril.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=133&COD_RECURSO=194&URL_RETORNO=' + escape(window.location + '?indAmigo=true'));
		return false;
	}*/

	var wEnv = window.open('/envieamigo/envie_amigo.shtml', 'PopEnviar', 'width=430,height=570,left=0,top=0');
	wEnv.focus();
}

if (URL.indexOf("indAmigo=true") > 0) {
	indAmigo();
}

// Função para validar um email
function emailValido (email)
{
   invalidChars = " /:,;"

   if (email == "") return false;
   
   for (i=0; i<invalidChars.length; i++)
   {
      badChar = invalidChars.charAt(i);
      if (email.indexOf(badChar,0) > -1) return false;
   }

   atPos = email.indexOf("@",1);
   if ((atPos == -1) || (email.indexOf("@",atPos+1) != -1)) return false;

   periodPos = email.indexOf(".",atPos)
   if ((periodPos == -1) || (periodPos+3 > email.length)) return false;

   return true;
}

// Função que checa se os emails são válidos e se a quantidade de nomes é igual a quantidade de emails
// Os valores das variáveis "nomesValue" e "emailsValue" devem estar sepadaros por ";"
function checkEmail(nomesValue, emailsValue)
{
   var NOMES = new Array();
   NOMES = nomesValue.split(";");

   if (emailsValue == "") return false;

   var emails;
   var re=/[ +]/g;
   emails = emailsValue.replace(re,"");

   var EMAILS = new Array();
   EMAILS = emails.split(";");

   if(NOMES.length > 1) {
      if(NOMES.length != EMAILS.length) {
         alert("Os campos de nome e endereço do destinatário devem ter a mesma quantidade.");
         return false;
      }
   }

   for (var i=0;i<EMAILS.length;i++) {
      if (!emailValido(EMAILS[i])) {
         alert("Por favor, preencha corretamente o campo do endereço do destinatário.");
         return false;
      }
   }

   return true;
}

var qntClick = 0;
function enviarComentario() {
	var frm = document.getElementById('commentform');	
	if (frm.comment.value == '') {
		alert('Preencher texto');
		return;
	}

	if (frm.author && frm.author.value == '') {
		alert('Preencher o seu nome');
		return;
	}
	qntClick++;
	if(qntClick == 1){			
		frm.submit();	
	}
}

