var months = new Array;
months[0] = 'Января';
months[1] = 'Февраля';
months[2] = 'Марта';
months[3] = 'Апреля';
months[4] = 'Мая';
months[5] = 'Июня';
months[6] = 'Июля';
months[7] = 'Августа';
months[8] = 'Сентября';
months[9] = 'Октября';
months[10] = 'Ноября';
months[11] = 'Декабря';

function contactObj(elem, title, name, tip, tippos){
	this.title = title;
	this.name = name;
	this.tip = tip;
	this.tippos = tippos;
	this.elem = elem;
}

var contacts = [];
contacts[0] = new contactObj('span', 'icq', 'ICQ');
contacts[1] = new contactObj('span', 'skype', 'SKYPE');
contacts[2] = new contactObj('span', 'jabber', 'GOOGLE TALK (JABBER)');
contacts[3] = new contactObj('a', 'livejournal', 'LIVEJOURNAL.COM');
contacts[4] = new contactObj('a', 'flickr', 'FLICKR.COM');
contacts[5] = new contactObj('a', 'lastfm', 'LAST.FM');
contacts[6] = new contactObj('a', 'vimeo', 'VIMEO.COM');
contacts[7] = new contactObj('a', 'blogger', 'BLOGGER.COM');
contacts[8] = new contactObj('a', 'twitter', 'TWITTER.COM');
contacts[9] = new contactObj('a', 'facebook', 'FACEBOOK.COM');
contacts[10] = new contactObj('a', 'vkontakte', 'VKONTAKTE.RU', 'Вводите только свой ID.<br/>Например, http://vkontakte.ru/id<b>100</b>');
contacts[11] = new contactObj('a', 'habrahabr', 'HABRAHABR.RU');

function profile_page(data)
{
     if (data.isLogin != 0) {
	 	var h = '';
		h += "<div class='subMenu user'>";
		h += "<a class='menuItem' href='/#main'>гараж</a>";
		h += "<a class='menuItem' href='/#friends'>друзья</a>";
		//h += "<a class='menuItem' href='/#favourites'>избранное</a>";
		//h += "<a class='menuItem' href='/#photos'>фотографии</a>";
		//h += "<a class='menuItem' href='/#events'>события</a>";
		//h += "<a class='menuItem' href='/#news'>новости</a>";
		//h += "<a class='menuItem' href='/#stream'>потоки</a>";
		h += "<a class='menuItem active' href='/#profile'>профиль</a>";
		h += "</div>";
		h += "<div class='subTitle'>ПРОФИЛЬ</div>";
		h += "<div class='pInfo'><span class='nPlaylists'>Профиль <b>" + data.userNick + "</b> создан " + data.regtime + "</span>";
		h += "<span class='howToWork' style='width:322px;left:304px;'><span class='cont' style='width:322px;'><span class='i-icon'></span><span class='cont' style='width:305px;margin-top:3px;height:12px;'>Заполните профиль полностью и ваш рейтинг увеличится</span></span><span class='tale'></span></span>";
		h += '</div>';
		
		h += '<div class="avatarChange">';
		h += '<div class="makePreviewField"></div>';
		h += '<form id="avatarForm" action="user/refreshavatar/" method="post" enctype="multipart/form-data">';
		h += '<input name="MAX_FILE_SIZE" value="10000000" type="hidden"/>';
		h += '<br clear="All"/>';
		h += '<input name="fileToUpload[]" class="avatarFile" type="file"/>';
		h += '</form><br clear="All"/>';
		h += "<span class='howToWork' style='float:left;width:404px;height:40px;left:226px;bottom:67px;//bottom:63;'><span class='cont' style='height:35px;width:404px;'><span class='i-icon'></span><span style='margin-top:4px;width:380px;float:left;'>Вы можете задать различные области для маленькой и большой аватарок — щелкните по маленькому изображению и задайте область.</span></span><span class='tale'></span></span>";
		h += '<button class="saveAvatar ui-helper-hidden-accessible">Сохранить</button>';
		h += '<br clear="All"/><div class="lessMB">';
		h += 'Файлы размером более 5 MB не загрузятся. В случае возникновения проблем попробуйте загрузить фотографию меньшего размера.';
		h += '</div>';
		h += '<a href="javascript:;" id="saveAvatarLink" class="profileButton">Сохранить</a><br clear="All"/>';
		h += '</div>';
		h += '<div class="separator"></div>';
		
		h += '<form id="profileInfo"  action="javascript:updateProfileInfo();">';
		h += '<div class="formStrings">';			
		h += '<span class="formTitles big">Имя</span>';
		h += '<span class="formTitles big margined">Фамилия</span>';
		h += '</div>';
			
		h += '<div class="formStrings">';
		h += '<input id="txtName" name="txtName" class="big" type="text" value="' + data.name + '" />';
		h += '<input id="txtSurname" name="txtSurname" class="big margined" type="text" value="' + data.surname + '" />';
		h += '</div>';
		h += '<div class="formStrings topMargined">';
		h += '<span class="formTitles" style="width:264px;">Дата рождения</span>';
		h += '<span class="formTitles" style="width:40px;">Пол</span>';
		h += '<span class="formTitles big margined">Родной город</span>';
		h += '</div>';
		h += '<div class="formStrings">';
		h += '<input id="chooseDay" class="comboBox"/>';
		h += '<input id="chooseMonth" class="comboBox"/>';
		h += '<input id="chooseYear" class="comboBox"/>';
		h += '<input id="chooseSex" class="comboBox"/>';
		h += '<input id="chooseNativeCountry" class="comboBox"/>';
		h += '<input id="chooseNativeCity" class="comboBox"/>';
		h += '</div>';

		h += '<div class="formStrings big tMargined">';
		h += '<input id="showBirthCheck" type="checkbox" class="ui-helper-hidden-accessible"/><label for="showBirthCheck">Не отображать дату рождения</label></div>';
		
		h += '<div class="formStrings big tMargined margined">';
		h += '<input id="showNativeCheck" type="checkbox" class="ui-helper-hidden-accessible"';
		h += '/><label for="showNativeCheck">Не отображать родной город</label></div>';
		h += '<div class="formStrings topMargined">';
		h += '<span class="formTitles" style="width:141px;">Мой сайт (название)</span>';
		h += '<span class="formTitles margined" style="width:141px;">Ссылка</span>';
		h += '<span class="formTitles big margined">Местоположение</span>';
		h += '</div>';
		h += '<div class="formStrings">';
		h += '<input id="siteName" value="' + data.sitename + '" style="width:134px;"/>';
		h += '<input id="siteLink" value="' + data.sitelink + '" class="margined" style="width:134px;"/>';
		h += '<input id="chooseCurrentCountry" class="comboBox"/>';
		h += '<input id="chooseCurrentCity" class="comboBox"/>';
		h += '</div>';
		h += '<div class="lessMB big">Пожалуйста, не указывайте адреса сервисов, которые можно ввести ниже.</div>';
		h += '<div class="separator"></div>';
		for(i=0;i<contacts.length;i++){
			if (i % 3 == 0) {
				if(i==0){
					h += '<div class="formStrings">';
				} else
				if (i < contacts.length) {
					h += '</div>';
					h += '<div class="formStrings topMargined">';
				} else
					h += '</div>';
			}
			if((i + 1)%3 == 0 && i!=0){
				h += '<span class="formTitles contactsTitle" style="margin-right:0;">';
			} else
				h += '<span class="formTitles contactsTitle">';
			h += '<span class="contactsIcon" style="background-position:-' + i*19 + 'px 0;"></span>'
			h += contacts[i].name + '<br clear="All"/>';
			h += '<input id="contact' + i + '" class="contactsInp" value="' + eval("data." + contacts[i].title) + '" style="width:199px;position:relative;z-index:1;"/>';
			h += '</span>';
		}
		h += '</div><br clear="All"/>';
		h += '<div class="separator"></div>';
		h += '<div class="formStrings">';
		h += '<span class="formTitles">О себе</span>';
		h += '</div>';
		h += '<div class="formStrings">';
		h += '<textarea id="txtAbout" name="txtAbout" type="text" value="' + data.about + '">' + data.about + '</textarea>';
		h += '</div><br clear="All"/><br clear="All"/>';
		h += '<div class="separator"></div>';
		h += '<div class="formStrings">';
		h += '<span class="formTitles">Любимые жанры музыки</span>';
		h += '</div>';
		h += '<div class="formStrings">';
		var fav_styles = [];
		fav_styles = data.fav_music.split(',');
		if(fav_styles.length==0)
				h += '<input id="genres0" class="comboBox favGenres first"/>';
		for(i=0;i<fav_styles.length;i++){
			if(i%4 == 0)
				h += '<input id="genres' + i + '" class="comboBox favGenres first"/>';
			else
				h += '<input id="genres' + i + '" class="comboBox favGenres"/>';
		}
		if (i % 4 == 0) {
			h += '<a href="javascript:;" class="addPlistLink" style="margin-left:0;">Добавить</a>';
		} else
			h += '<a href="javascript:;" class="addPlistLink">Добавить</a>';
		h += '</div><br clear="All"/>';
		h += '<div class="separator"></div>';
		h += '<div class="formStrings">';
		h += '<span class="formTitles">Изменение пароля аккаунта</span>';
		h += '</div>';
		h += '<div class="formStrings">';
		h += '<input class="big" type="text" value="Сначала введите текущий пароль" onfocus="$(this).next().show().focus();$(this).hide();"/>';
		h += '<input id="txtOldPass" name="txtOldPass" class="big" type="password" onblur=";if(this.value==\'\'){$(this).prev().show();$(this).hide();}" style="display:none;position:relative;"/>';
		h += '</div>';
		h += '<div class="formStrings">';
		h += '<a href="javascript:;" id="checkPassButton" class="profileButton">Подтвердить</a>';
		h += '</div>';
		h += '<br clear="All"/>';
		h += '<div class="separator"></div>';
		h += '<div class="formStrings">';
		h += '<span class="formTitles">Настройки приватности</span>';
		h += '</div>';
		h += '<div class="formStrings big tMargined">';
		h += '<input id="denyView" type="checkbox" class="ui-helper-hidden-accessible"';
		h += '/><label for="denyView">Запретить просматривать мою страницу</label></div>';
		
		h += '<div class="formStrings big tMargined margined">';
		h += '<input id="denyWall" type="checkbox" class="ui-helper-hidden-accessible"';
		h += '/><label for="denyWall">Запретить оставлять сообщения на моей стене</label></div>';
		h += "<span class='howToWork contactsTip' style='display:none;width:206px;height:40px;'><span class='cont' style='height:35px;width:206px;'><span class='i-icon'></span><span class='tipText' style='margin-top:4px;width:179px;float:left;'></span></span><span class='tale'></span></span><br clear='All'/>";
		h += '<div class="separator"></div>';
		h += '<div class="formStrings">';
		h += '<a href="javascript:;" id="profileSaveButton" class="profileButton">Сохранить</a>';
		h += '</div>';
		h += '</form>';
		h += '<br/><br/><br/><br/><br/>';

		

		$('#leftContent').html(h);
			
		$(".makePreviewField").makePreview({
			init: data.avatarInfo,
			image: data.avatar.replace(".jpg", "_back.jpg"),
			fullsize: '402x268',
			npreviews: 2,
			previewSizes: ['200x200', '55x55']
		});
			
		$('.saveAvatar').bind("click", 
			function(){
				var t = $('#saveAvatarLink');
				$(t).after('<img style="margin-top:9px;" src="/media/images/beta-pics/loaders/universal_loader_01.gif"/>').hide();
				var widths = $(".makePreviewField").getWidths();
				var heights = $(".makePreviewField").getHeights();
				var Xs = $(".makePreviewField").getXs();
				var Ys = $(".makePreviewField").getYs();

				$.post("/user/saveAvatar", {
					image : data.avatar,
					top1 : Math.floor(Ys[0]*1),
					left1 : Math.floor(Xs[0]*1),
					width1 : Math.floor(widths[0]*1),
					height1 : Math.floor(heights[0]*1),
					top2 : Math.floor(Ys[1]*1),
					left2 : Math.floor(Xs[1]*1),
					width2 : Math.floor(widths[1]*1),
					height2 : Math.floor(heights[1]*1)
				}, function(dat){
					$(t).show().next().remove();

					$('#loginLayout .smallAvatar img')[0].src = dat.replace(".jpg", "_55x55.jpg");
					data.avatar = dat;
					return false;
				});
		});

		$('#avatarForm').ajaxForm({
			beforeSubmit: function(a,f,o) {
				$(".makePreviewField").html("<div style='width:100%;height:154px;padding-top:120px;text-align:center;'><img src='/media/images/beta-pics/loaders/universal_loader_01.gif'</div>");
						
			$('#avatarimage').attr('src', '/media/images/loading.gif');
			},	
				success: function(im) {
				if (typeof im == 'object' && im.nodeType)
					im = elementToString(im.documentElement, true);
				else if (typeof im == 'object')
					im = objToString(im);
				data.avatar = im;
				
				$('#loginLayout .smallAvatar img').removeAttr('src');
				$('#loginLayout .smallAvatar img').attr('src', data.avatar.replace(".jpg", "_55x55.jpg"));
				
				$(".makePreviewField").makePreview({
					init: "",
					image: im.replace(".jpg", "_back.jpg"),
					fullsize: '402x268',
					npreviews: 2,
					previewSizes: ['200x200', '55x55']
				});
			}
		});
			
			$('.avatarFile').bind("change", function(){
				$('#avatarForm').submit();
			});
			var days = [];
			for(i = 0; i<31;i++){
				days[i] = '' + (i + 1);
			}
			$("#chooseDay").combobox({
				data: days,
				arrowHTML: function() {
								return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
							}
			});
			
			$("#chooseMonth").combobox({
				data: months,
				arrowHTML: function() {
								return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
							}
			});
			
			var years = [];
			curDate = new Date();
			var j = 0;
			for(i=curDate.getFullYear();i>=1930;i--){
				years[j] = '' + i;
				j++;
			}
			
			$("#chooseYear").combobox({
				data: years,
				arrowHTML: function() {
								return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
							}
			});
			
			$("#chooseSex").combobox({
				data: ['М', 'Ж'],
				arrowHTML: function() {
								return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
							}
			});
			
			var countries = [];
			for(i=0;i<data.countries.length;i++){
				countries[i] = data.countries[i].name;
			}
			
			$("#chooseNativeCountry, #chooseCurrentCountry").combobox({
				data: countries,
				initstr: "Выберите страну",
				arrowHTML: function() {
								return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
							}
			});
			
			var cities = [];
			if (data.cities) {
				for (i = 0; i < data.cities.length; i++) {
					cities[i] = data.cities[i].name;
				}
			}
			
			$("#chooseNativeCity").combobox({
				data: cities,
				initstr: "Выберите город",
				hideElse: 1,
				arrowHTML: function() {
								return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
							}
			});
			
			var cities1 = [];
			
			if (data.cities1) {
				for (i = 0; i < data.cities1.length; i++) {
					cities1[i] = data.cities1[i].name;
				}
			}
			
			
			$("#chooseCurrentCity").combobox({
				data: cities1,
				initstr: "Выберите город",
				hideElse: 1,
				arrowHTML: function() {
								return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
							}
			});
			
			$('#showBirthCheck').checkBox();
			$('#showNativeCheck').checkBox();
			$('#denyView').checkBox();
			$('#denyWall').checkBox();

			var genres = [];
			genres[0] = "Acid Jazz";
			genres[1] = "Afrobeat";
			genres[2] = "Alternative";
			genres[3] = "Brit-Pop";
			genres[4] = "Country";
			genres[5] = "Classical";
			genres[6] = "Drum&Bass";
			genres[7] = "Electro";
			genres[8] = "Folk";
			genres[9] = "Funk";			
			genres[10] = "House";
			genres[11] = "Industrial";
			genres[12] = "Jazz";
			genres[13] = "Metal";
			genres[14] = "Pop";
			genres[15] = "Punk";
			genres[16] = "Reggae";
			genres[17] = "Rock";
			genres[18] = "Rock n Roll";
			genres[19] = "Techno";
			genres[20] = "Trance";

			$(".favGenres").combobox({
				data: genres,
				initstr: "Выберите жанр",
				arrowHTML: function() {
								return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
							}
			});
			
			$('#chooseDay').val(data.birthday.split('/')[1]*1 + '');
			$('#chooseMonth').val(months[data.birthday.split('/')[0]*1 - 1]);
			$('#chooseMonth').addClass('value' + (data.birthday.split('/')[0]*1 - 1));
			$('#chooseYear').val(data.birthday.split('/')[2]*1 + '');
			$('#chooseSex').val(data.sex);
			if(data.country_id!=0)
				$('#chooseNativeCountry').val(data.country).addClass("value" + (data.country_id - 1));
			if(data.region!=0)
				$('#chooseNativeCity').val(data.region).addClass("value" + (data.region_id - 1));
			if(data.cur_country_id!=0)
				$('#chooseCurrentCountry').val(data.cur_country).addClass("value" + (data.cur_country_id - 1));
			if(data.cur_region!=0)
				$('#chooseCurrentCity').val(data.cur_region).addClass("value" + (data.cur_region_id - 1));
				
			var j = 0;
			$('input.favGenres').each(function(){
				this.value = fav_styles[j];
				j++; 
			});

			for (i = 0; i < data.show_profile.length; i++)
 				if (data.show_profile.substr(i,1) * 1 == 1) {
					$($('#profileInfo .ui-checkbox')[i]).trigger('click');
				}
			
			$('#saveAvatarLink').click(function(){
				$('button.saveAvatar').trigger('click');
			});
			
			$("#profileInfo .addPlistLink").click(function(){
				var that = this;
				var combos = $("#profileInfo input.favGenres");
				if(combos.length%4==0)
					$(this).before('<input id="genres' + combos.length + '" class="comboBox favGenres first"/>');
				else
					$(this).before('<input id="genres' + combos.length + '" class="comboBox favGenres"/>');
				if((combos.length + 1)%4==0){
					$(that).css('margin-left', '0');
				} else {
					$(that).css('margin-left', '8px');
				}
				$($("#profileInfo input.favGenres")[combos.length]).combobox({
					data: genres,
					initstr: "Выберите жанр",
					arrowHTML: function() {
									return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
								}
				});
			});
			
			$('#profileInfo .contactsInp').bind('focus', function(){
				var ind = this.id.substr(7, this.id.length);
				if(!contacts[ind].tip)
					return;

				$('#profileInfo .contactsTip').css('left', this.offsetLeft - 5 + 'px');
				$('#profileInfo .contactsTip').css('top', this.offsetTop - 37 + 'px');
				$('#profileInfo .contactsTip .tipText').html(contacts[ind].tip);
				$('#profileInfo .contactsTip').show();
			});
			
			$('#profileInfo .contactsInp').bind('blur', function(){
				$('#profileInfo .contactsTip').hide();
			});
			
			$('#checkPassButton').click(function(){
				changePass(this);
			});
			
			$('#txtOldPass').keydown(function (event) {if (event.keyCode == 13) $('#checkPassButton').trigger('click');});

			$('#chooseNativeCountry').bind('comboChanged', function(e, ind){
				$.post('/profile/getCity', {
					ci : (ind + 1)
				}, function(cities){
					for(i=0;i<cities.length;i++){
						cities[i] = cities[i].name;
					}
										
					$("#chooseNativeCity").next().remove();
					$("#chooseNativeCity").combobox({
						data: cities,
						initstr: "Выберите город",
						hideElse: 1,
						arrowHTML: function() {
									return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
									}
					});
				});				
			});
			
			$('#chooseCurrentCountry').bind('comboChanged', function(e, ind){
				$.post('/profile/getCity', {
					ci : (ind + 1)
				}, function(cities){
					for(i=0;i<cities.length;i++){
						cities[i] = cities[i].name;
					}
										
					$("#chooseCurrentCity").next().remove();
					$("#chooseCurrentCity").combobox({
						data: cities,
						initstr: "Выберите город",
						hideElse: 1,
						arrowHTML: function() {
									return $('<a href="javascript:;" class = "ui-combobox-arrow"></a>');
									}
					});
				});				
			});

			$('#profileSaveButton').bind('click', function(){
				var t = this;
				$(t).after('<img style="margin-top:9px;" src="/media/images/beta-pics/loaders/universal_loader_01.gif"/>').hide();
				
				var birth = getValue($('#chooseMonth')[0])*1+1 + '/' + $('#chooseDay').val() + '/' + $('#chooseYear').val();
				var toEval = "name: '" + $('#txtName').val() + "', surname: '" + $('#txtSurname').val() + "', birthday: '" + birth + "', sex: '" + $('#chooseSex').val() + "', sitename: '" + $('#siteName').val() + "', sitelink: '" + $('#siteLink').val() + "', ";
	

				for(i=0;i<contacts.length;i++){
					toEval += contacts[i].title + ": '";
					toEval += $('#contact' + i).val() + "', ";
				}
				
				toEval += "about : '" + $('#txtAbout').val() + "', ";
				var st = '';
				var gr = $('#profileInfo input.favGenres');
				for(i=0;i<gr.length;i++){
					var style = $(gr[i]).val();
					if (style != 'Выберите жанр') {
						st += $(gr[i]).val();
						st += ',';
					}
				}
				st = st.substr(0, st.length-1);
				toEval += "fav_music : '" + st + "', ";
				
				var checks = '';
				$('#profileInfo input[type="checkbox"]').each(function(){
					if(this.checked == true)
						checks +='1';
					else
						checks +='0';
				});
				toEval += "show_profile : '" + checks + "' ";
				
				if (getValue($('#chooseNativeCountry')[0]) + 1) {
					toEval += ", country : '" + (getValue($('#chooseNativeCountry')[0]) + 1) + "' ";
					if (getValue($('#chooseNativeCity')[0]) + 1) {
						toEval += ", region : '" + (getValue($('#chooseNativeCity')[0]) + 1) + "' ";
					}
				}
				
				if (getValue($('#chooseCurrentCountry')[0]) + 1) {
					toEval += ", cur_country : '" + (getValue($('#chooseCurrentCountry')[0]) + 1) + "' ";
					if (getValue($('#chooseCurrentCity')[0]) + 1) 
						toEval += ", cur_region : '" + (getValue($('#chooseCurrentCity')[0]) + 1) + "' ";
				}
				
				toEval = eval("({" + toEval + "})");

				$.post('/user/save/', toEval, function(data){
					$(t).show().next().remove();
				});
			});
			

			
		} else {
			location.hash = 'main';
            window.historyStock = 'main';
		}
}

function changePass(that){

	var opInput = $('#txtOldPass');
	var oldPass = opInput.val();
	
	if (oldPass == '') 
		return;
	$.post('/user/check_pass', {
		oldpass: oldPass
	}, function(data){
		if (data * 1 == 1) {
			opInput.parent().prev().html('<span class="formTitles" style="width:210px;">Новый пароль</span><span class="formTitles margined">Подтверждение</span>');
			opInput.replaceWith('<input type="password" id="txtNewPass" style="width:203px;position:relative;"/><input type="password" id="txtConfirmPass" class="margined" style="width:203px;position:relative;"/>');
			
			$(that).replaceWith('<a href="javascript:;" id="changePassButton" class="profileButton">Сменить</a><a href="javascript:;" id="passCancelButton" class="profileButton margined">Отмена</a>');
			
			$("#txtNewPass").focus();
			
			$('#passCancelButton').click(function(){
				var h = '<input class="big" type="text" value="Сначала введите текущий пароль" onfocus="$(this).next().show().focus();$(this).hide();"/>';
				h += '<input id="txtOldPass" name="txtOldPass" class="big" type="password" onblur=";if(this.value==\'\'){$(this).prev().show();$(this).hide();}" style="display:none;position:relative;"/>';
				$(this).parent().prev().prev().html('<span class="formTitles">Изменение пароля аккаунта</span>');
				$(this).parent().prev().html(h);
				$(this).parent().html(that);
				
				$('#checkPassButton').click(function(){
					changePass(this);
				});
				$('#txtOldPass').keydown(function (event) {if (event.keyCode == 13) $('#checkPassButton').trigger('click');});
			});
			
			$('#changePassButton').click(function(){
				var pass = $('#txtNewPass').val();
				var conf = $('#txtConfirmPass').val();
				if(pass == '')
					return;
				if (conf != pass) {
					$('#profileInfo .contactsTip').css('left', $('#txtConfirmPass')[0].offsetLeft - 5 + 'px');
					$('#profileInfo .contactsTip').css('top', $('#txtConfirmPass')[0].offsetTop - 37 + 'px');
					$('#profileInfo .contactsTip .tipText').html('Введенный пароль и его подтверждение не совпадают!');
					$('#profileInfo .contactsTip').show();
					setTimeout(function(){
						$('#profileInfo .contactsTip').fadeOut('slow');
					}, 1500);
					return;
				}
				$.post('/user/change_pass', {
					password: pass,
					confirm: conf
				}, function(data){
					if (data * 1 == 0) {
						$('#profileInfo .contactsTip').css('left', $('#txtNewPass')[0].offsetLeft - 5 + 'px');
						$('#profileInfo .contactsTip').css('top', $('#txtNewPass')[0].offsetTop - 37 + 'px');
						$('#profileInfo .contactsTip .tipText').html('Пароль должен содержать не менее трех символов!');
						$('#profileInfo .contactsTip').show();
						setTimeout(function(){
							$('#profileInfo .contactsTip').fadeOut('slow');
						}, 1500);
					}
					else {
						$('#profileInfo .contactsTip').css('left', $('#txtNewPass')[0].offsetLeft - 5 + 'px');
						$('#profileInfo .contactsTip').css('top', $('#txtNewPass')[0].offsetTop - 37 + 'px');
						$('#profileInfo .contactsTip .tipText').html('Пароль успешно изменен!');
						$('#profileInfo .contactsTip').show();
						setTimeout(function(){
							$('#profileInfo .contactsTip').fadeOut('slow');
						}, 1500);
						var h = '<input class="big" type="text" value="Сначала введите текущий пароль" onfocus="$(this).next().show().focus();$(this).hide();"/>';
						h += '<input id="txtOldPass" name="txtOldPass" class="big" type="password" onblur=";if(this.value==\'\'){$(this).prev().show();$(this).hide();}" style="display:none;position:relative;"/>';
						$('#changePassButton').parent().prev().prev().html('<span class="formTitles">Изменение пароля аккаунта</span>');
						$('#changePassButton').parent().prev().html(h);
						$('#changePassButton').parent().html(that);
						$('#checkPassButton').click(function(){
							changePass(this);
						});
						$('#txtOldPass').keydown(function (event) {if (event.keyCode == 13) $('#checkPassButton').trigger('click');});
					}
				});
			});
			$('#txtConfirmPass').keydown(function (event) {if (event.keyCode == 13) $('#changePassButton').trigger('click');});			
		}
		else {
			$('#profileInfo .contactsTip').css('left', opInput[0].offsetLeft - 5 + 'px');
			$('#profileInfo .contactsTip').css('top', opInput[0].offsetTop - 37 + 'px');
			$('#profileInfo .contactsTip .tipText').html('Пароль введен неверно!');
			$('#profileInfo .contactsTip').show();
			setTimeout(function(){
				$('#profileInfo .contactsTip').fadeOut('slow');
			}, 1500);
		}
	});
}


function viewProfile_page(data)
{

			var h = '';
			h += "<div class='subMenu user'>";
			h += "<a class='menuItem active' href='/#main'>общая</a>";
			//h += "<a class='menuItem' href='/#friends/'>друзья</a>";
			//h += "<a class='menuItem' href='/#photos'>фотографии</a>";
			//h += "<a class='menuItem' href='/#events'>плейлисты</a>";
			h += "</div>";
			h += "<div class='subTitle'>" + data.otherUser.name.toUpperCase();
			h += " " + data.otherUser.surname.toUpperCase();
			h += "<span class='subTitleNick'> / " +  data.otherUser.userNick + "</span></div>";
			
			h += "<div class='pInfo'>";
			if (data.otherUser.nowListening) {
				h += "Сейчас слушает: ";
				h += "<a class='performer-link' style='float:none;' href='/#performers/" + data.otherUser.nowListening.performer_id + "'>" + data.otherUser.nowListening.performer + "</a>";
				h += " &mdash <a style='float:none;' href='/#tracks/" + data.otherUser.nowListening.id + "'>" + data.otherUser.nowListening.name + "</a>"; 
			}
			
			h += "<div class='activities'>";
			h += "<span class='artComments' title='количество коментариев'></span>";
			h += "<span class='people' title='количество друзей'>" + data.otherUser.friends.length + "</span>";
			h += "<span class='votes' title='карма'>" + data.otherUser.karma + "</span>";
			
			h += "</div><br clear='All'/>";
			h += "<div class='articleTopInfo'>";
			if (loginFuncs.isLogin) {
				h += "<span class='buttons'>";
				h += "<a href='javascript:;' onclick='" + ((data.isFriend) ? ("un") : ("")) + "friend(" + data.otherUser.id + ", this)' class='inFav " + ((data.isFriend) ? ("favDone") : ("")) + "'>" + ((data.isFriend) ? ("Убрать из друзей") : ("Добавить в друзья")) + "</a>";
				h += "</span>";
			}
			
			h += "<div class='alsoInStream'>";
			if (data.otherUser.friends.length > 0) {
				h += "Друзья пользователя ";
				h += ((data.otherUser.friends.length>8)?("(8/" + data.otherUser.friends.length + "): "):(": "));
				for (i = 0; i < ((data.otherUser.friends.length>8)?(8):(data.otherUser.friends.length)); i++) {
					h += "<a id='a" + i + "' href='/#users/" + data.otherUser.friends[i].nick + "'>";
					h += "<img src='" + data.otherUser.friends[i].avatar + "' style='" + ((i == data.otherUser.friends.length - 1) ? ("margin-right:0;") : ("")) + "'/>";
					h += "</a>";
				}
			}
			h += '<div class="usersTooltip">';
			h += '<span class="cont">';
			h += '<span class="nick"></span>';
			h += '<span class="karma"></span>';
			h += '</span>';
			h += '<span class="tale"></span></div>';
			h += "</span>";
			h += "</div>";
			h += "</div>";
			h += '</div>';
			h += '<br clear="all"/>';
			
   		    h += "<div id='userInfo'  style='height:200px;'>";
			if (!data.otherUser.closedPage || data.isFriend) {
				h += "<span class='blockTitle userInf'>ИНФОРМАЦИЯ О ПОЛЬЗОВАТЕЛЕ</span><br clear='All'/>";
				if (data.otherUser.status) {
					h += "<span class='otherUserStatus'>" + data.otherUser.status.status + "</span>";
					h += "<span class='lastRefresh'>" + data.otherUser.status.last_refresh + "</span>";
				}
			} else{
				h += "<span class='blockTitle userInf'>ПОЛЬЗОВАТЕЛЬ ОГРАНИЧИЛ ДОСТУП К СВОЕЙ СТРАНИЦЕ</span><br clear='All'/>";
				h += ((loginFuncs.isLogin)?(info({title:"Но вы можете добавить этого пользователя в друзья", style:'right:215px;top:10px;'})):(""));
				h += "<img style='margin-top:32px;' src='/media/images/beta-pics/blocked.png'/>";
			}
			h += "<img class='otherUserAvatar' style='height:200px;' src='" + data.otherUser.avatar + "'/>";
			h += "<a href='javascript:;' class='editText outerLinks' onclick='write_to_user(\"" + data.otherUser.userNick + "\");'>Написать сообщение</a>";
			if (!data.otherUser.closedPage || data.isFriend) {
				h += "<div class='personal'>";
				if(data.otherUser.sex!='')
					h += "<span class='userInfoLabel'>Пол:</span><span class='data'>" + ((data.otherUser.sex == 'М') ? ("Мужской") : ("Женский")) + "</span>";
				if (data.otherUser.birthday) {
					if (months[data.otherUser.birthday.split('/')[0] * 1 - 1]) {
						h += "<span class='userInfoLabel'>День рождения:</span><span class='data'>";
						h += data.otherUser.birthday.replace(/\//g, '.');
						h += "</span>";
					}
				}
				h += ((data.otherUser.region != '0' && data.otherUser.region) ? ("<span class='userInfoLabel'>Родной город:</span><span class='data'>" + data.otherUser.region + "</span>") : (''));
				h += ((data.otherUser.cur_region != '0') ? ("<span class='userInfoLabel'>Местоположение:</span><span class='data'>" + data.otherUser.cur_region + '</span>') : (''));
				h += ((data.otherUser.fav_music) ? ("<span class='userInfoLabel lower'>Муз. предпочтения:</span><span class='data lower'>" + data.otherUser.fav_music + "</span>") : (""));
				h += ((data.otherUser.about) ? ("<span class='userInfoLabel lower'>О себе:</span><span class='data lower'>" + data.otherUser.about + "</span>") : (""));
				h += ((data.otherUser.sitename && data.otherUser.sitelink) ? ("<span class='userInfoLabel lower'>Свой сайт:</span><span class='data lower'><a target='_blank' class='outerLinks' href='" + data.otherUser.sitelink + "'>" + data.otherUser.sitename + "</a></span>") : (""));
				var fl = 0;
				for (i = 0; i < contacts.length; i++) {
					((eval('data.otherUser.' + contacts[i].title)) ? (fl++) : (''));
				}
				if (fl) {
					h += "<span class='userInfoLabel lower'>Ссылки на меня:</span>";
					h += "<span class='data lower'>";
					for (i = 0; i < contacts.length; i++) {
						contact = eval('data.otherUser.' + contacts[i].title);
						if (contact) {
							if (contacts[i].elem == 'a') {
								h += '<a target="_blank" href="';
								h += ((contacts[i].title == 'flickr') ? (contact) : (''));
								h += ((contacts[i].title == 'twitter') ? ('http://twitter.com/' + contact) : (''));
								h += ((contacts[i].title == 'lastfm') ? ('http://lastfm.com/user/' + contact) : (''));
								h += ((contacts[i].title == 'vimeo') ? ('http://vimeo.com/' + contact) : (''));
								h += ((contacts[i].title == 'blogger') ? ('http://' + contact + '.blogger.com/') : (''));
								h += ((contacts[i].title == 'facebook') ? ('http://facebook.com/' + contact) : (''));
								h += ((contacts[i].title == 'vkontakte') ? ('http://vkontakte.ru/id' + contact) : (''));
								h += ((contacts[i].title == 'habrahabr') ? ('http://' + contact + '.habrahabr.ru/') : (''));
								h += ((contacts[i].title == 'livejournal') ? ('http://livejournal.com/users/' + contact) : (''));
								h += '" class="outerLinks">';
							}
							else {
								h += '<span>';
							}
							h += '<span class="contactsIcon" style="margin-bottom:10px;background-position:-' + i * 19 + 'px 0;"></span>';
							h += contact;
							h += ((contacts[i].elem == 'a') ? ('</a>') : ('</span>'));
							h += '<br clear="All"/>';
						}
					}
					h += "</span>";
				}
				h += "</div>";
			}
			h += "</div>";
			h += '</div>';		
			h += '<br clear="All"/><div style="width:627px;border-top:1px solid #e3e3e3;top:10px;" class="ratingBlock block"></div>';
			h += "<br clear='All'/>";
			h += '<div id="userPls"></div>';
			h += '<br clear="all" />';
			h += '<div class="comments block"></div>';
			$('#leftContent').html(h);
			
			var rating = new ratingFuncs('users', data.otherUser.id, data.isVote, data.otherUser.karma*1, data.isLogin);
			rating.show('.ratingBlock');

			comments = new commentsFuncs(5, data.otherUser.id, '.comments', 'yellow');
			comments.show(1);
			
			var userPlaylists = new playlistFuncs(data.otherUser.userNick);
			userPlaylists.show($('#userPls')[0]);

			h = ban240x400(topArtists.init(data.topPerformers).get(0, 5));
			h += streams.init({
				streams: data.topStreams
			}).streams();
			$('#dynamicRightContent').css('margin-top', "0px");
			$('#dynamicRightContent').html(h);
			topArtists.addEvents("#dynamicRightContent .banner240x400 .topPerformers");

			commonToolTip({
				obj : ".alsoInStream",
				hoverObj : "a",
				data : data.otherUser.friends,
				field1 : "nick",
				field2 : "karma",
				initLeft : $(".alsoInStream")[0].offsetLeft - ((data.otherUser.friends.length>8)?(15):(42)),
				objectWidth : 33,
				initTop : -38,
				objectHeight: 58,
				perLine : 8
			});
			
}

function wall_page(data)
{

			var h = '';
			h += '<div class="comments block"></div>';
			$('#leftContent').html(h);
			
			comments = new commentsFuncs(5, data.id, '.comments', 'yellow');
			comments.show(1);
			
			h = ban240x400(topArtists.init(data.topPerformers).get(0, 5));
			h += streams.init({
				streams: data.topStreams
			}).streams();
			$('#dynamicRightContent').css('margin-top', "0px");
			$('#dynamicRightContent').html(h);
			topArtists.addEvents("#dynamicRightContent .banner240x400 .topPerformers");
			
}