
 jQuery(document).ready(function() {
     jQuery('a[rel*=facebox]').facebox() 
 })
 

 function loadXMLDoc(url,dado,valor)
{
    req = null;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url+"?"+dado+"="+valor, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET",url+"?"+dado+"="+valor, true);
            req.send();
        }
    }
}


function processReqChange()
{
    if (req.readyState == 4) {
        if (req.status == 200) {
            document.getElementById(_div).innerHTML = req.responseText;
        } else {
            alert("Error:\n" + req.statusText);
        }
    }

}

function ajax(valor,dado,div,url)
{
	_div = div;
    loadXMLDoc(url,dado,valor);
}

function mostrarAcoes(atividade_id) {
	obj = document.getElementById('barraAcao'+atividade_id);
	obj.style.display = 'block';
	
	obj = document.getElementById(atividade_id);
	obj.style.backgroundColor = '#FFFFFF';
}
function ocultarAcoes(atividade_id) {
	obj = document.getElementById('barraAcao'+atividade_id);
	obj.style.display = 'none';
	
	obj = document.getElementById(atividade_id);
	obj.style.backgroundColor = '#EFEFEF';
	
}


function mudaImg(obj,img) {
	obj.src = img;
}
function habilitaComment(obj,id) {
	obj.rows = 3;
	obj.value = '';
	obj2 = document.getElementById('acoes-'+id);	
	obj2.style.display = 'block';
	
	obj3 = document.getElementById('avatarlogado-'+id);	
	obj3.style.display = 'block';
}

function irjunto(id) {
	
	ajax(id,'meet','divajax','do/join');
	
	objir =  document.getElementById('ir-'+id);	
	objdeixar =  document.getElementById('deixar-'+id);	
	
	objir.style.display = 'none';
	objdeixar.style.display = 'block';
	
	//obj = document.getElementById('comentar-'+id);	
	//obj.style.display = 'block';
	
	$('#comentar-'+id).show("slow");
	
}

function deixar(id) {
	
	ajax(id,'meet','divajax','do/leave');
	
	objir =  document.getElementById('ir-'+id);	
	objdeixar =  document.getElementById('deixar-'+id);	
	
	objir.style.display = 'block';
	objdeixar.style.display = 'none';
	
//	obj = document.getElementById('comentar-'+id);	
//	obj.style.display = 'block';
	$('#comentar-'+id).show("slow");
	
}
function enviaComentario(id) {
	obj =  document.getElementById('textocomentario-'+id);	
	ajax(obj.value,'texto','alerta','do/add-comment?meet='+id+'&');
	
	$('#alerta').show("slow");
	 
	 setTimeout(function(){ $("#alerta").hide("normal");},3000);
	 
	obj2 = document.getElementById('comentar-'+id);	
	obj2.style.display = 'none';
}

function enviaMsgDireta(id,uid) {
	obj =  document.getElementById('textocomentario-'+id);	
	ajax(obj.value,'texto','divajax','do/add-message?uid='+uid+'&meet='+id+'&');
	
	obj2 = document.getElementById('comentar-'+id);	
	obj2.style.display = 'none';
}

function mostraOpcoesMeet() {
	//obj2 = document.getElementById('add-atividade-opcoes');	
	//obj2.style.display = 'block';	
	 $('#add-atividade-opcoes').show("slow");
}

function selecionacidade(id,nome) {
	obj = document.getElementById('meetcidade');	
	obj.value = nome;	
	
	obj2 = document.getElementById('meetcidadeid');	
	obj2.value = id;	
	
	obj3 = document.getElementById('lista-cidades');	
	obj3.innerHTML = '';

}
 
 function enviaMeet() {
	city = document.getElementById('meetcidade');	
 	city_id = document.getElementById('meetcidadeid');	
	texto	=  document.getElementById('textarea1');
	dia  =   document.getElementById('inputDate'); 
	nivel =  document.getElementById('privacidade'); 
	participante =  document.getElementById('participantes');
	qqr = document.getElementById('qualquerdia_input');
	if(texto.value != '') {
		ajax('1','meet','atividades','/do/addmeet?city='+city.value+'&city_id='+city_id.value+'&texto='+texto.value+'&dia='+dia.value+'&nivel='+nivel.value+'&part='+participante.value+'&qqr='+qqr.value+'&');
	}
	
	 $('#add-atividade-opcoes').hide("slow");
	 texto.value = '';
	 
	 count = document.getElementById('countsprytextarea1');
	 count.innerHTML = '140';
	
}
function showAvatarForm() {
	obj = document.getElementById('avatarForm');	
	obj.style.display = 'block';	
}

function limpaCampo(obj) {
	obj.value = '';
}
function limpaCampoSenha(obj) {
	obj.value = '';
	obj.type = "password";
}

function buscameets() {
	objmeet = document.getElementById('meet');	 
	objcidade = document.getElementById('meetcidadeid');	 
	objdata = document.getElementById('inputDate');	 
	objqualquer  = document.getElementById('qualquerdia_input');	 
	objsexo = document.getElementById('sexvalue');	 
	atividades.style.display = 'none';
	ajax('1','var','atividades','/do/find-meets?meet='+objmeet.value+'&cidade='+objcidade.value+'&data='+objdata.value+'&qualquer='+objqualquer.value+'&sexo='+objsexo.value+'&');
	
	 setTimeout(function(){ $("#atividades").show("normal");},1000);
}

function remover(id) {
	 $("#"+id).hide("normal");
	 ajax(id,'meet','divajax','do/remove-meet');
}

function more(start,type) {
	obj = document.getElementById('moremeets'+start);	
	obj.style.display = 'none';	
	ajax(start,'start','moremeets'+start,'do/more-meets?type='+type+'&');
	$('#moremeets'+start).show("slow");
}

function alerta(msg) {
	ajax(msg,'msg','alerta','do/alert');
}

function adicionarFavorita(id) {
	 ajax(id,'meet','alerta','do/add-favorite');
	 $('#alerta').show("slow");
	 
	 setTimeout(function(){ $("#alerta").hide("normal");},3000);
}

function exibeBoxResposta(id) {
	$('#responder-'+id).show("slow");
}

function removeMensagem(id) {
	ajax(id,'meet','divajax','do/remove-message');
	$('#box-'+id).hide("slow"); 	
} 

function changeSex(valor) {
	obj = document.getElementById('sexvalue');	
	obj.value = valor;
	
	_ich = document.getElementById('ich');	
	_icm = document.getElementById('icm');	
	_ichm = document.getElementById('ichm');	

	switch(valor) {
		case 'h' :
			_ich.src = '/images/hs.png';
			_icm.src  = '/images/mn.png';
			_ichm.src  = '/images/hmn.png';
		break;
		case 'm' :
				_ich.src = '/images/hn.png';
			_icm.src  = '/images/ms.png';
			_ichm.src  = '/images/hmn.png';
		break;
		case 'hm' :
			_ich.src = '/images/hn.png';
			_icm.src  = '/images/mn.png';
			_ichm.src  = '/images/hms.png';
		break;
	}
	
}

function exibeBoxData() {
	$('#qualquerdia').hide();
	$('#emumdia').show();
	
	obj = document.getElementById('qualquerdia_input');	
	obj.value = '1';

}
function fechaBoxData() {
	$('#qualquerdia').show();
	$('#emumdia').hide();

	obj = document.getElementById('qualquerdia_input');	
	obj.value = '0';
}

function enviaContato() {

	ajax(texto.value,'texto','alerta','/do/add-contact?assunto='+assunto.value+'&');
	
	texto.value = '';
	assunto.value = '';

	 $('#alerta').show("slow");
	 
	 setTimeout(function(){ $("#alerta").hide("normal");},3000);

}

function reenviaSenha() {
	ajax(login.value,'login','alerta','/do/resend-pass');
	
	login.value = '';

	$('#alerta').show("slow");
	 
	 setTimeout(function(){ $("#alerta").hide("normal");},3000);
}

function seguir(uid) {
	ajax(uid,'uid','alerta','/do/follow');
	
	$('#alerta').show("slow");
	 
	 setTimeout(function(){ $("#alerta").hide("normal");},3000);
	 
		$('#botaoseguir').hide(); 
		$('#botaounfollow').show("slow");
}

function unfollow(uid) {
	ajax(uid,'uid','alerta','/do/unfollow');
	
	$('#alerta').show("slow");
	 
	 setTimeout(function(){ $("#alerta").hide("normal");},3000);
	 
		$('#botaoseguir').show("slow");
		$('#botaounfollow').hide()
}

function alteraSenha() {
	
	obj = document.getElementById('senha');	
	
	
	ajax(obj.value,'senha','alerta','/do/change-pass');
	
	$('#alerta').show("slow");
	  
	 setTimeout(function(){ $("#alerta").hide("normal");},3000);
	 
}

function formatar_mascara(src, mascara) {
	var campo = src.value.length;
	var saida = mascara.substring(0,1);
	var texto = mascara.substring(campo);
	if(texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}
