function lerComentario(idPost){
	if($('#forms-'+idPost+' #commentlist').css('display') == "none"){
		$('#forms-'+idPost+' #commentlist').css('display','block');
	}else{
		$('#forms-'+idPost+' #commentlist').css('display','none');
	}
}


function fazerComentario(idPost){
	if($('#forms-'+idPost+' #respond').css('display') == "none"){
		$('#forms-'+idPost+' #respond').css('display','block');
	}else{
		$('#forms-'+idPost+' #respond').css('display','none');
	}
}

function enviarPorEmail(idPost){
	if($('#post-'+idPost+' .modulo_enviar_por_email').css('display') == "none"){
		$('#post-'+idPost+' .modulo_enviar_por_email').css('display','block');
	}else{
		$('#post-'+idPost+' .modulo_enviar_por_email').css('display','none');
	}
}

function msgFechar(obj){
	$(obj).css('display','none');
}

function wopen(page,nwin,larg,altu,scroll){
	window.open(page,nwin,'width='+larg+',height='+altu+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no,menubar=no,top=10,left=10');
}

function getHtmlTexto(id){
	if(window.opener.document.getElementById(id)){
		obj = window.opener.document.getElementById(id);
		texto = obj.innerHTML;
		texto = texto.replace(/href\=^["]*\"/gi,"");
		texto = texto.replace(/href\=\".\"/gi,"");
		alert(texto);
		document.body.innerHTML = '<a href="javascript:window.print()" class="bt_print">Imprimir</a>'+texto.split('<p class="postmetadata')[0];
	}
}

function addFav(){
    var url = window.location;
	var title = 'Loucos por Coleções';
	if( navigator.appName != 'Microsoft Internet Explorer' ){ 
		window.sidebar.addPanel(title,url,"");
	}else{ 
		window.external.AddFavorite(url,title); 
	} 
}

/******************************** FUNCOES DE AJAX ***************************************/
 
	function getXmlHttp(){
		 if(window.XMLHttpRequest){
			 return new XMLHttpRequest();
		 } else if (window.ActiveXObject) {			 
			 var axO=['Microsoft.XMLHTTP','Msxml2.XMLHTTP','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0'];
			 for(var i=0;i<axO.length;i++){ 
				try{ 
					return new ActiveXObject(axO[i]);
					}catch(e){
						
					} 
			}
		}
	 }  

	arrValores = [];
	var objHttp = false;
	var http_request = false;
	tagPai = 'item';
	function LoadXML(url,func){
		objHttp = getXmlHttp();		
		objHttp.onreadystatechange = function(){
			if (objHttp.readyState == 4 && objHttp.status == 200){ 				
				result = objHttp.responseXML;	
				
				tagsPai = result.getElementsByTagName(tagPai);
				for(j=0;j<tagsPai.length;j++){
					arrValores[j] = [];
					filhos = tagsPai[j].childNodes;	
					for(i=0;i<filhos.length;i++){
						if(filhos[i].nodeType == 1){										
							arrValores[j][filhos[i].nodeName] = filhos[i].childNodes[0].data;										
						}	
					}
				}
				func();
			}
		 }
        objHttp.open('GET', url, true);
        objHttp.send(null);
    }
	
/*******************************************************************************************************************/	
	/* WebDoor */
	var aux = 0;
	var timer;	
	var indxAtual = 0;
	function setRotativo(op,ligado) {	
		var lim = $('.widgets_lancamentos BLOCKQUOTE').length;
		if(op == '+'){
			if(indxAtual < lim-1){
				indxAtual++;
			}else{
				indxAtual = 0;
			}			
		}else{
			if(indxAtual > 0){
				indxAtual--;
			}else{
				indxAtual = lim-1;
			}	
		}
		//alert(indxAtual)
		indxAnt = aux;
		$("#q_"+indxAtual).fadeIn("slow");
		$("#q_"+indxAnt).fadeOut("slow");		
		aux = indxAtual;		
		if(ligado == true){
			clearTimeout(timer);
			timer = setTimeout('setRotativo(' + (aux+1) + ',true)', 5000);
		}else{
			clearTimeout(timer);
		}
	}
	
	function validaBusca(frm,campo){
		if(frm.elements[campo].value.length > 0){
			return true;
		}else{
			return false;
		}
	}
	
	
	$(document).ready(function(){
		$(".widgets_google_maps IFRAME").css("height","200px");
		$(".widgets_google_maps IFRAME").css("width","200px");
	});
	
	function makeRequest(url,funcao,isAssincrono) {	
        http_request = false;
		if(!isAssincrono){
			isAssincrono = true;
		}
		http_request=getXmlHttp();

        if (!http_request) {			
            return false;
        }else{	
			
		}
		
		if(!funcao){
			funcao = defaultRequest;
		}		
        http_request.onreadystatechange = funcao;
        http_request.open('GET', url, isAssincrono);
        http_request.send(null);		
    }
	var notaPost = 0;
	var caminho = '';
	function getAvaliacao(index,idPost){
		if(index >=0 && index <= 10  ){
			var url = caminho+"/controle_avaliacao.php?acao=avaliar&idPost="+idPost+"&nota="+index;
			func = function(){
				if (http_request.readyState == 4 && http_request.status == 200){ 
					var retorno = http_request.responseText;
					if(retorno != 'votado'){
						notaPost = retorno;
						$('#post-'+idPost+' #blocoAvaliacao A').each(function(i){
							if(((i+1)*2) <= notaPost ){
								$(this).attr('class','active');
							}else{
								$(this).attr('class','inactive');
							}
						});
						alert('Avaliação enviada com sucesso !');
					}else{
						alert('Você já avaliou este post');
					}
					$('#post-'+idPost+' #blocoAvaliacao2 A').each(function(i){
						if(((i+1)*2) <= index ){
							$(this).attr('class','active');
						}else{
							$(this).attr('class','inactive');
						}
					});					
				}
			}
			makeRequest(url,func);
		}
	}
