conf = function (str){return confirm('Realmente deseas :\n'+str);}

$(document).ready(function(){

/********* INICIO DOCUMENT READY *********/	
	
	/* Filtros */
	$("#numResultados").change( 
	    function() {		    	 
 			$("#frmfiltro").submit();        				
	    	}
	);	
	
	/* Buscar en la web*/
	$("#srcButton").click( 
		    function() {		    	 
	 			$("#searchFrm").submit();        				
		    	}
		);	
	
	$(".faq li").toggle( 
		    function() {$(this).addClass("active")},
		    function() {$(this).removeClass("active");} 
		);

        $(".toogle_mensaje").click(function () {
            $(this).next().toggle("slow");
        });

	
    /* Mostrar div de recordatorio de contraseña */
    $("a.link_forgot").toggle(
    	function(){$("#forgot").fadeIn(1000);},
    	function(){
    		$("#forgot").fadeOut(1000);
    		$("p.ok").hide();
    		$('#email').removeAttr("disabled");
    		$('#b_forgot').removeAttr("disabled");
    		$('#email').val('')}
    	)
	
	/* Recordar contraseña */
	$(function(){
	    var url=$("#located_url").val();
		$("#b_forgot").click(function(){
				$.post(url,{email: $("#email").val()}, function(j){
				// Ejecuta el php, pero no hace nada mas
                                    $("p.ok").html(j);
				})		
				//$('#email').attr("disabled", true);
				//$('#b_forgot').attr("disabled", true);
				$("p.ok").fadeIn(1000);
		})
	})

	/* Dar de alta en el boletín */
	$(function(){
	    var url=$("#urlBoletinAction").val();
		$("#submitBoletin").click(function(){
				$.post(url,{email: $("#emailBoletinAdd").val() , op: 0 }, function(j){
				// Ejecuta el php, pero no hace nada mas
                                    $("#vueltaBoletin").html(j);
				})
				$("#vueltaBoletin").fadeIn(1000);
                                return false;
		})
	})

	/* Dar de baja en el boletín */
	$(function(){
	    var url=$("#urlBoletinAction").val();
		$("#emailBoletinBaja").click(function(){
				$.post(url,{email: $("#emailBoletinAdd").val() , op: 1 }, function(j){
				// Ejecuta el php, pero no hace nada mas
                                    $("#vueltaBoletin").html(j);
				})
				$("#vueltaBoletin").fadeIn(1000);
                                return false;
		})
	})

        var remoteURLCalendar = '/cp-admin/modulos/calendario/getCalendarAJAX.php';
		//Initialize the HTTP cache
		var remoteCache = new Array();

		//For each link in the calendar...
		$('table.calendar a').each(function(i,item){

			//Unique ID for the link
			var linkId = item.id;

			//Unique URL for the link
			var linkUrl = remoteURLCalendar+'?timestamp='+linkId;

			//Attach onclick event handler
			$(this).click(function(){
				var calendarEvents = $('#calendar-events');
				calendarEvents.slideUp('fast',function(){
					if( remoteCache[linkId] != undefined ) {
						calendarEvents.html(remoteCache[linkId]);
						calendarEvents.slideDown('fast');
					} else {
						calendarEvents.load(linkUrl,function(){
							remoteCache[linkId] = calendarEvents.html();
							calendarEvents.slideDown('fast');
						});
					}
				});
				return false;
			});

		});

            $("#slider").easySlider({
                    auto: true,
                    continuous: true,
                    numeric: true,
                    pause: 4000,
                    speed: 1300

            });

            valorInicial = '';
            $(".mailBoletin").focus(function () {
                valorInicial = $(this).val();
                $(this).val("");
            }).blur(function() {
                if ($.trim($(this).val()) == '') {
                    $(this).val(valorInicial);
                }
            });


            $("#tabsDocu").tabs();

            $('#date_i').datepicker({ dateFormat: 'dd-mm-yy' }, $.datepicker.regional['es']);
            $('#date_f').datepicker({ dateFormat: 'dd-mm-yy' }, $.datepicker.regional['es']);


            $("#formAlta").validate();

        $(".toogle_carpeta").click(function () {
            $('.actual').each(function() {
                $(this).toggle("slow");
                $(this).removeClass('actual');
                $(this).addClass('blocked');
            });
            if ($(this).next().is('.blocked')) {
                
            }
            else {
                $(this).next().toggle("slow");
                $(this).next().addClass('actual');
            }
            $('.blocked').removeClass('blocked');
        });


	
	/********* FIN DOCUMENT READY *********/
});  
	
	
	           
// Ocultar email.
function MailLink (usuario, dominio, tld, texto) {
 //codifica los caracteres mas significativos
 var arroba = '@'
 var punto = '.'

 //utiliza variables para ocultar las palabras clave
 var etiqueta = 'ma' + '' + 'il'
 var dospuntos = 'to:'
 var localizador = usuario
 localizador = localizador + arroba + dominio
 localizador = localizador + punto + tld

 //escribe en enlace
 document.write('<a href="' + etiqueta + dospuntos + localizador + '">'+ localizador + '</a>')
}   

/**
 * Comprueba que se han aceptado las condiciones de envío del formulario de contacto
 * Si sí se envía el formulario.
 */
function checkFormContactConditions (){
	var enviar=true;
	if (document.getElementById('aceptar').checked==false){
		   document.getElementById('aceptar_condiciones').style.border="1px solid red";
		   enviar=false;
    }
    if (enviar==true){
    	document.getElementById('form_contact').submit();
	}	
}

/**
 * Popup
 */
function popup (page){
	  window.open(page, "", 'width=435,height=500');
}


/**
 * Comprueba que se han aceptado las condiciones de envío del formulario de contacto
 * Si sí se envía el formulario.
 */
function removeBorder (){
	if (document.getElementById('aceptar').checked==false){
		   document.getElementById('aceptar_condiciones').style.border="1px solid red";
    }
    else {
		   document.getElementById('aceptar_condiciones').style.border="0px solid red";
	}	
}
