
    var iconPlane = new GIcon(); 
    iconPlane.image = '/icon/plane.png';
    iconPlane.shadow = '/icon/plane.shadow.png';
    iconPlane.iconSize = new GSize(16, 20);
    iconPlane.shadowSize = new GSize(22, 20);
    iconPlane.iconAnchor = new GPoint(6, 20);
    iconPlane.infoWindowAnchor = new GPoint(5, 1);

    var iconRed = new GIcon(); 
    iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
    iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRed.iconSize = new GSize(8, 10);
    iconRed.shadowSize = new GSize(11, 10);
    iconRed.iconAnchor = new GPoint(6, 20);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

    var iconGreen = new GIcon(); 
    iconGreen.image = 'http://labs.google.com/ridefinder/images/mm_20_green.png';
    iconGreen.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconGreen.iconSize = new GSize(6, 10);
    iconGreen.shadowSize = new GSize(11, 10);
    iconGreen.iconAnchor = new GPoint(6, 20);
    iconGreen.infoWindowAnchor = new GPoint(5, 1);

    var iconBlue = new GIcon(); 
    iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(8, 10);
    iconBlue.shadowSize = new GSize(11, 10);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);


    var customIcons = [];
    customIcons["airfield"] = iconRed;
    customIcons["cairfield"] = iconPlane;
    customIcons["cstrip"] = iconPlane;
    customIcons["strip"] = iconGreen;
    

    var markerGroups = { "airfield": [], "strip": [], "cairfield": [], "cstrip": []};

var map;

    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addMapType(G_PHYSICAL_MAP);
        map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
		map.addControl(new MapCursorControl());//custom map and graticule selector
		map.addOverlay(new LatLonGraticule()); 
        map.setCenter(new GLatLng(47, 3.5), 6);
        map.enableScrollWheelZoom();
		map.enableDoubleClickZoom();
        //map.setMapType(G_HYBRID_MAP);
        map.setMapType(G_PHYSICAL_MAP);

     
        GDownloadUrl("/php/phpsqlajax_genxml.php", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var id = markers[i].getAttribute("id");
            var name = markers[i].getAttribute("name");
            var airfield_code = markers[i].getAttribute("airfield_code");
            var descr = markers[i].getAttribute("description");
			var PPRContact = markers[i].getAttribute("PPRContact");
			var email = markers[i].getAttribute("email");
            var url = markers[i].getAttribute("url");
            var type = markers[i].getAttribute("type");
			var type_description = markers[i].getAttribute("type_description");
            var author = markers[i].getAttribute("author");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
			var lat = markers[i].getAttribute("lat");
			var lng = markers[i].getAttribute("lng");
			var ddmmss = markers[i].getAttribute("ddmmss");
            var imgWidth = markers[i].getAttribute("imgWidth");
            var imgHeight = markers[i].getAttribute("imgHeight");
            var fir = markers[i].getAttribute("fir");
            var bria = markers[i].getAttribute("bria");
            var siv = markers[i].getAttribute("siv");
            var additions = markers[i].getAttribute("additions");
            var notes = markers[i].getAttribute("notes");
            var AIRAC = markers[i].getAttribute("AIRAC");

			var caution = markers[i].getAttribute("caution");
			var remarks = markers[i].getAttribute("remarks");
			var email = markers[i].getAttribute("email");
			var PPRContact = markers[i].getAttribute("PPRContact");
			var circuits = markers[i].getAttribute("circuits");
			var elevation = markers[i].getAttribute("elevation");
			var accommodation = markers[i].getAttribute("accommodation");
			var radio_freq = markers[i].getAttribute("radio_freq");
			var radio_freq_type = markers[i].getAttribute("radio_freq_type");


            var runways = markers[i].getElementsByTagName("Runway");
			var arrRunways = [];

			for (var r = 0; r < runways.length; r++) {
				var arrRWdata = [];
				arrRWdata[0] = runways[r].getAttribute("rw_base_identifier");
				arrRWdata[1] = runways[r].getAttribute("rw_far_identifier");
				arrRWdata[2] = runways[r].getAttribute("Length");
				arrRWdata[3] = runways[r].getAttribute("Width");
				arrRWdata[4] = runways[r].getAttribute("Surface");
				arrRWdata[5] = runways[r].getAttribute("Notes");

				arrRunways[r] = arrRWdata;
			}

//			arrRunways[0] = 'Test';
            var marker = createMarker(point, id, name, type, type_description, airfield_code, lat, lng, ddmmss, PPRContact, email, url, author, imgWidth, imgHeight, fir, bria, siv, additions, notes, AIRAC, elevation, radio_freq, radio_freq_type, circuits, arrRunways, caution, remarks);

            map.addOverlay(marker);
          }

//GEvent.trigger(markerGroups['cairfield'][1],"click");

        });
      }
    }

function createMarker(point, id, name, type, type_description, airfield_code, lat, lng, ddmmss, PPRContact, email, url, author, imgWidth, imgHeight, fir, bria, siv, additions, notes, AIRAC, elevation, radio_freq, radio_freq_type, circuits, arrRunways, caution, remarks) {

	if(author.length == 0){
		var icontype = type; }
	else {
		var icontype = "c" + type; }

	var marker = new GMarker(point, customIcons[icontype]);
	markerGroups[icontype].push(marker);

	var html = "<html><head></head><body>";

//	html = html +  "<b>" + name  + " (" + airfield_code + ")</b><br>";

//	if(imgWidth > 0){ 
//		html = html + "<center><br><img src=/flying/get_map_image.php?inum=" + id + " width=\"" + imgWidth + "\" height=\"" + imgHeight + "\" alt=\"Airfield image\"><br>";}

	html = html + "<table border=\"1\" class=\"fpltable\">";

	html = html +  "<tr><th colspan=\"4\">" + name  + " (" + airfield_code + ")</th></tr>";

	////
	html = html + "<tr><td>" + type_description + "</td>";
	html = html + "<td><a target=\"_blank\" href=\"http://www.arthurandarthur.co.uk/cgi-bin/awredir.pl?url=http://maps.google.com/?t=k&ll=" + lat + "," + lng + "\" class=\"green\">" + lat + "," + lng + "</a><br />";
	html = html + ddmmss;
	html = html + "</td>\n";

	html = html + "<td colspan=\"2\">";

	if (elevation != "") {
	  html = html +  "Elevation:&nbsp;" + elevation + "'<br />";
	 }

	if (radio_freq != "") {
	  html = html +  "Freq:&nbsp;" + radio_freq;
	 }
	if (radio_freq_type != "") {
	  html = html +  "&nbsp;-&nbsp;" + radio_freq_type;
	 }
	html = html + "</td></tr>";

////
	html = html + "<tr><td colspan=2>";

	if (PPRContact != "") {
		html = html + "Contact:<br />" + PPRContact;
		}

	html = html + "</td><td>";

	if (email != "") {
		html = html + "Email: <a href=\"mailto:" + email + "\" class=\"green\">" + email + "</a>";
		}
	html = html + "</td>";


	html = html + "<td colspan=2>Links:<br />";

	if(type == "airfield"){
		html = html + "<a href=\"http://www.arthurandarthur.co.uk/cgi-bin/awredir.pl?url=http://www.sia.aviation-civile.gouv.fr/aip/enligne/PDF_AIPparSSection/VAC/AD/2/" + AIRAC + "_AD-2." + airfield_code + ".pdf\" target=\"_blank\" class=\"green\">SIA</a>";
	}

	if (url != ""){
		if (type == "airfield") {
			html = html + "&nbsp;:&nbsp;";
			}
		html = html + "<a target=\"_blank\" href=\"" + url + "\" class=\"green\">Airfield</a>";
}

if ((type == "airfield") || (url != "")) {
	html = html + "&nbsp;:&nbsp";
	}

html = html + "<a target=\"_blank\" href=\"http://www.arthurandarthur.co.uk/cgi-bin/awredir.pl?url=http://www.navigeo.org/" + airfield_code + "\" class=\"green\">Navigeo</a>";

html = html + "</td></tr>";

////

	if (circuits != "") {
		html = html + "<tr><td colspan=\"5\" align=left>Circuits: " + circuits + "</td></tr>";
	}

////
	if (arrRunways.length > 0) {
	 	html = html + "<tr><th colspan=\"4\">Runways</th></tr>";

		for (var i=0; i<arrRunways.length; i++) {
			html = html + "<tr><td>" + arrRunways[i][0] + "-" + arrRunways[i][1] + "</td>";
			html = html + "<td>" + Math.round(arrRunways[i][2]) + "m";
			if (arrRunways[i][3] > 0) {
				 html = html + " x " + Math.round(arrRunways[i][3]) + "m";
				}
			html = html + "</td><td>" + arrRunways[i][4] + "</td>";
			html = html + "<td align=left>" + arrRunways[i][5] + "</td>";
			html = html + "</tr>";
		}
	}
////
	html = html + "<tr>";
	if (caution != "") {
		html = html + "<td colspan=\"5\" align=left>" + caution + "</td>";
	html = html + "</tr>";
	}
////
	html = html + "<tr>";
	if (remarks != "") {
		html = html + "<td colspan=\"5\" align=left>" + remarks + "</td>";
		}

	html = html + "</tr>";

////


	html = html + "</table>";


if(fir.length > 0)
	{ 
	html = html + "<br /><table border=\"1\" class=\"fpltable\"><tr><th colspan=\"5\">Flight Plan codes from ";
    html = html + "<a target=\"_blank\" href=\"https://www.sia.aviation-civile.gouv.fr/aip/enligne/fr/..%5CPDF_AIPparSSection%5CAIP%20FRANCE%5CENR%5C1%5C" + AIRAC + "_ENR-1.11.pdf\">SIA AIP ENR1.11</a>";
    html = html + "</th></tr><tr><th>Arriving</th><th>Departing</th><th>FIR</th><th>";
	html = html + "<a target=\"_blank\" href=\"http://www.arthurandarthur.co.uk/flying/get_BRIA_details.php?briaid=" + bria + "\" onClick='showPopup(this.href);return(false);'>BRIA</a></th>";

	html = html + "<th>SIV</th></tr><tr><td>" + airfield_code + "ZTZX</td><td>" + airfield_code + "ZPZX</td><td>" + fir + "ZFZX</td><td>";
	if(bria.length > 0)
		{
		html = html + bria + "ZPZX";
		}
	html = html + "</td><td>";

	if (siv.length > 0)
		{
		html = html + siv + "ZTZX";
		}
	html = html + "</td></tr><tr>";

	if (additions.length > 0)
		{
		html = html + "<td colspan=\"5\">Additional: " + additions;
		if (notes.length > 0)
			{
			html = html + " - " + notes;
			}	
		html = html + "</td>";
		}

	html = html + "</tr></table><br /></body></html>";

}

if(author.length > 0) {
	html = html + "<center>Click to read&nbsp;<a target=\"_blank\" href=\"/php/gaf.php?afid=" + id + "\" class=\"green\">" + author + "'s airfield description</a></center>";
	}

      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html,{maxWidth:550});
      });
      return marker;
    }


function toggleGroup(type) {
    for (var i = 0; i < markerGroups[type].length; i++) {
        var marker = markerGroups[type][i];
        if (marker.isHidden()) {
          marker.show();
        } else {
          marker.hide();
        }
    } 
}




