var baseIcon=new GIcon();baseIcon.shadow="/img/shadow50.png";baseIcon.iconSize=new GSize(20,34);baseIcon.shadowSize=new GSize(37,34);baseIcon.iconAnchor=new GPoint(9,34);baseIcon.infoWindowAnchor=new GPoint(9,2);baseIcon.infoShadowAnchor=new GPoint(18,25);var markerimages=Array();markerimages[1]="/img/011.png";markerimages[2]="/img/023.png";markerimages[3]="/img/036.png";markerimages[4]="/img/084.png";markerimages[5]="/img/106.png";markerimages[6]="/img/125.png";markerimages[7]="/img/167.png";var icon1=new GIcon(baseIcon);icon1.image=markerimages[1];var icon2=new GIcon(baseIcon);icon2.image=markerimages[2];var icon3=new GIcon(baseIcon);icon3.image=markerimages[3];var icon4=new GIcon(baseIcon);icon4.image=markerimages[4];var icon5=new GIcon(baseIcon);icon5.image=markerimages[5];var icon6=new GIcon(baseIcon);icon6.image=markerimages[6];var icon7=new GIcon(baseIcon);icon7.image=markerimages[7];var application=false;var loaddelay=20;function MyApplication(){if(startx=='undefinded'){startx=10.1;}
if(starty==null){starty=51.2;}
if(startz==null){startz=6;}
this.map=new GMap2(document.getElementById("map"));this.map.setCenter(new GLatLng(starty,startx),startz);this.map.addControl(new GLargeMapControl());this.map.addControl(new GMapTypeControl());this.map.enableContinuousZoom();this.markers=Array();this.infos=Array();this.ids=Array();this.changed=0;this.start=0;this.handleevent=1;GEvent.bind(this.map,"dragend",this,this.onMapClick);GEvent.bind(this.map,"zoomend",this,this.onMapClick);GEvent.bind(this.map,"moveend",this,this.onMapClick);this.notype=Array();this.notype['wg']=0;this.notype['haus']=0;this.notype['1zi']=0;this.notype['2zi']=0;this.notype['3zi']=0;this.notype['4zi']=0;this.notype['5zi']=0;this.anfangdatum=0;this.endedatum=0;this.zwimi=0;this.minpreis=0;this.maxpreis=0;this.sidebuffer='';GEvent.addListener(this.map.getInfoWindow(),"maximizeclick",function(){application.handleevent=0;});GEvent.addListener(this.map.getInfoWindow(),"maximizeend",function(){application.enableEvents();});}
MyApplication.prototype.updateBounds=function(){bounds=this.map.getBounds();min=bounds.getSouthWest();max=bounds.getNorthEast();this.changed=0;tmp=min.lat();if(tmp!=this.ymin){this.ymin=tmp;this.changed=1;}
tmp=max.lat();if(tmp!=this.ymax){this.ymax=tmp;this.changed=1;}
tmp=min.lng();if(tmp!=this.xmin){this.xmin=tmp;this.changed=1;}
tmp=max.lng();if(tmp!=this.xmax){this.xmax=tmp;this.changed=1;}}
MyApplication.prototype.onMapClick=function(){if(this.handleevent==1){this.updateBounds();if(this.changed==1){if(document.filter.autoupdate.checked){this.clearMarkers();this.loadData(0);}else{this.loadAnzahl();}}}}
MyApplication.prototype.typeChange=function(){this.updateBounds();if(document.filter.autoupdate.checked){window.setTimeout("application.clearMarkers()",10);window.setTimeout("application.loadData(0)",loaddelay);}else{this.loadAnzahl();}}
MyApplication.prototype.loadNewMarkers=function(){this.updateBounds();this.clearMarkers();this.loadData(0);}
MyApplication.prototype.clearMarkers=function(){for(var i=0;i<30;i++){if(this.markers[i]!=null){this.map.removeOverlay(this.markers[i]);delete this.markers[i];}}
this.map.clearOverlays();}
MyApplication.prototype.loadData=function(start){var url=this.buildUrl(start);GDownloadUrl(url,function(data,responseCode){application.handleData(data,responseCode);});}
MyApplication.prototype.buildUrl=function(start){if(start==null){start=0;}
this.start=start;var url="/server/?blub="+Math.random()+"&ymax="+this.ymax+'&xmax='+this.xmax+"&ymin="+this.ymin+'&xmin='+this.xmin+'&limit='+this.start;this.checkForm();url+='&anfangdatum='+this.anfangdatum;url+='&endedatum='+this.endedatum;url+='&zwimi='+this.zwimi;url+='&minpreis='+this.minpreis;url+='&maxpreis='+this.maxpreis;var found=0;for(var key in this.notype){if(this.notype[key]==1){url+='&'+key+'=1';found++;}}
if(found==7){document.filter.wg.checked=true;url=this.buildUrl(start);}
return url;}
MyApplication.prototype.loadAnzahl=function(){var url=this.buildUrl(0);GDownloadUrl(url,function(data,responseCode){application.updateAnzahl(data,responseCode);});}
MyApplication.prototype.createMarker=function(point,text,text2,icTyp,i,detailid){switch(icTyp){case 1:var marker=new GMarker(point,icon1);break;case 2:var marker=new GMarker(point,icon2);break;case 3:var marker=new GMarker(point,icon3);break;case 4:var marker=new GMarker(point,icon4);break;case 5:var marker=new GMarker(point,icon5);break;case 6:var marker=new GMarker(point,icon6);break;case 7:var marker=new GMarker(point,icon7);break;default:var marker=new GMarker(point);break;}
var zoomstr='';var infoTabs=[new GInfoWindowTab('Adresse',zoomstr+text),new GInfoWindowTab("Beschreibung",text2)];this.infos[i]=infoTabs;this.ids[i]=detailid;GEvent.addListener(marker,"click",function(){application.handleevent=0;if(detailid>0){var maxContent='<iframe src="detailframe.php?id='+detailid+'" width="640" height="450" frameborder="0"></iframe>';var maxTitle="Anzeigendetails";marker.openInfoWindowTabsHtml(infoTabs,{maxContent:maxContent,maxTitle:maxTitle});}else{marker.openInfoWindowTabsHtml(infoTabs);}
window.setTimeout("application.enableEvents()",650);});return marker;}
MyApplication.prototype.handleData=function(data,responseCode){var xml=GXml.parse(data);var markers=xml.documentElement.getElementsByTagName("marker");var sideinhalt='';var clear=0;for(var i=0;i<markers.length;i++){var lat=parseFloat(markers[i].getAttribute("lat"));var lng=parseFloat(markers[i].getAttribute("lng"));var point=new GLatLng(lat,lng);var text=this.detailUrlNeu(unescape(markers[i].getAttribute("text1")));var text2=this.detailUrlNeu(unescape(markers[i].getAttribute("text2")));var typ=parseInt(markers[i].getAttribute("typ"));var detailid=parseInt(markers[i].getAttribute("id"));this.markers[(this.start+i)]=this.createMarker(point,text,text2,typ,(this.start+i),detailid);this.map.addOverlay(this.markers[(this.start+i)]);if(this.start==0&&i==0){var clear=1;}
sideinhalt+='<tr onclick="application.clickMarker('+(this.start+i)+');return false;"><td width="10"><img src="'+markerimages[typ]+'" height="12"></td>'+unescape(markers[i].getAttribute("side"))+'</tr>';}
this.writeStatusDiv(sideinhalt,clear);var status=xml.documentElement.getElementsByTagName("status");var anzahl=parseInt(status[0].getAttribute("anzahl"));var weiter=this.start+5;var e=document.getElementById('nachricht');e.innerHTML="die neusten "+(this.start+i)+" Anzeigen von insgesammt "+anzahl;if(weiter<anzahl&&weiter<30){window.setTimeout("application.loadData("+weiter+")",loaddelay);}else{}}
MyApplication.prototype.detailUrlNeu=function(str,id){str=str.replace(/<a.*<\/a>/,'<br /><a href="javascript:void(0);" onclick="application.map.getInfoWindow().maximize();"  class="orangesmall">Details zu dieser Anzeige</a>');return str;}
MyApplication.prototype.updateAnzahl=function(data,responseCode){var xml=GXml.parse(data);var status=xml.documentElement.getElementsByTagName("status");var anzahl=parseInt(status[0].getAttribute("anzahl"));max=30;if(anzahl<30){max=anzahl;}
var e=document.getElementById('nachricht');e.innerHTML="die neusten "+max+" Anzeigen von insgesammt "+anzahl;}
MyApplication.prototype.enableEvents=function(){this.handleevent=1;}
MyApplication.prototype.disableEvents=function(){this.handleevent=0;}
MyApplication.prototype.writeStatusDiv=function(text,clear){var e=document.getElementById('danebeninhalt');if(clear==1){e.innerHTML='';this.sidebuffer='';}
var tabstart='<table id="ergtabelle" cellpadding="0" cellspacing="1" border="0" style="width:100%">';tabstart+='<tr><td>&nbsp;</td><td>Stadt</td><td>Art</td><td>Grö&szlig;e</td><td>KM</td><td>frei ab</td></tr>';e.innerHTML=tabstart+this.sidebuffer+text+'</table>';this.sidebuffer=this.sidebuffer+text;}
MyApplication.prototype.clickMarker=function(i){this.handleevent=0;detailid=this.ids[i];if(detailid>0){this.markers[i].openInfoWindowTabsHtml(this.infos[i],{maxUrl:"/f.php?id="+detailid});}else{this.markers[i].openInfoWindowTabsHtml(this.infos[i]);}
window.setTimeout("application.enableEvents()",650);}
MyApplication.prototype.checkForm=function(i){this.notype['wg']=(document.filter.wg.checked)?0:1;this.notype['hause']=(document.filter.haus.checked)?0:1;this.notype['1zi']=(document.filter.zi1.checked)?0:1;this.notype['2zi']=(document.filter.zi2.checked)?0:1;this.notype['3zi']=(document.filter.zi3.checked)?0:1;this.notype['4zi']=(document.filter.zi4.checked)?0:1;this.notype['5zi']=(document.filter.zi5.checked)?0:1;this.anfangdatum=document.filter.vondatum.options[document.filter.vondatum.selectedIndex].value;this.endedatum=document.filter.bisdatum.options[document.filter.bisdatum.selectedIndex].value;if(this.endedatum<this.anfangdatum){this.endedatum=0;document.filter.bisdatum.selectedIndex=0;}
this.zwimi=document.filter.zwimi.options[document.filter.zwimi.selectedIndex].value;this.minpreis=document.filter.minpreis.options[document.filter.minpreis.selectedIndex].value;this.maxpreis=document.filter.maxpreis.options[document.filter.maxpreis.selectedIndex].value;}
MyApplication.prototype.zoomToStadt=function(str){if(str!=''){var teile=str.split(";");var x=parseFloat(teile[0]);var y=parseFloat(teile[1]);this.map.setCenter(new GLatLng(y,x),12);}else{this.map.setCenter(new GLatLng(51.2,10.1),6);}}
function load(){if(GBrowserIsCompatible()){application=new MyApplication();window.setTimeout("application.onMapClick()",loaddelay);}}
function replace(string,text,by){var strLength=string.length;var txtLength=text.length;if((strLength==0)||(txtLength==0))return string;var i=string.indexOf(text);if((!i)&&(text!=string.substring(0,txtLength)))return string;if(i==-1)return string;var newstr=string.substring(0,i)+by;if(i+txtLength<strLength)newstr+=replace(string.substring(i+txtLength,strLength),text,by);return newstr;}
function toStadt(str){application.zoomToStadt(str);}
function toggleWeitere(){el=document.getElementById('weitere');if(el.style.display=='block'){el.style.display='none';}else{el.style.display='block';}}
function showFullBild(id,bild){el=document.getElementById('bildshow'+id);el.src='http://bilder.studenten-wg.info/'+id+'/'+bild;}
