var Partner = Class.create({	initialize: function() {		if (!$('jsondata'))			return;		this.ct = $('contentarea');		this.url = 'index.php';		this.per_page = 15;		this.page = 1;		this.max_dim = {x: 300, y: 50};		this.filter = {postleitzahl: '', ort: '', firma: ''};		this.empty_content = {postleitzahl: 'einer PLZ', ort: 'einem Ort', firma: 'einer Firma'};		this.data = $('jsondata').innerHTML.replace(/#:#/g, '').evalJSON();		this.minChars = 2;		$('jsondata').remove();				if (navigator && navigator.geolocation) {			//navigator.geolocation.getCurrentPosition(this.show_position.bind(this));		}				this.ct.setStyle({marginTop: '10px'});				this.ct.insert({			before: Builder.node('div', {					id: 'filter-form',					style: 'width: 95%; height:50px;'			}, [Builder.node('span', {style: 'font-size: 1.1em;'}, 'Suchen Sie nach (Mindesteingabe: '+this.minChars+' Zeichen) ...'), Builder.node('br')])		});				this.ff = $('filter-form');		this.ff.insert({			bottom: Builder.node('input', {				id: 'filter-postleitzahl',				value: this.empty_content.postleitzahl,				className: 'pl_benu filter filter-empty',				style: 'margin-right: 20px;'			})		});				this.ff.insert({			bottom: Builder.node('input', {				id: 'filter-ort',				value: this.empty_content.ort,				className: 'pl_benu filter filter-empty',				style: 'margin-right: 20px;'			})		});				this.ff.insert({			bottom: Builder.node('input', {				id: 'filter-firma',				value: this.empty_content.firma,				className: 'pl_benu filter filter-empty',				style: 'margin-right: 20px;'			})		});				$$('.filter-empty').each(function(s) {			Event.observe(s, 'keyup', function() {				if(window.mytimeout) 					window.clearTimeout(window.mytimeout);				window.mytimeout = window.setTimeout(this.set_filter.bind(this), 400);			}.bind(this));			Event.observe(s, 'focus', this.filter_focus_handler.curry(s).bind(this));			Event.observe(s, 'blur', this.filter_blur_handler.curry(s).bind(this));		}.bind(this));						this.ct.insert({			before: Builder.node('span', {					id: 'filter-result-num',					style: 'float: left; font-size: 1.1em;'			})		});				this.ct.insert({			before: Builder.node('span', {					id: 'pagination',					style: 'float: right; font-size: 1.1em;'			})		});		this.ct.insert({			before: Builder.node('br', {					style: 'clear: both'			})		});						if (typeof(pl_benu) != 'undefined' && pl_benu.length > 0) {			$('filter-postleitzahl').value = pl_benu;			this.set_filter();		}						this.show_page.curry(this.page, this.filter).bind(this)();	},		show_page: function(page, filter) {		this.ct.childElements().invoke('remove');			this.filter = filter;				var fdata = this.data;		if (this.filter.postleitzahl.length < this.minChars		    && this.filter.ort.length < this.minChars		    && this.filter.firma.length < this.minChars) {		  fdata = new Array();		}					if (!this.filter_empty()) {			if (!this.filter.postleitzahl.empty()) {				fdata = fdata.findAll(function(s) {					return (s.postleitzahl+'').startsWith(this.filter.postleitzahl);				}.bind(this));			}						if (!this.filter.ort.empty()) {				fdata = fdata.findAll(function(s) {					return new String(s.ort).toLowerCase().indexOf(this.filter.ort.toLowerCase()) != -1;				}.bind(this));			}						if (!this.filter.firma.empty()) {				fdata = fdata.findAll(function(s) {					return s.firma.toLowerCase().indexOf(this.filter.firma.toLowerCase()) != -1;				}.bind(this));			}								}				var f_length = fdata.length;		var f_total_pages = Math.ceil(f_length/this.per_page);		this.page = page;				$('filter-result-num').update(f_length+' Treffer, Filter: '+this.get_filter_string());				$('pagination').childElements().invoke('remove');		if (f_total_pages > 0) {			$('pagination').update('<a href="#" id="page-prev" class="subnav_content">&laquo;</a>&nbsp;&nbsp;Seite '+this.page+' von '+f_total_pages+'&nbsp;&nbsp;<a class="subnav_content" href="#" id="page-next">&raquo;</a>');		} else {			return;		}		if (this.page > 1)			Event.observe('page-prev', 'click', this.page_prev.bind(this));				if (this.page < f_total_pages)			Event.observe('page-next', 'click', this.page_next.bind(this));				var start = (this.page-1)*this.per_page;		var end = Math.min(start+this.per_page, f_length);				for (var i = start; i < end; i++) {			var d = Builder.node('div', {				id: 'partner-'+fdata[i].id,				className: 'normal_font_grau partner-box'			});			this.ct.insert(d);			//workaround for msie			d = $('partner-'+fdata[i].id);				d.update('<div class="partner-image"></div><div class="partner-info">'+						(!S_IS_SECUREPOINT ? fdata[i].firma : '<a href="?addentry=1&edit='+fdata[i].id+'">'+fdata[i].firma+'</a>')+					  '<br /><br />'+fdata[i].vorname+' '+fdata[i].nachname+'<br />'+fdata[i].strasse+'<br />'+fdata[i].postleitzahl+' '+fdata[i].ort+'</div><br style="clear:both" />');						//right column			//d.down('.partner-image').insert({bottom: '<img src="images/check.gif" alt="Ihr Logo" />'});						var im = new Image(); 			im.onerror = this.load_img.curry('error', fdata[i].id, im).bind(this); 			im.onload = this.load_img.curry('load', fdata[i].id, im).bind(this);							var ct = $('partner-'+fdata[i].id).down('.partner-image');			ct.insert({top: im});			im.id = 'logo-'+fdata[i].id;			im.src = 'images/logo-'+fdata[i].id+'.jpg';			im.alt = fdata[i].id;						var br = '<br /><br style="clear:both" />';			if (!fdata[i].land.empty() && fdata[i].land != 'None') {				d.down('.partner-info').insert({bottom: br+'<div class="left-col">'+fdata[i].land+'</div>'});				br = '<br style="clear:both" />';			}									//left column			var br = '<br /><br style="clear:both" />';			if (!fdata[i].webseite.empty()) {				fdata[i].webseite = fdata[i].webseite.toLowerCase();				if (!fdata[i].webseite.startsWith('http://'))					fdata[i].webseite = 'http://'+fdata[i].webseite;				d.down('.partner-image').insert({bottom: br+'<div class="left-col">Website:</div><div class="right-col"><a class="normal_font_black" href="'+fdata[i].webseite+'">'+fdata[i].webseite+'</a></div>'});				br = '<br style="clear:both" />';			}						if (!fdata[i].email.empty()) {				fdata[i].email = fdata[i].email.toLowerCase();				d.down('.partner-image').insert({bottom: br+'<div class="left-col">Email:</div><div class="right-col"> <a class="normal_font_black" href="mailto:'+this.rot_13(fdata[i].email)+'">Email</a></div>'});				br = '<br style="clear:both" />';			}			if (!new String(fdata[i].telefon).empty()) {				d.down('.partner-image').insert({bottom: br+'<div class="left-col">Telefon:</div><div class="right-col">'+fdata[i].telefon+'</div>'});				br = '<br style="clear:both" />';			}			if (!new String(fdata[i].faxnummer).empty()) {				d.down('.partner-image').insert({bottom: br+'<div class="left-col">Fax:</div><div class="right-col">'+fdata[i].faxnummer+'</div>'});				br = '<br style="clear:both" />';			}						//and another one for IE -.-			if (Prototype.Browser.IE) {				d.setStyle({height: '50px'});			}		}				$$('.mailrot').each(function(s) {			Event.observe(s, 'click', function(e) {				window.location = 'mailto:'+this.rot_13(s.href.substr(7));				e.stop();			}.bind(this));						Event.observe(s, 'contextmenu', function(e) {				alert('Bitte oeffnen sie diesen Link in ihrem Email-Client, um eine gueltige Mail-Addresse zu erhalten.');				e.stop();			}.bind(this));		}.bind(this));	},		load_img: function(state, id, im, ev) {		im.onload = Prototype.emptyFunction;		im.onerror = Prototype.emptyFunction;						im = $('logo-'+id);		if (!im) {		  //window.setTimeout(this.load_img.curry(state, id, im, ev).bind(this), 200);		  return;		}				//XXX remove this in an live anvironment		if (S_IS_SECUREPOINT === true)			Event.observe(im, 'dblclick', this.get_logo.curry(id).bind(this));				if (state == 'error') {			im.src = 'images/spacer.gif';			im.setStyle({width: this.max_dim.x+'px', height: this.max_dim.y+'px'});		}					//im.setStyle({height: '50px', width: '250px'});		var ct = im.up('.partner-image');				//we assume the image is wider than tall :P		var x = im.getWidth();		var y = im.getHeight();				if (x > this.max_dim.x) {			var c = this.max_dim.x/x;			x = Math.floor(this.max_dim.x);			y = Math.floor(y*c);					}		if (y > this.max_dim.y) {			var c = this.max_dim.y/y;			y = Math.floor(this.max_dim.y);			x = Math.floor(x*c);					}		if (parseInt(x) < 20 || parseInt(y) < 20) {			x = this.max_dim.x;			y = this.max_dim.y;		}		im.setStyle({width: x+'px', height: y+'px'});		//certified partner?		var p = this.data.find(function(s) {			return s.id == id;		});				var cert_ct = $('partner-'+id).down('.partner-info');		switch (p.lizensiert) {			case '1':			case 1:			case 99:			  cert_ct.setStyle({backgroundImage: 'url(images/certified.gif)', backgroundPosition: '100% 50%', backgroundRepeat: 'no-repeat'});			  break;			case '1':			case 1:				var l = Builder.node('div', {					id: 'certified-'+id,					style: 'background-image: url(images/certified.gif); background-position: bottom right; background-repeat: no-repeat;'				});								//XXX remove this in an live anvironment				Event.observe(l, 'dblclick', this.get_logo.curry(id).bind(this));							ct.insert({top: l});								//i hate msie				l = $('certified-'+id);				l.absolutize();				l.clonePosition(im);				break;			default:				break;		}	},		get_logo: function(id) {		var logo = prompt("Geben Sie die URL des Logos ein:", "");		if (logo && !logo.empty()) {			logo = logo.substr(logo.indexOf('http://')+7);			new Ajax.Request(				this.url,				{					parameters: {mode: 'getlogo', ajax: 1, url: logo, id: id},					onComplete: function(r) {											}				}			);		}	},		show_position: function(position) {			},		set_filter: function() {		var plz = ($F('filter-postleitzahl') == this.empty_content.postleitzahl) ? '' : $F('filter-postleitzahl');		var ort = ($F('filter-ort') == this.empty_content.ort) ? '' : $F('filter-ort');		var firma = ($F('filter-firma') == this.empty_content.firma) ? '' : $F('filter-firma');		this.filter = {postleitzahl: plz, ort: ort, firma: firma};		this.page = 1;		this.show_page(this.page, this.filter);	},		filter_focus_handler: function(el,ev) {		var f = el.id.substr(el.id.indexOf('-')+1);		if (el.value == this.empty_content[f])			el.value = '';				el.removeClassName('filter-empty');	},		filter_blur_handler: function(el, ev) {		if ($F(el).length == 0) {			var f = el.id.substr(el.id.indexOf('-')+1);			el.value = this.empty_content[f];			el.addClassName('filter-empty');		}	},		page_prev: function() {		this.show_page(this.page-1, this.filter);	},		page_next: function() {		this.show_page(this.page+1, this.filter);	},		filter_empty: function() {		return this.filter.postleitzahl.empty() && this.filter.ort.empty() && this.filter.firma.empty();	},		get_filter_string: function() {		var ret = '';		if (!this.filter.postleitzahl.empty())			ret += '  +PLZ '+this.filter.postleitzahl+'...';		if (!this.filter.ort.empty())			ret += '  +Ort '+this.filter.ort;		if (!this.filter.firma.empty())			ret += '  +Firma '+this.filter.firma;					if (ret.empty())			ret = '-keiner-';		return ret; 	},		rot_13: function(t) {		var keycode	= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";		var text	= t;		var textrot	= new String();		for(var i = 0; i < text.length; i++)		{			var codechar = text.substring(i, i + 1);			var pos = keycode.indexOf(codechar.toUpperCase());			if(pos >= 0)			{				pos = (pos + keycode.length / 2) % keycode.length;				codechar = (codechar == codechar.toUpperCase()) ? keycode.substring(pos, pos + 1) : keycode.substring(pos, pos + 1).toLowerCase();			}			textrot	= textrot + codechar;		}		return textrot;	}});