function len(a){return a && a.length ? a.length : 0}
function cpyobj(a, b) {
	if (a) for (var i in a) b[i] = a[i];
	return b
}
function fixControlTooltips(mapNode) {
	$('.map-controls area', mapNode).each(function(){
		var n = $(this);
		n.attr("title", "<p>" + n.attr("title") + "</p>");
	});
}
function updateAreaTooltips(mapId){
	$('#' + mapId + ' area').tooltip();
}
function send2TomTom(addr){
	if (len(addr) != 3) return;
	var name = 'ANWB routeplanner: ' + addr[0],
    	url = 'http://addto.tomtom.com/api/home/v2/georeference?action=add&apikey=506c6fd3-4489-4658-a77e-25981cebeb06&name=' + name + '&latitude=' + addr[1] + '&longitude=' + addr[2] + '&attribution=ANWB routeplanner&logo=http://route.anwb.nl' + uStatic + '/img/anwblogo_popup.gif',
     	win = window.open(encodeURI(url), 'RouteTomTom', "toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=1");
    pageTracker._trackPageview("/outgoing/routeplanner/voeg-toe-aan-tomtom");
    win.focus();
}
function openWin(url, pageview) {
	if (pageview) pageTracker._trackPageview(pageview);
	window.open(url);
}
function openUrl(url, pageview) {
	if (pageview) pageTracker._trackPageview(pageview);
	window.location.href = url;
}

var dpMapWidth = 200, // decision point map width
	dpMapHeight = 150; // decision point map height
function zoomDpRect(id, mod, x1, y1, x2, y2){ // zoom to the given rectangle
	var mapImg = $('#' + id), zoom = Math.min(getZoomToFit(Math.abs(x2 - x1), Math.abs(y2 - y1), dpMapWidth, dpMapHeight) + 1 /* modifier */, zoomMax) + 1,
		x = Math.round((x1 + x2)/2), y = Math.round((y1 + y2)/2);
	mapImg.attr('src', controller + "?action=4&width=" + dpMapWidth + "&height=" + dpMapHeight + "&zoom=" + zoom + "&x=" + x + "&y=" + y + "&modality=" + mod); 
}
function showRoute(mod, x1, y1, x2, y2){
	var m = maps[mod];
	if (!m) return;
	m.showRoute(x1, y1, x2, y2);
}
function rowClicked(mod,x1,y1,x2,y2){
	showRoute(mod,x1,y1,x2,y2);
	window.location.hash = 'topmap';
}      
function iframeLoad(frm) {
	var iframe = window.frames[frm.name];
	$(frm).height(iframe.document.body.scrollHeight);
}
function submitPois(mod) {
	var frm = document.forms['frm-pois'], list = [];
	if (!frm) return;
	for (var i = 0; i < len(frm); i++){
		var e = frm.elements[i];
		if (e.name == 'pois' && e.checked) list.push(e.value);
	}
	ensurePoiMgr().store('loc', list);
	$(frm).trigger('poischanged', {'modality': mod, 'pois': list})
}
function loadPoiSettings(mod){
	var pois = ensurePoiMgr().get('loc');
	for (var i = 0; i < len(pois); i++) {
		var e = document.getElementById('pois-' + pois[i]); // due to possible , in id field: jquery not possible  
		if (e) e.checked = true; 
	}
	$(document.forms['frm-pois']).trigger('poischanged', {'modality': mod, 'pois': pois})
}
function reloadOverlay(mod){
	var map = maps[mod];
	if (map && map.hasOverlay()) 
		map.getOverlay().redraw(true)
}
function loadWeather(frmName, loc) {
	var frm = window.frames[frmName], loc = loc;
	if (!frm || !loc) return;
	frm.location = controller + '?action=24&city=' + loc['cityOrMuni'] + '&name=' + (loc['name'] || '') + '&x=' + loc['coord']['x'] + '&y=' + loc['coord']['y'];
}
function showError(msg){$("#error").removeClass('hide').html('<dl class="error"><dt>Er is iets misgegaan</dt>' + msg + '</dl>')}
function hideError(){$("#error").addClass('hide')}
function crtAppl(ths, hndlr){
	return function() { hndlr.apply(ths, arguments) }
}
function cancelEvent(e) {
	if (e.stopPropagation) e.stopPropagation(); else e.cancelBubble = true;
}

function Locator(locs){
	if (len(locs) == 1){
		this.loc = locs[0];
		this.locs = []
	} else {
		this.locs = locs || [];
		this.loc = null
	}
};
Locator.prototype.canSelect = function(){ 
	return len(this.locs) > 1
};
Locator.prototype.select = function(idx){
	if (idx < 0 || idx >= len(this.locs)) return; 
	this.lookupCb([this.locs[idx]])
};
Locator.prototype.hasSelection = function(){ 
	return !!this.loc
};
Locator.prototype.getSelection = function() {
	return this.loc
};
Locator.prototype.hasLocations = function() {
	return len(this.locs) > 0
};
Locator.prototype.getLocations = function() {
	return this.locs
};
Locator.prototype.clear = function() {
	this.loc = null;
	this.locs.length = 0;
};
Locator.prototype.lookup = function(loc){
	if (!loc) return;
	var prms = cpyobj({'action': 13}, cpyobj(loc, {}));
	$.get(controller, prms, crtAppl(this, this.lookupCb), 'jsonp');
};
Locator.prototype.lookupCb = function(data) {
	this.loc = null;
	this.locs.length = 0;
	if (len(data) > 0){
		if (len(data) == 1)
			this.loc = new Location(data[0]);
		else 
			for (var i = 0; i < len(data); i++)
				this.locs.push(new Location(data[i]));
	}
	$(this).trigger('updated')
};

function Location(loc){
	if (!loc) loc = {};
	this.street = loc['street'] || '';
	this.housenr = loc['housenr'] || '';
	this.zip = loc['zip'] || '';
	this.city = loc['city'] || '';
	this.muni = loc['muni'] || '';
	this.cityOrMuni = loc['cityOrMuni'];
	this.ensureCityOrMuni(); 
	this.countryCode = loc['countryCode'] || '528';
	this.countryName = loc['countryName'] || 'Nederland';
	this.name = loc['name'] || '';
	this.coord = loc['coord'] || {x:0, y:0};
	if (loc['wgs']) this.wgs = loc['wgs'];
	else if (loc['lat'] || loc['lon']) this.wgs = {lat:loc['lat'], lon:loc['lon']};
	else this.wgs = {lat:0, lon:0};
	this.description = loc['description'] || '';
	this.detailsUrl = loc['detailsURL'] || '';
	this.tomTomName = loc['tomTomName'] || '';
	this.lines = loc['lines'] || '';
};
function _enc(a) { return a ? escape(a) : '' }
function _dec(a) { return a ? unescape(a) : null }
Location.fromTag = function(tag){
	if (!tag) return null;
	var parts = tag.split('^');
	if (len(parts) != 12) return null;
	return new Location({'name':_dec(parts[0]),'coord':{'x':parts[1],'y':parts[2]},'street':_dec(parts[3]),'housenr':_dec(parts[4]),'zip':_dec(parts[5]),'city':_dec(parts[6]),'muni':_dec(parts[7]),'countryCode':parts[8],'countryName':_dec(parts[9]),'description':_dec(parts[10]),'detailsURL':_dec(parts[11])});
};
Location.prototype.getTag = function(){
	var a = [];
	a.push(_enc(this.name));
	a.push(this.coord && this.coord.x != 0 ? this.coord.x : '');
	a.push(this.coord && this.coord.y != 0 ? this.coord.y : '');
	a.push(_enc(this.street));
	a.push(_enc(this.housenr));
	a.push(_enc(this.zip));
	a.push(_enc(this.city));
	a.push(_enc(this.muni));
	a.push(this.countryCode);
	a.push(_enc(this.countryName));
	a.push(_enc(this.description));
	a.push(_enc(this.detailsUrl));
	return a.join('^')
};
Location.prototype.getAddressTag = function(){
	var a = [];
	a.push('');
	a.push(this.coord ? this.coord.x : '');
	a.push(this.coord ? this.coord.y : '');
	a.push(_enc(this.street));
	a.push(_enc(this.housenr));
	a.push(_enc(this.zip));
	a.push(_enc(this.city));
	a.push(_enc(this.muni));
	a.push(this.countryCode);
	a.push(_enc(this.countryName));
	a.push('');
	a.push('');
	return a.join('^')
};
Location.prototype.ensureCityOrMuni = function(){
	if (this.cityOrMuni) return;
	this.cityOrMuni = this.city ? this.city : this.muni ? this.muni : ''
};
Location.prototype.getLocationName = function() {
	var s = '';
	if (len(this.name) > 0) s += this.name;
	if (len(this.street) > 0) {
		if (len(s) > 0) s += ', ';
		s += this.street;
		if (len(this.housenr) > 0) s += ' ' + this.housenr; 
	}
	if (len(this.zip) > 0) {
		if (len(s) > 0) {
			s += ', ' + this.zip;
		} else {
			s += 'postcode ' + this.zip;
			if (len(this.housenr) > 0) s += ' nr ' + this.housenr;
		}
	}
	if (len(this.city) > 0) {
		if (len(s) > 0) s += ', ';
		s += this.city;
		if (len(this.muni) > 0 && this.muni != this.city) s += ' (' + this.muni + ')';
	} else if (len(this.muni) > 0) {
		if (len(s) > 0) s += ', ';
		s += this.muni + ' (gem.)';
	}
	if (len(this.country) > 0) {
		if (len(s) > 0) s += ', ';
		s += this.countryName;
	}
	return s
};
Location.fromInput = function(type){
	var loc = new Location();
	loc['countryCode'] = $('#country' + type + ':not(.defaultInput)').val() || '';
	loc['zip'] = $('#zip' + type + ':not(.defaultInput)').val() || '';
	loc['street'] = $('#street' + type + ':not(.defaultInput)').val() || '';
	loc['housenr'] = $('#housenr' + type + ':not(.defaultInput)').val() || '';
	loc['city'] = $('#city' + type + ':not(.defaultInput)').val() || '';
	loc['wgs'] = {'lat': $('#lat' + type).val(), 'lon': $('#lon' + type).val()};
	loc['name'] = $('#name' + type).val();
	loc['detailsURL'] = $('#details' + type).val();
	loc.ensureCityOrMuni(); 
	return loc
};
Location.prototype.toDomNode = function(node){
	this.ensureLines();
	var e = $('.lines', node).empty();
	$.each(this.lines, function(i, val){e.append(val + '<br/>')});
	$('.street-address', node).html(this.street + ' ' + this.housenr);
	$('.postal-code', node).html(this.zip);
	$('.locality', node).html(this.city);
	$('.country-name', node).html(this.countryName);
	$('.latitude', node).html(this.wgs['lat']);
	$('.longitude', node).html(this.wgs['lon'])
};
Location.prototype.ensureLines = function(){
	if (this.lines) return;
	this.lines = ['' + this.name];
	if (len(this.street) > 0 && len(this.zip) > 0 && len(this.city) > 0){
		var s = '' + this.street;
		if (len(this.housenr) > 0) s += ' ' + this.housenr;
		this.lines.push(s);
		
		s = '';
		if (len(this.zip) > 0) s += this.zip + ' ';
		s += this.city;
		if (len(this.muni) > 0 && this.muni != this.city) s += ' (' + this.muni + ');';
		this.lines.push(s);
	} else if (len(this.street) > 0 && len(this.zip) > 0) {
		var s = 'Postcode ' + this.zip;
		if (len(this.housenr) > 0) s += ' nr ' + this.housenr;
		this.lines.push(s);
		
		s = '' + this.city;
		if (len(this.muni) > 0 && this.muni != this.city) s += ' (' + this.muni + ');';
		this.lines.push(s);
	} else if (len(this.city) > 0) {
		s = '' + this.city;
		if (len(this.muni) > 0 && this.muni != this.city) s += ' (' + this.muni + ');';
		this.lines.push(s);
	} else if (len(this.muni) > 0) {
		this.lines.push(this.muni + ' (gem.)');
	}
	if (len(this.countryName) > 0) this.lines.push(this.countryName)
};
Location.prototype.getTomTomAddr = function(){
	var name = this['tomTomName'], lat = 0, lon = 0;
	if (this['wgs']){
		lat = this['wgs']['lat'];
		lon = this['wgs']['lon']
	}
	return [name, lat, lon]
}

function Router(){
	this.routes = {'car':{'state':0}, 'ov':{'state':0}, 'bike':{'state':0}, 'ped':{'state':0}};
	this.curr = null;
	this.prms = {}
};
Router.prototype.getCurrent = function(){return this.curr};
Router.prototype.setModStart = function(mod, a) {
	var e = this.routes[mod];
	if (e) e['start'] = a;
};
Router.prototype.setModDest = function(mod, a) {
	var e = this.routes[mod];
	if (e) e['dest'] = a;
};
Router.prototype.setModBounds = function(mod, a) {
	var e = this.routes[mod];
	if (e) e['bounds'] = a;
};
Router.prototype.reloadOverlay = function() {
	var e = this.routes[this.getCurrent()];
	if (!e) return;
	reloadOverlay(this.getCurrent());
	for (var i in this.routes){
		var route = this.routes[i];
		route['pois'] = route !== e
	}
};
Router.prototype.load = function(mods, isBg) {
	for (var i = 0; i < len(mods); i++) {
		if (mods[i]){
			var mod = mods[i].toLowerCase(), e = this.routes[mod];
			if (e['state'] === 0) {
				e['state'] = 1;
				$('#times-txt-' + mod).html('route wordt geladen...');
				var prms = cpyobj({'action':8, 'modality':mod}, cpyobj(this.prms, {}));
				$('#page-' + mod).load(controller, prms, this.crtLoadCb(mod, isBg));
			}
		}
	}
};
Router.prototype.crtLoadCb = function(mod, isBg){
	var ths = this;
	return function(res, stat, req){
		mod = mod.toLowerCase();
		if (stat != 'success' || !ths.routes[mod]) {
			$(this).trigger('error', [mod, isBg]);
			return
		}
		ths.routes[mod]['state'] = 2; // Set as loaded
		ths.routes[mod]['pois'] = false;
		ths.loadData(mod); // load data
		// Visualize tab
		$('#tab-' + mod).removeClass('hide');
		$(this).trigger('load', [mod]);
		if (!isBg) ths.selectTab(mod)
	}
};
Router.prototype.loadData = function(mod){
	var data = $('#tab-data-' + mod).get(0);
	if (!data) return;
	
	// Set tab actions
	this.initTabLinks(mod);
	
	// import js blocks
	var head = $($('head')[0]);
	$('.import-js', data).each(function(i, jsNode){head.append('<script type="text/javascript">' + $(jsNode).html() + '</script>')});
	
	// Remove initialize container
	$(data).remove()
};
Router.prototype.loadPref = function(mod, start, dest, bounds) {
	var e = this.routes[mod];
	if (typeof e === undefined) return;
	this.curr = mod;
	this.setModStart(mod, start);
	this.setModDest(mod, dest);
	this.setModBounds(mod, bounds);
	this.crtLoadCb(mod, false)(null, 'success', null)
};
Router.prototype.setParameters = function(o) {
	if (!o) return;
	for (var i in o) this.setParameter(i, o[i])
};
Router.prototype.setParameter = function(n, v) {
	this.prms[n] = v
};
Router.prototype.selectTab = function(mod){
	if (!this.routes[mod] || this.routes[mod]['state'] !== 2) return;
	if (this.curr && this.curr != mod) {
		$('#tab-' + this.curr).removeClass('selected');
		$('#page-' + this.curr).addClass('hide');
	}
	$('#tab-' + mod).addClass('selected');
	$('#page-' + mod).removeClass('hide');
	this.curr = mod;
	var map = maps[mod];
	if (map){
		if (!map.hasMap()){
			this.routes[mod]['pois'] = false;
			map.initMap().addOverlay();
		} else if (this.routes[mod]['pois']){
			this.routes[mod]['pois'] = false;
			reloadOverlay(mod)
		}
	}
	$(this).trigger('selecttab', [mod])
};
function crtSelTabCb(rt, mod){return function(){rt.selectTab(mod);return false}}
function crtCenterOn(mod, c, z){return function(){if (maps[mod]) maps[mod].getMap().setCenter(c, z);return false}}
//function crtCenterBounds(mod, b){return function(){zoomRect(mod, b[0], b[1], b[2], b[3]);return false}}
function crtSubmitPois(mod, rld){return function(){submitPois(mod, rld);return false}}
Router.prototype.initTabLinks = function(mod){
	$('.tab-select.' + mod).click(crtSelTabCb(this, mod));
};
Router.prototype.setError = function(mod){
	this.routes[mod] && (this.routes[mod]['error'] = true)
};
Router.prototype.hasError = function(mod){
	return !!(this.routes[mod] && this.routes[mod]['error'])
};

function getCookieValue(name){
	var ck = document.cookie, parts, item;
	if (len(ck) > 0){
		parts = ck.split(';');
		for (var i = 0; i < len(parts); i++){
			item = $.trim(parts[i]).split('=');
			if (item[0] == name) return unescape(item[1])
		}
	}
	return ''
}
function setBit(s, idx, b){
	if (idx < 0) return '';
	if (idx >= len(s)) {var cnt = idx - len(s); while (--cnt > 0) s += '0'; return s + (b ? '1' : '0')}
	return s.substr(0, idx) + (b ? '1' : '0') + s.substr(idx + 1)
}
function isBit(s, idx){return idx < 0 || idx >= len(s) ? false : s.charAt(idx) == '1'}

function PoiManager(){
	this.name = 'ANWB-RP-Poi-';
	this.cache = {}
};
PoiManager.prototype.get = function(mod){
	if (!this.cache[mod]){
		var s = getCookieValue(this.name + mod);
		this.cache[mod] = len(s) == 0 ? [] : s.split('|');
	}
	return this.cache[mod]
};
PoiManager.prototype.store = function(mod, ids){
	this.cache[mod] = ids || [];
	this.writeCookie(mod)
	return this
};
PoiManager.prototype.writeCookie = function(mod){
	document.cookie = this.name + mod + '=' + escape(this.cache[mod].join('|')) + '; expires=' + getGMTString(366) + '; path=/'
};
var poiMgr = null; 
function ensurePoiMgr(){
	if (!poiMgr) poiMgr = new PoiManager();
	return poiMgr
}
function SettingsJar(){
	this.name = 'ANWB-RP-Settings';
	this.parts = (getCookieValue(this.name) || '000|||').split('|')
};
SettingsJar.prototype.storeFrom = function(b) {
	this.parts[0] = setBit(this.parts[0], 0, b);
	if (!b) this.parts[1] = '';
	this.writeCookie()
};
SettingsJar.prototype.hasStoreFrom = function(){
	return isBit(this.parts[0], 0)
};
SettingsJar.prototype.storeFromValue = function(v) {
	this.parts[1] = v;
	this.writeCookie()
};
SettingsJar.prototype.getFromValue = function() {
	return this.parts[1]
};
SettingsJar.prototype.storeTo = function(b) {
	this.parts[0] = setBit(this.parts[0], 1, b);
	if (!b) this.parts[2] = '';
	this.writeCookie()
};
SettingsJar.prototype.hasStoreTo = function(){
	return isBit(this.parts[0], 1)
};
SettingsJar.prototype.storeToValue = function(v) {
	this.parts[2] = v;
	this.writeCookie()
};
SettingsJar.prototype.getToValue = function() {
	return this.parts[2]
};
SettingsJar.prototype.storeMode = function(b) {
	this.parts[0] = setBit(this.parts[0], 2, b);
	if (!b) this.parts[3] = '';
	this.writeCookie()
};
SettingsJar.prototype.hasStoreMode = function(){
	return isBit(this.parts[0], 2)
};
SettingsJar.prototype.storeModeValues = function(tm, mode, obstr) {
	var s = ''
	for (var i = 0; i < len(tm); i++) s = setBit(s, i, tm[i]);
	this.parts[3] = s + '^' + mode + '^' + (obstr ? '1' : '0');
	this.writeCookie()
};
SettingsJar.prototype.getModeValues = function() {
	var a = [], parts = this.parts[3].split('^');
	for (var i = 0; i < len(parts[0]); i++)
		a.push(isBit(parts[0], i));
	return {'methods': a, 'mode': parts[1], 'obstr': parts[2] == '1'} 
};
function getGMTString(d){
	var exp = new Date();
	exp.setTime(exp.getTime() + (d*24*60*60*1000));
	return exp.toGMTString()
}
SettingsJar.prototype.writeCookie = function(){
	document.cookie = this.name + '=' + escape(this.parts.join('|')) + '; expires=' + getGMTString(366) + '; path=/'
};

function crtDelOvl(mod, act){
	return function() { 
		return '&action=' + act + '&modality=' + mod + '&pois=' + ensurePoiMgr().get('loc')
	}
}
function crtMapPrms(e, w, h, x, y){return function(){ return {zoom: getZoomToFit(w, h, e.offsetWidth, e.offsetHeight), coord: new Andes.Coordinate(x, y)}}}

function getZoomToFit(width, height, nodeWidth, nodeHeight) {
	if (!zoomScales) return zoomMin;
	var mpp = Math.max(width/nodeWidth, height/nodeHeight), i = 0, l = len(zoomScales);
	while (l--) {
		if (mpp <= zoomScales[i])
			return i + zoomMin;
		i++
	}
	return zoomMax
}	

var maps = {}, ovls = [], projection, imagePath, element, modality, zoomMin, zoomMax, zoomScales;
function initMap(tileUrl, zoomscales)
{
	zoomMin = 0;
	zoomMax = len(zoomscales) - 1;
	zoomScales = zoomscales;
	mapType = new Andes.GmMapType({id: 'EUset', baseUrls: [tileUrl], title: 'EU', scales: zoomScales, tileSize: new Andes.Size(256, 256), copyrights: ['Andes','NavTeq'], panBounds: new Andes.Rectangle(new Andes.Coordinate(-1188000, 3996000), new Andes.Coordinate(3546000, 11532000))});
	projection = mapType.getProjection();
    imagePath = uStatic + '/img/map/';
}
function MapWrapper(e, mod, delCrtImgPrms, delCrtJsPrms, delGetMapPrms)
{
	this.prnt = e;
	this.mod = mod;
	this.imgPrms = delCrtImgPrms;
	this.jsPrms = delCrtJsPrms;
	this.mapPrms = delGetMapPrms;
}
MapWrapper.prototype.initMap = function(){
	var prms = this.mapPrms(),
		map = new Andes.Map(this.prnt, {mapTypes: [mapType], 'images': imagePath}),
		c = new Andes.Coordinate(prms['coord']['x'], prms['coord']['y']);
	map.saveHomeLocation(c);
	map.setCenter(c, prms['zoom'] + 1);
	this.map = map;
	
 	map.enableScrollWheelZoom();
	map.enableDoubleClickZoom();
    map.enableContinuousZoom();
    
	ctrlPan = new Andes.PanControl({dragOpacity: .5});
	map.addControl(ctrlPan);
	ctrlCopyright = new Andes.CopyrightControl();
	map.addControl(ctrlCopyright);
	map.addControl(new Andes.ScaleControl());
	
	fixControlTooltips(this.prnt);
	$(this).trigger('load');
	return this;
}
MapWrapper.prototype.hasMap = function(){ 
	return !!this.map;
};
MapWrapper.prototype.getMap = function(){
	if(!this.map) this.initMap();
	return this.map;
};
MapWrapper.prototype.hasOverlay = function(){
	return !!this.ovl
};
MapWrapper.prototype.getOverlay = function(){
	return this.ovl
};
MapWrapper.prototype.addOverlay = function(){
	if (!this.map) return;
	var ovl = new Andes.ImageOverlay({getImageUrl : getImageOverlay, getMapUrl : getMapOverlay, isPng: true});				
	this.map.addOverlay(ovl);
    this.ovl = ovl;
    return this
};
MapWrapper.prototype.centerOn = function(coordinate, zl){
	return this.getMap().setCenter(coordinate,zl);
}
MapWrapper.prototype.showRoute = function(x1,y1,x2,y2){
	var southWest = new Andes.Coordinate(x1,y1);
	var northEast = new Andes.Coordinate(x2,y2);
	var centre = new Andes.Coordinate(x1+((Math.abs(x2-x1))/2), y1+((Math.abs(y2-y1))/2));
	if(this.map)
		{var zoomlevel = this.map.getRectZoom(new Andes.Rectangle(southWest,northEast));
		this.centerOn(centre,zoomlevel);}
	
}
MapWrapper.prototype.getImgPrms = function(){
	return this.imgPrms()
}
MapWrapper.prototype.getJsPrms = function(){
	return this.jsPrms()
}

function createMap(e, mod, delCrtImgPrms, delCrtJsPrms, delGetMapPrms){
	return maps[mod] = new MapWrapper(e, mod, delCrtImgPrms, delCrtJsPrms, delGetMapPrms);
}
function getMapObject(mod) {
	return maps[mod].getMap();
}
function getImageOverlay(options)
{
	var result;
	var x1 = options.bounds.getSouthWest().x;
	var y1 = options.bounds.getSouthWest().y; 
	var x2 = options.bounds.getNorthEast().x;
	var y2 = options.bounds.getNorthEast().y;

	var map;
	if(typeof(locator)!='undefined')
	{
		map = maps['loc'];
		var loc = locator.getSelection();
	}
	else if(typeof(router)!='undefined')
		var map = maps[router.getCurrent()];	
		
	result = controller + '?' + map.getImgPrms() + '&x1=' + Math.round(x1) + '&y1=' + Math.round(y1) + '&x2=' + Math.round(x2) + '&y2=' + Math.round(y2) + '&w=' + options.size.width + '&h=' + options.size.height + '&z=' + options.zoom + "&" + new Date().getTime();
	if(loc)
		result += "&x=" + Math.round(loc['coord']['x']) + "&y=" + Math.round(loc['coord']['y']);

	return result; 
}
function getMapOverlay(options)
{
	var result = "";
	var map;
	if(typeof(router)!='undefined')
		map = maps[router.getCurrent()];
	else if (typeof(locator)!='undefined')
		map	= maps['loc'];
		
	var x1 = options.bounds.getSouthWest().x;
	var y1 = options.bounds.getSouthWest().y; 
	var x2 = options.bounds.getNorthEast().x;
	var y2 = options.bounds.getNorthEast().y;
	result = controller + '?' + map.getJsPrms() + "&x1=" + Math.round(x1) + "&y1=" + Math.round(y1) + "&x2=" + Math.round(x2) + "&y2=" + Math.round(y2) + "&w=" + options.size.width + "&h=" + options.size.height + "&z=" + options.zoom + "&" + new Date().getTime();

	return result;
}
