 // A TextualZoomControl is a GControl that displays textual "Zoom In"
 // and "Zoom Out" buttons (as opposed to the iconic buttons used in
     // Google Maps).

function zoek() {}

function TextualZoomControl() {}
    
TextualZoomControl.prototype = new GControl();
		      
// 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.
TextualZoomControl.prototype.initialize = function(map) {
var container = document.createElement("div");
var zoek = document.createElement("div");
zoek.id="zoek";
this.setButtonStyle_(zoek);
container.appendChild(zoek);
//var myform = document.createElement('form');
var inputtext = document.createElement('input'); 
var mybutton = document.createElement('button')
theText=document.createTextNode("Zoek");

mybutton.appendChild(theText);
inputtext.setAttribute('type','text');
inputtext.setAttribute('name','rlcode');
inputtext.setAttribute('id','rlcode');
inputtext.setAttribute('size','8');
//inputtext.setAttribute('value','1');
zoek.appendChild(inputtext);
zoek.appendChild(mybutton);

//zoek.appendChild(myform);
//myOnChange = new Function("e", "location.href=myselect.options[myselect.selectedIndex].value");
GEvent.addDomListener(mybutton, "click", function() {                                                                              
     if (debug) GLog.write("ik zoek:" + document.getElementById("rlcode").value );               
     zoeklokatie= document.getElementById("rlcode").value;        
     Zoekparser("zoek.php?desc=" + zoeklokatie,map);    
    });                                                                                                                              
	                                                                                                                                         
map.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_BOTTOM_RIGHT, new GSize(7, 7));
}
																					         // Sets the proper CSS for the given button element.
TextualZoomControl.prototype.setButtonStyle_ = function(button) {
 button.style.textDecoration = "underline";
 button.style.color = "#0000cc";
 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 = "10em";
 button.style.cursor = "pointer";
 }
 
 function Zoekparser(path,map){ //path: url to the kml file. map: div where the map is
    if (debug) GLog.write("zoekparser" + path);
    var request = GXmlHttp.create();
    var icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);      
	var icon2 = new GIcon();
	icon2.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon2.iconSize = new GSize(22, 32);
    icon2.shadowSize = new GSize(22, 20);
    icon2.iconAnchor = new GPoint(6, 20);
    icon2.infoWindowAnchor = new GPoint(5, 1);      
	icon2.image = "http://labs.google.com/ridefinder/images/mm_20_yellow.png";
				    
    //iconblue = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_blue.png"); 
    //icongreen = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_green.png"); 
    //iconyellow = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_yellow.png"); 
   // om.Set('<b>Een Ogenblik geduld a.u.b...</b>');
		   
   request.open('GET', path, true);
   request.onreadystatechange = function(){		
	if (request.readyState == 4){
		var data = request.responseXML;
//		var batch = [];
		if (debug) GLog.write("iterating:" + zoeklokatie);
		
		placemarks = data.documentElement.getElementsByTagName("Placemark");
		//alert(zoeklokatie + " niet gevonden!" + placemarks.length);
		if (placemarks[0].getElementsByTagName("mp")[0].childNodes[0].nodeValue=="NF") { 
			alert(zoeklokatie + " niet gevonden!" );
			};
			if (debug) GLog.write("found: " + placemarks.length + " markers");
			for(var i=0; i<placemarks.length; i++){
	//			var px = parseFloat(placemarks[i].getElementsByTagName("fpx")[0].childNodes[0].nodeValue-0.00098);
	//			var py = parseFloat(placemarks[i].getElementsByTagName("fpy")[0].childNodes[0].nodeValue-0.00023);
  				var px = parseFloat(placemarks[i].getElementsByTagName("fpx")[0].childNodes[0].nodeValue);
				var py = parseFloat(placemarks[i].getElementsByTagName("fpy")[0].childNodes[0].nodeValue);
				var point = new GLatLng(px,py);
//				zoeklokatie = placemarks[i].getElementsByTagName("WG")[0].childNodes[0].nodeValue;
				// als zoeken geslaagd, gaan we verder met mp, niet wgnaam
				if (debug) GLog.write("lokatie:" + zoeklokatie);
				if (i == Math.round(placemarks.length/2)-1) map.setCenter(point, 15 );	
				if (debug) GLog.write("setcenter als i = " + Math.round(placemarks.length/2)-1);
				};
        	//om.Clear();
		};
   	};
     request.send(null);	
};

