$(document).ready(function(){	
	
	jQuery.fn.center = function()
	{
		//this.css("position","absolute");
		this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
		this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
		//alert("$(window).height(): "+$(window).height()+" - this.height():"+this.height()+" - $(window).scrollTop(): "+$(window).scrollTop() );
		return this;
	}
	


	//para saber que navegador se esta utilizando
	var NAVEGADOR="";
	var VERSION="";
	jQuery.each(jQuery.browser, function(i, val) {
		if ( i=="version" ) { VERSION=val; }
		if ( val==true ) { NAVEGADOR=i; }		
	});	
	$("body").data("NAVEGADOR",NAVEGADOR);
	
	
	if ( $("#breadCrumb0").width() > 751 ) { var a=330; var b=320; } else {  var a=280; var b=250;  }
	jQuery("#breadCrumb0").jBreadCrumb({
										maxFinalElementLength:a,
										minFinalElementLength:b,
										minimumCompressionElements:1,
										endElementsToLeaveOpen:1,
										beginingElementsToLeaveOpen:1,
										minElementsToCollapse:1,
										timeExpansionAnimation:800,
										timeCompressionAnimation:500,
										timeInitialCollapse:600,
										easing:'easeOutQuad',
										overlayClass:'.chevronOverlay',
										previewWidth:50
									});
	$(".breadCrumb li").hover(
      function () {
        $(this).prev("li").addClass("ant"); 
		
      }, 
      function () {
        $(this).prev("li").removeClass("ant"); 
      }
    );
	
	$("a.greybox").fancybox({'hideOnContentClick': false, frameWidth:800});//PARA PUBLICAR
	
	if ( NAVEGADOR=="msie" && VERSION=="6.0" ) {
		$(".h1_ficha_anuncio").append("<div class='top'></div><em></em><div class='bottom'></div>");
	} else {
		$(".h1_ficha_anuncio").append("<span class='top'></span><em></em><span class='bottom'></span>");
	}
   //if ( $("p.listadoanuncios").text().length>0 ) { $(".h1_ficha_anuncio").attr("title",$("p.listadoanuncios").text()); $("p.listadoanuncios").remove(); }
	
	//Si hay banners superiores los copio a la capa contiene_los_banners
	if ( $("#contiene_los_banners") && $("ul.banner_superior") ) {
		var banner_originales=$("ul.banner_superior");
		//$("#contiene_los_banners").html(  );
		$(banner_originales).clone().appendTo($("#contiene_los_banners"));
		$(banner_originales).remove();
	}
	
	
	$("*").live("click", function(){ 
		
		if ( $(this).attr('class')=='titulo_tiporadio' || $(this).attr('class')=='opcioneselegido' || $(this).parent().parent().parent().attr('class')=='tipocombo' || $(this).attr('class')=='span_tiporadio' ) {
		} else {
			$('ul.tipocombo li ul').css('display','none');
		}
		
		
		if ( $(this).attr('class')=='puntos' || $(this).attr('class')=='puntos puntosonhover' ) {
			
		} else {
			$('li.puntos').html("+");
		}		

		if ( $(this).parent().attr('id')=='boton_notificar' ) {
			$('#boton_notificar').children('div').removeClass("hd");
		} else {
			$('#boton_notificar').children('div').addClass("hd");
		}		

	});
	
	//* ******************** inicio usuario ************************* *//
	
	$(".aviso_user").hide();
	
	$(".user").bind("submit", function(e){
		$(".user *").removeClass("error");	
		if (typeof filters == 'undefined') return;
		$(this).find("input, textarea").each(function(x,el){ 
			if ($(el).attr("className") != 'undefined') {
			$.each(new String($(el).attr("className")).split(" "), function(x, klass){
			
				if ($.isFunction(filters[klass])) {
					if (!filters[klass](el)) {  
						$(el).addClass("error");
						if ( $(el).next(".aviso_user").length > 0 ) {
							$(el).next("p").attr("class", $(el).addClass("error").next("p").attr("class").replace("aviso_user","aviso_user_error") ).show(); 
						}
					} 
				}
			});
			}
		});		
		
		if ($(this).find(".error").size() > 0) {
			$.stop(e || window.event);
			return false;
		}
		
		return true;
		
	});		

	
	$(".user input[type!='submit']").click(function () { 
		if ( $(".aviso_user_error").text().length > 0 ) {//para que no de error
			$(".aviso_user_error").each(function (i) {
				$(this).attr("class", $(".aviso_user_error").attr("class").replace("aviso_user_error","aviso_user") );
			});
			
		}
		$(".aviso_user").hide();
		$(this).next(".aviso_user").show();
	});
	
	$(".user input[type!='submit']").blur(function () {
		
		$(this).next(".aviso_user").hide();
	});

	$(".user a, .ul_enlaces_user li a ").click(function () {

		switch ( $(this).attr("href") ) {
			case "http://"+location.hostname+"/usuario/recordar.html":
				$(".h1_user, .user").hide();
				$("#h1_recordar, #form_recordar").show();
			break;
			
			case "http://"+location.hostname+"/usuario/registrarse.html":
				$(".h1_user, .user").hide();
				$("#h1_alta, #form_alta").show();
			break;			
			
			
			case "http://"+location.hostname+"/usuario/acceder.html":
				$(".h1_user, .user").hide();
				$("#h1_user, #user").show();
			break;						
		}
		
		return false; 
	});
	
	//* ******************** fin usuario ************************* *//
	
	//* ******************** inicio anuncios de usuario ************************* *//
	
	//solo para ie6
	if ( NAVEGADOR=="msie" && VERSION=="6.0" ) {
		$(".opciones").hover( 
		  function () {
			$("#opciones").css("display", "block");
		  }, 
		  function () {
			$("#opciones").css("display", "none");
		  }		
		);
		
		$("#opciones a").hover( 
		  function () {
			$(this).children("span").css("display", "block");
		  }, 
		  function () {
			$(this).children("span").css("display", "none");
		  }		
		);		
	}
	
	var ttee=$(".opciones #opciones").attr("id");
	if ( ttee!=null ) {
		var altura=$(".opciones dl dt:first").position().top+( parseInt(($(".opciones dl dd:first").position().top-$(".opciones dl dt:first").position().top)/2) );
		$(".opciones #opciones").css("top",altura);
	}
	
	
	$("div.opciones dt, div.opciones dd").hover(
			
		  function () {
				
				//$("#searchform input").val( $("#opciones #borrar").data("borrar_ad") );
				
				//if ( $("#opciones #borrar").data("borrar_ad")==null || $("#opciones #borrar").data("borrar_ad")==false ) { 
				if ( $("#opciones_esperando").css("display")=="none" ) {
					//saber si esta sobre dt o dd

					
					var id_ad=$(this).attr("id").split("_");
					
					var id_ad=id_ad[1];
					if ( $(this).children("a.hd").attr("class")==null ) {
						var enlace=$(this).prev("dt").children("a.hd").attr("href");
					} else {
						var enlace=$(this).children("a.hd").attr("href");
					}
					
					
					//añadimos el id de anuncio al los enlaces de opciones
					$("#opciones #contactos").attr("href", "http://"+location.hostname+"/usuario/contactos/z" + id_ad );
					$("#opciones #editar").attr("href", "http://"+location.hostname+"/usuario/editar/" + id_ad );
					$("#opciones #borrar").attr("href", "http://"+location.hostname+"/usuario/borrar/" + id_ad );
					$("#opciones #estadisticas").attr("href", "http://"+location.hostname+"/usuario/estadisticas/" + id_ad );
					$("#opciones #verad").attr("href", enlace );
					
					
					var altura=$("#a_"+id_ad).position().top+( parseInt(($("#b_"+id_ad).position().top-$("#a_"+id_ad).position().top)/2) );
			
					
					if ( (altura) > 0 ) {
						$("#opciones").css("top", altura );
					} else {
						$("#opciones").css("top", altura );
					}
					
				
				}
			
		  }, 
		  function () {
				
		  }
		
	);
	
	$("#opciones #borrar").click(
		function ( ) {
			if ( confirm('¿Seguro que quieres borrar el anuncio?') ) {
				var id_ad=$(this).attr("href").split("/");
				id_ad=id_ad[ (id_ad.length)-1  ];

				if ( id_ad!=null ) {
					if ( parseInt(id_ad) ) {
						
						$("#opciones #borrar").data("borrar_ad",true);
						
						$("#opciones_esperando").css("top",$(".opciones #opciones").css("top")).show();
						$(".opciones #opciones").css("top","-10000px");
						

						borrar_ad( id_ad );
					}
				}
			}
				
			return false;
		}
	);

	
	//* ******************** fin anuncios de usuario ************************* *//	
	
	//* ******************** inicio tienda ************************* *//

	$("#tienda").children("li").click(function () { 	
		if ( $(this).attr("class")=="group" ) {
			$("#tienda .visible").children("ul").hide("slow").parent().removeClass("visible");
			$(this).children("ul").show("slow").parent().addClass("visible");
		}
	});

	//* ******************** fin tienda ************************* *//

	
				if ( $("ul.paginado li").length>0 ) {
					
					var calculo=parseInt( ( $('div.listado_anuncios').width() - $('ul.paginado').width() ) / 2 );
					
					//para ie6
					if ( $("div.paginadoie").attr("class")=="paginadoie" ) { calculo=parseInt(calculo/2); }

					$('ul.paginado').css("margin-left", calculo );
					
				}
				
				
				$("ul.paginado li.puntos").click(function () { 
					
					if ( $(this).html()!="+" ) { $(this).html("+"); } else { //si haces 2 click en los mismos puntos, se cierra
					
						var inverso=false;
						if( $(this).attr("id").indexOf("a")!=-1){
							var idli=$(this).attr("id").split("a");
							inverso=true;
						} else {
							var idli=$(this).attr("id").split("b");
						}
						


						$("ul.paginado li.puntos").html("+");						
						
						
						var anterior=parseInt(idli[1]);
						var posterior=parseInt(idli[2]);
						var nelementos=parseInt(idli[3]);		

						//alert( traducir_n( anterior ));

						/*
						 anterior=parseInt($(this).prev("li").children("a").text());
						 posterior=parseInt($(this).next("li").children("a").text());
						*/
						if ( inverso ) {
							var href_anterior=$(this).prev("li").children("a").attr("href");
							href_anterior_trozos = href_anterior.split("/");
							href_anterior_trozos[href_anterior_trozos.length-1]="";
							href_limpio=href_anterior_trozos.join("/");


							var titulo_anterior=$(this).prev("li").children("a").attr("title");
							titulo_anterior_trozos = titulo_anterior.split(" ");
							titulo_anterior_trozos[titulo_anterior_trozos.length-1]="";
							titulo_limpio=titulo_anterior_trozos.join(" ");
						} else {
							var href_anterior=$(this).prev("li").children("a").attr("href");
							href_anterior_trozos = href_anterior.split("=");
							href_anterior_trozos[href_anterior_trozos.length-1]="";
							href_limpio=href_anterior_trozos.join("=");

							var titulo_anterior=$(this).prev("li").children("a").attr("title");
							titulo_anterior_trozos = titulo_anterior.split(" ");
							titulo_anterior_trozos[titulo_anterior_trozos.length-1]="";
							titulo_limpio=titulo_anterior_trozos.join(" ");						
						}
							
						var texto="";
						var contador=0;
						if ( (posterior-anterior)>36 ) {
							var t=parseInt((posterior-anterior)/20);
							
							if ( t<1 ) { t=1; }
							
							if ( t==1 ) {
								for ( i=(anterior+1); i<=(posterior-1); i++ ) {
									if ( inverso ) {
										texto=texto+"<a href='"+href_limpio+traducir_n(nelementos-i+1)+"' title='"+titulo_limpio+i+"'>"+i+"</a>";
									} else {
										texto=texto+"<a href='"+href_limpio+i+"' title='"+titulo_limpio+i+"'>"+i+"</a>";
									}
								}													
							} else {
								var i=1;
								while ( (anterior+((i+1)*t))<posterior  ) {	
									contador=(anterior+(i*t));
									if ( inverso ) {
										texto=texto+"<a href='"+href_limpio+traducir_n(nelementos-contador+1)+"' title='"+titulo_limpio+contador+"'>"+contador+"</a>";
									} else {
										texto=texto+"<a href='"+href_limpio+contador+"' title='"+titulo_limpio+contador+"'>"+contador+"</a>";
									}
									i++;
								}
							}
						} else {
							for ( i=(anterior+1); i<=(posterior-1); i++ ) {
								if ( inverso ) {
									texto=texto+"<a href='"+href_limpio+traducir_n(nelementos-i+1)+"' title='"+titulo_limpio+i+"'>"+i+"</a>";
								} else {
									texto=texto+"<a href='"+href_limpio+i+"' title='"+titulo_limpio+i+"'>"+i+"</a>";
								}
								contador++;
							}
						}

						texto="<span>"+texto+"</span>";
						
						$(this).append(texto);
						

						
						//para ie6
						if ( $("div.paginadoie").attr("class")=="paginadoie" ) { 
							$(this).children("span").children("a").css("width", $(this).children("span").children("a:last").width() ); 
						} else { 
							$(this).children("span").children("a").css("min-width", $(this).children("span").children("a:last").width() );
						}
						
						
						if ( ( $(this).children("span").children("a").length )<5 ) {
							$(this).children("span").css("width", parseInt( ( $(this).children("span").children("a:last").width() ) * 6 ) );
							$(this).children("span").css("margin-left", -( parseInt( $(this).children("span").children("a").length * 10 ) ) );
						} else if (  $(this).children("span").children("a").length>4 && $(this).children("span").children("a").length<17  ) {
							$(this).children("span").css("width", 80 );
							$(this).children("span").css("margin-left", -( parseInt( $(this).children("span").width() /2 ) ) );					
						} else {
							$(this).children("span").css("width", parseInt( $(this).children("span").children("a").length/4 )*( ($(this).children("span").children("a:last").width())+10 ) );
							$(this).children("span").css("margin-left", -( parseInt( $(this).children("span").width() /2 ) ) );
						}
						
						
						$(this).children("span").css("margin-top", -(($(this).children("span").height())+10) );

					}					
					
				});
				
	/* ESTO PERTENECE SOLO A geo */
	$("div.categoriasmunicipios").each(function (i) {
		
		if ( $(this).children("div.contenido").height() > 26 && $(this).children("div.contenido").height() < 64  ) {
			$(this).children("div.contenido").css("height",64);
		}
	});
	/* ESTO PERTENECE SOLO A geo */	
	

	
	/*inicio ESTO PERTENECE SOLO A anuncio */

	

	/* *************** fancybox *********** */	

	
	var lista_images="";
	var id="";
	$(".lista_images img").each(function (i) {
		id=$(this).attr("src").split("/");
		id=id[ id.length-1 ];
		id=id.split(".");
		id=id[0];		
		lista_images+= "<a class='fancy' id='"+id+"' rel='grupo_images' href='"+$(this).attr("src").replace("d.",".")+"' title='"+$(this).attr("alt")+"'></a>";
	}).parent().parent().parent().append( lista_images );	


	
	$(".blancos").click(function () {
		
		id=$(this).prev("div").children("#foto").attr("src").split("/");
		id=id[ id.length-1 ];
		id=id.split("m.");
		id=id[0];
		$("#"+id+"d").click();		
	});	
	
	$("a.fancy").fancybox({'hideOnContentClick': false});		
	/* *************** fancybox *********** */	
	
	

	$("#form_contacto ~ hr").before("<div id='info' class='hd'></div>");

	



	
	$("div.ficha_anuncio_img span.derfa, div.ficha_anuncio_img span.izqfa").click(function () { 
		//var multiplicador=98;		

		

		
		//para ie6 el margin-left es la mitad
		if ( $("#minis").parent(".minisie6").length > 0 ) {  
			var multiplicador=$("#minis li:first").width() + ( parseInt($("#minis li:first").css("margin-left"))*2 ) + 2;		
		} else {
			var multiplicador=$("#minis li:first").width() + ( parseInt($("#minis li:first").css("margin-left")) ) + 2;
		}
		
		if ( $(this).attr("class")=="izqfa" || $(this).attr("class")=="izqfa izqno" ) { 
			var margen=$("#minis").css("margin-left");
			
			margen=margen.split("px");
			
			var maximo=($("#minis img").length - 2)*(-multiplicador);			
			margen=parseInt(margen)-multiplicador;
			
			if ( margen ) { while ( margen%multiplicador ) { margen--; } $("div.ficha_anuncio_img span.derfa").removeClass("derno");  }
			
			if ( margen > maximo ) {
				$("div.lista_images ul").animate({ marginLeft: margen }, "medium", function () { if ( margen == maximo || (margen-multiplicador)==maximo ) { $("div.ficha_anuncio_img span.izqfa").addClass("izqno"); } } );			
			} 
		} else {

			var margen=$("#minis").css("margin-left");			
			margen=margen.split("px");
			margen=parseInt(margen)+multiplicador;
			$("div.ficha_anuncio_img span.izqfa").removeClass("izqno");
			if ( margen ) { while ( margen%multiplicador ) { margen++; } }

			if ( margen<1 ) {
													
				$("div.lista_images ul").animate({ marginLeft: margen }, "medium", function () { if ( !margen ) { $("div.ficha_anuncio_img span.derfa").addClass("derno"); } } );			
			}
		}
	});	
	
	
	$('#minis img').click(function(e) { loadthumb($(this)); $(".borde_blanco").removeClass("borde_blanco"); $(this).parent().addClass("borde_blanco"); } );
	
	

	/* FIN ESTO PERTENECE SOLO A anuncio */	
	
	/*INICIO ESTO PERTENECE SOLO A activausuario */
	
	$("#form_activa_user").bind("submit", function(e){
		
		$("#form_activa_user #pass").removeClass("error");
		$("#form_activa_user #pass2").removeClass("error");
	
		if ( $("#form_activa_user #pass").val().length<5 || $("#form_activa_user #pass").val()!=$("#form_activa_user #pass2").val() ) { $("#form_activa_user #pass").addClass("error"); $("#form_activa_user #pass2").addClass("error"); }
			
		if ($(this).find(".error").size() > 0) {
			$.stop(e || window.event);
			return false;
		}
		return true;
	});		
	

	/* FIN  ESTO PERTENECE SOLO A activausuario */

	$(".notificar").click(function () {
		
		var ya=$(this).children("div");
		if ( $(ya).html() == null ) {
			$(this).append("<div></div>");
			$(this).children("div").load( 
											"http://"+location.hostname+"/mod/anuncio/tpl/notificar.php",
											{  },
											function(){ 
												var href=$("#id_ad").val();
												
												$("a.botones").each(function(){
													$(this).attr("href", $(this).attr("href")+"_"+href );
												});
												
												
												
												$("a.botones").fancybox({'hideOnContentClick': false, frameWidth:400, frameHeight:300, callbackOnShow: function(){ $('#boton_notificar').children('div').addClass("hd"); }  }); 
											}
			);
		} else {
			$('#boton_notificar').children('div').removeClass("hd");
		}
	});	
	
	$("#contactar").click(function(){
		mostrar_formulario2();
	});
	
	/* inicio esto es solo para contactos usuario */
	$(".contactos dd p").click(
		function () {
			
			if ( $(this).attr("class")!="opciones_contacto" ) {
				if ( $(this).parent().attr("class").indexOf("visto")==-1 ) {
						var visto=0;
						
						if ( $(this).attr("style")==null ) { visto=1; }
										
						var id=$(this).parent().attr("id").split("b_");
						//alert(id[1]);
						$.ajax({
							type: "POST",
							url: "http://"+location.hostname+"/mod/usuario/engine.php",
							data: "action=activar_contacto&id="+id[1]+"&visto="+visto,
							success: function(msg){
								eval(msg);													
							}
						});						
				}
			}
		}
	);
	
	$(".marcar_leido").click (//lo mismo que lo de arriba
		function () {
			$(this).parent("p").prev("p").trigger("click");
		}
	);

	$(".marcar_no_leido").click (
		function () {
			
			if ( $(this).parent("p").prev("p").parent().attr("class").indexOf("visto")!=-1 ) {
				
				var id=$(this).parent("p").prev("p").parent().attr("id").split("b_");
				//alert(id[1]);
				$.ajax({
					type: "POST",
					url: "http://"+location.hostname+"/mod/usuario/engine.php",
					data: "action=desactivar_contacto&id="+id[1],
					success: function(msg){
						eval(msg);													
					}
				});			
			}			
		}
	);	
	
	$("#marcar_desmarcar").change(
		function () {
			var este=$(this);
			var ides="";
			var alerta=0;
			if ( $(este).val()=="1" || $(este).val()=="2" ) {
				$("dt input:checked").each(
					function () {
						
						if ( $(este).val()=="1" && $(this).parent("dt").next("dd").attr("class").indexOf("visto")==-1  ) { ides+=","+$(this).val(); }
						if ( $(este).val()=="2" && $(this).parent("dt").next("dd").attr("class").indexOf("visto")!=-1  ) { ides+=","+$(this).val(); }
						
						if ( $(este).val()=="2" && $(this).parent("dt").next("dd").attr("class").indexOf("visto")==-1  ) { alerta=1; }
						if ( $(este).val()=="1" && $(this).parent("dt").next("dd").attr("class").indexOf("visto")!=-1  ) { alerta=2; }
					}
				);
				
				if ( ides.length > 1 ) {
					$.ajax({
						type: "POST",
						url: "http://"+location.hostname+"/mod/usuario/engine.php",
						data: "action=activar_desactivar&ides="+ides+"&valor="+$(este).val(),
						success: function(msg){
							eval(msg);													
						}
					});
				} else {//puede se que tenga marcados varios y no tenga que hacerles nada
					if ( alerta==1  ) {
						alert("Todos los contactos seleccionados ya estan marcados como NO leidos.");
					} else if ( alerta==2 ) {
						alert("Todos los contactos seleccionados ya estan marcados como leidos.");						
					} else {
						alert("No seleccionaste ningun contacto");
					}
				}

				$(este).children("option:first").attr('selected','selected');
			}
			
			return true;
		}
	);
		
	$("#opciones_marcar").change(
		function () {
			var este=$(this);
			switch ( $(este).val() ) {
				case "1":
					$("dt input").each( function() { $(this).attr("checked",true); } );
				break;
				case "2":
					$("dt input").each( function() { $(this).attr("checked",false); } );
				break;
				case "3":
					$("dt input").each( function() { 
						if ($(this).is(':checked')){
							$(this).attr("checked",false);	
						}else{
							$(this).attr("checked",true);	
						}
					});
				break;				
			}
			$(este).children("option:first").attr('selected','selected');
		}
	);
		
	/* fin    esto es solo para contactos usuario */
	
	$(".listado_anuncios dl dt a").append("<i></i>");	
	
	//** inicio esto es solo para banners **//
    $('ul.banners li a').click( function(ev){
        ev.preventDefault();
        the_id=$(this).parents('li[rel]').attr('rel');
        the_url=$(this).attr('href');
        $.post( 'http://'+document.domain+'/mod/banners/banners_track.php', { action:'click', id_banner:the_id }, function(data) { window.location=the_url; });
    });	
	
	
	$("#anunciantes").click( 
		function () {
			pedir_publicidad( $(this) );
		}
	);
	
	
	//** fin esto es solo para banners **//
	
	
	//** inicio esto solo es para anuncio **//	
	
	if ( window.location.hash.indexOf("#contact")!=-1 ) {
		$("#contactar").trigger("click");
	}
	//** fin esto solo es para anuncio **//
});

	function pedir_publicidad( este ) {
		var title=$(este).children("img").attr("title");
		var caso=$(este).children("samp.anun_caso").attr("id").replace("anun_caso","");
		var quitar=document.URL;
		quitar=quitar.replace("http://","");
		var sitio="&amp;sitio="+quitar;
			//sitio puede contener #
			sitio=sitio.split("#");
			sitio=sitio[0];
		var media=$(este).children("samp.anun_media").attr("id").replace("anun_media","");
		while ( media.indexOf("9") != -1 ) {
			media=media.replace("9","/");
		}

		var url=$(este).children("samp.anun_url").attr("id").replace("anun_url","");
		url=url.replace("9","/");
		while ( url.indexOf("9") != -1 ) {
			url=url.replace("9","/");
		}
		var em=$(este).children("em");
		
		$(este).html( "<a class='iframe' href='"+url+"anunciantes?caso="+caso+sitio+"' title='"+title+"'><img src='"+media+"img/base/banner_directo.png' alt='Tu anuncio' title='Tu publicidad en "+document.domain+"' /><em>"+$(em).html()+"</em></a>" );
		$("#anunciantes a").fancybox({'hideOnContentClick': false, frameWidth:800, frameHeight:460  }); 
		var enlace=$("#anunciantes a");
		$(enlace).trigger("click");
	}

	/* inicio esto es solo para contactos usuario */
	function marcar_desmarcar ( id, valor ) {
		
	}
	/* fin    esto es solo para contactos usuario */

	function mostrar_formulario( ) {
		$('#replace_form, #info').show(); $('#hh2').removeClass('hd');

			$("#form_contacto #replace_form").load(
													"http://"+location.hostname+"/mod/anuncio/tpl/formulario_contacto.html", 
													'',
													function(){ 
														//$(".form_contacto").attr("action",$(".breadCrumb ul li.last a").attr("href"));
														var correcto=false;
														$("#form_contacto #name").parent().parent().addClass("focused");
														$("#form_contacto").bind("submit", function(e){
															$("#form_contacto li").removeClass("error2");
															$("#form_contacto *").removeClass("error");
															if (typeof filters == 'undefined') return;
															$(this).find("input, textarea").each(function(x,el){ 
																if ($(el).attr("className") != 'undefined') {
																$.each(new String($(el).attr("className")).split(" "), function(x, klass){
																
																	if ($.isFunction(filters[klass])) {
																		if (!filters[klass](el)) {  $(el).parent().parent().addClass("error"); } 
																	}
																	
																	if ( klass=="telefono" ) {  if ( $(el).val() !="" ) { var telefono=pasa_a_integer ( $(el).val() ); if ( telefono > 0 ) { $(el).val( telefono ); } } } //el telefono, si tiene algo lo pasamos a numerico
								
																});
																}
															});
															
															
															if ( ( $("#telefono").parent().parent().attr("className").indexOf("error")==-1 && $("#email").parent().parent().attr("className").indexOf("error")!=-1 ) || ( $("#telefono").parent().parent().attr("className").indexOf("error")!=-1 && $("#email").parent().parent().attr("className").indexOf("error")==-1 ) ) { $("#telefono").parent().parent().removeClass("error"); $("#email").parent().parent().removeClass("error"); }
															
															if ($(this).find(".error").size() > 0) {
																$.stop(e || window.event);
																return false;
															}
															return true;
														});											
														


														$("#form_contacto input[type='text'], #form_contacto label, #form_contacto textarea").bind("focus", function(e) { 
															$("#form_contacto li").removeClass("focused").removeClass("error2"); 
															$(this).parent().parent().addClass("focused"); 
															$(".error").each(function (i) { $(this).addClass("error2");  });	
														});				
														
														$("a.greybox").fancybox({'hideOnContentClick': false, frameWidth:800});
																
															//aqui una acción axas, que me devuelve el telefono del anunciante si lo hay
															//<span class="ver"> Ver teléfono del anunciante </span>

														$("#ver").click(function () {
															if ( $("#ver").attr("class")!="ver viendo" ){
																var telefono;
																$.ajax({
																	type: "POST",
																	url: "http://"+location.hostname+"/mod/anuncio/ajax.php",
																	data: "id_ad="+$("#form_contacto #id_ad").val(),
																	success: function(msg){
																		telefono=msg;
																		
																		

																		$('#ver').html( telefono ).addClass("viendo");
																																	
																	}
																});
															}
														});
																
														
													}											

													
			);

			//$("#form_contacto #replace_form").load("http://"+location.hostname+"/mod/anuncio/tpl/formulario_contacto.html");
			$("#info").load( "http://"+location.hostname+"/mod/anuncio/tpl/informacion.html","", function(){ $("a.greybox2").fancybox({'hideOnContentClick': false, frameWidth:800}); });
		
		
	}

	function mostrar_formulario2( ) {//esto es solo para el formuario de contacto
		$('#replace_form, #info').show(); $('#hh2').removeClass('hd');

			$("#form_contacto #replace_form").load(
													"http://"+location.hostname+"/mod/anuncio/tpl/formulario_contacto.php", 
													'',
													function(){ 
														//$(".form_contacto").attr("action",$(".breadCrumb ul li.last a").attr("href"));
														var correcto=false;
														$("#form_contacto #name").parent().parent().addClass("focused");
														$("#form_contacto").bind("submit", function(e){
															$("#form_contacto li").removeClass("error2");
															$("#form_contacto *").removeClass("error");
															if (typeof filters == 'undefined') return;
															$(this).find("input, textarea").each(function(x,el){ 
																if ($(el).attr("className") != 'undefined') {
																$.each(new String($(el).attr("className")).split(" "), function(x, klass){
																
																	if ($.isFunction(filters[klass])) {
																			if (!filters[klass](el)) {  $(el).parent().parent().addClass("error"); } 
																	}
								
																});
																}
															});
															
															if ( $("#email").val().length > 0 ) {
																$("#telefono").parent().parent().removeClass("error");
															} else {
																if ( $("#telefono").parent().parent().attr("className").indexOf("error")!=-1 && $("#otracosa").parent().parent().attr("className").indexOf("error")==-1 ) { $("#telefono").parent().parent().removeClass("error"); }
																if ( $("#telefono").parent().parent().attr("className").indexOf("error")==-1 && $("#otracosa").parent().parent().attr("className").indexOf("error")!=-1 ) { $("#otracosa").parent().parent().removeClass("error"); }
															}
															
															$("#email").parent().parent().removeClass("error");
															
															if ($(this).find(".error").size() > 0) {
																$.stop(e || window.event);																
															} else {
																correcto=true;
															}
															return correcto;
														});											
														


														$("#form_contacto input[type='text'], #form_contacto label, #form_contacto textarea").bind("focus", function(e) { 
															$("#form_contacto li").removeClass("focused").removeClass("error2"); 
															$(this).parent().parent().addClass("focused"); 
															$(".error").each(function (i) { $(this).addClass("error2");  });	
														});				
														
														$("a.greybox").fancybox({'hideOnContentClick': false, frameWidth:800});
																
															//aqui una acción axas, que me devuelve el telefono del anunciante si lo hay
															//<span class="ver"> Ver teléfono del anunciante </span>

														$("#ver").click(function () {
															if ( $("#ver").attr("class")!="ver viendo" ){
																var telefono;
																$.ajax({
																	type: "POST",
																	url: "http://"+location.hostname+"/mod/anuncio/ajax.php",
																	data: "id_ad="+$("#form_contacto #id_ad").val(),
																	success: function(msg){
																		telefono=msg;
																		
																		

																		$('#ver').html( telefono ).addClass("viendo");
																																	
																	}
																});
															}
														});
																
														
													}											

													
			);

			//$("#form_contacto #replace_form").load("http://"+location.hostname+"/mod/anuncio/tpl/formulario_contacto.html");
			$("#info").load( "http://"+location.hostname+"/mod/anuncio/tpl/informacion.php","", function(){ $("a.greybox2").fancybox({'hideOnContentClick': false, frameWidth:800}); });
		
		
	}	
	
function borrar_ad( id_ad )	{
	
	$.ajax({
		type: "POST",
		async: false,
		url: "http://"+location.hostname+"/mod/usuario/engine.php",
		data: "action=borrar_ad&id_ad="+id_ad,
		success: function(msg){
			if ( $("#a_"+id_ad).attr("id")!=null ) {
				var dt=$("#a_"+id_ad).next("dd").next("dt");
			}

			if ( dt==false || dt==null ) {
				var dt=$("#a_"+id_ad).prev("dd").prev("dt");
			}
			
			
			
			eval(msg);
			
			
			if ( dt!=false && dt!=null ) {
			
				dt.trigger("mouseenter");
			}
			
			if ( $("dt").length=="1" ) {
				document.location.href="/usuario/tusanuncios.html";
			}
			
		}
	});
}
	
function traducir_n( string ) {
	string=string+"";	
	var resultado="";
	var codificado=new Array("a","b","c","d","e","f","g","h","i","j");
	for ( i=0; i<string.length; i++ ) {
		
		resultado=resultado+ codificado[ parseInt(string.charAt(i)) ];
	}
	
	return resultado;
}

function aleatorio(rango_superior, rango_inferior) {
	return Math.floor(Math.random()*(rango_superior-(rango_inferior-1))) + rango_inferior;
}

function muestralistaradio(este){

	
	$('ul.tipocombo li ul').each(function (i) {
		if ( $(this).parent().text()!=$(este).parent().text() ) {  $(this).css('display','none'); }
	});
	
	$(este).css("height","17px");
	$(este).children("ul").toggle();
	
	
	if ( $(este).children('ul').css('display')=='block' ) {  
		if ( $(este).children('ul').children('li').children('span.opcioneselegido').text() || $(este).children('ul').children('li').children('a.opcioneselegido').text() ) { 
		
			var queelemento=0;
			$( $(este).children('ul').children('li') ).each( function(i) { 
				
				if ( $(this).children('span').text() || $(this).children('a.opcioneselegido').text() ) { queelemento=i;}
			});
		
			$(este).children('ul').animate({ scrollTop: (queelemento*22) }, "slow");
		} else {
			var queelemento=0;
			$( $(este).children('ul').children('li') ).each( function(i) { 
				if ( $(this).children('a').attr('class')=='este' ) { queelemento=i;}
				
			});
		
			$(este).children('ul').animate({ scrollTop: (queelemento*22) }, "slow");		
		}
	}
}

jQuery.each(jQuery.browser, function(i, val) {
	var browservar=false;
	if(i=="safari" && val) {
		browservar="chrome";
	 }
	 else if (i=="opera" && val) {
		browservar="opera";
	 }
	if (browservar) { document.write('<link rel="StyleSheet" href="http://media.' + location.host + '/css/' + browservar + 'css.css" media="screen" type="text/css" />');	 }
});	

	/* ESTO PERTENECE SOLO A anuncio */
function loadthumb(wich){
	$(".titulo_image").html( wich.attr("alt") );
	$("#foto").attr("alt", wich.attr("alt") ).attr("title", wich.attr("alt") );
	$("#foto").parent("a").attr("title", wich.attr("alt") );
	$('#minis img').show();
	
	
	$(wich).hide();
	$("#foto").fadeOut("fast", function(e) {
		var img = new Image();
		$(img).load(function(){
			$("#foto").attr("src", wich.attr("src").replace("d.jpg","m.jpg"));
			$("#foto").parent("a").attr("href", wich.attr("src").replace("m.jpg",".jpg"));
			$("#foto").fadeIn("slow");
		}).attr("src", wich.attr("src").replace("d.jpg","m.jpg"));
		return false;
	});
}

	//Pasa a integer
	function pasa_a_integer ( i ) { 
		if ( parseInt(i)==0 ) {
			var result = 0;
		} else {
			var cadena=new Array();
			var result = 0;
			for ( e=0; e<i.length; e++ ) {
				
				if ( parseInt( i.charAt(e) )!=NaN && parseInt( i.charAt(e) )>-1 ) {  cadena.push( i.charAt(e) ); }
			}
			
			if ( parseInt(cadena)==0 ) {
				result = 0;
			} else {
				if ( cadena.length > 0 ) {
					result=cadena.join("");
					while(result.substr(0,1) == 0){//elimino los 0 por la izquierda, si no parseInt calcula mal 
						result = result.substr(1,result.length-1); 
					}		
					
					if ( result.length > 0 ) {
						result = parseInt( result );  
					}
				}
			}
		}
		return result;
	}
	
	//Filtros
	var filters = {
		obligatorio: function(el) {return ($(el).val() != '' && $(el).val() != -1 && $(el).val().replace(/^\s*|\s*$/g,"").length>4  );},
		forzoso: function(el) {return ($(el).val() != '' && $(el).val() != -1 && $(el).val().replace(/^\s*|\s*$/g,"").length>4  );},
		requerido: function(el) {return ($(el).val() != '' && $(el).val() != -1 && $(el).val().replace(/^\s*|\s*$/g,"").length>4  );},
		email: function(el) {return  /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test($(el).val());},
		//telefono: function(el){return /^[0-9]*$/.test($(el).val());}};
		telefono: function(el){ tel_num=pasa_a_integer ( $(el).val() ); return ( tel_num >= 100000000  ); }};//este no tiene en cuenta la marcacion internacional
	// Extensiones
	$.extend({
		stop: function(e){
			if (e.preventDefault) e.preventDefault();
			if (e.stopPropagation) e.stopPropagation();
		}
	});


	/* ESTO PERTENECE SOLO A anuncio */
