

	//
	// definizione del NS FlexJS
	//

FlexJS = window.FlexJS || {};

FlexJS.isIE = jQuery.browser.msie;
FlexJS.isGecko = jQuery.browser.mozilla;

	//
	// accesso alla configurazione
	//

FlexJS.AppConfigure = window.FlexJS.AppConfigure || {};

FlexJS.AppConfigure.Get = function (pName) {

	return gAppConfigure[pName];
}

	//
	// utility generiche
	//

FlexJS.Utils = window.FlexJS.Utils || {}

FlexJS.Utils.InArray = function (needle, haystack) {

	for (var i = 0, m = haystack.length; i < m; i++)
		if (haystack[i] === needle)
			return true;

	return false;
}

FlexJS.Utils.Random = function (min, max) {

	if (! min) min = 0;
	if (! max) max = 10e10;

	return Math.round(max * Math.random() + min)
}

	//
	// apertura in una nuova finestra dei link
	//

FlexJS.TBHack = window.FlexJS.TBHack || {}

FlexJS.TBHack.sKeyCode = [13, 32];

FlexJS.TBHack.Init = function() {

	$('a.target_blank').each(function() {

		this.title += FlexJS.AppConfigure.Get('kBlankLinkMessage');

		$(this).click(function(e) {

			FlexJS.TBHack.Open(this.href);

			return e.preventDefault();
		});

		$(this).keypress(function(e) {

			if (FlexJS.Utils.InArray(e.keyCode, TBHack.sKeyCode)) {

				FlexJS.TBHack.Open(this.href);

				return e.preventDefault();
			}
		});
	});
}

FlexJS.TBHack.Open = function(url) {

		// apre in una finestra nuova

	window.open(url, 'TBH' + FlexJS.Utils.Random());
}

$().ready(function() {

	FlexJS.TBHack.Init();
});
