var FX_Form_ResizableTextbox=Class.create({options:$H({min:5,max:500,step:7}),initialize:function(element,options){var that=this;this.options.update(options);this.el=$(element);this.width=this.el.offsetWidth;this.el.observe('keyup',function(){var newsize=that.options.get('step')*$F(this).length;if(newsize<=that.options.get('min'))newsize=that.width;if(!($F(this).length==this.retrieveData('rt-value')||newsize<=that.options.min||newsize>=that.options.max))
this.setStyle({'width':newsize});}).observe('keydown',function(){this.cacheData('rt-value',$F(this).length);});}});var FX_Form_TextBoxList=Class.create({options:$H({resizable:{},className:'bit',separator:'###',extrainputs:true,startinput:true,hideempty:true,fetchFile:undefined,results:10,wordMatch:false}),initialize:function(element,options){this.options.update(options);this.element=$(element).hide();this.bits=new Hash();this.events=new Hash();this.count=0;this.current=false;this.maininput=this.createInput({'class':'maininput'});this.holder=new Element('ul').insert(this.maininput).addClassName('holder');this.element.insert({'before':this.holder});this.holder.observe('click',function(event){event.stop();if(this.maininput!=this.current)this.focus(this.maininput);}.bind(this));this.makeResizable(this.maininput);this.setEvents();},setEvents:function(){document.observe(Prototype.Browser.IE?'keydown':'keypress',function(e){if(!this.current)return;if(this.current.retrieveData('type')=='box'&&e.keyCode==Event.KEY_BACKSPACE)e.stop();}.bind(this));document.observe('keyup',function(e){e.stop();if(!this.current)return;switch(e.keyCode){case Event.KEY_LEFT:return this.move('left');case Event.KEY_RIGHT:return this.move('right');case Event.KEY_DELETE:case Event.KEY_BACKSPACE:return this.moveDispose();}}.bind(this)).observe('click',function(){document.fire('blur');}.bindAsEventListener(this));},update:function(){this.element.value=this.bits.values().join(this.options.get('separator'));return this;},add:function(text,html){var id=this.options.get('className')+'-'+this.count++;var el=this.createBox($pick(html,text),{'id':id});(this.current||this.maininput).insert({'before':el});el.observe('click',function(e){e.stop();this.focus(el);}.bind(this));this.bits.set(id,text.value);if(this.options.get('extrainputs')&&(this.options.get('startinput')||el.previous()))this.addSmallInput(el,'before');return el;},addSmallInput:function(el,where){var input=this.createInput({'class':'smallinput'});el.insert({}[where]=input);input.cacheData('small',true);this.makeResizable(input);if(this.options.get('hideempty'))input.hide();return input;},dispose:function(el){this.bits.unset(el.id);if(el.previous()&&el.previous().retrieveData('small'))el.previous().remove();if(this.current==el)this.focus(el.next());if(el.retrieveData('type')=='box')el.onBoxDispose(this);el.remove();return this;},focus:function(el,nofocus){if(!this.current)el.fire('focus');else if(this.current==el)return this;this.blur();el.addClassName(this.options.get('className')+'-'+el.retrieveData('type')+'-focus');if(el.retrieveData('small'))el.setStyle({'display':'block'});if(el.retrieveData('type')=='input'){el.onInputFocus(this);if(!nofocus)this.callEvent(el.retrieveData('input'),'focus');}
else el.fire('onBoxFocus');this.current=el;return this;},blur:function(noblur){if(!this.current)return this;if(this.current.retrieveData('type')=='input'){var input=this.current.retrieveData('input');if(!noblur)this.callEvent(input,'blur');input.onInputBlur(this);}
else this.current.fire('onBoxBlur');if(this.current.retrieveData('small')&&!input.get('value')&&this.options.get('hideempty'))
this.current.hide();this.current.removeClassName(this.options.get('className')+'-'+this.current.retrieveData('type')+'-focus');this.current=false;return this;},createBox:function(text,options){return new Element('li',options).addClassName(this.options.get('className')+'-box').update(text.caption).cacheData('type','box');},createInput:function(options){var li=new Element('li').addClassName(this.options.get('className')+'-input');var el=new Element('input',Object.extend(options,{'type':'text'}));el.observe('click',function(e){e.stop();}).observe('focus',function(e){if(!this.isSelfEvent('focus'))this.focus(li,true);}.bind(this)).observe('blur',function(){if(!this.isSelfEvent('blur'))this.blur(true);}.bind(this)).observe('keydown',function(e){this.cacheData('lastvalue',this.value).cacheData('lastcaret',this.getCaretPosition());});var tmp=li.cacheData('type','input').cacheData('input',el).insert(el);return tmp;},callEvent:function(el,type){this.events.set(type,el);el[type]();},isSelfEvent:function(type){return(this.events.get(type))?!!this.events.unset(type):false;},makeResizable:function(li){var el=li.retrieveData('input');el.cacheData('resizable',new FX_Form_ResizableTextbox(el,Object.extend(this.options.get('resizable'),{min:el.offsetWidth,max:(this.element.getWidth()?this.element.getWidth():0)})));return this;},checkInput:function(){var input=this.current.retrieveData('input');return(!input.retrieveData('lastvalue')||(input.getCaretPosition()===0&&input.retrieveData('lastcaret')===0));},move:function(direction){var el=this.current[(direction=='left'?'previous':'next')]();if(el&&(!this.current.retrieveData('input')||((this.checkInput()||direction=='right'))))this.focus(el);return this;},moveDispose:function(){if(this.current.retrieveData('type')=='box')return this.dispose(this.current);if(this.checkInput()&&this.bits.keys().length&&this.current.previous())return this.focus(this.current.previous());}});Element.addMethods({getCaretPosition:function(){if(this.createTextRange){var r=document.selection.createRange().duplicate();r.moveEnd('character',this.value.length);if(r.text==='')return this.value.length;return this.value.lastIndexOf(r.text);}else return this.selectionStart;},cacheData:function(element,key,value){if(Object.isUndefined(this[$(element).identify()])||!Object.isHash(this[$(element).identify()]))
this[$(element).identify()]=$H();this[$(element).identify()].set(key,value);return element;},retrieveData:function(element,key){return this[$(element).identify()].get(key);}});function $pick(){for(var B=0,A=arguments.length;B<A;B++){if(!Object.isUndefined(arguments[B])){return arguments[B];}}return null;};var FX_Form_MultiList=Class.create(FX_Form_TextBoxList,{loptions:$H({autocomplete:{'opacity':0.8,'maxresults':10,'minchars':1}}),initialize:function($super,element,autoholder,options,func){$super(element,options);this.data=[];this.autoholder=$(autoholder).setOpacity(this.loptions.get('autocomplete').opacity);this.autoholder.observe('mouseover',function(){this.curOn=true;}.bind(this)).observe('mouseout',function(){this.curOn=false;}.bind(this));this.autoresults=this.autoholder.select('ul').first();var children=this.autoresults.select('li');children.each(function(el){this.add({value:el.readAttribute('value'),caption:el.innerHTML});},this);},autoShow:function(search){this.autoholder.setStyle({'display':'block'});this.autoholder.descendants().each(function(e){e.hide()});if(!search||!search.strip()||(!search.length||search.length<this.loptions.get('autocomplete').minchars))
{if(this.autoholder.select('.default').first()!=null){this.autoholder.select('.default').first().setStyle({'display':'block'});}
this.resultsshown=false;}else{this.resultsshown=true;this.autoresults.setStyle({'display':'block'}).update('');if(this.options.get('wordMatch'))
var regexp=new RegExp("(^|\\s)"+search,'i')
else
var regexp=new RegExp(search,'i')
var count=0;this.data.filter(function(str){return str?regexp.test(str.evalJSON(true).caption):false;}).each(function(result,ti){count++;if(ti>=this.loptions.get('autocomplete').maxresults)return;var that=this;var el=new Element('li');el.observe('click',function(e){e.stop();that.autoAdd(this);}).observe('mouseover',function(){that.autoFocus(this);}).update(this.autoHighlight(result.evalJSON(true).caption,search));this.autoresults.insert(el);el.cacheData('result',result.evalJSON(true));if(ti==0)this.autoFocus(el);},this);}
if(count>this.options.get('results'))
this.autoresults.setStyle({'height':(this.options.get('results')*24)+'px'});else
this.autoresults.setStyle({'height':(count?(count*24):0)+'px'});return this;},autoHighlight:function(html,highlight){return html.gsub(new RegExp(highlight,'i'),function(match){return'<em>'+match[0]+'</em>';});},autoHide:function(){this.resultsshown=false;this.autoholder.hide();return this;},autoFocus:function(el){if(!el)return;if(this.autocurrent)this.autocurrent.removeClassName('auto-focus');this.autocurrent=el.addClassName('auto-focus');return this;},autoMove:function(direction){if(!this.resultsshown)return;this.autoFocus(this.autocurrent[(direction=='up'?'previous':'next')]());this.autoresults.scrollTop=this.autocurrent.positionedOffset()[1]-this.autocurrent.getHeight();return this;},autoFeed:function(text){if(this.data.indexOf(Object.toJSON(text))==-1)
this.data.push(Object.toJSON(text));return this;},autoAdd:function(el){if(!el||!el.retrieveData('result'))return;this.add(el.retrieveData('result'));delete this.data[this.data.indexOf(Object.toJSON(el.retrieveData('result')))];this.autoHide();var input=this.lastinput||this.current.retrieveData('input');input.clear().focus();return this;},createInput:function($super,options){var li=$super(options);var input=li.retrieveData('input');input.observe('keydown',function(e){this.dosearch=false;switch(e.keyCode){case Event.KEY_UP:e.stop();return this.autoMove('up');case Event.KEY_DOWN:e.stop();return this.autoMove('down');case Event.KEY_RETURN:e.stop();if(!this.autocurrent)break;this.autoAdd(this.autocurrent);this.autocurrent=false;this.autoenter=true;break;case Event.KEY_ESC:this.autoHide();if(this.current&&this.current.retrieveData('input'))
this.current.retrieveData('input').clear();break;default:this.dosearch=true;}}.bind(this));input.observe('keyup',function(e){switch(e.keyCode){case Event.KEY_UP:case Event.KEY_DOWN:case Event.KEY_RETURN:case Event.KEY_ESC:break;default:if(!Object.isUndefined(this.options.get('fetchFile'))){new Ajax.Request(this.options.get('fetchFile'),{parameters:{keyword:input.value},onSuccess:function(transport){transport.responseText.evalJSON(true).each(function(t){this.autoFeed(t)}.bind(this));this.autoShow(input.value);}.bind(this)});}
else
if(this.dosearch)this.autoShow(input.value);}}.bind(this));input.observe(Prototype.Browser.IE?'keydown':'keypress',function(e){if(e.keyCode==Event.KEY_RETURN&&this.autoenter)e.stop();this.autoenter=false;}.bind(this));return li;},createBox:function($super,text,options){var li=$super(text,options);li.observe('mouseover',function(){this.addClassName('bit-hover');}).observe('mouseout',function(){this.removeClassName('bit-hover')});var a=new Element('a',{'href':'#'});a.addClassName('closebutton');a.observe('click',function(e){e.stop();if(!this.current)this.focus(this.maininput);this.dispose(li);}.bind(this));li.insert(a).cacheData('text',Object.toJSON(text));return li;}});Element.addMethods({onBoxDispose:function(item,obj){obj.autoFeed(item.retrieveData('text').evalJSON(true));},onInputFocus:function(el,obj){obj.autoShow();},onInputBlur:function(el,obj){obj.lastinput=el;if(!obj.curOn){obj.blurhide=obj.autoHide.bind(obj).delay(0.1);}},filter:function(D,E){var C=[];for(var B=0,A=this.length;B<A;B++){if(D.call(E,this[B],B,this)){C.push(this[B]);}}return C;}});;var FX_Form_Element_Abstract=Class.create({initialize:function(f,d){if(d.name!=undefined)this.setName(d.name);if(d.value!=undefined)this.setValue(d.value);if(d.width!=null)this.setWidth(d.width);if(d.height!=null)this.setHeight(d.height);if(d.input!=undefined)this.setInput(d.input);if(d.label!=undefined)this.setLabel(d.label);this.setType(d.type);this.setOptions(d);this.setForm(f);},setOptions:function(o){this._options=o;},getOptions:function(){return this._options;},setForm:function(f){this._form=f;},getForm:function(){return this._form;},setWidth:function(w){this._width=w;},getWidth:function(){return this._width;},setHeight:function(h){this._height=h;},getHeight:function(){return this._height;},setValue:function(v){this._value=v;},getValue:function(){return(this._value==undefined)?null:this._value;},setInput:function(i){this._input=i;},getInput:function(){return this._input;},setLabel:function(l){this._label=l;},getLabel:function(){return this._label;},setName:function(n){this._name=n;},getName:function(){return this._name;},setType:function(t){this._type=t;},getType:function(){return this._type;},setErrorMessages:function(m){this._errorMessages=m;},getErrorMessages:function(){return this._errorMessages;},setElement:function(e){this._element=e;},getElement:function(){return this._element;},setup:function(){},isNumeric:function(strString){var strValidChars="0123456789.";var strChar;var blnResult=true;if(strString==null)return false;if(strString.length==0)return false;for(i=0;i<strString.length&&blnResult==true;i++)
{strChar=strString.charAt(i);if(strValidChars.indexOf(strChar)==-1)
{blnResult=false;}}
return blnResult;}});;var FX_Form_Element_TextInput=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){var attr={};if(this.isNumeric(o.width)){attr.size=o.width;attr.style='width:100%;';}else{attr.style='width:'+o.width;}
attr.type=o.password==true?'password':'text';attr.value=o.value;var i=new Element('input',attr);this.__input=i;i.observe('keypress',this.pressKeyHandler.bindAsEventListener(this));$super(f,o);var d=new Element('div').insert(i);this.setElement(d);},pressKeyHandler:function(e){if(e.type=='keypress'){if(e.keyCode!=13)return;}
e.stop();this.getForm().submitForm();},getValue:function(){return this.__input.value;},setValue:function(value){this.__input.setAttribute('value',value);},isNumeric:function(strString){var strValidChars="0123456789.";var strChar;var blnResult=true;if(strString==null)return false;if(strString.length==0)return false;for(i=0;i<strString.length&&blnResult==true;i++)
{strChar=strString.charAt(i);if(strValidChars.indexOf(strChar)==-1)
{blnResult=false;}}
return blnResult;}});;var FX_Form_Element_Submit=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){$super(f,o);var d=new Element('a');var params={};var i=new Element('span').insert(this.getLabel());Element.observe(i,'click',this.clickHandler.bindAsEventListener(this));d.insert(i).addClassName(o.cssclass);this.setElement(d);},clickHandler:function(event){this.getForm().submitForm();}});;var FX_Form_Element_TextArea=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){var attr={};if(this.isNumeric(o.width)){attr.cols=o.width;}else{attr.style='width:'+o.width+';height:auto;';}
attr.rows=o.height;var i=new Element('textarea',attr).update(o.value);if(o.autoSize){Element.observe(i,'keyup',this.resizeHandler.bindAsEventListener(this));}
this.__input=i;$super(f,o);var d=new Element('div').insert(i);this.setElement(d);},getValue:function(){return this.__input.value;},setValue:function(value){this.__input.update(value);},resizeHandler:function(event){while(this.__input.scrollTop>0){this.__input.rows+=2;}}});;var FX_Form_Element_SelectBox=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){var i=new Element('select');if(o.width!=undefined){i.setStyle({width:o.width});}
this.__input=i;if(o.label!=null){i.options[0]=new Option(o.label,'',false,o.value==null);}
for(var j in o.multiOptions){if(typeof o.multiOptions[j]=='function')continue;i.options[i.options.length]=new Option(o.multiOptions[j],j,false,j==o.value);}
$super(f,o);var d=new Element('div').insert(i);this.setElement(d);},getValue:function(){return this.__input.value;}});;var FX_Form_Element_PicUpload=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){window.fxapplication.addEventListener('unserort.form.element.PicUpload.change',this.picChanged,this);window.fxapplication.addEventListener('unserort.form.element.GalleryUpload.add',this.addPic,this);$super(f,o);var flashVarObject={};flashVarObject.uploadurl=o.uploadUrl;if(o.value!=null){}
flashVarObject.label=o.label;flashVarObject.description=o.description;var scr='swfobject.embedSWF("'+o.swfUrl+'", "picuploadcontainer", '+o.width+', 32, "9.0.0", "expressInstall.swf", '+Object.toJSON(flashVarObject)+', {allowScriptAccess:"always", wmode:"opaque"});';var d=new Element('div',{style:'width:'+o.width+'px;min-height:32px;'}).insert(new Element('div',{id:'picuploadcontainer',style:'width:'+o.width+'px;min-height:32px;'}).insert('<p>F&uuml;r den Fotoupload wird der <a href="http://get.adobe.com/flashplayer/" target="_blank">Adobe Flash Player</a> ben&ouml;tigt.</p>'));d.insert('<script type="text/javascript">'+scr+'</script>');if(o.value!=null&&o.value!=''){var cont=new Element('div',{'id':'pic-upload-img-container'});var delBtn=new Element('a');delBtn.addClassName('button');delBtn.insert('<span>x</span>');delBtn.observe('click',this.deleteElement.bindAsEventListener(this));var img=new Element('img',{'id':'pic-upload-image',src:o.value.url,'pid':o.value.id,'temp':o.value.temp?1:0});cont.insert(delBtn);cont.insert(img);d.insert(cont);}
this.__container=d;this.setElement(d);},addPic:function(e){var rem=$('pic-upload-img-container');if(rem!=null){rem.remove();}
var cont=new Element('div',{'id':'pic-upload-img-container'});var delBtn=new Element('a');delBtn.addClassName('button');delBtn.insert('<span>x</span>');var img=new Element('img',{'id':'pic-upload-image',src:e.data.url,'pid':e.data.id});cont.insert(delBtn);cont.insert(img);this.__container.insert(cont);this.setValue({id:e.data.id,temp:true,url:e.data.url});},deleteElement:function(e){this.setValue(null);var rem=$('pic-upload-img-container');if(rem!=null){rem.remove();}}});;var FX_Form_Element_Hidden=Class.create(FX_Form_Element_Abstract,{});;var FX_Form_Element_RadioButtonGroup=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){var template;if(o.template!=null){template=new Template(o.template);}else{template=new Template('<label><input type="radio" name="#{name}" value="#{value}" #{checked}/> #{label}</label><br/>');}
var d=new Element('div');for(var j in o.multiOptions){var tempValues={name:o.name,value:j,checked:j==o.value?'checked="checked"':''};if(typeof o.multiOptions[j]=='object'){Object.extend(tempValues,o.multiOptions[j]);}else{Object.extend(tempValues,{label:o.multiOptions[j]});}
d.insert(template.evaluate(tempValues));}
$super(f,o);this.setElement(d);},getValue:function(){var t=$(this.getForm().id).select('input[name="'+this.getName()+'"]');for(var i in t){if(typeof t[i]=='object'){if(t[i].checked){return t[i].value;}}}}});;var FX_Form_Element_LocationChooser=Class.create(FX_Form_Element_Abstract,{initZoom:12,geocoder:null,__marker:null,initialize:function($super,f,o){$super(f,o);var d=new Element('div',{style:'width:'+o.width+'px;'}).insert(new Element('div',{id:'locationchooser'}));this.setElement(d);d.insert('<div id="drag-container"></div><div class="rnd-green"><div><div><div><table style="width:'+o.width+'px;height:'+o.height+'px;" cellspacing="0" cellpadding="0"><tr><td style="width: '+(o.width-40)+'px;"><div id="map-chooser-controls"><div id="location-chooser-control-container" style="padding:8px;"></div></div><div id="map-chooser-container" style="height:'+o.height+'px;width:100%;"></div></td><td style="width:40px;vertical-align:top;text-align:center;"><a href="javascript:window.fxapplication.gmap.zoomIn()" title="Reinzoomen"><img src="'+o.iconUrl+'zoom_in.gif" style="padding-top:8px;" alt="Reinzoomen"/></a><a href="javascript:window.fxapplication.gmap.zoomOut()" title="Rauszoomen"><img src="'+o.iconUrl+'zoom_out.gif" style="padding-top:8px;" alt="Rauszoomen"/></a></td></tr></table></div></div></div></div>');return;},initMap:function(){var m=this.__map=window.fxapplication.gmap=new GMap2($('map-chooser-container'));var o=this.getOptions();m.setCenter(new google.maps.LatLng(o.initPosition.latitude,o.initPosition.longitude),this.initZoom);if(o.value!=null&&o.value!=''){this.addMarker(new GLatLng(o.value.latitude,o.value.longitude),o.value.icon);}
this.geocoder=new GClientGeocoder();this.geocoder.setBaseCountryCode('de');},setup:function(){var o=this.getOptions();var c=$('location-chooser-control-container');c.insert(new Element('div',{id:'drag-marker',style:'width:32px;'}).insert(new Element('img',{src:o.iconUrl+'marker/'+this.getOptions().icons[0]+".png"})));c.insert(new Element('p').insert('Ziehen Sie den Marker mit der Maus auf die Karte.'));c.insert(new Element('input',{type:'text',id:'geocode-input',style:'width:300px;'}).observe('keydown',this.enterQuery.bindAsEventListener(this)));c.insert(new Element('div').addClassName('h-spacer'));c.insert(new Element('a').addClassName('button').insert(new Element('span').insert('Suchen')).observe('click',this.searchLocation.bindAsEventListener(this)));c.insert(new Element('div',{style:'clear:both;'}));this.initMap();Droppables.add('map-chooser-container',{onDrop:function(element){var mapoff=($('map-chooser-container').viewportOffset(element));var markoff=($('drag-marker').viewportOffset(element));var x=markoff[0]-mapoff[0];var y=markoff[1]-mapoff[1]+32;var point=this.__map.fromContainerPixelToLatLng(new GPoint(x,y));this.addMarker(point,this.getOptions().icons[0]);}.bind(this)});new Draggable('drag-marker',{revert:true,ghosting:true,starteffect:null,endeffect:null,});},enterQuery:function(e){if(e.type=='keydown'){if(e.keyCode==13){this.searchLocation();e.preventDefault();}}},searchLocation:function(){this.geocoder.getLatLng($('geocode-input').getValue(),function(point){this.__map.setCenter(point,12);}.bind(this));},addMarker:function(latLng,icon){var ico=new GIcon();if(''!=null||true){ico.iconSize=new GSize(35,35);ico.shadowSize=new GSize(22,20);ico.iconAnchor=new GPoint(0,32);ico.infoWindowAnchor=new GPoint(5,1);}else{ico.iconSize=new GSize(60,60);ico.shadowSize=new GSize(22,20);ico.iconAnchor=new GPoint(0,32);ico.infoWindowAnchor=new GPoint(5,1);}
ico.image=this.getOptions().iconUrl+'marker/'+icon+".png";markerOptions={icon:ico,draggable:true};var mark=new GMarker(latLng,markerOptions);mark.enableDragging();GEvent.addListener(mark,"dragend",function(m){this.__latitude=mark.getLatLng().lat();this.__longitude=mark.getLatLng().lng();this.__map.setCenter(new GLatLng(this.__latitude,this.__longitude),this.__map.getZoom());}.bind(this));if(this.__marker!=null){this.__map.removeOverlay(this.__marker);}
this.__map.addOverlay(mark);this.__marker=mark;this.__latitude=latLng.lat();this.__longitude=latLng.lng();this.__map.setCenter(latLng,this.initZoom+3);this.__icon=icon;},getValue:function(){if(this.__latitude==null||this.__longitude==null)return null;var ret={latitude:this.__latitude,longitude:this.__longitude,icon:this.__icon};return ret;}});;var FX_Form_Element_GalleryUpload=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){window.fxapplication.addEventListener('unserort.form.element.GalleryUpload.change',this.picChanged,this);window.fxapplication.addEventListener('unserort.form.element.GalleryUpload.add',this.addPic,this);$super(f,o);this.__picList=new Element('ul',{'id':'form-gallery-list'});this.__picList.addClassName('form-gu-list');var flashVarObject={};flashVarObject.uploadid=o.uploadId;flashVarObject.uploadurl=o.uploadUrl;if(o.value!=null&&o.value!=''){for(var i=0;i<o.value.length;i++){var e=o.value[i];this.addListElement(e.id,e.url,(e.temp?1:0),e.description);}
flashVarObject.label=o.label;flashVarObject.description=o.description;}
var scr='swfobject.embedSWF("'+o.swfUrl+'", "galleryuploadcontainer", '+o.width+', 32, "9.0.0", "expressInstall.swf", '+Object.toJSON(flashVarObject)+', {allowScriptAccess:"always", wmode:"opaque"});';var d=new Element('div',{style:'width:'+o.width+'px;min-height:32px'}).insert(new Element('div',{id:'galleryuploadcontainer',style:'width:'+o.width+'px;height:32px'}).insert('<p>F&uuml;r den Fotoupload wird der <a href="http://get.adobe.com/flashplayer/" target="_blank">Adobe Flash Player</a> ben&ouml;tigt.</p>'));d.insert('<script type="text/javascript">'+scr+'</script>');d.insert(this.__picList);this.setElement(d);},setup:function(){this.__initalized=1;Sortable.create('form-gallery-list');},getValue:function(){var elems=$('form-gallery-list').childElements();var ret=new Array();for(var i=0;i<elems.length;i++){ret[i]={id:elems[i].readAttribute('pid'),temp:elems[i].readAttribute('temporary'),url:elems[i].readAttribute('url'),'description':$('gu-descr-'+elems[i].readAttribute('pid')).value};}
return ret;},addPic:function(e){this.__initialized=1;this.addListElement(e.data.id,e.data.url,1,'');},addListElement:function(id,url,temporary,description){var li=new Element('li',{'id':'item'+id,'pid':id,'temporary':temporary,'url':url,style:'position:relative;'}).insert(new Element('img',{src:url}));var input=new Element('textarea',{'id':'gu-descr-'+id}).insert(description);li.insert(input);var delBtn=new Element('a').addClassName('button');delBtn.observe('click',this.deleteElement).insert(new Element('span',{'pid':id}).insert('x'));li.insert(new Element('div').insert(delBtn));this.__picList.insert(li);if(this.__initialized==1){Sortable.create('form-gallery-list');}},deleteElement:function(e){var elem=$('item'+e.target.readAttribute('pid')).remove();Element.remove(Element.extend(elem));}});;var FX_Form_Element_RegionChooser=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){$super(f,o);var d=new Element('div');var template=new Template('<table width="256" cellspacing="0" cellpadding="0" class="regionchooser"><tr><td colspan="2"><div id="regionchooser-label" class="rc-invalid">Wählen Sie das Ortsportal <br/> (Name oder PLZ)</div></td></tr><tr><td><input type="text" id="regionchooser-input"/></td><td><a class="button" id="regionchooser-button"><span>Suchen</span></a></td></tr></table><div id="regionchooser-ac-container"></div>');var btn=new Element('input',{type:'button',value:'Suchen'});this.setElement(d);d.insert(template.evaluate({button:btn}));},setup:function(){var o=this.getOptions();if(o.regionName.length>0&&o.value!=null){this.setRegion(o.value.region,o.regionName,o.regionDescription);}
$('regionchooser-button').observe('click',this.searchRegion.bindAsEventListener(this));$('regionchooser-input').observe('keyup',this.autoComplete.bindAsEventListener(this));$('regionchooser-input').observe('keydown',this.searchRegion.bindAsEventListener(this));},searchRegion:function(e){if(e!=null){if(e.type=='keydown'){switch(e.keyCode){case 13:break;case 40:this.setSelectedIndex(this.__index==null?0:this.__index+1);break;case 38:this.setSelectedIndex(this.__index-1);break;default:return;}
if(e.keyCode!=13){return;}}
e.stop();}
if(this.__index!=null){var elem=$('regionchooser-ac-container').childElements();this.setRegion(elem[this.__index].readAttribute('rid'),elem[this.__index].readAttribute('name'),elem[this.__index].readAttribute('description'));return;}
new Ajax.Request('/default/region/search/format/json',{method:'POST',onSuccess:this.searchResultHandler.bindAsEventListener(this),parameters:{query:$('regionchooser-input').value}});},setSelectedIndex:function(v){var elem=$('regionchooser-ac-container').childElements();if(v<0)v=elem.length-1;this.__index=v%elem.length;for(var i=0;i<elem.length;i++){if(i==this.__index){elem[i].addClassName('rc-ac-selected');}else{elem[i].removeClassName('rc-ac-selected');}}},autoComplete:function(e){var val=$('regionchooser-input').value;if(e.type=='keyup'){if(val.length==0){$('regionchooser-ac-container').hide();return;}
if(val==this.__lastQuery)return;var invalidKeys=[13,38,40];for(var i=0;i<invalidKeys.length;i++){if(e.keyCode==invalidKeys[i])return;}
this.__index=null;this.__requests=this.__requests!=null?this.__requests+1:1;if(!this.isNumeric($('regionchooser-input').value)){this.__lastQuery=val;if(this.__requests==1){new Ajax.Request('/default/region/auto-complete/format/json',{method:'POST',onSuccess:this.autoCompleteResultHandler.bindAsEventListener(this),parameters:{query:val}});}}else{if(val.length==5){this.searchRegion();}}}else{return;}},autoCompleteResultHandler:function(result){var regions=result.responseJSON['regions'];this.__acItems=[];var cont=$('regionchooser-ac-container').update().show();this.__index=null;if(this.__requests>1){this.autoComplete({type:'keyup',keyCode:'resent'});}
this.__requests=0;for(var i=0;i<regions.length;i++){var acItem=new Element('div',{'rid':regions[i]['id'],'name':regions[i]['name'],'description':regions[i]['description']}).update(regions[i]['name']).addClassName('rc-ac-item');acItem.observe('click',this.autoCompleteClickHandler.bindAsEventListener(this));cont.appendChild(acItem);}
if(regions.length==1&&this.getValue()==null){this.setRegion(regions[0].id,regions[0].name,regions[0].description);}},autoCompleteClickHandler:function(event){var e=Element.extend(event.target);this.setRegion(e.readAttribute('rid'),e.readAttribute('name'),e.readAttribute('description'));},searchResultHandler:function(result){var regions=result.responseJSON['regions'];this.__requests=0;if(regions.length==1){this.setRegion(regions[0]['id'],regions[0]['name'],regions[0]['description']);}else{$('regionchooser-label').update('Es wurde kein passender Ort gefunden. Bitte versuchen Sie es mit Ihrer Postleitzahl.').addClassName('rc-invalid').removeClassName('rc-valid');$('regionchooser-input').value='';}},setRegion:function(id,name,description){$('regionchooser-ac-container').hide();$('regionchooser-label').update(name).addClassName('rc-valid').removeClassName('rc-invalid');this.setValue({region:id});},isNumeric:function(strString){var strValidChars="0123456789";var strChar;var blnResult=true;if(strString==null)return false;if(strString.length==0)return false;for(i=0;i<strString.length&&blnResult==true;i++)
{strChar=strString.charAt(i);if(strValidChars.indexOf(strChar)==-1)
{blnResult=false;}}
return blnResult;}});;var FX_Form_Element_CheckBoxList=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){var template;if(o.template!=null){template=new Template(o.template);}else{template=new Template('<label><input type="checkbox" name="#{name}" value="#{value}" #{checked}/> #{label}</label><br/>');}
var d=new Element('div');for(var j=0;j<o.multiOptions.length;j++){var tempValues={name:o.name,value:j};var checked=false;if(typeof o.multiOptions[j]=='object'){Object.extend(tempValues,o.multiOptions[j]);if(o.value!=null){for(var k=0;k<o.value.length;k++){if(o.multiOptions[j].value==o.value[k]){checked=true;break;}}}
Object.extend(tempValues,{checked:(checked?'checked="checked"':'')});}else{for(var k=0;k<o.value.length;k++){if(j==o.value[k]){checked=true;break;}}
Object.extend(tempValues,{label:o.multiOptions[j],checked:(checked?'checked="checked"':'')});}
d.insert(template.evaluate(tempValues));}
$super(f,o);this.setElement(d);},getValue:function(){var t=$(this.getForm().id).select('input[name="'+this.getName()+'"]');var ret=[];for(var i in t){if(typeof t[i]=='object'){if(t[i].checked){ret.push(t[i].value);}}}
return ret;}});;var FX_Form_Element_CheckBox=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){var d=new Element('div');var l=new Element('label');var i=new Element('input',{type:'checkbox',name:o.name,value:o.checkedValue});if(o.checkedValue==o.value){i.setAttribute('checked','checked');}
l.insert(i);l.insert(' '+o.label);d.insert(l);$super(f,o);this.setElement(d);},getValue:function(){var t=$(this.getForm().id).select('input[name="'+this.getName()+'"]');for(var i in t){if(typeof t[i]=='object'){if(t[i].checked){return t[i].value;}}}
return this.getOptions().uncheckedValue;}});;var FX_Form_Element_HierarchicalList=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){this.__selectedItems=Array();var curValue=o.value==''?null:o.value;while(curValue!=null&&curValue!='null'){this.__selectedItems.push(curValue+'');var valueset=false;for(var i in o.listItems){if(o.listItems[i].value+''==curValue+''){curValue=o.listItems[i].parent;var valueset=true;}}
if(!valueset)break;}
var d=new Element('div');this.setElement(d);$super(f,o);this.generateList(null,1);this.__tmpValue=o.value+'';this.__selectedItems=[];},generateList:function(id,level)
{var opt=this.getOptions();var list=new Element('select');list.level=level;var item;for(var i in opt.listItems){if(opt.listItems[i].parent!=id||typeof opt.listItems[i]=='function')continue;if(list.options.length==0&&opt.label!=undefined){list.options[list.options.length]=new Option(opt.label,null,false,true);}
list.options[list.options.length]=new Option(opt.listItems[i].label,opt.listItems[i].value,false,false);}
Element.observe(list,'change',this.changeHandler.bindAsEventListener(this));if(list.options.length>0){this.getElement().insert(list).insert(new Element('br'));for(var j=0;j<this.__selectedItems.length;j++){for(var k=0;k<list.options.length;k++){if(list.options[k].value==this.__selectedItems[j]){list.value=this.__selectedItems[j];this.generateList(this.__selectedItems[j],level+1);}}}
this.__tmpValue=null;}else{this.__tmpValue=id;}
if(this.isNumeric(opt.width)){}else{list.setStyle({'width':opt.width});}
return;},changeHandler:function(event){var sel=event.target;var children=this.getElement().getElementsBySelector('select');for(var j=0;j<children.length;j++){if(children[j].level>sel.level){Element.remove(children[j].previous());Element.remove(children[j]);}}
this.generateList(sel.value,sel.level+1);},getValue:function(){return this.__tmpValue=='null'?null:this.__tmpValue;}});;var FX_Form_Element_MultiList=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){$super(f,o);var d=new Element('div').insert(new Element('input',{id:'multilist-input',type:'text'}));var au=new Element('div',{id:'multilist-auto-container'});var ul=new Element('ul',{'class':'feed'});au.insert(ul);if(o.value!=null){for(var i=0;i<o.value.length;i++){ul.insert(new Element('li',{value:o.value[i].value}).insert(o.value[i].caption));}}
au.insert(new Element('div',{'class':'default'}).insert(o.helpMessage));d.insert(au);this.setElement(d);},setup:function(){this._list=new FX_Form_MultiList('multilist-input','multilist-auto-container',{fetchFile:'/neighbour/list-my-autocomplete/format/json'});var opt=this.getOptions();if(opt.value!=null){opt.value.each(function(t){this._list.autoFeed(t);},this);}},getValue:function(){this._value=null;this._list.bits.each(function(t){this._value=this._value==null?[]:this._value;this._value.push({'caption':$(t.key).childNodes[0].data,'value':t.value});},this);return this._value;}});;var FX_Form_Element_ReCaptcha=Class.create(FX_Form_Element_Abstract,{initialize:function($super,f,o){$super(f,o);var x=new Element('div');this.__container=x;var divs='';divs+='<p>Geben Sie <strong>beide Wörter</strong> durch ein <strong>Leerzeichen getrennt</strong> unten ein.<br/>';divs+='Sie können das nicht entziffern? <a href="javascript:Recaptcha.reload()">Versuchen Sie andere Wörter</a></p>';divs+='<div id="recaptcha_image"></div>';divs+='Text im Feld: <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />';x.insert(new Element('div',{'id':'recaptcha_div'}).insert(divs));this.setElement(this.__container);},setup:function(){var o=this.getOptions();var c=this.__container;c.insert('<script type="text/javascript">Recaptcha.create("'+o.publicKey+'","recaptcha_div", {theme: "custom", lang:"de", custom_theme_widget:"recaptcha_div"});</script>');},getValue:function(){return{'challenge':Recaptcha.get_challenge(),'response':Recaptcha.get_response()};}});;var FX_Form=Class.create({initialize:function(id){this.id=id;this.elements=[];this.method='post';},generateForm:function(data){this.elements=[];if($(this.id).childElements().length){if($('form-'+this.id)){$('form-'+this.id).remove();}
$(this.id).childElements()[0].remove();var wait=$(this.id+'wait');if(wait!=undefined){wait.remove();}}
var attr=(data.attributes!=undefined?data.attributes:{});attr.id=data.name;var f=new Element('form',{id:'form-'+this.id});for(var i in attr){if(i=='class'){f.addClassName(attr[i]);}}
if(data.redirect!=undefined){var r=data.redirect;if(r.delay==0){window.location.href=r.url;}else{var reddiv=new Element('div');reddiv.insert('<p>'+data.redirect.content+'</p><p><a class="button" href="'+r.url+'"><span>Weiter</span></a><br/></p>').addClassName('infomessage');f.insert(reddiv);setTimeout("window.location.href='"+r.url+"'",r.delay*1000);$(this.id).insert(f);}
return;}
$(this.id).insert(f);var errm=data.errorMessages;if(errm.length>0){var errdiv=new Element('div');errdiv.addClassName('error');for(var i=0;i<errm.length;i++){errdiv.insert('<p>'+errm[i]+'</p>');}
f.insert(errdiv);}
var infm=data.infoMessages;if(infm.length>0){var infdiv=new Element('div');infdiv.addClassName('infomessage');for(var i=0;i<infm.length;i++){infdiv.insert('<p>'+infm[i]+'</p>');}
f.insert(infdiv);}
this.method=data.method;this.action=data.action;var template=new Template(data.template);var elmContainer={};var elements={};for(var i=0;i<data.elements.length;i++){var elm=data.elements[i];var clazz='FX_Form_Element_'+elm.type;if(eval('(typeof FX_Form_Element_'+elm.type+' == "function")')){var t=eval('new '+clazz+'(this, elm)');var d=new Element('div').insert(new Element('div',{id:this.id+'-'+data.name+'-'+elm.name}));elements[this.id+'-'+data.name+'-'+elm.name]=t;elmContainer[elm.name]=d.innerHTML;}else{alert('Class FX_Form_Element_'+elm.type+' not found.');}}
var d=new Element('div');f.insert(template.evaluate(elmContainer));this.elements=elements;for(var i in elements){if($(i)==null)continue;Element.extend($(i)).insert(elements[i].getElement());elements[i].setup();}
if(data.initCallback!=undefined){eval(data.initCallback+'()');}},loadForm:function(url){if(url==null)return;new Ajax.Request(url,{method:this.method,onSuccess:this.resultHandler.bindAsEventListener(this)});},submitForm:function(){$('form-'+this.id).hide();var wait=new Element('div',{id:this.id+'wait'});wait.addClassName('form-wait');$(this.id).insert({top:wait});var params={};for(var i in this.elements){var elm=this.elements[i];if(elm.getInput()){var value=elm.getValue();var brackets='';if(value instanceof Object){for(var j in value){if(value[j]instanceof Array){brackets='[]';}else{brackets='';}
if(value[j]instanceof Object){for(var k in value[j]){if(typeof value[j][k]=='function')continue;params[elm.getName()+'['+j+']['+k+']']=value[j][k]==null?'':value[j][k];}}else{var index;var reg=/^([0-9])+$/;if(reg.test(j)===false){index=j;}else{index='';}
params[elm.getName()+'['+index+']'+brackets]=index==''?value:value[j];}}}else{var tvalue=elm.getValue();params[elm.getName()]=tvalue!=null?tvalue:'';}}}
new Ajax.Request(this.action,{method:this.method,parameters:params,onComplete:this.resultHandler.bindAsEventListener(this)});},resultHandler:function(tr)
{if(tr.status!=200){$(this.id).childElements()[0].enable();var errdiv=new Element('div',{'class':'error'});errdiv.insert('<p>'+tr.responseText+'</p>');$(this.id).insert(errdiv);}else{if(tr.responseJSON!=null){this.generateForm(tr.responseJSON.form);}else{if($(this.id).childElements().length>0){$(this.id).childElements()[0].remove();}
$(this.id).insert(tr.responseText);}}},getElements:function()
{return this.elements;}});Event.observe(window,'load',function(){if(window.fxapplication.settings['unserort.form.Form']!=undefined){for(var i in window.fxapplication.settings['unserort.form.Form']){var set=window.fxapplication.settings['unserort.form.Form'][i];if(set.form!=null){var f=new FX_Form(set.id);f.generateForm(set.form);}else{var f=new FX_Form(set.id);f.loadForm(set.url);}}}
window.fxapplication.addEventListener('unserort.form.Form.loadForm',function(event){var f=new FX_Form(event.data.id);f.loadForm(event.data.url);},this);});
