function $(id) { return document.getElementById(id) }
function val(id, val) { var e = $(id); if (e) e.value = val }
function isempty(id) { return $(id).val == '' }
function disable(id, b) { $(id).disabled = b }
function eKey(evt) { return evt.which || evt.keyCode }
function trim(s) { while (s.substring(0,1) == ' ') s = s.substring(1, s.length); while (s.substring(s.length-1,s.length) == ' ') s = s.substring(0, s.length-1); return s }
function toggle(e){ if (e) e.style.display = e.style.display == '' ? 'none' : '' }
function showOnMap(){ toggle($('onMap')) }
function hideOnMap(){ $('onMap').style.display = 'none' }
function showError() { var e = $('description').style.display = '' }
function goBack(){ history.back() }
function showAttributes(id){
	var e = $('attribute-set' + id + '-group');
	if (e.style.display == '') {
		e.style.display = 'none';
		$('attribute-set' + id).className = 'attributes-in'
	} else {
		e.style.display = '';
		$('attribute-set' + id).className = 'attributes-out'
	}
} 

var dpMapWidth = 200, dpMapHeight = 150;	// decision point map width & map height
function zoomDpRect(id, x1, y1, x2, y2){	// zoom to the given rectangle
	var mapImg = $(id),
		zoom = getZoomToFit(x2 - x1, y2 - y1, dpMapWidth, dpMapHeight),
		x = Math.round((x1 + x2)/2),
		y = Math.round((y1 + y2)/2),
		url = controller + "&action=4&width=" + dpMapWidth + "&height=" + dpMapHeight + "&zoom=" + zoom + "&x=" + x + "&y=" + y;
	mapImg.src = url; 
}
   
function getZoomToFit(width, height, mapWidth, mapHeight) {
	var mpp = Math.max(width/mapWidth, height/mapHeight);
	for (zoom = zoomMin; zoom <= zoomMax; zoom++) if (mpp < mpps[zoom]) break;
	return Math.min(zoomMax, zoom);      
}

