/*
	Copyright MAPIDIRECTORIO.COM 2010
	Author: Sergio Armando Vasquez Colorado
	Email: sergio.vasquez@mapidirectorio.com
	MAPIDIRECTORIO.COM Sistema publico Version 2.48
*/

function setCookieLatLng(value){
	c_name = "mapidirectorio_qp";
	expiredays = 365;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookieLatLng(){
	c_name = "mapidirectorio_qp";
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1){ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}

function setCookieAyuda(value){
	c_name = "mapidirectorio_ayuda";
	expiredays = 365;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function getCookieAyuda(){
	c_name = "mapidirectorio_ayuda";
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1){ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}
	
/*
	Inicio Clase Punto
*/
	function Punto(lat,lng,domicilio,seccion,zona,barrio,negocioID,htmlCode,title) {
	    this.lat = lat;
		this.lng = lng;
		this.domicilio = domicilio;
		this.seccion = seccion;
		this.zona = zona;
		this.barrio = barrio;
		this.negocioID = negocioID;
		this.htmlCode = htmlCode;
		this.title = title;
	}

	Punto.prototype.lat;
	Punto.prototype.lng;
	Punto.prototype.domicilio;
	Punto.prototype.seccion;
	Punto.prototype.zona;
	Punto.prototype.barrio;
	Punto.prototype.negocioID;
	Punto.prototype.htmlCode;
	Punto.prototype.title;
/*
	Fin Clase Punto
*/

var homeHTML = "<div><strong style='color:#000'>Globo de Ubicaci&oacute;n Actual</strong><br /></div><div style='width:330px;'><img src='img/marker.gif' hspace='10' align='left' />Arrastre este punto hasta su ubicacion actual.<br /><br /><span>Cada vez que inicie MAPIDIRECTORIO.COM ver&aacute; este punto en el centro del mapa.</span></div>";
	
var shareHTML = "<div><strong style='color:#000'>Globo de Ubicaci&oacute;n Compartida</strong><br /></div><div style='width:330px;'><img src='img/markershare.gif' hspace='10' align='left' /><br />Te han compartido esta ubicaci&oacute;n.<br /><br /><span>&iexcl;Gracias por utilizar MAPIDIRECTORIO.COM!</span></div>";

var paginaNegocio_Global = false;
var resultadoBusquedas_Global = false;
var queryText_Global;
var map;
var homemarker;
var Markers;
var MarkersInteres;
var Puntos;
var puntos_interes;
var blankIcon;
var homeIcon;
var iconsec = new Array();
var minMapScale = 11;
var maxMapScale = 19;
var mm;
var comunaActual = "";
var barrioActual = "";
var idNegocio = "";
var timeToCloseCiudades = 0;
var timeToCloseFacebook = 0;
var timeToCloseLocation = 0;

function initialize() {
	if (GBrowserIsCompatible()) {
		if(punPers) homeHTML = shareHTML;
        map = new GMap2(document.getElementById("map_canvas"));
		var cookie = getCookieLatLng();
		eval("var center = new GLatLng"+puntoInicial+"");
		if(!punPers && cookie != null && cookie != ""){
	        eval("center = new GLatLng" + cookie +"");
		}

        map.setCenter(center, 15);
		
		loadZonas();
		
		map.enableScrollWheelZoom();

		map.enableContinuousZoom();

		map.setMapType(G_HYBRID_MAP);
		
		createShare(center.lat()+","+center.lng());
		
		map.openExtInfoWindow(center, "mapiInfoWindow",
		"<div style=\"text-align:center;margin-top:30px;margin-left:30px;margin-right:38px;\"><object width=\"60\" height=\"60\" align=\"left\"><param name=\"movie\" value=\"swf/loading.swf\"><param name=\"wmode\" value=\"transparent\"><embed src=\"swf/loading.swf\" width=\"60\" height=\"60\" wmode=\"transparent\" ></embed></object><br><br><strong>Cargando Datos. Por favor espere...</strong></div>"
		);

		loadMarkerIcons();
		
		if(punPers) homeIcon.image = "img/markershare.gif";
        homemarker = new GMarker(center, {icon: homeIcon, title: "Mi ubicacion fisica (ARRASTRABLE)" ,draggable: true});


        GEvent.addListener(homemarker, "dragstart", function() {
          map.closeInfoWindow();
        });

        GEvent.addListener(homemarker, "dragend", function() {
			createShare(homemarker.getPoint().lat()+","+homemarker.getPoint().lng());
		  setCookieLatLng(homemarker.getPoint());
		  if(getCookieAyuda() != "yes"){
			  setCookieAyuda("no");
		  }
          //homemarker.openInfoWindowHtml(homeHTML);
		  homemarker.openExtInfoWindow(map, "mapiInfoWindow",homeHTML);
        });
		
		GEvent.addListener(homemarker, "click", function() {
          //homemarker.openInfoWindowHtml(homeHTML);
		  homemarker.openExtInfoWindow(map, "mapiInfoWindow",homeHTML);
        });

		setTimeout("loadDataAndMarkers()",10);

		setTimeout("loadMapAddOns()",1000);


  GMarker.prototype.hide = function (){
    if (this.getPoint().lat() < 90)
      try {
        this.savePoint = this.getPoint();
        this.setPoint(new GLatLng(90, 0));
      } catch(e) {}
  }
  GMarker.prototype.show = function (){
    if (this.getPoint().lat() == 90)
    if (this.savePoint)
      try {
        this.setPoint(this.savePoint);
        this.savePoint = null;
      } catch(e) {}
	}


	ox=10;
	oy=10;

	lockX=0;
	lockY=0;


      }

    }
	
function MapiControl(){}	
MapiControl.prototype = new GControl();
MapiControl.prototype.initialize = function(map) {
	var container = document.createElement("div");
	container.setAttribute('id',"mapiControl");

	var vistaMapa = document.createElement("div");
	this.setButtonStyle_(vistaMapa);
	container.appendChild(vistaMapa);
	vistaMapa.appendChild(document.createTextNode("MAPA"));
	GEvent.addDomListener(vistaMapa, "click", function() {
		map.setMapType(G_NORMAL_MAP);
	});
	
	var panUpBt = document.createElement("div");
	panUpBt.style.cssFloat = "left";
	panUpBt.style.styleFloat = "left";
	panUpBt.style.background = "url(img/controlbts.gif) -70px 0px  no-repeat";
	panUpBt.style.marginTop = "1px";
	panUpBt.style.marginLeft = "1px";
	panUpBt.style.width = "60px";
	panUpBt.style.height = "37px";
	panUpBt.style.cursor = "pointer";
	container.appendChild(panUpBt);
	GEvent.addDomListener(panUpBt, "click", function() {
		map.panBy(new GSize (0,200));
	});

	var vistaSatelite = document.createElement("div");
	this.setButtonStyle_(vistaSatelite);
	container.appendChild(vistaSatelite);
	vistaSatelite.appendChild(document.createTextNode("SAT\xC9LITE"));
	GEvent.addDomListener(vistaSatelite, "click", function() {
		map.setMapType(G_SATELLITE_MAP);
	});

	var zoomInDiv = document.createElement("div");
	zoomInDiv.style.cssFloat = "left";
	zoomInDiv.style.styleFloat = "left";
	zoomInDiv.style.background = "url(img/controlbts.gif) no-repeat -130px 0px";
	zoomInDiv.style.marginTop = "1px";
	zoomInDiv.style.marginLeft = "1px";
	zoomInDiv.style.width = "60px";
	zoomInDiv.style.height = "37px";
	zoomInDiv.style.cursor = "pointer";
	container.appendChild(zoomInDiv);
	GEvent.addDomListener(zoomInDiv, "click", function() {
		map.zoomIn();
	});
	
	var panLeftBt = document.createElement("div");
	panLeftBt.style.cssFloat = "left";
	panLeftBt.style.styleFloat = "left";
	panLeftBt.style.background = "url(img/controlbts.gif) no-repeat 0px -37px";
	panLeftBt.style.marginTop = "1px";
	panLeftBt.style.marginLeft = "1px";
	panLeftBt.style.width = "70px";
	panLeftBt.style.height = "60px";
	panLeftBt.style.cursor = "pointer";
	container.appendChild(panLeftBt);
	GEvent.addDomListener(panLeftBt, "click", function() {
		map.panBy(new GSize (200,0));
	});
	
	var panCentro = document.createElement("div");
	panCentro.style.cssFloat = "left";
	panCentro.style.styleFloat = "left";
	panCentro.style.background = "url(img/controlbts.gif) no-repeat -70px -37px";
	panCentro.style.marginTop = "1px";
	panCentro.style.marginLeft = "1px";
	panCentro.style.width = "60px";
	panCentro.style.height = "60px";
	panCentro.style.cursor = "pointer";
	container.appendChild(panCentro);
	GEvent.addDomListener(panCentro, "click", function() {
		map.panTo(homemarker.getLatLng());
	});
		
	var panRightBt = document.createElement("div");
	panRightBt.style.cssFloat = "left";
	panRightBt.style.styleFloat = "left";
	panRightBt.style.background = "url(img/controlbts.gif) no-repeat -130px -37px";
	panRightBt.style.marginTop = "1px";
	panRightBt.style.marginLeft = "1px";
	panRightBt.style.width = "70px";
	panRightBt.style.height = "60px";
	panRightBt.style.cursor = "pointer";
	container.appendChild(panRightBt);
	GEvent.addDomListener(panRightBt, "click", function() {
		map.panBy(new GSize (-200,0));
	});
	
	var zoomContainer = document.createElement("div");
	zoomContainer.style.cssFloat = "left";
	zoomContainer.style.styleFloat = "left";
	zoomContainer.style.background = "url(img/controlbts.gif) no-repeat -200px -37px";
	zoomContainer.style.marginTop = "1px";
	zoomContainer.style.marginLeft = "1px";
	zoomContainer.style.textAlign = "center";
	zoomContainer.style.width = "60px";
	zoomContainer.style.height = "60px";
	
	var zoom6 = document.createElement("div");
	zoom6.setAttribute('id',"zoom6");
	this.setZoomStyle_(zoom6);
	zoomContainer.appendChild(zoom6);
	GEvent.addDomListener(zoom6, "click", function() {
		map.setZoom(minMapScale + 6);
	});
	
	var zoom5 = document.createElement("div");
	zoom5.setAttribute('id',"zoom5");
	this.setZoomStyle_(zoom5);
	zoomContainer.appendChild(zoom5);
	GEvent.addDomListener(zoom5, "click", function() {
		map.setZoom(minMapScale + 5);
	});
	
	var zoom4 = document.createElement("div");
	zoom4.setAttribute('id',"zoom4");
	this.setZoomStyle_(zoom4);
	zoomContainer.appendChild(zoom4);
	GEvent.addDomListener(zoom4, "click", function() {
		map.setZoom(minMapScale + 4);
	});
		
	var zoom3 = document.createElement("div");
	zoom3.setAttribute('id',"zoom3");
	this.setZoomStyle_(zoom3);
	zoomContainer.appendChild(zoom3);
	GEvent.addDomListener(zoom3, "click", function() {
		map.setZoom(minMapScale + 3);
	});
	
	var zoom2 = document.createElement("div");
	zoom2.setAttribute('id',"zoom2");
	this.setZoomStyle_(zoom2);
	zoomContainer.appendChild(zoom2);
	GEvent.addDomListener(zoom2, "click", function() {
		map.setZoom(minMapScale + 2);
	});
	
	var zoom1 = document.createElement("div");
	zoom1.setAttribute('id',"zoom1");
	this.setZoomStyle_(zoom1);
	zoomContainer.appendChild(zoom1);
	GEvent.addDomListener(zoom1, "click", function() {
		map.setZoom(minMapScale + 1);
	});

	var zoom0 = document.createElement("div");
	zoom0.setAttribute('id',"zoom0");
	this.setZoomStyle_(zoom0);
	zoomContainer.appendChild(zoom0);
	GEvent.addDomListener(zoom0, "click", function() {
		map.setZoom(minMapScale + 0);
	});
	
	container.appendChild(zoomContainer);
	
	var vistaHibrido = document.createElement("div");
	this.setButtonStyle_(vistaHibrido);
	container.appendChild(vistaHibrido);
	vistaHibrido.appendChild(document.createTextNode("HIBRIDO"));
	GEvent.addDomListener(vistaHibrido, "click", function() {
		map.setMapType(G_HYBRID_MAP);
	});
	
	var panDownBt = document.createElement("div");
	panDownBt.style.cssFloat = "left";
	panDownBt.style.styleFloat = "left";
	panDownBt.style.background = "url(img/controlbts.gif) no-repeat -70px -97px";
	panDownBt.style.marginTop = "1px";
	panDownBt.style.marginLeft = "1px";
	panDownBt.style.width = "60px";
	panDownBt.style.height = "37px";
	panDownBt.style.cursor = "pointer";
	container.appendChild(panDownBt);
	GEvent.addDomListener(panDownBt, "click", function() {
		map.panBy(new GSize (0,-200));
	});
	
	var vistaFisico = document.createElement("div");
	this.setButtonStyle_(vistaFisico);
	container.appendChild(vistaFisico);
	vistaFisico.appendChild(document.createTextNode("RELIEVE"));
	GEvent.addDomListener(vistaFisico, "click", function() {
		map.setMapType(G_PHYSICAL_MAP);
	});

	var zoomOutDiv = document.createElement("div");
	zoomOutDiv.style.cssFloat = "left";
	zoomOutDiv.style.styleFloat = "left";
	zoomOutDiv.style.background = "url(img/controlbts.gif) no-repeat -130px -97px";
	zoomOutDiv.style.marginTop = "1px";
	zoomOutDiv.style.marginLeft = "1px";
	zoomOutDiv.style.width = "60px";
	zoomOutDiv.style.height = "37px";
	zoomOutDiv.style.cursor = "pointer";
	container.appendChild(zoomOutDiv);
	GEvent.addDomListener(zoomOutDiv, "click", function() {
		map.zoomOut();
	});
	map.getContainer().appendChild(container);
	return container;
}
MapiControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
}
MapiControl.prototype.setButtonStyle_ = function(button) {
	button.style.cssFloat = "left";
	button.style.styleFloat = "left";
	button.style.color = "#FFF";
	button.style.background = "url(img/controlbts.gif) 0px 0px no-repeat";
	button.style.font = "115% Arial, Helvetica, sans-serif";
	button.style.fontWeight = "bold";
	button.style.padding = "2px";
	button.style.paddingTop = "10px";
	button.style.marginTop = "1px";
	button.style.marginLeft = "1px";
	button.style.textAlign = "center";
	button.style.width = "66px";
	button.style.height = "25px";
	button.style.cursor = "pointer";
}
MapiControl.prototype.setZoomStyle_ = function(button) {
	button.style.border = "1px #CFCFCF solid";
	button.style.marginTop = "3px";
	button.style.marginBottom = "2px";
	button.style.marginLeft = "5px";
	button.style.width = "48px";
	button.style.height = "3px";
	button.style.cursor = "pointer";
}
function drawZoom(){
	var zoomValue = map.getZoom() - (minMapScale + 1);
	for(var i = 0; i <= 6; i++){
		if(i <= zoomValue)
			eval("document.getElementById(\"zoom"+i+"\").style.background = \"#FFF\";");
		else
			eval("document.getElementById(\"zoom"+i+"\").style.background = \"#000\";");
	}
}
function MapiBarra() {}
MapiBarra.prototype = new GControl();
MapiBarra.prototype.initialize = function(map) {
	var container = document.createElement("div");
	container.style.marginRight = "0px";
	
	if(document.getElementById("locatorbt")){
		container.appendChild(document.getElementById("nuevolocator"));
		container.appendChild(document.getElementById("locatorbt"));
		
	}
	//container.appendChild(document.getElementById("showhidebtsearch"));
	document.getElementById("showhidebt").style.cursor = "pointer";
	container.appendChild(document.getElementById("showhidebt"));
	document.getElementById("showhidebtotros").style.cursor = "pointer";
	container.appendChild(document.getElementById("showhidebtotros"));
	map.getContainer().appendChild(container);
	return container;
}

MapiBarra.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT , new GSize(4, 4));
}
function loadMapAddOns(){
	var mapTypes = map.getMapTypes();
	for (var i=0; i<mapTypes.length; i++) {
		mapTypes[i].getMinimumResolution = function() {return minMapScale;}
		mapTypes[i].getMaximumResolution = function() {return maxMapScale;}
	} 
	var fisico = G_PHYSICAL_MAP;
	fisico.getMinimumResolution = function() {return minMapScale;};
	var mapControl = new GMapTypeControl();
	map.addControl(new MapiControl());
	map.addControl(new MapiBarra());
	new GKeyboardHandler(map);
	GEvent.addListener(map, "zoomend", function() {
		drawZoom();
	});
	drawZoom();
}
function loadMarkerIcons(){
	blankIcon = new GIcon(G_DEFAULT_ICON);
      blankIcon.image = "img/blankmarker.gif";
	blankIcon.iconSize = new GSize(43,54);
	blankIcon.imageMap = [0,0, 0,43, 54,43, 54,7];
	blankIcon.iconAnchor = new GPoint(2,49);
	homeIcon = new GIcon(G_DEFAULT_ICON);
	homeIcon.iconSize = new GSize(66,82);
	homeIcon.image = "img/marker.gif";
	homeIcon.imageMap = [0,0, 0,66, 82,66, 66,7];
	homeIcon.iconAnchor = new GPoint(2,79);
	homeIcon.dragCrossImage = "img/cross.gif";
	homeIcon.dragCrossSize = new GSize(36,17);
	homeIcon.dragCrossAnchor = new GPoint(18,4);
	homeIcon.maxHeight = 30;
/*
		iconsec[11] =  new GIcon(G_DEFAULT_ICON);
        iconsec[11].image = "img/marker11.gif";
	*/	
	iconsec[29] =  new GIcon(G_DEFAULT_ICON);
    iconsec[29].image = "img/marker29.gif";
	iconsec[29].iconSize = new GSize(43,54);
	iconsec[29].imageMap = [0,0, 0,43, 54,43, 54,7];
	iconsec[29].iconAnchor = new GPoint(2,49);
/*
		iconsec[37] =  new GIcon(G_DEFAULT_ICON);
        iconsec[37].image = "img/marker37.gif";
		
*/
	iconsec[43] =  new GIcon(G_DEFAULT_ICON);
    iconsec[43].image = "img/marker43.gif";
	iconsec[43].iconSize = new GSize(43,54);
	iconsec[43].imageMap = [0,0, 0,43, 54,43, 54,7];
	iconsec[43].iconAnchor = new GPoint(2,49);
/*
		iconsec[48] =  new GIcon(G_DEFAULT_ICON);
        iconsec[48].image = "img/marker48.gif";	
		

		iconsec[51] =  new GIcon(G_DEFAULT_ICON);
        iconsec[51].image = "img/marker51.gif";	
*/
	iconsec[52] =  new GIcon(G_DEFAULT_ICON);
	iconsec[52].image = "img/marker52.gif";
	iconsec[52].iconSize = new GSize(43,54);
	iconsec[52].imageMap = [0,0, 0,43, 54,43, 54,7];
	iconsec[52].iconAnchor = new GPoint(2,49);
	
	iconsec[59] =  new GIcon(G_DEFAULT_ICON);
	iconsec[59].image = "img/marker59.gif";
	iconsec[59].iconSize = new GSize(43,54);
	iconsec[59].imageMap = [0,0, 0,43, 54,43, 54,7];
	iconsec[59].iconAnchor = new GPoint(2,49);
}

	function loadDataAndMarkers(){
		new Ajax.Request("load_negocios_markers.php", {
		  method: 'post', parameters:{ciudad:varCiudad},
		  onSuccess: function(transport) {
			eval(transport.responseText);
			loadMarkers();
		  }
		});

	}

function loadMarkers(){
	//map.clearOverlays();
	mm = new GMarkerManager(map); 
	Markers = new Array();
	for (var i = 0; i < Puntos.length; i++) {
		var latlng = new GLatLng(Puntos[i].lat,Puntos[i].lng);
		switch(Puntos[i].seccion){
			/*case 11:
				Markers[i] = new GMarker(latlng,{icon: iconsec[Puntos[i].seccion], title: Puntos[i].title});
				break;*/
			case 29:
				Markers[i] = new GMarker(latlng,{icon: iconsec[Puntos[i].seccion], title: Puntos[i].title});
				break;
			/*case 37:
				Markers[i] = new GMarker(latlng,{icon: iconsec[Puntos[i].seccion], title: Puntos[i].title});
				break;*/

			case 43:
				Markers[i] = new GMarker(latlng,{icon: iconsec[Puntos[i].seccion], title: Puntos[i].title});
				break;
			/*case 48:
				Markers[i] = new GMarker(latlng,{icon: iconsec[Puntos[i].seccion], title: Puntos[i].title});
				break;

			case 51:
				Markers[i] = new GMarker(latlng,{icon: iconsec[Puntos[i].seccion], title: Puntos[i].title});
				break;*/
			case 52:
				Markers[i] = new GMarker(latlng,{icon: iconsec[Puntos[i].seccion], title: Puntos[i].title});
				break;
			case 59:
				Markers[i] = new GMarker(latlng,{icon: iconsec[Puntos[i].seccion], title: Puntos[i].title});
				break;
			default:
					Markers[i] = new GMarker(latlng,{icon: blankIcon, title: Puntos[i].title});
		}
		eval("GEvent.addListener(Markers["+i+"], 'click', function() {Markers["+i+"].openExtInfoWindow(map,\"mapiInfoWindow\" ,Puntos["+i+"].htmlCode); });");
	}
	mm.addMarkers(Markers, 14)
	mm.refresh();
	var evento = GEvent.addListener(mm, "changed", function(bounds,markerCount) {
		map.addOverlay(homemarker);
		if(!paginaNegocio_Global)setTimeout("homemarker.openExtInfoWindow(map,\"mapiInfoWindow\" ,homeHTML)",500)
		else map.closeInfoWindow();
		GEvent.removeListener(evento);
		loadPuntosInteres();
	});
}

function loadPuntosInteres(){
	new Ajax.Request("load_sitios_interes_markers.php", {
	  method: 'post', parameters:{ciudad:varCiudad},
	  onSuccess: function(transport) {
		eval(transport.responseText);
		loadMarkersInteres();
	  }
	});
}

	function loadMarkersInteres(){
		var parkico =  new GIcon(G_DEFAULT_ICON);
        parkico.image = "img/park-icon.gif";
		parkico.iconSize = new GSize(43,54);
		parkico.imageMap = [0,0, 0,43, 54,43, 54,7];
		parkico.iconAnchor = new GPoint(2,49);
		MarkersInteres = new Array();
		for (var i = 0; i < puntos_interes.length; i++) {
			var latlng = new GLatLng(puntos_interes[i].lat,puntos_interes[i].lng);
			if(puntos_interes[i].seccion == 1){
			  MarkersInteres[i] = new GMarker(latlng,{icon: parkico, title: puntos_interes[i].title});
			  eval("GEvent.addListener(MarkersInteres["+i+"], 'click', function() {MarkersInteres["+i+"].openExtInfoWindow(map, \"mapiInfoWindow\",puntos_interes["+i+"].htmlCode); });");
			}
		}
		mm.addMarkers(MarkersInteres, 14);
		mm.refresh();
		if(paginaNegocio_Global)setTimeout("findNegocio("+idNegocio+")",400);

	}

	function ventanaAyuda(){
		var winHelp = new Window("ventana_inicia_ayuda",{className: "mapiayuda", title: "", width:460, height:291, resizable:false,minimizable:false,maximizable:false, recenterAuto:false, showEffectOptions: {duration:1.5}});

		winHelp.setContent("ayuda_inicial");

		if(getCookieAyuda() == "yes") document.getElementById("nomasayudainicial").checked = false;

		winHelp.setZIndex(5);
		if(getCookieAyuda() != "no" && !paginaNegocio_Global && !resultadoBusquedas_Global && !punPers){
			myObserver = { onClose: function(eventName, win) { 
				if (win == winHelp) { 
					if(document.getElementById("nomasayudainicial").checked){
						setCookieAyuda("--");
					}else{
						setCookieAyuda("yes");
					}
				}
			}}

			Windows.addObserver(myObserver);
			winHelp.showCenter(true); 
		}
	}

	function cleanSecc(seccId){
		for(var i = 0; i < Puntos.length; i++){
			if(Puntos[i].seccion == seccId){
				//map.removeOverlay(Markers[i]);
				Markers[i].hide();
			}
		}
	}

	function addSecc(seccId){
		for(var i = 0; i < Puntos.length; i++){
			if(Puntos[i].seccion == seccId){
				Markers[i].show();
			}
		}
	}
	
	function cambiarSecc(obj,seccId){
		mantenerSoloUnaSecc(obj);
		loadNegocios();
		if(obj.checked){
			addSecc(seccId);
		}else{
			cleanSecc(seccId);
		}
	}

	function soloUnaSecc(obj){
		if(obj.checked){
			var seccs = document.getElementsByName("secciones[]");
			var tempSecc = false;
			for(var i =0; i< seccs.length ; i++){
				if(seccs[i].checked == true){
					if(tempSecc){
						seccs[i].checked = false;
						cleanSecc(seccs[i].value);
					}
					tempSecc = true;
				}
			}
		}else{
			var seccs = document.getElementsByName("secciones[]");
			for(var i =0; i< seccs.length ; i++){
				if(seccs[i].checked != true){
					seccs[i].checked = true;
					addSecc(seccs[i].value);
				}
			}
		}
		loadNegocios();
	}

	function mantenerSoloUnaSecc(obj){
		if(document.getElementById("unaseccion").checked){
			if(obj.checked){
				var seccs = document.getElementsByName("secciones[]");
				for(var i =0; i< seccs.length ; i++){
					if(seccs[i] != obj && seccs[i].checked == true){
						seccs[i].checked = false;
						cleanSecc(seccs[i].value);
					}
				}
			}
		}
	}
	
	function cleanSinDomicilios(){
		for(var i = 0; i < Puntos.length; i++){
			if(!Puntos[i].domicilio){
				Markers[i].hide();
			}
		}
	}

	function addSinDomicilios(){
		for(var i = 0; i < Puntos.length; i++){
			if(!Puntos[i].domicilio){
				Markers[i].show();
			}
		}
	}

	function soloDomicilio(obj){
		loadNegocios()
		if(obj.checked){
			cleanSinDomicilios();
		}else{
			addSinDomicilios();
		}
	}

	function reubicarme(){
		var answer = confirm("Esta seguro de querer borrar su ubicacion actual en el mapa?");
		if(answer){
			homemarker.setPoint(map.getCenter());
			setCookieLatLng(homemarker.getPoint());
			homemarker.openExtInfoWindow(map,"mapiInfoWindow" ,homeHTML);
		}
	}

	function reubicarmapa(){
		map.panTo(homemarker.getPoint());
		//homemarker.openInfoWindowHtml(homeHTML);
		homemarker.openExtInfoWindow(map, "mapiInfoWindow",homeHTML);
	}

	function irAZona(lat,lng,obj){
		map.closeExtInfoWindow();
		clean(obj.parentNode);
		obj.style.background = "#04A2C9";
		obj.style.color = "#FFFFFF";
		//homemarker.openInfoWindowHtml(homeHTML);
		setTimeout("map.panTo(new GLatLng("+lat+","+lng+"))",300);
	}

	function clean(obj){
		var objetos = obj.getElementsByTagName("div")
		for(var i=0; i < objetos.length; i++){
			objetos[i].style.background = "";
			objetos[i].style.color = "#000000";
		}
	}

	function openNegocioWindow(url, titulo){
		if (document.body && (document.body.clientWidth !=0)) {
		  clientWidth=document.body.clientWidth;
		  clientHeight=document.body.clientHeight;
	   }
	   if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
		  clientWidth=document.documentElement.clientWidth;   
		  clientHeight=document.documentElement.clientHeight;   
	   }
		var win;
		if(clientHeight > 655){
			win = new Window({className: "mapiwindow", width:770, height:590, url: url,resizable:false,minimizable:false,maximizable:false, recenterAuto:false, showEffectOptions: {duration:1.5}});
		}else{
			win = new Window({className: "mapiwindow", width:770, height:(clientHeight-65), url: url,resizable:false,minimizable:false,maximizable:false, recenterAuto:false, showEffectOptions: {duration:1.5}});
		}
		win.setZIndex(5);
		win.showCenter(true); 
		win.setDestroyOnClose();
	}

	function loadBarrios(zona){
		comunaActual = zona;
		barrioActual = "";
		loadNegocios();
		document.getElementById("barrios_container").innerHTML = "<div style=\"text-align:center;margin-top:10px;\"><object width=\"60\" height=\"60\"><param name=\"movie\" value=\"swf/loading.swf\"><embed src=\"swf/loading.swf\" width=\"60\" height=\"60\"></embed></object></div>";
		new Ajax.Request("load_barrios.php", {
		  method: 'post', parameters:{zona:zona},
		  onSuccess: function(transport) {
			document.getElementById("barrios_container").innerHTML = transport.responseText;
		  }
		});
	}
	
	function loadNegocios(){
		var seccs = document.getElementsByName("secciones[]");
		var strSeccs = "";
		for(var i =0; i< seccs.length ; i++){
			if(seccs[i].checked == true){
				strSeccs = strSeccs + seccs[i].value + ",";
			}
		}

		var domicilios = "0";
		domicheck = document.getElementById("domicilios").checked;
		if(domicheck){
			var domicilios = "1";
		}
		document.getElementById("resultadosBuscador").innerHTML = "<div style=\"text-align:center;margin-top:10px;\"><object width=\"60\" height=\"60\"><param name=\"movie\" value=\"swf/loading.swf\"><embed src=\"swf/loading.swf\" width=\"60\" height=\"60\"></embed></object></div>";

		new Ajax.Request("load_negocios.php?barrio="+barrioActual+"&seccs="+strSeccs+"&solodom="+domicilios+"&zona="+comunaActual, {
		  method: 'get',
		  onSuccess: function(transport) {
			document.getElementById("resultadosBuscador").innerHTML = transport.responseText;
		  }
		});
	}

function resize(){
	var footerHeight = 28;
	var headerHeight = 68
	clientWidth = 1024;
	clientHeight = 768;
	if (document.body && (document.body.clientWidth !=0)) {
		clientWidth=document.body.clientWidth;
		clientHeight=document.body.clientHeight;
	}
	if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
		clientWidth=document.documentElement.clientWidth;   
		clientHeight=document.documentElement.clientHeight;   
	}
	var contenedor = document.getElementById("content");
	var mapa = document.getElementById("map_canvas");
	var controlPanel = document.getElementById("controlPanel");
	var searchPanel = document.getElementById("searchPanel");
	var otrosPanel = document.getElementById("otrosPanel");
	contenedor.style.width = clientWidth + "px";
	mapa.style.width = (clientWidth-8) + "px";
	mapa.style.height = (clientHeight-headerHeight-8-footerHeight) + "px";
	searchPanel.style.height = (clientHeight-headerHeight-footerHeight-187) + "px";
	document.getElementById("searchDiv").style.height = document.getElementById("searchDivWhite").style.height = (clientHeight-headerHeight-footerHeight-187-10) + "px";
	document.getElementById("resultadosBuscador").style.height = (clientHeight-headerHeight-footerHeight-187-10-22) + "px";
		
	otrosPanel.style.top = controlPanel.style.top = (110) + "px";
	controlPanel.style.left = (clientWidth-542 - 12) + "px";
	otrosPanel.style.left = (clientWidth-542 - 12) + "px";
	if(clientWidth > 1040){
		document.getElementById("headerBlankSpace").style.display="block";
		document.getElementById("headerBlankSpace").style.width = (clientWidth-401-474) + "px";
	}else{
		document.getElementById("headerBlankSpace").style.display="none";
	}
}
function showhideSearchPanel(){
	if (document.getElementById("searchPanel").style.visibility != "visible"){
		document.getElementById("searchPanel").style.visibility = "visible";
		document.getElementById("tabResults").style.left = "273px";
	}else{
		document.getElementById("searchPanel").style.visibility = "hidden";
		document.getElementById("tabResults").style.left = "4px";
	}
}
function showhideControlPanel(){
	obj = document.getElementById("showhidebt");
	if (document.getElementById("controlPanel").style.visibility != "visible"){
		if (document.getElementById("otrosPanel").style.visibility == "visible"){
			document.getElementById("otrosPanel").style.visibility = "hidden";
			objtmp = document.getElementById("showhidebtotros");
		}
		document.getElementById("controlPanel").style.visibility = "visible";
		if(document.getElementById("searchPanel").style.visibility != "visible"){
			document.getElementById("searchPanel").style.visibility = "visible";
			document.getElementById("tabResults").style.left = "273px";
		}
	}else{
		document.getElementById("controlPanel").style.visibility = "hidden";
	}
}
	
function showCiudadades(){
	timeToCloseCiudades = 2;
	if (document.getElementById("cambiarCiudad").style.visibility != "visible"){
		hideCiudades();
	}
	document.getElementById("cambiarCiudad").style.visibility = "visible";
	
}
	
function hideCiudades(){
	timeToCloseCiudades--;
	if(timeToCloseCiudades > 0){
		setTimeout("hideCiudades()",1000);
	}else{
		document.getElementById("cambiarCiudad").style.visibility = "hidden";
	}
}

function showLocationWidget(){
	var clientWidth = 0;
	if (document.body && (document.body.clientWidth !=0)) {
	  clientWidth=document.body.clientWidth;
   }
   if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
	  clientWidth=document.documentElement.clientWidth; 
   }  
	timeToCloseLocation = 2;
	document.getElementById("locationwidget").style.left = ((clientWidth)-480)+"px";
	document.getElementById("locationwidget").style.visibility = "visible";
}

function hideLocationWidget(){
	timeToCloseLocation--;
	if(timeToCloseLocation > 0){
		setTimeout("hideLocationWidget()",1000);
	}else{
		document.getElementById("locationwidget").style.visibility = "hidden";
	}
}

function showFacebookWidget(){
	var clientWidth = 0;
	if (document.body && (document.body.clientWidth !=0)) {
	  clientWidth=document.body.clientWidth;
   }
   if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
	  clientWidth=document.documentElement.clientWidth; 
   }  
	timeToCloseFacebook = 15;
	if (document.getElementById("facebookwidget").style.visibility != "visible"){
		hideFacebookWidget();
	}
	document.getElementById("facebookwidget").style.left = ((clientWidth/2)-110)+"px";
	document.getElementById("facebookwidget").style.visibility = "visible";
}
	
function hideFacebookWidget(){
	timeToCloseFacebook--;
	if(timeToCloseFacebook > 0){
		setTimeout("hideFacebookWidget()",1000);
	}else{
		document.getElementById("facebookwidget").style.visibility = "hidden";
	}
}
	
function hideFacebookWidgetInstant(){
	document.getElementById("facebookwidget").style.visibility = "hidden";
}

function showhideOtros(){
	obj = document.getElementById("showhidebtotros");
	if (document.getElementById("otrosPanel").style.visibility != "visible"){
		if (document.getElementById("controlPanel").style.visibility == "visible"){
			document.getElementById("controlPanel").style.visibility = "hidden";
			objtmp = document.getElementById("showhidebt");
		}
		document.getElementById("otrosPanel").style.visibility = "visible";
	}else{
		document.getElementById("otrosPanel").style.visibility = "hidden";
	}
}
	
	function buscar(ciudadId){
		var q = document.getElementById("q").value;
		if(q){
			if(document.getElementById("searchPanel").style.visibility != "visible"){
				document.getElementById("searchPanel").style.visibility = "visible";
				document.getElementById("tabResults").style.left = "273px";
			}

			document.getElementById("resultadosBuscador").innerHTML = "<div style=\"text-align:center;margin-top:50px;\"><object width=\"60\" height=\"60\"><param name=\"movie\" value=\"swf/loading.swf\"><embed src=\"swf/loading.swf\" width=\"60\" height=\"60\"></embed></object></div>";

			new Ajax.Request("../load_search.php", {
			  method: 'post', parameters:{ciudad:varCiudad,q:q},
			  onSuccess: function(transport) {
				document.getElementById("resultadosBuscador").innerHTML = transport.responseText;
			  }
			});
		}
	}

	function buscarEnter(e){
		var keynum;
		if(window.event){
			keynum = e.keyCode
		}else if(e.which){
			keynum = e.which
		}

		if(keynum == 13)
			buscar(varCiudad);
	}

	function loadFacebook(){
		document.getElementById("facebookwidget").innerHTML = '<iframe src="http://www.facebook.com/plugins/likebox.php?id=27640849434&amp;width=246&amp;connections=8&amp;stream=false&amp;header=true&amp;height=255" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:255px;" allowTransparency="true"></iframe>';
	}
	
	function createShare(coord){
		document.getElementById("link-share").value = "http://www.mapidirectorio.com/"+varCiudadUrl+"/?p="+coord;
		document.getElementById("html-share").value = "<a href=\"http://www.mapidirectorio.com/"+varCiudadUrl+"/?p="+coord+"\" ><img src='http://www.mapidirectorio.com/img/markershare.gif' border=0 /></a>";
	}

	function findNegocio(id){
		var breakvar = false;
		var i =0;
		while(i < Puntos.length && !breakvar){

			if(Puntos[i].negocioID == id){
				breakvar = true;
				setTimeout("Markers["+i+"].openExtInfoWindow(map,\"mapiInfoWindow\",Puntos["+i+"].htmlCode)",500);
				setTimeout("map.setCenter(Markers["+i+"].getLatLng())",700);
			}
			i++;
		}
	}

	function query(){
		document.getElementById("q").value = queryText_Global;
		showhideSearchPanel();
		buscar(varCiudad);
	}

	function hideCargando(){
		if(document.getElementById('loadingDiv')){
			document.getElementById('content').style.display = 'block';
			document.getElementById('loadingDiv').style.display = 'none';
		}
	}

	function hideSinDomicilios(){
		
	}

	function showSinDomicilios(){
		
	}
	
	window.onload = function(){
		resize();
		hideCargando();
		initialize();
		if(paginaNegocio_Global)negInicio();
		if(resultadoBusquedas_Global)query();
		else setTimeout("loadNegocios()",800);
		ventanaAyuda();
		setTimeout("loadFacebook()",900);
	}
	
	window.onresize = function(){
		resize();
	}
	
	window.unload = function(){
		GUnload();
	};
	
	
function loadZonas(){
	if(varCiudad==1){
	var polygon = new GPolygon([
		new GLatLng(6.212308716246232,-75.57020902633667),
		new GLatLng(6.212564696189013,-75.56427597999573),
		new GLatLng(6.207946372254782,-75.56276321411133),
		new GLatLng(6.206229156028899,-75.56642174720764),
		new GLatLng(6.206197158157899,-75.57175397872925),
		new GLatLng(6.209578255778419,-75.57112097740173),
		new GLatLng(6.212308716246232,-75.57020902633667)
		], "#DA0B78", 2, 1, "#DA0B78", 0.2);
	map.addOverlay(polygon);
	}
}
	
var browserSupportFlag =  new Boolean();
function findLocation(){
	if(navigator.geolocation) {
		browserSupportFlag = true;
		navigator.geolocation.getCurrentPosition(function(position) {
		initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
			homemarker.setPoint(initialLocation);
			setCookieLatLng(homemarker.getPoint());
			setTimeout("homemarker.openExtInfoWindow(map,\"mapiInfoWindow\" ,homeHTML)",500);
			setTimeout("map.setCenter(initialLocation)",700);
			
		}, function() {
		handleNoGeolocation(browserSupportFlag);
	});
	}else if(google.gears) {
	// Try Google Gears Geolocation
		browserSupportFlag = true;
		var geo = google.gears.factory.create('beta.geolocation');
		geo.getCurrentPosition(function(position) {
			initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
			homemarker.setPoint(initialLocation);
			setCookieLatLng(homemarker.getPoint());
			setTimeout("homemarker.openExtInfoWindow(map,\"mapiInfoWindow\" ,homeHTML)",500);
			setTimeout("map.setCenter(initialLocation)",700);
			}, function(){
			handleNoGeolocation(browserSupportFlag);
		});
	}else{
	// Browser doesn't support Geolocation
	browserSupportFlag = false;
	handleNoGeolocation(browserSupportFlag);
	}
}
function handleNoGeolocation(errorFlag) {
	if(errorFlag == true) {
		contentString = "Error: El navegador no soporta este servixio.";
	}else{
		contentString = "Error: The Geolocation service failed.";
	}
	map.openExtInfoWindow(center, "mapiInfoWindow",contentString);
	map.setCenter(center);
}
