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


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


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 gravaretorno(url){
var Retorno = GetCookie('Retorno');
Retorno=url;
pathname = location.pathname;
myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var largeExpDate = new Date ();
	largeExpDate.setTime(largeExpDate.getTime() + (30 * 24 * 3600 * 100000));
SetCookie('Retorno',Retorno,largeExpDate,myDomain);
}

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, " ")
		}
		if(Tipo!=""){
			document.write(Paths[1])
		}
		else{
			document.write("Olá " + Paths[1] + " [<a href='javascript:LogOut()' class='padrao3-9px'>logout</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 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=53&COD_RECURSO=816&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=53&COD_RECURSO=816&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();
}

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


function popVejaComent() {
   var wVjComent = window.open('/comente/' + 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 janela(param,w,h,nome,scroll) {

		if (scroll!='yes' && scroll!='no'){
			scroll='no';
		}
        var nomearq=param;
		var parfim='scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,resizable=no,toolbar=no,width='+ w + ',height='+h;
       var windowvar =window.open(nomearq,nome,parfim);
}

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=53&COD_RECURSO=816&URL_RETORNO='+url);
		return false;
	}
	/*else{
		window.location.href=url;
	}*/
	return true;
}

moveContent = function(nameDivOas, nameDivOasDisplay) {
 var elemDivOas = document.getElementById(nameDivOas);
 var elemDivOasDisplay = document.getElementById(nameDivOasDisplay);
 if(elemDivOasDisplay != null){
  elemDivOasDisplay.appendChild(elemDivOas);
  elemDivOas.style.display='block';
 }
}


function mntfoto(ft){
		getElementByClass('foto');
		if(ccollect.length>0){
		cont=ccollect[ft];
		}
		else{
		cont='';
		}
			return cont;
	}

function buscar(nome){
			document.BuscaHome.qu.value=document.getElementById(nome).innerHTML;
			document.BuscaHome.submit();
	}

function clearbusc(){
	if(document.BuscaHome.qu.value=='BUSCAR' || document.BuscaHome.qu.value==''){
		alert('Vocę precisa digitar uma palavra na busca!');
		return false;
	}
	else{
		document.BuscaHome.action="http://saude.abril.com.br/busca2/resultado.shtml";
		document.BuscaHome.submit();
		return true;
	}
}
