/*

This code was created by http://www.ase.ch 
If you are interested feel free to contact us for further informations. 

*/
/** 
 * @fileoverview Definition of global utility methods and objects used
 * by both the application and the data acquisition tool.
 *
 * @author Michael Moos mm@ase.ch
 * @version 2.0 
 */
/*--------------------------------------------------------------------------------------------------------------------------------div operations-*/
// Author: MitLinks
function div_show(dropdownId)
{
	// Variable "nr" contains the selected breadcrumb-level as number (0-n).
  	document.getElementById(dropdownId).style.display='block';
	// WORKAROUND FOR IE6 (Problem: No DIVs over INPUTs possible):
	if ( !(window.XMLHttpRequest) )
	{
		// if IE6:
		document.getElementById('shops').style.visibility='hidden';
		document.getElementById('centers').style.visibility='hidden';
	}
}

function div_hide(dropdownId)
{
	//var dropdownId='dropdown'+nr;
	document.getElementById(dropdownId).style.display='none';
	// WORKAROUND FOR IE6 (Problem: No DIVs over INPUTs possible):
	if ( !(window.XMLHttpRequest) )
	{
		// if IE6:
		document.getElementById('shops').style.visibility='visible';
		document.getElementById('centers').style.visibility='visible'; 
	}
}

function btn_back_diagram()
{	
	// Variable "nr" contains the selected breadcrumb-level as number (0-n).
  	document.getElementById('right_map').style.display='block';
	if ( !(window.XMLHttpRequest) )
	{
		document.getElementById('right_map').style.visibility='visible';
	}
	
	document.getElementById('DiagramList').style.display='none';
	if ( !(window.XMLHttpRequest) )
	{
		document.getElementById('DiagramList').style.visibility='hidden'; 
	}
}
/*--------------------------------------------------------------------------------------------------------------------------------elementlistobj-*/
/**
 * @class Constructs a new elementobj. An object with key and data.
 * @constructor
 */
function elementobj(key,data)
{
	//properties
	this.key=key;
	this.data=data;
}
/**
 * @class Constructs a new elementlistobj. A list of elementobj's and a pointer to one of the elements.
 * Notice: The list can have multiple elements with the same key.
 * @constructor 
 */
function elementlistobj()
{
	//properties
	this.pointer=0;
	this.list=new Array();
}
/**
 * Add an elementobj to the list.
 */
elementlistobj.prototype.add=function(key,data)
{
	this.list.push(new elementobj(key,data));
}
/**
 * Removes the next elementobj with the given key from the pointer position.
 * If no such element exists in the range between pointer and the end of the list,
 * The search is done in the range between the first element and the current pointer
 * position. If an element is found, the pointer position is set to that position. 
 */
elementlistobj.prototype.remove=function(key)
{
	var i=this.find(key);
	if(i!=-1) this.list.splice(i,1);
}
/**
 * Finds the next elementobj with the given key from the pointer position.
 * If no such element exists in the range between pointer and the end of the list,
 * The search is done in the range between the first element and the current pointer
 * position. If an element is found, the pointer position is set to that position. 
 */
elementlistobj.prototype.find=function(key)
{
	for(var i=this.pointer+1;true;i++)
	{
		if(i==this.list.length) i=0;
		if(this.list[i].key==key) { this.pointer=i; return i; }
		if(i==this.pointer) return -1;
	}
}
/**
 * Find all elements with the given key.
 * @return A new elementlistobj with all elements of the given key.
 */
elementlistobj.prototype.findall=function(key)
{
	var datalist=new elementlistobj();
	var initindex=this.find(key);
	if(initindex!=-1)
	{
		datalist.add(this.list[initindex].key,this.list[initindex].data);
		for(var i=this.find(key);i!=initindex;i=this.find(key)) datalist.add(this.list[i].key,this.list[i].data);
	}
	
	return datalist;
}
/*--------------------------------------------------------------------------------------------------------------------------------------ajaxutil-*/
function writeHTML(text,id,append) 
{
	if(append==1) document.getElementById(id).innerHTML+=text;
	else  document.getElementById(id).innerHTML=text;
}

function ddd(text)
{
	document.getElementById("Debug").innerHTML+="<br><br>["+text+"]";	
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	// Firefox, Opera 8.0+, Safari
	try { xmlHttp=new XMLHttpRequest(); }
	//Internet Explorer
	catch (e)
	{
		try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return xmlHttp;
}

function sqlselect(db,select,from,where,order,echo)
{
	var xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
	var reqstr="sqlselect.php?se="+select+"&fr="+from+"&wh="+where+"&or="+order+"&db="+db+"&echo="+echo;
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);
	
	var response;
	response = xmlHttp.responseText;
	return response;
}

function sql_last_id(table)
{
	var last_id_req =GetXmlHttpObject();
	if(last_id_req==null) { alert ("Browser does not support HTTP Request"); return; }
	var reqstr="last_insert_id.php?table="+table;
	last_id_req.open("GET",reqstr,false);
	last_id_req.send(null);
	
	var id_response;
	id_response = last_id_req.responseText;
	return id_response;
}

function multiselect(db,statements)
{
	var xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
	var reqstr="multiselect.php?db="+db+"&st="+statements;
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);

	var response;
	response = xmlHttp.responseText;
	return response;
}

function getkmldata(db,zoneid,bool)
{
	var xmlHttp=GetXmlHttpObject();
	var reqstr="kmldata.php?bool="+bool+"&id="+zoneid+"&db="+db;
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);
	
	return xmlHttp.responseText.split("xXcXx");
}

function getFreqKmlData(db,idOrAll){
	var xmlHttp=GetXmlHttpObject();
	var reqstr="kmldata.php?getData=Frequenz&Id="+idOrAll+"&db="+db;
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);
	
	var response;
	response = xmlHttp.responseText;
	return response
	//response = xmlHttp.responseText.split("xXcxx");
}
/*------------------------------------------------------------------------------------------------------------------------------------stringutil-*/
String.prototype.replaceumlaut=function()
{
	var str=this;
	
	str=str.replace(/ä/g,"ae");
	str=str.replace(/ö/g,"oe");
	str=str.replace(/ü/g,"ue");
	str=str.replace(/Ä/g,"Ae");
	str=str.replace(/Ö/g,"Oe");
	str=str.replace(/Ü/g,"Ue");
	str=str.replace(/ /g,"");
	
	return str;
}

String.prototype.comma2code=function()
{
	return this.replace(/,/g,"xXcXx");
}
	
String.prototype.code2comma=function()
{
	return this.replace(/xXcXx/g,",");
}
/*----------------------------------------------------------------------------------------------------------------------------------------staobj-*/
/**
 * @class Constructs a new string-array-object. The object has the property 'value' which is a string but represents
 * a comma separated array. Elements can only be added. Instead of a comma, a separator can be defined.
 * @param initvalue initial value of the object.
 * @param sep separator string.
 * @constructor
 */
function staobj(initvalue,sep)
{
	//initialization
	if(!sep) this.sep=","; else this.sep=sep;
	if(initvalue==undefined)
	{
		this.length=0;
		this.value="";
	}
	else
	{
		this.length=1;
		this.value=initvalue;
	}
}
/**
 * Add a string element.
 */
staobj.prototype.add=function(element)
{
	if(!element) element="";
	if(!this.length) this.value+=element;
	else this.value+=this.sep+element;
	this.length++;
}
/*--------------------------------------------------------------------------------------------------------------------------------------IE fixes-*/
if(!Array.indexOf){
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
        return -1;
    }
}


/** 
 * @fileoverview Definition of kmlfileobj with all methods.
 *
 * @author Michael Moos mm@ase.ch
 * @version 2.0 
 */
/*------------------------------------------------------------------------------------------------------------------------------------kmlfileobj-*/
/**
 * @class Constructs a new kml file object.
 * @constructor
 */
function kmlfileobj()
{
	//properties
	this.xmlDoc;
	this.polystyle=new Array();
}
/**
 * Read the polygon style section.
 * @param opacity The opacity information of the style is ignored and instead the
 * given opacity as an argument is used. 
 */
kmlfileobj.prototype.readpolystyle=function(opacity)
{
	var styleXml=this.xmlDoc.documentElement.getElementsByTagName("Style");
	for(var i=0;i<styleXml.length;i++)
	{
		var code='#'+styleXml[i].getAttribute("id");
		this.polystyle[code]=new Object();
		var polystyleXml=styleXml[i].getElementsByTagName("PolyStyle")[0];
		if(polystyleXml)
		{
			var colorXml=polystyleXml.getElementsByTagName("color")[0];
			if(colorXml)
			{
				var fillcolor=colorXml.firstChild.nodeValue;
				fillcolor='#'+fillcolor.substr(6,2)+fillcolor.substr(4,2)+fillcolor.substr(2,2);
				this.polystyle[code].fillopa=opacity;
				this.polystyle[code].fillcolor=fillcolor;
				if(opacity==1) this.polystyle[code].linecolor='#000000';
				else this.polystyle[code].linecolor=fillcolor;
			}
			else
			{
				this.polystyle[code].fillopa=0;
			}
		}
		if(!this.polystyle[code].fillopa)
		{
			var linestyleXml=styleXml[i].getElementsByTagName("LineStyle")[0];
			if(linestyleXml)
			{
				var colorXml=linestyleXml.getElementsByTagName("color")[0];
				if(colorXml)
				{
					var linecolor=colorXml.firstChild.nodeValue;
					linecolor='#'+linecolor.substr(6,2)+linecolor.substr(4,2)+linecolor.substr(2,2);
					this.polystyle[code].linecolor=linecolor;
					this.polystyle[code].fillopa=0;
				}
				else
				{
					this.polystyle[code].linecolor='#000000';
				}
			}
		}
	}
}
/**
 * Read the polygon information and create the polygons on the map.
 * @param layer Pointer to the target layer object.
 * @param map Pointer to the map object.
 * @param zoneobj elementlistobj to add the polygons that are created.
 * @param zonelist associative array of elementlistobj's with all polygon codes of the current zone.
 */
kmlfileobj.prototype.readpolygon=function(layer,map,zoneobj,zonelist)
{
	var placemarkXml=this.xmlDoc.documentElement.getElementsByTagName("Placemark");
	for(var i=0;i<placemarkXml.length;i++)
	{
		if(zonelist!=undefined)
		{
			var polycode=GXml.value(placemarkXml[i].getElementsByTagName("description")[0]);
			if(polycode=="") polycode=GXml.value(placemarkXml[i].getElementsByTagName("name")[0]);
		}
		var polygonXml=placemarkXml[i].getElementsByTagName("Polygon");
		if(polygonXml.length)
		{
			polygonXml=polygonXml[0];
			var styleurl=placemarkXml[i].getElementsByTagName("styleUrl")[0].firstChild.nodeValue;
			if(zonelist!=undefined&&zonelist[polycode]!=undefined)
			{
				zoneobj.add(zonelist[polycode].key,map.createpolygon(layer,polygonXml,this.polystyle[styleurl],polycode,zonelist[polycode]));
			}
			else if(zonelist==undefined) zoneobj.add(0,map.createpolygon(layer,polygonXml,this.polystyle[styleurl]));
		}
	}
	
	if(zoneobj.list.length) return 0; else return -1;
}
/**
 * Read all markers of the file, create them on the GoogleMap and add them to the itemobj list
 * @param layer Pointer to the target layer object.
 * @param map Pointer to the map object.
 * @param itemobj elementlistobj to add the markers that are created.
 * @param itemlist associative array of elementlistobj's with all item codes of the current zone.
 */
kmlfileobj.prototype.readpoint=function(layer,map,itemobj,itemlist)
{
	var icon=new GIcon();
	icon.image="img/punkt8x8.png";
	icon.iconSize=new GSize(7, 7);
	icon.iconAnchor=new GPoint(4, 4);
	icon.infoWindowAnchor=new GPoint(6, 1);
	icon.infoShadowAnchor=new GPoint(13, 13);
	
	var placemarkXml=this.xmlDoc.documentElement.getElementsByTagName("Placemark");
	for (var i=0;i<placemarkXml.length;i++)
	{
		var pointcode=GXml.value(placemarkXml[i].getElementsByTagName("description")[0]);
		if(pointcode=="") pointcode=GXml.value(placemarkXml[i].getElementsByTagName("name")[0]);
		for(var j=0;j<itemlist.length;j++) if(pointcode==itemlist[j]) break;
		if(j<itemlist.length)
		{
			var pointXml=placemarkXml[i].getElementsByTagName("Point")[0];
			var bits=pointXml.getElementsByTagName("coordinates")[0].childNodes[0].nodeValue.split(",");
			var coords=new GLatLng(parseFloat(bits[1]),parseFloat(bits[0]));
			itemobj.add(pointcode,map.createmarker(layer,coords,pointcode,icon));
		}
	}
	
	if(itemobj.list.length) return 0; else return -1;
}

/**
 * function readDiagramPoint
 *
 * @author Andreas Zumstein
 * @param layer,map,diagramobj,diagramlist
 * @return return int 0/1,  0 = succes, 1 = failure
 */
kmlfileobj.prototype.readDiagramPoint=function(layer,map,diagramobj,diagramlist)
{
	var markerIcon=new GIcon();
	markerIcon.image="img/flag_gelb.png";
	markerIcon.iconSize=new GSize(20 , 20);
	markerIcon.iconAnchor=new GPoint(4, 4);
	markerIcon.infoWindowAnchor=new GPoint(6, 1);
	markerIcon.infoShadowAnchor=new GPoint(13, 13);
	//window.alert("xml doc ist \n"+xmlDocFreq);
	
	var xmlDocFreq=this.xmlDoc.getElementsByTagName("Document");
	for (var i=0;i<xmlDocFreq.length;i++)
	{
		var placemark=GXml.value(xmlDocFreq[i].getElementsByTagName("Placemark")[0]); // get the id
		//window.alert("placemark ist \n"+placemark);
		var xmldoxfreq=xmlDocFreq[i].getElementsByTagName("Point")[0];
		//window.alert("thepoint: \n"+freqId);
		var coordinates=xmldoxfreq.getElementsByTagName("coordinates")[0].childNodes[0].nodeValue.split(","); // get coords
		//window.alert("coordinates: \n"+coordinates);
		var coords=new GLatLng(parseFloat(coordinates[1]),parseFloat(coordinates[0]));
		diagramobj.add("ASE",map.createDiagramMarker(layer,coords,placemark,markerIcon));
	}
	if(diagramobj.list.length) return 0; 
	else return -1;
}

/**
 * Parse the given Kml File.
 * @kmlfile Kml File to be parsed.
 */
kmlfileobj.prototype.fileopen=function(kmlfile)
{
	this.xmlDoc=GXml.parse(kmlfile);
}



/** 
 * @fileoverview Definition of layerobj with all methods.
 *
 * @author Michael Moos mm@ase.ch
 * @version 2.0 
 */
/*--------------------------------------------------------------------------------------------------------------------------------------layerobj-*/
/**
 * @class Constructs a new layer object.
 * @constructor
 * @param map Pointer to the map object.
 * @param zoneid Id of the zone of the new layer.
 */
function layerobj(map,zoneid)
{
	//properties
	this.zoneid=zoneid;
	this.path;
	this.bounds;
	this.map=map;
	this.itemtypelist=new Array();
	this.usertypelist=new Array();
	this.zonetypelist=new Array();
	this.diagramlist=new Array();
	
	//initialization
	var zonedata=sqlselect(1,"HasLayers,zone.Name as Name,Path,TypeId","zone,zonetype",
		"zone.TypeId=zonetype.Id and zone.Id="+this.zoneid).split(",");
	//HasLayers: load child zone with Nr=0
	if(zonedata[0]==1) 
	{
		zonedata=sqlselect(1,"HasLayers,zone.Name as Name,Path,TypeId,zone.Id as Id","zone,zonetype",
			"zone.TypeId=zonetype.Id and zone.ParentId="+this.zoneid+" and Nr=0").split(",");
		this.zoneid=zonedata[4];
	}
	
	this.zonename=zonedata[1].code2comma();
	this.path=zonedata[2];
	this.typeid=zonedata[3];
	this.bounds=new GLatLngBounds();
	this.kml=getkmldata(1,this.zoneid);
	// Frequenzmessungspunkt darf nicht auf oberstem layer erscheinen,  
	// weil sonst nichtmehr der höchstmögliche Zoom auf einer neuen Zone erreicht werden kann!
	// Dies ist so weil die Bounds GLatLngBounds() der GMap karte immer den Frequenzmessungspunkt miteinbeziehen
	if(this.zonename == "Bellevueplatz")
	{	
		this.kml[4] = getFreqKmlData(db=2,id='all'); //window.alert("Bellevueplatz : "+this.zonename);
	}
	else if(this.zonename == "ZH - Stadt Zürich")
	{
		this.kml[4] = getFreqKmlData(db=2,id='all');
	}
	else
	{
		this.kml[4] = false; //window.alert(this.zonename);
	}//window.alert("KMLTEXT in kml4"+this.kml[4]);
	//window.alert("KMLTEXT in kml4"+this.kml[4]);
	
	this.settypeids();	
}
/**
 * Load the kml overlays of the current layer. the kml list defines
 * which overlays are loaded.
 */
layerobj.prototype.load=function()
{
	if(this.kml[0]) if(this.constructitems(this.kml[0])) return -1;
	if(this.kml[2]) this.constructdesign(this.kml[2]);
	if(this.kml[1]) if(this.constructzones(this.kml[1])) return -1;
	if(this.kml[3]) this.constructoverlap(this.kml[3]);
	if(this.kml[4]) this.constructdiagram(this.kml[4]);
	//writeHTML("<h2 class='block'>Eingangsfront</h2>","ShopInfoHead");
	//writeHTML("","ShopInfoHead");
	
	return 0;
}
/**
 * Construct all items of the given kmlfile
 * @param kmlfile Kml file with item information.
 */
layerobj.prototype.constructitems=function(kmlfile)
{
	this.item=new elementlistobj();
	var tmp=sqlselect(1,"item.Code,item.TypeId,user.TypeId",
		"item left join useritemlist on ItemId=item.Id left join user on UserId=user.Id","item.ZoneId="+this.zoneid).split(",");
		
	if(tmp.length<1) return 0;//no items
	var itemlist=new Array();
	for(var i=0;i<tmp.length;i+=3) if(this.itemtypelist.indexOf(tmp[i+1])>=0&&(!tmp[i+2]||this.usertypelist.indexOf(tmp[i+2])>=0))
	{
		itemlist.push(tmp[i]);
	}

	this.map.selitem=0;
	var itemfile=new kmlfileobj();
	var map=this.map;
	
	if(itemfile.fileopen(kmlfile)) return -1;
	if(itemfile.readpoint(this,this.map,this.item,itemlist)) return -1;

	GEvent.addListener(this.map.googlemap,"mousemove",function(p) { map.moved=1; });
	GEvent.addListener(this.map.googlemap,"click",function(p)
	{
		if(globalmap.moved==1&&globalmap.selitem!=0)
		{
			globalmap.selitem.setImage("img/punkt8x8.png");
			globalmap.selitem=0;
			writeHTML("","ShopInfo")
		}
	});

	return 0;
}
/**
 * Construct all zones of the given kmlfile
 * @param kmlfile Kml file with zone information.
 */
layerobj.prototype.constructzones=function(kmlfile)
{
	this.zone=new elementlistobj();
	var tmp=sqlselect(1,"Code,Id,Name,TypeId","zone","ParentId="+this.zoneid).split(",");
	if(tmp.length<4) return 0;//no zones
	var zonelist=new Array();
	for(var i=0;i<tmp.length;i+=4)
	{
		if(this.zonetypelist.indexOf(tmp[i+3])>=0)
			zonelist[tmp[i]]=new elementobj(tmp[i+1],tmp[i+2].code2comma());
	}
	var zonefile=new kmlfileobj();
	if(zonefile.fileopen(kmlfile)) return -1;
	zonefile.readpolystyle(0.5);
	if(zonefile.readpolygon(this,this.map,this.zone,zonelist)) return -1;
	
	return 0;
}
/**
 * Construct all designs of the given kmlfile
 * @param kmlfile Kml file with design information.
 */
layerobj.prototype.constructdesign=function(kmlfile)
{
	this.design=new elementlistobj();
	var designfile=new kmlfileobj();
	if(designfile.fileopen(kmlfile)) return -1;
	designfile.readpolystyle(1);
	designfile.readpolygon(this,this.map,this.design);
		
	return 0;
}
/**
 * Construct all overlaps of the given kmlfile
 * @param kmlfile Kml file with overlap information.
 */
layerobj.prototype.constructoverlap=function(kmlfile)
{
	this.overlap=new elementlistobj();
	var tmp=sqlselect(1,"zone.Code,zone.Id,zone.Name,zone.TypeId","zone,overlap",
		"zone.Id=overlap.ChildId and overlap.ParentId="+this.zoneid).split(",");
	if(tmp.length<4) return -1;//keine zonen
	var zonelist=new Array();
	for(var i=0;i<tmp.length;i+=4)
	{
		if(this.zonetypelist.indexOf(tmp[i+3])>=0)
			zonelist[tmp[i]]=new elementobj(tmp[i+1],tmp[i+2].code2comma());
	}
	var zonefile=new kmlfileobj();
	var ret=zonefile.fileopen(kmlfile);
	if(ret) return -1;
	zonefile.readpolystyle(0.5);
	zonefile.readpolygon(this,this.map,this.overlap,zonelist);
		
	return 0;
}

/**
 * function constructdiagram
 * 
 * @param kmlfile Kml file with Diagram Informations
 * @return bool 0=success/1=failure
 */
layerobj.prototype.constructdiagram=function(kmlfile)
{
	this.diagram = new elementlistobj();
	var tmp=sqlselect(2,"id,standort,img_folder,show_diagram_days","frequency","id>0").split(",");
	if(tmp.length<1) return -1;//no diagram datas
	var diagramlist=new Array();
	for(var i=0;i<tmp.length;i+=4) if( this.diagramlist.indexOf(tmp[i+1])>=0 && ( !tmp[i+2] || this.diagramlist.indexOf(tmp[i+2])>=0 ) )
	{
		diagramlist.push(tmp[i]);
	}

	this.map.selitem=0;
	diagramfile = new kmlfileobj();
	var map = this.map;
	if(diagramfile.fileopen(kmlfile)) return -1;
	
	if(diagramfile.readDiagramPoint(this,this.map,this.diagram,diagramlist)) return -1;
	
//	for(var i=0; i < kmlfile.length; i++){
//	//for( i in kmfile){
//		window.alert("KMLFILE = "+kmlfile[i]);
//		
//		if(diagramfile.fileopen(kmlfile[i])) return -1;
//		if(diagramfile.readDiagramPoint(this,this.map,this.diagram,diagramlist)) return -1;
//	}
		
	
	GEvent.addListener(this.map.googlemap,"mousemove",function(p) { map.moved=1; });
	GEvent.addListener(this.map.googlemap,"click",function(p)
	{
		if(globalmap.moved==1&&globalmap.selitem!=0)
		{
			globalmap.selitem.setImage("img/punkt8x8.png");
			globalmap.selitem=0;
			writeHTML("","DiagramInfo");
		}
	});
	
	return 0;
}

/**
 * Display a form to choose the zonetypes that are shown on the map.
 */
layerobj.prototype.choosezonetypes=function()
{
	var map=this.map,layer=this;
	var disp="<div class='contentBlockHead'><h2 class='block'>Angezeigte Zonenarten</h2></div><div id='staticContent'><p><table>";
	var allzones0=sqlselect(1,"distinct zonetype.Id,zonetype.Name","zonetype,zone","zone.TypeId=zonetype.Id and zone.ParentId="+this.zoneid).split(",");
	var allzones1=sqlselect(1,"distinct zonetype.Id,zonetype.Name","zonetype,zone,overlap,zone as zone0",
		"zone.Id="+this.zoneid+" and overlap.ParentId=zone.Id and overlap.ChildId=zone0.Id and zone0.TypeId=zonetype.Id").split(",");
		
	var allzones;
	if(allzones0[0]&&allzones1[0]) allzones=allzones0.concat(allzones1);
	else if(allzones0[0]) allzones=allzones0;
	else if(allzones1[0]) allzones=allzones1;
	
	div_hide("right_map");
	div_show("right_info");
	for(var i=0;i<allzones.length;i+=2)
	{
		disp+="<tr><td><input type='checkbox' id='"+allzones[i]+"'";
		if(this.zonetypelist.indexOf(allzones[i])>=0) disp+=" checked='true'";
		disp+="></td><td><span class='large'>"+allzones[i+1]+"</span></td></tr>";
	}	
	disp+="</table></p><p><input value='OK' type='button' id='btn_zonetype'/></p><br><p><a href='#' onclick='reload(\"map\")' style='float:left;'>"+
		"<img class='linkIcon' src='img/iconMap.jpg'/><span class='big'>Zur&uuml;ck zur Kartenansicht</span></a></p></div>";
	writeHTML(disp,"right_info");
	document.getElementById('btn_zonetype').onclick=function()
	{
		for(var i=0;i<allzones.length;i+=2)
		{
			if(document.getElementById(allzones[i]).checked&&layer.zonetypelist.indexOf(allzones[i])==-1) layer.zonetypelist.push(allzones[i]);
			else
			{
				var index=layer.zonetypelist.indexOf(allzones[i]);
				if(!document.getElementById(allzones[i]).checked&&index>=0) layer.zonetypelist.splice(index,1);
			}
		}
		div_hide("right_info");
		div_show("right_map");
		layer.reload(false,true,true,false);
		map.writebreadcrump();
	}
}
/**
 * Display a form to choose the usertypes that are shown on the map.
 */
layerobj.prototype.chooseusertypes=function()
{
	var usertypelist=this.usertypelist;
	var allusers=sqlselect(1,"distinct usertype.Id,usertype.Name",
		"usertype,user,useritemlist,item","usertype.Id=user.TypeId and user.Id=useritemlist.UserId and useritemlist.ItemId=item.Id and item.ZoneId="+
		this.zoneid,"usertype.Name").split(",");
	var disp="<div class='contentBlockHead'><h2 class='block'>Angezeigte Anbieter</h2></div><div id='staticContent'><p><table>";
	var layer=this;
	
	div_hide("right_map");
	div_show("right_info");
	for(var i=0;i<allusers.length;i+=2)
	{
		disp+="<tr><td><input type='checkbox' id='"+allusers[i]+"'";
		if(usertypelist.indexOf(allusers[i])>=0) disp+=" checked='true'";
		disp+="></td><td><span class='large'>"+allusers[i+1]+"</span></td></tr>";
	}
	disp+="</table></p><p><input value='OK' type='button' id='btn_usertype'/></p><br><p><a href='#' onclick='reload(\"map\")' style='float:left;'>"+
		"<img class='linkIcon' src='img/iconMap.jpg'/><span class='big'>Zur&uuml;ck zur Kartenansicht</span></a></p></div>";
	writeHTML(disp,"right_info");
	document.getElementById('btn_usertype').onclick=function()
	{
		for(var i=0;i<allusers.length;i+=2)
		{
			if(document.getElementById(allusers[i]).checked&&usertypelist.indexOf(allusers[i])==-1) usertypelist.push(allusers[i]);
			else
			{
				var index=usertypelist.indexOf(allusers[i]);
				if(!document.getElementById(allusers[i]).checked&&index>=0) usertypelist.splice(index,1);
			}
		}
		div_hide("right_info");
		div_show("right_map");
		layer.reload(true,false,false,false);
		layer.map.writebreadcrump();
	}
}
/**
 * Reload the kml overlays of the current layer.
 */
layerobj.prototype.reload=function(item,zone,overlap,diagram)
{
	if(item&&this.item)
	{
		for(var i=0;i<this.item.list.length;i++) this.map.googlemap.removeOverlay(this.item.list[i].data);
		if(this.kml[0]) this.constructitems(this.kml[0]);
	}
	if(zone&&this.zone)
	{
		for(var i=0;i<this.zone.list.length;i++) this.map.googlemap.removeOverlay(this.zone.list[i].data);
		if(this.kml[1]) this.constructzones(this.kml[1]);
	}
	if(overlap&&this.overlap)
	{
		for(var i=0;i<this.overlap.list.length;i++) this.map.googlemap.removeOverlay(this.overlap.list[i].data);
		if(this.kml[3]) this.constructoverlap(this.kml[1]);
	}
	
	if(diagram&&this.diagram)
	{
		for(var i=0;i<this.diagram.list.length;i++) this.map.googlemap.removeOverlay(this.diagram.list[i].data);
		if(this.kml[4]) this.constructdiagram(this.kml[4]);
	}
}
/**
 * set the itemtype,usertype,zonetype that are displayed on the map according to the actual view. 
 */
layerobj.prototype.settypeids=function()
{
	// use )( to separate the sql select responses.
	var typeids=multiselect(1,"ItemTypeId:viewitemlist:ViewId="+this.map.actualview+
		")(UserTypeId:userzonelist,zone:ZoneTypeId=zone.TypeId and zone.Id="+this.zoneid+
		")(ZoneTypeId:viewzonelist:ViewId="+this.map.actualview).split(")(");
		
	this.itemtypelist=typeids[0].split(",");
	this.usertypelist=typeids[1].split(",");
	this.zonetypelist=typeids[2].split(",");
}

/** 
 * @fileoverview Definition of mapobj with all methods and also
 * the definition of some additional googlemap control objects.
 *
 * @author Michael Moos mm@ase.ch
 * @version 2.0 
 */
/*----------------------------------------------------------------------------------------------------------------------------------------mapobj-*/
/**
 * @class Constructs a new map object. The GoogleMap object is a property of mapobj.
 * @constructor
 * @param divname The id tag of the target div for the googlemap.
 * @param view initial view. Refers to the Id of the 'view' table in the database.
 */
function mapobj(divname,view)
{
	//properties
	this.selitem=0;
	this.moved=0;
	this.layerlist=new Array();
	this.hiddenlist=new elementlistobj();
	//googlemap initialization
	this.googlemap=new GMap2(document.getElementById(divname));
	this.googlemap.setMapType(G_SATELLITE_MAP);
	this.googlemap.addControl(new GSmallMapControl());
	this.googlemap.addControl(new GMapTypeControl());
	this.googlemap.addControl(new TextualZoomControl());
	this.googlemap.addControl(new GTextField());
	this.googlemap.enableContinuousZoom();
	//view initialization
	this.views=sqlselect(1,"Id,Name","view","1","Seq").split(",");
	if(view) this.actualview=view; else this.actualview=this.views[0];
}
/**
 * Clears the current map and loads a new one.
 * @param zoneid Id of the new zone to load.
 */
mapobj.prototype.loadmap=function(zoneid)
{
	//*remove all elements from the map and delete all layers
	if(this.layerlist.length) { var currentid=this.layerlist[0].zoneid; this.layerlist.length=0; }
	this.clearmap();
	//*add a new layer with the given zoneid and refresh the breadcrump
	if(this.addlayer(zoneid)) { if(currentid) this.loadmap(currentid); return; }
	var newlayer=this.layerlist[this.layerlist.length-1];
	this.writebreadcrump();
	//*set the bounds according to the added layer 
	this.setbounds(newlayer);
	this.zonename=newlayer.zonename;
	writeHTML(this.zonename,"tfield");	
	writeHTML("","ShopInfo");
}
/**
 * Clears the given zone and displays its content instead.
 * @param zoneid Id of the zone to expose.
 */
mapobj.prototype.exposezone=function(zoneid)
{
	//*find the map element with the given zoneid
	var element=0;
	var nlayer=this.layerlist.length;
	for(var i=0;i<nlayer&&!element;i++)
	{
		if(this.layerlist[i].zone) for(var j=0;j<this.layerlist[i].zone.list.length;j++) if(this.layerlist[i].zone.list[j].key==zoneid)
		{
			element=this.layerlist[i].zone.list[j];
			break;	
		}
		if(this.layerlist[i].overlap&&!element) for(var j=0;j<this.layerlist[i].overlap.list.length;j++) if(this.layerlist[i].overlap.list[j].key==zoneid)
		{
			element=this.layerlist[i].overlap.list[j];
			break;	
		}
	}
	//*if not found, load a new map with the given zoneid and return
	if(!element) { this.loadmap(zoneid); return; }
	//*exit all layers with index greater than the layer containing the given zoneid 
	while(i<nlayer) { this.exitlayer(true); i++; }
	//*hide the element with the given zoneid	
	this.hide(element);
	//*add a new layer with the given zoneid and refresh the breadcrump
	if(this.addlayer(zoneid)) { this.unhide(); return -1; }
	var newlayer=this.layerlist[this.layerlist.length-1];
	this.writebreadcrump();
	//*set the bounds according to the added layer 
	this.setbounds(newlayer);
	this.zonename=newlayer.zonename;
	writeHTML("","ShopInfo");
	
	return 0;
}
/**
 * Removes current layer and unhides the top layer of the hiddenlayer stack.
 * If the current layer was the only one, load the current parentzone.
 * @param multiple If not set, rewrite the breadcrump and reset the bounds.
 * Is set if more than one layer is exited at once.
 */
mapobj.prototype.exitlayer=function(multiple)
{
	var zoneid=this.layerlist[this.layerlist.length-1].zoneid;
	if(this.layerlist.length>1)
	{
		this.removelayer();
		this.unhide();
		if(!multiple)
		{
			this.writebreadcrump();
			this.setbounds(this.layerlist[this.layerlist.length-1]);
			this.zonename=this.layerlist[this.layerlist.length-1].zonename;
			writeHTML(this.zonename,"tfield");	
			writeHTML("","ShopInfo");
		}
	}
	else
	{
		var parentdata=sqlselect(1,"HasLayers,zone.ParentId as ParentId,zone1.ParentId as ParentId1","zonetype as zonetype1,zone,zone as zone1",
			"zone.ParentId=zone1.Id and zone1.TypeId=zonetype1.Id and zone.Id="+zoneid).split(",");
		if(parentdata[0]==1)var parentid=parentdata[2]; else var parentid=parentdata[1];
		if(parentid) this.loadmap(parentid);
	}
}
/**
 * Creates a new marker on the map.
 * @param layer Pointer to the target layer.
 * @param coords Coordinates of the marker.
 * @param code ItemCode of the marker.
 * @param icon GIcon() object.
 * @return pointer to the created marker. 
 */
mapobj.prototype.createmarker=function(layer,coords,code,icon)
{
	var map=this;
	var marker=new GMarker(coords,icon); 
	layer.bounds.extend(coords);

	GEvent.addListener(marker, "mouseout", function()
	{
		if(!map.selitem)
		{
			marker.setImage("img/punkt8x8.png");
			writeHTML("","DiagramInfo")
		}
	});
	GEvent.addListener(marker, "click", function()
	{
		if(map.selitem) map.selitem.setImage("img/punkt8x8.png");
		marker.setImage("img/punkt8x8_gelb.png");
		map.selitem=marker;
		map.moved=0;
		showinfo(code);
	});
	GEvent.addListener(marker, "mouseover", function()
	{
		if(!map.selitem)
		{
			marker.setImage("img/punkt8x8_blau.png");
			showinfo(code);
		}
	});
	this.googlemap.addOverlay(marker);
	
	return marker;
}

/**
 * Creates a new Diagram marker on the map.
 * @param layer Pointer to the target layer.
 * @param coords Coordinates of the marker.
 * @param code ItemCode of the marker.
 * @param icon GIcon() object.
 * @return pointer to the created marker. 
 */
mapobj.prototype.createDiagramMarker=function(layer,coords,freqId,icon)
{
	var map=this;
	var marker=new GMarker(coords,icon); 
	layer.bounds.extend(coords);

	GEvent.addListener(marker, "mouseout", function()
	{
		if(!map.selitem)
		{
			marker.setImage("img/flag_black.png");
			div_show("ShopInfo");
			writeHTML("","DiagramInfo");
			div_hide("DiagramInfo");
			div_hide("right_map2");
			
		}
	});
	GEvent.addListener(marker, "click", function()
	{
		if(map.selitem) map.selitem.setImage("img/flag_black.png");
		marker.setImage("img/flag_gruen.png");
		map.selitem=marker;
		map.moved=0;
		showDiagramList(freqId);
	});
	GEvent.addListener(marker, "mouseover", function()
	{
		if(!map.selitem)
		{
			marker.setImage("img/flag_gelb.png");
			showDiagramInfo(freqId);
		}
	});
	this.googlemap.addOverlay(marker);
	
	return marker;
}

/**
 * Creates a new polygon on the map.
 * @param layer Pointer to the target layer.
 * @param style Style information of the polygon.
 * @param code Code of the polygon. If !undefined, the polygon is clickable.
 * @param element elementobj with (Id,Name) of the zone that the polygon represents.
 */
mapobj.prototype.createpolygon=function(layer,polygonelement,style,code,element)
{	
	var pts=new Array();
	var map=this;

	// Bearbeitet den String mit den Koordinaten und speichert sie in das array loc //
	locstr=polygonelement.getElementsByTagName("coordinates")[0].textContent;
	if(locstr==undefined) locstr=polygonelement.getElementsByTagName("coordinates")[0].childNodes[0].nodeValue; // IE Hack
	
	locstr=locstr.replace(/\s+/g," "); // tidy the whitespace
	locstr=locstr.replace(/^ /,"");	 // remove possible leading whitespace
	locstr=locstr.replace(/ $/,"");	 // remove possible leading whitespace
	//locstr=locstr.replace(/, /,",");	// tidy the commas
	var loc=locstr.split(" ");
	
	// speichert die Punkte in loc als Koordinaten in pts und erweitert bounds //	
	for (var p=0; p<loc.length; p++)
	{
		bits=loc[p].split(",");
		pts[p]=new GLatLng(parseFloat(bits[1]),parseFloat(bits[0]));
		layer.bounds.extend(pts[p]);
	}
	// erstellt die Polygone //
	var polygon=new GPolygon(pts,style.linecolor,1,1,style.fillcolor,style.fillopa);
	if(code!=undefined)
	{
		if(element!=undefined)
		{
		  	GEvent.addListener(polygon, "mouseover", function() { writeHTML(element.data,"tfield"); });
		  	GEvent.addListener(polygon, "mouseout",  function()	{ writeHTML(map.zonename,"tfield"); });
		  	GEvent.addListener(polygon, "click", function()
		  	{
		  		if(element.key) map.exposezone(element.key);
		  		else alert("keine Daten");
		  	});
		}
	}
	this.googlemap.addOverlay(polygon);
	
	return polygon;
}
/**
 * Refreshes the breadcrump.
 */
mapobj.prototype.writebreadcrump=function()
{
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
	
	var zoneids=new staobj(),usertypes=new staobj(undefined,"/"),zonetypes=new staobj(undefined,"/");
	for(var i=0;i<this.layerlist.length;i++)
	{
		zoneids.add(this.layerlist[i].zoneid);
		zonetypes.add(this.layerlist[i].zonetypelist);
		usertypes.add(this.layerlist[i].usertypelist);
	}
	
	var reqstr="breadcrump.php?vi="+this.actualview+"&id="+zoneids.value+"&zo="+zonetypes.value+"&us="+usertypes.value;
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);

	writeHTML(xmlHttp.responseText,"breadcrump");
}  
/**
 * Delete all currently loaded layers of the map.
 */
mapobj.prototype.clearmap=function()
{
	this.layerlist.length=0;
	GEvent.clearListeners(this.googlemap,"mousemove");
	this.googlemap.clearOverlays();
}
/**
 * Add a new layer to the map.
 * @param zoneid Id of the zone of the new layer.
 */
mapobj.prototype.addlayer=function(zoneid)
{
	var newlayer=new layerobj(this,zoneid);
	if(newlayer.load()) return -1;
	this.layerlist.push(newlayer);
	
	return 0;
}
/**
 * Delete the last layer of the layerlist. Because the layerlist can be
 * regarded as a stack, this is a pop operation.
 */
mapobj.prototype.removelayer=function()
{
	var ll=this.layerlist[this.layerlist.length-1];
	var zoneid=ll.zoneid;
	if(ll.item) for(var i=0;i<ll.item.list.length;i++)    this.googlemap.removeOverlay(ll.item.list[i].data);
	if(ll.zone) for(var i=0;i<ll.zone.list.length;i++)    this.googlemap.removeOverlay(ll.zone.list[i].data);
	if(ll.design) for(var i=0;i<ll.design.list.length;i++)  this.googlemap.removeOverlay(ll.design.list[i].data);
	if(ll.overlap) for(var i=0;i<ll.overlap.list.length;i++) this.googlemap.removeOverlay(ll.overlap.list[i].data);
	this.layerlist.length--;
	this.selitem=0;
	
	return zoneid;
}
/**
 * Set the current bounds to the the bounds of the given layer.
 * @param layer layer with the new bounds.
 */
mapobj.prototype.setbounds=function(layer)
{
	if(this.googlemap.getBoundsZoomLevel(layer.bounds)>17) this.googlemap.setCenter(layer.bounds.getCenter(),17);
	else this.googlemap.setCenter(layer.bounds.getCenter(),this.googlemap.getBoundsZoomLevel(layer.bounds));
}
/**
 * Replace the last layer of the layerlist with a new one.
 * @param newid Id of the zone of the new layer.
 */
mapobj.prototype.exchangelayer=function(newid)
{
	var lastid=this.removelayer();
	if(this.addlayer(newid)) this.addlayer(lastid);
	this.writebreadcrump();
	writeHTML("","ShopInfo");
}
/**
 * Unhide the last layer of the hiddenlist.
 */
mapobj.prototype.unhide=function()
{
	var element=this.hiddenlist.list[this.hiddenlist.list.length-1];
	element.data.show();
	this.hiddenlist.list.length--;
}
/**
 * Hide target element (usually a polygon that represents a zone) and
 * add it to the hiddenlist.
 * @param element element to be hidden. 
 */
mapobj.prototype.hide=function(element)
{
	element.data.hide();
	this.hiddenlist.list.push(element);
}
/**
 * Select an item on the map.
 * @param itemcode Sets the selitem variable of the map.
 */
mapobj.prototype.selectitem=function(itemcode)
{
	for(var j=0;j<this.layerlist.length;j++) if(this.layerlist[j].item)
	{
		var layeritemlist=this.layerlist[j].item.list;
		for(var i=0;i<layeritemlist.length;i++) {if(layeritemlist[i].key==itemcode) break;}
		if(i<layeritemlist.length)
		{
			if(this.selitem) this.selitem.setImage("img/punkt8x8.png");
			layeritemlist[i].data.setImage("img/punkt8x8_gelb.png");
			this.selitem=layeritemlist[i].data;
			this.moved=0;
			showinfo(itemcode);
			break;
		}
	}
}
/**
 * Reload current layer. If the layer can not be load anymore (due to
 * a change of the current view), exit it and reload the previous layer
 * of the layerlist (recursive).
 */
mapobj.prototype.reloadlayer=function()
{
	var lastid=this.layerlist[this.layerlist.length-1].zoneid;
	this.exitlayer(true);
	while(this.exposezone(lastid))
	{
		lastid=this.layerlist[this.layerlist.length-1].zoneid;
		this.exitlayer(true);
	}
	this.writebreadcrump();
	writeHTML("","ShopInfo");
}
/**
 * Change the view and reload the current layer.
 * @param id Id of the new view.
 */
mapobj.prototype.changeview=function(id)
{
	var disp="<ul id='navigation'>";
	for(var i=0;i<this.views.length;i+=2)
	{
		if(this.views[i]==id) disp+="<li><div class='navButtonActive'><span>"+this.views[i+1]+"</span></div></li>";
		else disp+="<li><a href='#' onclick='globalmap.changeview("+this.views[i]+")' class='navButtonInactive'><span>"+this.views[i+1]+"</span></a></li>";
	}
	writeHTML(disp,"navi");
	this.actualview=id;
	this.reloadlayer();
}
/*----------------------------------------------------------------------------------------------------------------------------------googlemapobj-*/
function GTextField() { } GTextField.prototype=new GControl();
GTextField.prototype.initialize=function(googlemap)
{
	var container=document.createElement("div");
	var TField=document.createElement("div");

	TField.id="tfield";
	TField.style.backgroundColor="white";
	TField.style.width="200px";
	TField.style.height="12px";
	TField.style.padding="2px";
	TField.style.border="1px solid black";

	container.appendChild(TField);
	googlemap.getContainer().appendChild(container);

	return container;
}
GTextField.prototype.getDefaultPosition=function()
{
	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(68, 4));
}
// A TextualZoomControl is a GControl that displays textual "Zoom In"
// and "Zoom Out" buttons (as opposed to the iconic buttons used in
// Google Maps).
// Creates a one DIV for each of the buttons and places them in a container
// DIV which is returned as our control element. We add the control to
// to the map container and return the element for the map class to
// position properly.
function TextualZoomControl() { } TextualZoomControl.prototype=new GControl();
TextualZoomControl.prototype.initialize=function(googlemap)
{
	var container=document.createElement("div");
	var zoomOutDiv=document.createElement("div");
	var image=document.createElement("img");
	image.setAttribute( "src", "img/return.png" );
	this.setButtonStyle_(zoomOutDiv);
	container.appendChild(zoomOutDiv);
	zoomOutDiv.appendChild(image);
	GEvent.addDomListener(zoomOutDiv, "click", function() { globalmap.exitlayer(); });
	googlemap.getContainer().appendChild(container);
	
	return container;
}
// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
TextualZoomControl.prototype.getDefaultPosition=function()
{
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(50, 7));
}
// Sets the proper CSS for the given button element.
TextualZoomControl.prototype.setButtonStyle_=function(button)
{
	//button.style.textDecoration="underline";
	button.style.color="#000000";
	button.style.backgroundColor="white";
	button.style.font="small Arial";
	button.style.border="1px solid black";
	button.style.padding="2px";
	button.style.marginBottom="3px";
	button.style.textAlign="center";
	button.style.width="2em";
	button.style.cursor="pointer";
}
/** 
 * @fileoverview Definition of several global methods including initialize,
 * which is the initialization of the whole application
 *
 * @author Michael Moos mm@ase.ch
 * @version 2.0 
 */
var globalmap;
var globalopt=new Object();


function userdetails(userid,itemcode)
{
	var xmlHttp,reqstr;

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
	reqstr="shopdetails.php?id="+userid+"&code="+itemcode;
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);
	writeHTML(xmlHttp.responseText,"right_info");
}

function shopdetails(userid,itemcode)
{
	var ids=userid.split(",");
	
	div_hide("right_map");
	div_show("right_info");
	
	if(ids.length==1) userdetails(userid,itemcode)
	else
	{
		var disp="<div style='padding:100px;'><span class='big'><p>Dieses Objekt hat mehrere Anbieter:</p>";
		var names=sqlselect(1,"Name","user","Id in ("+userid+")","Name").split(",");
		for(var i=0;i<ids.length;i++) disp+="<li><a href='#' onclick='userdetails("+ids[i]+",\""+itemcode+"\")'>"+names[i]+"</a></li>";
		disp+="</span></div>";
		writeHTML(disp,"right_info");
	}
}

function geturl(option)
{
	var layerlist=globalmap.layerlist;
	var xmlHttp=GetXmlHttpObject();
	var zoneids=new staobj();

	for(var i=0;i<layerlist.length;i++) zoneids.add(layerlist[i].zoneid);
	if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
	var reqstr="getsecurl.php?id="+zoneids.value;
	if(globalmap.selitem)
	{
		for(var i=0,key=0;i<layerlist.length&&!key;i++) if(layerlist[i].item)
		{
			for(j=0;j<layerlist[i].item.list.length;j++) if(layerlist[i].item.list[j].data==globalmap.selitem)
			{
				key=layerlist[i].item.list[j].key;
				reqstr+="&se="+key;
				break;
			}
		}
	}
	var center=globalmap.googlemap.getCenter();
	reqstr+="&vi="+globalmap.actualview;
	reqstr+="&br="+globalopt.brand;
	reqstr+="&zoom="+globalmap.googlemap.getZoom();
	reqstr+="&lat="+center.lat();
	reqstr+="&lng="+center.lng();
	if(option!=undefined) reqstr+="&"+option;
	
	return reqstr;
}

function reload(content)
{
	if(content=="reload")
	{
		var xmlHttp,reqstr;
		
		reqstr=geturl();
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
		xmlHttp.open("GET",reqstr,false);
		xmlHttp.send(null);
		window.location="index.php?"+xmlHttp.responseText;
	}
	else if(content=="geturl")
	{
		window.location=geturl();	
	}
	else if(content=="map")
	{
		div_hide("right_info");
		div_show("right_map");
		div_hide("left_info");
		div_show("left_map");
	}
	else if(content=="info")
	{
		writeHTML(
			"<div class='contentBlockHead'>"+
			"	<h2 class='block'>Fakten</h2>"+
			"</div>"+
			"<div class='contentBlockNormal'>"+
			"	<h3 class='block'>Gr&uuml;ndung:</h3>"+
			"	<p>2009</p>"+
			"	<h3 class='block'>Entwickelt von:</h3>"+
			"	<p><a href='http://www.markimo.ch'>Markimo</a></p>"+
			"	<h3 class='block'>in Zusammenarbeit mit:</h3>"+
			"	<p><a href='http://www.ase.ch'>ASE GmbH</a></p>"+
			"</div>","left_info");
		div_hide("left_map");
		div_show("left_info");
		writeHTML(
			"<div id='staticContent'>"+
			"	<h1>Willkommen auf der Startseite von</h1>"+
			"	<h2>www.shoppingareas.ch</h2>"+
			"	<p>Wo alle Ladengeschäfte in deren Umfeld übersichtlich präsentiert werden.</p>"+
			"	<p>Wählen Sie das Land, dann die Stadt, und auf der Karte oder auf der Liste das Gebiet und dann die Flanierzone."+
			"	Es werden hier alle Ladengeschäfte mit ihrer Ladentüre abgebildet.</p>"+
			"	<p>Mit Klicken auf den Namen des Ladengeschäftes oder auf den Punkt bei der Ladentüre erscheint das Bild des Ladengeschäftes.</p>"+
			"	<p>Mit Klicken auf das Bild des Ladengeschäftes erscheint dieses in Grossformat, mit weiteren Informationen sofern verfügbar.</p>"+
			"</div>","right_info");
		div_hide("right_map");
		div_show("right_info");
	}
	else if(content=="kontakt")
	{
		writeHTML("<div class='contentBlockHead'></div>","left_info");
		div_hide("left_map");
		div_show("left_info");
		writeHTML(
			"<div id='staticContent'>"+
			"	<h1>markimo ag</h1>"+
			"	<p>Immobilien.Standorte.Positionierung<br>Höschgasse 50<br>CH-8034 Zürich</p>"+
			"	<p>Tel +41 43 336 77 20<br>Fax +41 43 336 77 29<br>Email info@markimo.ch<br><a href='http://www.markimo.ch' target='_blank'>www.markimo.ch</a></p>"+
			"	<h2>Offertanfrage</h2>"+
			"	<h3>Der Ort als Produkt</h3>"+
			"	<p>markimo hat eine Methodik erarbeitet, mit welcher Standorte und ihre Nutzungen "+
			"	als marktorientierte Gebiete definiert, analysiert, georeferenziert dargestellt und auf "+
			"	dem Web publiziert werden können. Wir analysieren die Flows (Passanten, Cash Flow, Logistik),"+ 
			"	die Community und die Atmosphäre  in den lokalen Clustern als Basis für die Interpretation"+
			"	von Trends und für die Erarbeitung von Entwicklungsstrategien.</p>"+
			"	<p>markimo offeriert Web-Präsentationen für Standorte und Anbieter."+ 
			"	Es ist eine fugenlose Integration in die Web-Publikationen von Kooperationspartnern"+ 
			"	und ein Marktauftritt für die Angebote und Projekte der Anbieter am Standort möglich."+
			"	Der Zugang zu speziellen Informationen lässt sich auf Anbietergruppen beschränken.</p>"+
			"	<p>Gerne stellen wir unser Know-how auch für Ihre spezifischen Bedürfnisse zur Verfügung.</p>"+
			"	<h2>Medienkontakt</h2><p>Für Medienauskünfte steht Ihnen Herr Christoph Ackeret zur Verfügung.</p>"+
			"	<p><a href='mailto:christoph.ackeret@markimo.ch'>christoph.ackeret@markimo.ch</a></p>"+
			"	<p>Telefon  +41 43 336 77 27</p>"+
			"</div>","right_info");
		div_hide("right_map");
		div_show("right_info");
	}
	else if(content=="login")
	{
		writeHTML(
			"<div id='staticContent'>"+
				"<p><a href='#' onclick='reload(\"map\")' style='float:left;'>"+
					"<img class='linkIcon' src='img/iconMap.jpg'/>"+
					"<span class='big'>Zur&uuml;ck zur Kartenansicht</span>"+
				"</a></p>"+
				"<p><form action='index.php' method='post'><table border=0>"+
				"<tr><td><span class='large'>Benutzer:</span></td><td><input type='text' name='user'></td></tr>"+
				"<tr><td><span class='large'>Passwort:</span></td><td><input type='password' name='pass'></td></tr><tr><td></td>"+
				"<td><input type='submit' name='senden' value=Login></td></tr></table></form></p>"+
			"</div>","right_info");
		div_hide("right_map");
		div_show("right_info");
	}
	else if(content=="logout")
	{
		var xmlHttp,reqstr;
		
		reqstr=geturl("logout");
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
		xmlHttp.open("GET",reqstr,false);
		xmlHttp.send(null);
		window.location="index.php"+xmlHttp.responseText;
	}
}

function showinfo(id)
{
	var xmlHttp,reqstr;

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
	
	reqstr="front.php?code="+id;
	
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);

	writeHTML(xmlHttp.responseText,"ShopInfo");
}

/**
 * function showDiagramInfo
 * 
 * @param 	freq_id; the frequency-Id
 * @return  xmlHttp.responseText
 * @desc	Send the frequency-Id to "dev.diagramInfo.app.php" 
 * 			and displays the Server response Text from this PHP-Side
 */
function showDiagramInfo(freq_id)
{
	var xmlHttp,reqstr;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
	
	reqstr="dev.diagramInfo.app.php?freqId="+freq_id;
	
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);
	
	div_hide("ShopInfo");
	div_show("DiagramInfo");
	div_show("right_map2");
	
	writeHTML(xmlHttp.responseText,"DiagramInfo");
}

/**
 * function showDiagramList
 * 
 * @param 	freq_id; the frequency-Id
 * @return  xmlHttp.responseText
 * @desc	Send the frequency-Id to "dev.diagramList.app.php" 
 * 			and displays the Server response Text from this PHP-Side	
 */
function showDiagramList(freq_id)
{
	var xmlHttp,reqstr;

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }
	
	reqstr="dev.diagramList.app.php?freqId="+freq_id;
	
	xmlHttp.open("GET",reqstr,false);
	xmlHttp.send(null);
	
	div_hide("right_map");
	div_hide("DiagramInfo");
	div_show("DiagramList");
	writeHTML(xmlHttp.responseText,"DiagramList");
}

function printview()
{
	div_hide("left_map");
		
	var tmp=sqlselect(1,"item.Code,itemtype.Name,user.Name,user.Store,zone.Name",
		"(((item left join useritemlist on item.Id=useritemlist.ItemId) left join user on useritemlist.UserId=user.Id) "+
		"left join zone on item.ZoneId=zone.Id) left join itemtype on item.TypeId=itemtype.Id",
		"zone.Id="+globalmap.layerlist[globalmap.layerlist.length-1].zoneid,
		"item.Code").split(",");
		
	var disp="<table id='printuser'>";;
	for(var i=0;i<tmp.length;i+=5)
	{
		disp+="<tr><td>"+tmp[i]+"</td><td>"+tmp[i+1].code2comma()+"</td><td>"+tmp[i+2].code2comma()+"</td><td>"+
			tmp[i+3].code2comma()+"</td><td>"+tmp[i+4].code2comma()+"</td></tr>";
	}
	disp+="</table>";
	
	writeHTML(disp,"ShopInfoHead");
}

function initialize(zoneid,brandpar,select,view,zoom,lat,lng)
{
	//*adapt given parameters
	globalopt.brand=brandpar;
	//*create a new googlemap 
	globalmap=new mapobj("MapInfo",+view);
	
	//*if initial position given, navigate to it else load the supreme zone
	if(zoneid)
	{
		zoneid=zoneid.split(",");
		globalmap.loadmap(zoneid[0]);
		for(var j=1;j<zoneid.length;j++)
		{
			globalmap.exposezone(zoneid[j]);
		}
		globalmap.writebreadcrump();
	}
	else globalmap.loadmap(sqlselect(1,"Id","zone","ParentId is null"));
	//*if asked for, select a given entry and set the current position of the googlemap
	if(select) globalmap.selectitem(select);
	if(zoom&&lat&&lng) globalmap.googlemap.setCenter(new GLatLng(lat,lng),+zoom);
}




