function startSearch(event){
if(event === null || event.which == 13){
locateTo('/people-search/' + $('arama_ad').value);
}
}

function toggleMoreCriteria()
{
	var mcsb = $('more_criteria_selection_box');
	var mc = $('more_criteria');
	var isVisible = mcsb.style.display == 'block';
	if(isVisible){
		mcsb.setStyle({display:'none'});
		mc.update(Lang.people_search.more_criteria);
	}else{
		mcsb.setStyle({display:'block'});
		mc.update(Lang.people_search.less_criteria);
	}
}

var PSVars = {
	gender_all : 'gender_all',
	gender_male : 'gender_male',
	gender_female : 'gender_female',
	with_photo : 'with_photo',
	looking_for_arr : ['meet_new_people', 'dating', 'relationship', 'networking'],
	gender_arr : ['gender_all', 'gender_female', 'gender_male']
};

var PeopleSearcher = Class.create();
PeopleSearcher.prototype = {
	initialize : function(){
		this.initListeners();
	},
	startSearch : function(){
		var _queryStr = new StringBuffer();
		_queryStr.add('/people-search?s=true');
		var gender = '0';
		if($(PSVars.gender_arr[1]).checked)gender = '1';
		if($(PSVars.gender_arr[2]).checked)gender = '2';
		if($)
		_queryStr.add('&gender=').add(gender);
		var ageMin=getValueOfIndex('age_min');
		var ageMax=getValueOfIndex('age_max');
		if(ageMin>ageMax){
			var tmpAge=ageMin;
			ageMin=ageMax;
			ageMax=tmpAge;
		}
		_queryStr.add('&age_min=').add(ageMin);
		_queryStr.add('&age_max=').add(ageMax);
		_queryStr.add('&with_photo=').add($('with_photo').checked ? '1' : '0');
		var nation = getValueOfIndex('nations');
		if(nation > 0){
			_queryStr.add('&nation=').add(nation);
		}
		var body_type = $('body_type').selectedIndex;
		if(body_type > 0){
			_queryStr.add('&body_type=').add(body_type);
		}
		var _tmpFlag = false;
		for(var i=0; i<3; i++){
				if($(PSVars.looking_for_arr[i]).checked){
					_tmpFlag = true;
				}
		}
		if(_tmpFlag){
			for(var i=0; i<4; i++){
				_queryStr.add('&looking_for=');
				if($(PSVars.looking_for_arr[i]).checked){_queryStr.add('1');}else{_queryStr.add('0');}
			}
		}
		location.href = _queryStr.toString();
		
	},
	showSelections : function(){
		var tmp = null;
		var showMore = false;
		if((tmp = this.getFromDH('age_min')) != 'null' && tmp != null){
			selectOptionByValue('age_min', tmp);
		}
		if((tmp = this.getFromDH('age_max')) != 'null' && tmp != null){
			selectOptionByValue('age_max', tmp);
		}
		if((tmp = this.getFromDH('nation')) !=  'null' && tmp != null){
			selectOptionByValue('nations', tmp);
		}
		if((tmp = this.getFromDH('body_type')) != 'null' && tmp != null){
			selectOptionByValue('body_type', tmp);
			showMore = true;
		}
		if((tmp = this.getFromDH('looking_for')) != 'null' && tmp != null){
			if(tmp.length == 4){
				for(var i=0; i<4; i++){
					if(tmp.charAt(i) == '1')$(PSVars.looking_for_arr[i]).checked = true;
				}
			}
			showMore = true;
		}		
		if(showMore){
				toggleMoreCriteria();
		}
	},
	onSearchButtonClicked : function(){
		this.startSearch();
	},
	initListeners : function(){
		Event.observe($('search_button'), 'click', this.onSearchButtonClicked.bind(this));
	},
	getFromDH : function(name)
	{
		return globDH.get('PeopleSearcher', name);	
	}
};
var peopleSearcher = null;
function __initPeopleSearcher(){
peopleSearcher= new PeopleSearcher();
}
runner.add(__initPeopleSearcher);