var cargaDefer = function(){
        S.map = new MapCity.Maps.map('mapa_mapa',{
                country:'chile'
                ,provider: 'mapcity'
                ,type: 'vector'
                ,controls:[
                    new MapCity.Maps.Controls.ArrowMapNorth({north: true})
                    ,new MapCity.Maps.Controls.ArrowMapSouth({south: true})
                    ,new MapCity.Maps.Controls.ArrowMapEast({east: true})
                    ,new MapCity.Maps.Controls.ArrowMapWest({west: true})
                    ,new MapCity.Maps.Controls.ZoomBar()
                    ,new MapCity.Maps.Controls.ScaleLine()
                    ,new MapCity.Maps.Controls.Navigation({zoomWheelEnabled:false})
                    ,new MapCity.Maps.Controls.SwitchMapBar({
                            vector: true
                            ,photo: true
                            ,guide: true
                    })
                ]
        });

	S.map.getLayer('lyrCapa', 'marker');

        utilidades.obtienePuntosPromocione('tableDatosConama');
};


MapCity.Core.onReady(function() {
	MapCity.Maps.setPopupNormal();
	S.resizeApp();	

	/* CARGA EL MAPA
	S.map = new MapCity.Maps.map('mapa_mapa',{
		country:'chile'
		,provider: 'mapcity'
		,type: 'vector'
		,controls:[
		    new MapCity.Maps.Controls.ArrowMapNorth({north: true})
		    ,new MapCity.Maps.Controls.ArrowMapSouth({south: true})
		    ,new MapCity.Maps.Controls.ArrowMapEast({east: true})
		    ,new MapCity.Maps.Controls.ArrowMapWest({west: true})
	            ,new MapCity.Maps.Controls.ZoomBar()
	            ,new MapCity.Maps.Controls.ScaleLine()
	            ,new MapCity.Maps.Controls.Navigation({zoomWheelEnabled:false})
		    ,new MapCity.Maps.Controls.SwitchMapBar({
			    vector: true
			    ,photo: true
			    ,guide: true
		    })
		]
	});	*/
	
	/* BUSQUEDA DIRECCION CON CAMPOS */
	S.searchSeparado = new MapCity.Widgets.AdvancedSearchComboBox({
		street: 'q1_dir1'
		,number: 'q1_dir2'
		,district: 'q1_dir3'
		,intersection: 'q1_dir4'
		,action: 'q1_bt'
		,limit: 9
		,widthStreet: 170
		,widthNumber: 55
		,widthDistrict: 110
		,widthIntersection: 170
		,before: function(){			
			q = S.query('input.q_dir'); S.each(q, function(el){el.disabled = true;});
			q = S.query('input.bt_buscar'); S.each(q, function(el){el.disabled = true;});
			S.before('D');
			S.map.removeAllFeatures();
			S.map.removeAllMarkers();
		//	S.home_toogle('hide');
		}
		,actionCallback: function(json,product,service){
			q = S.query('input.q_dir'); S.each(q, function(el){el.disabled = false;});
			q = S.query('input.bt_buscar'); S.each(q, function(el){el.disabled = false;});			
			S.resultadosD(json,product,service);
		}
	});
	
	
	S.searchChange(1);
	S.tabChange(1);
	//S.locate(S.map); //set map center a cuidad del ip
	q = S.query('input.bt_buscar'); S.each(q, function(el){el.disabled = false;});


	 /* CARGA EL MAPA
        S.map = new MapCity.Maps.map('mapa_mapa',{
                country:'chile'
                ,provider: 'mapcity'
                ,type: 'vector'
                ,controls:[
                    new MapCity.Maps.Controls.ArrowMapNorth({north: true})
                    ,new MapCity.Maps.Controls.ArrowMapSouth({south: true})
                    ,new MapCity.Maps.Controls.ArrowMapEast({east: true})
                    ,new MapCity.Maps.Controls.ArrowMapWest({west: true})
                    ,new MapCity.Maps.Controls.ZoomBar()
                    ,new MapCity.Maps.Controls.ScaleLine()
                    ,new MapCity.Maps.Controls.Navigation({zoomWheelEnabled:false})
                    ,new MapCity.Maps.Controls.SwitchMapBar({
                            vector: true
                            ,photo: true
                            ,guide: true
                    })
                ]
        });


	iutilidades.obtienePuntosPromocione('tableDatosConama');*/

	cargaDefer.defer(2000);
});

MapCity.Core.namespace('S');
S.totalMarkTick = 0;
S.home=1;
S.tok=0;
S.markers;
S.get=MapCity.Core.get; 
S.sel=MapCity.Core.select;
S.query=MapCity.Core.query;
S.each=MapCity.Core.each;
S.dom=MapCity.Core.DomHelper;
S.dom.useDom = true;
S.qb=1;
S.streetInfo = new MapCity.Services.Geocoding.streetInfoById();
S.enviroment = new MapCity.Services.Geocoding.enviroment();
S.bounds;
S.q;
S.p;
S.countArr;
S.numberLayer;
S.popups;
S.table= 'restaurant';
S.este;
S.norte="";
S.tipoVia;
S.nombreVia
S.altura;
S.comuna;
S.ciudad;
S.codigo;
S.entorno;

/* MANEJO DE RESULTADO */
S.before = function(i){
	var ul=S.get('ul_resultado'+i);
	while (ul.dom.firstChild) {
			ul.dom.removeChild(ul.dom.firstChild);
	}
	var l = {tag: 'li', cn: 
		{tag: 'div', cls: 'resuli', cn: [
			{tag: 'div', cls: 'resulico', cn: 
				{tag: 'img', src: 'img/loading.gif'}
			},
			{tag: 'div', cls: 'resultxt', cn: 
				{tag: 'div', 
				html: 'BUSCANDO...'
				}
			},
			{tag: 'div', cls: 'clear'}
		]}
	};
	S.dom.append(ul,l);
	S.get('resultado'+i).setDisplayed('block');
	S.sel('a.reset').setDisplayed('inline');
}

S.mouseOver=function(idBoton){
		document.getElementById(idBoton).src = 'images/imgTicket/ticket-'+idBoton+'-active.png';
	}
S.mouseOut=function(idBoton){
		document.getElementById(idBoton).src = 'images/imgTicket/ticket-'+idBoton+'-clear.png';
}
S.resultadosC = function(json,product,service){
	S.q=json;
	var puntos=0;
	var ul=S.get('ul_resultadoC');
	while (ul.dom.firstChild) {
			ul.dom.removeChild(ul.dom.firstChild);
	}
	S.markers = Array(S.q.totalCount);
	if(product=='geobusiness' && service=='searchcommerce')
		for (var i=0;i<S.q.totalCount;i++)
			if(S.q.searchcommerce[i].lon && S.q.searchcommerce[i].lat){
				var lonlat = new MapCity.Maps.LonLat(S.q.searchcommerce[i].lon, S.q.searchcommerce[i].lat);
				var l = {tag: 'li', id: 'resul'+i, cn: 
					{tag: 'div', cls: 'resuli', onclick: 'S.clickComercio('+i+');', cn: [
						{tag: 'div', cls: 'resulico', cn: 
							{tag: 'img', src: 'img/marker'+(i+1)+'.png'}
						},
						{tag: 'div', cls: 'resultxt', cn: [
							{tag: 'div', html: S.q.searchcommerce[i].name+': <strong>'+S.q.searchcommerce[i].fantasyName+'</strong>. Tel:'+S.q.searchcommerce[i].originalPhone
							},
							{tag: 'div', cn:
								{tag: 'a', 
								href: 'javascript:S.clickComercio('+i+');',
								html: S.q.searchcommerce[i].classStreet+' '+S.q.searchcommerce[i].nameStreet+' '+S.q.searchcommerce[i].number+', '+S.q.searchcommerce[i].district
								}
							}							
						]},
						{tag: 'div', cls: 'clear'}
					]}
				};
				S.dom.append(ul,l);
				var icon = new MapCity.Maps.Icon( 
						'img/marker'+(i+1)+'.png' 
						,new MapCity.Maps.Size(28,28) 
				);	
				S.markers[i]=S.map.addPopUpMarker( 
					null
					,lonlat 
					,S.q.searchcommerce[i].name+': <strong>'+S.q.searchcommerce[i].fantasyName+'</strong>. Fono:'+S.q.searchcommerce[i].originalPhone
					,icon 
					,true 
					,true 
					,MapCity.Maps.PopUp.FramedBubble
					,false
				);				
			}			
	if(S.q.totalCount==0){ //NO SE ENCONTRARON RESULTADOS
		var l = {tag: 'li', id: 'resul'+i, cn: 
			{tag: 'div', cls: 'resuli', cn: [
				{tag: 'div', cls: 'resulico', cn: 
					{tag: 'img', src: 'img/error.png'}
				},
				{tag: 'div', cls: 'resultxt', cn: 
					{tag: 'div', 
					html: 'NO SE ENCONTRARON RESULTADOS'
					}
				},
				{tag: 'div', cls: 'clear'}
			]}
		};
		S.dom.append(ul,l);		
	}
	var icon = new MapCity.Maps.Icon( 
			'img/marker.png' 
			,new MapCity.Maps.Size(28,28) 
	);
	if(S.q.address){
		var lonlat = new MapCity.Maps.LonLat(S.q.address.lon, S.q.address.lat);
		S.markers[i]=S.map.addPopUpMarker( 
			null
			,lonlat 
			,S.q.address.classStreet+' '+S.q.address.name+' '+S.q.address.number+', '+S.q.address.district
			,icon 
			,true 
			,true 
			,MapCity.Maps.PopUp.FramedBubble
			,false
		);
	}
	S.zoomToExtent();
}

S.resultadosD = function(json,product,service){
	
	//alert('product,service '+product+" "+service)
	S.q=json;
	var puntos=0;
	var ul=S.get('ul_resultadoD');
	
	while (ul.dom.firstChild) {
			ul.dom.removeChild(ul.dom.firstChild);
	}
	S.markers = Array(S.q.totalCount);
	S.romoverLosMarker();
	
	if(product=='geocoding' && service=='searchstreet'){
		for (var i=0;i<S.q.totalCount;i++){
			if(S.q.searchstreet[i].lon && S.q.searchstreet[i].lat){/* ENCONTRO DIRECCION */
				puntos=1;
				var lonlat = new MapCity.Maps.LonLat(S.q.searchstreet[i].lon, S.q.searchstreet[i].lat);
				if(S.q.totalCount==1){ //cuando es solo un resultado la estrella no tienen numeros
					var icon = new MapCity.Maps.Icon( 
							'img/marker.png' 
							,new MapCity.Maps.Size(28,28) 
					);
					S.markers[i]=S.map.addPopUpMarker( 
						null
						,lonlat 
						,S.q.searchstreet[i].classStreet+' '+S.q.searchstreet[i].name+' '+S.q.searchstreet[i].number+', '+S.q.searchstreet[i].district
						,icon 
						,true 
						,true 
						,MapCity.Maps.PopUp.FramedBubble
						,false
					);									
					S.clickResultado("Di",i);		
				}
				else {
					var l = {tag: 'li', id: 'resul'+i, cn: 
						{tag: 'div', cls: 'resuli', /*onclick: 'S.clickResultado("Di",'+i+');',*/ cn: [
							{tag: 'div', cls: 'resulico', cn: 
								{tag: 'img', src: 'img/marker'+(i+1)+'.png'}
							},
							{tag: 'div', cls: 'resultxt', cn:
								{tag: 'div', cn:
									{tag: 'a', 
									href: 'javascript:S.clickResultado("Di",'+i+');', onmouseover: 'S.setCenter3('+i+');',
									html: S.q.searchstreet[i].classStreet+' '+S.q.searchstreet[i].name+' '+S.q.searchstreet[i].number+', '+S.q.searchstreet[i].district
									}
								}
							},
							{tag: 'div', cls: 'clear'}
						]}
					};
					S.dom.append(ul,l);
					var icon = new MapCity.Maps.Icon( 
							'img/marker'+(i+1)+'.png' 
							,new MapCity.Maps.Size(28,28) 
					);
					S.markers[i]=S.map.addPopUpMarker( 
						null
						,lonlat 
						,S.q.searchstreet[i].classStreet+' '+S.q.searchstreet[i].name+' '+S.q.searchstreet[i].number+', '+S.q.searchstreet[i].district
						,icon 
						,true 
						,true 
						,MapCity.Maps.PopUp.FramedBubble
						,false
					);
				}			
			}
			else /* ENCONTRO RESULTADO SIN LONLAT (CALLE)*/ {
				puntos=0;
				if(S.q.totalCount==1){
					S.clickResultado("Ca",0);
				}
				else{				
					var l = {tag: 'li', id: 'resul'+i, cn: 
						{tag: 'div', cls: 'resuli', onclick: 'javascript:S.clickResultado("Ca",'+i+');', cn: [
							{tag: 'div', cls: 'resulico', cn: 
								{tag: 'img', src: 'img/marker'+(i+1)+'.png'}
							},
							{tag: 'div', cls: 'resultxt', cn: 
								{tag: 'div', cn:
									{tag: 'a', 
									href: 'javascript:S.clickResultado("Ca",'+i+');',
									html: S.q.searchstreet[i].classStreet+' '+S.q.searchstreet[i].name+', '+S.q.searchstreet[i].district
									}
								}
							},
							{tag: 'div', cls: 'clear'}
						]}
					};
					S.dom.append(ul,l);
				}
			}
		}
	}else if(product=='geocoding' && service=='searchintersection')
		for (var i=0;i<S.q.totalCount;i++){
			puntos=1;
			if(S.q.searchintersection[i].lon && S.q.searchintersection[i].lat)/* ENCONTRO INTERSECCION */{
				var lonlat = new MapCity.Maps.LonLat(S.q.searchintersection[i].lon, S.q.searchintersection[i].lat);
				if(S.q.totalCount==1){ //cuando es solo un resultado la estrella no tienen numeros
					var icon = new MapCity.Maps.Icon( 
							'img/marker.png' 
							,new MapCity.Maps.Size(28,28) 
					);	
					S.markers[i]=S.map.addPopUpMarker( 
						null
						,lonlat 
						,S.q.searchintersection[i].classStreet1+' '+S.q.searchintersection[i].nameStreet1+' CON '+S.q.searchintersection[i].classStreet2+' '+S.q.searchintersection[i].nameStreet2+', '+S.q.searchintersection[i].districtStreet1
						,icon 
						,true 
						,true 
						,MapCity.Maps.PopUp.FramedBubble
						,false
					);					
					S.clickResultado("In",i);			
				}
				else {
					var l = {tag: 'li', id: 'resul'+i, cn: 
						{tag: 'div', cls: 'resuli', onclick: 'javascript:S.clickResultado("In",'+i+');', onmouseover: 'S.setCenter3('+i+');', cn: [
							{tag: 'div', cls: 'resulico', cn: 
								{tag: 'img', src: 'img/marker'+(i+1)+'.png'}
							},
							{tag: 'div', cls: 'resultxt', cn: [
								{tag: 'div', cn:
									{tag: 'a', 
									href: 'javascript:S.clickResultado("In",'+i+');', onmouseover: 'S.setCenter3('+i+');',
									html: S.q.searchintersection[i].classStreet1+' '+S.q.searchintersection[i].nameStreet1+' / '+S.q.searchintersection[i].classStreet2+' '+S.q.searchintersection[i].nameStreet2
									}
								},
								{tag: 'div',
								html: S.q.searchintersection[i].districtStreet1
								}						
							]},
							{tag: 'div', cls: 'clear'}
						]}
					};
					S.dom.append(ul,l);
					var icon = new MapCity.Maps.Icon( 
							'img/marker'+(i+1)+'.png' 
							,new MapCity.Maps.Size(28,28) 
					);
					S.markers[i]=S.map.addPopUpMarker( 
						null
						,lonlat 
						,S.q.searchintersection[i].classStreet1+' '+S.q.searchintersection[i].nameStreet1+' CON '+S.q.searchintersection[i].classStreet2+' '+S.q.searchintersection[i].nameStreet2+', '+S.q.searchintersection[i].districtStreet1
						,icon 
						,true 
						,true 
						,MapCity.Maps.PopUp.FramedBubble
						,false
					);					
				}		
	
			}
		}
	else if(product=='geocoding' && service=='searchdistrict') //COMUNA
		for (var i=0;i<S.q.totalCount;i++){ 
		 	var l = {tag: 'li', id: 'resul'+i, cn: 
				{tag: 'div', cls: 'resuli', onclick: 'javascript:S.clickResultado("Co",'+i+');', cn: [
					{tag: 'div', cls: 'resulico', cn: 
						{tag: 'img', src: 'img/marker'+(i+1)+'.png'}
					},
					{tag: 'div', cls: 'resultxt', cn: 
						{tag: 'div', cn:
							{tag: 'a', 
							href: 'javascript:S.clickResultado("Co",'+i+');',
							html: S.q.searchdistrict[i].label
							}
						}
					},
					{tag: 'div', cls: 'clear'}
				]}
			};
			S.dom.append(ul,l);	
		}
	else if(product=='geocoding' && service=='streetinfobycp') //CODIGO POSTAL
		for (var i=0;i<S.q.totalCount;i++){ 
		 	var l = {tag: 'li', id: 'resul'+i, cn: 
				{tag: 'div', cls: 'resuli', onclick: 'javascript:S.clickResultado("Co",'+i+');', cn: [
					{tag: 'div', cls: 'resulico', cn: 
						{tag: 'img', src: 'img/marker'+(i+1)+'.png'}
					},
					{tag: 'div', cls: 'resultxt', cn: 
						{tag: 'div', cn:
							{tag: 'a', 
							href: 'javascript:S.clickResultado("Co",'+i+');',
							html: S.q.searchdistrict[i].label
							}
						}
					},
					{tag: 'div', cls: 'clear'}
				]}
			};
			S.dom.append(ul,l);	
		}	
	if(S.q.totalCount==0){ //NO SE ENCONTRARON RESULTADOS
		var l = {tag: 'li', id: 'resul'+i, cn: 
			{tag: 'div', cls: 'resuli', cn: [
				{tag: 'div', cls: 'resulico', cn: 
					{tag: 'img', src: 'img/error.png'}
				},
				{tag: 'div', cls: 'resultxt', cn: 
					{tag: 'div', 
					html: 'NO SE ENCONTRARON RESULTADOS'
					}
				},
				{tag: 'div', cls: 'clear'}
			]}
		};
		S.dom.append(ul,l);		
	}
	else if(puntos==1)
		S.zoomToExtent(); //extend a los puntos
	else if(puntos==0 && S.q.totalCount>1)
		S.drawStreet(0);
}

S.zoomToExtent = function(){
	S.bounds = new OpenLayers.Bounds();
	for(var z=0; z<S.markers.length /*&& z<4*/; z++)		
		S.bounds.extend(S.markers[z].lonlat);
	S.bounds.toBBOX();
	S.map.zoomToExtent(S.bounds);
}

S.drawStreet = function(j){
	S.map.removeAllFeatures();
	S.streetInfo.get(
		{idStreet: S.q.searchstreet[j].idStreet},
		function(json){
			var feat=S.map.addFeatureWKT(null,json.streetinfobyid[0].wkt);
			S.bounds=feat.geometry.getBounds();
			S.map.zoomToExtent(S.bounds);
		}
	);
}


S.clickResultado = function(t,j){   
	S.sel('a.back').setDisplayed('inline-block');
	S.numberLayer = j; 
	var q = '';
	if(t=='Di'){
		S.norte = S.q.searchstreet[j].lon;
	    S.este = S.q.searchstreet[j].lat;
	    S.tipoVia =S.q.searchstreet[j].classStreet;
		S.nombreVia =S.q.searchstreet[j].name;
		S.altura =S.q.searchstreet[j].number;
		S.comuna =S.q.searchstreet[j].district;
		S.ciudad ='';
		
		S.sel('input.q_dir1').setStyle({'background': '#FFFFFF ', 'color': '#000000'});
		S.sel('input.q_dir2').setStyle({'background': '#FFFFFF ', 'color': '#000000'});
		S.sel('input.q_dir3').setStyle({'background': '#FFFFFF ', 'color': '#000000'});
		S.sel('input.q_dir5').setStyle({'background': '#FFFFFF ', 'color': '#000000'});
		
		
		q = S.query('input.q_dir1'); S.each(q, function(el){el.value = S.q.searchstreet[j].classStreet+' '+S.q.searchstreet[j].name;});
		q = S.query('input.q_dir2'); S.each(q, function(el){el.value = S.q.searchstreet[j].number;});
		q = S.query('input.q_dir3'); S.each(q, function(el){el.value = S.q.searchstreet[j].district;});
		q = S.query('input.q_dir4'); S.each(q, function(el){el.value = '';});
		q = S.query('input.q_dir5'); S.each(q, function(el){el.value = S.q.searchstreet[j].name+" "+S.q.searchstreet[j].number+", "+S.q.searchstreet[j].district;});
		
	
	   	for(var n=0; n<S.markers.length-1; n++)
			S.markers[n].hidePopup();
		S.markers[j].showPopup();
		S.map.setCenter(S.markers[j].lonlat,13);
		S.get('resultadoD').setDisplayed('none');
		S.startRequest();
			
	}
	if(t=='In'){
		
		S.norte = S.q.searchintersection[j].lon;
	    S.este = S.q.searchintersection[j].lat;
	    S.tipoVia =S.q.searchintersection[j].classStreet;
		S.nombreVia =S.q.searchintersection[j].name;
		S.altura =S.q.searchintersection[j].number;
		S.comuna =S.q.searchintersection[j].district;
		S.ciudad ='';
		
		S.norte = S.q.searchintersection[j].lon;
	    S.este = S.q.searchintersection[j].lat;
		q = S.query('input.q_dir1'); S.each(q, function(el){el.value = S.q.searchintersection[j].nameStreet1;});
		q = S.query('input.q_dir2'); S.each(q, function(el){el.value = '';});
		q = S.query('input.q_dir3'); S.each(q, function(el){el.value = S.q.searchintersection[j].districtStreet1;});
		q = S.query('input.q_dir4'); S.each(q, function(el){el.value = S.q.searchintersection[j].nameStreet2;});
		q = S.query('input.q_dir5'); S.each(q, function(el){el.value = S.q.searchintersection[j].nameStreet1+" con "+S.q.searchintersection[j].nameStreet2+", "+S.q.searchintersection[j].districtStreet1;});
	//	S.setCenter2(j,12);
	   S.startRequest();
	}
	if(t=='Co'){
		S.map.removeAllFeatures();
		var feat=S.map.addFeatureWKT(null,S.q.searchdistrict[j].wkt);
		S.bounds=feat.geometry.getBounds();
		S.map.zoomToExtent(S.bounds);
		q = S.query('input.q_dir1'); S.each(q, function(el){el.value = '';});
		q = S.query('input.q_dir2'); S.each(q, function(el){el.value = '';});
		q = S.query('input.q_dir3'); S.each(q, function(el){el.value = S.q.searchdistrict[j].label;});
		q = S.query('input.q_dir4'); S.each(q, function(el){el.value = '';});
		q = S.query('input.q_dir5'); S.each(q, function(el){el.value = S.q.searchdistrict[j].label;});			
	}
	
};

S.backResultado = function(){
	S.get('resultadoD').setDisplayed('block');
	//S.get('resultadoC').setDisplayed('none');
	S.sel('a.back').setDisplayed('none');	
	S.romoverLosMarker();
	//var elemento = document.getElementById("searchform22");
	//elemento.innerHTML = '';
	//elemento.className = "";
	S.norte = '';
	S.este = '';
};





S.resetResultado = function(){
		var q = '';
	S.get('resultadoD').setDisplayed('none');
	S.sel('input.q_dir1').setStyle({'background': '#FFFFFF url(img/q_dir1.png) left no-repeat', 'color': '#000000'});
	S.sel('input.q_dir2').setStyle({'background': '#FFFFFF url(img/q_dir2.png) left no-repeat', 'color': '#000000'});
	S.sel('input.q_dir3').setStyle({'background': '#FFFFFF url(img/q_dir3.png) left no-repeat', 'color': '#000000'});
	S.sel('input.q_dir4').setStyle({'background': '#FFFFFF url(img/q_dir4.png) left no-repeat', 'color': '#000000'});
	S.sel('input.q_dir5').setStyle({'background': '#FFFFFF url(img/q_dir5.png) left no-repeat', 'color': '#000000'});
	q = S.query('input.q_dir'); S.each(q, function(el){el.value = ''; el.disabled = false;});
	q = S.query('input.q_com'); S.each(q, function(el){el.value = ''; el.disabled = false;});
	q = S.query('input.bt_buscar'); S.each(q, function(el){el.disabled = false;});
	S.sel('a.back').setDisplayed('none');
	$('lonDir').value = '';
	$('latDir').value = '';
	S.romoverLosMarker();
	//var elemento = document.getElementById("searchform22");
	//elemento.innerHTML = '';
	//elemento.className = "";
	S.norte = '';
	S.este = '';	
	
};

S.setCenter3 = function(i){
	for(var j=0; j<S.markers.length; j++)
		S.markers[j].hidePopup();
	    S.markers[i].showPopup();
	    S.map.zoomToExtent(S.bounds);
	//map.setCenter(S.markers[i].lonlat);
};

S.setCenter2 = function(i,z){
	
	for(var j=0; j<S.markers.length-1; j++)
		S.markers[j].hidePopup();
	S.markers[i].showPopup();
	alert(S.markers[i].lonlat)	
	alert(z)
	S.map.setCenter(S.markers[i].lonlat,z);
};

S.setCenter = function(lon,lat,z,i){
	var lonlat = new MapCity.Maps.LonLat(lon,lat);
	S.map.setCenter(lonlat,z);
	if(i){
		for(var j=0; j<S.markers.length; j++)
			S.markers[j].hidePopup();
		S.markers[i].showPopup();
		
	}	
};

S.searchChange = function(i){
	S.get('tab11').setDisplayed('block');
}

S.tabChange = function(i){
	S.get('tab1').setDisplayed('block');
	if(i!=3)
		S.get('resultadoD').appendTo('tab'+i);
}
S.cambiaAdhesivo = function(dato,dato2,dato3){
	document.getElementById(dato).src = 'images/imgTicket/ticket-'+dato+'-active.png';
	document.getElementById(dato2).src = 'images/imgTicket/ticket-'+dato2+'-clear.png';
	document.getElementById(dato3).src = 'images/imgTicket/ticket-'+dato3+'-clear.png';
	var fondo;
	
	switch(dato)
		{
		case "restaurant":
		  fondo = 1;
		  break;
		case "sala_cuna":
		  fondo = 2;
		   break;
		case "complimen":
		  fondo = 3;
		  break;
		default:
		  
		}
	
	S.get('searchform').setStyle({'background': 'url(images/imgTicket/caja-main-active'+fondo+'.png) no-repeat'});
	
	S.table = dato; 
	if (S.norte!="")
	{
		S.romoverLosMarker();
		
		S.startRequest();
		
			
	}
	
	
}

S.resizeApp = function() {
	var side=380;
	var top=26;
	var head=92;
	var mapa=1;
	h = S.viewport.getHeight();
	w = S.viewport.getWidth();
	
	//S.get('header_container').setStyle('width', eval(w-50)+'px');	
	h = h - eval(head+top);
	w = w - side - 10;
	
	S.get('page').setStyle('height', eval(h+2+50)+'px');
	S.get('mapa').setStyle('height', eval(h-180)+'px');
	S.get('mapa').setStyle('width', eval(w+side-80)+'px');
	S.get('mapa_mapa').setStyle('height', eval(h-1-mapa-180)+'px');
	S.get('panel').setStyle('height', eval(h)+'px');
	
	//if(S.get('searchform22').getStyle('display')!='none'){
	//	var ancoMap =	S.get('mapa').getStyle('width');
        //anchoMap = ancoMap.substring(0,ancoMap.length-2)
        //valor = parseInt(anchoMap)
       // valor = valor-371;
        //S.get('searchform22').setStyle('width', eval((valor)-50)+'px');
    //}

};

S.viewport = {
	getWidth: function(){
	    if( typeof( window.innerWidth ) == 'number' ) {
	    	return window.innerWidth; //Non-IE
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    	return document.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    	return document.body.clientWidth; //IE 4 compatible
	  }
	}
	,getHeight: function(){
	    if( typeof( window.innerWidth ) == 'number' ) {
	        	return window.innerHeight; //Non-IE
	      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	        	return document.documentElement.clientHeight; //IE 6+ in 'standards compliant mode'
	      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	        	return document.body.clientHeight; //IE 4 compatible
	      }
	}
};



S.startRequest = function() {
	
	
};

S.creaMarkers2 = function(lpLon, lpLat, szContentMarker,i) {
	if(i==0){
		
		 var icon = new MapCity.Maps.Icon( 
	        'images/imgTicket/icono_accor.gif'
	        ,new MapCity.Maps.Size(30,30) 
			
		 ); 
	}else{
		 	var icon = new MapCity.Maps.Icon( 
	        'images/imgTicket/icono_accor.gif'
	        ,new MapCity.Maps.Size(20,20) 
			
		 );	
	}
	var lonlat= new OpenLayers.LonLat(lpLon, lpLat,i)
	eval("var layerCapa = S.map.getLayer('lyrCapa" + i + "', 'marker');");
	if (layerCapa != undefined) {
			eval("S.map.removeAllMarkers('lyrCapa" + i + "', 'marker');");
			eval("var layerCapa = S.map.getLayer('lyrCapa" + i + "', 'marker');");
			eval("S.map.getLayer('lyrCapa" + i + "', 'marker').setVisibility(true);");
	}else {
			eval("var layerCapa = S.map.addLayer('lyrCapa" + i + "', 'marker');")
			eval("S.map.getLayer('lyrCapa" + i + "', 'marker').setVisibility(true);");
	}
	
	var marker = new MapCity.Maps.Marker( 
	        lonlat 
	        ,icon 
	); 
	S.map.addMarker(layerCapa,marker);
		 
	OpenLayers.Event.observe(icon.imageDiv,'click',function(e){
			//alert('maker');
			S.popupPuntoPromocion(lpLon,lpLat, szContentMarker);
			Event.stop(e);
	});
	
	
	
}

S.popupPuntoPromocion = function(lon,lat,content) {
	content= content.replace("***","'");
		var lonlat = new OpenLayers.LonLat(lon,lat)
		if (S.popups != undefined) {
				S.popups.hide();
		}
		  S.popups = new MapCity.Maps.PopUp.FramedCloud(
						   "InfoDataCliente",
						   lonlat,
						   new OpenLayers.Size(150,150),
						   content,
						   {
							   size: new OpenLayers.Size(5,5),
							   offset: new OpenLayers.Pixel(0,0)
						   },
						   true
				);			
			S.map.addPopup(S.popups);
			S.popups.show();
			
	}

S.romoverLosMarker = function (){
	
	
		for (i=0;i<S.totalMarkTick;i++){
	        eval("S.map.removeAllMarkers('lyrCapa" + i + "', 'marker');");	
	   }
}

S.romoverLosMarker2 = function (index){
	 
	
	   
		for (i=0;i<S.totalMarkTick;i++){
			eval("var layerCapa = S.map.getLayer('lyrCapa" + i + "', 'marker');");
			
		   eval("S.map.getLayer('lyrCapa" + i + "', 'marker').setVisibility(false);");
	   }
	   
	
		for (z=index*10;z<(index*10)+10;z++){
			eval("var layerCapa2 = S.map.getLayer('lyrCapa" + z + "', 'marker');");
			if (layerCapa2 != undefined) 
	        eval("S.map.getLayer('lyrCapa" + z + "', 'marker').setVisibility(true);");
	   }
	   
	   
}

