MAJOR_VERSION = "WebDocument-2.0";
MINOR_VERSION = parseFloat(("$Revision: 00097 $").match(/\d+/)) - 100000;

IsLoaded = false;
if (typeof(LR_LibCore) != 'undefined') {
	IsLoaded = (LR_LibCore.NewLibrary(MAJOR_VERSION, MINOR_VERSION, "Inheritance-2.0", "BrowserInfo-1.0") != null) ? true : false;
}

if ((typeof(LR_LibCore) != 'undefined' && IsLoaded) || (typeof(LR_LibCore) == 'undefined')) {

/////////////////////////////////

// Testa se sono gia' state dichiarate o meno, in tal caso crea o estende l'oggetto.
// Quando estende l'oggetto sovrascrive i sotto-oggetti se li trova duplicati.
oldLR_GVars = (typeof(LR_GVars)=='undefined') ? { } : LR_GVars;

LR_GVars = {
	ElementTag: {
		INPUT: {
			"hidden" : { subType: 'hidden' },
			"text" : { subType: 'text' },
			"radio" : {	subType: 'radio' },
			"textarea" : { subType: 'textarea' },
			"password" : { subType: 'password' },
			// ------------------------ DA CONTROLLARE! -----------------------------------//
			"checkbox" : {	subType: 'radio' },
			// ------------------------ DA CONTROLLARE! -----------------------------------//
			"button": {	subType: ''	}
		},
		SELECT: {
			"select-multiple" : { subType: 'select' },
			"select-one" : { subType: 'select' }
		},
		OPTION: {
			"option" : { subType: 'select' }
		},
		TR: {

		},
		TD: {
			
		},
		TBODY: {
			
		},
		TABLE: {
			
		},
		DIV: {
			"div": { subType: 'div' }
		}
	},
	
	CSS: {
		Rsrd_Wrds: {
			"for": "htmlFor",
			"class": "className",
			"float": LR_BrowserCheck.Supports.styleFloat,		//styleFloat,
			cssFloat: LR_BrowserCheck.Supports.styleFloat,		//styleFloat,
			styleFloat: LR_BrowserCheck.Supports.styleFloat,	//styleFloat,
			readonly: "readOnly",
			maxlength: "maxLength",
			cellspacing: "cellSpacing",
			rowspan: "rowSpan",
			tabindex: "tabIndex"
		}
	}
}

LR_GVars = LR_LibCore.Object.Extend(LR_GVars, oldLR_GVars || { })
delete oldLR_GVars;


// Note:
// Jquery.props = LR_GVars.CSS.Rsrd_Wrds




LR_CSS = {

	attr: function( name, value, type ) {
		var options = name;

		// Look for the case where we're accessing a style value
		if ( typeof name === "string" )
			if ( value === undefined ) {
				throw "LR_CSS::attr(...) type property can't be changed";
				return this[0] && jQuery[ type || "attr" ]( this[0], name );
			} else {
				options = {};
				options[ name ] = value;
			}

			// Set all the styles
			for ( name in options )
				this.__attr(type ? this.$Obj.style : this, name, this.prop(this, options[name], type, 0, name));
	},

	__attr: function(elem, name, value) {
		// don't set attributes on text and comment nodes
		if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
			return undefined;

		var notxml = !this.isXMLDoc( elem ),
			// Whether we are setting (or getting)
			set = value !== undefined;

		// Try to normalize/fix the name
		name = notxml && LR_GVars.CSS.Rsrd_Wrds[ name ] || name;

		// Only do all the following if this is a node (faster for style)
		// IE elem.getAttribute passes even for style
		if ( elem.tagName ) {

			// These attributes require special treatment
			var special = /href|src|style/.test( name );

			// Safari mis-reports the default selected property of a hidden option
			// Accessing the parent's selectedIndex property fixes it
			if ( name == "selected" && elem.parentNode )
				elem.parentNode.selectedIndex;

			// If applicable, access the attribute via the DOM 0 way
			if ( name in elem && notxml && !special ) {
				if ( set ){
					// We can't allow the type property to be changed (since it causes problems in IE)
					if ( name == "type" && this.nodeName( elem, "input" ) && elem.parentNode )
						throw "type property can't be changed";

					elem[ name ] = value;
				}

				// browsers index elements by id/name on forms, give priority to attributes.
				if( this.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
					return elem.getAttributeNode( name ).nodeValue;

				// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
				// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
				if ( name == "tabIndex" ) {
					var attributeNode = elem.getAttributeNode( "tabIndex" );
					return attributeNode && attributeNode.specified
						? attributeNode.value
						: elem.nodeName.match(/(button|input|object|select|textarea)/i)
							? 0
							: elem.nodeName.match(/^(a|area)$/i) && elem.href
								? 0
								: undefined;
				}

				return elem[ name ];
			}

			if ( !LR_BrowserCheck.Supports["style"] && notxml &&  name == "style" )
				return jQuery.attr( elem.style, "cssText", value );

			// convert the value to a string (all browsers do this but IE) see #1070
			if ( set ) elem.setAttribute( name, "" + value );

			var attr = !LR_BrowserCheck.Supports["hrefNormalized"] && notxml && special
					// Some attributes require a special call on IE
					? elem.getAttribute( name, 2 )
					: elem.getAttribute( name );

			// Non-existent attributes return null, we normalize to undefined
			return attr === null ? undefined : attr;
		}

		// elem is actually elem.style ... set the style

		// IE uses filters for opacity
		if ( !LR_BrowserCheck.Supports["opacity"] && name == "opacity" ) {
			if ( set ) {
				// IE has trouble with opacity if it does not have layout. Force it by setting the zoom level
				elem.zoom = 1;

				// Set the alpha filter to set the opacity
				elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
					(parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
			}

			return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
				(parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
				"";
		}

		name = name.replace(/-([a-z])/ig, function(all, letter){
			return letter.toUpperCase();
		});

		if ( set )
			elem[ name ] = value;

		return elem[ name ];
	},

	CSS: function(key, value) {
		// ignore negative width and height values
		if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
			value = undefined;
		return this.attr( key, value, "curCSS" );
	},
	
	
	prop: function( elem, value, type, i, name ) {
		// Handle executable functions
		if ( isFunction( value ) )
			value = value.call( elem, i );

		// Handle passing in a number to a CSS property
		return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ? value + "px" : value;
	},
	
	
	// check if an element is in a (or is an) XML document
	isXMLDoc: function( elem ) {
		return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
			!!elem.ownerDocument && isXMLDoc( elem.ownerDocument );
	},

	nodeName: function( elem, name ) {
		return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
	}


}




LR_Element = Class.extend ({
	include: [LR_CSS],
	
	initialize: function(element) {
		this.Obj = element;
		this.$Obj = $$A(this.Obj);

		//if (!(this.Obj)) {
		if ( !(this.Obj)  ||  ( isUndefined(this.Obj.tagName) ? (isUndefined(this.Obj[0]) ? true : !(this.Obj[0].tagName) ) : !(this.Obj.tagName) )  ) {
			var errorString;
			errorString = 'LR_Element::initialize(...) Can\'t find element called {0}, designed to be in the form called {1}.\n'.format(this.Name, this.Form);
			if (LR_Event.IsDOMLoaded() == false) 
				errorString += 'DOM not loaded yet, something could be broken.\n';
			alert(errorString);
			return;
		}

		//this.Tag = (isUndefined(this.Obj.tagName) ? this.Obj[0].tagName : this.Obj.tagName).toString().toUpperCase();
		this.Tag = isUndefined(this.$Obj.tagName) ? (isUndefined(this.$Obj[0].tagName) ? 'undefined' : this.$Obj[0].tagName) : this.$Obj.tagName;
		if (!isUndefined(this.Tag)) this.Tag = this.Tag.toString().toUpperCase();

		if (this.Tag == 'SELECT' || this.Tag == 'INPUT') {
			this.Name = (isUndefined(this.$Obj.name) ? this.$Obj[0].name : this.$Obj.name);
		} else if (this.Tag == 'OPTION') {
			// does nothing. This is a fix for IE8 and how it traits SELECT tags.
		} else {
			this.Name = 'undefined';		//Se non c'e' il nome
		}

		//   /radio|checkbox/.test(this.type)

		this.Type = this.FindType(this.$Obj);
		


		/*
		function $arguments(i){
			return function(){
				return arguments[i];
			};
		}
		*/
		
	},

	Test: function() {
		var Return = '';
		
		if (this.Type) {
			Return += 'Type.subType: '+ this.Type.subType +'\n';
		}
		Return += 'this.Tag: '+ this.Tag +'\n';
		Return += 'this.Name: '+ this.Name +'\n';
		Return += 'this.Size: '+ this.Size() + '\n';
		
		return Return;
	},

	
	Insert: function(position, element) {
		var i, found, t;
		
		if ((element instanceof LR_Element)) {
			element = element.Obj;
		} else {
				
		}
		
		//Controllo che Position sia un argomento valido
		enabled_insertions = ['before', 'after', 'top', 'bottom'];
		
		found = false;
		for (i = 0; i < enabled_insertions.length; i++) {
			if (enabled_insertions[i] == position) {
				found = true;
			}
		}
		if (found == false) { alert('LR_Element.Insert - #0 argument is not valid.'); return; }
		
		// Inizio il processo
		//element = ((position == 'before' || position == 'after') ? element.parentNode : element);

		switch (position) {
			case 'before': t = function(element, node) { element.parentNode.insertBefore(node, element); }; break;
			case 'after': t = function(element, node) { element.parentNode.insertBefore(node, element.nextSibling); }; break;
			case 'top': t = function(element, node) { element.insertBefore(node, element.firstChild); }; break;
			case 'bottom': t = function(element, node) { element.appendChild(node); }; break;
			//default: result = 'unknown';
		}

/*
		this.Tag = ''
		  tags: {
			TABLE:  ['<table>',                '</table>',                   1],
			TBODY:  ['<table><tbody>',         '</tbody></table>',           2],
			TR:     ['<table><tbody><tr>',     '</tr></tbody></table>',      3],
			TD:     ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
			SELECT: ['<select>',               '</select>',                  1]
		  }

Element._getContentFromAnonymousElement = function(tagName, html) {
  var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
  if (t) {
    div.innerHTML = t[0] + html + t[1];
    t[2].times(function() { div = div.firstChild });
  } else div.innerHTML = html;
  return $A(div.childNodes);
};
*/


		t(element, this.Obj);




		/*
		Element._insertionTranslations = {
		  before: function(element, node) {
			element.parentNode.insertBefore(node, element);
		  },
		  top: function(element, node) {
			element.insertBefore(node, element.firstChild);
		  },
		  bottom: function(element, node) {
			element.appendChild(node);
		  },
		  after: function(element, node) {
			element.parentNode.insertBefore(node, element.nextSibling);
		  },
		  tags: {
			TABLE:  ['<table>',                '</table>',                   1],
			TBODY:  ['<table><tbody>',         '</tbody></table>',           2],
			TR:     ['<table><tbody><tr>',     '</tr></tbody></table>',      3],
			TD:     ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
			SELECT: ['<select>',               '</select>',                  1]
		  }
		};
		*/

	},


	// Corretta
	GetValue: function() {
		var Result = '';
		var i;
		
		/*
		if (this.Obj.length) {
			for (i = 0; i < this.Obj.length; i++) {
				if (this.Tag == 'SELECT') {
					if (this.Obj.options[i].selected) Result += (Result=='' ? this.Obj[i].value : ', '+this.Obj[i].value);
				} else if (this.Tag == 'OPTION') {
					if (this.Obj[i].selected == true) Result += (Result=='' ? this.Obj[i].value : ', '+this.Obj[i].value);
				} else if (this.Tag == 'INPUT') {
					if ((this.Type.subType == 'radio') && (this.Obj[i].checked)) Result += (Result=='' ? this.Obj[i].value : ', '+this.Obj[i].value);
				}
			}
		} else {
			if (this.Tag == 'INPUT') {
				if ((this.Type.subType == 'text') || (this.Type.subType == 'hidden') || (this.Type.subType == 'password')) { Result = this.Obj.value; }
				else if ((this.Type.subType == 'radio') && (this.Obj.checked)) { Result = this.Obj.value; }
			} else if (this.Tag == 'SELECT' || this.Tag == 'OPTION') {
				Result = '';
			} else {
				Result = this.Obj.innerHTML;
			}
		}
		*/
		
		this.Each(function(el, i){
			if (/SELECT|OPTION/.test(this.Tag)) {
				if (el.selected == true) Result += (Result=='' ? el.value : ', '+el.value);
			} else if (this.Tag == 'INPUT') {
				if ((this.Type.subType == 'radio') && (el.checked)) Result += (Result=='' ? el.value : ', '+el.value);
				//if ((this.Type.subType == 'text') || (this.Type.subType == 'hidden') || (this.Type.subType == 'password')) { Result = this.Obj.value; }
				if (/text|hidden|password/.test(this.Type.subType)) { Result = el.value; }
			} else {
				try {	Result = el.innerHTML; } catch(e) { Result = null; }
			}
		}, this)
		
		return Result;
	},


	SetValue: function(Value) {
		/*
		if (this.Obj.length) {
			for (i = 0; i < this.Obj.length; i++) {
				if ((this.Type.subType == 'radio') && (this.Obj[i].value == Value)) { this.Obj[i].checked = true; }
				else if ((this.Type.subType == 'select') && (this.Obj[i].value == Value)) { this.Obj[i].selected = true; };
			}
		} else {
			if (this.Tag == 'INPUT') {
				if ((this.Type.subType == 'text') || (this.Type.subType == 'hidden')) { this.Obj.value = Value; }
				else if ((this.Type.subType == 'radio') && (this.Obj.checked)) { this.Obj.value = Value; }
			} else {
				this.Obj.innerHTML = Value;
			}
		}
		*/
		this.Each(function(el, i){
			if (this.Tag == 'INPUT') {
				if ((this.Type.subType == 'radio') && (el.value == Value)) { el.checked = true; }
				else if (/text|hidden|password/.test(this.Type.subType)) { el.value = Value; }
			} else if (this.Type.subType == 'select') {
				if (el.value == Value) { el.selected = true; }				
			} else {
				this.Obj.innerHTML = Value;
			}
		
		}, this)
								 
	},
	
	
	GetAttribute: function(Name) {
		if (Name.toLowerCase() == 'value') {
			return this.GetValue();
		} else {
			return this.Obj.getAttribute(Name);
		}
	},
	

	SetAttribute: function(Name, Value) {
		if (Name.toLowerCase() == 'value') {
			this.SetValue(Value);
		} else {
			this.Obj.setAttribute(Name, Value);
		}
	},
	

	Show: function() {
		this.$Obj.style.display = '';
		if (this.$Obj.style.visibility) this.$Obj.style.visibility = 'visible';
	},
	
	
	Hide: function() {
		this.$Obj.style.display = 'none';
		if (this.$Obj.style.visibility) this.$Obj.style.visibility = 'hidden';
	},


	// Da testare e da vedere se lasciare qui o trasportare altrove
	Create: function(tag) {
		
	},	
	
	FindType: function(Obj) {
		var TIPO;

		try {	TIPO = Obj.type.toLowerCase(); }
		catch (err) {	}

		if (typeof(TIPO) == 'undefined') {
			try {	TIPO = Obj[0].type.toLowerCase(); }
			catch (err) {
				try {	TIPO = Obj.nodeName.toLowerCase(); }
				catch (err) {
					try {	TIPO = Obj[0].nodeName.toLowerCase(); }
					catch (err) { return null; }
				}
			}
		}
		// alert('>N1 '+ this.Tag +'\n'+ '>N2 '+ TIPO +'\n'+ '>N3 '+ LR_GVars.ElementTag[this.Tag][TIPO]);
		
		if (LR_GVars.ElementTag[this.Tag]) {
			if (LR_GVars.ElementTag[this.Tag][TIPO])
				return LR_GVars.ElementTag[this.Tag][TIPO];
			else
				return null;
		}
	}

});


LR_WebDocument = Class.create();

LR_WebDocument = Class.extend({

	initialize: function() {
		// Initialize the Validator
		//this.Forms = Forms;

		// initialize the WebControl referement
		//this.WebControl = WebControl;
		this.Items = new Array();
	},
	
	
	//document.forms[number].elements
	
	// Da testare e da inserire nella concezione del nuovo LR_WebDocument
	Forms: function (Form) {
		var Result, formsList, tmpArray;
		var nomeTmp;
		
		//Ottiene la collection di forms
		formsList = document.forms;
		if (formsList) {
			if (formsList.length) {
				var tmpArray = [];
				for (var i = 0; i < formsList.length; i++) tmpArray.push(formsList[i]);
				formsList = tmpArray;
			}
		} else formsList = null;

		//Cerca una form (se specificato)
		if (arguments.length == 1) {
			if (isInt(Form)) {
				//Result = formsList[Form];
				var tmpArray = [];
				for (var i = 0; i < formsList[Form].length; i++) tmpArray.push(formsList[Form][i]);
				Result = tmpArray;
			} else {
				for(var x = 0; x < formsList.length; x++) {
					if (formsList[x].name == Form)  {
						var tmpArray = [];
						for (var i = 0; i < formsList[x].length; i++) {
							nomeTmp = formsList[x][i].name;
							if (isString(nomeTmp) && nomeTmp != '')	tmpArray.push(new LR_WebControl(x, nomeTmp));
						}
						Result = tmpArray;
					} else Result = null;
				}
			}
		}

		return Result;
	},
	
	WebControl: function (Form, Name) {
		var x, I_Found, I_New;
		var Found = false;
		
		if (!(this.Items[Form])) {
			this.Items[Form] = new Array();
		}

		for(var x = 0; x < this.Items[Form].length; x++) {
			if (this.Items[Form][x].Name == Name) {
				Found = true;
				I_Found = x;
			}
		}
		
		if (!(Found)) {
			I_New = this.Items[Form].length;

			this.Items[Form][I_New] = new LR_WebControl(Form, Name);
			return this.Items[Form][I_New];
		} else {
			return this.Items[Form][I_Found];
		}
	},
	
	// Generic function to retrieve an element inside the document
	WebElement: function(Identifier) {
		return new LR_Element(FindElement(Identifier));
	}

});




LR_WebControl = Class.extend(LR_Element, {

	initialize: function(Form, Name, Source) {
		// initialize the member variables for this instance
		this.Form = Form;
		this.Name = Name;

		if (Source) {
			this.parent(FindElement(Name, Source));
		} else {
			this.parent(FindElement(Name));
			// alert('>1 '+ this.Obj +'\n>2 '+ this.Tag +'\n>3 '+ this.Type +'\n>4 '+ this.Name +'\n>Test \n'+ this.Test());
		}
		// alert('>1 '+ this.Obj +'\n>2 '+ this.Tag +'\n>3 '+ this.Type +'\n>4 '+ this.Name +'\n>Test \n'+ this.Test());


		//alert(this.Type.subType);
		if (this.Type) {
			if (this.Type.subType == "select") {	// -----SELECT tag-----
				//this["IsSelected"] = null;
	
				this["AddOption"] = (function(name, value, position) {
					try{
					 if (isUndefined(position)) this.$Obj.add(new Option(name, value), null) //add new option to end of "sample"
					 else this.$Obj.add(new Option(name, value), this.$Obj[position])
					 //myselect.add(new Option("New First Option", "0"), myselect.options[0]) //add new option to beginning of "sample"
					}
					catch(e){ //in IE, try the below version instead of add()
					 if (isUndefined(position)) this.$Obj.add(new Option(name, value)) //add new option to end of "sample"
					 else this.$Obj.add(new Option(name, value), position)
					 //myselect.add(new Option("New First Option", "0"), 0) //add new option to beginning of "sample"
					}
				})
				
				this["RemoveOption"] = (function(position) {
					this.$Obj.remove(position);
				})
				
				this["RemoveAll"] = (function() {
					this.Each(function(el, i) { this.$Obj.remove(0) }, this)
				})
				
			}
		}
	},


	//Funzionante
	Click: function (Value)	{
		if (this.Obj.length) {
			for (i = 0; i < this.Obj.length; i++) {
				if (this.Obj[i].value == Value) { this.Obj[i].click(); }
			}
		} else {
			if (this.Obj.value == Value) { this.Obj.click(); }
		}
	},

	Selected: function(YesNo, Value) {
		var ApplyToAll = (Value==null ? true : false);
		YesNo = Boolean(YesNo);
		
		this.Each(function (el, i){
			if (this.Size() > 0) {
				if ((this.Tag == 'OPTION') || (this.Tag == 'SELECT')) {
					if (el.value==Value) el.selected = YesNo;
				} else {
					throw ('LR_WebControl::Selected(...) Case not coded.');
				}
			} else {
				el.selected = YesNo;
			}
		}, this)
	},

	IsChecked: function(Value) {	// Funzione corretta - da prendere come riferimento
		var ApplyToAll = (Value==null ? true : false);
		Result = false;
		
		if (this.Obj.length) {
			//alert ('multiple choice - index: '+ this.ObjControl.length);
			for (i = 0; i < this.Obj.length; i++) {
				//alert ('choice ['+ i +']'+ this.ObjControl[i].checked);
				if (ApplyToAll) { if (this.Obj[i].checked) { Result = true; }; }
				else if	(this.Obj[i].value == Value) { if (this.Obj[i].checked) { Result = true; }; }
			}
		} else {
			if ( (this.Obj.value == Value) || (ApplyToAll == true) ) { if (this.Obj.checked) { Result = true; }; }
		}
		
		return Result;
	},


	IsSelected: function(Value) {
		var ApplyToAll = (Value==null ? true : false);
		Result = false;
		
		if (this.Obj.length) {
			//alert ('multiple choice - index: '+ this.Obj.length);
			for (i = 0; i < this.Obj.length; i++) {
				//alert ('choice ['+ i +']'+ this.Obj[i].selected);
				if (ApplyToAll) { if (this.Obj[i].selected) { Result = true; }; }
				else if	(this.Obj[i].value == Value) { if (this.Obj[i].selected) { Result = true; }; }
			}
		} else {
			if ( (this.Obj.value == Value) || (ApplyToAll == true) ) { if (this.Obj.selected) { Result = true; }; }
		}
		
		return Result;
	},


	IsDisabled: function(Value) {
		var ApplyToAll = (Value==null ? true : false);
		
		if (this.Type.subType == 'select') {
			if (this.$Obj.disabled) return true; else return false;
			return;
		}

		this.Each(function (el, i) {
			if (ApplyToAll) { if (el.disabled) return true; else return false; }
			else if (el.value = Value) { if (el.disabled) return true; else return false; }
		})
	},

	Checked: function (YesNo, Value) {	// Funzione corretta - da prendere come riferimento
		var ApplyToAll = (Value==null ? true : false);
		YesNo = Boolean(YesNo);
		
		if (this.Obj.length) {
			for (i = 0; i < this.Obj.length; i++) {
				//alert ('ApplyToAll? '+ ApplyToAll +' --- Is Array? '+ isArray(Value));
				if (ApplyToAll) {
					this.Obj[i].checked = YesNo;
				} else {
					if (isArray(Value)) {
						for (ii = 0; ii < Value.length; ii++) {
							//alert (Value[ii]);
							if (this.Obj[i].value == Value[ii]) this.Obj[i].checked = YesNo;
						}
					} else {
						if (this.Obj[i].value == Value) this.Obj[i].checked = YesNo;
					}
				}
			}
		} else {
			if ( (this.Obj.value == Value) || (ApplyToAll == true) ) { this.Obj.checked = YesNo; }
		}
	},


	Disabled: function (YesNo, Value) {	// Funzione corretta - da prendere come riferimento
		var ApplyToAll = (Value==null ? true : false);
		YesNo = Boolean(YesNo);
		
		if (this.Tag == 'SELECT') {
			this.$Obj.disabled = YesNo;
			return;
		}
		
		this.Each(function(el, i) {
			if (ApplyToAll) {
				el.disabled = YesNo;
			} else {
				if (isArray(Value)) {
					Value.Each(function(el, ii) {
						if (this.el.value == el[ii]) this.el.disabled = YesNo;
					}, this)
				} else {
					if (el.value == Value) el.disabled = YesNo;
				}
			}									 
		})
		
		/*
		if (this.Obj.length) {
			for (i = 0; i < this.Obj.length; i++) {
				//alert ('ApplyToAll? '+ ApplyToAll +' --- Is Array? '+ isArray(Value));
				if (ApplyToAll) {
					this.Obj[i].disabled = YesNo;
				} else {
					if (isArray(Value)) {
						//alert (ApplyToAll);					
						for (ii = 0; ii < Value.length; ii++) {
							if (this.Obj[i].value == Value[ii]) this.Obj[i].disabled = YesNo;
						}
					} else {
						if (this.Obj[i].value == Value) this.Obj[i].disabled = YesNo;
					}
				}
			}
		} else {
			if ( (this.Obj.value == Value) || (ApplyToAll == true) ) { this.Obj.disabled = YesNo;	}
		}
		*/
	},

	IsReadOnly: function() {	// Funzione corretta
		var Result = false;
		
		if (this.Obj.readOnly == true) { Result = true; }
		return Result;
	},

	ReadOnly: function(YesNo) {		// Funzione corretta
		YesNo = Boolean(YesNo);
		this.Obj.readOnly = YesNo;
	}

});




LR_WebDocumentParent = Class.extend (LR_WebDocument, {
	
   initialize: function() {
		this.parent();
	},

	WebControl: function (Form, Name) {
		var x, I_Found, I_New;
		var Found = false;
		
		if (!(this.Items[Form])) {
			this.Items[Form] = new Array();
		}

		for(var x = 0; x < this.Items[Form].length; x++) {
			if (this.Items[Form][x].Name == Name) {
				Found = true;
				I_Found = x;
			}
		}
		
		if (!(Found)) {
			I_New = this.Items[Form].length;
			this.Items[Form][I_New] = new LR_WebControl(Form, Name, window.opener);

			return this.Items[Form][I_New];
		} else {
			return this.Items[Form][I_Found];
		}
	}
	
	
});




FindElement = function(Identifier, Relative) {
	
	function getElementsByTagNames(list,obj) {
		if (!obj) var obj = document;
		var tagNames = list.split(',');
		var resultArray = new Array();
		for (var i=0;i<tagNames.length;i++) {
			var tags = obj.getElementsByTagName(tagNames[i]);
			for (var j=0;j<tags.length;j++) {
				resultArray.push(tags[j]);
			}
		}
		var testNode = resultArray[0];
		if (!testNode) return [];
		if (testNode.sourceIndex) {
			resultArray.sort(function (a,b) {
					return a.sourceIndex - b.sourceIndex;
			});
		}
		else if (testNode.compareDocumentPosition) {
			resultArray.sort(function (a,b) {
					return 3 - (a.compareDocumentPosition(b) & 6);
			});
		}
		return resultArray;
	}

	//------------	
	
	var element, i;
	if (!(Relative)) {
		Relative = this.window;
	}
	
	if (document.getElementById) {	// IE 6 >= - Firefox 2 >=
		element = Relative.document.getElementById(Identifier);

		if (LR_BrowserCheck.is_ie6 || LR_BrowserCheck.is_ie7)  {	// IE 6-7 fix - don't retrieve NAME instead of ID
			//alert('1> Element: '+ element);
			var found = false; var tmpElement;
			if (element) {
				if (!(element.attributes['id'].value == Identifier)) {				//make sure that it is a valid match on id
					for(var i=1;i<Relative.document.all[Identifier].length;i++) {	//otherwise find the correct element
						//alert(document.all[Identifier][i].attributes['id'].value);
						if(Relative.document.all[Identifier][i].attributes['id'].value == Identifier) {
							element = Relative.document.all[Identifier][i];
							//alert('IE6-IE7');
						}
					}
					//alert ('Found: '+ found);
					if (found == false) element = null;
				}
			}
		} else if (LR_BrowserCheck.is_ie8) {
			if (element) {
				if ((document.getElementsByName) && (element != null)) {	//fix for SELECT tag
					element = Relative.document.getElementsByName(Identifier);
					//	alert('Trovato l\'element in IE8\n'+'id.value: '+ element.attributes['id'].value +'\n'+'name.value: '+ element.attributes['name'].value);
				}
			}
		}

		//alert('element: '+ element);

		if ((document.getElementsByName) && (element == null)) {	//Firefox doesn't see NAME tag as ID tag, like IE 6-7 does
			element = Relative.document.getElementsByName(Identifier);
//			alert('Firefox Mode: '+ element);
		}
		

	} else if (document.all) {
		element = Relative.document.all[Identifier];
		//alert('GetElement 2');
	} else if (document.layers) {
		element = Relative.document.layers[Identifier];
		//alert('GetElement 3');
	}
	
//	alert ('Return: '+ element);
	return element;
};



$LR_Collection = {
	Each: function(fn, bind) {
		try {
			//for (var i = 0, l = this.Size(); i < l; i++) fn.call(bind, this.Obj[i], i, this.Obj);

			if (this.Size() == 0)
				fn.call(bind, this.$Obj);
			else
				for (var i = 0, l = this.Size(); i < l; i++) fn.call(bind, this.$Obj[i], i, this.$Obj);
		} catch (e) {
			if (e != {}) throw e; 
		}	
	},
	
	Size: function() {
		if (this.$Obj.length) return this.$Obj.length;
		else return 0;
	}

}


LR_LibCore.Object.Extend(LR_Element.prototype, $LR_Collection);
LR_LibCore.Object.Extend(LR_WebControl.prototype, $LR_Collection);
LR_LibCore.Object.Extend(LR_WebDocument.prototype, $LR_Collection);

}
