/**
 * mapselect.js
 *
 * requires: prototype.js (1.5) core.js scriptaculous.js effects.js tooltip.js
 *
 * GLOBALS:
 * imsLayoutPath:	should be defined in "/inc/immosuchmaske.php" according to layout path
 * glob_imsMaps: singleton. Map-Container for all maps.
 *
 * LOCALS
 * imsImgRoot:	Path to images.
 *
 * IMPORTANT
 * This script assumes the following path/file situation:
 *
 * +
 * +-- /js/mapselect.js
 * +-- /img/...
 *
 * Path to images is constructed via "imsRoot + imsLayoutPath"
 *
 *
 * @version 1.00
 * @author C. Dölling, Hufen & Dölling GbR, www.hud-net.com (2006)
 *
 */
 
 
var imsScripts 	= document.getElementsByTagName("script")[0].src;	// get the path where we sit in
var imsPath 	= imsScripts.replace(/js\/script\.js(\?.*)?$/,'');	// get the path above us
var imsImgRoot;

// 24.808.2010
// Hardcode the path due to google-analytics code interference

// if ( imsPath.indexOf("_preview") != -1 )	imsImgRoot = "/_gb_relaunch/_preview/im/";
// else										imsImgRoot = imsPath + "img/";	// assume images lie in subpath "/img/"
imsImgRoot = '/fileadmin/img/';

if ( typeof(imsLayoutPath) == "undefined" ) imsLayoutPath = "gb/maps/";	// fallback. should be set in "immobiliensuche.php" according to layout

//alert( imsLayoutPath );

var imsCache 		= 1;

// PREDEFINES EXTERNAL OBJECTs (Elements, Functions, etc.)
var imsPageElements = [];

imsPageElements["SelectImmobilienArt"]	= "imsArt";						// ImmoArt <select>
imsPageElements["SelectCity"]			= "imsLocationCity";			// City <select>
imsPageElements["SelectQuarter"] 		= "iLQ";						// Quarter <select>
imsPageElements["DivBoxMap"]			= "imsLocationMapContainer";	// Option box ("boxOptionSingle") <div>
imsPageElements["DivBoxList"]			= "imsLocationList";			// Option box ("boxOptionSingle") <div>
imsPageElements["DivMapContainer"]		= "imsLocationMap"				// Holds the map <div>
imsPageElements["DivMapImage"] 			= "imsImageMapContainer";		// The Map <div>
imsPageElements["DivModeSwitch"] 		= "imsLocationMode";			// Holds the link/button to switch between selector/map mode <p>
imsPageElements["DivModeSwitchCT"] 		= [];							// Entries for the mode switch. Defined in "mapselect_data_lang_ger", "mapselect_data_lang_eng"
imsPageElements["SelectOptionsCT"] 		= "";							// Entries for the select options. Defined in "mapselect_data_lang_ger", "mapselect_data_lang_eng"

externalFunctions						= []
externalFunctions["select_change"]		= "select_change";	// Defined in "immosuchmaske.php". Is called when a selectbox (e.g. Immobilienart, Kategorie) is changed)


/**
*	Class imsClassArea
*
*/
var imsClassArea = Class.create();
imsClassArea.prototype = {
	initialize:	function(owner,idInt,id,name,imNorm,dim,areaCoords,quarters ) {
		this.owner		= owner;
		this.id			= id;
		this.idInt		= idInt;
		this.name		= name;
		var ir = imsImgRoot + imsLayoutPath;
		this.images		= [ir + imNorm + ".gif", ir + imNorm + "_hil.gif", ir + imNorm + "_sel.gif" ];
		this.nodeImage	= null;
		this.nodeImages	= [];
		this.nodeArea	= null;
		this.dim		= dim ? dim.splitInt(",") : [];
		this.quarters 	= quarters ? quarters.split(",") : "";
		this.areaCoords 	= "";
		this.areaCoordsBup	= "";
		this.active 	= true;
		this.isSelected	= false;

		// shift coords
		if ( areaCoords )
		{
			var c = areaCoords.splitInt(",");
			for ( var i=0; i<c.length; i+=2 )
				this.areaCoords += (c[i]+this.dim[0]) + "," + (c[i+1]+this.dim[1]) + ",";
			this.areaCoords += (c[0]+this.dim[0]) + "," + (c[1]+this.dim[1]);
		}
		this.areaCoordsBup = this.areaCoords;

		// cache/preload images	- works for all browsers
		if ( id )
		{
			document.write( "<img style='position:absolute;left:-500px;top:-500px;' id='" + this.id + "_cacheimg0' src='" + this.images[0] + "' />" );
			document.write( "<img style='position:absolute;left:-500px;top:-500px;' id='" + this.id + "_cacheimg1' src='" + this.images[1] + "' />" );
			document.write( "<img style='position:absolute;left:-500px;top:-500px;' id='" + this.id + "_cacheimg2' src='" + this.images[2] + "' />" );			
		}
	},

	createAreaNode:	function() {
		var node = document.createElement('area');
		Object.extend(node,{id:this.id,shape:"POLYGON",coords:this.areaCoords,href:"javascript:void 1;"});

		Event.observe( node, "mouseover", this.handleEvent.bind(this) );
		Event.observe( node, "mouseout", this.handleEvent.bind(this) );
		Event.observe( node, "click", this.handleEvent.bind(this) );

		this.nodeArea = node;
		return node;
	},

	handleEvent: function(ev) {
		if ( !this.active ) return;
		this.changeImage(ev.type);
		if ( ev.type == "click" )
		{
			this.owner.optionsUpdate();
		}
	},

	createImageNode: function(pa,size) {
		var zi = [10,12,11];

		for ( var i=0; i<3; i++ )
		{
			var node = $(this.id+"_cacheimg"+i);

			Element.setStyle(node,{position:'absolute',left:'auto',top:'auto',marginLeft:(this.dim[0]+ 'px'),marginTop:(this.dim[1]+ 'px'),zIndex:zi[i],width:(this.dim[2]+'px'),height:(this.dim[3]+'px') });
			( i==0 ) ? (this.nodeImage = node) : (node.style["display"] = "none");

			this.nodeImages.push(node);
			pa.appendChild(node);
		}

		return node;
	},

	changeImage: function(mode) {
		if ( mode=='click' )
		{
			(this.isSelected=!this.isSelected) ? Element.show(this.nodeImages[2]) : Element.hide(this.nodeImages[2]);
			Element.hide(this.nodeImages[1]);
			if ( this.isSelected ) Element.show(this.nodeImages[0]);	// Show normal (unselected) image

			var el = $(this.nodeArea.id);
			if ( el.blur ) el.blur();
		}
		else if ( mode=='mouseover' )
		{
			var dur = ( /MSIE/.test(navigator.userAgent) && navigator.version()<6 ) ? 0.0 : 0.3;
			Effect.Appear( this.nodeImages[1], {duration:dur, to:0.5} );

		}
		else if ( mode=='mouseout' )
		{
			var dur = ( /MSIE/.test(navigator.userAgent) && navigator.version()<6 ) ? 0.0 : 0.05;
			Effect.Fade( this.nodeImages[1], {duration:dur} );
		}
		else if ( mode=='deselect' )
		{
			this.isSelected = false;
			Element.hide(this.nodeImages[2]);
			Element.show(this.nodeImages[0]);
		}
	},

	activate: function() {	// Activates this Area
		this.active = true;
		Element.show( this.id + "_cacheimg0" );
		Object.extend(this.nodeArea,{coords:this.areaCoordsBup});
	},

	deactivate: function() {	// Deactivates this Area
		this.active = false;
		Element.hide( this.id + "_cacheimg0" );
		Object.extend(this.nodeArea,{coords:'0,0,1,1'});
	},

	selectArea: function() {
		if ( !this.active || this.isSelected ) return;
		this.isSelected = false;
		this.changeImage("click");
	},

	deselectArea: function() {
		if ( !this.active || !this.isSelected ) return;
		this.isSelected = true;
		this.changeImage("click");
	}

};

/**
*	Class imsClassMap
*
*/
var imsClassMap = Class.create();
imsClassMap.prototype = {
	initialize: function(id,mapImage,w,h) {
		this.id			= id;
		this.mapImage	= imsImgRoot + imsLayoutPath + mapImage;
		this.Areas		= [];
		this.Quarters	= [];	// caches all quarters. speeds up updating the select
		this.mapSize	= new Array(w,h);
		this.isCached	= false;
		this.cacheMap	= null;
		this.infoArea = [];

		this.blockDiv	= null;

		// cache/preload image
		document.write( "<img style='display:none;' id='" + this.id + "_cacheimg' src='" + this.mapImage + "' />" );
	},

	addArea: function() {
		var area = new imsClassArea();
		var args = $A(arguments);
		args.reverse(true);
		args.push( Math.pow(2,this.Areas.length) );
		args.push( this );
		args.reverse(true);

		imsClassArea.apply( area, args );
		this.Areas.push(area);
	},

	addInfoArea: function(coords,title) {
		this.infoArea.push( {coords:coords, title:title} );
	},

	getArea: function(id) {
		for (var i=0; i<this.Areas.length; i++ )
			if ( this.Areas[i].id == id ) return this.Areas[i];
		return null;
	},

	getSelAreaBitField: function() {
		var bitField = 0;
		for ( var i=0; i<this.Areas.length; i++ )
			bitField += this.Areas[i].isSelected ? this.Areas[i].idInt : 0;

		return bitField;
	},

	addParameter: function(areaId, param) {
		var area = this.getArea( areaId );
		Object.extend( area, param );
	},

	create: function() {
		this.cacheMap = document.createElement('DIV');
		this.cacheMap.id = this.id + "_container";

		var nodeMap 	= document.createElement('map');
		nodeMap.name 	= this.id + "_map";
		nodeMap.id		= this.id + "_map";
		nodeMap.border	= "0";

		for ( var i=0; i<this.Areas.length; i++ ) {
			var node = this.Areas[i].createAreaNode();
			nodeMap.appendChild( node );

			ttAddElement( this.Areas[i].nodeArea, this.Areas[i].name, {fixed:false,keepOutsideElement:false,displayAtCenter:false,autoHide:true} );

			//this.cacheMap.appendChild( this.Areas[i].createImageNode() );
			this.Areas[i].createImageNode(this.cacheMap,this.mapSize)
		}

		// Info Tooltips
		for ( var j=0; j<this.infoArea.length; j++ )
		{
			//alert( "Appending info area tooltip" );
			var node = document.createElement('area');

			Object.extend(node,{shape:'POLYGON',coords:this.infoArea[j].coords,cursor:'default'});
			nodeMap.appendChild( node );
			ttAddElement( node, this.infoArea[j].title, {fixed:false,keepOutsideElement:false,displayAtCenter:false,autoHide:true} );

			/*
			Object.extend(node,{shape:'RECT',coords:'230,170,260,200',cursor:'default'});
			nodeMap.appendChild( node );
			ttAddElement( node, "Außen-Alster", {fixed:false,keepOutsideElement:false,displayAtCenter:false,autoHide:true} );
			*/
		}

		this.cacheMap.appendChild( nodeMap );

		var nodeImg = document.createElement('IMG');
		nodeImg.src					= imsImgRoot + "bl.gif";
		nodeImg.useMap				= "#" + nodeMap.name;
		nodeImg.border				= "0";
		nodeImg.width				= this.mapSize[0];
		nodeImg.height				= this.mapSize[1];
		nodeImg.style["position"]	= "absolute";
		nodeImg.style["zIndex"]		= "15";

		this.cacheMap.appendChild( nodeImg );

		nodeImg = document.createElement('IMG');
		nodeImg.src					= this.mapImage;
		nodeImg.style["position"]	= "absolute";
		nodeImg.style["zIndex"]		= "9";
		nodeImg.style["width"]		= (this.mapSize[0]+"px");
		nodeImg.style["height"]		= (this.mapSize[1]+"px");
		this.cacheMap.appendChild( nodeImg );

		var nodeMapContainer = $(imsPageElements["DivMapImage"]);
		nodeMapContainer.appendChild( this.cacheMap );

		this.blockDiv		= document.createElement('DIV');
		this.blockDiv.id	= this.id + "_block";
		Element.setStyle(this.blockDiv, {position:'absolute',zIndex:20,display:'none',background:'transparent',width:(this.mapSize[0]+'px'),height:(this.mapSize[1]+'px') } );		

		nodeMapContainer.appendChild( this.blockDiv );

		// Cache all quarters in an assoc array
		for ( var a=0; a<this.Areas.length; a++ )
		{
			for ( q=0; q<this.Areas[a].quarters.length; q++ )
			{
				if ( !this.Quarters[this.Areas[a].quarters[q]] )
					this.Quarters[this.Areas[a].quarters[q]] = [];
				
				this.Quarters[this.Areas[a].quarters[q]].push(this.Areas[a]);
			}
		}

		// Auswahloptionen unterhalb der Karte einfügen.
		// 23.01.2007 - Christian Dölling - Optionen nur einmal einfügen		
		if ( !$("imsMapSelectOptions") )
		{		
			var divBoxMap = $(imsPageElements["DivBoxMap"]);
			
			if ( divBoxMap )
			{
				var p = document.createElement('p');
				p.innerHTML = "<br />" + imsPageElements["SelectOptionsCT"];
				p.id = "imsMapSelectOptions";
				
				divBoxMap.appendChild(p);
			}
		}
		
		this.isCached = true;
	},

	activate: function() {
		if ( !this.isCached )	this.create();
		else					this.cacheMap.style["visibility"] = "visible";

		// Adjust Map-Container size
		Element.setStyle(imsPageElements["DivMapContainer"], {width:this.mapSize[0]+0+"px", height:this.mapSize[1]+0+"px"} );
	},

	deactivate: function() {
		this.cacheMap.style["visibility"] = "hidden";
	},

	activateArea: function() {},
	deactivateArea: function() {},

	optionsClear: function() {
		// TODO: Hier wird kein on Change übertragen - nachricht an die entsprechende ajax-routine in der suche schicken, dass sich die auswahl geändert hat
		$A($(imsPageElements["SelectQuarter"])).each( function(n) {n.selected = false; });

		// select_change( imsPageElements["SelectQuarter"] )
	},

	optionsUpdate: function() {
		var node	= $A($(imsPageElements["SelectQuarter"]));
		var a		= this.Areas;
		var count	= 0;
		var quarters = this.Quarters;
		
		node.each( function(n) {			
			n.selected = false;
			
			//if ( quarters[n.innerHTML] )
			if ( quarters[n.value] )			
			{
				//for ( var i=0; i<quarters[n.innerHTML].length; i++ )
				for ( var i=0; i<quarters[n.value].length; i++ )
				{
					//if ( quarters[n.innerHTML][i].isSelected )
					if ( quarters[n.value][i].isSelected )
					{
						n.selected=true;
						break;
					}
				}
			}
			// else alert( "Kein Eintrag für: " + n.value );
		});		

		/*
		this.optionsClear();
		a.each( function(q) {
			if ( q.isSelected )
			{
				node.each( function(n) {
					if( !n.selected && q.quarters.find( function(a) {return (a==n.innerHTML);} ) )
						n.selected=true;
				});
			}
		});
		*/
		/*
		node.each( function(n) {
			count++;
			n.selected = false;
			a.each( function(q) {
				count++;
				if ( q.isSelected && q.quarters.find( function(a) {return (a==n.innerHTML);}) )	// use n.value instead ?
				{
					n.selected=true;
				}
			});
		});
		*/

		//alert( count );
		// Hier wird kein onChange übertragen - nachricht an die entsprechende ajax-routine in der suche schicken, dass sich die auswahl geändert hat
		eval(externalFunctions["select_change"])( imsPageElements["SelectQuarter"] );
	},

	resetMap:	function() {
		var qa = [];
		var list = "Treffende Stadtgebiete:\n\n";
		var element = $(imsPageElements["SelectQuarter"]);

		// get available quarters/districts
		for (var i = 0; i<element.length; i++)
	        qa.push(element.options[i].value || element.options[i].text);

	    // check for areas with avail quarters
		for ( a=0; a<this.Areas.length; a++ )
		{
			this.Areas[a].deactivate();
			for ( var q=0; q<qa.length; q++ )
				if ( this.Areas[a].quarters.indexOf(qa[q]) != -1 )
				{
					this.Areas[a].activate();
					//list += this.Areas[a].id + " (" + this.Areas[a].name + ") - Stadtteil: " + qa[q] + "\n";
					list += qa[q] + " (" + this.Areas[a].name + ")\n";
				}
		}

		//alert( list );
	},

	selectAreasByQuarters: function() {
		var qa = $F(imsPageElements["SelectQuarter"]);	// get selected quarters
		for ( a=0; a<this.Areas.length; a++ )
		{
			this.Areas[a].deselectArea();
			var qc = [];
			for ( var q=0; q<qa.length; q++ )
			{
				if ( this.Areas[a].quarters.indexOf(qa[q]) != -1 )
				{
					if ( qc.indexOf(qa[q]) == -1 )
						qc.push(qa[q]);
				}
			}

			if ( qc.length == this.Areas[a].quarters.length )
				this.Areas[a].selectArea();
		}
	},

	// selects all areas which idInt match bitField. if bitField=-1, everything is selected
	selectAreasByBitField: function(bitField) {		
		if ( bitField<-1 || bitField>this.Areas[this.Areas.length-1].idInt*2-1 ) return;
		for ( var i=0; i<this.Areas.length; i++ )
		{
			if ( bitField == -1 )
				this.Areas[i].selectArea();
			else
			{
				if ( (bitField & this.Areas[i].idInt) > 0 )	this.Areas[i].selectArea();
				else										this.Areas[i].deselectArea();
			}
		}
		this.optionsUpdate();
	}


};

/**
*	Class imsClassMapContainer
*
*/
var imsClassMapContainer = Class.create();
imsClassMapContainer.prototype = {
	initialize: function() {
		this.Maps 		= [];
		this.MapsIdList	= [];
		this.activeMap	= null;
		this.activeMode	= 0;		// 0=Listbox, 1=Map
	},

	addMap: function(id,mapImage,w,h) {
		//alert( "imsClassMapContainer: addMap" );
		this.Maps[id] = new imsClassMap(id,mapImage,w,h);
		this.MapsIdList.push(id);
		return this.Maps[id];
	},

	addArea: function(idMap) {
		var args = ($A(arguments));
		args.shift();
		//args[0] = idMap + this.Maps[idMap].Areas.length;	// auto id
		this.Maps[idMap].addArea.apply( this.Maps[idMap], args );
	},

	activateMap: function(id) {
		if ( !this.Maps[id] ) {
			//alert( "maps doesn't exist" );
			return this.changeMode(2,id);
		}

		this.changeMode(this.activeMode);

		if ( this.activeMap == id ) return;
		if ( this.activeMap ) this.Maps[this.activeMap].deactivate();
		this.activeMap = id;
		this.Maps[this.activeMap].activate();
		
		//alert( this.activeMap );
		this.Maps[this.activeMap].resetMap();
		
		

		// Show Mode-Selector (redundant, but needed for first call after page load
		//Element.setStyle( imsPageElements["DivModeSwitch"], {display:'block'} );
	},

	blockActiveMap: function(doBlock) {
		if ( !this.activeMap ) return;

		if ( doBlock )
			//this.Maps[this.activeMap].blockDiv.style["display"] = "block";
			Element.show( this.Maps[this.activeMap].blockDiv );
		else
			//this.Maps[this.activeMap].blockDiv.style["display"] = "none";
			Element.hide( this.Maps[this.activeMap].blockDiv );
	},

	refresh: function() {
		if ( this.Maps[this.activeMap] ) this.Maps[this.activeMap].optionsUpdate();
	},

	getMapById: function(mapId) {
		return this.Maps[mapId] ? this.Maps[mapId] : null;
	},

	getSelAreaBitField: function() {
		var map = this.Maps[this.activeMap];
		if ( !map ) return -1;
		return map.getSelAreaBitField();
	},

	resetMap: function() {
		var map = this.Maps[this.activeMap];
		if ( !map ) return;
		for ( var i=0; i<map.Areas.length; i++ )
			map.Areas[i].changeImage("deselect");

		map.optionsClear();

		// check which quarters match areas
		map.resetMap();
	},

	updateQuarters: function() {
		this.update();
	},

	changeMode: function(mode,id) {
		this.activeMode = mode!=2 ? mode : 0;		// Always use listmode after an unsuccessful map-request
		//if ( mode != 2 ) this.activeMode = mode;	// Use last successful mode

		this.resetMap();
		
		//alert( this.activeMap );
		//alert( this.Maps[this.activeMap] );


		if ( mode == 0 ) // List
		{
			Element.hide(imsPageElements["DivBoxMap"]);
			Element.show(imsPageElements["DivBoxList"]);
			$(imsPageElements["DivModeSwitch"]).innerHTML = "<a class=\"icon15x15Change\" href=\"javascript:imsMapSelectMode(1);\">" + imsPageElements["DivModeSwitchCT"][0] + "</a>";
		}
		if ( mode == 1 ) // Map
		{
			Element.hide(imsPageElements["DivBoxList"]);				
			Element.show(imsPageElements["DivBoxMap"]);
			$(imsPageElements["DivModeSwitch"]).innerHTML = "<a class=\"icon15x15Change\" href=\"javascript:imsMapSelectMode(0);\">" + imsPageElements["DivModeSwitchCT"][1] + "</a>"

			// Scroll map to view
			Position.prepare();
			var mapPos 	= Position.cumulativeOffset($(imsPageElements["DivMapContainer"]));
			if ( document.getClientBottom() < mapPos[1]+this.Maps[this.activeMap].mapSize[1] )
				window.scrollTo( document.getScrollLeft(), document.getScrollTop() + mapPos[1]+this.Maps[this.activeMap].mapSize[1] - document.getClientBottom() + 50 );
		}
		if ( mode == 2 ) // No Map available
		{
			Element.show(imsPageElements["DivBoxList"]);
			Element.hide(imsPageElements["DivBoxMap"]);
			// 23.01.2007 - Christian Dölling - Erweiterung für die Unterscheidung zwischen Gewerbe und Wohnen
			// Gewerbe	=> mapName = Stadtname
			// Wohnen	=> mapName = Stadtname___Wohnen
			// Hierdurch muss der Mapname aus der id durch splitten nach "___" extrahiert werden
			//$(imsPageElements["DivModeSwitch"]).innerHTML = imsPageElements["DivModeSwitchCT"][2].replace(/#/,id);
			var cityName = id.split("___");
			$(imsPageElements["DivModeSwitch"]).innerHTML = imsPageElements["DivModeSwitchCT"][2].replace(/#/,cityName[0]);
		}
	},

	getActiveMode: function() {
		return this.activeMode;
	},

	selectAreasByQuarters: function() {
		if ( this.Maps[this.activeMap] )
			this.Maps[this.activeMap].selectAreasByQuarters();
	},

	selectAreasByBitField: function(bitField) {		
		if ( this.activeMode != 1 ) return;	// no selecting in other modes than "map"
		if ( this.Maps[this.activeMap] )
			this.Maps[this.activeMap].selectAreasByBitField(bitField);
	}
	
};

// GLOBAL MAP HOLDER
var glob_imsMaps = new imsClassMapContainer();

// GLOBAL FUNCTIONS

function imsmapsGetMapById(id) {
	if ( glob_imsMaps ) return glob_imsMaps.getMapById(id);
}
function imsBlockMap(doBlock) {
	if ( glob_imsMaps ) glob_imsMaps.blockActiveMap(doBlock);
}
function imsMapGetActiveMode() {
	if ( glob_imsMaps ) return glob_imsMaps.getActiveMode();
	return 0;
}
function imsSetActiveMap(mapName) {
	
	if ( !mapName )
	{
		var nodeSelectCity = $(imsPageElements["SelectCity"]);
		mapName = nodeSelectCity.value;
	}

	if ( mapName == "" ) return;
	if ( !glob_imsMaps ) return;

	// 04.04.2008 - Sonderfall Sylt
	if ( mapName == "city_sylt" ) {
		mapName = "Sylt";
	}
	
	// 23.01.2007 - Christian Dölling - Erweiterung für die Unterscheidung zwischen Gewerbe und Wohnen
	// Gewerbe	=> mapName = Stadtname
	// Wohnen	=> mapName = Stadtname___Wohnen
	
	var imsMapImmoArt = $(imsPageElements["SelectImmobilienArt"]);
	
	if ( imsMapImmoArt.value == 2 )	// Wohnen
		mapName += "___Wohnen";
		
	//alert( mapName );
	glob_imsMaps.activateMap(mapName);
}
function imsGetMapBitField() {
	if ( glob_imsMaps ) return glob_imsMaps.getSelAreaBitField();
	return -1;
}
function imsSelectAreasByBitField(bitField) {	
	if ( glob_imsMaps ) glob_imsMaps.selectAreasByBitField(bitField);
}
function imsSelectAreasByOptions() {
	glob_imsMaps.selectAreasByQuarters();
}
function imsSelectOptionsByArea() {
	glob_imsMaps.refresh();
}
function imsMapSelectMode(mode) {
	if ( glob_imsMaps ) glob_imsMaps.changeMode(mode);
}
function imsMapReset() {
	if ( glob_imsMaps ) glob_imsMaps.resetMap();
}
function imsMapUpdateQuarters() {
	if ( glob_imsMaps ) glob_imsMaps.updateQuarters();
}
function imsInit() {	
	if ( glob_imsMaps ) imsSetActiveMap();
}

// ACTIVATE
Event.observe( window, "load", imsInit );