// Pega o nome do canal - primeira ocorrência dentro do split para usar no box de Busca das Sub Homes
function PegaNomeCanal()
{
	var Path;
	if(par["cl"])
	{
		var re = /%2F/g;
		Path = (par["cl"]).replace(re,"\/");
		var re = /.*\/(.*)/;
		Path = Path.replace(re,"$1");
	}
	else if(secao)
	{
		var re = /.*\/(.*)/;
		Path = (secao).replace(re,"$1");
	}
	else
	{		
		var re = /.*\/(.*)\/.*/;
		Path = (document.location.pathname).replace(re,"$1");
	}
	document.write(Path.toUpperCase());
}

// Retorna o nome do canal - primeira ocorrência dentro do split para usar no box de Busca das Sub Homes
function ReturnNomeCanal()
{
	var Path;
	if(par["cl"])
	{
		var re = /%2F/g;
		Path = (par["cl"]).replace(re,"\/");
		var re = /.*\/(.*)/;
		Path = Path.replace(re,"$1");
	}
	else
	{		
		var re = /.*\/(.*)\/.*/;
		Path = (document.location.pathname).replace(re,"$1");
	}
	return Path.toUpperCase();
}

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 LogOut() // Deleta os cookies ticket e usuario
{
	pathname = location.pathname;
	myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var largeExpDate = new Date();
	largeExpDate.setTime(largeExpDate.getTime() + (60 * 24 * 3600 * -1000));
	SetCookie('usuario',"unknown",largeExpDate,myDomain);
	SetCookie('Ticket',"unknown",largeExpDate,myDomain);
	location.replace('http://passaporte.abril.com.br/pas_logout.php?COD_SITE=3&URL_RETORNO=http://capricho.abril.com.br');
}

function MostraNomeUsuario(Tipo) // Mostra nome do usuário na barra do site
{
	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, " ")
		}


		// Pego só o primeiro nome do usuário para mostrar na barra do site
		PrimeiroNome = Paths[1].split(' ');
		//for(var x=0;x<=1;x++)
		//{			
		//	alert(PrimeiroNome[x])
		//}

		
		if(Tipo!=""){
			document.write(PrimeiroNome[0])
		}
		else{
			document.write("Olá, " + PrimeiroNome[0] + " [<a href='javascript:LogOut()' class='padrao3-9px'>logout</a>] ")		
		}
	}
	else {
			document.write("Olá visitante [<a href='javascript:PassAbril()' class='padrao3-9px'>login</a>] ");
	}
}

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 verificaApresentaMensagemMateriaSalva(){
	
	if((window.location.search).match(".*mensagemSalva=true.*")){
		alert('Matéria salva com sucesso!\nEsta matéria está em sua página pessoal.');
	}

	if((window.location.search).match(".*mensagemSalva=false.*")){
		alert('Não foi possível salvar a matéria.');
	}
}
verificaApresentaMensagemMateriaSalva();


// funcoes Denis xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function wopen(page,nwin,larg,altu){
	window.open(page,nwin,'width='+larg+',height='+altu+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,top=10,left=10');
}


// Função para visualizar um artigo
function lerArtigo(URL)
{
  MM_openBrWindow(URL,'Artigo','scrollbars=yes,width=800,height=600,resizable=yes,menubar=yes,toolbar=yes,location=yes');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

// 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("O campo 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;
}

//Function de enquete da NGTools - LabOne
function NGTools_Abre_Enquete(theURL,winName,features)	{
    window.open(theURL,winName,features);
}

function participarPromocao(codigo,lib) {

	var retorno = 'http://elle.abril.com.br/promocao/' + codigo + '_promocao.shtml';
	username = GetCookie('usuario');
	ticket = GetCookie('ticket');
	
	if ((username == null) && (ticket == null))
	{
		location.replace('http://passaporte.abril.com.br/alteraUsuario.do?metodo=prepararAlterarDadosUsuario&COD_SITE=1&COD_RECURSO='+lib+'&URL_RETORNO=' + escape(retorno));
	} else {
		location.replace(retorno);
	}
}

function envComent() {

	username = GetCookie('usuario');
	ticket = GetCookie('ticket');

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

	var wComent = window.open('/comente/' + codigofwa + '_comente.shtml', 'PopComent', 'width=430,height=350,left=0,top=0');
	wComent.focus();
}

function envAmigo() {
	
	username = GetCookie('usuario');
	ticket = GetCookie('ticket');

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

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


function popVejaComent() {
   var wVjComent = window.open('/comente/' + codigofwa + '_comentarios.shtml', 'PopComent', 'width=430,height=500,left=0,top=0,scrollbars=yes');
   wVjComent.focus();
}

 function abrejanela(url,l,h,s)
 {
   xyz=window.open(url, 'enquete', 'width='+l+',height='+h+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+s+',resizable=no');
   xyz.focus(); 
 }

 function janela(param,w,h,nome,scroll) {
		if (scroll!='yes' || scroll!='no'){
			scroll='yes';
		}
        var nomearq=param;
        var windowvar = window.open(nomearq,nome,"scrollbars="+scroll+",location=no,directories=no,status=no,menubar=no,resizable=no,toolbar=no,width="+ w + ",height="+h );
}
 
function participar(frm, codigoAssunto, urlRetorno) {

	if (frm.texto.value == '') {
		alert('Por favor, preencha o campo texto.');
		return;
	}
	
	var retorno = 'http://fwa.abril.com.br/fwa/comentario.do?' +
   				 'tarefa=incluir' +
   				 '&situacaoComentario=1' +
   				 '&codigoAssunto=' + codigoAssunto +
   				 '&texto=' + frm.texto.value +
   				 '&urlRetorno=http://elle.abril.com.br' + urlRetorno;

	username = GetCookie('usuario');
	ticket = GetCookie('ticket');
	
	if ((username == null) && (ticket == null))
	{
		location.replace('http://passaporte.abril.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=1&COD_RECURSO=561&COD_ACAO=1&URL_RETORNO=' + escape(retorno));
	} else {
		location.replace(retorno);
	}
}

function ValidaTicket(url)
{
	username = GetCookie('usuario');
	ticket = GetCookie('ticket');

	if ((username == null) && (ticket == null))
	{
		location.replace('http://passaporte.abril.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=1&COD_RECURSO=561&URL_RETORNO='+url);
		return false;
	}
	else{
		window.location.href=url;
	}
}

function abrePop(pag,h) {
	//var wEnv = window.open(pag, 'PopEnviar', 'width=530, height=' + h + ',left=0,top=0')
window.location=pag;
}


function mostratela(){
	res=screen.width;
		if (res>=1024){
		document.getElementById('oas_oculta').style.display='block';
		}
}


function mostrar(con,parar,volta){
    if(total_fotos > 0 && document.readyState == 'complete'){
		slide.style.filter = '';
		slide.style.filter = 'progid:DXImageTransform.Microsoft.GradientWipe(duration=3, gradientsize=2, motion=forward, wipestyle=0)'; 
		if (volta=='sim'){
			con--;
		}else{
			con++;
		}
		if(con > total_fotos){
			con = 0;
		}
		if(con < 0){
			con = total_fotos;
		}
		nomeimg='imagens/'+con+'.jpg';
		slide.filters.item(0).Apply();  
		slide.src = nomeimg;
		slide.filters.item(0).Play();
	}
	num=con;
	var retorna='<a href="javascript:mostrar('+num+',\'sim\',\'sim\');"><IMG SRC="/spfw/fw_verao_2007/imagens/desfiles_volta.gif" WIDTH="10" HEIGHT="18" BORDER="0" ALT=""></a>';
	var anda='<a href="javascript:mostrar('+num+',\'sim\',\'nao\')"><IMG SRC="/spfw/fw_verao_2007/imagens/desfiles_vai.gif" WIDTH="10" HEIGHT="18" BORDER="0" ALT=""></a>';
	if (parar=='nao'){
		timer=window.setTimeout("mostrar(num,'nao','nao')", 4000); 
		var stagna='<a href="javascript:mostrar('+num+',\'sim\',\'nao\');"><IMG SRC="/spfw/fw_verao_2007/imagens/desfiles_parar.gif" WIDTH="151" HEIGHT="18" BORDER="0" ALT=""></a>';
	}
	if (parar=='sim'){
		window.clearTimeout(timer);
		var stagna='<a href="javascript:mostrar('+num+',\'nao\',\'nao\');"><IMG SRC="/spfw/fw_verao_2007/imagens/desfiles_slide.gif" WIDTH="151" HEIGHT="18" BORDER="0" ALT=""></a>';
	}
	document.getElementById('menuslide').innerHTML=retorna+stagna+anda;
}
