/**
	@name EURIPYPSearchClass
	@version 1.1
	@copyright 2011 EURIP.com
**/
var EURIPYPSearchClass = Class.create(EURIPYPAjaxClass,{
	ConfigLocal: {
		divsearch:false,
		divsearchcategories:false,
		divsearchdetails:false,
		divresult:false,
		containerresult:false,
		formname:'formypsearch',
		formobj:false,
		searchphrase:''},
	TemplateLocal: $H({"top":false,"row":false,"bottom":false,"empty":false}),

//	EURIPYPSearch Constructor
	initialize: function() {
	  },

//	loadTemplate
	loadTemplate: function(template) {
		if (typeof(template)=='string' && template=='big')  {
		  	this.TemplateLocal['top']		= new Template('<fieldset><legend>#{count} Ergebnis(se)</legend>');
		  	this.TemplateLocal['row']		= new Template('<a class=\"location\" href=\"/yp/entry/#{country}-#{type}/#{city_print}/#{name_print}-id-#{id}.html">#{name}</a><div class=\"small\" style=\"text-align:left\">#{category} in #{city_name}<br>&nbsp;</div>');
		  	this.TemplateLocal['rowc']		= new Template('<a class=\"box\" href=\"javascript:void(0)\" onClick=\"#{dynjs}\">#{name}</a><div class=\"status_#{status}\" style=\"text-align:left\">#{city_name}<br>#{category}</div>');
		  	this.TemplateLocal['bottom']	= new Template('</fieldset');
		  	this.TemplateLocal['empty']		= new Template('<div>keine Treffer</b></div>');
			}
		else  {
			this.TemplateLocal['top']		= new Template('<fieldset class="css3radius css3shadowbox"><legend>#{count} Ergebnis(se)</legend><div style="width:auto;height:20px;background:url(/imglib/bt/20/close.png) no-repeat top right;cursor:pointer;" onClick="EURIPYPSearch.resetResults()">&nbsp;</div>');
		  	this.TemplateLocal['row']		= new Template('<a class=\"location\" href=\"/yp/entry/#{country}-#{type}/#{city_print}/#{name_print}-id-#{id}.html">#{name}</a><div class=\"location_d\">#{category} in #{city_name}<br>&nbsp;</div>');
		  	this.TemplateLocal['rowc']		= new Template('<a class=\"box\" href=\"javascript:void(0)\" onClick=\"#{dynjs}\">#{name}</a><div class=\"status_#{status}\" style=\"text-align:left\">#{city_name}<br>#{category}</div>');
		  	this.TemplateLocal['bottom']	= new Template('</fieldset');
		  	this.TemplateLocal['empty']		= new Template('<div>keine Treffer</b></div>');
		  }
	  },

//	setTemplate
	setTemplate: function(templateid,templatedata) {
		if (typeof(templateid)=='string' && typeof(templatedata)=='string')  {
			this.TemplateLocal[templateid] = new Template(templatedata);
			}
	  },

//	formInit
	formInit: function(searchcontainer,resultcontainer) {
		if (typeof(searchcontainer) == 'string')  {
			this.ConfigLocal.divsearch = searchcontainer;
			this.ConfigLocal.containersearch = $(searchcontainer);
			if (!this.ConfigLocal.containersearch)  {
				this.formInitERROR();
				return false;
				}
			FORCERAjax.UpdateDiv(this.ConfigLocal.divsearch,this.ConfigAjax.urlformsearch,{'parameters':$H({"width":'99%',"onsubmit":'EURIPYPSearch.formSearch'})},'EURIPYPSearch.formInitOK','EURIPYPSearch.formInitERROR','div');
			}
		if (typeof(resultcontainer) == 'string')  {
			this.ConfigLocal.divresult = resultcontainer;
			this.ConfigLocal.containerresult = $(resultcontainer);
			if (!this.ConfigLocal.containerresult)  {
				this.formInitERROR();
				return false;
				}
			}
		this.loadTemplate();
		return true;
		},

//	formInitOK
	formInitOK: function() {
		this.ConfigLocal.containerresult = $(this.ConfigLocal.divresult);
		if (!this.ConfigLocal.containerresult)  {
			this.formInitERROR();
			return false;
			}
		},

//	formInitERROR
	formInitERROR: function() {
		FORCERWindow.OpenAlert('Systemerror occured','error','ok');
		},


//	searchChanges
	searchChanges: function() {
		FORCERAjax.RequestData('js',this.ConfigAjax.urlsearchchanges,{'parameters':$H({})},'EURIPYPSearch.searchChangesOK','EURIPYPSearch.searchChangesERROR','overlay');
		},

//	searchChangesOK
	searchChangesOK: function(data) {
		try  {data = eval(data.responseText);}
		catch(data)  {data = false;}
		this.ConfigLocal.containerresult = $(this.ConfigLocal.divresult);
		if (typeof(data) != 'object' || !this.ConfigLocal.containerresult)  {
			FORCERWindow.OpenAlert('Systemerror occured','error','ok');
			return false;
			}
		var datastats = {count:data.length};
		var	output = this.TemplateLocal['top'].evaluate(datastats);
		if (data.length < 1) {
			output += this.TemplateLocal['empty'].evaluate(datastats);
			}
		else {
			for (var index = 0; index < data.length; ++index) {
				var item = data[index];
				var outputrow = this.TemplateLocal['rowc'].evaluate(item);
				output += outputrow;
				}
			}
		output += this.TemplateLocal['bottom'].evaluate(datastats);
		this.ConfigLocal.containerresult.update(output);
		return true;
		},

//	searchChangesERROR
	searchChangesERROR: function() {
		FORCERWindow.OpenAlert('Systemerror occured','error','ok');
		},

//		searchChanges
	searchDeletes: function() {
		FORCERAjax.RequestData('js',this.ConfigAjax.urlsearchdeletes,{'parameters':$H({})},'EURIPYPSearch.formSearchResult','EURIPYPSearch.formSearchERROR','overlay');
		},

//	formSearch
	formSearch: function() {
		FORCERAjax.sendForm(this.ConfigLocal.formname,'EURIPYPSearch.formSearchResult','EURIPYPSearch.formSearchERROR','overlay');
		return false;
		},

//	doSearch
	doSearch: function(searchdata) {
		this.ConfigLocal.containerresult.update(this.DefaultContainer.loadingimg);
		FORCERAjax.RequestData(false,this.ConfigAjax.urlsearch,{"parameters":$H(searchdata)},'EURIPYPSearch.formSearchResult','EURIPYPSearch.formSearchERROR',false);
		},

//	formSearchResult
	formSearchResult: function(data) {
		try  {data = eval(data.responseText);}
		catch(data)  {data = false;}
		this.ConfigLocal.containerresult = $(this.ConfigLocal.divresult);
		if (typeof(data) != 'object' || !this.ConfigLocal.containerresult)  {
			if (currfieldmsg = $('search_js_yp_system')) {
				FORCERWindow.OpenAlert(currfieldmsg.innerHTML,'error','ok');
				}
			else  {
				FORCERWindow.OpenAlert('Systemerror occured','error','ok');
				}
			return false;
			}
		var datastats = {searchphrase: this.ConfigLocal.searchphrase,count:data.length};
		var	output = this.TemplateLocal['top'].evaluate(datastats);
		if (data.length < 1) {
			output += this.TemplateLocal['empty'].evaluate(datastats);
			}
		else {
			for (var index = 0; index < data.length; ++index) {
				var item = data[index];
				var outputrow = this.TemplateLocal['row'].evaluate(item);
				output += outputrow;
				}
			}
		output += this.TemplateLocal['bottom'].evaluate(datastats);
		this.ConfigLocal.containerresult.update(output);
		return true;
		},

//	formSearchOK
	formSearchOK: function() {
		return false;
		},

//	formSearchERROR
	formSearchERROR: function() {
		FORCERWindow.OpenAlert('Systemerror occured','error','ok');
		return false;
		},

//	formCategoriesInit
	formCategoriesInit: function(targetdiv,searchcfg,detailsdiv) {
		if (typeof(searchcfg)!="object")  {return false;}
		this.ConfigLocal.divsearchcategories = targetdiv;
		if (detailsdiv) {
			this.ConfigLocal.divsearchdetails = detailsdiv;
			this.ConfigLocal.lastType = searchcfg.type;
			FORCERAjax.UpdateDiv(this.ConfigLocal.divsearchcategories,this.ConfigAjax.urlformsearchcategories,{"parameters":$H(searchcfg)},'EURIPYPSearch.formDetailsInit','EURIPYPSearch.formDetailsInitERROR','divimg');
			}
		else {
			FORCERAjax.UpdateDiv(this.ConfigLocal.divsearchcategories,this.ConfigAjax.urlformsearchcategories,{"parameters":$H(searchcfg)},'EURIPYPSearch.formDetailsInitOK','EURIPYPSearch.formDetailsInitERROR','divimg');
			}
		return true;
		},

//	formDetailsInit
	formDetailsInit: function() {
		if (typeof(this.ConfigLocal.lastType)!="string" || typeof(this.ConfigLocal.divsearchdetails)!="string")  {return false;}
		FORCERAjax.UpdateDiv(this.ConfigLocal.divsearchdetails,this.ConfigAjax.urlformsearchdetails+this.ConfigLocal.lastType+'.html',false,false,false,'divimg');
		return true;
		},

//	formInitOK
	formDetailsInitOK: function() {
		},

//	formDetailsInitERROR
	formDetailsInitERROR: function() {
		},

//	resetResults
	resetResults: function() {
		this.ConfigLocal.containerresult.update();
		}
	});
var EURIPYPSearch = new EURIPYPSearchClass();

