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

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

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

/*
 * 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 if (content.is('.window')) {
				popup(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");
		}
	});
});

// abre un popup centrado
function popup(url) {
	var aw = screen.availWidth - 10;
	w = 400;
	h = 435;
	if(popup.arguments.length>1){
		w = popup.arguments[1];
	}
	xc = (aw - w) / 2; // center

	features = 'status=no,scrollbars=yes,menubar=no,toolbar=no,'
			+ 'location=no,directories=no,resizable=yes,copyhistory=no,'
			+ 'width=' + w + ',height=' + h + ',' + 'left=' + xc
			+ ',top=0,screenX=' + xc + ',screenY=0';

	window.open(url, 'popup'+w, features).focus();
}

$( function() {
	$('.window').click( function() {
		popup($(this).attr('href'));
		return false;
	});
});

$( function() {
	$('#segueixForm, #continuaForm, #responderFrm').submit( function() {
		var boton = $(this).find("input[type='submit']");
		boton.attr("disabled", true);
		return true;
	});
});
