// abrir y cerrar opciones de búsqueda con jquery
  $(document).ready(function(){
/* javascript activado */
    $("body").addClass("js_active");

    //$("#busqueda_opciones").addClass("oculto");
    //$("#abrir_opciones").text("[+]");

    /*$("#abrir_opciones").click(function () {
      if ($("#busqueda_opciones").is(":hidden")) {
        $("#busqueda_opciones").slideDown("slow");
        $("#abrir_opciones").text("[ - ]");
      } else {
        $("#busqueda_opciones").slideUp("slow");
        $("#abrir_opciones").text("[+]");
      }
    });*/

// abrir y cerrar opciones de registro / login / RSS
/* activar registro */
    $(" #li_registro").addClass("activo");
/* abrir/cerrar registro */
    $("#activar_registro").click(function (){
        $("#li_login").removeClass("activo");
        $("#li_rss").removeClass("activo");
        $("#li_registro").addClass("activo");
         return false;
    });
/* abrir/cerrar login */
    $("#activar_login").click(function (){
        $("#li_registro").removeClass("activo");
        $("#li_rss").removeClass("activo");
        $("#li_login").addClass("activo");
         return false;
    });
/* abrir/cerrar rss */
    $("#activar_rss").click(function (){
        $("#li_login").removeClass("activo");
        $("#li_registro").removeClass("activo");
        $("#li_rss").addClass("activo");
        return false;
    });
    $(".imprimir_nb").click(function (){
        window.print();
        return false;
    });
});


function abrirOpciones(){
	//$("#abrir_opciones").click(function () {
		if ($("#busqueda_opciones").is(":hidden")){
			$("#busqueda_opciones").slideDown("slow");
			$("#abrir_opciones").text("[ menos opciones de búsqueda ]");
		}else{
			$("#busqueda_opciones").slideUp("slow");
			$("#abrir_opciones").text("[ más opciones de búsqueda ]");
		}
	//});
}


// execute your scripts when DOM is ready. this is a good habit
$(function(){
	$("div.scrollable").scrollable();
});



/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch(){
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order

    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function(){
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

/*** 
    Simple jQuery TABS Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

$(function(){
	$("#nav ul").tabs("#panes > div", {});

	//
	//	Slideshow plugin for the Tabs
	//
	$("div.paraslide_tabs").tabs(".paraslide > div", { 
	 	    
			// start from the beginning after the last tab 

			// enable "cross-fading" effect
	        effect: 'fade', 
	        fadeOutSpeed: "slow",
	        rotate: true,
  	 

	 
	    // use the slideshow plugin. It accepts its own configuration 
	    }).slideshow({autoplay:true, interval: 10000, autopause: true});
	
	//$("div.paraslide_tabs").tabs().play();
});






//
//	Funciones de envio de datos por form
//
function enviaDadesCerca(url){
	//document.getElementById("clicatCerca").value = 1;

	document.forms.cerca.submit();

}


function envia_receta(){

	algunBuid = 0;
	nombre = document.getElementById("nombre").value;
	email = document.getElementById("email").value;
	nombre_amigo = document.getElementById("nombre_amigo").value;
	email_amigo = document.getElementById("email_amigo").value;
	url_plana = document.getElementById("url_plana").value;
	titol_plana = document.getElementById("titol_plana").value;
	var filter=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

	if((email == "")||(email == "-1")||(email_amigo == "")||(email_amigo == "-1")||(nombre == "")||(nombre == "-1")||(nombre_amigo == "")||(nombre_amigo == "-1")){
		algunBuid = 1;
		$("#camp_buid").fadeIn("slow");
	}else{
		$("#camp_buid").fadeOut("slow");
	}

	if(!filter.test(email)){
		algunBuid = 1;
		$("#wrong_mail").fadeIn("slow");
	}else{
		$("#wrong_mail").fadeOut("slow");
	}

	if(!filter.test(email_amigo)){
		algunBuid = 1;
		$("#wrong_mail_amigo").fadeIn("slow");
	}else{
		$("#wrong_mail_amigo").fadeOut("slow");
	}

	if(algunBuid == 0){
	//loading('formulari_contact');
		$.ajax({
			type: "POST",
			url: "frontoffice/secciones/recetas/subscripcio.php",
			data: "ajax=1&nombre="+nombre+"&email="+email+"&nombre_amigo="+nombre_amigo+"&email_amigo="+email_amigo+"&url_plana="+url_plana+"&titol_plana="+titol_plana,

			success: function(msg){
				if(msg == "ok"){
					cerrarModal();
				}else{
					$('#msg_error_mail').fadeIn("slow");
				}
			}
	 	});
	}
}


function envia_registro(){
	$('#error_1').hide();
	$('#error_2').hide();
	$('#error_3').hide();
	nombre = document.getElementById("nombre").value;
	email = document.getElementById("email").value;
	newsletter_reg = document.getElementById("newsletter_reg").value;
	informacion = document.getElementById("informacion").value;
	acepto = document.getElementById("acepto").checked;

	var filter=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

	mailok=filter.test(email);

	if ((acepto) && (mailok) && (nombre != '') && (email != '')){

		$.ajax({
			type: "POST",
			url: "frontoffice/secciones/registro/enviar_registro.php",
			data: "ajax=1&nombre="+nombre+"&email="+email+"&newsletter_reg="+newsletter_reg+"&informacion="+informacion+"&acepto="+acepto,
			success: function(msg){
				//alert(msg);
				if(msg == "ok"){
					$('#info_orig').hide();
					$('#campos_reg').hide();
					
					$('#missatge_Ok').fadeIn("slow");
					$('#mail_conf').fadeIn("slow");
					
				}else{
					$('#error_3').fadeIn("slow");
				}
			}
	 	});
	}else{
		if((nombre == '') || (email == '')|| (!acepto)){
			$('#error_1').fadeIn("slow");
		}
		if((email != '')&&(!mailok)){
			$('#error_2').fadeIn("slow");
		}
		
	}
}

function seleccionaTodos(){

	for(var i=1; i<7; i++ ){
		document.getElementById('check_'+i).checked =document.getElementById('todos_rss').checked;
	}
	opciones = "all";
	document.getElementById('opciones_rss').value = opciones;
}

function seleccionaCheck(chk){
	opciones="";
	if(!document.getElementById('check_'+chk).checked){
		document.getElementById('todos_rss').checked = false;
	}
	contador=0;
	for(var i=1; i<7; i++ ){
		if(document.getElementById('check_'+i).checked == true){
			opciones += document.getElementById('check_'+i).value +",";
			contador++;
		}
	}
	if(contador==6){
		document.getElementById('todos_rss').checked = true;
	}

	document.getElementById('opciones_rss').value = opciones;

}

function enviaRSS(){
	opciones = document.getElementById('opciones_rss').value;
	url_rss = document.getElementById('url_rss').value;
	document.getElementById('form_rss').href = url_rss + opciones;
}
