/*
 * Copyright 2008-2010 Eduards Samersovs <eduards.samersovs@lotusmedia.lv>
 * This software is part of LotusMedia CMS
 * All Rigth Reserved
 *
 * Modification History:
 * Rev# Date        By  CR#   Reason
 * 1.0  2008-07-21  ES        Initial version
 * 1.1  2010-07-24  ES        fixed
 */
if (!UI) { var UI = new Object(); };

// Constants
UI.Constants = {
	PARAM_MENU_ID : 'menuId'
};

// Settings
UI.Settings = {
	sPathIcons : '',
	setPathIcons :
		function(sPath) {
			this.sPathIcons = sPath;
	    },
	getPathIcons :
		function() {
			return this.sPathIcons;
	    }
};

// Labels
UI.Labels = {
	sLanguage : 'en',
	aLabels : new Array(),
	init :
		function(sLanguage, aLabels) {
			this.aLanguage = sLanguage;
			this.aLabels = aLabels;
	    },
	find :
		function(sName, sDefaultLabel) {
			nSize = this.aLabels.length;
			for (var i = 0; i < nSize; i++) {
				if (this.aLabels[i][0] == sName) {
					return this.aLabels[i][1];
				}
			}
			return sDefaultLabel;
	    },
	trace :
		function() {
			var trace = 'UI.Labels ';
			for (var i = 0; i < this.aLabels.length; i++) {
				trace = trace+"\n"+ 'name='+this.aLabels[i][0] +', value='+this.aLabels[i][1] +"\n";
			}
			alert(trace);
	    }
};

// ListCreator methods
UI.ListCreator = {
	aListCreator : new Array(),
	bIsReadonly : false,
	create :
		function(sObjectName, bIsReadonly) {
			try {
				this.aListCreator[this.aListCreator.length] = new Array(sObjectName, new Array());
				this.bIsReadonly = bIsReadonly;
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	addElement :
		function(sObjectName, sIdentifier, sLabel) {
			try {
				if (sObjectName.length > 0 && sIdentifier.length > 0 && sLabel.length > 0) {
			    	// loop object list
					nOuterSize = this.aListCreator.length;
					for (var i = 0; i < nOuterSize; i++) {
						if (this.aListCreator[i][0] == sObjectName) {
							var isRewrite = false;
							// loop elements
							nInnerSize = this.aListCreator[i][1].length;
							for (var n = 0; n < nInnerSize; n++) {
								// rewrite element value
								if (this.aListCreator[i][1][n][0] == sIdentifier) {
									this.aListCreator[i][1][n][1] = sLabel;
									isRewrite = true;
									break;
								}
							}
							// add
							if (!isRewrite) {
								this.aListCreator[i][1][this.aListCreator[i][1].length] = new Array(sIdentifier, sLabel);
							}
						}
					}
					// display
					this.display(sObjectName);
				}
		    } catch (e) {
		    	//alert(e);
		    }
			//UI.ListCreator.trace('addElement');
	    },
    addElementFromListbox :
		function(sObjectName) {
			try {
		    	sListboxObjectName = sObjectName+'_listbox';
		    	oListbox = document.getElementById(sListboxObjectName);
		    	if (oListbox != null) {
			    	sIdentifier = oListbox.options[oListbox.selectedIndex].value;
			    	sLabel = oListbox.options[oListbox.selectedIndex].text;
			    	// add
			    	this.addElement(sObjectName, sIdentifier, sLabel);
		    	}
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	removeElement :
		function(sObjectName, sIdentifier) {
			try {
				if (sObjectName.length > 0 && sIdentifier.length > 0) {
			    	// loop object list
					nOuterSize = this.aListCreator.length;
					for (var i = 0; i < nOuterSize; i++) {
						if (this.aListCreator[i][0] == sObjectName) {
							aBuffer = new Array();
							// loop elements
							nInnerSize = this.aListCreator[i][1].length;
							for (var n = 0; n < nInnerSize; n++) {
								// remove element
								if (this.aListCreator[i][1][n][0] != sIdentifier) {
									aBuffer[aBuffer.length] = this.aListCreator[i][1][n];
								}
							}
							this.aListCreator[i][1] = aBuffer;
						}
					}
					// display
					this.display(sObjectName);
				}
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	findElement :
		function(sObjectName, sIdentifier) {
			try {
		    	// loop object list
				nOuterSize = this.aListCreator.length;
		    	for (var i = 0; i < nOuterSize; i++) {
					if (this.aListCreator[i][0] == sObjectName) {
						// loop elements
						nInnerSize = this.aListCreator[i][1].length;
						for (var n = 0; n < nInnerSize; n++) {
							// check
							if (this.aListCreator[i][1][n][0] == sIdentifier) {
								return true;
							}
						}
					}
				}
		    	return false;
		    } catch (e) {
		    	//alert(e);
		    	return false;
		    }
	    },
	display :
		function(sObjectName) {
			try {
		    	sDisplayObjectName = sObjectName+'_display';
		    	oDisplay = document.getElementById(sDisplayObjectName);
		    	oListCratorValue = document.getElementById(sObjectName);
		    	if (oDisplay != null) {
			    	sDisplay = '';
			    	sListCratorValue = '';
			    	// loop object list
					nOuterSize = this.aListCreator.length;
			    	for (var i = 0; i < nOuterSize; i++) {
						if (this.aListCreator[i][0] == sObjectName) {
							// loop elements
							nInnerSize = this.aListCreator[i][1].length;
							for (var n = 0; n < nInnerSize; n++) {
								if (!this.bIsReadonly) {
									sDisplay = sDisplay + this.aListCreator[i][1][n][1] + '<img src="'+UI.Settings.getPathIcons()+'standart/cross.png" border="0" style="cursor: pointer;" onClick="UI.ListCreator.removeElement(\''+sObjectName+'\', \''+this.aListCreator[i][1][n][0]+'\');"><br/>'+"\n";
								} else {
									sDisplay = sDisplay + this.aListCreator[i][1][n][1] + '<br/>'+"\n";
								}
								sListCratorValue = sListCratorValue + this.aListCreator[i][1][n][0]+';';
							}
						}
					}
			    	oDisplay.innerHTML = sDisplay;
			    	oListCratorValue.value = sListCratorValue;
		    	}
		    } catch (e) {
		    	alert(e);
		    }
	    },
	trace :
		function(sFunctionName) {
			var trace = 'UI.ListCreator.trace ' + sFunctionName + ' ';
			for (var i = 0; i < this.aListCreator.length; i++) {
				trace = trace + "\n"+'name=' + this.aListCreator[i][0] + ': '+"\n";
				for (var n = 0; n < this.aListCreator[i][1].length; n++) {
					trace = trace + ' identifier=' + this.aListCreator[i][1][n][0] + ', label=' + this.aListCreator[i][1][n][1]+"\n";
				}
			}
			alert(trace);
	    }
};

// FileList methods
UI.FileList = {
	sControllerThumbnail : '',
	sControllerFile : '',
	aFileList : new Array(),
	aErrors : new Array(),
	bIsLeftPosition : true,
	bIsRemoveAvailable : true,
	importString :
		function(sFileData) {
			try {
				// get elements start positions
				nPosIdentifier = sFileData.indexOf('IDENTIFIER:');
				nPosFullname = sFileData.indexOf('FULLNAME:');
				nPosBasename = sFileData.indexOf('BASENAME:');
				nPosMimeType = sFileData.indexOf('MIMETYPE:');
				nPosMimeExt = sFileData.indexOf('MIMEEXT:');
				nPosFilesize = sFileData.indexOf('FILESIZE:');
				nPosDirectory = sFileData.indexOf('DIRECTORY:');
				nPosDescription = sFileData.indexOf('DESCRIPTION:');
				nPosOperDate = sFileData.indexOf('OPERDATE:');
				nPosControllerThumbnail = sFileData.indexOf('CONTROLLERTHUMBNAIL:');
				nPosControllerFile = sFileData.indexOf('CONTROLLERFILE:');
				// get elements data
				nIdentifier = sFileData.substring(nPosIdentifier+'IDENTIFIER:'.length, nPosFullname);
				sFullname = sFileData.substring(nPosFullname+'FULLNAME:'.length, nPosBasename);
				sBasename = sFileData.substring(nPosBasename+'BASENAME:'.length, nPosMimeType);
				sMimeType = sFileData.substring(nPosMimeType+'MIMETYPE:'.length, nPosMimeExt);
				sMimeExt = sFileData.substring(nPosMimeExt+'MIMEEXT:'.length, nPosFilesize);
				sFilesize = sFileData.substring(nPosFilesize+'FILESIZE:'.length, nPosDirectory);
				sDirectory = sFileData.substring(nPosDirectory+'DIRECTORY:'.length, nPosDescription);
				sDescription = sFileData.substring(nPosDescription+'DESCRIPTION:'.length, nPosOperDate);
				sOperDate = sFileData.substring(nPosOperDate+'OPERDATE:'.length, nPosControllerThumbnail);
				sControllerThumbnail = sFileData.substring(nPosControllerThumbnail+'CONTROLLERTHUMBNAIL:'.length, nPosControllerFile);
				sControllerFile = sFileData.substring(nPosControllerFile+'CONTROLLERTHUMBNAIL:'.length);
				// set
				this.sControllerThumbnail = sControllerThumbnail;
				this.sControllerFile = sControllerFile;
				this.add(nIdentifier, sFullname, sBasename, sMimeType, sMimeExt, sFilesize, sDirectory, sDescription, sOperDate);
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	add :
		function(nIdentifier, sFullname, sBasename, sMimeType, sMimeExt, sFilesize, sDirectory, sDescription, sOperDate) {
			try {
				this.aFileList[this.aFileList.length] = new Array(nIdentifier, sFullname, sBasename, sMimeType, sMimeExt, sFilesize, sDirectory, sDescription, sOperDate);
				this.display(sFullname);
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	setFileInfo :
		function(nIdentifier, sFullname, sBasename, sMimeType, sMimeExt, sFilesize, sDirectory, sDescription, sOperDate) {
			try {
				var found = false;
				for (var i = 0; i < this.aFileList.length; i++) {
					if (sFullname == this.aFileList[i][1]) {
						found = true;
						// identifier
						nNewIdentifier = this.aFileList[i][0];
						if (nIdentifier !='undefined' && nIdentifier != null) {
							nNewIdentifier = nIdentifier;
						}
						// basename
						sNewBasename = this.aFileList[i][2];
						if (sBasename !='undefined' && sBasename != null) {
							sNewBasename = sBasename;
						}
						// mimetype
						sNewMimeType = this.aFileList[i][3];
						if (sMimeType !='undefined' && sMimeType != null) {
							sNewMimeType = sMimeType;
						}
						// mimeext
						sNewMimeExt = this.aFileList[i][4];
						if (sNewMimeExt !='undefined' && sNewMimeExt != null) {
							sNewMimeExt = sMimeExt;
						}
						// filesize
						sNewFilesize = this.aFileList[i][5];
						if (sFilesize !='undefined' && sFilesize != null) {
							sNewFilesize = sFilesize;
						}
						// directory
						sNewDirectory = this.aFileList[i][6];
						if (sDirectory !='undefined' && sDirectory != null) {
							sNewDirectory = sDirectory;
						}
						// description
						sNewDescription = this.aFileList[i][7];
						if (sDescription !='undefined' && sDescription != null) {
							sNewDescription = sDescription;
						}
						// operdate
						sNewOperDate = this.aFileList[i][8];
						if (sOperDate !='undefined' && sOperDate != null) {
							sNewOperDate = sOperDate;
						}
						// rewrite
						this.aFileList[i] = new Array(nNewIdentifier, sFullname, sNewBasename, sNewMimeType, sNewMimeExt, sNewFilesize, sNewDirectory, sNewDescription, sNewOperDate);
						break;
					}
				}
				// add
				if (!found) {
					this.add(nIdentifier, sFullname, sBasename, sMimeType, sMimeExt, sFilesize, sDirectory, sDescription, sOperDate);
				}
				this.display();
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	remove :
		function(sFullname) {
			try {
				if (sFullname.length > 0) {
					aFileListNew = new Array();
					nSize = this.aFileList.length;
					for (var i = 0; i < nSize; i++) {
						if (this.aFileList[i][1] != sFullname) {
							aFileListNew[aFileListNew.length] = this.aFileList[i];
						}
					}
					this.aFileList = aFileListNew;
					this.displayAll();
				}
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	isErrorsExist :
		function() {
			try {
				if (this.aErrors !='undefined' && this.aErrors != null && this.aErrors.length > 0) {
					return true;
				} else {
					return false;
				}
		    } catch (e) {
		    	//alert(e);
		    }
	    },
    displayAll :
		function() {
			try {
				// clear thumbnails
				thumbnailsObj = document.getElementById('swfuploadThumbnails');
				if (thumbnailsObj != null) {
					thumbnailsObj.innerHTML = '';
				}
				// clear file array
				sFileArrayObj = document.getElementById('swfuploadFileArray');
				if (sFileArrayObj != 'undefined' && sFileArrayObj != null) {
					sFileArrayName = sFileArrayObj.value;
					if (sFileArrayName != 'undefined' && sFileArrayName != null) {
						document.getElementById(sFileArrayName).value = '';
					}
				}
				// display files
				for (var i = 0; i < this.aFileList.length; i++) {
					this.display(this.aFileList[i][1]);
				}
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	display :
		function(sFullname) {
			try {
				// using swdupload handler
				// addImage(this.sControllerThumbnail+'?id='+this.aFileList[i][1]);
				//
				// loop files
				for (var i = 0; i < this.aFileList.length; i++) {
					if (sFullname == this.aFileList[i][1]) {
						/*
						 * add files into array
						 */
						sFileArrayObj = document.getElementById('swfuploadFileArray');
						if (sFileArrayObj != 'undefined' && sFileArrayObj != null) {
							sFileArrayName = sFileArrayObj.value;
							if (sFileArrayName != 'undefined' && sFileArrayName != null) {
								sFileArray = document.getElementById(sFileArrayName).value;
								sNewFileData = 'FULLNAME:'+sFullname+'BASENAME:'+this.aFileList[i][2]+'MIMETYPE:'+this.aFileList[i][3]+'MIMEEXT:'+this.aFileList[i][4]+'FILESIZE:'+this.aFileList[i][5];
								if (sFileArray.length > 0) {
									sFileArray = sFileArray + ';' + sNewFileData;
									document.getElementById(sFileArrayName).value = sFileArray;
								} else {
									document.getElementById(sFileArrayName).value = sNewFileData;
								}
							}
						}
						/*
						 * Display file
						 */
						thumbnailsObj = document.getElementById('swfuploadThumbnails');
						if (thumbnailsObj != null) {
							// create table
							var newTable = document.createElement('table');
							newTable.setAttribute('class','progressContainer');
							if (this.bIsLeftPosition) {
								newTable.setAttribute('style','float:left; width:290px; overflow:hidden;');
							} else {
								newTable.setAttribute('style','float:right; width:290px; overflow:hidden;');
							}
							thumbnailsObj.appendChild(newTable);
							var newTableRow = document.createElement('tr');
							newTable.appendChild(newTableRow);
							var newTableCell_1 = document.createElement('td');
							newTableCell_1.setAttribute('width','100');
							newTableCell_1.setAttribute('align','left');
							newTableRow.appendChild(newTableCell_1);
							var newTableCell_2 = document.createElement('td');
							newTableCell_2.setAttribute('width','180');
							newTableCell_2.setAttribute('align','left');
							newTableRow.appendChild(newTableCell_2);
							// progress image
							var newProgressImage = document.createElement('div');
							newProgressImage.setAttribute('class','progressImage');
							// create image
							var newImage = document.createElement('img');
							newImage.style.margin = '5';
							if (newImage.filters) {
								try {
									newImage.filters.item('DXImageTransform.Microsoft.Alpha').opacity = 0;
								} catch (e) {
									newImage.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + 0 + ')'; // If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
								}
							} else {
								newImage.style.opacity = 0;
							}
							newImage.onload = function () {
								UI.Effects.fadeIn(newImage, 0);
							};
							// create url
							var sFileSrc = UI.Settings.getPathIcons()+'mime/mime_'+this.aFileList[i][3]+'_48.gif';
							if (this.aFileList[i][3] == 'jpe' || this.aFileList[i][3] == 'jpeg' || this.aFileList[i][3] == 'jpg' ||
									this.aFileList[i][3] == 'png' || 
									this.aFileList[i][3] == 'gif') {
								sFileSrc = this.sControllerThumbnail+'?fname='+sFullname+'&fpath='+this.aFileList[i][6];
								// create url
								var newImageUrl = document.createElement('a');
								newImageUrl.setAttribute('href', this.sControllerFile+'?fname='+sFullname+'&fpath='+this.aFileList[i][6]);
								newImageUrl.setAttribute('target', '_blank');
								newImageUrl.setAttribute('style', 'border-bottom: none;');
								newImageUrl.appendChild(newImage);
								newProgressImage.appendChild(newImageUrl);
								newTableCell_1.appendChild(newProgressImage);
							} else {
								newProgressImage.appendChild(newImage);
								newTableCell_1.appendChild(newProgressImage);
							}
							newImage.src = sFileSrc;
							// create text container
							var newTextContainer = document.createElement('span');
							newTableCell_2.appendChild(newTextContainer);
							// fullname
							var newFullname = document.createElement('div');
							newFullname.setAttribute('class','progressName');
							newFullname.innerHTML = this.aFileList[i][2];
							newTableCell_2.appendChild(newFullname);
							newTableCell_2.appendChild(document.createElement('br'));
							// filesize
							var newFilesize = document.createElement('div');
							newFilesize.setAttribute('class','progressBarStatus');
							newFilesize.appendChild(document.createTextNode('size: '+(this.aFileList[i][5])));
							newTableCell_2.appendChild(newFilesize);
							newTableCell_2.appendChild(document.createElement('br'));
							// description
							var newDescription = document.createElement('div');
							newDescription.setAttribute('class','progressBarStatus');
							newDescription.appendChild(document.createTextNode(this.aFileList[i][7]));
							newTableCell_2.appendChild(newDescription);
							// delete button
							if (this.bIsRemoveAvailable) {
								var newTableCell_3 = document.createElement('td');
								newTableCell_3.setAttribute('width','5');
								newTableCell_3.setAttribute('valign','top');
								newTableRow.appendChild(newTableCell_3);
								var newDelete = document.createElement('span');
								newDelete.innerHTML = '<img src="'+UI.Settings.getPathIcons()+'standart/cross.png" border="0" style="cursor: pointer;" onClick="UI.FileList.remove(\''+sFullname+'\');">';
								newTableCell_3.appendChild(newDelete);
							}
						}
						// switch left to right position
						if (this.bIsLeftPosition) {
							this.bIsLeftPosition = false;
						} else {
							this.bIsLeftPosition = true;
						}
					}
				}
				// create thumbnails gallery
			    $("#swfuploadThumbnails a").lightBox();
		    } catch (e) {
		    	//alert(e);
		    }
	    },
	trace :
		function(sFunctionName) {
			var trace = 'UI.FileList.trace ' + sFunctionName + ' ';
			for (var i = 0; i < this.aFileList.length; i++) {
				trace = trace + "\n" + 'Identifier=' + this.aFileList[i][0] + "\n" 
									 + 'Fullname=' + this.aFileList[i][1] + "\n"
									 + 'Basename=' + this.aFileList[i][2] + "\n"
									 + 'MimeType=' + this.aFileList[i][3] + "\n"
									 + 'MimeExt=' + this.aFileList[i][4] + "\n"
									 + 'Filesize=' + this.aFileList[i][5] + "\n"
									 + 'Directory=' + this.aFileList[i][6] + "\n"
									 + 'Description=' + this.aFileList[i][7] + "\n"
									 + 'OperDate=' + this.aFileList[i][8] + "\n"
									 + "\n";
			}
			trace = trace + 'ControllerThumbnail=' + this.sControllerThumbnail + "\n";
			trace = trace + 'ControllerFile=' + this.sControllerFile + "\n";
			alert(trace);
	    }
};

// Order
UI.Order = {
	sOrderAsc: 'accessing',
	sOrderDesc: 'descending',
	sOrderSort: 'sort',
	bIsInitialized: false,
	init:
		function () {
			this.sOrderAsc = UI.Label.find('order_asc', this.sOrderAsc);
			this.sOrderDesc = UI.Label.find('order_desc', this.sOrderDesc);
			this.sOrderSort = UI.Label.find('order_sort', this.sOrderSort);
			this.bIsInitialized = true;
	    },
	changeSort :
		function (sObjectName, sPrefixVisual, sPrefixHidden) {
	    	if (!this.bIsInitialized) {
	    		this.init();
	    	}
			oVisual = document.getElementById(sPrefixVisual + sObjectName);
			oHidden = document.getElementById(sPrefixHidden + sObjectName);
			if (oHidden.value == 'order_sort' || oHidden.value == '') {
				oVisual.innerHTML = '<span class="formSortActive">'+this.order_asc+'</span>';
				oHidden.value = 'order_asc';
			} else if (oHidden.value == 'order_asc') {
				oVisual.innerHTML = '<span class="formSortActive">'+this.order_desc+'</span>';
				oHidden.value = 'order_desc';
			} else if (oHidden.value == 'order_desc') {
				oVisual.innerHTML = '<span class="formSortInactive">'+this.order_sort+'</span>';
				oHidden.value = 'order_sort';
			}
	    }
}

// Visual effects
UI.Effects = {
	changeDisplay :
		function (sObjectName) {
			try {
	    		o = document.getElementById(sObjectName);
	    		if (o != null) {
		    		// prepare display
		    		if (o.style.display == '' && o.className == 'menuChildOpen') {
		    			o.style.display = 'block';
		    		}
		    		// make display
			    	if (o.style.display != 'block') {
			        	o.style.display = 'block';
			    	} else {
			    		o.style.display = 'none';
			    	}
	    		}
		    } catch (e) {
		    	return false;
		    }
	    },
	changeRowDisplay :
		function (sObjectName) {
			try {
	    		o = document.getElementById(sObjectName);
	    		if (o != null) {
		    		// make display
			    	if (o.style.display != 'none') {
			        	o.style.display = 'none';
			    	} else {
			    		o.style.display = 'table-row';
			    	}
	    		}
		    } catch (e) {
		    	//alert(e);
		    	return false;
		    }
	    },
	changeMultipleDisplay :
		function (sObjectName, nStartIndex, nEndIndex) {
			try {
				for (var i = nStartIndex; i <= nEndIndex; i++) {
					UI.Effects.changeRowDisplay(sObjectName+i);
				}
		    } catch (e) {
		    	//alert(e);
		    	return false;
		    }
	    },
	flipImage :
		function (sObjectNameImg, sImg1, sImg2) {
			try {
				oImg = document.getElementById(sObjectNameImg);
				if (oImg.src == sImg1) {
					oImg.src = sImg2;
				} else {
					oImg.src = sImg1;
				}
		    } catch (e) {
		    	alert(e);
		    	return false;
		    }
	    },
	flipImageBasic :
			function (sObjectNameImg, sImgSrc) {
				try {
					oImg = document.getElementById(sObjectNameImg);
					oImg.src = sImgSrc;
			    } catch (e) {
			    	alert(e);
			    	return false;
			    }
		    },
	showInpageWindow :
		function (sObjectName, event) {
			try {
	    		o = document.getElementById(sObjectName);
	    		if (o.style.display != 'block') {
		    		d = document;
					de = d.documentElement;
					mouseX = event.clientX + d.body.scrollLeft;
					mouseY = event.clientY + (de.scrollTop ? de.scrollTop : d.body.scrollTop);
					if ((o.clientWidth + mouseX) >= d.body.offsetWidth) {
						mouseX = d.body.offsetWidth - o.clientWidth;
					}
					o.style.left = (mouseX-3)+"px";
					o.style.display = 'block';
					o.style.top = (mouseY-(o.offsetHeight)-10)+"px";
		    	} else {
		    		o.style.display = 'none';
		    	}
		    } catch (e) {
		    	return false;
		    }
	    },
	changeDisable :
		function (oThisObject, sObjectTargetName) {
			try {
	    		oTargetObject = document.getElementById(sObjectTargetName);
	    		if (oThisObject.checked) {
	    			oTargetObject.checked = true;
	    			oTargetObject.disabled = true;
	    		} else {
	    			oTargetObject.disabled = false;
	    		}
		    } catch (e) {
		    	return false;
		    }
	    },
	setListboxMultiple :
		function (oObjectName, isMultiple) {
			try {
	    		oObject = document.getElementById(oObjectName);
	    		if (oObject != null) {
	    			oObject.multiple = isMultiple;
	    		}
		    } catch (e) {
		    	// alert(e);
		    }
	    },
    fadeIn :
	    function (element, opacity) {
			try {
		    	var reduceOpacityBy = 5;
		    	var rate = 30;	// 15 fps
		    	if (opacity < 100) {
		    		opacity += reduceOpacityBy;
		    		if (opacity > 100) {
		    			opacity = 100;
		    		}
		    		if (element.filters) {
		    			try {
		    				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
		    			} catch (e) {
		    				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
		    				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
		    			}
		    		} else {
		    			element.style.opacity = opacity / 100;
		    		}
		    	}
		    	if (opacity < 100) {
		    		setTimeout(function () {
		    			UI.Effects.fadeIn(element, opacity);
		    		}, rate);
		    	}
		    } catch (e) {
		    	// alert(e);
		    }
	    },
	setWidth :
		function (oObjectName, nNewWidth, nOriginalWidth) {
			try {
	    		oObject = document.getElementById(oObjectName);
	    		if (oObject != null) {
	    			if (oObject.width == nOriginalWidth || oObject.width == '') {
	    				oObject.width = nNewWidth;
	    			} else {
	    				oObject.width = nOriginalWidth;
	    			}
	    		}
		    } catch (e) {
		    	alert(e);
		    }
	    }
};
