//<![CDATA[
	var str="";
	var entrado = "1";
	var latCoord = "0";
	var longCoord = "0";
	var idPos = "0";
	var nomMoun = "0";
	var tipoCoord = "0";
	var mark="";
    function OnLoad() {
      new RawSearchControl();
    }

    /**
     * The RawSearchControl demonstrates how to use Searcher Objects
     * outside of the standard GSearchControl. This includes calling
     * searcher .execute() methods, reacting to search completions,
     * and if you had previously disabled html generation, how to generate
     * an html representation of the result.
     */
    function RawSearchControl() {
      // latch on to key portions of the document
      this.searcherform = document.getElementById("searcher");
      this.results = document.getElementById("results");
      this.cursor = document.getElementById("cursor");
      this.searchform = document.getElementById("searchform");

      // create map of searchers as well as note the active searcher
      this.activeSearcher = "web";
      this.searchers = new Array();

      // create and wire up an instance of GwebSearch and one of
      // GlocalSearch. Note, we disable html generation. We are doing
      // this so that we can demonstrate how to manually create it if
      // needed. Note that we register to handle search completion notifications
      // when searches complete, they are called in the context of this instance
      // of RawSearchControl and they are passed the searcher that just completed

      // wire up a raw GwebSearch searcher
      var searcher = new GwebSearch();
      searcher.setNoHtmlGeneration();
      searcher.setSearchCompleteCallback(this,
                                         RawSearchControl.prototype.searchComplete,
                                         [searcher]
                                         );
      this.searchers["web"] = searcher;

      // do the same for local
      searcher = new GlocalSearch();
      searcher.setNoHtmlGeneration();
      searcher.setCenterPoint("98074");
      searcher.setSearchCompleteCallback(this,
                                         RawSearchControl.prototype.searchComplete,
                                         [searcher]
                                         );
      this.searchers["local"] = searcher;

      // now, create a search form and wire up a submit and clear handler
      this.searchForm = new GSearchForm(true, this.searchform);
      this.searchForm.setOnSubmitCallback(this,
                                          RawSearchControl.prototype.onSubmit);
      this.searchForm.setOnClearCallback(this,
                                          RawSearchControl.prototype.onClear);
    }

    /**
     * figure out which searcher is active by looking at the radio
     * button array
     */
    RawSearchControl.prototype.computeActiveSearcher = function() {
     // for (var i=0; i<this.searcherform["searcherType"].length; i++) {
     //   if (this.searcherform["searcherType"][i].checked) {
     //     this.activeSearcher = this.searcherform["searcherType"][i].value;
	 this.activeSearcher = "local";
          return;
     //   }
     // }
    }

    /**
     * onSubmit - called when the search form is "submitted" meaning that
     * someone pressed the search button or hit enter. The form is passed
     * as an argument
     */
    RawSearchControl.prototype.onSubmit = function(form) {
      this.computeActiveSearcher();
      if (form.input.value) {
        // if there is an expression in the form, call the active searcher's
        // .execute method
		str = form.input.value;
        this.searchers[this.activeSearcher].execute(form.input.value);
      }

      // always indicate that we handled the submit event
      return false;
    }

    /**
     * onClear - called when someone clicks on the clear button (the little x)
     */
    RawSearchControl.prototype.onClear = function(form) {
      this.clearResults();
    }

    /**
     * searchComplete - called when a search completed. Note the searcher
     * that is completing is passes as an arg because thats what we arranged
     * when we called setSearchCompleteCallback
     */
    RawSearchControl.prototype.searchComplete = function(searcher) {

      // always clear old from the page
      this.clearResults();
	puesto = "0";
      // if the searcher has results then process them
	  longitudP3000 = 0;
	  var divs = createDiv("<font class=\"tituloP3000\"><b>Resultados</b></font><br><br>", "resultadosP3000");
	  GDownloadUrl("/servlet/BuscadorCoordenadas?STRBUSCAR="+str, function(data, responseCode) {
				              var xml = GXml.parse(data);
				              if (xml) { 
				                var markers = xml.getElementsByTagName("marker");
								var zoom = 14; 
				                var numMarkers = markers.length;
				                longitudP3000 = markers.length;
								divs.innerHTML = divs.innerHTML + "";
				                if (markers) { 
				                  for (var i = 0; i < markers.length; i++) {
				                    var matchID = markers[i].getAttribute("id");
				                    var matchName = markers[i].getAttribute("name");
				                    var matchLat = parseFloat(markers[i].getAttribute("lat"));
				                    var matchLong = parseFloat(markers[i].getAttribute("long"));
									if (!isNaN(matchLat)){
										divs.innerHTML = divs.innerHTML +"<a class=\"linkP3000\" href=\"javascript:creaPunto("+matchID+",'"+matchName.replace("'","´")+"',"+matchLat+","+matchLong+","+zoom+",1);\"><img src=\"http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png\"  width=\"10\" height=\"17\"  border=\"0\">&nbsp;"+matchName+" ---- "+"LAT: "+matchLat+"/ LONG:"+matchLong+"</a><br><br><br>";
									}else{
										divs.innerHTML = divs.innerHTML +"<a class=\"linkP3000\" href=\"http://www.pirineos3000.com/servlet/Busca?PARAM_ID_SITIO="+matchID+"&PARAM_TIPO=1\">"+matchName.replace("'","´")+"</a><br>No disponemos de coordenadas y no podemos posicionar en el mapa. Haz click para ver las ascensiones directamente<br><br>";
									}
				                  }
				                }
								
								
				              }
					    });
	 this.results.appendChild(divs);
      if (searcher.results && searcher.results.length > 0) {

        // print the result titles
        /*var div = createDiv("Result Titles", "header");
        this.results.appendChild(div);
        for (var i=0; i<searcher.results.length; i++) {
          var result = searcher.results[i];
          var titleLine = result.title;

          // add in lat,lng for local results
          if (result.GsearchResultClass == GlocalSearch.RESULT_CLASS) {
            titleLine += " (" + result.lat + ", " + result.lng + ")";
          }
          if (result.html) {
            titleLine += " ** html is present **";
          }
          div = createDiv(titleLine);
          this.results.appendChild(div);
        }*/

        // now manually generate the html that we disabled
        // initially and display it
        var div = createDiv("", "resultadosP3000");
        this.results.appendChild(div);
        for (var i=0; i<searcher.results.length; i++) {
          var result = searcher.results[i];
		  div.innerHTML = div.innerHTML + "<a class=\"linkP3000\" href=\"javascript:creaPunto("+i*100000+",'"+result.title+"',"+result.lat+","+result.lng+","+12+",2);\"><img src=\"http://gmaps-samples.googlecode.com/svn/trunk/markers/red/blank.png\" width=\"10\" height=\"17\" border=\"0\">&nbsp;<font style='tahoma'>"+result.title+"  "+"LAT: "+result.lat+"/ LONG:"+result.lng+"</font></a><br><br><br>";
          /*searcher.createResultHtml(result);
          if (result.html) {
            div = result.html.cloneNode(true);
          } else {
            div = createDiv("** failure to create html **");
          }
		  alert(div);
          this.results.appendChild(div);*/
        }
        

        // now, see if we have a cursor, and if so, create the 
        // cursor control
        if (searcher.cursor) {
          var cursorNode = createDiv(null, "gsc-cursor");
          for (var i=0; i<searcher.cursor.pages.length; i++) {
            var className = "gsc-cursor-page";
            if (i == searcher.cursor.currentPageIndex) {
              className = className + " gsc-cursor-current-page";
            }
            var pageNode = createDiv(searcher.cursor.pages[i].label, className);
            pageNode.onclick = methodClosure(this, this.gotoPage, 
                                             [searcher, i]); 
            cursorNode.appendChild(pageNode);
          }
          this.cursor.appendChild(cursorNode);
          var more = createLink(searcher.cursor.moreResultsUrl,
                                GSearch.strings["more-results"] + "&nbsp;&raquo;",
                                GSearch.LINK_TARGET_SELF,
                                "gsc-trailing-more-results");
          this.cursor.appendChild(more);
        }
      }
      if (searcher.results.length+longitudP3000==0){
    	var diva = createDiv("", "resultadosP3000");    	  
    	diva.innerHTML = diva.innerHTML + "No se han encontrado resultados<br><br>";
      	this.results.appendChild(diva);
      }
    }

    RawSearchControl.prototype.gotoPage = function(searcher, page) {
      searcher.gotoPage(page);
    }

    /**
     * clearResults - clear out any old search results
     */
    RawSearchControl.prototype.clearResults = function() {
      removeChildren(this.results);
      removeChildren(this.cursor);
    }

    /**
     * Static DOM Helper Functions
     */
    function removeChildren(parent) {
      while (parent.firstChild) {
        parent.removeChild(parent.firstChild);
      }
    }
    function createDiv(opt_text, opt_className) {
      var el = document.createElement("div");
      if (opt_text) {
        el.innerHTML = opt_text;
      }
      if (opt_className) { el.className = opt_className; }
      return el;
    }

    function methodClosure(object, method, opt_argArray) {
      return function() {
        return method.apply(object, opt_argArray);
      }
    }
	function creaPunto(id,name,lat,long,zoom,tipo){
		idPos = id;
		nomMoun = name;
		latCoord = lat;
		longCoord = long;
		entrado = "0";
		tipoCoord = tipo;
		map.setCenter(new GLatLng(lat, long), zoom);
	}
    function createLink(href, opt_text, opt_target, opt_className, opt_divwrap) {
      var el = document.createElement("a");
      el.href = href;
      if (opt_text) {
        el.innerHTML = opt_text;
      }
      if (opt_className) {
        el.className = opt_className;
      }
      if (opt_target) {
        el.target = opt_target;
      }
      if (opt_divwrap) {
        var div = this.createDiv(null, opt_className);
        div.appendChild(el);
        el = div;
      }
      return el;
    }

    // register to be called at OnLoad when the page loads
    GSearch.setOnLoadCallback(OnLoad);
    //]]>



					function createMarker(point,matchID,matchName,zoom,tipo,puedeMover) {
					var blueIcon = new GIcon(G_DEFAULT_ICON);
					if (tipo==1){
						 blueIcon = new GIcon(G_DEFAULT_ICON);
	        			blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png";
						// Set up our GMarkerOptions object
						markerOptions = { icon:blueIcon,title: matchName };
					}else{
						if (tipo==2){
						blueIcon = new GIcon(G_DEFAULT_ICON);
	        			blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/red/blank.png";
						// Set up our GMarkerOptions object
						markerOptions = { icon:blueIcon,title: matchName };
						}else{
						markerOptions = { title: matchName };
						}
					}
					if (puedeMover=='S'){
					var marker = new PdMarker(point,{icon: blueIcon, draggable:true});
					marker.setTooltip(matchName);
					//var html = "http://www.pirineos3000.com/servlet/PeticionAscensionesBuscador/IDMOUNTAIN--" +matchID ;
					//location.target="_blank";
				    //location.href = html;
					//
					//marker.setDetailWinHTML(html);
					

					GEvent.addListener(marker, "dragstart", function() {
          				map.closeInfoWindow();
        			});

        			GEvent.addListener(marker, "dragend", function() {
						GDownloadUrl("/servlet/UpdatePosicion?ID="+matchID+"&LAT="+marker.getPoint().lat().toFixed(6)+"&LONG="+marker.getPoint().lng().toFixed(6), function(data, responseCode) {});
          				//marker.openInfoWindowHtml(matchID+" "+marker.getPoint().lat().toFixed(6)+", "+marker.getPoint().lng().toFixed(6));
        			});
					}else{
					var marker = new PdMarker(point,{icon: blueIcon});
					marker.setTooltip(matchName);
					}
					
					//var html = "http://www.pirineos3000.com/servlet/PeticionAscensionesBuscador/IDMOUNTAIN--" +matchID ;
					//location.target="_blank";
				    //location.href = html;
					//
					//marker.setDetailWinHTML(html);
					GEvent.addListener(marker, "mouseover", function() {
							marker.topMarkerZIndex(); 
							marker.setOpacity(100);
					}); 

					GEvent.addListener(marker, "mouseout", function() {
							marker.setOpacity(70);
							marker.restoreMarkerZIndex();
						//marker.remove();
						//marker = createMarker(mark);
						});
					GEvent.addListener(marker, "click", function() {
						  	var link = "http://www.pirineos3000.com/servlet/Busca?PARAM_ID_SITIO=" +matchID ; 
							location.target="_blank";
				            location.href = link+"&PARAM_TIPO=1";
						  	//info = matchName+"<br>"+"<a href='"+link+"'>"+matchName+"</a>";
						  	//marker.openInfoWindowHtml(info);
						  
				          });
					//map.addOverlay(marker);
					//marker.showTooltip();
					

					//marker.setHoverImage("http://www.google.com/mapfiles/dd-start.png");
					
				          /*var marker = new GMarker(point, markerOptions);
						  if (tipo!=2){
				          	GEvent.addListener(marker, "click", function() {
						  	var link = "http://www.pirineos3000.com/servlet/PeticionAscensionesBuscador/IDMOUNTAIN--" +matchID ; 
					    	link = link + ".html";
							location.target="_blank";
				            location.href = link;
						  	//info = matchName+"<br>"+"<a href='"+link+"'>"+matchName+"</a>";
						  	//marker.openInfoWindowHtml(info);
						  
				          });
						  }*/
				          return marker;
				        }
