var admin_map    = 'none';
var search_map   = 'none';
var location_map = 'none';
var shadow_map   = 'none';

function ErrorControl(){}
//ErrorControl.prototype = new GControl;

ErrorControl.prototype.initialize = function( map ){
	
	var me = this;
	me.panel = new Element(
		'div', 
		{
			'id' : 'error-control',
			'class' : 'error-control'
		}
	);
	map.getContainer().appendChild(me.panel);
	GEvent.addDomListener(
		me.panel, 
		'click', 
		function(){
			map.removeControl( me );
		}
	);
	return me.panel;
	
};

ErrorControl.prototype.getDefaultPosition = function() {
	
	return new GControlPosition( G_ANCHOR_TOP_RIGHT, new GSize(30, 100) );
		
};

ErrorControl.prototype.getPanel = function() {

	return me.panel;

};

function CHeim( geodata, title, desc, link, image, free, customer ) {

	this.createMarker = function() {
		
		if( this.point != null ) {
			
			var marker = new google.maps.Marker({
				position : this.point, 
				title    : this.title, 
				icon     : this.createHeimIcon()
			});
			marker.html = '<h3>' + this.title + '</h3>';
			marker.html += '<div class="' + this.settings.classes.map_info_box + '">'
			
			if( this.customer == false ) {
				marker.html += this.desc + '<br />';
			} else {

				if( this.image != '' ) marker.html += '<img src="' + this.image + '" class="' + this.settings.classes.marker_image + '"/>';

				marker.html += '<p>';
				marker.html += this.desc + '<br />';

				if( this.free == 'true' ){
					marker.html += '<span class="' + this.settings.classes.places.free + '">Freie Plätze vorhanden</span><br />';
				} else if( this.free == 'false' ) {
					marker.html += '<span class="' + this.settings.classes.places.no_free + '">Keine freien Plätze vorhanden</span><br />';
				}
			}
			
			marker.html += '<a href="' + this.link + '">Zur Einrichtung</a>';
			marker.html += '</p>';
			marker.html += '<hr style="clear:both;"/>';
			marker.html += '</div>';
				
			GEvent.addListener( 
				marker, 
				'click', 
				function() {
					this.openInfoWindowHtml(
						this.html,
						{
							maxWidth: 300
						}
					);
				}
			);
			return marker;
		} else {
			return null;
		}
	};
	
	this.createHeimIcon = function() {

		icon = new google.maps.MarkerImage( G_DEFAULT_ICON );
		
		if( this.customer == false ){
			icon.image = this.settings.img.no_customer;
		} else {
			icon.image = this.settings.img.customer;
		}
	
		icon.iconSize = new GSize(22,20);
		icon.shadow = null;
		icon.iconAnchor = new GPoint(11,10);
	
		return icon;
	
	};
	
	this.is_valid_geo_string = function( str ) {
	
		regex = new RegExp( '^LAT=\[[0-9]{1,3}\.?[0-9]{0,10}\]:LNG=\[[0-9]{1,3}\.?[0-9]{0,10}\]$' );
		return regex.test( str );
		
	};
	
	this.splitGeoData = function( str ){
	
		if( !this.is_valid_geo_string( str ) ) return false;
		
		parts = str.split( ':' );
		lat = parts[0].replace( 'LAT=', '' ).replace( 'LNG=', '' ).replace( '\[', '' ).replace( '\]', '' );
		lng = parts[1].replace( 'LAT=', '' ).replace( 'LNG=', '' ).replace( '\[', '' ).replace( '\]', '' );
		
		return new google.maps.LatLng( lat,lng );

	};

	this.formatGeoData = function() {
		
		return 'LAT=[' + this.point.lat() + ']:LNG=[' + this.point.lng() + ']';
		
	};
	
	this.point    = this.splitGeoData( geodata );
	this.title    = title;
	this.desc     = desc;
	this.link     = link;
	this.image    = image;
	this.free     = free;
	this.customer = customer;
	this.settings = {
		img : {
			customer : '/extension/r_geo_google/design/standard/images/einrichtung_b2.gif',
			no_customer : '/extension/r_geo_google/design/standard/images/einrichtung_g.gif'
		},
		classes : {
			map_info_box : 'map-info-box',
			marker_image : 'marker-image',
			places : {
				free : 'free',
				not_free : 'not-free'
			}
		}
	};
	
}

function formatGeoData( point ){
	
	return "LAT=["+point.lat()+"]:LNG=["+point.lng()+"]";
	
}




