function AbrePopUp(url, w, h){
	var x = (screen.width-w)/2
	var y = (screen.height-h)/2
	window.open(url ,"Passaporte","height="+h+" , width="+w+", top="+y+", left="+x+"");          
}

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 ValidaPassaporteComentarios()
{
	username = GetCookie('usuario');
	ticket = GetCookie('ticket');
	if(typeof(arguments[0]) == undefined)
  		URL = escape(window.location);
 	else
 		URL = arguments[0];		
	if ((username == null) && (ticket == null))  return false;
	return true;
}

function ShowButton(){
	if(ValidaPassaporteComentarios(window.location.href)){			
		document.getElementById('texto').disabled = false;	
		document.write('<input type="button" name="enviar" id="envia" value="     Enviar     " onclick="Envia();" />');
	}else{
		document.getElementById('texto').disabled = true;
		document.write('<input type="button" name="enviar" id="envia" value="     Enviar     " onclick="Envia();" disabled="true" />');
		document.write('<div id="comentarios-logar">Para comentar você precisa estar logado.<strong><a href="javascript:;" onclick="Autentica()">Clique aqui para entrar.</a></strong></div>');
	}
}
function Autentica(){
	var u = window.location.href;			
	if(u.indexOf('info.abril.uol.com.br')!=-1){
		var pass = 'http://passaporte.abril.uol.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=58&COD_RECURSO=83&URL_RETORNO=';
		pass = pass + 'http://portalexame.abril.com.br/v2009/areascomuns/closewindow.html'
		AbrePopUp(pass, 780, 570);
	}else if(u.indexOf('info.abril.ig.com.br')!=-1){
		var pass = 'http://passaporte.abril.ig.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=58&COD_RECURSO=83&URL_RETORNO=';
		pass = pass + 'http://portalexame.abril.com.br/v2009/areascomuns/closewindow.html'
		AbrePopUp(pass, 780, 570);
	}else{
		var pass = 'http://passaporte.abril.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=35&COD_RECURSO=83&URL_RETORNO=';
		pass = pass + 'http://portalexame.abril.com.br/v2009/areascomuns/closewindow.html'
		myLightWindow.activateWindow({href: pass, title: 'Entre com seu passaporte Abril', height: 570, width: 780});							
	}
}
function Envia(){
	username = GetCookie('usuario');
	ticket = GetCookie('Ticket');
	if ((username == null) || (ticket == null)){
		alert('Falha na autenticação. Por favor, faça o login novamente.');
		Autentica();
	}else{
		OBform = document.getElementById('frm1');
		if(OBform.texto.value==''){
			alert('Preencha o campo de comentário antes de enviar');
			OBform.texto.focus();
		}else{	
			document.getElementById('envia').disabled='disabled';			
			//OBform.codigoAssunto.value = cod_fwa;
			OBform.urlRetorno.value = window.location.href;
			OBform.action = 'http://fwa.abril.com.br/fwa/comentario.do?tarefa=incluir';
			//OBform.texto.value = Utf8.encode(OBform.texto.value);
			OBform.submit();
			
			//OBform.envia.value = "Aguarde...";
			//OBform.enviar.onclick = "javascript:void(0);";
			OBform.texto.style.visibility = "none";
		}
	}
} 
function EscondeComentarios(){
	if(cod_fwa == '0'){
		document.getElementById('comentarios-topo').style.display = 'none';
		document.getElementById('bloco-comentarios').style.display = 'none';
	}
}

function qtde_comentarios(z){
if(z==1 || z==0){ncomentarios="<a href=\"#comente\">" +z+" coment&aacute;rio</a>";}
else{ncomentarios="<a href=\"#comente\">"+z+" coment&aacute;rios</a>";}

document.getElementById("materia_comentarios").innerHTML=ncomentarios;

}