function ListCore() {
	this.ident ='';
	this.currentPage = 1;
	this.perPage  = 20;	
	this.sort = 0;
	this.age_from = 0;
	this.age_till = 0;
	this.gender = 2;
	this.with_photo = 0;
	this.now_online = 0;
	this.country = 0;
	this.region = 0;
	this.firstname = '';
	this.lastname='';
	this.city = 0;

	
	this.addFriend = function(id) {
		if (confirm('Добавить пользователя в друзья?') == true) {
			var data = new Object();	
			data['friendid'] = id;
			data['act'] = 'addfriend';
			data['widget'] = 'userslist';
			this.InitializeRequest('POST', '/ajax.php');
	        this.Commit(postquery(data));
		}
	}
	
	this.displayMailblock = function(id) {
		if (!$('mailblock_'+id)) {
			if(window.mainblock && $(window.mainblock)) $(window.mainblock).parentNode.removeChild($(window.mainblock));
			
			var box = document.createElement('div');
			box.id = 'mailblock_'+id;
			box.style.position = 'absolute';
			box.style.padding = '5px';
			//box.style.border = '1px solid #999';
			box.style.background = '#d3e2f0';
			box.innerHTML = '<div><input type="text" style="width:300px;" value="Тема" id="subject_'+id+'" onfocus="if (this.value==\'Тема\') {this.value=\'\';}"></div><div><textarea style="width:300px;height:65px;" id="message_'+id+'" onfocus="if (this.value==\'Сообщение\') {this.value=\'\';}">Сообщение</textarea></div><div style="text-align:center;"><span style="padding:2px;margin-right:5px;"><a style="cursor:pointer;" onclick="List.sendMail(\''+id+'\');">отправить</a></span><span style="padding:2px;margin-left:5px;"><a style="cursor:pointer;" onclick="List.cancelMail(\''+id+'\');">отменить</a></span></div>';
			$('useractions_'+id).appendChild(box);
			window.mainblock='mailblock_'+id;
		}
	}
	
	this.sendMail = function(id) {
		if ($('message_'+id) && $('message_'+id).value != '') {
			var data = new Object();	
			data['userid'] = id;
			data['subject'] = $('subject_'+id).value;
			data['message'] = $('message_'+id).value;
			data['act'] = 'sendmail';
			data['widget'] = 'userslist';
			this.InitializeRequest('POST', '/ajax.php');
	        this.Commit(postquery(data));
		} else alert('Вы пытаетесь отправить пустое собщение.');
	}
	
	this.cancelMail = function(id) {
		if ($('mailblock_'+id)) {
			$('useractions_'+id).removeChild($('mailblock_'+id));
		}
	}
	
	this.setcurrentPage = function(page) {
		if (page > 0) {
			this.currentPage = page;		
		} else {
			this.currentPage = 1;
		}
	}
	
	this.setParams = function() {
		this.age_from = $('age_from').options[$('age_from').selectedIndex].value;
		this.age_till = $('age_till').options[$('age_till').selectedIndex].value;
		if ($('gender_0').checked == true) {
			this.gender = 0;
		} else if ($('gender_1').checked == true) {
			this.gender = 1;
		} else this.gender = 2;
		if ($('with_photo').checked == true) this.with_photo = 1; else this.with_photo = 0;
		if ($('now_online').checked == true) this.now_online = 1; else this.now_online = 0;
		this.country = $('countryid').options[$('countryid').selectedIndex].value;
		this.region = $('regionid').options[$('regionid').selectedIndex].value;
		this.city = $('cityid').options[$('cityid').selectedIndex].value;
		this.firstname = $('firstname').value;
		this.lastname = $('lastname').value;
	}
	
	this.setSort = function (sort) {
		this.sort = sort;
	}
	
	this.selectCountry = function (country) {
		var data = new Object();	
		data['country'] = country;
		data['act'] = 'country';
		data['widget'] = 'userslist';
		this.InitializeRequest('POST', '/ajax.php');
        this.Commit(postquery(data));
	}
	
	this.selectRegion = function (region) {
		var data = new Object();	
		data['region'] = region;
		data['act'] = 'region';
		data['widget'] = 'userslist';
		this.InitializeRequest('POST', '/ajax.php');
        this.Commit(postquery(data));
	}
	
	this.query = function() {
		var data = new Object();	
		data['page'] = this.currentPage;
		data['perpage'] = this.perPage;
		data['age_from'] = this.age_from;
		data['age_till'] = this.age_till;
		data['groupid'] = window.groupid;
		data['eventid'] = window.eventid;
		data['firstname'] = encodeURIComponent(this.firstname);
		data['lastname'] = encodeURIComponent(this.lastname);
		data['gender'] = this.gender;
		data['sort'] = this.sort;
		data['with_photo'] = this.with_photo;
		data['now_online'] = this.now_online;
		data['country'] = this.country;
		data['region'] = this.region;
		data['city'] = this.city;
		data['act'] = 'query';
		data['widget'] = 'userslist';
		this.InitializeRequest('POST', '/ajax.php');
        this.Commit(postquery(data));		
	}
	
	this.OnSuccess = function()
      {
      	//alert(this.GetResponseText());
      	eval(this.GetResponseText());
      	// fade(0,"form_"+this.ident);
      	// $("loading_"+this.ident).style.display = 'none';
      }
}

ListCore.prototype = new ajax();
List = new ListCore();