/**
 * @author omada
 */
document.write("<link rel='stylesheet' media='screen' href='/styles/javascript.css'/>");
document.write("<link rel='stylesheet' media='screen' href='/styles/thickbox.css'/>");

IE6 = (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent));

function fixIE6() {
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch (e) {
	}
}

// Hace visibles los PNG despues del filtro de transparencia IE6
if (IE6) {
	fixIE6();

	document.styleSheets[0].addRule('.png', 'visibility: hidden');
	document.styleSheets[0].addRule('.png',	'behavior: url(/scripts/iepngfix.htc)');

	$( function() {
		setTimeout( function() {
			$('.png').each( function() {
				$(this).css('visibility', 'visible');
			});
		}, 30);
	});
}

function showanswer(question, answer)
{
	var correcta = document.getElementById(question + "_correcta").value;
	
	if(correcta == answer)
	{
		document.getElementById("div_correct_"  +question).style.display = "block";
		document.getElementById("div_incorrect_"+question).style.display = "none";
	}
	else
	{
		document.getElementById("div_correct_"  +question).style.display = "none";
		document.getElementById("div_incorrect_"+question).style.display = "block";
	}
}

function showfieldset(num,old){
	document.getElementById("fieldset"+num).style.display="block";
	if(old!=0){
		document.getElementById("fieldset"+old).style.display="none";
		document.getElementById("startlink").style.display="none";
	}
	anteriorfieldset=num;
}

anteriorfieldset=0;
function togglefieldset(num){
	estil=document.getElementById("fieldset"+num).style.display;
	//alert(estil);
	if(estil=='' || estil=="none"){
		document.getElementById("fieldset"+num).style.display="block";
		if(anteriorfieldset!=0) document.getElementById("fieldset"+anteriorfieldset).style.display="none";
		anteriorfieldset=num;
	}
	else{
		document.getElementById("fieldset"+num).style.display="none";
	}
}

/*
 * Define el area seleccionable de un bloque con enlace
 */
$( function() {
	function exclude(event) {
		var element = $(event.target);

		if (element.is('.clicable-exclude') || element.is('.clickable-exclude')) {
			return true;
		}
		if (event.target.tagName == 'A' || event.target.tagName == 'INPUT') {
			return true;
		}
	}

	$(".clicable, .clickable").click( function(event) {
		if (exclude(event)) {
			return true;
		}

		$(this).find("a").each( function() {
			var content = $(this);
			var url = content.attr("href");

			if (content.is('.external')) {
				window.open(url);
			} else {
				document.location = url;
			}

			return false;
		});
	});

	$(".clicable, .clickable").mouseover( function(event) {
		if (exclude(event)) {
			return true;
		}

		if ($(this).find("a").size() > 0) {
			$(this).css("cursor", "pointer");
		}
	});

	$(".clicable, .clickable").mouseout( function(event) {
		if (exclude(event)) {
			return true;
		}

		if ($(this).find("a").size() > 0) {
			$(this).css("cursor", "auto");
		}
	});
});

$( function() {
	$('.tracker').click( function() {
		pageTracker._trackPageview($(this).attr('href'));
	});

	$('.tracker-link').click( function() {
		pageTracker._trackPageview("/external-link/" + $(this).attr('href'));
	});

	$('.tracker-print').click( function() {
		pageTracker._trackPageview("/print/" + requestURI);
		window.print();
	});

	$('.tracker-sendfriend').click( function() {
		pageTracker._trackPageview("/sendfriend/" + requestURI);
	});

	$('.tracker-back').click( function() {
		pageTracker._trackPageview("/back/" + requestURI);
	});
	$('.tracker-doc').click( function() {
		pageTracker._trackPageview("/recursos/" + requestURI);
	});
	return true;
});


/*
 * Simular target ="_blank" y abre los enlaces en ventana nueva
 */
$( function() {
	$('.external').click( function() {
		window.open($(this).attr('href'));
		return false;
	});
});


$(document).ready(function(){	
	$("#enviar-amicfrm").validate();
	$("#contactanosfrm").validate();
});

/*
 * qTip
 */
$(document).ready(function() {	
	$('.agenda-anual td a').each(function() {
		var htmlelement = $('#' + $(this).attr("rel") + " div.anotacio-container");
		var elem = $(this);
		
		if (htmlelement.size() > 0) {
			$(this).qtip( {
				content : {
					text: htmlelement.html()
					/*,
					title: {
						text: '',
						button: '<span><em>Tanca</em></span>'
					}*/
				},
				position : {
					corner : {
						target: 'topRight',
						tooltip: 'bottomLeft'
					}
				},
				show : {
					when : 'click'
				},
				hide : 'unfocus', // Hide it when inactive
				style : {
					width : 320,
					tip : true,
					border : {
						width : 6,
						radius : 5,
						color : "#C7C7C7"
					},
					background : "#E6E6E6",
					color : 'black',
					textAlign : 'left',
					padding: 8,
					classes : {
						//title  : "qtip-title aspa",
						content: "qtip-content"
					}
				},
				
				api: {
					onHide : function() {
						//hideQtips();
						elem.removeClass("active");
						elem.addClass("visited");
					}
					
				},
				fixed : true
			});
		}
		
		// No onclick + styles
		
		
		$(this).click(function(event) {			
			$(this).addClass("active");
			$(this).removeClass("visited");
			return false;
		});
	});
});

/*
function hideQtips(){
	$('a.popup,a.tipext,a.tip').each(function(){
		$(this).qtip('hide');
	});
}*/
