//---------------------------------------------------------------
// dbgtCode.js
// Copyright (C) 2002 David Bollinger (davebollinger@hotmail.com)
//
// version 1.0 05/16/2002

// version 1.1 changes:  (only released as a patch)
//   added simple rescrolling after a refresh
//
// version 1.2 11/26/2002 changes:
//   additional testing with ArcIMS 4.0
//   objecwrite* methods no longer write directly to
//     a document, instead simply return an html string,
//     method names changed (postfixed with "HTML")
//   output is inteded to go to DIV's, thus fixing the
//     flicker and scrolling problems in previous version
//   toc.setOutput() method added
//   .divToc and divTocHelp added to TOC object
//   toc.refresh() method rewritten
//   easier to set optional help, simply do (or do not) supply
//     a DIV for the help when calling toc.setOutput()
//   (above changes also improve support for toc in a popup window)
//   layer info button removed, now a hyperlink around layer name
//   .iconInfo removed from RESOURCE object
//   added a sample legend image for sf demo
//   added comments inside writeHTML() methods to aid customizers
//   added these comments regarding table structure to aid customizers:
//
//     the toc table is 5 columns wide as so:
//
//     group rows:
//       | fldr | visi | groupname               |
//     layer rows:
//       | bars | visi | actv | swch | layername |
//     legend rows:
//       | emty | emty | emty | legend           |
//
//
// Support code for the "dbGroupToc" modification - A grouped
// table of contents for ArcIMS 3.1+ HTML viewer sites.
//
// Notice:   This code may be freely distributed, used and
//           modified provided that this comment remains intac
//---------------------------------------------------------------

var old_oname=""; //siehe GROUP_writeHTML() 
var old_o1name=""; //siehe GROUP_writeHTML() 
var old_o2name=""; //siehe GROUP_writeHTML() 
var old_o3name=""; //siehe GROUP_writeHTML() 
var old_o4name=""; //siehe GROUP_writeHTML() 

//-----------------
// RESOURCE
//-----------------

function RESOURCE(name) {
  this.name = name;
}


//-----------------
// TOC
//-----------------

function TOC(name) {
  this.name = name;
  this.groups = new Array();
  this.isInited = false;
  this.divToc = null;
  this.divTocHelp = null;
  this.setOutput = TOC_setOutput;
  this.init = TOC_init;
  this.refresh = TOC_refresh;
  this.writeHTML = TOC_writeHTML;
  this.writeHelpHTML = TOC_writeHelpHTML;
  this.addGroup = TOC_addGroup;
  this.groupToggleOpened = TOC_groupToggleOpened;
  this.ogroupToggleOpened = TOC_ogroupToggleOpened;
  this.o2groupToggleOpened = TOC_o2groupToggleOpened;
  this.o3groupToggleOpened = TOC_o3groupToggleOpened;
  this.o4groupToggleOpened = TOC_o4groupToggleOpened;
  this.groupSetVisible = TOC_groupSetVisible;
  this.layerToggleVisible = TOC_layerToggleVisible;
  this.layerSetActive = TOC_layerSetActive;
}

function TOC_setOutput( Toc, TocHelp ) {
  this.Toc = Toc;
//  this.divTocHelp = divTocHelp;
}

function TOC_init() {
  for (var g=0; g<this.groups.length; g++) {
    for (var l=0; l<this.groups[g].layers.length; l++) {
      var lyr = this.groups[g].layers[l];
	  var o4=this.groups[g].o4name;
	  var o3=this.groups[g].o3name;
	  var o2=this.groups[g].o2name;
	  var o1=this.groups[g].o1name;
	  var o=this.groups[g].name;
	  if (lyr.index < 0) {
	    lyr.index = getLayerIndexByName(lyr.name);
      }
    }
  }
  this.isInited = true;
  
}

function TOC_refresh() {
	old_o1name="";
	old_o2name="";
	old_o3name="";
	old_o4name="";
	if (this.name=="TABOFCONT"){
		dbgtResource.t = "toc.";               
	}
	if (this.name=="TABOFCONTABC"){
		dbgtResource.t = "tocabc.";               
	}
	if (this.name=="TABOFCONTTHEMEN"){
		dbgtResource.t = "tocthemen.";               
	}
	
	if (this.Toc != null){
		this.Toc.innerHTML = this.writeHTML();
	}
}


function TOC_writeHTML() {
  var s = "";
  if (!this.isInited)
    this.init();

	//-------------------
	// START OF TOC TABLE
	//-------------------
	s+="";
	s+="<table id=\"toctab\" style=\"width:113%\"><tr ><td style=\"padding-left:5px;background-color:black;color:white;font-size:11;font-weight:bold;\">Kartenebenen</td></tr><tr><td class='table.tbltoctd'>";
	if (blnEbeneOrdner){
		s+="<a id=\"tocordner\" tabindex=\"15\" href=\"javascript:toggle_toc(0)\"";
		if (intTOC==0){
			s+=" style=\"border:thin solid gray\" "
		}
		s+="onmouseover=\"setToolTip(\'Layerliste nach Orga-Einheiten sortieren\')\" onmouseout=\"setToolTip()\">&nbsp;Ordner&nbsp;</a>"
	}
	if (blnEbeneThemen){
		s+="<a id=\"tocthemen\" tabindex=\"16\" href=\"javascript:toggle_toc(2)\"";
		if (intTOC==2){
			s+=" style=\"border:thin solid gray\" "
		}
		s+="onmouseover=\"setToolTip(\'Layerliste nach Themen sortieren\')\" onmouseout=\"setToolTip()\">&nbsp;Themen&nbsp;</a>";
	}
	if (blnEbeneAbc){
		s+="<a id=\"tocabc\" tabindex=\"17\" href=\"javascript:toggle_toc(1)\"";
		if (intTOC==1){
			s+=" style=\"border:thin solid gray\" "
		}
		s+="onmouseover=\"setToolTip(\'Layerliste aphabetisch sortieren\')\" onmouseout=\"setToolTip()\">&nbsp;ABC&nbsp;</a>";
	}
	s+="</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>";
	s += "<TABLE style=\"left:3\" WIDTH='100%' BORDER='0' CELLSPACING='2' CELLPADDING='1' NOWRAP>";
	   

  //------------------
  // CASCADE TO GROUPS
  //------------------
  //JR
  //s+=writewms();
  
	var level = 0;
	var x="";
	for (var c=0; c<this.groups.length; c++) {
		s+=this.groups[c].writeHTML(level+1,(c==this.groups.length-1));
	}
	//-----------------
	// END OF TOC TABLE
	//-----------------
	/*
	s+="<table class='table.tbltoc'>";
	s+="<tr><td style='font-size=10;font-weight=normal;color:#FF0000'><input type='Button' id='Standardeinstellung' onclick='LayerVisible=LayerVisibleOriginal.split(\",\");getAllMaps();' value='Standardeinstellung'></input></td></tr>";
	s+="<tr><td>&nbsp;</td></tr>";
	*/
	s+="</table>";
	s+="<br><br><br>"
	return s;
}

function TOC_writeHelpHTML() {
	var s = "";
	//s += "<BR><BR><DIV  CLASS='LayerListHelp' ALIGN='left' NOWRAP><BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconClosed + "'> An closed group, click to open.<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconOpened + "'> An open group, click to close.<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconChildLast + "'> Layer gehoert zu einer Gruppe<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconOrphan + "'> Layer gehoert nicht zu einer Gruppe<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconHidden + "'> Layer/Gruppe ausgeschaltet<BR>&#160;&#160;&#160;&#160;&#160;&#160;(zum Anschalten anklicken)<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisible + "'> Layer/Gruppe angeschaltet<BR>&#160;&#160;&#160;&#160;&#160;&#160;(zum Ausschalten anklicken)<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisscale + "'> Layer ist beim aktuellen<br>&#160;&#160;&#160;&#160;&#160;&#160;Massstab nicht sichtbar<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconTristate + "'> Layergruppe ist teilweise sichtbar<br>&#160;&#160;&#160;&#160;&#160;&#160;(anklicken, um alle an-/auszuschalten)<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconInactive + "'> An inactive layer, click to make active.<BR>";
	//s += "<IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconActive + "'> The active layer.<BR>";
	//s += "</DIV></CENTER>";
	return s;
}

function TOC_addGroup(group) {
	group.parent = this;
	group.index = this.groups.length;
	this.groups[group.index] = group;
	return group;
}

function TOC_o4groupToggleOpened(index) {
	this.groups[index].o4opened = !this.groups[index].o4opened;
	for (var l=0; l<this.groups.length; l++){
		if (this.groups[l].o4name==this.groups[index].o4name){
			this.groups[l].o4opened = this.groups[index].o4opened;
			this.groups[l].o3opened = false;
			this.groups[l].o2opened = false;
			this.groups[l].o1opened = false;
			this.groups[l].opened = false;
		}
	}
	this.refresh();
}

function TOC_o3groupToggleOpened(index) {
	this.groups[index].o3opened = !this.groups[index].o3opened;
	for (var l=0; l<this.groups.length; l++){
		if (this.groups[l].o3name==this.groups[index].o3name){
			this.groups[l].o3opened = this.groups[index].o3opened;
			this.groups[l].o2opened = false;
			this.groups[l].o1opened = false;
			this.groups[l].opened = false;
		}
	}
	this.refresh();
}
function TOC_o2groupToggleOpened(index) {
	this.groups[index].o2opened = !this.groups[index].o2opened;
	for (var l=0; l<this.groups.length; l++){
		if ((this.groups[l].o3name==this.groups[index].o3name) && (this.groups[l].o2name==this.groups[index].o2name)){
			this.groups[l].o2opened = this.groups[index].o2opened;
			this.groups[l].o1opened = false;
			this.groups[l].opened = false;
		}
	}
	this.refresh();
}
function TOC_ogroupToggleOpened(index) {
	this.groups[index].o1opened = !this.groups[index].o1opened;
	for (var l=0; l<this.groups.length; l++){
		if ((this.groups[l].o3name==this.groups[index].o3name) && (this.groups[l].o2name==this.groups[index].o2name) && (this.groups[l].o1name==this.groups[index].o1name)){
			this.groups[l].o1opened = this.groups[index].o1opened;
			this.groups[l].opened = false;
		}
	}
	this.refresh();
}
function TOC_groupToggleOpened(index) {
	this.groups[index].opened = !this.groups[index].opened;
	this.refresh();
}

function TOC_groupSetVisible(index,value) {
	for (var l=0; l<this.groups[index].layers.length; l++){
		LayerVisible[this.groups[index].layers[l].index] = value;
		intActiveMapservice=LayerMS[this.groups[index].layers[l].index];
		if (LayerGruppe[this.groups[index].layers[l].index]!=''){
			for (var k=0;k<LayerID.length;k++) {
				if (LayerGruppe[k]==LayerGruppe[this.groups[index].layers[l].index]) {
					LayerVisible[k]=LayerVisible[this.groups[index].layers[l].index];
					if (value==1){
						setBgMap(this.groups[index].layers[l].index);
					}
					if (lngMapMassstab<LayerMinScale[k] || lngMapMassstab>LayerMaxScale[k]){
						if (value==1){
							LayerVisible[k] = 2;
						}
					}

				}
			}
		}
	}
	if (blnAutoRefresh){
		refreshTOC();
		getAllMaps(true);
	}
}

function TOC_layerToggleVisible(index) {
	LayerVisible[index] = 1-LayerVisible[index];
	if (LayerSelAttr[index]){
		LayerSelAttr[index]=""
	}
	if (LayerVisible[index]<0){
		LayerVisible[index]=0;
	}
	var idx=index;
	if (LayerGruppe[index]!=""){
		var l=0;
		for (var k=0;k<LayerID.length;k++) {
			if (LayerGruppe[k]==LayerGruppe[index]) {
				LayerVisible[k]=LayerVisible[index];
				if ((lngMapMassstab<LayerMinScale[k] || lngMapMassstab>LayerMaxScale[k])&&LayerVisible[index]==1){
					LayerVisible[k] = 2;
				}
			}
		}
	}
	if (LayerVisible[index]==1||LayerVisible[index]==2){
		setBgMap(index);
	}
	
	if (blnAutoRefresh){
		getAllMaps(true);
	}
	if ((index==rgs_layerid_wmslgndop||index==rgs_layerid_dop ||index==rgs_layerid_dop2007 || index==rgs_layerid_wmslgndop||index==rgs_layerid_dophh) && rgs_layerid_f001_f!=-1){
		// umschalten der flurkarte gelb/schwarz
		//if (LayerVisible[rgs_layerid_f001_f]==1){
			var x=intActiveMapservice;
			intActiveMapservice=LayerMS[rgs_layerid_f001_f];
			writeProtokoll("Luftbild wurde eingeschaltet, ALK auf gelb setzen\n");
			getAllMaps(false,intActiveMapservice);
			intActiveMapservice=x;
		//}
	}
}
function setBgMap(index){
	if (rgs_layerid_wmslgngrauak5 > -1){
		if (index==rgs_layerid_wmslgngrauak5){
			if (LayerVisible[rgs_layerid_wmslgnfarbeak5]>0){
				setLayerInvisible(rgs_layerid_wmslgnfarbeak5);
			}
			if (rgs_layerid_wmslgndop>-1&&LayerVisible[rgs_layerid_wmslgndop]==1){
				setLayerInvisible(rgs_layerid_wmslgndop);
			}
			if (rgs_layerid_dop>-1&&LayerVisible[rgs_layerid_dop]==1){
				setLayerInvisible(rgs_layerid_dop);
			}
			if (rgs_layerid_dop2007>-1&&LayerVisible[rgs_layerid_dop2007]==1){
				setLayerInvisible(rgs_layerid_dop2007);
			}
			if (rgs_layerid_dop2007ir>-1&&LayerVisible[rgs_layerid_dop2007ir]==1){
				setLayerInvisible(rgs_layerid_dop2007ir);
			}
		}
	}
	if (rgs_layerid_wmslgnfarbeak5 > -1){
		if (index==rgs_layerid_wmslgnfarbeak5){
			if (LayerVisible[rgs_layerid_wmslgngrauak5]>0){
				setLayerInvisible(rgs_layerid_wmslgngrauak5);
			}
			if (rgs_layerid_wmslgndop>-1&&LayerVisible[rgs_layerid_wmslgndop]==1){
				setLayerInvisible(rgs_layerid_wmslgndop);
			}
			if (rgs_layerid_dop>-1&&LayerVisible[rgs_layerid_dop]==1){
				setLayerInvisible(rgs_layerid_dop);
			}
			if (rgs_layerid_dop2007>-1&&LayerVisible[rgs_layerid_dop2007]==1){
				setLayerInvisible(rgs_layerid_dop2007);
			}
			if (rgs_layerid_dop2007ir>-1&&LayerVisible[rgs_layerid_dop2007ir]==1){
				setLayerInvisible(rgs_layerid_dop2007ir);
			}
		}
	}
	if (rgs_layerid_wmslgngrau > -1){
		if (index==rgs_layerid_wmslgngrau){
			if (LayerVisible[rgs_layerid_wmslgnfarbe]>0){
				setLayerInvisible(rgs_layerid_wmslgnfarbe);
			}
			if (LayerVisible[rgs_layerid_wmslgndop]>0){
				setLayerInvisible(rgs_layerid_wmslgndop);
			}
			if (rgs_layerid_dop>-1&&LayerVisible[rgs_layerid_dop]>0){
				setLayerInvisible(rgs_layerid_dop);
			}
			if (rgs_layerid_dop2007>-1&&LayerVisible[rgs_layerid_dop2007]>0){
				setLayerInvisible(rgs_layerid_dop2007);
			}
			if (rgs_layerid_dop2007ir>-1&&LayerVisible[rgs_layerid_dop2007ir]>0){
				setLayerInvisible(rgs_layerid_dop2007ir);
			}
			if (rgs_layerid_metropolregion>-1&&LayerVisible[rgs_layerid_metropolregion]>0){
				setLayerInvisible(rgs_layerid_metropolregion);
			}
		}
	}
	if (rgs_layerid_wmslgnfarbe > -1){
		if (index==rgs_layerid_wmslgnfarbe){
			if (rgs_layerid_wmslgngrau>-1&&LayerVisible[rgs_layerid_wmslgngrau]>0){
				setLayerInvisible(rgs_layerid_wmslgngrau);
			}
			if (rgs_layerid_wmslgndop>-1&&LayerVisible[rgs_layerid_wmslgndop]>0){
				setLayerInvisible(rgs_layerid_wmslgndop);
			}
			if (rgs_layerid_dop>-1&&LayerVisible[rgs_layerid_dop]>0){
				setLayerInvisible(rgs_layerid_dop);
			}
			if (rgs_layerid_dop2007>-1&&LayerVisible[rgs_layerid_dop2007]>0){
				setLayerInvisible(rgs_layerid_dop2007);
			}
			if (rgs_layerid_dop2007ir>-1&&LayerVisible[rgs_layerid_dop2007ir]>0){
				setLayerInvisible(rgs_layerid_dop2007ir);
			}
			if (rgs_layerid_metropolregion>-1&&LayerVisible[rgs_layerid_metropolregion]>0){
				setLayerInvisible(rgs_layerid_metropolregion);
			}
		}
	}
	if (rgs_layerid_wmslgndop > -1){
		if (index==rgs_layerid_wmslgndop){
			if (rgs_layerid_wmslgngrau>-1&&LayerVisible[rgs_layerid_wmslgngrau]>0){
				setLayerInvisible(rgs_layerid_wmslgngrau);
			}
			if (rgs_layerid_wmslgnfarbe>-1&&LayerVisible[rgs_layerid_wmslgnfarbe]>0){
				setLayerInvisible(rgs_layerid_wmslgnfarbe);
			}
			if (rgs_layerid_dop>-1&&LayerVisible[rgs_layerid_dop]>0){
				setLayerInvisible(rgs_layerid_dop);
			}
			if (rgs_layerid_dop2007>-1&&LayerVisible[rgs_layerid_dop2007]>0){
				setLayerInvisible(rgs_layerid_dop2007);
			}
			if (rgs_layerid_dop2007ir>-1&&LayerVisible[rgs_layerid_dop2007ir]>0){
				setLayerInvisible(rgs_layerid_dop2007ir);
			}
			if (rgs_layerid_metropolregion>-1&&LayerVisible[rgs_layerid_metropolregion]>0){
				setLayerInvisible(rgs_layerid_metropolregion);
			}
		}
	}
	if (rgs_layerid_dop > -1){
		if (index==rgs_layerid_dop){
			if (rgs_layerid_wmslgngrau>-1&&LayerVisible[rgs_layerid_wmslgngrau]>0){
				setLayerInvisible(rgs_layerid_wmslgngrau);
			}
			if (rgs_layerid_wmslgnfarbe>-1&&LayerVisible[rgs_layerid_wmslgnfarbe]>0){
				setLayerInvisible(rgs_layerid_wmslgnfarbe);
			}
			if (rgs_layerid_wmslgndop>-1&&LayerVisible[rgs_layerid_wmslgndop]>0){
				setLayerInvisible(rgs_layerid_wmslgndop);
			}
			if (rgs_layerid_dop2007>-1&&LayerVisible[rgs_layerid_dop2007]>0){
				setLayerInvisible(rgs_layerid_dop2007);
			}
			if (rgs_layerid_dop2007ir>-1&&LayerVisible[rgs_layerid_dop2007ir]>0){
				setLayerInvisible(rgs_layerid_dop2007ir);
			}
			if (rgs_layerid_metropolregion>-1&&LayerVisible[rgs_layerid_metropolregion]>0){
				setLayerInvisible(rgs_layerid_metropolregion);
			}
		}
	}
	if (rgs_layerid_dop2007 > -1){
		if (index==rgs_layerid_dop2007){
			if (rgs_layerid_wmslgngrau>-1&&LayerVisible[rgs_layerid_wmslgngrau]>0){
				setLayerInvisible(rgs_layerid_wmslgngrau);
			}
			if (rgs_layerid_wmslgnfarbe>-1&&LayerVisible[rgs_layerid_wmslgnfarbe]>0){
				setLayerInvisible(rgs_layerid_wmslgnfarbe);
			}
			if (rgs_layerid_wmslgndop>-1&&LayerVisible[rgs_layerid_wmslgndop]>0){
				setLayerInvisible(rgs_layerid_wmslgndop);
			}
			if (rgs_layerid_dop>-1&&LayerVisible[rgs_layerid_dop]>0){
				setLayerInvisible(rgs_layerid_dop);
			}
			if (rgs_layerid_dop2007ir>-1&&LayerVisible[rgs_layerid_dop2007ir]>0){
				setLayerInvisible(rgs_layerid_dop2007ir);
			}
			if (rgs_layerid_metropolregion>-1&&LayerVisible[rgs_layerid_metropolregion]>0){
				setLayerInvisible(rgs_layerid_metropolregion);
			}
		}
	}
	if (rgs_layerid_dop2007ir > -1){
		if (index==rgs_layerid_dop2007ir){
			if (rgs_layerid_wmslgngrau>-1&&LayerVisible[rgs_layerid_wmslgngrau]>0){
				setLayerInvisible(rgs_layerid_wmslgngrau);
			}
			if (rgs_layerid_wmslgnfarbe>-1&&LayerVisible[rgs_layerid_wmslgnfarbe]>0){
				setLayerInvisible(rgs_layerid_wmslgnfarbe);
			}
			if (rgs_layerid_wmslgndop>-1&&LayerVisible[rgs_layerid_wmslgndop]>0){
				setLayerInvisible(rgs_layerid_wmslgndop);
			}
			if (rgs_layerid_dop>-1&&LayerVisible[rgs_layerid_dop]>0){
				setLayerInvisible(rgs_layerid_dop);
			}
			if (rgs_layerid_dop2007>-1&&LayerVisible[rgs_layerid_dop2007]>0){
				setLayerInvisible(rgs_layerid_dop2007);
			}
			if (rgs_layerid_metropolregion>-1&&LayerVisible[rgs_layerid_metropolregion]>0){
				setLayerInvisible(rgs_layerid_metropolregion);
			}
		}
	}
	if (rgs_layerid_metropolregion > -1){
		if (index==rgs_layerid_metropolregion){
			if (rgs_layerid_wmslgngrau>-1&&LayerVisible[rgs_layerid_wmslgngrau]>0){
				setLayerInvisible(rgs_layerid_wmslgngrau);
			}
			if (rgs_layerid_wmslgnfarbe>-1&&LayerVisible[rgs_layerid_wmslgnfarbe]>0){
				setLayerInvisible(rgs_layerid_wmslgnfarbe);
			}
			if (rgs_layerid_wmslgndop>-1&&LayerVisible[rgs_layerid_wmslgndop]>0){
				setLayerInvisible(rgs_layerid_wmslgndop);
			}
			if (rgs_layerid_dop>-1&&LayerVisible[rgs_layerid_dop]>0){
				setLayerInvisible(rgs_layerid_dop);
			}
			if (rgs_layerid_dop2007>-1&&LayerVisible[rgs_layerid_dop2007]>0){
				setLayerInvisible(rgs_layerid_dop2007);
			}
			if (rgs_layerid_dop2007ir>-1&&LayerVisible[rgs_layerid_dop2007ir]>0){
				setLayerInvisible(rgs_layerid_dop2007ir);
			}
		}
	}
}
function setLayerInvisible(idx){
	LayerVisible[idx]=0;
	if (LayerGruppe[idx]!=""){
		for (var k=0;k<LayerID.length;k++) {
			if (LayerGruppe[k]==LayerGruppe[idx]) {
				LayerVisible[k]=0;
			}
		}
	}
}
function TOC_layerSetActive(index) {
	//setActiveLayer(index);
	var isOk = checkHyperLinkLayer(index);
	if (toolMode==15) {
		if (!isOk) {
			currentHyperLinkLayer="";
			currentHyperLinkField="";
			currentHyperLinkPrefix="";
			currentHyperLinkSuffix="";
			alert("This layer does not have any Hyperlinks.");
		}
	}
	this.refresh();
}


//-----------------
// GROUP
//-----------------

function GROUP(name,opened) {
	this.parent = null;
	this.index = -1;
	var arrname=new Array();
	arrname=name.split("^");
	arrname.reverse();
	this.name = arrname[0];
	this.opened = opened; //opened;
	this.o1name = arrname[1];
	this.o1opened = opened;
	this.o2name = arrname[2];
	this.o2opened = opened;
	this.o3name = arrname[3];
	this.o3opened = opened;
	this.o4name = arrname[4];
	this.o4opened = opened;
	this.layers = new Array();
	this.writeHTML = GROUP_writeHTML;
	this.addLayer = GROUP_addLayer;
}

function GROUP_writeHTML() {
	var s = "";
	if (this.o4name.length>0 && this.o4name!=old_o4name){
		old_o4name=this.o4name;
		old_o3name="";
		old_o2name="";
		old_o1name="";
		old_oname="";
		s += "<TABLE style='table-layout:fixed; empty-cells:show'>";
		s += "<TR>";
		if (this.o4opened){
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconOpened + "' onclick='"+dbgtResource.t+"o4groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"' alt='Ordner schließen'>&nbsp;</TD>";
		}else{
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconClosed + "' onclick='"+dbgtResource.t+"o4groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"' alt='Ordner öffnen'>&nbsp;</TD>";
		}
		if (this.o3name.length==0){				       
			var count = 0;
			for (var l=0; l<this.layers.length; l++){
				if (LayerVisible[this.layers[l].index]>0){
					count++;
				}
			}
			if (count == 0){
			  s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconHidden + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index+",1);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer einschalten'>&nbsp;</TD>";
			}else if (count == this.layers.length){
				s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisible + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
			}else{
				s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconTristate + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
			}
		}
		s += "<TD  style='font-weight:bold;'>" + this.o4name + "</TD>";
		s += "</TR>";
		s += "</TABLE>"
	}
	// 3OberOberOrdner
	if ((this.o4name.length==0 || this.o4opened) && (this.o3name.length>0 && this.o3name!=old_o3name)){
		old_o3name=this.o3name;
		old_o2name="";
		old_o1name="";
		old_oname="";
		s += "<TABLE style='table-layout:fixed; empty-cells:show'>";
		s += "<TR>";
		if (this.o4name.length>0){
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconChild + "'  onmouseover='this.style.cursor =\"pointer\"' alt='Ordner öffnen'>&nbsp;</TD>";
		}
		if (this.o3opened){
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconOpened + "' onclick='"+dbgtResource.t+"o3groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"' alt='Ordner schließen'>&nbsp;</TD>";
		}else{
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconClosed + "' onclick='"+dbgtResource.t+"o3groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"' alt='Ordner öffnen'>&nbsp;</TD>";
		}
		if (this.o2name.length==0){				       
		    var count = 0;
		    for (var l=0; l<this.layers.length; l++){
			  	if (LayerVisible[this.layers[l].index]>0){
					count++;
			  	}
		    }
			if (count == 0){
				s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconHidden + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index+",1);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer einschalten'>&nbsp;</TD>";
		    }else if (count == this.layers.length){
				s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisible + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
		    }else{
				s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconTristate + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"'  alt='alle Layer ausschalten'>&nbsp;</TD>";
		    }
		}
		s += "<TD  style='font-weight:bold;'>" + this.o3name + "</TD>";
	    s += "</TR>";
		s += "</TABLE>"
	}
	if ((this.o2name.length>0)&&(this.o2name!=old_o2name)){
	    if ((this.o4name.length==0 || this.o4opened) && (this.o3name.length==0 || this.o3opened)){
	  	    old_o2name=this.o2name;
			old_o1name="";
	  		old_oname="";
	  	  	s += "<TABLE style='table-layout:fixed; empty-cells:show'>";
			s += "<TR>";
			if (this.o4name.length>0){
			  s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconChild + "'  onmouseover='this.style.cursor =\"pointer\"'>&nbsp;</TD>";
			}
			if (this.o3name.length>0){
			  s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconChild + "'  onmouseover='this.style.cursor =\"pointer\"'>&nbsp;</TD>";
			}
			if (this.o2opened){
		      s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconOpened + "' onclick='"+dbgtResource.t+"o2groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"' alt='Ordner schließen'>&nbsp;</TD>";
		    }else{
		      s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconClosed + "' onclick='"+dbgtResource.t+"o2groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"' alt='Ordner öffnen'>&nbsp;</TD>";
			}
			if (this.o1name.length==0){				       
			    var count = 0;
			    for (var l=0; l<this.layers.length; l++){
				  	if (LayerVisible[this.layers[l].index]>0){
						count++;
				  	}
			    }
				if (count == 0){
					s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconHidden + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index+",1);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer einschalten'>&nbsp;</TD>";
			    }else if (count == this.layers.length){
					s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisible + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
			    }else{
					s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconTristate + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
			    }
			}
			s += "<TD  style='font-weight:bold;'>" + this.o2name + "</TD>";
			s += "</TR>";
			s += "</TABLE>"
		}
	} 
	// OberOrdner
	if (this.o1name.length>0 && this.o1name!=old_o1name){
		if ((this.o4name.length==0 || this.o4opened) && (this.o3name.length==0 || this.o3opened) && (this.o2name.length==0 || this.o2opened)){
			old_o1name=this.o1name;
			s += "<TABLE style='table-layout:fixed; empty-cells:show'>";
			s += "<TR>";
			if (this.o4name.length>0){
			  s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconChild + "' >&nbsp;</TD>";
			}
			if (this.o3name.length>0){
			  s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconChild + "' >&nbsp;</TD>";
			}
			if (this.o2name.length>0){
			  s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconChild + "' >&nbsp;</TD>";
			}
				
			if (this.o1opened){
		      s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconOpened + "' onclick='"+dbgtResource.t+"ogroupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"' Ordner schließen>&nbsp;</TD>";
		    }else{
		      s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconClosed + "' onclick='"+dbgtResource.t+"ogroupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"' Ordner öffnen>&nbsp;</TD>";
			}
			if (this.name.length==0){				       
			    var count = 0;
				for (var l=0; l<this.layers.length; l++){
				  	if (LayerVisible[this.layers[l].index]>0){
						count++;
				  	}
				}
				if (count == 0){
					s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconHidden + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index+",1);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer einschalten'>&nbsp;</TD>";
			    }else if (count == this.layers.length){
					s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisible + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
			    }else{
					s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconTristate + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
			    }
			}
			s += "<TD  style='font-weight:bold;'>" + this.o1name + "</TD>";
			s += "</TR>";
			s += "</TABLE>"
		}
	}
	if ((this.o4name.length==0 || this.o4opened) && (this.o3name.length==0 || this.o3opened) && (this.o2name.length==0 || this.o2opened) && (this.o1name.length==0||this.o1opened) && (this.name.length>0)){
		s += "<TABLE style='table-layout:fixed; empty-cells:show'>";
		s += "<TR>";
		if (this.o4name.length>0){
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconLine + "' onclick='"+dbgtResource.t+"groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"'>&nbsp;</TD>";
		}
		if (this.o3name.length>0){
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconLine + "' onclick='"+dbgtResource.t+"groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"'>&nbsp;</TD>";
		}
		if (this.o2name.length>0){
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconLine + "' onclick='"+dbgtResource.t+"groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"'>&nbsp;</TD>";
		}
		if (this.o1name.length>0){
			s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconChild + "' onclick='"+dbgtResource.t+"groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"'>&nbsp;</TD>";
		}
		if (this.opened){
		    s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconOpened + "' onclick='"+dbgtResource.t+"groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"'  alt='Ordner schließen'>&nbsp;</TD>";
		}else{
		    s += "<TD style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconClosed + "' onclick='"+dbgtResource.t+"groupToggleOpened(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\"'  alt='Ordner öffnen'>&nbsp;</TD>";
		}
		if (this.name.length>0){				       
		    var count = 0;
			for (var l=0; l<this.layers.length; l++){
			  	if (LayerVisible[this.layers[l].index]>0){
					count++;
			  	}
			}
			if (count == 0){
				s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconHidden + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index+",1);' onmouseover='this.style.cursor =\"pointer\"'  alt='alle Layer einschalten'>&nbsp;</TD>";
		    }else if (count == this.layers.length){
				s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisible + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
		    }else{
				s += "<TD  style='width:18px;font-weight:bold;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconTristate + "' onclick='"+dbgtResource.t+"groupSetVisible(" + this.index + ",0);' onmouseover='this.style.cursor =\"pointer\"' alt='alle Layer ausschalten'>&nbsp;</TD>";
			}
		}
	    s += "<TD style='width:18px;font-weight:bold;' >" + this.name + "</TD>";
	    s += "</TR>";
		s += "</TABLE>"
	}
	if ((this.name.length==0 && this.o1opened>0) ||
		(this.name.length==0 && this.o1name.length==0 && this.o2opened>0) || 
		(this.name.length==0 && this.o1name.length==0 && this.o2name.length==0 && this.o3opened>0) ||
		(this.name.length==0 && this.o1name.length==0 && this.o2name.length==0 && this.o3name.length==0 && this.o4opened>0)|| 
		(this.opened)) {
			for (var l=0; l<this.layers.length; l++){
				s += this.layers[l].writeHTML((l==this.layers.length-1),this.index);
			}
	}
	return s;
}


function GROUP_addLayer(layer) {
  layer.parent = this;
  this.layers[this.layers.length] = layer;
  return layer;
}


//-----------------
// LAYER
//-----------------

function LAYER(name,swatch,legend,id) {
  //if ((srtlegend==0) || (srtlegend==1 && LayerVisible[id]==1)){
  	this.parent = null;
  	this.name = name;
  	this.index = id;
  	this.swatch = swatch;
  	this.legend = legend;
  	this.writeHTML = LAYER_writeHTML;
  //}
}

function LAYER_writeHTML(lastone,groupindex) {
	if (LayerVisibleInLegend[this.index]=="1"){
		var s = "";
		var c = 0;
		//-------------------
		// START OF LAYER ROW
		//-------------------
		if (this.parent.o1name.length>0){
			c++;
		}
		if (this.parent.o2name.length>0){
			c++;
		}
		if (this.parent.o3name.length>0){
			c++;
		}
		if (this.parent.o4name.length>0){
			c++;
		}
		s += "<TABLE style='table-layout:fixed; empty-cells:show'>";
		s += "<TR>";
		for (var d=0; d<c; d++){
			s+="<TD style='WIDTH:" + dbgtResource.imageWidth +"px'>&nbsp;</TD>";
		}
		
		//---------------------------------
		// SECOND COL = VISIBILITY CHECKBOX
		//---------------------------------
		var x=LayerAliasname[this.index];
		if (LayerMinScale[this.index]>0 || LayerMaxScale[this.index]<999999999){
			x="";
			if (LayerMinScale[this.index]>0){
				x+="M. min.1:"+LayerMinScale[this.index];
			}
			if (LayerMaxScale[this.index]<999999999){
				x+=" M. max.1:"+LayerMaxScale[this.index];
			}
		}
		if (LayerVisible[this.index]==0){
			s += "<TD style='width:18px;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconHidden + "' onclick='"+dbgtResource.t+"layerToggleVisible(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\";this.alt=\""+x+"\"'>&nbsp;</TD>";
		}
		if (LayerVisible[this.index]==1){
			s += "<TD style='width:18px;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisible + "' onclick='"+dbgtResource.t+"layerToggleVisible(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\";this.alt=\""+x+"\"'>&nbsp;</TD>";
		}
		if (LayerVisible[this.index]==2){
			s += "<TD style='width:18px;top:0;'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconVisscale + "' onclick='"+dbgtResource.t+"layerToggleVisible(" + this.index + ");' onmouseover='this.style.cursor =\"pointer\";this.alt=\""+x+"\"'>&nbsp;</TD>";
		}	

		//-----------------------
		// FIFTH COL = LAYER NAME
		//-----------------------
		if (LayerHyperlinkList[this.index]==""){
			s += "<TD style='width:1px;'>&nbsp;</TD>";
		}else{
			s += "<TD style='width:18px;' align='left' onclick='javascript:showlayerInfo(" + this.index+")'><IMG SRC='" + dbgtResource.iconPath + dbgtResource.iconInfo + "' onMouseover='javascript:this.src=\"" + dbgtResource.iconPath + "icon_info_mo.png\";this.alt=\"wichtiger Hinweis !\";this.style.cursor =\"pointer\"' width=\"15\" height=\"15\" onMouseout='javascript:this.src=\"" + dbgtResource.iconPath +dbgtResource.iconInfo +"\"'>&nbsp;</TD>";
		}
		s += "<TD>";
		s += this.name;
		s += "</TD>";
		
	  //-----------------
	  // END OF LAYER ROW
	  //-----------------
	  s += "</TR>";

	  //--------------------
	  // OPTIONAL LEGEND ROW
	  //--------------------
		if (this.legend != "") {
			s+="<TR>";
			for (var d=0; d<c+2; d++){
				s+="<TD style='width:18px;'>&nbsp;</TD>";
			}
			if (this.legend.indexOf("a href") > -1) {
				s += "<TD style=''>" + this.legend + "</TD>";
			}else if (this.legend.indexOf("http") > -1) {
				s += "<TD style=''><IMG SRC='" + this.legend + "'>&nbsp;</TD>";
			}else{
				s += "<TD style=''><IMG SRC='" + dbgtResource.legendPath + this.legend + "'>&nbsp;</TD>";
			}
			s+="</TR>";
		}
		s += "</TABLE>";
		return s;
	}
}


//-----------------
// eof
//-----------------




