var General = {
	_check_user : false,
	_confirmed : false,
	_allowed_image_types : '.jpg.gif.png.jpeg.',
	_is_ie : /MSIE/.test(navigator.userAgent) || false,
	_picId : 0,
	_x : 0,
	_y : 0,
	_clicked : 0,
	_close_birthday : function()
	{
		$('birthday_container').remove();
		this._create_cookie('birthdayClosed', 'yes', 1);
	},
	_in_array : function(_a, p_val) 
	{
		for ( var i = 0, l = _a.length; i < l; i++ ) 
		{
			if ( _a[i] == p_val )
				return true;
		}
	return false;
	},	
	_create_cookie : function( name, value, days )
    {    
	var expires;	
        if ( days )
		{
			 var date = new Date();
			 date.setTime(date.getTime() + (days*24*60*60*1000));
			 expires = "; expires=" + date.toGMTString();
		}
		else 
			expires = "" ;
		
		document.cookie = name + "=" + value + expires + "; path=/; domain=.hot.bg" ;
		
		if ( !document.cookie )    
			return false ;
	
   return true ;

   },
   _read_cookie : function( name )
   {
        var nameEQ = name + "=";
        var ca = document.cookie.split( ';' );
        for ( var i=0; i < ca.length; i++ )
        {
                var c = ca[i] ;
                while ( c.charAt( 0 ) == ' ' ) 
					c = c.substring( 1, c.length ) ;

                if ( c.indexOf(nameEQ) == 0 ) 
					return c.substring( nameEQ.length, c.length );
        }
        return true;
    },
	_bookmark : function(url, title) 
	{	 	
		if ( window.sidebar ) 
			window.sidebar.addPanel( title, url, '');
		else if ( window.external ) 
			window.external.AddFavorite( url, title);
		else if ( window.opera && window.print ) 
			return true;
        return false;
 	},
	_no_results : function(id, text)
	{
		if ( !id || typeof id == 'undefined' || !$(id) )
			return false;
			
		var el = $$('div.user_panel').length;

		if ( el == 0 )
			$(id).update('<div class="not_found"><span>' + text + '</span></div>');
			
	return false;
	},
	_register_form : function(form)
	{
		var email = form.userEmail.value;
		var userFullName = form.userFullName.value;
		var pass = form.userPassword.value;		
		//var picture = form.userPicture.value;
		var sex = form.userGender.options[form.userGender.selectedIndex].value;
		
		var year = form.userBirthDateYear.options[form.userBirthDateYear.selectedIndex].value;
		var month = form.userBirthDateMonth.options[form.userBirthDateMonth.selectedIndex].value;
		var day = form.userBirthDateDay.options[form.userBirthDateDay.selectedIndex].value;
		
		var tos = form.accept_tos.checked;
				
		var q = form.userQuestion.value;
		
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		//var ext = picture.split('.');
		//ext = '.' + ext[ext.length-1].toLowerCase() + '.';
		
		if ( userFullName.blank() )
			this._error('Въведи пълно име', 'userFullNameText');
		else if ( !filter.test(email) )
			this._error('Въведи валиден e-mail адрес', 'userEmailCheck');
		else if ( pass.blank() )
			this._error('Въведи парола', 'userPasswordRText');
		else if ( sex == 0 )
			this._error('Избери твоя пол', 'userGender');		
		else if ( year == 0 || month == 0 || day == 0 )
			this._error('Въведи валидна рожденна дата', 'userBirthDateYear');
		//else if ( picture.blank() )
			//this._error('Избери снимка за профила си');
		//else if ( !picture.blank() && this._allowed_image_types.indexOf(ext) == -1 )
			//this._error('Файла, който искаш да качиш не е снимка', 'userPictureText');
		else if ( q.blank() )
			this._error('Напиши отговор на въпроса', 'userQuestionText');
		else if ( tos == false )
			this._error('За да продължите регистрацията трябва да отбележите, че сте съгласни с нашите условия за ползване.', 'accept_tos_container');
		else
		{			
			/*if ( picture != '')
			{
				$('register_form').hide();
				$('register_text').show();
			}*/
		return true;
		}
				
	return false;
	},
	_password_strength : function(pass, msg)
	{
		var length = pass.length;
		var strength = 0;
		
		if( length == 0 )
			return false;
		
		number_re = new RegExp('[0-9]');		
		if ( number_re.test(pass) )
			strength++;
		
		non_alpha_re = new RegExp('[^A-Za-z0-9]');
		if ( non_alpha_re.test(pass) )
			strength++;
		
		upper_alpha_re = new RegExp('[A-Z]');
		if ( upper_alpha_re.test(pass) )
			strength++;
		
		
		if ( length >= 8 )
			strength++;		
		
		var error = '<div style="font-weight: normal; color: #000; font-size: 11px;">Сигурност на паролата: ';
		
		if ( strength <= 1 )		
			error += '<strong style="color: #808080;">слаба</strong>';		
		else if ( strength <= 2 )		
			error += '<strong style="color: #008FEB;">средно</strong>';		
		else		
			error += '<strong style="color: #008048;">сигурна</strong>';
			
		error += '</div>';
		if( length < 4 )		
			error = '<strong style="color: #FFA548;">Твърде кратка</strong>';
		
		this._error(error, msg, true);
		
	return false;
	},
	_upload_picture : function()
	{
		var picture = $('userPicture').value;
		var ext = picture.split('.');
		ext = '.' + ext[ext.length-1].toLowerCase() + '.';
		
		if ( this._allowed_image_types.indexOf(ext) == -1 )
			this._error('Файла, който искаш да качиш не е снимка');
		else
			return true;
			
	return false;
	},
	_pictures_edit_my_comments : function(comId)
	{
		$('pic_comment_div_' + comId, 'pic_comments_edit_form_' + comId).invoke('toggle');
	},
	_pictures_save_my_comments : function(comId)
	{
		var text = $('picCommentText_' + comId).value;
		
		if ( text.blank() )
			return this._error('Коментара не може да бъде празен.', 'pic_comments_edit_form_' + comId);
		
		$('loading').show();
		new Ajax.Request('ajax', {
				parameters : {'section' : '_pictures_save_my_comments', 'comId' : comId, 'text' : text.stripTags()},
				onComplete : function(response)
				{
					$('loading').hide();
					General._pictures_edit_my_comments(comId);
					$('pic_comment_span_' + comId).update(response.responseText);
					$('picCommentText_' + comId).update(response.responseText);
				}
						 });
	return false;
	},
	_picture_inplace_editor : function(picId)
	{
		if ( typeof picId == 'undefined' || picId <= 0 )
			return false;
		
		new Ajax.InPlaceEditor( 'name_' + picId, 'ajax', {
							   okText: 'Запис', 
							   rows: 10, 
							   cols: 40, 
							   savingText: 'Записване...', 
							   highlightcolor: '#ECF2F9', 
							   highlightendcolor: '#ECF2F9', 
							   clickToEditText: 'Цъкни за да редактираш', 
							   cancelText: 'Отказ', 
							   callback: function(form, value) 
							   {
								   return 'section=_inplace_edit_name&id=' + picId + '&value=' + value.stripTags(); 
								}
			});
	return false;
	},
	_pictures_save_topOffset : function(form)
	{
		var topOffset = parseInt(form.topOffset.value);
		var picId = parseInt(form.picId.value);
		$('loading').show();
		new Ajax.Request('ajax', {
						 parameters : {'section' : '_pictures_save_topOffset', 'topOffset' : topOffset, 'picId' : picId},
						 onComplete : function()
						 {
							General._success('Позицията на снимката е запазена.', 'profile_big_picture_coords_container');
							$('loading').hide(); 
						 }
						 });
	return false;
	},
	_change_picture_permission : function(el, picId)
	{
		if ( typeof el == 'string' )
			el = $(el);
			
		if ( typeof picId == 'undefined' )
			picId = this._picId;
			
		var permission = el.options[el.selectedIndex].value;
		var value = el.options[el.selectedIndex].text;
		
		new Ajax.Request('ajax', {
						 parameters : {'section' : '_change_picture_permission', 'picId' : picId, 'permission' : permission},
						 onComplete : function()
						 {
							General._success('Достъпа до снимката е променен. Достъп до нея ще имат - ' + value); 
						 }
						 });
	return false;
	},
	_pictures_change_album : function(el, picId)
	{
		if ( typeof el == 'string' )
			el = $(el);
			
		if ( typeof picId == 'undefined' )
			picId = this._picId;
			
		var albumId = el.options[el.selectedIndex].value;
		var value = el.options[el.selectedIndex].text;
		
		if ( albumId == 0 )
			value = 'Основен';
		
		new Ajax.Request('ajax', {
						 parameters : {'section' : '_pictures_change_album', 'picId' : picId, 'albumId' : albumId},
						 onComplete : function()
						 {
							General._success('Снимката е преместена в албум - ' + value); 
						 }
						 });
	return false;
	},
	_pictures_album_delete : function(albumId)
	{
		if ( typeof albumId == 'undefined' )
			return false;
			
		if ( this._confirm('Сигурен ли си, че искаш да изтриеш албума? Всички снимки ще бъдат прехвърлени към Основен албум.', 'General._pictures_album_delete(' + albumId + ');') == false )
			return false;
			
		new Ajax.Request('ajax', {
						 	parameters : {'section' : '_pictures_album_delete', 'albumId' : albumId},
							onComplete : function()
							{
								window.location = 'profile?a=picture';
							}
						 });
	return false;
	},
	_save_picture_tag : function(form)
	{
		if ( typeof i == 'undefined' )
			i = 1;
		else
			i++;
		
		var tag = form.pic_tag.value;
		if ( tag.blank() )
			this._error('Напиши ключова дума или име');
		else
		{
			var coords = form.pic_tag_coords.value;
			var html = '<div id="tag_' + i + '" style="padding: 5px;" onmouseover="$(\'picture_coords_show_' + i + '\').show();" onmouseout="$(\'picture_coords_show_' + i + '\').hide();"><span>' + tag + '</span> <a href="javascript:void(0)" onclick="$(\'tag_' + i + '\', \'picture_coords_show_' + i + '\').invoke(\'remove\');">премахни</a><input type="hidden" name="_tags[' + i + '][value]" value="' + tag + '" /><input type="hidden" name="_tags[' + i + '][coords]" value="' + coords + '" /></div>';
			
			new Insertion.Bottom('picture_tags_form', html);
			form.pic_tag_coords.value = '';
			form.pic_tag.value = '';
			$('picture_tags_form_container').show();
			$('picture_tags').hide();
			this._gen_picture_coords(coords, 'profile_big_picture');
			CropImageManager.resetCropper();
		}
	return false;
	},
	_save_picture_tag_user : function(userId, userName, forms)
	{
		if ( typeof i == 'undefined' )
			i = 1;
		else
			i++;
			
		var form = $(forms);
		var coords = form.pic_tag_coords.value;
		var html = '<div id="tag_' + i + '" style="padding: 5px;" onmouseover="$(\'picture_coords_show_' + i + '\').show();" onmouseout="$(\'picture_coords_show_' + i + '\').hide();"><img src="i/icons/user.gif" alt="" /> <a href="profile?id=' + userId + '">' + userName + '</a> <a href="javascript:void(0)" onclick="$(\'tag_' + i + '\', \'picture_coords_show_' + i + '\').invoke(\'remove\');">премахни</a><input type="hidden" name="_tags[' + i + '][userId][value]" value="' + userId + '" /><input type="hidden" name="_tags[' + i + '][userId][coords]" value="' + coords + '" /></div>';
			
		new Insertion.Bottom('picture_tags_form', html);
		form.pic_tag_coords.value = '';
		form.pic_tag.value = '';
		$('picture_tags_form_container').show();
		$('picture_tags').hide();
		this._gen_picture_coords(coords, 'profile_big_picture');
		CropImageManager.resetCropper();
		
	return false;
	},
	_gen_picture_coords : function(coords, el)
	{
		var _coords = coords.split(',');
		
		var html = '<div id="picture_coords_show_' + i + '" style="position: absolute; top: ' + _coords[1] + 'px; left: ' + _coords[0] + 'px; padding: 1px; z-index: 2000; display: none; border: 1px solid #7F7F7F;"><div style="width: ' + _coords[4] + 'px; height: ' + _coords[5] + 'px; border: 1px solid #ccc;">&nbsp;</div></div>';
		
		new Insertion.After(el, html);
	},
	_close_picture_coords : function()
	{
		$('picture_coords_show').remove();
	},
	_picture_tags : function(pId)
	{
		var id = $(pId);
		var tag = id.getElementsByTagName('img')[0];
		$(tag.id).observe('load', General._picture_tags_show);
		id.observe('mouseover', General._picture_tags_show);
		id.observe('mouseout', General._picture_tags_hide);
	},
	_picture_tags_hide : function()
	{
		var els = $$('div.pictures_tags');
		
		els.each(function(el){						 
						 Event.stopObserving(el, 'mouseover', function(){
														  el.setStyle({'border' : '1px solid #008FEC'});
														  $(el.id + '_text').show().setStyle({zIndex : 9999});
														  });
						 Event.stopObserving(el, 'mouseout', function(){
														 el.setStyle({'border' : '1px solid #7F7F7F'});
														 $(el.id + '_text').hide().setStyle({zIndex : 1000});
														 });
						 el.hide();
						 });
	},
	_picture_tags_show : function()
	{
		var els = $$('div.pictures_tags');
		
		els.each(function(el){
						 Event.observe(el, 'mouseover', function(){
														  el.setStyle({'border' : '1px solid #008FEC'});
														  $(el.id + '_text').show().setStyle({zIndex : 9999});
														  });
						 Event.observe(el, 'mouseout', function(){
														 el.setStyle({'border' : '1px solid #7F7F7F'});
														 $(el.id + '_text').hide().setStyle({zIndex : 1000});
														 });
						 el.show();
						 });
	},
	_check_username : function(el)
	{
		if ( typeof _t != 'undefined' )		
			clearTimeout(_t);
			
		var username = el.value;
		
		if ( !username.blank() && username.length > 2 )
		{
			_t = window.setTimeout(function(){new Ajax.Request('ajax', {
						 		parameters : {'section' : '_check_username', 'username' : escape(username.stripTags())},
								onComplete : function(res)
								{
									if ( $('userNameError') )
										$('userNameError').remove();
										
									var response = res.responseText;
									
									var _response = response.split('|');
																		
									new Insertion.After('userNameCheck', '<span id="userNameError" class="' + (_response[0] == 'success' ? 'Success' : 'Error') + '" style="font-size: 11px; padding: 0 10px;">' + _response[1] + '</span>');
								}
						 });}, 200);
		}
	},	
	_check_email : function(el)
	{
		if ( typeof _t_e != 'undefined' )		
			clearTimeout(_t_e);
		
		var email = el.value;
		
		if ( email.blank() || email.length < 4 )
			return false;
		
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if ( filter.test(email) )
		{
				_t_e = window.setTimeout(function(){new Ajax.Request('ajax', {
						 		parameters : {'section' : '_check_email', 'email' : email},
								onComplete : function(res)
								{
									if ( $('userEmailError') )
										$('userEmailError').remove();
										
									var response = res.responseText;									
									var _response = response.split('|');
									
									new Insertion.After('userEmailCheck', '<span id="userEmailError" class="left" style="color: #' + (_response[0] == 'success' ? '008FEB' : 'EF8D0E') + '; font-size: 11px; padding: 0 10px;">' + _response[1] + '</span>');
								}
						 });}, 200);
		}
	return false;
	},	
	_hide : function(id, time)
	{
		if ( typeof time == 'undefined' )
			time = 1000;
			
		setTimeout(function(){$(id).update('').hide();}, time);	
	},	
	_confirm : function(text, func)
	{
		if ( General._confirmed == true )
		{
			return true;
		}
		
		var b_w = window.innerWidth || document.body.offsetWidth;
		var c_w = 870;

		if ( $('confirm').style.display == '' )
			return false;

		$('confirm').show();
		$('confirm_message').update(text);	
		$('confirm_button').onclick = function()
		{
			General._confirmed = true;
			eval(func); 
			General._hide_confirm(func);
		}		
	return false;
	},	
	_hide_confirm : function(func)
	{
		General._confirmed = false;

		$('confirm_button').onclick = function(){}
		
		$('confirm').setStyle({top : 0 + 'px'}).hide();
		$('confirm_message').update('');	
	},	
	_error : function(text, id, stop_hide)
	{
		var name = (typeof id == 'undefined' ? '' : id.name) || '';
		if ( typeof id != 'undefined' && typeof id == 'string' )
		{
			name = id;
			id = $(id);
		}
		
		if ( typeof stop_hide == 'undefined' )
			stop_hide = false;
			
		if ( !$('Error' + name) )
		{
			var div = new Element('div', {'class': 'Error', 'id' : 'Error' + name});
			new Insertion.After((id || 'header'), div);
		}

		$('Error' + name).update(text).show();
			
		if ( typeof _e_t != 'undefined' )
			clearTimeout(_e_t);
			
		if ( typeof _el != 'undefined' )
			$('Success').setStyle({'left' : (_el[0]-200) + 'px', 'top' : _el[1] + 'px', 'position' : 'absolute', 'border' : '1px solid #FF9000'});
		
		if ( stop_hide == false )
			_e_t = setTimeout(function(){$('Error' + name).update('').hide();}, 4000);
	},	
	_success : function(text, id)
	{
		var name = (typeof id == 'undefined' ? '' : id.name) || '';
		if ( typeof id != 'undefined' && typeof id == 'string' )
		{
			name = id;
			id = $(id);
		}
		
		if ( typeof stop_hide == 'undefined' )
			stop_hide = false;
		
		if ( !$('Success' + name) )
		{
			var div = new Element('div', {'class': 'Success', 'id' : 'Success' + name});
			new Insertion.After((id || 'header'), div);
		}
		
		if ( typeof _s_t != 'undefined' )
			clearTimeout(_s_t);
			
		if ( typeof _el != 'undefined' )
			$('Success').setStyle({'left' : (_el[0]-200) + 'px', 'top' : _el[1] + 'px', 'position' : 'absolute', 'border' : '1px solid #008FEC'});
		
		$('Success' + name).update(text).show();
		
		if ( stop_hide == false )
			_s_t = setTimeout(function(){$('Success' + name).update('').hide();}, 4000);		
	},
	_get_group_topics : function(groupId, order, position)
	{
		if ( typeof groupId == 'undefined' || groupId <= 0 )
			return false;
			
		$('loading').show();
		new Ajax.Updater('group_topics_container', 'ajax', {
						 				parameters : {'section' : '_get_group_topics', 'groupId' : groupId, 'order' : order, 'position' : position},
										onComplete : function()
										{
											$('loading').hide();
										}
		});
	return false;
	},
	_group_topic_watch : function(topicId, watch)
	{
		if ( typeof topicId == 'undefined' )
			return false;
			
		$('loading').show();
		new Ajax.Updater('topic_watch_container', 'ajax', {
						  parameters : {'section' : '_group_topic_watch', 'topicId' : topicId, 'watch' : watch},
						  onComplete : function()
						  {
							$('loading').hide();
						  }
						  });
	return false;
	},
	_attach_toggle_button : function(from, button)
	{
		if ( typeof button == 'string' )
			button = $(button);
		
		if ( typeof from == 'string' )
			from = $(from);
		
		if ( !(from.value).blank() )		
			button.removeClassName('inbox_menu_disabled');
		else
			button.addClassName('inbox_menu_disabled');
	},
	_attach_to_mail : function(froms, tos, a)
	{
		var from = $(froms);
		var to = $(tos);
		
		if ( typeof a == 'string' )
			a = $(a);
		
		if ( typeof uid == 'undefined' )
			uid = 1;
		
		if ( !(from.value).blank() )
			a.removeClassName('inbox_menu_disabled');
			
		if ( a.className.indexOf('inbox_menu_disabled') != -1 )
			return false;

			var ext = from.value.split('.');
			ext = '.' + ext[ext.length-1].toLowerCase().strip() + '.';
									
			if ( General._allowed_image_types.lastIndexOf(ext) == -1 )
				to.value += ' ' + from.value + ' ';
			else
			{
				if ( $('attach_url').value.indexOf(from.value) == -1 )
				{
					if ( typeof total_images == 'undefined' )
						total_images = 1;
					else if ( total_images < 3 )
						total_images += 1;
						
					if ( total_images == 3 )
					{
						General._error('Можеш по 2 снимки да прикачаш', 'inbox_attach_container');
						total_images = 2;
						from.value = '';
						a.addClassName('inbox_menu_disabled');
						return false;
					}
					
					var div = new Element('div', {'class' : 'left', 'id' : 'container_remove_attach_' + uid, 'style' : 'text-align: center;'});
					var a_href = new Element('a', {'href' : from.value, 'target' : '_blank'});
					var img = new Element('img', {'src' : from.value, 'alt' : '', 'border' : '0', 'width' : '80', 'style' : 'padding: 5px;'});
					var br = new Element('br');
					
					var img_x = new Element('img', {'src' : 'i/icons/x.gif', 'alt' : '', 'style' : 'padding-right: 5px;'});
					var a_remove = new Element('a', {'href' : 'javascript:void(0);', 'id' : 'remove_attach_' + uid}).update('премахни');
					
					a_href.appendChild(img);
					div.appendChild(a_href);
					div.appendChild(br);
					div.appendChild(img_x);
					div.appendChild(a_remove);					
					
					new Insertion.Bottom('attach_preview', div);
					$('attach_url').value += ' ' + from.value + ' ';
					$('attach_preview').show();
										
					Event.observe('remove_attach_' + uid, 'click', function(e){Inbox._remove_attach(e);});
					uid += 1;
				}
			}
										
			to.focus();
			from.value = '';
			a.addClassName('inbox_menu_disabled');
		
	return false;
	},
	_remove_attach : function(e)
	{	
		var el_id = Event.element(e).id;
		var href = $('container_' + el_id).getElementsByTagName('a')[0].href;
		total_images -= 1;
		
		Event.stopObserving(el_id, 'click', function(e){Inbox._remove_attach(e); return false;});
				
		$('attach_url').value = $('attach_url').value.replace(href, '');
		$('container_' + el_id).remove();
		
	return false;
	},
	_group_delete_post : function(postsId)
	{
		if ( typeof postsId == 'undefined' || postsId <= 0 )
			return false;
			
		$('loading').show();
		new Ajax.Request('ajax', {
						 				parameters : {'section' : '_group_delete_post', 'postsId' : postsId},
										onComplete : function(res)
										{
											new Insertion.After('post_container_' + postsId, '<tr><td colspan="3" style="background-color: #EFEFEF; height: 30px; line-height: 30px; text-align: center;"><span>Съобщението е изтрито на ' + res.responseText + '</span></td></tr>');
											$('post_container_' + postsId).remove();
											$('loading').hide();
										}
		});
	return false;
	},
	_group_transfer_owner : function(groupId)
	{
		if ( typeof groupId == 'undefined' || groupId <= 0 )
			return false;
			
		$('loading').show();
		new Ajax.Updater('transfer', 'ajax', {
						 				parameters : {'section' : '_group_transfer_owner', 'groupId' : groupId},
										onComplete : function()
										{
											$('transfer').show();
											$('loading').hide();
										}
		});
	return false;
	},	
	_group_reply_form : function(form, index)
	{
		 var msgtext = form.postText.value;
		 if ( msgtext.length > 5000 || msgtext.blank() )
		 {
			 this._error('Отговорите могат да бъдат максимум 5000 символа. Написал си ' + msgtext.length + '');
			 scroll(0, 0);
			 return false;
		 }
		 $('loading').show();
		 var replyId = 0;
		 
		 if ( $('quoteMessage_' + index).checked ) 
		 {
			 replyId = index;
		 }
		 
		 new Ajax.Request('ajax', {
						  parameters : {'section' : '_group_post_reply', 'topicId' : parseInt(form.topicId.value), 'replyId' : parseInt(replyId), 'postText' : msgtext.escapeHTML()},
						  onComplete : function(res)
						  {
							 $('post_reply_' + index).hide();
							 form.postText.value = '';
							 new Insertion.Bottom('container_posts', res.responseText);
							 $('loading').hide();
						  }
			});
		
		 return false;
	},
	_group_new_post_form : function(form)
	{
		var msgtext = form.postText.value;
		 if ( msgtext.length > 5000 || msgtext.blank() )
		 {
			 this._error('Отговорите могат да бъдат максимум 5000 символа. Написал си ' + msgtext.length + '.', 'group_post_reply_button');
			 return false;
		 }
		 $('loading').show();
		 		 
		 new Ajax.Request('ajax', {
						  parameters : {'section' : '_group_post_reply', 'topicId' : parseInt(form.topicId.value), 'postText' : msgtext.escapeHTML(), 'attach_url' : form.attach_url.value},
						  onComplete : function(res)
						  {
							 form.postText.value = '';
							 form.attach_url.value = '';
							 $('attach_preview').hide().update('');
							 total_images = 0;
							 new Insertion.Bottom('container_posts', res.responseText);
							 $('loading').hide();
						  }
			});
		
		 return false;
	},
	_group_transfer_owner_process : function(userId, username, groupId)
	{
		if ( (typeof userId == 'undefined' || userId <= 0) || (typeof groupId == 'undefined' || groupId <= 0) )
			return false;

		if ( this._confirm('Сигурен ли си, че искаш да прехвърлиш собствеността на групата на ' + username + '?', 'General._group_transfer_owner_process(' + userId + ', \'' + username + '\', ' + groupId + ');') == false )
																																						   	return false;

			$('loading').show();
			new Ajax.Request('ajax', {
							 	parameters : {'section' : '_group_transfer_owner_process', 'userId' : userId, 'groupId' : groupId},
								onComplete : function()
								{
									window.location = 'group?g=' + groupId;
									$('manage_container').remove();
									General._success('Собствеността на групата е прехвърлена на ' + username + '. Ти си вече член на групата');
									$('loading').hide();
								}
							 });		
		return false;
	},
	_group_leave : function(groupId, userId)
	{
		if ( typeof groupId == 'undefined' || groupId <= 0 )
			return false;
			
		if ( typeof userId == 'undefined' )
			userId = 0;
			
		if ( this._confirm('Сигурен ли си, че искаше да напуснеш групата?', 'General._group_leave(' + groupId + ', ' + userId + ');') == false )
			return false;
			
		$('loading').show();
		new Ajax.Updater('group_leave_button', 'ajax', {
					parameters : {'section' : '_group_leave', 'groupId' : groupId},
					insertion: Insertion.Before,
					onComplete : function()
					{
						if ( $('group_members_' + userId) )
							$('group_members_' + userId).remove();
						
						if ( $('group_leave_button_2') )
							$('group_leave_button_2').remove();
							
						if ( $('posts_reply_form_2') )
							$('posts_reply_form_2').remove();
							
						$$('div.posts_reply_button').invoke('remove');
						$$('li.posts_reply_form').invoke('remove');
						
						$('loading').hide();
						
						$('group_leave_button', 'group_new_topic_button', 'group_new_topics', 'group_invite', 'group_share').invoke('remove');
					}
			});
	return false;
	},
	_share_check_form : function(form)
	{
		if ( $$('input.inbox_inputs').length == 0 )
		{
			General._error('Напиши до кого е съобщението', 'inbox_sender_container');
			Inbox._gen_inputs();
			return false;
		}
	return true;
	},
	_group_fire : function(userId, groupId, position, hide)
	{
		if ( typeof userId == 'undefined' || userId <= 0 )
			return false;
			
		if ( typeof groupId == 'undefined' || groupId <= 0 )
			return false;
			
		if ( typeof hide == 'undefined' )
			hide = 0;
		
		if ( this._confirm('Сигурен ли си, че искаш да изгониш потребителя?', 'General._group_fire(' + userId + ', ' + groupId + ', ' + position + ', ' + hide + ');') == false )
			return false;
			
		$('loading').show();
			
		new Ajax.Updater('group_members_container', 'ajax', {
						 		parameters : {'section' : '_group_fire', 'userId' : userId, 'groupId' : groupId, 'hide' : hide, 'position' : position},
								onComplete : function()
								{
									$('loading').hide();
								}
						 });
	return false;
	},
	_group_requests : function(type, userId, groupId, position, hide)
	{
		if ( typeof userId == 'undefined' || userId <= 0 )
			return false;
			
		if ( typeof groupId == 'undefined' || groupId <= 0 )
			return false;
			
		if ( typeof hide == 'undefined' )
			hide = 0;
		
		if ( type == 0 && this._confirm('Сигурен ли си, че искаш да откажеш заявка за членство на потребителя?', 'General._group_requests(' + type + ', ' + userId + ', ' + groupId + ', ' + position + ', ' + hide + ');') == false )
			return false;
			
		$('loading').show();
			
		new Ajax.Updater('group_requests_container', 'ajax', {
						 		parameters : {'section' : '_group_requests_manage', 'b' : type, 'userId' : userId, 'groupId' : groupId, 'hide' : hide, 'position' : position},
								onComplete : function()
								{
									$('loading').hide();
								}
						 });
	return false;
	},
	_group_abuse_report : function(postId)
	{
		if ( typeof postId == 'undefined' || postId <= 0 )
			return false;
		
		if ( this._confirm('Сигурен ли си, че искаш да съобщиш за нередно съобщение?', 'General._group_abuse_report(' + postId + ');') == false )
			return false;
			
		$('loading').show();
			
		new Ajax.Request('ajax', {
						 		parameters : {'section' : '_group_abuse_report', 'postId' : postId},
								onComplete : function()
								{
									$('loading').hide();
									this._success('Съобщението ти е изпратено');
								}
						 });
	return false;
	},
	_group_share_set_user : function(userId, username)
	{
		if ( typeof userId == 'undefined' || userId <= 0 )
			return false;
		
		var div = new Element('div', {'id' : 'share_' + userId, 'style' : 'display: inline; width: auto; padding: 0 15px 0 0;'});
		var input = new Element('input', {'type' : 'hidden', 'name' : 'userId[]', 'value' : userId});
		var a = new Element('a', {'href' : 'profile?id=' + userId, 'style' : 'margin-right: 10px;'}).update(username);
		
		var img_remove = new Element('img', {'src' : 'i/icons/x.gif', 'border' : 0, 'alt' : '', 'style' : 'padding: 0 5px;'});
		var a_remove = new Element('a', {'href' : 'javascript:void(0)', 'onclick' : '$(\'share_' + userId + '\').remove(); $(\'friend_list_user_' + userId + '\').show();'}).update('премахни');
		
		div.appendChild(input);
		div.appendChild(a);
		div.appendChild(img_remove);
		div.appendChild(a_remove);
		
		$('friends_list_share').appendChild(div);
		$('friend_list_user_' + userId).hide();
	return false;
	},
	_events_type : function(subtypes_array)
	{
		var selector = $('two_level_category');
		var subselector = $('two_level_subcategory');	
		if ( selector && subselector )
		{
			subselector.options.length = 1;
			var type_value = selector.options[selector.selectedIndex].value;
			if ( type_value == '' )
				type_value = -1;
					
			var index = 1;
			var suboptions = subtypes_array[type_value];
			if ( typeof(suboptions) != 'undefined' )
			{
				var suboptins_length = suboptions.length;
				for ( var key = 0; key < suboptins_length; key++ )
				{
					if ( typeof(suboptions[key]) != 'undefined' )
						subselector.options[index++] = new Option(suboptions[key], key);
				}
			}
			subselector.disabled = (subselector.options.length <= 1 ? true : false);
		}
	},	
	_wall_delete : function(wallId)
	{
		if ( typeof wallId == 'undefined' || wallId <= 0 )
			return false;

		if ( this._confirm('Сигурен ли си, че искаш да изтриеш това съобщение?', 'General._wall_delete(' + wallId + ');') == false )
			return false;

		$('loading').show();
		new Ajax.Request('ajax', {
						 parameters : {'section' : '_wall_delete', 'wallId' : wallId},
						 onComplete : function(res)
						 {
							General._success('Съобщението беше изтрито');
							new Insertion.Before('wall_post_' + wallId, '<div class="clear" style="background-color: #EFEFEF; height: 30px; line-height: 30px; text-align: center; margin-top: 10px;"><span>Съобщението е изтрито на ' + res.responseText + '</span></div>');
							$('wall_post_' + wallId).remove();
							$('loading').hide();
						 }
				});
		return false;
	},	
	_show_picture : function(el)
	{
		var src = el.getAttribute('src');
		src = src.replace(/_thumb_80/, '');
		$('picture_main').setAttribute('src', src);
	},	
	_show_picture_main : function()
	{
		var el = $('picture_main_container');
		
		if ( el.getStyle('position') == 'absolute' )
			el.setStyle({position : 'relative', zIndex : 1, overflow : 'hidden'});
		else		
			el.setStyle({position : 'absolute', zIndex : 5000, overflow : ''});
		
		return false;
	},	
	_badge_element_toggle : function(el, id)
	{
		var isChecked = el.checked;
		
		if ( isChecked == true )		
			$(id).show();
		else
			$(id).hide();
	},	
	_badge_change_theme : function(type, userId)
	{
		$$('div.badge_theme').each(function(el)
											{
												el.hide();
											});
		$('badge_' + type).show();
	},	
	_badge_toggle_element : function(element, el, id)
	{
		var _is_checked = el.checked;
		
		if ( _is_checked == true )
			$('badge_' + id + '_' + element).show();
		else
			$('badge_' + id + '_' + element).hide();
	},
	_is_enter : function(e)
	{
		  return General._get_key(e) == 13 ? true : false;
	},	
	_get_key : function(e)
	{
		var characterCode = '';
		if ( e && e.which )
		{           
			e = e;
			characterCode = e.which;
		}
		else 
		{
			e = event;
			characterCode = e.keyCode;
		}
	return characterCode;
	},
	_enable_city : function(el)
	{
		var checked =  el.checked ? true : false;
		
		var form = $('city_container');
		form[checked ? 'show' : 'hide']();
		
		var els = $('cityId');
		els[checked ? 'enable' : 'disable']();
	},
	_get_hots : function(gender, el, limit)
	{
		if ( typeof gender == 'undefined' || gender <= 0 || isNaN(gender) )
			gender = 2;
			
		if ( typeof limit == 'undefined' || isNaN(limit) )
			limit = -1;
		
		$('loading').show();
				
		new Ajax.Updater('hot_users', 'ajax', {
						 	parameters : {'section' : '_hot_users', 'gender' : gender, 'limit' : limit},
							evalScripts : true,
							onComplete : function()
							{
								$('loading').hide();
							}
						 });
		
	return false;
	},
	_get_active : function(gender, el, limit)
	{
		if ( typeof gender == 'undefined' || gender <= 0 || isNaN(gender) )
			gender = 1;
			
		if ( typeof limit == 'undefined' || isNaN(limit) )
			limit = -1;
		
		$('loading').show();
				
		new Ajax.Updater('active_users', 'ajax', {
						 	parameters : {'section' : '_active_users', 'gender' : gender, 'limit' : limit},
							evalScripts : true,
							onComplete : function()
							{
								$('loading').hide();
							}
						 });
		
	return false;
	},
	_show_status_update : function()
	{
		$('statusUpdateForm').show();
		$('statusValue').focus();
	},
	_key_press_status : function(e)
	{
		if ( General._is_enter(e) == false )
			return false;
			
		$('statusValue').blur();
	return false;
	},
	_update_status : function(value)
	{
		$('loading').show();
		if ( typeof value == 'undefined' )
			value = '';
			
		new Ajax.Request('ajax', {
						parameters : {'section' : '_update_status', 'status' : value},
						onComplete : function(response)
						{
							$('loading').hide();
						}
				});
	},
	_get_feeds : function(my, limit, position)
	{
		if ( typeof my == 'undefined' || my == false )
			my = '';
			
		if ( typeof limit == 'undefined' )
			limit = '';
			
		if ( typeof position == 'undefined' )
			position = 0;
		
		$('loading').show();
		new Ajax.Updater('news_feed_container', 'ajax', {
						 parameters : {'section' : '_news_feed', 'my' : my, 'limit' : limit, 'position' : position},
						 onComplete : function()
						 {
							$('loading').hide(); 
						 }
						 });
		return false;
	},
	_feed_action : function(el, toggleClass)
	{
		$('news_feed_' + parseInt(el)).toggleClassName(toggleClass);
	},
	_report_pic : function(picId, report)
	{
		if ( this._confirm('Сигурен ли си, че искаш да съобщиш за тази снимка?', 'General._report_pic(' + picId + ', ' + report + ');') == false )
			return false;
			
		var report_status = '';
			
		switch ( report )
		{
			case 1 :
				report_status = 'Неподходяща';
			break;
			case 2 :
				report_status = 'Повредена';
			break;
		}
			
		new Ajax.Request('ajax', {
						 parameters : {'section' : '_report_pic', 'picId' : parseInt(picId), 'report' : parseInt(report)},
						 onComplete : function()
						 {
							 General._success('Снимката беше маркирана като "' + report_status + '"');
						 }
					});
		return false;
	},
	_add_favorites : function(userId, profile)
	{
		if ( typeof userId == 'undefined' || userId <= 0 )
			return false;
			
		if ( typeof profile == 'undefined' )
			profile = false;
			
		$('loading').show();
		new Ajax.Request('ajax', {
						 parameters : {'section' : '_add_favorites', 'userId' : userId},
						 onComplete : function()
						 {
							 General._success('Потребителя е добавен към твоя списък с любими');
							 
							 if ( $('favorites_' + userId) )
							 {
							 	new Insertion.Before('favorites_' + userId, '<div id="favorites_remove_' + userId + '" style="display: inline;"><img src="i/icons/remove_favorite.gif" alt="" /> <a href="match?favorites=' + userId + '&amp;remove" onclick="General._remove_favorites(' + userId + ');event.returnValue = false;return false;">Mахни от любими</a></div>');
								$('favorites_' + userId).remove();
							 }
								
							 if ( $('favorites_2_' + userId) )
							 {
							 	if ( profile == false )
									new Insertion.Before('favorites_2_' + userId, '<div id="favorites_2_remove_' + userId + '" style="position: absolute; top: 270px; right: 35px; z-index: 100;"><div style="position: absolute; left: 10px; top: 0;"><img src="i/icons/remove_favorite_2.gif" alt="" /> <a href="match?favorites=' + userId + '&amp;remove" onclick="General._remove_favorites(' + userId + ');event.returnValue = false;return false;" style="color: #fff;">Mахни от любими</a></div><div style="background: #000; height: 20px; width: 150px; opacity: 0.40; filter: alpha(opacity=40);"></div></div>');								
								else
									new Insertion.Before('favorites_2_' + userId, '<div id="favorites_2_remove_' + userId + '" style="display: inline;"><img src="i/icons/remove_favorite.gif" alt="" /> <a href="match?favorites=' + userId + '&amp;remove" onclick="General._remove_favorites(' + userId + ', true);event.returnValue = false;return false;">Mахни от любими</a></div>');
									
								$('favorites_2_' + userId).remove();
							 }
								
							 $('loading').hide();
						 }
				});
		
	return false;
	},
	_remove_favorites : function(userId, profile)
	{
		if ( typeof userId == 'undefined' || userId <= 0 )
			return false;
			
		if ( typeof profile == 'undefined' )
			profile = false;
			
		$('loading').show();
		new Ajax.Request('ajax', {
						 parameters : {'section' : '_remove_favorites', 'userId' : userId},
						 onComplete : function()
						 {
							 General._success('Потребителя е премахнат от твоя списък с любими');
							 
							 if ( $('favorites_remove_' + userId) )
							 {
							 	new Insertion.Before('favorites_remove_' + userId, '<div id="favorites_' + userId + '" style="display: inline;"><img src="i/icons/add_favorite.gif" alt="" /> <a href="match?favorites=' + userId + '" onclick="General._add_favorites(' + userId + ');event.returnValue = false;return false;">Добави в любими</a></div>');
								$('favorites_remove_' + userId).remove();
							 }
								
							 if ( $('favorites_2_remove_' + userId) )
							 {
							 	if ( profile == false )
									new Insertion.Before('favorites_2_remove_' + userId, '<div id="favorites_2_' + userId + '" style="position: absolute; top: 270px; right: 35px; z-index: 100;"><div style="position: absolute; left: 10px; top: 0;"><img src="i/icons/add_favorite_2.gif" alt="" /> <a href="match?favorites=' + userId + '" onclick="General._add_favorites(' + userId + ');event.returnValue = false;return false;" style="color: #fff;">Добави в любими</a></div><div style="background: #000; height: 20px; width: 150px; opacity: 0.40; filter: alpha(opacity=40);"></div></div>');
								else
									new Insertion.Before('favorites_2_remove_' + userId, '<div id="favorites_2_' + userId + '" style="display: inline;"><img src="i/icons/add_favorite.gif" alt="" /> <a href="match?favorites=' + userId + '" onclick="General._add_favorites(' + userId + ', true);event.returnValue = false;return false;">Добави в любими</a></div>');
								$('favorites_2_remove_' + userId).remove();
							 }
								
							 $('loading').hide();
						 }
				});
		
	return false;
	},
	_block_user : function(userId)
	{
		if ( typeof userId == 'undefined' || userId <= 0 )
			return false;
			
		if ( this._confirm('Сигурен ли си, че искаш да блокираш този потребител?', 'General._block_user(' + userId + ');') == false )
			return false;
			
		$('loading').show();
		new Ajax.Request('ajax', {
						 parameters : {'section' : '_block_user', 'userId' : userId},
						 onComplete : function()
						 {
							 General._success('Потребителя е добавен в списъка с блокирани');
							 $('block_user').remove();
							 $('loading').hide();
						 }
				});
		
	return false;
	},
	_wall_check : function(form)
	{
		if ( ($('graffiti_text').value).blank() && (form.wall_msg.value).blank() )
		{
			General._error('Напиши текст към съобщението на стената или напиши графит.', 'wall_post_form', true);
			return false;	
		}
	return true;
	},
	_set_graffiti_font : function(name)
	{
		$('graffiti_font_input').value = name;
		$('graffiti_font_container').hide();		
		$('graffiti_set_font').update('<span>Текущ шрифт:</span> <img src="i/graffiti/' + name + '.gif" alt="' + name + '" />');
		
	},
	_graffiti_preview : function()
	{
		var font_color = $F('graffiti_color');
		var font = $F('graffiti_font_input');
		var text = $F('graffiti_text');
		
		if ( text.empty() )
		{
			General._error('Напиши текст към графита', 'graffiti_preview');
			return false;	
		}
		
		$('loading').show();
		new Ajax.Updater('graffiti_preview', 'ajax', {
						 parameters : {'section' : '_gen_graffiti', 'font_color' : font_color, 'font' : font, 'text' : text},
						 onComplete : function()
						 {
							 $('loading').hide();
						 }
				});
	return false;
	},
	_gen_custom_select : function(id, width, func, cclass)
	{
		if ( typeof _stop_custom_select != 'undefined' && _stop_custom_select == 1 )
			return false;
		
		if ( typeof el == 'string' )
            el = $(el);
		
		var el = $(id);
		el.hide();

		var _total_el = el.length;
		var _selected_i = el.selectedIndex;
		
		var _selected = el.options[_selected_i].text;
		var _selected_value = el.options[_selected_i].value;				
		
		if ( !_selected )
			_selected = el.options[0].text;
			
		func = func || '';
		cclass = cclass || '';
		
		width = parseInt(width);
        width = isNaN(width) ? 200 : width;
		
		var parent_div = new Element('div', {'id' : 'select_form_' + id + '', 'class' : 'select_container'});
		var left_img = new Element('img', {'src' : 'i/forms/input_left.gif', 'alt' : '', 'class' : 'left', 'width' : '6', 'height' : '22'});
		var first_div = new Element('div', {'class' : 'input left', 'style' : 'position: relative; width: ' + width + 'px;'});
		var first_ol = new Element('ol', {'id' : 'select_list_first_' + id + '', 'class' : 'select_list_first'});
		var first_ol_li = new Element('li', {'class' : 'nopadding', 'style' : 'width: ' + (width-21) + 'px;'});
		var first_ol_li_a = new Element('a', {'href' : 'javascript:void(0);', 'id' : 'first_' + id}).update(_selected);
		
		//var selected_ol = new Element('ol', {'id' : 'select_list_' + id + '', 'class' : 'select_list', 'style' : (_total_el > 5 && this._is_ie ? 'width: ' + (width-5) + 'px;' : '') + ' display: none; ' + (_total_el > 5 ? 'height: 100px;' : '') + ''});
		
		var selected_ol = new Element('ol', {'id' : 'select_list_' + id + '', 'class' : 'select_list', 'style' : (_total_el > 5 ? 'width: ' + (width+5) + 'px;' : 'width: ' + (width-11) + 'px;') + ' display: none; ' + (_total_el > 5 ? 'height: 100px;' : '') + ''});

		for ( var i = 0; i < el.length; i++ )
		{
			//var selected_ol_li_a = new Element('a', {'href' : 'javascript:void(0);', 'id' : 'href_' + id + '_' + i + '', 'style' : 'width: ' + (width-20-(_total_el > 5 ? (this._is_ie ? 12 : 15) : 5)) + 'px;"', 'class' : 'selected_list_a_' + id + (_selected_value == el.options[i].value ? ' select_list_selected' : '')}).update(el.options[i].text);
			
			var selected_ol_li_a = new Element('a', {'href' : 'javascript:void(0);', 'id' : 'href_' + id + '_' + i + '', 'style' : 'width: 100%;"', 'class' : 'selected_list_a_' + id + (_selected_value == el.options[i].value ? ' select_list_selected' : '')}).update(el.options[i].text);

			var selected_ol_li = new Element('li', {'class' : 'nopadding', 'style' : 'width: ' + (width - 20) + 'px;'});
			selected_ol_li.appendChild(selected_ol_li_a);
			selected_ol.appendChild(selected_ol_li);
		}
		
		var arrow_img = new Element('img', {'src' : 'i/icons/select_drop.gif', 'alt' : '', 'id' : 'arrow_image_' + id, 'class' : 'right', 'style' : 'cursor: pointer;'});
		var right_img = new Element('img', {'src' : 'i/forms/input_right.gif', 'alt' : '', 'class' : 'left', 'width' : '6', 'height' : '22'});
		
		first_ol_li.appendChild(first_ol_li_a);
		first_ol.appendChild(first_ol_li);				
		first_div.appendChild(first_ol);
		first_div.appendChild(selected_ol);
		first_div.appendChild(arrow_img);
		parent_div.appendChild(left_img);
		parent_div.appendChild(first_div);
		parent_div.appendChild(right_img);
				
		new Insertion.Before(id, parent_div);
		
		Event.observe('first_' + id, 'click', function(){General._show_custom_select('' + id + '');});
		Event.observe('arrow_image_' + id, 'click', function(){General._show_custom_select('' + id + '');});
		Event.observe('select_list_' + id, 'mouseover', function(){$('select_list_' + id).show();});
		Event.observe('select_list_' + id, 'mouseout', function(){$('select_list_' + id).hide();});
		
		$$('a.selected_list_a_' + id).each(function(el)
		{
			Event.observe(el, 'click', function()
				{ 
					var i = (el.id).toString().split('_');
					var i_l = i.length;
					General._select_custom_select(i[(i_l - 1)], '' + id + '', '' + func + '', '' + cclass + '');
				});
		});
	return false;
	},
	_select_custom_select : function(selected, id, func, cclass)
	{
		
		var el = $(id);
		$('first_' + id).update(el.options[selected].text);
		
		var hide = 'select_list_' + id;
		
		el.options[selected].selected = "selected";
		
		if ( typeof cclass == 'undefined' || cclass == '' )
			cclass = 'General';

		if ( typeof func != 'undefined' && func != '' )
			eval(cclass + '.' + func + '(\'' + id + '\')');
		
		var els = $$('#select_form_' + id + ' li.nopadding a');		
		els.each(function(elss)
						  {
								if ( elss.hasClassName('select_list_selected') )
									elss.removeClassName('select_list_selected');
						  });
		
		$('href_' + id + '_' + selected).addClassName('select_list_selected');
		General._hide_custom_select(hide);
	},
	_show_custom_select : function(id)
	{
		var els = $$('div ol.select_list');
		var elss = $(id);
		_total_el = elss.length;
		var show = 'select_list_' + id;
		
		els.each(function(el)
						  {
								if ( el.visible() && el.id != show )
									el.hide();
						  });
		$(show).toggle();
		
		if ( _total_el > 5 )
		{
			_selected_i = elss.selectedIndex;
			
			if ( _selected_i > 4 )
				$(show).scrollTop = ((_selected_i - 2) * 20);			
		}
	},
	_hide_custom_select : function(hide)
	{
		$(hide).hide();
	},
	_profile_manage_cities : function(el)
	{
		if ( typeof el == 'string' )
			el = $(el);
			
		if ( el.options[el.selectedIndex].value == 0 )
		{
			$('profile_city_list', 'profile_other_city').invoke('hide');
			$('profileCity').options[0].selected = 'selected';
			$('profileOtherCityName').value = '';
		}
		else if ( el.options[el.selectedIndex].value == 1 )
		{
			$('profile_city_list').show();
			$('profile_other_city').hide();
			$('profileCity').options[0].selected = 'selected';
			$('profileOtherCityName').value = '';
		}
		else
		{
			$('profile_city_list').hide();
			$('profile_other_city').show();
			$('profileCity').options[0].selected = 'selected';
			$('profileOtherCityName').value = '';
		}
	},
	_profile_manage_custom_city : function(el)
	{
		if ( typeof el == 'string' )
			el = $(el);
		
		if ( el.options[el.selectedIndex].value != 139 )
			$('profile_other_city').hide();
		else
		{
			$('profile_other_city').show();			
		}
		$('profileOtherCityName').value = '';
	},
	_search_friends : function(userId)
	{
		if ( typeof userId == 'undefined' )
			return false;
			
		if ( typeof General._friend_list == 'undefined' )
		{
			new Ajax.Request('ajax', {
							 	parameters : {'section' : '_search_friends', 'userId' : userId},
								onComplete : function(response)
								{
									General._friend_list = (response.responseText).evalJSON();
								}
							 });
		}
	return false;
	},
	_search_suggestion : function(el)
	{		
		var value = (el.value).stripTags();
		
		$('headerSearch').observe('blur', function(e){setTimeout(function(){$('search_suggestion').hide();}, 500);});
		
		if ( typeof General._friend_list == 'undefined' )
			return false;
		
		if ( value.length < 2 )
		{
			if ( $('suggestions_list_search') )
				$('suggestions_list_search').remove();
				
			$('search_suggestion').show().update('<span style="padding-left: 15px;">Напиши потребител</span>');
		return false;
		}
		
		var ol = new Element('ol',{ 'id' : 'suggestions_list_search'});
		$('search_suggestion').update(ol);
		_search_founded = [];
		var _t = 0;

			for ( var j = 0; j < General._friend_list.length; j++ )
			{
				if ( ((General._friend_list[j].username).toLowerCase()).lastIndexOf(value.toLowerCase()) != -1 || ((General._friend_list[j].fullname).toLowerCase()).lastIndexOf(value.toLowerCase()) != -1 )
				{
					var user = ((General._friend_list[j].fullname).length > 0 ? General._friend_list[j].fullname : General._friend_list[j].username);
					_search_founded.push(user);
					var userFullname = General._friend_list[j].fullname;
					var userName = General._friend_list[j].username;
					var city = General._friend_list[j].city;
					var age = General._friend_list[j].age;
					var userId = General._friend_list[j].userId;
					
					userFullname = userFullname.replace(new RegExp(value, 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});
					userName = userName.replace(new RegExp(value, 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});

					var li = new Element('li', {'class' : 'nomargin'});
					var a_href = new Element('a', {'href' : 'profile?id=' + General._friend_list[j].userId, 'class' : 'inbox_found_href', 'style' : 'padding-left: 5px;'}).update(userFullname + '<br />' + userName + (city != '' ? ', гр. ' + city : '') + ', ' + age + ' г.');
					li.appendChild(a_href);
					_t += 1;
					
					if ( _t > 5 )
					{
						$('search_suggestion').setStyle({'height' : '185px', 'overflow' : 'auto'});
						$('suggestions_list_search').setStyle({'width' : '150px'});
					}
					else
					{
						$('search_suggestion').setStyle({'height' : 'auto', 'overflow' : 'hidden'});
						$('suggestions_list_search').setStyle({'width' : 'auto'});
					}
					
					new Insertion.Bottom('suggestions_list_search', li);
					$('search_suggestion').show();
				}
			}	

		if ( _search_founded.length == 0 )
			$('search_suggestion').hide();
	return false;
	},
	_delete_profile : function()
	{
		if ( this._confirm('Сигурен ли си, че искаш да изтриеш профила?', '$(\'account_delete\').submit();') == false )
			return false;
			
		return true;
	},
	_select_action_set_to_default : function()
	{
		$('select_action').selectedIndex = 0;
		$('first_select_action').update('-- Избери --');
		//$A($('select_list_select_action').getElementsByTagName('a')).each(function(el){el.removeClassName('select_list_selected');});
		//$('href_select_action_0').addClassName('select_list_selected');
	},
	_disable_balon : function()
	{
		new Ajax.Request('ajax', {
						 	parameters : {'section' : '_disable_balon'},
							onComplete : function()
							{
								$$('div.balon_container:not(.stop_disable)').each(function(el){	
														el.remove();
														});
							}
						 });
	return false;
	},
	_toggle_profile_visits : function(visible)
	{
		new Ajax.Updater('profile_visits_container', 'ajax', {
						parameters : {'section' : '_toggle_profile_visits', 'visible' : visible},
						evalScripts : true
						 });
		return false;
	},
	_poke : function(userId, pokeId)
	{
		if ( typeof pokeId == 'undefined' )
			pokeId = 0;

		if ( this._confirm('Сигурен ли си, че искаш да щипнеш потребителя?', 'General._poke(' + userId + ', ' + pokeId + ');') == false )
			return false;
		
		new Ajax.Request('ajax', {
						 	parameters : {'section' : '_poke', 'userId' : userId},
							onComplete : function()
							{
								if ( $('poke') )
									$('poke').remove();
									
								if ( $('poke_' + pokeId) )
									$('poke_' + pokeId).remove();									
								
								if ( $('main_updates') && $$('li.poke_li').length > 0 )
									$$('li.poke_li').last().setStyle({'border' : 'none', 'paddingBottom' : '0', 'marginBottom' : '0'});
								
								if ( $('main_updates') && $$('li.poke_li').length == 0 )
								{
									if ( $$('li.main_updates_li').length == 0 )
										$('main_updates_container').remove();
									else
										$('poke_title').remove();
								}
							}
						 });
	return false;
	},
	_remove_poke : function(pokeId)
	{
		new Ajax.Request('ajax', {
						 	parameters : {'section' : '_remove_poke', 'pokeId' : pokeId},
							onComplete : function()
							{
								$('poke_' + pokeId).remove();
								
								if ( $('main_updates') && $$('li.poke_li').length > 0 )
									$$('li.poke_li').last().setStyle({'border' : 'none', 'paddingBottom' : '0', 'marginBottom' : '0'});
								
								if ( $('main_updates') && $$('li.poke_li').length == 0 )
								{
									if ( $$('li.main_updates_li').length == 0 )
										$('main_updates_container').remove();
									else
										$('poke_title').remove();
								}
							}
						 });
	return false;
	},
	_emo_observe : function(el_c, el)
	{
		Event.observe(el_c, 'click', function(){General._show_emo_container(el);});
	},
	_hide_emo_container : function(el)
	{
		$(el).hide();
		$('smiley_container').setStyle({'width' : '100px'});
	},
	_show_emo_container : function(el)
	{
		$('smiley_container').setStyle({'width' : '100%'});
		$(el).show();
	},
	_show_emo_text : function(el, hide)
	{
		emo_id = el.id;
		if ( typeof hide != 'undefined' && hide == true )
			$(el.id + '_tooltip').hide();
		else
			$(el.id + '_tooltip').show();
	},
	_set_smiley : function(form, smile)
	{
		$(form).value += smile + ' ';

		$('smiley').hide();
		$('emo_text').hide();
		
		if ( typeof emo_id != 'undefined' )
			$(emo_id + '_tooltip').hide();
	},
	_pickup_contact_user : function(el)
	{
		if ( typeof el == 'string' )
			el = $(el);
		
		var status = el.value;
		var id = el.id;		
		var container = id + 'Container';
		
		if ( status == 0 || status == 1 )
		{
			$(container).hide();			
		}
		else
		{
			$(container).show();	
			
		}
		
		$('profileContactStatusWith').update('с');
		
		if ( this._in_array(new Array(3,4), status) )
			$('profileContactStatusWith').update('за');
	},
	_pickup_contact_user_set : function(e)
	{
		var el = Event.element(e).id;
		var _id = el.split('_');
		var userId = _id[1];
		var userName = '';
						
		for ( var i = 0; i < General._friend_list.length; i++ )
		{
			if ( General._friend_list[i].userId == userId )
			{
				var userFullname = General._friend_list[i].fullname;
				var userName = General._friend_list[i].username;						
				var userName = ((userFullname).length > 0 ? userFullname : userName);
			}
		}
			
		$('profileContactStatusUserId').value = userId;
		$('_profile_contact_users').value = userName;
		
		$('profile_suggestion').hide();
		
		if ( $('suggestions_list') )
			$('suggestions_list').remove();
			
		General._search_founded = [];
	},
	_profile_suggestion : function(el)
	{		
		var value = (el.value).stripTags();
		
		$('_profile_contact_users').observe('blur', function(e){setTimeout(function(){$('profile_suggestion').hide();}, 500);});
		
		if ( typeof General._friend_list == 'undefined' )
			return false;
		
		if ( value.length < 2 )
		{
			if ( $('suggestions_list_profile') )
				$('suggestions_list_profile').remove();
				
			$('profile_suggestion').show().update('<span style="padding-left: 15px;">Напиши потребител</span>');
		return false;
		}
		
		var ol = new Element('ol',{ 'id' : 'suggestions_list_profile', 'class' : 'nopadding nomargin'});
		$('profile_suggestion').update(ol);
		General._search_founded = [];
		var _t = 0;
		var user = '';
		var userId = '';
		$('profileContactStatusUserId').value = '';
					
			for ( var j = 0; j < General._friend_list.length; j++ )
			{
				if ( ((General._friend_list[j].username).toLowerCase()).lastIndexOf(value.toLowerCase()) != -1 || ((General._friend_list[j].fullname).toLowerCase()).lastIndexOf(value.toLowerCase()) != -1 )
				{
					user = ((General._friend_list[j].fullname).length > 0 ? General._friend_list[j].fullname : General._friend_list[j].username);
					
					if ( typeof General._search_founded[0] == 'undefined' )
						General._search_founded = [{'userId' : userId, 'user' : user}];
						
					var userFullname = General._friend_list[j].fullname;
					var userName = General._friend_list[j].username;
					var city = General._friend_list[j].city;
					var age = General._friend_list[j].age;
					userId = General._friend_list[j].userId;
					
					userFullname = userFullname.replace(new RegExp(value, 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});
					userName = userName.replace(new RegExp(value, 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});

					var li = new Element('li', {'class' : 'nomargin'});
					var a_href = new Element('a', {'href' : 'javascript:void(0)', 'class' : 'inbox_found_href', 'style' : 'padding-left: 5px;', 'id' : 'profileusers_' + userId}).update(userFullname + '<br />' + userName + (city != '' ? ', гр. ' + city : '') + ', ' + age + ' г.').observe('click', function(e){General._pickup_contact_user_set(e);});
					li.appendChild(a_href);
					_t += 1;
					
					if ( _t > 5 )
					{
						$('profile_suggestion').setStyle({'height' : '185px', 'overflow' : 'auto'});
						$('suggestions_list_profile').setStyle({'width' : '150px'});
					}
					else
					{
						$('profile_suggestion').setStyle({'height' : 'auto', 'overflow' : 'hidden'});
						$('suggestions_list_profile').setStyle({'width' : 'auto'});
					}
					
					new Insertion.Bottom('suggestions_list_profile', li);
					$('profile_suggestion').show();
				}
			}

	if ( General._search_founded.length == 0 )
		$('profile_suggestion').hide();
	return false;
	},
	_search_other_city : function(el)
	{
		if ( typeof el == 'string' )
			el = $(el);
			
		if ( el.value != 139 )
		{
			$('otherCity').hide();
			$('city').value = '';
		return false;
		}
			
		$('otherCity').show();

		if ( typeof General._city_list == 'undefined' )
		{
			new Ajax.Request('ajax', {
							 	parameters : {'section' : '_search_city_other'},
								onComplete : function(response)
								{
									General._city_list = (response.responseText).evalJSON();
								}
							 });
		}
	return false;
	},
	_search_other_city_set : function(e)
	{
		var el = Event.element(e).id;
		var _id = el.split('_');
		var id = _id[1];
		var city = '';
						
		for ( var i = 0; i < General._city_list.length; i++ )
		{
			if ( General._city_list[i].id == id )
			{
				var city = General._city_list[i].city;				
			}
		}
			
		$('city').value = city;
				
		$('other_city_suggestion').hide();
		
		if ( $('other_city_suggestions_list') )
			$('other_city_suggestions_list').remove();
			
		General._city_founded = [];
	},
	_search_other_city_suggestion : function(el)
	{
		var value = (el.value).stripTags();
		
		$('city').observe('blur', function(e){setTimeout(function(){$('other_city_suggestion').hide();}, 500);});
		
		if ( value.length < 2 )
		{
			if ( $('other_city_suggestions_list') )
				$('other_city_suggestions_list').remove();
				
			$('other_city_suggestion').show().update('<span style="padding-left: 15px;">Напиши град</span>');
		return false;
		}
		
		var ol = new Element('ol',{ 'id' : 'other_city_suggestions_list', 'class' : 'nopadding nomargin'});
		$('other_city_suggestion').update(ol);
		General._city_founded = [];
		var _t = 0;

			for ( var j = 0; j < General._city_list.length; j++ )
			{
				if ( ((General._city_list[j].city).toLowerCase()).lastIndexOf(value.toLowerCase()) != -1 )
				{						
					var city = General._city_list[j].city;
					var id = General._city_list[j].id;
					
					if ( typeof General._city_founded[0] == 'undefined' )
						General._city_founded = [{'id' : id, 'city' : city}];
											
					city = city.replace(new RegExp(value, 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});

					var li = new Element('li', {'class' : 'nomargin'});
					var a_href = new Element('a', {'href' : 'javascript:void(0)', 'class' : 'inbox_found_href', 'style' : 'padding-left: 5px;', 'id' : 'othercities_' + id}).update(city).observe('click', function(e){General._search_other_city_set(e);});
					li.appendChild(a_href);
					_t += 1;
					
					if ( _t > 5 )
					{
						$('other_city_suggestion').setStyle({'height' : '185px', 'overflow' : 'auto'});
						$('other_city_suggestions_list').setStyle({'width' : '150px'});
					}
					else
					{
						$('other_city_suggestion').setStyle({'height' : 'auto', 'overflow' : 'hidden'});
						$('other_city_suggestions_list').setStyle({'width' : 'auto'});
					}
					
					new Insertion.Bottom('other_city_suggestions_list', li);
					$('other_city_suggestion').show();
				}
			}	
				
	if ( General._city_founded.length == 0 )
		$('other_city_suggestion').hide();
	return false;
	},
	_scroll_to : function(last_message, form_element)
	{
		if( !last_message || !form_element )
			return false;
		
		var _begin_top = form_element.cumulativeScrollOffset()[1];
		var _duration = 600;
		var _start_time = (new Date()).getTime();
		var _last_top = null;
		var _interval_scroll = '';
		
		_interval_scroll = window.setInterval(function(){			
			var _window_height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
			var _last_msg_height = form_element.cumulativeOffset()[1] + form_element.offsetHeight;			
			var _form_height = last_message.cumulativeOffset()[1] - 100;
	
				if ( _last_msg_height-_form_height < _window_height )
				{
					_form_height -= (_window_height+_form_height)-_last_msg_height;
				}
				if ( _last_msg_height < _window_height+100 )
				{
					window.clearInterval(_interval_scroll);
					_interval_scroll = '';
				}
			var _time = (new Date()).getTime();
			var _scroll = null;
			var _current_top = form_element.cumulativeScrollOffset()[1];
			
			var _p = (_time-_start_time)/_duration;
			
				if ( _p > 1 )	
				{		
					_scroll = _form_height;
					window.clearInterval(_interval_scroll);
					_interval_scroll = '';
				}			
				else
				{
					if ( _p <= 0.5 )
						_fp = (_p * _p) * 2;
					else
					{
						_p -= 1; 
						_fp = (_p * _p) * - 2 + 1;
					}
					_scroll = parseInt((_form_height-_begin_top) * _fp + _begin_top);
				}
				if ( _last_top && _current_top != _last_top && _current_top != 0 )
				{
					window.clearInterval(_interval_scroll);
					_interval_scroll = '';
				}
				else
				{
					window.scrollBy(0, (_scroll-_current_top));
					_last_top = _scroll;
				}
		}, 25);
	return false;
	},
	
	_ajax_school_edu : function(el)
	{
		new Ajax.Request('ajax', {
			parameters : el,
			onComplete : function()
			{
				General._cancel_work_edu();
			}
		});
	},
	
	_more_schools : function()
	{
		var total = $$('ol.userEducationsVisible').length;
		var next = total + 1;
		
		var totalEl = $$('ol.userEducations').length;
		
		if ( totalEl == next )
			$('userEducationRemoveSchool').hide();
		else
			$('userEducationRemoveSchool').show();

		if ( $('select_form_userEducationType' + next) == null )
		{
			General._gen_custom_select('userEducationType' + next, 120);
			General._gen_custom_select('userEducationYearFrom' + next, 80);
			General._gen_custom_select('userEducationYearTo' + next, 80);
		}
		
		$('userEducationContainer' + next).addClassName('userEducationsVisible').show();
	},
	
	_remove_more_schools : function(number)
	{
		if ( General._confirm('Сигурен ли си, че искаш да премахнеш училището?', 'General._remove_more_schools(' + number + ');') == false )
			return false;
		
		var total = $$('ol.userEducationsVisible').length;	
		var next = total + 1;
		
		var totalEl = $$('ol.userEducations').length;
		
		if ( totalEl == next )
			$('userEducationRemoveSchool').hide();
		else
			$('userEducationRemoveSchool').show();
		
		if ( number > 1 )
			$('userEducationContainer' + number).removeClassName('userEducationsVisible').hide();
		else
			$('userEducationRemove' + number).hide();
		
		$('userEducation' + number).value = '';
		$('userEducationType' + number).selectedIndex = 0;
		$('userEducationSubject' + number).value = '';
		$('userEducationYearFrom' + number).selectedIndex = 0;
		$('userEducationYearTo' + number).selectedIndex = 0;
		$('userEducationPresent' + number).checked = false;
		General._school_present($('userEducationPresent' + number), number);
		
		document.forms['educationForm'].submit();
	return false;
	},
	
	_school_present : function(el, number)
	{
		var checked = el.checked;
		
		if ( checked == true )
			$('userEducationToContainer' + number).hide();
		else
			$('userEducationToContainer' + number).show();
	},
	
	_suggest_school : function(el, number)
	{
		
		$('userEducation' + number).observe('blur', function(e){var element = Event.element(e); var id = element.id; var _ids = id.split('userEducation'); setTimeout(function(){$('school_suggestion_' + _ids[1]).hide();}, 500);});
		
		if ( el.value.length < 2 )
		{
			//$('school_suggestion_' + number).hide();
			if ( $('school_suggestions_list_' + number) )
				$('school_suggestions_list_' + number).remove();
				
			$('school_suggestion_' + number).show().update('<span style="padding-left: 15px;">Напиши името на училището</span>');
				
		return false;
		}
		
		_schoolFounded = [];
		new Ajax.Request('ajax', {
			parameters : {'section' : '_suggest_school', 'school' : el.value},
			onComplete : function(response)
			{
				var json = (response.responseText).evalJSON();
				
				var ol = new Element('ol',{ 'id' : 'school_suggestions_list_' + number});
				$('school_suggestion_' + number).update(ol);
				var _t = 0;
				for ( var j = 0; j < json.length; j++ )
				{
					var schoolName = json[j].schoolName;
					_schoolFounded.push(schoolName);
					
					schoolName = schoolName.replace(new RegExp(el.value, 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});
					schoolName = schoolName.replace(new RegExp(General._translate(el.value), 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});
					
					var li = new Element('li', {'class' : 'nomargin'});
					var a_href = new Element('a', {'href' : 'javascript:void(0);', 'class' : 'inbox_found_href', 'id' : 'shoolNumber_' + number + '_' + j}).update(schoolName).observe('click', function(e){var element = Event.element(e); var id = element.id; var _ids = id.split('_'); $('userEducation' + _ids[1] + '').value = '' + _schoolFounded[_ids[2]].unescapeHTML() + '';$('school_suggestion_' + number).hide();});
					li.appendChild(a_href);
					_t += 1;
					
					if ( _t > 5 )
					{
						$('school_suggestion_' + number).setStyle({'height' : '185px', 'overflow' : 'auto'});
						$('school_suggestions_list_' + number).setStyle({'width' : '218px'});
					}
					else
					{
						$('school_suggestion_' + number).setStyle({'height' : 'auto', 'overflow' : 'hidden'});
						$('school_suggestions_list_' + number).setStyle({'width' : 'auto'});
					}
					
					new Insertion.Bottom('school_suggestions_list_' + number, li);
					$('school_suggestion_' + number).show();
				}
				
			if ( json.length == 0 )
				$('school_suggestion_' + number).hide();
			}
		});
	return false;
	},
	
	_suggest_school_subject : function(el, number)
	{
		$('userEducationSubject' + number).observe('blur', function(e){var element = Event.element(e); var id = element.id; var _ids = id.split('userEducationSubject'); setTimeout(function(){$('subject_suggestion_' + _ids[1]).hide();}, 500);});
		
		if ( el.value.length < 2 )
		{
			//$('subject_suggestion_' + number).hide();
			
			if ( $('school_subject_suggestions_list_' + number) )
				$('school_subject_suggestions_list_' + number).remove();
				
			$('subject_suggestion_' + number).show().update('<span style="padding-left: 15px;">Напиши името на твоята специалност</span>');
			
			return false;
		}
		_schoolSubjectFounded = [];
		
		new Ajax.Request('ajax', {
			parameters : {'section' : '_suggest_school_subject', 'schoolSubject' : el.value},
			onComplete : function(response)
			{
				var json = (response.responseText).evalJSON();
				
				var ol = new Element('ol',{ 'id' : 'school_subject_suggestions_list_' + number});
				$('subject_suggestion_' + number).update(ol);
				var _t = 0;
				for ( var j = 0; j < json.length; j++ )
				{
					var schoolSubject = json[j].schoolSubject;
					_schoolSubjectFounded.push(schoolSubject);
					
					schoolSubject = schoolSubject.replace(new RegExp(el.value, 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});
					schoolSubject = schoolSubject.replace(new RegExp(General._translate(el.value), 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});
					
					var li = new Element('li', {'class' : 'nomargin'});
					var a_href = new Element('a', {'href' : 'javascript:void(0);', 'class' : 'inbox_found_href', 'id' : 'shoolSubjectNumber_' + number + '_' + j}).update(schoolSubject).observe('click', function(e){var element = Event.element(e); var id = element.id; var _ids = id.split('_'); $('userEducationSubject' + _ids[1] + '').value = '' + _schoolSubjectFounded[_ids[2]].unescapeHTML() + '';$('subject_suggestion_' + number).hide();});
					li.appendChild(a_href);
					_t += 1;
					
					if ( _t > 5 )
					{
						$('subject_suggestion_' + number).setStyle({'height' : '185px', 'overflow' : 'auto'});
						$('school_subject_suggestions_list_' + number).setStyle({'width' : '218px'});
					}
					else
					{
						$('subject_suggestion_' + number).setStyle({'height' : 'auto', 'overflow' : 'hidden'});
						$('school_subject_suggestions_list_' + number).setStyle({'width' : 'auto'});
					}
					
					new Insertion.Bottom('school_subject_suggestions_list_' + number, li);
					$('subject_suggestion_' + number).show();
				}
				
			if ( json.length == 0 )
				$('subject_suggestion_' + number).hide();
			}
		});
	return false;
	},

	_more_work : function()
	{
		var total = $$('ol.userWorksVisible').length;
		var next = total + 1;
		
		var totalEl = $$('ol.userWorks').length;
		
		if ( totalEl == next )
			$('userWorkRemoveCompany').hide();
		else
			$('userWorkRemoveCompany').show();

		if ( $('select_form_userWorkMonthFrom' + next) == null )
		{
			General._gen_custom_select('userWorkMonthFrom' + next, 80);
			General._gen_custom_select('userWorkMonthTo' + next, 80);
			General._gen_custom_select('userWorkYearFrom' + next, 80);
			General._gen_custom_select('userWorkYearTo' + next, 80);
		}
		
		$('userWorkContainer' + next).addClassName('userWorksVisible').show();
	},
	
	_remove_more_work : function(number)
	{
		if ( General._confirm('Сигурен ли си, че искаш да премахнеш работата?', 'General._remove_more_work(' + number + ');') == false )
			return false;
		
		var total = $$('ol.userWorksVisible').length;	
		var next = total + 1;
		
		var totalEl = $$('ol.userWorks').length;
		
		if ( totalEl == next )
			$('userWorkRemoveCompany').hide();
		else
			$('userWorkRemoveCompany').show();
		
		if ( number > 1 )
			$('userWorkContainer' + number).removeClassName('userWorksVisible').hide();
		else
			$('userWorkRemove' + number).hide();
		
		$('userWork' + number).value = '';
		$('userWorkDescription' + number).value = '';
		$('userWorkBranch' + number).value = '';
		$('userWorkPosition' + number).value = '';
		
		$('userWorkMonthFrom' + number).selectedIndex = 0;
		$('userWorkMonthTo' + number).selectedIndex = 0;
		$('userWorkYearFrom' + number).selectedIndex = 0;
		$('userWorkYearTo' + number).selectedIndex = 0;
		$('userWorkPresent' + number).checked = false;
		General._work_present($('userWorkPresent' + number), number);
		
		document.forms['workForm'].submit();
	return false;
	},
	
	_work_present : function(el, number)
	{
		var checked = el.checked;
		
		if ( checked == true )
			$('userWorkToContainer' + number).hide();
		else
			$('userWorkToContainer' + number).show();
	},
	
	_suggest_work : function(el, number)
	{
		$('userWork' + number).observe('blur', function(e){var element = Event.element(e); var id = element.id; var _ids = id.split('userWork'); setTimeout(function(){$('work_suggestion_' + _ids[1]).hide();}, 500);});
		
		if ( el.value.length < 2 )
		{
			//$('work_suggestion_' + number).hide();
			
			if ( $('work_suggestions_list_' + number) )
				$('work_suggestions_list_' + number).remove();
				
			$('work_suggestion_' + number).show().update('<span style="padding-left: 15px;">Напиши името на фирмата</span>');
			
			return false;
		}
		
		_workFounded = [];
		new Ajax.Request('ajax', {
			parameters : {'section' : '_suggest_work', 'companyName' : el.value},
			onComplete : function(response)
			{
				var json = (response.responseText).evalJSON();
				
				var ol = new Element('ol',{ 'id' : 'work_suggestions_list_' + number});
				$('work_suggestion_' + number).update(ol);
				var _t = 0;
				for ( var j = 0; j < json.length; j++ )
				{
					var companyName = json[j].companyName;
					_workFounded.push(companyName);
					
					companyName = companyName.replace(new RegExp(el.value, 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});
					
					companyName = companyName.replace(new RegExp(General._translate(el.value), 'gi'), function(found){return '<em style="font-size: 11px !important; background-color: #ECF2F9;">' + found + '</em>'});
					
					var li = new Element('li', {'class' : 'nomargin'});
					var a_href = new Element('a', {'href' : 'javascript:void(0);', 'class' : 'inbox_found_href', 'id' : 'workNumber_' + number + '_' + j}).update(companyName).observe('click', function(e){var element = Event.element(e); var id = element.id; var _ids = id.split('_'); $('userWork' + _ids[1] + '').value = '' + _workFounded[_ids[2]].unescapeHTML() + '';$('work_suggestion_' + number).hide();});;
					li.appendChild(a_href);
					_t += 1;
					
					if ( _t > 5 )
					{
						$('work_suggestion_' + number).setStyle({'height' : '185px', 'overflow' : 'auto'});
						$('work_suggestions_list_' + number).setStyle({'width' : '218px'});
					}
					else
					{
						$('work_suggestion_' + number).setStyle({'height' : 'auto', 'overflow' : 'hidden'});
						$('work_suggestions_list_' + number).setStyle({'width' : 'auto'});
					}
					
					new Insertion.Bottom('work_suggestions_list_' + number, li);
					$('work_suggestion_' + number).show();
				}
				
			if ( json.length == 0 )
				$('work_suggestion_' + number).hide();
			}
		});
	return false;
	},
	
	_cancel_work_edu : function()
	{
		this._create_cookie('schoolClosed', 'yes', 1);
		this._create_cookie('workClosed', 'yes', 1);

		$('workEduContainer').remove();
	},
	_translate : function(text)
	{
		var cyrMap = new Array();
		cyrMap['а'] = 'a'
		cyrMap['б'] = 'b'
		cyrMap['в'] = 'w'
		cyrMap['г'] = 'g'
		cyrMap['д'] = 'd'
		cyrMap['е'] = 'e'
		cyrMap['ж'] = 'v'
		cyrMap['з'] = 'z'
		cyrMap['и'] = 'i'
		cyrMap['й'] = 'j'
		cyrMap['к'] = 'k'
		cyrMap['л'] = 'l'
		cyrMap['м'] = 'm'
		cyrMap['н'] = 'n'
		cyrMap['о'] = 'o'
		cyrMap['п'] = 'p'
		cyrMap['р'] = 'r'
		cyrMap['с'] = 's'
		cyrMap['т'] = 't'
		cyrMap['у'] = 'u'
		cyrMap['ф'] = 'f'
		cyrMap['х'] = 'h'
		cyrMap['ц'] = 'c'
		cyrMap['ч'] = 'ch'
		cyrMap['ш'] = 'sh'
		cyrMap['щ'] = 'sht'
		cyrMap['ъ'] = 'y'
		cyrMap['ь'] = 'jo'
		cyrMap['ю'] = 'ju'
		cyrMap['я'] = 'ja'
		
		var latMap = new Array();
		latMap['a'] = 'а'
		latMap['b'] = 'б'
		latMap['w'] = 'в'
		latMap['g'] = 'г'
		latMap['d'] = 'д'
		latMap['e'] = 'е'
		latMap['v'] = 'ж'
		latMap['z'] = 'з'
		latMap['i'] = 'и'
		latMap['j'] = 'й'
		latMap['k'] = 'к'
		latMap['l'] = 'л'
		latMap['m'] = 'м'
		latMap['n'] = 'н'
		latMap['o'] = 'о'
		latMap['p'] = 'п'
		latMap['r'] = 'р'
		latMap['s'] = 'с'
		latMap['t'] = 'т'
		latMap['u'] = 'у'
		latMap['f'] = 'ф'
		latMap['h'] = 'х'
		latMap['c'] = 'ц'
		latMap['ch'] = 'ч'
		latMap['sh'] = 'ш'
		latMap['sht'] = 'щ'
		latMap['y'] = 'ъ'
		latMap['jo'] = 'ь'
		latMap['ju'] = 'ю'
		latMap['ja'] = 'я'
		
		var pos = 0;
		var finalText = "";
		var textLength = text.length;
                var finalChar;
		
		if ( textLength > 0 )
		{
			while ( pos < textLength )
			{
				var charSymbol = text.charAt(pos);
				var lowerChar = charSymbol.toLowerCase();
								
				if ( typeof cyrMap[lowerChar] != 'undefined' )
				{
					finalChar = cyrMap[lowerChar];
					
					if ( charSymbol != lowerChar )
						finalChar.toUpperCase();
						
					finalText += finalChar;
				}
				else if ( typeof latMap[lowerChar] != 'undefined' )
				{
					finalChar = latMap[lowerChar];
					
					if ( charSymbol != lowerChar )
						finalChar.toUpperCase();
						
					finalText += finalChar;
				}
				else
					finalText += charSymbol;
			pos++;
			}			
			
		return finalText;
		}
		else
			return '';
	},
	
	_post_video : function(id)
	{
		$$('div.postVideo').each(function(el){el.hide();});
		$(id).show();
	},
	
	_slide_bar : function(ids, currentPercent)
    {		
		var speed = 30;
		var divIdWidth = ids.split(':');
		var id = $(ids);
		id.show();
				
			if ( divIdWidth[1] == 0 )
				return;
				 
		currentPercent = ((currentPercent/1) + 1) ;						 
		var calc = Math.round( currentPercent / 100*divIdWidth[1] );
		
		id.setStyle({width : calc + 'px'});
		
		if ( currentPercent < 100 ) 
		{
			t = setTimeout( 'General._slide_bar("' + ids + '", ' + currentPercent + ')', speed) ;			
		}
		else
		{
			clearTimeout(t);
		}
    },
	
	_hide_profile : function(el)
	{
		var v = el.name;
		
		if ( v == 0 )
			el.name = 1;
		else
			el.name = 0;
		
		new Ajax.Request('ajax', {
			parameters : {'section' : '_hide_profile', 'v' : v},
			onComplete : function(res)
			{
				el.update(res.responseText);	
			}
		});	
	}
}

// End General Functions

var Favorites = {
	_change_status : function(el)
	{
		if ( typeof el == 'string' )
			el = $(el);
		
		var status = el.value;
				
		if ( status == "none" )
			return false;
			
		$('loading').show();
		
		var li = $$('div.favorites');
		
		if ( status == "" || status == "all" )
		{
			li.each(function(el)
				{
					el.getElementsByTagName('input')[0].checked = (status == "all") ?  true : false;
				}
			);
		}
		else
		{		
			li.each(function(el)
					{
						el.getElementsByTagName('input')[0].checked = el.className.indexOf(status) != -1 ?  true : false;
					}
			);
		}
		Favorites._status_buttons();
		
		if ( status == "" )
			$('select_action').selectedIndex = 0;
		
		$('loading').hide();
	return false;
	},
	_action : function(action, el)
	{
		if ( el.indexOf('menu_disabled') != -1 )
			return false;
		
		if ( action == 'delete' && General._confirm('Сигурен ли си, че искаш да премахнеш потребителите от любими?', 'Favorites._action(\'' + action + '\', \'' + el + '\');') == false )
			return false;
		
		var li = $$('div.favorites');
		var json = [];
		$('loading').show();
		li.each(function(el)
				{
					var input = el.getElementsByTagName('input')[0];
					if ( input.checked == true )
					{
						json.push(input.value);						
						if ( action == 'delete' )
							el.remove();
					}
				}
			);
		
		if ( json.length == 0 )
		{
			$('loading').hide();
			return false;
		}

		new Ajax.Request('ajax', {
						 	parameters : {'section' : '_favorites_action', '_id[]' : json},
							onComplete : function()
							{								
								Favorites._status_buttons();
								General._no_results('favorites_container', 'Нямаш любими потребители.');
								$('loading').hide();
							}
						 });
		$('select_action').selectedIndex = 0;
		return false;
	},
	_status_buttons : function()
	{
		var delete_disabled = false;
		var json = [];
		var li = $$('div.favorites');
		
		li.each(function(el)
				{
					var input = el.getElementsByTagName('input')[0];
					if ( input.checked == true )					
						json.push(input.value);
				}
			);
		if ( json.length == 0 )
		{
			var delete_disabled = true;
			$('select_action').selectedIndex = 0;
		}
		
		var span = $('buttons').getElementsByTagName('a');		
		var loop = [{l : span[0], d : delete_disabled}];
		var loop_length = loop.length;
		for ( var i = 0; i < loop_length; i++ ) 
		{
			if ( loop[i].l )
			  loop[i].l.className = (loop[i].l.className.replace('menu_disabled', '') + (loop[i].d ? ' menu_disabled' : ''));			
		}
		
	}
}

var Permissions = {
	_change_status : function(el)
	{
		if ( typeof el == 'string' )
			el = $(el);
			
		var status = el.value;
				
		if ( status == "none" )
			return false;
			
		$('loading').show();
		
		var li = $$('div.permissions');
		
		if ( status == "" || status == "all" )
		{
			li.each(function(el)
				{
					el.getElementsByTagName('input')[0].checked = (status == "all") ?  true : false;
				}
			);
		}
		else
		{		
			li.each(function(el)
					{
						el.getElementsByTagName('input')[0].checked = el.className.indexOf(status) != -1 ?  true : false;
					}
			);
		}
		Permissions._status_buttons();
		
		if ( status == "" )
		{
			General._select_action_set_to_default();
		}
		
		$('loading').hide();
	return false;
	},
	_action : function(action, el)
	{
		if ( el.indexOf('menu_disabled') != -1 )
			return false;
		
		if ( action == 'delete' && General._confirm('Сигурен ли си, че искаш да премахнеш потребителите от списъка с блокирани?', 'Permissions._action(\'' + action + '\', \'' + el + '\');') == false )
			return false;
		
		var li = $$('div.permissions');
		var json = [];
		$('loading').show();
		li.each(function(el)
				{
					var input = el.getElementsByTagName('input')[0];
					if ( input.checked == true )
					{
						json.push(input.value);						
						if ( action == 'delete' )
							el.remove();
					}
				}
			);
		
		if ( json.length == 0 )
		{
			$('loading').hide();
			return false;
		}

		new Ajax.Request('ajax', {
						 	parameters : {'section' : '_permissions_action', '_id[]' : json},
							onComplete : function()
							{								
								Permissions._status_buttons();
								General._no_results('permission_container', 'Нямаш блокирани потребители.');
								$('loading').hide();
							}
						 });
		$('select_action').selectedIndex = 0;
		return false;
	},
	_status_buttons : function()
	{
		var delete_disabled = false;
		var json = [];
		var li = $$('div.permissions');
		
		li.each(function(el)
				{
					var input = el.getElementsByTagName('input')[0];
					if ( input.checked == true )					
						json.push(input.value);
				}
			);
		if ( json.length == 0 )
		{
			var delete_disabled = true;
			$('select_action').selectedIndex = 0;
		}
		
		var span = $('buttons').getElementsByTagName('a');		
		var loop = [{l : span[0], d : delete_disabled}];
		var loop_length = loop.length;
		for ( var i = 0; i < loop_length; i++ ) 
		{
			if ( loop[i].l )
			  loop[i].l.className = (loop[i].l.className.replace('menu_disabled', '') + (loop[i].d ? ' menu_disabled' : ''));			
		}
		
	}
}

var Balon = Class.create({
	initialize : function(el, _stop_disable)
	{
		this.el = $(el);
		if ( typeof _stop_disable != 'undefined' && _stop_disable == true )
		{
			_disable_balon = 0;
			this._stop_disable = 1;			
		}
		else
			this._stop_disable = 0;
			
		if ( typeof _disable_balon != 'undefined' && _disable_balon == 1 )
		{
			this.el.title = '';
			return false;
		}	
		
		this.el.setStyle({'position' : 'relative'});
		var div_el = 'div_' + el;
		this.div_el = $(div_el) || '';	
		
		if ( !this.div_el )
		{
			var div = new Element('div', {'id' : div_el, 'class' : 'balon_container' + (this._stop_disable == 1 ? ' stop_disable' : ''), 'style' : 'display: none;'});
			var div_inner = new Element('div', {'id' : div_el + '_inner', 'class' : 'balon_container_inner'});
			var div_inner_inner = new Element('div', {'id' : div_el + '_inner_inner', 'class' : 'balon_container_inner_inner'});
			div_inner.appendChild(div_inner_inner);
			div.appendChild(div_inner);
			new Insertion.Top('body', div);
			
		this.div_el = $(div_el);
		this.div_el_inner_inner = $('div_' + el + '_inner_inner');
		}

		this.title = $(el).title;
		Event.observe(el, 'mouseover', this._show.bindAsEventListener(this));
		Event.observe(el, 'mouseout', this._hide.bindAsEventListener(this));
		
		Event.observe(div_el, 'mouseover', this._show2.bindAsEventListener(this));
		Event.observe(div_el, 'mouseout', this._hide.bindAsEventListener(this));
	return false;	
	},
	_show : function(e)
	{
		if ( typeof _disable_balon != 'undefined' && _disable_balon == 1 )
		{
			this.el.title = '';
			return false;
		}

		var element = Event.element(e);
		_el = element.cumulativeOffset();
		_h = element.getHeight();
		_w = element.getWidth();
		_x = _el[0];
		_y = _el[1];

		this.el.title = '';
		var div_el = this.div_el.show().setStyle({'top' : ((_y+_h)-2) + 'px', 'left' : (_x + (_w/4)) + 'px'});
		var t = (this._stop_disable == 0 ? '<div style="padding-top: 10px;"><a href="settings?a=op" class="blue balonLink" onclick="General._disable_balon();event.returnValue = false;return false;">Изключи ме</a></div>' : '');
		var div_el_inner_inner = (this.div_el_inner_inner || $('div_' + element.id + '_inner_inner')).update(this.title + t);
	return false;
	},
	_show2 : function(e)
	{
		var div_el = this.div_el.show();
	},
	_hide : function(e)
	{
		this.div_el.hide();	
		this.el.title = this.title;
	}
});

function _e()
{
	Event.observe('container', 'click', function(e){
		var element = Event.element(e);

		if ( element.tagName == 'A' || element.tagName == 'INPUT' || element.tagName == 'IMG' )
		{			
			var _el = element.cumulativeOffset();
			
			$('loading').setStyle({'top' : (_el[1]-30) + 'px', 'left' : (_el[0]-25) + 'px'});

			if ( _el[0] < 320 )
			{
				if ( _el[0] < 300 )
					$('confirm_strike').setStyle({'right' : ((320-_el[0]-24) + 50) + 'px'});
				else
					$('confirm_strike').setStyle({'right' : 24 + 'px'});
					
				_el[0] = (320-_el[0])+_el[0];
			}
				
			if ( _el[1] < 110 )
				_el[1] = (110-_el[1])+_el[1];		
			
			$('confirm').setStyle({'top' : (_el[1]-120) + 'px', 'left' : (_el[0]-270) + 'px'});
		}
	});
}