//Globales
Site.visibleColLeft = true;
Site.visibleColRight = true;
Site.NoCookies=false;
Site.FadeVelocity=0;
Site.IE;
Site.color_menu = "";
Site.color_title = "";
Site.color_active = "";
Site.color_pointer_menu = "";	
Site.color_pointer_active_menu = "";	
Site.NoSaveThemeSelected="";

Site.logo = "";
Site.title_bar = "";	
Site.motive = "";

Site.DefaultBanner = "";


Site.bandera=0;

//=============CONFIG SITE ==========
Site.Config="";

// =======   MENU WIDGET BUSQUEDA  =============
Site.menu_color="";
Site.menu_active_color="";

Site.menu_style="";
Site.menu_active_style="";

// =======   GAME  =============
Site.StateGame="off";

// =======   TIPS  =============

Site.TipsArray = new Array();
Site.TipsNanPosition = new Array();


// =======    CANALES ACTIVOS =============
Site.num_activechannels="";
Site.exist_channel_active=false;
Site.is_channel_active="";
Site.ChannelActive=new Array();
//Site.BannerTimer=0;

// =======    GEO TWITTER =============
Site.layerTwitter=="";
Site.SwitchRefreshTwetts=false;



// =======    JQUERY =============
$(document).ready(function() {
	Site.IE=Site.IsInternetExplorer();						   
						   
	$(window).bind('resize', function() {	
		
		if(Site.visibleColRight==true)
			ResizeChangeBarRight();
		//if (Site.visibleColRight==true) document.getElementById("tabsF").style.left = (widthWindow-550-183)+"px"; else document.getElementById("tabsF").style.left = (widthWindow-730)+"px";		
	});	
	
	var widthWindow = $(window).width();

	$("#leftpanelContent").show('fast');	
			
	$("#loadingglobal").hide();	
	document.getElementById('loadingsearch').style.display="none";

	$("#tabsF").css("right","0px");
	document.getElementById("tabsF").style.visibility='visible';
	
	
	Site.CurrentCountry=(Site.CurrentCountry=='ch')?'cl':Site.CurrentCountry;
	
	
	var pais=(Site.CurrentCountry=='ch')?'cl':Site.CurrentCountry;
	document.getElementById('imgCoutry').src='img/pais/'+pais+'.png'

	Site.LoadConfiguration();	  
   if (Site.IE) {
	   Site.FadeVelocity=0;
	   window.onerror=function(){return true}
   }
	//$.ajax({type: 'POST',url: '/ws/interface/MapcitySocial.game.php',data:"method=sv",success: function(data) {	Site.Machine = parseInt(data);}})	 
	 ChangeBarRight();
    // Site.loadTips();
	
	
	
	//MUESTRA EL BANNER SOLO EN LOS PAISES QUE CUENTEN CON PUBLICIDAD ==========================================
	
					Site.Switch_Off_Banner();
					
	//============================================================================================================
	
	
	
});

Site.Switch_Off_Banner=function(){

	//MUESTRA EL BANNER SOLO EN LOS PAISES QUE CUENTEN CON PUBLICIDAD
	//cl CHILE
	//pe PERU
	//ar  ARGENTINA
	//br  BRAZIL
	//mx   MEXICO 	
	
	var paises_con_publidad =  new Array("cl");
	
	
	var pais_actual = location.href;
	var parametros = location.search;
	if (parametros==""){	
	
		pais_actual = pais_actual.split("/");
		pais_actual = pais_actual[2];
		pais_actual = pais_actual.split(".");
		pais_actual = pais_actual[(pais_actual.length)-1];
		pais_actual = (pais_actual == "com")?"cl":pais_actual;
		

	}else{
	
		parametros = parametros.substring(1,(parametros.length));
		
		if (parametros.indexOf("country")>-1){
			parametros = parametros.split("&");
			parametros=parametros[1];
			pais_actual=parametros.split("=");
			pais_actual = pais_actual[1];
		}
		
	}

	var show_banner=false;
	
	for (var c=0;c<paises_con_publidad.length;c++){
				
		if (pais_actual!=paises_con_publidad[c]){
			
			show_banner=false;
		
		}else{
		
			show_banner=true;		
			
		}
	}
	
	if (show_banner==false){
			ChangeBarRight();					
			try{
				$("#divBanner").hide("fast");
				$("#colright").hide("fast");
				$("#imgchange_right").hide("fast");	
			
			}catch(err){}	
		}else{
		
			try{
				$("#divBanner").show("fast");
				$("#colright").show("fast");
				$("#imgchange_right").show("fast");				
			}catch(err){}	
	
			
		}
	
	
}

Site.LoadConfiguration=function(){
	$.ajax({
	  type: 'GET',
	  url: '/ws/interface/MapcitySocial.site.php',
	  dataType: 'json',
	  data: 'method=config&pais='+Site.CurrentCountry+'',
	  success: function(theme_json) {
			Site.Config = theme_json;
		}
	});						
}

Site.loadTips=function(){
		var len_arr="";
		var tips_list=new Array();
		var tips=new Array();
			
		$.ajax({
			type: 'GET',
			url: '/ws/interface/MapcitySocial.site.php',
			data: 'method=tipslist',
			success: function(data) {
														
				tips_list=data.split("{rg}");
				len_arr = tips_list.length;				
				for (var c=0;c<len_arr;c++){
					
					Site.TipsArray[c]=tips_list[c];  
					var cod = "";
					var msg = "";
					var tips = "";
					var horizontal = "";					
					var vertical = "";					
					tips =tips_list[c].split("{fld}");
					cod = "#"+tips[1];
					top = tips[4];
					left = tips[5];
					right = tips[6];															
					bottom = tips[7];	
					
					if (top>-1 || left>-1 || right>-1){
					
						var tipdata = cod+"{fld}"+top+"{fld}"+left+"{fld}"+right+"{fld}"+bottom;	
						Site.TipsNanPosition.push(tipdata);
					}					
				}
			    setInterval("Site.goTips();",5000);
			}
		});
}

Site.goTips=function(){
    
    
        var numtips = Site.TipsArray.length;
        var thistip = Site.Aleatorio(0,numtips-1);
		var cod = "";
		var msg = "";
		var tips = "";
		var horizontal = "";					
		var vertical = "";					
		
		tips = Site.TipsArray[thistip].split("{fld}");
		cod = "#"+tips[1];
		msg = tips[2];
		pos = tips[3];
		offsetx = tips[5];
		offsety = tips[6];
		try{ $("#tooltip").remove(); }catch(err){}
		tooltip_init(300,100,"body");	
		tooltip_show(msg,$(cod),pos,offsetx,offsety,3000);
}

Site.Aleatorio=function(inferior,superior){
    numPosibilidades = superior - inferior
    aleat = Math.random() * numPosibilidades
    aleat = Math.floor(aleat)
    return parseInt(inferior) + aleat
} 

Site.SetBackgrd=function(theme){
	Site.Backgrd=theme;		
}
Site.IsInternetExplorer=function(){
	var navegador = navigator.appName;

	if (navegador == "Microsoft Internet Explorer"){
		var IsExplorer = (MapCity.Core.isIE6==true)?6:(MapCity.Core.isIE7==true)?7:8;
			
	} else{
		var IsExplorer = false;
	}
	return IsExplorer;
}
function ChangeLine(num){
	var miclase = "divBusquedas_line"+num; 
	document.getElementById('search_by_address_line').className=miclase;
}
function ChangeButtonSearch(act){
	var img = (act==1)?"img/interface/btn-buscar-on.png":"img/interface/btn-buscar-off.png";
	document.getElementById('buttonsearch').src=img;
}

function changeClassPointMenu(mnu){
	//MENU WIDGET BUSQUEDAS ---------
	$("#pointermenu").css("color",Site.menu_color);
	$("#pointermenu ul").css("background",Site.menu_style);
	for (var c=1; c<5;	c++){ 
		document.getElementById(c).className="";
		$("#"+c).css("background",Site.menu_style);					
		$("#"+c).css("color",Site.menu_color);					
	}
	document.getElementById(mnu).className="checked";
	$("#pointermenu div#"+mnu).css("background",Site.menu_active_style);
	$("#pointermenu div#"+mnu).css("color",Site.menu_active_color);	

}
Site.ChangeTheme=function(){

	var my_theme = (document.getElementById('theme_user')!=null)?document.getElementById('theme_user').value:"default";
	Site.ChangeBackground(my_theme);
}
Site.ChangeBanner=function(){
	//alert("1");
	var content_banner = $("#divBanner").html();
	if(content_banner!=Site.DefaultBanner){$("#divBanner").html(Site.DefaultBanner);}	
}
Site.ChangeBackground=function(theme,opt){

//alert(theme);
//NUEVO SISTEMA
	if ((theme=='default' && (getTiny()=="" || opt==1)) || ($.isNumeric(theme)==false && theme!='default')){
		var theme_default = Site.Config.theme_default;		
		var item = jQuery.parseJSON(theme_default);	
		if (item!=null){	
			//BODY -----------------------
			var body_style = item.body_backcolor;
			
			if(item.body_backimg!="0") body_style += " url(/img/textures/"+item.body_backimg+") "+item.body_backimg_position+" "+item.body_backimg_repeat;				
			$("body").css("background",body_style);
			
			//LOGO SITE
			if(item.logo_img!="0") {
				document.getElementById('mapcity_logo').src="/img/interface/"+item.logo_img;	
				document.getElementById('mapcity_logo').height=item.logo_img_height;
				document.getElementById('mapcity_logo').width=item.logo_img_width;						
			}else{
				document.getElementById('mapcity_logo').style.display='none';						
			}
			
			//HEADER -----------------------
			$("#framecontentTop div#tabsF a").css("color",item.header_color);
			var header_style = "";				
			if (item.header_backcolor!="0") header_style += item.header_backcolor;
			if (item.header_backimg!="0") header_style += " url(/img/textures/"+item.header_backimg+") "+item.header_backimg_position+" "+item.header_backimg_repeat;
			$("#framecontentTop").css("background",header_style);

			//MENU WIDGET BUSQUEDAS ---------
			Site.menu_color = item.menu_color;
			Site.menu_active_color = item.menu_active_color;
			$("#pointermenu").css("color",Site.menu_color);
			
			Site.menu_style = "";
			if (item.menu_backcolor!="0") Site.menu_style += item.menu_backcolor;
			if (item.menu_backimg!="0") Site.menu_style += " url(/img/textures/"+item.menu_backimg+") "+item.menu_backimg_position+" "+item.menu_backimg_repeat;
			$("#pointermenu ul").css("background",Site.menu_style);

			Site.menu_active_style = "";
			if (item.menu_active_backcolor!="0") Site.menu_active_style += item.menu_active_backcolor;
			if (item.menu_active_backimg!="0") {
				Site.menu_active_style += " url(/img/textures/"+item.menu_active_backimg+") "+item.menu_active_backimg_position+" "+item.menu_active_backimg_repeat;
			}
			for (var c=1; c<5;	c++){ 
				document.getElementById(c).className="";
				$("#"+c).css("background",Site.menu_style);					
				$("#"+c).css("color",Site.menu_color);					
			}

			document.getElementById("1").className="checked";
			$("#pointermenu div#1").css("background",Site.menu_active_style);
			$("#pointermenu div#1").css("color",Site.menu_active_color);				
			
			//WIDGET BUSQUEDAS ---------
			$(".title").css("color",item.widget_color);

			Site.widget_style = "";
			if (item.widget_backcolor!="0") Site.widget_style += item.widget_backcolor;
			if (item.widget_backimg!="0") Site.widget_style += " url(/img/textures/"+item.widget_backimg+") "+item.widget_backimg_position+" "+item.widget_backimg_repeat;
			$("#leftpanelsearch").css("background",Site.widget_style);					

			//TITULO SECCIONES ( ---------
			$(".ItemListTitle").css("color",item.titulo_color);
			
			Site.titulo_style = "";
			if (item.titulo_backcolor!="0") Site.titulo_style += item.titulo_backcolor;
			
			if (item.titulo_backimg!="0") {
				Site.titulo_style += " url(/img/textures/"+item.titulo_backimg+") "+item.titulo_backimg_position+" "+item.titulo_backimg_repeat;
				$("#searchdivisor").css("background","none");
//					}else{						
//						var separator_bar = " url(/img/interface/topshadow.png) top left repeat-x";						
//						$("#searchdivisor").css("background",separator_bar);												
			}

			$(".ItemListHead").css("background",Site.titulo_style);						
			
			//IMG REPRESENTA AL TEMA (MARCA)-----------------------
			if (item.marca_backimg!="0") {
				var marca_style = " url(/img/textures/"+item.marca_backimg+") "+item.marca_backimg_position+" "+item.marca_backimg_repeat;
				$(".ItemListContent").css("background",marca_style);
			}else{
				$(".ItemListContent").css("background","");
			}
			
	}else{
			//NULLL----------
			$.ajax({
			  type: 'GET',
			  url: '/ws/interface/MapcitySocial.site.php',
			  dataType: 'json',
			  data: 'method=config&pais='+Site.CurrentCountry+'',
			  success: function(theme_json) {
					Site.Config = theme_json;
					var theme_default = theme_json.theme_default;
					var item = jQuery.parseJSON(theme_default);	
							
							//BODY -----------------------
							var body_style = item.body_backcolor;
							if(item.body_backimg!="0") body_style += " url(/img/textures/"+item.body_backimg+") "+item.body_backimg_position+" "+item.body_backimg_repeat;				
							$("body").css("background",body_style);
				
				
							//LOGO SITE
							if(item.logo_img!="0") {
								document.getElementById('mapcity_logo').src="/img/interface/"+item.logo_img;	
								document.getElementById('mapcity_logo').height=item.logo_img_height;
								document.getElementById('mapcity_logo').width=item.logo_img_width;						
							}else{
								document.getElementById('mapcity_logo').style.display='none';						
							}
							
							//HEADER -----------------------
							$("#framecontentTop div#tabsF a").css("color",item.header_color);
							var header_style = "";				
							if (item.header_backcolor!="0") header_style += item.header_backcolor;
							if (item.header_backimg!="0") header_style += " url(/img/textures/"+item.header_backimg+") "+item.header_backimg_position+" "+item.header_backimg_repeat;
							$("#framecontentTop").css("background",header_style);
				
							//MENU WIDGET BUSQUEDAS ---------
							Site.menu_color = item.menu_color;
							Site.menu_active_color = item.menu_active_color;
							$("#pointermenu").css("color",Site.menu_color);
							
							Site.menu_style = "";
							if (item.menu_backcolor!="0") Site.menu_style += item.menu_backcolor;
							if (item.menu_backimg!="0") Site.menu_style += " url(/img/textures/"+item.menu_backimg+") "+item.menu_backimg_position+" "+item.menu_backimg_repeat;
							$("#pointermenu ul").css("background",Site.menu_style);
				
							Site.menu_active_style = "";
							if (item.menu_active_backcolor!="0") Site.menu_active_style += item.menu_active_backcolor;
							if (item.menu_active_backimg!="0") {
								Site.menu_active_style += " url(/img/textures/"+item.menu_active_backimg+") "+item.menu_active_backimg_position+" "+item.menu_active_backimg_repeat;
							}
							for (var c=1; c<5;	c++){ 
								document.getElementById(c).className="";
								$("#"+c).css("background",Site.menu_style);					
								$("#"+c).css("color",Site.menu_color);					
							}
							document.getElementById("1").className="checked";
							$("#pointermenu div#1").css("background",Site.menu_active_style);
							$("#pointermenu div#1").css("color",Site.menu_active_color);				

							//WIDGET BUSQUEDAS ---------
							$(".title").css("color",item.widget_color);
				
							Site.widget_style = "";
							if (item.widget_backcolor!="0") Site.widget_style += item.widget_backcolor;
							if (item.widget_backimg!="0") Site.widget_style += " url(/img/textures/"+item.widget_backimg+") "+item.widget_backimg_position+" "+item.widget_backimg_repeat;
							$("#leftpanelsearch").css("background",Site.widget_style);					
				
							//TITULO SECCIONES ( ---------
							$(".ItemListTitle").css("color",item.titulo_color);
							
							Site.titulo_style = "";
							if (item.titulo_backcolor!="0") Site.titulo_style += item.titulo_backcolor;
							
							if (item.titulo_backimg!="0") {
								Site.titulo_style += " url(/img/textures/"+item.titulo_backimg+") "+item.titulo_backimg_position+" "+item.titulo_backimg_repeat;
								$("#searchdivisor").css("background","none");
				//					}else{						
				//						var separator_bar = " url(/img/interface/topshadow.png) top left repeat-x";						
				//						$("#searchdivisor").css("background",separator_bar);												
							}
				
							$(".ItemListHead").css("background",Site.titulo_style);						
							
							//IMG REPRESENTA AL TEMA (MARCA)-----------------------
							if (item.marca_backimg!="0") {
								var marca_style = " url(/img/textures/"+item.marca_backimg+") "+item.marca_backimg_position+" "+item.marca_backimg_repeat;
								$(".ItemListContent").css("background",marca_style);
							}else{
								$(".ItemListContent").css("background","");
							}
			  }});
		}
			
	}
	if(theme>0) {
			var destino = '/ws/interface/MapcitySocial.site.php';
			var parametros = 'method=gettheme&selected='+theme;		

			$.ajax({
				
			  type: 'GET',
			  url: destino,
			  dataType: 'json',
			  data: parametros,
			  success: function(theme_json) {
					
							var item = theme_json;
								
							//BODY -----------------------
							var body_style = (item.body_backcolor!=0)?item.body_backcolor:"";
							item.body_backimg_position = (item.body_backimg_position!=0)?item.body_backimg_position:"";
							item.body_backimg_repeat=(item.body_backimg_repeat!=0)?item.body_backimg_repeat:"";
							if(item.body_backimg!=0) body_style += " url(/img/textures/"+item.body_backimg+") "+item.body_backimg_position+" "+item.body_backimg_repeat;				

							$("body").css("background",body_style);
		
		
							//LOGO SITE
							if(item.logo_img!="0") {
								document.getElementById('mapcity_logo').src="/img/interface/"+item.logo_img;	
								document.getElementById('mapcity_logo').height=item.logo_img_height;
								document.getElementById('mapcity_logo').width=item.logo_img_width;						
							}else{
								document.getElementById('mapcity_logo').style.display='none';						
							}
							
							//HEADER -----------------------
							$("#framecontentTop div#tabsF a").css("color",item.header_color);
							var header_style = "";				
							if (item.header_backcolor!="0") header_style += item.header_backcolor;
							if (item.header_backimg!="0") header_style += " url(/img/textures/"+item.header_backimg+") "+item.header_backimg_position+" "+item.header_backimg_repeat;
							$("#framecontentTop").css("background",header_style);
			
			
							//MENU WIDGET BUSQUEDAS ---------
							Site.menu_color = item.menu_color;
							Site.menu_active_color = item.menu_active_color;
							$("#pointermenu").css("color",Site.menu_color);
							
							Site.menu_style = "";
							if (item.menu_backcolor!="0") Site.menu_style += item.menu_backcolor;
							if (item.menu_backimg!="0") Site.menu_style += " url(/img/textures/"+item.menu_backimg+") "+item.menu_backimg_position+" "+item.menu_backimg_repeat;
							$("#pointermenu ul").css("background",Site.menu_style);
			
							Site.menu_active_style = "";
							if (item.menu_active_backcolor!="0") Site.menu_active_style += item.menu_active_backcolor;
							if (item.menu_active_backimg!="0") {
								Site.menu_active_style += " url(/img/textures/"+item.menu_active_backimg+") "+item.menu_active_backimg_position+" "+item.menu_active_backimg_repeat;
								
							}
			
							for (var c=1; c<5;	c++){ 
								document.getElementById(c).className="";
								$("#"+c).css("background",Site.menu_style);					
								$("#"+c).css("color",Site.menu_color);					
							}
			
							document.getElementById("1").className="checked";
							$("#pointermenu div#1").css("background",Site.menu_active_style);
							$("#pointermenu div#1").css("color",Site.menu_active_color);				
							
							
							//WIDGET BUSQUEDAS ---------
							$(".title").css("color",item.widget_color);
		
							Site.widget_style = "";
							if (item.widget_backcolor!="0") Site.widget_style += item.widget_backcolor;
							if (item.widget_backimg!="0") Site.widget_style += " url(/img/textures/"+item.widget_backimg+") "+item.widget_backimg_position+" "+item.widget_backimg_repeat;
							$("#leftpanelsearch").css("background",Site.widget_style);					
			
							//TITULO SECCIONES ( ---------
							$(".ItemListTitle").css("color",item.titulo_color);
							
							Site.titulo_style = "";
							if (item.titulo_backcolor!="0") Site.titulo_style += item.titulo_backcolor;
							
							if (item.titulo_backimg!="0") {
								Site.titulo_style += " url(/img/textures/"+item.titulo_backimg+") "+item.titulo_backimg_position+" "+item.titulo_backimg_repeat;
								$("#searchdivisor").css("background","none");
							//}else{						
							//	var separator_bar = " url(/img/interface/topshadow.png) top left repeat-x";						
							//	$("#searchdivisor").css("background",separator_bar);												
							}
		
							$(".ItemListHead").css("background",Site.titulo_style);						
							
							
							//IMG REPRESENTA AL TEMA (MARCA)-----------------------
		
							if (item.marca_backimg!="0") {
								var marca_style = " url(/img/textures/"+item.marca_backimg+") "+item.marca_backimg_position+" "+item.marca_backimg_repeat;
								$(".ItemListContent").css("background",marca_style);
							}else{
								$(".ItemListContent").css("background","");
							}	
					
							}
					});
	}	
}
function ChangeUserBackground(theme){
			
		$.ajax({
			type: 'GET',
			url: '/ws/interface/MapcitySocial.site.php',
			data: 'method=gettheme&selected='+theme,
			success: function(data) {
				var theme_data = data.split("{sep}");
				var img = theme_data[2];
				Site.color_menu = theme_data[3];
				Site.color_title = theme_data[4];
				Site.color_active = theme_data[5];
				Site.color_pointer_menu = theme_data[6];	
				Site.color_pointer_active_menu = theme_data[7];							
				Site.logo = theme_data[8];
				
				$("#pointermenu ul").css("backgroundColor",Site.color_pointer_menu);										

				for (var c=1; c<5;	c++){
					var codold = "#"+c;
					document.getElementById(c).className="";
					$(codold).css("backgroundColor",Site.color_pointer_menu);	
				}
				document.getElementById("1").className="checked";
				var cod = "#1";
				$(cod).css("backgroundColor",Site.color_pointer_active_menu);						
				
				$("#tabsF a").css("color",Site.color_menu);
				$(".title").css("color",Site.color_title);
				$(".ItemListTitle").css("color",Site.color_active);

				if (img==""){
					Site.ChangeBackground('default');
					
				}else{
					
					var fondo = "url(/img/textures/"+img+") #fff";
					$("body").css("background",fondo);
					
					document.getElementById('mapcity_logo').src="/img/interface/"+Site.logo;				
					SaveThemeSelected(theme);
				}

			}
		})
}


function SaveThemeSelected(selected){

	var user = $("#id_user").val();

//	var selected = Site.NoSaveThemeSelected;//$("#theme_user").val();
	var theme_data = 'method=themeselect&selected='+selected+"&user="+user;

	$.ajax({
		type: 'GET',
		url: '/ws/interface/MapcitySocial.users.php',
		data: theme_data,
		success: function(data) {
			var msg="msgbox_savepreference";
			var ico="ok";			
			
			if (document.getElementById('theme_user')!=null){ 
			
				document.getElementById('theme_user').value=selected;//Site.NoSaveThemeSelected;
				//Site.NoSaveThemeSelected="";
			}
		}
})						
}

function ChangeleftButtonBar(button,state){

		switch (button){
			case 1: if (state==1) {document.getElementById('buttonchannel').src="img/but/sidebar-icon4-on.png";}//OVER
			
					if (state==0) { document.getElementById('buttonchannel').src="img/but/sidebar-icon4-off.png";}//OUT
										
					if (state==2) {	//CLICK
					
						document.getElementById('buttonchannel').src="img/but/sidebar-icon4-on.png";						
						document.getElementById('buttonchannel').onmouseover=null;
						document.getElementById('buttonchannel').onmouseout=null;

						addEvent( document.getElementById('buttonadress'), 'mouseover', function(){ ChangeleftButtonBar(2,1); }  );
						addEvent( document.getElementById('buttonadress'), 'mouseout', function(){ ChangeleftButtonBar(2,0); }  );						
						
						addEvent( document.getElementById('buttonphoto'), 'mouseover', function(){ ChangeleftButtonBar(3,1); }  );
						addEvent( document.getElementById('buttonphoto'), 'mouseout', function(){ ChangeleftButtonBar(3,0); }  );						
						
						addEvent( document.getElementById('buttonpoi'), 'mouseover', function(){ ChangeleftButtonBar(4,1); }  );
						addEvent( document.getElementById('buttonpoi'), 'mouseout', function(){ ChangeleftButtonBar(4,0); }  );						

						addEvent( document.getElementById('buttonoption'), 'mouseover', function(){ ChangeleftButtonBar(5,1); }  );
						addEvent( document.getElementById('buttonpoi'), 'mouseout', function(){ ChangeleftButtonBar(5,0); }  );						

						$("#buttonadress").attr("src","img/but/sidebar-icon1-off.png");			
						$("#buttonphoto").attr("src","img/but/sidebar-icon2-off.png");
						$("#buttonpoi").attr("src","img/but/sidebar-icon3-off.png");
						$("#buttonoption").attr("src","img/but/sidebar-icon5-off.png");							
						
					}
					break;
	
			case 2: if (state==1) { document.getElementById('buttonadress').src="img/but/sidebar-icon1-on.png";}
			
					if (state==0) { document.getElementById('buttonadress').src="img/but/sidebar-icon1-off.png";}
					
					if (state==2) {	

						document.getElementById('buttonadress').onmouseover=null;
						document.getElementById('buttonadress').onmouseout=null;
						document.getElementById('buttonadress').src="img/but/sidebar-icon1-on.png";

						var channel = document.getElementById('buttonchannel').src.split("-");
						if (channel[2]=='on') {
							addEvent( document.getElementById('buttonchannel'), 'mouseover', function(){ ChangeleftButtonBar(1,1); }  );
							addEvent( document.getElementById('buttonchannel'), 'mouseout', function(){ ChangeleftButtonBar(1,0); }  );	
							document.getElementById('buttonchannel').src="img/but/sidebar-icon1-off.png";
						}
						
						var photo = document.getElementById('buttonphoto').src.split("-");
						if (photo[2]=='on') {
							addEvent( document.getElementById('buttonphoto'), 'mouseover', function(){ ChangeleftButtonBar(3,1); }  );
							addEvent( document.getElementById('buttonphoto'), 'mouseout', function(){ ChangeleftButtonBar(3,0); }  );	
							document.getElementById('buttonphoto').src="img/but/sidebar-icon2-off.png";
						}						
						
						var poi = document.getElementById('buttonpoi').src.split("-");
						if (poi[2]=='on') {
							addEvent( document.getElementById('buttonpoi'), 'mouseover', function(){ ChangeleftButtonBar(4,1); }  );
							addEvent( document.getElementById('buttonpoi'), 'mouseout', function(){ ChangeleftButtonBar(4,0); }  );	
							document.getElementById('buttonpoi').src="img/but/sidebar-icon4-off.png";
						}	
						
						var option = document.getElementById('buttonoption').src.split("-");
						if (option[2]=='on') {
							addEvent( document.getElementById('buttonoption'), 'mouseover', function(){ ChangeleftButtonBar(5,1); }  );
							addEvent( document.getElementById('buttonoption'), 'mouseout', function(){ ChangeleftButtonBar(5,0); }  );	
							document.getElementById('buttonoption').src="img/but/sidebar-icon5-off.png";
						}													
					}
					break;
	
			case 3: if (state==1) { document.getElementById('buttonphoto').src="img/but/sidebar-icon2-on.png";}
					if (state==0) { document.getElementById('buttonphoto').src="img/but/sidebar-icon2-off.png";}
					if (state==2) {

						document.getElementById('buttonphoto').onmouseover=null;
						document.getElementById('buttonphoto').onmouseout=null;								
						document.getElementById('buttonphoto').src="img/but/sidebar-icon2-on.png";
						
						var channel = document.getElementById('buttonchannel').src.split("-");
						if (channel[2]=='on') {
							addEvent( document.getElementById('buttonchannel'), 'mouseover', function(){ ChangeleftButtonBar(1,1); }  );
							addEvent( document.getElementById('buttonchannel'), 'mouseout', function(){ ChangeleftButtonBar(1,0); }  );	
							document.getElementById('buttonchannel').src="img/but/sidebar-icon1-off.png";
						}
						
						var address = document.getElementById('buttonadress').src.split("-");
						if (address[2]=='on') {
							addEvent( document.getElementById('buttonadress'), 'mouseover', function(){ ChangeleftButtonBar(2,1); }  );
							addEvent( document.getElementById('buttonadress'), 'mouseout', function(){ ChangeleftButtonBar(2,0); }  );	
							document.getElementById('buttonadress').src="img/but/sidebar-icon1-off.png";
						}						
						
						var poi = document.getElementById('buttonpoi').src.split("-");
						if (poi[2]=='on') {
							addEvent( document.getElementById('buttonpoi'), 'mouseover', function(){ ChangeleftButtonBar(4,1); }  );
							addEvent( document.getElementById('buttonpoi'), 'mouseout', function(){ ChangeleftButtonBar(4,0); }  );	
							document.getElementById('buttonpoi').src="img/but/sidebar-icon4-off.png";
						}	
						
						var option = document.getElementById('buttonoption').src.split("-");
						if (option[2]=='on') {
							addEvent( document.getElementById('buttonoption'), 'mouseover', function(){ ChangeleftButtonBar(5,1); }  );
							addEvent( document.getElementById('buttonoption'), 'mouseout', function(){ ChangeleftButtonBar(5,0); }  );	
							document.getElementById('buttonoption').src="img/but/sidebar-icon5-off.png";
						}									
						
					}
					break;
					
			case 4: if (state==1) {document.getElementById('buttonpoi').src="img/but/sidebar-icon3-on.png";}
					if (state==0) {document.getElementById('buttonpoi').src="img/but/sidebar-icon3-off.png";} 
					if (state==2) {	
						document.getElementById('buttonpoi').onmouseover=null;
						document.getElementById('buttonpoi').onmouseout=null;	;									
						document.getElementById('buttonpoi').src="img/but/sidebar-icon3-on.png";
						
						var channel = document.getElementById('buttonchannel').src.split("-");
						if (channel[2]=='on') {
							addEvent( document.getElementById('buttonchannel'), 'mouseover', function(){ ChangeleftButtonBar(1,1); }  );
							addEvent( document.getElementById('buttonchannel'), 'mouseout', function(){ ChangeleftButtonBar(1,0); }  );	
							document.getElementById('buttonchannel').src="img/but/sidebar-icon1-off.png";
						}
						
						var address = document.getElementById('buttonadress').src.split("-");
						if (address[2]=='on') {
							addEvent( document.getElementById('buttonadress'), 'mouseover', function(){ ChangeleftButtonBar(2,1); }  );
							addEvent( document.getElementById('buttonadress'), 'mouseout', function(){ ChangeleftButtonBar(2,0); }  );	
							document.getElementById('buttonadress').src="img/but/sidebar-icon1-off.png";
						}						
						
						var photo = document.getElementById('buttonphoto').src.split("-");
						if (photo[2]=='on') {
							addEvent( document.getElementById('buttonphoto'), 'mouseover', function(){ ChangeleftButtonBar(3,1); }  );
							addEvent( document.getElementById('buttonphoto'), 'mouseout', function(){ ChangeleftButtonBar(3,0); }  );	
							document.getElementById('buttonphoto').src="img/but/sidebar-icon2-off.png";
						}	
						
						var option = document.getElementById('buttonpoi').src.split("-");
						if (option[2]=='on') {
							addEvent( document.getElementById('buttonpoi'), 'mouseover', function(){ ChangeleftButtonBar(4,1); }  );
							addEvent( document.getElementById('buttonpoi'), 'mouseout', function(){ ChangeleftButtonBar(4,0); }  );	
							document.getElementById('buttonpoi').src="img/but/sidebar-icon3-off.png";
						}												
					}
					break;
					
			case 5: if (state==1) {document.getElementById('buttonoption').src="img/but/sidebar-icon5-on.png";}
					if (state==0) {document.getElementById('buttonoption').src="img/but/sidebar-icon5-off.png";}
					if (state==2) {	

						var channel = document.getElementById('buttonchannel').src.split("-");
						if (channel[2]=='on') {
							addEvent( document.getElementById('buttonchannel'), 'mouseover', function(){ ChangeleftButtonBar(1,1); }  );
							addEvent( document.getElementById('buttonchannel'), 'mouseout', function(){ ChangeleftButtonBar(1,0); }  );	
							document.getElementById('buttonchannel').src="img/but/sidebar-icon1-off.png";
						}
						
						var address = document.getElementById('buttonadress').src.split("-");
						if (address[2]=='on') {
							addEvent( document.getElementById('buttonadress'), 'mouseover', function(){ ChangeleftButtonBar(2,1); }  );
							addEvent( document.getElementById('buttonadress'), 'mouseout', function(){ ChangeleftButtonBar(2,0); }  );	
							document.getElementById('buttonadress').src="img/but/sidebar-icon1-off.png";
						}						
						
						var photo = document.getElementById('buttonphoto').src.split("-");
						if (photo[2]=='on') {
							addEvent( document.getElementById('buttonphoto'), 'mouseover', function(){ ChangeleftButtonBar(3,1); }  );
							addEvent( document.getElementById('buttonphoto'), 'mouseout', function(){ ChangeleftButtonBar(3,0); }  );	
							document.getElementById('buttonphoto').src="img/but/sidebar-icon2-off.png";
						}	
						
						var poi = document.getElementById('buttonoption').src.split("-");
						if (poi[2]=='on') {
							addEvent( document.getElementById('buttonoption'), 'mouseover', function(){ ChangeleftButtonBar(5,1); }  );
							addEvent( document.getElementById('buttonoption'), 'mouseout', function(){ ChangeleftButtonBar(5,0); }  );	
							document.getElementById('buttonoption').src="img/but/sidebar-icon5-off.png";
						}	
																	
					}
					break;		
		}
}


function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

function ChangeChkLang(type,obj){
	if (type=='country'){
		
		var paises = new Array('cl','ar','br','pe','mx');
		var numpaises = paises.length;
		
		for (c=0; c<numpaises;c++){
			document.getElementById(paises[c]).checked=false;
		}
		document.getElementById(obj.id).checked=true;				
		var ico = 'img/pais/'+obj.id+".png";
		document.getElementById('imgCoutry').src=ico;

	}else if (type=='lang'){
		
		var lang = new Array('es','en');
		var numlang = lang.length;
		
		for (r=0; r<numlang;r++){
			document.getElementById(lang[r]).checked=false;
		}
		
		document.getElementById(obj.id).checked=true;				
		
	}
}
function ChangeInterfaceLang(){
	$("#loadingglobal").show();	
	var paises = new Array('cl','ar','br','pe','mx');
	var lang = new Array('es','en');
	
	var numpaises = paises.length;
	var numlang = lang.length;
	
	var pais="";
	var idioma="";
	for (c=0; c<numpaises;c++){
			if (document.getElementById(paises[c]).checked==true){ pais = paises[c];  }
	}

	for (r=0; r<numlang;r++){
			if (document.getElementById(lang[r]).checked==true){ idioma = lang[r];  }
	}	
	
	if ( (pais=="")	|| (idioma=="") ){
	
		alert("Seleccione el idioma y pa\u00EDs a visualizar");
	}else{
		
		window.location='?l='+idioma+'&country='+pais;
		$('#SelectLangCountry').hide();
		
	}
	var ico = 'img/pais/'+pais+".png";

	document.getElementById('imgCoutry').src=ico;
		$("#loadingglobal").hide();	
}
function ChangeInterfaceLangActual(lang,country){

	var lang = lang.substring(5,7);// back.es.png
	if (country=='ch') country='cl';
	
	var ico = 'img/pais/'+country+".png";
	
	document.getElementById('imgCoutry').src=ico;
	
	document.getElementById(lang).checked=true;
	document.getElementById(country).checked=true;
	
	var allcountries = 'http://www.mapcity.com/?ver=old';
	var peru = 'http://www.mapcity.com/index.asp?id=7&ver=old';	
	
	if (country=='pe') {
		var location=peru;
	}else{
		var location=allcountries;
		
	}	
	document.getElementById('changeOldSite').href=location;
	

}
function CloseSelectLagCountry(mylang){
	var paises = new Array('cl','ar','br','pe','mx');
	var numpaises = paises.length;
	var country = Site.CurrentCountry;
	if (country=='ch') country='cl';

	for (c=0; c<numpaises;c++){
		document.getElementById(paises[c]).checked=false;
	}
	document.getElementById(country).checked=true;

	var ico = 'img/pais/'+country+".png";
	document.getElementById('imgCoutry').src=ico;

	var lang = new Array('es','en');

	var numlang = lang.length;
	
	var mylang = mylang.substring(5,7);

	for (r=0; r<numlang;r++){
		document.getElementById(lang[r]).checked=false;
	}
	document.getElementById(mylang).checked=true;

	$('#SelectLangCountry').hide();
}
function ChangeButtonReturn(imgid,estado){
	switch (estado){
		case 0:   var img = 'img/but/btn-volver-off';break;		
		case 1:   var img = 'img/but/btn-volver-on';break;
	}
	var boton = "#"+imgid+ "_img";
	$(boton).attr("src",img);
}
function detailnew(act,cod){
	$("#loadingsearch").show();
	if (act==1){
		$.ajax({
            type: 'GET',
            url: 'news.php',
            data: "cod="+cod,
            success: function(data) {
                $("#detailnews").html(data);
             Site.BackButton('detail');
			 $("#NewBar").show();
			 document.getElementById('NewBar').style.display="inline";
            }
        })
		$("#listnews").hide(Site.FadeVelocity);	
		$("#detailnews").show(Site.FadeVelocity);	
		$("#loadingsearch").hide();
			document.getElementById('detailnews').scrollTop=0;
			document.getElementById('StartArea').scrollTop=0;	
	}else{
		$("#NewBar").hide();
		$("#listnews").show(Site.FadeVelocity);
		$("#detailnews").hide(Site.FadeVelocity);
		$("#detailnews").html("");
		$("#loadingsearch").hide();	
	}
		Site.BackButton('detail');
}
function listnew(){
	document.getElementById('loadingsearch').style.display="inline";	
	var pag = document.getElementById('pag').value;
	$.ajax({
		type: 'GET',
		url: 'news.php',
		data: "pag="+pag,
		success: function(data) {
		    $('#divButtonMoreNews').hide().remove(); 
			var encab = '<table id="tblListNews" width="235" border="0" cellpadding="0" cellspacing="0">'
            var fin   = '</table>';
			if ($("#tblListNews").html()!=null){
				document.getElementById('listnews').style.width="235px";						
				document.getElementById('tblListNews').style.width="235px";						
				var listnoti = $("#tblListNews").html();
			}else{
				var listnoti = "";
			}
			listnoti += data;
			var tblnoti = encab + listnoti + fin;			
			$("#listnews").html('');			
			$("#listnews").html(tblnoti);
			pag++;
		  	document.getElementById('pag').value=pag;
		}
	})
	document.getElementById('loadingsearch').style.display="none";	
}

function ResizeChangeBarRight(val){
	var widthColRight = $("#colright").width();
	var widthDivisor = 9;
	var widthleftpanel = 291;		
	var widthWindow = $(window).width();
	var heightWindow = $(window).height();		
	
	if (widthWindow<900){
		if (Site.visibleColRight==true){
		$("#divBanner").hide("fast");
		$("#colright").hide(Site.FadeVelocity);// HIDE RIGHT COLUMN
		Site.visibleColRight=false;

		//REDIMENSIONA EL BANNER INFERIOR DEL SITIO SI ES QUE ESTA VISIBLE
		var wscr = $(window).width();
		if(document.getElementById('bgnomodal')!=null  && wscr>900){			
			var hscr = $(window).height();
			
			var wcnt = $('#bgnomodal').width();
			var hcnt = $('#bgnomodal').height();			
			
			Site.visibleColleft=(document.getElementById('leftpanelContent').style.display=='none')?false:true;
			
			var lcol=(Site.visibleColleft==true)?291:0;
			var rcol=(Site.visibleColRight==true)?172:0;
			
			var ldiv=7;
			var rdiv=7;
			
			var paneles = lcol+rcol+ldiv+rdiv; //left, right y divisores
			
			wscr2 = wscr-paneles; //espacio del mapa

			// obtener posicion central
			var mleft = (( wscr2 - wcnt ) / 2)+(lcol+ldiv+rdiv);
			var mtop = ( hscr - hcnt ) / 2;
			
			// estableciendo posicion
			$('#bgnomodal').css("left", mleft+'px');
			$('#bgnomodal').css("bottom", '25px');				
		}

		document.getElementById("framecontentTop").style.right = "0px";
		//document.getElementById("tabsF").style.left = (widthWindow-550)+"px";
		document.getElementById("rightdivisor").style.right = "0px";
		
		document.getElementById("mapcontent").style.right = "0px";		
		
		//REDIMENSIONA LA BARRA DE USUARIO SI ES QUE EXISTE
		var statusbar_width = (document.getElementById('mapcontent').style.width);
		if (document.getElementById('statusbar')!=undefined && document.getElementById('statusbar')!=null){
			$("#statusbar").css("width",statusbar_width);
		}
		document.getElementById('imgchange_right').src="img/but/pestana-izquierda-in.png";
		
	} 
	}else{
		
		$("#colright").show(Site.FadeVelocity);	//SHOW RIGHT COLUMN
		$("#divBanner").show("fast");
		Site.visibleColRight=true;		

		//REDIMENSIONA EL BANNER INFERIOR DEL SITIO SI ES QUE ESTA VISIBLE
		var wscr = $(window).width();
		if(document.getElementById('bgnomodal')!=null  && wscr>900){			
			var hscr = $(window).height();
			
			var wcnt = $('#bgnomodal').width();
			var hcnt = $('#bgnomodal').height();			
			
			Site.visibleColleft=(document.getElementById('leftpanelContent').style.display=='none')?false:true;
			
			var lcol=(Site.visibleColleft==true)?291:0;
			var rcol=(Site.visibleColRight==true)?172:0;
			
			var ldiv=7;
			var rdiv=7;
			
			var paneles = lcol+rcol+ldiv+rdiv; //left, right y divisores
			
			wscr2 = wscr-paneles; //espacio del mapa

			// obtener posicion central
			var mleft = (( wscr2 - wcnt ) / 2)+(lcol+ldiv+rdiv);
			var mtop = ( hscr - hcnt ) / 2;
			
			// estableciendo posicion
			$('#bgnomodal').css("left", mleft+'px');
			$('#bgnomodal').css("bottom", '25px');				
		}
		
		document.getElementById("framecontentTop").style.right = "0px";		
		
		var LeftTabsF = widthWindow - (widthColRight + widthDivisor + 350); //700 ancho de botonera tabsF	
		
		document.getElementById("rightdivisor").style.right =  "183px";
		
		document.getElementById("mapcontent").style.right = "183px";		
		
		//REDIMENSIONA LA BARRA DE USUARIO SI ES QUE EXISTE
		var statusbar_width = (document.getElementById('mapcontent').width)+"px";
		if (document.getElementById('statusbar')!=undefined && document.getElementById('statusbar')!=null){
			$("#statusbar").css("width",statusbar_width);
		}
		try{
document.getElementById('imgchange_right').src="img/but/pestana-izquierda-out.png";	
}catch(err){}			
	
	}
}
function ChangeBarRight(){
	var heightWindow = $(window).height();
	var widthWindow = $(window).width();
	var widthColRight = $("#colright").width();
	var widthDivisor = 9;
	var widthleftpanel = 291;	

	if (Site.visibleColRight==true){
		$("#divBanner").hide("fast");
		$("#colright").hide(Site.FadeVelocity);// HIDE RIGHT COLUMN
		Site.visibleColRight=false;

		//REDIMENSIONA EL BANNER INFERIOR DEL SITIO SI ES QUE ESTA VISIBLE
		var wscr = $(window).width();
		if(document.getElementById('bgnomodal')!=null  && wscr>900){			
			var hscr = $(window).height();
			
			var wcnt = $('#bgnomodal').width();
			var hcnt = $('#bgnomodal').height();			
			
			Site.visibleColleft=(document.getElementById('leftpanelContent').style.display=='none')?false:true;
			
			var lcol=(Site.visibleColleft==true)?291:0;
			var rcol=(Site.visibleColRight==true)?172:0;
			
			var ldiv=7;
			var rdiv=7;
			
			var paneles = lcol+rcol+ldiv+rdiv; //left, right y divisores
			
			wscr2 = wscr-paneles; //espacio del mapa

			// obtener posicion central
			var mleft = (( wscr2 - wcnt ) / 2)+(lcol+ldiv+rdiv);
			var mtop = ( hscr - hcnt ) / 2;
			
			// estableciendo posicion
			$('#bgnomodal').css("left", mleft+'px');
			$('#bgnomodal').css("bottom", '25px');				
		}

		document.getElementById("framecontentTop").style.right = "0px";
		//document.getElementById("tabsF").style.left = (widthWindow-550)+"px";
		document.getElementById("rightdivisor").style.right = "0px";
		
		document.getElementById("mapcontent").style.right = "0px";		
		
		//REDIMENSIONA LA BARRA DE USUARIO SI ES QUE EXISTE--------------------------------------------------------------------			
		if (document.getElementById('statusbar')!=undefined && document.getElementById('statusbar')!=null){
			
				if (Site.visibleColLeft==true){
					var statusbar_width = (widthWindow-291)+"px";
					$("#statusbar").css("width",statusbar_width);
					$("#statusbar").css("left","292px");	
				}else{
					var statusbar_width = (widthWindow)+"px";
					$("#statusbar").css("width",statusbar_width);
					$("#statusbar").css("left","0px");					
				}			
		}
		document.getElementById('imgchange_right').src="img/but/pestana-izquierda-in.png";
		
	}else{
		$("#colright").show(Site.FadeVelocity);	//SHOW RIGHT COLUMN
		$("#divBanner").show("fast");
		Site.visibleColRight=true;
		

		//REDIMENSIONA EL BANNER INFERIOR DEL SITIO SI ES QUE ESTA VISIBLE
		var wscr = $(window).width();
		if(document.getElementById('bgnomodal')!=null  && wscr>900){			
			var hscr = $(window).height();
			
			var wcnt = $('#bgnomodal').width();
			var hcnt = $('#bgnomodal').height();			
			
			Site.visibleColleft=(document.getElementById('leftpanelContent').style.display=='none')?false:true;
			
			var lcol=(Site.visibleColleft==true)?291:0;
			var rcol=(Site.visibleColRight==true)?172:0;
			
			var ldiv=7;
			var rdiv=7;
			
			var paneles = lcol+rcol+ldiv+rdiv; //left, right y divisores
			
			wscr2 = wscr-paneles; //espacio del mapa

			// obtener posicion central
			var mleft = (( wscr2 - wcnt ) / 2)+(lcol+ldiv+rdiv);
			var mtop = ( hscr - hcnt ) / 2;
			
			// estableciendo posicion
			$('#bgnomodal').css("left", mleft+'px');
			$('#bgnomodal').css("bottom", '25px');				
		}
		
		document.getElementById("framecontentTop").style.right = "0px";		
		
		var LeftTabsF = widthWindow - (widthColRight + widthDivisor + 350); //700 ancho de botonera tabsF	
		
		document.getElementById("rightdivisor").style.right =  "183px";
		
		document.getElementById("mapcontent").style.right = "183px";		
		
		//REDIMENSIONA LA BARRA DE USUARIO SI ES QUE EXISTE--------------------------------------------------------------------			
		if (document.getElementById('statusbar')!=undefined && document.getElementById('statusbar')!=null){
			
				if (Site.visibleColLeft==true){
					var statusbar_width = (widthWindow-291-183)+"px";
					$("#statusbar").css("width",statusbar_width);
					$("#statusbar").css("left","292px");	
				}else{
					var statusbar_width = (widthWindow-183)+"px";
					$("#statusbar").css("width",statusbar_width);
					$("#statusbar").css("left","0px");					
				}			
		}
		document.getElementById('imgchange_right').src="img/but/pestana-izquierda-out.png";				
	}
}
function ChangeBarLeft(){
	var heightWindow = $(window).height();
	var widthWindow = $(window).width();
	var widthColRight = $("#colright").width();
	var widthDivisor = 9;
	var widthleftpanel = 291;	

	if (Site.visibleColLeft==true){
		$("#leftpanel").hide(Site.FadeVelocity);	// HIDE LEFT COLUMN
		Site.visibleColLeft=false;
		
		$('#FrontBarSite').hide();
		document.getElementById('FrontBarSite').style.display='none';
		
		$('#barra_tabs_portada').hide();		
		document.getElementById('barra_tabs_portada').style.display='none';
		
		$('#sort-box').hide();
		document.getElementById('sort-box').style.display='none';
		
		$('.ItemListTitle').hide();
		$('.boxMessage').hide();
		$('.ovalbutton').hide();
		
		
		$('#searchdivisor').hide();							
		$('#bottomdivisor').hide();		
		$('#channels').hide();	
		$('#twitter').hide();	
		$('#leftpanelBottomMenu').hide();
		$('#btFinder').hide();				
		
		var LeftLeftDivisorX = 0;
		document.getElementById("leftdivisor").style.left = LeftLeftDivisorX + "px";
		
		document.getElementById("mapcontent").style.left = "0px";

		
		//REDIMENSIONA EL BANNER INFERIOR DEL SITIO SI ES QUE ESTA VISIBLE
		var wscr = $(window).width();
		if(document.getElementById('bgnomodal')!=null  && wscr>900){			
			var hscr = $(window).height();
				
			var wcnt = $('#bgnomodal').width();
			var hcnt = $('#bgnomodal').height();			
			
			Site.visibleColleft=(document.getElementById('leftpanelContent').style.display=='none')?false:true;
			
			var lcol=(Site.visibleColleft==true)?291:0;
			var rcol=(Site.visibleColRight==true)?172:0;
			
			var ldiv=7;
			var rdiv=7;
			
			var paneles = lcol+rcol+ldiv+rdiv; //left, right y divisores
			
			wscr2 = wscr-paneles; //espacio del mapa

			// obtener posicion central
			var mleft = (( wscr2 - wcnt ) / 2)+(lcol+ldiv+rdiv);
			var mtop = ( hscr - hcnt ) / 2;
			
			// estableciendo posicion
			$('#bgnomodal').css("left", mleft+'px');
			$('#bgnomodal').css("bottom", '25px');				
		}
		
		document.getElementById('imgchange_left').src="img/but/pestana-derecha-in.png";
		document.getElementById("topdivisor").style.left =  "0px";		
		
		//REDIMENSIONA LA BARRA DE USUARIO SI ES QUE EXISTE--------------------------------------------------------------------			
		if (document.getElementById('statusbar')!=undefined && document.getElementById('statusbar')!=null){
			
				if (Site.visibleColRight==true){
					var statusbar_width = (widthWindow-183)+"px";
					$("#statusbar").css("width",statusbar_width);
					$("#statusbar").css("left","0px");	
				}else{
					var statusbar_width = (widthWindow)+"px";
					$("#statusbar").css("width",statusbar_width);
					$("#statusbar").css("left","0px");
										
				}			
		}		
		
	}else{
		$("#leftpanel").show(Site.FadeVelocity);
		
		Site.visibleColLeft=true;
		$('#FrontBarSite').show();
		$('#barra_tabs_portada').show();		
		$('#sort-box').show();
		$('#channels').show();	
		$('.ItemListTitle').show();
		$('.boxMessage').show();
		$('.ovalbutton').show();		
		$('#bottomdivisor').show();	
		$('#searchdivisor').show();			
		
		$('#twitter').show();	
		$('#leftpanelBottomMenu').show();	
		$('#btFinder').show();		
		
		var LeftDivisorX = widthleftpanel + 1;
		document.getElementById("leftdivisor").style.left = LeftDivisorX + "px";
		
		document.getElementById("mapcontent").style.left = "293px";		
		
		//REDIMENSIONA EL BANNER INFERIOR DEL SITIO SI ES QUE ESTA VISIBLE
		var wscr = $(window).width();
		if(document.getElementById('bgnomodal')!=null  && wscr>900){			
			var hscr = $(window).height();				
			var wcnt = $('#bgnomodal').width();
			var hcnt = $('#bgnomodal').height();			
			
			Site.visibleColleft=(document.getElementById('leftpanelContent').style.display=='none')?false:true;
			
			var lcol=(Site.visibleColleft==true)?291:0;
			var rcol=(Site.visibleColRight==true)?172:0;
			
			var ldiv=7;
			var rdiv=7;
			
			var paneles = lcol+rcol+ldiv+rdiv; //left, right y divisores
			
			wscr2 = wscr-paneles; //espacio del mapa

			// obtener posicion central
			var mleft = (( wscr2 - wcnt ) / 2)+(lcol+ldiv+rdiv);
			var mtop = ( hscr - hcnt ) / 2;
			
			// estableciendo posicion
			$('#bgnomodal').css("left", mleft+'px');
			$('#bgnomodal').css("bottom", '25px');				
		}	
		
		document.getElementById('imgchange_left').src="img/but/pestana-derecha-out.png";	
		document.getElementById("topdivisor").style.left =  "291px";		
				
		//REDIMENSIONA LA BARRA DE USUARIO SI ES QUE EXISTE--------------------------------------------------------------------			
		if (document.getElementById('statusbar')!=undefined && document.getElementById('statusbar')!=null){
			
				if (Site.visibleColRight==true){
					var statusbar_width = (widthWindow-183-292)+"px";
					$("#statusbar").css("width",statusbar_width);
					$("#statusbar").css("left","292px");	
				}else{
					var statusbar_width = (widthWindow-291)+"px";
					$("#statusbar").css("width",statusbar_width);
					$("#statusbar").css("left","292px");
										
				}			
		}					
	}
	Site.Map.map.olMap.updateSize();
}
function VisibledBar(bar){
	var visibled = (bar=="leftpanel")?Site.visibleColRight:Site.visibleColLeft;
	var statusbar =(visible==false)?true:false;
	return statusbar;
}

Site.InitBanner=function(){

	var databanner = Site.Config.banner_default;
	if(databanner==undefined){			
		$.ajax({
		type: 'GET',
		url: '/ws/interface/MapcitySocial.site.php',
		data: 'method=defaultbanner',
			success: function(data) {
				Site.Config.banner_default = data;
				Site.DefaultBanner = Site.Config.banner_default;
				$("#divBanner").show();
				document.getElementById('divBanner').innerHTML=Site.DefaultBanner;
				$("#adsmapcity").show();				
			}
		})					
	}else{
		Site.DefaultBanner = Site.Config.banner_default;			
		$("#divBanner").show();
		document.getElementById('divBanner').innerHTML=Site.DefaultBanner;
		$("#adsmapcity").show();
	}
}


Site.GoMapcity=function(){

var direc = "San Sebastian 2952 Las Condes";
self.parent.document.getElementById('search_by_address_addr').value=direc;
$("#btFinder","self.parent").click();
}

//===================================0000 MANEJO DE COOKIES =====================================================
    function cookiesAllowed() {
		setCookie('checkCookie', 'test', 1);
		
		if (getCookie('checkCookie')) {
			deleteCookie('checkCookie');
			return true;
		}
		return false;
    }
    function setCookie(name,value,expires, options) {
		var date = new Date();		
		var expires = date.setTime(date.getTime()+(365*24*60*60*1000));
    	if (options===undefined) { options = {}; }
    	if ( expires ) {
		    var expires_date = new Date();
		    expires_date.setDate(expires_date.getDate() + expires);
	    }		
    	document.cookie = name+'='+escape( value ) +    ( ( expires ) ? ';expires='+expires_date.toGMTString() : " ) +    ( ( options.path ) ? ';path=' + options.path : " ) +    ( ( options.domain ) ? ';domain=' + options.domain : " ) +    ( ( options.secure ) ? ';secure' : " );
    }
    function getCookie( name ) {
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;
		if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
		}
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ';', len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
    }
    function deleteCookie( name, path, domain ) {
    	if ( getCookie( name ) ) 
		document.cookie = name + '=' + ( ( path ) ? ';path=' + path : ") +  ( ( domain ) ? ';domain=' + domain : " ) + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
    } 
//CONVERTIR ARRAY EN STRING PARA PASARLO A PHP POR AJAX
Site.array2string = function(myarr){ var str=""; return str=myarr.join("{sep}");}

//game
Site.layerMarkerConsTreasure={}
Site.popupBusquedaTreasure= null
Site.treasure=function(){
	
	var zoom = Site.Map.map.getZoom();
	var selectzoom=11;
	
			$.ajax({
			type: 'GET',
			url: '/ws/interface/MapcitySocial.game.php',
			data: 'method=game',
			success: function(data) {

				//alert(data.replace(/\,/g,"\n"));// REEMPLAZAR , DEL JSON POR BR PARA QUE APAREZCA LISTADO DE ITEMES!!
				var objJson = MapCity.Core.decode(data);
				
				MapCity.Core.each(objJson, function(element){
				
					var lon = element.treasure_sites_lon;
					var lat = element.treasure_sites_lat;									
					var lonlat = new MapCity.Maps.LonLat(lon, lat);	
					var treasure_id = element.treasure_id;
					var tesicon= "img/"+element.treasure_detail_icon;
					var treasure_detail_id = element.treasure_detail_id;	

				Site.Map.map.setCenter(lonlat,zoom);
				
	
	
			var ContentMarker = "aaa";
			var size_treasure = new MapCity.Maps.Size(48,48);
			var offset_treasure = new MapCity.Maps.Pixel(-(size_treasure.w/2), -size_treasure.h);
			var icon_treasure = new MapCity.Maps.Icon(tesicon,size_treasure,offset_treasure);
	
			var marker = new MapCity.Maps.Marker(lonlat, icon_treasure);
			
			if(Site.layerMarkerConsTreasure[treasure_id] == null  || Site.layerMarkerConsTreasure[treasure_id] == undefined){
				Site.layerMarkerConsTreasure[treasure_id] = Site.Map.map.addLayer('MarkerClick_','marker');
			}	
			
			Site.layerMarkerConsTreasure[treasure_id].addMarker(marker);
			//document.getElementById(icon.imageDiv.id).style.cursor = 'auto';
			
			/*Genero popup para que aparesca altiro*/
			Site.AuxPopup(treasure_detail_id,treasure_id,ContentMarker,lonlat);
			
			/*Genero popup para que aparesca cuando hago click en el marker*/
			Event.observe(icon_treasure.imageDiv,'mousedown',function(e){
			//alert(element.channel_id+"\n"+element.treasure_id);
			var pixel_pos = Site.Map.map.olMap.getPixelFromLonLat(lonlat);

		if(document.getElementById('id_framePopupTreasure')){
			Site.clickMarkerTreasure(
				function(ContentMarker,lonlat){
					Site.popupBusquedaTreasure.destroy();
					Site.popupBusquedaTreasure = new OpenLayers.Popup.FramedCloud('id_framePopupTreasure',lonlat,null,ContentMarker,null,true);
					Site.Map.map.addPopup(Site.popupBusquedaTreasure);
				}
				,element
				 
			);
			}else{
			/*si hago click en el marker*/
			Site.clickMarkerTreasure(
			function(ContentMarker,lonlat){
				Site.popupBusquedaTreasure = new OpenLayers.Popup.FramedCloud('id_framePopupTreasure',lonlat,null,ContentMarker,null,true);
				Site.Map.map.addPopup(Site.popupBusquedaTreasure
				);
			}
			,element
			);
			
			}
});	
			});
			}
		})
}
Site.CloseTreasure=function(obj){
	
				$("#id_framePopupTreasure_close").parent().hide();
				Site.Map.map.removeAllMarkers('MarkerClick_', 'marker');
				$("#id_framePopupTreasure").remove();
}

Site.OkTreasure=function(cd){
	$("#loading_treasure").show();
	$.ajax({
		type: 'GET',
		url: '/ws/interface/MapcitySocial.game.php',
		data: "method=wr&cd="+cd,
		success: function(data) {	
							
			if (data==-1){
				
				Site.Modal('error_point',Site.CurrentLanguage+'{sep}notreasure');
				$("#id_framePopupTreasure_close").parent().hide();
				Site.Map.map.removeAllMarkers('MarkerClick_', 'marker');
				$("#id_framePopupTreasure").remove();														
				
				
			}else if (data==0){
				
				Site.Modal('error_point',Site.CurrentLanguage+'{sep}existwinnertreasure');
				$("#id_framePopupTreasure_close").parent().hide();
				Site.Map.map.removeAllMarkers('MarkerClick_', 'marker');
				$("#id_framePopupTreasure").remove();
				
				
			}else if (data==1){	
				Site.SendMail(cd);
				Site.Modal('error_point',Site.CurrentLanguage+'{sep}winnertreasure');
				$("#id_framePopupTreasure_close").parent().hide();
				Site.Map.map.removeAllMarkers('MarkerClick_', 'marker');
				$("#id_framePopupTreasure").remove();
			}else{
				alert("Momentaneamente estamos con problemas.\n\nPor favor inf\u00F3rmenos de este error:"+data);
				$("#id_framePopupTreasure_close").parent().hide();
				
			}
			
			$("#loading_treasure").hide();
		}
	})}
	
Site.Tsr=function(f){

		if (f=='l') { 
			if(document.getElementById("caja_user")!=null){Site.LoadTreasures(); }else{ alert('inicie sesion para este testing');}
		
		}else if (f=='m') {
			 if(document.getElementById("caja_user")!=null){  
			 
			 	if(Site.Map.map.getZoom() >= 12){
					Site.LoadTreasures();  
				}else{
					$("#id_framePopupTreasure_close").parent().hide();
					Site.Map.map.removeAllMarkers('MarkerClick_', 'marker');
					$("#id_framePopupTreasure").remove();					
				}
			 }
		}
}

Site.clickMarkerTreasure=function(callback,objJson){

	var html = ""
	var src = "";
	var lonlat = "";
	var feature = "";	
	MapCity.Core.each(objJson, function(element){

		var parser = new OpenLayers.Format.WKT();	
		feature =  parser.read(element.geometria); 								
		var lon = feature.geometry.x;	
		var lat = feature.geometry.y;
		var foto=element.foto;
		var describe=element.descripcion;
		var detailtreasure="{sep}"+foto+"{sep}"+describe;


		lonlat = new MapCity.Maps.LonLat(lon, lat);	
		
		var gift =  element.premio;
		var treasure_id = element.treasure_id;

				
		var tesicon= "img/"+element.treasure_detail_icon;
		var treasureImg = '<img class="id_framePopupTreasure_contentDiv_img" src="'+tesicon+'" border="0" align="left">'; 
		var treasure_title="<div class='id_framePopupTreasure_contentDiv_title'>Cofre del Tesoro Mapcity</div>"; //element.treasure_detail_title;
		var treasure_conditions = "<div class='id_framePopupTreasure_contentDiv_conditions'><a href='#' target='_blank'>Instrucciones para Retiro de Premio</a></div>";		
		var treasure_legend = "<div class='id_framePopupTreasure_contentDiv_legend'>¡Felicidades!, encontraste el tesoro Mapcity.</div>";
		var treasure_gift = "<div class='id_framePopupTreasure_contentDiv_gift'><span style=color:#333;>Ganaste: </span><br><a alt=\"Ver Descripci\u00F3n del Premio\" id=\"describepremio\"  title=\"Ver Descripci\u00F3n del Premio\"href=\"#\"  onclick=\"Site.Modal('error_point',Site.CurrentLanguage+'{sep}detailtreasure"+detailtreasure+"');\">"+gift+"</a></div>";
		
		treasure_question ="<div class=\"id_framePopupTreasure_contentDiv_img\"><img src=\"/img/treasure/text-loquieres.png\" border=\"0\" align=\"left\"></div>";

		treasure_question =treasure_question+ "<div class=\"Treasure_si\"   id=\"Treasure_si\"onclick=\"Site.OkTreasure('"+treasure_id+"');\"></div>";

		treasure_question =treasure_question+ "<div class=\"Treasure_no\"  id=\"Treasure_no\" onclick=\"Site.CloseTreasure(this.parentNode.parentNode);\"></div>";
		
		treasure_question =treasure_question+ "<img src=\"/img/loading2.gif\" id=\"loading_treasure\" border=\"0\" align=\"right\">";
		
		Site.ThisPointId=treasure_id;	
	
		$("#map_OpenLayers_Container").css("width","305px");
		$("#map_OpenLayers_Container").css("height","1530px");		
		
		$("#id_framePopupTreasure").css("height","300px");		
		$("#id_framePopupTreasure").css("padding-bottom","30px");				
		
		html +=treasure_gift+treasure_question;		
		html +="<br><br><br><br><br><br><br><br><br><br><br>";
		})
	/*genero el popup del marker*/
	callback(html,lonlat);
	 //inicializa los botones de los concursos con tooltips
	var email=document.getElementById('email_user').value;
	var msg="Te enviaremos un e-mail a <b>"+ email + "</b> con<br>las instrucciones para cobrar tu premio";
	var msgpremio = "Click aqu&iacute; para ver descripci&oacute;n del premio";
	Site.ToolTipsInit('Treasure_si',msg,"top","top");
	Site.ToolTipsInit('describepremio',msgpremio,"top","top");
}
Site.ToolTipsInit=function(cod,msg,x,y){
	 $('#'+cod).bt(msg,
  {
    fill: '#FFFF99',
    cornerRadius: 10,
    strokeWidth: 0,
    shadow: true,
    shadowOffsetX: 3,
    shadowOffsetY: 3,
    shadowBlur: 8,
    shadowColor: 'rgba(0,0,0,.9)',
    shadowOverlap: false,
    noShadowOpts: {strokeStyle: '#999', strokeWidth: 2},
    positions: [x, y]
  });
	
}

Site.layerMarkerConsTreasure;
Site.popupBusquedaTreasure= null
Site.LoadTreasures = function(){

	var layerMarkerConsTreasure = Site.Map.map.getLayer('MarkerClick_', 'marker');
							
	if (layerMarkerConsTreasure != undefined) {
		Site.Map.map.removeAllMarkers('MarkerClick_', 'marker');
		var layerMarkerConsTreasure = Site.Map.map.getLayer('MarkerClick_', 'marker');
		
	}else {
		var layerMarkerConsTreasure = Site.Map.map.addLayer('MarkerClick_', 'marker');
	}		
	 var bound = Site.Map.map.getExtent();						 
	 var xmin = bound.left;
	 var xmax = bound.right;
	 var ymax = bound.top;
	 var ymin = bound.bottom;
	 var cod = "";					 
	 
	 Site.ThisCenter = Site.Map.map.getCenter();
	 var thisLon = Site.ThisCenter.lon;
	 var thisLat = Site.ThisCenter.lat;	

	$.ajax({
			type: 'GET',
			url: 'ws/interface/MapcitySocial.game.php',
			data: 'method=gm&trs=1&ymin='+ymin+'&ymax='+ymax+'&xmin='+xmin+'&xmax='+xmax+'&lon='+thisLon+'&lat='+thisLat,
			success: function(json) {

				if(json != ""){
					try{
					
				var objJson = MapCity.Core.decode(json); 
				
				if (objJson!=""){
					var xmin="";
					var ymin="";
					var xmax="";
					var ymax="";
					
					var format_line_color;
					var format_fill_color;
					var format_line_width;
					var format_fill_transparency;
					MapCity.Core.each(objJson, function(element,i){
						if (element.totalPoints!=undefined && element.MaxPoints	!=undefined) {
								var total = element.totalPoints;
								var maximo = element.MaxPoints;																								
									
							}												
						try{if (element.geometria.indexOf("POINT")>-1){
							
							cod = element.treasure_id;
													
							var parser = new OpenLayers.Format.WKT();
							var feature =  parser.read(element.geometria); 		
							
							element.lon = feature.geometry.x;	
							element.lat = feature.geometry.y;
							
							var ContentMarker = "aaa";
													
							var lonlat = new MapCity.Maps.LonLat(element.lon, element.lat);
							var size = new MapCity.Maps.Size(50,50);
							var offset = new MapCity.Maps.Pixel(-(size.w/2), -size.h);
							var icon = new MapCity.Maps.Icon('img/treasure/treasure.png',size,offset);
	
						
							var marker = new MapCity.Maps.Marker(lonlat, icon);
	
							//Site.layerMarkerConsTreasure[cod].addMarker(marker);
							Site.Map.map.addMarker(layerMarkerConsTreasure,marker);
							
							Event.observe(icon.imageDiv,'mousedown',function(e){
							var pixel_pos = Site.Map.map.olMap.getPixelFromLonLat(lonlat);
							
									if(document.getElementById('id_framePopupTreasure'))
										Site.popupBusquedaTreasure.destroy();
							/*si hago click en el marker*/
								Site.clickMarkerTreasure(
								function(ContentMarker,lonlat){
									Site.popupBusquedaTreasure = new OpenLayers.Popup.FramedCloud('id_framePopupTreasure',lonlat,null,ContentMarker,null,true);
									Site.Map.map.addPopup(Site.popupBusquedaTreasure);
								
								}
								,element
								);
							
							Event.stop(e);
							}); 
	
						}else{}
						
						}catch(err){};
					});
					MapCity.Core.select('div[id^=OpenLayers.Layer.Markers]').setStyle('zIndex',800);
					
				}
			}catch(err){}
			
			}
				try{document.getElementById('tabs_loading').style.display='none';}catch(err){}
			}
		})	
}

Site.opu=function(){
	
		$("#tabsPerfilUser_loading").show();
		$.get("/ws/interface/MapcitySocial.users.php",{ method:"issn" } ,function(data) { 
			
				
			var ssn=data;
			var chain=ssn.indexOf("{sep}");
	
			if ( (chain==-1) ||  (ssn=0)){
		
				Site.switchView('View_Options',true);
				try{
					if (self.parent.document.getElementById('divNoLogin').style.display!='') {
						self.parent.document.getElementById('divNoLogin').style.display='inline';
					}
				}catch(err){}
									
			}else if (chain>-1){
				
				Site.switchView('View_Options',true);				
				try{document.getElementById('divNoLogin').style.display='none';	 $("#divNoLogin").remove();	}catch(err){}				
				document.getElementById('FrontBarSite').style.display='none';				
				document.getElementById('FrontBarPerfilUser').style.display='block';								
				
				var mylang = self.parent.Site.CurrentLanguage;
				var mywords = "tit_tabtema,tit_usuario_cuenta,tit_usuario_pass,tit_usuario_perfil";//tit_tabcuenta
				$.get("/func/getwords.php",{lang:mylang, words:mywords } ,function(datawords) { 
				
					var arraywords = datawords.split("{sep}"); 							
					$.get("/webparts/usertabsjs.php" ,function(datatabs) {	
					
							try{$('#FrontBarPerfilUser', self.parent.document).html(datatabs);}catch(err){}
							
							if( (self.parent.document.getElementById('FrontBarPerfilUser').innerHTML) =="") {
							//	alert('');
								try{$('#FrontBarPerfilUser', self.parent.document).html(datatabs);}catch(err){}
								try{$('#FrontBarPerfilUser').html(datatabs); }catch(err){}
							}
																		
							$.get("/webparts/users/frm_login.php" ,function(datalogin) {
	
								$("#PerfilUserDetail").html(datalogin);
								$.get("/webparts/users/frm_perfil.php" ,function(dataperfil) {
	
										$("#divUserPerfil").html(dataperfil);
										$("#tabsPerfilUser_loading").hide();
									
								});
									
							});
							
							$("#barra_tabs_PerfilUser").show();
							$("#tabPerfilUser").show();
							$("#tabPerfilUser2").show();
							
							$("#tit_usuario_cuenta").show();
							$("#tit_usuario_pass").show();
							$("#tit_usuario_perfil").show();								
							
							
							self.parent.document.getElementById('tabPerfilUser').innerHTML=arraywords[1];
							self.parent.document.getElementById('tabPerfilUser2').innerHTML=arraywords[0];								
							self.parent.document.getElementById('tit_usuario_cuenta').innerHTML=arraywords[1];																																
							self.parent.document.getElementById('tit_usuario_pass').innerHTML=arraywords[2];														
							self.parent.document.getElementById('tit_usuario_perfil').innerHTML=arraywords[3];
							self.parent.document.getElementById('tit_usuario_perfil').innerHTML=arraywords[3];																					
							self.parent.document.getElementById('Menu_User_Theme').innerHTML=arraywords[0]; 								
																						
					});										
				});
			}
		});
}

Site.ActiveThemes=function(){
	$("#tabsPerfilUser_loading").show();
	$('#Menu_User_Account').hide();			
	$('#divUserPerfil').hide();		
	$('#divPass').hide();		
	$('#divAccount').hide();
	
	$('#Menu_User_Theme').show();	
	$('#divUserThemes').show();		
	
			
	document.getElementById('tabPerfilUser2').className='tabs_portada_hover';
	document.getElementById('tabPerfilUser').className='tabs_portada';	
	$.get("/webparts/users/frm_themes.php" ,function(datathemes) { 
	
		var divthem = '<div id="divUserThemes" style="position:relative; top:0; min-height:700px; bottom:0; height:auto; "></div>'
		$("#PerfilUserDetail").html($("#PerfilUserDetail").html()+divthem);		
		$('#divUserThemes').html(datathemes);		
		$("#tabsPerfilUser_loading").hide();
		
	});
}
Site.Activeperfil=function(){
	$("#tabsPerfilUser_loading").show();
	$('#divUserPerfil').show();	
	$('#Menu_User_Account').show();
	$('#Menu_User_Theme').hide();
	
	$('#divUserPerfil').hide();		
	$('#divPass').hide();
	$('#divUserThemes').hide();	
	$('#divAccount').show();
	document.getElementById('tabPerfilUser').className='tabs_portada_hover';
	document.getElementById('tabPerfilUser2').className='tabs_portada';			
	$("#tabsPerfilUser_loading").hide();
}

tooltiphelp_edit_channel=function(obj){

	
	var help_es='Ingresa el nombre que tendra tu canal';
	var help_en='Login to your account Mapcity with e-mail address you used when you registered';	
	
	if (Site.CurrentLanguage=="es") {helpmsg=help_es;}else{helpmsg=help_en;}

	var cod ="#channel_name";
	var msg = helpmsg;
	var x="bottom";
	var y ="bottom";
	
	$(cod).bt(msg,
	  {
		fill: '#FFFF99',
		cornerRadius: 10,
		strokeWidth: 0,
		shadow: true,
		shadowOffsetX: 3,
		shadowOffsetY: 3,
		shadowBlur: 8,
		shadowColor: '#f9f9f9',
		shadowOverlap: false,
		noShadowOpts: {strokeStyle: '#ccc', strokeWidth: 2},
		positions: [x, y]
	});
	
}
function is_int(input){
    return typeof(input)=='number'&&parseInt(input)==input;
  }

function thisbound(){
	
		 var bound = Site.Map.map.getExtent();
		 
		 var xmin = bound.left;
		 var xmax = bound.right;
		 var ymax = bound.top;
		 var ymin = bound.bottom;	
		
		var msg = xmin+","+ymin+","+xmax+","+ymax;
		
		alert(msg);
	
}
function print_j(array, return_val) {
    
    var output = "", pad_char = " ", pad_val = 4, d = this.window.document;    var getFuncName = function (fn) {
        var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
        if (!name) {
            return '(Anonymous)';
        }        return name[1];
    };
 
    var repeat_char = function (len, pad_char) {
        var str = "";        for (var i=0; i < len; i++) {
            str += pad_char;
        }
        return str;
    }; 
    var formatArray = function (obj, cur_depth, pad_val, pad_char) {
        if (cur_depth > 0) {
            cur_depth++;
        } 
        var base_pad = repeat_char(pad_val*cur_depth, pad_char);
        var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
        var str = "";
         if (typeof obj === 'object' && obj !== null && obj.constructor && getFuncName(obj.constructor) !== 'PHPJS_Resource') {
            str += "Array\n" + base_pad + "(\n";
            for (var key in obj) {
                if (obj[key] instanceof Array) {
                    str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char);                } else {
                    str += thick_pad + "["+key+"] => " + obj[key] + "\n";
                }
            }
            str += base_pad + ")\n";        } else if (obj === null || obj === undefined) {
            str = '';
        } else { // for our "resource" class
            str = obj.toString();
        } 
        return str;
    };
 
    output = formatArray(array, 0, pad_val, pad_char); 
    if (return_val !== true) {
        if (d.body) {
            this.echo(output);
        }        else {
            try {
                d = XULDocument; // We're in XUL, so appending as plain text won't work; trigger an error out of XUL
                this.echo('<pre xmlns="http://www.w3.org/1999/xhtml" style="white-space:pre;">'+output+'</pre>');
            }            catch (e) {
                this.echo(output); // Outputting as plain text may work in some plain XML
            }
        }
        return true;    } else {
        return output;
    }
}
Site.TwitterSearch=function(string){
	
	
	string = (string==0)?"":string;
	Site.GetTweets=true;
	// ***************  BORRAR LAYER CON MARKER Y VOLVER A CARGARLO  ***************************
		try{
			Site.layerTwitter.destroy();
			Site.layerTwitter = null;
			Site.Map.map.removeLayer("Site.layerTwitter");
		}catch(err){}
		
		if (Site.layerTwitter==undefined || Site.layerTwitter==null) { 
			Site.layerTwitter = Site.Map.map.addLayer('MarkerClickTwitter','marker'); 
			
		}
	// ***************  BORRAR LAYER CON MARKER Y VOLVER A CARGARLO  ***************************
	$("#tabs_loading").show();	

	Site.ThisCenter = Site.Map.map.getCenter();
	var lon = Site.ThisCenter.lon;
	var lat = Site.ThisCenter.lat;	
	//GET EXTEND DEL MAPA VM
  var exten = Site.Map.map.olMap.getExtent();	
	var lonI=exten.left;
	var latI=exten.bottom;
	var lonD=exten.right;
	var latS=exten.top;
	
	//FIN
  
	var params = "lat="+lat+"&lon="+lon+"&loni="+lonI+"&lati="+latI+"&lond="+lonD+"&lats="+latS+"&query="+string;	
		 $.ajax({
					type: 'GET',
					url: 'webparts/twitter.php',
					data: params,
					// Mostramos un mensaje con la respuesta de PHP
					success: function(responseObject) {
						if(responseObject.indexOf("alert")!=-1){
								eval(responseObject); 
								return false;
						}					

							//alert(responseObject);
						var json = jQuery.parseJSON(responseObject);
						//alert(json);
						//alert(print_r(json,true));
						
						var TwittsList = json['menu'];
						if($("#list_elements_370").html()!=null)
						{
							var lst = ($("#list_elements_370").html()).split(" ");
						}
					
							Site.Map.map.olMap.zoomTo(14);					
					
							var jsonitem = json['results'];	
							var num_jsonitem = (json['results']).length;

							var numTuits = (num_jsonitem==1)?num_jsonitem+" tweet":num_jsonitem+" tweets";
							if($("#list_elements_370").html()!=null)
							{
								$("#spanNumElements").text(numTuits);
							}

							var twicon ="";
								
							if(num_jsonitem > 0) {
								if($("#list_elements_370").html()!=null)
								{
									$("#normal_elements_370").html(TwittsList);
								}
								
								TwitterSearch_Circle();
								//Site.layerTwitter.setZIndex(Site.Map.map.olMap.Z_INDEX_BASE['Feature']);
								Site.layerTwitter.setZIndex(1000);
								try{
									Site.markers_FSQ.setZIndex(Site.Map.map.olMap.Z_INDEX_BASE['Feature']);
								}catch(err){}
								$.each(jsonitem, function(i, element) {
									var lat 			= element.lat;																												
									var lon 			= element.lon;							
									/*if(lat<=latS && lat >= latI && lon <=lonD && lon >=lonI)
									{*/
										var tweet_id=json['id'][i];
										
										var popupdata		= new Array();	
										var usuario 		= element.usuario;
										var mensaje 		= element.mensaje;												
										var imagen 			= element.imagen;				
										var fec_msg 		= element.fec_msg;
										var location 		= element.location;																												
										var lat 			= element.lat;																												
										var lon 			= element.lon;							
										var LonLat			= new OpenLayers.LonLat(lon,lat);
										var zoom_actual		= 14;
										var size 			= new OpenLayers.Size(33,40);
										var offset 			= new OpenLayers.Pixel(-(size.w/2), -((size.h/2) + 7));
										var icon 			= new OpenLayers.Icon('/img/markers/sin_ico.png', size, offset);	
										icon.imageDiv.title = usuario;														
										icon.imageDiv.id = tweet_id;
																															
										$(icon.imageDiv).css("cursor","pointer");
										
                  	
										twicon=icon;									
										
                  	
										var size 			= new OpenLayers.Size(24,22);
										var offset 			= new OpenLayers.Pixel(-(size.w/2), -size.h);
										var iconimg 		= new OpenLayers.Icon(imagen, size, offset);	
										iconimg.imageDiv.title = usuario;
                  	
                  	
                  	
										
										
										
										$(iconimg.imageDiv).css("cursor","pointer");
                  	
	                	
										var layerTwitterMarker = new OpenLayers.Marker(LonLat, icon);
										Site.layerTwitter.addMarker(layerTwitterMarker);
										
										var layerTwitterMarker = new OpenLayers.Marker(LonLat, iconimg);
										Site.layerTwitter.addMarker(layerTwitterMarker);
										Event.observe(iconimg.imageDiv,'mousedown',function(e) {
												Site.TwitterSearch_marker(element,this);
												Event.stop(e);
												return false;							
											});
										i++;
									//}
									});
									//alert(print_r(twicon,true));
									
							}
							else {
								
								var img = "<div align='center'><table><tr><td><img src='/img/twitter_search.png' width='32' height='32' border='0'></td>";
								var TwittsNotResults = img+"<td><b><h3 align='center' style='font-size:14px; color:#333;'>B&uacute;squeda sin resultados</h2></b></td></tr></table>";
								$("#normal_elements").html(TwittsNotResults);
																
						}
						$("#tabs_loading").hide();							
						//TwitterSearch_Circle();

				}
		 });
}



							


Site.TwitterSearch_marker=function(json,icon){


		try{
			Site.layerPopupTwitter.destroy();
			Site.layerPopupTwitter = null;
			Site.Map.map.removeLayer("Site.layerPopupTwitter");
		}catch(err){}

	var usuario = json['usuario'];
	var lblusuario = '<span style="color:#003399; font-size:15px; font-weight:bold;">@'+usuario+"</span>";
	var link_usuario = '<a href="http://twitter.com/'+usuario+'" target="_blank">'+lblusuario+'</a';
	
	
	var mensaje = json['mensaje'];
	var imagen = json['imagen'];
	var currentdate = new Date();
	//alert(new Date(json['fec_msg']).getTime());
	var fec_msg = '<span style="color:#999; margin-top:25px;"><br>'+  timeAgo(json['fec_msg'],currentdate.toUTCString()) + '</span>';
	var location = json['location'];																												
	var lat = json['lat'];																												
	var lon = json['lon'];
		
	var ContentHTML = '\<div style="width:150px; height: 130px; padding:0px; padding-bottom:15px;">\
						<table border="0" cellspacing="0" cellpadding="0" width="150">\
						  <tr>\
							<td>\<img src="'+imagen+'" alt="usert" name="user" width="60" height="60" id="user" style="margin-right:5px;" />\</td>\
							<td>\<a href="#">'+link_usuario+'</a>\</td>\
						  </tr>\
						  <tr>\
							<td>\&nbsp;</td>\
							<td>\&nbsp;</td>\
						  </tr>\
						  <tr>\
							<td colspan="2">'+mensaje+'<br></td>\
						  </tr>\
						  <tr>\
							<td colspan="2">'+fec_msg+'</td>\
						  </tr>\
						  <tr>\
							<td colspan="2">\&nbsp;</td>\
						  </tr>\
						</table>\
						</div>\
						';




var a = Math.round(Math.random()*(3-1))+1;
a = a * 10000; 

var Popupid = "_"+usuario+"_"+a+"_"+lon+"_"+lat;


Site.layerPopupTwitter = new OpenLayers.Popup.FramedCloud("popup"+Popupid,
														new OpenLayers.LonLat(lon,lat),
														null,//new OpenLayers.Size(50,50),
														ContentHTML,
														null,
														true
														);
Site.layerPopupTwitter.closeOnMove = false; //vm false
Site.layerPopupTwitter.panMapIfOutOfView=true;	 //vm true
Site.Map.map.addPopup(Site.layerPopupTwitter);	

}




Site.TwitterSearch_openpopup=function(json,icon){


		try{
			Site.layerPopupTwitter.destroy();
			Site.layerPopupTwitter = null;
			Site.Map.map.removeLayer("Site.layerPopupTwitter");
		}catch(err){}
		
		
json = json.replace(/SP/g, '"');
var json = MapCity.Core.decode(json); 


	var usuario = json['usuario'];
	var lblusuario = '<span style="color:#003399; font-size:15px; font-weight:bold;">@'+usuario+"</span>";
	var link_usuario = '<a href="http://twitter.com/'+usuario+'" target="_blank">'+lblusuario+'</a';
	
	var currentdate = new Date();
	var mensaje = json['mensaje'];
	var imagen = json['imagen'];
	var fec_msg = '<span style="color:#999; margin-top:25px;"><br>'+  timeAgo(json["fec_msg"],currentdate.toUTCString()) + '</span>';
	var location = json['location'];																												
	var lat = json['lat'];																												
	var lon = json['lon'];
		//LISTADO //VM
	var ContentHTML = '\<div style="width:150px; height: 130px;">\
						<table border="0" cellspacing="0" cellpadding="0" width="150">\
						  <tr>\
							<td>\<img src="'+imagen+'" alt="usert" name="user" width="60" height="60" id="user" style="margin-right:5px;" />\</td>\
							<td>\<a href="#">'+link_usuario+'</a>\</td>\
						  </tr>\
						  <tr>\
							<td>\&nbsp;</td>\
							<td>\&nbsp;</td>\
						  </tr>\
						  <tr>\
							<td colspan="2">'+mensaje+'<br></td>\
						  </tr>\
						  <tr>\
							<td colspan="2">'+fec_msg+'</td>\
						  </tr>\
						  <tr>\
							<td colspan="2">\&nbsp;</td>\
						  </tr>\
						</table>\
						</div>\
						';

var a = Math.round(Math.random()*(3-1))+1;
a = a * 10000; 

var Popupid = "_"+usuario+"_"+a+"_"+lon+"_"+lat;



Site.layerPopupTwitter = new OpenLayers.Popup.FramedCloud("popup"+Popupid,
														new OpenLayers.LonLat(lon,lat),
														null,
														ContentHTML,
														null,
														true
														);
Site.layerPopupTwitter.closeOnMove = false;	 //vm false
Site.layerPopupTwitter.panMapIfOutOfView=true;			 //vm true										
$(Site.layerPopupTwitter.olPopup).css("cursor","pointer");
Site.Map.map.addPopup(Site.layerPopupTwitter);



//alert(print_r(json,true));
	
}
TwitterSearch_center=function(lon,lat,cod,json,obj){
	

	var marker = $("#"+cod);
	
	Site.TwitterSearch_openpopup(json,marker);	

	//var selectrow = obj.id;
//	
//	$(obj).css("background","#FF9");
//	
//	$("#selected_elements").val(selectrow);


	
	
}


function isDefined( variable) { return (typeof(window[variable]) != "undefined");}


Site.TwitterSearch_keyactive=function(e) {
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
if(keynum==13){ Site.TwitterSearch(); }
//keychar = String.fromCharCode(keynum)
//numcheck = /\d/
//return !numcheck.test(keychar)
	
}



TwitterSearch_Circle=function(){
	var drawRad = Site.Map.map.getLayer('Draw_Layer', 'vector');
	if (drawRad != undefined) {
		Site.Map.map.removeAllFeatures('Draw_Layer', 'vector');
		drawRad = Site.Map.map.getLayer('Draw_Layer', 'vector');
		Site.Map.map.removeLayer(drawRad);
	}

	var circleStyle = {
			fillColor: "#cccccc",
			fillOpacity: 0.3,
			strokeColor: "#c0c0c0",
			strokeOpacity: 1,
			strokeWidth: 1,
			pointRadius: 6,
			pointerEvents: "visiblePainted",
			cursor: "pointer",
			zIndex: 0
		};

	var lonlat = new OpenLayers.Geometry.Point(Site.Map.map.getCenter().lon, Site.Map.map.getCenter().lat);
	drawRad = Site.Map.map.addLayer('Draw_Layer', 'vector');

	var radius_usr = "1";
	radius_usr = (radius_usr * 0.0000110816939286905);
	var polygon1 = new OpenLayers.Feature.Vector(OpenLayers.Geometry.Polygon.createRegularPolygon(lonlat, radius_usr, 40,0), null, circleStyle); 
	drawRad.addFeatures([polygon1]);

	var radius_usr = "3000";
	radius_usr = (radius_usr * 0.0000110816939286905);
	var polygon1 = new OpenLayers.Feature.Vector(OpenLayers.Geometry.Polygon.createRegularPolygon(lonlat, radius_usr, 40,0), null, circleStyle); 
	drawRad.addFeatures([polygon1]);
}

function timeAgo(date1, date2, granularity){
var self = this;
periods = [];
periods['semana'] = 604800;
periods['d\u00eda'] = 86400;
periods['hora'] = 3600;
periods['minuto'] = 60;
periods['segundo'] = 1;
if(!granularity){
granularity = 5;
}
(typeof(date1) == 'string') ? date1 = new Date(date1).getTime() / 1000 : date1 = new Date().getTime() / 1000;

(typeof(date2) == 'string') ? date2 = new Date(date2).getTime() / 1000 : date2 = new Date().getTime() / 1000;
if(date1 > date2){
difference = date1 - date2;
}else{
difference = date2 - date1;
}

output = '';
for(var period in periods){
var value = periods[period];
if(difference >= value){
time = Math.floor(difference / value);
difference %= value;
output = output +  time + ' ';
if(time > 1){
output = output + period + 's ';
}else{
output = output + period + ' ';
}
}
granularity--;
if(granularity == 0){
break;
}
}
return 'hace '+output ;
}


