LIBCORE_MAJOR = "LibCore";
LIBCORE_MINOR = parseFloat("$Revision: 10053 $".match(/\d+/)) - 100000;  // NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!

if (!(LR_LibCore) || (LR_LibCore.minor < LIBCORE_MINOR)) {
	
	//alert('aaaa');
	var LR_LibCore = {
		libs: [],
		debug: false,
		
		minor: LIBCORE_MINOR,

		/*[[---------------------------------------------------------------------------
		Notes:
			* Crea una nuova libreria con il nome specificato.
		Arguments:
			string - name of the addon.
			tuple - list of mixins with which to embed into this addon.
		Returns:
			number - minor version of addon
		Example:
			LR_LibCore:NewLibrary("MyAddon", "$Revision: 10000$", "Mixin-1.0", "OtherMixin-2.0")
		-----------------------------------------------------------------------------]]*/
		NewLibrary: function (major, minor) {
			// Controlla le dependencies
			var areDependencies = arguments.length > 2 ? true : false;
			
			var result = '';
			if (areDependencies) {
				for (var i=2; i<arguments.length; i++) {
					result += arguments[i] + '\n';
					if (this.GetLibrary(arguments[i], false) == false) {
						if (this.debug) { alert('Dependency '+ arguments[i] +' not found.'); }
						return null;
					}
				}
				if (this.debug) { alert('List of Dependencies:\n'+ result);	}
			}
			
			// Se le dependecies sono presenti carica la libreria
			if (this.debug) { alert('New instance of Library '+ major); }
			assert(typeof(major) == "string", true, "Bad argument #2 to `NewLibrary' (string expected)");
			//alert ('.1.'+ minor +' - type:'+ typeof(minor));
			//minor = parseFloat((minor).match(/\d+/)) - 100000;
			//alert ('.2.'+ minor +' - type:'+ typeof(minor));

			//alert ('.3.'+ parseFloat(minor.toString().match(/\d+/)) +' - type:'+ typeof(minor));
			minor = assert(parseFloat(minor.toString().match(/\d+/)), true, "Minor version must either be a number or contain a number.")

			var oldminor = this.libs[major];
			if (oldminor && minor >= oldminor) {
				if (this.debug) {
					alert ('LR_LibCore.NewLibrary - Exit function cause a newest ('+ oldminor +') version of '+ major +' has been found.');
				}
				return null;
			}
			this.libs[major] = minor;
			
			if (this.debug) {
				alert  ('major: '+ major +'\n' +
						'this.libs[major]: '+ this.libs[major] +'\n' +
						'oldminor: '+ oldminor);
			}
			return this.libs[major];
			//return this.libs[major], oldminor;
		},
		
		GetLibrary: function (major, silent) {
			if (this.debug) silent = false;
			if (!this.libs[major] && !silent) {
				alert("Cannot find a library instance of {0}.".format(major), 2)
			}
			if (this.debug) { alert('LR_LibCore.GetLibrary('+ major +'): '+ (typeof(this.libs[major])=='undefined' ? false : this.libs[major])); }
			if (typeof(this.libs[major]) == 'undefined') {
				return false;
			} else {
				return this.libs[major];
			}
		},
		
		IterateLibraries: function () {
			return this.libs;
		},
		
		LoadLibrary: function() {
			var areArgs = arguments.length > 0 ? true : false;
			var newArgs = new Array; 
			var lib, i, length, IsLoaded;
			
			if (areArgs == true) {
				lib = arguments[arguments.length - 1];
				//alert(lib);
				for (var i=0, length=arguments.length - 1; i<length; i++) {
					newArgs[i] = arguments[i];
				}
				
				newArgs[1] = parseFloat((newArgs[1]).match(/\d+/)) - 100000;
				//alert('newArgs[1]:'+ newArgs[1]);
				
				if (isFunction(lib)) {
					IsLoaded = (this.NewLibrary.apply(this, newArgs) != null) ? true : false;
					if (IsLoaded == true) { lib(); }
				}
			}
		}
		
	
	};

	// Da toglere il commento. Era solo per testare la registrazione della libreria che mi interessava.
	//LR_LibCore.NewLibrary(LIBCORE_MAJOR, LIBCORE_MINOR);
}




function $A(iterable){
	if (iterable.item){
		var l = iterable.length, array = new Array(l);
		while (l--) array[l] = iterable[l];
		return array;
	}
	return Array.prototype.slice.call(iterable);
};



// --Esempio
//var Car = function() { this.name = 'car'; }
//var Truck = function() { this.name = 'truck'; }
//
//var func = function() { alert(this.name); }
//
//var c = new Car();
//var t = new Truck();
//
//func.apply(c);
//func.apply(t);
//-- Lo stesso risultato lo ottengo con:
//func.bind(c)();
//func.bind(t)();

Function.prototype.bind = function() {
	if (arguments.length < 2 && arguments[0] === undefined) return this;
	var __method = this, args = Array.prototype.slice.call(arguments), object = args.shift();
	return function() {
		//return __method.apply(object, args.concat($A(arguments)));
		return __method.apply(object, args);
	}
}




Function.prototype.delay = function() {
    var __method = this, args = Array.prototype.slice.call(arguments), timeout = args.shift() * 1000;
    return window.setTimeout(function() {
      return __method.apply(__method, args);
    }, timeout);
}



// ------------------------------------------------------------------------------------------------------------- //
// ---------------------------------------- // Function.__prototype__ // --------------------------------------- //
// ------------------------------------------------------------------------------------------------------------- //


/*
function $A(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) return iterable.toArray();
  var length = iterable.length, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}
*/

/*
Function.prototype.bind = function() {
	if (arguments.length < 2 && arguments[0] === undefined) return this;
	var __method = this, args = $A(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat($A(arguments)));
	}
}
*/

// In testing {
Function.prototype.bindAsEventListener = function() {
	var __method = this, args = $A(arguments), object = args.shift();
	return function(event) {
		return __method.apply(object, [event || window.event].concat(args));
	}
}
// }

// ---[Esempio pratico di .curry]---
//
// function sayHello(msg) {
//    alert(msg+'\n You clicked on '+this.id);
// }
//
// sayHello('Hello World from Dustin');
// sayHello.curry(el, 'Hello World from Dustin');
Function.prototype.curry = function() {
    if (!arguments.length) return this;
    var __method = this, args = $A(arguments);
    return function() {
      return __method.apply(this, args.concat($A(arguments)));
    }
}

/*
Function.prototype.delay = function() {
    var __method = this, args = $A(arguments), timeout = args.shift() * 1000;
    return window.setTimeout(function() {
      return __method.apply(__method, args);
    }, timeout);
}
*/

Function.prototype.defer = Function.prototype.delay.curry(0.01);






function assert(assertString) {
  var throwException = arguments.length > 1 ? arguments[1] : false;
  var argsObj = arguments.length > 2 ? arguments[2] : {};
  var argsString = "";

  var mustBeTrue = false;
  try {
    mustBeTrue = assertString;
  }
  catch(e) {
	// fall through.  An exception will leave mustBeTrue as false, and the assertion still fails.
    throw new Error("Error (" + argsObj + ")");
  }
  
  try {
    if (!mustBeTrue) {
     throw new Error("ECMAScript assertion failed:  (" + assertString + ")");
    }
  }
  catch(e) {
    if (throwException) {
      throw e;
    } else {
      alert(e);
    }
  }
  return mustBeTrue;
}


// Un try-catch che consente piu' di un parametro
var Try = {
  these: function() {
    var returnValue;

    for (var i = 0, length = arguments.length; i < length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) { }
    }

    return returnValue;
  }
};

// $$A - funzione che permette il passaggio da un contenitore Object ad uno Array(plurale)/Object(singolare)
function $$A(element) {
	if (element) {
		if (element.length) {
			if (element.length > 1) {
				var tmpArray = [];
				for (var i = 0; i < element.length; i++) tmpArray.push(element[i]);
				element = tmpArray;
			} else element = element[0];
		}
	} else element = null;
	return element;
}

// -------------------------------------------------------------------------------------------------- //
// --- Inspector                                                                                  --- //
// --- Inspect an object and return ONLY its properties (no methods)                              --- //
// -------------------------------------------------------------------------------------------------- //

function Inspector(thisOBJ, childOBJ, objname) {
	var tmpString;
	var debugMode = false;

	function Constructor() {
		this.toDiv = toDiv;
		this.toAlert = toAlert;
		
		this.MyCSS =	" "+
							"#modalContainer { "+
							"	background-color:transparent; "+
							"	position:absolute;  "+
							"	width:100%;  "+
							"	height:100%;  "+
							 "	top:0px;  "+
							"	left:0px;  "+
							"	z-index:10000;  "+
							"	background-image:url(tp.png); /* required by MSIE to prevent actions on lower z-index elements */  "+
							"}  "+
							"#alertBox {  "+
							"	position:relative;  "+
							"	width:300px;  "+
							"	min-height:100px;  "+
							"	margin-top:50px;  "+
							"	border:2px solid #000;  "+
							"	background-color:#F2F5F6;  "+
							"	background-image:url(alert.png);  "+
							"	background-repeat:no-repeat;  "+
							"	background-position:20px 30px;  "+
							"}  "+
							"#modalContainer > #alertBox {  "+
							"	position:fixed;  "+
							"}  "+
							"#alertBox h1 {  "+
							"	margin:0;  "+
							"	font:bold 0.9em verdana,arial;  "+
							"	background-color:#78919B;  "+
							"	color:#FFF;  "+
							"	border-bottom:1px solid #000;  "+
							"	padding:2px 0 2px 5px;  "+
							"}  "+
							"#alertBox p {  "+
							"	font:0.7em verdana,arial;  "+
							"	height:50px;  "+
							"	padding-left:5px;  "+
							"	margin-left:55px;  "+
							"}  "+
							"#alertBox #closeBtn {  "+
							"	display:block;  "+
							"	position:relative;  "+
							"	margin:5px auto;  "+
							"	padding:3px;  "+
							"	border:2px solid #000;  "+
							"	width:70px; "+
							"	font:0.7em verdana,arial; "+
							"	text-transform:uppercase; "+
							"	text-align:center; "+
							"	color:#FFF;  "+
							"	background-color:#78919B;  "+
							"	text-decoration:none;  "+
							"}  "
		
		var AlertMessage = Inspect(thisOBJ, childOBJ, objname);
		//alert(AlertMessage);
		//this.toDiv(AlertMessage);
		//this.toAlert(AlertMessage);
	}

	// creo una DIV per stampare a video i risultati
	function createCustomAlert(txt) {
		// constants to define the title of the alert and button text.
		var ALERT_TITLE = "Debug";
		var ALERT_BUTTON_TEXT = "Ok";
		var PRINT_BUTTON_TEXT = "Print";
		
		//alert('createCustomAlert');
		
		//loadjscssfile(this.MyCSS, "style");
		//loadjscssfile("../risorse/!Libs/test.css", "css");
		
		// shortcut reference to the document object
		var d = document, mObj, alertObj, h1, msg, btn;
	
		// if the modalContainer object already exists in the DOM, bail out.
		if(d.getElementById("modalContainer")) return;
	
		// create the modalContainer div as a child of the BODY element
		mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
		mObj.id = "modalContainer";
		 // make sure its as tall as it needs to be to overlay all the content on the page
		mObj.style.height = document.documentElement.scrollHeight + "px";
	
		// create the DIV that will be the alert 
		alertObj = mObj.appendChild(d.createElement("div"));
		alertObj.id = "alertBox";
		// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
		if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
		// center the alert box
		alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
	
		// create an H1 element as the title bar
		h1 = alertObj.appendChild(d.createElement("h1"));
		h1.appendChild(d.createTextNode(ALERT_TITLE));
	
		// create a paragraph element to contain the txt argument
		msg = alertObj.appendChild(d.createElement("p"));
		msg.innerHTML = txt;
		
		// create an anchor element to use as the confirmation button.
		btn = alertObj.appendChild(d.createElement("a"));
		btn.id = "closeBtn";
		btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
		btn.href = "#";
		// set up the onclick event to remove the alert when the anchor is clicked
		btn.onclick = function() { removeCustomAlert();return false; }
		
		// create an anchor element to use as print button.
		btn = alertObj.appendChild(d.createElement("a"));
		btn.id = "printBtn";
		btn.appendChild(d.createTextNode(PRINT_BUTTON_TEXT));
		btn.href = "#";
		btn.onclick = function() { printCustomAlert(); return false; }
	}
	
	// removes the custom alert from the DOM
	function removeCustomAlert() {
		document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
	}


	function loadjscssfile(filename, filetype){
		if (filetype=="js") { //if filename is a external JavaScript file
			var fileref=document.createElement('script')
			fileref.setAttribute("type","text/javascript")
			fileref.setAttribute("src", filename)
		} else if (filetype=="css") { //if filename is an external CSS file
			var fileref=document.createElement("link")
			fileref.setAttribute("rel", "stylesheet")
			fileref.setAttribute("type", "text/css")
			fileref.setAttribute("href", filename)
		} else if (filetype=="style") {
			var fileref=document.createElement("div")
			fileref.innerHTML = '<p>x</p><style>'+ MyCSS +'</style>';
			document.body.appendChild(fileref.childNodes[1]);
		}
		if (typeof fileref!="undefined" || fileref == "css") {
			document.getElementsByTagName("head")[0].appendChild(fileref)
		}
	}

	function printCustomAlert(AlertMessage) {
		var Win = window.open('','','width=300,height=300');  
		Win.document.open("text/html");
		Win.document.write(document.getElementById('modalContainer').innerHTML);  
		Win.document.close();  
		Win.focus();
		Win.print();
		Win.close();
	}

	function debug(message, SourceString) {
		if (debugMode == true) return SourceString += message;
	}

	//------------------

	function toDiv(AlertMessage) {
		if (AlertMessage) createCustomAlert(AlertMessage);
		else createCustomAlert(tmpString);
	}
	
	function toAlert(AlertMessage) {
		if (AlertMessage) alert(AlertMessage);
		else alert(tmpString);
	}

	//------------------
	
	function Inspect(thisOBJ, childOBJ, objname) {
		//alert(thisOBJ +', '+ childOBJ +', '+ objname);
		if (!childOBJ) {
			tmpString = '[#Object]\n';
			var parent = thisOBJ;
			//var parent = new Array(thisOBJ);
		} else {
			//alert('Recursive for '+ obj +' listed as '+ objname);
			tmpString = ('[#child -> '+ objname +']\n');
			var parent = childOBJ;
			//var parent = new Array(childOBJ);
		}

		debug('1) '+ typeDef(parent));
		var typeParent = typeDef(parent);

		if (typeDef(parent) != "string") {
			
			for (var item in parent) {
				debug('2) '+ item +' - ['+ typeDef(parent[item]) +']');
				var typeChild = typeDef(parent[item]);

				if (typeof(parent[item])  != "object") {	// Se c'e' da fare una funzione ricorsiva evito di scrivere il typeDef
					tmpString += '['+ typeChild +']\n';
				}
				
				if (typeChild != "function") {
					debug('3) '+ typeChild);
					if (!childOBJ) tmpString += (item +' = '+ parent[item] +'\n');
					else tmpString += ('\t.'+ item +' = '+ parent[item] +'\n');
				} else {
					debug('4) '+ typeChild);
					if (typeof(parent[item])  == "object") {
						tmpString += Inspect(null, parent[item], item.toString());
					} else {
						tmpString += item +'\n';
					}
				}
				
				if (typeof(parent[item])  != "object") {
					tmpString += '[/'+ typeChild +']\n';
				}
			}
		} else {
			tmpString += (isUndefined(objname) ? '<no name assigned>' : objname ) +' = '+ parent +'\n';
		}
		
		if (!childOBJ) tmpString += '[/Object]';
		else tmpString += ('[/'+ objname +']\n');
		
		return tmpString;
	}

	return new Constructor();
}

// ------------------------------------------------------------------------------------------------------------- //
// -------------------------------------- // Operazioni sulle stringhe // -------------------------------------- //
// ------------------------------------------------------------------------------------------------------------- //

// Mid
function Mid(stringa, Start, Length) {
    if (stringa == null)
        return (false);
    
    if (Start > stringa.length)
        return '';
    
    if (Length == null || Length.length == 0)
        return (false);
    
    return stringa.substr((Start - 1), Length);
}


function InStr(String1, String2) {
    var a = 0;
    
    if (String1 == null || String2 == null) return (false);
    
    String1 = String1.toLowerCase();
    String2 = String2.toLowerCase();
    
    a = String1.indexOf(String2);
    if (a == -1) return 0;
    else return a + 1;
}


function Len(stringa) {
    if (stringa == null)
        return (false);
    
    return String(stringa).length;
}


function Trim(Stringa) {
    if (Stringa == 'undefined') {
		return;	
	}

	re = /\s+$|^\s+/g;
	return Stringa.replace(re, '');
}


function format() {
    var str = this;

    for(var i=0;i<arguments.length;i++) {

        var re = new RegExp('\\{' + (i) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }

    return str;
}
String.prototype.format = format;


// Al posto del .replace usiamo questa funzione per una semplice sostituzione del testo
function replaceText(pattern, substitute) {
    return this.split(pattern).join(substitute);
}
String.prototype.replaceText = replaceText;


function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}



function LFill(STRINGA, N, X) {
	var Result, i;
	if (isEmpty(STRINGA)) {
		STRINGA = '';
	}
	Result = STRINGA;
	if (STRINGA.length > N) {
		Result = STRINGA.substring(1, N);
	} else {
		for (i = 0; i < (N - STRINGA.length); i++) {
			Result = X + Result;
		}
	}
	return Result;
}


function RFill(STRINGA, N, X) {
	var Result, i;
	if (isEmpty(STRINGA)) {
		STRINGA = '';
	}
	Result = STRINGA;
	if (STRINGA.length > N) {
		Result = STRINGA.substring(1, N);
	} else {
		for (i = 0; i < (N - STRINGA.length); i++) {
			Result = Result + X;
		}
	}
	return Result;
}


function isPath() {
	if ( !(this.match(/^(([a-zA-Z]:|\\)\\)?(((\.)|(\.\.)|([^\\\/:\*\?"\|<>\. ](([^\\\/:\*\?"\|<>\. ])|([^\\\/:\*\?"\|<>]*[^\\\/:\*\?"\|<>\. ]))?))\\)*[^\\\/:\*\?"\|<>\. ](([^\\\/:\*\?"\|<>\. ])|([^\\\/:\*\?"\|<>]*[^\\\/:\*\?"\|<>\. ]))?$/)) ) {
		return false;
	} else {
		return true;
	}
}
String.prototype.isPath = isPath;


// ----------------------------------- // Controlli sui prototype // ----------------------------------- //


function isArray(it) {
	if (typeof it == 'object') {
		var criterion = it.constructor.toString().match(/array/i);
		return (criterion != null);
	}
	return false;
}


function isString(it) {
	if (typeof it == 'string') return true;
	if (typeof it == 'object') {
		var criterion = it.constructor.toString().match(/string/i);	
		return (criterion != null);
	}
	return false;
}


function isFunction(it) {
	return it && (typeof it == "function" || it instanceof Function); // Boolean
}


// Esempio di implementazione di typeDef
//
//	var a0 = 'abc';										var a1 = new String();
//	var a2 = 123; 											var a3 = new Number();
//	var a4 = [1, 2, 3]; 									var a5 = new Array();
//	var a6 = function() { return 1 }; 				var a7 = new Function("return 1");
//																var a8 = new Date();
//	var a9 = true; 										var a10 = new Boolean();
//	var a11 = /array/;									var a12 = new RegExp();
//	var a13 = undefined;									var a14;
//	var a15 = document.createElement("image");	var a16 = new Image();
//	
//	var arrtmp = [a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a12, a11, a13, a14, a15, a16];
//
//
//	arrtmp.Each(function (el, i) {
//		var tmp = typeDef(el);
//		alert('---[N. '+ i +']---\n'+	'a) '+ tmp.result +'\n'+ 'b) '+ tmp.source +'\n');
//	}, this)

function typeDef(it) {
	var tmpTypeof = typeof it;
	var result;
	
	switch (tmpTypeof) {
		case 'string': result = 'string'; break;
		case 'array': result = 'array'; break;
		case 'number': result = 'number'; break;
		case 'boolean': result = 'boolean'; break;
		case 'date': result = 'date'; break;
		case 'regexp': result = 'regexp'; break;
		case 'function': if ((it instanceof Function) && it) result = 'function'; break;
		case 'object':
			if (it.constructor) { // if "it" is not an object properly passed (i.e.: no constructor, no prototype, etc) it causes an error
				var criterion = it.constructor.toString();
				if (criterion.match(/string/i)) result = 'string';
				else if (criterion.match(/array/i)) result = 'array';
				else if (criterion.match(/number/i)) result = 'number';
				else if (criterion.match(/boolean/i)) result = 'boolean';
				else if (criterion.match(/date/i)) result = 'date';
				else if (criterion.match(/regexp/i)) result = 'regexp';
				else if (criterion.match(/function/i)) result = 'function';		// da lasciare come ultima condizione
			} else {
				result = 'unknown';
			}
			break;
		default: result = tmpTypeof; break;
	}
	
	return result;
	//return { result: result, source: criterion };	// da usare per i test
}




// ------------------------------------------------------------------------------------------------------------- //
// ---------------------------------------- // Operazioni sui numeri // ---------------------------------------- //
// ------------------------------------------------------------------------------------------------------------- //

function isNumeric(vTestValue) {
	// put the TEST value into a string object variable
	var sField = new String(Trim(vTestValue));
	
	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}
	
	// made it through the loop - we have a number
	return true;
}

function isInt(x) { 
   var y = parseInt(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
} 







// ------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------- //

LR_LibCore.LoadLibrary("Events-1.0", "$Revision: 00012 $", function() {

	LR_Event = {
	
		Initialize: function() {
			if (navigator.userAgent.toLowerCase().indexOf('opera ')+1 || navigator.userAgent.toLowerCase().indexOf('opera/')+1) {
				// opera is dumb at times.
				//this.addEvent = addEventHandlerOpera;
				this.addEvent =
					function(o,eventType,eventHandler,eventBubble) {
						if (!this.postLoadEvent(eventType)) (o==window?document:o).addEventListener(eventType,eventHandler,eventBubble);
						else eventHandler();
					}
	
				this.onceAddEvent =
					function(o,eventType,eventHandler,eventBubble) {
						(o==window?document:o).addEventListener(eventType,eventHandler,eventBubble);
					}
						
				//this.removeEvent = removeEventHandlerOpera;
				this.removeEvent =
					function(o,eventType,eventHandler,eventBubble) {
						(o==window?document:o).removeEventListener(eventType,eventHandler,eventBubble);
					}
			} else if (document.addEventListener) { // DOM event handler method
				//this.addEvent = this.addEventHandlerDOM;
				this.addEvent =
					function(o,eventType,eventHandler,eventBubble) {
						if (!this.postLoadEvent(eventType)) o.addEventListener(eventType,eventHandler,eventBubble);
						else eventHandler();
					}
	
				this.onceAddEvent =
					function(o,eventType,eventHandler,eventBubble) {
						o.addEventListener(eventType,eventHandler,eventBubble);
					}
	
				//this.removeEvent = this.removeEventHandlerDOM;
				this.removeEvent = 
					function(o,eventType,eventHandler,eventBubble) {
						o.removeEventListener(eventType,eventHandler,eventBubble);
					}
			} else if (document.attachEvent) { // IE event handler method
				//this.addEvent = addEventHandlerIE;
				this.addEvent =
					function(o,eventType,eventHandler) { // IE workaround
						if (!eventType.indexOf('on')+1) eventType = 'on'+eventType;
						if (!this.postLoadEvent(eventType)) o.attachEvent(eventType,eventHandler); // Note addition of "on" to event type
						else eventHandler();
					}
	
				this.onceAddEvent =
					function(o,eventType,eventHandler,eventBubble) {
						if (!eventType.indexOf('on')+1) eventType = 'on'+eventType;
						o.attachEvent(eventType,eventHandler); // Note addition of "on" to event type
					}
	
				//this.removeEvent = removeEventHandlerIE;
				this.removeEvent =
					function(o,eventType,eventHandler) {
						if (!eventType.indexOf('on')+1) eventType = 'on'+eventType;
							o.detachEvent(eventType,eventHandler);
					}
			} else { // Neither "DOM level 2" (?) methods supported
				this.addEvent = function(o,eventType,eventHandler,eventBubble) {
					o['on'+eventType] = eventHandler;
					// Multiple events could be added here via array etc.
				}
				
				this.onceAddEvent = function(o,eventType,eventHandler,eventBubble) {
					o['on'+eventType] = eventHandler;
					// Multiple events could be added here via array etc.
				}
	
				this.removeEvent = function(o,eventType,eventHandler,eventBubble) {}
			};
			
			


			this.IsDOMLoaded = 
			function() {
			  if (isUndefined(document.LR_DomLoaded)) document.LR_DomLoaded = false;
			  var i = function() { document.LR_DomLoaded = true; };
			  var u = navigator.userAgent.toLowerCase();
			  var ie = /*@cc_on!@*/false;
			  if (/webkit/.test(u)) {	// safari
					if ( document.readyState == "loaded" || document.readyState == "complete" ) document.LR_DomLoaded = true;
					else document.LR_DomLoaded = false;
			  } else if ((/mozilla/.test(u) && !/(compatible)/.test(u)) || (/opera/.test(u))) {	// opera/moz
				 document.addEventListener("DOMContentLoaded",i,false);
			  } else if (ie) {
				 // IE
				 (function (){ 
					var tempNode = document.createElement('document:ready'); 
					try {
					  tempNode.doScroll('left'); 
					  i(); 
					  tempNode = null; 
					} catch(e) { document.LR_DomLoaded = false; } 
				 })();
			  } else {
				 window.onload = i;
			  }
			  return document.LR_DomLoaded;
			};

			
//			(function(i) {
//			  var u = navigator.userAgent.toLowerCase();
//			  var ie = /*@cc_on!@*/false;
//			  if (/webkit/.test(u)) {
//				 // safari
//				 timeout = setTimeout(function(){
//						if ( document.readyState == "loaded" || 
//							document.readyState == "complete" ) {
//							i();
//						} else {
//						  setTimeout(arguments.callee,10);
//						}
//					}, 10); 
//			  } else if ((/mozilla/.test(u) && !/(compatible)/.test(u)) ||
//							 (/opera/.test(u))) {
//				 // opera/moz
//				 document.addEventListener("DOMContentLoaded",i,false);
//			  } else if (ie) {
//				 // IE
//				 (function (){ 
//					var tempNode = document.createElement('document:ready'); 
//					try {
//					  tempNode.doScroll('left'); 
//					  i(); 
//					  tempNode = null; 
//					} catch(e) { 
//					  setTimeout(arguments.callee, 0); 
//					} 
//				 })();
//			  } else {
//				 window.onload = i;
//			  }
//			})(init);
	
		},
	
		postLoadEvent: function(eventType) {
			// test for adding an event to the body (which has already loaded) - if so, fire immediately
			// Se avviene dopo l'OnLoad ritorna un Object altrimenti ritorna False - //CommentBy: Lorenzo
			return ((eventType.toLowerCase().indexOf('load')>=0) && document.body);
		}
	}
	LR_Event.Initialize();
});

// ------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------- //

LR_LibCore.LoadLibrary("Timer-1.0", "$Revision: 00003 $", function () {
	LR_Timer = function(callback, frequency, oWindow) {
	
		function Constructor() {
	
			// Methods
			this.destroy = destroy;
			this.execute = execute;
			this.registerCallback = registerCallback;
			this.onTimerEvent = onTimerEvent;
	
			// Parameters
			this.callback = callback;
			this.frequency = frequency;
			//this.destObject = o;
			//this.destObject = (typeof(oWindow)=='undefined' ? window : oWindow);
			this.destObject = (window || oWindow);
			
			// other
			this.currentlyExecuting = false;
	
			this.self = this;	//untested
	
	
			this.registerCallback();
	
		}
	
	
	
		function destroy() {
			if (!this.timer) return;
			this.destObject.clearInterval(this.timer);
			this.timer = null;
		}
		
		
		function execute() {
			this.callback(this);
		}
	
	
		function onTimerEvent() {
			if (!this.currentlyExecuting) {
				try {
					this.currentlyExecuting = true;
					this.execute();
				} finally {
					this.currentlyExecuting = false;
				}
			}
		}
	
		function registerCallback() {
			this.timer = this.destObject.setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); //Codice originale
			//this.timer = this.destObject.setInterval(this.execute.bind(this), this.frequency * 1000);
		}
	
		return new Constructor();
		
		
			/*
			//Funzioni comuni
			var PeriodicalExecuter = Class.create({
			  initialize: function(callback, frequency) {
				this.callback = callback;
				this.frequency = frequency;
				this.currentlyExecuting = false;
			
				this.registerCallback();
			  },
			
			  registerCallback: function() {
				this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
			  },
			
			  execute: function() {
				this.callback(this);
			  },
			
			  stop: function() {
				if (!this.timer) return;
				clearInterval(this.timer);
				this.timer = null;
			  },
			
			  onTimerEvent: function() {
				if (!this.currentlyExecuting) {
				  try {
					this.currentlyExecuting = true;
					this.execute();
				  } finally {
					this.currentlyExecuting = false;
				  }
				}
			  }
			});
			*/
	}
});


// ------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------- //

LR_LibCore.LoadLibrary("BrowserInfo-1.0", "$Revision: 00021 $", function () {

	LR_BrowserCheck = {
		Initialize: function() {
			this.BrowserName = '';
			this.BrowserShortName = '';
			this.BrowserVersion = '';
			
			this.Source = {
				b: navigator.appName,
				ua: navigator.userAgent.toLowerCase(),
				v: parseInt(navigator.appVersion)
			}

			//LR_BrowserCheck.Supports = {}
			this.Supports = { }

			//Run-time
			this.Run();
		},
		
		Run: function() {

			// Tests for LR_BrowserCheck.Supports	- // rev00020
			(function() {
				var div = document.createElement("div");
				div.style.display = "none";
				div.innerHTML = '   <link/><table></table><a href="/a" style="color:red;float:left;opacity:.5;">a</a><select><option>text</option></select><object><param/></object>';
				
				var a = div.getElementsByTagName("a")[0];
				
				// Verify style float existence (IE uses styleFloat instead of cssFloat)
				var styleFloat = !!a.style.cssFloat ? "cssFloat" : "styleFloat";
				
				// Make sure that element opacity exists (IE uses filter instead)
				var opacity = a.style.opacity === "0.5";
				
				// Make sure that URLs aren't manipulated (IE normalizes it by default)
				var hrefNormalized = a.getAttribute("href") === "/a";
		
				// Get the style information from getAttribute (IE uses .cssText insted)
				var style = /red/.test( a.getAttribute("style") );
				
				//alert('Caricato LR_BrowserCheck.Supports()');
				
				// Settings values discovered by this function()
				LR_BrowserCheck.Supports["styleFloat"] = styleFloat;
				LR_BrowserCheck.Supports["opacity"] = opacity;
				LR_BrowserCheck.Supports["hrefNormalized"] = hrefNormalized;
				LR_BrowserCheck.Supports["style"] = style;
				LR_BrowserCheck.Supports["noCloneEvent"] = true;
		
				if ( div.attachEvent && div.fireEvent ) {
					div.attachEvent("onclick", function(){
						// Cloning a node shouldn't copy over any bound event handlers (IE does this)
						LR_BrowserCheck.Supports["noCloneEvent"] = false;
						div.detachEvent("onclick", arguments.callee);
					});
					div.cloneNode(true).fireEvent("onclick");
				}
		
			})();

			
			// convert all characters to lowercase to simplify testing
			var agt=navigator.userAgent.toLowerCase();
			var appVer = navigator.appVersion.toLowerCase();


			// *** BROWSER VERSION ***
		
			var is_minor = parseFloat(appVer);
			var is_major = parseInt(is_minor);
		
			// Note: On IE, start of appVersion return 3 or 4
			// which supposedly is the version of Netscape it is compatible with.
			// So we look for the real version further on in the string
		
			var iePos  = appVer.indexOf('msie');
			if (iePos !=-1) {
			   is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
			   is_major = parseInt(is_minor);
			}
			
			this.is_gecko = ((navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
			var is_gver  = 0;
			if (this.is_gecko) is_gver=navigator.productSub;
		
			this.is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
							(agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
							(agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
							(this.is_gecko) && 
							((navigator.vendor=="")||(navigator.vendor=="Mozilla")));
			if (this.is_moz) {
			   this.is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
			   if(!(this.is_moz_ver)) {
				   this.is_moz_ver = agt.indexOf('rv:');
				   this.is_moz_ver = agt.substring(this.is_moz_ver+3);
				   var is_paren = this.is_moz_ver.indexOf(')');
				   this.is_moz_ver = this.is_moz_ver.substring(0,is_paren);
			   }
			   is_minor = this.is_moz_ver;
			   is_major = parseInt(this.is_moz_ver);
			}
		
			this.is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
						&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
						&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
						&& (!(this.is_moz)));
		
			// Netscape6 is mozilla/5 + Netscape6/6.0!!!
			// Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
			// Changed this to use navigator.vendor/vendorSub - dmr 060502   
			// var nav6Pos = agt.indexOf('netscape6');
			// if (nav6Pos !=-1) {
			if ((navigator.vendor)&&
				((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
				(this.is_nav)) {
			   var is_major = parseInt(navigator.vendorSub);
			   // here we need is_minor as a valid float for testing. We'll
			   // revert to the actual content before printing the result. 
			   var is_minor = parseFloat(navigator.vendorSub);
			}
		
			this.is_opera = (agt.indexOf("opera") != -1);
			this.is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
			this.is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
			this.is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
			this.is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
			this.is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1); // new 020128- abk
			this.is_opera5up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4);
			this.is_opera6up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4 && !this.is_opera5); // new020128
		
			this.is_nav2 = (this.is_nav && (is_major == 2));
			this.is_nav3 = (this.is_nav && (is_major == 3));
			this.is_nav4 = (this.is_nav && (is_major == 4));
			this.is_nav4up = (this.is_nav && is_minor >= 4);  // changed to is_minor for
														// consistency - dmr, 011001
			this.is_navonly      = (this.is_nav && ((agt.indexOf(";nav") != -1) ||
								  (agt.indexOf("; nav") != -1)) );
		
			this.is_nav6   = (this.is_nav && is_major==6);    // new 010118 mhp
			this.is_nav6up = (this.is_nav && is_minor >= 6) // new 010118 mhp
		
			this.is_nav5   = (this.is_nav && is_major == 5 && !this.is_nav6); // checked for ns6
			this.is_nav5up = (this.is_nav && is_minor >= 5);
		
			this.is_nav7   = (this.is_nav && is_major == 7);
			this.is_nav7up = (this.is_nav && is_minor >= 7);
		
			this.is_ie   = ((iePos!=-1) && (!this.is_opera));
			this.is_ie3  = (this.is_ie && (is_major < 4));
		
			this.is_ie4   = (this.is_ie && is_major == 4);
			this.is_ie4up = (this.is_ie && is_minor >= 4);
			this.is_ie5   = (this.is_ie && is_major == 5);
			this.is_ie5up = (this.is_ie && is_minor >= 5);
			
			this.is_ie5_5  = (this.is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
			this.is_ie5_5up =(this.is_ie && is_minor >= 5.5);                // 020128 new - abk
			
			this.is_ie6   = (this.is_ie && is_major == 6);
			this.is_ie6up = (this.is_ie && is_minor >= 6);

			this.is_ie7 = (this.is_ie && is_minor == 7);	// rev00015
			this.is_ie7up = (this.is_ie && is_minor >= 7);	// rev00016

			this.is_ie8 = (this.is_ie && is_minor == 8);	// rev00018
			this.is_ie8up = (this.is_ie && is_minor >= 8);	// rev00018

			this.is_safari = agt.indexOf("safari") > -1;

			// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
			// or if this is the first browser window opened.  Thus the
			// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
		
			this.is_aol   = (agt.indexOf("aol") != -1);
			this.is_aol3  = (this.is_aol && this.is_ie3);
			this.is_aol4  = (this.is_aol && this.is_ie4);
			this.is_aol5  = (agt.indexOf("aol 5") != -1);
			this.is_aol6  = (agt.indexOf("aol 6") != -1);
			this.is_aol7  = ((agt.indexOf("aol 7")!=-1) || (agt.indexOf("aol7")!=-1));
		
			this.is_webtv = (agt.indexOf("webtv") != -1);
			
			// new 020128 - abk
			
			this.is_AOLTV = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
		
			this.is_hotjava = (agt.indexOf("hotjava") != -1);
			this.is_hotjava3 = (this.is_hotjava && (is_major == 3));
			this.is_hotjava3up = (this.is_hotjava && (is_major >= 3));
			
		    // Done with is_minor testing; revert to real for N6/7
			if (this.is_nav6up) {
				var is_minor = navigator.vendorSub;
			}

		}
		
	}
	LR_BrowserCheck.Initialize();
	
});





// ------------------------------------------------------------------------------------------------------------- //
// ------------------------------------------- // $Array (derivate of Array.prototype) // ------------------------------------------ //
// ------------------------------------------------------------------------------------------------------------- //


LR_LibCore.LoadLibrary("Natives-1.0", "$Revision: 00008 $", function() {


	(function() {
 		// var LR_Object_extend = function(destination, source) {
		/*
		LR_Object_extend = function(destination, source) {
			for (var property in source)
				destination[property] = source[property];
			return destination;
		};
		*/
		LR_LibCore.Object = {};
		
		//LR_LibCore.ObjectExtend = function(destination, source) {
		//	for (var property in source)
		//		destination[property] = source[property];
		//	return destination;
		//};
		LR_LibCore.Object.Extend = function(destination, source) {
			for (var property in source)
				destination[property] = source[property];
			return destination;
		};
	
		//LR_LibCore.ObjectClone = function(object) {
		//	return LR_LibCore.ObjectExtend({ }, object);			
		//};
		LR_LibCore.Object.Clone = function(object) {
			return LR_LibCore.Object.Extend({ }, object);			
		};
	
	
		LR_LibCore.Object.isUndefined = function(object) {
			return typeof object == "undefined";
		};
		isUndefined = LR_LibCore.Object.isUndefined;
		
		//---------------------------- Estendo l'Array.prototype ----------------------------//
	
		$Array = {
			Each: function(fn, bind) {
				try {
					for (var i = 0, l = this.Size(); i < l; i++) fn.call(bind, this[i], i, this);
				} catch (e) {
					if (e != {}) throw e; 
				}
			},
			
			/*
			@description   Returns true if at least one element in the array satisfies the provided testing function. 
			*/
			Some: function(fn, bind){
				for (var i = 0, l = this.Size(); i < l; i++){
					if (fn.call(bind, this[i], i, this)) return true;
				}
				return false;
			},
		
			Add: function(value) {
				if (isArray(this)) this.push(value);
			},
			

			Remove: function(value) {
				for (var i = this.length; i--; i){
					if (this[i] === value) this.splice(i, 1);
				}
				return this;
			},

			/*
			@description   Delete every item in the array, leaving an empty array. 
			*/
			Clear: function() {
				this.splice(0, this.length);
				return this;				
			},
		
			Size: function() {
				if (this.length) return this.length;
				else return 0;
			}
			
		}
		LR_LibCore.Object.Extend(Array.prototype, $Array);


		//---------------------------- LR_Hash: Object extension da usare come se fosse un Object ma ----------------------------//
		//----------------------------          con metodi e proprieta' aggiuntive. Necessario per   ----------------------------//
		//----------------------------          evitare di intaccare l'Object.prototype              ----------------------------//
		
		/*
		$Collection = {
			Each: function(fn, bind) {
				try {
					for (var i = 0, l = this.Size(); i < l; i++) fn.call(bind, this[i], i, this);
				} catch (e) {
					if (e != {}) throw e; 
				}	
			},
			
			Size: function() {
				if (this.length) return this.length;
				else return 0;
			}
		}
		*/
		

		//---------------------------- Estendo String.prototype ----------------------------//

		$String = {
			Size: function() {
				if (this.length) return this.length;
				else return 0;
			},
			
			isEmpty: function() {
				return ((this == null) || (this.length == 0));
			},
			
			lTrim: function() {
				var newstr = this;
				while(newstr.charAt(0) == " ")
					newstr = newstr.substring(1, newstr.length);
				return newstr;
			},
			
			rTrim: function() {
				var newstr = this;
				while(newstr.charAt(newstr.length - 1) == " ") 
					newstr = newstr.substring(0, newstr.length - 1);    
				return newstr;
			},
			
			Trim: function() {
				return this.replace(/^\s+|\s+$/g, '');
			},
			
			// Trasforma la prima lettera di una String in maiuscola e il resto in minuscolo
			Capitalize: function() {
				 return this.replace(/\w+/g, function(a) {
					  return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
				 });
			}

		}
		LR_LibCore.Object.Extend(String.prototype, $String);
		

	})();
	
//	alert('-------------Prima prova----------');
//	
//	var ghi = new Array();
//	ghi.Add('A');
//	ghi.Add('B');
//	ghi.Add('C');
//	ghi.push('123');
//	ghi.Add('789');
//	
//	ghi.Each(function(item, index){alert('Index['+ index +']'+ item) });
//	
//	alert(ghi[3]);
//	
// /* Come risultato da': A, B, C, 123, 789, 123
//	
//	alert('-------------Seconda prova----------');
//	
//	var ERT = new Array('a', 'b', 'c');
//	ERT.Each(function(item, index){alert('Index['+ index +']'+ item) });
//
// /* Come risultato da': a, b, c


});

