/**
 * Flächensuche
 */

function Flaechensuche()
{
	
	var map 		= new Array();
	var dir_base 	= null;
	var selected	= null;
	
	this.init = function(dirBase, sel)
	{
		dir_base = dirBase;
						// id, aktiv, name, img
		map.push(new Array(1, true, "Charlottenburg-Wilmersdorf", "berlin_wilmersd.png"));
		map.push(new Array(2, true, "Friedrichshain-Kreuzberg", "berlin_fhain.png"));
		map.push(new Array(3, true, "Lichtenberg", "berlin_lichtenb.png"));
		map.push(new Array(4, true, "Marzahn-Hellersdorf", "berlin_marzahn.png"));
		map.push(new Array(5, true, "Mitte", "berlin_mitte.png"));
		map.push(new Array(6, true, "Neukölln", "berlin_neukoelln.png"));
		map.push(new Array(7, true, "Pankow", "berlin_pankow.png"));
		map.push(new Array(8, true, "Reinickendorf", "berlin_reinickend.png"));
		map.push(new Array(9, false, "Spandau", "berlin_spandau.png"));
		map.push(new Array(10, false, "Steglitz-Zehlendorf", "berlin_steglitz.png"));
		map.push(new Array(11, true, "Tempelhof-Schöneberg", "berlin_tempelhof.png"));
		map.push(new Array(12, false, "Treptow-Köpenick", "berlin_treptow.png"));
		
		var selectList = $$("#FlaechensucheForm select")[0];
		for( var i = 0; i < map.length; i ++ ) {
			if( map[i][1] == true ) {
				var newOption = new Option(map[i][2], map[i][0], false, false);
				selectList.options[selectList.length] = newOption;
			}
		}
		
		// Größe
		var sizes = $$("#FlaechensucheForm input[name=size]")[0].value.split(/-/);
		if( sizes.length == 2 ) {
			$$("#FlaechensucheForm input[name=size_from]")[0].value = sizes[0];
			$$("#FlaechensucheForm input[name=size_to]")[0].value = sizes[1];
		}
		
		// SELECT
		if( parseInt(sel) > 0 ) {
			selected = parseInt(sel);
			this.click(selected);
		}
	}
	
	function getEntryById(id)
	{
		for( var i = 0; i < map.length; i ++ ) {
			if( map[i][0] == id ) {
				return map[i];
			}
		}
		return null;
	}
	
	this.click = function(id) 
	{
		var entry = getEntryById(id);
		if( entry[1] == true ) {
			$('FlaechensucheMapImage').src = dir_base+'/img/map/'+entry[3];
		}
		selected = id;
		
		var selectList = $$("#FlaechensucheForm select")[0];
		selectList.value = entry[0];
	}
	
	this.over = function(id) 
	{
		var entry = getEntryById(id);
		if( entry[1] == true ) {
			$('FlaechensucheMapImage').src = dir_base+'/img/map/'+entry[3];
		}
	}
	
	this.out = function() 
	{
		if( selected != null ) {
			var entry = getEntryById(selected);
			$('FlaechensucheMapImage').src = dir_base+'/img/map/'+entry[3];
		} else {
			$('FlaechensucheMapImage').src = dir_base+'/img/map/berlin.png';
		}
	}
	
	this.sendForm = function()
	{
		$$("#FlaechensucheForm input[name=size]")[0].value = $$("#FlaechensucheForm input[name=size_from]")[0].value+'-'+$$("#FlaechensucheForm input[name=size_to]")[0].value;
		return true;
	}
}
