try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}
function popup_comentarios_noticia(cod_noticia){
	var fundo = document.getElementById("popup_fundo");
	var popup = document.getElementById("popup");
	var desktop = document.getElementById("desktop");
	fundo.style.display = "block";
	popup.style.display = "block";
	popup.innerHTML = "<div align='center' style='background-color: #FFFFFF;'><img src='../icones/carregando.gif'><br />AGUARDE! CONSULTANDO DADOS...</div>";
	if(xmlhttp){
		xmlhttp.open("GET", "/php/popup_comentarios.php?COD_NOTICIA="+cod_noticia, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				var texto=xmlhttp.responseText;
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);
				popup.innerHTML = texto;
				popup.innerHTML = texto + "<div align='right' style='width:380px'><input type='button' onclick='popup_some()' value='Fechar' /></div>";
				fundo.style.display = "block";
				popup.style.display = "block";
				fundo.style.height = document.body.parentNode.scrollHeight + "px";
				fundo.style.width = document.body.parentNode.scrollWidth + "px";
				
				if(fundo.offsetHeight < popup.offsetHeight){
					//fundo.style.height = popup.offsetHeight+150 + "px";
				}
			}
		}
		xmlhttp.send(null);
	}	
}
function popup_indicar_noticia(cod_noticia){
	var fundo = document.getElementById("popup_fundo");
	var popup = document.getElementById("popup");
	var desktop = document.getElementById("desktop");
	fundo.style.display = "block";
	popup.style.display = "block";
	popup.innerHTML = "<div align='center' style='background-color: #FFFFFF;'><img src='../icones/carregando.gif'><br />AGUARDE! CONSULTANDO DADOS...</div>";
	if(xmlhttp){
		xmlhttp.open("GET", "/php/popup_indicar.php?COD_NOTICIA="+cod_noticia, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				var texto=xmlhttp.responseText;
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);
				popup.innerHTML = texto;
				popup.innerHTML = texto + "<div align='right' style='width:380px'><input type='button' onclick='popup_some()' value='Fechar' /></div>";
				fundo.style.display = "block";
				popup.style.display = "block";
				fundo.style.height = document.body.parentNode.scrollHeight + "px";
				fundo.style.width = document.body.parentNode.scrollWidth + "px";
				if(fundo.offsetHeight < popup.offsetHeight){
					fundo.style.height = popup.offsetHeight+150 + "px";
				}
			}
		}
		xmlhttp.send(null);
	}	
}
function setaTamanhoDiv(){
	var menu = document.getElementById("menu");
	var blogger = document.getElementById("blogger");
	var dir = document.getElementById("dir");
	var tam_menu = menu.offsetHeight;
	var tam_blogger = blogger.offsetHeight;
	if(tam_menu > tam_blogger){
		blogger.style.height = tam_menu + 'px';
		dir.style.height = tam_menu+74 + 'px';
	}else{
		menu.style.height = tam_blogger + 'px';
		dir.style.height = tam_blogger+74 + 'px';
	}
	
}
function popup_some(){
	var fundo = document.getElementById("popup_fundo");
	var popup = document.getElementById("popup");
	popup.innerHTML = "<div align='center' style='background-color: #FFFFFF;'><img src='icones/carregando.gif'><br />AGUARDE! CONSULTANDO DADOS...</div>";
	fundo.style.display = "none";
	popup.style.display = "none";
}
function envia_comentario(){
	var nome = document.getElementById("comentario_nome").value;
	var email = document.getElementById("comentario_email").value;
	var comentario = document.getElementById("comentario_comentario").value;
	var cod_comentario = document.getElementById("cod_comentario").value;
	var popup = document.getElementById("popup");
	
	if(nome != "" && comentario != ""){
		popup.innerHTML = "<div align='center' style='background-color: #FFFFFF;'><img src='icones/carregando.gif'><br />AGUARDE! CONSULTANDO DADOS...</div>";
		if(xmlhttp){
			xmlhttp.open("POST", "/php/ajax.php", true);
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
			var dados = "tipo=cadComentario&cod_comentario="+cod_comentario+"&nome="+nome+"&email="+email+"&comentario="+escape(comentario);
			xmlhttp.send(dados);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4){
					popup_comentarios(cod_comentario);
				}
			}
		}
	}else{
		alert("Campos Nome e Comentário são Obrigatórios");
	}
}
function ajaxVotar(cod_resposta){
	var enquete = document.getElementById("enquete");
	enquete.innerHTML = "Votando...";
	if(xmlhttp){
		xmlhttp.open("POST", "/php/ajax.php", true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		var dados = "tipo=votar&cod_resposta="+cod_resposta;
		xmlhttp.send(dados);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				var texto=xmlhttp.responseText;
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);
				enquete.innerHTML = texto;
				setaTamanhoDiv();
			}
		}
	}
}
function valida_comentario(){
	var msg = '';
	var nome = document.comentar.nome;
	var comentario = document.comentar.comentario;
	if(nome.value == ''){
		msg += '- Nome\n';
	}
	if(comentario.value == ''){
		msg += '- Comentario\n';
	}
	if(msg == ''){
		return true;
	}else{
		alert('Campos Obrigatorios: \n' + msg);
		return false;
	}
}
function valida_indicar(){
	var msg = '';
	var nome = document.indicar.nome;
	var email = document.indicar.email;
	var nome_dest = document.indicar.nome_dest;
	var email_dest = document.indicar.email_dest;
	var comentario = document.indicar.comentario;
	if(nome.value == ''){
		msg += '- Nome Remetente\n';
	}
	if(email.value == ''){
		msg += '- E-Mail Remetente\n';
	}
	if(nome_dest.value == ''){
		msg += '- Nome Destinatario\n';
	}
	if(email_dest.value == ''){
		msg += '- E-Mail Destinatario\n';
	}
	if(comentario.value == ''){
		msg += '- Comentario\n';
	}
	if(msg == ''){
		return true;
	}else{
		alert('Campos Obrigatorios: \n' + msg);
		return false;
	}
}