﻿$(function(){
	$("#modalBg").css({"opacity":"0.5"});
	$(".modalResp").click(function(){
		var respostas = new Array();
		respostas[0] = "To dentro";
		respostas[1] = "To fora";
		respostas[2] = "Talvez";
		var pai = $(this).parent().parent();var evento ="";var resp="";
		pai.find(".optionsEvent").children().children("input").each(function(i){
			if($(this).attr("checked")==true){
				evento =  $(this).attr("name").split("event");				
				resp = $(this).val();				
			}
		});
		if(evento==""){
			alert("Selecione alguma opção!");
			return false;
		}
		$.post("acoes.php?action=respEvento",{r:resp,e:evento[1]},function(retorno){
			if(retorno!=0){
				pai.find(".optionsEvent").children().children("input").each(function(i){
					if($(this).attr("value")==retorno){
						$(this).attr("checked","checked");
					}
				});
				var mylink = document.createElement("a");
				mylink.innerText = respostas[retorno-1];
				mylink.href="javascript:void(0);";
				mylink.setAttribute("class","LinkAzul11 showModal");
				mylink.onclick = function(){
						pai.parent().find(".modalRespEvent").show();
						$("#modalBg").show();
				}
				pai.parent().find(".rfloat").html("");
				pai.parent().find(".rfloat").append(mylink);
			}else{
				alert("Não foi possível completar a operação. Tente novamente mais tarde.");				
			}
			pai.hide();
			$("#modalBg").hide();
		});
	});
	$(".modalCancel").click(function(){
		$(this).parent().parent().hide();	
		$("#modalBg").hide();
	});
	$(".showModal").click(function(){
		$(this).parent().parent().find(".modalRespEvent").show();
		var t = (document.body.scrollHeight);
		$("#modalBg").show();
	});
	var text="";	   			   
	var selectedIndex = 0;
	$("input[name=evento]").click(function(){
		$("#seeAllEvents").html("Cancelar");
		$(".eventAdvanced").show();
		selectedIndex = $("select[name=horaEvento]").attr("selectedIndex");
	});	   
	$("#seeAllEvents").click(function(){
		var o = $(this).html();
		var today = new Date();
		var hj = new Array(3);
		if(o=="Cancelar"){
			$(".eventAdvanced").hide();
			hj[0] = today.getDay();
			if(hj[0]<10){
				hj[0] = "0"+hj[0];
			}
			hj[1] = "0"+parseInt((today.getMonth())+1);
			hj[2] = today.getFullYear() ;
			$(this).html('Ver todos');
			$("select[name=horaEvento]").attr("selectedIndex",selectedIndex);
			$("input[name=evento]").val('Qual é o evento?');
			$("input[name=localidadeEnvento]").val('Onde?');
			$("input[name=dataEvento]").val(hj[0]+"/"+hj[1]+"/"+hj[2]);
			return false;
		}
	});
	$(".autoLimpar").click(function(){
		text = $(this).val();
		$(this).val('');
	}).blur(function(){
		var conteudo = $(this).val();
		if(conteudo==""){
			$(this).val(text);
		}
	});
	$("#mais_atualizacao").click(function(){
		var until = $("input[name='nextMenssages']").val();
		var h = 0;
		$("#mural .mural_item").each(function(i){
			if(i<(parseInt(until)+0)){
				h += $(this).height()+11;	
			}								  
		});
		$("#mural").css({height:(h+10)});
		if(until!=30){
			$("input[name='nextMenssages']").val(parseInt(until)+10);	
		}else{
			$("#mais_atualizacao").css({"display":"none"});
		}
	});
	
	$("#boxFiltrosToggle").click(function(){
		$("#boxfiltros").slideToggle();
	});
	$(".picEditAlbum textarea").click(function(){
		var valor = $(this).val();
		if(valor=="Clique para adicionar uma legenda."){
			$(this).val('');
		}
	}).blur(function(){
		var valor = $(this).val();
		if(valor==""){
			$(this).val('Clique para adicionar uma legenda.');
		}	
	});
	$(".messages").mouseover(function(){
		$(this).find(".messageDelOne").show();
	}).mouseout(function(){
		$(this).find(".messageDelOne").hide();	
	});	   
	$(".excluirPhoto,.excluirVideo").click(function(){
		var _class = $(this).attr('class');	 
		var pai = $(this).parent();
		if(_class=="excluirVideo"){
			var video = $(this).parent().find('input[type="hidden"]').val();
			$.ajax({
			   type: "POST",url: "acoes.php",data:"videoID="+video+"&a=remove",
			   success: function(retorno){
					if(retorno==1){
						$(this).remove();		
						pai.remove();		
					}else{
					  alert("Erro ao Excluir este Vídeo! Tente Novamente mais Tarde");
					}
			   }
			 });
		}else{
			var photo = $(this).parent().find('input[type="hidden"]').val();
			$.ajax({
			   type: "POST",url: "acoes.php",data:"photoID="+photo+"&a=remove",
			   success: function(retorno){
					if(retorno==1){
						$(this).remove();		
						pai.remove();		
					}else{
					  alert("Erro ao Excluir esta Imagem! Tente Novamente mais Tarde");
					}
			   }
			 });
		}
	});
	$(".excluirAlbum,.excluirAlbum_V").click(function(){
		var _class = $(this).attr('class');
		var album = $(this).parent().find('input[type="hidden"]').val();
		var pai = $(this).parent();
		if(_class == "excluirAlbum_V"){
			$.ajax({
			   type: "POST",url: "acoes.php",data: "albumID_V="+album+"&a=remove",
			   success: function(retorno){
					if(retorno==1){
						$(this).remove();		
						pai.remove();		
					}else{
					  alert("Erro ao Excluir este álbum! Tente Novamente mais Tarde");
					}
			   }
			 });	
		}else{
			$.ajax({
			   type: "POST",url: "acoes.php",data: "albumID="+album+"&a=remove",
			   success: function(retorno){
					if(retorno==1){
						$(this).remove();		
						pai.remove();		
					}else{
					  alert("Erro ao Excluir este álbum! Tente Novamente mais Tarde");
					}
			   }
			 });			
		}
	});		   
	$(".album,.album_pic").hover(
	function(){
		var c = $(this).attr('class');
		var pos = $(this).offset();
		var w = $(this).width();
		if(c=="album"){
			var t = $(this).find('.excluirAlbum').width();
			$(this).find('.excluirAlbum').css({left:(pos.left+5),top:(pos.top+5)}).show();
			$(this).find('.excluirAlbum_V').css({left:(pos.left+5),top:(pos.top+5)}).show();
		}else{
			var t = $(this).find('.excluirPhoto').width();
			$(this).find('.excluirPhoto').css({left:(pos.left+5),top:(pos.top+5)}).show();
			$(this).find('.excluirVideo').css({left:(pos.left+5),top:(pos.top+5)}).show();			
		}
	},
	function(){
		var c = $(this).attr('class');
		if(c=="album"){
			$(this).find('.excluirAlbum').hide();	
			$(this).find('.excluirAlbum_V').hide();	
		}else{
			$(this).find('.excluirPhoto').hide();	
			$(this).find('.excluirVideo').hide();	
		}
		
	});
	$("input[name=video_select]").click(function(){
		var tipo = $(this).val();
		var texto =$(this).parent().find("span[class=block]").html();
		if(tipo==2){
			$(this).parent().find("span[class=block]").html("<strong>Carregue seu V&iacute;deo...</strong>");
			$(this).parent().find("input[name=url_video]").hide();
			$("#enviar_movSub").removeClass("hidden").attr("disabled","disabled");
			$("#enviar_mov").hide();
			$(this).parent().find("input[name=arquivoVideo]").removeClass("hidden");	
		}else if(tipo!=2 && texto=="<strong>Carregue seu Vídeo...</strong>" ){
			$(this).parent().find("span[class=block]").html("<strong>Insira a URL do v&iacute;deo.</strong>");
			$(this).parent().find("input[name=url_video]").show();
			$("#enviar_movSub").addClass("hidden");
			$("#enviar_mov").show();
		}
	});
	$("input[name=arquivoVideo]").change(function(){
		var ext = $(this).val().split(".")[1].toLowerCase();
		if(ext=="mov" || ext=="swf" || ext=="wmv" || ext=="mpeg" || ext=="ogg" || ext=="webm" ){
			$("#enviar_movSub").removeAttr('disabled');
		}else{
			alert("Somente Arquivos de Vídeo");	
			$(this).val('');
		}
	});
	var click = 0;
	$("input[name='foto_share']").change(function(){
		$("#enviar_pic").attr('disabled','');
	});
	$("input[name='upload_pic'],input[name='upload_mov']").click(function(){
		var valor = $(this).val();
		if(valor=="Faça um comentário sobre a foto..." || valor=="Faça um comentário sobre a vídeo..."){
			$(this).val('');
		}
	}).blur(function(){
		var valor = $(this).val();
		if(valor==""){
			if($(this).attr('name')=="upload_mov"){
				$(this).val("Faça um comentário sobre a vídeo...");	
			}else{
				$(this).val("Faça um comentário sobre a foto...");
			}
		}
	});
	var tog = new Array();
	var background = new Array();
	$("#jewelSolicitation,#jewelMensages,#jewelNotification").each(function(i){
		return false;
		tog[i] = $(this).parent().find(".toggle");
		background[i] = $(this).parent(); 
		$(this).click(function(){
			var id = $(this).parent().find(".toggle").attr("id");
			for(x=0;x<tog.length;x++){
				if(id!=tog[x].attr("id")){
					tog[x].css("display","none");
					background[x].css({background:'#3f6e55'});
				}
			}
			var display = $(this).parent().find(".toggle").css("display");
			if(display=="none"){
				$(this).parent().find(".toggle").css("display","block");
				$(this).parent().css({background:'white'});
			}else{
				$(this).parent().find(".toggle").css("display","none");	
				$(this).parent().css({background:'#3f6e55'});
			}
			return false;
		});
	});
	$("#jewelSolicitation,#jewelMensages,#jewelNotification").click(function(){
		return false;
		var offset = $(this).offset();
		var posleft = 0;
		var cor = $(this).parent().css("background-color");
		if(offset.left==0){
			posleft = 863;
		}else{
			posleft = offset.left;
		}
		if(color="rgb(0,153,153)"){
			$(this).parent().css({background:'white'});
		}else{
			$(this).parent().css({background:'#009999'});
		}
		
		$(this).parent().find(".toggle").toggle().css({left:posleft});
		return false;
	});
	
	function hasNew(t){
		var id = $("#usuario").val();
		switch(t){
			case 1:
				$.ajax({url: 'acoes.php?hasNew=1&user='+id,
				  success: function(retorno) {
				    $("#solicitationsCountValeu").text(retorno);
					if(retorno>0){
						$("#jewelSolicitation span").removeClass('hidden');	
					}
				  }
				});
				break;
			case 2:
				$.ajax({url: 'acoes.php?hasNew=2&user='+id,
				  success: function(retorno) {
				    $("#mensagesCountValeu").text(retorno);
					if(retorno>0){
						$("#jewelMensages span").removeClass('hidden');	
					}
				  }
				});
				break;
			case 3:
				$.ajax({url: 'acoes.php?hasNew=3&user='+id,
				  success: function(retorno) {
				    $("#notificationsCountValeu").text(retorno);
					if(retorno>0){
						$("#jewelNotification span").removeClass('hidden');	
					}
				  }
				});
				break;
		}
	}
	hasNew(1);hasNew(2);hasNew(3);
	$("#pesquisar input[type='text']").click(function(){
		if(click==0){
			$(this).val('');
			click=1;
		}								 
	});
	$("#open_status,#open_link,#open_foto,#open_video").click(function(event){
		$("#status,#link,#foto,#video").addClass("hidden");
		click=0;
		event.preventDefault();
		var obj = $(this).attr("name");
		$("#"+obj).removeClass("hidden");
	});
	$("#status textarea,#link input").click(function(){
		if(click==0){
			$(this).text('');
			$(this).val('');
			click=1;
		}
		if(click!=0){
			$(this).parent().find("button").show();
		}
	});
	var e = 0;
	$("#cad_home").submit(function(){
		var c = 0;
		$("#cad_home input[type='text'],#cad_home input[type='password'],#cad_home select").each(function(i){
			if($(this).val()==""){
				$(this).focus();
				$(".error").fadeIn().html("Você deve preencher todo os campos.");
				return false;
			}else{
				c += 1;	
			}
		});
		var email = $("#cad_home input[name='email']").val(); 
		var email2 = $("#cad_home input[name='email_again']").val();
		if(email!=email2){
			$(".error").fadeIn().html("E-mails devem ser iguais!");
			return false;
		}
		if(c==10 && e==1){
			return true;
		}
		return false;
	});
	$("#cad_home input[name='email']").blur(function(){
		email = $(this).val();
		if((email.indexOf("@")=="-1") || (email.indexOf(".")=="-1")){
			$(".error").fadeIn().html("E-mail inválido.");
			e=0;
			return false;
		}
		$.ajax({
		   type: "POST",url: "acoes.php",data: "email="+email,
		   beforeSend:function(){$(".carregando").show();},
		   success: function(retorno){
			   $(".carregando").hide();
			   	if(retorno==0){
			   		$(".error").fadeIn().html("Este e-mail já esta sendo utilizado.");
			   		e=0;
			   	}else{
			   		e = 1;
			   	}
		   }
		 });
	});
	if($("a[rel='example1']")){
		$("a[rel='example1']").colorbox();
	}
	if($("a[rel='photo']")){
		$("a[rel='photo']").colorbox({iframe:true, innerWidth:600, innerHeight:486});
	}
	if($("a[rel='video']")){
		$("a[rel='video']").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	}
});

//AJAX 
function Ajax() {
	var ajax;
	if (window.ActiveXObject) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				ajax = false;
			}
		}
	} else if (window.XMLHttpRequest) {
		ajax = new XMLHttpRequest
	} else {
		ajax = false;
	}
	return ajax;
}
//ADD AMIGO
function addFriend(i,f,obj){
	var ajax = new Ajax();
	ajax.open('POST', 'acoes.php?a=add&u='+i+'&f='+f, true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState < 4) {
			//Executa algo enquanto esta enviando a requisição
		}else{
			if (ajax.status == 200) {
				alert(ajax.responseText);
				obj.innerHTML="Solicitação Enviada";
				obj.disabled = true;
			}
		}
	}
	ajax.send(null);
return false;
}

function toogle(t){
	var ajax = new Ajax();
	var id = document.getElementById('usuario').value;
	switch(t){
		case 1:
			var obj = document.getElementById('tg_solicitacoes');
			ajax.open('POST', 'acoes.php?user='+id+'&toggle=1', true);
			break;
		case 2:
			var obj = document.getElementById('tg_mensagens');
			ajax.open('POST', 'acoes.php?user='+id+'&toggle=2', true);
			break;
		case 3:
			var obj = document.getElementById('tg_notificacoes');
			ajax.open('POST', 'acoes.php?user='+id+'&toggle=3', true);
			break;
	}
	
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
				obj.innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
return false;
}
//CARREGA MURAL
function carregaMural(){
	var ajax = new Ajax();
	var mural = document.getElementById('mural') ;
	var id = document.getElementById('usuario').value;
	var id_profile = document.getElementById('profile_id').value;
	var usuario = 0;
	if(id_profile==0){
		usuario = id;
	}else{
		usuario = id_profile;
	}
	ajax.open('POST', 'mural.php?user='+usuario, true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState < 4) {
			mural.innerHTML = "Carregando...";
		}else{
			if (ajax.status == 200) {
				//alert(ajax.responseText);
				mural.innerHTML = ajax.responseText;
				$(function(){
					var h =0;	  
					var nextMessages = new Array();
					nextMessages['obj'] = $("input[name='nextMenssages']");
					nextMessages['value']= $("input[name='nextMenssages']").val();
					$("#mural .mural_item").each(function(i){
						if(i<(parseInt(nextMessages['value'])+1)){
							h += $(this).height()+11;		
						}
					});
					$("#mural").css({height:(h),"overflow":"hidden"});
					nextMessages['obj'].val(parseInt(nextMessages['value'])+10);
					$("#mais_atualizacao").show();
				});
			}
		}
	}
	ajax.send(null);
return false;
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

function share($tipo){
	var ajax = new Ajax();
	var id = document.getElementById('usuario').value;
	var id_amigo = document.getElementById('profile_id').value;
	if(id_amigo=id){
		id_amigo = 0;
	}
	switch($tipo){
		case 'status':
			var msg = document.getElementById('textStatus').value;
			document.getElementById('textStatus').value="";
			break;
		case 'link':
			var msg = document.getElementById('textLink').value;
			document.getElementById('textLink').value="";
			break;
		case 'video':
			var msg = document.getElementById('textVideo').value;
			var site = document.getElementsByName("video_select");
			var url_video = document.getElementById('urlVideo').value;
			if(trim(url_video)==""){
				return false;
			}
			for(var i=0;i<site.length;i++){
				if(site[i].checked==true){ 
					var s = site[i].value;
				}
			}

			if(s==0 && !url_video.match(/youtube.com/)){
				alert("URL Inválida para vídeos do Youtube!");
				return false;
			}else if(s==1 && !url_video.match(/vimeo.com/)){
				alert("URL Inválida para vídeos do Vimeo!");	
				return false;
			}
			document.getElementById('textVideo').value="";
			break;
	}
	if(msg=="" && $tipo!="video"){
		return false;
	}
	ajax.open('POST', 'mural.php?msg='+msg+'&cad='+$tipo+'&user='+id+'&amigo='+id_amigo+'&url='+url_video, true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
				carregaMural();
		}
	}
	ajax.send(null);
return false;
}
//
function like($u,obj){
	var texto = obj.childNodes[0];
	texto.innerHTML="Curtir(desfazer)";
	var ajax = new Ajax();
	var id = document.getElementById('usuario').value;
	ajax.open('POST', 'mural.php?post='+$u+'&user='+id+'&cad=curtir', true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			carregaMural();
		}
	}
	ajax.send(null);
	return false;
}
//ENVIAR
function enviar(obj,e){
	var c = obj.value;var shift;var r = obj.rows; shift = e.shiftKey;
	var post_id = obj.id;
	if(shift && e.keyCode==13){
		obj.rows = r+1;
	}else if(e.keyCode==13){
		obj.value ="";
		obj.rows = r;
		var ajax = new Ajax();
		var id = document.getElementById('usuario').value;
		ajax.open('POST', 'mural.php?coment='+c+'&post='+post_id+'&user='+id, true);
		ajax.onreadystatechange = function leituraRequisicao() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				if(document.getElementById('mural')){
					carregaMural();	
				}else{
					window.location.reload();
				}
			}
		}
		ajax.send(null);
		return false;
	}
}
//
function addAmigo(x,y){
	//x = id da solicitação
	//y = id de quem pediu
	var id = document.getElementById('usuario').value; // id do usuario logado
	var ajax = new Ajax();
	ajax.open('GET', 'mural.php?pedido='+x+'&amigo='+y+'&user='+id, true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			carregaMural();
			toogle(1);toogle(2);toogle(3);
			window.parent.location.reload();
		}
	}
	ajax.send(null);
	return false;
}
//
function mostrarDel(obj){
	var x = obj.firstChild;
	var y  = document.querySelectorAll("div.mural_item");
	var z  = document.querySelectorAll(".uiList li");
	var _class ="" ;
	if(obj=='[object HTMLDivElement]'){
		for(var i=0;i<y.length;i++){
			if(y[i].firstChild!='[object HTMLImageElement]' && y[i]!=obj){
				y[i].firstChild.style.visibility= "hidden";
			}
		}	
	}else{
		for(var g=0;g<z.length;g++){
			//alert(z[g].firstChild);
			_class = z[g].getAttribute('class');	
			if(_class!="seeAllComments"){
				z[g].firstChild.style.color= "red";
				z[g].firstChild.style.visibility= "hidden";	
			}
			
		}		
	}
	x.style.visibility= "visible";
}
//
function removePost(id_post,obj,tipo){
	obj.parentNode.parentNode.removeChild(obj.parentNode);
	var ajax = new Ajax();
	switch(tipo){
		case 1:
			ajax.open('POST', 'mural.php?del=1&post='+id_post, true);
			break;
		case 2:
			ajax.open('POST', 'mural.php?del=1&coment_id='+id_post, true);
			break;	
	}
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			//alert(ajax.responseText);
		}
	}
	ajax.send(null);
	return false;
}
//RECUSA AMIGO
function recusaAmigo(x,y,obj){
	//x = id da solicitação
	//y = id de quem pediu
	var id = document.getElementById('usuario').value; // id do usuario logado
	var ajax = new Ajax();
	ajax.open('POST', 'mural.php?tipo=recusa&pedido='+x+'&amigo='+y+'&user='+id, true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			//toogle();
			window.parent.location.reload();
			//counts(1);
		}
	}
	ajax.send(null);
	return false;
}
//RESPONDE SOLICITACAO
function responderSolicitacao(x,y,obj){
	var usuario = document.getElementById('nome_pedido').value;
	var confirma = confirm(usuario+" gostaria de adicionar você aos amigos. Caso você conheça "+usuario+", clique em Ok.");
	if(confirma==true){
		//x = id da solicitação
		//y = id de quem pediu
		var id = document.getElementById('usuario').value; // id do usuario logado
		var ajax = new Ajax();
		ajax.open('GET', 'mural.php?pedido='+x+'&amigo='+y+'&user='+id, true);
		ajax.onreadystatechange = function leituraRequisicao() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				window.parent.location.reload();
			}
		}
		ajax.send(null);
		return false;
	}
}
//DESAFIAR
function desafiar(obj){
	var x = document.getElementById('usuario').value;
	var y =document.getElementById('profile_id').value;
	var ajax = new Ajax();
	ajax.open('GET', 'mural.php?tipo=desafio&amigo='+y+'&user='+x, true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if(ajax.readyState == 4 && ajax.status == 200) {
			var resp = ajax.responseText;
			if(resp==0){
				obj.disabled=true;
				obj.innerHTML="Desafio enviado";	
			}else{
				alert("Erro ao Desafiar,este usuário!");	
			}
		}
	}
	ajax.send(null);
	return false;	
}
//RESPONDER DESAFIO
function respDesafio(n,d,s){
	var ajax = new Ajax();
	ajax.open('GET', 'mural.php?tipo=resp&not='+n+'&resp='+s+'&desafio='+d, true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if(ajax.readyState == 4 && ajax.status == 200) {
			window.parent.location.reload();
		}
	}
	ajax.send(null);
	return false;
}

function deslike(post,obj){
	var id = document.getElementById('usuario').value;
	var texto = obj.childNodes[0];
	texto.innerHTML="Curtir";
	var ajax = new Ajax();
	ajax.open('POST', 'mural.php?post='+post+'&user='+id+'&cad=curtir_remove', true);
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			carregaMural();
		}
	}
	ajax.send(null);
	return false;
}

function abrePopUp(type){
	if(type==0){
		window.parent.location = "criarAlbum.php";	
	}else{
		window.parent.location = "criarAlbum_V.php";	
	}
}

function verificaTamanho(){
	var oas = new ActiveXObject("Scripting.FileSystemObject");
	alert(document.getElementById("videoFile").value);
	alert(document.getElementById("videoFile").fileSize);
	return false;
}

function aumentaCampo(obj){
	var tamanhoTotal = (obj.rows*obj.cols);
	var tamamhoAtual = obj.value.length;
	if(tamanhoTotal==tamamhoAtual){
		obj.rows = obj.rows +1;
	}
}

function verificaEnter(obj,e){
	var r = obj.rows;
	if(e.keyCode==13){
		obj.rows = r+1;
	}
}

function validaCampo(obj){
	var div = obj.childNodes[1]; 
	var v =div.childNodes[1].value;
	if(v!=""){
		return true;	
	}
	return false;
}

function actionMsg(obj){
	var v = obj.value;
	var ajax = new Ajax();
	var x = document.getElementById('userId').value; // x id do usuario logado
	var y = document.getElementById('amigoId').value; // y id do amigo

	if(v==1){
		var c = confirm("Deseja realmente excluir todas as mensagens?");
		if(c==false){
			obj.selectedIndex = 0;
			return false;
		}
		ajax.open('POST', 'acoes.php?excluir=mensagem&user='+x+'&amigo='+y, true);
	}else if(v==2){
		obj.selectedIndex = 0;
	}
	ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			window.parent.location.reload();
		}
	}
	ajax.send(null);
	return false;
}

function delMsg(obj){
	var elemento = obj.parentNode;
	var conf = confirm("Deseja realmente excluir todas as mensagens entre você e esse usuário?");
	if(conf==true){
		var idAmigo = elemento.childNodes[1].value;
		var ajax = new Ajax();
		ajax.open('POST', 'acoes.php?action=delAllMsgs&amigo='+idAmigo, true);
			ajax.onreadystatechange = function leituraRequisicao() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				window.parent.location.reload();
			}
		}
		ajax.send(null);
		return false;
	}
}

function deletarMsg(obj){
	var elemento = obj.parentNode;
	var pai = elemento.parentNode;
	var conf = confirm("Deseja realmente excluir esta mensagen?");
	if(conf==true){
		var idMensagem = elemento.childNodes[1].value;
		var ajax = new Ajax();
		ajax.open('POST', 'acoes.php?action=delMsgs&mensagemID='+idMensagem, true);
			ajax.onreadystatechange = function leituraRequisicao() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				var retorno = ajax.responseText;
				if(retorno==1){
					pai.style.display="none";
				}
			}
		}
		ajax.send(null);
		return false;
	}
}

function filterGroup(obj){
	var filterText = document.getElementById('typeSearch');
	var v = obj.value;
	if(v==3){
	  filterText.value = "players";	
	}else if(v==2){
	  filterText.value = "team";
	}else if(v==4){
	  filterText.value = "torcidas";	
	}
	document.frm_busca.submit();
	if(document.getElementById("advancedSearch")){
		var popup = document.getElementById("advancedSearch");
		//popup.style.display="block";
	}
}

function criarEvento(){
	var nomeEvent = new Array(2);
		nomeEvent['obj'] = document.frm_eventos.evento;
		nomeEvent['value'] = document.frm_eventos.evento.value;
	var localEvent = new Array(2);
		localEvent['obj'] = document.frm_eventos.localidadeEnvento;
		localEvent['value'] = document.frm_eventos.localidadeEnvento.value;
	if(nomeEvent['value'] =="Qual é o evento?"){
		alert("Dê um nome para o Evento!");	
		nomeEvent['obj'].focus();
		return false;
	}
	if(localEvent['value']=="Onde?"){
		alert("Onde será este evento?\nPor favor preenchar o campo!");
		localEvent['obj'].focus();
		return false;
	}
	return true;
}

function searchConvidados(v){
	var ajax = new Ajax();
	var list = document.getElementById('inviteFriendList');
	ajax.open('POST', 'acoes.php?action=inviteEvent&name='+v, true);
		ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			list.innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
	return false;
}

function responderEvento(resp,o){
	var pai = o.parentNode;
	var filhos = pai.childNodes.length;
	for(var i = 0;i<filhos;i++){
		if(pai.childNodes[i]=="[object HTMLInputElement]"){
			var id = pai.childNodes[i].value;
		}
	}
	var ajax = new Ajax();
	ajax.open('POST', 'acoes.php?action=respConviteEvento&id='+id+'&resp='+resp, true);
		ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			alert(ajax.responseText);
		}
	}
	ajax.send(null);
	return false;
}
//show_hideEvent
function show_hideEvent(){
	var toogle = document.getElementById('convitesEventos');	
	toogle.style.display = "block";
}
//showOlheiro
function showOlheiro(){
	if(document.getElementById("modalOlheiro")){
		document.getElementById("modalOlheiro").setAttribute("class","");
	}
}
//toogleObj
function toogleObj(obj){
	var o = document.getElementsByTagName("li");
	for(var i = 0;i<o.length;i++){
		if(o[i].getAttribute("class")== "selectedItem"){
			o[i].setAttribute("class","");	
		}
	}
	var _class = obj.getAttribute("class");
	//_eclass.setAttribute("class","");
	obj.parentNode.setAttribute("class","selectedItem");
	if(_class == "hidden"){
		obj.setAttribute("class","");
	}else{
		obj.setAttribute("class","hidden");	
	}
}
//VALIDAR FORM OLHEIRO VIRTUAL
function validadeActionForm(obj){
	var nJog = obj.nameJogador.value;
	if(nJog !=""){
		var s = obj.getAttribute("action").split("&");
		var newAction = s[0]+nJog+"&"+s[1];
		obj.setAttribute("action",newAction);
	}
}
//TROCAR GRUPO[USUARIO]
function changeGroup(o){
	var oldGr = document.getElementById("oldGr").value;
	if(oldGr==o.value){
		alert("Esse já é o seu grupo atual!");
		return false;
	}
	if(confirm("Alterando seu grupo seus dados serão resetados.\nDeseja realmente alterar seu grupo?")){
		var ajax = new Ajax();
		ajax.open('POST', 'acoes.php?action=alterGroup&new_gr='+o.value, true);
		ajax.onreadystatechange = function leituraRequisicao() {
			if (ajax.readyState < 4) {
				
			}else{
				if (ajax.status == 200) {
					var retorno = ajax.responseText;
					if(retorno==1){
						alert("Alteração realizada com sucesso!");
						window.location.href="editprofile.php?sk=basic";					
					}else{
						alert("Não foi possível realizar essa alteração.");
					}
				}
			}
		}
		ajax.send(null);
	}
}
//EXCLUIR GRUPO
function delGroup(){
	if(confirm("Deseja relamente excluir esse Grupo?")==true){
		return true;
	}else{
		return false;		
	}
}
//ATUALIZA CONTADORES
function reloadCounters(type,obj){
	var ajax = new Ajax();
	ajax.open('POST', 'acoes.php?action=atualizaCont&type='+type, false);
		ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			if(ajax.responseText==1){
				window.parent.location.href=obj;
			}else{
				alert(ajax.responseText);	
			}
		}
	}
	ajax.send(null);
	return false;
}
//validadeFormInviteGr
function validadeFormInviteGr(){
	var ck = document.getElementsByName("idConvidados[]");
	var idGr = document.getElementsByName('idGrupo')[0].value;			
	var convidados = "", selecionados = 0;
	for(var i=0;i<ck.length;i++){
		if(ck[i].checked==true){
			if(convidados!=""){
				convidados = convidados+"|";
			}
			convidados = convidados+ck[i].value;
			selecionados += 1;
		}
	}
	if(selecionados>0){
		var ajax = new Ajax();
		ajax.open('POST', 'acoes.php?action=inviteFriendsGr&c='+convidados+'&gr='+idGr, true);
		ajax.onreadystatechange = function leituraRequisicao() {
			if (ajax.status == 200 && ajax.readyState == 4) {
				var retorno = ajax.responseText;
				if(retorno==1){
					alert("Convites enviados!\nSeus amigos receberam uma notificação!");
					window.parent.location.reload();
				}else{
					alert("Ocorreu um erro ao enviar o convite!\nPor favor, tente mais tarde.");
				}
			}
		}
		ajax.send(null);
	}else{
		alert("Selecione pelo menos um dos seus amigos!");
	}
	
	return false;
}
function setModalLock(){
	var _body = document.body;
	var div = "<div id=\"modalBg\"></div>";
	_body.innerHTML =  div+_body.innerHTML;
	var $j = jQuery.noConflict();
	$j(function(){
		$j("#modalBg").css({"opacity":"0.5"});
	});
}

function getInvitesEvents(obj){
	var event_id = (obj.parentNode.getElementsByTagName('input')[0].value);
	openModal(false,'boxInvitesEvent',500);
	var ajax = new Ajax();
	ajax.open('POST', 'acoes.php?action=getConvidadosEvent&event='+event_id, false);
		ajax.onreadystatechange = function leituraRequisicao() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			var modal = document.getElementById('boxInvitesEvent').getElementsByTagName('div')[1];
			modal.innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
	return false;
}

function openModal(hasModal_lock,obj,w){
	if(hasModal_lock==true){
		setModalLock();
	}
	var _obj = document.getElementById(obj);
	var _class = _obj.getAttribute('class'); 
	if(_class=="hidden"){
		_obj.setAttribute('class','modal'); 
	}
	var porc = Math.round((w/1000)*100);
	var margin = (100 - porc)/2;
	_obj.style.width= w+"px";
	_obj.style.marginLeft= (margin-5)+"%";
	_obj.style.marginRight= margin+"%";
}
function closeModal(obj){
	if(document.getElementById("modalBg")){}
	var _obj = document.getElementById(obj);
	_obj.setAttribute('class','hidden'); 
	if(document.getElementById("modalBg")){
		var div = document.getElementById("modalBg");
		document.body.removeChild(div);
	}
}


function getElement(obj,type){
	switch(type){
		case 1:
		default:
			return document.getElementById(obj);
			break;
		case 2:
			return document.getElementsByTagName(obj);
			break;	

	}
}

function showAllComments(obj){
	var hiddenComents =  getElement('li',2);
	var _class;
	for(i=0;i<hiddenComents.length;i++){
		_class = hiddenComents[i].getAttribute('class');
		if(_class=="hidden"){
			hiddenComents[i].setAttribute('class','');
		}
	}
}
