// JavaScript Document
var thisLocationURL = location.href;
var paramRequestQuery = thisLocationURL.substring(thisLocationURL.indexOf("?")+1);
var addressLocationHome = thisLocationURL.substring(0,thisLocationURL.indexOf("?"));
var paramRequestGET = new Array();
paramRequestGET = paramRequestQuery.split("&");
var _QueryString = new Array();
for(var x=0; x<paramRequestGET.length; x++)
{
	var paramValue = new Array();
	paramValue = paramRequestGET[x].split("=");
	_QueryString[paramValue[0]] = paramValue[1];
}

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

function getElementByClass(classname){
ccollect=new Array()
var alltags=document.all? document.all : document.getElementsByTagName("*")
for(i=0; i<alltags.length; i++){
if(alltags[i].className==classname)
ccollect[ccollect.length]=alltags[i].innerHTML;
}
}

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/autenticaUsuario.do?metodo=logout&URL_RETORNO=http://vocesa.abril.com.br');
}

function mostraNomeUsuario() // 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, " ")
		}
		
		return Paths[1];
	}
}

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 pegaCodigoUsuario() // Retorna o email do usuário logado
{
	username = getCookie('usuario');
	if (username != null)
	{
		var Paths = new Array;
		Paths = username.split(';');
		
		return Paths[0];
	}
	else return "";
}

function grantBlog(){
/*
Kaio		-	8021174
Milton		-	2568881
Piero		-	7811591
Marcia		-	5866615
Priscilla	-	8081939*/

		var grant	=	new	Array();
			grant[grant.length]	= 	8021174;
			//grant[grant.length]	= 	2568881;
			grant[grant.length]	= 	7811591;
			grant[grant.length]	= 	5866615;
			grant[grant.length]	= 	8081939;

		cod	=	pegaCodigoUsuario();
		if(cod!=""){
				for (x=0;x<grant.length ;x++ )
				{
						if(cod	== grant[x]){
							return 'permited';
						}
				}
		}
		else{
			return 'denied';
		}
}

function sendok(cdid){
	if(document.comentarioForm.texto.value==''){
	alert('Vocę precisa digitar um comentário!')
	return false;
	}
	else{
		textodig=document.comentarioForm.texto.value;
	document.comentarioForm.texto.value='<!--'+cdid+'-->'+textodig;
	document.getElementById('senderok').style.display='none';
	document.getElementById('sendedok').style.display='block';
	document.comentarioForm.action = 'http://fwa.abril.com.br/fwa/comentario.do?tarefa=incluir' ;
	document.comentarioForm.submit();
	return true
	}
}

function commentBlg(cdid){
		cdassunto	=	thisLocationURL.split('?');
		cdassok	=	cdassunto[1].replace('_comentarios.shtml','');
		cmform	=	'<form name="comentarioForm" method="post" style="margin-top:30px;">';
		cmform	+=	'<input type="hidden" name="codigoAssunto" value="'+cdassok+'">';
		cmform	+=	'<input type="hidden" name="tarefa" value="incluir">';
		cmform	+=	'<input type="hidden" name="situacaoComentario" value="1">';
		cmform	+=	'<input type="hidden" name="urlRetorno" value="'+thisLocationURL+'">';
		cmform	+=	'<textarea name="texto" cols="25" rows="8" class="campo"></textarea><br><br>';
		cmform	+=	'<div id="senderok" class="coment"><a href="javascript:sendok('+cdid+');">enviar</a></div>';
		cmform	+=	'<div id="sendedok" style="display:none;" class="coment">enviando o comentário</div>';
		cmform	+=	'</form>';
		document.getElementById('enviar_coment').innerHTML=cmform;
		document.getElementById('enviar_coment').style.display='block';
		document.getElementById('postlat').style.display='none';
}

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=88&COD_RECURSO=1154&URL_RETORNO='+url);
		return false;
	}
	return true;
}

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=32&COD_RECURSO=853&URL_RETORNO=' + escape(window.location));
		return false;
	}

	var wComent = window.open('/fwa/comentario/fechado/' + codigofwa + '_comente.shtml', 'PopComent', 'width=430,height=300,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=88&COD_RECURSO=1154&URL_RETORNO=' + escape(window.location + '?envAmigo=true'));
		return false;
	}

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

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

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

function addBookmark(url, desc)
{
	var desc=document.title;

	var ver = navigator.appName;
	var num = parseInt(navigator.appVersion);
	
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4))
	{
		javascript:window.external.AddFavorite(url, desc);
	}
	else
	{
		alert("Para adicionar esta página nos favoritos tecle Control-D.");
	} 
}

function participar(retorno,codigo) {

	if (document.comentarioForm.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="+codigo +
   				 "&texto=" + document.comentarioForm.texto.value +
   				 "&urlRetorno="+retorno;

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

	if ((username == null) && (ticket == null))
	{
		location.replace('http://passaporte.abril.com.br/p_login.php?COD_SITE=88&COD_RECURSO=1154&URL_RETORNO=' + escape(retorno));
	} else {
		location.replace(retorno);
	}
}

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

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function janela(param,w,h,nome,scroll) {
		if (scroll!='yes' && scroll!='no'){
			scroll='no';
		}
        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 );
}