var comunidade = {
		paramsEvento: function() {
			return {
			 TituloEvento:$("txtTituloEvento").value,
			 LocalEvento:$("txtLocal").value,
			 DataEvento: $("Calendario").value,
			 DescricaoEvento:$("txtDescricao_Evento").value,
			 idComunidade: $("hidComunidade").value,
			 Entrada: $("txtEntrada").value
			}	
		},
			paramsdrop: function(){
				
				var tipo = document.getElementById("sltRanking");
				var tipobusca = tipo.options[tipo.selectedIndex].value;
				var ordenabusca;
				ordenabusca = "desc";
				
				
				return{
					ordena: ordenabusca,
					busca: tipobusca,
					acao: 'exibeRanking'
				}
			},
			
			validarPesquisa: function(){
				if($("txtNome").value.length < 3) {
					Mensagem.exibir("false", 'Favor digitar ao menos 3 letras!');
					return false;
				}
				return true;
			},
			
			paramsPesquisar: function(){
				var txtNome = document.getElementById("txtNome").value;
				var cboTipo = document.getElementById("cboTipo").value;
				var cboCategoria = document.getElementById("cboCategoria").value;
				var cboOrdenaComunidade = document.getElementById("cboOrdenaComunidade").value;
				return {
					txtNome : txtNome,
					cboTipo : cboTipo,
					cboCategoria : cboCategoria,
					cboOrdenaComunidade : cboOrdenaComunidade
				};
			},
			
			paramsPesquisarComunidade: function(){
				var txtNome = document.getElementById("txtNome").value;
				var cboTipo = document.getElementById("cboTipo").value;
				var cboCategoria = document.getElementById("cboCategoria").value;
				var cboOrdenaComunidade = document.getElementById("cboOrdenaComunidade").value;
				
				var qs = "?acao=buscarComunidade";
				if(txtNome != ''){
					qs = qs + "&txtNome="+txtNome;
				}
				if(cboTipo != ''){
					qs = qs +"&cboTipo="+cboTipo;
				}
				if(cboCategoria != ''){
					qs = qs + "&cboCategoria="+cboCategoria;
				}
				if(cboOrdenaComunidade != ''){
					qs = qs + "&cboOrdenaComunidade="+cboOrdenaComunidade;
				}
				window.parent.location.href=qs;
				/*return {
					txtNome : txtNome,
					cboTipo : cboTipo,
					cboCategoria : cboCategoria,
					cboOrdenaComunidade : cboOrdenaComunidade
				};*/
			},
			
			paramsPesquisarParticipante: function()
			{
				var txtBusca = document.getElementById("txtCampoBuscaParticipante").value;
				var ordena = document.getElementById("ordenar").value;
				return {
					txtCampoBuscaParticipante : txtBusca,
					ordenar: ordena
				};
			},
			
			exibirEdicaoPerfil: function($perfil){
				if($perfil){
					$("conteudo-perfil").hide();
					$("conteudo-alterarperfil").show();
				}else{
					$("conteudo-alterarperfil").hide();
					$("conteudo-perfil").show();
				}
			},
			abrirUpload: function($exibir){
				if($exibir){
					$("trocarFoto").hide();
					$("inputUpload").show();
				}else{
					$("inputUpload").hide();
					$("trocarFoto").show();
				}
			},
			exibir_img:function($exibir){
				if($exibir){
					$("tam_max").show();
					
				}else{
					$("tam_max").hide();
				
				}
			},
			verificaUpload: function(){
				if($("realupload").value==''){
					Mensagem.exibir("false", 'Favor informar o arquivo!');
					return false;
				}else if($("realupload").value!=''){
					
					var ext = comunidade.strrchr($("realupload").value,'.');
					
					if(ext.toLowerCase() != '.gif' && ext.toLowerCase() != '.jpg' && ext.toLowerCase() != '.png')
					{
						Mensagem.exibir("false","Imagem com extens&atilde;o inv&aacute;lida!");
						return false;

					}
				}else{
					$("uploadFotoComunidade").submit();
				}
				return true;
				
			},
			enviarArquivo: function(){
				$("uploadFotoComunidade").submit();
			},
			enviarUpload: function(){
				document.forms[0].submit();
			},
			escreveHiddenUpload: function(valor){
				$("hidUpload").value = valor;
			},
			enviar:function(){
				var	titulo = $("txt_titulo_comunidade").value;
				var descricao = $("txtCriaComunidade").value;
				var upload = $("hidUpload").value; 
				
				
				if(titulo == ''){
					Mensagem.exibir("false","O campo titulo &eacute; obrigat&oacute;rio");
					return false;
				}
				
				if(descricao == ''){
					Mensagem.exibir("false","Digite a descri&ccedil;&atilde;o da comunidade");
					return false;
				}
			
				if(upload != ""){
					var ext = comunidade.strrchr(upload,'.');
					
					
					if(ext.toLowerCase() != '.gif' && ext.toLowerCase() != '.jpg' && ext.toLowerCase() != '.png')
					{
						Mensagem.exibir("false","Imagem com extens&atilde;o inv&aacute;lida!");
						return false;

					}
				}
				
			
				var controle = 0;
				var tipo = 0;
				
				for (i=0;i<document.form_comunidade.pm_comunidade.length;i++){
					if (document.form_comunidade.pm_comunidade[i].type == "radio"){
						if (document.form_comunidade.pm_comunidade[i].checked == true){
							controle++;
						}
					}
				}
				
				for (i=0;i<document.form_comunidade.tp_comunidade.length;i++){
					if (document.form_comunidade.tp_comunidade[i].type == "radio"){
						if (document.form_comunidade.tp_comunidade[i].checked == true){
							tipo++;
						}
					}
				}
				
				if (controle <= 0){
				
					Mensagem.exibir("false","Por favor selecione a permiss&atilde;o da comunidade");
				return false;
				}
				
				if (tipo <= 0){
					
					Mensagem.exibir("false","Por favor selecione o tipo da comunidade");
				return false;
				}
				
				
				return	document.forms['form_comunidade'].submit();
				
		
			},
			
			paramsEscreverTopico: function(){
				
				var titulo = $("tituloTopico").value;
				var texto = $("txtTopico").value;
				var id = $("idComunidade").value;
				$("divEscreverTopicos").setStyle({'display':'none'});
				$("divTopicos").setStyle({'display':'block'}); 
				//$("recTop").setStyle({'display':'block'});
				
				document.getElementById("txtTopico").value = "";
				document.getElementById("tituloTopico").value="";
				
				return{
					acao: 'escrever_topicos',
					titulo: titulo,
					texto: texto,
					idComunidade:id
				}
				
			},
			paramsBuscarEvento: function(){
				return{
					Nome: $("txtNome").value,
					Ordenacao: $("cboOrdenaEventos").value,
					idComunidade: $("hidComunidade").value
				}	

			},
			
			paramsEditarComunidade: function(){
				
				return{
					titulo : $("txtTitulo").value,
					categoria : $("cboCategoria").value,
					tipo : $("cboTipo").value,
					permissao : $("cboPermissao").value,
					descricao : $("txtDescricao").value,
					idComunidade : $("idComunidade").value
				}
			},
			
			Participar: function(){
				return{
					acao:'participar'
				}	

			},
			
			paramsEscreverRespTopico: function(){
				
				var texto = '';
				
				if($("txtTopico").value != undefined){
					texto = $("txtTopico").value;
				}

				return{
					
					texto: texto,
					acao: 'resposta_topico'
				}
				
			},
			uploadForm: function(valor){
				
				var ext = comunidade.strrchr(valor,'.');
				
				if(ext.toLowerCase() != '.gif' && ext.toLowerCase() != '.jpg' && ext.toLowerCase() != '.png')
				{
					Mensagem.exibir("false","Imagem com extens&atilde;o inv&aacute;lida!");
					return false;
				}
				
				/*var oas = new ActiveXObject("Scripting.FileSystemObject");
				var d = $("realupload").value;
				var e = oas.getFile(d);
				var f = e.size;
				var mb=f/(1024);
				if (mb >= 500){
					Mensagem.exibir("false","A Imagem n&atilde;o pode ter mais do que 500Kb!");
					return false;
				}else{
					Mensagem.exibir("false","A Imagem passou no teste!");
					return false;
				}*/
				
				$("formUpload").submit();
				comunidade.submitUpload($("formUpload"));
				return true;
				
			},
			submitUpload: function(form){
				inicioLoading();
				  form.request({
			          onComplete: function(transport){
			              /*
			            se o retorno for diferente de -1, entende-se que não houve problemas, então apaga-se
			            os campos do formulário usando o método reset() da classe Form
			            */
			            if(transport.responseText!=-1)
			            	fechaDiv();
			            }
			        });
			        return false;

				
			},
			exibirDetalheEvento: function ($id){
				return{
					idEvento: $id
				}
			},
			paramsComentarioEvento: function(){
				return{
					Comentario: $("txtComentario_Evento").value,
					idEvento: $("hidEvento").value
				}
			},
			validarComentarioEvento: function(){
				if($("txtComentario_Evento").value == ''){
					Mensagem.exibir("false", 'Favor informar o coment&aacute;rio!');
					return false;
				}
				return true;
			},
			exibeCompletoEvento:function(){
				$("texto-resumido").setStyle({'display':'none'});
				$("texto-completo").setStyle({'display':'block'});
				$("link-ver-completo").setStyle({'display':'none'});
				$("link-ver-resumo").setStyle({'display':'block'});
			},
			exibeResumoEvento:function(){
				$("texto-resumido").setStyle({'display':'block'});
				$("texto-completo").setStyle({'display':'none'});
				$("link-ver-completo").setStyle({'display':'block'});
				$("link-ver-resumo").setStyle({'display':'none'});
			},
			
		    ordenaParticipantes: function(){
				var ordenarValue = '';
				if(document.formParticipantes != undefined)
				{
				var i = document.formParticipantes.ordenaParticipantes.selectedIndex;
				ordenarValue = document.formParticipantes.ordenaParticipantes[i].value;
				}
					
				return{
					ordenar: ordenarValue,
					acao: 'exibirParticipantes'
				}
		  },
			
		  validarPerfilComunidade:function(){
				if($("txtTitulo").value== ''){
					Mensagem.exibir("false", 'Favor informar o Titulo!');
					return false;
				}
				if($("txtDescricao").value == ''){
					Mensagem.exibir("false", 'Favor informar a Descri&ccedil;&atilde;o!');
					return false;
				}
				return true;
			},
				  
	        ContarCaracteres: function (Campo){
				  if((400-$(Campo).value.length) <= 0){
					   $(Campo).value = $(Campo).value.substr(0,400);
					   $("QtdCaractes").value = $(Campo).value;
					}
					$("QtdCaractes").innerHTML = 400-$(Campo).value.length + " Caracteres";
				  },
			validarCamposEvento:function()
			{
				if($('txtTituloEvento').value.length <= 0)
				{
					Mensagem.exibir('false','&Eacute; necess&aacute;rio informar o t&iacute;tulo do evento!');
					return false;
				}
				if($('txtLocal').value.length <= 0)
				{
					Mensagem.exibir('false','&Eacute; necess&aacute;rio informar o local do evento!');
					return false;
				}
				if($('Calendario').value.length <= 0)
				{
					Mensagem.exibir('false','&Eacute; necess&aacute;rio informar a data do evento!');
					return false;
				}
				if($('txtDescricao_Evento').value.length <= 0)
				{
					Mensagem.exibir('false','&Eacute; necess&aacute;rio informar a descri&ccedil;&atilde;o do evento!');
					return false;
				}
				
				
				return true;
			},
			ContarEvento:function(Campo){
				if((800-Campo.value.length) <= 0){
				   Campo.value = Campo.value.substr(0,800);
				   $("Qtd").value = Campo.value;
				}
					$("Qtd").innerHTML = 800-Campo.value.length + " Caracteres";
				},
				
			mensagemConvite: function(){
				Mensagem.exibir("true", texto.responseText);
				
			},
			strrchr:function(haystack, needle) {
			    // http://kevin.vanzonneveld.net
			    // +   original by: Brett Zamir (http://brett-zamir.me)
			    // +   input by: Jason Wong (http://carrot.org/)
			    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
			    // *     example 1: strrchr("Line 1\nLine 2\nLine 3", 10).substr(1)
			    // *     returns 1: 'Line 3'
			 
			    var pos = 0;
			 
			    if (typeof needle !== 'string') {
			        needle = String.fromCharCode(parseInt(needle, 10));
			    }
			    needle = needle.charAt(0);
			    pos = haystack.lastIndexOf(needle);
			    if (pos === -1) {
			        return false;
			    }
			 
			    return haystack.substr(pos);
			},
			escreverTop:function(log){
				if(log){
					document.getElementById('recTop').style.display = 'block'; //none nao mostra os recados na pagina
					document.getElementById('textareaRec').style.display = 'block';
					document.getElementById('recTopPag').style.display = 'none';
					
				}else{
					Mensagem.exibirLogin();
				}
			},	
			
			escreverTopNComunidade:function(log){
				if(log){
					document.getElementById('recTop').style.display = 'none';
					document.getElementById('textareaRec').style.display = 'block';
					document.getElementById('recTopPag').style.display = 'none';
					
				}else{
					Mensagem.exibir('false',"Voc&ecirc; precisa ser membro da comunidade para poder responder a um t&oacute;pico!")
				}
			},
			
			alterarNotifComentTopico:function(){
				
				var bit_coment_comunidade = 0;
				
				if($('bit_coment_comunidade').checked){
					bit_coment_comunidade = 1;
				}
				
				var qs = "?acao=notifComentTop&comentTop="+bit_coment_comunidade;
				
				var idComunidade = $('idComunidade').value;
				
				
				if (idComunidade > 0) {
					qs = qs + "&idcom="+idComunidade;
				}
				window.parent.location.href=qs;
			},
			
			alterarNotifComentTopicoCriado:function(){
				
				var bit_coment_meu_top = 0;
				
				if($('bit_coment_meu_top').checked){
					bit_coment_meu_top = 1;
				}
				
				var qs = "?acao=notifComentTopCriado&comentMeuTop="+bit_coment_meu_top;
				
				var idComunidade = $('idComunidade').value;
				
				
				if (idComunidade > 0) {
					qs = qs + "&idcom="+idComunidade;
				}
				window.parent.location.href=qs;
			},
			
			alterarNotifNovoTopico:function(){
				
				var bit_novo_top = 0;
				
				if($('bit_novo_top').checked){
					bit_novo_top = 1;
				}
				
				var qs = "?acao=notifNovoTop&criacaoTop="+bit_novo_top;
				
				var idComunidade = $('idComunidade').value;
				
				
				if (idComunidade > 0) {
					qs = qs + "&idcom="+idComunidade;
				}
				window.parent.location.href=qs;
			}
			
				
}



