
Fusion.Lib.ConfigMgr=Class.create();Object.extend(Fusion.Lib.ConfigMgr.prototype,{oApp:null,oBroker:null,aoMapWidget:null,oWebLayout:null,oWebLayout:null,aWidgetNames:[],aWidgets:null,initialize:function(app,sessionid){this.oApp=app;this.aoMapWidget=[];this.aWidgets=[];this.scriptLang=app.getScriptLanguage();this.redirectScript=app.getRedirectScript();this.sessionID=sessionid||null;this.createWebLayout();},createWebLayout:function()
{this.oWebLayout=new Fusion.Lib.WebLayout(this.oApp);this.oWebLayout.registerForEvent(Fusion.Event.WEBLAYOUT_PARSED,this.loadWidgets.bind(this));this.oWebLayout.parse();},getListofWidgets:function(){var oCommand=null;var sTmp;var aCommands=[];for(var i=0;i<this.oWebLayout.commandObj.length;i++){oCommand=this.oWebLayout.commandObj[i];if($(oCommand.getName())){aCommands.push(oCommand);}}
return aCommands;},getListofToolbarWidgets:function(){var aCommands=[];var toolbars=this.oWebLayout.aToolbars;for(var i=0;i<toolbars.length;i++){if($(toolbars[i].container)){for(var j=0;j<toolbars[i].buttons.length;j++){var button=toolbars[i].buttons[j];if(button.func=='Command'){var oCommand=this.oWebLayout.getCommandByName(toolbars[i].buttons[j].obj.name);if(oCommand){aCommands.push(oCommand);}}else if(button.func=='Flyout'){aCommands=aCommands.concat(this.getListofMenuWidgets(button.obj.subItems));}}}}
return aCommands;},getListofContextMenuWidgets:function(){var aCommands=[];var menus=this.oWebLayout.aMenus;for(var i=0;i<menus.length;i++){if(menus[i].mapName==''||this.getMapByName(menus[i].mapName)){aCommands=aCommands.concat(this.getListofMenuWidgets(menus[i].items));}}
return aCommands;},getListofMenuWidgets:function(menuItems){var aCommands=[];for(var i=0;i<menuItems.length;i++){var item=menuItems[i];switch(item.func){case'Separator':break;case'Command':var oCommand=this.oWebLayout.getCommandByName(item.obj.name);if(oCommand){aCommands.push(oCommand);}
break;case'Flyout':aCommands=aCommands.concat(this.getListofMenuWidgets(item.obj.subItems));break;default:}}
return aCommands;},loadWidgets:function(){var aCommands=this.getListofWidgets();aCommands=aCommands.concat(this.getListofToolbarWidgets());aCommands=aCommands.concat(this.getListofContextMenuWidgets());for(var i=0;i<aCommands.length;i++){var c=aCommands[i];var js=c.sLocation+'/'+c.getAction()+'.js';Fusion.require(js);}
this.oApp.setLoadState(this.oApp.LOAD_WIDGETS);},createWidgets:function(){this.createMapWidget();this.createAllWidgets();this.createToolbars();this.createContextMenus();},createMapWidget:function(){var aCommands=this.oWebLayout.getCommandByType('MapCommandType');if(aCommands.length>0)
{var oCommand=null;for(var i=0;i<aCommands.length;i++)
{oCommand=aCommands[i];var oElement=$(oCommand.getName());if(oElement!=null)
{var widget;var sID=this.sessionID?',"'+this.sessionID+'"':'';var sTmp='widget = new Fusion.Widget.'+oCommand.getAction()+'(oCommand'+sID+')';eval(sTmp);if($(oCommand.getName())){$(oCommand.getName()).widget=widget;}
this.aoMapWidget.push(widget);}}}},getMapInfo:function(resourceId){for(var i=0;i<this.oWebLayout.aMaps.length;i++){if(this.oWebLayout.aMaps[i].resourceId==resourceId){return this.oWebLayout.aMaps[i];}}
return null;},getMapByName:function(sName)
{var nMaps=this.aoMapWidget.length;var oMap=null;for(var i=0;i<nMaps;i++)
{if(this.aoMapWidget[i].getMapName()==sName){oMap=this.aoMapWidget[i];break;}}
return oMap;},getMapById:function(sId)
{var nMaps=this.aoMapWidget.length;var oMap;for(var i=0;i<nMaps;i++)
{oMap=this.aoMapWidget[i];if(oMap.getDomId()==sId)
{return oMap;}}
return null;},getMapByIndice:function(nIndice)
{if(nIndice<this.aoMapWidget.length)
{var oMap=this.aoMapWidget[nIndice];return oMap;}
return null;},createAllWidgets:function()
{var aCommands=this.getListofWidgets();for(var i=0;i<aCommands.length;i++){var oCommand=aCommands[i];if(oCommand.getAction()!=''&&oCommand.getAction()!='MGMap'&&oCommand.getAction()!='MSMap'){var widget;var sTmp='widget = new Fusion.Widget.'+oCommand.getAction()+'(oCommand)';eval(sTmp);this.aWidgets.push(widget);if($(oCommand.getName())){$(oCommand.getName()).widget=widget;}}}},createToolbars:function(){var dummyAction=new Jx.Action(null);var toolbars=this.oWebLayout.aToolbars;if(toolbars.length>0){for(var i=0;i<toolbars.length;i++){var toolbarObj=$(toolbars[i].container);if(toolbarObj){var toolbar=toolbars[i];var tb=new Jx.Toolbar(toolbarObj);tb.domObj.id=toolbar.name;for(var j=0;j<toolbar.buttons.length;j++){var id='toolbar'+i+'command'+j;var button=toolbar.buttons[j];var tbItem=null;switch(button.func){case'Separator':tb.add(new Jx.ToolbarSeparator());break;case'Command':var oCommand=this.oWebLayout.getCommandByName(button.obj.name);tbItem=new Jx.ToolbarItem();tbItem.domObj.id=id;tb.add(tbItem);var oldName=oCommand.getName();oCommand.setName(id);var widget;var sTmp='widget = new Fusion.Widget.'+oCommand.getAction()+'(oCommand)';eval(sTmp);this.aWidgets.push(widget);oCommand.setName(oldName);break;case'Flyout':var options={};options.label=button.obj.label;options.tooltip=button.obj.tooltip;if(button.obj.imageUrl!=''){options.imgPath=button.obj.imageUrl;}
var menu=new Jx.Menu(options);this.processMenuUiItems(button.obj.subItems,menu,null);tb.add(menu);break;default:tb.add(new Jx.ToolbarSeparator());}}}}}},createContextMenus:function(){var menus=this.oWebLayout.aMenus;if(menus.length>0){for(var i=0;i<menus.length;i++){var oMap=null;if(menus[i].mapName!=''){oMap=this.getMapByName(menus[i].mapName);}else{oMap=this.getMapByIndice(0);}
var menu=new Jx.ContextMenu();this.processMenuUiItems(menus[i].items,menu,oMap);oMap.setContextMenu(menu);}}},processMenuUiItems:function(menuItems,menu,oMap){for(var i=0;i<menuItems.length;i++){var item=menuItems[i];switch(item.func){case'Separator':break;case'Command':var widget=this.createWidgetFromCommandName(item.obj.name,'');if(widget){if(widget.isMenuWidget){menu.add(widget.getMenu());}else{var action;if(oMap){action=new Jx.Action(oMap.executeFromContextMenu.bind(oMap,widget));widget.registerForEvent(Fusion.Event.WIDGET_STATE_CHANGED,function(eventID,aWidget){this.setEnabled(aWidget.isEnabled());}.bind(action));}else{action=new Jx.Action(widget.activateTool.bind(widget));}
var options={};options.label=widget._oCommand.sLabel;options.image=widget._oCommand.sImageurl;menu.add(new Jx.MenuItem(action,options));}}
break;case'Flyout':var options={};options.label=item.obj.label;if(item.obj.imageUrl!=''){options.image=item.obj.imageUrl;}
var subMenu=new Jx.SubMenu(options);this.processMenuUiItems(item.obj.subItems,subMenu,oMap);menu.add(subMenu);break;default:}}},createWidgetFromCommandName:function(name,id){var widget=null;var oCommand=this.oWebLayout.getCommandByName(name);if(oCommand){var oldName=oCommand.getName();oCommand.setName('');var widget;var sTmp='widget = new Fusion.Widget.'+oCommand.getAction()+'(oCommand)';eval(sTmp);this.aWidgets.push(widget);oCommand.setName(oldName);}
return widget;},getWidgetById:function(id){return $(id).widget;},getWidgetsByType:function(type){var a=[];for(var i=0;i<this.aWidgets.length;i++){if(this.aWidgets[i].sName==type){a.push(this.aWidgets[i]);}}
return a;}});var DomNode=Class.create();DomNode.prototype={initialize:function(xmlNode){this.textContent='';this.nodeName=xmlNode?xmlNode.nodeName:'';this.parentNode=arguments[1]?arguments[1]:null;this.childNodes=[];this.attributes=[];this.attributeNames=[];if(xmlNode){if(xmlNode.attributes){for(var i=0;i<xmlNode.attributes.length;i++){this.attributeNames.push(xmlNode.attributes[i].name);this.attributes[xmlNode.attributes[i].name]=xmlNode.attributes[i].nodeValue;}}
for(var i=0;i<xmlNode.childNodes.length;i++){if(xmlNode.childNodes[i].nodeType!=3){this.childNodes.push(new DomNode(xmlNode.childNodes[i],this));}else{this.textContent=this.textContent+xmlNode.childNodes[i].nodeValue;}}}
this._currentNode=0;},getAttribute:function(name){return typeof(this.attributes[name])!='undefined'?this.attributes[name]:null;},removeChild:function(child){var result=null;for(var i=0;i<this.childNodes.length;i++){if(this.childNodes[i]==child){this._currentNode=0;this.childNodes.splice(i,1);child.parentNode=null;result=child;break;}}
return result;},appendChild:function(child){if(child.parentNode){child.parentNode.removeChild(child);}
child.parentNode=this;this.childNodes.push(child);},insertBefore:function(newChild,refChild){var bInserted=false;if(refChild){for(var i=0;i<this.childNodes.length;i++){if(this.childNodes[i]==refChild){if(newChild.parentNode){newChild.parentNode.removeChild(child);}
newChild.parentNode=this;this.childNodes.splice(i,0,newChild);bInserted=true;break;}}}
if(!bInserted){this.appendChild(newChild);}},toString:function(depth){var s='';var spacer='';for(i=0;i<depth;i++){spacer=spacer+'';}
s=spacer+'&lt;'+this.nodeName;if(this.attributes.length>0){for(var name in this.attributes){if(typeof(this.attributes[name])=='String'){s=s+' '+name+'="'+this.attributes[name]+'"';}}}
s=s+'&gt;'
if(this.childNodes.length==0){s=s+this.textContent;spacer='';}else{s=s+'\n';}
for(var i=0;i<this.childNodes.length;i++){s=s+this.childNodes[i].toString(depth+1);}
s=s+spacer+'&lt;/'+this.nodeName+'&gt;';return s;},toXML:function(){var s=this.parentNode?'':'<?xml version="1.0" encoding="UTF-8"?>\n';s=s+'<'+this.nodeName;if(this.attributeNames.length>0){for(var i=0;i<this.attributeNames.length;i++){var name=this.attributeNames[i];s=s+' '+name+'="'+this.attributes[name]+'"';}}
s=s+'>'
if(this.childNodes.length==0){var content=this.textContent+'';content=content.replace('&','&amp;');content=content.replace(/</g,encodeURIComponent('&lt;'));content=content.replace(/>/g,encodeURIComponent('&gt;'));s=s+content;}
for(var i=0;i<this.childNodes.length;i++){s=s+this.childNodes[i].toXML();}
s=s+'</'+this.nodeName+'>\n';return s;},getNodeText:function(name){var s='';var n=this.findFirstNode(name);if(n){s=n.textContent;}
return s;},setNodeText:function(name,value){var n=this.findFirstNode(name);if(n){n.setTextContent(value);}},setTextContent:function(value){this.textContent=value;},setAttribute:function(name,value){if(typeof this.attributes[name]=='undefined'){this.attributeNames.push(name);}
this.attributes[name]=value;},findFirstNode:function(name){this._currentNode=0;if(this.nodeName==name){return this;}else{for(var i=0;i<this.childNodes.length;i++){var node=this.childNodes[i].findFirstNode(name);if(node){if(node.parentNode==this){this._currentNode=i+1;}else{this._currentNode=i;}
return node;}}
return false;}},findNextNode:function(name){if(this.nodeName==name){return this;}else{for(var i=this._currentNode;i<this.childNodes.length;i++){var node=this.childNodes[i].findNextNode(name);if(node){if(node.parentNode==this){this._currentNode=i+1;}else{this._currentNode=i;}
return node;}}
return false;}}};var DomNodeFactory={create:function(name,value){var node=new DomNode();node.nodeName=name;node.textContent=value||'';return node;}};Fusion.Error=Class.create();Fusion.Error.prototype={FATAL:0,WARNING:1,NOTICE:2,type:null,message:null,initialize:function(type,message){this.type=type;this.message=message;},alert:function(){var type=this.typeToString(this.type);alert('Fusion Error: '+type+'\n'+this.message);},toString:function(){var type=this.typeToString(this.type);return type+": "+this.message;},typeToString:function(type){switch(type){case Fusion.Error.FATAL:return'FATAL';case Fusion.Error.WARNING:return'WARNING';case Fusion.Error.NOTICE:return'NOTICE';default:return'UNKNOWN ('+type+')';}}};Fusion.Lib.ConfigMgr=Class.create();Object.extend(Fusion.Lib.ConfigMgr.prototype,{oApp:null,oBroker:null,aoMapWidget:null,oWebLayout:null,oWebLayout:null,aWidgetNames:[],aWidgets:null,initialize:function(app,sessionid){this.oApp=app;this.aoMapWidget=[];this.aWidgets=[];this.scriptLang=app.getScriptLanguage();this.redirectScript=app.getRedirectScript();this.sessionID=sessionid||null;this.createWebLayout();},createWebLayout:function()
{this.oWebLayout=new Fusion.Lib.WebLayout(this.oApp);this.oWebLayout.registerForEvent(Fusion.Event.WEBLAYOUT_PARSED,this.loadWidgets.bind(this));this.oWebLayout.parse();},getListofWidgets:function(){var oCommand=null;var sTmp;var aCommands=[];for(var i=0;i<this.oWebLayout.commandObj.length;i++){oCommand=this.oWebLayout.commandObj[i];if($(oCommand.getName())){aCommands.push(oCommand);}}
return aCommands;},getListofToolbarWidgets:function(){var aCommands=[];var toolbars=this.oWebLayout.aToolbars;for(var i=0;i<toolbars.length;i++){if($(toolbars[i].container)){for(var j=0;j<toolbars[i].buttons.length;j++){var button=toolbars[i].buttons[j];if(button.func=='Command'){var oCommand=this.oWebLayout.getCommandByName(toolbars[i].buttons[j].obj.name);if(oCommand){aCommands.push(oCommand);}}else if(button.func=='Flyout'){aCommands=aCommands.concat(this.getListofMenuWidgets(button.obj.subItems));}}}}
return aCommands;},getListofContextMenuWidgets:function(){var aCommands=[];var menus=this.oWebLayout.aMenus;for(var i=0;i<menus.length;i++){if(menus[i].mapName==''||this.getMapByName(menus[i].mapName)){aCommands=aCommands.concat(this.getListofMenuWidgets(menus[i].items));}}
return aCommands;},getListofMenuWidgets:function(menuItems){var aCommands=[];for(var i=0;i<menuItems.length;i++){var item=menuItems[i];switch(item.func){case'Separator':break;case'Command':var oCommand=this.oWebLayout.getCommandByName(item.obj.name);if(oCommand){aCommands.push(oCommand);}
break;case'Flyout':aCommands=aCommands.concat(this.getListofMenuWidgets(item.obj.subItems));break;default:}}
return aCommands;},loadWidgets:function(){var aCommands=this.getListofWidgets();aCommands=aCommands.concat(this.getListofToolbarWidgets());aCommands=aCommands.concat(this.getListofContextMenuWidgets());for(var i=0;i<aCommands.length;i++){var c=aCommands[i];var js=c.sLocation+'/'+c.getAction()+'.js';Fusion.require(js);}
this.oApp.setLoadState(this.oApp.LOAD_WIDGETS);},createWidgets:function(){this.createMapWidget();this.createAllWidgets();this.createToolbars();this.createContextMenus();},createMapWidget:function(){var aCommands=this.oWebLayout.getCommandByType('MapCommandType');if(aCommands.length>0)
{var oCommand=null;for(var i=0;i<aCommands.length;i++)
{oCommand=aCommands[i];var oElement=$(oCommand.getName());if(oElement!=null)
{var widget;var sID=this.sessionID?',"'+this.sessionID+'"':'';var sTmp='widget = new Fusion.Widget.'+oCommand.getAction()+'(oCommand'+sID+')';eval(sTmp);if($(oCommand.getName())){$(oCommand.getName()).widget=widget;}
this.aoMapWidget.push(widget);}}}},getMapInfo:function(resourceId){for(var i=0;i<this.oWebLayout.aMaps.length;i++){if(this.oWebLayout.aMaps[i].resourceId==resourceId){return this.oWebLayout.aMaps[i];}}
return null;},getMapByName:function(sName)
{var nMaps=this.aoMapWidget.length;var oMap=null;for(var i=0;i<nMaps;i++)
{if(this.aoMapWidget[i].getMapName()==sName){oMap=this.aoMapWidget[i];break;}}
return oMap;},getMapById:function(sId)
{var nMaps=this.aoMapWidget.length;var oMap;for(var i=0;i<nMaps;i++)
{oMap=this.aoMapWidget[i];if(oMap.getDomId()==sId)
{return oMap;}}
return null;},getMapByIndice:function(nIndice)
{if(nIndice<this.aoMapWidget.length)
{var oMap=this.aoMapWidget[nIndice];return oMap;}
return null;},createAllWidgets:function()
{var aCommands=this.getListofWidgets();for(var i=0;i<aCommands.length;i++){var oCommand=aCommands[i];if(oCommand.getAction()!=''&&oCommand.getAction()!='MGMap'&&oCommand.getAction()!='MSMap'){var widget;var sTmp='widget = new Fusion.Widget.'+oCommand.getAction()+'(oCommand)';eval(sTmp);this.aWidgets.push(widget);if($(oCommand.getName())){$(oCommand.getName()).widget=widget;}}}},createToolbars:function(){var dummyAction=new Jx.Action(null);var toolbars=this.oWebLayout.aToolbars;if(toolbars.length>0){for(var i=0;i<toolbars.length;i++){var toolbarObj=$(toolbars[i].container);if(toolbarObj){var toolbar=toolbars[i];var tb=new Jx.Toolbar(toolbarObj);tb.domObj.id=toolbar.name;for(var j=0;j<toolbar.buttons.length;j++){var id='toolbar'+i+'command'+j;var button=toolbar.buttons[j];var tbItem=null;switch(button.func){case'Separator':tb.add(new Jx.ToolbarSeparator());break;case'Command':var oCommand=this.oWebLayout.getCommandByName(button.obj.name);tbItem=new Jx.ToolbarItem();tbItem.domObj.id=id;tb.add(tbItem);var oldName=oCommand.getName();oCommand.setName(id);var widget;var sTmp='widget = new Fusion.Widget.'+oCommand.getAction()+'(oCommand)';eval(sTmp);this.aWidgets.push(widget);oCommand.setName(oldName);break;case'Flyout':var options={};options.label=button.obj.label;options.tooltip=button.obj.tooltip;if(button.obj.imageUrl!=''){options.imgPath=button.obj.imageUrl;}
var menu=new Jx.Menu(options);this.processMenuUiItems(button.obj.subItems,menu,null);tb.add(menu);break;default:tb.add(new Jx.ToolbarSeparator());}}}}}},createContextMenus:function(){var menus=this.oWebLayout.aMenus;if(menus.length>0){for(var i=0;i<menus.length;i++){var oMap=null;if(menus[i].mapName!=''){oMap=this.getMapByName(menus[i].mapName);}else{oMap=this.getMapByIndice(0);}
var menu=new Jx.ContextMenu();this.processMenuUiItems(menus[i].items,menu,oMap);oMap.setContextMenu(menu);}}},processMenuUiItems:function(menuItems,menu,oMap){for(var i=0;i<menuItems.length;i++){var item=menuItems[i];switch(item.func){case'Separator':break;case'Command':var widget=this.createWidgetFromCommandName(item.obj.name,'');if(widget){if(widget.isMenuWidget){menu.add(widget.getMenu());}else{var action;if(oMap){action=new Jx.Action(oMap.executeFromContextMenu.bind(oMap,widget));widget.registerForEvent(Fusion.Event.WIDGET_STATE_CHANGED,function(eventID,aWidget){this.setEnabled(aWidget.isEnabled());}.bind(action));}else{action=new Jx.Action(widget.activateTool.bind(widget));}
var options={};options.label=widget._oCommand.sLabel;options.image=widget._oCommand.sImageurl;menu.add(new Jx.MenuItem(action,options));}}
break;case'Flyout':var options={};options.label=item.obj.label;if(item.obj.imageUrl!=''){options.image=item.obj.imageUrl;}
var subMenu=new Jx.SubMenu(options);this.processMenuUiItems(item.obj.subItems,subMenu,oMap);menu.add(subMenu);break;default:}}},createWidgetFromCommandName:function(name,id){var widget=null;var oCommand=this.oWebLayout.getCommandByName(name);if(oCommand){var oldName=oCommand.getName();oCommand.setName('');var widget;var sTmp='widget = new Fusion.Widget.'+oCommand.getAction()+'(oCommand)';eval(sTmp);this.aWidgets.push(widget);oCommand.setName(oldName);}
return widget;},getWidgetById:function(id){return $(id).widget;},getWidgetsByType:function(type){var a=[];for(var i=0;i<this.aWidgets.length;i++){if(this.aWidgets[i].sName==type){a.push(this.aWidgets[i]);}}
return a;}});Fusion.Lib.WebCommand=Class.create();Fusion.Lib.WebCommand.prototype={sName:"",sLabel:"",sTooltip:"",sDescription:"",sImageurl:"",sDisabledImageURL:"",sTargetViewer:"",sType:'CommandType',sLocation:'widgets/',jsonNode:null,sAction:"",sMapId:'',initialize:function(jsonNode){this.jsonNode=Object.extend({},jsonNode);this.sType=jsonNode['@type']?jsonNode['@type'][0]:'CommandType';if(jsonNode!=null){this.sName=jsonNode.Name?jsonNode.Name[0]:'';this.sLabel=jsonNode.Label?jsonNode.Label[0]:'';this.sTooltip=jsonNode.Tooltip?jsonNode.Tooltip[0]:'';this.sDescription=jsonNode.Description?jsonNode.Description[0]:'';this.sLocation=jsonNode.Location?jsonNode.Location[0]:'';if(this.sLocation==''){this.sLocation='widgets';}
this.sTargetViewer=jsonNode.TargetViewer?jsonNode.TargetViewer[0]:'';this.sAction=jsonNode.Action?jsonNode.Action[0]:'';this.sMapId=jsonNode.MapId?jsonNode.MapId[0]:'';var sImageurl=jsonNode.ImageURL?jsonNode.ImageURL[0]:'';if(sImageurl.length>4&&sImageurl.substring(0,4)=="http"){this.sImageurl=sImageurl;}else{if(this.sType=='BasicCommandType'){this.sImageurl=Fusion.getFusionURL()+sImageurl;}else{this.sImageurl=sImageurl;}}
var sDisabledImageURL=jsonNode.DisabledImageUrl?jsonNode.DisabledImageUrl[0]:'';if(sImageurl.length>4&&sImageurl.substring(0,4)=="http"){this.sDisabledImageURL=sDisabledImageURL;}
else if(sDisabledImageURL==''){sDisabledImageURL=sImageurl;}else{if(this.sType=='BasicCommandType'){this.sDisabledImageURL=Fusion.getFusionURL()+sDisabledImageURL;}else{this.sDisabledImageURL=sDisabledImageURL;}}}},getName:function(){return this.sName;},setName:function(sName){this.sName=sName;},getImageURL:function(){return this.sImageurl;},getDisabledImageURL:function(){return this.sDisabledImageURL;},getType:function(){return this.sType;},getAction:function(){return this.sAction;},getMap:function(){if(this.sMapId!=''){return Fusion.getMapById(this.sMapId);}else{return Fusion.getMapByIndice(0);}}};Fusion.Event.WEBLAYOUT_PARSED=Fusion.Event.lastEventId++;Fusion.Lib.WebLayout=Class.create();Object.extend(Fusion.Lib.WebLayout.prototype,Fusion.Lib.EventMgr);Object.extend(Fusion.Lib.WebLayout.prototype,{mapId:'',aMaps:null,commandObj:null,aToolbars:null,aMenus:null,webLayout:null,oBroker:null,oConfigManager:null,initialize:function(app){Fusion.Lib.EventMgr.initialize.apply(this,[]);this.app=app;this.oBroker=app.getBroker();this.webLayout=app.getWebLayout();this.commandObj=[];this.aMaps=[];this.registerEventID(Fusion.Event.WEBLAYOUT_PARSED);},parse:function(){if(this.webLayout.match('Library://')==null){var options={};options.method='get';options.onSuccess=this.convertXML.bind(this);new Ajax.Request(this.webLayout,options);}else{var r=new Fusion.Lib.MGRequest.MGGetResourceContent(this.webLayout);this.oBroker.dispatchRequest(r,this.parseXML.bind(this));}},convertXML:function(r,json){var options={};options.onSuccess=this.parseXML.bind(this);options.parameters='xml='+encodeURIComponent(r.responseText.replace(/\\/g,'\\\\\\\\'))+'&ts='+((new Date()).getTime());var sl=Fusion.getScriptLanguage();Fusion.ajaxRequest('common/'+sl+'/Xml2JSON.'+sl,options);},parseXML:function(r,json){if(json){var mainNode;eval("mainNode="+r.responseText);var webLayout=mainNode.WebLayout;if(webLayout.Map instanceof Array){var maps=webLayout.Map;for(var i=0;i<maps.length;i++){var map=maps[i];var mapObj={};mapObj.resourceId=map.ResourceId[0];mapObj.referenceImageUrl=map.ReferenceImageUrl[0];mapObj.links={layers:[],groups:[]};mapObj.layerEvents={};if(map.Links){if(map.Links[0].Group instanceof Array){for(var j=0;j<map.Links[0].Group.length;j++){var group=map.Links[0].Group[j];mapObj.links.groups.push({name:group.Name,url:group.Url});}}
if(map.Links[0].Layer instanceof Array){for(var j=0;j<map.Links[0].Layer.length;j++){var layer=map.Links[0].Layer[j];mapObj.links.layers.push({name:layer.Name,url:layer.Url});}}}
if(map.LayerEvents){if(map.LayerEvents[0].Layer instanceof Array){for(var j=0;j<map.LayerEvents[0].Layer.length;j++){var layer=map.LayerEvents[0].Layer[j];var layerObj={};layerObj.name=layer.Name[0];layerObj.onEnable=[];layerObj.onDisable=[];if(layer.OnEnable instanceof Array){for(var k=0;k<layer.OnEnable[0].Layer.length;k++){var kLayer=layer.OnEnable[0].Layer[k];layerObj.onEnable.push({name:kLayer.Name[0],enable:kLayer.Enable[0]=='true'?true:false});}}
if(layer.OnDisable instanceof Array){for(var k=0;k<layer.OnDisable[0].Layer.length;k++){var kLayer=layer.OnDisable[0].Layer[k];layerObj.onDisable.push({name:kLayer.Name[0],enable:kLayer.Enable[0]=='true'?true:false});}}
mapObj.layerEvents[layerObj.name]=layerObj;}}}
this.aMaps.push(mapObj);}}
var commandSet=webLayout.CommandSet;if(commandSet instanceof Array){var commands=commandSet[0].Command;if(commands instanceof Array){for(var i=0;i<commands.length;i++){this.commandObj.push(new Fusion.Lib.WebCommand(commands[i]));}}}
this.aToolbars=[];if(webLayout.ToolBar instanceof Array){var toolbars=webLayout.ToolBar;for(var i=0;i<toolbars.length;i++){this.aToolbars.push(new Fusion.Lib.WebLayout.Toolbar(toolbars[i]));}}
this.aMenus=[];if(webLayout.ContextMenu instanceof Array){var menus=webLayout.ContextMenu;for(var i=0;i<menus.length;i++){this.aMenus.push(new Fusion.Lib.WebLayout.ConextMenu(menus[i]));}}
this.aSearchCategories={};this.aSearchDefinitions={};if(webLayout.SearchDefinitions instanceof Array){var categories=webLayout.SearchDefinitions[0];if(categories.SearchCategory instanceof Array){for(var i=0;i<categories.SearchCategory.length;i++){var oCategory={};var category=categories.SearchCategory[i];oCategory.id=category['@id'];oCategory.name=category['@name'];oCategory.layer=category.Layer?category.Layer[0]:'';oCategory.searchDefinitions=[];var defns=category.SearchDefinition;for(var k=0;k<defns.length;k++){var defn=new Fusion.Lib.WebLayout.SearchDefinition(defns[k]);defn.category=oCategory;oCategory.searchDefinitions[defn.id]=defn;this.aSearchDefinitions[defn.id]=defn;}}}}
this.triggerEvent(Fusion.Event.WEBLAYOUT_PARSED);}},getMapResourceId:function(){return this.mapId;},getCommandByName:function(sName){var oCommand;for(var i=0;i<this.commandObj.length;i++){oCommand=this.commandObj[i];if(oCommand.getName()==sName){return this.commandObj[i];}}},getCommandByType:function(sType){var oCommand;var aReturn=[];for(var i=0;i<this.commandObj.length;i++){oCommand=this.commandObj[i];if(oCommand.getType()==sType){aReturn.push(oCommand);}}
return aReturn;}});Fusion.Lib.WebLayout.Toolbar=Class.create();Fusion.Lib.WebLayout.Toolbar.prototype={buttons:null,name:null,container:null,initialize:function(jsonNode){this.name=jsonNode.Name?jsonNode.Name[0]:'';this.container=jsonNode.Container?jsonNode.Container[0]:'';this.buttons=[];if(jsonNode.Button instanceof Array){for(var i=0;i<jsonNode.Button.length;i++){this.buttons.push(new Fusion.Lib.WebLayout.UiItem(jsonNode.Button[i]));}}}};Fusion.Lib.WebLayout.ConextMenu=Class.create();Fusion.Lib.WebLayout.ConextMenu.prototype={items:null,mapName:null,initialize:function(jsonNode){this.mapName=jsonNode.Map?jsonNode.Map[0]:'';this.items=[];if(jsonNode.MenuItem instanceof Array){for(var i=0;i<jsonNode.MenuItem.length;i++){this.items.push(new Fusion.Lib.WebLayout.UiItem(jsonNode.MenuItem[i]));}}}};Fusion.Lib.WebLayout.UiItem=Class.create();Fusion.Lib.WebLayout.UiItem.prototype={func:null,obj:null,initialize:function(jsonNode){this.func=jsonNode.Function[0];switch(this.func){case'Separator':break;case'Command':this.obj=new Fusion.Lib.WebLayout.Command(jsonNode);break;case'Flyout':this.obj=new Fusion.Lib.WebLayout.Flyout(jsonNode);break;default:}}};Fusion.Lib.WebLayout.Command=Class.create();Fusion.Lib.WebLayout.Command.prototype={name:null,initialize:function(jsonNode){this.name=jsonNode.Command[0];}};Fusion.Lib.WebLayout.Flyout=Class.create();Fusion.Lib.WebLayout.Flyout.prototype={label:null,tooltip:null,description:null,imageUrl:null,disabledImageUrl:null,subItems:null,initialize:function(jsonNode){this.label=jsonNode.Label?jsonNode.Label[0]:'';this.tooltip=jsonNode.Tooltip?jsonNode.Tooltip[0]:'';this.description=jsonNode.Description?jsonNode.Description[0]:'';this.imageUrl=jsonNode.ImageURL?jsonNode.ImageURL[0]:'';this.disabledImageUrl=jsonNode.DisabledImageURL?jsonNode.DisabledImageURL[0]:'';this.subItems=[];if(jsonNode.SubItem instanceof Array){for(var i=0;i<jsonNode.SubItem.length;i++){this.subItems.push(new Fusion.Lib.WebLayout.UiItem(jsonNode.SubItem[i]));}}}};Fusion.Lib.WebLayout.SearchDefinition=Class.create();Fusion.Lib.WebLayout.SearchDefinition.prototype={id:null,name:null,category:null,parameters:null,join:null,rule:null,initialize:function(json){this.id=json['@id'];this.name=json['@name'];if(json.Join instanceof Array){this.join=new Fusion.Lib.WebLayout.SearchJoin(json.Join[0]);}
this.parameters=[];if(json.Parameter instanceof Array){for(var i=0;i<json.Parameter.length;i++){this.parameters.push(json.Parameter[i]['@name']);}}
var rule;if(json.SearchAnd instanceof Array){this.rule=new Fusion.Lib.WebLayout.SearchRule('AND');rule=json.SearchAnd[0];}else if(json.SearchOr instanceof Array){this.rule=new Fusion.Lib.WebLayout.SearchRule('OR');rule=json.SearchOr[0];}
if(rule&&rule.SearchCondition instanceof Array){for(var i=0;i<rule.SearchCondition.length;i++){this.rule.add(new Fusion.Lib.WebLayout.SearchCondition(rule.SearchCondition[i]));}}},getJoinUrl:function(params){if(this.join){return'&joinlayer='+this.join.layer+'&joinpk='+this.join.primaryKey+'&joinfk='+this.join.foreignKey;}else{return'';}},getFilterUrl:function(params){return'&filter='+encodeURIComponent(this.rule.toString(params));}};Fusion.Lib.WebLayout.SearchJoin=Class.create();Fusion.Lib.WebLayout.SearchJoin.prototype={layer:null,primaryKey:null,foreignKey:null,initialize:function(json){this.layer=json.Layer?json.Layer[0]:'';this.primaryKey=json.PrimaryKey?json.PrimaryKey[0]:'';this.foreignKey=json.ForeignKey?json.ForeignKey[0]:'';}};Fusion.Lib.WebLayout.SearchRule=Class.create();Fusion.Lib.WebLayout.SearchRule.prototype={type:null,conditions:null,initialize:function(type){this.type=type;this.conditions=[];},add:function(condition){this.conditions.push(condition);},remove:function(condition){for(var i=0;i<this.conditions.length;i++){if(this.conditions[i]==condition){this.conditions.splice(i,1);break;}}},toString:function(params){var conditions=[];for(var i=0;i<this.conditions.length;i++){this.conditions[i].setParams(params);var c=this.conditions[i].toString();if(c!=''){conditions.push(c);}}
return'('+conditions.join(') '+this.type+' (')+')';}};Fusion.Lib.WebLayout.SearchCondition=Class.create();Fusion.Lib.WebLayout.SearchCondition.prototype={column:null,operator:null,parameter:null,quote:null,value:null,operators:{eq:'=',like:'like',lt:'<',lte:'<=',gt:'>',gte:'>=',neq:'<>'},includeIfEmpty:false,initialize:function(json){this.column=json.Column[0];this.operator=this.operators[json.Operator[0].toLowerCase()];this.parameter=json.Parameter[0];this.quote=json['@quote']?json['@quote']:'';this.wildcard=json['@wildcard']?json['@wildcard']:'both';},setParams:function(p){if(p[this.parameter]){this.value=p[this.parameter];}else{this.value='';}},toString:function(){var value=this.value?this.value:'';if(value==''&&!this.includeIfEmpty){return'';}
var prewildcard='';var prewildcard='';var postwildcard='';if(this.operator=='like'){if(this.wildcard=='before'||this.wildcard=='both'){prewildcard='*';}
if(this.wildcard=='after'||this.wildcard=='both'){postwildcard='*';}}
var wildcard=this.operator=='like'?'*':'';return this.column+' '+this.operator+' '+this.quote+prewildcard+value+postwildcard+this.quote;}};Fusion.Lib.MGBroker=Class.create();Fusion.Lib.MGBroker.prototype={mapGuideURL:'',mapAgentURL:'',method:null,initialize:function(){},dispatchRequest:function(r,f){var s=r.encode()+'&ts='+(new Date()).getTime();if(this.method){r.options.method=this.method;}
var a=new Ajax.Request(this.mapAgentURL,Object.extend({parameters:s,onComplete:f},r.options));a.originalRequest=r;},setSiteURL:function(url,user,pass){this.user=user;this.pass=pass;if(url.indexOf('mapagent.fcgi')==-1){if(url.charAt(url.length-1)!='/'){url=url+'/';}
this.mapGuideURL=url;url=url+'mapagent/mapagent.fcgi';}
this.mapAgentURL=url;},clearSiteURL:function(){this.user='';this.pass='';this.mapGuideURL='';this.mapAgentURL='';}};Fusion.Lib.MGRequest=Class.create();Fusion.Lib.MGRequest.prototype={options:null,parameters:null,initializeRequest:function(){this.options={method:'post'};this.parameters={version:'1.0.0',locale:'en'};},setParams:function(o){Object.extend(this.parameters,(o||{}));},setOptions:function(o){Object.extend(this.options,(o||{}));},encode:function(){var s=sep='';for(var p in this.parameters){if(this.parameters[p]){s=s+sep+p+'='+encodeURI(this.parameters[p]);}
sep='&';}
return s;}};Fusion.Lib.MGRequest.MGEnumerateResources=Class.create();Object.extend(Fusion.Lib.MGRequest.MGEnumerateResources.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGEnumerateResources.prototype,{initialize:function(resourceID,type,depth){this.initializeRequest();this.setParams({operation:'ENUMERATERESOURCES',resourceid:(resourceID||"Library://"),type:(type||""),depth:(typeof depth=='undefined'?-1:depth)});}});Fusion.Lib.MGRequest.MGGetResourceContent=Class.create();Object.extend(Fusion.Lib.MGRequest.MGGetResourceContent.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGGetResourceContent.prototype,{initialize:function(resourceID){this.initializeRequest();this.setParams({operation:'GETRESOURCECONTENT',resourceid:(resourceID||"Library://")});}});Fusion.Lib.MGRequest.MGGetResourceHeader=Class.create();Object.extend(Fusion.Lib.MGRequest.MGGetResourceHeader.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGGetResourceHeader.prototype,{initialize:function(resourceID){this.initializeRequest();this.setParams({operation:'GETRESOURCEHEADER',resourceid:(resourceID||"Library://")});}});Fusion.Lib.MGRequest.MGCreateSession=Class.create();Object.extend(Fusion.Lib.MGRequest.MGCreateSession.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGCreateSession.prototype,{initialize:function(){this.initializeRequest();this.setParams({operation:'CREATESESSION'});}});Fusion.Lib.MGRequest.MGCopyResource=Class.create();Object.extend(Fusion.Lib.MGRequest.MGCopyResource.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGCopyResource.prototype,{initialize:function(sourceID,destinationID,overwrite){this.initializeRequest();this.setParams({operation:'COPYRESOURCE',source:sourceID,destination:destinationID,overwrite:overwrite});}});Fusion.Lib.MGRequest.MGDeleteResource=Class.create();Object.extend(Fusion.Lib.MGRequest.MGDeleteResource.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGDeleteResource.prototype,{initialize:function(resourceID){this.initializeRequest();this.setParams({operation:'DELETERESOURCE',resourceid:resourceID});}});Fusion.Lib.MGRequest.MGMoveResource=Class.create();Object.extend(Fusion.Lib.MGRequest.MGMoveResource.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGMoveResource.prototype,{initialize:function(sourceID,destinationID,overwrite){this.initializeRequest();this.setParams({operation:'MOVERESOURCE',source:sourceID,destination:destinationID,overwrite:overwrite});}});Fusion.Lib.MGRequest.MGMoveResource=Class.create();Object.extend(Fusion.Lib.MGRequest.MGMoveResource.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGMoveResource.prototype,{initialize:function(resourceID,content,header){this.initializeRequest();this.setParams({method:'post',operation:'SETRESOURCE',resourceid:resourceID,content:content,header:header});}});Fusion.Lib.MGRequest.MGDescribeSchema=Class.create();Object.extend(Fusion.Lib.MGRequest.MGDescribeSchema.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGDescribeSchema.prototype,{initialize:function(resourceID,schema){this.initializeRequest();this.setParams({operation:'DESCRIBEFEATURESCHEMA',resourceid:resourceID,schema:schema});}});Fusion.Lib.MGRequest.MGGetSpatialContexts=Class.create();Object.extend(Fusion.Lib.MGRequest.MGGetSpatialContexts.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGGetSpatialContexts.prototype,{initialize:function(resourceID,activeonly){this.initializeRequest();this.setParams({operation:'GETSPATIALCONTEXTS',resourceid:resourceID,activeonly:activeonly?'1':'0'});}});Fusion.Lib.MGRequest.MGEnumerateResourceReferences=Class.create();Object.extend(Fusion.Lib.MGRequest.MGEnumerateResourceReferences.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGEnumerateResourceReferences.prototype,{initialize:function(resourceID){this.initializeRequest();this.setParams({operation:'ENUMERATERESOURCEREFERENCES',resourceid:resourceID});}});Fusion.Lib.MGRequest.MGEnumerateResourceData=Class.create();Object.extend(Fusion.Lib.MGRequest.MGEnumerateResourceData.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGEnumerateResourceData.prototype,{initialize:function(resourceID){this.initializeRequest();this.setParams({operation:'ENUMERATERESOURCEDATA',resourceid:resourceID});}});Fusion.Lib.MGRequest.MGGetVisibleMapExtent=Class.create();Object.extend(Fusion.Lib.MGRequest.MGGetVisibleMapExtent.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGGetVisibleMapExtent.prototype,{initialize:function(sessionId,mapName,viewCenterX,viewCenterY,viewScale,dataExtent,displayDpi,displayWidth,displayHeight,showLayers,hideLayers,showGroups,hideGroups,refreshLayers){this.initializeRequest();this.setParams({operation:'GETVISIBLEMAPEXTENT',session:sessionId,mapname:mapName,setviewcenterx:viewCenterX,setviewcentery:viewCenterY,setviewscale:viewScale,setdataextent:dataExtent,setdisplaydpi:displayDpi,setdisplaywidth:displayWidth,setdisplayheight:displayHeight,showlayers:showLayers,hidelayers:hideLayers,showgroups:showGroups,hidegroups:hideGroups,refreshlayers:refreshLayers});}});Fusion.Lib.MGRequest.MGQueryMapFeatures=Class.create();Object.extend(Fusion.Lib.MGRequest.MGQueryMapFeatures.prototype,Fusion.Lib.MGRequest.prototype);Object.extend(Fusion.Lib.MGRequest.MGQueryMapFeatures.prototype,{initialize:function(sessionId,mapName,geometry,maxFeatures,persist,selectionVariant,layerNames)
{this.initializeRequest();this.setParams({operation:'QUERYMAPFEATURES',session:sessionId,mapname:mapName,geometry:geometry,maxFeatures:maxFeatures,persist:persist,selectionVariant:selectionVariant,layerNames:layerNames});}});Fusion.Event.WIDGET_STATE_CHANGED=Fusion.Event.lastEventId++;Fusion.Widget=Class.create();Fusion.Widget.prototype={bIsMutuallyExclusive:null,sName:null,oMap:null,bEnabled:false,mapLoadedWatcher:null,groups:[],group:null,initialize:function(sName,bMutEx,oCommand){this.bIsMutuallyExclusive=bMutEx;this.sName=sName;this._oCommand=oCommand;Object.inheritFrom(this,Fusion.Lib.EventMgr,[]);this.registerEventID(Fusion.Event.WIDGET_STATE_CHANGED);var group=oCommand.jsonNode.Group?oCommand.jsonNode.Group[0]:'';if(group!=''){if(!this.groups[group]){this.groups[group]=[];}
this.groups[group].push(this);this.group=group;}},setMap:function(oMap){if(this.mapLoadedWatcher){this.oMap.deregisterForEvent(Fusion.Event.MAP_LOADED,this.mapLoadedWatcher);this.mapLoadedWatcher=null;}
this.oMap=oMap;if(oMap){this.mapLoadedWatcher=this.mapLoaded.bind(this);oMap.registerForEvent(Fusion.Event.MAP_LOADED,this.mapLoadedWatcher);}
if(oMap.isLoaded()){this.enable();}else{this.disable();}},getMap:function(){return this.oMap;},mapLoaded:function(){if(this.oMap&&this.oMap.isLoaded()){this.enable();}else{this.disable();}},setMutEx:function(bIsMutEx){this.bIsMutuallyExclusive=bIsMutEx;},isMutEx:function(){return this.bIsMutuallyExclusive;},getName:function(){return this.sName;},isEnabled:function(){return this.bEnabled;},enable:function(){this.bEnabled=true;this.triggerEvent(Fusion.Event.WIDGET_STATE_CHANGED,this);},disable:function(){this.bEnabled=false;this.triggerEvent(Fusion.Event.WIDGET_STATE_CHANGED,this);},setParameter:function(param,value){}};Fusion.Tool.ButtonBase=Class.create();Fusion.Tool.ButtonBase.prototype={initialize:function(){this.enable=Fusion.Tool.ButtonBase.prototype.enable;this.disable=Fusion.Tool.ButtonBase.prototype.disable;this._oDomObj=$(this._oCommand.getName());this._oButton=new Fusion.Tool.Button(this._oCommand);if(!this.isEnabled()){this._oButton.disableTool();}
this.clickWatcher=this.clickCB.bind(this);this._oButton.observeEvent('click',this.clickWatcher);},clickCB:function(e){if(this.isEnabled()){this.activateTool();}
this._oButton._oButton.domObj.blur();},activateTool:function(){if(this.execute){this.execute();}
if(this.group){this._oButton.activateTool();for(var i=0;i<this.groups[this.group].length;i++){if(this.groups[this.group][i]!=this){this.groups[this.group][i]._oButton.deactivateTool();}}}},enable:function(){Fusion.Widget.prototype.enable.apply(this,[]);this._oButton.enableTool();},disable:function(){Fusion.Widget.prototype.disable.apply(this,[]);this._oButton.disableTool();}};Fusion.Tool.Button=Class.create();Fusion.Tool.Button.prototype={_sHtmlId:null,_sImageURL:null,_sDisabledImageURL:null,_nWidth:-1,_nHeight:-1,_oDomObj:null,_oDomImg:null,bActive:null,sActiveClass:null,sDisabledClass:null,initialize:function(oCommand){var json=oCommand.jsonNode;this._sHtmlId=oCommand.getName();this._sDisabledImageURL=json.DisabledImageURL?json.DisabledImageURL[0]:'';this._sImageURL=json.ImageURL?json.ImageURL[0]:'';if(this._sDisabledImageURL==''&&this._sImageURL!=''){this._sDisabledImageURL=this._sImageURL;}else if(this._sImageURL==''&&this._sDisabledImageURL!=''){this._sImageURL=this._sDisabledImageURL;}
this._nWidth=json.Width?parseInt(json.Width[0]):null;this._nHeight=json.Height?parseInt(json.Height[0]):null;this._sTooltip=json.Tooltip?json.Tooltip[0]:'';this._sDescription=json.Description?json.Description[0]:'';this._sLabel=json.Label?json.Label[0]:'';this.sImageClass=json.ImageClass?json.ImageClass[0]:'';this.sActiveClass=json.ActiveClass?json.ActiveClass[0]:'jxButtonActive';this.sDisabledClass=json.DisabledClass?json.DisabledClass[0]:'jxButtonDisabled';this.buttonAction=new Jx.Action(this.buttonClicked.bind(this));if(oCommand.getName()!=''){this._oDomObj=$(this._sHtmlId);}
if(this._oDomObj){var options={};options.imgPath=this._sDisabledImageURL;options.imgClass=this.sImageClass;options.tooltip=this._sTooltip;options.label=this._sLabel;options.disabledClass=this.sDisabledClass;this._oButton=new Jx.Button(this.buttonAction,options);this._oDomObj.appendChild(this._oButton.domObj);}
this.bActive=false;this.bEnabled=true;var startDisabled=json.Disabled?json.Disabled[0]:'false';if(startDisabled=='true'||startDisabled=='1'){this.disableTool();}},buttonClicked:function(){},observeEvent:function(sEvent,fnCB){if(this._oButton){Event.observe(this._oButton.domObj,sEvent,fnCB);}},stopObserveEvent:function(sEvent,fnCB){if(this._oButton){Event.stopObserving(this._oButton.domObj,sEvent,fnCB);}},enableTool:function(){this.buttonAction.setEnabled(true);},disableTool:function(){this.buttonAction.setEnabled(false);},activateTool:function(){this.bActive=true;if(!this._oButton){return;}
if(this._sImageURL!=null&&this._sImageURL.length>0){this._oButton.setImage(this._sImageURL);}
if(this.sActiveClass!=''){Element.addClassName(this._oButton.domA,this.sActiveClass);}},deactivateTool:function()
{this.bActive=false;if(!this._oButton){return;}
if(this._sDisabledImageURL!=null&&this._sDisabledImageURL.length>0){this._oButton.setImage(this._sDisabledImageURL);}
if(this.sActiveClass!=''){Element.removeClassName(this._oButton.domA,this.sActiveClass);}},clickCB:function(e){this.activateTool();},isActive:function(){return this.bActive;}};Fusion.Tool.Canvas=Class.create();Fusion.Tool.Canvas.prototype={context:null,canvas:null,width:null,height:null,initialize:function()
{this.context=null;this.canvas=null;this.width=null;this.height=null;this.mouseMoveCB=this.mouseMove.bindAsEventListener(this);this.mouseUpCB=this.mouseUp.bindAsEventListener(this);this.mouseDownCB=this.mouseDown.bindAsEventListener(this);this.dblClickCB=this.dblClick.bindAsEventListener(this);this.resizeCanvasFn=this.resizeCanvas.bind(this);},clearContext:function(){if(this.context){this.context.clearRect(0,0,this.width,this.height);}},activateCanvas:function(){var map=this.getMap();map.registerForEvent(Fusion.Event.MAP_RESIZED,this.resizeCanvasFn);var domObj=map.getDomObj();var size=Element.getDimensions(domObj);this.width=size.width;this.height=size.height;if(!this.canvas){this.canvas=document.createElement('canvas');if(typeof G_vmlCanvasManager!="undefined"){document.getElementsByTagName('BODY')[0].appendChild(this.canvas);G_vmlCanvasManager.initElement(this.canvas);this.canvas=document.getElementsByTagName('BODY')[0].lastChild;}
this.canvas.id='featureDigitizer';this.canvas.style.position='absolute';this.canvas.style.top='0px';this.canvas.style.left='0px';this.canvas.style.width=this.width+'px';this.canvas.style.height=this.height+'px';this.canvas.width=this.width;this.canvas.height=this.height;this.canvas.style.zIndex=99;}
domObj.appendChild(this.canvas);if(!this.context){this.context=this.canvas.getContext('2d');}
this.canvas.style.width=this.width+'px';this.canvas.style.height=this.height+'px';this.canvas.width=this.width;this.canvas.height=this.height;map.observeEvent('mousemove',this.mouseMoveCB);map.observeEvent('mouseup',this.mouseUpCB);map.observeEvent('mousedown',this.mouseDownCB);map.observeEvent('dblclick',this.dblClickCB);},resizeCanvas:function(){var map=this.getMap();var domObj=map.getDomObj();var size=Element.getDimensions(domObj);this.width=size.width;this.height=size.height;this.canvas.style.width=this.width+'px';this.canvas.style.height=this.height+'px';this.canvas.width=this.width;this.canvas.height=this.height;},deactivateCanvas:function(){var map=this.getMap();map.deregisterForEvent(Fusion.Event.MAP_RESIZED,this.resizeCanvasFn);map.getDomObj().removeChild(this.canvas);this.context.clearRect(0,0,this.width,this.height);map.stopObserveEvent('mousemove',this.mouseMoveCB);map.stopObserveEvent('mouseup',this.mouseUpCB);map.stopObserveEvent('mousedown',this.mouseDownCB);map.stopObserveEvent('dblclick',this.dblClickCB);},mouseDown:function(e){},mouseUp:function(e){},mouseMove:function(e){},dblClick:function(e){}};Fusion.Tool.Canvas.Point=Class.create();Fusion.Tool.Canvas.Point.prototype={center:null,radius:null,lineStyle:null,fillStyle:null,initialize:function(map){this.center=new Fusion.Tool.Canvas.Node(0,0,map);this.radius=5;this.lineStyle=new Fusion.Tool.Canvas.Style({lineWidth:2,strokeStyle:'rgba(0,0,0,1.0)'});this.fillStyle=new Fusion.Tool.Canvas.Style({fillStyle:'rgba(0,0,255, 0.5)'});this.segments=[];},setPoint:function(x,y){this.center.set(x,y);},getPoint:function(){this.center.updateGeo();return{x:this.center.x,y:this.center.y};},draw:function(context){var x=this.center.px;var y=this.center.py;var radius=this.radius;this.fillStyle.apply(context);this.lineStyle.apply(context);context.beginPath();context.arc(x,y,radius,0,2*Math.PI,1);context.closePath();context.fill();context.stroke();},getNodes:function(){return[this.center];},clean:function(){},updateGeo:function(){this.center.updateGeo();},updatePx:function(){this.center.updatePx();}};Fusion.Tool.Canvas.Circle=Class.create();Fusion.Tool.Canvas.Circle.prototype={map:null,center:null,radius:null,radiusPx:null,start:null,end:null,lineStyle:null,fillStyle:null,initialize:function(map){this.map=map;this.center=new Fusion.Tool.Canvas.Node(0,0,map);this.radius=1;this.lineStyle=new Fusion.Tool.Canvas.Style({lineWidth:2,strokeStyle:'rgba(0,0,0,1.0)'});this.fillStyle=new Fusion.Tool.Canvas.Style({fillStyle:'rgba(0,0,255, 0.5)'});this.segments=[];},setCenter:function(x,y){this.center.set(x,y);},setRadius:function(r){if(r>1||r<-1){this.radius=Math.abs(r);this.radiusPx=this.map.geoToPixMeasure(this.radius);}else{this.radius=1;this.radiusPx=1;}},draw:function(context){var x=this.center.px;var y=this.center.py;var radius=this.radiusPx;this.fillStyle.apply(context);this.lineStyle.apply(context);context.beginPath();if(this.start&&this.end){context.moveTo(x,y);var s=this.start;var e=this.end;if(s<e){var t=s;s=e;e=t;}
var sx=x+Math.sin(s)*radius;var sy=y-Math.cos(s)*radius;context.lineTo(sx,sy);context.arc(x,y,radius,s-Math.PI/2,e-Math.PI/2,1);context.lineTo(x,y);}else{context.arc(x,y,radius,0,2*Math.PI,1);}
context.closePath();context.fill();context.stroke();},getNodes:function(){return[this.center];},clean:function(){},updateGeo:function(){this.center.updateGeo();this.radius=this.map.pixToGeoMeasure(this.radiusPx);},updatePx:function(){this.center.updatePx();this.radiusPx=this.map.geoToPixMeasure(this.radius);}};Fusion.Tool.Canvas.Polygon=Class.create();Fusion.Tool.Canvas.Polygon.prototype={segments:null,lineStyle:null,fillStyle:null,map:null,initialize:function(map){this.map=map;this.segments=[];this.lineStyle=new Fusion.Tool.Canvas.Style({lineWidth:2,strokeStyle:'rgba(0,0,0,1.0)'});this.fillStyle=new Fusion.Tool.Canvas.Style({fillStyle:'rgba(0,0,255, 0.5)'});},clean:function(){var nodes=this.getNodes();this.segments=[];var n1=nodes[0];var n2=nodes[1];for(var i=1;i<nodes.length;i++){if(n1.x!=n2.x||n1.y!=n2.y){this.addSegment(new Fusion.Tool.Canvas.Segment(n1,n2));n1=n2;}
n2=nodes[i];}
this.addSegment(new Fusion.Tool.Canvas.Segment(n1,nodes[0]));},getNodes:function(){var nodes=[];nodes.push(this.segments[0].from);for(var i=0;i<this.segments.length;i++){nodes.push(this.segments[i].to);}
return nodes;},reverseNodes:function(){var nSegments=this.segments.length;if(!nSegments){return;}
for(var i=0;i<nSegments;i++){var seg=this.segments[i];var tmp=seg.from;seg.from=seg.to;seg.to=tmp;};this.segments.reverse();},removeNode:function(node){if(node==this.segments[0].from){this.segments[0].from=null;this.segments.shift();this.segments[0].from=this.segments[this.segments.length-1].to;return;}
if(node==this.segments[this.segments.length-1].from){this.segments[this.segments.length-1].from=null;this.segments.pop();this.segments[0].from=this.segments[this.segments.length-1].to;return;}
for(var i=1;i<this.segments.length;i++){if(node==this.segments[i].from){this.segments[i-1].to=this.segments[i].to;this.segments[i].from=null;this.segments.splice(i,1);return;}};},draw:function(context){var x=this.segments[0].from.px;var y=this.segments[0].from.py;if(this.segments.length>2){this.fillStyle.apply(context);context.beginPath();context.moveTo(x,y);for(var i=0;i<this.segments.length;i++){var s=this.segments[i];context.lineTo(s.to.px,s.to.py);}
context.lineTo(x,y);context.closePath();context.fill();}
for(var i=0;i<this.segments.length;i++){this.segments[i].draw(context);}
var last=this.lastSegment();context.beginPath();context.moveTo(last.to.px,last.to.py);context.lineTo(x,y);context.stroke();},addSegment:function(s){s.normalStyle=this.lineStyle;this.segments[this.segments.length]=s;},lastSegment:function(){return this.segments[this.segments.length-1];},segmentTo:function(node){var margin=arguments.length>1?arguments[1]:3;for(var i=0;i<this.segments.length;i++){if(this.segments[i].hasTo(node,margin)){return this.segments[i];}}
return null;},segmentFrom:function(node){var margin=arguments.length>1?arguments[1]:3;for(var i=0;i<this.segments.length;i++){if(this.segments[i].hasFrom(node,margin)){return this.segments[i];}}
return null;},extendLine:function(){var last=this.lastSegment();var newNode=new Fusion.Tool.Canvas.Node(last.to.x,last.to.y,this.map);var newSegment=new Fusion.Tool.Canvas.Segment(last.to,newNode);this.addSegment(newSegment);return newSegment;},contains:function(node){return true;},toString:function(){var szFeature=this.segments[0].from.toString();for(var i=0;i<this.segments.length;i++){szFeature+=','+this.segments[i].to.toString();}
return'POLYGON('+szFeature+')';},updateGeo:function(){for(var i=0;i<this.segments.length;i++){this.segments[i].updateGeo();}},updatePx:function(){for(var i=0;i<this.segments.length;i++){this.segments[i].updatePx();}}};Fusion.Tool.Canvas.Line=Class.create();Fusion.Tool.Canvas.Line.prototype={segments:null,lineStyle:null,map:null,initialize:function(map){this.map=map;this.segments=[];this.lineStyle=new Fusion.Tool.Canvas.Style({strokeStyle:'rgba(0,0,0,1.0)'});},clean:function(){var nodes=this.getNodes();this.segments=[];var n1=nodes[0];var n2=nodes[1];for(var i=1;i<nodes.length;i++){n2=nodes[i];if(n1.x!=n2.x||n1.y!=n2.y){this.addSegment(new Fusion.Tool.Canvas.Segment(n1,n2));n1=n2;}}},getNodes:function(){var nodes=[];nodes.push(this.segments[0].from);for(var i=0;i<this.segments.length;i++){nodes.push(this.segments[i].to);}
return nodes;},reverseNodes:function(){var nSegments=this.segments.length;if(!nSegments){return;}
for(var i=0;i<nSegments;i++){var seg=this.segments[i];var tmp=seg.from;seg.from=seg.to;seg.to=tmp;};this.segments.reverse();},removeNode:function(node){if(node==this.segments[0].from){this.segments[0].from=null;this.segments.shift();return;}
if(node==this.segments[this.segments.length-1].from){this.segments[this.segments.length-1].from=null;this.segments.pop();return;}
for(var i=1;i<this.segments.length;i++){if(node==this.segments[i].from){this.segments[i-1].to=this.segments[i].to;this.segments[i].from=null;this.segments.splice(i,1);return;}};},draw:function(context){for(var i=0;i<this.segments.length;i++){this.segments[i].draw(context);}},addSegment:function(s){s.normalStyle=this.lineStyle;this.segments[this.segments.length]=s;},lastSegment:function(){return this.segments[this.segments.length-1];},segmentTo:function(node){var margin=arguments.length>1?arguments[1]:3;for(var i=0;i<this.segments.length;i++){if(this.segments[i].hasTo(node,margin)){return this.segments[i];}}
return null;},segmentFrom:function(node){var margin=arguments.length>1?arguments[1]:3;for(var i=0;i<this.segments.length;i++){if(this.segments[i].hasFrom(node,margin)){return this.segments[i];}}
return null;},extendLine:function(){var last=this.lastSegment();var newNode=new Fusion.Tool.Canvas.Node(last.to.x,last.to.y,this.map);var newSegment=new Fusion.Tool.Canvas.Segment(last.to,newNode);this.addSegment(newSegment);return newSegment;},updateGeo:function(){for(var i=0;i<this.segments.length;i++){this.segments[i].updateGeo();}},updatePx:function(){for(var i=0;i<this.segments.length;i++){this.segments[i].updatePx();}}};Fusion.Tool.Canvas.Segment=Class.create();Fusion.Tool.Canvas.Segment.prototype={from:null,to:null,initialize:function(from,to){this.from=from;this.to=to;this.isEditing=false;this.normalStyle=new Fusion.Tool.Canvas.Style({lineWidth:1,strokeStyle:'rgba(0,0,0,1.0)'});this.editStyle=new Fusion.Tool.Canvas.Style({lineWidth:1,strokeStyle:'rgba(255,0,0,1.0)'});},hasTo:function(node,margin){return this.to.near({x:node.px,y:node.py},margin);},hasFrom:function(node,margin){return this.from.near({x:node.px,y:node.py},margin);},intersectsPoint:function(point,margin){var minX=Math.min(this.to.px,this.from.px);var maxX=Math.max(this.to.px,this.from.px);if(point.x>maxX||point.x<minX){return false;};var maxY=Math.max(this.to.py,this.from.py);var minY=Math.min(this.to.py,this.from.py);if(point.y<minY||point.y>maxY){return false;};var slope=parseFloat((maxY-minY))/(maxX-minX);var segY=slope*(point.x-minX)+minY;return(segY-margin<point.y&&segY+margin>point.y);},setNormalStyle:function(style){this.normalStyle=style;},setEditStyle:function(style){this.editStyle=style;},draw:function(context){if(this.isEditing){this.editStyle.apply(context);}else{this.normalStyle.apply(context);}
context.beginPath();context.moveTo(this.from.px,this.from.py);context.lineTo(this.to.px,this.to.py);context.closePath();context.stroke();if(this.isEditing){this.from.draw(context);this.to.draw(context);}},setEditing:function(bEditing){this.isEditing=bEditing;},toString:function(){return this.from.toString()+', '+this.to.toString();},updateGeo:function(){this.from.updateGeo();this.to.updateGeo();},updatePx:function(){this.from.updatePx();this.to.updatePx();}};Fusion.Tool.Canvas.Node=Class.create();Fusion.Tool.Canvas.Node.prototype={x:null,y:null,px:null,py:null,uid:null,map:null,counter:[0],isSelected:false,initialize:function(x,y,map){this.map=map;this.set(x,y);var p=map.geoToPix(x,y);this.setPx(p.x,p.y);this.radius=3;this.uid=this.counter[0];this.counter[0]++;this.normalStyle=new Fusion.Tool.Canvas.Style({lineWidth:1,strokeStyle:'rgba(0,0,0,1.0)'});this.selectedStyle=new Fusion.Tool.Canvas.Style({lineWidth:1,fillStyle:'rgba(255,0,0,1.0)',strokeStyle:'rgba(255,0,0,1.0)'});},set:function(x,y){this.x=x;this.y=y;var p=this.map.geoToPix(x,y);this.setPx(p.x,p.y);},setPx:function(px,py){this.px=px;this.py=py;},updateGeo:function(){if(!this.px||!this.py){return;};var g=this.map.pixToGeo(this.px,this.py);this.set(g.x,g.y);},updatePx:function(){if(!this.x||!this.y){return;};var p=this.map.geoToPix(this.x,this.y);this.setPx(p.x,p.y);},near:function(point,tolerance){var minX=point.x-tolerance;var maxX=point.x+tolerance;var maxY=point.y+tolerance;var minY=point.y-tolerance;return((this.px>minX&&this.px<maxX)&&(this.py>minY&&this.py<maxY))?true:false;},within:function(bbox){var minX=Math.min(bbox[0],bbox[2]);var maxX=Math.max(bbox[0],bbox[2]);var minY=Math.min(bbox[1],bbox[3]);var maxY=Math.max(bbox[1],bbox[3]);return((this.px>minX&&this.px<maxX)&&(this.py>minY&&this.py<maxY))?true:false;},draw:function(context){if(this.isSelected){this.selectedStyle.apply(context);}else{this.normalStyle.apply(context);}
context.beginPath();context.arc(this.px,this.py,this.radius,0,2*Math.PI,1);context.closePath();context.stroke();if(this.isSelected){context.fill();};},setSelected:function(bSelected){this.isSelected=bSelected;},toString:function(){return'('+this.uid+') '+this.x+' ['+this.px+'px] '+this.y+' ['+this.py+'px] ';}};Fusion.Tool.Canvas.Style=Class.create();Fusion.Tool.Canvas.Style.prototype={properties:['fillStyle','globalAlpha','globalCompositeOperation','lineCap','lineJoin','lineWidth','miterLimit','shadowBlur','shadowColor','shadowOffsetX','shadowOffsetY','strokeStyle'],initialize:function(o){for(var i=0;i<this.properties.length;i++){var p=this.properties[i];this[p]=o[p]?o[p]:null;}},set:function(p,v){this[p]=v;},apply:function(context){for(var i=0;i<this.properties.length;i++){var p=this.properties[i];if(this[p]){context[p]=this[p];}}}};Fusion.Tool.Click=Class.create();Fusion.Tool.Click.prototype={initialize:function()
{this.mouseUpCB=this.mouseUp.bindAsEventListener(this);},execute:function(x,y)
{},activateClickTool:function()
{if(this.oMap){this.oMap.observeEvent('mouseup',this.mouseUpCB);}},deactivateClickTool:function()
{if(this.oMap){this.oMap.stopObserveEvent('mouseup',this.mouseUpCB);}},mouseUp:function(e)
{if(Event.isLeftClick(e)){var sPixPoint=this.oMap.getEventPosition(e);this.execute(sPixPoint.x,sPixPoint.y);}}};Fusion.Tool.Rectangle=Class.create();Fusion.Tool.Rectangle.prototype={oRectDiv:null,_sStartPos:null,_bIsActive:null,initialize:function(){this.oRectDiv=document.createElement('div');this.oRectDiv.style.position='absolute';this.oRectDiv.style.border='1px solid red';this.oRectDiv.style.top='0px';this.oRectDiv.style.left='0px';this.oRectDiv.style.width='1px';this.oRectDiv.style.height='1px';this.oRectDiv.style.visibility='hidden';this.oRectDiv.style.lineHeight='1px';this.oRectDiv.style.zIndex=99;this._bIsActive=false;this.mouseMoveCB=this.mouseMove.bindAsEventListener(this);this.mouseUpCB=this.mouseUp.bindAsEventListener(this);this.mouseDownCB=this.mouseDown.bindAsEventListener(this);this.mouseOutCB=this.mouseOut.bindAsEventListener(this);},execute:function(l,b,r,t){},activateRectTool:function(){if(this._bIsActive){return;}
if(this.oMap){this.oRectDiv.style.left='0px';this.oRectDiv.style.top='0px';this.oRectDiv.style.width='1px';this.oRectDiv.style.height='1px';this.oRectDiv.style.visibility='hidden';this._bIsActive=true;var oDomElem=this.oMap.getDomObj();oDomElem.appendChild(this.oRectDiv);this.oMap.observeEvent('mousemove',this.mouseMoveCB);this.oMap.observeEvent('mouseup',this.mouseUpCB);this.oMap.observeEvent('mousedown',this.mouseDownCB);}},deactivateRectTool:function(){this._sStartPos=null;if(!this._bIsActive){return;}
this._bIsActive=false;var oDomElem=this.oMap.getDomObj();oDomElem.removeChild(this.oRectDiv);this.oMap.stopObserveEvent('mousemove',this.mouseMoveCB);this.oMap.stopObserveEvent('mouseup',this.mouseUpCB);this.oMap.stopObserveEvent('mousedown',this.mouseDownCB);},mouseDown:function(e){if(Event.isLeftClick(e)){var p=this.oMap.getEventPosition(e);this._sStartPos=p;this.oRectDiv.style.left=p.x+'px';this.oRectDiv.style.top=p.y+'px';this.oRectDiv.style.width='1px';this.oRectDiv.style.height='1px';this.oRectDiv.style.visibility='visible';Event.observe(document,'mouseout',this.mouseOutCB);}
Event.stop(e);},mouseUp:function(e){if(this._sStartPos!=null){var t=parseInt(this.oRectDiv.style.top);var l=parseInt(this.oRectDiv.style.left);var r=l+parseInt(this.oRectDiv.style.width);var b=t+parseInt(this.oRectDiv.style.height);this.event=e;this.execute(l,b,r,t);this.oRectDiv.style.left='0px';this.oRectDiv.style.top='0px';this.oRectDiv.style.width='1px';this.oRectDiv.style.height='1px';this.oRectDiv.style.visibility='hidden';this._sStartPos=null;}
Event.stopObserving(document,'mouseout',this.mouseOutCB);Event.stop(e);},mouseMove:function(e){if(this._sStartPos!=null)
{var p=this.oMap.getEventPosition(e);var l=this._sStartPos.x;var t=this._sStartPos.y;var r=p.x;var b=p.y;this.oRectDiv.style.left=Math.min(l,r)+'px';this.oRectDiv.style.top=Math.min(t,b)+'px';this.oRectDiv.style.width=Math.abs(r-l)+'px';this.oRectDiv.style.height=Math.abs(t-b)+'px';Event.stop(e);}},mouseOut:function(e){var target=e.target||e.srcElement;if(target.tagName.toLowerCase()=='html'){this.mouseUp(e);}}};Fusion.Event.MAP_EXTENTS_CHANGED=Fusion.Event.lastEventId++;Fusion.Event.MAP_BUSY_CHANGED=Fusion.Event.lastEventId++;Fusion.Event.MAP_GENERIC_EVENT=Fusion.Event.lastEventId++;Fusion.Event.MAP_RESIZED=Fusion.Event.lastEventId++;Fusion.Constant.LAYER_POINT_TYPE=0;Fusion.Constant.LAYER_LINE_TYPE=1;Fusion.Constant.LAYER_POLYGON_TYPE=2;Fusion.Constant.LAYER_SOLID_TYPE=3;Fusion.Constant.LAYER_RASTER_TYPE=4;Fusion.Widget.Map=Class.create();Fusion.Widget.Map.prototype={_oDomObj:null,_sDomObj:'',_oEventDiv:null,_sMapname:'',_nWidth:-1,_nHeight:-1,_fMetersperunit:-1,_fScale:-1,_nDpi:96,_afCurrentExtents:null,_afInitialExtents:null,oContextMenu:null,bSupressContextMenu:false,layerRoot:null,aLayers:null,initialize:function(oCommand){Object.inheritFrom(this,Fusion.Lib.EventMgr,[]);this.layerRoot=new Fusion.Widget.Map.Group();this.aLayers=[];this._nCellSize=-1;var json=oCommand.jsonNode;this._sDomObj=json.Name?json.Name[0]:'';this._oDomObj=$(this._sDomObj);if(this._oDomObj.jxLayout){this._oDomObj.jxLayout.addSizeChangeListener(this);}
var d=Element.getDimensions(this._oDomObj);this._nWidth=d.width;this._nHeight=d.height;this._nWorkers=0;this.swapImageFn=this.swapImages.bindAsEventListener(this);this.imageErrorFn=this._imageError.bindAsEventListener(this);this._oImg=document.createElement('img');this._oImg.className='png24';this._oImg.id='gMapImg';this._oImg.style.position='absolute';this._oImg.style.top='0px';this._oImg.style.left='0px';this._oImg.style.width=this._nWidth+'px';this._oImg.style.height=this._nHeight+'px';this._oImg.src='images/a_pixel.png';this._oImg.onerror=this.imageErrorFn;this._oImgNew=document.createElement('img');this._oImgNew.className='png24';this._oImgNew.id='gMapImgNew';this._oImgNew.style.position='absolute';this._oImgNew.style.top='0px';this._oImgNew.style.left='0px';this._oImgNew.style.width=this._nWidth+'px';this._oImgNew.style.height=this._nHeight+'px';this._oImgNew.src='images/a_pixel.png';this._oImgNew.onerror=this.imageErrorFn;this._oImg.galleryimg="no";this._oDomObj.appendChild(this._oImg);this._oDomObj.oncontextmenu=function(){return false;};this._oImg.ondrag=function(){return false;};this._oEventDiv=document.createElement('div');this._oEventDiv.id='_oEventDiv_'+this._oDomObj.id;this._oEventDiv.style.position='absolute';this._oEventDiv.style.top='0px';this._oEventDiv.style.left='0px';this._oEventDiv.style.width='100%';this._oEventDiv.style.height='100%';this._oEventDiv.style.zIndex=100;this._oEventDiv.style.backgroundColor='white';this._oEventDiv.style.opacity=0;this._oEventDiv.style.mozOpacity=0;this._oEventDiv.style.filter='Alpha(opacity=0)';this._oDomObj.appendChild(this._oEventDiv);this.registerEventID(Fusion.Event.MAP_EXTENTS_CHANGED);this.registerEventID(Fusion.Event.MAP_BUSY_CHANGED);this.registerEventID(Fusion.Event.MAP_GENERIC_EVENT);this.registerEventID(Fusion.Event.MAP_RESIZED);Event.observe(this._oDomObj,'contextmenu',this.onContextMenu.bind(this));this.bMouseWheelZoom=json.AllowWheelZoom?(json.AllowWheelZoom[0]=='true'?true:false):false;this.nFactor=json.WheelZoomFactor?json.WheelZoomFactor[0]:2.0;if(this.bMouseWheelZoom){Event.observe(this._oEventDiv,'mousewheel',this.onMouseWheel.bind(this));if(window.addEventListener&&navigator.product&&navigator.product=="Gecko"){this._oEventDiv.addEventListener("DOMMouseScroll",this.onMouseWheel.bind(this),false);}}
var fn=this.onMouseMove.bind(this);var ed=this._oEventDiv;Event.observe(ed,'mousemove',fn);Event.observe(window,'unload',function(){Event.stopObserving(ed,'mousemove',fn);});},onMouseMove:function(e){this.lastMousePos=this.getEventPosition(e);},onMouseWheel:function(e){var wheelDelta=e.wheelDelta?e.wheelDelta:e.detail*-1;var wheelSet=null;var factor=this.nFactor;var size=Element.getDimensions(this._oImg);if(!this.lastMousePos){this.lastMousePos={x:size.width/2,y:size.height/2};}
var top=parseInt(this._oImg.style.top);var left=parseInt(this._oImg.style.left);var newLeft,newTop,newWidth,newHeight;var newCenterX,newCenterTop;var direction=1;if(wheelDelta>0){var x=this.lastMousePos.x-left;var y=this.lastMousePos.y-top;newLeft=left-x;newTop=top-y;newWidth=size.width*factor;newHeight=size.height*factor;}else{newWidth=size.width/factor;newHeight=size.height/factor;var x=(this.lastMousePos.x-left)/factor;var y=(this.lastMousePos.y-top)/factor;newLeft=left+x;newTop=top+y;direction=-1;}
this._oImg.style.width=newWidth+"px";this._oImg.style.height=newHeight+"px";this._oImg.style.top=newTop+'px';this._oImg.style.left=newLeft+'px';var geoPoint={};if(this.lastMousePos){var geoFactor=(size.width/newWidth);var curGW=this._afCurrentExtents[2]-this._afCurrentExtents[0];var curGH=this._afCurrentExtents[3]-this._afCurrentExtents[1];var newGW=curGW*geoFactor;var newGH=curGH*geoFactor;var mouseLoc=this.pixToGeo(this.lastMousePos.x,this.lastMousePos.y);var newGL=mouseLoc.x-(mouseLoc.x-this._afCurrentExtents[0])*geoFactor;var newGT=mouseLoc.y+(this._afCurrentExtents[3]-mouseLoc.y)*geoFactor;geoPoint.x=(newGL+newGW/2);geoPoint.y=(newGT-newGH/2);}else{geoPoint=this.getCurrentCenter();}
this.zoom(geoPoint.x,geoPoint.y,direction*factor);},getDomObj:function(){return this._oDomObj;},getPixelSize:function(){return{width:parseInt(this._oImg.width),height:parseInt(this._oImg.height)};},getMapName:function(){return this._sMapname;},getDomId:function(){return this._sDomObj;},_addWorker:function(){this._nWorkers+=1;this.triggerEvent(Fusion.Event.MAP_BUSY_CHANGED,this);},_removeWorker:function(){if(this._nWorkers>0){this._nWorkers-=1;}
this.triggerEvent(Fusion.Event.MAP_BUSY_CHANGED,this);},isBusy:function(){return this._nWorkers>0;},drawMap:function()
{alert("Fusion.Widget.Map::drawMap");},sizeChanged:function(){this.resize();},resize:function(){var d=Element.getDimensions(this.getDomObj());this._nWidth=d.width;this._nHeight=d.height;if(this._afInitialExtents){this.drawMap();}
this.triggerEvent(Fusion.Event.MAP_RESIZED,this);},setMapImageURL:function(url){console.log('setting map image url: '+url);if(this._oImgNew.width!=this._nWidth||this._oImgNew.height!=this._nHeight){this._oImgNew.src='images/a_pixel.png';this._oImgNew.style.width=this._nWidth+'px';this._oImgNew.style.height=this._nHeight+'px';}
if(this._oImgNew.runtimeStyle&&this._oImgNew.runtimeStyle.filter){this._oImgNew.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+url+"',sizingMethod='scale')";this.swapImages();}else{if(this._oImgNew.onload){this._removeWorker();}
this._oImgNew.onload=this.swapImageFn;this._oImgNew.src=url;}},swapImages:function(e){if(!this._oImg.complete&&this._oImg.onload){this._oImg.onload=null;this._removeWorker();}
this._oImgNew.onload=null;this._oImg=this._oDomObj.replaceChild(this._oImgNew,this._oImg);var i=this._oImg;this._oImg=this._oImgNew;this._oImgNew=i;this._oImgNew.style.top='0px';this._oImgNew.style.left='0px';this._oImgNew.style.width=this._oImg.style.width;this._oImgNew.style.height=this._oImg.style.height;this._removeWorker();},_imageError:function(){this._removeWorker();setTimeout(this.drawMap.bind(this),1000);},_calculateScale:function(){var fMetersPerPixel=0.0254/this._nDpi;var fdeltaX=this._afCurrentExtents[2]-this._afCurrentExtents[0];var fdeltaY=this._afCurrentExtents[3]-this._afCurrentExtents[1];var nWidth=this._nWidth;var nHeight=this._nHeight;if(fdeltaX*nWidth>fdeltaY*nHeight){this._fScale=fdeltaX*this._fMetersperunit/(nWidth*fMetersPerPixel);}else{this._fScale=fdeltaY*this._fMetersperunit/(nHeight*fMetersPerPixel);}},setExtents:function(aExtents){if(!this._afInitialExtents){this._afInitialExtents=aExtents;}
var bResize=false;if(this._afCurrentExtents){bResize=true;var cXold=(this._afCurrentExtents[2]+this._afCurrentExtents[0])/2;var cYold=(this._afCurrentExtents[3]+this._afCurrentExtents[1])/2;var cellSizeOld=this._nCellSize;}
var gWidth=Math.abs(aExtents[2]-aExtents[0]);var gHeight=Math.abs(aExtents[3]-aExtents[1]);var nWidth=this._nWidth;var nHeight=this._nHeight;this._nCellSize=Math.max(gWidth/nWidth,gHeight/nHeight);if(gWidth/nWidth!=gHeight/nHeight){var cX=(aExtents[2]+aExtents[0])/2;var cY=(aExtents[3]+aExtents[1])/2;aExtents[0]=cX-(this._nCellSize*nWidth)/2;aExtents[1]=cY-(this._nCellSize*nHeight)/2;aExtents[2]=cX+(this._nCellSize*nWidth)/2;aExtents[3]=cY+(this._nCellSize*nHeight)/2;}
this._afCurrentExtents=aExtents;this._calculateScale();this.triggerEvent(Fusion.Event.MAP_EXTENTS_CHANGED);},fullExtents:function(){this.setExtents(this._afInitialExtents);},zoom:function(fX,fY,nFactor){var fDeltaX=this._afCurrentExtents[2]-this._afCurrentExtents[0];var fDeltaY=this._afCurrentExtents[3]-this._afCurrentExtents[1];var fMinX,fMaxX,fMinY,fMaxy;if(nFactor==1||nFactor==0){fMinX=fX-(fDeltaX/2);fMaxX=fX+(fDeltaX/2);fMinY=fY-(fDeltaY/2);fMaxY=fY+(fDeltaY/2);}else if(nFactor>0){fMinX=fX-(fDeltaX/2/nFactor);fMaxX=fX+(fDeltaX/2/nFactor);fMinY=fY-(fDeltaY/2/nFactor);fMaxY=fY+(fDeltaY/2/nFactor);}else if(nFactor<0){fMinX=fX-((fDeltaX/2)*Math.abs(nFactor));fMaxX=fX+((fDeltaX/2)*Math.abs(nFactor));fMinY=fY-((fDeltaY/2)*Math.abs(nFactor));fMaxY=fY+((fDeltaY/2)*Math.abs(nFactor));}
this.setExtents([fMinX,fMinY,fMaxX,fMaxY]);},zoomScale:function(fScale){var fMetersPerPixel=0.0254/this._nDpi;var nWidth=this._nWidth;var nHeight=this._nHeight;var fMapUnitsPerPixel=fScale*fMetersPerPixel/this._fMetersperunit;var c=this.getCurrentCenter();var fMinX=c.x-(fMapUnitsPerPixel*nWidth/2);var fMinY=c.y-(fMapUnitsPerPixel*nHeight/2);var fMaxX=c.x+(fMapUnitsPerPixel*nWidth/2);var fMaxY=c.y+(fMapUnitsPerPixel*nHeight/2);this.setExtents([fMinX,fMinY,fMaxX,fMaxY]);},_updateExtents:function()
{var cx=(this._afCurrentExtents[0]+this._afCurrentExtents[2])/2;var cy=(this._afCurrentExtents[1]+this._afCurrentExtents[3])/2;this._afCurrentExtents[0]=cx-(this._nCellSize*parseInt(this.img.width))/2;this._afCurrentExtents[1]=cy-(this._nCellSize*parseInt(this.img.height))/2;this._afCurrentExtents[2]=cx+(this._nCellSize*parseInt(this.img.width))/2;this._afCurrentExtents[3]=cy+(this._nCellSize*parseInt(this.img.height))/2;},queryRect:function(fMinX,fMinY,fMaxX,fMaxY)
{},queryPoint:function(fX,fY)
{},pixToGeo:function(pX,pY)
{if(!(this._afCurrentExtents)){return null;}
var gX=parseFloat(this._afCurrentExtents[0])+(pX*this._nCellSize);var gY=parseFloat(this._afCurrentExtents[3])-(pY*this._nCellSize);return{x:gX,y:gY};},pixToGeoMeasure:function(nPixels)
{return(nPixels*this._nCellSize);},geoToPixMeasure:function(fGeo)
{return parseInt(fGeo/this._nCellSize);},geoToPix:function(gX,gY)
{if(!(this._afCurrentExtents)){return null;}
var pX=parseFloat(gX-this._afCurrentExtents[0])/this._nCellSize;var pY=-1*parseFloat(gY-this._afCurrentExtents[3])/this._nCellSize;return{x:Math.floor(pX),y:Math.floor(pY)};},getCurrentScale:function(){return this._fScale;},getCurrentCenter:function()
{var cx=(this._afCurrentExtents[0]+this._afCurrentExtents[2])/2;var cy=(this._afCurrentExtents[1]+this._afCurrentExtents[3])/2;return{x:cx,y:cy};},getCurrentExtents:function()
{return this._afCurrentExtents;},getInitialExtents:function()
{return this._afInitialExtents;},getEventPosition:function(e)
{var posX,posY;if(e.target){posX=posY=0;var o=e.target;while(o.offsetParent)
{posX+=o.offsetLeft;posY+=o.offsetTop;o=o.offsetParent;}
posX=e.pageX-posX;posY=e.pageY-posY;}else if(e.offsetX){posX=e.offsetX;posY=e.offsetY;}else{posX=e.clientX;posY=e.clientY;}
return{x:posX,y:posY};},setCursor:function(cursor)
{if(cursor&&cursor.length&&typeof cursor=='object')
{for(var i=0;i<cursor.length;i++)
{this._oDomObj.style.cursor=cursor[i];if(this._oDomObj.style.cursor==cursor[i])
{break;}}}
else if(typeof cursor=='string')
{this._oDomObj.style.cursor=cursor;}else
{this._oDomObj.style.cursor='auto';}},observeEvent:function(sEventName,fnCB)
{Event.observe(this._oDomObj,sEventName,fnCB,false);},stopObserveEvent:function(sEventName,fnCB)
{Event.stopObserving(this._oDomObj,sEventName,fnCB,false);},activateWidget:function(oWidget)
{if(oWidget.isMutEx()){if(this.oActiveWidget){this.deactivateWidget(this.oActiveWidget);}
oWidget.activate();this.oActiveWidget=oWidget;}else{oWidget.activate();}},deactivateWidget:function(oWidget)
{oWidget.deactivate();this.oActiveWidget=null;},isLoaded:function(){return(this._afCurrentExtents!=null);},supressContextMenu:function(bSupress){this.bSupressContextMenu=bSupress;},setContextMenu:function(menu){this.oContextMenu=menu;},onContextMenu:function(e){if(this.oContextMenu&&!this.bSupressContextMenu&&this.isLoaded()){this.oContextMenu.show(e);this.contextMenuPosition=this.getEventPosition(e);Event.stop(e);}},executeFromContextMenu:function(widget){widget.execute(this.contextMenuPosition.x,this.contextMenuPosition.y);}};Fusion.Event.LAYER_PROPERTY_CHANGED=Fusion.Event.lastEventId++;Fusion.Widget.Map.Layer=Class.create();Fusion.Widget.Map.Layer.prototype={name:null,initialize:function(name){Object.inheritFrom(this,Fusion.Lib.EventMgr,[]);this.name=name;this.registerEventID(Fusion.Event.LAYER_PROPERTY_CHANGED);},set:function(property,value){this[property]=value;this.triggerEvent(Fusion.Event.LAYER_PROPERTY_CHANGED,this);}};Fusion.Event.GROUP_PROPERTY_CHANGED=Fusion.Event.lastEventId++;Fusion.Widget.Map.Group=Class.create();Fusion.Widget.Map.Group.prototype={name:null,groups:null,layers:null,initialize:function(name){Object.inheritFrom(this,Fusion.Lib.EventMgr,[]);this.name=name;this.groups=[];this.layers=[];this.registerEventID(Fusion.Event.GROUP_PROPERTY_CHANGED);},set:function(property,value){this[property]=value;this.triggerEvent(Fusion.Event.GROUP_PROPERTY_CHANGED,this);},addGroup:function(group){group.parentGroup=this;this.groups.push(group);},addLayer:function(layer){layer.parentGroup=this;this.layers.push(layer);},findGroup:function(name){return this.findGroupByAttribute('name',name);},findGroupByAttribute:function(attribute,value){if(this[attribute]==value){return this;}
for(var i=0;i<this.groups.length;i++){var group=this.groups[i].findGroupByAttribute(attribute,value);if(group){return group;}}
return null;},findLayer:function(name){return this.findLayerByAttribute('name',name);},findLayerByAttribute:function(attribute,value){for(var i=0;i<this.layers.length;i++){if(this.layers[i][attribute]==value){return this.layers[i];}}
for(var i=0;i<this.groups.length;i++){var layer=this.groups[i].findLayerByAttribute(attribute,value);if(layer){return layer;}}
return null;}};var GxSelectionObject=Class.create();GxSelectionObject.prototype={aLayers:null,initialize:function(oXML)
{this.aLayers=[];this.nTotalElements=0;var root=new DomNode(oXML);var node=root.getNodeText('minx');if(node)
{this.fMinX=parseFloat(root.getNodeText('minx'));this.fMinY=parseFloat(root.getNodeText('miny'));this.fMaxX=parseFloat(root.getNodeText('maxx'));this.fMaxY=parseFloat(root.getNodeText('maxy'));}
var oTmpNode=root.findFirstNode('TotalElementsSelected');if(oTmpNode)
{this.nTotalElements=parseInt(oTmpNode.textContent);if(this.nTotalElements>0)
{this.nLayers=root.getNodeText('NumberOfLayers');var layerNode=root.findFirstNode('Layer');var iLayer=0;while(layerNode)
{this.aLayers[iLayer++]=new GxSelectionObjectLayer(layerNode);layerNode=root.findNextNode('Layer');}}}},getNumElements:function()
{return this.nTotalElements;},getLowerLeftCoord:function()
{return{x:this.fMinX,y:this.fMinY};},getUpperRightCoord:function()
{return{x:this.fMaxX,y:this.fMaxY};},getNumLayers:function()
{return this.nLayers;},getLayerByName:function(name)
{var oLayer=null;for(var i=0;i<this.nLayers;i++)
{if(this.aLayers[i].getName()==name)
{oLayer=this.aLayers[i];break;}}
return oLayer;},getLayer:function(iIndice)
{if(iIndice>=0&&iIndice<this.nLayers)
{return this.aLayers[iIndice];}
else
{return null;}}};var GxSelectionObjectLayer=Class.create();GxSelectionObjectLayer.prototype={sName:null,nElements:null,aElements:null,nProperties:null,aPropertiesName:null,aPropertiesTypes:null,type:null,area:null,distance:null,bbox:null,center:null,initialize:function(oNode)
{this.sName=oNode.getNodeText('Name');this.nElements=oNode.getNodeText('ElementsSelected');this.aElements=[];this.nProperties=oNode.getNodeText('PropertiesNumber');this.aPropertiesName=[];var oTmp=oNode.getNodeText('PropertiesNames');this.aPropertiesName=oTmp.split(",");this.aPropertiesTypes=[];oTmp=oNode.getNodeText('PropertiesTypes');this.aPropertiesTypes=oTmp.split(",");var oValueCollection=oNode.findNextNode('ValueCollection');this.area=0;this.distance=0;var iElement=0;while(oValueCollection)
{this.aElements[iElement]=[];for(var i=0;i<oValueCollection.childNodes.length;i++)
{oTmp=oValueCollection.childNodes[i].findFirstNode('v');this.aElements[iElement][i]=oTmp.textContent;}
var type=oValueCollection.attributes['type'];var area=oValueCollection.attributes['area'];var distance=oValueCollection.attributes['distance'];var bbox=oValueCollection.attributes['bbox'];var center=oValueCollection.attributes['center'];this.aElements[iElement]['attributes']={};this.aElements[iElement]['attributes'].type=type;this.aElements[iElement]['attributes'].bbox=bbox;this.aElements[iElement]['attributes'].center=bbox;if(type>1){this.area+=parseFloat(area);this.aElements[iElement]['attributes'].area=area;}
if(type>0){this.aElements[iElement]['attributes'].distance=distance;this.distance+=parseFloat(distance);}
oValueCollection=oNode.findNextNode('ValueCollection');iElement++;}},getName:function()
{return this.sName;},getNumElements:function()
{return this.nElements;},getNumProperties:function()
{return this.nProperties;},getPropertyNames:function()
{return this.aPropertiesName;},getPropertyTypes:function()
{return this.aPropertiesTypes;},getElementValue:function(iElement,iProperty)
{if(iElement>=0&&iElement<this.nElements&&iProperty>=0&&iProperty<this.nProperties)
{return this.aElements[iElement][iProperty];}
else
{return null;}}};