//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.bandera=0;

// =======    JQUERY =============
$(document).ready(function() {
	Site.IE=Site.IsInternetExplorer();						   
						   
	$(window).bind('resize', function() {	
		
		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'
	  
	$('ul li:has(ul)').hover( 
		  function(e) 
		  { 
			 $(this).find('ul').css({display: "block"}); 
			 $(this).find('ul').css({top: "50"}); 		 
			$(this).find('ul').css({zIndex: "900000"}); 		 
		  }, 
		  function(e) 
		  { 
			 $(this).find('ul').css({display: "none"}); 
		  } 
	   ); 
	//Cambia velocidad de fade si es explorer y oculta errores de js
	 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);}})	 

	 //Site.InitBanner();
});



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){
	for (var c=1; c<5;	c++){
		var codold = "#"+c;
		document.getElementById(c).className="";
		$(codold).css("backgroundColor",Site.color_pointer_menu);	
	}
	document.getElementById(mnu).className="checked";
	var cod = "#"+mnu;
	$(cod).css("backgroundColor",Site.color_pointer_active_menu);	
}
function ChangeTheme(){

	var my_theme = (document.getElementById('theme_user')!=null)?document.getElementById('theme_user').value:"default";
	Site.ChangeBackground(my_theme);

}
Site.ChangeBackground=function(theme){

	$("body").css("backgroundColor","#ffffff");
		if (theme=='default'){
			
				$.ajax({
					type: 'POST',
					url: '/ws/interface/MapcitySocial.site.php',
					data: 'method=config&field=theme_default',
					success: function(data) {
										//alert(data);
						var theme = data.split("{sep}");
						var img = theme[2];
						Site.color_menu = theme[3];
						Site.color_title = theme[4];
						Site.color_active = theme[5];
						Site.color_pointer_menu = theme[6];	
						Site.color_pointer_active_menu = theme[7];
						Site.logo = theme[8];							
						
						//$("#pointermenu").css("backgroundColor",Site.color_pointer_menu);
						$("#pointermenu ul").css("backgroundColor",Site.color_pointer_menu);						
//						$("#pointermenu ul li div.checked").css("backgroundColor",Site.color_pointer_active_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);

						var fondo = "url(img/textures/"+img+")"; // repeat";
//						try{ 
							var bodybackground=fondo+" #fff";
							$("body").css("background",bodybackground);
//						}catch(err){}	
						document.getElementById('mapcity_logo').src="/img/interface/"+Site.logo;						
					}
				})
								
		}else{
			
				$.ajax({
					type: 'POST',
					url: '/ws/interface/MapcitySocial.site.php',
					data: 'method=gettheme&selected='+theme,
					success: function(data) {
										//alert(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];
						//Site.color_header = theme_data[9];
						Site.back_img_position=(theme_data[9]!="")?theme_data[9]:"left top";
						
						//$("#pointermenu").css("backgroundColor",Site.color_pointer_menu);
						$("#pointermenu ul").css("backgroundColor",Site.color_pointer_menu);						
//						$("#pointermenu ul li div.checked").css("backgroundColor",Site.color_pointer_active_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);
						//$("#framecontentTop").css("backgroundColor",Site.color_header);


						img = (img=="")?"twitter.gif":img;

						var fondo = "url(/img/textures/"+img+") #fff";
						//var fondo = "url(/img/textures/"+img+") "+Site.back_img_position+" #fff";
						document.body.style.background=fondo;
						document.getElementById('mapcity_logo').src="/img/interface/"+Site.logo;

					}
				})
		}
		Site.ShowActiveChannels();
		
}


function ChangeUserBackground(theme){
			
		$.ajax({
			type: 'POST',
			url: '/ws/interface/MapcitySocial.site.php',
			data: 'method=gettheme&selected='+theme,
			success: function(data) {
								//alert(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").css("backgroundColor",Site.color_pointer_menu);
				$("#pointermenu ul").css("backgroundColor",Site.color_pointer_menu);						
//						$("#pointermenu ul li div.checked").css("backgroundColor",Site.color_pointer_active_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);

				img = (img=="")?"twitter.gif":img;
				
//				Site.NoSaveThemeSelected=theme;

				var fondo = "url(/img/textures/"+img+") #fff";
				//document.body.style.background=fondo;
				$("body").css("background",fondo);
				
				document.getElementById('mapcity_logo').src="/img/interface/"+Site.logo;				
//				document.getElementById('SaveThemeButton').className="MenuThemes_atention";
				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;
	
	//alert(Site.NoSaveThemeSelected);

	$.ajax({
		type: 'POST',
		url: '/ws/interface/MapcitySocial.users.php',
		data: theme_data,
		success: function(data) {
			//alert(data);
			var msg="msgbox_savepreference";
			var ico="ok";			
			//Site.Modal('error_point',Site.CurrentLanguage+"{sep}alert{sep}"+msg+"{sep}"+ico);
			
			if (document.getElementById('theme_user')!=null){ 
			
				document.getElementById('theme_user').value=selected;//Site.NoSaveThemeSelected;
				//alert(document.getElementById('theme_user').value);
				//Site.NoSaveThemeSelected="";
			}
			//document.getElementById('SaveThemeButton').className="MenuThemes";
			
		}
})						


}

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 );
}




Site.LoadConfig=function(){
	  $.ajax({
            type: 'POST',
            url: 'webparts/themes.php',
            data: "method=list",
            success: function(data) {
                $("#divThemes").html(data);
            }
        })
}

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;

}
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: 'POST',
            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: 'POST',
		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)+"px";
		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(){//a25c01b6


var banner = "<iframe id='adsmapcity' name='adsmapcity' style='z-index:0;' src='http://ads.mapcity.com/www/delivery/afr.php?refresh=30&amp;zoneid=23&amp;target=_blank&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;ct0=INSERT_CLICKURL_HERE' framespacing='0' frameborder='no' scrolling='no' width='160' height='600' allowtransparency='true'>";
banner += "<a href='http://ads.mapcity.com/www/delivery/ck.php?n=af6d0485&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'>"
banner += "<img src='http://ads.mapcity.com/www/delivery/avw.php?zoneid=23&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=af6d0485&amp;ct0=INSERT_CLICKURL_HERE' border='0' alt='' />";
+"</a></iframe>";
$("#divBanner").show();
document.getElementById('divBanner').innerHTML=banner;
$("#adsmapcity").show();
//document.getElementById('adsmapcity').className="";



//alert(document.getElementById('divBanner').innerHTML);

/*		if (Site.certifica==false) {
//								Site.include('js/certifica/certifica-js14.js');
//								Site.include('js/certifica/certifica.js');
//								setTimeout("cert_registerHit(200704,'/home/beta');",500);
		
//$("#imgCertifica").html('<img src="http://hits.e.cl/hit.dll?sitio_id=200704&path=/home/beta" name="cert_Pivot_x" id="cert_Pivot_x" alt="" height="1" width="1">');
$("#imgCertifica").html('<img src="http://hits.e.cl/cert/hit.dll?sitio_id=200704&path=/home/beta" height="1" width="1">');
								Site.certifica=true;	
		}*/
		


}


Site.GoMapcity=function(){

var direc = "San Sebastian 2952 Las Condes";
self.parent.document.getElementById('search_by_address_addr').value=direc;
$("#btFinder","self.parent").click();
//self.parent.document.getElementById('btFinder').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;
	
	//if (zoom>=selectzoom){
		
	
			$.ajax({
			type: 'POST',
			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";/*"<font size='3'><b>"+title+"</b></font><br><br><table width='270px'>";
			ContentMarker += "<tr><td><b>"+description+"</b></td></tr>";
			ContentMarker += "<tr><td></td></tr>";
			ContentMarker += "<tr><td>"+  Site.social +"</td></tr>";		//Site.social				
			ContentMarker += "</table>";*/
									
			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);
//->aqui	


		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: 'POST',
		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.SendMail=function(cod){
	$.ajax({
		type: 'POST',
		url: '/webparts/treasure/winner_email.php',
		data: "cod="+cod,
		success: function(data) {
			
			//alert(data);
		}
	})
}
	
Site.Tsr=function(f){
	
	if (Site.Machine==1){
		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 = "";	

//	var objJsoxn = MapCity.Core.encode(objJson); 
//	alert(objJsoxn);
//debugger;
	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*/
	//alert("sss : "+lonlat);
	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.calculateRating(callback,html,lonlat,id_channel,id_object,countComments);

}
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: 'POST',
			url: 'ws/interface/MapcitySocial.game.php',
			data: 'method=gm&trs=1&ymin='+ymin+'&ymax='+ymax+'&xmin='+xmin+'&xmax='+xmax+'&lon='+thisLon+'&lat='+thisLat,
			// Mostramos un mensaje con la respuesta de PHP
			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;
					
						//debugger;
					MapCity.Core.each(objJson, function(element,i){
						if (element.totalPoints!=undefined && element.MaxPoints	!=undefined) {
								//alert("total: "+element.totalPoints+" /  maiximo: "+element.MaxPoints);
								var total = element.totalPoints;
								var maximo = element.MaxPoints;																								
									
							}												
						try{if (element.geometria.indexOf("POINT")>-1){
							
							cod = element.treasure_id;
							
//
//							if(Site.layerMarkerConsTreasure[cod] == null  || Site.layerMarkerConsTreasure[cod] == undefined){
//								Site.layerMarkerConsTreasure[cod] = Site.Map.map.addLayer('MarkerClick_','marker');
//							}
//							
												
							
							
													
							var parser = new OpenLayers.Format.WKT();
							var feature =  parser.read(element.geometria); 		
							
							//debugger;
							element.lon = feature.geometry.x;	
							element.lat = feature.geometry.y;
							
							var ContentMarker = "aaa";
							/*var ContentMarker = "<font size='3'><b>"+element.content_title+"</b></font><br><br><table width='270px'>";
							ContentMarker += "<tr><td><b>"+element.content_description+"</b></td></tr>";
							ContentMarker += "<tr><td></td></tr>";											
							ContentMarker += "<tr><td>"+  Site.social +"</td></tr>";		//Site.social				
							ContentMarker += "</table>";*/
													
							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);
							
							
							
							//document.getElementById(icon.imageDiv.id).style.cursor = 'pointer';
	
	
							Event.observe(icon.imageDiv,'mousedown',function(e){
							//alert(element.content_id+"\n"+element.content_id);
							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){}
			
			}
				
	// 			var bounds = new OpenLayers.Bounds(xmin,ymin,xmax,ymax);
	// 			Site.Map.map.zoomToExtent(bounds); 
				try{document.getElementById('tabs_loading').style.display='none';}catch(err){}
				
			}
		})	
}

Site.opu=function(){
		$("#tabsPerfilUser_loading").show();
		$.post("/ws/interface/MapcitySocial.users.php",{ method:"issn" } ,function(data) { 
				
			var ssn=data;
			if (ssn==0){
		
					Site.switchView('View_Options',true);
					if (self.parent.document.getElementById('divNoLogin').style.display!='') self.parent.document.getElementById('divNoLogin').style.display='inline';
									
			}else{
				$("#divNoLogin").remove();
				
				document.getElementById('FrontBarSite').style.display='none';
				Site.switchView('View_Options',true);
				var mylang = self.parent.Site.CurrentLanguage;
				var mywords = "tit_tabtema,tit_usuario_cuenta,tit_usuario_pass,tit_usuario_perfil";//tit_tabcuenta
				$.post("/func/getwords.php",{lang:mylang, words:mywords } ,function(datawords) { 
				
					var arraywords = datawords.split("{sep}"); 						
	
						//$('#FrontBarPerfilUser', self.parent.document).load("/webparts/usertabsjs.php", function() {
						$.get("/webparts/usertabsjs.php" ,function(datatabs) {					
								$('#FrontBarPerfilUser', self.parent.document).html(datatabs);							
								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];  				
	
								$.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();
										
									});
									
										
								});
						});										
				});
			}
		});
}

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();
}
