MAJOR_VERSION = "ShowHide-1.0";
MINOR_VERSION = parseFloat(("$Revision: 00168 $").match(/\d+/)) - 100000;

IsLoaded = false;
if (typeof(LR_LibCore) != 'undefined') {
	IsLoaded = (LR_LibCore.NewLibrary(MAJOR_VERSION, MINOR_VERSION) != null) ? true : false;
}

if ((typeof(LR_LibCore) != 'undefined' && IsLoaded) || (typeof(LR_LibCore) == 'undefined')) {



function LR_ShowHideAnything() {

	function Constructor() {
		// Debug
		this.Debug = false;

		// Properties
		this.get_ShowImage = function () { return this.ShowImage };
		this.set_ShowImage = function (vNewValue) { this.ShowImage = vNewValue; };

		this.get_HideImage = function () { return this.HideImage };
		this.set_HideImage = function (vNewValue) { this.HideImage = vNewValue; };


		// initialize the Validator referement
		this.Items = new Array();


		//////////////////////////////////////
		
		
		this.ShowHide = ShowHide;
		
		this.ShowHideAll = ShowHideAll;
		this.IsShowAllActive = function () { return this.ShowAllActive };
		
		this.Groups = Array();
		this.CreateGroup = CreateGroup;
		this.Group = Group;
		this.ShowHideGroup = ShowHideGroup;
		
	}
	
	
	function ShowHide(menuID, Cmd) {
		var menuObj, imageObj, ImageExists, ObjExists, cObjStyle, cObjImage, cObjMenu;
		
		//alert('menuID: ' + menuID + ' - Cmd: ' + Cmd);		
		menuObj = "Link" + menuID;
		imageObj = "Image" + menuID;
	
		//function to determine an element with a specified id
		if (document.getElementById) { // DOM3 = IE5, NS6
			//document.getElementById(id).style.display = 'none';
	
			ImageExists = (document.getElementById(imageObj) ? true : false);
			ObjExists = (document.getElementById(menuObj) ? true : false);
			if (document.getElementById(imageObj)) { cObjImage = document.getElementById(imageObj); }
			if (document.getElementById(menuObj)) {	cObjMenu = document.getElementById(menuObj); }
	
			cObjStyle = document.getElementById(menuObj).style;
		} else {	// IE 4
			//document.all.id.style.display = 'none';
	
			ImageExists = (document.all.item(imageObj) ? true : false);
			ObjExists = (document.all.item(menuObj) ? true : false);
			if (document.all.item(imageObj)) { cObjImage = document.all.item(imageObj); }
			if (document.all.item(menuObj)) { cObjMenu = document.all.item(menuObj); }
	
			cObjStyle = document.all.item(menuObj).style;
		}
	
	
		if (ObjExists) {
			if (Cmd == 'Show') {
				cObjStyle.display = '';
				if (ImageExists) { cObjImage.src = this.HideImage; }
			} else if (Cmd == 'Hide') {
				cObjStyle.display = 'none';
				if (ImageExists) { cObjImage.src = this.ShowImage; }
			} else {
				if (cObjStyle.display == '') {
					cObjStyle.display = 'none';
					if (ImageExists) { cObjImage.src = this.ShowImage; }
				} else {				
					cObjStyle.display = '';
					if (ImageExists) { cObjImage.src = this.HideImage; }
				}
			}
		}
	}


	function ShowHideAll(BeginID, EndID) {
		var Operazione, IDCorrispondente;
		var argv = ShowHideAll.arguments;		// ARRAY OF ARGUMENT VALUES
		var argc = argv.length;					// THE NUMBER OF ARGUMENTS PASSED TO THIS FUNCTION
		// Se c'e' un solo parametro BeginID conta come EndID, ovvero parte sempre da Link001 per arrivare a Link<BeginID>
		// Se ci sono due parametri si parte sempre da Link<BeginID> per arrivare a Link<EndID>
	
		if (this.ShowAllActive == 1) {
			Operazione = 'Hide';
			this.ShowAllActive = 0;
		} else {
			Operazione = 'Show';
			this.ShowAllActive = 1;
		}
	
		for (var i=0;i < document.all.length;i++) {
			if (document.all[i].id.indexOf('Link') > -1) {
				IDCorrispondente = document.all[i].id.substr(4, document.all[i].id.length - 4);
				if (argc == 0) {
					this.ShowHide(IDCorrispondente, Operazione);
				} else if (argc == 1) {
					if (IDCorrispondente <= BeginID) { this.ShowHide(IDCorrispondente, Operazione); }
				} else if (argc == 2) {
					if ((IDCorrispondente <= EndID) && (IDCorrispondente >= BeginID)) { this.ShowHide(IDCorrispondente, Operazione); }
				}
			}
		}
	}




	function ShowHideGroup(IDGroup, Cmd) {
		var ItemList, i, ii;
		
		ItemList = this.Group(IDGroup);
	
		for (var i=0; i < ItemList.Length(); i++) {
			ii = ItemList.Items[i];
			if (document.all["Link"+ii]) {
				//IDCorrispondente = document.all[ii].id.substr(4, document.all[ii].id.length - 4);
				this.ShowHide(ii, Cmd);
				//eval('SH_ShowHide(ii, "'+ Cmd +'");');
			}
		}
	}
	
	
	function SH_GroupByRange (IDGroup, MinItem, MaxItem) {
		var ItemList = "";
	
		for (var i=0; i < (MaxItem - MinItem); i++) {
			ItemList = ItemList + i + ", ";
		}
		this.Groups[IDGroup] = new Array(1);
		this.Groups[IDGroup][0] = ItemList.substr(0, ItemList.length - 2);	// Lista degli elementi
	}
	
	
	function SH_GroupByList (IDGroup, ItemList) {
		this.Groups[IDGroup] = new Array(1);
		this.Groups[IDGroup][0] = ItemList;									// Lista degli elementi
	}


	function CreateGroup(IDGroup, Param1, Param2) {
		var Found, x, ItemsArray, Param1, Param2;
		var argv = CreateGroup.arguments;		// ARRAY OF ARGUMENT VALUES
		var argc = argv.length;					// THE NUMBER OF ARGUMENTS PASSED TO THIS FUNCTION
		// Se ci sono due parametri <Param1> conta come lista di elementi, inserita come stringa e separati da <,>, contenenti l'ID dei Link
		// Se ci sono tre parametri <Param1> e' l'inizio dell'Array per il nuovo gruppo e <Param2> ne determina la fine

		Found = false;
		for(var x = 0; x < this.Groups.length; x++) {
			if (this.Groups[x].Name == IDGroup) {
				if (this.Debug == true) { alert('Found ['+ IDGroup +']. No need to add new one.'); }
				Found = true;
			}
		}

		if (!(Found)) {
			if (this.Debug == true) { alert('Added ['+ IDGroup +'] as Group ID '+ this.Groups.length +'.'); }
			this.Groups[this.Groups.length] = SH_Group(IDGroup);
		}
		
		if (argc > 1) {
			if (argc == 2) {
				if (typeof(argv[1]) != 'string') {
					return
				}

				ItemsArray = argv[1].split(", ");
				for (i=0; i<ItemsArray.length; i++) {
					this.Group(IDGroup).Add(ItemsArray[i]);
				}
			} else if (argc == 3) {
				Param1 = argv[1];
				Param2 = argv[2];
				
				for (i=Param1; i<=Param2; i++) {
					this.Group(IDGroup).Add(i);
				}
				
			}
		}
	}


	function Group(Name) {
		var Found, x, I_Found;
		
		Found = false;
		for(var x = 0; x < this.Groups.length; x++) {
			if (this.Groups[x].Name == Name) {
				Found = true;
				I_Found = x
			}
		}
		if (Found) { return this.Groups[I_Found]; }
	}





	//--------------------------------------------------------------------------------------//
	function SH_Group(Name) {
	
		function Constructor() {
			// initialize the member variables for this instance
			this.Name = Name;
			this.Items = new Array();
	
			// initialize the member function references
			this.Add = Add;
			this.Length = Length;
		}


		function Add(Value, Bool) {
			this.Items.push(Value);
		}
		

		function Length() {
			return this.Items.length;
		}

		return new Constructor();
	}
	//--------------------------------------------------------------------------------------//



	return new Constructor();
}



}
