﻿// JavaScript Document

var enProceso = false;
var http = getHTTPObject();
var campo="";
var abierto="";
var carro="";

var map;
var labels = [];
var mrs = new Array(0);
var ps;
var ls;
var is;

function handleHttpResponse() {
	
    if (http.readyState == 4) 
	{
       if (http.status == 200) 
	   {
			indice=parseInt(campo.id.substring(carro.length+6))+1;
			valor=http.responseText;
			
			if(valor!="")
			{
				if(carro=="SubCategoria")
					document.getElementById("capa"+carro+indice).innerHTML="<img src='/imagenes/arrowsearch.gif'><select onchange=\"retornaLista(this,this.options[this.selectedIndex].value,'"+carro+"')\" id='"+"select"+carro+indice+"' class='body' name='"+"select"+carro+indice+"'><option value='0'>Todos</option>"+valor+"</select><div class='capa"+carro+"' id='capa"+carro+(indice+1)+"'></div>";
				else
					document.getElementById("capa"+carro+indice).innerHTML="<img src='/imagenes/arrowsearch.gif'><select onchange='processQuery(document.searchForm);' id='"+"select"+carro+indice+"' class='body' name='"+"select"+carro+indice+"'><option value='-1'>Todos</option>"+valor+"</select>";
			}
			else
				document.getElementById("capa"+carro+indice).innerHTML="";
				
			document.getElementById('loading').innerHTML=""
			document.getElementById('loading').style.visibility="hidden";
			enProceso = false;
			
			processQuery(document.searchForm);
       }
    }
}

function retornaLista(camp, idPadre, tipo)
{
	carro=tipo;
	
	if (!enProceso && http)
	{
		campo=camp;
		document.getElementById('loading').innerHTML="<img src='/imagenes/icons/loading2.gif'> cargando..."
		document.getElementById('loading').style.visibility="visible";
		abierto=campo.id
		http.open("GET","loadListBox.php?tipo="+tipo+"&id="+idPadre, true);
		http.onreadystatechange = handleHttpResponse;
		enProceso = true;
		http.send(null);
    }
}



function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
       try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; }
       }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } 
	   catch (e) 
	   { 
	  	
	 	 xmlhttp = false; 
	   }
	}
    return xmlhttp;
}

function initialize() 
{
  if (GBrowserIsCompatible())
  {
	map = new GMap2(document.getElementById("map_canvas"));
	map.setCenter(new GLatLng(40.396764, -3.713379), 6);
	var customUI = map.getDefaultUI();
	customUI.maptypes.hybrid = false;
	map.setUI(customUI);
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.disableScrollWheelZoom();
  }
}
GSearch.setOnLoadCallback(initialize);
function animate()
{    
  map.panTo(new GLatLng(37.4569, -122.1569));
}


var baseIcon = new GIcon();
//baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 21);
//baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);


function addPOI(Latitud, Longitud, texto, IdCategoria, id)
{
	var latlng = new GLatLng(Latitud, Longitud);
	
	var i4 = new GIcon();
	i4.image = "/imagenes/categorias/" + IdCategoria + ".gif";
	i4.iconSize = new GSize(22, 22);
	i4.iconAnchor = new GPoint(10, 32);
	i4.shadow = "/imagenes/categorias/defecto.gif";
	i4.shadowSize = new GSize(22, 22);
	i4.infoWindowAnchor = new GPoint(10, 1);
	
	ps[id] = latlng;
	is[id] = i4;
	ls[id] = texto;
	mrs[id] = createMarker(latlng, texto, i4);
	
	map.addOverlay(mrs[id]);
}

function createMarker2(point, index, texto, IdCategoria, IdPOI, Nombre)
{
 // Create a lettered icon for this point using our icon class

	var letter = String.fromCharCode("A".charCodeAt(0) + index);
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "/imagenes/categorias/" + IdCategoria + ".gif";
	
	marker = new PdMarker(point,letteredIcon);
	marker.setId(IdPOI);
	marker.setTooltip(Nombre);
	marker.setDetailWinHTML(texto);
	marker.setOpacity(70);
	
	GEvent.addListener(marker, "mousein", function()
	{
	
	});
	
	GEvent.addListener(marker, "mouseout", function()
	{
	
	});
	
	return marker;
}


function createMarker(p, l, i)
{
	var marker = new GMarker(p, i);

	if (l != '')
		GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(l);});
		
	return marker;
}

function reCenter(index)
{
	map.panTo(ps[index], map.getZoom());
	mrs[index].openInfoWindowHtml(ls[index]);
}


function enterPressed(e,formu)
{
	if (((document.all)?e.keyCode:e.which)=="13")
		processQuery2(formu);
}

function processQuery(formu)
{
	carro="&mode=traditional&"+formu.elements[0].name+"="+formu.elements[0].value;
	
	for (i=1;i<formu.elements.length;i++)
		carro+="&"+formu.elements[i].name+"="+formu.elements[i].value;

	// document.getElementById("test").innerHTML = carro;
	$("#flex1").flexOptions({url: rutaPost+carro});
	
	document.getElementById("FGBuscar").value='';
	$("#flex1").flexOptions({query: '', newp: 1});
	
	$("#flex1").flexReload(); 
}

function processQuery2(formu)
{
	carro="&mode=cool&texto="+formu.busqueda.value;
	
	// document.getElementById("test").innerHTML = carro;
	$("#flex1").flexOptions({url: rutaPost+carro});
	
	document.getElementById("FGBuscar").value='';
	$("#flex1").flexOptions({query: ''});
	
	$("#flex1").flexReload(); 
}


String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


function MM_preloadImages() { //v3.0
	
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}












