// JavaScript Document
$(document).ready( function() {
	inicializarEventos();

	$("#jq_form").dialog({
		width: 550,
		height: 700,
		autoOpen: false,
		draggable: false,
    	modal: true,
    	position: ['center', '30'],
    	overlay: {
    		opacity: 0.2,
        	background: "black"
    	}
	});

	$('#alarm').dialog({
		width: 435,
		height: 220,
    	modal: true,
		draggable: false,
		resizable: false,
		autoOpen: false,
		position: ['center', '30'],
    	overlay: {
    		opacity: 0.2,
        	background: "black"
    	}
	});
	$('#alarm_form').ajaxForm( {
		beforeSubmit:  verifyAjaxRegFields,
		success: function() {
			$("#alarm").dialog("close");
			alert("Alarma seteada.");
		}
	});

	$("#doAlert").click(function() {
		$("#alarm").dialog("open");
		$("#email").focus();
	});

	$('#recommend').dialog({
		width: 435,
		height: 260,
    	modal: true,
		draggable: false,
		resizable: false,
		autoOpen: false,
		position: ['center', '30'],
    	overlay: {
    		opacity: 0.2,
        	background: "black"
    	}
	});
	$('#recommend_form').ajaxForm( {
		beforeSubmit:  verifyAjaxRecommendFields,
		success: function() {
			$("#recommend").dialog("close");
			alert("Mensaje enviado.");
		}
	});

	$("#doRecommend").click(function() {
		$("#recommend").dialog("open");
		$("#email").focus();
	});
});

function openDialog(src)
{
	$("#jq_if_form").attr("innerHTML", '<iframe scrolling="no" frameborder="0" id="iframe1" class="lightbox" style="border: 1px none rgb(255, 255, 255); margin: -2px;width: 500px; height: 650px;" src="' + src + '&x=' + Math.round(Math.random()*(10000-1000)) + '" border="0" framespacing="none" cellspacing="0" marginwidth="0" marginheight="0" noresize="noresize"/></iframe>');
	$("#jq_form").dialog("open");
}


function inicializarEventos(){
	cambiarIdioma();
	muestraLogin();
	tabs();
	mapa();
	chicaForm();
	expandeMasInfo();
	filtroDesplegable();
	desplegarPath();
	globo();
	datosAmpliados();
	puntuarCurso();
	formulariosHOME();
	ajustaCompara();
	dptoMapa();
	fnc_favorito();
	botonesArreglo();
	carga_favs();
	globoCien();
	titulo_filtro_directorio();
	titulo_filtros();
	escondeInfo();
	visibilidadPestanyasResultados();
	verMasSedes();
	recomendarAmigo();
	doCompararClick();
	doList();
}

function addMarker(markers)
{
	//height:500px;
	//margin:0 auto;
	//position:relative;
	//width:774px;

	marcadorVillas = new GIcon();
    marcadorVillas.image = "../img/marcador.png";
    marcadorVillas.iconSize = new GSize(24, 35);
    marcadorVillas.shadow = "../img/shadow50.png";
    marcadorVillas.shadowSize = new GSize(37, 34);
    marcadorVillas.iconAnchor = new GPoint(5, 34);
    marcadorVillas.infoWindowAnchor = new GPoint(17, 0);

	var bounds = new GLatLngBounds();
	jQuery(document).ready(function()
	{
		$('#gmap').jmap('init', function(map) {
			for (x in markers) {
				var marcador = '<table width="350" border="0" cellspacing="0" cellpadding="0"><tr><td width="100" valign="top"><img src="'+markers[x][3]+'"></td><td width="250" valign="top"><h4 style="margin:0; padding:0; margin-bottom:10px; line-height:27px; font-size:19px">'+markers[x][2]+'</h4></td></tr><tr><td colspan="2"><a href="'+markers[x][6]+'" target="_blank">'+markers[x][5]+'</a></td></tr><tr><td colspan="2"><a href="'+markers[x][4]+'" target="_blank">Consulta nuestros cursos disponibles</a><br><a href="#streetview" onclick="street(\''+markers[x][0]+','+markers[x][1]+'\');">Street View</a></td></tr></table>';

				//document.write(marcador + "<br />");
				jQuery('#gmap').jmap('AddMarker', {
					'pointLatLng': [markers[x][0],markers[x][1]],
					'pointHTML': marcador,
					'pointIcon': marcadorVillas
				});

				var point = new GLatLng(markers[x][0],markers[x][1]);
	      		bounds.extend(point);
			}
			map.setCenter(bounds.getCenter());
			map.setZoom(map.getBoundsZoomLevel(bounds));
			map.setMapType(G_PHYSICAL_MAP)
		});

	});
}


function street(posicion){
	var cordanadas = posicion.split(",");
	$('#streetview').show();
	$('.streetview_donde').jmap('CreateStreetviewPanorama', {
		'latlng':[parseFloat(cordanadas[0]),parseFloat(cordanadas[1])]
	});
	return false;
}

function cambiarIdioma(){
	/* Chequeamos si existe el elemento*/
	if ($("#cambiarIdioma").length > 0){


		var x = $("#cambiarIdioma");
		x.click(
				function(){
							$("#despliega_idiomas").show();
						  }
				);


		var x = $("#despliega_idiomas");
		x.bind("mouseleave", function(e){
								 $("#despliega_idiomas").fadeOut("slow");
								 }
				);

	}
}
function muestraLogin(){
	/* Chequeamos si existe el elemento*/
	if ($("#muestraLogin").length > 0){


		var x = $("#muestraLogin");
		x.click(
				function(){
							$("#despliega_login").show();
						  }
				);


		var x = $("#despliega_login");
		x.bind("mouseleave", function(e){
								 $("#despliega_login").fadeOut("slow");
								 }
				);

	}
}
function tabs(){
	/* Chequeamos si existe el elemento */
	if ($(".pestanyaSelector").length > 0){
		/* */
		$(".pestanyaSelector").click(function () {
			// apago todos los tabs
			$(".pestanyaSelector_izq").removeClass("activa_izq").addClass("inactiva_izq");
			$(".pestanyaSelector_cen").removeClass("activa_cen").addClass("inactiva_cen");
			$(".pestanyaSelector_der").removeClass("activa_der").addClass("inactiva_der");
			// activo el tab del click
			$(this).children('.pestanyaSelector_izq').removeClass("inactiva_izq").addClass("activa_izq");
			$(this).children('.pestanyaSelector_cen').removeClass("inactiva_cen").addClass("activa_cen");
			$(this).children('.pestanyaSelector_der').removeClass("inactiva_der").addClass("activa_der");
			for(i=1; i<=$(".pestanyaSelector").length; i++){
				$("#pestanya_"+i+"_contenido").hide();
			}
			$("#"+$(this).attr("id")+"_contenido").show();
				if ($("#formulario").length > 0){
					if($(this).children('.pestanyaSelector_cen').text() == "Opiniones"){
						$("#formulario").hide();
					} else {
						$("#formulario").show();
					}
				}
			if($(this).attr('title') == "mapa"){
					addMarker(markers);
				}
		});
		/* */
	}
}
function mapa(){
	if ($("#mapa_de_seleccion").length > 0){
		/* Creamos el div que mostrarï¿½ los datos del mapa */
		var div1=document.createElement('div');
		div1.setAttribute('id','datos_mapa');
		var div2=document.createElement('div');
		div2.className='datos_mapa_flecha';
		div1.appendChild(div2);
		var img1=document.createElement('img');
		img1.setAttribute('src','img/datos_mapa_flecha.gif');
		div2.appendChild(img1);
		var div3=document.createElement('div');
		div3.setAttribute('id','datos_mapa_texto');
		div3.className='datos_mapa_texto';
		div1.appendChild(div3);
		document.body.appendChild(div1);
		/* llamamos al js del mapa */
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = 'js/mapa.min.js';
		document.getElementsByTagName('head')[0].appendChild(script);
	}
}
function chicaForm(){
	if ($("#que_alto").length > 0){
		/* */
		var esto = document.getElementById('que_alto').offsetHeight;
		document.getElementById('el_flash').setAttribute('height',esto);
		/* */
	}
}
function expandeMasInfo(){
	if ($(".mas_info").length > 0){
				/* */
		$(".mas_info").unbind("click");
		$(".mas_info").click(function () {
			/* Chequeamos si esta activo o no y segun el estado aplicamos el efecto */
			if($(this).text() == "Cerrar"){
				$(this).html("Detalles");
				$(this).parent().parent().parent().parent().parent().next(".expande_mas_info").slideUp("slow");
			} else {
				$(this).html("Cerrar");
				$(this).parent().parent().parent().parent().parent().next(".expande_mas_info").slideDown("slow");
			}

		});
		/* */
	}
}
function filtroDesplegable(){
	if ($(".filtro_desplegable").length > 0){
				/* */
				$(".filtro_desplegable").click(function () {
											   		if($(this).next().css("display") == "none"){
														$(this).next().slideDown("slow");
														$(this).children("b").attr("class","flecha_desplegada");
													} else {
														$(this).next().slideUp("slow");
														$(this).children("b").attr("class","flecha_no_desplegada");
													}
											  	});
		/* */
	}
}
function desplegarPath(){
	if ($("#despliega_path").length > 0){
				/* */
				$("#despliega_path").click(function () {
											   		var izquierda = $(this).offset().left;
													var top = $(this).offset().top;
													$("#desplegado_fin").css("top",top+18);
													$("#desplegado_fin").css("left",izquierda);
													$("#desplegado_fin").show();
													var x = $("#desplegado_fin");
													x.bind("mouseleave", function(e){
																			 $("#desplegado_fin").fadeOut("slow");
																			 }
															);

											  	});
		/* */
	}
}
function globo(){
	if ($("#flotador").length > 0){
		/* */
			$(window).scroll(function()
			{
			  if($(window).scrollTop() > $("#pestanya_2_contenido").offset().top){
				if($(window).scrollTop() > ($("#pestanya_2_contenido .info_extendida_c1").height()+$("#pestanya_2_contenido").offset().top)-($("#flotador").height()-30)){

					$('#flotador').animate({top:($("#pestanya_2_contenido .info_extendida_c1").height()-$("#flotador").height())+30+"px" },{queue: false, duration: 350});
				} else {
					$('#flotador').animate({top:($(window).scrollTop()-$("#pestanya_2_contenido").offset().top)+"px" },{queue: false, duration: 350});
				}
			  } else {
				$('#flotador').animate({top:"0" },{queue: false, duration: 350});
			  }
			});
		/* */
	}
}
function datosAmpliados(){
	if ($(".mas_datos").length > 0){
		/* */
		$(".mas_datos").click(function () {
			// apago todos los tabs
			$(".pestanyaSelector_izq").removeClass("activa_izq").addClass("inactiva_izq");
			$(".pestanyaSelector_cen").removeClass("activa_cen").addClass("inactiva_cen");
			$(".pestanyaSelector_der").removeClass("activa_der").addClass("inactiva_der");
			// activo el tab del click
			$("#pestanya_2").children('.pestanyaSelector_izq').removeClass("inactiva_izq").addClass("activa_izq");
			$("#pestanya_2").children('.pestanyaSelector_cen').removeClass("inactiva_cen").addClass("activa_cen");
			$("#pestanya_2").children('.pestanyaSelector_der').removeClass("inactiva_der").addClass("activa_der");

			for(i=1; i<=$(".pestanyaSelector").length; i++){
				$("#pestanya_"+i+"_contenido").hide();
			}
			$("#pestanya_2_contenido").show();

		});
		/* */
	}
}
function puntuarCurso(){
	if ($(".slider").length > 0){
	/* */
	var slider = $('.slider').slider({
		steps: 20,
		handle: $('.knob'),
		animate:'true',
		min:0,
		max:20,
		value:15,
		change: function(e,ui){
				//Do something with ui.value
				$(this).css({backgroundPosition: '0 -'+(ui.value*19)+'px'});
				$(this).children(".puntos_slider").text(ui.value/2);
			},
		slide: function(e,ui){
				//Do something with ui.value
				$(this).css({backgroundPosition: '0 -'+(ui.value*19)+'px'});
				$(this).children(".puntos_slider").text(ui.value/2);
			}

	});
	/* */
	}

}
function formulariosHOME(){
	if ($(".buscador_doble").length > 0){
	//
		$(".titulo_gadget").click(function () {
									//
									var formulario_id = $(this).parents('form:first').attr("id")
									$("#"+formulario_id+" .contenido_gadget").hide();
									//$(".contenido_gadget").hide();
									$(".buscadores_flecha_mini").attr("src","img/flechas_negra.gif");
									$(this).next().show();
									$(this).children(".buscadores_flecha_mini").attr("src","img/flechas_negra2.gif");
									if($(this).children("div:first").attr("class") == "simple"){
										$(this).parents('form:first').children("input[name = tipo_buscador]").attr("value","com");
									} else {
										$(this).parents('form:first').children("input[name = tipo_buscador]").attr("value","adv");
									}
									//
										});
	//
	}
}


function ajustaCompara(){
	/* Chequeamos si existe el elemento*/
	if ($("#ajusteVisualItem").length > 0){

		var aDonde = $("#pestanyas_resultados_item").offset().top-$("#item").offset().top;
		$("#ajusteVisualItem").css("height",aDonde);

	}
}

function dptoMapa(){
	/* Chequeamos si existe el elemento*/
	if ($("#mapa_despliega").length > 0){
		$("#mapa").click(function(){

		if($("#gmapa").css("display") == "none"){
			$("#mapa_despliega").attr("src","img/flechaBlancaEx.gif");
		} else {
			$("#mapa_despliega").attr("src","img/flechaBlanca.gif");
		}
		$("#gmapa").toggle("slow");
	  });

	}
}
function fnc_favorito(){
	if ($(".fnc_favorito").length > 0){
		$(".fnc_favorito").unbind("click");
		$(".fnc_favorito").click(favoritosDos);

	}
}
function favoritosDos(){
									str_curso = $(this).attr("id");
									id_curso = str_curso.substring(1);
									id_sesion = $(this).children('span:first').children('span:first').attr("class");
									accion = $(this).children('span:first').attr("class");
									//alert(id_curso+" "+accion+" "+id_sesion);

									var path = getNivelPorPagina();

									if(accion == "anyadir"){
										var max_favs = 30;
										var cant = parseInt($("#cantfavs").text());
										var max = parseInt(max_favs);
										if(cant < max){
											$(this).children('span:first').attr("class","eliminar");
											$(this).children('.img_fav').removeClass("img_add_fav").addClass("img_del_fav");
											$(this).children('font').html("Eliminar favorito");
											$("#favoritos2").load(path+"favoritos.php?id_item="+id_curso+"&opt=add&sid="+id_sesion+"", function() {
												fnc_favorito();
												expandeMasInfo();
												botonesArreglo();
												doCompararClick();
												//$("#pestanya_3_contenido").load("../favoritos-matriz.php?sid="+id_sesion+"&x="+Math.round(Math.random()*(10000-1000)));
											});
											$("#cantfavs").text(cant+1);
										} else {
											alert("Puedes agregar hasta 30 cursos favoritos.");
										}
									}
									if(accion == "eliminar"){
										var cant = parseInt($("#cantfavs").text());
										$(this).children('span:first').attr("class","anyadir");
										$(this).children('.img_fav').removeClass("img_del_fav").addClass("img_add_fav");
										$(this).children('font').html("A&ntilde;adir a favoritos");
										$("#favoritos2").load(path+"favoritos.php?id_item="+id_curso+"&opt=del&sid="+id_sesion+"", function() {
											fnc_favorito();
											expandeMasInfo();
											botonesArreglo();
											doCompararClick();
											//$("#pestanya_3_contenido").load("../favoritos-matriz.php?sid="+id_sesion+"&x="+Math.round(Math.random()*(10000-1000)));
										});
										$("#cantfavs").text(cant-1);
										$("#c"+id_curso).children('font').html("A&ntilde;adir a favoritos");
										$("#c"+id_curso).children('.img_fav').removeClass("img_del_fav").addClass("img_add_fav");
										$("#c"+id_curso).children('span:first').attr("class","anyadir");
									}
									visibilidadPestanyasResultados();

								  }
function botonesArreglo(){
	if ($(".botones_over").length > 0){
		$(".botones_over").unbind("mouseover");
		//$(".boton_home input[type='submit']").css("border","solid 1px #f00");
		$(".botones_over").mouseover(function(){$(this).removeClass("boton_off").addClass("boton_on");});
		$(".botones_over").mouseout(function(){$(this).removeClass("boton_on").addClass("boton_off");});
	}

}
function carga_favs(){
	var path = getNivelPorPagina();
	if ($(".carga_favs").length > 0){

		var id_sesion = $(".carga_favs").text();
		$("#favoritos2").load(path+"favoritos.php?sid="+id_sesion+"&x="+Math.round(Math.random()*(10000-1000)),function(){botonesArreglo();expandeMasInfo();fnc_favorito();});
		$("#pestanya_3_contenido").load("../favoritos-matriz.php?sid="+id_sesion+"&x="+Math.round(Math.random()*(10000-1000)),function(){botonesArreglo();expandeMasInfo();fnc_favorito();});
		$("#pestanya_2_contenido").show();


	}
}
function globoCien(){
	if ($(".flotador_cien").length > 0){
		flotador = $(".flotador_cien");
		relativo = $(".relativo");
		flotadorTop = $("#"+$("input[name='top_flotador']").attr("value"));
		relativo.css("height",flotadorTop.height());
		$(window).scroll(function()
			{
			if($(window).scrollTop() > flotadorTop.offset().top){
				if($(window).scrollTop() > (flotadorTop.height()+flotadorTop.offset().top)-(flotador.height()-30)){
					flotador.animate({top:(flotadorTop.height()-flotador.height())+30+"px" },{queue: false, duration: 350});
				} else {
					flotador.animate({top:($(window).scrollTop()-flotadorTop.offset().top)+"px" },{queue: false, duration: 350});
				}
			  } else {
				flotador.animate({top:"0" },{queue: false, duration: 350});
			  }
			}
		);

		/* */
		/*
			$(window).scroll(function()
			{
			  flotadorTop = $("input[name='top_flotador']").attr("value");
			  if($(window).scrollTop() > $("."+flotadorTop).offset().top){
				if($(window).scrollTop() > ($("."+flotadorTop).height()+$("."+flotadorTop).offset().top)-($(".flotador_cien").height()-30)){

					$(".flotador_cien").animate({top:($("."+flotadorTop).height()-$(".flotador_cien").height())+30+"px" },{queue: false, duration: 350});
				} else {
					$(".flotador_cien").animate({top:($(window).scrollTop()-$("."+flotadorTop).offset().top)+"px" },{queue: false, duration: 350});
				}
			  } else {
				$('.flotador_cien').animate({top:"0" },{queue: false, duration: 350});
			  }
			});
			*/
		/* */
	}
}
function titulo_filtro_directorio(){
	if ($(".titulo_filtro_directorio").length > 0){
		$(".titulo_filtro_directorio:first").addClass("titulo_filtro_directorio_first");
	}
}
function titulo_filtros(){
	if ($(".cabecera_expandible").length > 0){
		$(".cabecera_expandible:first").addClass("cabecera_expandible_top");
	}
}
function escondeInfo(){
	if ($(".expande_directorio").length > 0){
		$(".expande_directorio").hide();
		$(".dir_detalles").click(function(){
										  if($(this).text() == "Detalles del curso"){
											  $(this).parent().parent().children(".expande_directorio").slideDown("slow");
											  $(this).text("Ocultar detalles");
										  } else {
										  	$(this).parent().parent().children(".expande_directorio").slideUp("slow");
											$(this).text("Detalles del curso");
										  }
										  });

	}
}
/* FUNCION PARA ABRIR LOS TERMINOS Y CONDICIONES, ETC... */
function MM_openBrWindow(theURL,winName,features)
{ 	//v2.0
	window.open(theURL,winName,features);
}

function anyadeFavItem(id_item,accion,id_sesion)
{
	$.ajax({
		type: "POST",
		url: "../favoritos.php",
		data: "id_item="+id_item+"&opt="+accion+"&sid="+id_sesion+"",
		success: function() {
			var cant = parseInt($("#cantfavs").text());
			$("#cantfavs").text((cant*1)+1);
		},
		error: function(objeto, quepaso, otroobj) {
			alert("ERROR");
		}
	});
}

function visibilidadPestanyasResultados()
{
	var pr = document.getElementById('pestanyas_resultados');
	var path = getNivelPorPagina();
	var cant = parseInt($("#cantfavs").text());

	if(cant > 0) {
		$("#favoritos").html("<a style=\"text-decoration: none;\" href=\""+path+"cursos/favoritos\" rel=\"nofollow\" ><img height=\"16\" border=\"0\" width=\"16\" alt=\"favoritos\" src=\""+path+"img/nav/favs.gif\"/>&nbsp;<strong id=\"cantfavs\">"+cant+"</strong>&nbsp;Favoritos</a>")
	}
	else {
		$("#favoritos").html("<img height=\"16\" border=\"0\" width=\"16\" alt=\"favoritos\" src=\""+path+"img/nav/favs.gif\"/>&nbsp;<strong id=\"cantfavs\">0</strong>&nbsp;Favoritos");
	}

	if(pr != null) {
		if( cant > 0) {
			$("#pestanya_2").css("display","block");
		}
		else {
			$("#pestanya_2").css("display","none");

			$(".pestanyaSelector_izq").removeClass("activa_izq").addClass("inactiva_izq");
			$(".pestanyaSelector_cen").removeClass("activa_cen").addClass("inactiva_cen");
			$(".pestanyaSelector_der").removeClass("activa_der").addClass("inactiva_der");
			// activo el tab del click
			$("#pestanya_1").children('.pestanyaSelector_izq').removeClass("inactiva_izq").addClass("activa_izq");
			$("#pestanya_1").children('.pestanyaSelector_cen').removeClass("inactiva_cen").addClass("activa_cen");
			$("#pestanya_1").children('.pestanyaSelector_der').removeClass("inactiva_der").addClass("activa_der");

			for(i=1; i<=$(".pestanyaSelector").length; i++) {
				$("#pestanya_"+i+"_contenido").hide();
			}
			$("#pestanya_1_contenido").show();
		}
	}
}

function verMasSedes()
{
	/* Chequeamos si existe el elemento*/
	if ($(".ver_mas_sedes").length > 0) {
		// AGREGAMOS EL DIV
		var ver_mas_sedes = document.createElement('div');
		ver_mas_sedes.id = 'ver_mas_sedes';
		document.getElementsByTagName('body')[0].appendChild(ver_mas_sedes);
		// ACCIONES
		var x = $(".ver_mas_sedes");
		x.mouseover(function() {
			var top = $(this).offset().top;
			var left = $(this).offset().left;
			var x = $("#ver_mas_sedes");
			x.css("top",top);
			x.css("left",left);
			x.html($(this).children("span").html());
			x.show();
		});
		var x = $("#ver_mas_sedes");
		x.bind("mouseleave", function(e) {
			$("#ver_mas_sedes").fadeOut("slow");
		});
	}
}

function recomendarAmigo()
{
	if ($(".recomendarAmigo").length > 0) {
				/* */
		$(".recomendarAmigo").unbind("click");
		$(".recomendarAmigo").click(function () {
			/* Chequeamos si esta activo o no y segun el estado aplicamos el efecto */
				$(this).children("div").slideDown("slow");
				return false;
		});
	}
}

function getNivelPorPagina()
{
	var nivel1 = document.getElementById('nivel1');
	var nivel2 = document.getElementById('nivel2');
	var path = "";
	if(nivel1 != null) {
		path = "../";
	}
	else if(nivel2 != null) {
		path = "../../";
	}
	return path;
}

function doCompararClick()
{
	if ($(".doComparar").length > 0) {
		$(".doComparar").unbind("click");
		$(".doComparar").click(function() {
			doComparar();
			return false;
		});
	}
	$("input[type='checkbox']").unbind("click");
	$("input[type='checkbox']").click(
	function() {
		$("input[name='"+$(this).attr("name")+"']").attr('checked',$(this).attr('checked'));
	});
	$("input[type='checkbox']:checked").each(
	function() {
		$("input[name='"+$(this).attr("name")+"']").attr('checked',$(this).attr('checked'));
	});
}

function doComparar()
{
	var x = [];
	var path = getNivelPorPagina();

	//[name^='res_item_']
	$("input[type='checkbox']:checked").each(function() {
		x.push($(this).val());
	});

	if (x.length == 0)
		alert("Debes seleccionar como minimo un curso para comparar");
	else if (x.length > 5)
		alert("No puede comparar mas de 5 Cursos");
	else {
		$("#pestanya_3_contenido").load(path+"favoritos-matriz.php?path="+path+"&x="+Math.round(Math.random()*(10000-1000)), { 'choices[]': x });

		$(".pestanyaSelector_izq").removeClass("activa_izq").addClass("inactiva_izq");
		$(".pestanyaSelector_cen").removeClass("activa_cen").addClass("inactiva_cen");
		$(".pestanyaSelector_der").removeClass("activa_der").addClass("inactiva_der");
		// activo el tab del click
		$("#pestanya_3").children('.pestanyaSelector_izq').removeClass("inactiva_izq").addClass("activa_izq");
		$("#pestanya_3").children('.pestanyaSelector_cen').removeClass("inactiva_cen").addClass("activa_cen");
		$("#pestanya_3").children('.pestanyaSelector_der').removeClass("inactiva_der").addClass("activa_der");

		for(i=1; i<=$(".pestanyaSelector").length; i++) {
			$("#pestanya_" + i + "_contenido").hide();
		}
		$("#pestanya_3_contenido").show();
	}
}

function doList()
{
	if($("#checkboxall").length > 0) {
		$("#checkboxall").click(function() {
			if ($('#checkboxall').attr('checked')== true) {
				$("input[type='checkbox']").attr('checked', true);
			}
			else {
				$("input[type='checkbox']").attr('checked', false);
			}
		});
	}
}


function verifyAjaxRecommendFields()
{
	var form = document.recommend_form;

	if (!validateEmail(form.email.value)) {
		alert('Introduce una dirección de email válida.');
		return false;
	}

	if (!validateEmail(form.email_amigo.value)) {
		alert('Introduce una dirección de email amigo válida.');
		return false;
	}
//	if (!validatePasswd(form.passwd.value)) {
//		alert('La contraseï¿½a debe contener un mï¿½nimo de seis caracteres, sin espacios ni tabulaciones.');
//		return false;
//	}
	return true;
}


function verifyAjaxRegFields()
{
	var form = document.alarm_form;

	if (!validateEmail(form.email.value)) {
		alert('Introduce una dirección de email válida.');
		return false;
	}
//	if (!validatePasswd(form.passwd.value)) {
//		alert('La contraseï¿½a debe contener un mï¿½nimo de seis caracteres, sin espacios ni tabulaciones.');
//		return false;
//	}
	return true;
}

function validateEmail(email)
{
    if(email.length <= 0)
    {
      return false;
    }
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.\+]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null)
      {
        var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
        if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
    return false;
}

function validatePasswd(passwd)
{
	var illegalChars = /\W/; // allow letters, numbers, and underscores

	if (passwd.length < 6) {
		return false;
	}
	else
		if (illegalChars.test(passwd)) {
			return false;
		}
	return true;
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function esVaciaBusquedaAvanzada(){
	if(document.getElementById("busqueda_txt_adv").value.length == 0)
	{
		if(document.getElementById("bc_categorias").value == -1)
		{
			if(document.getElementById("bc_metodo").value == -1)
			{
				if(document.getElementById("bc_lugar").value == -1)
				{
					if(document.getElementById("bc_tipo").value == -1)
					{
						alert("Debe seleccionar al menos un filtro o completar el campo de texto");
						return false;
					}
				}
			}
		}
	}
	return true;
}




