<?php
# $Id$
# http://www.mapbender.org/index.php/mod_selectMapsize.php
# Copyright (C) 2002 CCGIS 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

require_once(dirname(__FILE__)."/../php/mb_validateSession.php");

$sql = "SELECT e_src, e_target FROM gui_element WHERE e_id = 'selectMapsize' AND fkey_gui_id = $1";
$v = array($gui_id);
$t = array('s');
$res = db_prep_query($sql, $v, $t);
$cnt = 0;
while($row = db_fetch_array($res)){ 
	$e_target = $row["e_target"];
	$cnt++;
}
if($cnt > 1){
	echo "alert('selectMapsize: ID not unique!');";
}
echo "var mod_selectMapsize_target = '".$e_target."';";
?>

function mod_selectMapsize(obj){
	var ind = getMapObjIndexByName(mod_selectMapsize_target);     
	var p = obj.value.split(",");
	var w = parseInt(p[0]) ;
	var h = parseInt(p[1]);
	var pos = makeClickPos2RealWorldPos(mod_selectMapsize_target,w,h);
	var coords = mb_mapObj[ind].extent.split(",");
	mb_mapObj[ind].extent = coords[0] + "," + pos[1] + "," + pos[0] + "," + coords[3]; 
	mb_mapObj[ind].width = w;
	mb_mapObj[ind].height = h;
	document.getElementById(mod_selectMapsize_target).style.width = mb_mapObj[ind].width;
	document.getElementById(mod_selectMapsize_target).style.height = mb_mapObj[ind].height;
	window.frames[mod_selectMapsize_target].document.getElementById("maps").style.width = mb_mapObj[ind].width;
	window.frames[mod_selectMapsize_target].document.getElementById("maps").style.height = mb_mapObj[ind].height;
	setMapRequest(mod_selectMapsize_target);
}