/*
Original datei vor komprimierung
änderungen müssen hier durchgeführt werden und dann die datei komprimiert
*/


var APcMerkliste_echt = new Class({
	Implements : [APcListe],
	
	initialize: function(opts){
		this.parent(opts);
	},
	
	
	HTMLSchreiben: function(){
		this.parent()
		
		
		this.HTMLContainer.getElements('.Entfernen').addEvent('click', function(event){
			entfernen(this.getParent().getProperty('zid'))
			event.stopPropagation()
		});
		this.HTMLContainer.getElements('.up').addEvent('click', function(event){
			APMerkliste.reihenfolge(this.getParent().getProperty('zid'),36)
			event.stopPropagation()
		});
		this.HTMLContainer.getElements('.down').addEvent('click', function(event){
			APMerkliste.reihenfolge(this.getParent().getProperty('zid'),36)
			event.stopPropagation()
		});
		
		
		
		
	},
	
	
	reihenfolge : function(x, updown) {return this.aktualisieren(updown,x) },
	entfernen : function(x) {return this.aktualisieren(38,x)}
	
}); //new class





/*
Original datei vor komprimierung
änderungen müssen hier durchgeführt werden und dann die datei komprimiert
*/
var rstart,rend;


var APcMerklisteBox = new Class({
	initialize: function(opts){
		this.Liste =  new APcListe();
		this.zahl = 0;
		this.Titel = '';
		this.s = '';
		this.s0 = '';
		this.Options = opts;
		
		q = new QS();
		
		this.Route = (q.get('aproute')=='go');
		if(this.Route){
			this.RouteStart = unescape(decodeURIComponent(q.get('aproutestart')));
			this.RouteEnd =  unescape(decodeURIComponent(q.get('aprouteend')));

			//if (this.RouteStart!=""){
		
				var geocoder = new GClientGeocoder();
				geocoder.setBaseCountryCode("at");
				
				
				if (this.RouteStart!=""){
				geocoder.getLocations(this.RouteStart,function(response){
					 if (!response || response.Status.code != 200) {
    				alert("Adresse "+this.RouteStart+" nicht gefunden. Status Code:" + response.Status.code);
  			} else {
						place = response.Placemark[0];
   					point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
						rstart=point;
					}
				});
				}
				if (this.RouteEnd!=""){
				geocoder.getLocations(this.RouteEnd,function(response){
					 if (!response || response.Status.code != 200) {
    				alert("Adresse "+this.RouteEnd+" nicht gefunden. Status Code:" + response.Status.code);
  			} else {
						place = response.Placemark[0];
   					point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
						rend=point;
					}
				});
			
			}	
		}
		
		this.Request = new Request({url: this.Options.AjaxURL, 
			link:'cancel', method : 'get', 
			onSuccess : function(atxt, bxml){
				if (atxt){
					var a = eval('(' + atxt + ')')
					this.parent.Liste.Elemente = a.Elemente;
					this.parent.BoxHTML = a.BoxHTML;
					this.parent.schreibeHTML();
					if(this.parent.Route) apKarteRoute(this.parent.Liste,rstart, rend)
				}
				apKarteaktualisieren(this.parent.Liste, 2);
				
			}
		});
		this.Request.parent = this; 
	},
		
		

	schreibeHTML : function() {
		if($(this.Options.MerklisteBox)){
			if(this.Liste.Elemente.length>0){
				try{
					$(this.Options.MerklisteBox).removeClass('leer')
				}catch(e){}
				
				$(this.Options.MerklisteBox).set('html', '<h2>' +this.BoxHTML.Titel + '</h2>', this.BoxHTML.s.replace(/\%_AP_ZAHL_\%/i,this.Liste.Elemente.length));
				$(this.Options.MerklisteBox).adopt(new Element('div', {'class': 'Menu'}));
				var mhtml = this.BoxHTML.menuHTML.replace(/\%_AP_QUERYSTRING_\%/i, location.search.substring(1,location.search.length) )
				$(this.Options.MerklisteBox).getElement('.Menu').set('html',mhtml);
				
				
				var xl = new Element('div', {'class': 'Liste', 'id':this.Options.ListeContainer});
				
				$(this.Options.MerklisteBox).adopt(xl);
				this.Liste.ListeContainer = $(this.Options.ListeContainer);
				this.Liste.schreibeHTML()
				if (this.BoxHTML.MLID>0){
					$(this.Options.MerklisteBox).adopt(new Element('div', {'class': 'zurueck', 'html':'<a href="?apseite=2"><img src="img/mp1z.gif" width="3" height="5" alt="zur&uuml;ck zur Auswahl" align="absmiddle" /> zur&uuml;ck zur Auswahl</a>'}));
				}else{
					$(this.Options.MerklisteBox).adopt(new Element('div', {'class': 'zurueck', 'html':'<a href="?apakt=1"><img src="img/mp1z.gif" width="3" height="5" alt="zur&uuml;ck zur Auswahl" align="absmiddle" /> zur&uuml;ck zur Auswahl</a>'}));
				}
			}else{
				try{
					$(this.Options.MerklisteBox).addClass('leer')
				}catch(e){
				
				}
					$(this.Options.MerklisteBox).innerHTML = '<h2>' +this.BoxHTML.Titel + '</h2>' + this.BoxHTML.s0;
			
			}
			if (APMerkliste.onchange) APMerkliste.onchange();
		}
		return false;
	},
	
	
	aktualisieren : function(ak,zid) {
		if($('apListeZiel'+zid)) $('apListeZiel'+zid).addClass('deaktiviert');
		this.parent.aktualisieren(ak,'apzielid='+ zid +'&random=' + Math.random())
	},
	
	laden : function(ak) {
		if($(this.Options.MerklisteBox) && !this.Options.WirkungsloseAktionen.contains(ak)){
			this.Request.cancel();
			this.Request.send('apakt=81&random=' + Math.random());
			return false;
		}
		return false;
	},
	
	hinzufuegen : function(x) { return this.aktualisieren(35,x)	},
	reihenfolge : function(x, updown) {return this.aktualisieren(updown,x) },
	entfernen : function(x) {return this.aktualisieren(38,x)}
	
}); //new class





