function Search()
{
	this.reqWidgetQueue= new Array();//queue with the widgets that made a request through this controller object
	var self=this;
	
	this.sexFilter = 0;
	this.sortFilter = 0;
	
	/**
	 * @param The manager index of the request 
	 * @desc This method is a handler for the completition of one request
	 */
	this.handleResponse=function (managerIndex)
	{		
		var code = RequestManager.getInstance().getRequestObj (managerIndex).getResponseErrorCode();
		var content = RequestManager.getInstance().getRequestObj (managerIndex).getResponseContent();
		switch(code)
		{
			//nu are access la mesaj
			case 1:
				
			break;
		}
	}

	this.getMessage=function(mesaj_id)
	{
		var rqid=RequestManager.getInstance().createRequest(self,Config.APP_URL+"dy.php?action=get_message&mesaj_id="+mesaj_id);
		RequestManager.getInstance().startRequest(rqid);
		return rqid;
	} 	
	
	/**
	 * @param the index of the request 
	 * @desc Remove widget from the queue
	 */
	this.removeWidget=function (managerIndex)
	{
		RequestManager.getInstance().removeRequest(managerIndex);		
		self.reqWidgetQueue[managerIndex]=null;
	}

	this.setSexFilter = function (filter)
	{
		_e("sex_filter_"+this.sexFilter).className = "";
		_e("sex_filter_"+this.sexFilter).setAttribute("class","");
		
		_e("sex_filter_"+filter).className = "selected";
		_e("sex_filter_"+filter).setAttribute("class","selected");
		
		this.sexFilter = filter;
		_e("sex").value = filter;
		
		this.setSearchText();
	}
	
	this.setSortFilter = function (filter)
	{
		_e("sort_filter_"+this.sortFilter).className = "";
		_e("sort_filter_"+this.sortFilter).setAttribute("class","");
		
		_e("sort_filter_"+filter).className = "selected";
		_e("sort_filter_"+filter).setAttribute("class","selected");
		
		this.sortFilter = filter;
		_e("sort").value = filter;
		
		this.setSearchText();
	}
	
	this.setSearchText = function ()
	{
		var text = "Cauta "
		//sex
		switch (_e('sex').value)
		{
			case "1" : text += "<b>baieti</b> "; break;
			case "2" : text += "<b>fete</b> "; break;
			default : text += "<b>fete si baieti</b> "; break;
		}
		
		var age_from = _e('age_from').value;
		var age_to = _e('age_to').value;
		
		if(age_from!="")
		{
			if(age_to!="") text += "cu varsta cuprinsa intre <b>"+age_from+" si "+age_to+" ani </b>";
			else  text += "cu varsta <b>mai mare de "+age_from+" ani</b> ";
		}
		else
		if(age_to!="") text += "cu varsta <b>pana la "+age_to+" ani</b> ";
		
		if(_e("zodia").selectedIndex>0)
		{
			text += "nascuti in zodia <b>"+_e("zodia").options[_e("zodia").selectedIndex].innerHTML+"</b> ";
		}
		
		if(_e("judetul").selectedIndex>0)
		{
			text += "si locuiesc in judetul <b>"+_e("judetul").options[_e("judetul").selectedIndex].innerHTML+"</b> ";
		}
		
		if(_e('has_picture').checked)
		{
			text += "care <b>au poza</b> ";
		}
		
		text += "sortati dupa ";
		switch (_e('sort').value)
		{
			case "1" : text += "<b>varsta</b> "; break;
			case "2" : text += "<b>ultima logare</b> "; break;
			default : text += "<b>data inregistrarii</b> "; break;
		}
		
		text += ".";
		_e("explain").innerHTML = text;
		_e("search_string").value = text;  
	}
	
	this.getPage = function (page)
	{
		var inputReff = _e("curr_page");
		
		if(page>0)
		{
			inputReff.value = page;
			_e("search_form").submit();
		}
		
		return true;
	}
}


Search.__instance__=null;

Search.getInstance=function()
{
	if(Search.__instance__==null)
	{
		Search.__instance__=new Search();
	}
	return Search.__instance__;
}
