/* -------------------------------------------------------------------------------------------- */
// COMMON PROPERTIES
/* -------------------------------------------------------------------------------------------- */
var topPart = null;
var leftPart = null;
var bodyPart = null;
var ie = (navigator.appName.indexOf("Microsoft Internet Explorer") >= 0) ? true : false;
var ie7 = ie && (navigator.userAgent.indexOf('MSIE 7') != -1);
var Title = "";
var IdPart = "";
var KeyPart = "";
var currentDisplayMode = "";
var currentExtendedDisplayMode = "";
var leftData = "";
var leftInfo = "";
var leftOpenPage = "";
var leftScript = "";
var submited = false;
var timeoutStatusID = null;
var IDDate = null;
var IDHour = null;
var IDMinute = null;
var currentSuffix = "";
var prvYY = "";
var prvMM = "";
var prvDD = "";
var prvHH = "";
var prvMIN = "";
var currentTextarea = null;
var currentMode = "";
var previewImageURL = "";
var previewImage = null;
var defaultHeight = "20px";
var hiddenSelected = new Array();
var labels = new Array();
try { var hiddenTdText = new Hash(); } catch( e ) {}	
var ajaxResponse =null;
var menuId;
var externalTabs = new MenuBar( "externalTabs" );
var isFieldUpdated = false;
var updatedToReset = false;
var allSelected = false;
var openPageMore = "";
var lastSelectItem = "-1";
var tooltip_id;
var translateCopyAll = false;
var timer;
var blurTimer;

// Windows
// =======
var winPopup 	 = null;
var winEdit 	 = null;
var winDate 	 = null;
var winTreeS 	 = null;
var winColor 	 = null;
var winPrompt 	 = null;
var winQuickList = null;
var winDiaries 	 = null;
var winFiles 	 = null;
var winUpload 	 = null;
var winDebug	 = null;

/* -------------------------------------------------------------------------------------------- */
// FRAMES PARTS LOCATION
/* -------------------------------------------------------------------------------------------- */
function initializeParts()
{
	try
	{
		switch ( parent.frames.length )
		{
			case 2 :
				topPart = parent.frames[0];
				bodyPart = parent.frames[1];
				break;
			case 1 :
			case 0 :
				topPart = null;
				bodyPart = parent;
				break;
		}
	}
	catch (e) { alert(e.message); }
}
//-----------------------------------------------------------------------------------------------
function getTop() 
{
	if (topPart == null) initializeParts();
	return topPart;
}
//-----------------------------------------------------------------------------------------------
function getLeft() 
{
	if (leftPart == null) initializeParts();
	return leftPart;
}
//-----------------------------------------------------------------------------------------------
function getBody() 
{
	if (bodyPart == null) initializeParts();
	return bodyPart;
}
//-----------------------------------------------------------------------------------------------
function getWindowWidth(obj)
{
	var w = 0;	
	try { w = obj.offsetWidth; } catch (e) { w = 0; }
	try { if ( w == null || w == "undefined" || w == 0 ) w = obj.document.body.offsetWidth; } catch (e) { w = 0; }
	try { if ( w == null || w == "undefined" || w == 0 ) w = obj.innerWidth; } catch (e) { w = 0; }
	return parseInt(w) == 0 ? 200 : parseInt(w);
}
function getWindowHeight(obj)
{
	var h = 0;
	try { h = obj.offsetHeight; } catch (e) { w = 0; }
	try { if ( h == null || h == "undefined" || h == 0 ) h = obj.document.body.offsetHeight; } catch (e) { w = 0; }
	try { if ( h == null || h == "undefined" || h == 0 ) h = obj.innerHeight; } catch (e) { w = 0; }
	return parseInt(h) == 0 ? 200 : parseInt(h);
}
function getWindowTop(obj)
{
	try
	{
	    if (obj.offsetParent)
    	    return (obj.offsetTop + getWindowTop(obj.offsetParent));
	    else
    	    return (obj.offsetTop);
   	}
   	catch(e) {}
}
function getWindowLeft(obj)
{
	try
	{
	    if (obj.offsetParent)
    	    return (obj.offsetLeft + getWindowLeft(obj.offsetParent));
	    else
    	    return (obj.offsetLeft);
   	}
   	catch(e) {}
}
function adjustBodyHeight()
{
	var width  = "";
	var height = "";
	
	try
	{
	if (document.body)
	{
		width  = (document.body.clientWidth);
		height = (document.body.clientHeight);
	}  
	else
	{
		width  = (window.innerWidth);
		height = (window.innerHeight);
	}

	//debugMsg( arguments, "height=" + height );
	if ( ie )
	{
		if ( document.body.scrollWidth > width )
			document.getElementById( "BodyDiv" ).style.height=eval(height - 16 );
		else
			document.getElementById( "BodyDiv" ).style.height=eval(height - 32 );
		document.getElementById( "BodyDiv" ).style.width=eval(width - 10);
	}
	else
	{
		document.getElementById( "BodyDiv" ).style.height=eval(height - 32 );
	}
	document.getElementById( "BodyDiv" ).style.display="inline";
	}
	catch(e) {}
}
//-----------------------------------------------------------------------------------------------
function getEventX(eventObj)
{
	if ( ie ) return eventObj.clientX + document.body.scrollLeft;
  	else return eventObj.pageX;
}
function getEventY(eventObj)
{
	if ( ie ) return eventObj.clientY + document.body.scrollTop;
  	else return eventObj.pageY;
}
//-----------------------------------------------------------------------------------------------
function getBodyWidth()
{
	var w = 0;
	try { parent.document.body.offsetWidth; } catch(e) { w = 0; }
	try { if ( w == null || w == "undefined" || w == 0 ) w = parent.innerWidth; } catch(e) { w = 0; }
	return parseInt(w) - 185;
}
//-----------------------------------------------------------------------------------------------
function getBodyHeight()
{
	var h = 0;
	try { h = document.body.offsetHeight; } catch(e) { w = 0; }
	try { if ( h == null || h == "undefined" || h == 0 ) h = document.innerHeight; } catch(e) { w = 0; }
	return parseInt(h) - 90;
}
//-----------------------------------------------------------------------------------------------
function resizeWindow(refObject, wDefault, hDefault, wDelta, hDelta)
{
	var w = 0;
	var h = 0;
	
	try
	{
		w = getWindowWidth(refObject);
		h = getWindowHeight(refObject);
		if ( w == null || w == "undefined" || w == 0 ) w = wDefault;
		if ( h == null || h == "undefined" || h == 0 ) h = hDefault;
	}
	catch (e)
	{
		w = wDefault;
		h = hDefault;
	}
	w += wDelta;
	h += hDelta;

	if ( w < ( wDefault + wDelta ) ) w = wDefault + wDelta;
	if ( h < ( hDefault + hDelta ) ) h = hDefault + hDelta;
	
	if ( ie )
	{
		if ( w > ( screen.width - window.screenLeft ) )
		{
			// Case multi-screen
			if ( screen.width - window.screenLeft > 0 )
				w = screen.width - window.screenLeft;
			else
				if ( w > screen.width )
					w = screen.width;				
		}
		if ( h > ( screen.height - screenTop ) ) h = screen.height - window.screenTop;	
		//debugMsg( arguments, "w=" + w + "\nh=" + h + "\nscreen.width=" + screen.width + "\nscreen.height=" + screen.height + "\nscreenLeft=" + window.screenLeft + "\nscreenTop=" + window.screenTop );		
	}
	else
	{
		//debugMsg( arguments, "w=" + w + "\nh=" + h + "\nscreen.width=" + screen.width + "\nscreen.height=" + screen.height + "\nscreenX=" + window.screenX + "\nscreenY=" + window.screenY );
		if ( w > ( screen.width - screenX ) )
		{
			// Case multi-screen
			if ( screen.width - window.screenX > 0 )
				w = screen.width - window.screenX;
			else
				if ( w > screen.width )
					w = screen.width;
		}
		 
		if ( h > ( screen.height - screenY ) ) h = screen.height - window.screenY;
	}
	//debugMsg(arguments, "w=" + w + "\nh=" + h );
	
	if ( ie )
		window.resizeTo( w, h );
	else
	{
		window.outerWidth  = w;
		window.outerHeight = h;
	}
	
	return w;
	
}
/* -------------------------------------------------------------------------------------------- */
function closePage()
{
	try { if ( winPrompt != null )	winPrompt.close(); } catch (e) {}
	try { if ( winEdit != null )	winEdit.close(); } catch (e) {}
	try { if ( winDate != null )	winDate.close(); } catch (e) {}
	try { if ( winColor != null )	winColor.close(); } catch (e) {}
	try { if ( winTreeS != null )	winTreeS.close(); } catch (e) {}
	try { if ( winQuickList != null )	winQuickList.close(); } catch (e) {}
	try { if ( winDiaries != null ) winDiaries.close(); } catch (e) {}
	try { if ( winFiles != null ) 	winFiles.close(); } catch (e) {}	
	try { if ( winUpload != null ) 	winUpload.close(); } catch (e) {}		
	try { if ( winDebug != null )	winDebug.close(); } catch (e) {}	
	try { if ( TABadjustment != null ) clearInterval(TABadjustment); } catch (e) {}
	
}
/* -------------------------------------------------------------------------------------------- */
// Set color (for SelectColor.jsp)
/* -------------------------------------------------------------------------------------------- */
function setColorPicker( fieldName, colorRef )
{
	with (document.FORM1.elements[fieldName])
	{
		value = colorRef;
		style.background = colorRef;
	}
}
/* -------------------------------------------------------------------------------------------- */
// Function for SelectDate in quick list
/* -------------------------------------------------------------------------------------------- */

function isNumeric(sText) 
{ 
	var ValidChars = "0123456789"; 

	if ( ValidChars.indexOf(sText) == -1 ) 
		return false; 
	else
		return true;
} 

function getIndex(fieldName)
{
	var index = "";
	
	for ( i = fieldName.length; i >= 0  ; i-- ) 
	{
		if ( isNumeric( fieldName.charAt(i) ) )
			index = fieldName.charAt(i) + index;
		else
			break;
	}
	
	return index;
}

/* -------------------------------------------------------------------------------------------- */
// Show document on separate window
/* -------------------------------------------------------------------------------------------- */
function showDocument(url)
{
	var top  = parseInt(screen.height / 2 - 200);
	var left = parseInt(screen.width / 2 - 200);
	var WID = "W"+new Date().getTime();
	window.open("/actricity/servlet/actricityV1.common.objects.DisplayDocument?P_SPHERE="+getBody()._sphere+"&EXTKEY="+getBody()._key+"&SERVER="+getBody()._previewImageSrv+"&DOCURL="+url+"&NAME="+getBody()._previewName+"&TOP="+top+"&LEFT="+left+"&WinID="+getBody()._winID, WID, "width=100,height=100,scrollbars,resizable,top="+top+",left="+left);
}

function showDocumentFromId( b_document )
{
	var top  = parseInt(screen.height / 2 - 200);
	var left = parseInt(screen.width / 2 - 200);
	var WID = "W"+new Date().getTime();
	window.open("/actricity/servlet/actricityV1.common.objects.DisplayDocument?P_SPHERE="+getBody()._sphere+"&EXTKEY="+getBody()._key+"&B_DOCUMENT="+b_document+"&NAME="+getBody()._previewName+"&TOP="+top+"&LEFT="+left+"&WinID="+getBody()._winID, WID, "width=100,height=100,scrollbars,resizable,top="+top+",left="+left);
}

function showFile( server, filePath, download, name )
{
	//debugMsg( arguments, "" );
	if ( name == null || name == "undefined" ) name = "";
	var w = 1;
	var h = 1;
	var WID = "W"+new Date().getTime();
	dwDialog = window.open( "/actricity/servlet/actricityV1.tool.functions.DisplayFile?B_FTPSERV=" + server + "&REFFILE=" + filePath + "&DOWNLOAD=" + download + "&NAME=" + name + "&WinID=" + _winID, WID, "scrollbars,resizable,top=10,left=10,width="+w+",height="+h);
	
//	if ( navigator.appName.indexOf("Microsoft") != -1 )
//		setInterval( "dwDialog.close();", 100);	
//	else
//		setTimeout( "dwDialog.close();", 4000);	
}

function PopupSelectFile( server, path, returnFunction, onlyDirectory, onlyFile, selector )
{
	var WID = "W"+new Date().getTime();
	
	var params = "server=" + server + "&loadPath=" + path + "&returnFunction=" + returnFunction;
	if ( onlyDirectory != undefined && onlyDirectory ) params += "&onlyDirectory=1";
	else params += "&onlyDirectory=0";
	if ( onlyFile != undefined && onlyFile ) params += "&onlyFile=1";
	else params += "&onlyFile=0";
	if ( selector != undefined ) params += "&selector=" + selector;
	else params += "&selector=radio";
	params += "&ScreenWidth=800&ScreenHeight=500&WinID=" + getBody()._winID;	
	
	if ( winFiles == null || winFiles.closed ) 
		winFiles = window.open("/actricity/servlet/actricityV1.tool.system.explorer.ExplorerTree?" + params
						 , WID, "width=800,height=500,resizable=yes,scrollbars=yes,top=100,left=100");
	else
		winFiles.location.href = "/actricity/servlet/actricityV1.tool.system.explorer.ExplorerTree?" + params;
	winFiles.focus();
}

function PopupUploadFile( params )
{
	var WID = "W"+new Date().getTime();
	
	params += "&ScreenWidth=400&ScreenHeight=300&WinID=" + getBody()._winID;	
	
	//debugMsg( arguments, "params=" + params );
	if ( winUpload == null || winUpload.closed ) 
		winUpload = window.open("/actricity/servlet/actricityV1.tool.addon.document.DocumentGenerationManagement?" + params
						 , WID, "width=400,height=300,resizable=yes,scrollbars=yes,top=100,left=100");
	else
		winUpload.location.href = "/actricity/servlet/actricityV1.tool.addon.document.DocumentGenerationManagement?" + params;
	winUpload.focus();
}
	
function getPathEncrypted( path, returnFunction )
{
	setTimeout( function () { ajaxRequest( "/actricity/servlet/actricityV1.tool.system.explorer.Decrypt", "type=path&value=" + path, returnFunction );}, 30 );
}

function changeFont( name, value, id )
{
	var checked;
	var font;
	var selector = eval( "document.FORM1." + name );
	if ( selector != undefined )
	{
		for ( var i = 0; i < selector.length; i++ )
		{
			if ( selector[ i ].value == value )
			{
				checked = selector[ i ].checked;
				if ( !selector[ i ].disabled )
				{
					if ( selector[ i ].type == "radio" )
					{
						if ( lastChecked != "" )
						{
							document.getElementById( "fId" + lastChecked ).className = "String";
						}							
					}
					font = document.getElementById( "fId" + id );
					if ( font != null )
					{
						if ( checked )
							font.className = "String";
						else
						{
							font.className = "TreeSelected";
							lastChecked = id;
						}
						break;
					}
				}
			}
		}
	}
}
/* -------------------------------------------------------------------------------------------- */
// HEADER TEXT FUNCTIONS
/* -------------------------------------------------------------------------------------------- */
function setTitle(t)
{
	try
	{
		try { if ( KeepTop == "1" ) return; }catch(e) {}
		try
		{
			var n = getBody()._listLength;
			var i = getBody()._currentIdx + 1;
			if ( n > 1 ) t += " ("+  i + " / " + n + ")";
		} catch (e) {}
		parent.document.title = t;
		t = "<nobr>" + t + "</nobr>";		
		
		var titlePart = getTop().document.getElementById("TitlePart");
		if ( t.length == 0 ) t = "&nbsp;"
		titlePart.innerHTML = t;

	} catch (e) { alert(e.message); }
}
//-----------------------------------------------------------------------------------------------
function loadRecordSecurity()
{
	with ( getBody() )
	{
		document.FORM1.Function.value = "VALIDATE";
		document.FORM1.DisplayMode.value = "SECURITY_MNG";
		submitFORM1();
	}
}
//-----------------------------------------------------------------------------------------------
function selectRecordSecurity()
{
	with ( getBody() )
	{
		document.FORM1.Function.value = "VALIDATE";
		document.FORM1.DisplayMode.value = "SECURITY_ADD";
		submitFORM1();
	}
}
//-----------------------------------------------------------------------------------------------
function setIdPart(text)
{
	var html = "";
	var _newRecord = false;
		
	try
	{
		try { if ( KeepTop == "1" ) return; }catch(e) {}
		if ( text == "&nbsp;" ) text == "";
		else if ((currentDisplayMode == "DSP_NEW") || (currentDisplayMode == "DSP_CPY") )
		{
			text = "";		
			if (currentDisplayMode == "DSP_CPY" ) 
				text = "<b>" + TC_TextCopy + "</b>";
			_newRecord = true;
		}

		if ( currentDisplayMode != "INVITE" )
		{			
			// Security group
			// ==============
			try
			{
				if ( ! _readonly )
				{
					if ( _securityGroup > 0 ) html += '<img style="vertical-align: bottom;" src="/actricity/theme/Images/Security.gif" onclick="loadRecordSecurity()">&nbsp;&nbsp;';
					else if ( _securityGroup == 0 ) html += '<img style="vertical-align: bottom;" src="/actricity/theme/Images/SecurityFindGroup.gif" onclick="selectRecordSecurity()">&nbsp;&nbsp;';
				}
			}
			catch (e) {}

			// Preview
			// =======
			try
			{
				if ( _previewName.length > 0 ) html += '<img style="vertical-align: bottom;" src="/actricity/theme/Images/PreviewImage.gif" class="clickable" onclick="showDocument( getBody()._previewImage )" onmouseout="hidePopupInfo( this, event)" onmouseover="showPopupInfo( this, event, getBody()._previewName )">&nbsp;&nbsp;';
			}
			catch (e) {}
			
			// Update info
			// ===========
			try
			{
				if ( _updateInfo != null && _updateInfo.length > 0 && ! _newRecord )
				{
					html += '<img style="vertical-align: bottom;" src="/actricity/theme/Images/Information.gif" onmouseout="hidePopupInfo(this, event)" onmouseover="showPopupInfo( this, event, &quot;' + _updateInfo + '&quot;)">';
				}
			}
			catch (e) {}
			
			html = "<nobr>" + text + "&nbsp;&nbsp;" + html + "</nobr>";
		}
	
		var e = getTop().document.getElementById("IdPart");
		if ( html.length == 0 ) html = "&nbsp;";
			e.innerHTML = html;

	} catch (e) { alert(e.message); }
}
//-----------------------------------------------------------------------------------------------
function setKeyPart(t)
{
	try
	{
		try { if ( KeepTop == "1" ) return; }catch(e) {}
		if ((currentDisplayMode == "DSP_NEW") || (currentDisplayMode == "DSP_CPY") ) t = "&nbsp;";
		var e = getTop().document.getElementById("KeyPart");
		e.innerHTML = t;
	} catch (e) { alert(e.message); }
}


/* -------------------------------------------------------------------------------------------- */
// LEFT MENU COMMON FUNCTIONS
/* -------------------------------------------------------------------------------------------- */
function writeToLeft( txt )
{
	leftData += txt;
}
	
//-----------------------------------------------------------------------------------------------
function mouseOver(obj)
{
	obj.className = "AreaSelected";
}
//-----------------------------------------------------------------------------------------------
function mouseOut(obj)
{
	obj.className = "AreaDefault";
}

//-----------------------------------------------------------------------------------------------
function beginMenu()
{
	submited = false;
	var submitActive = true;
	var listPresent	= false;

	try { adjustBodyHeight(); } catch (e) {}
	
	// Cancel request not active
	// =========================
	try { setCancelButton(false); } catch (e) {}

	// Print entity / Export
	// =====================
	try { getTop().popExportArray = new Array(); } catch (e) {}
	
	// Set Editor
	// ==========
	try
	{
		currentDisplayMode = getBody().document.FORM1.DisplayMode.value;
		currentExtendedDisplayMode = getBody().document.FORM1.ExtendedDisplayMode.value;

		var f = document.FORM1.elements;
		for (i = 0; i < f.length; i++)
		{
			if ( (f[i].type == "textarea") && (f[i].ondblclick == null) && (f[i].name.indexOf("RefLabel") == -1) )
			{
				f[i].title = TC_TEXTAREA_EDIT;
			}
		}
	} catch (e) {}

	// SET focus function for input fields
	// ===================================
	try
	{
		var elems = getBody().document.FORM1.elements;
		for (i=0; i < elems.length; i++)
		{
			try
			{
				if ( (elems[i].type.indexOf("text") >= 0) || (elems[i].type == "select-one") )
				{
					elems[i].onfocus = setFocus;
				}
			} catch (e) { myVoid(); }
		}
		
	} catch (e) { myVoid(); }


	// SELECT ALL / UNSELECT ALL buttons
	// =================================
	try 
	{ 
		if ( (getBody().list != null) && (getBody().list[0].type == "checkbox") ) listPresent = true;
	} catch (e) { listPresent = false; }
	
	try { setSelectButton(listPresent); } catch (e) { myVoid(); }
	
	// BUTTONS
	// =======
	try
	{				
		setReturnButton( true );
		setStackButton( true );
		setSubmitButton( false );
		setSaveButton( false );
		setCreateButton( false );
		setDeleteButton( false );
		setCopyButton( false );
		setSelectButton( false );
		setClearButton( false );
		setRefreshButton( true );
		setPrintButton( true );
		setExportButton( false );
		setIndicatorButton( false );
		setWorkflowButton( true );
		setWorkButton( true );		
		setMemoButton( true );		
		setMailButton( true );
		setPhoneButton( true );
		setMediaButton( false );
		setGanttButton( true );
		setFavoriteButton( true );
		setBatchButton( false );
		setContextButton( false );
		setMenuButton( true );
		setLogoutButton( true );
		setQuickHelpButton( false );
		setHelpButton( true );	
		setNavigationFunctions( "0000" );
		
		// Display Mode
		if ( currentDisplayMode == "DSP_DSP" )
		{
			setExportButton( true );
		}
		if ( currentDisplayMode == "DSP_UPD" )
		{
			// V2 JT 19/06/06
			// setSubmitButton( true );
			// ==============					
			setExportButton( true );
			// V2 JT 19/06/06
			setSaveButton( false );
			setCreateButton( true );
			setDeleteButton( true );
			setCopyButton( true );
			// %% Start %%
			// %% 27/05/08 VR Specific AEBI %%			
			// setRefreshButton( false );
			// %% End %%
			// ==============					
		}
		else
		if ( currentDisplayMode == "DSP_CPY" )
		{	
			setExportButton( true );
			setSaveButton( true );
			setCreateButton( false );
			setDeleteButton( false );
			setCopyButton( false );						
		}
		else
		if ( currentDisplayMode == "DSP_NEW" )
		{
			if ( currentExtendedDisplayMode == "RETURN_ON_VALIDATE" )
			{
				setSubmitButton( true );
			}
			else
			{
				// V2 JT 19/06/06
				// setSubmitButton( true );
				setSaveButton( true );
				// ==============					
			}
		}
		else
		if ( currentDisplayMode == "INVITE" )
		{
			if ( _topMode != null && _topMode == "2" ) setClearButton( false );
			else setClearButton( true );
			// V2 JT 19/06/06
			setSubmitButton( true );
			setCreateButton( true );
			// ==============			
			try { initCombos(); } catch(e) {}		
		}
		else
		if ( currentDisplayMode == "DSP_LST2" || currentDisplayMode == "DSP_LST"  )
		{
			setSelectButton( true );
			setExportButton( true );
			// DM ACT-031532
			setWorkflowButton( false );
			setWorkButton( false );		
			setMemoButton( false );		
			setMailButton( false );
			setPhoneButton( false );
		}
		else
		if ( currentDisplayMode == "UPD_LST"  )
		{
			setSelectButton( true );		
			setSubmitButton( true );
			// V2 JT 18/09/06
			setSaveButton( true );
			// DM ACT-031532
			setWorkflowButton( false );
			setWorkButton( false );		
			setMemoButton( false );		
			setMailButton( false );
			setPhoneButton( false );
			
		}
		else
			// V2 JT 19/06/06		
		if ( currentDisplayMode == "QUERY" )
		{

			setSubmitButton( true );
			setCreateButton( true );				
		}
			// ==============		
		
		// V2 JT 19/06/06	
		// Multi records
		// =============		
		if ( _listLength != null && _listLength > 1 )
		{
			setCreateButton( false );
			setCopyButton( false );
		}
				
		// Authorizations
		// ==============
		try { if ( !_authUPD ) setSaveButton( false ); } catch(e) {}
		try { if ( !_authDLT ) setDeleteButton( false ); } catch(e) {}
		try 
		{ 
			if ( !_authCRT )	
			{
				setCreateButton( false );
				setCopyButton( false );
			}
		} catch(e) {}
					
		// Special Buttons for external users
		// ==================================	
		if ( _topMode != null && _topMode == "2" )
		{
			setExportButton( false );
			setBatchButton( false );
			setContextButton( false );
			setStackButton( false );
			setPrintButton( false );
			// %% Start %%
			// %% 27/05/08 VR Specific AEBI %%
			setWorkflowButton( false );
			// %% End %%
		}
		
		// Workflow
		// ========
		if ( !_workflow ) getButtonsBar().HideButton( "Workflow" );

	} catch (e) { myVoid(); }
	
	// NAVIGATION buttons
	// ==================
	try { getTop().setNavigationOption("0000"); } catch (e) { myVoid(); }

	// Convert Reference Label values
	// ==============================
	try { getBody().convertReferences(); } catch (e) { myVoid(); }
	
	// Init listbox warnings
	// =====================
	try{ initListboxWarning(); } catch (e) { myVoid(); }
	
	// Document button
	// ===============
	try
	{
		if ( document.FORM1.ServletDocument.value != "0" )
			setQuickHelpButton( true );			
	}
	catch(e) {}
	
	// Format Find or Translate Image
	for ( i = 0; i < document.images.length; i++ )
	{
		if ( document.images[ i ].src.indexOf( "/Find.gif", 0 ) > 0 || document.images[ i ].src.indexOf( "/Translate.gif", 0 ) > 0 )
		{
			document.images[ i ].style.cursor="pointer";
		}
	}
}
//-----------------------------------------------------------------------------------------------
function endMenu()
{
	var formatedName = "";

	timeoutStatusID = setTimeout("setDefaultStatus()", 100);
	
	try
	{
		if( document.FORM1.PROCESS_ADDRESS != null && document.FORM1.PROCESS_ADDRESS != "undefined" && document.FORM1.PROCESS_ADDRESS.value == "1" )
		{
			generateAddressList(true);
		}
		if( document.FORM1.PROCESS_MEDIA != null && document.FORM1.PROCESS_MEDIA != "undefined" && document.FORM1.PROCESS_MEDIA.value == "1" )
		{
			generateMediaList();
		}
	}
	catch (e) {}

	try
	{
		document.FORM1.ScreenWidth.value = document.body.clientWidth;
		document.FORM1.ScreenHeight.value = document.body.clientHeight;
	}
	catch (e) {}
	// alert ( "DBG endMenu: ScreenWidth.value=" + document.body.clientWidth + " ScreenHeight.value=" + document.body.clientHeight );
	// Draw buttons bar	
	try { getTop().ButtonsBar.Draw(); }	catch (e) {}
	// V2 JT 11/07/06
	// ==============
	try { externalTabs.Draw(); } catch (e) {}
	try { document.FORM1.isIE.value = ie; } catch (e) {}
	if ( eval( "document.FORM1." + document.FORM1.PageName.value + "RecordUpdated != null && document.FORM1." + document.FORM1.PageName.value + "RecordUpdated.value == '1'" ) || isFieldUpdated )	
	{
		isFieldUpdated = false;
		checkUpdate();
	}
	// ==============

	try { openPageAddOn(); } catch (e) {}
	try { eval(openPageMore); } catch (e) {}
}

//-----------------------------------------------------------------------------------------------
function setDefaultStatus()
{
	try 
	{ 
		clearTimeout(timeoutStatusID);
		window.status = parent.defaultStatus; 
		processPullDown();
	} catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function beginMenuWithPullDown()
{
	beginMenu();
}
//-----------------------------------------------------------------------------------------------
function genOption(fName, fText, iName, iAction, act)
{
	var menuOption = new MenuOption( fName, fText, false );
	externalTabs.AddOption( menuOption );
}
//-----------------------------------------------------------------------------------------------
function setImage(name, src)
{
	try
	{
		previewImage = new Image();
		previewImage.src = src;
		setImageLoad(name, src);
	}
	catch (e) 
	{
		alert("setImage(" + name + ", " + src + ") : " +e);
	}
}

function setImageLoad( name, src )
{
	//alert( "[DBG CommonScript.js setImageLoad]\nname=" + name + "\nsrc=" + src );
	if ( previewImage.complete ) setImageEndLoad( name, src )
	else setTimeout( "setImageLoad('" + name + "','" + src + "')", 200 );
}

function setImageEndLoad(name, src)
{
	try
	{
			var img = new Image();
			img.src = src;	
			var obj = getTop().document.getElementById( name );
			obj.style.visibility = "hidden";
			obj.src = img.src;
			obj.alt = img.src;
			obj.width = img.width;
			obj.height = img.height;
			//alert( "DBG: " + img.src + " " + img.width + " " + img.height );
			//alert( "DBG: " + obj.src + " " + obj.width + " " + obj.height );			
			adjustImageSize( obj, 72, 72 );				
	}
	catch (e) 
	{
		alert("setImageLoad(" + name + ", " + src + ") : " +e);
	}
}

//-----------------------------------------------------------------------------------------------
var adjustImageSizeTimer;
function adjustImageSize(img, maxWidth, maxHeight)
{
	if ( img.complete )
	{
		//debugMsg( arguments, "Complete" );
		if ( ie )
				adjustImageSizeTimer = setTimeout( function(){ adjustImageSizeComplete(img, maxWidth, maxHeight); }, 800 );
		else
			adjustImageSizeComplete(img, maxWidth, maxHeight);
	}
	else
	{
		clearTimeout( adjustImageSizeTimer );
		adjustImageSizeTimer = setTimeout( function(){ adjustImageSize(img, maxWidth, maxHeight); }, 500 );
	}
}

function adjustImageSizeComplete(img, maxWidth, maxHeight)
{
	clearTimeout( adjustImageSizeTimer );
	if ( img.src.indexOf("/1p.gif") != -1 )
	{
		img.border = "0";
		return;
	}
	
	var w = 0;
	var h = 0;
	try
	{
		var w1 = img.width;
		var h1 = img.height;
		
		// Avoid resizing image nor width neither height equals 0
		if ( w1 <= 0 || h1 <= 0 ) return;
		//debugMsg( arguments, "src=" + img.src + "\nw1=" + w1 + "\nh1=" + h1 );		
		
		var c = 0;
		if ( w1 > h1 ) c = maxWidth / w1;
		else c = maxHeight / h1;

		w = Math.round(w1 * c);
		h = Math.round(h1 * c);
		if ( isNaN(w) ) w = 0;			
		if ( isNaN(h) ) h = 0;						
		img.width = w;			
		img.height = h;						
		

		// V2 JT 22/08/2006
		img.border = "1";
		//debugMsg( arguments, "w=" + w + "\nh=" + h );
	}
	catch (e) 
	{ 
		alert("Error in adjustImageSize (CommonScript.js) : "+e.message); 
	}
	img.style.visibility = "visible";
}
//-----------------------------------------------------------------------------------------------
function errorOnImage(obj)
{
	try
	{
		//alert( "[DBG CommonScript.js errorOnImage]" );
		imgError = true;
		var img = new Image();
		var langDirectory = "/Gb";
		langDirectory = getBody().document.FORM1.Directory.value;
		img.src = "/actricity/theme/Images" + langDirectory + "NotAnImage.gif";
		obj.onload = myVoid;
		obj.src = img.src;
		obj.border = 1;
		obj.width=150;
		//adjustImageSize( obj, 72, 72 );				
		//obj.title = getBody().TC_OBJ_NOT_FOUND;
	} 
	catch (e) 
	{
		alert("Error in errorOnImage(CommonScript.js) : "+e.message); 
	}
}
//-----------------------------------------------------------------------------------------------
function getPreviewByDoc( docId )
{
	showDocumentFromId( docId );
}
//-----------------------------------------------------------------------------------------------
function getPreviewByRef( server, refdoc )
{
	getAPreviewByRef( server, refdoc );
}
//-----------------------------------------------------------------------------------------------
function getAPreviewByRef( server, refdoc )
{
	showFile( server, refdoc, false );
}
//-----------------------------------------------------------------------------------------------
function genTR(className)
{
	if (className=="functionTextInactive") return '<TR class="functionTextInactive">';
	return '<TR onmouseover="this.style.color=\'#aa2200\';" onmouseout="this.style.color=\'#242F35\';"class="'+className+'">';
}
//-----------------------------------------------------------------------------------------------

// ================
// TEXTAREA edition
// ================
function editTextarea(element, event, tableField)
{
	// Already in a textarea editor ?
	if ( document.FORM1.PageName.value == "TextareaEditor" ) return;
	try
	{
		if ( currentDisplayMode == "DSP_DSP" || currentDisplayMode == "DSP_DLT" || currentDisplayMode.indexOf("DSP_LST") >= 0 ) currentMode = "DISPLAY";
		else currentMode = "EDIT";
	}
	catch (e) { alert(e.message); }
	
	try 
	{
		if (event.target) currentTextarea = event.target;
		currentTextarea = element;
	} 
	catch (e) {}

	try
	{
		winEdit = window.open("/actricity/Common/Objects/TextareaEditor.jsp?WinID=" + getBody()._winID + "&tableField=" + tableField, "EDIT", "width=700,height=460,resizable");
		winEdit.focus();
	}
	catch (e) { alert(e.message); }
}

function editRichTextarea( element, event)
{
	try
	{
		if ( currentDisplayMode == "DSP_DSP" || currentDisplayMode == "DSP_DLT" || currentDisplayMode.indexOf("DSP_LST") >= 0 ) currentMode = "DISPLAY";
		else currentMode = "EDIT";
	}
	catch (e) { alert(e.message); }
	
	currentTextarea = element;
	
	try
	{
		winEdit = window.open("/actricity/Common/Objects/RichTextareaEditor.jsp", "EDIT", "fullscreen=yes,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,left=0,top=0,width=" + screen.availWidth + ",height="  + screen.availHeight);
		winEdit.focus();
	}
	catch (e) { alert(e.message); }
}
//-----------------------------------------------------------------------------------------------
function textareaKeyUp(event, zone, type, size)
{
	var source = null;
	source = zone;

	try
	{	
		if (winEdit != null && winEdit != window) winEdit.document.FORM1.Text.value = source.value;
	}
	catch(e){}
	
	return keyPressedRefresh( event, zone, type, size );
}

// ================
// FOCUS management
// ================
function setFocus(event)
{
	var source = null;
	try 
	{
		if (event.target) source = event.target
	} catch (e) {source = this;}
	try
	{
		getBody().document.FORM1.FocusField.value = source.name;
	} catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setPageFocus()
{
	try
	{
		var f = getBody().document.FORM1.elements;
		var name = getBody().document.FORM1.FocusField.value;
		
		if ( getBody().document.FORM1.DisplayMode.value == "DSP_NEW" ) name = "";
		
		var wIdx = -1;
		for (i = 0; i < f.length; i++)
		{
			try
			{
				if ( (f[i].type == "text") || (f[i].type == "textarea") )
				{
					if ( f[i].disabled ) continue;
					if ( f[i].readonly ) continue;
					if ( f[i].ReadOnly ) continue;
					if ( wIdx == -1 ) wIdx = i;
					if ( (f[i].name == name) || (name == "") )
					{
		 				wIdx = i;
						break;
					}
				}
				else
				if ( f[i].type == "select-one" )
				{
					f[i].blur();
				}
			}
			catch (ex) { wIdx = -1; }
		}
	
		if ( wIdx >= 0 ) f[wIdx].focus();
		else getBody().focus();
	} 
	catch (e) {}
}


/* -------------------------------------------------------------------------------------------- */
// INFORMATION SHOWING MECHANISM
/* -------------------------------------------------------------------------------------------- */
var popX = 0;
var popY = 0;
var xOffset = 20;
var yOffset = 20;
var popText = null;
var popID = null;
var popupInfoDelay = 1000;

function showPopupInfo(element, popEvent, text) 
{
	if ( text == null || text.length == 0 ) return;

	var maxWidth  = eval( document.body.clientWidth - 20 );
	var maxHeight = eval( document.body.clientHeight - 30 );
	
	// lifetime [ms] : The duration of time before the tooltip is automatically terminated, as long as it is still activated.
	// delay [ms] : Time in milliseconds before the tip appears. 
	// closeAction ['hide'|'destroy'] : Determines if the tip should be destroyed (removed from DOM) or just hidden when deactivated. (If fading is used, hiding is forced) 
	// Need to remove the tooltip because of the combo content tooltip.
	// If not, the combo content tooltip shows always the first text.	
	return domTT_activate(element, popEvent, 'content', text, 'lifetime', 5000, 'delay', popupInfoDelay, 'advStyle', true, 'closeAction', 'destroy', 'maxWidth', maxWidth, 'maxHeight', maxHeight );
}
function hidePopupInfo(element, popEvent) 
{
	domTT_mouseout(element, popEvent);
}
function hideBodyPopupInfo() 
{
	getBody().domTT_deactivate( getBody().domTT_lastOpened );
}

function showPopupInput(element, popEvent, text, validateFnc, returnFnc, x, y ) 
{
	if ( text == null || text.length == 0 ) return;
	//text = _HTMLStringToString( text );
	//	hideBodyPopupInfo();	

	// lifetime [ms] : The duration of time before the tooltip is automatically terminated, as long as it is still activated.
	// delay [ms] : Time in milliseconds before the tip appears. 
	// closeAction ['hide'|'destroy'] : Determines if the tip should be destroyed (removed from DOM) or just hidden when deactivated. (If fading is used, hiding is forced) 
	// Need to remove the tooltip because of the combo content tooltip.
	// If not, the combo content tooltip shows always the first text.
	domTT_closeLink = '';
	if ( x != undefined && y!= undefined )
		return domTT_activate(element, popEvent, 'caption', '<img src="/actricity/theme/Images/Top/Return.gif" onclick="' + returnFnc + ';domTT_close(this)"> <img src="/actricity/theme/Images/Top/Run.gif" onclick="' + validateFnc + ';domTT_close(this)">', 'content', text, 'delay', popupInfoDelay, 'type', 'sticky', 'draggable', false, 'advStyle', true, 'closeAction', 'destroy', 'x', x, 'y', y);	
	else
		return domTT_activate(element, popEvent, 'caption', '<img src="/actricity/theme/Images/Top/Return.gif" onclick="' + returnFnc + ';domTT_close(this)"> <img src="/actricity/theme/Images/Top/Run.gif" onclick="' + validateFnc + ';domTT_close(this)">', 'content', text, 'delay', popupInfoDelay, 'type', 'sticky', 'draggable', false, 'advStyle', true, 'closeAction', 'destroy' );	
}

function showPopupVelcro(element, popEvent, text) 
{
	if ( text == null || text.length == 0 ) return;

	var maxWidth  = eval( document.body.clientWidth - 20 );
	var maxHeight = eval( document.body.clientHeight - 30 );
	
	// lifetime [ms] : The duration of time before the tooltip is automatically terminated, as long as it is still activated.
	// delay [ms] : Time in milliseconds before the tip appears. 
	// closeAction ['hide'|'destroy'] : Determines if the tip should be destroyed (removed from DOM) or just hidden when deactivated. (If fading is used, hiding is forced) 
	// Need to remove the tooltip because of the combo content tooltip.
	// If not, the combo content tooltip shows always the first text.	
	//alert( "[DBG CommonScript.js] showPopupVelcro\nmaxWidth=" + maxWidth + " maxHeight=" + maxHeight );
	return domTT_activate(element, popEvent, 'content', text, 'lifetime', 5000, 'delay', popupInfoDelay, 'type', 'velcro', 'advStyle', true, 'closeAction', 'destroy', 'maxWidth', maxWidth, 'maxHeight', maxHeight );
}

function showPopupTrail(element, popEvent, text) 
{
	if ( text == null || text.length == 0 ) return;

	var maxWidth  = eval( document.body.clientWidth - 20 );
	var maxHeight = eval( document.body.clientHeight - 30 );
	
	// lifetime [ms] : The duration of time before the tooltip is automatically terminated, as long as it is still activated.
	// delay [ms] : Time in milliseconds before the tip appears. 
	// closeAction ['hide'|'destroy'] : Determines if the tip should be destroyed (removed from DOM) or just hidden when deactivated. (If fading is used, hiding is forced) 
	// Need to remove the tooltip because of the combo content tooltip.
	// If not, the combo content tooltip shows always the first text.	
	return domTT_activate(element, popEvent, 'content', text, 'advStyle', false, 'trail', true, 'offsetY', 10, 'offsetX', 10, 'closeAction', 'destroy', 'maxWidth', maxWidth, 'maxHeight', maxHeight );
}

function updatePopup( tooltip_id, text ) 
{
	domTT_update( tooltip_id, text, "content" );
}
//-----------------------------------------------------------------------------------------------
function checkVisibility( obj )
{
	if ( obj.style.visibility == "hidden" || obj.style.display == "none" )
		return false;
	else
	{
		if ( document.all )
		{
	  		obj = obj.parentElement;
	  		while ( obj != null )
	  		{	
	  			if ( obj.style.display == "none" || obj.style.visibility == "hidden" ) 
					return false;
				obj = obj.parentElement;
	  		}
	  	}
	}
	return true;
}
//-----------------------------------------------------------------------------------------------
function openPopupWindow(event, popupText)
{
	try
	{
		if ( popupText == null || popupText == "undefined" || popupText == "" ) return;
		
		popupData = '<html><head><script src="/actricity/Common/CommonScript.js"></script><LINK rel="stylesheet" href="/actricity/theme/Master.css" type="text/css"></head><body onblur="window.close()"><div style="z-index:2" id="Data">' + popupText + '</div></body></html>';
		winPopup = window.open("about:blank", "POPUP", "width=300,height=150,top="+event.screenY+",left="+event.screenX);
		winPopup.document.open();
		winPopup.document.write( popupData );
		winPopup.document.close();
		var w = 0;
		var h = 0;
		
		try
		{
			var refObject = winPopup.document.getElementById("Data");
			w = refObject.offsetWidth;
			h = refObject.offsetHeight;
		}
		catch (ex)
		{
			w = 250;
			h = 150;
		}
		w += 20;
//		h += 10;
	
		winPopup.resizeTo( w, h );
		var wY = event.screenY + 10;
		var wX = event.screenX;
		if ( (event.screenY + h) > screen.height ) wY = screen.height - h - 50;
		if ( (event.screenX + w) > screen.width ) wX = event.screenX - w;
		winPopup.moveTo(wX, wY);
		winPopup.document.focus();
	}
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function closePopupWindow()
{
	if ( winPopup != null ) 
	{
		winPopup.close();
		winPopup = null;
	}
}


/* -------------------------------------------------------------------------------------------- */
// COMMON FUNCTIONS
/* -------------------------------------------------------------------------------------------- */
function setReturnButton(flag)
{
	try { getTop().setReturnButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setStackButton(flag)
{
	try { getTop().setStackButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setSubmitButton(flag)
{
	try { getTop().setSubmitButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setCancelButton(flag)
{
	try { getTop().setCancelRequest(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setDeleteButton(flag)
{
	try { getTop().setDeleteButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setQuickHelpButton(flag)
{
	try { getTop().setQuickHelpButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setSaveButton(flag)
{
	try { getTop().setSaveButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setCreateButton(flag)
{
	try { getTop().setCreateButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setCopyButton(flag)
{
	try { getTop().setCopyButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setSelectButton(flag)
{
	try { getTop().setSelectButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setClearButton(flag)
{
	try { getTop().setClearButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setRefreshButton(flag)
{
	try { getTop().setRefreshButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setPrintButton(flag)
{
	try { getTop().setPrintButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setExportButton(flag)
{
	try { getTop().setExportButton(flag); } catch (e) {}
}
function addExportOption( text, action )
{
	try { getTop().addExportOption( text, "getBody()." + action ); } catch (e) {}
}
function addPrintOption( text, action )
{
	try { getTop().addPrintOption( text, "getBody()." + action ); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setIndicatorButton(flag)
{
	try { getTop().setIndicatorButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setWorkflowButton(flag)
{
	try { getTop().setWorkflowButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setWorkButton(flag)
{
	try { getTop().setWorkButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setMemoButton(flag)
{
	try { getTop().setMemoButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setMailButton(flag)
{
	try { getTop().setMailButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setPhoneButton(flag)
{
	try { getTop().setPhoneButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setMediaButton(flag)
{
	try { getTop().setMediaButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setBatchButton(flag)
{
	try { getTop().setBatchButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setContextButton(flag)
{
	try { getTop().setContextVisibility(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setMenuButton(flag)
{
	try { getTop().setMenuButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setLogoutButton(flag)
{
	try { getTop().setLogoutButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setGanttButton(flag)
{
	try { getTop().setGanttButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setFavoriteButton(flag)
{
	try { getTop().setFavoriteButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setHelpButton(flag)
{
	try { getTop().setHelpButton(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function setBatchMessages(flag)
{
	try { getTop().setBatchMessages(flag); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function disableAllButton()
{
	try { getTop().ButtonsBar.DisableAll(); } catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function selectItem(i, event)
{
	selectItemList( i, event, list );
}
function selectItemList(i, event, selectedList)
{
	try
	{
		if ( selectedList == undefined || selectedList == null ) return;
		if ( event != null && event.shiftKey )
		{
			if ( selectedList[ i ].type == "checkbox" )
			{
				if ( selectedList[ i ].checked )
				{
					if ( i > lastSelectItem ) unselectAllLst( lastSelectItem + 1, i, selectedList);
					else unselectAllLst( i, lastSelectItem - 1, selectedList );		
				}
				else
				{
					if ( i > lastSelectItem ) selectAllLst( lastSelectItem + 1, i, selectedList );
					else selectAllLst( i, lastSelectItem - 1, selectedList );
				}
			 	selectedList[ i ].focus();
			 }		 
		}
		else
		{
			if (selectedList.length > 1)
			{
				 if ( selectedList[ i ].checked )
				 {
			 		unhighlight( selectedList[ i ].parentNode.parentNode );
				 	selectedList[ i ].checked = false;			 		
			 	 }
			 	 else
			 	 {
			 		highlight( selectedList[ i ].parentNode.parentNode );	 	 
			 		selectedList[ i ].checked = true;
				 }
 				 //debugMsg( arguments, "selectedList[" + i + "]=" + selectedList[i].checked );
			 	 // Case of radio button, only one check, so on each new item selected, unhighlight last item selected.
			 	 // ===================================================================================================
			 	 if ( selectedList[ i ].type == "radio" && lastSelectItem >= 0 )
			 	 {
			 	 	unhighlight( selectedList[ lastSelectItem ].parentNode.parentNode );
		 	 	 }
			 	 // ===================================================================================================		 	 
			}
			else 
			{
				var checked;
				if ( ie && selectedList.checked == undefined )
					checked = selectedList[ 0 ].checked;
				else
					checked = selectedList.checked;
				
				if ( checked )
				{
					if ( ie && selectedList.parentNode == undefined )
					{
				 		unhighlight( selectedList[ 0 ].parentNode.parentNode );
						selectedList[ 0 ].checked = false;
					}
				 	else
				 	{
				 		unhighlight( selectedList.parentNode.parentNode );
						selectedList.checked = false;
					}				 					 		
			 	}
			 	else
			 	{
 					if ( ie && selectedList.parentNode == undefined )
 					{
				 		highlight( selectedList[ 0 ].parentNode.parentNode );	 	 	 		
						selectedList[ 0 ].checked = true;			 						 		
				 	}
				 	else
				 	{
			 			highlight( selectedList.parentNode.parentNode );	 	 	 						 	
						selectedList.checked = true;
			 		}			 		
			 	}			
				i = 0;
			 }	 
		 	lastSelectItem = i;
		 }
	}
	catch(e)
	{alert( e.message );}
}

function highlight( tr )
{
	var childs = tr.childNodes;
	for (var j = 0; j < childs.length; j++) 
		try { childs[j].style.backgroundColor='#FEE3C4'; } catch(e) {}	
}

function highlightOver( tr )
{
	var childs = tr.childNodes;
	for (var j = 0; j < childs.length; j++) 
		try { childs[j].style.backgroundColor='#fef1e2'; } catch(e) {}	
}

function unhighlight( tr )
{
	var childs = tr.childNodes;
	for (var j = 0; j < childs.length; j++) 
		try { childs[j].style.backgroundColor='white';} catch(e) {}	
}

function unhighlightOver( tr, i, selectedList )
{
	if ( selectedList == undefined || selectedList == null ) return;
	var childs = tr.childNodes;
	if ( selectedList.length > 1 )
	{
		if ( selectedList[ i ].checked )
			highlight( tr );
		else
			unhighlight( tr );
	}
	else
	{
		var checked;
		if ( ie && selectedList.checked == undefined )
			checked = selectedList[ 0 ].checked;
		else
			checked = selectedList.checked;
		if ( checked )
			highlight( tr );
		else
			unhighlight( tr );		
	}
}

function selectItemTr( elem )
{
	var td = "";
	var childs = elem.childNodes;	
	for (var i = 0; i < childs.length; i++) 
   	{
   		input = childs[i].firstChild;
   		if ( input != null  )
   		{
   			if ( input.type == "checkbox" || input.type == "radio" )
	   		{
	   			input.checked = input.checked ? false : true;
	   		}
	   		break;
   		}
   	}
}
function selectItemInput( elem )
{
	if ( elem.type == "checkbox" || elem.type == "radio" )
	{
		elem.checked = elem.checked ? false : true;
	}
}

//-----------------------------------------------------------------------------------------------
function selectAll( begin, end )
{
	selectAllLst( begin, end, list );
}

function selectAllLst( begin, end, selectedList )
{
	if ( selectedList == null ) return;
	if ( begin == null && end == null ) allSelected = true;
	if ( begin == null ) begin = 0;
	if ( end == null ) end = selectedList.length - 1;
	
	if ( selectedList.length > 1 )
	{
		for ( i = begin; i <= end; i++ )
		{
			if ( !selectedList[ i ].disabled ) 
			{
				if ( selectedList[ i ].type == "radio" ) return;
				selectedList[ i ].checked = true;
				highlight( selectedList[ i ].parentNode.parentNode );
			}
		}
	}
	else
	{
		selectedList.checked = true;
		highlight( selectedList.parentNode.parentNode );
	}

}
//-----------------------------------------------------------------------------------------------
function unselectAll( begin, end )
{
	unselectAllLst( begin, end, list );
}

function unselectAllLst( begin, end, selectedList)
{
	if ( selectedList == null ) return;
	if ( begin == null && end == null ) allSelected = false;
	if ( begin == null ) begin = 0;
	if ( end == null ) end = selectedList.length - 1;
	
	if ( selectedList.length > 1 )
	{
		for ( i = begin; i <= end; i++ ) 
		{
			selectedList[ i ].checked = false;
			unhighlight( selectedList[ i ].parentNode.parentNode );
		}
	}
	else
	{
		selectedList.checked = false;
		unhighlight( selectedList.parentNode.parentNode );
	}
}
//-----------------------------------------------------------------------------------------------
function showImage(img)
{
	previewImageURL = img.alt;
	fenImage = window.open("/actricity/Common/Objects/ShowImage.jsp", "Viewer", "width=420,height=420,resizable");
}
//-----------------------------------------------------------------------------------------------
function actFields()
{
	try
	{
		var f = getBody().document.FORM1.elements;
		for (i = 0; i < f.length; i++)
		{
			try
			{
				if ( (f[i].type == "checkbox" || f[i].type == "radio") && currentDisplayMode != DSP_LST && currentDisplayMode != DSP_LST2 ) f[i].disabled = false;
				else if ( f[i].name.indexOf("RefLabel") < 0 && f[i].type != "visible" )
				{
					if ( f[i].type == "select-one" || f[i].type == "select-multiple" ) f[i].disabled = false;
					else f[i].setAttribute("readOnly", false);
					
					if (f[i].className.indexOf("Num") != -1)
					{
						f[i].className = "INPUT_Activ";
						f[i].style.textAlign = "right";
					}
					else f[i].className = "INPUT_Activ";
				}
			}
			catch (ex) {}
		}
	} 
	catch (ex) 
	{
		alert(ex);
	}
}
//-----------------------------------------------------------------------------------------------
function deactFields()
{
	try
	{
		var f = getBody().document.FORM1.elements;
		for (i = 0; i < f.length; i++)
		{
			try
			{
				if ( (f[i].type == "checkbox" || f[i].type == "radio") && currentDisplayMode != DSP_LST && currentDisplayMode != DSP_LST2 ) f[i].disabled = true;
				else if ( f[i].name.indexOf("RefLabel") < 0 && f[i].type != "hidden" )
				{
					if ( f[i].type == "select-one" || f[i].type == "select-multiple" ) f[i].disabled = true;
					else f[i].setAttribute("readOnly", true);
					
					if (f[i].className.indexOf("Num") != -1)
					{
						f[i].className = "INPUT_Inactiv";
						f[i].style.textAlign = "right";
					}
					else f[i].className = "INPUT_Inactiv";
					
					images = document.getElementsByName( "imgExtkey" + f[i].name );
					for ( var j = 0; j < images.length; j++ )
					{
						images[ j ].style.display = "none";
					}
					
				}
				
			}
			catch (ex) {}
		}
	} 
	catch (ex) 
	{
		alert(ex);
	}
}
//-----------------------------------------------------------------------------------------------
function deactFieldsList(lFields)
{
	deactFieldsListForm(getBody().document.FORM1, lFields);
}
function deactFieldsListForm(form, lFields)
{
	try
	{
		var l = ";"+lFields+";";
		var f = form.elements;
		var images;
		
		for (i = 0; i < f.length; i++)
		{
			try
			{
				if ( l.indexOf( ";"+f[i].name+";" ) != -1 )
				{
					if ( f[i].type == "select-one" || f[i].type == "select-multiple" ) f[i].disabled = true;
					else f[i].setAttribute("readOnly", true);
					
					if (f[i].className.indexOf("Num") != -1)
					{
						f[i].className = "INPUT_Inactiv";
						f[i].style.textAlign = "right";
					}
					else f[i].className = "INPUT_Inactiv";
					
					images = document.getElementsByName( "imgExtkey" + f[i].name );
					for ( var j = 0; j < images.length; j++ )
					{
						images[ j ].style.display = "none";
					}
				}
			}
			catch (ex) {}
		}
	}
	catch (e) 
	{ 
		alert(e.message); 
	}
}
//-----------------------------------------------------------------------------------------------
function resetLabels()
{
	var a;
	
	for ( var i = 0; i < labels.length; i++ )
	{
		a = document.getElementById( labels[ i ] );
		if ( a != null )
			a.style.display = "none";
	}
}
//-----------------------------------------------------------------------------------------------
function resetFORM1()
{
	clearFORM1( getBody().document.FORM1 );
}
//-----------------------------------------------------------------------------------------------
function clearFORM1(f)
{
	var searchKey = "";
	
	for ( var i = 0; i < f.length; i++)
	{
		if ( !f.elements[ i ].disabled )
		{
			if (f.elements[ i ].type == 'text')
			{
				if (f.elements[ i ].name.indexOf("RefLabel") >= 0)
				{
					searchKey = document.getElementsByName( f.elements[ i ].name.substring( 8 ) )[0];			
					try
					{
						if ( !searchKey.disabled )
							f.elements[ i ].style.visibility = "hidden";
					}
					catch(e)
					{
						f.elements[ i ].style.visibility = "hidden";
					}							
				} 
				else
					f.elements[ i ].value='';
			}
			else if (f.elements[ i ].type == 'select-one')
			{
				if ( f.elements[ i ].length > 0 )
					f.elements[ i ].options[ 0 ].selected = true;
			}
			else if (f.elements[ i ].type == 'select-multiple' )
			{
				try{ unselectAllList( "listbox" + f.elements[ i ].name ); } catch(e) {}
					
				// Remove arrows
				try
				{
					document.getElementById( "MoreValuesUp" + f.elements[ i ].name ).style.visibility = "hidden";
					document.getElementById( "MoreValuesDown" + f.elements[ i ].name ).style.visibility = "hidden";				
				}
				catch(e) {}
			}
		}
	}
	
	try{ resetLabels(); } catch(e) {}
	
	// Show all values for combo list
	try{ resetCombos(); } catch(e) {}
}
//-----------------------------------------------------------------------------------------------
function checkFORM1() { return true; }

function submitFORM1()
{
	// Additional check
	// ================
	try { if ( !checkFORM1() ) return; } catch (e) {}

	try 
	{
		if ( document.FORM1.Function.value == "VALIDATE" && (document.FORM1.DisplayMode.value == "INTERFACE" || document.FORM1.DisplayMode.value == "TRANSLATE" ) )
			if ( !displayConfirmValidate() ) return;
	} 
	catch (e) {}
	
	if ( submited ) return;
	submited = true;

	// Add Address data when screen manages addresses
	// ==============================================
	try
	{
		if ( document.FORM1.PROCESS_ADDRESS != null && document.FORM1.PROCESS_ADDRESS != "undefined" && document.FORM1.PROCESS_ADDRESS.value == "1" ) setFORM1AddressParameters();
	}
	catch (e) {}
	
	// Add Media data when screen manages medias
	// =========================================
	try
	{
		if ( document.FORM1.PROCESS_MEDIA != null && document.FORM1.PROCESS_MEDIA != "undefined" && document.FORM1.PROCESS_MEDIA.value == "1" ) setFORM1MediaParameters();
	}
	catch (e) {}
	
	// Add Ticket Item Type List 1 
	// ================================================
	try
	{
		if ( document.FORM1.IIQL_INVOICE_ITEM != null && document.FORM1.IIQL_INVOICE_ITEM != "undefined" && document.FORM1.IIQL_INVOICE_ITEM.value == "1" ) IIQL_generateINPUT_List();
	}
	catch (e) {}

	// Add Ticket Item Type List 1 
	// ================================================
	try
	{
		if ( document.FORM1.LT1_TICKET_ITEM != null && document.FORM1.LT1_TICKET_ITEM != "undefined" && document.FORM1.LT1_TICKET_ITEM.value == "1" ) LT1_generateINPUT_List();
	}
	catch (e) {}

	// Add Ticket Item Type List 3
	// ================================================
	try
	{
		if ( document.FORM1.LT3_TICKET_ITEM != null && document.FORM1.LT3_TICKET_ITEM != "undefined" && document.FORM1.LT3_TICKET_ITEM.value == "1" ) LT3_generateINPUT_List();
	}
	catch (e) {}

	// Add Ticket Item Type List 4
	// ================================================
	try
	{
		if ( document.FORM1.LT4_TICKET_ITEM != null && document.FORM1.LT4_TICKET_ITEM != "undefined" && document.FORM1.LT4_TICKET_ITEM.value == "1" ) LT4_generateINPUT_List();
	}
	catch (e) {}

	// Add Ticket Item Type List 5 
	// ================================================
	try
	{
		if ( document.FORM1.LT5_TICKET_ITEM != null && document.FORM1.LT5_TICKET_ITEM != "undefined" && document.FORM1.LT5_TICKET_ITEM.value == "1" ) LT5_generateINPUT_List();
	}
	catch (e) {}

	// Add Subscription data 
	// ================================================
	try
	{
		if ( document.FORM1.SUBSCRIPTION_LIST != null && document.FORM1.SUBSCRIPTION_LIST != "undefined" && document.FORM1.SUBSCRIPTION_LIST.value == "1" ) generateINPUT_List();
	}
	catch (e) {}

	// Add Action Diary data 
	// ================================================
	try
	{
		if ( document.FORM1.PROCESS_ACTIONDIARY != null && document.FORM1.PROCESS_ACTIONDIARY != "undefined" && document.FORM1.PROCESS_ACTIONDIARY.value == "1" ) generateINPUT_List_diary();
	}
	catch (e) {}

	// Add Action Return data 
	// ================================================
	try
	{
		if ( document.FORM1.PROCESS_ACTIONRETURN != null && document.FORM1.PROCESS_ACTIONRETURN != "undefined" && document.FORM1.PROCESS_ACTIONRETURN.value == "1" ) generateINPUT_List_return();
	}
	catch (e) {}

	// Add Action Spesen data 
	// ================================================
	try
	{
		if ( document.FORM1.PROCESS_ACTIONSPESEN != null && document.FORM1.PROCESS_ACTIONSPESEN != "undefined" && document.FORM1.PROCESS_ACTIONSPESEN.value == "1" ) generateINPUT_List_spesen();
	}
	catch (e) {}

	// Add Movement Item data 
	// ================================================
	try
	{
		if ( document.FORM1.PROCESS_MVTITEM != null && document.FORM1.PROCESS_MVTITEM != "undefined" && document.FORM1.PROCESS_MVTITEM.value == "1" ) generateINPUT_List_mvtitem();
	}
	catch (e) {}

	// Adapt function when INTERFACE is request on Confirm Delete screen
	// =================================================================
	try
	{
		if ( (currentDisplayMode == "DSP_DLT") && ((document.FORM1.DisplayMode.value == "INTERFACE") || (document.FORM1.DisplayMode.value == "TRANSLATE")) )
		{
			document.FORM1.Function.value = "";
		}
	}
	catch (ex) {}

	// Get main frame id
	// =================
	try 
	{ 
		if ( parent.Actricity_Frame_ID != null ) document.FORM1.WinID.value = parent.Actricity_Frame_ID; 
	} 
	catch (e) {}
	
	// Get all expanded references for Tree View only
	// ==============================================
	try { getAllExpanded(); } catch (e) {}
	
	// Save pulldown state
	// ===================
	try
	{
		var out = "";
		var aArray = getBody().PullDown;
		for (x=0; x<aArray.length; x++) 
		{ 
			out += aArray[x].name +"="+ aArray[x].attr + "#" + aArray[x].onOpenEvent + "#" + aArray[x].onCloseEvent + ";"; 
		}
		getBody().document.FORM1.PullDown.value = out;
	}
	catch (e) {}

	// Save tree state
	// ===================
	try
	{
		var out = "";
		var aArray2 = getBody().treeAjaxOpenIds.toArray();
		for (x=0; x<aArray2.length; x++) 
		{ 
			out += aArray2[x].id + "=" + aArray2[x].url + "," + aArray2[x].params + "," + aArray2[x].opened + ";"; 
		}
		getBody().document.FORM1.TreeNode.value = out;
		//alert( "[DBG CommonScript.js] submitFORM1()\nout=" + out );
	}
	catch (e) {}
	
	// 2007/12/12 JT ACT-004613
	// ========================
	if ( translateCopyAll )
	{
		getBody().translate();
	}
	// ========================
		
	try
	{
		if ( updatedToReset )
		{
			eval( "document.FORM1." + document.FORM1.PageName.value + "RecordUpdated.value = '0'" );	
		}
	}
	catch (e) {}
	
	// Now submit form !
	// =================
	try
	{
		document.FORM1.submit();
		if ( getTop() != null )
		{
			startWait();			
			// getTop().setCancelRequest(true);
			getTop().setSubmitButton(false);		
			getTop().ButtonsBar.Draw();		
		} 
	} 
	catch (e) 
	{ 
		alert("Common Script Error while sending document.FORM1 " + this + " : " + e.message); 
	}
}
//-----------------------------------------------------------------------------------------------
function startWait()
{
	try
	{
		document.FORM1.wait.src = "/actricity/theme/Images/Top/Waiting.gif";
		document.body.style.cursor = "wait";
	}
	catch (e) {}
}
function stopWait()
{
	try
	{
		document.FORM1.wait.src = "/actricity/theme/Images/Top/NotWaiting.gif";
		document.body.style.cursor = "default";
	}
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function convertReferences()
{
	try
	{
		var f = document.FORM1.elements;
		for (i = 0; i < f.length; i++)
		{
			try
			{
				if ( ((f[i].type == "text") || (f[i].type == "textarea")) && (f[i].name.indexOf("RefLabel") >= 0) )
				{
					
					if (f[i].value == "") f[i].ondblclick = myVoid();
					else f[i].value = checkHTMLKeywords(f[i].value);
				}
			}
			catch (ex) {}
		}
	}
	catch (ex) {}
}
//-----------------------------------------------------------------------------------------------
function checkHTMLKeywords(value)
{
	var result = "";
	var inKeyword = false;
	for ( x=0; x<value.length; x++)
	{
		if ( value.charAt(x) == "<" ) inKeyword = true;
		else if ( value.charAt(x) == ">" && inKeyword ) inKeyword = false;
		else if ( !inKeyword ) result += value.charAt(x);
	}
	return result;
}
//-----------------------------------------------------------------------------------------------
function backMenu()
{
	getTop().menuOption();
}
//-----------------------------------------------------------------------------------------------
function validate()
{
	//debugMsg( arguments, "" );
	try
	{
		if (currentDisplayMode == "INVITE")
		{
			// V2 JT 19/06/06
			//dsp();
			upd();
			// ==============			
		}
		// JT 02/12/2005
		//else if (currentDisplayMode == "DSP_LST")
		//{
		//	dspDL();
		//}
		else
		{	
			document.FORM1.Function.value = "VALIDATE";
			updatedToReset = true;			
			submitFORM1();		
		}
	}
	catch (e) { alert(e.message); }
}
//-----------------------------------------------------------------------------------------------
function reloadFORM1()
{
	var DisplayMode = getBody().document.FORM1.DisplayMode.value;
	if ( DisplayMode == "INVITE" ) getBody().document.FORM1.Function.value = "";
	else if ( DisplayMode != "DSP_NEW" ) getBody().document.FORM1.Function.value = "FIND";
	updatedToReset = true;
	getBody().document.FORM1.DisplayMode.value = "";	
	submitFORM1();
}
//-----------------------------------------------------------------------------------------------
function refreshFORM1()
{
	var DisplayMode = getBody().document.FORM1.DisplayMode.value;
	if ( DisplayMode == "INVITE" ) getBody().document.FORM1.Function.value = "";
	else if ( DisplayMode != "DSP_NEW" ) getBody().document.FORM1.Function.value = "REFRESH";
	if ( updatedToReset ) updatedToReset = false;
	else updatedToReset = true;
	getBody().document.FORM1.DisplayMode.value = "";
	submitFORM1();
}
/* -------------------------------------------------------------------------------------------- */
// NAVIGATION FUNCTIONS
/* -------------------------------------------------------------------------------------------- */
function setNavigationFunctions(o)
{
	try
	{
		getTop().setNavigationOption(o);
	}
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function first()
{
	if ( displayConfirm() ) return;
	getBody().document.FORM1.Function.value = "FIRST";
	updatedToReset = true;
	submitFORM1();
}
//-----------------------------------------------------------------------------------------------
function next()
{
	if ( displayConfirm() ) return;
	getBody().document.FORM1.Function.value = "NEXT";
	updatedToReset = true;	
	submitFORM1();
}
//-----------------------------------------------------------------------------------------------
function previous()
{
	if ( displayConfirm() ) return;
	getBody().document.FORM1.Function.value = "PREVIOUS";
	updatedToReset = true;	
	submitFORM1();
}
//-----------------------------------------------------------------------------------------------
function last()
{
	if ( displayConfirm() ) return;
	getBody().document.FORM1.Function.value = "LAST";
	updatedToReset = true;	
	submitFORM1();
}

/* -------------------------------------------------------------------------------------------- */
// KEYBOARD FUNCTIONS
/* -------------------------------------------------------------------------------------------- */
function keyPressedCommon(eventObj, zone, fieldType, maxLength, keyCode)
{
	var result  = true;

	try
	{	
		//alert( "[DBG CommonScript.js] keyPressedCommon()\nkeyCode=" + keyCode );
		// V2 JT 10/10/06
		// ==============
		// Backspace, Delete and Space
		if ( eventObj.type == "keydown" )
		{
			//alert( "[DBG CommonScript.js] keyPressedCommon()\nkeydown" );
			if (keyCode == 8 || keyCode == 46 || keyCode == 32 ) 
			{
				checkUpdate();
			}
			if ( ie )
			{
				if (keyCode == 8 || keyCode == 46 )
					if (fieldType == "N") numericField(keyCode, zone);
			}
			// Return if event is keyDown, because keyCode values are not good
		 	return true;
		}
		if ( !ie && !ie7 )
		{
			// ==============
			// Paste
			var pasteChar = /[v]/i;
			var valueBefore = zone.value;
			if ( eventObj.ctrlKey && pasteChar.test( String.fromCharCode( keyCode ) ) )
			{
				if ( zone.selectionStart < zone.selectionEnd ) maxLength = maxLength - 1;
				setTimeout( function(){keyPaste( eventObj, zone, fieldType, maxLength, valueBefore );},10);			
				return true;
			}
			// ==============
			// Copy
			var copyChar = /[c]/i;
			if ( eventObj.ctrlKey && copyChar.test( String.fromCharCode( keyCode ) ) )
			{
				return true;
			}
		}

		// If fieldType is numeric and backspace is pressed, not return immediately to format number
		//if (keyCode <= 31 && fieldType != "SN" && fieldType != "N" )
		//{
		//	checkUpdate();
		//	return true;
		//}
	
		if ((keyCode == 45) && ((fieldType == "I") || (fieldType == "SI")) )
		{
			var v = parseInt(zone.value);
			if ( isNaN(v)) v = 0;
			v -= 1;
			if (fieldType == "SI") zone.value = v;
			else if (v >= 0) zone.value = v;
		}
		if ((keyCode == 43) && ((fieldType == "I") || (fieldType == "SI")) )
		{
			var v = v = parseInt(zone.value);
			if ( isNaN(v)) v = 0;
			v += 1;
			zone.value = v;
		}
		if (fieldType == "I") result = integerField(keyCode);
		else if (fieldType == "N") result = numericField(keyCode, zone);
		else if (fieldType == "SN") result = signedNumericField(keyCode, zone);
		else if (fieldType == "SI") result = signedIntegerField(keyCode, zone);
		else if (fieldType == "T") result = timeField(keyCode, zone);
		else if ( keyCode == 34 ) return false;
	
		//alert( "[DBG CommonScript.js] keyPressedCommon()\nmaxLength=" + maxLength );
		if ( (maxLength > 0) && (result == true) )
		{
			//alert( "[DBG CommonScript.js] keyPressedCommon()\nzone.value.length=" + zone.value.length );
			if (zone.value.length >= maxLength)
			{			
				if ( getBody() != null )
				{
					if ( timer == undefined )
					{
						timer = setTimeout( "getBody().status='" + getBody().status + "';timer=undefined;", 3000 );		
						getBody().status = TC_TextMaxLen+" "+maxLength;
					}
				}
				result = false;
			}
		}
	} 
	catch (e) {}
	// V2 JT 10/10/06
	// ==============
	if ( result ) checkUpdate();
	// ==============	

	return result;
}

function restoreCursorPos( zone, selStart, length )
{
	var elem;
	if ( document.FORM1.elements[ zone ] == null )
	{
		if ( document.getElementById( zone ) == null )
			elem = document.getElementById( zone )
	}
	else
		elem = document.FORM1.elements[ zone ];
		
	if ( elem != null )
	{
		if ( elem.value.length != length )
		{
			//debugMsg( arguments, "selStart=" + selStart + "\nelem.value.length=" + elem.value.length + "\nlength=" + length );
			selStart = selStart + elem.value.length - length;
			setCursorPos( elem, selStart );
		}
	}
}

function keyCode( event )
{
	var keyCode = null;
	var evt = ( event ) ? event : ( window.event ) ? window.event : null; 
	if ( evt )
		keyCode = ( evt.charCode ) ? evt.charCode : ( ( evt.keyCode ) ? evt.keyCode : ( ( evt.which ) ? evt.which : 0 ) );
	return keyCode;
}

function keyPressed(eventObj, zone, fieldType, maxLength)
{
	var result  = true;
	var key = keyCode( eventObj );
	
	//debugMsg( arguments, "keyPressed\nkey = " + key );

	try
	{
		if ( ie )
		{
			if ( document.selection.createRange().text.length > 0 )
				maxLength = maxLength + 1;
		}
		else
			if ( zone.selectionStart < zone.selectionEnd ) maxLength = maxLength + 1;
		
		// 9  : Tab
		// 35 : Home
		// 36 : End
		// 37 : Left arrow
		// 39 : Right arrow
		if ( key == 9 || key == 35 || key == 36 || key == 37 || key == 39 ) return true;
		
		if ( zone.value.length >= maxLength )
		{
			// keyCodes :
			// 8  : backspace
			// 46 : delete			
			if ( key == 8 || key == 46 || key == 37 || key == 38 || key == 39 || key == 40 )
				return true;
		}
			
		if ( (key == 13) && (zone.type != "textarea") )
		{
			try { changeValue(zone); } catch (e1) {}
			return false;
		}
		return keyPressedCommon(eventObj, zone, fieldType, maxLength, key );
	} 
	catch (e2){}
	return true;
}

function keyPressedRefresh(eventObj, zone, fieldType, maxLength)
{
	var result  = true;
	var key = keyCode( eventObj );
	
	try
	{
		if ( ie )
		{
			if ( document.selection.createRange().text.length > 0 )
				maxLength = maxLength + 1;
		}
		else
			if ( zone.selectionStart < zone.selectionEnd ) maxLength = maxLength + 1;
			
		// 9  : Tab
		// 35 : Home
		// 36 : End
		// 37 : Left arrow
		// 39 : Right arrow
		if ( key == 9 || key == 35 || key == 36 || key == 37 || key == 39 ) return true;
		
		if ( zone.value.length >= maxLength )
		{
			// keyCodes :
			// 8  : backspace
			// 46 : delete			
			if ( key == 8 || key == 46 || key == 37 || key == 38 || key == 39 || key == 40 )
				return true;
		}
			
		if ( (key == 13) && (zone.type != "textarea") )
		{
			try { changeValue(zone); } catch (e) {}
			// Start JT 2005/09/16 : Enter doesn't validate
			//validate();
			updatedToReset = true;
			refreshFORM1();
			// End JT
			return false;
		}
		return keyPressedCommon( eventObj, zone, fieldType, maxLength, key );
	} catch (e) {}

	return true;
}

function keyPressedFnc(eventObj, zone, fieldType, maxLength, returnFnc)
{
	var result  = true;
	var key = keyCode( eventObj );
	
	try
	{
		if ( ie )
		{
			if ( document.selection.createRange().text.length > 0 )
				maxLength = maxLength + 1;
		}
		else
			if ( zone.selectionStart < zone.selectionEnd ) maxLength = maxLength + 1;

		// 9  : Tab
		// 35 : Home
		// 36 : End
		// 37 : Left arrow
		// 39 : Right arrow
		if ( key == 9 || key == 35 || key == 36 || key == 37 || key == 39 ) return true;
		
		if ( zone.value.length >= maxLength )
		{
			// keyCodes :
			// 8  : backspace
			// 46 : delete			
			if ( key == 8 || key == 46 || key == 37 || key == 38 || key == 39 || key == 40 )
				return true;
		}
			
		if ( (key == 13) && (zone.type != "textarea") )
		{
			try { changeValue(zone); } catch (e) {}
			updatedToReset = true;
			//debugMsg( arguments, "returnFnc=" + returnFnc );
			eval( returnFnc );
			return false;
		}
		return keyPressedCommon( eventObj, zone, fieldType, maxLength, key );
	} catch (e) {alert( e.message );}

	return true;
}

function keyPressedValidate(eventObj, zone, fieldType, maxLength)
{
	var result  = true;
	var key = keyCode( eventObj );

	try
	{
		if ( ie )
		{
			if ( document.selection.createRange().text.length > 0 )
				maxLength = maxLength + 1;
		}
		else
			if ( zone.selectionStart < zone.selectionEnd ) maxLength = maxLength + 1;
			
		// 9  : Tab
		// 35 : Home
		// 36 : End
		// 37 : Left arrow
		// 39 : Right arrow
		if ( key == 9 || key == 35 || key == 36 || key == 37 || key == 39 ) return true;
		
		if ( zone.value.length >= maxLength )
		{
			// keyCodes :
			// 8  : backspace
			// 46 : delete			
			if ( key == 8 || key == 46 || key == 37 || key == 38 || key == 39 || key == 40 )
				return true;
		}
			
		if ( (key == 13) && (zone.type != "textarea") )
		{
			try { changeValue(zone); } catch (e) {}
			validate();
			return false;
		}
		return keyPressedCommon( eventObj, zone, fieldType, maxLength, key );
		
	} catch (e) {}

	return true;
}

// Check paste value
function keyPaste(eventObj, zone, fieldType, maxLength, value)
{
	var testChar;

	//debugMsg( arguments, "" );
	// Test S : String
	// All strings are accepted	
	
	// Test I : Integer
	if ( fieldType == "I" )
	{
		testChar = new RegExp( "^[0-9]*$", "g" );
		if ( !testChar.test( zone.value ) )
		{		
			// Don't paste
			zone.value = value;
			return;
		}
	}
	else
	{
		// Test N : Numeric
		if ( fieldType == "N" )
		{
			testChar = new RegExp( "^[0-9]*[,.]{0,1}[0-9]*$", "g" );
			if ( !testChar.test( zone.value ) )
			{
				// Don't paste
				zone.value = value;
				return;
			}
		}
	}
	
	checkUpdate();

	// Test length
	if ( maxLength > 0 && zone.value.length >= maxLength)
	{
		if ( timer == undefined )
		{
			timer = setTimeout( "getBody().status='" + getBody().status + "';timer=undefined;", 3000 );		
			getBody().status = TC_TextMaxLen+" "+maxLength;
		}
		zone.value = zone.value.substr( 0, maxLength );
		checkUpdate();
	} 
}

// Special function for IE : Get field value before paste.
function keyBeforePaste(eventObj, zone, fieldType, maxLength, valueBefore)
{
	setTimeout( function(){keyPaste( eventObj, zone, fieldType, maxLength, valueBefore );},10);
}

function getCursorStart( zone )
{
	var selStart;
	
	if ( ie )
	{
		zone.focus();
		var range = zone.createTextRange();
		range.moveToBookmark(document.selection.createRange().getBookmark());
		range.moveEnd('character', zone.value.length);
		selStart = zone.value.length - range.text.length;	
	}
	else
	{
		selStart = zone.selectionStart;
	}
	return selStart;
}

function getCursorEnd( zone )
{
	var selEnd;
	
	if ( ie )
	{
		zone.focus();
		var range = zone.createTextRange();
		range.moveToBookmark(document.selection.createRange().getBookmark());
		range.moveStart('character', - zone.value.length);
		selEnd = range.text.length;
		
	}
	else
	{
		selEnd = zone.selectionEnd;
	}
	return selEnd;
}

function setCursorPos( zone, pos )
{
	if ( ie )
	{
       var range = zone.createTextRange();
       range.moveStart('character', pos );
       range.moveEnd('character', pos );	       
       range.collapse();
       range.select();
	}
	else
	{
		zone.selectionStart = pos;
		zone.selectionEnd = pos;	
	}
}

/* -------------------------------------------------------------------------------------------- */
function integerField(keyCode)
{
	// Thousand separator
	if (keyCode == _thousandSeparator.charCodeAt( 0 ) ) return true;
	if ((( keyCode < 48) || ( keyCode > 57)) && (keyCode > 31)) return false;
	return true;
}
//-----------------------------------------------------------------------------------------------
function numericField(keyCode, f)
{
	var str = f.value;
	setTimeout( function(){ f.value = formatNumber( f.value ); }, 100 );	
	setTimeout( f.onchange, 110 );
	// Decimal separator
	if (keyCode == _decimalSeparator.charCodeAt( 0 ) ) return true;
	if ((( keyCode < 48) || ( keyCode > 57)) && (keyCode > 31)) return false;	
	return true;
}
//-----------------------------------------------------------------------------------------------
function parseFormatedFloat( value )
{
	var p = 0;
	var tempValue = "";
	
	// Remove thousand separators
	while ( ( p = value.indexOf( _thousandSeparator, 0 ) ) >= 0 )
	{
		tempValue = value.substring( 0, p );
		//Manage error like 123'  ,  123,45,
		if ( p + 1  < value.length )
			tempValue += value.substring( p + 1 );
		value = tempValue;
	}
	
	// Replace decimal separator
	if ( ( p = value.indexOf( _decimalSeparator, 0 ) ) >= 0 ) 
	{
		tempValue = value.substring( 0, p );
		//Manage error like 12. 
		if ( p + 1  < value.length )
		{
			tempValue += ".";
			tempValue += value.substring( p + 1 );			
		}
		value = tempValue;
	}
	return parseFloat( value );
}
//-----------------------------------------------------------------------------------------------
function signedIntegerField(keyCode, f)
{
	var str = f.value;
	
	// Thousand separator
	if (keyCode == _thousandSeparator.charCodeAt( 0 ) ) return true;
	
	// Only one "-" allowed
	if(keyCode == 45)
	{ 
		if (str.indexOf("-") < 0) f.value = "-" + f.value;
		if (str.indexOf("-") == 0) f.value = f.value.substring(1);
		return false;
	}
	if ((( keyCode < 48) || ( keyCode > 57)) && (keyCode > 31)) return false;
	return true;
}
//-----------------------------------------------------------------------------------------------
function signedNumericField(keyCode, f)
{
	var str = f.value;

	// Decimal separator
	if (keyCode == _decimalSeparator.charCodeAt( 0 ) )
	{
		if (str.indexOf( _decimalSeparator ) >= 0)
			return false;
		return true;			
	} 
	// Thousand separator
	if (keyCode == _thousandSeparator.charCodeAt( 0 ) ) return true;

	// Only one "-" allowed
	if(keyCode == 45)
	{ 
		if (str.indexOf("-") < 0) f.value = "-" + f.value;
		if (str.indexOf("-") == 0) f.value = f.value.substring(1);
		return false;
	}
	if ((( keyCode < 48) || ( keyCode > 57)) && (keyCode > 31)) return false;
	return true;
}
//-----------------------------------------------------------------------------------------------
function dateKeyPressed(eventObj, suffix)
{
	currentSuffix = suffix;	
	prvYY = document.FORM1.elements["yy"+currentSuffix];
	prvMM = document.FORM1.elements["mm"+currentSuffix];
	prvDD = document.FORM1.elements["dd"+currentSuffix];
	
	var evt = ( eventObj ) ? eventObj : ( window.event ) ? window.event : null; 
	if ( evt )
		var keyCode = ( evt.charCode ) ? evt.charCode : ( ( evt.keyCode ) ? evt.keyCode : ( ( evt.which ) ? evt.which : 0 ) );

	if ( keyCode == 13 )
	{
		return true;
	}
	// V2 JT 10/10/06
	// ==============
	// Backspace, Delete and Space
	if (keyCode == 8 || keyCode == 46 || keyCode == 32 ) 
	{
		checkUpdate();
		return true;
	}
	// ==============
	if (keyCode <= 31) return true;

	if ((( keyCode < 48) || ( keyCode > 57)) && (keyCode > 31)) return false;
	IDDate = setTimeout("checkDate()", 10);
	checkUpdate();
	return true;
}
//-----------------------------------------------------------------------------------------------
function hourKeyPressed(eventObj, f)
{
	prvHH = f;
	var keyCode = document.all ? eventObj.keyCode : eventObj.which;

	if ( keyCode == 13 )
	{
		return true;
	}
	// V2 JT 10/10/06
	// ==============
	// Backspace, Delete and Space
	if (keyCode == 8 || keyCode == 46 || keyCode == 32 ) 
	{
		checkUpdate();
		return true;
	}
	// ==============
	if (keyCode <= 31) return true;

	if ((( keyCode < 48) || ( keyCode > 57)) && (keyCode > 31)) return false;
	IDHour = setTimeout("checkHour()", 10);
	checkUpdate();
	
	return true;
}
//-----------------------------------------------------------------------------------------------
function minuteKeyPressed(eventObj, f)
{
	prvMIN = f;
	var keyCode = document.all ? eventObj.keyCode : eventObj.which;

	if ( keyCode == 13 )
	{
		return true;
	}
	// V2 JT 10/10/06
	// ==============
	// Backspace, Delete and Space
	if (keyCode == 8 || keyCode == 46 || keyCode == 32 ) 
	{
		checkUpdate();
		return true;
	}
	// ==============
	if (keyCode <= 31) return true;

	if ((( keyCode < 48) || ( keyCode > 57)) && (keyCode > 31)) return false;
	IDMinute = setTimeout("checkMinute()", 10);
	checkUpdate();

	return true;
}
//-----------------------------------------------------------------------------------------------
function checkMinute()
{
	if ( IDMinute == null ) return;
	
	clearTimeout(IDMinute);
	var mm = prvMIN.value;
	
	try
	{
		// Check Hour part
		// ===============
		if (  mm < 0 || mm > 59 )
		{
			prvMIN.value = "";
			return;
		}
		
		return;
	} 
	catch (e) { alert(e.message); }
}
//-----------------------------------------------------------------------------------------------
function checkHour()
{
	if ( IDHour == null ) return;
	
	clearTimeout(IDHour);
	var hh = prvHH.value;
	
	try
	{
		// Check Hour part
		// ===============
		if (  hh < 0 || hh > 23 )
		{
			prvHH.value = "";
			return;
		}
		
		return;
	} 
	catch (e) { alert(e.message); }
}
//-----------------------------------------------------------------------------------------------
function timeKeyPressed( event, elem )
{	
	var key = keyCode( event );
	
	if ( key == 35 || key == 36 || key == 37 ) return true;
	setTimeout( function(){ checkTime( key, elem, false  ); }, 10 );
	checkUpdate();
	if ( ie && ( key == 107 || key == 109 ) ) return false;
	if ( key == 43 || key == 45 ) return false;
}

function checkTime( keyCode, elem, formatAll )
{
	var exp  = new RegExp( ":", "ig" );
	var time = elem.value.split(exp);
	
	// Need to parseFloat because parseInt doesn't work well for 0x numbers
	// For example 09 gives 0	
	var hh  = parseFloat( time[ 0 ] );
	var mm  = parseFloat( time[ 1 ] );	

	function validHour()
	{
		if ( isNaN( hh ) ) return "00";
		if ( time[ 0 ].charAt( 0 ) == "0" && time[ 0 ].length == 3 ) return time[ 0 ].charAt( 0 ) + time[ 0 ].charAt( 1 ) + ":" + time[ 0 ].charAt( 2 );
		if ( hh < 10 ) return "0" + hh;
		// if ( hh < 24 ) OK
		if ( hh > 23 && hh < 100 )
		{
			if ( parseFloat( time[ 0 ].charAt( 0 ) ) < 10 ) return "0" + time[ 0 ].charAt( 0 ) + ":" + time[ 0 ].charAt( 1 );			
		 	return time[ 0 ].charAt( 0 ) + ":" + time[ 0 ].charAt( 1 );			
		 }
		if ( hh > 99 ) return time[ 0 ].charAt( 0 ) + time[ 0 ].charAt( 1 ) + ":" + time[ 0 ].charAt( 2);
		return hh;
	};
	
	function validMinute()
	{
		if ( isNaN( mm ) ) return "00";
		if ( mm < 10 ) return "0" + mm;
		// if ( mm < 60 ) OK
		if ( mm > 59 && mm < 100 ) return time[ 1 ].charAt( 0 );			
		// Maximum length = 5
		if ( mm > 99 ) return time[ 1 ].charAt( 0 ) + time[ 1 ].charAt( 1 );
		return mm;
	};

	try
	{	
		// Format all time
		if ( formatAll )
		{
			if ( elem.value.length > 0 ) elem.value = validHour() + ":" + validMinute();
		}
		else
		// :
		if ( keyCode != null & keyCode == 58 )
		{
			elem.value = validHour() + ":";
		}
		else
		// Right arrow
		if ( keyCode != null && keyCode == 39 )
		{
			if ( ie && time.length == 1 && elem.value.indexOf( ":" ) > 0 )
				elem.value = validHour() + ":" + validMinute();
			else
				if ( time.length <= 1 ) elem.value = validHour() + ":";
				else 		
					elem.value = validHour() + ":" + validMinute();
		}
		else
		// Plus
		if ( keyCode != null && ( ( ie && keyCode == 107 ) || keyCode == 43 ) )
		{
			mm++;
			if ( mm > 59 ) 
			{
				mm = 0;
				hh++;
			}
			if ( hh > 23 )
				hh = 0;
			elem.value = validHour() + ":" + validMinute();
		}
		else
		// Minus
		if ( keyCode != null && ( ( ie && keyCode == 109 ) || keyCode == 45 ) )
		{
			mm--;
			if ( mm < 0 )
			{
				mm = 59;
				hh--;
			}
			if ( hh < 0 )
				hh = 23;
			elem.value = validHour() + ":" + validMinute();				
		}		
		else
		{
			if ( time.length == 1 )
			{
				if ( elem.value.length > 1 ){  elem.value = validHour() };	
			}
			else
				if ( time.length >= 2 )
					if ( elem.value.length > 4 )
					{
					 	elem.value = validHour() 
					 	if ( elem.value.indexOf( ":" ) <= 0 )
					 		elem.value += ":" + validMinute();
					 }	
		}
	}
	catch(e){ alert(e.message);}
}

function timeField(keyCode, f)
{
	if ((( keyCode < 48) || ( keyCode > 58)) && (keyCode > 31) && keyCode!=37 && keyCode!=39 && keyCode!=43 && keyCode!=45 ) return false;
	
	if ( keyCode == 58 && f.value.indexOf( ":" ) > 0 ) return false;
	setTimeout( function(){ checkTime( keyCode, f, false ) }, 10);
	checkUpdate();
	if ( keyCode==43 || keyCode==45 ) return false;
	// Thousand separator
//	if (keyCode == _thousandSeparator.charCodeAt( 0 ) ) return true;
	return true;
}
//-----------------------------------------------------------------------------------------------
function durationHourKeyPressed( event, elem )
{	
	var key = keyCode( event );
	
	if ( key == 35 || key == 36 || key == 37 ) return true;
	// Save cursor position
	clearTimeout( blurTimer );
	var selStart = getCursorStart( elem );
	var selEnd = getCursorEnd( elem );
	var length = elem.value.length;	
	
	setTimeout( function(){ checkDuration( elem, key, true, false  ); }, 10 );
	checkUpdate();
	try { setTimeout( elem.onchange, 10 ); } catch(e) {}
	if ( ie && ( key == 107 || key == 109 ) ) return false;
	if ( key == 43 || key == 45 ) return false;
	
	// Restore cursor position
	if ( selStart == selEnd && key != 39 )
	{
		blurTimer = setTimeout( "restoreCursorPos( '" + elem.name + "', " + selStart + ", " + length + " );", 10 );
	}
}
function durationDayKeyPressed( event, elem )
{	
	var key = keyCode( event );
	setTimeout( function(){ checkDuration( elem, key, false, false  ); }, 10 );
	checkUpdate();
	try { setTimeout( elem.onchange, 10 ); } catch(e) {}
	if ( ie && ( key == 107 || key == 109 ) ) return false;	
	if ( key == 43 || key == 45 ) return false;
}

function checkDuration( elem, keyCode, hour, formatAll, DisplayDuration )
{
	var exp;
	var time;
	var type;
	var sep;
	var hh;
	var mm;

	//debugMsg(arguments, "elem.value=" + elem.value );
	if ( hour && elem.value.indexOf( ":" ) >= 0 )
	{
		if ( InputDuration == "2" )
		{
			elem.value = elem.value.substring( 0, elem.value.length - 1 );
			return;
		}
		else
		{
			exp  = new RegExp( ":", "ig" );
			time = elem.value.split(exp);
			type = 1;
			sep  = ":";		
			if ( ie )
			{
				if ( time[ 0 ].length + 1 == elem.value.length )
					time[ 1 ] = "";
			}
		}
	}
	else
	if ( elem.value.indexOf( _decimalSeparator ) >= 0 )
	{
		if ( InputDuration == "1" )
		{
			elem.value = elem.value.substring( 0, elem.value.length - 1 );
			return;
		}
		else
		{
			if ( _decimalSeparator == "." )
				exp  = new RegExp( "\\.", "ig" );
			else
				exp  = new RegExp( _decimalSeparator, "ig" );
				
			time = elem.value.split(exp);		
			type = 2;
			sep  = _decimalSeparator;	
			if ( ie )
			{
				if ( time[ 0 ].length + 1 == elem.value.length )
					time[ 1 ] = "";
			}	
		}
	}
	else
	{		
		time = new Array( elem.value );	
		if ( DisplayDuration == "1" )
		{
			type = 2;
			sep  = _decimalSeparator;				
		}
		else
		{
			type = 1;
			sep  = ":";		
		}
	}
	
	for ( var i = 0; i < time.length; i++ )
	{
		if ( i == 0 ) time[ i ] = parseFloat( unformatNumber( time[ i ] ) );
		else time[ i ] = unformatNumber( time[ i ] );
	}
		
	if ( formatAll )
	{
		if ( hour && DisplayDuration == "1" ) // hh:mm
		{
			if ( type == 2 ) // hh.mm
			{
				time[ 1 ] = eval( parseFloat( "0." + time [ 1 ] ) * 60 ).toString().replace( "\.", "" );
				type 	  = 1;
				sep 	  = ":";
			}
		}
		else
		// hh.mm
		{
			if ( hour )
				if ( type == 1 ) // hh:mm
				{
					time[ 1 ] = eval( time [ 1 ] / 6 ).toString().replace( "\.", "" );
					type	  = 2;
					sep 	  = _decimalSeparator;
				}
		}
		if ( time[ 0 ] == null || time[ 0 ].length == 0 ) hh = "0";
		else hh = time[ 0 ];
		mm = time[ 1 ];		 
		if ( type == 1 && parseFloat( mm ) < 10 ) mm = "0" + parseFloat( mm );

		if( time[ 1 ] == null || isNaN( time[ 1 ] ) || time[ 1 ] == undefined || time[ 1 ].length == 0 )
			elem.value = formatNumWithThousandSep( hh ) + ".00";		
		else elem.value = formatNumWithThousandSep( hh ) + sep + formatMinute( mm, type );		
	}
	else
	{
		try
		{
		if ( hour && type == 1 )
		{
			if ( time[ 1 ] != null && time[ 1 ].length > 0 )			
				eval( "document.FORM1." + elem.name.substring( 8 ) + ".value = " + eval( parseFloat(unformatNumber( time[ 0 ] )) + parseFloat((unformatNumber( time[ 1 ] ) / 60)) ) );
			else
				eval( "document.FORM1." + elem.name.substring( 8 ) + ".value = " + unformatNumber( time[ 0 ] ) );
		}
		else eval( "document.FORM1." + elem.name.substring( 8 ) + ".value = " + parseFloat( unformatNumber( time[ 0 ] ) + "." + unformatNumber( time[ 1 ] ) ) );
		}
		catch(e){}	
		// Right arrow
		if ( keyCode != null && keyCode == 39 && ( time.length < 2 || time[ 1 ].length == 0 ) )
		{
			if ( type == 1 && ( InputDuration == "2" || InputDuration == "3" ) ) sep = _decimalSeparator;
			if ( hour && type == 2 && ( InputDuration == "1" || InputDuration == "3" ) ) sep = ":";
			
			if ( time.length = 1 ) 
			{
				elem.value = formatNumWithThousandSep( time[ 0 ] );
				if ( elem.value.length <= 0 ) elem.value = "0";
				elem.value += sep;
			}
			else elem.value = formatNumWithThousandSep( time[ 0 ] ) + sep + formatMinute( time[ 1 ], type );
		}
		else
		// Plus
		if ( keyCode != null && ( ( ie && keyCode == 107 ) || keyCode == 43 ) )
		{
			hh = parseFloat( time[ 0 ] );
			if ( isNaN( time[ 1 ] ) )
			{
				hh++;
				elem.value = formatNumWithThousandSep( hh );
			}
			else
			{
				mm = parseFloat( time[ 1 ] );
				mm++;				
				if ( type == 2 && time[ 1 ].length == 1 && mm > 9 )
				{
					mm = "0";
					hh++;
				}
				if ( type == 1 && mm > 59 ) 
				{
					mm = "00";
					hh++;
				}				
				else
				if ( type == 2 && time[ 1 ].length == 2 && mm > 99 )
				{
					mm = "00";	
					hh++;				
				}
				
				if ( type == 1 && mm < 10 )
					mm = "0" + mm;
	
				if ( type == 2 && time[ 1 ].length == 2 && mm >= 0 && mm < 10 )
				{
					mm = "0" + mm;			
				}
						
				elem.value = formatNumWithThousandSep( hh ) + sep + formatNumWithDecimalSep( mm, 2 );
			}
	
		}
		else
			// Minus
			if ( keyCode != null && ( ( ie && keyCode == 109 ) || keyCode == 45 ) )
			{
				hh = parseFloat( time[ 0 ] );
				if ( isNaN( time[ 1 ] ) )
				{
					hh--;
					elem.value = formatNumWithThousandSep( hh );
				}
				else
				{	
					mm = parseFloat( unformatNumber( time[ 1 ] ) );
					mm--;
					if ( type == 2 && time[ 1 ].length == 1 && mm < 0 )
					{
						mm = 9;
						hh--;
					}
					if ( type == 2 && time[ 1 ].length == 2 && mm >= 0 && mm < 10 )
					{
						mm = "0" + mm;					
					}
					if ( type == 1 && mm < 0 )
					{
						mm = 59;
						hh--;
					}
					else
					if ( type == 2 && mm < 0 )
					{
						mm = 99;
						hh--;
					}
					
					if ( hh < 0 )
					{
						hh = "0";
						mm = "00";
					}
					if ( type == 1 && mm < 10 )
						mm = "0" + mm;
					elem.value = formatNumWithThousandSep( hh ) + sep + formatNumWithDecimalSep( mm, 2 );
				}
			}		
			else
			if ( !isNaN( time [ 1 ] ) )
				elem.value = formatNumWithThousandSep( time[ 0 ] ) + sep + formatMinute( time[ 1 ], type );
			else
				elem.value = formatNumWithThousandSep( time[ 0 ] );
	}		
}

function formatNumWithThousandSep( number )
{
	var t  = unformatNumber( number );

	var reg = new RegExp('[^0-9]+', 'g');
	if ( reg.test( t ) )
	{
		t = t.replace( /[^0-9]+/, '' );
	}
	
	if ( isNaN( t ) || t.length <= 0 ) return "";
	
	var cnt = 0;
	var newt = "";
	var j = 0;
	
	for ( var i = 0; i < t.length; i++ )
	{
		j = t.length - i;
		newt = newt + t.charAt( i );		
		if ( j > 3 && j % 3 == 1 )
			newt = newt + _thousandSeparator;
	}
	return newt;
}

function formatNumWithDecimalSep( number, decimal )
{
	//alert( "[DBG CommonScript.js] formatNumWithDecimalSep\nnumber = " + number + "\ndecimal = " + decimal );
	var tempNumber = number;
	var reg = new RegExp('[^0-9]+', 'g');
	if ( isNaN( number ) ) return "";	
	if ( reg.test( tempNumber ) ) tempNumber = tempNumber.replace( /[^0-9]+/, '' );
	if ( tempNumber.length > decimal ) tempNumber = tempNumber.substring( 0, decimal );
			
	return tempNumber;
}

function formatNumber( number )
{
	var num = "";
	number = number.toString();
	// Format is nnnnnnnn.ddddd
	if ( number.indexOf( _decimalSeparator ) >= 0 )
	{
		if ( _decimalSeparator == "." )
			exp  = new RegExp( "\\.", "ig" );
		else
			exp  = new RegExp( _decimalSeparator, "ig" );
				
		num = number.split( exp );		
		if ( num.length == 1 )
			// Case nnnn.
			num = formatNumWithThousandSep( num[ 0 ] ) + _decimalSeparator;
		else
			num = formatNumWithThousandSep( num[ 0 ] ) + _decimalSeparator + num[ 1 ];
	}
	else
	// Format is nnnnnnnn
	{
		num = formatNumWithThousandSep( number );
	}
	return num
	
}

function unformatNumber( number )
{
	var exp;
	var dec = "";
	
	// need a string for operations
	if ( number != undefined && number != null )
	{	
	  	number = number.toString();
 		if ( number.indexOf( _decimalSeparator ) >= 0 )
 		{
		  	if ( _decimalSeparator == "." )
				exp  = new RegExp( "\\.", "ig" );
			else
				exp  = new RegExp( _decimalSeparator, "ig" );
				
			var num = number.split( exp );
			number = num[ 0 ];
			dec = num [ 1 ]
			exp = new RegExp('[^0-9]+', 'g');
			if ( exp.test( dec ) ) dec = dec.replace( exp, '' );
		}
			
		exp = new RegExp('[^0-9]+', 'g');
		if ( exp.test( number ) ) number = number.replace( exp, '' );
	  	if ( _thousandSeparator == "." ) exp =  new RegExp( "\\.", "g" );
		else exp =  new RegExp( _thousandSeparator, "g" );
		number = number.replace( exp, "" );
		
		if ( dec != "" ) number = number + _decimalSeparator + dec;

		return number;
	}
	else
		number = "";
	return number;
}

function formatMinute( number, type )
{
	// type = 1 : minute is 1/60
	// type = 2 : minute is 1/100
	
	var mm = "";
	if ( isNaN( number ) ) return "";
	var tempNumber = number.toString();
	var reg = new RegExp('[^0-9]+', 'g');
	if ( reg.test( tempNumber ) ) tempNumber = tempNumber.replace( /[^0-9]+/, '' );
	//tempNumber = parseFloat( number );
	if ( tempNumber.length > 2 )
	{
	tempNumber = Math.round( parseFloat( "0." + tempNumber ) * 100 );
	}
	// if ( mm < 60 ) OK
	mm = parseFloat( tempNumber );
	//if ( type == 1 && mm < 10 ) return "0" + mm;	
	if ( type == 1 && mm > 59 && mm < 100 ) return tempNumber.substring( 0, 1 );			
	return tempNumber;
}
//-----------------------------------------------------------------------------------------------
function checkDate()
{
	checkDateForm(document.FORM1);
}

function checkDateForm(form)
{
	if ( IDDate == null ) return;
	
	clearTimeout(IDDate);
	
	var yyObj = form.elements["yy"+currentSuffix];
	var mmObj = form.elements["mm"+currentSuffix];
	var ddObj = form.elements["dd"+currentSuffix];
	
	var yy = -1;
	var mm = -1;
	var dd = -1;
	
	try { yy = parseInt( yyObj.value ); if ( isNaN(yy) ) yy = -1; } catch (e) { yy = -1; }
	try { mm = parseInt( mmObj.value ); if ( isNaN(mm) ) mm = -1; } catch (e) { mm = -1; }
	try { dd = parseInt( ddObj.value ); if ( isNaN(dd) ) dd = -1; } catch (e) { dd = -1; }

	var limit = 31;

	try
	{
		// Check Year part
		// ===============
		
// %% Start %%
// %% 08/04/08 VR Specific AEBI %%		
		/*
		if ( (yy != -1) && ( 
			 (yy > 2 && yy < 19 ) ||
			 (yy > 20 && yy < 195 ) ||
			 (yy > 205 && yy < 1950 ) ||
			 (yy > 2050 ) ) )
		{
//			alert(TC_YY_ERROR);
//			yyObj.focus();
			yyObj.value = "";
			return;
		}	
		*/
// %% End %%

		if ( (yy != -1) && ( yy > 9999 ) )
		{
//			alert(TC_YY_ERROR);
//			yyObj.focus();
			yyObj.value = "";
			return;
		}

		
		// Check Month part
		// ================
		if ( (mm != -1) && (mm < 1 || mm > 12) )
		{
//			alert(TC_MM_ERROR);
//			mmObj.focus();
			mmObj.value = "";
			return;
		}
		
		// Check Day part
		// ==============
		if ( dd != -1 )
		{
			if ( mm == 4 || mm == 6 || mm == 9 || mm == 11 ) limit = 30;
			else if ( mm == 2 )
			{
				limit = 28;
				
				if ((yy > 0) && (yy % 400 == 0 || (yy % 4 == 0 && yy % 100 != 0)) ) limit = 29;
			}
	
			if ( dd == 0 || dd > limit )
			{
//				alert(TC_DD_ERROR+limit);
//				ddObj.focus();
				ddObj.value = "";
				return;
			}
		}
		return;
	} 
	catch (e) { alert(e.message); }
}
//-----------------------------------------------------------------------------------------------
function _StringToFloat(v, decimalSep, thousandSep)
{
	var neg = "";
	if ( v.indexOf("-") != -1 ) neg = "-";

	if ( decimalSep != "." )
	{
		p = v.indexOf(decimalSep);
		v = v.substring(0, p)+"."+v.substring(p+1);
	}
	var r = "";
	for (i=0; i<v.length; i++)
	{
		if ( (v.charAt(i) != thousandSep) && (v.charAt(i) != "-") )  r += v.charAt(i);
	}
	v = neg + r;
	return parseFloat(r);
}
//-----------------------------------------------------------------------------------------------
function _StringToInt(v, decimalSep, thousandSep)
{
	var neg = "";
	if ( v.indexOf("-") != -1 ) neg = "-";

	if ( decimalSep != "." )
	{
		p = v.indexOf(decimalSep);
		v = v.substring(0, p)+"."+v.substring(p+1);
	}
	var r = "";
	for (i=0; i<v.length; i++)
	{
		if ( (v.charAt(i) != thousandSep) && (v.charAt(i) != "-") )  r += v.charAt(i);
	}
	v = neg + r;
	return parseInt(r);
}
/* -------------------------------------------------------------------------------------------- */
// PULL-DOWN MENU
/* -------------------------------------------------------------------------------------------- */
var currentGroupId = 0;
var currentGroupName = "";
var grpList = new Array();
//-----------------------------------------------------------------------------------------------
function GroupDef(id, name, text)
{
	this.id = id;
	this.name = name;
	this.text = text;
	this.optList = new Array();
}
//-----------------------------------------------------------------------------------------------
function OptionDef(fnc, text, icon, iAct, act)
{
	this.groupId = currentGroupId;
	this.fnc = fnc.indexOf("getBody()") == -1 ? "getBody()."+fnc : fnc;
	this.text = text;
	this.icon = icon;
	this.iAct = iAct;
	if ((act == "1") || (act == 1) || (act == true)) this.active = true;
	else this.active = false;
}
//-----------------------------------------------------------------------------------------------
function findGroupDef(name)
{
	for (i=0; i<grpList.length; i++)
	{
		if (grpList[i].name == name) return grpList[i];
	}
	return null;
}
//-----------------------------------------------------------------------------------------------
function clearMenuGroup(groupName)
{
	try
	{
		var groupDef = findGroupDef(groupName);
		groupDef.optList = new Array();
	} catch (e) {}

}
//-----------------------------------------------------------------------------------------------
function addPullDownGroup(name, text)
{
	addMenuGroup(name, text);
}
//-----------------------------------------------------------------------------------------------
function addMenuGroup(name, text)
{
	clearMenuGroup(name);
	var id = grpList.length;
	currentGroupId = id;
	currentGroupName = name;
	var grp = new GroupDef(id, name, text);
	grpList[grpList.length] = grp;

}
//-----------------------------------------------------------------------------------------------
function addPullDownOption(fnc, text, icon, iAct, act )
{
	addMenuOption( fnc, text, icon, iAct, act );
}
//-----------------------------------------------------------------------------------------------
function addMenuOption(fnc, text, icon, iAct, act )
{
	var opt = new OptionDef(fnc, text, icon, iAct, ((act == null) || (act == "undefined")) ? true : act);
	var groupDef = findGroupDef(currentGroupName);
	groupDef.optList[groupDef.optList.length] = opt;
}
//-----------------------------------------------------------------------------------------------
function createPullDownGroup(groupName)
{
	createPullDownGroup(groupName, "");
}
//-----------------------------------------------------------------------------------------------
function createPullDownGroup(groupName, lastOpened)
{
	var output = "";
	var display = "none";
	var Arrow = "ArrowDown.gif";
	var groupDef = findGroupDef(groupName);
	var txt = "";

	if (groupDef == null) return;
	
	if (groupName == lastOpened) 
	{
		display = "block";
		Arrow = "ArrowUp.gif";
	}
	
	var items = domMenu_data.get('externalTabs');
	
	if ( items == null ) items = new Hash();

	if ( groupDef.optList.length > 0 )
		txt = "<img src='/actricity/theme/Images/ArrowDown.gif'>";
				
	var groupName = new Hash( 'contents', '<nobr>' + groupDef.text + txt + '</nobr>', 'uri', '', 'statusText', '' );
	
	for ( i = 0; i < groupDef.optList.length; i++ )
	{
		groupName.set( i + 1, new Hash( 'contents', '<nobr>' + groupDef.optList[i].text + '</nobr>', 'uri', 'javascript:' + groupDef.optList[i].fnc, 'statusText', '' ) );
	}
	
	items.set( items.size() + 1, groupName );
	domMenu_data.set( 'externalTabs', items );
	return "";
}
//-----------------------------------------------------------------------------------------------
function createPullDownOption(groupName)
{
	createPullDownGroup( groupName );
	return "";
}
//-----------------------------------------------------------------------------------------------
function showHideGroup(id, event, onOpenEvent, onCloseEvent )
{
	if ( event != null && event.ctrlKey )
	{
		try{ eval( "showHideAllGroup" + id + "()" ); } catch(e){}		
	}
	else
	{
		var o = document.getElementById(id);	
		if (o.style.display == "none")
		{
			showHidePullDown(id, "block", onOpenEvent, onCloseEvent);
		}
		else
		{
			showHidePullDown(id, "none", onOpenEvent, onCloseEvent);
		}
	}
}
//-----------------------------------------------------------------------------------------------
function showHidePullDown(id, attr, onOpenEvent, onCloseEvent)
{
	try
	{
		//alert( "[DBG CommonScript.js] showHidePullDown()\nid=" + id + "\nattr=" + attr + "\nonOpenEvent=" + onOpenEvent + "\nonCloseEvent=" + onCloseEvent );
		var obj1 = document.getElementById(id);
		var img1 = document.getElementById(id+"I");
		var img2 = document.getElementById(id+"II");
			
		if (attr == "block")
		{
			obj1.style.display = "block";
			img1.src = "/actricity/theme/Images/ArrowUp.gif";
			img1.style.cursor= "pointer";
			if ( img2 != null ) img2.src = "/actricity/theme/Images/ArrowUp.gif";
			try{ eval( onOpenEvent ); } catch(e){}			
		}
		else
		{
			obj1.style.display = "none";
			img1.src = "/actricity/theme/Images/ArrowDown.gif";
			img1.style.cursor= "pointer";			
			if ( img2 != null ) img2.src = "/actricity/theme/Images/ArrowDown.gif";
			try{ eval( onCloseEvent ); } catch(e){}		
		}
		try
		{
			var updated = false;
			var aArray = getBody().PullDown;
			for (x=0; x < aArray.length; x++)
			{
				if (aArray[x].name == id) 
				{
					getBody().PullDown[x].attr = obj1.style.display;
					getBody().PullDown[x].onOpenEvent = onOpenEvent;					
					getBody().PullDown[x].onCloseEvent = onCloseEvent;								
					updated = true;
					break;
				}
			}
			if ( !updated ) getBody().PullDown[aArray.length] = new PullDownAttr(id, obj1.style.display, onOpenEvent, onCloseEvent);
		}
		catch (e) {}
	}
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function processPullDown()
{
	try
	{
		var aArray = getBody().PullDown;
		for (x=0; x<aArray.length; x++)
		{
			//alert( "[DBG CommonScript.js] processPullDown()\n" + aArray[x].name + " " + aArray[x].attr + " " + aArray[x].onOpenEvent + " " + aArray[x].onCloseEvent );
			showHidePullDown(aArray[x].name, aArray[x].attr, aArray[x].onOpenEvent, aArray[x].onCloseEvent);
		}
	}
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------
function processTreeNode( treeName )
{
	try
	{
		var aArray = new Array;
		aArray = treeAjaxOpenIds.toArray();		
		for ( var x=0; x<aArray.length; x++)
		{
			//alert( "[DBG CommonScript.js] processTreeNode()\nid=" + aArray[x].id + "\nurl=" + aArray[x].url + "\nparams=" + aArray[x].params ) ;
			openAjaxNode(aArray[x].id, aArray[x].url, aArray[x].params, treeName);
		}
	}
	catch (e) {alert(e.message);}
}
//-----------------------------------------------------------------------------------------------
function PullDownAttr(name, attr, onOpenEvent, onCloseEvent)
{
	this.name = name;
	this.attr = attr;
	this.onOpenEvent = onOpenEvent;
	this.onCloseEvent = onCloseEvent;	
}
//-----------------------------------------------------------------------------------------------
function TreeNodeAttr(id, url, params, opened)
{
	this.id = id;
	this.url = url;
	this.params = params;
	this.opened = opened;
}

/* -------------------------------------------------------------------------------------------- */
// PULL-DOWN MENU
/* -------------------------------------------------------------------------------------------- */
function Popup(text, action, isDefault)
{
	this.text = text;
	this.action = action;
	this.isDefault = isDefault;
}
//-----------------------------------------------------------------------------------------------
function PopupMenu(titleText, width, height, options)
{
	this.titleText = titleText;
	this.width = width;
	this.height = height;
	this.options = options;
}
//-----------------------------------------------------------------------------------------------
function loadPopup(event, pop)
{
	try
	{
		var popData = "";
		
		// Open popup window
		// =================
		var x = event.screenX;	
		if ( (x + pop.width + 20) > screen.width ) x = screen.width - pop.width - 20;
		if ( winPopup != null ) { try { winPopup.close(); } catch (e) {}  };
		winPopup = window.open("about:blank", "Popup", "width="+pop.width+",height="+pop.height+",top="+event.screenY+",left="+x);
		
		// Build content
		// =============
		popData = '<HTML><HEAD><META http-equiv="Content-Style-Type" content="text/css">';
		popData += '<BASE href="http://' + location.host + '">';
		popData += '<title>';
		popData += pop.titleText;
		popData += '</title>';
		popData += '<LINK rel="stylesheet" href="/actricity/theme/Master.css" type="text/css">';
		popData += '<script type="text/javascript" src="/actricity/Common/CommonScript.js"></SCRIPT>';
		popData += '<SCRIPT>';
		popData += 'function openPage() {';
		popData += '    focus();';
		popData += '    resizeWindow(document.getElementById("Table"), 250, 150, 20, 50);';
		popData += '}</SCRIPT>';
		popData += '</HEAD><BODY onload="openPage()" onblur="focus()">';
		popData += '<table id="Table" cellspacing="1" cellpadding="0" width="100%">';
		for ( i = 0; i < pop.options.length; i++ )
		{
			var opt = pop.options[i].text;
			var act = pop.options[i].action;
			popData += '<tr class="AreaDefault" onmouseover="mouseOver(this)" onmouseout="mouseOut(this)">';
			popData += '<td class="MenuOption_activ" onclick="' + act + ';window.close()">&nbsp;';
			//popData += '<td class="MenuOption_activ" onclick="' + act + '">&nbsp;';
			popData += '<nobr>' + opt  + '</nobr></td></tr>';
		}
		popData += '</table>';
		popData += '</BODY></HTML>';
		
		// Write data on popup window
		// ==========================
		var doc = winPopup.document;
		doc.open();
		doc.write( popData );
		doc.close();
		
	} catch (e) { alert("Error while loading popup : " + e.message); }
}
//-----------------------------------------------------------------------------------------------
function getCookie( name )
{
	var cookies = "";
	var value = "";
	var start = 0;
	var end = 0;
	
	try
	{
		cookies = document.cookie;
		if ( (start = cookies.indexOf( name + "=" )) != -1 )
		{
			start = start + name.length + 1;
			end = cookies.indexOf(";", start);
			if ( end == -1 ) value = cookies.substring(start, cookies.length);
			else value = cookies.substring(start, end);
		}
	}
	catch (e)
	{
		value = "";
	}
	
	return value;
}
//-----------------------------------------------------------------------------------------------
var pNames = null;
var pValues = null;
function decodeURLParameters()
{
	decodeParameters(location.search);
}
//-----------------------------------------------------------------------------------------------
function decodeParameters(parms)
{
	pNames = new Array();
	pValues = new Array();
	var p = 0;
	
	if ( parms.length == 0 ) return;
	if ( (p=parms.indexOf("?")) != -1 ) parms = parms.substring(p);
	
	var i = 0;
	var aParms1 = parms.substring(1).split("&");
	for ( i=0; i < aParms1.length; i++ )
	{
		var aParms2 = aParms1[i].split("=");
		pNames[pNames.length] = aParms2[0];
		pValues[pValues.length] = aParms2[1];
	}
}
//-----------------------------------------------------------------------------------------------
function getURLParameter(name)
{
	var i = 0;
	for ( i = 0; i < pNames.length; i++ )
	{
		if ( pNames[i] == name )
		{
			return pValues[i];
			break;
		}
	}
	return "";
}
//-----------------------------------------------------------------------------------------------
function myVoid()
{
	return true;
}
// --------------------------------------------------------------------------------------------------
function checkSelected()
{
	return checkSelectedList(list);
}
function checkSelectedList(selectedList)
{
	try
	{
		if (selectedList == null) return false;
		if (selectedList != "undefined")
		{
			if (selectedList.length > 1)
			{
				for (i=0; i < selectedList.length; i++)
				{
					if (selectedList[i].checked) return true;
				}
			}
			else
			{
				var checked;
				if ( ie && selectedList.checked == undefined )
					checked = selectedList[ 0 ].checked;
				else
					checked = selectedList.checked;
				if (checked) return true;
				else return false;
			}
			return false;
		}
	}
	catch (e) {}
	return true;
}
// --------------------------------------------------------------------------------------------------
function returnSelected( index )
{
	return returnSelectedList( list, index );
}
function returnSelectedList( selectedList, index )
{
	var lst;
	var result = new Array;
	
	if ( index != null ) lst = index;
	else lst = selectedList;
	
	try
	{
		if (lst != null) 
		{
			if (lst != "undefined")
			{
				if (lst.length > 1)
				{
					for (i=0; i < lst.length; i++)
					{
						if (lst[i].checked) result[ result.length ] = lst[ i ].value;
					}
				}
				else
				{
					if ( ie && lst.checked == undefined )
						result[ 0 ] = lst[0].value;
					else
						if (lst.checked) result[ 0 ] = lst.value;
				}
			}
		}
	}
	catch (e) {}
	return result;
}
function returnSelectedIdx()
{
	var result = new Array;
	
	try
	{
		if (list != null) 
		{
			if (list != "undefined")
			{
				if (list.length > 1)
				{
					for (i=0; i < list.length; i++)
					{
						if (list[i].checked) result[ result.length ] = i;
					}
				}
				else
				{
					if ( ie && list.checked == undefined )
						result[ 0 ] = list[0].value;
					else
						if (list.checked) result[ 0 ] = list.value;
				}
			}
		}
	}
	catch (e) {}
	return result;
}

// --------------------------------------------------------------------------------------------------
function selectedCount()
{
	return selectedCountList(list);
}
function selectedCountList(selectedList)
{
	var count = 0;
	
	try
	{
		if (selectedList == null) return false;
		if (selectedList != "undefined")
		{
			if (selectedList.length > 1)
			{
				for (i=0; i < selectedList.length; i++)
				{
					if (selectedList[i].checked) count++;
				}
			}
			else
			{
				if (selectedList.checked) count++;
			}
		}
	}
	catch (e) {}
	return count;
}
//-----------------------------------------------------------------------------------------------
function showHideEditors( tab ) 
{
    try
    {
    	if ( editors != null )
    	{
	    	for( var i = 0; i < editors.length; i++ )
	    	{
		       	if ( editors[ i ] != null )
		    	{
		    		if ( tab == i )
		    		{
			    		for ( var j = 0; j < editors[ i ].length; j++ )
			    		{
				    		if ( !tinyMCE.getInstanceById( editors[ i ][ j ] ) )
				    		{
					    		//alert( "show " + editors[ tab ][ j ] );
					    		tinyMCE.addMCEControl( document.getElementById( editors[ i ][ j ] ), editors[ i ][ j ] );
					    	}
				    	}
				   	}
				   	else
				   	{
				   		for ( var j = 0; j < editors[ i ].length; j++ )
			    		{
			    			if ( tinyMCE.getInstanceById( editors[ i ][ j ] ) )
			    			{
				   				//alert( "hide " + editors[ i ][ j ] );
						    	tinyMCE.removeMCEControl(tinyMCE.getEditorId( editors[ i ][ j ] ) );
						    }			    
						}   
				   	}
			    }
			}
		}
    }
    catch(e) 
    {
        //error handling
    }
}
// ==============
// Date selection
// ==============
var yearPart = null;
var monthPart = null;
var dayPart = null;
function selectDate(y,m,d)
{
	yearPart = y;
	monthPart = m;
	dayPart = d;
	var targetURL = "/actricity/Common/SelectDate.jsp";
	winDate = window.open( targetURL, "SelectDATE", "width=710,height=510,resizable");
}

// ===============
// Color selection
// ===============
function selectColor(n)
{
	var targetURL = "/actricity/Common/SelectColor.jsp?ReturnColorTo="+n;
	winColor = window.open( targetURL, "SelectCOLOR", "width=450,height=250,resizable");
}

// --------------------------------------------------------------------------------------------------
function setDisplayMode(m, b)
{
//	 Save current displayMode
//	 ========================
	currentDisplayMode = m;
	var canChangeMode = true;
	var opt = new String();
	
	// V2 JT 02/10/06
	//	if ((m == "DSP_DSP") || (m == "DSP_LST") || (m == "DSP_DLT")) deactFields();
	// else if (m != "SELECT") setPageFocus();
	//if (m != "SELECT") setPageFocus();
	// ==============

	// V2 JT 20/06/06
	try
	{
		if ( (b != null) && (b == '0') ) canChangeMode = false;
	}
	catch (ex) { canChangeMode = true; }
	
//	opt = '<TR>';
//	
//	opt += '<TD onmouseover="this.style.cursor=\'pointer\'" class="functionMode" colspan="2">'+TC_TextStart;
//	switch (m)
//	{
//		case "DSP_LST" : opt += TC_TextList; break;
//		case "DSP_LST2": opt += TC_TextList; break;
//		case "UPD_LST" : opt += TC_TextList; break;
//		case "DSP_DSP" : opt += TC_TextDisplay; break;
//		case "DSP_UPD" : opt += TC_TextUpdate; break;
//		case "DSP_DLT" : opt += TC_TextDelete; break;
//		case "DSP_NEW" : opt += TC_TextCreate; break;
//		case "DSP_CPY" : opt += TC_TextCopy; break;
//		case "INVITE"  : opt += TC_TextSelect; break;
//		case "SELECT"  : opt += TC_TextSelect; break;
//		case "QUERY"   : opt += TC_TextQuery; break;
//		case "SORT"    : opt += TC_TextSort; break;
//		case "FIELDS"  : opt += TC_TextFields; break;
//		default        : opt += TC_TextDisplay; break;
//	}
//	opt += '</TD></TR>';
	
	return opt;
}


// BASIC FUNCTIONS
// ===============
function setBasicFunctions(g)
{
	if ( ( g.length >= 7 ) && ( g.charAt(6) == "1" ) ) getTop().printEntity = true;
	if ( ( g.length >= 7 ) && ( g.charAt(6) == "0" ) ) getTop().printEntity = false;	
	if ( ( g.length >= 8 ) && ( g.charAt(7) == "1" ) ) getTop().setIndicatorButton(true);
	if ( ( g.length >= 8 ) && ( g.charAt(7) == "0" ) ) getTop().setIndicatorButton(false);
}
// --------------------------------------------------------------------------------------------------
function cancel()
{
	if ( displayConfirm() ) return;
	getBody().document.FORM1.Function.value = "CANCEL";
	translateCopyAll = false;
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function displayConfirm() 
{
	try
	{
		if ((currentDisplayMode=="DSP_NEW") || (currentDisplayMode=="DSP_CPY"))
		{
			if (!confirm(TC_ConfirmDeleteNew)) return true;
		}
		else
		if ((currentDisplayMode=="DSP_UPD") && isFieldUpdated )
		{
			if (!confirm(TC_ConfirmUpdate)) return true;
		}		
	}
	catch (e) {}
	return false;
}
// --------------------------------------------------------------------------------------------------
function displayConfirmValidate() 
{
	try
	{
		if ( ( (currentDisplayMode=="DSP_NEW") || (currentDisplayMode=="DSP_UPD") || (currentDisplayMode=="DSP_CPY") ) && isFieldUpdated )
		{
			if (confirm(TC_ConfirmValidate))
			{
			eval( "document.FORM1." + document.FORM1.PageName.value + "RecordUpdated.value = '0';" );
			 return true;
			 }
		}
		else return true;
	}
	catch (e) {}
	return false;
}
// --------------------------------------------------------------------------------------------------
function printEntity() 
{
	printEntityP("DETAIL");
}
// --------------------------------------------------------------------------------------------------
function printEntityP(mode) 
{
	try
	{
		var urlTemp="";
		var temp="";
		
		if (mode == "DETAIL")
		{
			urlTemp += "&EXTKEY="     + _key;
		}
		if (mode == "LIST" && list != null)
		{
			if (!checkSelected()) return;
			if (list.length > 1)
			{

				for (i=0; i < list.length; i++)
				{
					if (list[i].checked) temp = temp + list[i].value + ",";
				}
			}
			else
			{
				if (list.checked) temp = temp + list.value + ",";
			}
			urlTemp += "&IDX="		  + temp;
		}
	
	
		var url = "/actricity/servlet/actricityV1.tool.report.print.PrintChoiceManagement?WinID=" + _winID;
		url += "&Function="   + mode;
		url += "&P_SPHERE="   + _sphere;
		url += urlTemp
		url += "&EXTKEY2="    + _item;
		url += "&B_LANGUAGE=" + _langPrint;
		url += "&ScreenWidth=300&ScreenHeight=300";
		window.open(url, "_blank", "width=300,height=300,resizable,scrollbars");
	} catch (e) {}
}

// --------------------------------------------------------------------------------------------------
function exportPrint() 
{
	exportEntity("3");
}

// --------------------------------------------------------------------------------------------------
function exportSelect() 
{
	exportEntity("1");
}

// --------------------------------------------------------------------------------------------------
function exportScreen() 
{
	exportEntity("2");
}

// --------------------------------------------------------------------------------------------------
function exportEntity( typeExport ) 
{
	try
	{
		var url = "/actricity/servlet/actricityV1.tool.export.ExportChoiceManagement?Function=FIND&WinID=" + _winID;
		url += "&B_T_EXPORT=" + typeExport;
		url += "&P_SPHERE="   + _sphere;
		url += "&EXTKEY="     + _key;
		url += "&EXTKEY2="    + _item;
		url += "&B_LANGUAGE=" + _langPrint;		
		url += "&ScreenWidth=600";				
		url += "&ScreenHeight=350";						
		window.open(url, "_blank", "width=610,height=350,resizable,scrollbars");
	} catch (e) {}
}
// ================
// HEADER FUNCTIONS
// ================
function setHeaderFunctions(g1, t1)
{
	// V2 JT 19/06/06
	//if ((t1!=null) && (t1!="undefined")) writeToLeft( '<TR><TD colspan="2" class="functionTitle">'+t1+'</TD></TR>' );
	
//	if ( ( g1.length >=1 ) && ( g1.charAt(0) =="1" ) ) genOption("dsp()", TC_TextDisplay, "", "", true);
//	if ( ( g1.length >=2 ) && ( g1.charAt(1) =="1" ) ) genOption("upd()", TC_TextUpdate, "", "", true);
//	if ( ( g1.length >=3 ) && ( g1.charAt(2) =="1" ) ) genOption("dlt()", TC_TextDelete, "", "", true);
//	if ( ( g1.length >=4 ) && ( g1.charAt(3) =="1" ) ) genOption("crt()", TC_TextCreate, "", "", true);
//	if ( ( g1.length >=5 ) && ( g1.charAt(4) =="1" ) ) genOption("cpy()", TC_TextCopy, "", "", true);
//	if ( ( g1.length >=6 ) && ( g1.charAt(5) =="1" ) ) genOption("dspDL()", TC_TextList, "", "", true);
	
}
// --------------------------------------------------------------------------------------------------
function dspDL()
{
	document.FORM1.DisplayMode.value = "DSP_LST";
	document.FORM1.Function.value = "FIND";
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function dsp()
{
	document.FORM1.DisplayMode.value = "DSP_DSP";
	if ( currentDisplayMode.indexOf("DSP_LST") == -1 ) document.FORM1.Function.value = "FIND";
	else document.FORM1.Function.value = "";
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function upd()
{
	document.FORM1.DisplayMode.value = "DSP_UPD";
	if ( currentDisplayMode.indexOf("DSP_LST") == -1 ) document.FORM1.Function.value = "FIND";
	else document.FORM1.Function.value = "";
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function dlt()
{
	// V2 JT 20/06/06
//	document.FORM1.DisplayMode.value = "DSP_DLT";
//	if ( currentDisplayMode.indexOf("DSP_LST") == -1 ) document.FORM1.Function.value = "FIND";
//	else document.FORM1.Function.value = "";
//	submitFORM1();
	// ==============
	try
	{
		if (!confirm(TC_ConfirmDelete)) return;
		document.FORM1.Function.value = "VALIDATE";
		document.FORM1.DisplayMode.value = "DSP_DLT";
		submitFORM1();
	}
	catch(e) {}
}
// --------------------------------------------------------------------------------------------------
function crt()
{
	if ( displayConfirm() ) return;
	document.FORM1.DisplayMode.value = "DSP_NEW";
	document.FORM1.Function.value = "NEW";
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function cpy()
{
	if ( displayConfirm() ) return;
	document.FORM1.DisplayMode.value = "DSP_CPY";
	document.FORM1.Function.value = "COPY";
	submitFORM1();
}

// ===================
// LIST ITEM FUNCTIONS
// ===================
function setItemFunctions(g1, t1, type)
{
	var typeList = "1";
	try
	{
		if ((type != null) && (type != "undefined") && (type == "2")) typeList = "2";

		//if ((t1!=null) && (t1!="undefined")) writeToLeft( '<TR><TD colspan="2" class="functionTitle">'+t1+'</TD></TR>' );
		
		if ( ( ( g1.length >= 1 ) && ( g1.charAt(0) == "1" ) ) || ( ( g1.length >= 2 ) && ( g1.charAt(1) == "1" ) ) ) 
		{
			setSubmitButton( true );
			getButtonsBar().ChangeOnClickEvent( "Submit", "getBody().updItem()" );
		}
		if ( ( g1.length >= 3 ) && ( g1.charAt(2) == "1" ) )
		{
			setDeleteButton( true );
			if (typeList == "2")
			{
				getButtonsBar().ChangeOnClickEvent( "Delete", "getBody().rmvItem()" );
				getButtonsBar().ChangeTitle( "Delete", TC_TextRemove );
			}
			else
			{
				getButtonsBar().ChangeOnClickEvent( "Delete", "getBody().dltItem()" );
				getButtonsBar().ChangeTitle( "Delete", TC_TextDelete );
			}
		}
		if ( (g1.length >= 4 ) && ( g1.charAt(3) == "1" ) )
		{
			setCreateButton( true );
			if (typeList == "2") 
			{
				getButtonsBar().ChangeOnClickEvent( "Create", "getBody().addItem()" );
				getButtonsBar().ChangeTitle( "Create", TC_TextAdd );
			}
			else
			{
				getButtonsBar().ChangeOnClickEvent( "Create", "getBody().crtItem()" );
				getButtonsBar().ChangeTitle( "Create", TC_TextCreate );
			}
		}
		if ( ( g1.length >= 5 ) && ( g1.charAt(4) == "1" ) )
		{
			setCopyButton( true );		
			getButtonsBar().ChangeOnClickEvent( "Copy", "getBody().cpyItem()" );
			getButtonsBar().ChangeTitle( "Copy", TC_TextCopy );
		}
	}
	catch (e) {}
}
// --------------------------------------------------------------------------------------------------
function dspItem()
{
	if (!checkSelected()) return;
	// V2 JT 20/06/06
	// document.FORM1.Function.value = "DISPLAY_ITEM";
	document.FORM1.Function.value = "UPDATE_ITEM";
	// ==============
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function updItem()
{
	updItemBase();
}
// --------------------------------------------------------------------------------------------------
function updItemBase()
{
	if (!checkSelected()) return;
	document.FORM1.Function.value = "UPDATE_ITEM";
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function dltItem()
{
	if (!checkSelected()) return;
	if ( confirm( TC_ConfirmDeleteAll + ' ' + selectedCount() + ' ' + TC_Record + '. \n' + TC_Confirm ) )
	{
		document.FORM1.Function.value = "DELETE_ITEM";
		submitFORM1();
	}
}
// --------------------------------------------------------------------------------------------------
function crtItem()
{
	document.FORM1.Function.value = "NEW_ITEM";
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function rmvItem()
{
	if (!checkSelected()) return;
	if ( confirm( TC_ConfirmDeleteAll + ' ' + selectedCount() + ' ' + TC_Record + '. \n' + TC_Confirm ) )
	{
		document.FORM1.Function.value = "RMV_ITEM";
		submitFORM1();
	}
}
// --------------------------------------------------------------------------------------------------
function addItem()
{
	document.FORM1.Function.value = "ADD_ITEM";
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function cpyItem()
{
	if (!checkSelected()) return;
	document.FORM1.Function.value = "COPY_ITEM";
	submitFORM1();
}
// --------------------------------------------------------------------------------------------------
function searchOption()
{
	if ( winTreeS != null && !winTreeS.closed ) winTreeS.focus();
	else winTreeS = window.open("/actricity/Common/TreeSearch.jsp", "_blank", "width=250,height=80,resizable").focus();
}
// ***********
// BUTTONS BAR
// ***********
function ButtonsBar ( imagesPath, drawTarget )
{
    this.data       = new Array ();
    this.imagesPath = imagesPath;
    this.drawTarget = drawTarget;
    this.mapping 	= new Array();

    this.Add              	= ButtonsBarAdd;
    this.Separator         	= ButtonsBarSeparator;    
    this.Draw               = ButtonsBarDraw;
    this.DisableButton		= ButtonsBarDisableButton;
    this.EnableButton		= ButtonsBarEnableButton;  
    this.HideButton			= ButtonsBarHideButton;     
    this.ChangeTitle		= ButtonsBarChangeTitle;  
    this.ChangeText			= ButtonsBarChangeText;      
    this.ChangeImageName	= ButtonsBarChangeImageName;
    this.ChangeMode		   	= ButtonsBarChangeMode;
    this.ChangeOnClickEvent	= ButtonsBarChangeOnClickEvent;    
    this.Init				= ButtonsBarInit;    
    this.IsEnabled			= ButtonsBarIsEnabled;
    this.DisableAll			= ButtonsBarDisableAll;

    return this;
}

function ButtonsBarAdd( button)
{
	this.mapping[ button.id ] = this.data.length;
	this.data[ this.data.length ] = button;

}
function ButtonsBarClear ()
{
    this.data = new Array ();
}

function ButtonsBarDraw ()
{
	var output = "";
	var width  = 0;
	var title  = "";
	var mode4  = new Array;
	
	for ( var i = 0; i < this.data.length; i++ )
	{
		if ( this.data[ i ] != null )
		{
			if ( this.data[ i ].half != null && this.data[ i ].half )
			{
				classDefault = "halfButtonDefault";
				classOver 	 = "halfButtonMouseOver";
				classDown    = "halfButtonMouseDown";
				switch ( this.data[ i ].mode )
				{
					case "1" : // Icon and Text
						//width = parseInt( 15 + getTextWidth( this.data[ i ].text ) );
						width = parseFloat( 15 + getTextWidth( this.data[ i ].text )   ) + "px";
						break;
					case "2" : // Icon
						//width = 13;
						width = "13px";
						break;
					case "3" : // Text
						//width = parseInt( getTextWidth( this.data[ i ].text ) );
						width =  parseFloat( getTextWidth( this.data[ i ].text ) ) + "px";
						break;
				}
			}
			else
			{
				classDefault = "buttonDefault";	
				classOver 	 = "buttonMouseOver";
				classDown    = "buttonMouseDown";		
				switch ( this.data[ i ].mode )
				{
					case "1" : // Icon and Text
						//width = parseInt( 26 + getTextWidth( this.data[ i ].text ) );
						width = parseFloat( 24 + getTextWidth( this.data[ i ].text )  ) + "px";
						break;
					case "2" : // Icon
						//width = 24;
						width= "24px";
						break;
					case "3" : // Text
						//width = parseInt( getTextWidth( this.data[ i ].text ) );
						width =  parseFloat( getTextWidth( this.data[ i ].text ) ) + "px";
						break;
					case "4" : // Combo or Input type text
						classOver 	 = "buttonDefault";
						classDown    = "buttonDefault";
						width		 = "";
						mode4[ mode4.length ] = this.data[ i ].id;
						break;
					case "5" : // Date
						classOver 	 = "buttonDefault";
						classDown    = "buttonDefault";
						width		 = "105";						
						break;						
				}
			}
			
			title = this.data[ i ].title;
			if ( title == null || title.length == 0 )
				title = "";
			else
				title = "<nobr>" + title + "</nobr>";
				
			if ( this.data[ i ].enable != null && this.data[ i ].enable )
			{		
				if ( this.data[ i ].align == "right" ) 
					output += "<td width=\"100%\" align=\"" + this.data[ i ].align + "\"";
				else
					output += "<td width=\"" + width + "\"";	
				
				//alert( this.data[ i ].imageName );
				output+= ">";
			
				output += "<div class=\"" + classDefault + "\" id=\"" + this.data[ i ].id  + "\" style=\"display: inline;width:" + width + "\"";
				
				if ( this.data[ i ].visible != null && this.data[ i ].visible )
				{
					output += ( this.data[ i ].onClickEvent != "" ) ? " onClick=\"javascript:" + this.data[ i ].onClickEvent + "\"" : "";
					output += " onMouseOver=\"this.className='" + classOver + "';showPopupInfo( this, event,'" + title + "')\"" + 
			            " onMouseOut=\"this.className='" + classDefault + "';hidePopupInfo( this, event )\"" + 
			           	" onMouseDown=\"this.className='" + classDown + "'\" onMouseUp=\"this.className='" + classOver + "'\"><nobr>";
			           	
			        if ( ie )
			        {
			        	if ( this.data[ i ].align == "right" ) 
						{
							output += "<div class=\"topTextRight\">";
						}
						else
		   				{
			   				output += "<div class=\"topText\">";
			   			}
			   			if ( this.data[ i ].imageName.length > 0 && this.data[ i ].mode != 3 )
			   			{
		     			   output += "\n<img align=\"middle\" id=\"" + this.data[ i ].id + "Img\" src=\"" + this.imagesPath + this.data[ i ].imageName + "\" border=0>"; 
		     			}
		     			if ( this.data[ i ].mode != 2 )
		     			{
		   					output += "&nbsp;" + this.data[ i ].text + "&nbsp;";
		   				}
		   				output += "</div>";		   				
			        }
			        else
			        {
						if ( this.data[ i ].imageName.length > 0 && this.data[ i ].mode != 3 )
	     				    output += "\n<img align=\"middle\" id=\"" + this.data[ i ].id + "Img\" src=\"" + this.imagesPath + this.data[ i ].imageName + "\" border=0>";     
	     			    if ( this.data[ i ].mode != 2 )
		     			{
							output += "<font class=\"topText\">&nbsp;" + this.data[ i ].text + "&nbsp;</font>";
		   				}	   				
			        }
	   					
     				output += "</nobr></div></td>\n";     			
				}
				else
				{
					output += " onMouseOver=\"showPopupInfo( this, event,'" + title + "')\"" + 
			            " onMouseOut=\"hidePopupInfo( this, event )\"><nobr>";
	     			if ( this.data[ i ].disabledImageName.length > 0 && this.data[ i ].mode != 3 )
     				    output += "\n<img align=\"middle\" id=\"" + this.data[ i ].id + "Img\" src=\"" + this.imagesPath + this.data[ i ].disabledImageName + "\" border=0>"; 
 				    if ( this.data[ i ].mode != 2 )
 				    {
						if ( ie )
						{
							if ( this.data[ i ].align == "right" ) 
			   					output += "<div class=\"topTextRight\"><i>&nbsp;" + this.data[ i ].text + "&nbsp;</i></div>";
			   				else
			   					output += "<div class=\"topText\"><i>&nbsp;" + this.data[ i ].text + "&nbsp;</i></div>";
			   			}
		   				else
		   					output += "<font class=\"topText\"><i>&nbsp;" + this.data[ i ].text + "&nbsp;</i></font>";
	   				}
     				output += "</nobr></div></td>\n";			
     			}
			}
			else
			{
				output += "<td width=\"0\"";	
				output += "<div class=\"" + classDefault + "\" id=\"" + this.data[ i ].id  + "\" style=\"display: none;width:" + width + "\"></div></td>\n";
			}
		}		
	}
    if (document.getElementById(this.drawTarget) != null)
    {
    	//debugMsg( arguments, "output=" + output );
        document.getElementById(this.drawTarget).innerHTML = "<table height=24 cellspacing=1 cellpadding=0 border=0><tr>" + output + "</tr></table>";        
 
 		if ( ie )
 		{
	 		for ( var i = 0; i < mode4.length; i++ )
	 		{
	        	openPageMore += "document.getElementById('" + mode4[ i ] + "').style.width=document.FORM1." + mode4[ i ] + ".offsetWidth + 5;";
	        }
	    }
    }
}
function ButtonsBarChangeMode( buttonID, mode )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].mode = mode;
}
function ButtonsBarDisableButton( buttonID )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].visible = false;
	this.data[ i ].enable  = true;
}
function ButtonsBarIsEnabled( buttonID )
{
	var i = this.mapping[ buttonID ];
	return this.data[ i ].enable;
}
function ButtonsBarEnableButton( buttonID )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].visible = true;
	this.data[ i ].enable  = true;
}
function ButtonsBarHideButton( buttonID )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].enable = false;
}
function ButtonsBarChangeTitle( buttonID, newTitle )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].title = newTitle;
}
function ButtonsBarChangeText( buttonID, newText )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].text = newText;
}
function ButtonsBarChangeImageName( buttonID, newImageName )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].imageName = newImageName;
}
function ButtonsBarChangeOnClickEvent( buttonID, newOnClickEvent )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].onClickEvent = newOnClickEvent;
}
function ButtonsBarSeparator( id )
{
	var sep = new button( id, "", "Separator.gif", "Separator.gif", "", "", false, "" );
	sep.visible = false;
	sep.enable = true;	
	this.Add( sep );
}
function ButtonsBarDisableAll()
{
	for ( var i = 0; i < this.data.length; i++ )
	{
		if ( this.data[ i ].enable )
		{
			this.data[ i ].visible = false;
		}
	}	
}
// New version
function button( id, text, imageName, disabledImageName, onClickEvent, title, half, align )
{
	this.id 			   = id;
	this.text			   = text;
	this.imageName 		   = imageName;
	this.disabledImageName = disabledImageName;
	this.onClickEvent 	   = onClickEvent;
	this.title 			   = title;
	this.visible 		   = true;
	this.enable 		   = true;
	this.half			   = half;
	this.align			   = align;	
	this.mode			   = "2";
} 
function ButtonsBarInit( buttonID, text, imageName, disabledImageName, onClickEvent, title, half, align )
{
	var i = this.mapping[ buttonID ];
	this.data[ i ].text 			 = text;
	this.data[ i ].imageName 		 = imageName;
	this.data[ i ].disabledImageName = disabledImageName;
	this.data[ i ].onClickEvent 	 = onClickEvent;
	this.data[ i ].title 			 = title;
	this.data[ i ].visible 		   	 = true;
	this.data[ i ].enable 		   	 = true;
	this.data[ i ].half			   	 = half;
	this.data[ i ].align			 = align;	
	this.data[ i ].mode			   	 = "2";
} 
function getButtonsBar()
{
	return getTop().ButtonsBar;
}
function getTextWidth( text )
{
	var count = 0;
	var currentChar = "";
	var character;
	
	//Remove HTML Tag
	var exp = new RegExp("<[^>]+>","g");
	text = text.replace( exp, "" );
	
	for ( var i = 0; i < text.length; i++)
	{
		currentChar = text.charAt( i );
		character = /[ilI()]/;
		if ( character.test( currentChar ) )
		{
			// 1 px - 1 space after = 0
			count += 1;
		}
		else
		{
			character = /[j]/;
			if ( character.test( currentChar ) ) count += 2;
			else
			{
				character = /[rt]/;
				if ( character.test( currentChar ) )
				{
				 	// 3 px - 1 space after = 2
				 	count += 2;
				}
				else
				{
					character = /[cf\-]/;
					if ( character.test( currentChar ) ) count += 4;
					else
					{
						character = /[asudeBELPS]/;
						if ( character.test( currentChar ) ) count += 6;
						else
						{
							character = /[ACDGHKMNOQRTUVXYZ]/;
							if ( character.test( currentChar ) ) count += 7;
							else
							{
								character = /[mw]/;
								if ( character.test( currentChar ) ) count += 9;
								else
								{
									character = /[W]/;
									if ( character.test( currentChar ) ) count += 11;
									else
									{
										count += 5;
									}								
								}							
							}						
						}				
					}				
				}
			
			}
		}
		// Add space
		count += 2;
	}
	return count;
}

// ===============
// MULTIPLE SELECT
// ===============
var previousElem = "";
var nextElem = "";
var selectedElems = "";

function initListboxWarning()
{
	var f = getBody().document.FORM1;
	var firstElemFound = false;
	
	for ( i = 0; i < f.length; i++)
	{
		var selectControl = f.elements[ i ];
		if (selectControl.type == 'select-multiple' )
		{	
			var j = 0;
			while (  j < selectControl.length && !firstElemFound )
			{
				if ( selectControl.options[ j ].selected )
				{
					selectControl.options[ j ].selected = false;
					selectControl.options[ j ].selected = true;	
					firstElemFound = true;	
					showWarning( null, 4, selectControl.name, j );
				}
				j++;
			}					
		}
	}
}
function showWarningIE( event, selectControl )
{
	var newSelectedElems = new Array();
	var j = 0;
	
	if ( document.all )
	{
		for ( i = 0; i < selectControl.length; i++ )
		{
			if ( selectControl.options[ i ].selected )
			{
				newSelectedElems += i + ";";
				if ( selectedElems.indexOf( i + ";" ) < 0 )
				{
					j = i;
				}				
			}
		}
		selectedElems = newSelectedElems;
		showWarning( event, 0, "listbox" + selectControl.name, j);
	}
}

function showWarning( event, pos, name, i )
{
	var selectControl = document.getElementById( name );
	var selectTop = getWindowTop( selectControl );
	var mouseTop = 0;
	var shiftUp = 0;
	var shiftDown = 0;
	var hiddenValues = false;
	
	if ( selectControl == null ) return;
	
	if ( event != null )
	 	mouseTop = event.clientY;
	 	
	if ( pos == 1 || mouseTop <= selectTop + 14 )
	{
		shiftDown = 4;
		shiftUp = 1;
		//alert( "zone 1" );
	}
	else
	if ( pos == 2 || mouseTop <= selectTop + 28 )
	{
		shiftDown = 3;
		shiftUp = 2;
		//alert( "zone 2" );		
	}
	else	
	if ( pos == 3 || mouseTop <= selectTop + 42 )
	{
		shiftDown = 2;
		shiftUp = 3;
		//alert( "zone 3" );		
	}
	else	
	if ( pos == 4 || mouseTop <= selectTop + 56 )
	{
		shiftDown = 1;
		shiftUp = 4;
		//alert( "zone 4" );		
	}
	
	//alert( "mouseTop=" + mouseTop +  "shiftUp=" + shiftUp + " i=" + i );
	for ( j = i - shiftUp; j >= 0; j-- )
	{
		if ( selectControl.options[ j ].selected )
		{
			if ( document.getElementById( "MoreValuesUp" + name ) != null )
				document.getElementById( "MoreValuesUp" + name ).style.visibility = "visible";
			previousElem = j;
			hiddenValues = true;
			break;
		}		
	}
	try
	{
		if ( !hiddenValues )
		{
			previousElem = -1;
			if ( document.getElementById( "MoreValuesUp" + name ) != null )
				document.getElementById( "MoreValuesUp" + name ).style.visibility = "hidden";
		}
	}
	catch(e) { alert( e ) };
	hiddenValues = false;
	for ( j = i + shiftDown; j < selectControl.length; j++ )
	{
		if ( selectControl.options[ j ].selected )
		{
			if ( document.getElementById( "MoreValuesDown" + name ) != null )
				document.getElementById( "MoreValuesDown" + name ).style.visibility = "visible";
			nextElem = j;
			hiddenValues = true;			
			break;
		}
	}
	if ( !hiddenValues )
	{
		if ( document.getElementById( "MoreValuesDown" + name ) != null )
			document.getElementById( "MoreValuesDown" + name ).style.visibility = "hidden";	
		nextElem = -1;
	}
}

function setFocusUp( event, name, i )
{
	var selectControl = document.getElementById( name );
	
	if( name != null && i > 0 )
	{
		selectControl.options[ i ].selected = false;
		selectControl.options[ i ].selected = true;		
	}
	for ( j = i - 1; j >= 0; j-- )
	{
		if ( selectControl.options[ j ].selected )
		{
			previousElem = j;
			break;
		}
	}	
	showWarning( event, 0, name, i );	
}

function setFocusDown( event, name, i )
{
	var selectControl = document.getElementById( name );
	
	if( name != null && i > 0 )
	{
		selectControl.options[ i ].selected = false;
		selectControl.options[ i ].selected = true;		
	}
	for ( j = i + 1; j < selectControl.length; j++ )
	{
		if ( selectControl.options[ j ].selected )
		{
			nextElem = j;
			break;
		}
	}	
	showWarning( event, 0, name, i );
}

function selectAllList( name )
{
	var selectControl = document.getElementById( name );
	for ( i = selectControl.length - 1; i >= 0; i-- )
		selectControl.options[ i ].selected = true;
		
	try
	{
		refreshCount( selectControl, document.getElementById( "Count" + name ) );
		document.getElementById( "MoreValuesUp" + name ).style.visibility = "hidden";		
		document.getElementById( "MoreValuesDown" + name ).style.visibility = "hidden";			
	}
	catch(e) {}
}

function unselectAllList( name )
{
	var selectControl = document.getElementById( name );
	for ( i = selectControl.length - 1; i >= 0; i-- )
		selectControl.options[ i ].selected = false;
	
	// Focus on the first element	
	if ( selectControl.length > 0 )
	{
		selectControl.options[ 0 ].selected = true;
		selectControl.options[ 0 ].selected = false;				
	}
	
	try
	{
		refreshCount( selectControl, document.getElementById( "Count" + name ) );
		document.getElementById( "MoreValuesUp" + name ).style.visibility = "hidden";		
		document.getElementById( "MoreValuesDown" + name ).style.visibility = "hidden";					
	}
	catch(e){}
}

function refreshCount( multipleList, label )
{
	var count = 0;
	for( i = 0; i < multipleList.length; i++ )
	{
		if ( multipleList.options[ i ].selected )
			count++;
	}
	label.innerHTML= "(" + count + "/" + multipleList.length + ")";
}

function getContent( name )
{
	var selectControl = document.getElementById( name );
	var content = "";
	var first = true;
	for ( var i = 0; i < selectControl.length; i++ )
	{
		if ( selectControl.options[ i ].selected )
		{
			if ( !first ) content += "<BR>";
			else first = false;
			content += selectControl.options[ i ].text;
		}
	}
	return content;
}

function addUniqueOption( tagName, optText, optValue )
{
	for ( var i = 0; i < tagName.length; i++ )
	{
		if ( tagName.options[ i ].value == optValue )
			return;
	}
	tagName.options[ tagName.length ] = new Option( optText, optValue );
}
//-----------------------------------------------------------------------------------------------
// type = 1 : Text
// type = 2 : Textarea
function promptAct( type, maxLength )
{
	var params = "";
	if ( type != undefined )
		params += "type=" + type;
	if ( maxLength != undefined )
		params += "&maxLength=" + maxLength;
	if ( winPrompt == null || winPrompt.closed ) 
		winPrompt = window.open("/actricity/Common/Prompt.jsp?" + params, "PROMPT", "width=250,height=80,resizable");
	winPrompt.focus();		
}
//-----------------------------------------------------------------------------------------------
// ===================
// C O N V E R S I O N
// ===================

function _HTMLStringToString( text )
{
	text = text.replace( '&nbsp;', ' ' );
	text = text.replace( '&quot;', ' ' );
	text = text.replace( '&acute;', ' ' );
	text = text.replace( '&#39;', ' ' );	
	
	return text;
}
//-----------------------------------------------------------------------------------------------
// =======
// A J A X
// =======

function getXhr()
{
	var xhr;
	
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else 
		if(window.ActiveXObject)
		{ // Internet Explorer 
	   		try
	   		{
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
            	try	{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
            }
            
            if(!xhr)
            {
            	xhr = false;
            }
		}
		else 
		{ 	// XMLHttpRequest non supporté par le navigateur 
	   		alert("Your browser doesn't support XMLHTTPRequest objects..."); 
		   	xhr = false; 
		}
	return xhr;
}

function ajaxRequest( url, params, fnc )
{
	var xmlResponse = null;
	// var txtResponse = null;
	if ( submited ) return;
	var xhr = getXhr();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			ajaxResponse = xhr.responseText;
			xmlResponse  = xhr.responseXML;
			//debugMsg( arguments, "ajaxResponse=" + ajaxResponse + "\n" + "xmlResponse=" + xmlResponse );
			
			try
			{
				if ( fnc == undefined || fnc == "" )
					eval( ajaxResponse );
				else
					eval( fnc );
			}
			catch(e){}
			stopWait();
		}
	}
 
	xhr.open("POST", url, true);
	xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
	xhr.send( "WinID=" + getBody()._winID + "&" + params );	
	startWait();
}

function ajaxShowPopupVelcro( element, popEvent, url, params )
{
	tooltip_id = showPopupVelcro( element, popEvent, "&nbsp;"+TC_Wait );
	ajaxRequest( url, params, "ajaxUpdatePopup('" + tooltip_id + "')" );
}

function ajaxShowPopupInfo( element, popEvent, url, params )
{
	tooltip_id = showPopupInfo( element, popEvent, "&nbsp;" );
	ajaxRequest( url, params, "ajaxUpdatePopup('" + tooltip_id + "')" );
}

function ajaxUpdatePopup( tooltip_id )
{
	updatePopup( tooltip_id, ajaxResponse );
}

function ajaxClassLoader( url, params, returnFunction )
{
	ajaxRequest( "/actricity/servlet/actricityV1.common.objects.ClassLoader", "url=" + url + "&params=" + urlencode(params), returnFunction );
}

function ajaxShowPopupDocument( element, popEvent, sphere, extkey )
{
	ajaxShowPopupVelcro( element,  popEvent, "/actricity/servlet/actricityV1.tool.addon.document.functions.LoadDocuments", "sphere=" + sphere + "&extkey=" + extkey );
}
//-----------------------------------------------------------------------------------------------
// ========================
// C O N T E X T    M E N U
// ========================

function contextMenu()
{    
    domTT_addPredefined('menu', 'content', document.getElementById('menu'), 'caption', false, 'type', 'sticky', 'statusText', '', 'clearMouse', false, 'offsetX', 0, 'offsetY', 0);

	document.oncontextmenu = function(in_event)
	{ 
		if (typeof(in_event) == 'undefined')
		{
			in_event = event;
		}

	    if (in_event.ctrlKey)
		{
	        return;
	    }
	
	    if (domTT_isActive(menuId))
		{
	        domTT_deactivate(menuId);
	    }
	    else
		{
	        menuId = domTT_activate(this, in_event, 'predefined', 'menu');
	    }
	    
	    return false;
	};
	
	document.onmousedown = function(in_event)
	{ 
		if (typeof(in_event) == 'undefined')
		{
			in_event = event;
		}

	    if (domLib_isOpera || domLib_isKonq)
		{
	        if ((domLib_isKonq || in_event[domLib_eventButton] == 1) && domTT_isActive(menuId))
			{
	            domTT_deactivate(menuId); 
	        }
	        else if (in_event.ctrlKey)
			{
	            menuId = domTT_activate(this, in_event, 'predefined', 'menu');
				return false; 
	        }
	    }
	    else
		{
	        if (in_event[domLib_eventButton] == 1 && domTT_isActive(menuId))
			{ 
	            domTT_deactivate(menuId); 
	        } 
	    }
	};
}

function HoverMe(in_this)
{
    in_this.style.backgroundColor = '#4C59A6';
    in_this.style.color = '#FFFFFF';
    in_this.style.cursor = domLib_isIE ? 'hand' : 'pointer';
}

function UnhoverMe(in_this)
{
    in_this.style.backgroundColor = '';
    in_this.style.color = '';
    in_this.style.cursor = '';
}

// V2 JT 26/06/06

function setTopMessage( txt )
{
	if ( getTop() != null )
		getTop().document.getElementById( "MsgPart" ).innerHTML = "<nobr>" + txt + "</nobr>";
}

function setDeleteMessage( txt )
{
	try { TC_ConfirmDelete = txt; } catch (e) {}
}
// ================

// ================
// M E N U    B A R
// ================
function MenuBar( name )
{
    this.options    = new Array ();
    this.name 		= name;

    this.Draw       = MenuBarDraw;
    this.AddOption  = MenuBarAddOption;
    this.CreateItems = MenuBarCreateItems;
    this.CreateOption = MenuBarCreateOption;
    this.RemoveOption = MenuBarRemoveOption;    
    
    return this;
}

function MenuBarDraw()
{	
	this.CreateItems();
	domMenu_settings.set( this.name, new Hash(
    'menuBarWidth', '0%',
    'menuBarClass', 'menuBar',
    'menuElementClass', 'menuElement',
    'menuElementHoverClass', 'menuElementHover',
    'menuElementActiveClass', 'menuElementActive',
    'subMenuBarClass', 'subMenuBar',
    'subMenuElementClass', 'subMenuElement',
    'subMenuElementHoverClass', 'subMenuElementHover',
    'subMenuElementActiveClass', 'subMenuElementHover',
    'subMenuMinWidth', 'auto',
    'distributeSpace', false,
    'openMouseoverMenuDelay', 300,
    'closeClickMenuDelay', 0,
    'closeMouseoutMenuDelay', 300,
    'expandMenuArrowUrl', '/actricity/theme/Images/ArrowRight.gif'
	));
	domMenu_activate( this.name, true);
}

function MenuBarCreateItems()
{
	var fnc   = "";
	var txt   = "";
	var items = domMenu_data.get( this.name );
		
	if ( items == null ) items = new Hash();
	items = new Hash();
	
	//debugMsg( arguments, "this.options.length=" + this.options.length );
	
	for ( var i = 0; i < this.options.length; i++ )
	{
		if ( this.options[ i ].fnc == null || this.options[ i ].fnc == "" ) fnc = "";
		else fnc = 'javascript:' + this.options[ i ].fnc;
		if ( this.options[ i ].childs.length > 0 && this.options[ i ].active )
			txt = "<nobr><font class='menuActive'>" + this.options[ i ].text + "<img src='/actricity/theme/Images/ArrowDown.gif'></font></nobr>";		
		else
		{
			if ( this.options[ i ].childs.length > 0 )
				txt = "<nobr>" + this.options[ i ].text + "<img width='13px' src='/actricity/theme/Images/ArrowDown.gif'></nobr>";
			else
				if ( this.options[ i ].active )
					txt = "<nobr><font class='menuActive'>" + this.options[ i ].text + "</font></nobr>";
				else
					txt = "<nobr>" + this.options[ i ].text + "</nobr>";
		}
		groupName = new Hash( 'contents', txt, 'uri', fnc, 'statusText', '' );
		groupName = this.CreateOption( groupName, this.options[ i ] );
		
		items.set( items.size() + 1, groupName );
	} 
	domMenu_data.set( this.name, items );
}

function MenuBarCreateOption( groupName, opt )
{
	var childs = opt.childs;
	var groupChild = "";
		
	for ( var i = 0; i < childs.length; i++ )
	{
		if ( childs[ i ].fnc == null || childs[ i ].fnc == "" ) fnc = "";
		else fnc = 'javascript:' + childs[ i ].fnc;
		groupChild = new Hash( 'contents', '<nobr>' + childs[ i ].text + '</nobr>', 'uri', fnc, 'statusText', '' );
		groupChild = this.CreateOption( groupChild, childs[ i ] );
		groupName.set( i + 1, groupChild );					
	}
	return groupName;	
}

function MenuBarAddOption( opt )
{
	this.options[ this.options.length ] = opt;
}

function MenuBarRemoveOption( fnc )
{
	for ( var i = 0; i < this.options.length; i++ )
	{
		if ( this.options[ i ].fnc == fnc )
		{
			this.options.splice( i, 1 );
			break;
		}
	}
}

function MenuOption( fnc, text, active )
{
    this.childs    = new Array ();
    this.fnc 	   = fnc;
    this.text	   = text;
    this.active	   = active;

    this.AddOption = MenuOptionAddOption;
    
    return this;
}

function MenuOptionAddOption( opt )
{
	this.childs[ this.childs.length ] = opt;
}

function removeExternalTab( fnc )
{
	document.getElementById( "externalTabs" ).innerHTML = "";
	externalTabs.RemoveOption( fnc );
 	externalTabs.Draw();
}

function addExternalTab( fnc, text )
{
	document.getElementById( "externalTabs" ).innerHTML = "";
	externalTabs.AddOption( new MenuOption( fnc, text, false ) );
 	externalTabs.Draw();	
}

function checkUpdate()
{
	try
	{
		if ( isFieldUpdated ) return;
		isFieldUpdated = true;
		if ( currentDisplayMode == "DSP_UPD" )
		{
			setSaveButton( true );
			setCancelButton( true );
			getButtonsBar().ChangeOnClickEvent( "Stop", "getBody().reloadFORM1()" );
			try { getButtonsBar().Draw(); }	catch (e) {}
			eval( "document.FORM1." + document.FORM1.PageName.value + "RecordUpdated.value = '1';" );						
			setTopMessage( "" );
		}
	}
	catch(e){}
}

function createTAB( label, tab, fnc )
{
	// Get "tr" for internal tabs
	parentObj = document.getElementById( "internalTabTr" );
    var parentDoc = parentObj.ownerDocument || parentObj.document;
    // Remove last child which is a td width=100%
    // DOM insertBefore should be better better didn't manage to use it successfully
    parentObj.removeChild( parentObj.lastChild );
    // Add new internal tab
    var internalTabTd = parentObj.appendChild( parentDoc.createElement('td') );
    internalTabTd.id = "internalTAB" + tab;
    // Tab class is by default "TabOther"
    // If a tab is active, the function showTAB will change its class
    internalTabTd.className = "TabOther";
    internalTabTd.onclick = function()
    {
    	eval( fnc );
    	showTAB( "TAB" + tab );
	}
    internalTabTd.innerHTML = label;            
    // Add last td to draw a horizontal line
    var lastInternalTabTd = parentObj.appendChild( parentDoc.createElement('td') );
 	lastInternalTabTd.className = "TabEnd";
    lastInternalTabTd.setAttribute( "width", "100%" );
    lastInternalTabTd.innerHTML = "&nbsp;";
}

function hideTR( inputName, style )
{
	try
	{
		var td1 = document.getElementById( inputName + "TD1" );
		
		if ( td1 != null )
		{
			//alert( "DBG: set(" + inputName + "TD1" + "," + td1.innerHTML + ")" );
			// Hide Label
			if ( !hiddenTdText.has( inputName + "TD1" ) )
				hiddenTdText.set( inputName + "TD1", td1.innerHTML );
				
			td1.innerHTML = "";
			
			for ( var i = 0; i < td1.childNodes.length; i++ )
			{
				try
				{
					if ( style == "visibility" )
						td1.childNodes[ i ].style.visibility = "hidden";
					else
						td1.childNodes[ i ].style.display = "none";					
				}
				catch(e){}	
			}
			var td2 = document.getElementById( inputName + "DIV" );
			if ( style == "visibility" )
			{
				td2.style.visibility = "hidden";
				if ( ie )
				{
					for ( var i = 0; i < td2.childNodes.length; i++ )
					{
						try
						{
							if ( style == "visibility" )
								td2.childNodes[ i ].style.visibility = "hidden";
						}
						catch(e){}	
					}
				}
			}
			else
				td2.style.display = "none";
		}

	}
	catch(e){ alert( e.message);}
}

function displayTR( inputName, style )
{
	try
	{
		var td1 = document.getElementById( inputName + "TD1" );
		
		if ( td1 != null )
		{
			// Display Label
			var label = hiddenTdText.get( inputName + "TD1" );
			//alert( "DBG: get(" + inputName + "TD1" + "," + label + ")" );		
			if ( label != null )
			{
				td1.innerHTML = label;
				//hiddenTdText.remove( inputName + "TD1" );	
			}
			
			for ( var i = 0; i < td1.childNodes.length; i++ )
			{
				try
				{
					if ( style == "visibility" )
						td1.childNodes[ i ].style.visibility = "visible";
					else
						td1.childNodes[ i ].style.display = "inline";					
	
				}
				catch(e){}
			}
			var td2 = document.getElementById( inputName + "DIV" );
			if ( style == "visibility" )
			{
				td2.style.visibility = "visible";
				if ( ie )
				{
					for ( var i = 0; i < td2.childNodes.length; i++ )
					{
						try
						{
							if ( style == "visibility" )
								td2.childNodes[ i ].style.visibility = "visible";
						}
						catch(e){}	
					}
				}
			}
			else				
				td2.style.display = "inline";			
		}
	}
	catch(e){}
}

function hideGroup( groupName, style )
{
	try
	{
	
		var grp = document.getElementById( groupName );
		if ( grp != null )
		{
			if ( style == "visibility" )
				grp.style.visibility = "hidden";
			else
				grp.style.display = "none";
		}
		grp = document.getElementById( "ActGroup" + groupName );
		if ( grp != null )
		{
			if ( style == "visibility" )
				grp.style.visibility = "hidden";
			else
				grp.style.display = "none";
		}
	}
	catch(e){}
}

function displayGroup( groupName, style )
{
	try
	{
	
		var grp = document.getElementById( groupName );		
		if ( grp != null )
		{
			if ( style == "visibility" )
				grp.style.visibility = "visible";
			else
				grp.style.display = "block";
		}
		grp = document.getElementById( "ActGroup" + groupName );	
		if ( grp != null )
		{
			if ( style == "visibility" )
				grp.style.visibility = "visible";
			else
				grp.style.display = "block";
		}

	}
	catch(e){}
}

function hideInput( inputName, style )
{
	try
	{
	
		var input = document.FORM1.elements[ inputName ];
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "hidden";
			else
				input.style.display = "none";
		}

	}
	catch(e){}
}

function displayInput( inputName, style )
{
	try
	{
	
		var input = document.FORM1.elements[ inputName ];
		
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "visible";
			else
				input.style.display = "inline";
		}

	}
	catch(e){}
}

function hideInputDate( inputName, style )
{
	hideInputDateFORM( inputName, style, "FORM1" );
}

function hideInputDateFORM( inputName, style, form )
{
	try
	{	
		var input = eval( "document." + form + ".elements[ 'yy" + inputName + "']" );
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "hidden";
			else
				input.style.display = "none";
		}
		input = eval( "document." + form + ".elements[ 'mm" + inputName + "']" );
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "hidden";
			else
				input.style.display = "none";
		}
		input = eval( "document." + form + ".elements[ 'dd" + inputName + "']" );
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "hidden";
			else
				input.style.display = "none";
		}
		input = eval( "document." + form + ".elements[ 'btn" + inputName + "']" );
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "hidden";
			else
				input.style.display = "none";
		}
	}
	catch(e){alert( e.message);}
}

function displayInputDate( inputName, style )
{
	displayInputDateFORM( inputName, style, "FORM1" );
}

function displayInputDateFORM( inputName, style, form )
{
	try
	{	
		var input = eval( "document." + form + ".elements[ 'yy" + inputName + "']" );	
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "visible";
			else
				input.style.display = "inline";
		}
		input = eval( "document." + form + ".elements[ 'mm" + inputName + "']" );	
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "visible";
			else
				input.style.display = "inline";
		}
		input = eval( "document." + form + ".elements[ 'dd" + inputName + "']" );	
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "visible";
			else
				input.style.display = "inline";
		}		
		input = eval( "document." + form + ".elements[ 'btn" + inputName + "']" );	
		if ( input != null )
		{
			if ( style == "visibility" )
				input.style.visibility = "visible";
			else
				input.style.display = "inline";
		}		
	}
	catch(e){}
}

function setMandatory( name )
{
	try
	{
		document.getElementById( name + "TD1" ).className = "labelMandatory";
	}
	catch(e)
	{}
	try
	{
		if ( document.FORM1.elements[ name ].className == "String" )
			document.FORM1.elements[ name ].className = "mandatoryString";
		else
		if ( document.FORM1.elements[ name ].className == "Num" )
			document.FORM1.elements[ name ].className = "mandatoryNum";						
	}
	catch(e)
	{}
}

function unsetMandatory( name )
{
	try
	{
		document.getElementById( name + "TD1" ).className = "String";
	}
	catch(e)
	{alert(e.message);}
	try
	{
		if ( document.FORM1.elements[ name ].className == "mandatoryString" )
			document.FORM1.elements[ name ].className = "String";
		else
		if ( document.FORM1.elements[ name ].className == "mandatoryNum" )
			document.FORM1.elements[ name ].className = "Num";						
	}
	catch(e)
	{alert(e.message);}
}

function resize()
{
	try
	{
		var cmargin = 33;
		var rmargin = 16;

		//debugMsg( arguments, "ScreenWidth.value=" + document.body.clientWidth + "\nScreenHeight.value=" + document.body.clientHeight + "\nwidthCol1=" + widthCol1 + "\nwidthCol2=" + widthCol2 );

		try
		{
			document.FORM1.ScreenWidth.value = document.body.clientWidth;
			document.FORM1.ScreenHeight.value = document.body.clientHeight;
		}
		catch(e) {}
		var images =document.getElementsByTagName( "img" );
		for ( var i = 0; i < images.length; i++ )
		{
			if ( images[ i ].className == "imgColumn" )			
				images[ i ].style.width = eval( document.body.clientWidth /2 - cmargin );
			if ( images[ i ].className == "imgSecondColumnRow" )
				images[ i ].style.width = eval( document.body.clientWidth - rmargin - 124 );
			if ( images[ i ].className == "imgSecondColumn" )			
				images[ i ].style.width = eval( document.body.clientWidth /2 - cmargin - 124 );
				
		}
		adjustBodyHeight();
	}
	catch (e) {}
}

function urlencode( url )
{
	url = escape( url );
	url = url.replace("+", "%2B");
	url = url.replace("/", "%2F");
	return url;
}

function keyPressedCatchNew( event )
{
	var result  = true;
	if ( event != null )
	{
		var keyCode = ie ? event.keyCode : event.which;
		if ( event.ctrlKey )
		{
			if ( keyCode == 78 ) // Ctrl + N
				result = false;
		}
	}
	return result;
}

// JT 05/26/2006
// = Added code ===============

var actField_name;
var actUrl;
var actWin;

// File Browser
function actricityFileBrowser(field_name, url, type, win )
{
	actField_name = field_name;
	actUrl = url;
	actWin = win;
	w = window.open("/actricity/Tool/AddOn/Document/ImageUploadDetail.jsp", "_blank", "width=250,height=80,resizable");
	w.focus();
}

	function initActTextarea()
	{
		try
		{
		var inst = tinyMCE.selectedInstance;
        var layer = new TinyMCE_Layer(inst.editorId+ "actLayer", false);
         
        //alert( document.getElementById(inst.editorId + '_parent') );
        var dv = layer.create('div', 'mceBlockBox', document.getElementById(inst.editorId + '_parent'));
        //dv.style.backgroundColor="red";
        alert( document.getElementById(inst.editorId).style.width );
        var p = tinyMCE.getAbsPosition(inst.iframeElement);
        dv.style.left=p.absLeft;
        dv.style.top=p.absTop - 45;
        
        if ( body.offsetHeight > inst.iframeElement.offsetHeight )
        	dv.style.width = eval( parseInt( document.getElementById(inst.editorId).style.width ) - 16 );             
        else
        dv.style.width=document.getElementById(inst.editorId).width;      
 
        dv.style.height=eval(parseInt( document.getElementById(inst.editorId).height) + 25 );  
       // dv.style.width=document.getElementById(inst.editorId).width;   
        //layer.moveRelativeTo( inst.iframeElement, "tl" );
        layer.show();               
        }
        catch(e){alert(e.message);}
	}
	
    function pasteFromClipboard( name)
	{		
		startWait();
    	eval( "if (document.ActTextareaPaste" + name + " ) {document.ActTextareaPaste" + name + ".pasteFromClipboard();}" );
	}
            	
	function pasteDone( path, name )
    {
    	try
    	{
	    	var extension = path.substring( path.lastIndexOf( "." ) + 1 );
	    	switch( extension )
	    	{
	    		case "jpg" :
	    		case "gif" :
	    		case "bmp" :
	    		case "tif" :
	    		case "pcx" :	    		
	    		case "png" :
			    	tinyMCE.getInstanceById( name ).execCommand('mceInsertContent',false,'<img src=\"' + path + '\">');
			    	break;
			    default :
			    	alert( TC_NotAnImage );
			}
	    }
	    catch(e)
	    {}
	    stopWait();
	}	
// =============================
function debugMsg( args, text, type)
{
	var fnc = (args.callee).toString().substring( 0, (args.callee).toString().indexOf( "{" ) );
	
	var sep = "------------------------------------------------------------\n";
		
	var msg = "[DEBUG CommonScript.js]\n";
	msg += sep;
	msg += fnc;	
	msg += "\n";
	for ( var i = 0; i < args.length; i++ )
	{
		msg += "Argument " + i + " = " + args[ i ] + "\n";
	}
	
	msg += sep;
	msg += text;
	
	if ( type != "undefined" )
	{ 
		if ( type == "top" )
		{
			msg = msg.replace( "\n", "<br/>" )
//			setTopMessage( msg );
			setTopMessage( text );
		}
		else
			if ( type == "keyPart" )
			{
				msg = msg.replace( "\n", "<br/>" )
				setKeyPart( msg );
			}
			else
				if ( type == "file" )
				{
					if ( ie )
					{
						var fh;
						var fso = new ActiveXObject("Scripting.FileSystemObject");
						fh = fso.OpenTextFile("logScript.txt", 8, true)
						fh.WriteLine( msg );
						fh.Close();
					}
				}
				else
					if ( type == "window" )
					{
						if ( winDebug == null || winDebug.closed ) 
						{
							msg = msg.replace( "\n", "<br/>" )
							winDebug = window.open("", "DEBUG", "width=400,height=250,resizable,scrollbars");
							winDebug.document.write("<TITLE>DEBUG</TITLE>");
							winDebug.document.write("<BODY><DIV id='content'>" + msg + "</DIV></BODY>");
							winDebug.document.close();	
						}	
						else
						{
							winDebug.document.getElementById( "content" ).innerHTML = winDebug.document.getElementById( "content" ).innerHTML + "<BR>" + msg;
						}									
					}
					else
						alert( msg );			
	}
	else
		alert( msg );
}

function submitToQuicklist( name, targetKeyName, returnFunction, selectMode )
{
	document.FORM1.TargetKeyName.value 	   = targetKeyName;
	document.FORM1.SelectRtnFunction.value = returnFunction;
}

function addFromList( name, values, url, params )
{
	setTimeout( function(){ ajaxClassLoader( url, "values=" + values + "&" + params , "sendQuery('" + name + "', '', '')" ); }, 30 );
}

function loadQuicklist( selectModule, targetKeyName, selectWhat, name, selectQuery, selectQueryTemp, returnFunction, selectMode )
{
	if ( selectModule != null && selectModule.length > 0 )
	{
		var WID = "W"+new Date().getTime();
		if ( selectQuery == undefined ) selectQuery = ""; 
		if ( selectMode == undefined ) selectMode = "unique"; 
		if ( selectQueryTemp == undefined ) selectQueryTemp = ""; 	
		if ( targetKeyName.indexOf( ";" ) > 0 )
		{
			var exp  = new RegExp( ";", "ig" );
			var keyNames = targetKeyName.split(exp);
			targetKeyName = keyNames[ 1 ] + "." + keyNames[ 0 ] + ";" + keyNames[ 1 ] + "." + keyNames[ 1 ];
		}
		else
			targetKeyName = targetKeyName + "." + targetKeyName;
		var params = "SelectModule=" + selectModule + "&SelectWhat=" + selectWhat + "&InputName=" + name 
					+ "&SelectQuery=" + urlencode( selectQuery ) + "&SelectQueryTemp=" + urlencode( selectQueryTemp ) 
					+ "&ReturnFunction=" + urlencode( returnFunction ) + "&SelectMode=" + selectMode + "&WinID="+getBody()._winID;	
		//debugMsg( arguments, "params=" + params );
		if ( winQuickList == null || winQuickList.closed ) 
			winQuickList = window.open("/actricity/servlet/actricityV1.common.objects.select.quick.QuicklistManagement?" + params
							 , WID, "width=100,height=150,resizable=yes,scrollbars=yes,top=100,left=100");
		else
			winQuickList.location.href = "/actricity/servlet/actricityV1.common.objects.select.quick.QuicklistManagement?" + params;
		winQuickList.focus();
	}
}
        	   
function loadReflabel( name, inputName, reflabelName, keyValue, displayFunction, targetKeyName, returnFunction, readonly, length, tooltipAjaxUrl )
{
	//debugMsg( arguments, "" );
	var keyValueReturn = "";
	if ( returnFunction == null ) returnFunction = "";
	else
	{
		if ( returnFunction.indexOf( "<K>" ) >= 0 )
		{
			if ( keyValue.indexOf( ";" ) > 0 ) keyValueReturn = keyValue.substring( 0 , keyValue.indexOf( ";" ) );
			returnFunction = returnFunction.substring( 0, returnFunction.indexOf( "<K>" ) ) + keyValueReturn + returnFunction.substring( returnFunction.indexOf( "<K>" ) + 3 );
		}
	}
	ajaxRequest( "/actricity/servlet/actricityV1.tool.reflabel.library.LoadReflabel", "name=" + name + "&inputName=" + inputName + "Label&reflabelName=" + reflabelName + "&keyValue=" + keyValue + "&displayFunction=" + displayFunction + "&targetKeyName=" + targetKeyName + "&readonly=" + readonly + "&length=" + length + "&tooltipAjaxUrl=" + urlencode( tooltipAjaxUrl ), "refreshReflabel(ajaxResponse,'" + inputName + "');" + returnFunction );
//	document.getElementById( name + "Label" ).innerHTML = TC_Wait;	
}

function refreshReflabel( ajaxResponse, inputName )
{
	//debugMsg( arguments, "ajaxResponse=" + ajaxResponse);
	try { eval( ajaxResponse ); } catch(e){}
	try { document.getElementById( inputName + "Label" ).style.display = "inline"; }catch(e) {}	
	try { document.images[ "Clear" + inputName ].style.display = "inline";	} catch(e) {}
}

function checkExternalKey( name, inputName, selectModule, targetKeyName, selectWhat, extkeyValue, selectQuery, returnFunction )
{
	//debugMsg( arguments, "");
	if ( returnFunction == null ) returnFunction = "";
	// Reset
	if ( extkeyValue == "" )
	{
		resetExternalKey( name, inputName );
		try{ eval( returnFunction ) } catch(e) {}
	}
	else
		ajaxRequest( "/actricity/servlet/actricityV1.common.objects.select.quick.library.CheckExternalKey", "name=" + name + "&inputName=" + inputName + "&selectModule=" + selectModule + "&selectWhat=" + selectWhat + "&targetKeyName=" + targetKeyName + "&extkeyValue=" + extkeyValue + "&selectQuery=" + urlencode(selectQuery) + "&returnFunction=" + returnFunction, "refreshReflabel(ajaxResponse);" );
}

function resetExternalKey( name, inputName )
{
	try { document.FORM1.elements[ inputName ].value = "";	} catch(e) {}
	try { document.images[ "Clear" + inputName ].style.display = "none";	} catch(e) {}
	try{ document.getElementById( inputName + "Label" ).innerHTML = ""; }catch(e) {}
	try
	{
		if ( inputName.indexOf( "ActExternalKey" ) == 0 ) 
		{
			document.getElementById( name ).value = "0";
			document.getElementById( inputName ).value = "";
		}
		else
			document.getElementById( inputName ).value = "";
	}
	catch(e) {}
}

function loadFieldsWithKeys( file, fields, keys )
{
	ajaxRequest( "/actricity/servlet/actricityV1.common.objects.LoadFieldsWithKeys", "file=" + file + "&fields=" + fields + "&keys=" + keys, "refreshFields(ajaxResponse)" );
}

function refreshFields( ajaxResponse )
{
	try
	{
		var fields = new Array;
		eval( ajaxResponse );
		fieldsChanged( fields );
	}
	catch(e)
	{}
}

function cancelEvent( event )
{
	if (!ie) 
 		{
	   	event.preventDefault();
	    event.stopPropagation();
	}
	else
		event.cancelBubble = true;
    event.returnValue = false;	
}
