
function write_email(user){

	var link = user + "@ffzm.com";
	document.write("<a hre" + "f=ma" + "ilto:" + user + "@ffzm.com>" + link + "</a>");

}


function onSelectChangeFamilia(){ 

	firebug("click family..");		
	
	//familia elegida
	var selected = $("#familia option:selected");  
	firebug("selected = "+selected.val());		
	
	if(selected.val() != 0){ 

		//ponerlo a 0	    
		$("#area_select").empty();
		$("#accio_select").empty();

		//montar de nuevo el selecct de areas y reemplazarlo (obtener item a añadir)
		$.get('/areas/get/'+selected.val(), function(data) {
	
			var options = data.split("#");
			var select = document.createElement("select");
			select.setAttribute("id","area");
			select.setAttribute("name","area");
			$("#area_select").append(select);
			$("#area").addOption(0,'Selecciona una opció');
			$("#area").children().first().attr('id', 'no-selected');
			for(i=0;i<(options.length-1);i++){
				var register = options[i].split(",");
				$("#area").addOption(register[0],register[1]);
			}
			$("#area").removeAttr('disabled');
			$("#area").selectOptions("0");
			$('#area').sSelect();	
			$("#area_select .newList li a").bind('click',onSelectChangeArea);
	
			var select = document.createElement("select");
			select.setAttribute("id","accio");
			select.setAttribute("name","accio");
			$("#accio_select").append(select);	
			$("#accio").addOption(0,'Especialitat');
			$("#accio").children().first().attr('id', 'no-selected');
			$('#accio').sSelect();	
	
		}); 
	
	}
	
}

function onSelectChangeArea(){

	firebug("click area..");		

	//area elegida
	var selected = $("#area option:selected");  
	firebug("selected = "+selected.val());		

	if(selected.val() != 0){  

		//ponerlo a 0	    
		$("#accio_select").empty();

		//montar de nuevo el selecct de areas y reemplazarlo (obtener item a añadir)
		$.get('/accio/get/'+selected.val(), function(data) {
	
			var options = data.split("#");
			var select = document.createElement("select");
			select.setAttribute("id","accio");
			select.setAttribute("name","accio");
			$("#accio_select").append(select);
			$("#accio").addOption(0,'Selecciona una opció');
			$("#accio").children().first().attr('id', 'no-selected');
			for(i=0;i<(options.length-1);i++){
				var register = options[i].split(",");
				$("#accio").addOption(register[0],register[1])
			}
			$("#accio").removeAttr('disabled');
			$("#accio").selectOptions("0");
			$('#accio').sSelect();	
	
		}); 
	
	}

}

function firebug(text, type)
{
	if(window.console && window.console.firebug)
	{
		if(typeof type == "undefined") type = 'log';
		eval("console."+type+"(text)");
	}
}




function trim (myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

jQuery.fn.exists = function(){return jQuery(this).length>0;}

$(document).ready(function(){  	
	
	firebug("inicio document ready..");
	
	Shadowbox.init();

	$('#familia').sSelect();
	$('#area').sSelect();
	$('#accio').sSelect();
	$('#tipo').sSelect();
	$('#centro').sSelect();
	$('#startMonth').sSelect();

	//DEPRECATED
	//$("#familia").change(onSelectChangeFamilia);
	//$("#area").change(onSelectChangeArea);
	
	$("#family_select .newList li a").bind('click',onSelectChangeFamilia);
	$("#area_select .newList li a").bind('click',onSelectChangeArea);
		
	if ($('#mycarousel').exists()) {
	
		
		jQuery('#mycarousel').jcarousel({
			scroll: 1
		});
		jQuery('#mycarousel2').jcarousel({
			scroll: 1
		});
		jQuery('#mycarousel3').jcarousel({
			scroll: 1
		});
		jQuery('#mycarousel4').jcarousel({
			scroll: 1
		});
		
	}
	

});


