
//<![CDATA[
    function load(dataed) {
      if (GBrowserIsCompatible()) {

// A function to create the marker and set up the event window
// Dont try to unroll this function. It has to be here for the function closure
// Each instance of the function preserves the contends of a different instance
// of the "marker" and "html" variables which will be needed later when the event triggers.    
        function simpleMarker(point, icon, tekst) {
           var marker = new GMarker(point,{icon:icon, title:tekst});
           
           return marker;
        }

// === Define the function thats going to process the text file ===
        process_it = function(doc) {
// === split the document into lines ===

           var latcen, loncen, scale, maxst, minst, ichw, dirbeg, dirend;

           var hillname, npunt, ireg, nsteil;
           var latpt = new Array();
           var lonpt = new Array();
           var latst = new Array();
           var lonst = new Array();
           var perc  = new Array();
           var st300 = new Array();
           var ichh = 16;
           var facs = 1.3;
           var hh = 0.5 * ichh;
           var hw;
           var voeth = 1.2 * ichh;
           var hvoeth = 0.5 * voeth;
           var voetw = 2.4 * voeth;
           var topw = 2.1 * voeth;
           var footh = 1.42 * voeth;
           var hfooth = 0.5 * footh;
           var iconloc;
           var icontekst;

           lines = doc.split("\n");

// === split each line into parts separated by "\t" and use the contents ===
           parts = lines[0].split("\t");
           hillname = parts[0];

           parts = lines[1].split("\t");
           latcen = parseFloat(parts[0]);
           loncen = parseFloat(parts[1]);
           scale = parseInt(parts[2]);

// nederland = 1: Nederland; nederland = 0: andere landen
           if (latcen > 49.0 && latcen < 53.5 && loncen > 3.0 && loncen < 7.5)
                {var nederland = 1;}
           else {var nederland = 0;}

           var map = new GMap2(document.getElementById("map"));
// Maakt het mogelijk in- en uit te zoemen
           map.addControl(new GSmallMapControl());
// Maakt het mogelijk om te kiezen tussen kaart en satellietbeeld
           map.addControl(new GMapTypeControl());
// Voegt schaal toe
           map.addControl(new GScaleControl());
// Roept kaart op met breedtegraad, lengtegraad en schaal
           map.setCenter(new GLatLng(latcen,loncen), scale, G_HYBRID_MAP);

           parts = lines[2].split("\t");
           npunt = parseInt(parts[0]); 
           for (var ipunt=0; ipunt<npunt; ipunt++) {
              parts = lines[3+ipunt].split("\t");
              latpt[ipunt] = parseFloat(parts[0]);
              lonpt[ipunt] = parseFloat(parts[1]);
           }

// Zet de punten die de helling op de kaart definieren in een array
           var points = [];
           for (var i = 0; i < npunt; i++) {
              points[i] = new GLatLng(latpt[i],lonpt[i]);
           }

           map.addOverlay(new GPolyline(points,"#FF0000",5));

           parts = lines[npunt+3].split("\t");
           dirbeg = parseInt(parts[0]); 
           dirend = parseInt(parts[1]); 
           parts = lines[npunt+4].split("\t");
           nsteil = parseInt(parts[0]); 
           parts = lines[npunt+5].split("\t");
           minst = parseInt(parts[0]); 
           maxst = parseInt(parts[1]); 

           for (var isteil=0; isteil<nsteil; isteil++) {
              parts = lines[npunt+6+isteil].split("\t");
              perc[isteil]  = parseInt(parts[0]);
              latst[isteil] = parseFloat(parts[1]);
              lonst[isteil] = parseFloat(parts[2]);
              st300[isteil] = parseInt(parts[3]);
           }

           var strn = ["m9","m8","m7","m6","m5","m4","m3","m2","m1","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17"]; 
           var steilicon = new Array();
           for (var ist=minst; ist<maxst+1; ist++) {
              steilicon[ist] = new GIcon();
              var strfile = "http://www.heuvelsfietsen.nl/figuren/ikonen/stik" + strn[ist+9] + ".png";
              steilicon[ist].image = strfile;
              if (ist >= 0 && ist < 10) {ichw = 15;}
              else {ichw = 17;}
              hw = 0.5 * ichw; 
              steilicon[ist].infoWindowAnchor = new GPoint(ichw,0);
           }

// Plaatst icons met hellingspercentage in kaart 
           for (var isteil=0; isteil<nsteil; isteil++) {
              var point = new GLatLng(latst[isteil],lonst[isteil]);
              iconloc = steilicon[perc[isteil]];
              if (st300[isteil] == 1) {
                 iconloc.iconSize = new GSize(ichw*facs,ichh*facs);
                 iconloc.iconAnchor = new GPoint(hw*facs, hh*facs);
                 if (nederland == 1) {icontekst = 'helling (%); deel van steilste 300 meter';}
                 else                {icontekst = 'slope (%); part of steepest kilometer';}}
              else {
                 iconloc.iconSize = new GSize(ichw,ichh);
                 iconloc.iconAnchor = new GPoint(hw, hh);
                 if (nederland == 1) {icontekst = 'helling (%)';}
                 else                {icontekst = 'slope (%)';}}
              var marker = simpleMarker(point,iconloc,icontekst);
              map.addOverlay(marker);
           }

           var voeticon = new GIcon();
           voeticon.image = "http://www.heuvelsfietsen.nl/figuren/ikonen/voet.png";
           if (nederland == 1) {
              voeticon.image = "http://www.heuvelsfietsen.nl/figuren/ikonen/voet.png";
              voeticon.iconSize = new GSize(voetw,voeth);
              voeticon.iconAnchor = new GPoint(voetw*dirbeg,hvoeth);}
           else {
              voeticon.image = "http://www.heuvelsfietsen.nl/figuren/ikonen/foot.png";
              voeticon.iconSize = new GSize(voetw,footh);
              voeticon.iconAnchor = new GPoint(voetw*dirbeg,hfooth);}
           var point = new GLatLng(latpt[0],lonpt[0]);
           var marker = simpleMarker(point,voeticon);
           map.addOverlay(marker);

           var topicon = new GIcon();
           topicon.image = "http://www.heuvelsfietsen.nl/figuren/ikonen/top.png";
           topicon.iconSize = new GSize(topw,voeth);
           topicon.iconAnchor = new GPoint(topw*dirend,hvoeth);
           var point = new GLatLng(latpt[npunt-1],lonpt[npunt-1]);
           var marker = simpleMarker(point,topicon);
           map.addOverlay(marker);

        }
        
        GDownloadUrl(dataed, process_it);


      }
    }


