// JavaScript Document

boby1 = new variable(0);
boby2 = new variable(0);
boby3 = new variable(0);
boby1b = new variable(0);
dadoc = new variable('a');
var cmarkers = [];
var hmarkers = [];
var cmarkersb = [];
var hmarkersb = [];

function variable(x)
{
  this.x=x;
}

function loadmap()
{
	var map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(48.2098166666667, 4.494525), 15);	
	while(boby2.x>0)
	{
		var vfrom=document.getElementById('right');
		var vgonea=eval("document.getElementById('ted"+boby2.x+"')");
		var vgoneb=eval("document.getElementById('lasy"+boby2.x+"')");
		vfrom.removeChild(vgonea);
		vfrom.removeChild(vgoneb);
		boby2.x--;
	}
	GEvent.addListener(map,"click",function cheese(marker, platform_id, point,strhtml) 
	{  
		if (marker&&boby1.x==1)	{map.removeOverlay(marker);	}
		else if(boby1.x==1) 
		{
			boby2.x++;
			var ted=document.createElement("<input type='button'/>");
			ted.id = 'ted'+boby2.x;
			document.getElementById('right').appendChild(ted);
			var jill=eval("document.getElementById('ted"+boby2.x+"')");
			ted.value = platform_id  //"marker"+boby2.x;
			ted.style.width="100px";
			
			var lasy=document.createElement("textarea");
			lasy.id = 'lasy'+boby2.x;
			document.getElementById('right').appendChild(lasy);
			var joly=eval("document.getElementById('lasy"+boby2.x+"')");
			lasy.style.width="100px";
			joly.value=strhtml
			joly.style.height=0+"px";
			ted.onmouseover=function() {this.style.backgroundColor='#000'; this.style.color='#fff'; map.removeOverlay(cmarkers[this.id.substr(3,2)]); map.addOverlay(hmarkers[this.id.substr(3,2)]); }
			ted.onmouseout=function() {this.style.backgroundColor=''; this.style.color=''; map.removeOverlay(hmarkers[this.id.substr(3,2)]); map.addOverlay(cmarkers[this.id.substr(3,2)]); }
			map.addOverlay(createMarker(point,boby2.x,strhtml));
		} 
	});
boby1.x=1;
initTraverse("testxml.xml");
tree = dadoc.x;

var nodes=tree.childNodes.length;
for(var i=0; i<tree.childNodes.length; i++) 
{
	if(tree.hasChildNodes()) 
	{
		treeb = tree.childNodes(i);
		//alert(treeb.tagName);
        if(treeb.tagName=='name')
		{
			var lnname = treeb.text;
		}
		else if(treeb.tagName=='locationx')
		{
			var lnlocationx = treeb.text;
		}
		else if(treeb.tagName=='locationy')
		{
			var lnlocationy = treeb.text;
            cheese(0, lnname, new GLatLng(lnlocationx,lnlocationy),"<p>Platform ID: 008<br/>Lat: 048 12.5890<br/>Lon: 004 29.6715</p>");
		}
	}
}
boby1.x=0;
setTimeout('loadmap();',10001);
}

var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

function loadXML(xmlFile) {
        xmlDoc.async="false";
        xmlDoc.onreadystatechange=verify;
        xmlDoc.load(xmlFile);
}

function verify() { 
        if(xmlDoc.readyState!=4)
                return false; 
}

function initTraverse(file) {
        loadXML(file);
        var doc=xmlDoc.documentElement;
        dadoc.x = doc;
}


/*
cheese(0, 'CLARION (008)', new GLatLng(48.2098166666667, 4.494525),"<p>Platform ID: 008<br/>Lat: 048 12.5890<br/>Lon: 004 29.6715</p>");
cheese(0, 'RHUM (007)', new GLatLng(48.25915, 4.47985333333333),"<p>Platform ID: 007<br/>Lat: 048 15.5490<br/>Lon: 004 28.7912</p>");
cheese(0, 'MISTY (006)', new GLatLng(48.24045, 4.52039333333333),"<p>Platform ID: 006<br/>Lat: 048 14.4270<br/>Lon: 004 31.2236</p>");
cheese(0, 'MIGHTY MAX (005)', new GLatLng(48.2124166666667, 4.50681333333333),"<p>Platform ID: 005<br/>Lat: 048 12.7450<br/>Lon: 004 30.4088</p>");
cheese(0, 'LADY EMMA (004)', new GLatLng(48.2350333333333, 4.37526166666667),"<p>Platform ID: 004<br/>Lat: 048 14.1020<br/>Lon: 004 22.5157</p>");
cheese(0, 'RACE-TRAX (003)', new GLatLng(48.2463833333333, 4.551765),"<p>Platform ID: 003<br/>Lat: 048 14.7830<br/>Lon: 004 33.1059</p>");
cheese(0, 'NAV-TRAX (002)', new GLatLng(48.2316, 4.446035),"<p>Platform ID: 002<br/>Lat: 048 13.8960<br/>Lon: 004 26.7621</p>");
cheese(0, 'EIRETECH (001)', new GLatLng(48.2081833333333, 4.45841333333333),"<p>Platform ID: 001<br/>Lat: 048 12.4910<br/>Lon: 004 27.5048</p>");
*/

function createMarker(point,number,htmlcode) 
{  
	  var jill=eval("document.getElementById('ted"+boby2.x+"')");
	  var jogy=eval("document.getElementById('lasy"+boby2.x+"')");
      var hotIcon = new GIcon();
      hotIcon.image = "marker.png";
      hotIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
      hotIcon.iconSize = new GSize(20, 34);
      hotIcon.shadowSize = new GSize(37, 34);
      hotIcon.iconAnchor = new GPoint(9, 34);
      hotIcon.infoWindowAnchor = new GPoint(9, 2);
      hotIcon.infoShadowAnchor = new GPoint(18, 25);
    
      var coldIcon = new GIcon(hotIcon);
      coldIcon.image = "coldmarker.png";
	var marker = new GMarker(point,coldIcon);  
	jill.onclick = function() {if(boby1.x==0){killcol(); jogy.style.height=150+"px"; marker.openInfoWindowHtml(htmlcode);}};
	GEvent.addListener(marker, "click", function() {if(boby1.x==0){marker.openInfoWindowHtml(htmlcode); killcol(); jill.style.backgroundColor='#000'; jill.style.color='#fff'; jogy.style.height=150+"px";  }});
	cmarkers[boby2.x] = marker;
	hmarkers[boby2.x] = new GMarker(point,hotIcon);
	return marker;	
}

function loadmapb()
{
	var mapp = new GMap2(document.getElementById("mapp"));
	mapp.addControl(new GSmallMapControl());
	mapp.addControl(new GMapTypeControl());
	mapp.setCenter(new GLatLng(48.2098166666667, 4.494525), 15);	
	GEvent.addListener(mapp,"click",function(marker,pointb,strhtml)
	{  
		if (marker&&boby1b.x==1)	{mapp.removeOverlay(marker);	}
		else if(boby1b.x==1) 
		{
			boby3.x++;
			var tedd=document.createElement("<input type='button'/>");
			tedd.id = 'tedd'+boby3.x;
			document.getElementById('rightt').appendChild(tedd);
			var jill=eval("document.getElementById('tedd"+boby3.x+"')");
			tedd.value = "marker"+boby3.x;
			tedd.style.width="100px";
			
			tedd.onmouseover=function() {this.style.backgroundColor='#000'; this.style.color='#fff'; mapp.removeOverlay(cmarkersb[this.id.substr(4,2)]); mapp.addOverlay(hmarkersb[this.id.substr(4,2)]); }
			tedd.onmouseout=function() {this.style.backgroundColor=''; this.style.color=''; mapp.removeOverlay(hmarkersb[this.id.substr(4,2)]); mapp.addOverlay(cmarkersb[this.id.substr(4,2)]); }

			strhtml = 'point'+boby3.x;
			mapp.addOverlay(createMarkerb(pointb,boby3.x,strhtml));
		} 
	});
//	refreshPlots();
}

function createMarkerb(pointb,number,htmlcode) 
{  
	  var jill=eval("document.getElementById('tedd"+boby3.x+"')");
      var hotIcon = new GIcon();
      hotIcon.image = "marker.png";
      hotIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
      hotIcon.iconSize = new GSize(20, 34);
      hotIcon.shadowSize = new GSize(37, 34);
      hotIcon.iconAnchor = new GPoint(9, 34);
      hotIcon.infoWindowAnchor = new GPoint(9, 2);
      hotIcon.infoShadowAnchor = new GPoint(18, 25);
    
      var coldIcon = new GIcon(hotIcon);
      coldIcon.image = "coldmarker.png";
	var marker = new GMarker(pointb,coldIcon);  
	jill.onclick = function() {if(boby1b.x==0){killcol(); marker.openInfoWindowHtml(htmlcode);}};
	GEvent.addListener(marker, "click", function() {if(boby1b.x==0){marker.openInfoWindowHtml(htmlcode); killcol(); jill.style.backgroundColor='#000'; jill.style.color='#fff';  }});
	cmarkersb[boby3.x] = marker;
	hmarkersb[boby3.x] = new GMarker(pointb,hotIcon);
	return marker;	
}

function killcol()
{
for(i=1;i<=boby2.x;i++)
{
var lucy=eval("document.getElementById('ted"+i+"')");
lucy.style.backgroundColor=''; 
lucy.style.color='';
var jogy=eval("document.getElementById('lasy"+i+"')");
jogy.style.height=0+"px";
}	
}


function switchmarker(onoff)
{
	if(onoff=='on')
	{
		boby1b.x=1
	}
	else
	{
		boby1b.x=0
	}
}