/* Comunidades */
var com = {

	buscador_home: function(){
		if($('form[name="buscador_home"] input[name="q"]').val()=='' || $('form[name="buscador_home"] input[name="q"]').val()==$('form[name="buscador_home"] input[name="q"]').attr('title')){
			$('form[name="buscador_home"] input[name="q"]').focus();
			return false;
		}
	},
	buscador_home_radio: function(en){
		//Cambio de action form
		$('form[name="buscador_home"]').attr('action', '/comunidades/buscador/'+en+'/');
	},

	TopsTabs_here: 'Semana',
	TopsTabs: function(tab){
		if(tab == this.TopsTabs_here)
			return;
		$('.box_cuerpo div.filterBy a#'+tab).addClass('here');
		$('.box_cuerpo div.filterBy a#'+this.TopsTabs_here).removeClass('here');
		$('.box_cuerpo ol.filterBy#filterBy'+tab).fadeIn();
		$('.box_cuerpo ol.filterBy#filterBy'+this.TopsTabs_here).fadeOut();
		this.TopsTabs_here = tab;
	},

	/* Crear shortnames */
	crear_shortname_key: function(val){
		$('#preview_shortname').html(val).removeClass('error').removeClass('ok');
		$('#msg_crear_shortname').html('');
	},
	crear_shortname_check_cache: new Array(),
	crear_shortname_check: function(val){
		if(val=='')
			return;
		for(i=0; i<this.crear_shortname_check_cache.length; i++){ //Verifico si ya lo busque
			if(this.crear_shortname_check_cache[i][0]===val){ //Lo tengo
				if(this.crear_shortname_check_cache[i][1]==='1'){ //Disponible
					$('#preview_shortname').removeClass('error').addClass('ok');
					$('#msg_crear_shortname').html(this.crear_shortname_check_cache[i][2]).removeClass('error').addClass('ok');
				}else{ //No disponible
					$('#preview_shortname').removeClass('ok').addClass('error');
					$('#msg_crear_shortname').html(this.crear_shortname_check_cache[i][2]).removeClass('ok').addClass('error');
				}
				return;			
			}
		}
		$('.gif_cargando#shortname').css('display', 'block');
		$.ajax({
			type: 'POST',
			url: '/comunidades/shortname_check.php',
			data: 'shortname='+encodeURIComponent(val),
			success: function(h){
				com.crear_shortname_check_cache[com.crear_shortname_check_cache.length] = new Array(val, h.charAt(0), h.substring(3)); //Guardo los datos de verificacion
				$('.gif_cargando#shortname').css('display', 'none');
				switch(h.charAt(0)){
					case '0': //Error
						$('#preview_shortname').removeClass('ok').addClass('error');
						$('#msg_crear_shortname').html(h.substring(3)).removeClass('ok').addClass('error');
						break;
					case '1': //OK
						$('#preview_shortname').removeClass('error').addClass('ok');
						$('#msg_crear_shortname').html(h.substring(3)).removeClass('error').addClass('ok');
						break;
				}
			},
			error: function(){
				$('.gif_cargando#shortname').css('display', 'none');
				$('#msg_crear_shortname').html(lang['error procesar']).removeClass('ok').addClass('error');
			}
		});
	},

	get_subcategorias_cache: new Array(),
	get_subcategorias: function(catid){
		mydialog.close();
		$('.agregar_subcategoria').html('').append('<option value="-1" selected>Elegir una subcategor&iacute;a</option>').attr('disabled', 'true').val(-1);
		if(catid==-1)
			return false;
		if(this.get_subcategorias_cache[catid]){ //Lo tengo
			$.each(this.get_subcategorias_cache[catid], function(i, val){
				$('.agregar_subcategoria').append('<option value="'+i+'">'+val+'</option>');
			});
			$('.agregar_subcategoria').removeAttr('disabled');
			return true;			
		}
		$('.gif_cargando#subcategoria').css('display', 'block');
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: '/comunidades/get-subcategorias.php',
			data: 'catid='+catid,
			success: function(h){
				com.get_subcategorias_cache[catid] = h;
				$.each(h, function(i, val){
					$('.agregar_subcategoria').append('<option value="'+i+'">'+val+'</option>');
				});
				$('.agregar_subcategoria').removeAttr('disabled');
			},
			error: function(){
				$('.agregar_subcategoria').attr('disabled', 'true').val(-1);
				mydialog.error_500("com.get_subcategorias('"+catid+"')");
			},
			complete: function(){
				$('.gif_cargando#subcategoria').css('display', 'none');
			}
		});
	},

		/* rango auto */
	create_show_rango_def: function(show){
		if(show)
			$('#rango_default').slideDown('fast');
		else
			$('#rango_default').slideUp('fast');
	},

	comunidad_eliminar: function(acepto){
		mydialog.show();
		mydialog.title('Eliminar Comunidad');
		switch(acepto){
			case 0:
				mydialog.body('&iquest;Realmente deseas eliminar la comunidad?<br />Esta opci&oacute;n no tiene retorno, es un camino de ida');
				mydialog.buttons(true, true, 'S&iacute;', 'com.comunidad_eliminar(1)', true, false, true, 'No', 'close', true, true);
				break;
			case 1:
				mydialog.body('Te pregunto de nuevo. &iquest;Realmente deseas eliminar la comunidad?');
				mydialog.buttons(true, true, 'S&iacute;', 'com.comunidad_eliminar(2)', true, false, true, 'No', 'close', true, true);
				break;
			case 2:
				mydialog.body('Una &uacute;ltima vez, &iquest;estas seguro que quieres eliminar la comunidad?<br />Este es el &uacute;ltimo paso y es el punto de no retorno');
				mydialog.buttons(true, true, 'S&iacute;, acepto los cargos', 'com.comunidad_eliminar(3)', true, false, true, 'No', 'close', true, true);
				break;
			case 3:
				mydialog.procesando_inicio('Eliminando...', 'Eliminar Comunidad');
				$.ajax({
					type: 'POST',
					url: '/comunidades/comunidad-eliminar.php',
					data: gget('comid', true) + gget('key'),
					success: function(h){
						mydialog.alert('Comunidad eliminada', 'La comunidad ha sido eliminada.<br />Has dejado muchos usuarios hu&eacute;rfanos :(', true);
					},
					error: function(){
						mydialog.error_500("com.comunidad_eliminar(3)");
					},
					complete: function(){
						mydialog.procesando_fin();
					}
				});
				break;
		}
		mydialog.center();
	},
	comunidad_reactivar: function(acepto){
		mydialog.show();
		mydialog.title('Reactivar Comunidad');
		switch(acepto){
			case 0:
				mydialog.body('&iquest;Realmente deseas reactivar la comunidad?');
				mydialog.buttons(true, true, 'S&iacute;', 'com.comunidad_reactivar(1)', true, false, true, 'No', 'close', true, true);
				break;
			case 1:
				mydialog.procesando_inicio('Reactivando...', 'Reactivar Comunidad');
				$.ajax({
					type: 'POST',
					url: '/comunidades/comunidad-reactivar.php',
					data: gget('comid', true) + gget('key'),
					success: function(h){
						mydialog.alert('Comunidad reactivada', 'La comunidad ha sido reactivada', true);
					},
					error: function(){
						mydialog.error_500("com.comunidad_reactivar(1)");
					},
					complete: function(){
						mydialog.procesando_fin();
					}
				});
				break;
		}
		mydialog.center();
	},

	error_logo: function(o){
		o.src = global_data.img + 'images/avatar.gif';
	},

	ir_a_categoria: function(cat){
		if(cat!='root' && cat!='linea')
			if(cat==-1)
				document.location.href='/' + lang['comunidades url'] + '/';
			else
				document.location.href='/' + lang['comunidades url'] + '/home/' + cat + '/';
	},

	//Info Comunidad
	masinfo1: 0,
	masinfo2: 0,
	masinfo_procesando: false,
	masinfo: function(){
		if(this.masinfo_procesando==true)
			return;
		this.masinfo_procesando=true;
		//Open
		if($('#cMasInfo').css('display')=='none'){
			$('#aVerMas').html('&laquo; Ver menos');
			if(this.masinfo1==0)
				this.masinfo1 = document.getElementById('ComInfo').clientHeight - 12;
			$('#ComInfo').css('height', this.masinfo1);
			$('#cMasInfo').css('display', 'block').css('opacity', 0);
			if(this.masinfo2==0)
				this.masinfo2 = this.masinfo1 + document.getElementById('cMasInfo').clientHeight - 5;
			$('#cMasInfo').animate({ opacity: 1 }, 1000);
			$('#ComInfo').animate({ height: this.masinfo2 }, 1000, 0, function(){ com.masinfo_procesando=false; });
		}
		//Close
		else{
			$('#aVerMas').html('Ver m&aacute;s &raquo;');
			if(this.masinfo1 == 0 || this.masinfo2 == 0)
				return false;
			$('#cMasInfo').animate({ opacity: 0 }, 1000);
			$('#ComInfo').animate({ height: this.masinfo1 }, 1000, 0, function(){ $('#cMasInfo').css('display', 'none'); com.masinfo_procesando=false; });
		}
	},

	actualizar_respuestas: function(cat){
		$('#ult_resp').slideUp(1);
		if(gget('comid'))
			var params = gget('comid', true);
		if(cat)
			var params = cat;
		$.ajax({
			type: 'GET',
			url: '/comunidades/ultimas-respuestas.php',
			cache: false,
			data: params,
			success: function(h){
				$('#ult_resp').html(h.substring(3));
				$('#ult_resp').slideDown({duration: 1000, easing: 'easeOutBounce'});
			},
			error: function(){
				$('#ult_resp').slideDown({duration: 1000, easing: 'easeOutBounce'});
			}
		});
	},

	citar_resp: function(id, nick){
	  $('#body_resp').focus();
		$('#body_resp').val((($('#body_resp').val()!='') ? $('#body_resp').val() + '\n' : '') + '[quote=' + nick + ']' + $('#citar_resp_'+id).html() + '[/quote]\n');
	},

	lastid_resp: 0,
	add_resp: function(mostrar_resp){
		if($('#body_resp').val()=='' || $('#body_resp').val()==$('#body_resp').attr('title')){
			$('#body_resp').focus();
			return;
		}
		$('.add_resp_error').hide();
		$('#button_add_resp').attr('disabled', 'true').addClass('disabled');
		$.ajax({
			type: 'POST',
			url: '/comunidades/respuesta.php',
			data: 'respuesta=' + encodeURIComponent($('#body_resp').val()) + '&lastid=' + this.lastid_resp + '&mostrar_resp=' + mostrar_resp + gget('temaid') + gget('key'),
			success: function(h){
				$('#button_add_resp').removeAttr('disabled').removeClass('disabled');
				switch(h.charAt(0)){
					case '0': //Error
						$('.add_resp_error').html(h.substring(3)).show('slow');
						break;
					case '1': //OK
						/*
						$('#body_resp').val('Escribir otra respuesta...').attr('title', 'Escribir otra respuesta...').addClass('onblur_effect');
						$('#body_resp').focus();
						*/

						/*** agregar respuesta al final ***/
							$('#body_resp').attr('title', 'Escribir otra respuesta...').val('');
							onblur_input($('#body_resp'));
							if($('#respuestas').css('display')=='none'){ //No habian respuestas
								$('#respuestas').html($('#respuestas').html()+h.substring(3)).slideDown('slow', function(){
									if($('#buttons.filterBy.modBar'))
										$('#buttons.filterBy.modBar').slideDown('slow');
								});
							}else{
								$('#respuestas').html($('#respuestas').html()+'<div id="nuevas_respuestas" style="display:none">'+h.substring(3)+'</div>');
								$('#nuevas_respuestas').slideDown('slow', function(){
									$('#nuevas_respuestas').removeAttr('id');
								});
							}
						break;
				}
			},
			error: function(){
				$('#button_add_resp').removeAttr('disabled').removeClass('disabled');
				mydialog.error_500("com.add_resp('"+this.lastid_resp+"')");
			}
		});
	},

	borrar_resp: function(respid){
		mydialog.close();
		$.ajax({
			type: 'POST',
			url: '/comunidades/respuesta-borrar.php',
			data: 'respid=' + respid + gget('temaid') + gget('key'),
			success: function(h){
				switch(h.charAt(0)){
					case '0': //Error
						mydialog.alert('Error', h.substring(2));
						break;
					case '1': //OK
					case '2': //La respuesta no existe o ya fue eliminada
						$('#respuestas #id_'+respid).fadeOut('normal', function(){ $(this).remove(); });
						break;
				}
			},
			error: function(){
				mydialog.error_500("com.borrar_resp('"+respid+"')");
			}
		});
	},

	del_tema: function(confirm){
		if(!confirm){
			mydialog.show();
			mydialog.title('Borrar tema');
			mydialog.body(lang['html tema confirma borrar'] + '<br /><br />Causa: <input type="text" id="icausa_status" value="Causa del borrado" title="Causa del borrado" onfocus="onfocus_input(this)" onblur="onblur_input(this)" onkeypress="if(keypress_intro(event)) com.del_tema(true)" />', 370);
			mydialog.buttons(true, true, 'Aceptar', "com.del_tema(true)", true, false, true, 'Cancelar', 'close', true, false);
			mydialog.center();
			$('#icausa_status').focus();
		}else{
			if($('#icausa_status').val()=='' || $('#icausa_status').val()==$('#icausa_status').attr('title')){
				$('#icausa_status').focus();
				return;
			}
			mydialog.procesando_inicio('Borrando...');
			$.ajax({
				type: 'POST',
				url: '/comunidades/tema-borrar.php',
				data: 'causa='+encodeURIComponent($('#icausa_status').val())+gget('temaid')+gget('key'),
				success: function(h){
					if(h.charAt(0)==0) //Error
						mydialog.alert('Error', h.substring(2));
					else if(h.charAt(0)==1) //OK
						mydialog.alert('Tema borrado', 'El tema fue eliminado satisfactoriamente', true);
				},
				error: function(){
					mydialog.error_500("com.del_tema('"+confirm+"')");
				},
				complete: function(){
					mydialog.procesando_fin();
				}
			});
		}
	},

	react_tema: function(confirm){
		if(!confirm){
			mydialog.show();
			mydialog.title('Reactivar tema');
			mydialog.body('Realmente deseas reactivar este tema');
			mydialog.buttons(true, true, 'Aceptar', "com.react_tema(true)", true, true, true, 'Cancelar', 'close', true, false);
			mydialog.center();
		}else{
			mydialog.procesando_inicio('Reactivando...');
			$.ajax({
				type: "POST",
				url: '/comunidades/tema-reactivar.php',
				data: 'causa='+encodeURIComponent($('#icausa_status').val())+gget('temaid')+gget('key'),
				success: function(h){
					if(h.charAt(0)==0) //Error
						mydialog.alert('Error', h.substring(2));
					else if(h.charAt(0)==1) //OK
						mydialog.alert('Tema reactivado', 'El tema fue reactivado satisfactoriamente', true);
				},
				error: function(){
					mydialog.error_500("com.react_tema('"+confirm+"')");
				},
				complete: function(){
					mydialog.procesando_fin();
				}
			});
		}
	},

	tema_votar_action: '',
	tema_votar: function(voto){
		if(!gget('key')){
			mydialog.alert('Error al votar', 'Tenes que estar logueado para poder votar el tema');
			return;
		}
		this.tema_votar_action = $('.rateBox #actions').html();
		$('.rateBox #actions').html('Votando...');
		$.ajax({
			type: 'POST',
			url: '/comunidades/tema-votar.php',
			data: 'voto='+voto+gget('temaid')+gget('key'),
			success: function(h){
				switch(h.charAt(0)){
					case '0': //Error
						mydialog.alert('Error al votar', h.substring(2));
						$('.rateBox #actions').html('Error');
						break;
					case '1': //OK
						votos_total += voto;
						$('#votos_total').html((votos_total>0?'+':'')+votos_total);
						votos_total = 'listo';
						$('.rateBox #actions').html('Votado');
						break;
					case '2': //Ya votaste
						mydialog.alert('Ya votaste', 'Ya votaste este tema');
						votos_total = 'listo';
						$('.rateBox #actions').html('Votado');
						break;
				}
			},
			error: function(){
				$('.rateBox #actions').html(com.tema_votar_action);
				mydialog.error_500("com.tema_votar('"+voto+"')");
			}
		});
	},

	miembros_list_section_here: 'act',
	miembros_list_pag_actual: 0,
	miembros_list: function(section){
		if(!section)
			section = this.miembros_list_section_here;
		else if(this.miembros_list_section_here==section)
			return;
		if (this.miembros_list_section_here!=section || this.miembros_list_search) this.miembros_list_pag_actual = 0;
		var params = gget('comid', true)+gget('key');
		var filename = '/comunidades/';
		$('.filterBy #'+this.miembros_list_section_here).removeClass('here');
		this.miembros_list_section_here = section;
		$('.filterBy #'+section).addClass('here');
		switch(section){
			case 'act':
			case 'susp':
				filename += 'miembros.php';
				params += '&ajax=1&section='+section+'&p='+com.miembros_list_pag_actual;
				break;
			case 'history':
				filename += 'miembros-history.php';
				break;
		}
		if (this.miembros_list_search) params += '&q='+this.miembros_list_search;
		$('.gif_cargando').css('display', 'block');
		$.ajax({
			type: 'GET',
			url: filename,
			data: params,
			success: function(h){
				switch(h.charAt(0)){
					case '0': //Error
						$('#showResult').html('<div class="warningData">'+h.substring(3)+'</div>');
						break;
					case '1': //OK
						$('#showResult').html(h.substring(3));
						break;
				}
			},
			error: function(){
				$('#showResult').html('<div class="emptyData">'+lang['error procesar']+'. <a href="javascript:com.miembros_list()">Reintentar</a></div>');
			},
			complete: function(){
				$('.gif_cargando').css('display', 'none');
			}
		});
	},
	miembros_list_search: '',
	miembros_list_search_set: function() {
	    this.miembros_list_search = $.trim($('#miembros_list_search').val());
	    this.miembros_list();
	},
	miembros_list_sig: function(){
		this.miembros_list_pag_actual++;
		this.miembros_list();
	},
	miembros_list_ant: function(){
		this.miembros_list_pag_actual--;
		this.miembros_list();
	},
	admin_users: function(userid){
		mydialog.procesando_inicio('Cargando...', 'Administrar al usuario');
		$.ajax({
			type: 'POST',
			url: '/comunidades/miembros-admin.php',
			cache: false,
			data: 'userid=' + userid + gget('comid') + gget('key'),
			success: function(h){
				switch(h.charAt(0)){
					case '0': //Error
						mydialog.alert('Error', h.substring(3));
						break;
					case '1': //OK. Muestra info
						mydialog.title('Administrar al usuario');
						mydialog.body(h.substring(3), 340);
						mydialog.buttons(true, true, 'Aceptar', "com.admin_users_save('"+userid+"')", false, false, true, 'Cancelar', 'close', true, true);
						break;
				}
				mydialog.center();
			},
			error: function(){
				mydialog.error_500("com.admin_users('"+user+"')");
			},
			complete: function(){
				mydialog.procesando_fin();
			}
		});
	},
	admin_users_vermas: function(){
		if($('.suspendido_data #ver_mas').css('display') == 'none'){
			$('.suspendido_data #ver_mas').show('slow');
			$('.suspendido_data #vermas').html('&laquo; Ver menos');
		}else{
			$('.suspendido_data #ver_mas').hide('slow');
			$('.suspendido_data #vermas').html('Ver m&aacute;s &raquo;');
		}
	},
	admin_users_check: function(){
		if(is_checked('r_suspender')){
			if($('#t_causa').val()=='' || (!is_checked('r_suspender_dias1') && !is_checked('r_suspender_dias2')) || (is_checked('r_suspender_dias2') && $('#t_suspender').val()=='')){
				mydialog.buttons_enabled(false, true);
				return false;
			}else{
				mydialog.buttons_enabled(true, true);
				return true;
			}
		}else if(is_checked('r_rehabilitar')){
			if($('#t_causa').val()==''){
				mydialog.buttons_enabled(false, true);
				return false;
			}else{
				mydialog.buttons_enabled(true, true);
				return true;
			}
		}else if(is_checked('r_rango')){
			if(rango_actual == $('#s_rango').val()){
				mydialog.buttons_enabled(false, true);
				return false;
			}else{
				mydialog.buttons_enabled(true, true);
				return true;
			}
		}
	},
	admin_users_save: function(userid){
		if(!this.admin_users_check())
			return false;
		if(is_checked('r_suspender'))
			var action = 'suspender';
		else if(is_checked('r_rehabilitar'))
			var action = 'rehabilitar';
		else if(is_checked('r_rango'))
			var action = 'rango';
		mydialog.procesando_inicio('Guardando...');
		var params = 'userid=' + userid + gget('comid') + gget('key');
		params += '&action='+action;
		switch(action){
			case 'suspender':
				params += '&causa=' + encodeURIComponent($('#t_causa').val()) + '&dias=' + (is_checked('r_suspender_dias1')?'0':parseInt($('#t_suspender').val()));
				break;
			case 'rehabilitar':
				params += '&causa=' + encodeURIComponent($('#t_causa').val());
				break;
			case 'rango':
				params += '&new_rango=' + $('#s_rango').val();
				break;
		}
		$.ajax({
			type: 'POST',
			url: '/comunidades/miembros-admin-save.php',
			cache: false,
			data: params,
			success: function(h){
				switch(h.charAt(0)){
					case '0': //Error
						mydialog.alert('Error', h.substring(3));
						break;
					case '1': //OK
						mydialog.title('Administrar al usuario');
						mydialog.body(h.substring(3));
						mydialog.buttons(true, true, 'Aceptar', 'close', true, true, false);
						if(action == 'suspender')
							$('#cont_miembros').html(parseInt($('#cont_miembros').html())-parseInt(1));
						else if(action == 'rehabilitar')
							$('#cont_miembros').html(parseInt($('#cont_miembros').html())+parseInt(1));
						if(action=='suspender' || action=='rehabilitar')
							$('#userid_'+userid).remove();
						break;
				}
				mydialog.center();
			},
			error: function(){
				mydialog.error_500("com.admin_users_save('"+userid+"')");
			},
			complete: function(){
				mydialog.procesando_fin();
			}
		});
	},

	miembro_add: function(aceptar){
		mydialog.procesando_inicio('Procesando...', 'Unirme a la comunidad');
		$.ajax({
			type: 'POST',
			url: '/comunidades/miembro-add.php',
			cache: false,
			data: gget('comid', true) + gget('key') + (aceptar?'&aceptar=1':''),
			success: function(h){
				switch(h.charAt(0)){
					case '0': //Error
						mydialog.alert('Error', h.substring(3));
						break;
					case '1': //OK. Ya es miembro
						mydialog.alert('Ya sos miembro', h.substring(3), true);
						break;
					case '2': //OK. Confirmacion del admin
						mydialog.title('Unirme a la comunidad');
						mydialog.body(h.substring(3));
						mydialog.buttons(true, true, 'Enviar mensaje', "com.miembro_add(true)", true, true, true, 'Cancelar', 'close', true, false);
						break;
					case '3': //OK. Realmente queres ser miembro?
						mydialog.title('Unirme a la comunidad');
						mydialog.body(h.substring(3));
						mydialog.buttons(true, true, 'Si', "com.miembro_add(true)", true, true, true, 'No', 'close', true, false);
						break;
				}
				mydialog.center();
			},
			error: function(){
				mydialog.error_500("com.miembro_add('"+aceptar+"')");
			},
			complete: function(){
				mydialog.procesando_fin();
			}
		});
	},

	miembro_del: function(aceptar){
		if(!aceptar){
			mydialog.show();
			mydialog.title('Abandonar la comunidad');
			mydialog.body('&iquest;Realmente deseas salir de la comunidad?');
			mydialog.buttons(true, true, 'SI', 'com.miembro_del(true)', true, false, true, 'NO', 'close', true, true);
			mydialog.center();
		}else{
			mydialog.procesando_inicio('Saliendo...');
			$.ajax({
				type: 'POST',
				url: '/comunidades/miembro-del.php',
				cache: false,
				data: gget('comid', true) + gget('key'),
				success: function(h){
					switch(h.charAt(0)){
						case '0': //Error
							mydialog.alert('Error', h.substring(3));
							break;
						case '1': //Unico admin
							mydialog.title('Falta de administrador');
							mydialog.body(h.substring(3));
							mydialog.buttons(true, true, 'Aceptar', 'close', true, true, false);
							break;
						case '2': //OK. Fuiste eliminado
							mydialog.alert('Has salido de la comunidad', h.substring(3), true);
							break;
					}
					mydialog.center();
				},
				error: function(){
					mydialog.error_500("com.miembro_del('"+aceptar+"')");
				},
				complete: function(){
					mydialog.procesando_fin();
				}
			});
		}
	},

	mis_com_sort_actual: '',
	mis_com_pag_actual: 1,
	mis_com_sort: function(value){
		if(value == this.mis_com_sort_actual)
			return;
		this.mis_com_pag_actual = 1;
		document.location.href='/comunidades/mis-comunidades/'+(value=='rango'?'':value+'/');
	},

	global_tops: function(filtro, val){
		switch(filtro){
			case 'fecha':
				if(this.global_tops_fecha!=val)
					document.location.href='/comunidades/top/'+((val!='historico' || this.global_tops_categoria!=-1) ? val+((this.global_tops_categoria!=-1) ? '.'+this.global_tops_categoria : '')+'/' : '');
				this.global_tops_fecha=val;
				break;
			case 'categoria':
				if(this.global_tops_categoria!=val)
					document.location.href='/comunidades/top/'+((val!=-1 || this.global_tops_fecha!='historico') ? this.global_tops_fecha+((val!=-1) ? '.'+val : '')+'/' : '');
				this.global_tops_categoria=val;
				break;
		}
	},

	denuncia_publica: function(){
		mydialog.procesando_inicio('Cargando...', 'Formulario de denuncias');
		$.ajax({
			type: 'GET',
			url: '/comunidades/denuncia-publica-form.php',
			data: '',
			success: function(h){
				mydialog.title('Formulario de denuncias');
				mydialog.body(h, 450);
				mydialog.buttons(true, true, 'Enviar Denuncia', 'com.denuncia_publica_send()', true, true, true);
				mydialog.center();
				$('#denuncia-publica #nombre').focus();
			},
			error: function(){
				mydialog.error_500("com.denuncia_publica()");
			},
			complete: function(){
				mydialog.procesando_fin();
			}
		});
	},
	denuncia_publica_send: function(){
		if($('#denuncia-publica #nombre').val()==''){
			$('#denuncia-publica #error_data').html('El campo Nombre y Apellido es obligatorio').slideDown('fast');
			$('#denuncia-publica #nombre').focus();
			return;
		}else if($('#denuncia-publica #email').val()==''){
			$('#denuncia-publica #error_data').html('El campo Email es obligatorio').slideDown('fast');
			$('#denuncia-publica #email').focus();
			return;
		}else if($('#denuncia-publica #url').val()==''){
			$('#denuncia-publica #error_data').html('El campo URL de la Comunidad o Tema es obligatorio').slideDown('fast');
			$('#denuncia-publica #url').focus();
			return;
		}else if($('#denuncia-publica #email').val()==''){
			$('#denuncia-publica #error_data').html('El campo Email es obligatorio').slideDown('fast');
			$('#denuncia-publica #email').focus();
			return;
		}else if($('textarea[name="textarea_denuncia_publica"]').val()==''){
			$('#denuncia-publica #error_data').html('El campo Comentarios es obligatorio').slideDown('fast');
			$('#denuncia-publica #comentarios').focus();
			return;
		}

		mydialog.procesando_inicio('Enviando...', 'Formulario de denuncias');
		$.ajax({
			type: 'POST',
			url: '/comunidades/denuncia-publica.php',
			data: 'nombre='+encodeURIComponent($('#denuncia-publica #nombre').val())+'&email='+encodeURIComponent($('#denuncia-publica #email').val())+'&telefono='+encodeURIComponent($('#denuncia-publica #telefono').val())+'&horario='+encodeURIComponent($('#denuncia-publica #horario').val())+'&empresa='+encodeURIComponent($('#denuncia-publica #empresa').val())+'&url='+encodeURIComponent($('#denuncia-publica #url').val())+'&comentarios='+encodeURIComponent($('textarea[name="textarea_denuncia_publica"]').val()),
			success: function(h){
				mydialog.alert('Formulario de denuncias', h.substring(3));
			},
			error: function(){
				mydialog.error_500("com.denuncia_publica_send()");
			},
			complete: function(){
				mydialog.procesando_fin();
			}
		});		
	},

	contacto_beta: function(){
		mydialog.procesando_inicio('Cargando...', 'Formulario de contacto');
		$.ajax({
			type: 'GET',
			url: '/comunidades/contacto-beta-form.php',
			data: '',
			success: function(h){
				mydialog.title('Formulario de contacto');
				mydialog.body(h);
				mydialog.buttons(true, true, 'Enviar Formulario', 'com.contacto_beta_send()', true, true, true);
				mydialog.center();
				$('#contacto-beta #email').focus();
			},
			error: function(){
				mydialog.error_500("com.contacto_beta()");
			},
			complete: function(){
				mydialog.procesando_fin();
			}
		});
	},
	contacto_beta_send: function(){
		if($('#contacto-beta #email').val()==''){
			$('#contacto-beta #error_data').html('El campo Email es obligatorio').slideDown('fast');
			$('#contacto-beta #email').focus();
			return;
		}else if($('#contacto-beta #razon').val()=='-1'){
			$('#contacto-beta #error_data').html('El campo Razon es obligatorio').slideDown('fast');
			$('#contacto-beta #razon').focus();
			return;
		}else if($('#contacto-beta #mensaje').val()==''){
			$('#contacto-beta #error_data').html('El campo Mensaje es obligatorio').slideDown('fast');
			$('#contacto-beta #mensaje').focus();
			return;
		}

		mydialog.procesando_inicio('Enviando...', 'Formulario de contacto');
		$.ajax({
			type: 'POST',
			url: '/comunidades/contacto-beta.php',
			data: 'email='+encodeURIComponent($('#contacto-beta #email').val())+'&razon='+encodeURIComponent($('#contacto-beta #razon').val())+'&mensaje='+encodeURIComponent($('textarea[name="textarea_contacto_beta"]').val()),
			success: function(h){
				mydialog.alert('Formulario de contacto', h.substring(3));
			},
			error: function(){
				mydialog.error_500("com.contacto_beta_send()");
			},
			complete: function(){
				mydialog.procesando_fin();
			}
		});		
	}
};
/* FIN - Comunidades */

/* strpos (php.js) 909.322 */
function strpos(a,c,b){a=(a+"").indexOf(c,b?b:0);return a===-1?false:a};

$(document).ready(function(){
	print_editor();
	$('.autogrow').css('max-height', '500px').autogrow();
	$('.userInfoLogin a[class!=ver-mas], .comOfi, .post-compartir img').tipsy({gravity: 's'});
	for(var i = 1; i <= 15; ++i) $('.markItUpButton'+i+' > a:first-child').tipsy({gravity: 's'});
	$('img.lazy').lazyload({ placeHolder: 'http://i.t.net.ar/images/space.gif', sensitivity: 300 });
	$('div.avatar-box').mouseenter(function(){ $(this).children('ul').show(); }).mouseleave(function(){ $(this).children('ul').hide() });
	var zIndexNumber = 99;
	$('div.avatar-box').each(function(){
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 1;
	});
});

document.onkeydown = function(e){
	key = (e==null)?event.keyCode:e.which;
	if(key == 27) //escape, close mydialog
		mydialog.close();
};

(function(a){a.fn.lazyload=function(c){var b={placeHolder:'blank.gif',effect:'show',effectSpeed:0,sensitivity:0};if(c)a.extend(b,c);this.each(function(){if(a(this).attr('src')!=b.placeHolder)a(this).attr('src',b.placeHolder);a(this).one('dl',function(){if(a(this).attr('orig')&&a(this).attr('orig')!=a(this).attr('src'))a(this).hide().attr('src',a(this).attr('orig'))[b.effect](b.effectSpeed)})});var d=this;a(window).bind('scroll',function(){a(d).filter('[src$='+b.placeHolder+']').each(function(){if((a(window).height()+a(window).scrollTop()>a(this).offset().top-b.sensitivity)&&(a(window).width()+a(window).scrollLeft()>a(this).offset().left-b.sensitivity)&&(a(window).scrollTop()<a(this).offset().top+a(this).height()+b.sensitivity)&&(a(window).scrollLeft()<a(this).offset().left+a(this).width()+b.sensitivity))a(this).trigger('dl')})});a(window).trigger('scroll');return this}})(jQuery);

function TopsTabs(parent, tab) {
		if($('.box_cuerpo ol.filterBy#filterBy'+tab).css('display') == 'block') return;
		$('#'+parent+' > .box_cuerpo div.filterBy a').removeClass('here');
		$('.box_cuerpo div.filterBy a#'+tab).addClass('here');
		$('#'+parent+' > .box_cuerpo ol.filterBy').fadeOut();
		$('.box_cuerpo ol.filterBy#filterBy'+tab).fadeIn();
}

$(document).ready(function(){
    var location_box_more = false;
    $('.location-box-more').click(function(){
        if (location_box_more) {
            $('.location-box ul').css('height', '170px');
            $(this).html("Ver más");
            location_box_more = false;
        }
        else {
            $('.location-box ul').css('height', '170%');
            $(this).html("Ver menos");
            location_box_more = true;
        }
    });
    $('input[name=q]').focus(function(){
        if ($.trim($(this).attr('value')) == 'Buscar en comunidades') $(this).attr('value', '');
        $(this).removeClass("value");
    }).blur(function(){
        if ($.trim($(this).attr('value')) == '') $(this).attr('value', 'Buscar en comunidades');
        $(this).addClass("value");
    });
});
