	
	var oBocasExpendio = {
		req: null,
		//
		init: function(){
			this.eBarrio = $('barrioBocaExpendio');
			this.eDireccion = $('direccionBocaExpendio');
			this.eError = $('errorBocaExpendio');
			this.eLoader = $('loaderBocaExpendio');
			this.eCont = $('grillaBocaExpendio');
			
			this.req = new Request();
			this.req.listener = this.onLoad.closure(this);
		}, 
		isValid: function (){
			var ret = false, vacio = 0, v = '';
			this.sError = '';
			this.sValues = {};
			//
			v = trim(this.eBarrio.value);
			if (v != '' && v.length < 3) { this.sError += 'Debe ingresar al menos 3 caracteres en el <strong>barrio</strong><br />'; }
			else if (v == '') { vacio++; }
			else {
				ret = true;
				this.sValues['barrio'] = v;
			}
			//
			v = trim(this.eDireccion.value);
			if (v != '' && v.length < 3) { this.sError += 'Debe ingresar al menos 3 caracteres en la <strong>direcci&oacute;n</strong><br />'; }
			else if (v == '') { vacio++; }
			else {
				ret = true;
				this.sValues['direccion'] = v;
			}
			//
			if (vacio == 2) {
				this.sError += 'Debe ingresar el <strong>barrio</strong> o la <strong>direcci&oacute;n</strong><br />';
			}
			//
			return ret;
		}, 
		onKeyPress: function(e){
			if (!!e && e.keyCode == 13) {
				this.search(e);
			}
		}, 
		//
		search: function(e){
			if (!!e) { StopEvent(e); }
			if (!this.req) { this.init(); }
			var v = '';
			
			if (this.isValid()) {
				if (!!this.sValues['barrio']) {
					v += 'barrio' + SEP_IGUAL + this.sValues['barrio'] + SEP_AND;
				}
				if (!!this.sValues['direccion']) {
					v += 'direccion' + SEP_IGUAL + this.sValues['direccion'] + SEP_AND;
				}
				
				this.eError.style.display = 'none';
				this.eCont.style.display = 'none';
				this.eLoader.style.display = 'block';
				this.req.pedir('/requests/bocas_expendio.php', v);
			}
			else {
				this.eError.innerHTML = this.sError;
				this.eError.style.display = 'block';
			}
		}, 
		onLoad: function(){
			var d = this.req.respuestaXML, o = null;
			
			this.eLoader.style.display = 'none';
			if (!!d) {
				this.eCont.innerHTML = d.firstChild.data;
				this.eCont.style.display = 'block';
				
				if (d.childNodes.length == 2) {
					this.initMap(d.lastChild.data);
				}
				FireEvent($('tabListadoBocaExpendio'), 'click');
				
				if(!!this.map){ this.map.checkResize(); }
			}
		}, 
		//
		changeTab: function(e, o){
			if (!!e) { StopEvent(e); }
			if (!!this.oTabOn) {
				this.oTabOn.t.className = '';
				this.oTabOn.c.style.display = 'none';
			}
			this.oTabOn = o;
			this.oTabOn.t.className = 'on';
			this.oTabOn.c.style.display = 'block';
			if (o.t.id == 'tabMapaBocaExpendio' && !this.map) {
				this.loadMap();
			}
		}, 
		//
		loadMap: function(){
			if (GBrowserIsCompatible() && !this.map) {
				this.map = new GMap2($("mapaBocaExpendio"));
				this.map.enableDragging();
				this.map.enableInfoWindow();
				this.map.enableDoubleClickZoom();
				this.map.disableContinuousZoom();
				this.map.disableGoogleBar();
				this.map.disableScrollWheelZoom();
				this.map.setCenter(new GLatLng('-31.416706174503304', '-64.18381333351135'), 14);
				this.map.addControl(new GLargeMapControl());
				
				if (!!this.infMap) { this.initMap(this.infMap); }
			}
		}, 
		initMap: function(inf){
			if (!this.map) { this.infMap = inf; }
			else { eval(inf); }
		}, 
		clearMarkers: function(){
			this.map.clearOverlays();
			this.markers = {};
		}, 
		addMarker: function(idx, ttl, lat, lng){
			if(lat != 0 && lng != 0){
				var GMO = {}
				GMO.icon = G_DEFAULT_ICON;
				GMO.dragCrossMove = false;
				GMO.title = ttl;
				GMO.clickable = true;
				GMO.draggable = false;
				GMO.bouncy = false;
				GMO.autoPan = false;
				
				this.markers[idx] = new GMarker(new GLatLng(lat, lng), GMO);
				this.markers[idx].show();
				this.map.addOverlay(this.markers[idx]);
				GEvent.addListener(this.markers[idx], "click", function() {
					this.openInfoWindowHtml(
					'<div class="globoMapaGoogle">' + 
					'<h5>Punto de venta</h5>' + 
					'<p>' + this.getTitle() + '</p>' + 
					'</div>'
					);
				});
			}
		},
		focusMarker: function(idx){
			oBocasExpendio.changeTab(false, {t:$('tabMapaBocaExpendio'), c:$('contMapaBocaExpendio')});
			if(!!this.markers && !!this.markers[idx]){
				this.map.setCenter(this.markers[idx].getLatLng(), 15);
				GEvent.trigger(this.markers[idx], "click");
			}
		}
	}
	
	AddEvent($('buscarBocaExpendio'), 'click', function(e){ oBocasExpendio.search(e); });
	AddEvent($('barrioBocaExpendio'), 'keypress', function(e){ oBocasExpendio.onKeyPress(e); });
	AddEvent($('direccionBocaExpendio'), 'keypress', function(e){ oBocasExpendio.onKeyPress(e); });
	
	AddEvent($('tabListadoBocaExpendio'), 'click', function(e){
		oBocasExpendio.changeTab(e, {t:$('tabListadoBocaExpendio'), c:$('contListadoBocaExpendio')});
	});
	AddEvent($('tabMapaBocaExpendio'), 'click', function(e){
		oBocasExpendio.changeTab(e, {t:$('tabMapaBocaExpendio'), c:$('contMapaBocaExpendio')});
	});
	FireEvent($('tabMapaBocaExpendio'), 'click');
	
