function contar_letras(){
	limite = 600;
	campo_texto = document.form_postar_mensagem.mensagem;

	qtde_linhas = campo_texto.value.split('\r');

	if (qtde_linhas.length > 6)
		campo_texto.value = qtde_linhas[0]+qtde_linhas[1]+qtde_linhas[2]+qtde_linhas[3]+qtde_linhas[4]+qtde_linhas[5];

	if (campo_texto.value.length > limite)
		campo_texto.value = campo_texto.value.substring(0, limite);
	else
		document.getElementById('caracteres_digitados').innerHTML = limite - campo_texto.value.length;
}

// Funções da Legenda
function pegar_posicao_esquerda(el) {
	var posicao_esquerda = el.offsetLeft;
	var parel = el.offsetParent;
	while (parel){
		posicao_esquerda += parel.offsetLeft; 
		parel = parel.offsetParent;
	}
	return posicao_esquerda; 
}

function pegar_posicao_topo(el){
	var posicao_topo = el.offsetTop; 
	var parel = el.offsetParent;
	while (parel){ 
		posicao_topo += parel.offsetTop; 
		parel = parel.offsetParent; 
	}
	return posicao_topo; 
}

function legendaApaga() {
	obj = document.getElementById('legenda');
	obj.style.visibility= "hidden";
}

function exibir_legenda(img,texto) {
	obj = document.getElementById('legenda');
	obj.style.top=pegar_posicao_topo(img)+34;
	obj.style.left=pegar_posicao_esquerda(img)-103;
	obj.style.zIndex=10;
	obj.innerHTML="<div style='font: 11px verdana; color:#000000; padding-top:8px; text-align:center'>"+texto+"</div>";
	obj.style.visibility= "visible";
}
// FIM - Funções da Legenda


function c(cd_usuario, nickname, data_hora, mensagem){
	document.write("<div class=\"mensagem\"><div id=\"foto_rosto_comentario\"><a href=http://www.garagem.com.br/usuario/?n="+escape(nickname)+"><img src=\"../fotos/fotos_rosto/70/"+cd_usuario+".jpg\" width=70 height=70 border=0></a></div><a href=http://www.garagem.com.br/usuario/?n="+escape(nickname)+" class=\"cor_letra\"><b>"+nickname+"</b> - "+data_hora+"</a><br>"+mensagem+"</div>");
}

function createXMLHttpRequest() {
	try{return new ActiveXObject("Msxml2.XMLHTTP")} catch(e){}
	try{return new ActiveXObject("Microsoft.XMLHTTP")} catch(e){}
	try{return new XMLHttpRequest()} catch(e){}
	return null;
}


function carregar(opcao, cd_usuario, nickname, sexo){
	document.getElementById('exibir_opcao').style.display = 'block';
	document.getElementById('exibir_opcao').innerHTML = 'Aguarde...';

	var form_string = "opcao="+opcao+"&cd_usuario="+cd_usuario+"&nickname="+nickname+"&sexo="+sexo;
	var xhReq = createXMLHttpRequest();
	xhReq.open("post","opcoes.php",true);
	xhReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhReq.onreadystatechange = function(){
		if (xhReq.readyState==4 && xhReq.status==200){
			document.getElementById('exibir_opcao').innerHTML = xhReq.responseText;
		}
	}
	xhReq.send(form_string);
}


function carregar_opcoes_amigos(opcao, cd_usuario, nickname, sexo){
	document.getElementById('exibir_opcao').style.display = 'block';
	document.getElementById('exibir_opcao').innerHTML = 'Aguarde...';

	var form_string = "opcao="+opcao+"&cd_usuario="+cd_usuario+"&nickname="+nickname+"&sexo="+sexo;
	var xhReq = createXMLHttpRequest();
	xhReq.open("post","opcoes_amizade.php",true);
	xhReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhReq.onreadystatechange = function(){
		if (xhReq.readyState==4 && xhReq.status==200){
			document.getElementById('espaco_opcoes_amigos').innerHTML = xhReq.responseText;
		}
	}
	xhReq.send(form_string);
}


function carregar_form_login(cd_usuario){
	var form_string = "opcao=carregar_form_login&cd_usuario="+cd_usuario;
	var xhReq = createXMLHttpRequest();
	xhReq.open("post","opcoes.php",true);
	xhReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhReq.onreadystatechange = function(){
		if (xhReq.readyState==4 && xhReq.status==200){
			document.getElementById('espaco_form_login').innerHTML = xhReq.responseText;
		}
	}
	xhReq.send(form_string);
}

function enviar(url){
	var form_string = url;
	var xhReq = createXMLHttpRequest();
	xhReq.open("post","opcoes.php",true);
	xhReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhReq.onreadystatechange = function(){
		if (xhReq.readyState==4 && xhReq.status==200){
			document.getElementById('exibir_opcao').innerHTML = xhReq.responseText;
		}
	}
	xhReq.send(form_string);
}

function postar_mensagem(cd_usuario){
	document.form_postar_mensagem.botao.disabled = true;
	document.form_postar_mensagem.botao.value = 'Gravando...';
	var form_string = "opcao=postar_mensagem&cd_usuario_mensagem="+cd_usuario+"&mensagem="+document.form_postar_mensagem.mensagem.value;
	var xhReq = createXMLHttpRequest();
	xhReq.open("post","opcoes.php",true);
	xhReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhReq.onreadystatechange = function(){
		if (xhReq.readyState==4 && xhReq.status==200){
			eval(xhReq.responseText);
		}
	}
	xhReq.send(form_string);
}


function foto(diretorio, cd_foto, largura, altura, exibir_borda, exibir_linha_separadora, margem_rodape, legenda_data, exibir_linha_separadora, cont){
	var nova_largura = largura;
	var	nova_altura = altura;

	borda = exibir_borda == 1 ? "border:1px solid #000000" : "";
	linha = exibir_linha_separadora == 1 ? "<hr size=1 class=\"cor_letra\" style=\"opacity:.60; -moz-opacity:.60; filter:alpha(opacity=60);\">" : "";

	if (cont == 1)
		document.write('<img src='+diretorio+'/'+cd_foto+' width='+nova_largura+' height='+nova_altura+' name=foto style="\margin-bottom:'+margem_rodape+'px; '+borda+'\" title="'+legenda_data+'">'+linha);
	else
		document.write('<div class=espaco_foto style=\"margin-bottom:$campo_foto[margem_rodape]px\">$comentario<br><br><img src=../fotos/$campo_foto[diretorio]/$campo_foto[codigo_foto].jpg width=$campo_foto[largura] height=$campo_foto[altura]></div>');
		document.write('<img src='+diretorio+'/thumbs/'+cd_foto+' width=94 height=71 name=foto style="\margin-bottom:'+margem_rodape+'px; '+borda+'\" onclick="javascript: this.src=\''+diretorio+'/'+cd_foto+'\'; this.width='+nova_largura+'; this.height='+nova_altura+';" title="'+legenda_data+'" style="cursor:hand">'+linha);
	}

	function fechar(){
		document.getElementById('exibir_opcao').style.display = 'none';
}