function trim(s) {
	var l = 0;
	var r = s.length - 1;
	while (l < s.length && s[l] == ' ') {
		l++;
	}
	while (r > l && s[r] == ' ') {
		r-= 1;
	}
	return s.substring(l, r+1);
}

var post_tweets = 0;

$(document).ready(function() {
	/* a little variable to help with the drop down menu of the homepage search */
	var hideHugeSearchSelectMenu = true;
	/* handlers to open the signup/signin box */
	$('#lnkOpenAccountBox').click(function(e) {
		$('#divAccountBox').slideDown('fast');
		$('#divAccountBoxOpen').slideUp('fast');
		$.ajax({
			url: site_url+'/ajax.php?section=general&type=showAccountBox',
			type: 'get'
		});
		e.preventDefault();
	})
	$('#lnkOpenAccountBoxBottom').click(function(e) {
		$('#divAccountBox').slideDown('fast');
		e.preventDefault();
	})
	$('#lnkRightOpenAccountBox').click(function(e) {
		$('#divAccountBox').slideDown('fast');
	})
	$('#lnkLeftOpenAccountBox').click(function(e) {
		$('#divAccountBox').slideDown('fast');
	})
	$('#lnkAdvantagesOpenAccountBox').click(function(e) {
		$('#divAccountBox').slideDown('fast');
	})
	/* handler to close the signup/signin box */
	$('#lnkCloseAccountBox').click(function(e) {
		$('#divAccountBox').slideUp('fast');
		$('#divAccountBoxOpen').slideDown('fast');
		$.ajax({
			url: site_url+'/ajax.php?section=general&type=closeAccountBox',
			type: 'get'
		});
		e.preventDefault();
	})
	/* handler to show the signup/signin box */
	$('#divAccountBoxOpen a').click(function(e) {
		$('#divAccountBox').slideDown('fast');
		$('#divAccountBoxOpen').slideUp('fast');
		$.ajax({
			url: site_url+'/ajax.php?section=general&type=showAccountBox',
			type: 'get'
		});
		e.preventDefault();
	})
	/* handler to hide the default value of the homepage search box */
	$('#homepageSearchBox').focus(function() {
		$(this).css('color','#0F0F0F');
		if ($(this).val() == 'Ex: numele persoanei, functia sau compania') {
			$(this).val('');
		}
		/* a little hack for firefox which does not close the drop down menu when clicking on this input */
		$('#hugeSearchSelectOptions').slideUp('fast');
	})
	/* handler to restore the default value of the homepage search box */
	$('#homepageSearchBox').blur(function() {
		if ($(this).val() == 'Ex: numele persoanei, functia sau compania' || trim($(this).val()) == '') {
			$(this).css('color','#9d9d9d');
			$(this).val('Ex: numele persoanei, functia sau compania');
		}
	})
	/* handler to display the homepage search drop down menu */
	$('#lnkHugeSearchDropMenu').click(function(e) {
		var top = $(this).offset().top - 3;
		var left = $(this).offset().left - 6;
		top = top + 'px';
		left = left + 'px';
		$('#hugeSearchSelectOptions').css('top',top);
		$('#hugeSearchSelectOptions').css('left',left);
		$('#hugeSearchSelectOptions').slideDown('fast');
		hideHugeSearchSelectMenu = false;
		e.preventDefault();
	})
	/* handler to hide the homepage search drop down menu */
	$('body').click(function(e) {
		if (hideHugeSearchSelectMenu == true) {
			$('#hugeSearchSelectOptions').slideUp('fast');
		}
		$('#searchSuggestions').slideUp('fast');
	})
	$('#center').click(function(e) {
		if (hideHugeSearchSelectMenu == true) {
			$('#hugeSearchSelectOptions').slideUp('fast');
		}
		$('#searchSuggestions').slideUp('fast');
	})
	/* handler which help with the homepage search drop down menu */
	$('#hugeSearchSelectOptions').mouseout(function() {
		hideHugeSearchSelectMenu = true;
	})
	/* handler which help with the homepage search drop down menu */
	$('#hugeSearchSelectOptions').mouseover(function() {
		hideHugeSearchSelectMenu = false;
	})
	///////////
	/* handler for voters list */
	$('.tei_5').mouseout(function() {
		var the_id = $(this).attr('id').replace('tei5_', '');
		$('#tei6_'+the_id).css('display', 'none');
	})
	/* handler for voters list */
	$('.tei_5').mouseover(function() {
		var the_id = $(this).attr('id').replace('tei5_', '');
		$('#tei6_'+the_id).css('display', 'block');
	})
	///////////
	/* handler for each link in the homepage search drop down menu */
	$('#hugeSearchSelectOptions a').click(function(e) {
		if ($(this).attr('id') == 'hugeSearchOptionAll') {
			$('#lnkHugeSearchDropMenu').text('Toate sectiunile');
			$('#lookFor').val('all');
		} else if ($(this).attr('id') == 'hugeSearchOptionMembers') {
			$('#lnkHugeSearchDropMenu').text('Lista membrilor');
			$('#lookFor').val('members');
		} else if ($(this).attr('id') == 'hugeSearchOptionArrdep') {
			$('#lnkHugeSearchDropMenu').text('Lista sosiri/plecari');
			$('#lookFor').val('arrdep');
		} else if ($(this).attr('id') == 'hugeSearchOptionForum') {
			$('#lnkHugeSearchDropMenu').text('Forum KeyPeople');
			$('#lookFor').val('forum');
		}
		$('#hugeSearchSelectOptions').slideUp('fast');
		e.preventDefault();
	})
	
	$(window).load(function(e) {
		var maskHeight = $(window).height() + 'px';
		var maskWidth = $(window).width() + 'px';
		var loginBoxLeft = (parseInt(maskWidth)-441)/2;
		loginBoxLeft = loginBoxLeft + 'px';
		var loginBoxTop = (parseInt(maskHeight)-210)/2;
		loginBoxTop = loginBoxTop + 'px';
		$('#import_gmail').css({'top':loginBoxTop,'left':loginBoxLeft});
		$('#import_gmail').fadeIn('slow');
	})
	$('.hr_im_delete').click(function() {
		$(this).parent().remove();
	})
	/* handler for positioning banners and others */
	$(window).load(function() {
		/* positioning banners */
		var top = $('#topBrandingBanner').offset().top;
		top = parseInt(top + $('#topBrandingBanner').height()) + 'px';
		var left = parseInt(($(window).width() - 1245) / 2) + 'px';
		$('#leftBrandingBanner').css('top',top);
		$('#leftBrandingBanner').css('left',left);
		var windowWidth = $(window).width();
		var rightBrandingWidth = (windowWidth - 990) / 2 >= 0 ? (windowWidth - 990) / 2 : 0;
		rightBrandingWidth = rightBrandingWidth > 125 ? 125 : rightBrandingWidth;
		if (rightBrandingWidth < 125) {
			$('#rightBrandingBanner').css('overflow','hidden');
		} else {
			$('#rightBrandingBanner').css('overflow','auto');
		}
		var rightHacker = parseInt(($(window).width() - 1245) / 2);
		left = $(window).width() <= 1245 ? parseInt($(window).width() - rightBrandingWidth) + 'px' : parseInt($(window).width() - rightBrandingWidth - rightHacker) + 'px';
		rightBrandingWidth = rightBrandingWidth + 'px';
		$('#rightBrandingBanner').css('top',top);
		$('#rightBrandingBanner').css('left',left);
		$('#rightBrandingBanner').css('width',rightBrandingWidth);
		var topBrandingBannerLeft = parseInt(($(window).width() - 1245) / 2) + 'px';
		var topBrandingBannerWidth = $(window).width() >= 1245 ? '1245px' : parseInt($(window).width() - ($(window).width() - 1245) / 2) + 'px';
		$('#topBrandingBanner').css('left',topBrandingBannerLeft).css('width',topBrandingBannerWidth);
		$('#rightBrandingBanner').show();
		$('#leftBrandingBanner').show();
		$('#topBrandingBanner').show();
		var top_tmp = $('#topBrandingBanner').offset();
		var top = top_tmp.top;
		top = parseInt(top + $('#topBrandingBanner').height()) + 'px';
		$('#center').css('padding-top',top);
		/* positioning search suggestions */
		top = $('#topKeywordInput').offset().top;
		top = parseInt(top + 22) + 'px';
		left = $('#topKeywordInput').offset().left;
		if ($.browser.mozilla) {
			left = parseInt(left + 1) + 'px';
		} else {
			left = left + 'px';
		}
		$('#searchSuggestions').css('top',top);
		$('#searchSuggestions').css('left',left);
		/* positioning the floating banner */
		var windowHeight = $(window).height();
		var scrollTop = $(window).scrollTop();
		var floatingBannerLeft = parseInt((windowWidth - 1007) / 2) + 'px';
		var floatingBannerTop = parseInt(windowHeight - 57 + scrollTop) + 'px';
		var floatingBannerWidth = windowWidth >= 1007 ? '1007px' : parseInt(windowWidth + floatingBannerLeft) + 'px';
		$('#stickyBottomBanner').css('top',floatingBannerTop);
		$('#stickyBottomBanner').css('left',floatingBannerLeft);
		$('#stickyBottomBanner').css('width',floatingBannerWidth);
		$('#stickyBottomBanner').css('display','block');
	})
	/* handler for positioning banners and others */
	$(window).resize(function() {
		/* positioning banners */
		var top = $('#topBrandingBanner').offset().top;
		top = parseInt(top + $('#topBrandingBanner').height()) + 'px';
		var left = parseInt(($(window).width() - 1245) / 2) + 'px';
		$('#leftBrandingBanner').css('top',top);
		$('#leftBrandingBanner').css('left',left);
		var windowWidth = $(window).width();
		var rightBrandingWidth = (windowWidth - 990) / 2 >= 0 ? (windowWidth - 990) / 2 : 0;
		rightBrandingWidth = rightBrandingWidth > 125 ? 125 : rightBrandingWidth;
		if (rightBrandingWidth < 125) {
			$('#rightBrandingBanner').css('overflow','hidden');
		} else {
			$('#rightBrandingBanner').css('overflow','auto');
		}
		var rightHacker = parseInt(($(window).width() - 1245) / 2);
		left = $(window).width() <= 1245 ? parseInt($(window).width() - rightBrandingWidth) + 'px' : parseInt($(window).width() - rightBrandingWidth - rightHacker) + 'px';
		rightBrandingWidth = rightBrandingWidth + 'px';
		$('#rightBrandingBanner').css('top',top);
		$('#rightBrandingBanner').css('left',left);
		$('#rightBrandingBanner').css('width',rightBrandingWidth);
		var topBrandingBannerLeft = parseInt(($(window).width() - 1245) / 2) + 'px';
		var topBrandingBannerWidth = $(window).width() >= 1245 ? '1245px' : parseInt($(window).width() - ($(window).width() - 1245) / 2) + 'px';
		$('#topBrandingBanner').css('left',topBrandingBannerLeft).css('width',topBrandingBannerWidth);
		$('#rightBrandingBanner').show();
		$('#leftBrandingBanner').show();
		$('#topBrandingBanner').show();
		/* positioning the floating banner */
		var windowHeight = $(window).height();
		var scrollTop = $(window).scrollTop();
		var floatingBannerLeft = parseInt((windowWidth - 1007) / 2) + 'px';
		var floatingBannerTop = parseInt(windowHeight - 57 + scrollTop) + 'px';
		var floatingBannerWidth = windowWidth >= 1007 ? '1007px' : parseInt(windowWidth + floatingBannerLeft) + 'px';
		$('#stickyBottomBanner').css('top',floatingBannerTop);
		$('#stickyBottomBanner').css('left',floatingBannerLeft);
		$('#stickyBottomBanner').css('width',floatingBannerWidth);
		$('#stickyBottomBanner').css('display','block');
	})
	/* handler for positioning banners and others */
	$(window).scroll(function() {
		/* positioning the floating banner */
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();
		var scrollTop = $(window).scrollTop();
		var floatingBannerLeft = parseInt((windowWidth - 1007) / 2) + 'px';
		var floatingBannerTop = parseInt(windowHeight - 57 + scrollTop) + 'px';
		var floatingBannerWidth = windowWidth >= 1007 ? '1007px' : parseInt(windowWidth + floatingBannerLeft) + 'px';
		$('#stickyBottomBanner').css('top',floatingBannerTop);
		$('#stickyBottomBanner').css('left',floatingBannerLeft);
		$('#stickyBottomBanner').css('width',floatingBannerWidth);
		$('#stickyBottomBanner').css('display','block');
	})
	/* handler for search suggestions */
	$('#topKeywordInput').keyup(function() {
		var entry = '';
		$('#searchSuggestions div.entry').html('');
		if ($(this).val().length >= 2) {
			$.ajax({
				type : 'POST',
				dataType : 'json',
				data: {keyword: encodeURIComponent($('#topKeywordInput').val())},
				url : site_url+"/searchsuggestions.php",
				success : function(data) {
					if (data.results.length >= 1) {
						if (data.results.length <= 5) {
							var myHeight = (230 / 5) * data.results.length;
							myHeight = myHeight + 'px';
						} else {
							var myHeight = '190px';
						}
						$('#searchSuggestions').css('height',myHeight);
						$('#searchSuggestions').slideDown('fast',function() {
							for (i in data.results) {
								var entry = '<a href="' + data.results[i].link + '" onfocus="this.blur()" title="' + data.results[i].name + '"><i>' + data.results[i].name + '</i><br /><span>' + data.results[i].position + ', ' + data.results[i].company + '</span></a>';
								$('#searchSuggestions div.entry').append(entry);
							}
						});
					}
				}
			});
		}
	});
	/* handler for send message suggestions */
	$('#recipient_name').keyup(function() {
		var entry = '';
		$('#send_message_tooltip').html('');
		if ($(this).val().length >= 2) {
			$.ajax({
				type : 'POST',
				dataType : 'json',
				data: {keyword: encodeURIComponent($('#recipient_name').val())},
				url : site_url+"/searchsuggestions.php",
				success : function(data) {
					if (data.results.length >= 1) {
						$('#send_message_tooltip').css('display','inline');
						if (data.results.length <= 5) {
							var myHeight = (230 / 5) * data.results.length;
							myHeight = myHeight + 'px';
						} else {
							var myHeight = '190px';
						}
						$('#send_message_tooltip').css('height',myHeight);
						$('#send_message_tooltip').slideDown('fast',function() {
							for (i in data.results) {
								var entry = '<a href="javascript:void(0)" onclick="change_msg_receiver(\''+data.results[i].id+'\', \''+data.results[i].name_title+'\')" onfocus="this.blur()" title="';
								entry += data.results[i].name_title + '"><em>';
								entry += data.results[i].name + '</em><br /><span>';
								entry += data.results[i].position + ', ';
								entry += data.results[i].company + '</span></a>';
								//var entry = '<div style="font-size: 12px; float: none; border-bottom: 1px solid #ccc; display: block; width: 100%;">'+data.results[i].name+'</div>';
								$('#send_message_tooltip').append(entry);
							}
						});
					}
				}
			});
		}
	});
	/* handlers for manipulating new tweets box appearance */
	$('#txtNewTweet').focus(function(){
		if ($(this).val() == 'Posteaza un mesaj...') {
			$(this).val('');
			$(this).css('color','#0F0F0F');
			$('#newTweetCharacters').html('Caractere ramase: 300');
		}
	})
	$('#txtNewTweet').blur(function(){
		if (trim($(this).val()) == '') {
			$(this).val('Posteaza un mesaj...');
			$(this).css('color','#c3c3c3');
			$('#newTweetCharacters').html('Caractere ramase: 300');
		}
	})
	/* handler for manipulating the number of left characters for the new tweets box */
	$('#txtNewTweet').keypress(function(e){
		//$(this).val($(this).val().substring(0, 300));
		var chars = $(this).val().length;
		if (chars > 300) {
			$(this).val($(this).val().substring(0, 300));
		}
		characters = 300 - $(this).val().length;
		characters = 'Caractere ramase: ' + characters;
		$('#newTweetCharacters').html(characters);
	})
	$('#txtNewTweet').keyup(function(e){
		var chars = $(this).val().length;
		if (chars > 300) {
			$(this).val($(this).val().substring(0, 300));
		}
		characters = 300 - $(this).val().length;
		characters = 'Caractere ramase: ' + characters;
		$('#newTweetCharacters').html(characters);
	})
	$('#txtNewTweet').keydown(function(e){
		//$(this).val($(this).val().substring(0, 300));
		var chars = $(this).val().length;
		if (chars > 300) {
			$(this).val($(this).val().substring(0, 300));
		}
		characters = 300 - $(this).val().length;
		characters = 'Caractere ramase: ' + characters;
		$('#newTweetCharacters').html(characters);
	})
	
	/* handlers for manipulating the tweets comments boxes */
	$('div.tweetEntry textarea').focus(function(){
		if ($(this).val() == 'Comenteaza si tu...') {
			$(this).val('');
			$(this).css('color','#0F0F0F');
			$(this).parent().children('div.characters').html('Caractere ramase: 300');
		}
	})
	$('div.tweetEntry textarea').blur(function(){
		if (trim($(this).val()) == '') {
			$(this).val('Comenteaza si tu...');
			$(this).css('color','#c3c3c3');
			$(this).parent().children('div.characters').html('Caractere ramase: 300');
		}
	})
	
	$('div.tweetEntry a.lnkTweetComment').click(function(e){
		$(this).parents('div.content').children('div.commentForm').slideDown('fast');
	})
	$('div.tweetEntry textarea').keypress(function(e){
		//$(this).val($(this).val().substring(0, 300));
		characters = 300 - $(this).val().length;
		characters = 'Caractere ramase: ' + characters;
		$(this).parent().children('div.characters').html(characters);
	})
	$('div.tweetEntry textarea').keyup(function(e){
		//$(this).val($(this).val().substring(0, 300));
		characters = 300 - $(this).val().length;
		characters = 'Caractere ramase: ' + characters;
		$(this).parent().children('div.characters').html(characters);
	})
	$('div.tweetEntry textarea').keydown(function(e){
		//$(this).val($(this).val().substring(0, 300));
		characters = 300 - $(this).val().length;
		characters = 'Caractere ramase: ' + characters;
		$(this).parent().children('div.characters').html(characters);
	})

	/* handler for submitting the sign-up form*/
	$('#signupBox a.mySmallButton').click(function(e){
		$(this).parents('#signupBox').children('form').submit();
		e.preventDefault();
	});
	/* handler for make the mass message delete */
	$('.messageDeleteLine a.mySmallButton').click(function(e){
		if (!confirm('Esti sigur ca vrei sa stergi aceste mesaje?')) return;
		$('input.chk_delete_msg').each(function(){
			if($(this).is(':checked')) {
				var the_id = $(this).val();
				if ($(this).parent().hasClass('sent')) {
					var type = 'sent';
				} else {
					var type = 'inbox';
				}
				// ajax request for delete
				$.ajax({
					url: site_url+'/ajax.php?section=profile',
					type: 'post',
					data: {
						message_id : the_id,
						enforcer: 'delete_message',
						folder: type
					},
					success: function(response) {
						$('#message_'+the_id).css('background', 'pink');
						$('#message_'+the_id).fadeOut('slow');
					}
				});
			}
		});
		e.preventDefault();
	});
	/* handler for submitting the send message form*/
	$('a#lnkSendPrivateMessage').click(function(e){
		//$(this).parents('#signupBox').children('form').submit();
		document.message_form.submit();
		e.preventDefault();
	});
	/* handler for deleting tweets */
	$('div.tweetEntry a.lnkTweetDelete').click(function(e){
		var postID = $(this).attr('id').replace('tw_','');
		if (confirm('Esti sigur ca vrei sa stergi acest post?')) {
			$.ajax({
				url: site_url+'/ajax.php?section=profile',
				type: 'post',
				data: {
					id: postID,
					enforcer: 'delete_post'
				},
				success: function(response) {
					if (response == 2) {
						$('#post_'+postID).css('background', '#f25b5b');
						$('#post_'+postID).fadeOut('slow');
					} else {
						//alert(response);
					}
					e.preventDefault();
				}
			});
		}
	});
	$('div.comment a.lnkCommentDelete').click(function(e){
		var commentID = $(this).attr('id').replace('lnk_','');
		if (confirm('Esti sigur ca vrei sa stergi acest post?')) {
			$.ajax({
				url: site_url+'/ajax.php?section=profile',
				type: 'post',
				data: {
					id: commentID,
					enforcer: 'delete_comment'
				},
				success: function(response) {
					if (response == 2) {
						$('#comment_'+commentID).css('background', '#f25b5b');
						$('#comment_'+commentID).fadeOut('slow');
					} else {
						//alert(response);
					}
					e.preventDefault();
				}
			});
		}
	});
	$('div.newTweetBox a#lnkSubmitNewTweet').click(function(e){
		var text = $('#txtNewTweet').val();
		if ((text == 'Posteaza un mesaj...') || (text.lenght < 1)) {
			//alert('Nu ati scris comentariul');
			return false;
		}
		if (post_tweets == 0) {
			post_tweets++;
			$.ajax({
				url: site_url+'/ajax.php?section=profile',
				type: 'post',
				data: {
					comment: text,
					enforcer: 'add_tweet'
				},
				success: function(response) {
					if (response == 2) {
						window.location.href=window.location.href;
					} else {
						//alert(response);
					}
				}
			});
		} else {
			alert('Ati mai apasat o data. Va rugam asteptati');
		}
	});
	$('div.tweetEntry a.mySmallButton').click(function(e){
		var the_id = $(this).attr('id').replace('lnkSubmitNewComment_', '');
		var text = $('#add_comment_'+the_id).val();	
		if (text == 'Comenteaza si tu...' || text.lenght < 1) {
			//alert('Nu ati scris comentariul');
			return false;
		}
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type: 'post',
			data: {
				comment: text,
				tweet_id : the_id,
				enforcer: 'add_comment'
			},
			success: function(response) {
				if (response == 2) {
					window.location.href=window.location.href;
				} else {
					//alert(response);
				}
			}
		});
	});
	/* delete studies */
	$('div.oldStudiesSubmitLine a.mySmallButtonRed').click(function(e){
		if (!confirm('Esti sigur ca vrei sa stergi acest studiu?')) return false;
		var the_id = $(this).attr('id').replace('delete_studies_', '');
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type: 'post',
			data: {
				study_id : the_id,
				enforcer: 'delete_study'
			},
			success: function(response) {
				if (response == 2) {
					$('#study_'+the_id).css('background', 'pink');
					$('#study_'+the_id).fadeOut('slow');
					setTimeout("$('#study_"+the_id+"').remove()", 700);
				} else {
					//alert(response);
				}
			}
		});
	});
	/* delete jobs */
	$('div.oldJobsSubmitLine a.mySmallButtonRed').click(function(e){
		if (!confirm('Esti sigur ca vrei sa stergi aceasta activitate?')) return false;
		var the_id = $(this).attr('id').replace('delete_jobs_', '');
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type: 'post',
			data: {
			study_id : the_id,
			enforcer: 'delete_job'
		},
		success: function(response) {
			if (response == 2) {
				$('#job_'+the_id).css('background', 'pink');
				$('#job_'+the_id).fadeOut('slow');
				setTimeout("$('#job_"+the_id+"').remove()", 700);
			} else {
				//alert(response);
			}
		}
		});
	});
	/* handler for opening messages */
	$('a.lnkViewFullMessage').click(function(e) {
		$(this).parent().slideUp('fast');
		$(this).parents('div.messageDetails').children('div.contentShort').slideUp('fast');
		$(this).parents('div.messageDetails').children('div.contentLong').slideDown('fast');
		$(this).parents('div.messageDetails').children('div.optionsLong').slideDown('fast');
		$(this).parents('div.messageLineUnread').css('background-color','#FFFFFF');
		var the_id = $(this).attr('id').replace('lnkMessage','');
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type: 'post',
			data: {
				message_id : the_id,
				enforcer: 'mark_message_read'
			},
			success: function(response) {
				// enjoy the silence
				// change messages number in left menu
				var nr_invit = $('#link_my_messages').html();
				nr_invit = nr_invit.replace("(", "");
				nr_invit = nr_invit.replace(")", "");
				var new_invit = parseInt(nr_invit) - 1;
				if (new_invit > 0) {
					new_invit = '('+new_invit+')';
				} else {
					new_invit = '';
				}
				$('#link_my_messages').html(new_invit)
				$('#my_messages_right').html('Mesajele mele '+new_invit)
			}
		});
	});
	/* handler for closing messages */
	$('a.message_close').click(function(e) {
		$(this).parent().slideDown('fast');
		$(this).parents('div.messageDetails').children('div.contentShort').slideDown('fast');
		$(this).parents('div.messageDetails').children('div.contentLong').slideUp('fast');
		$(this).parents('div.messageDetails').children('div.optionsLong').slideUp('fast');
	});
	/* handler for delete received message */
	$('a.message_delete').click(function(e) {
		if (!confirm('Esti sigur ca vrei sa stergi acest mesaj?')) return;
		var the_id = $(this).attr('id').replace('deleter_','');
		
		if ($(this).parent().hasClass('sent')) {
			var type = 'sent';
		} else {
			var type = 'inbox';
		}
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type: 'post',
			data: {
				message_id : the_id,
				enforcer: 'delete_message',
				folder: type
			},
			success: function(response) {
				$('#message_'+the_id).css('background', 'pink');
				$('#message_'+the_id).fadeOut('slow');
			}
		});
	})
	/* handler for submitting the login info */
	$('#loginBox a.mySmallButton').click(function(e){
		$('#loginBox form').submit();
		e.preventDefault();
	})
	/* handlers for sending invitations */
	$('a.inviteLinkGray').click(function(e){
		location.href = '#';
		$('#divAccountBox').slideDown('fast',function(){
			alert('Pentru a putea trimite invitatii trebuie sa fii autentificat in contul tau KeyPeople.');
		});
		e.preventDefault();
	})
	$('a.inviteLink').click(function(e){
		if (!confirm('Esti sigur ca vrei sa-ti devina partener in reteaua KeyPeople?')) return false;
		var recipientID = $(this).attr('id').replace('sendInvite_','');
		var theLink = $(this);
		$.ajax({
			type : 'POST',
			dataType : 'text',
			data: {
				'action' : 'send', 
				'recipient' : recipientID
			},
			url: site_url+'/ajax.php?section=invitation',
			success : function(data) {
//				if (data.indexOf('Felicitari!') != -1 || data.indexOf('Exista deja') != -1) {
				if (data.indexOf('Felicitari!') != -1) {
					theLink.html('Invitatie trimisa!');
					theLink.removeClass('inviteLink');
					theLink.addClass('inviteLinkSent');
				}
				alert(data);
			}
		});
		e.preventDefault();
	})
	$('a.outFriend').click(function(e){
		if (!confirm('Esti sigur ca vrei sa elimini acest utilizator din reteaua ta de parteneri ?')) return false;
		var recipientID = $(this).attr('id').replace('friendOut_','');
		recipientID = recipientID.replace('ignore_my_friend_','');
		var theLink = $(this);
		$.ajax({
			type : 'POST',
			dataType : 'text',
			data: {
				'enforcer' : 'remove_friend', 
				'victim' : recipientID
			},
			url: site_url+'/ajax.php?section=profile',
			success : function(data) {
				if (data.msg != '') {
					alert(data.msg);
				}
			}
		});
		e.preventDefault();
	})
	//profile_ignore_user({$smarty.request,id})
	$('a.removeMyFriend').click(function(e){
		if (!confirm('Esti sigur ca vrei sa elimini acest utilizator din reteaua ta de parteneri ?')) return false;
		var ID = $(this).attr('id').replace('remove_my_friend_','');
		$.ajax({
			type : 'POST',
			dataType: 'json',
			data: {
				'enforcer' : 'remove_friend', 
				'victim' : ID
			},
			url: site_url+'/ajax.php?section=profile',
			success : function(data) {
				if (data.code == 2) {
					$('#friend_list_'+ID).fadeOut('slow')
				} else {
					alert(data.msg);
				}
			}
		});
		e.preventDefault();
	})
	$('a.ignoreMyFriend').click(function(e){
		if (!confirm('Esti sigur ca vrei sa ignori acest utilizator ?')) return false;
		var ID = $(this).attr('id').replace('ignore_my_friend_','');
		$.ajax({
			type : 'POST',
			dataType: 'json',
			data: {
				'enforcer' : 'profile_ignore_user', 
				'victim' : ID
			},
			url: site_url+'/ajax.php?section=profile',
			success : function(data) {
				if (data.code == 2) {
					$('#friend_list_'+ID).fadeOut('slow')
					alert('Nu veti mai primi mesaje de la acest utilizator');
				} else {
					alert(data.msg);
				}
			}
		});
		e.preventDefault();
	})
	$('a.removeMyIgnored').click(function(e){
		if (!confirm('Esti sigur ca vrei sa ignori acest utilizator ?')) return false;
		var ID = $(this).attr('id').replace('remove_my_ignored_','');
		$.ajax({
			type : 'POST',
			dataType: 'json',
			data: {
				'enforcer' : 'profile_remove_ignored_user', 
				'victim' : ID
			},
			url: site_url+'/ajax.php?section=profile',
			success : function(data) {
				if (data.code == 2) {
					$('#friend_list_'+ID).fadeOut('slow')
				} else {
					alert(data.msg);
				}
			}
		});
		e.preventDefault();
	})
	$('div.acceptInvitationButton a').click(function(e){
		var invitationID = $(this).attr('id').replace('acceptInvitation_','');
		var theDiv = $(this).parents('div.myInvitation');
		$.ajax({
			type : 'POST',
			dataType : 'text',
			data: {
				'action' : 'accept', 
				'invitationid' : invitationID
			},
			url: site_url+'/ajax.php?section=invitation',
			success : function(data) {
				if (data == 1) {
					//theDiv.slideUp('fast');
					$('#invite_accept_'+invitationID).hide();
					$('#invite_reject_'+invitationID).hide();
//					var msg = 'Ai acceptat sa fii partener cu '+$('#invite_name_'+invitationID).html();
//					alert(msg);
					$('#invite_response_'+invitationID).html('Ai acceptat invitatia');
					$('#invite_response_'+invitationID).addClass('invite_accepted');
					// change invitations number in left menu
					var nr_invit = $('#link_my_invitations').html();
					nr_invit = nr_invit.replace("(", "");
					nr_invit = nr_invit.replace(")", "");
					var new_invit = parseInt(nr_invit) - 1;
					if (new_invit > 0) {
						new_invit = '('+new_invit+')';
					} else {
						new_invit = '';
					}
					$('#link_my_invitations').html(new_invit)
					$('#my_invites_right').html('Invitatiile mele '+new_invit)
				} else {
					alert('Actiunea nu a fost posibila. Daca eroarea persista, va rugam sa ne contactati.');
				}
			}
		});
		e.preventDefault();
	})
	$('div.refuseInvitationButton a').click(function(e){
//		if (!confirm('Sigur doresti re refuzi aceasta invitatie?')) return false; 
		var invitationID = $(this).attr('id').replace('refuseInvitation_','');
		var theDiv = $(this).parents('div.myInvitation');
		$.ajax({
			type : 'POST',
			dataType : 'json',
			data: {
				'action' : 'reject', 
				'invitationid' : invitationID
			},
			url: site_url+'/ajax.php?section=invitation',
			success : function(data) {
				if (data.code == 1) {
					//theDiv.css('background', '#DF6161');
					//theDiv.slideUp('fast');
					$('#invite_accept_'+invitationID).hide();
					$('#invite_reject_'+invitationID).hide();
					//var msg = 'Ai refuzat sa fi partener cu '+$('#invite_name_'+invitationID).html();
					//$('#invite_response_'+invitationID).html('Ai refuzat invitatia');
					
					$('#invite_response_'+invitationID).html(data.msg);
					$('#invite_response_'+invitationID).addClass('invite_rejected');
					// change invitations number in left menu
					var nr_invit = $('#link_my_invitations').html();
					nr_invit = nr_invit.replace("(", "");
					nr_invit = nr_invit.replace(")", "");
					var new_invit = parseInt(nr_invit) - 1;
					if (new_invit > 0) {
						new_invit = '('+new_invit+')';
					} else {
						new_invit = '';
					}
					$('#link_my_invitations').html(new_invit);
					$('#my_invites_right').html('Invitatiile mele '+new_invit);
				} else {
					alert('Actiunea nu a fost posibila. Daca eroarea persista, va rugam sa ne contactati.');
				}
			}
		});
		e.preventDefault();
	})
	/* handlers for submitting top sign-in/sign-up forms */
	$('#loginBox a.mySmallButton').click(function(e){
		$('#frmLogin').submit();
	})
	/* handler for submitting the email confirmation form */
	$('#lnkConfirmCodeSubmit').click(function(e){
		$('#frmConfirmCode').submit();
	})
	/* handler for submitting the invite a friend form */
	$('#lnkSubmitInviteFriend').click(function(e){
		$('#frmInviteFriend').submit();
	})
	/* handler for submitting the sign up form from the invite section */
	$('#lnkInviteSubmit').click(function(e){
		$('#frmNewAccount').submit();
	})
	/* handlers for offers section */
	$('a.offersMultilink').click(function(e){
		$('#divAccountBox').slideDown('fast',function(){
			alert('Pentru a putea beneficia de ofertele noastre trebuie sa fii autentificat ca membru KeyPeople.');
		});
	})
	$('a.prizesMultilink').click(function(e){
		$('#divAccountBox').slideDown('fast',function(){
			alert('Pentru a putea beneficia de ofertele noastre trebuie sa fii autentificat ca membru KeyPeople.');
		});
	})
	$('div.offer a.offersMultilinkLogged').click(function(e){
		myElement = $(this);
		if (!myElement.parent().children('div.benefitForm').is(':visible')) {
			$('div.offer').each(function() {
				if ($(this).children('div.benefitForm').is(':visible')) {
					$(this).children('div.benefitForm').slideUp('fast');
					$(this).css('background-color','transparent');
				}
			})
			myElement.parent().css('background-color','F7F7F7');
			myElement.parent().children('div.benefitForm').slideDown('fast');
		}
		e.preventDefault();
	})
	$('a.prizesMultilinkLogged').click(function(e){
		location.href = '/?section=invitefriend';
		e.preventDefault();
	})
	$('div.benefitForm a.mySmallButton').click(function(e){
		var offerid = $(this).attr('id').replace('offer_','');
		var myObject = $(this);
		$.ajax({
			type : 'POST',
			dataType : 'text',
			data: {
				'offerid' : offerid
			},
			url: site_url+'/ajax.php?section=offers',
			success : function(data) {
				if (data == 1) {
					myObject.parents('div.benefitForm').children('div.infobox').html('<b>Felicitari!</b><br />Cererea ta de a beneficia de aceasta oferta speciala a fost trimisa.');
					myObject.parents('div.benefitForm').children('div.messageLine').slideUp('fast',function(){
						myObject.parents('div.benefitForm').children('div.messageLine').remove();
					});
					myObject.parent().slideUp('fast',function(){
						myObject.parent().remove();
					})
				} else {
					alert('Actiunea nu a fost posibila. Daca eroarea persista, va rugam sa ne contactati.');
				}
			}
		});
	})
	/* handler for the links in the bottom sticky banner */
	$('#stickyBottomBanner a.close').click(function(e) {
		$('#stickyBottomBanner').fadeOut('slow',function() {
			$(this).remove();
			$.ajax({
				type : 'POST',
				dataType : 'text',
				data: {
					'noFooterStickyBanner' : 'yes'
				},
				url: site_url+'/ajax.php?section=setsession',
				success : function(data) {
				}
			});
		});
		e.preventDefault();
	})
	$('#stickyBottomBanner a.goLink').click(function(e) {
		$('#stickyBottomBanner').fadeOut('slow',function() {
			$(this).remove();
			$.ajax({
				type : 'POST',
				dataType : 'text',
				data: {
					'noFooterStickyBanner' : 'yes'
				},
				url: site_url+'/ajax.php?section=setsession',
				success : function(data) {
					location.href = '/oferte-speciale/';
				}
			});
		});
		e.preventDefault();
	})	
	$('#stickyBottomBanner a').click(function(e) {
	})
	/*
	var list_cv = 0;
	$('a.list_cv').click(function(e) {
		if (list_cv == 0) {
			list_cv = 1;
			alert('Pentru vizualizarea CV-urilor este perceputa o taxa de 8 Euro');
		}
	})
	*/
	
	/* handler for displaying the contest prizes */
	/*
	$("label.previewContestLabel").hover(function(e){
		imageUrl = this.title;
		this.title = "";
		$("body").append("<p id='preview'><img src='"+ imageUrl +"' alt='' /></p>");								 
		$("#preview")
			.css("top",(e.pageY + 20) + "px")
			.css("left",(e.pageX + 0) + "px")
			.css("position",'absolute')
			.fadeIn("slow");
    	}, function(){
			this.title = imageUrl;
			$("#preview").fadeOut('fast');
			$("#preview").remove();
    });	
	$("label.previewContestLabel").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY + 20) + "px")
			.css("left",(e.pageX + 0) + "px");
	});
	$('div.prizesForm div.closeLink a').click(function(e){
		$('div.prizeBox div.prizesForm').slideUp('fast',function(){
			$('div.prizeBox div.prizes').slideDown('slow');
		});
	})
	*/
	
	/**
	 * afiseaza linkul de stergere a imaginii de pe profilul utilizatorului (media pictures)
	 */
	$('.foto_item').hover(function(e){
		$(this).children('.foto_delete').show();
	},function(e){
		$(this).children('.foto_delete').hide();
	});
		
	/**
	 * sterge imaginile din galeria utilizatorului.
	 * doar adminul sau autorul poate sa faca asta :P
	 */
	$('.sterge_media_image').click(function(e){
		if (!confirm('Esti sigur ca vrei sa stergi aceasta imagine ?')) return false;
		var the_id = $(this).attr('id');
		var id = the_id.replace('smi_', '');
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type : 'POST',
			dataType: 'json',
			data: {
				'enforcer' : 'profile_remove_media_image', 
				'id' : id
			},
			success : function(data) {
				if (data.code == 2) {
					$('#fi_'+id).fadeOut('slow')
				} else {
					alert(data.msg);
				}
			}
		});
		e.preventDefault();
	});
	
	/**
	 * sterge filmele din galeria utilizatorului.
	 * doar adminul sau autorul poate sa faca asta :P
	 */
	$('.sterge_media_video').click(function(e){
		if (!confirm('Esti sigur ca vrei sa stergi aceast video ?')) return false;
		var the_id = $(this).attr('id');
		var id = the_id.replace('smv_', '');
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type : 'POST',
			dataType: 'json',
			data: {
			'enforcer' : 'profile_remove_media_video', 
			'id' : id
		},
		success : function(data) {
			if (data.code == 2) {
				$('#vid_'+id).removeClass('media_video_item');
				$('#vid_'+id).css('background', 'red !important');
				$('#vid_'+id).fadeOut('fast');		
			} else {
				alert(data.msg);
			}
		}
		});
		e.preventDefault();
	});

	/**
	 * sterge filmele din galeria utilizatorului.
	 * doar adminul sau autorul poate sa faca asta :P
	 */
	$('.sterge_media_doc').click(function(e){
		if (!confirm('Esti sigur ca vrei sa stergi aceast document ?')) return false;
		var the_id = $(this).attr('id');
		var id = the_id.replace('smd_', '');
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type : 'POST',
			dataType: 'json',
			data: {
			'enforcer' : 'profile_remove_media_doc', 
			'id' : id
		},
		success : function(data) {
			if (data.code == 2) {
				$('#di_'+id).fadeOut('slow');		
			} else {
				alert(data.msg);
			}
		}
		});
		e.preventDefault();
	});
	
	$(".foto_descriere").hover(
		function () {
			$(this).addClass('foto_opac');
			$(this).removeClass('foto_transp');
		}, 
		function () {
			$(this).addClass('foto_transp');
			$(this).removeClass('foto_opac');
		}
	);

	
	$("div.domainList label").hover(function(e){
		imageUrl = this.title;
		this.title = "";
		if (imageUrl.length > 0) {
			$("body").append("<p id='preview'>"+ imageUrl +"</p>");
		}						 
		$("#preview")
			.css("top",(e.pageY + 20) + "px")
			.css("left",(e.pageX + 0) + "px")
			.css("position",'absolute')
			.css("background",'#ffffef')
			.css("border",'1px solid #cccccc')
			.css("padding",'5px')
			.css("font-family",'tahoma')
			.css("font-size",'12px')
			.fadeIn("slow");
    	}, function(){
			this.title = imageUrl;
			$("#preview").fadeOut('fast');
			$("#preview").remove();
		}
	);	
	$("div.domainList label").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY + 20) + "px")
			.css("left",(e.pageX + 0) + "px");
	});
	/* handler for voting stars */
	$('.tei_4').mouseout(function() {
		var the_id = parseInt($(this).attr('id').replace('tei4_', ''));
		var nr = $('#info_tei_'+the_id).html();
		star_out(the_id, nr);
	})
	setTimeout("session_stay()", 60000);
	
	$('#btn-intreaba').click(function(e){
		var mesaj = $('#txt-intreaba').val();
		var intrebarea_mea = $('#intrebarea_mea').val();
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type: 'post',
			dataType: 'json',
			data: {
				inid: intrebarea_mea,
				content: mesaj,
				enforcer: 'intrebare-noua'
			},
			success: function(rasp){
				if (rasp.code == 2) {
					$('#intreaba-nou').html('<div style="width: 470px;">'+mesaj+'</div><div id="txt-intreaba-post"><p style="text-align: center;">mesajul dumneavoastra a fost trimis cu succes</p></div>');
					setTimeout(function(){
						$('#txt-intreaba-post').fadeOut('slow');
					}, 3000);
				} else {
					alert(rasp.msg);
				}
			}
		});
	});
	
	$('.btn-intreaba-new').click(function(e){
		
		var spec_id = $(this).attr('id');
		spec_id = spec_id.replace('btni_', '');
		
		var mesaj = $('#txt-intreaba_'+spec_id).val();
		
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type: 'post',
			dataType: 'json',
			data: {
				spec_id: spec_id,
				content: mesaj,
				enforcer: 'intrebare-noua-spec'
			},
			success: function(rasp){
				if (rasp.code == 2) {
					$('#intreaba-nou-'+spec_id).html('<div style="width: 450px;">'+mesaj+'</div><div id="txt-intreaba-post_'+spec_id+'" style="width: 450px;"><p style="text-align: center; background: lightgreen; margin: 0; padding: 5px;">mesajul dumneavoastra a fost trimis cu succes</p></div>');
					setTimeout(function(){
						$('#txt-intreaba-post_'+spec_id).fadeOut('slow');
					}, 3000);
				} else {
					alert(rasp.msg);
				}
			}
		});
	});
	
	
	$('#tabs').tabs();
	
	
});

function session_stay() {
	$.ajax({
		url: '/session.php',
		method: 'get'
	});
	setTimeout("session_stay()", 200000);
}

function change_msg_receiver(id, name) {
	$('#receiver_id').val(id);
	$('#recipient_name').val(name);
	$('#send_message_tooltip').html('');
	$('#send_message_tooltip').css('height', 0);
	$('#send_message_tooltip').css('display','none');
}

function msg_options(id, type, userid) {
	var ch = $('#ch_'+id).attr('checked');
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		data: {
			type: type,
			what: (ch === true) ? 'add' : 'remove',
			enforcer: 'change_alert',
			userid: userid
		},
		success: function(response) { }
	});
}

function visibility_account() {
	var ch = $('#visibility_account').attr('checked');
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		data: {
			what: (ch === true) ? 'add' : 'remove',
			enforcer: 'change_visibility'
		},
		success: function(response) { }
	});
}

function delete_web_link(id, user) {
	if (!confirm('Esti sigur ca vrei sa stergi acest link ?')) return false;
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		data: {
			link: id,
			user: user,
			enforcer: 'delete_web_link'
		},
		success: function(response) {
			if (response == 2) {
				$('#user_link_'+id).css('background', 'pink');
				$('#user_link_'+id).fadeOut('slow');
			}
		}
	});
}
function submit_comment() {
	document.new_comment.submit();
	return false;
}
function sterge_avatar(user_id) {
	if (!confirm('Esti sigur ca vrei sa stergi poza de profil ?')) return false;
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		data: {
			userid: user_id,
			enforcer: 'delete_avatar'
		},
		success: function(response) {
			if (response == 2) {
				$('#small_avatar_edit').attr('src', '/imgs/dummy-profile-small.gif');
				//$('#profileLeft .image img').attr('src', '/imgs/dummy-profile-large.gif');
				$('#sterge_poza').hide();
			}
		}
	});
}


function add_sondaj() {
	$('#sondaj_add').hide();
	$('#sondaj').show();
}

var forum_form = {
	maxim: 12,
	check: function() {
		var I = 0;
		$('.p_opt').each(function(){ I++; });
		if (I < forum_form.maxim) {
			return true;
		} else {
			return false;
		}
	},
	add_option: function() {
		if (forum_form.check()) {
			var p = document.createElement('p');
			p.setAttribute('class', 'p_opt');
			var inpt = document.createElement('input');
			inpt.setAttribute('type', 'text');
			inpt.setAttribute('name', 'poll_option[new][]');
			inpt.setAttribute('class', 'poll_option');
			document.getElementById('poll_option').appendChild(p).appendChild(inpt);
			var img = document.createElement('img');
			img.setAttribute('alt', 'delete');
			img.setAttribute('src', '/imgs/ico/x-red.gif');
			img.setAttribute('onclick', '$(this).parent().remove()');
			p.appendChild(img);
		} else {
			alert('Se pot pune maxim '+forum_form.maxim+' variante');
		}
	},
	remove_option: function(id, thread) {
		if (!confirm('Esti sigur ca vrei sa stergi aceasta optiune?')) return false;
		$.ajax({
			url: '/ajax.php?section=forum',
			type: 'post',
			data: {
				id: id,
				threadid: thread,
				type: 'delete_poll_option'
			},
			success: function(response) {
				if (response == 2) {
					$('#p_opt_'+id).fadeOut('slow');
					$('#p_opt_'+id).remove();					
				} else {
					alert('A intervenit o eroare');
				}
			}
		});
	}
};

function vote_poll(poll_id, option_id) {
	$.ajax({
		url: '/ajax.php?section=forum',
		type: 'post',
		dataType: 'json',
		data: {
			poll_id: poll_id,
			option_id: option_id,
			enforcer: 'poll_vote',
			type: 'poll_vote'
		},
		success: function(msg) {
			if (msg.code != 2) {
				alert(msg.msg);
			} else {
				for (var I in msg.poll_options) {
					if (msg.poll_options[I].id == option_id) {
						$('#radio_'+msg.poll_options[I].id).html('<img src="/imgs/voted.png" alt="voted">');
					} else {
						$('#radio_'+msg.poll_options[I].id).html('&nbsp;');
					}
					$('#graf_line_'+msg.poll_options[I].id).css('width', msg.poll_options[I].percent+'%');
					var voturi = (msg.poll_options[I].votes == 1) ? 'vot' : 'voturi';
					$('#percentage_'+msg.poll_options[I].id).html(msg.poll_options[I].votes+' '+voturi+', '+msg.poll_options[I].percent+'%');
				}
			}
		}
	});
}

var nr_job = 0;
function add_new_job() {
	nr_job++;
	$.ajax({
		url : '/ajax.php?section=profile',
		type: 'post',
		data: {
			nr: nr_job,
			enforcer: 'add_new_job'
		},
		success: function(response) {
			$('#add_new_job').append(response);
		}
	});
}



var nr_std = 0;
function add_new_study() {
	nr_std++;
	$.ajax({
		url : '/ajax.php?section=profile',
		type: 'post',
		data: {
			nr: nr_std,
			enforcer: 'add_new_study'
		},
		success: function(response) {
			$('#add_new_study').append(response);
		}
	});
}

function show_date_picker(the_id) {
	Calendar.setup({
	    inputField  : the_id,         // ID of the input field
	    ifFormat    : "%d-%m-%Y",    // the date format
	    firstDay    : 1    // first day of the week
		}
	);
}

function hide_gmail_importer_banner() {
	$.ajax({
		url: '/ajax.php?section=general&',
		type: 'POST',
		data: {
			type: 'hide_gmail_importer_banner'
		}
	});
	$('#import_gmail').fadeOut('slow');
}

function profile_ignore_user(recipientID) {
	if (!confirm('Esti sigur ca vrei sa ignori acest utilizator ?')) return false;
	$.ajax({
		type : 'post',
		dataType : 'json',
		data: {
			'enforcer' : 'profile_ignore_user', 
			'victim' : recipientID
		},
		url: site_url+'/ajax.php?section=profile',
		success : function(data) {
			if (data.code == 2) {
//				alert(data.msg);
			}
			alert(data.msg);
		}
	});
	e.preventDefault();
}

function delete_tweet(id) {
	//var postID = $(this).attr('id').replace('tw_','');
	if (confirm('Esti sigur ca vrei sa stergi acest post?')) {
		$.ajax({
			url: site_url+'/ajax.php?section=profile',
			type: 'post',
			data: {
				id: id,
				enforcer: 'delete_user_event'
			},
			success: function(response) {
				if (response == 2) {
					$('#event_'+id).css('background', '#f25b5b');
					$('#event_'+id).fadeOut('slow');
				}
				e.preventDefault();
			}
		});
	}
}

var vote_titles = new Array('nici un vot', 'foarte slab', 'slab', 'merge', 'bun', 'foarte bun');

function star_hover(id, nr) {
	if (nr > 0) {
		$('#img_'+id+'_1').attr('src', '/imgs/star/on.png');
	} else {
		$('#img_'+id+'_1').attr('src', '/imgs/star/off.png');
	}
	if (nr > 1) {
		$('#img_'+id+'_2').attr('src', '/imgs/star/on.png');
	} else {
		$('#img_'+id+'_2').attr('src', '/imgs/star/off.png');
	}
	if (nr > 2) {
		$('#img_'+id+'_3').attr('src', '/imgs/star/on.png');
	} else {
		$('#img_'+id+'_3').attr('src', '/imgs/star/off.png');
	}
	if (nr > 3) {
		$('#img_'+id+'_4').attr('src', '/imgs/star/on.png');
	} else {
		$('#img_'+id+'_4').attr('src', '/imgs/star/off.png');
	}
	if (nr > 4) {
		$('#img_'+id+'_5').attr('src', '/imgs/star/on.png');
	} else {
		$('#img_'+id+'_5').attr('src', '/imgs/star/off.png');
	}
//	write_vote_title(id, nr);
}
function star_out(id, nr) {
	$('#img_'+id+'_1').attr('src', '/imgs/star/'+((nr > 0) ? 'on' : 'off')+'.png');
	$('#img_'+id+'_2').attr('src', '/imgs/star/'+((nr > 1) ? 'on' : 'off')+'.png');
	$('#img_'+id+'_3').attr('src', '/imgs/star/'+((nr > 2) ? 'on' : 'off')+'.png');
	$('#img_'+id+'_4').attr('src', '/imgs/star/'+((nr > 3) ? 'on' : 'off')+'.png');
	$('#img_'+id+'_5').attr('src', '/imgs/star/'+((nr > 4) ? 'on' : 'off')+'.png');
}
function write_vote_title(id, nr) {
	/*if (nr < 1) {
		var text = vote_titles[(nr)];
		$('#tei5_'+id).html(text);
	} else if (nr > 5) {
		var text = vote_titles[(nr)];
		$('#tei5_'+id).html(text);
	} else {
		var text = vote_titles[(nr)];
		$('#tei5_'+id).html(text);
	}*/
}
function tw_vote(id, nr) {
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		dataType : 'json',
		data: {
			id: id,
			score: nr,
			enforcer: 'vote_tweet'
		},
		success: function(result) {
			if (result.code == 2) {
				$('#info_tei_'+id).html(nr);
				get_tw_votes(id);
				alert(result.msg);
			} else {
				alert(result.msg);
			}
		}
	});
}
function get_tw_votes(id) {
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		dataType : 'json',
		data: {
			id: id,
			enforcer: 'get_vote_tweet'
		},
		success: function(result) {
			if (result.votes == 1) {
				var _vot_ = '1 vot';
			} else {
				var _vot_ = result.votes+' voturi';
			}
			$('#tei5_'+id).html(_vot_);
			star_hover(id, result.score);
		}
	});
}
function share_tweet(id) {
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		dataType : 'json',
		data: {
			id: id,
			enforcer: 'share_tweet'
		},
		success: function(result) {
			if (result.code == 2) {
				alert(result.msg);
			} else {
				alert(result.msg);
			}
		}
	});
}
function unshare_tweet(id) {
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		dataType : 'json',
		data: {
			id: id,
			enforcer: 'unshare_tweet'
		},
		success: function(result) {
			if (result.code == 2) {
				alert(result.msg);
			} else {
				alert(result.msg);
			}
		}
	});
}

function positionBranding() {
	/* positioning banners */
	var top = $('#topBrandingBanner').offset().top;
	top = parseInt(top + $('#topBrandingBanner').height()) + 'px';
	var left = parseInt(($(window).width() - 1245) / 2) + 'px';
	$('#leftBrandingBanner').css('top',top);
	$('#leftBrandingBanner').css('left',left);
	var windowWidth = $(window).width();
	var rightBrandingWidth = (windowWidth - 990) / 2 >= 0 ? (windowWidth - 990) / 2 : 0;
	rightBrandingWidth = rightBrandingWidth > 125 ? 125 : rightBrandingWidth;
	if (rightBrandingWidth < 125) {
		$('#rightBrandingBanner').css('overflow','hidden');
	} else {
		$('#rightBrandingBanner').css('overflow','auto');
	}
	var rightHacker = parseInt(($(window).width() - 1245) / 2);
	left = $(window).width() <= 1245 ? parseInt($(window).width() - rightBrandingWidth) + 'px' : parseInt($(window).width() - rightBrandingWidth - rightHacker) + 'px';
	rightBrandingWidth = rightBrandingWidth + 'px';
	$('#rightBrandingBanner').css('top',top);
	$('#rightBrandingBanner').css('left',left);
	$('#rightBrandingBanner').css('width',rightBrandingWidth);
	var topBrandingBannerLeft = parseInt(($(window).width() - 1245) / 2) + 'px';
	var topBrandingBannerWidth = $(window).width() >= 1245 ? '1245px' : parseInt($(window).width() - ($(window).width() - 1245) / 2) + 'px';
	$('#topBrandingBanner').css('left',topBrandingBannerLeft).css('width',topBrandingBannerWidth);
	$('#rightBrandingBanner').show();
	$('#leftBrandingBanner').show();
	$('#topBrandingBanner').show();
	var top = $('#topBrandingBanner').offset().top;
	top = parseInt(top + $('#topBrandingBanner').height()) + 'px';
	$('#center').css('padding-top',top);
}

var fb_perms = {perms:'publish_stream,user_birthday,user_education_history,user_hometown,user_location,user_work_history,email'}; 

function fb_post(id) {
	FB.login(function(response) {
		if (response.session) {
			$.ajax({
				url: 'http://keypeople.dailybusiness.ro/fb/post_on_facebook.php',
				type: 'post',
				dataType: 'json',
				data: {
					id: id
				},
				success: function(r) {
					alert(r.msg)
				}
			});
		} else {
			//alert('Nu te-ai autentificat in FACEBOOK');
		}
	}, fb_perms);
}
function get_fb_info() {
	var token = '154314457949168';
	$.ajax({
		url: 'http://keypeople.dailybusiness.ro/fb/graf.php',
		type: 'post',
		dataType: 'json',
		success: function(rasp) {
			$('#top_first_name').val(rasp.first_name);
			$('#top_last_name').val(rasp.last_name);
			$('#top_email').val(rasp.email);
			$('#top_username').val(rasp.username);
			$('#fb_user_id').val(rasp.id);
		}
	});
}
function my_fb_login() {
	FB.login(function(r){
		if (r.session) {
			fb_kp_login();
		}
	}, fb_perms);
}

function fb_kp() {
	$.ajax({
		url: 'http://keypeople.dailybusiness.ro/fb/sync.php',
		type: 'post',
		dataType: 'json',
		success: function(rasp) {
			if (rasp.code == 1) {
				FB.login(function(r){
					if (r.session) {
						//fb_kp();
					}
				}, fb_perms);
			} else if (rasp.code == 2) {
				alert('Va multumim. Contul dumneavoastra de Facebook a fost sincronizat cu contul de KeyPeople');
			} else {
				alert(rasp.msg);
			}
		}
	});
}
function fb_kp_login() {
	$.ajax({
		url: 'http://keypeople.dailybusiness.ro/fb/graf_login.php',
		type: 'post',
		dataType: 'json',
		success: function(rasp) {
			if (rasp.code == 2) {
				window.location = rasp.url;
			} else {
				alert(rasp.msg);
			}
		}
	});
}

function intreaba_specialistul(id) {
	var the_content = $('#intrebare_'+id).val();
	$.ajax({
		url: site_url+'/ajax.php?section=profile',
		type: 'post',
		dataType: 'json',
		data: {
			admin_id: id,
			content: the_content,
			enforcer: 'profile_intreaba_specialistul'
		},
		success: function(rasp){
			if (rasp.code == 2) {
				$('#specialist_'+id).html('<div id="txt-intreaba-specialist-'+id+'"><p style="text-align: center; color: green;">mesajul dumneavoastra a fost trimis cu succes</p></div>');
				setTimeout(function() {
					$('#txt-intreaba-specialist-'+id+' p').css('color', '#000000');
				}, 2000);
			} else {
				alert(rasp.msg);
			}
		}
	});
}
