function change_img_title(){
	var uid = $("#uid").val();
	var Id =  $(this).attr("id");
	var current = $(this).val();
	var previous = $(".photo_"+Id).val();
	//alert(previous+'->'+current+' ID:'+Id+' UID:'+uid);
	if(current != previous){
		$('#loading-'+Id).fadeIn();
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/photos_ajax.php",
			data: "a=ptitle&uid="+uid+"&imgid="+Id+"&data="+current,
			cache: false,
			success: function(html){
				$('#loading-'+Id).fadeOut();
			}
		});
	}
}
function share_option(id){
	if(id == 'photo' || id == 'movie' || id == 'link'){
			$("#listo").hide();
			$(".uploadbutton").show();
	}else{
			$(".uploadbutton").hide();
			$("#listo").show();
	}
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/share-options.php",
		data: "share="+id,
		cache: false,
		success: function(html){
			$("#share-box").html(html);	
		}
	});
}
function hidemeandshow(ocultar,mostrar){
	$(ocultar).hide();
	$(mostrar).show();
}
function change_wall(uid,wall,tipo){
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/change_wall.php",
			data: "uid="+uid+"&wall="+wall+"&tipo="+tipo,
			cache: false,
			success: function(html){
				if(html == 'nowidget'){
					alert('Lo sentimos, pero para cambiar tu fondo necesitas comprar la funcion de Fondo Personalizado.');	
				}
				if(html == 'OK'){
					$('#wall-image').attr('src','http://www.imeev.com/images/themes/thumb_'+wall+'.jpg');
					alert('Fondo aplicado!\nNo es necesario guardar los cambios.');	
				}
			}
		});
}
function buywidget(uid,wid){
	//ARREGLAR!!!!
	$('.widget-'+wid+' .plus').html('<img src="/images/ajax-loader.gif" border="0">');
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/buywidget.php",
		data: "uid="+uid+"&wid="+wid,
		cache: false,
		success: function(html){
			if(html == 'nopoints'){alert('Lo sentimos, no tienes puntos suficientes');$('#widget-'+wid+' .plus').html('+');}else{
				$('.widget-'+wid).fadeOut();
				location.reload();
			}
		}
	});
}
//REMOVER LA IMAGEN DE UN EVENTO EN UNA AGENDA
function remove_event_image(evento,uid){
	var dataString = 'event='+evento+'&uid='+uid;
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/change_event_img.php?action=remove",
		data: dataString,
		cache: false,
		success: function(html){
			$("#delete_event_image").hide();
			$("#event_image_span").html(html);
		}
	});
}
//REEMPLAZA <3 POR ♥
function heart(texto){
	var ret = texto.replace("<3","♥");
	return ret;
}
//MUESTRA MAS ESTADOS DE ANIMO EN FRIENDS_MOODS
function show_more_moods(mood_id){
	$("#same-user-moods-"+mood_id).slideDown("slow");
	$("#same-user-mood-option-"+mood_id).hide();
}
//MUESTRA EL EVENTO EN EL PANEL DE CONTROL, CONVOCADO DESDE EL CALENDARIO
function showevent(anio,mes,dia,uid){
	mes = (mes*1)+1;
	$("#showevent").html('<div align="center" style="margin:5px" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/load_dates.php",
		data: "action=loadevents&id="+uid+"&anio="+anio+"&mes="+mes+"&dia="+dia,
		cache: false,
		success: function(html){
				$("#showevent").html(html);
		}
	});
}
//AGREGA AL USUARIO A UN GRUPO
function add_group(gid,uid,sig){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/add_group.php",
		data: "uid="+uid+"&gid="+gid+"&sig="+sig,
		cache: false,
		success: function(){
			$("#related-group-"+gid+" #popular-options").fadeOut(500);
			$("#related-group-"+gid+" #popular-options").fadeIn(500,function(){
				$(this).html("<b>Te has unido.</b>");
			});
		}
	});
}
//REMUEVE COMMENTS
function remove_comment(id){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=comment",
		cache: false,
		success: function(){
			$(".comment-"+id).fadeOut();
		}
	});
}
function remove_comment_adv(id,type,linker){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a="+type,
		cache: false,
		success: function(){
			$(linker+id).fadeOut();
		}
	});
}
function remove_comment_pro(id,type,linker,action){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a="+action+"&type="+type,
		cache: false,
		success: function(){
			$(linker+id).fadeOut();
		}
	});
}
function remove_history(id){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=historial",
		cache: false,
		success: function(){
			$("#history-"+id).fadeOut();
		}
	});
}
function remove_history_comment(id){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=historial_comment",
		cache: false,
		success: function(){
			$("mini-comment-"+id).fadeOut();
		}
	});
}
function remove_group_comment(id){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=group_comment",
		cache: false,
		success: function(){
			$(".comment-"+id).fadeOut();
		}
	});
}
function remove_minicomment(id,type){
	$.ajax({
		type: "POST",
		url: "http://www.imeev.com/ajax/remove_engine.php",
		data: "id="+id+"&a=mini-comment&type="+type,
		cache: false,
		success: function(){
			$("#mini-comment-"+id).fadeOut();
		}
	});
}
function Change_This(aList)
{
	var x=document.getElementById("otro")
	if(aList.selectedIndex == 0){
		x.disabled=false
	}else{
		x.disabled=true;
		x.value = '';
	}

}
function cargaragenda(uid){
	$.ajax({
		url: "http://www.imeev.com/ajax/load_dates.php",
		data: "action=loadcalendar&id="+uid,
		dataType: "json",
		success: function(calendarEvents){ 
			$("#calendar-event-list").datepicker({
				dayNames: ['Domingo', 'Lunes', 'Martes', 'Mi&eacute;rcoles', 'Jueves', 'Viernes', 'S&aacute;bado'],
				dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
				dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mi&eacute;', 'Jue', 'Vie', 'S&aacute;b'],
				monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
				monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
				nextText: 'Siguiente',
				prevText: 'Atr&aacute;s',
				changeYear: true,
				changeMonth: true,
				// [rows, columns] if you want to display multiple calendars.                         
				numberOfMonths: [1, 1],
				showCurrentAtPos: 0,
				beforeShowDay: function (date){
					for (i = 0; i < calendarEvents.length; i++) {
					  	if (date.getMonth() == calendarEvents[i][0] - 1 
					  	&& date.getDate() == calendarEvents[i][1]
					  	&& date.getFullYear() == calendarEvents[i][2]) {
							return [true,"ui-datepicker-current-day ui-state-active",calendarEvents[i][3],uid]; 
						}
					}
					return [true, "",,uid];//enable all other days
				}
			});
		}
	});
}
function show_friends(type,uid,orden){
	$("#friends-frame").html('<div align="center" style="margin:5px" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando amigos...</div>');
	$.post("http://www.imeev.com/ajax/show_friends.php",
		{type: type, uid: uid,orden: orden},
		 function(html){
			$("#friends-frame").html(html);
		}
	);
}
function profile_page(uid,url){
	$("#profile-loader").load("http://www.imeev.com/profile_pages/"+url+".php");
	return false;	
}
function comment_mood(comment_id,cambio){
	$("#mood_comment_inputs_"+comment_id).toggle();
	if(cambio == 0){
		$("#mood_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
function load_cats_gift_shop(uid){
	var categoria = $("#gift_cats_shop").val();
	$("#gift_lastid").val('');
	$("#gifts_load").load('http://www.imeev.com/gifts_loader.php?uid=' + uid + '&cat=' + categoria);
}
function comment_mood_cancel(comment_id,cambio){
	$("#mood_comment_inputs_"+comment_id).hide();
	if(cambio == 0){
		$("#mood_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
function comment_historial(comment_id){
	var comments = $("#historial_comment_comments_"+comment_id).val();
	$("#historial_comment_inputs_"+comment_id).toggle();
	if(comments == 0){
		$("#historial_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
function comment_historial_cancel(comment_id){
	var comments = $("#historial_comment_comments_"+comment_id).val();
	$("#historial_comment_inputs_"+comment_id).hide();
	if(comments == 0){
		$("#historial_comment_frame_"+comment_id).toggleClass("mood_comment_frame");
	}
}
function load_more_activities(lastid,user){
	$("#lasthistid").val(lastid);
	$(".morebox").html('<div align="center" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
	if(lastid > 0){
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/load_more.php?uid="+user,
			data: "lastmsg="+ lastid,
			cache: false,
			success: function(html){
				$("#last-activities").append(html);
				$("#more"+lastid).remove(); // removing old more button
			}
		});
	}else{
		$("#more"+lastid).remove();// no results
	}
}
function next_gift_step(step){
	switch(step){
		case '1':
				$(".step_1").fadeIn(1000);
				$(".step_2").hide();
		break;
		case '2':
			if($("#gift_lastid").val() == 0 || $("#gift_lastid").val() == ""){
				alert("Elige un regalo!");
			}else{
				$(".step_1").hide();
				$(".step_2").fadeIn(1000);
				$(".step_3").hide();
			}
		break;
		case '3':
			if($("#para").val() == 0){
				alert("Elige un amigo!");
			}else{
				$(".step_2").hide();
				$(".step_3").fadeIn(1000);
				$(".step_4").hide();
			}
		break;
		case '4':
			$(".step_3").hide();
			$(".step_4").fadeIn(1000);
			$("#gift_para").text($("#para :selected").text());	
		break;
	}
}
function gift_box_click(boxid,precio_caja,caja,nombre){
	var precio_regalo = $("#gift_price").val();
	var total = (precio_caja * 1)+(precio_regalo * 1);
	$("#gift_box_img").attr("src","http://www.imeev.com/images/gifts/boxes/"+ caja + ".png");
	$("#gift_total").text(total);
	$("#total_price").val(total);
	$("#gift_box_price_val").text(precio_caja);
	$("#box_price").text(precio_caja);
	$("#gift_box_title").text(nombre);
}
function select_gift(giftid,precio,category,regalo,nombre,tipo){	
	var lastid = $("#gift_lastid").val();
	$("#gift_inner_"+lastid).toggleClass("gift_outer_click");
	$("#gift_lastid").val(giftid);
	$("#gift_inner_"+giftid).toggleClass("gift_outer_click");
	$("#gift_total").val(precio);
	$("#gift_price").val(precio);
	$("#gift_price_val").text(precio);
	var precio_regalo = $("#gift_price").val();
	var precio_caja = $("#gift_box_price_val").text();
	var total = (precio_caja * 1)+(precio_regalo * 1);
	$("#gift_total").text(total);
	$("#total_price").val(total);
	$("#gift_title").text(nombre);
	if(tipo == 0){
		$("#gift_img").attr("src","http://www.imeev.com/images/gifts/" + category + "/big/" + regalo);
	}else{
		$("#gift_img").attr("src","http://www.imeev.com/custom_gifts/" + category + "/big/" + regalo);
	}
}
function slide_plz(id,name){
	if($("#"+id).css('display') == 'none'){
		$("#"+id).slideDown();
		$("#"+id+"_click").html('&#9660; '+name);
	}else{
		$("#"+id).slideUp();
		$("#"+id+"_click").html('&#9658; '+name);
	}
}
function closeshare(){
	$("#share-js").fadeOut();
	$(".uploadbutton").hide();
	$("#listo").show();
}
$(document).ready(function (){
	$(".event_hover").hover(function(){
		var Id = $(this).attr("id");
		$("."+Id).fadeIn('fast',function(){
				if($("."+Id).html() == '' || $("."+Id).html() == 'undefined'){
					$("."+Id).html('<div align="left" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div');
					$.ajax({
						type: "POST",
						url: "http://www.imeev.com/ajax/event_loader.php",
						data: "eid="+Id,
						cache: false,
						success: function(html){
							$("."+Id).html(html);
						}
					});
				}
		});
	},function(){
		var Id = $(this).attr("id");
		$("."+Id).fadeOut('fast');	
	});
	$("#rvsp").live("click",function(){
		var rvsp = $("#rvsp:checked").val();
		var uid = $("#uid").val();
		var eid = $("#eid").val();
		var e_inv = $("#e_inv").val();
		$.ajax({
			type: "POST",
			url: "http://www.imeev.com/ajax/events_ajax.php?a=rvsp&eid="+eid,
			data: "uid="+ uid+"&rvsp="+rvsp,
			cache: false,
			success: function(html){
				if(e_inv == 1){
					$("#other_invited").load("http://www.imeev.com/ajax/events_ajax.php?a=other&eid="+eid);
					$("#confirmed_invited").load("http://www.imeev.com/ajax/events_ajax.php?a=confirmed&eid="+eid);
				}
			}
		});
		//alert(rvsp);
	});
	$('#photo-options').hover(function(){
		$(".photo-ops").show();   
	},function(){
		$(".photo-ops").hide();
	});
	$("#comment-profile").live("click",function(){
		$("#comment-profile").attr('disabled',true);									
		var comment_to = $("#comment-to").val();
		var comment_from = $("#comment-from").val();
		var comment = $("#profile-comment").val();
		$.post("http://www.imeev.com/ajax/publish_profile_comment.php",
		{uid: comment_from,fid: comment_to, comentario: comment},
		function(last){
			$("#activities-holder").html('<div align="center" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
			setTimeout(function(){
				last = last+1;
				$("#activities-holder").load("http://www.imeev.com/ajax/load_more.php?uid="+comment_to+"&lastmsg="+last);
				$("#profile-comment").val('');
				$("#comment-profile").removeAttr("disabled");	
			},1000);
		});
	});
	$("#comment-group").live("click",function(){
		$("#comment-group").attr('disabled',true);									
		var comment_to = $("#comment-to").val();
		var comment_from = $("#comment-from").val();
		var comment = $("#group-comment").val();
		$.post("http://www.imeev.com/ajax/publish_comment.php",
		{uid: comment_from,id: comment_to, tipo: 'group', comentario: comment},
		function(last){
			$("#activities-holder").html('<div align="center" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
			setTimeout(function(){
				$("#activities-holder").html(last);
				$("#group-comment").val('');
				$("#comment-group").removeAttr("disabled");	
			},1000);
		});
	});
	$("#comment-event").live("click",function(){
		$("#comment-event").attr('disabled',true);									
		var comment_to = $("#comment-to").val();
		var comment_from = $("#comment-from").val();
		var comment = $("#event-comment").val();
		$.post("http://www.imeev.com/ajax/publish_comment.php",
		{uid: comment_from,id: comment_to, tipo: 'eventos', comentario: comment},
		function(last){
			$("#activities-holder").html('<div align="center" class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif"> Cargando...</div>');
			setTimeout(function(){
				$("#activities-holder").html(last);
				$("#event-comment").val('');
				$("#comment-event").removeAttr("disabled");	
			},1000);
		});
	});
	$("#box_image").click(function (){
		$.post("http://www.imeev.com/update_gift_status.php", {
			llave: $('#llave_gift').text()
		});
	});
	$("#send_gift").click(function (){
			if(
				($("#mypoints").text() * 1) >= ($("#total_price").text() * 1) 
			){
				return true;
			}else{
				alert("No tienes los puntos suficientes!");	
			}
			return false;
	});
	$("#gift_frame").click(function (){ 
		if($("#para_gift").text() == $("#viendo_gift").text()){
			$("#box_image").fadeOut(500);
			setTimeout(function () {
				$("#gift_image").fadeIn(500);
			},1000);
			$("#box_caption").text("");
		}else{
			$("#box_caption").text("No puedes abrir un regalo que no es tuyo!");
		}
   });
	$('#gift_cats').change(function (){
		var categoria = $("#gift_cats").val();
		$("#gift_lastid").val('');
		$("#gifts_load").load('http://www.imeev.com/gifts_loader.php?cat=' + categoria);
	});
	
	$(".mood_comment_publish").click(function(){
		var element = $(this);
		var Id = element.attr("id");
		var comment = $("#mood_comment_textarea_"+Id).val();
		var uid = $("#mood_comment_myid_"+Id).val();
		var fid = $("#mood_comment_fromid_"+Id).val();
		var comments = $("#mood_comment_comments_"+Id).val();
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<span  class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Cargando...</span>');
			$.post("http://www.imeev.com/ajax/publish_mood_comment.php",
				    {
					 	comentario: comment,
						aid: Id,
						uid: uid,
						fid: fid,
						comments: comments
					},
				 	function(html){
					$("#mood_comment_load_"+Id).html(html);
					$("#flash_"+Id).hide();
				}
			);
		}
		return false;
	});
	$(".historial_comment_publish").live('click',function(){
		var element = $(this);
		var Id = element.attr("id");
		var comment = $("#historial_comment_textarea_"+Id).val();
		var uid = $("#historial_comment_myid_"+Id).val();
		var fid = $("#historial_comment_fromid_"+Id).val();
		var comments = $("#historial_comment_comments_"+Id).val();
		var tipo = $("#historial_comment_type_"+Id).val();
		if(tipo == '' || tipo == null){tipo = 'own';}
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<span class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Publicando...</span>');
			$.post( "http://www.imeev.com/ajax/publish_historial_comment.php",
				{
					comentario: comment,
					type: tipo,
					aid: Id,
					uid: uid,
					fid: fid,
					comments: comments
				},
				function(html){
					$("#historial_comment_load_"+Id).html(html);
					$("#flash_"+Id).hide();
				}
			);
		}
	});
		$(".event_minicomment_publish").live('click',function(){
		var element = $(this);
		var Id = element.attr("id");
		var comment = $("#historial_comment_textarea_"+Id).val();
		var uid = $("#historial_comment_myid_"+Id).val();
		var fid = $("#historial_comment_fromid_"+Id).val();
		var bid = $("#historial_comment_gid_"+Id).val();
		var comments = $("#historial_comment_comments_"+Id).val();
		var tipo = $("#historial_comment_type_"+Id).val();
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<span class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Publicando...</span>');
			$.post( "http://www.imeev.com/ajax/publish_event_comment.php",
				{
					comentario: comment,
					type: tipo,
					aid: Id,
					uid: uid,
					fid: fid,
					bid: bid,
					comments: comments
				},
				function(html){
					$("#historial_comment_load_"+Id).html(html);
					$("#flash_"+Id).hide();
				}
			);
		}
	});
	$(".group_minicomment_publish").live('click',function(){
		var element = $(this);
		var Id = element.attr("id");
		var comment = $("#historial_comment_textarea_"+Id).val();
		var uid = $("#historial_comment_myid_"+Id).val();
		var fid = $("#historial_comment_fromid_"+Id).val();
		var bid = $("#historial_comment_gid_"+Id).val();
		var comments = $("#historial_comment_comments_"+Id).val();
		var tipo = $("#historial_comment_type_"+Id).val();
		//var dataString = 'comentario='+ comment + '&aid=' + Id + '&uid=' + uid + '&fid=' + fid + '&comments=' + comments;
		if(comment==''){
			alert("Introduce tu comentario!");
		}else{
			$("#flash_"+Id).show();
			$("#flash_"+Id).fadeIn(400).html('<span class="loading"><img src="http://www.imeev.com/images/ajax-loader.gif" align="absmiddle"> Publicando...</span>');
			$.post( "http://www.imeev.com/ajax/publish_group_comment.php",
				{
					comentario: comment,
					type: tipo,
					aid: Id,
					uid: uid,
					fid: fid,
					bid: bid,
					comments: comments
				},
				function(html){
					$("#historial_comment_load_"+Id).html(html);
					$("#flash_"+Id).hide();
				}
			);
		}
	});
	$('#mood_comment_publish').click(function(){
		$.post("http://www.imeev.com/publish_mood_comment.php", {
			comentario: $('#mood_comment_textarea').val(),
			uid: $('#mood_comment_myid').val(),
			aid: $('#mood_comment_id').val()
		});
		uid = $('#fid').val();
		 $("#comments-popup").fadeOut(500); 
		 setTimeout(function () {
		 	$("#comments_frame").load("http://www.imeev.com/profile_pages/comments.php?uid=" + uid);
			$('#comentario').val() = '';
		 }, 1000);
	});
});