
UTILS=new Object();UTILS.loadJS=function(src,id){var agent=navigator.userAgent;var docWrite=(agent.match("MSIExxx")||agent.match("Safarixxx"));if(docWrite){var s="<script src='"+src+"'></script>";document.write(s);}else{var el=document.createElement("script");el.src=src;if(typeof(id)!="undefined"){el.id=id;}
var h=document.getElementsByTagName("head").length?document.getElementsByTagName("head")[0]:document.body;h.appendChild(el);}};GUI=new Object();GUI.initialMapHeight=0;GUI.initialMapWidth=0;GUI.popupFts=null;GUI.popupLayerInfo=null;GUI.showFTSResults=function(query,page,bounds)
{var params=new Object();params.query=query;params.page=page;if(!page)
params.page=1;params.ext=null;if($('cb_fts_map_extent').checked){var ext=map.getExtent().toArray();params.ext=Object.toJSON(ext);}
var popupElt=document.getElementById('popup_fts');GUI.popupFts=new goog.ui.Popup(popupElt);GUI.popupFts.setAutoHide(false);new Ajax.Updater('popup_fts_content',CONST.ROOT_DIR+'layer/fts',{onCreate:function(request)
{},onComplete:function(request)
{GUI.popupFts.setVisible(true);$('btn_close_fts_popup').observe('click',function(evt){GUI.popupFts.setVisible(false);GUI.popupFts.dispose();});},onError:function(request)
{},parameters:params,asynchronous:true,method:'post',evalScripts:true});}
GUI.showLayerInfo=function(layer_id)
{if(GUI.popupFts)
{}
if(GUI.popupLayerInfo)
{GUI.popupLayerInfo.setVisible(false);GUI.popupLayerInfo.dispose();}
GUI.popupLayerInfo=new goog.ui.Dialog();GUI.popupLayerInfo.setId('popup_layer_info');GUI.popupLayerInfo.setContent('<div id="popup_layer_info_content"></div>');GUI.popupLayerInfo.setTitle('Layer Info');GUI.popupLayerInfo.setDisposeOnHide(true);GUI.popupLayerInfo.setButtonSet(null);GUI.popupLayerInfo.setVisible(true);$('popup_layer_info').hide();GUI.popupLayerInfo.setModal(true);new Ajax.Updater('popup_layer_info_content',CONST.ROOT_DIR+'layer/tabbed-info-dialog',{onCreate:function(request)
{},onComplete:function(request)
{GUI.popupLayerInfo.reposition();$('popup_layer_info_content').style.minHeight='450px';$('popup_layer_info').show();},onError:function(request)
{},parameters:'layer_id='+layer_id+'&tabbed_view=1&popup=1',asynchronous:true,method:'post',evalScripts:true});}
GUI.disableGui=function(disable)
{if(disable)
{$('overlay').style.zIndex=3;}
else
{$('overlay').style.zIndex=1;}}
GUI.centerElement=function(el,topOffset)
{var elW=el.getWidth();var scrW=screen.width;var left=(scrW-elW)/2;el.style.left=left+'px';if(!topOffset)
{var elH=el.getHeight();var scrH=screen.width;var top=(scrH-elH)/2;el.style.top=top+'px';}
else
{el.style.top=topOffset+'px';}}
GUI.showPopup=function(el_id,show)
{el=$(el_id);contentEl=$(el_id+'_content')
if(show)
{GUI.disableGui(true);GUI.centerElement($(el_id),80);el.style.zIndex=3;el.show();}
else
{GUI.disableGui(false);el.style.zIndex=1;contentEl.innerHTML='';el.hide();}}
GUI.adjustAppHeight=function()
{}
GUI.showSidePanel=function(show)
{if(show)
{$('overlay_panel').show();GUI.adjustAppHeight();$('btn_side_panel_show').hide();$('btn_side_panel_hide').show();if(map)
map.updateSize();}
else
{$('overlay_panel').hide();GUI.adjustAppHeight();$('btn_side_panel_hide').hide();$('btn_side_panel_show').show();if(map)
map.updateSize();}
GUI.moveSearchControlOverlay();}
GUI.moveSearchControlOverlay=function()
{}
GUI.DefaultValueTextField=Class.create({id:null,el:null,defaultValue:"",initialize:function(id,defaultValue)
{if($(id))
{this.id=id;this.el=$(id);if(defaultValue)
this.defaultValue=defaultValue;this.checkReset();var fnActivate=this.activate.bind(this);$(id).observe('click',fnActivate);var fnCheckReset=this.checkReset.bind(this);$(id).observe('blur',fnCheckReset);}
else
{}},reset:function()
{this.el.style.color="#808080";this.el.value=this.defaultValue;},activate:function()
{if(this.el.value==this.defaultValue)
{this.el.style.color="#000000";this.el.value="";}},checkReset:function()
{if(this.el.value==""||this.el.value==this.defaultValue)
this.reset();}});APP=new Object();APP.serviceTestManager=null;APP.subscribeLayer=function(layer_id,idPart)
{new Ajax.Request(CONST.ROOT_DIR+'layer/subscribe-layer',{onCreate:function(request)
{$('spinner_layer_info_'+layer_id+'_'+idPart).show();},onComplete:function(request)
{$('spinner_layer_info_'+layer_id+'_'+idPart).hide();if(!request.responseJSON.success)
{if(request.responseJSON.notLoggedIn)
{alert('Sie mÃ¼ssen angemeldet sein um Layer zu abonnieren');}
else
{alert('DB Fehler: '+request.responseJSON.err);}}},onError:function(request)
{},parameters:'layer_id='+layer_id,asynchronous:true,method:'post',evalScripts:true});}
APP.setLayerStatus=function(service_id){new Ajax.Request(CONST.ROOT_DIR+'layer/layer-status',{parameters:{'service_id':service_id},method:'get',asynchronous:true,evalScripts:true,onComplete:function(request)
{if(request.responseJSON)
{request.responseJSON.layers.each(function(layer){if(!layer.status_ok){$$('div#layer_'+layer.layer_id+' div.status').each(function(e){e.innerHTML=layer.reason;})}});APP.changeLayerDisplay();}}});}
APP.removeWmsTest=function(metaxml_id,testObj)
{new Ajax.Updater('test_server_list',CONST.ROOT_DIR+'service/remove-wms-test',{parameters:{'metaxml_id':metaxml_id},method:'post',asynchronous:true,evalScripts:true,onComplete:function(request)
{if(typeof(testObj)!='undefined'&&testObj!=null)
testObj.stopUpdater();}});}
APP.changeLayerDisplay=function(toggleButton){var show_valid=false;if($('disp_layer_valid').hasClassName('selected'))
{show_valid=true;}
var show_invalid=false;if($('disp_layer_invalid').hasClassName('selected'))
{show_invalid=true;}
var show_archived=false;if($('disp_layer_archived').hasClassName('selected'))
{show_archived=true;}
$H(layers_obj).each(function(layer)
{$('layer_'+layer.key).hide();if(show_valid)
{if(layer.value.indexOf('ok')>-1)
$('layer_'+layer.key).show();}
if(show_invalid)
{if(layer.value.indexOf('failed')>-1)
$('layer_'+layer.key).show();}
if(show_archived)
{if(layer.value.indexOf('archived')>-1)
$('layer_'+layer.key).show();}});}
APP.keepTrack=function(layer_id,service_id)
{if(layer_id)
{params="layer_id="+layer_id;new Ajax.Updater('status_monitoring_layer',CONST.ROOT_DIR+'monitoring/keep-track',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onComplete:function(request)
{}});}
else if(service_id)
{params="service_id="+service_id;new Ajax.Updater('status_monitoring_service',CONST.ROOT_DIR+'monitoring/keep-track',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onComplete:function(request)
{}});}}
APP.changeName=function()
{var params=$('form_personal_name').serialize();new Ajax.Updater('li_personal_name',CONST.ROOT_DIR+'/user/change-name',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onCreate:function()
{},onComplete:function(request)
{}});}
APP.changeEmail=function()
{var params=$('form_personal_email').serialize();new Ajax.Updater('li_personal_email',CONST.ROOT_DIR+'user/change-email',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onCreate:function()
{},onComplete:function(request)
{}});}
APP.changePassword=function()
{var params=$('form_personal_password').serialize();new Ajax.Updater('li_personal_password',CONST.ROOT_DIR+'user/change-password',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onCreate:function()
{},onComplete:function(request)
{}});}
APP.changeLocation=function()
{var params=$('form_personal_location').serialize();new Ajax.Updater('li_personal_location',CONST.ROOT_DIR+'user/change-location',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onCreate:function()
{},onComplete:function(request)
{}});}
APP.changeNews=function()
{var params=$('form_personal_news').serialize();new Ajax.Updater('li_personal_news',CONST.ROOT_DIR+'user/change-news',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onCreate:function()
{},onComplete:function(request)
{}});}
APP.search=function(newSearch)
{if(newSearch)
{$('search_form_page').value=1;}
var params=$('adv_search_form').serialize();new Ajax.Updater('search_results',CONST.ROOT_DIR+'search/search',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onCreate:function()
{$('spinner_search').show();},onComplete:function(request)
{$('spinner_search').hide();}});}
APP.changeResultPage=function(page)
{var params=$('search-data-pagination').serialize();params+='&page='+page;new Ajax.Updater('search_results',CONST.ROOT_DIR+'search/search',{parameters:params,method:'post',asynchronous:true,evalScripts:true,onCreate:function()
{$('spinner_search').show();},onComplete:function(request)
{$('spinner_search').hide();}});}
APP.enlargeSearchMap=function(enlarge)
{if(enlarge)
{var el=$('map_search').remove();$('insert_map_large').appendChild(el);$('container_map_small').hide();$('container_map_large').show();$('map-layer').show();$('map_search').style.width=$('insert_map_large').getWidth()+'px';$('map_search').style.height='600px';miniMap.updateSize();miniMap.addPanZoomPanel();miniMap.initLegendPanel(true);}
else
{var el=$('map_search').remove();$('insert_map_small').appendChild(el);$('container_map_large').hide();$('map-layer').hide();$('container_map_small').show();$('map_search').style.width=$('insert_map_small').getWidth()+'px';$('map_search').style.height=$('insert_map_small').getHeight()+'px';miniMap.updateSize();miniMap.removePanZoomPanel();}}
if(typeof(window.Geops)=='undefined')
{Geops=new Object();}
Geops.IconSwitcher=Class.create({icon1:null,icon2:null,initialize:function(icon1,icon2,evt)
{if(!evt){evt='click'};this.icon1=icon1;this.icon2=icon2;if(evt=='click')
{fnOnClick1=this.onClick.bindAsEventListener(this,this.icon1);this.icon1.element.observe('click',fnOnClick1);fnOnClick2=this.onClick.bindAsEventListener(this,this.icon2);this.icon2.element.observe('click',fnOnClick2);}
else if(evt=='hover')
{fnOnMouseOver=this.onMouseOver.bindAsEventListener(this,this.icon1);this.icon1.element.observe('mouseover',fnOnMouseOver);fnOnMouseOut=this.onMouseOut.bindAsEventListener(this,this.icon2);this.icon2.element.observe('mouseout',fnOnMouseOut);}},onClick:function(evt,icon)
{if(icon==this.icon1)
{this.icon1.element.hide();this.icon2.element.show();this.icon1.onClick(evt,icon);}
else
{this.icon2.element.hide();this.icon1.element.show();this.icon2.onClick(evt,icon);}},onMouseOver:function(evt,icon)
{this.icon1.element.hide();this.icon2.element.show();},onMouseOut:function(evt,icon)
{this.icon2.element.hide();this.icon1.element.show();}});Geops.Icon=Class.create({id:null,element:null,params:null,onClick:function(evt,icon){},initialize:function(id,callback,params)
{this.id=id;this.element=$(id);this.onClick=callback;if(params!=null)
{this.params=params;}
else
{this.params=new Object();}}});if(typeof(window.Geops)=='undefined')
Geops=new Object();Geops.ToggleButton=Class.create({el:null,selected:false,fnOnClick:null,initialize:function(el_id,fnOnClick)
{if($(el_id))
this.el=$(el_id);if(this.el.hasClassName('selected'))
this.selected=true;if(fnOnClick)
this.fnOnClick=fnOnClick;fnClick=this.click.bind(this);this.el.observe('click',fnClick);},click:function()
{this.selected=!this.selected;if(this.selected)
{this.el.addClassName('selected');}
else
{this.el.removeClassName('selected');}
if(this.fnOnClick)
{this.fnOnClick(this);}}});if(typeof(window.Geops)=='undefined')
Geops=new Object();Geops.RadioGroup=Class.create({buttons:null,selectedButton:null,initialize:function()
{this.buttons=new Array();},addButton:function(button)
{this.buttons.push(button);var fnClick=this.click.bind(this,button);button.el.observe('click',fnClick);},click:function(button)
{for(var i=0;i<this.buttons.length;i++)
{this.buttons[i].setSelected(false);}
button.setSelected(true);button.fnClick();}});Geops.RadioButton=Class.create({el:null,fnClick:null,initialize:function(el_id,fnClick)
{if($(el_id))
this.el=$(el_id);if(fnClick)
this.fnClick=fnClick;},setSelected:function(selected)
{if(selected)
this.el.addClassName('selected');else
this.el.removeClassName('selected');}});if(typeof(window.Geops)=='undefined')
Geops=new Object();Geops.SimpleTabs=Class.create({tabs:null,currentTab:null,onTabSwitched:function(){},initialize:function()
{this.tabs=new Array();},addTab:function(tab)
{fnClickTab=this.clickTab.bind(this,tab)
tab.handle.observe('click',fnClickTab);this.tabs.push(tab);if(!this.currentTab)
this.currentTab=tab;},clickTab:function(tab)
{if(tab.status=='enabled')
{this.switchTab(tab);this.currentTab=tab;}},switchTab:function(tab)
{for(var i=0;i<this.tabs.length;i++)
{this.tabs[i].inactivate();}
tab.activate();this.onTabSwitched(tab);},getTab:function(handleId)
{for(var i=0;i<this.tabs.length;i++)
{if(this.tabs[i].handleId==handleId)
return this.tabs[i];}
return null;}});Geops.SimpleTab=Class.create({handleId:null,handle:null,contentId:null,content:null,loaded:false,status:'enabled',url:null,updateParams:"",updateDiv:null,onTabLoaded:function(tab){},initialize:function(handleId,contentId,url,updateParams,updateDiv)
{this.handleId=handleId;this.handle=$(handleId);this.contentId=contentId;this.content=$(contentId);if(url)
{this.url=url;if(updateParams)
this.updateParams=updateParams;}
if(updateDiv)
{this.updateDiv=updateDiv;}},setStatus:function(status)
{this.status=status;this.handle.removeClassName('enabled');this.handle.removeClassName('disabled');this.handle.removeClassName('selected');this.handle.addClassName(status);},setLoaded:function(loaded)
{this.loaded=loaded;},loadTab:function()
{},activate:function()
{this.setStatus('selected');this.show();},inactivate:function()
{this.setStatus('enabled');this.hide();},show:function(spinner_id)
{if(!this.loaded&&this.url)
{var update=this.contentId;if(this.updateDiv)
{update=this.updateDiv;}
fnOnTabLoaded=this.onTabLoaded.bind(this);new Ajax.Updater(update,CONST.ROOT_DIR+this.url,{onCreate:function(request)
{if(spinner_id&&$(spinner_id))
$(spinner_id).show();},onComplete:function(request)
{if(spinner_id&&$(spinner_id))
$(spinner_id).hide();fnOnTabLoaded(this);},onError:function(request)
{},parameters:this.updateParams,asynchronous:true,method:'post',evalScripts:true});this.loaded=true;this.content.show();}
else
{this.content.show();}},hide:function()
{this.content.hide();}});if(typeof(window.Geops)=='undefined')
Geops=new Object();Geops.ServiceTestManager=Class.create({tests:null,list_id:null,list_el:null,listCounter:0,TIMEOUT:60,initialize:function(list_id)
{if($(list_id))
{this.list_id=list_id;this.list_el=$(list_id);}
else alert('Error: unknown id for list');this.tests=new Array();this.fetchTestsFromSession();},addTestToList:function(test)
{this.tests.push(test);},addTest:function(test)
{var added=false;for(var i=0;i<this.tests.length;i++)
{if(this.tests[i].url==test.url)
added=true;}
if(!added)
{this.addTestToList(test);this.createListElement(test);var params='url='+encodeURIComponent(test.url)+'&form=add_service_test';var fnSetError=test.setError.bind(test);var fnSetMetaxmlId=test.setMetaxmlId.bind(test);var fnSetStatus=test.setStatus.bind(test);new Ajax.Request(CONST.ROOT_DIR+'service/add-service',{onCreate:function(request)
{},onComplete:function(request)
{if(request.responseJSON.error)
{var msg='';for(var i=0;i<request.responseJSON.errors.length;i++)
{msg+=request.responseJSON.errors[i]+'</br>';}
fnSetError(msg);fnSetStatus('finished_err');}
else if(request.responseJSON.metaxml_id)
{fnSetMetaxmlId(request.responseJSON.metaxml_id);}},onError:function(request)
{},parameters:params,asynchronous:true,method:'post',evalScripts:true});}
else
{alert('URL has already been added');}},createListElement:function(test)
{this.listCounter++;var li=test.createLi(this.listCounter);var first=this.list_el.firstChild;if(first)
this.list_el.insertBefore(li,first);else
this.list_el.appendChild(li);var fnRemoveTest=this.removeTest.bind(this,test);$('btn_remove_service_test_'+test.index).observe('click',fnRemoveTest);$('validation_errors_service_test_'+test.index).observe('click',function(){$('validation_errors_service_test_'+test.index).hide();});},removeTest:function(test)
{var params='metaxml_id='+test.metaxml_id;var pos=this.tests.indexOf(test);Element.remove(test.li_el);this.tests.splice(pos,1);new Ajax.Request(CONST.ROOT_DIR+'service/remove-service-test',{onCreate:function(request)
{},onComplete:function(request)
{},onError:function(request)
{},parameters:params,asynchronous:true,method:'post',evalScripts:true});},fetchTestsFromSession:function()
{var fnCreateListElement=this.createListElement.bind(this);var fnAddTestToList=this.addTestToList.bind(this);new Ajax.Request(CONST.ROOT_DIR+'service/get-service-tests',{onCreate:function(request)
{},onComplete:function(request)
{var tests=request.responseJSON;for(var i=0;i<tests.length;i++)
{var test=new Geops.ServiceTest(tests[i].url,tests[i].status,tests[i].metaxml_id);fnAddTestToList(test);fnCreateListElement(test);if(tests[i].error)
{test.setError(tests[i].error)}
if(tests[i].has_validation_errors)
{test.setValidationErrors();}
if(tests[i].status=='ready')
{test.setReady(tests[i].title,tests[i].service_id);}}},onError:function(request)
{},asynchronous:false,method:'post',evalScripts:true});},getTest:function(metaxml_id)
{for(var i=0;i<this.tests.length;i++)
{if(this.tests[i].metaxml_id==metaxml_id)
return this.tests[i];}
return false;},run:function()
{this.checkTests();var fnCheckTests=this.checkTests.bind(this);this.updater=new PeriodicalExecuter(function(pe){fnCheckTests();},15);},checkTests:function()
{var metaxml_ids=new Array();for(var i=0;i<this.tests.length;i++)
{if(this.tests[i].status=='running'&&this.tests[i].metaxml_id!=null)
{metaxml_ids.push(this.tests[i].metaxml_id);}}
var params='';for(var i=0;i<metaxml_ids.length;i++)
{params+='metaxml_ids[]='+metaxml_ids[i]+'&';}
var fnGetTest=this.getTest.bind(this);if(params!='')
{new Ajax.Request(CONST.ROOT_DIR+'service/test-services',{onCreate:function(request)
{},onComplete:function(request)
{var tests=request.responseJSON;for(var i=0;i<tests.length;i++)
{var test=fnGetTest(tests[i].metaxml_id);if(tests[i].status=='timeout')
{test.setTimeout();test.setError(tests[i].error)}
else if(tests[i].ready==true)
{test.setReady(tests[i].title,tests[i].service_id);if(tests[i].has_validation_errors)
{test.setValidationErrors();}}}},onError:function(request)
{},parameters:params,asynchronous:true,method:'post',evalScripts:true});}}});Geops.ServiceTest=Class.create({metaxml_id:null,li_id:null,li_el:null,url:null,title:null,status:null,ts_start:null,index:null,error:null,initialize:function(url,status,metaxml_id)
{this.url=url;if(status)
this.status=status;else
this.status='running';if(metaxml_id)
this.metaxml_id=metaxml_id;this.error='';},setStatus:function(status)
{this.status=status;},createLi:function(counter)
{this.index=counter;this.li_el=document.createElement('LI');this.li_el.id='li_service_test_'+counter;var title=this.url;if(this.title)
title=this.title;var displayRunning='display: none;';if(this.status=='running')
{displayRunning='';}
var displayReady='display: none;';if(this.status=='ready')
{displayReady='';}
var html='<span id="title_'+this.index+'">'+title+'&nbsp;</span>';html+='<ul class="icons">';html+='<li class="running" id="running_'+this.index+'" style="'+displayRunning+'">running</li>';html+='<li class="ready" id="ready_'+this.index+'" style="'+displayReady+'">ready</li>';html+='<li id="btn_remove_service_test_'+this.index+'" class="remove"><a title="remove from list" href="#">remove</a></li>';html+='</ul>'
html+='<div class="subline">'+this.url+'</div>';html+='<div style="background-color: #f3f3f3; margin-right: 10px;">';html+='<div class="hint_small" id="li_service_test_'+this.index+'_hint" style="margin-top: 5px;"></div>';html+='<div class="xml_validation_errors" id="validation_errors_service_test_'+this.index+'" style="display: none;"></div>'
html+='</div>';html+='<div class="error_small" id="li_service_test_'+this.index+'_error" style="margin-top: 3px;"></div>';this.li_el.innerHTML=html;return this.li_el;},setHint:function(hint)
{$('li_service_test_'+this.index+'_hint').innerHTML=hint;},loadValidationErrors:function()
{var params='metaxml_id='+this.metaxml_id;var updateDiv='validation_errors_service_test_'+this.index;var index=this.index;if($(updateDiv).innerHTML=='')
{new Ajax.Updater(updateDiv,CONST.ROOT_DIR+'service/xml-validation-errors',{onCreate:function(request)
{$('spinner_xml_validation_errors_'+index).show();$(updateDiv).show();},onComplete:function(request)
{$('spinner_xml_validation_errors_'+index).hide();},onError:function(request)
{},parameters:params,asynchronous:false,method:'post',evalScripts:true});}
else
{$(updateDiv).show();}},setValidationErrors:function()
{$('li_service_test_'+this.index+'_hint').innerHTML='XML Validation failed. <a href="#" id="link_validation_errors_'+this.index+'" onclick="return false;">More...</a><br/><img src="'+CONST.ROOT_DIR+'img/spinner.gif" id="spinner_xml_validation_errors_'+this.index+'" style="display: none;" />';fnLoadValidationErrors=this.loadValidationErrors.bind(this);$('link_validation_errors_'+this.index).observe('click',fnLoadValidationErrors);},setError:function(error)
{$('running_'+this.index).hide();this.error=error;$('li_service_test_'+this.index+'_error').innerHTML=error;},setMetaxmlId:function(metaxml_id)
{this.metaxml_id=metaxml_id;},setReady:function(title,service_id)
{this.setStatus('ready');this.title=title;$('running_'+this.index).hide();$('ready_'+this.index).show();$('title_'+this.index).innerHTML='<a href="/server/'+service_id+'">'+title+'</a>';},setTimeout:function()
{this.setStatus('timeout');$('running_'+this.index).hide();this.setError(this.error);},writeToSession:function()
{}});SessionMgmnt=new Object();SessionMgmnt.layers=new Array();SessionMgmnt.addLayer=function(layerid){if(SessionMgmnt.layers!=undefined&&SessionMgmnt.layers.length>=3){alert('Maximum number of layers reached. Remove a layer first.');return false;}else{new Ajax.Request(CONST.ROOT_DIR+'map/ajax/addlayer/'+layerid,{asynchronous:true,method:'get',evalScripts:true,evalJson:true,onComplete:function(request){SessionMgmnt.layers=request.responseJSON.layers;SessionMgmnt.updateControls();}});return true;}};SessionMgmnt.removeLayer=function(layerid){new Ajax.Request(CONST.ROOT_DIR+'map/ajax/removelayer/'+layerid,{asynchronous:true,method:'get',evalScripts:true,evalJson:true,onComplete:function(request){SessionMgmnt.layers=request.responseJSON.layers;SessionMgmnt.updateControls();}});};SessionMgmnt.hasLayer=function(layerid,callback){new Ajax.Request(CONST.ROOT_DIR+'map/ajax/removelayer/'+layerid,{asynchronous:true,method:'get',evalScripts:true,evalJson:true,onComplete:function(request){callback(request.responseJSON.result);}});};SessionMgmnt.loadSession=function(){new Ajax.Request(CONST.ROOT_DIR+'map/ajax/layers',{asynchronous:true,method:'get',evalScripts:true,evalJson:true,onComplete:function(request){SessionMgmnt.layers=request.responseJSON.layers;SessionMgmnt.updateControls();}});};SessionMgmnt.updateLayerControls=function(layerid){if(SessionMgmnt.layers){var pos=SessionMgmnt.layers.indexOf(layerid);}
else{var pos=-1;}
var es=$$('div#layer_'+layerid+' div.controls');if(es.length>0){es.each(function(e){if((e!=null)&&(e!=undefined)){if(pos!==-1){e.innerHTML='<a href="javascript:SessionMgmnt.removeLayer('+layerid+');">Remove</a>';}
else{e.innerHTML='<a href="javascript:SessionMgmnt.addLayer('+layerid+');">Add</a>';}}});}};SessionMgmnt.updateControls=function(){var ide=$$('.layerid');for(var i=0;i<ide.length;i++){var layer=ide[i].innerHTML;SessionMgmnt.updateLayerControls(parseInt(layer));};};OpenLayers.Control.MMLayerSwitcher=OpenLayers.Class(OpenLayers.Control.LayerSwitcher,{remove_image:CONST.ROOT_DIR+"img/remove_small.png",statistics_image:CONST.ROOT_DIR+"img/statistics.png",zoom_image:CONST.ROOT_DIR+"img/zoom.png",activeColor:"#6e90a6",initialize:function(options){OpenLayers.Control.LayerSwitcher.prototype.initialize.apply(this,arguments);},draw:function(){OpenLayers.Control.LayerSwitcher.prototype.draw.apply(this);if(!this.outsideViewport){this.maximizeControl();}
return this.div;},redraw:function(){if(!this.checkRedraw()){return this.div;}
this.clearLayersArray("base");this.clearLayersArray("data");var containsOverlays=false;var containsBaseLayers=false;var len=this.map.layers.length;this.layerStates=new Array(len);for(var i=0;i<len;i++){var layer=this.map.layers[i];this.layerStates[i]={'name':layer.name,'visibility':layer.visibility,'inRange':layer.inRange,'id':layer.id};}
var layers=this.map.layers.slice();if(!this.ascending){layers.reverse();}
for(var i=0,len=layers.length;i<len;i++){var layer=layers[i];var baseLayer=layer.isBaseLayer;if(layer.displayInLayerSwitcher){if(baseLayer){containsBaseLayers=true;}else{containsOverlays=true;}
var checked=(baseLayer)?(layer==this.map.baseLayer):layer.getVisibility();var inputElem=document.createElement("input");inputElem.id=this.id+"_input_"+layer.name;inputElem.name=(baseLayer)?"baseLayers":layer.name;inputElem.type=(baseLayer)?"radio":"checkbox";inputElem.value=layer.name;inputElem.checked=checked;inputElem.defaultChecked=checked;if(!baseLayer&&!layer.inRange){inputElem.disabled=true;}
var context={'inputElem':inputElem,'layer':layer,'layerSwitcher':this};OpenLayers.Event.observe(inputElem,"mouseup",OpenLayers.Function.bindAsEventListener(this.onInputClick,context));var labelSpan=document.createElement("span");if(!baseLayer&&!layer.inRange){labelSpan.style.color="gray";}
labelSpan.innerHTML=layer.name;labelSpan.style.verticalAlign=(baseLayer)?"bottom":"baseline";OpenLayers.Event.observe(labelSpan,"click",OpenLayers.Function.bindAsEventListener(this.onInputClick,context));var br=document.createElement("br");var removeImg=null;var statsImg=null;var zoomImg=null;if(!baseLayer){removeImg=document.createElement("img");removeImg.style.cursor="Pointer";removeImg.title="remove layer from map";var srcAttr=document.createAttribute("src");srcAttr.nodeValue=this.remove_image;removeImg.setAttributeNode(srcAttr);OpenLayers.Event.observe(removeImg,"click",OpenLayers.Function.bindAsEventListener(this.onRemoveClick,context));statsImg=document.createElement("img");statsImg.style.cursor="Pointer";statsImg.title="show layer info";var srcAttr=document.createAttribute("src");srcAttr.nodeValue=this.statistics_image;statsImg.setAttributeNode(srcAttr);OpenLayers.Event.observe(statsImg,"click",OpenLayers.Function.bindAsEventListener(this.onInfoClick,context));if(layer.contentExtent!=null&&layer.contentExtent!=undefined){zoomImg=document.createElement("img");zoomImg.style.cursor="Pointer";zoomImg.title="zoom to layer";var srcAttr=document.createAttribute("src");srcAttr.nodeValue=this.zoom_image;zoomImg.setAttributeNode(srcAttr);OpenLayers.Event.observe(zoomImg,"click",OpenLayers.Function.bindAsEventListener(this.onZoomClick,context));}}
var groupArray=(baseLayer)?this.baseLayers:this.dataLayers;groupArray.push({'layer':layer,'inputElem':inputElem,'removeImg':removeImg,'statsImg':statsImg,'statsImg':zoomImg,'labelSpan':labelSpan});var groupDiv=(baseLayer)?this.baseLayersDiv:this.dataLayersDiv;groupDiv.appendChild(inputElem);if((removeImg!=undefined)&&(removeImg!=null)){groupDiv.appendChild(removeImg);};if((statsImg!=undefined)&&(statsImg!=null)){groupDiv.appendChild(statsImg);};if((zoomImg!=undefined)&&(zoomImg!=null)){groupDiv.appendChild(zoomImg);};groupDiv.appendChild(labelSpan);groupDiv.appendChild(br);}}
this.dataLbl.style.display=(containsOverlays)?"":"none";this.baseLbl.style.display=(containsBaseLayers)?"":"none";return this.div;},clearLayersArray:function(layersType){var layers=this[layersType+"Layers"];if(layers){for(var i=0,len=layers.length;i<len;i++){var layer=layers[i];OpenLayers.Event.stopObservingElement(layer.inputElem);OpenLayers.Event.stopObservingElement(layer.labelSpan);if((layer.removeImg!=undefined)&&(layer.removeImg!=null)){OpenLayers.Event.stopObservingElement(layer.removeImg);}
if((layer.statsImg!=undefined)&&(layer.statsImg!=null)){OpenLayers.Event.stopObservingElement(layer.statsImg);}
if((layer.zoomImg!=undefined)&&(layer.zoomImg!=null)){OpenLayers.Event.stopObservingElement(layer.zoomImg);}}}
this[layersType+"LayersDiv"].innerHTML="";this[layersType+"Layers"]=[];},loadContents:function(){this.div.style.position="absolute";this.div.style.top="25px";this.div.style.right="0px";this.div.style.left="";this.div.style.fontFamily="sans-serif";this.div.style.fontWeight="bold";this.div.style.marginTop="3px";this.div.style.marginLeft="3px";this.div.style.marginBottom="3px";this.div.style.fontSize="smaller";this.div.style.color="white";this.div.style.backgroundColor="transparent";OpenLayers.Event.observe(this.div,"mouseup",OpenLayers.Function.bindAsEventListener(this.mouseUp,this));OpenLayers.Event.observe(this.div,"click",this.ignoreEvent);OpenLayers.Event.observe(this.div,"mousedown",OpenLayers.Function.bindAsEventListener(this.mouseDown,this));OpenLayers.Event.observe(this.div,"dblclick",this.ignoreEvent);this.layersDiv=document.createElement("div");this.layersDiv.id=this.id+"_layersDiv";this.layersDiv.style.paddingTop="5px";this.layersDiv.style.paddingLeft="10px";this.layersDiv.style.paddingBottom="5px";this.layersDiv.style.paddingRight="75px";this.layersDiv.style.backgroundColor=this.activeColor;this.layersDiv.style.width="100%";this.layersDiv.style.height="100%";this.baseLbl=document.createElement("div");this.baseLbl.innerHTML=OpenLayers.i18n("baseLayer");this.baseLbl.style.marginTop="3px";this.baseLbl.style.marginLeft="3px";this.baseLbl.style.marginBottom="3px";this.baseLayersDiv=document.createElement("div");this.baseLayersDiv.style.paddingLeft="10px";this.dataLbl=document.createElement("div");this.dataLbl.innerHTML=OpenLayers.i18n("overlays");this.dataLbl.style.marginTop="3px";this.dataLbl.style.marginLeft="3px";this.dataLbl.style.marginBottom="3px";this.dataLayersDiv=document.createElement("div");this.dataLayersDiv.style.paddingLeft="10px";if(this.ascending){this.layersDiv.appendChild(this.baseLbl);this.layersDiv.appendChild(this.baseLayersDiv);this.layersDiv.appendChild(this.dataLbl);this.layersDiv.appendChild(this.dataLayersDiv);}else{this.layersDiv.appendChild(this.dataLbl);this.layersDiv.appendChild(this.dataLayersDiv);this.layersDiv.appendChild(this.baseLbl);this.layersDiv.appendChild(this.baseLayersDiv);}
this.div.appendChild(this.layersDiv);OpenLayers.Rico.Corner.round(this.div,{corners:"bl",bgColor:"transparent",color:this.activeColor,blend:false});OpenLayers.Rico.Corner.changeOpacity(this.layersDiv,0.75);var imgLocation=OpenLayers.Util.getImagesLocation();var sz=new OpenLayers.Size(18,18);var img=imgLocation+'layer-switcher-maximize.png';this.maximizeDiv=OpenLayers.Util.createAlphaImageDiv("OpenLayers_Control_MaximizeDiv",null,sz,img,"absolute");this.maximizeDiv.style.top="5px";this.maximizeDiv.style.right="0px";this.maximizeDiv.style.left="";this.maximizeDiv.style.display="none";OpenLayers.Event.observe(this.maximizeDiv,"click",OpenLayers.Function.bindAsEventListener(this.maximizeControl,this));this.div.appendChild(this.maximizeDiv);var img=imgLocation+'layer-switcher-minimize.png';var sz=new OpenLayers.Size(18,18);this.minimizeDiv=OpenLayers.Util.createAlphaImageDiv("OpenLayers_Control_MinimizeDiv",null,sz,img,"absolute");this.minimizeDiv.style.top="5px";this.minimizeDiv.style.right="0px";this.minimizeDiv.style.left="";this.minimizeDiv.style.display="none";OpenLayers.Event.observe(this.minimizeDiv,"click",OpenLayers.Function.bindAsEventListener(this.minimizeControl,this));this.div.appendChild(this.minimizeDiv);this.baseLbl.innerHTML=OpenLayers.i18n("Background");;this.dataLbl.innerHTML=OpenLayers.i18n("WMS Layers");this.div.style.top="0px";this.div.style.marginTop="0px";},onZoomClick:function(e){if(this.layer.layer_id!=undefined&&this.layer.layer_id!=null){this.layer.map.zoomToExtent(this.layer.contentExtent,true);}
OpenLayers.Event.stop(e);},onRemoveClick:function(e){if(this.layer.layer_id!=undefined&&this.layer.layer_id!=null){this.layer.map.removeMMLayer(this.layer.layer_id);this.layerSwitcher.redraw();}
OpenLayers.Event.stop(e);},onInfoClick:function(e){var statsDiv=$('popup_layerinfo');if(statsDiv&&this.layer.layer_id!=undefined&&this.layer.layer_id!=null){GUI.showLayerInfo(this.layer.layer_id,'popup_layerinfo_content',false,true,true,true,'spinner_popup_layer_info');GUI.showPopup('popup_layerinfo',true);}
OpenLayers.Event.stop(e);},CLASS_NAME:"OpenLayers.Control.MMLayerSwitcher"});OpenLayers.Control.MMSearch=OpenLayers.Class(OpenLayers.Control,{element:null,searchfield:null,imgbutton:null,map_extent_cb:null,allowSelection:false,searchImg:CONST.ROOT_DIR+"img/search.png",initialize:function(){OpenLayers.Control.prototype.initialize.apply(this,arguments);},destroy:function(){if(this.imgbutton){OpenLayers.Event.stopObservingElement(this.imgbutton);this.element.removeChild(this.imgbutton);this.imgbutton=null;}
if(this.searchfield){OpenLayers.Event.stopObservingElement(this.searchfield);this.element.removeChild(this.searchfield);this.searchfield=null;}
if(this.element.parentNode==this.div){this.div.removeChild(this.element);}
this.element=null;OpenLayers.Control.prototype.destroy.apply(this,arguments);},performSearch:function(e){if((this.searchfield!=null)||(this.searchfield!=undefined)){var query=this.searchfield.value;if(query!=''){if(this.map_extent_cb.checked==true){GUI.showFTSResults(this.searchfield.value,1,this.map.getExtent());}
else{GUI.showFTSResults(this.searchfield.value);}}}
OpenLayers.Event.stop(e);},performSearch2:function(e){if(($('search_control_search_field')!=null)||($('search_control_search_field')!=undefined)){var query=$('search_control_search_field').value;if(query!=''){if(this.map_extent_cb.checked==true){GUI.showFTSResults($('search_control_search_field').value,1,this.map.getExtent());}
else{GUI.showFTSResults($('search_control_search_field').value);}}}
OpenLayers.Event.stop(e);},keypressSearch2:function(e){if(($('search_control_search_field')!=null)||($('search_control_search_field')!=undefined)){if(e.keyCode==13){var query=$('search_control_search_field').value;if(query!=''){if(this.map_extent_cb.checked==true){GUI.showFTSResults($('search_control_search_field').value,1,this.map.getExtent());}
else{GUI.showFTSResults($('search_control_search_field').value);}}
OpenLayers.Event.stop(e);}}},focusSearch:function(e){if((this.searchfield!=null)||(this.searchfield!=undefined)){this.searchfield.focus();}
OpenLayers.Event.stop(e);},draw:function(){OpenLayers.Control.prototype.draw.apply(this,arguments);if(!this.element){this.div.className=this.displayClass;this.element=document.createElement("div");this.div.appendChild(this.element);this.searchfield=document.createElement("input");this.searchfield.type="text";this.searchfield.name="query";this.searchfield.id="searchfield_dummy";this.searchfield.className="MMMSearch";this.searchfield.zIndex="10000";this.searchfield.style.visibility='hidden';this.element.appendChild(this.searchfield);this.imgbutton=document.createElement("img");this.imgbutton.src=this.searchImg;this.imgbutton.style.cursor='Pointer';this.imgbutton.title='search';this.element.appendChild(this.imgbutton);var br=document.createElement("br");this.element.appendChild(br);this.map_extent_cb=document.createElement("input");this.map_extent_cb.type="checkbox";this.map_extent_cb.style.verticalAlign="middle";this.element.appendChild(this.map_extent_cb);var cbLabel=document.createElement("label");cbLabel.innerHTML="search map extent only";cbLabel.style.fontSize="12px";cbLabel.style.color='white';this.element.appendChild(cbLabel);var context={'searchfield':$('search_control_search_field'),'map_extent_cb':this.map_extent_cb,'map':this.map};OpenLayers.Event.observe(this.imgbutton,"click",OpenLayers.Function.bindAsEventListener(this.performSearch2,context));OpenLayers.Event.observe($('search_control_search_field'),"keypress",OpenLayers.Function.bindAsEventListener(this.keypressSearch2,context));}
return this.div;},CLASS_NAME:"OpenLayers.Control.MMSearch"});OpenLayers.Control.MMPanZoomPanel=OpenLayers.Class(OpenLayers.Control.PanZoomBar,{zoomWorldIcon:true,allowSelection:true,initialize:function(){OpenLayers.Control.PanZoomBar.prototype.initialize.apply(this,arguments);},destroy:function(){OpenLayers.Control.PanZoomBar.prototype.destroy.apply(this,arguments);},CLASS_NAME:"OpenLayers.Control.MMPanZoomPanel"});OpenLayers.Layer.MM=OpenLayers.Class(OpenLayers.Layer.TMS,{baseurl:"http://79.125.34.108/",origUrl:null,layer_id:null,contentExtent:null,displayOutsideMaxExtent:false,trackLayer:false,displayInLayerSwitcher:false,EVENT_TYPES:["loadstart","loadend","loadcancel","visibilitychanged","move","moveend","trackingchanged"],initialize:function(name,layer_id,options){var newArguments=[];this.layer_id=layer_id;if((options==undefined)||(options==null)){options=new Object();}
else{if(options.contentExtentStr!=undefined){this.contentExtent=new OpenLayers.Bounds.fromString(options.contentExtentStr.replace(/ /g,","));}
if(options.contentExtent!=undefined){this.contentExtent=options.contentExtent;}
if(options.origUrl!=undefined){this.origUrl=options.origUrl;}}
options.layername=layer_id;options.type="png";options.isBaseLayer=false;options.sphericalMercator=true;newArguments.push(name,this.baseurl,options);OpenLayers.Layer.TMS.prototype.initialize.apply(this,newArguments);},destroy:function(){OpenLayers.Layer.TMS.prototype.destroy.apply(this,arguments);},clone:function(obj){if(obj==null){obj=new OpenLayers.Layer.MM(this.name,this.layer_id,this.options);}
obj=OpenLayers.Layer.TMS.prototype.clone.apply(this,[obj]);return obj;},setTracking:function(tracking){if(tracking!=this.tracking){this.tracking=tracking;this.events.triggerEvent("trackingchanged");}},zoomToXYZ:function(x,y,z){var resolution=this.map.getResolutionForZoom(z);var right=this.tileOrigin.lon+(resolution*this.tileSize.w*(x+1))
var top=this.tileOrigin.lat+(resolution*this.tileSize.h*(y+1));var left=right-(resolution*this.tileSize.w);var bottom=top-(resolution*this.tileSize.h);var bounds=new OpenLayers.Bounds(left,bottom,right,top);this.map.zoomToExtent(bounds);},CLASS_NAME:"OpenLayers.Layer.MM"});if(typeof(window.Geops)=='undefined')
Geops=new Object();Geops.BaseMap=OpenLayers.Class(OpenLayers.Map,{legend_panel:null,pan_zoom_panel:null,tilesLayer:null,userLayers:null,visibleLayers:null,initialize:function(div,options,legend_panel)
{this.visibleLayers=new Array();this.layers=new Array();this.userLayers=new Array();this.legend_panel=legend_panel;if(options==null){options={};}
options.projection=new OpenLayers.Projection("EPSG:900913");options.displayProjection=new OpenLayers.Projection("WGS84");options.units="m";options.numZoomLevels=18;options.maxResolution=156543.0339;options.maxExtent=new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34);options.controls=[];OpenLayers.Map.prototype.initialize.apply(this,[div,options]);this.addPanZoomPanel();this.addControl(new OpenLayers.Control.Navigation());this.addControl(new OpenLayers.Control.MousePosition());this.addControl(new OpenLayers.Control.KeyboardDefaults());var gphy=new OpenLayers.Layer.Google("Physical",{type:G_PHYSICAL_MAP,"sphericalMercator":true,isBaseLayer:true});var gmap=new OpenLayers.Layer.Google("Streets",{numZoomLevels:20,"sphericalMercator":true,isBaseLayer:true});var gsat=new OpenLayers.Layer.Google("Satellite",{type:G_SATELLITE_MAP,numZoomLevels:20,"sphericalMercator":true,isBaseLayer:true});var layer_style=new OpenLayers.StyleMap({'default':{fill:false,strokeOpacity:0.3,strokeColor:"${favColor}",label:"${timestr}",strokeWidth:2,fontColor:"${favColor}",fontSize:"18px",fontFamily:"Arial, Courier New, monospace",fontWeight:"bold"}});this.tilesLayer=new OpenLayers.Layer.Vector("Tiles",{styleMap:layer_style,displayInLayerSwitcher:false});this.boxesLayer=new OpenLayers.Layer.Boxes("boxes");this.addLayers([gmap,gphy,gsat,this.boxesLayer,this.tilesLayer]);this.zoomToExtent(new OpenLayers.Bounds(-14000000,-4000000,14000000,5000000));if(this.legend_panel){};},addPanZoomPanel:function()
{this.pan_zoom_panel=new OpenLayers.Control.MMPanZoomPanel();this.addControl(this.pan_zoom_panel);},removePanZoomPanel:function()
{this.removeControl(this.pan_zoom_panel);},addMMLayer:function(name,layer_id,options)
{var tms=new OpenLayers.Layer.MM(name,layer_id,options);this.userLayers.push(tms);if(options!=undefined){if((options.no_load==null)||(options.no_load==undefined)){}}
else{}
this.addLayer(tms);this.removeLayer(this.tilesLayer);this.addLayer(this.tilesLayer);tms.events.register("visibilitychanged",tms,this.showBox);tms.events.triggerEvent("visibilitychanged",this.showBox);if(tms.origUrl!=null){var ctrls=this.getControlsByClass('OpenLayers.Control.WMSGetFeatureInfo');if(ctrls.length>0){var info=ctrls[0];info.url=tms.origUrl;info.activate();}}
return tms;},removeMMLayer:function(layer_id)
{for(var i=0;i<this.userLayers.length;i++)
{if(this.userLayers[i].layer_id==layer_id)
{this.userLayers.splice(i,1);}}
SessionMgmnt.removeLayer(layer_id);var layers=this.getLayersBy('layer_id',layer_id);for(var i=0;i<layers.length;i++){this.visibleLayers.without(layers[i]);this.removeLayer(layers[i]);}
for(i=0;i<this.boxesLayer.markers.length;i++){if(this.boxesLayer.markers[i].layer_id==layer_id){this.boxesLayer.removeMarker(this.boxesLayer.markers[i]);break;}}},showMaxTwo:function(evt){var changed=false;if((evt.layer!=undefined)&&(evt.layer.layer_id!=undefined)&&(evt.layer.CLASS_NAME=="OpenLayers.Layer.MM")&&((evt.type="addlayer")||(evt.property=="visibility"&&evt.layer[evt.property]))){while(this.visibleLayers.length>1){this.visibleLayers.shift();}
this.visibleLayers.push(evt.layer.layer_id);this.layers.each(function(l){if((l.layer_id)&&(l.CLASS_NAME=="OpenLayers.Layer.MM")&&(l.visibility)&&(l.map.visibleLayers.indexOf(l.layer_id)==-1)){l.visibility=false;changed=true;if($('checkbox_legend_user_layer_'+l.layer_id)){$('checkbox_legend_user_layer_'+l.layer_id).checked=l.visibility;}}});}
if(changed){evt.layer.redraw();evt.layer.events.triggerEvent("visibilitychanged");}},showBox:function(remove){if((!this.getVisibility())||(remove==true)){for(i=0;i<this.map.boxesLayer.markers.length;i++){if(this.map.boxesLayer.markers[i].layer_id==this.layer_id){this.map.boxesLayer.removeMarker(this.map.boxesLayer.markers[i]);break;}}}else{this.map.removeLayer(this.map.boxesLayer);this.map.addLayer(this.map.boxesLayer);if(this.contentExtent!=null){var contentExtent=this.contentExtent;var fullExtent=new OpenLayers.Bounds(-180,-90,180,90);fullExtent=fullExtent.transform(new OpenLayers.Projection("WGS84"),this.map.getProjectionObject());if(!contentExtent.containsBounds(fullExtent)){var box=new OpenLayers.Marker.Box(contentExtent);box.layer_id=this.layer_id;this.map.boxesLayer.addMarker(box);}}}},zoomToMMLayer:function(layer_id){var layers=this.getLayersBy('layer_id',layer_id);for(var i=0;i<layers.length;i++)
{if(layers[i].contentExtent==null){this.zoomToMaxExtent();}
else{this.zoomToExtent(layers[i].contentExtent);}}},setTrackLayer:function(layer){if(!layer){for(var i=this.layers.length-1;i>=0;i--){if(this.layers[i].trackLayer&&this.layers[i].visible){layer=this.layers[i];break;}}}
if(!layer)return;for(var i=this.layers.length-1;i>=0;i--){if(this.layers[i].trackLayer&&this.layers[i]!=layer){this.removeTrackEvents(this.layers[i]);}
if(this.layers[i]==layer){this.registerTrackEvents(layer);}}},removeTrackEvents:function(layer){layer.events.un({"loadstart":layer.loadstart});for(var iRow=0,len=layer.grid.length;iRow<len;iRow++){var row=layer.grid[iRow];for(var iCol=0,clen=row.length;iCol<clen;iCol++){tile=row[iCol];tile.unload();tile.events.un({"loadend":layer.onTileLoadEnd,"loadstart":layer.onTileLoadStart,scope:this});}}},registerTrackEvents:function(layer){layer.date2Layer=function(){this.loadstart=new Date();}
layer.events.register("loadstart",layer,layer.date2Layer);layer.cleantiles=function(){var xyz=new Array();var bounds=this.getTilesBounds();for(var i=this.map.tilesLayer.features.length-1;i>=0;i--){if(!bounds.containsBounds(this.map.tilesLayer.features[i].geometry.getBounds(),true,false)){this.map.tilesLayer.destroyFeatures(this.map.tilesLayer.features[i]);}else{xyz.push(new Array(this.map.tilesLayer.features[i].attributes.x*1,this.map.tilesLayer.features[i].attributes.y*1,this.map.tilesLayer.features[i].attributes.z*1));}}
tileTime(layer.layer_id,xyz);}
layer.events.register("loadend",layer,layer.cleantiles);var urlToXyz=function(url){var xyz=new Array();var urlarray=url.split('/');var z=urlarray[5];var x=urlarray[6];var y=urlarray[7].split('.')[0];xyz.push(x*1,y*1,z*1);return xyz;}
var drawTileFeature=function(tile,loadstart){if(tile.feature){layer.map.tilesLayer.destroyFeatures([tile.feature]);tile.feature=null;}
var xyz=null;if(tile.url){urlToXyz(tile.url);tile.feature=new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygon([new OpenLayers.Geometry.LinearRing([new OpenLayers.Geometry.Point(tile.bounds.left,tile.bounds.bottom),new OpenLayers.Geometry.Point(tile.bounds.right,tile.bounds.bottom),new OpenLayers.Geometry.Point(tile.bounds.right,tile.bounds.top),new OpenLayers.Geometry.Point(tile.bounds.left,tile.bounds.top)])]),{'layer_id':layer.layer_id,'x':xyz[0],'y':xyz[1],'z':xyz[2]});if(loadstart){tile.feature.attributes.time='loading...';tile.feature.attributes.timestr=tile.feature.attributes.time;tile.feature.attributes.favColor="#ee9900";}else{if(tile.imgDiv._attempts>OpenLayers.IMAGE_RELOAD_ATTEMPTS){tile.feature.attributes.time='Error';tile.feature.attributes.timestr=tile.feature.attributes.time;tile.feature.attributes.favColor="#990000";}else{tile.feature.attributes.time=layer.map.getTimeStamp(tile.loadstart,new Date());tile.feature.attributes.timestr=tile.feature.attributes.time;tile.feature.attributes.favColor="#009900";}}
layer.map.tilesLayer.addFeatures([tile.feature]);}}
var tileTime=function(layer_id,xyz){new Ajax.Request(CONST.ROOT_DIR+'layer/tiletime',{parameters:{'layer_id':layer_id,'xyz':xyz.toJSON()},method:'post',asynchronous:false,evalScripts:false,onComplete:function(request){if(request.responseJSON){var features=layer.map.tilesLayer.features;for(var i=0,len=features.length;i<len;i++){request.responseJSON.tiletimes.each(function(tiletime){if(((tiletime.layer_id==features[i].attributes.layer_id)&&(tiletime.t_x==features[i].attributes.x)&&(tiletime.t_y==features[i].attributes.y)&&(tiletime.t_z==features[i].attributes.z))){features[i].attributes.timestr=tiletime.time_download+'/'+features[i].attributes.time;layer.map.tilesLayer.drawFeature(features[i]);}})}}}});}
layer.onTileLoadStart=function(){this.tiletime=null;this.loadstart=new Date();drawTileFeature(this,true);;};for(var iRow=0,len=layer.grid.length;iRow<len;iRow++){var row=layer.grid[iRow];for(var iCol=0,clen=row.length;iCol<clen;iCol++){tile=row[iCol];tile.loadstart=new Date();tile.events.register("loadstart",tile,layer.onTileLoadStart);}}
layer.onTileLoadEnd=function(){drawTileFeature(this,false);var ntiles=this.layer.grid.length;ntiles=ntiles*this.layer.grid[0].length;if((this.layer.numLoadingTiles!=ntiles)&&(this.layer.numLoadingTiles%10)==0){var xyz=new Array();for(var iRow=0,len=this.layer.grid.length;iRow<len;iRow++){var row=this.layer.grid[iRow];for(var iCol=0,clen=row.length;iCol<clen;iCol++){tile=row[iCol];if(!tile.isLoading&&tile.url!=null){xyz.push(urlToXyz(tile.url));}}}
tileTime(this.layer.layer_id,xyz);}};for(var iRow=0,len=layer.grid.length;iRow<len;iRow++){var row=layer.grid[iRow];for(var iCol=0,clen=row.length;iCol<clen;iCol++){tile=row[iCol];tile.events.register("loadend",tile,layer.onTileLoadEnd);}}},pad:function(n){var padded=''+n;while(padded.length<2){padded='0'+padded;}
return padded;},getTimeStamp:function(start,end){var duration=end-start;var date=new Date(duration);var timeParts=[date.getSeconds(),this.pad(Math.round(date.getMilliseconds()/10))];var timeStamp=timeParts.join(".")+" sec";return timeStamp;},updateLegendPanelOverlays:function()
{},initLegendPanel:function()
{},changeBaseLayer:function(layerId,evt)
{var layer=this.getLayer(layerId);this.setBaseLayer(layer);evt.target.checked=true;},showOverlay:function(layerId,evt)
{var layer=this.getLayer(layerId);if(evt.target.checked)
{layer.display(true);}
else
{layer.display(false);}}});if(typeof(window.Geops)=='undefined')
Geops=new Object();Geops.Map=OpenLayers.Class(Geops.BaseMap,{initialize:function(div,options,legend_panel)
{Geops.BaseMap.prototype.initialize.apply(this,[div,options,legend_panel]);},initLegendPanel:function(withoutUserLayers)
{$('legend_base_layers').innerHTML='';$('legend_user_layers').innerHTML='';var baseLayers=new Array();var userLayers=new Array();for(var i=0;i<this.layers.length;i++)
{if(this.layers[i].isBaseLayer){baseLayers.push(this.layers[i]);}else{userLayers.push(this.layers[i]);}}
var radioGroup=new Geops.RadioGroup();var liEl=null;for(i=0;i<baseLayers.length;i++)
{liEl=document.createElement('li');liEl.innerHTML=baseLayers[i].name;liEl.id='legend_base_layer_'+i;$('legend_base_layers').appendChild(liEl);if(this.baseLayer.name==baseLayers[i].name){$(liEl.id).addClassName('selected');}
var fnSwitch=this.setBaseLayer.bind(this,baseLayers[i]);var btn=new Geops.RadioButton('legend_base_layer_'+i,fnSwitch);radioGroup.addButton(btn);}
if(!withoutUserLayers)
{for(i=0;i<userLayers.length;i++)
{liEl=document.createElement('li');liEl.id='legend_item_'+userLayers[i].layer_id;liEl.innerHTML='<input type="checkbox" id="checkbox_legend_user_layer_'+userLayers[i].layer_id+'" />';if(userLayers[i].layer_id)
{liEl.innerHTML+='<a id="legend_show_popup_'+userLayers[i].layer_id+'" href="'+CONST.ROOT_DIR+'wms/'+userLayers[i].layer_id+'" onclick="">'+userLayers[i].name+'</a>';}
else
{liEl.innerHTML+=userLayers[i].name;}
if(userLayers[i].layer_id)
{$('legend_user_layers').appendChild(liEl);var iconsList=document.createElement('ul');iconsList.style.display="none";iconsList.id='legend_icons_'+userLayers[i].layer_id;iconsList=liEl.appendChild(iconsList);$('legend_icons_'+userLayers[i].layer_id).addClassName('icons');var iconsListItem=document.createElement('li');iconsListItem.id='legend_user_layer_zoom_'+userLayers[i].layer_id;iconsListItem.title='zoom to extent';iconsListItem.innerHTML='<a href="#">zoom</a>';iconsList.appendChild(iconsListItem);$('legend_user_layer_zoom_'+userLayers[i].layer_id).addClassName('zoom-layer');var iconsListItem=document.createElement('li');iconsListItem.id='legend_user_layer_remove_'+userLayers[i].layer_id;iconsListItem.title='remove from map';iconsListItem.innerHTML='<a href="#">remove</a>';iconsList.appendChild(iconsListItem);$('legend_user_layer_remove_'+userLayers[i].layer_id).addClassName('remove');$('checkbox_legend_user_layer_'+userLayers[i].layer_id).checked=userLayers[i].getVisibility();var layer=userLayers[i];var cb=$('checkbox_legend_user_layer_'+userLayers[i].layer_id);var fnShowLayer=this.clickVisibilityCheckbox.bindAsEventListener(this,layer,cb);$('checkbox_legend_user_layer_'+userLayers[i].layer_id).observe('click',fnShowLayer);var layer_id=userLayers[i].layer_id;var fnRemove=this.removeLayerAndUpdate.bind(this,layer_id);$('legend_user_layer_remove_'+userLayers[i].layer_id).observe('click',fnRemove);var fnZoom=this.zoomToExtent.bind(this,userLayers[i].contentExtent);$('legend_user_layer_zoom_'+userLayers[i].layer_id).observe('click',fnZoom);var fnShowLegendIcons=this.showLegendIcons.bind(this,userLayers[i].layer_id,true);$('legend_item_'+userLayers[i].layer_id).observe('mouseover',fnShowLegendIcons);var fnHideLegendIcons=this.showLegendIcons.bind(this,userLayers[i].layer_id,false);$('legend_item_'+userLayers[i].layer_id).observe('mouseout',fnHideLegendIcons);}}}},clickVisibilityCheckbox:function(evt,layer,cb)
{layer.setVisibility(cb.checked);},removeLayerAndUpdate:function(layer_id)
{this.removeMMLayer(layer_id);this.initLegendPanel();},showLegendIcons:function(layer_id,show)
{if(show)
$('legend_icons_'+layer_id).show();else
$('legend_icons_'+layer_id).hide();}});Geops.Map.CLASS_NAME="Geops.Map";GRAPH=new Object();GRAPH.posX=0;GRAPH.posY=0;GRAPH.getMouseXY=function(e){if(!e){var e=window.event;};GRAPH.posX=Event.pointerX(e);GRAPH.posY=Event.pointerY(e);};GRAPH.showStats=function(avg,min,max,nt,avail,navail,tick){var responseHtml,availHtml;if(nt>0){responseHtml='<b>'+avg+'</b> ('+min+' - '+max+') <span class="sub">n = '+nt+'</span>';}else{responseHtml="no data";}
if(navail>0){availHtml='<b>'+avail+' % </b><span class="sub">n = '+navail+'</span>';}else{availHtml="no data";}
$('show_stats').innerHTML="<b>Statistics for "+tick+"</b><h4>Response Time</h4> "+responseHtml+" <h4>Availability</h4> "+availHtml;$('show_stats').style.left=GRAPH.posX+10+"px";$('show_stats').style.top=GRAPH.posY+10+"px";$('show_stats').show();};GRAPH.hideStats=function(){$('show_stats').hide();};TempVars=new Object();TempVars.statTabs=null;TempVars.currentStatTab=null;if(typeof(window.Geops)=='undefined')
Geops=new Object();Geops.HoverIcons=Class.create({hoverEl:null,iconsEl:null,initialize:function(hoverElId,iconsElId)
{if($(hoverElId))
this.hoverEl=$(hoverElId);if($(iconsElId))
this.iconsEl=$(iconsElId);var fnShowIcons=this.showIcons.bind(this,true);this.hoverEl.observe('mouseover',fnShowIcons)
var fnHideIcons=this.showIcons.bind(this,false);this.hoverEl.observe('mouseout',fnHideIcons)},showIcons:function(show)
{if(show)
{this.iconsEl.show();}
else
{this.iconsEl.hide();}}});