/**********************************************************
***********************************************************
*  Copyright 2004 (c) Aumediage S.P.R.L. All Rights Reserved.								*
*  This is a commercial software product, please visit												*
*  http://www.aumediage.net for more information. or send email to					*
*  aumediage@hotmail.com																						*
*  See http://www.aumediage.net for Commercial License Agreement				*
*  All Copyright statements must always remain in place in all files at all times	*
*		***** PLEASE NOTE: THIS IS NOT FREE SOFTWARE	*****						*
*				*****	IT MUST BE LICENSED FOR ALL USE	*****								*
*  HISTORY																												*
*	Name			Date							Action											Version			*
*	GdB				01/03/2001			Creation										1.00					*
*	GdB				20/10/2003			Added more type support			2.00					*
*																																	*
************************************************************
***********************************************************/

/*********************************************************
**********************************************************
**********************************************************
GENERIC FORM FUNCTIONS
**********************************************************
*********************************************************/

function CheckDeleteOk(__Url, __Text){
	if (!__Text)
		__Text = '';
	if(customMsgBox(g_DeleteMessage.replace('@@ITEM@@', __Text), vbYesNo, 'Security Alert'))
		GoToPage(__Url);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function CheckModifyOk(bValue){
	customMsgBox('You do not have the rights to modify!',vbOK,'Security Alert');
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function ChangeFormModifiedStat(__Value){
	top.window.g_isFormModified = (__Value == false)?false:true;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function ReputDefaultValue(__Form){
	for (i=0; i<__Form.length-1 ; i++){
		thisItem = __Form.elements[i];
		if (thisItem.type != 'select-one' && thisItem.type != 'select-multiple')
			thisItem.value = thisItem.defaultValue;
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** check if form was modified ***/
function HasFormBeenModified (__Form){
	var thisItem;
	var bReturnValue= false;
	for (i=0; i<__Form.length-1 ; i++){
		thisItem = __Form.elements[i];
		if (thisItem.value != thisItem.defaultValue){
				bReturnValue = true;
		}
	}
	if (bReturnValue == false){
		customMsgBox(getCommonVoc(92), vbOK+vbExclamation);
	}
	return bReturnValue;	
}
/*********************************************************
**********************************************************
**********************************************************
RADIO & CHECKBOX HANDLING
**********************************************************
*********************************************************/
/***GET THE SELECTED RADIO VALUE ***/
function CheckRadioSelected(__RadioBox){
	__RadioBox = (__RadioBox.name)? eval('document.'+__RadioBox.form.name+'.'+__RadioBox.name) : __RadioBox;
	if (__RadioBox.length){		
		for (var i=0; i <__RadioBox.length; i++){
			if (__RadioBox[i].checked == true)
				return true;
		}
		return false
	}
	else {
		return __RadioBox.checked;
	}
	return false;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/***GET THE SELECTED RADIO VALUE ***/
function GetRadioValue(__RadioBox){
	__RadioBox = (__RadioBox.name)? eval('document.'+__RadioBox.form.name+'.'+__RadioBox.name) : __RadioBox;
	if (__RadioBox.length){
		
		for (var i=0; i <__RadioBox.length; i++){
			if (__RadioBox[i].checked == true)
				return __RadioBox[i].value;
		}
	}
	else if (__RadioBox.checked){
		return __RadioBox.value;
	}
	return null;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/***GET THE SELECTED RADIO VALUE ***/
function GetRadioArrayValue(__RadioBox, __Type){
	var aryBuffer = new Array();
	if (typeof(__RadioBox) == 'object' || typeof(__RadioBox) == 'function'){
		__RadioBox = (__RadioBox.name)? eval('document.'+__RadioBox.form.name+'.'+__RadioBox.name) : __RadioBox;
		if (__RadioBox.length > 0){
			for (var i=0; i <__RadioBox.length; i++){
				if (__RadioBox[i].checked == true){
					aryBuffer[aryBuffer.length] =  __RadioBox[i].value;
				}
			}
		}
		else{
			if (__RadioBox.checked == true){
					aryBuffer[aryBuffer.length] =  __RadioBox.value;
			}
		}
	}
	return aryBuffer;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/***True false depending if it is selected or not. ***/
function GetRadioSelected(__RadioBox, __Type){
	__RadioBox = (__RadioBox.name)? eval('document.'+__RadioBox.form.name+'.'+__RadioBox.name) : __RadioBox;
	for (var i=0; i <__RadioBox.length; i++){
		if (__RadioBox[i].checked == true){
			return (__Type == 'value')? __RadioBox[i].value : true;
		}
	}
	return false;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** Select All ***/
function DoRadioSelectAll(__RadioBox){
	//oRadioBox		= (typeof(oRadioBox) == 'object')?oRadioBox : getObject(oRadioBox);
	__RadioBox = (__RadioBox.name)? eval('document.'+__RadioBox.form.name+'.'+__RadioBox.name) : __RadioBox;
	for (var i=0; i <__RadioBox.length; i++){
		__RadioBox[i].checked = true;
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** DeSelect All ***/
function DoRadioDeselectAll(__RadioBox){
	//oRadioBox		= (typeof(oRadioBox) == 'object')?oRadioBox : getObject(oRadioBox);
	__RadioBox = (__RadioBox.name)? eval('document.'+__RadioBox.form.name+'.'+__RadioBox.name) : __RadioBox;
	for (var i=0; i <__RadioBox.length; i++){
		__RadioBox[i].checked = false;
	}
}
/*********************************************************
**********************************************************
**********************************************************
SELECT HANDLING
**********************************************************
*********************************************************/

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/***   REMOVE ALL OPTIONS FROM A SELECT ELEMENT   ***/
function DoSelectRemoveAll(__Select, __SkipFirstRow){
	var sBuffer;
	var iStop = (__SkipFirstRow)?0 : -1;
	if (! (__SkipFirstRow && __Select.length == 1)){
		for (var i=__Select.length; i >iStop; i--){
			DoSelectRemove(__Select, i);
		}
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/***   ADD AN OPTION TO A SELECT ELEMENT  ***/
function DoSelectAdd(__Select, __OptionText, __OptionValue, __Index){
	__Index = (__Index >=0)? __Index : __Select.length;
	if (__Index == 0){
		for (var i=__Select.length-1; i >=0; i--){
			DoSelectAdd(__Select, __Select.options[i].text, __Select.options[i].value, i+1);
		}
	}
	__Select.options[__Index]			= new Option(__OptionText);
	__Select.options[__Index].value	= __OptionValue;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** TRANSFER AN OPTION FROM A SELECT ELEMENT TO AN OTHER ***/
function DoRemoveFromAddToSelect(__SelectFrom, __SelectTo){
	var readyToContinue = false;
	for (i=0;i < __SelectFrom.length; i++){
		if (__SelectFrom.options[i].selected == true){
			try{
				DoSelectAdd(__SelectTo, __SelectFrom.options[i].text, __SelectFrom.options[i].value, __SelectTo.length);
				readyToContinue = true;
			}
			catch(exception){
				readyToContinue = false;
			}
			if (readyToContinue == true){
				try{
					DoSelectRemove(__SelectFrom,i);
				}
				catch(exception){
					DoSelectRemove(__SelectTo, __SelectTo.length-1);
				}
			}
			i--;
		}
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** REMOVE AN OPTION FROM A SELECT ELEMENT ***/
function DoSelectRemove(__Select, __Index){
	if (__Select.length > 0){
		__Index = (__Index >=0)? __Index : __Select.length-1;
		if ( !(isOp && isOp7 != true)  && !(isIE && isMac))
			__Select.remove (__Index);
		else{
			__Select.options[__Index]			= null;
		}
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function DoRemoveFromSelect(__Select){
	var readyToContinue = false;
	for (i=__Select.length-1;i >= 0; i--){
		if (__Select.options[i].selected == true){
			try{
				DoSelectRemove(__Select, i);
			}
			catch(exception){
				DoSelectRemove(__SelectTo, __SelectTo.length-1);
			}
		}
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** get Array with select selected value(s) ***/
function GetSelectArraySelected(__Select, __Type){
	var aryBuffer = new Array();
	for (var i = 0; i< __Select.length ; i++){
		if (__Select.options[i].selected == true)
			aryBuffer[aryBuffer.length] = (__Type == 'value') ? __Select.options[i].value : i;
	}
	return aryBuffer;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** get int with select selected value(s) ***/
function GetSelectSelected(__Select, __Type){
	return (__Type == 'value') ? __Select.options[__Select.options.selectedIndex].value : __Select.options.selectedIndex;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** Handles move of the options ***/
function DoSelectMove(__Direction, __Select, __SkipFirstRow){
	__Select		= (typeof(__Select) == 'object')?__Select : getObject(__Select);
	var aryTemp		= new Array();
	var arySel			= GetSelectArraySelected(__Select);
	var iAllowed;
	if (__Direction == 1){
		iAllowed		= __Select.length-1;
		arySel.reverse();
	}
	else if (__Direction == -1)
		iAllowed		= bSkipFirstRow ? 1 : 0;
	for (var i = 0; i< arySel.length ; i++){
		__Select.options[arySel[i]].selected = false;
		if ( !(__SkipFirstRow && arySel[i] == 0) && ( (__Direction == 1 && arySel[i] < iAllowed)  ||(__Direction == -1 && arySel[i] > iAllowed) ) ){
			aryTemp[0]	= new Array(__Select.options[arySel[i]].text, __Select.options[arySel[i]].value);
			aryTemp[1]	= new Array(__Select.options[arySel[i]+__Direction].text, __Select.options[arySel[i]+__Direction].value);
			__Select.options[arySel[i]+__Direction].text	= aryTemp[0][0];
			__Select.options[arySel[i]+__Direction].value	= aryTemp[0][1];
			__Select.options[arySel[i]].text				= aryTemp[1][0];
			__Select.options[arySel[i]].value				= aryTemp[1][1];				
			arySel[i] = arySel[i]+__Direction;
		}
	}
	__Select.options.selectedIndex = -1;
	for (var i = 0; i< arySel.length ; i++){
		__Select.options[arySel[i]].selected = true;
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** Move Option up ***/
function DoSelectMoveUp(__Select, __SkipFirstRow){
	doSelectMove(-1, __Select, __SkipFirstRow)
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** Move option Down ***/
function DoSelectMoveDown(__Select, __SkipFirstRow){
	doSelectMove(1, __Select, __SkipFirstRow)
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** Select All ***/
function DoSelectSelectAll(__Select){
	var __Select		= (typeof(__Select) == 'object')?__Select : getObject(__Select);
	for (var i = 0; i< __Select.length ; i++){
		__Select.options[i].selected = true;
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** DeSelect All ***/
function DoSelectDeselectAll(__Select){
	var __Select		= (typeof(__Select) == 'object')?__Select : getObject(__Select);
	__Select.options.selectedIndex = -1;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** Fill linked Select depending on selected value ***/
function ChangeLinked(__Select){
	var sLinked = __Select.getAttribute('oLinked');
	if (sLinked) {
		var arySel			= GetSelectArraySelected(__Select, 'value');
		var oLinked = eval('document.'+__Select.form.name+'.'+sLinked);
		DoSelectRemoveAll(oLinked, true)
		var aryTemp = eval(oLinked.getAttribute('contentFrom'));
		for (var i = 0; i< arySel.length ; i++){
			for (var j = 0; j< aryTemp.length ; j++){
				if (arySel[i] == aryTemp[j][2]){
					DoSelectAdd(oLinked,aryTemp[j][1],aryTemp[j][0]);
				}
			}
		}
		ChangeLinked(oLinked);
	}
}
/*********************************************************
**********************************************************
**********************************************************
FORM PROCESSIONG
**********************************************************
*********************************************************/
/*** Loop through each element of the form and check required fields and field type ***/
var sErrorMessage = '';
function IsFormReadyToProcess (__Form){
	sErrorMessage = '';
	//__Form.fldSubmit.disabled = true;
	var thisItem;
	var bReturnValue = true;
	for (var i=0; i < __Form.length-1 ; i++){
		thisItem			= __Form.elements[i];
		if (thisItem.getAttribute('validate') == 'true' &&  IsFieldReadyToProcess(thisItem) == false ){
			bReturnValue = false;
		}
	}
	if (bReturnValue == false){
		var sError = '';
		if (__Form.fldDefaultErrorMessage && __Form.fldDefaultErrorMessage.value != "")
			sError = __Form.fldDefaultErrorMessage.value;
		else
			sError = getCommonVoc(50);
		//customMsgBox(sError + NewLine + sErrorMessage,vbOK+vbCritical , getCommonVoc(51));
	}
	//__Form.fldSubmit.disabled = false;
	return bReturnValue;	
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//function isFieldReadyToProcess (frmItem){	try{
function IsFieldReadyToProcess (__oFormItem){	try{
		var FLD_Type			= __oFormItem.type;
		var FLD_Required		= (__oFormItem.getAttribute('required') == 'true')?true:false;
		var FLD_Validate		= (__oFormItem.getAttribute('validate') == 'true')?true:false;
		var FLD_FieldType		= (__oFormItem.getAttribute('fieldType'))?__oFormItem.getAttribute('fieldType').toLowerCase():__oFormItem.getAttribute('fieldType');
		var FLD_Format			= (__oFormItem.getAttribute('fieldFormat'))?__oFormItem.getAttribute('fieldFormat').toLowerCase():__oFormItem.getAttribute('fieldFormat');
		var FLD_MaxValue		= __oFormItem.getAttribute('maxValue');
		var FLD_MinValue		= __oFormItem.getAttribute('minValue');
		var FLD_MaxLength		= __oFormItem.getAttribute('maxLength');
		var FLD_MinLength		= (__oFormItem.getAttribute('minLength') )?parseInt(__oFormItem.getAttribute('minLength')):null;
		var FLD_CompareTo		= __oFormItem.getAttribute('compareTo');
		var FLD_CompareAction	= __oFormItem.getAttribute('compareAction') || '==';
		var FLD_ErrorMessage	= __oFormItem.getAttribute('errorMessage');
		var FLD_ValueViewer		= __oFormItem.getAttribute('valueViewer');
		var FLD_ValueExclusion	= __oFormItem.getAttribute('valueExclusion');
		var FLD_ValueInclusion	= __oFormItem.getAttribute('valueInclusion');
		var FLD_CharExclusion	= __oFormItem.getAttribute('CharExclusion');
		var FLD_CharInclusion	= __oFormItem.getAttribute('CharInclusion');
		var FLD_Caption			= __oFormItem.getAttribute('caption');
		var vValue				= __oFormItem.value;
		var bReturnValue		= true;
		if (FLD_Type == 'text' || FLD_Type == 'textarea' || FLD_Type == 'hidden' || FLD_Type == 'password' || FLD_Type == 'file'){/*CHECK IF IT IS A TEXT FIELD*/
			if (FLD_FieldType == 'date'){					/*CASE DATE*/
				bReturnValue  = IsFormatedDate(vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !FLD_Required);
				if (bReturnValue && FLD_CompareTo){
					bReturnValue  = CompareDate(__oFormItem,FLD_CompareTo, FLD_CompareAction)
				}
			}
			else if (FLD_FieldType == 'integer'){		/*CASE integer*/
				bReturnValue  = IsInteger(__oFormItem, vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !FLD_Required);
			}
			else if (FLD_FieldType == 'decimal'){		/*CASE Decimal*/
				bReturnValue  = IsDecimal(__oFormItem, vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !FLD_Required);
			}
			else if (FLD_FieldType == 'double'){		/*CASE double*/
				bReturnValue  = IsDouble(vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !FLD_Required);
			}
			else if (FLD_FieldType == 'currency'){		/*CASE Currency*/
				bReturnValue  = IsCurrency(vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !FLD_Required);
			}
			else if (FLD_FieldType == 'numeric'){		/*CASE NUMERIC*/
				bReturnValue  = IsNumeric(vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !FLD_Required);
			}
			else if (FLD_FieldType == 'email'){		/*CASE EMAIL*/
				bReturnValue  = IsEmail(vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !FLD_Required);
			}
			else if (FLD_FieldType == 'password'){		/*CASE EMAIL*/
				bReturnValue  = IsPassword(vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !FLD_Required);
			}
			else if (FLD_Required && isEmpty(vValue)){
				bReturnValue = false;
			}
				//alert(vValue + FLD_MaxLength);
			if (bReturnValue && !IsLengthOk(vValue, FLD_MinLength, FLD_MaxLength) ){
				bReturnValue = false;
				//alert('Too Long');
			}
			if (bReturnValue && FLD_CompareTo){
				var oLinked = eval(__oFormItem.form.name+'.'+FLD_CompareTo);
				bReturnValue = eval('\'' + __oFormItem.value + '\'' + FLD_CompareAction + '\'' + oLinked.value + '\'');
				if (!bReturnValue){
					HighlightWrongField(oLinked);
				}
			}
			if (bReturnValue == false){
				HighlightWrongField(__oFormItem);
			}
		}
		else if (FLD_Type == 'select-one' || FLD_Type == 'select-multiple'){/*CHECK IF IT IS A SELECT FIELD*/
			if ( FLD_Required && isEmpty(vValue) ){
				HighlightWrongField(__oFormItem);
				bReturnValue = false;
			}
			else{
				bReturnValue = true;
			}
		}
		else if (FLD_Type == 'radio'){/*CHECK IF IT IS A RADIO BOX FIELD*/
			vValue = GetRadioValue(__oFormItem);
			if (!vValue){
				bReturnValue = false;
			}
		}
		else if (FLD_Type == 'checkbox'){/*CHECK IF IT IS A CHECK BOX FIELD*/
			//alert(__oFormItem.name + ' - ' + CheckRadioSelected(__oFormItem))
			if (!CheckRadioSelected(__oFormItem)){
			//if (__oFormItem.checked == false){
				bReturnValue = false;
			}
		}
		//if (!IsValueOK(vValue, FLD_MinValue, FLD_MaxValue)){
		//	bReturnValue = false;
		//}
		if (FLD_ValueExclusion && IsExclusion(vValue, FLD_ValueExclusion)){
			bReturnValue = false;
		}
		if (FLD_CharExclusion && IsCharExclusion(vValue, FLD_CharExclusion)){
			HighlightWrongField(__oFormItem);
			bReturnValue = false;
		}
		//if (!IsInclusion(vValue, FLD_ValueInclusion)){
		//	bReturnValue = false;
		//}
		//if (!IsCharInclusion(vValue, FLD_CharInclusion)){
		//	bReturnValue = false;
		//}
		if (bReturnValue == false){
				BuildErrorMessage(FLD_Caption);
				if (getExists(__oFormItem.name + 'Error')){
					setDisplayOn(__oFormItem.name + 'Error');
				}
		}
		else{
			UnHighlightWrongField(__oFormItem);
			if (getExists(__oFormItem.name + 'Error')){
					setDisplayOff(__oFormItem.name + 'Error');
			}
		}
		return bReturnValue;
}catch(e){handleClientError('isFieldReadyToProcess', e);}}

function CheckInstantInputSize(__Input, __MaxLength, __Html){try{
	var sValue = (__Html)?parseHtml(__Input.value, true):__Input.value;
	var sLength = sValue.length;
	var iDiff = sLength - __Input.value.length
	//setWindowStatus(sLength + ' - ' + __Input.value.length)
	if (sLength > __MaxLength){
		__Input.value = __Input.value.substring(0, (__MaxLength-iDiff));
	}
}catch(e){handleClientError('CheckInstantInputSize', e);}}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsInclusion(__Value, __AryInclusion){try{
	if (__AryInclusion){
		__AryInclusion = __AryInclusion.split('~~');
		for (var i = 0 ; i < __AryInclusion.length ; i++){
			if (__Value == __AryInclusion[i])
				return true;
		}
	}
	return false;
}catch(e){handleClientError('IsInclusion', e);}}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsExclusion(__Value, __AryExclusion){try{
	if (__AryExclusion){
		__AryExclusion = __AryExclusion.split('~~');
		for (var i = 0 ; i < __AryExclusion.length ; i++){
			if (__Value == __AryExclusion[i])
				return true;
		}
	}
	return false;
}catch(e){handleClientError('IsExclusion', e);}}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsCharInclusion(__Value, __AryInclusion){try{
	if (__AryInclusion){
		__AryInclusion = __AryInclusion.split('~~');
		for (var i = 0 ; i < __AryInclusion.length ; i++){
			if (__Value.indexOf(__AryInclusion[i]) != -1){
				return true;
			}
		}
	}
	return false;
}catch(e){handleClientError('IsCharInclusion', e);}}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsCharExclusion(__Value, __AryExclusion){try{
	if (__AryExclusion){
		__AryExclusion = __AryExclusion.split('~~');
		for (var i = 0 ; i < __AryExclusion.length ; i++){
			if (__Value.indexOf(__AryExclusion[i]) != -1){
				return true;
			}
		}
	}
	return false;
}catch(e){handleClientError('IsCharExclusion', e);}}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsValueOK(__Value, __MinValue, __MaxValue){try{
        if (__Value && !isNaN(parseInt(__Value))){
                __Value = parseInt(__Value);
                if (__MinValue && !isNaN(parseInt(__MinValue))){
                        __MinValue = parseInt(__MinValue);
                        if (__MinValue > __Value)
                                return false;
                }
                if (__MaxValue && !isNaN(parseInt(__MaxValue))){
                        __MaxValue = parseInt(__MaxValue);
                        if (__MaxValue < __Value)
                                return false;
                }
        }
        return true;
}catch(e){handleClientError('IsValueOK', e);}}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function AddErrorMessage(__oFormItem, __Message){
				if (getExists(__oFormItem.name + 'Error')){
					var oError = getObject(__oFormItem.name + 'Error');
					writeLayer(oError, getInnerHtml(oError) + __Message);
				}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function BuildErrorMessage(__Message){
	if (__Message)
		sErrorMessage += __Message + NewLine;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsLengthOk(__vValue, __iMinLength, __iMaxLength){
	var iLength = (__vValue)?__vValue.length:0;
	//alert(iLength + " - " + __iMinLength + " - " + __iMaxLength)
	if (__iMinLength && iLength < __iMinLength){
		return false;
	}
	if (__iMaxLength && iLength > __iMaxLength){
		return false;
	}
	return true;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsStringTooLong(__FormField, __Length){
	if (__FormField.value.length > __Length){
		/*oFormField.value = oFormField.value.replace('This is too Long','')*/
		/*oFormField.value = 'This is too Long\n'+oFormField.value*/
		customMsgBox(getCommonVoc(55),vbOK+vbCritical , getCommonVoc(51));
	}
}
/*********************************************************
**********************************************************
**********************************************************
CHECKING TYPE
**********************************************************
*********************************************************/
function CompareDate(__oFormItem,__CompareTo, __CompareAction){
	var oLinked = eval(__oFormItem.form.name+'.'+__CompareTo);
	var thisDate = GetNewDateFromDB(__oFormItem.value);
	var CompareDate = GetNewDateFromDB(oLinked.value);
	//if (CompareDate){
	//	return eval( Date.parse(__oFormItem.value ) + __CompareAction + Date.parse(CompareDate) );
	//}
	//else{
		return true;
	//}
}
function IsFormatedDate(__FieldDate, __DateFormat, __MinDate, __MaxDate, __Nullable){
	//alert(__FieldDate)
	if (__Nullable && isEmpty(__FieldDate) )
		return true; 
	if (!__Nullable && isEmpty(__FieldDate) )
		return false; 
	var bReturnValue = false;
	__FieldDate = GetNewDateFromDB(__FieldDate);
	if (__FieldDate){
		if (!__MinDate || (GetNewDateFromDB(__MinDate) && __FieldDate >= GetNewDateFromDB(__MinDate)))
			bReturnValue = true;
		else
			bReturnValue = false;
		if (bReturnValue && (!__MaxDate || (GetNewDateFromDB(__MaxDate) && __FieldDate <= GetNewDateFromDB(__MaxDate))))
			bReturnValue = true;
		else
			bReturnValue = false;
	}
	//var bReturnValue		= false;
	//var patternDate		= /\d\d\ +[a-zA-Z][a-zA-Z][a-zA-Z] *\d\d\d\d\ *$/;
	//var patternDate2		= /\d\ *[a-zA-Z][a-zA-Z][a-zA-Z] *\d\d\d\d\ *$/;
	//var patternDate3		= /\d\d\ *[a-zA-Z][a-zA-Z][a-zA-Z] *\d\d\d\d\ *\d\d\:\d\d *$/;
	//var patternDate4		= /\d\ *[a-zA-Z][a-zA-Z][a-zA-Z] *\d\d\d\d\ *\d\d\:\d\d *$/;
	//if (patternDate.test(__FieldDate)==false && patternDate2.test(__FieldDate)==false && patternDate3.test(__FieldDate)==false && patternDate4.test(__FieldDate)==false){
	//	bReturnValue		=  false;
	//}
	//else if (! isNaN(Date.parse(__FieldDate))){
	//		bReturnValue	=  true;
	//}
	//else{
	//		bReturnValue	= false;
	//}
	//alert(bReturnValue)
	return bReturnValue;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsInteger(__oFormItem, __Value, __Format, __MinValue, __MaxValue, __Nullable){
	if (__Nullable && isEmpty(__Value) )return true;
	var exp = /^\s*[-\+]?\d+\s*$/;
	if (__Value.match(exp) == null) 
		return false;
	__Value = parseInt(__Value, 10);
	/*return (isNaN(num) ? null : num);*/
	if (!isNaN(parseInt(__Value, 10))){
		var bIsOk = false;
		if (!__MinValue || (__MinValue && __Value >= __MinValue))
			bIsOk = true;
		else
			bIsOk = false;
		if (bIsOk && (!__MaxValue || (__MaxValue && __Value <= __MaxValue)))
			bIsOk = true;
		else
			bIsOk = false;
		if (!bIsOk){
			var sTemp = (__MinValue)?g_MinMaxValueCheck.replace('@@MINVALUE@@', __MinValue):g_MinMaxValueCheck.replace('@@MINVALUE@@', '...');
			sTemp = (__MaxValue)?sTemp.replace('@@MAXVALUE@@', __MaxValue):sTemp.replace('@@MAXVALUE@@', '...');
			AddErrorMessage(__oFormItem, sTemp);
		}
		return bIsOk
	}
	else{
		false
	}
	return false;//(isNaN(__Value) ? false : true);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsDecimal(__oFormItem, __Value, __Format, __MinValue, __MaxValue, __Nullable){
	if (__Nullable && isEmpty(__Value) )return true;
	var bIsOk = false;
	if (parseFloat(__Value) == __Value){
		var dValue = parseFloat(__Value);
		if (!__MinValue || (__MinValue && dValue >= __MinValue))
			bIsOk = true;
		else
			bIsOk = false;
		if (bIsOk && (!__MaxValue || (__MaxValue && dValue <= __MaxValue)))
			bIsOk = true;
		else
			bIsOk = false;
		if (!bIsOk){
			var sTemp = (__MinValue)?g_MinMaxValueCheck.replace('@@MINVALUE@@', __MinValue):g_MinMaxValueCheck.replace('@@MINVALUE@@', '...');
			sTemp = (__MaxValue)?sTemp.replace('@@MAXVALUE@@', __MaxValue):sTemp.replace('@@MAXVALUE@@', '...');
			AddErrorMessage(__oFormItem, sTemp);
		}
	}
	//var bIsDecimal = (parseFloat(__Value) == __Value)?true:false;
	return bIsOk;
	return  (parseFloat(__Value) == __Value)?true:false;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsDouble(__Value, __Format, __MinValue, __MaxValue, __Nullable){
	if (__Nullable && isEmpty(__Value) )return true;
	var sDecimalSep = ",";
	var exp			= new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + sDecimalSep + "(\\d+))?\\s*$");
	var aryMatches	= __Value.match(exp);
	if (aryMatches == null)
		return null;
	aryMatches = aryMatches[1] + (aryMatches[2].length>0 ? aryMatches[2] : "0") + "." + aryMatches[4];
	aryMatches = parseFloat(aryMatches);
	/*return (isNaN(num) ? null : num);*/
	return (isNaN(aryMatches) ? false : true);            
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsCurrency(__Value, __Format, __MinValue, __MaxValue, __Nullable){
	if (__Nullable && isEmpty(__Value) )return true;
	var SGroupSep = ".";
	var sDecimalSep = ",";
	var sDecimalDigits = 2;
	exp = new RegExp(	"^\\s*([-\\+])?(((\\d+)\\" + SGroupSep + ")*)(\\d+)"
						+ ((sDecimalDigits > 0) ? "(\\" + sDecimalSep + "(\\d{1," + sDecimalDigits + "}))?" : "")
						+ "\\s*$");
	aryMatches = __Value.match(exp);
	if (aryMatches == null)
		return false;
	var intermed = aryMatches[2] + aryMatches[5] ;
	aryMatches = aryMatches[1] + intermed.replace(new RegExp("(\\" + SGroupSep + ")", "g"), "") + ((sDecimalDigits > 0) ? "." + aryMatches[7] : 0);
	aryMatches = parseFloat(aryMatches);
	/*alert(aryMatches);*/
	return (isNaN(aryMatches) ? false : true);            
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsNumeric(__Value, __Format, __MinValue, __MaxValue, __Nullable){
	if (__Nullable && isEmpty(__Value) )return true;
	var rPattern = /^\s*[-\+]?[0-9 ., ]+$/;
	return rPattern.test(__Value);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsEmail(__Value, __Format, __MinValue, __MaxValue, __Nullable){
	if (__Nullable && isEmpty(__Value) )return true;
		var rPattern = /^[a-zA-z0-9_.-]{2,}@[a-zA-z0-9_.-]+.[a-zA-z0-9_]+$/i;
		return rPattern.test(__Value);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function IsPassword(vValue, __Format, __MinValue, __MaxValue, __Nullable){
		//isPassword(vValue, FLD_Format, FLD_MinValue, FLD_MaxValue, !bRequired);
	if (__Nullable && isEmpty(__Value) )return true;
	var bReturnValue = false;
	var sBuffer;
	var bLetter		= false;
	var bNumbers	= false;
	for(var n=0 ; n < __Value.length ; n++)	{
		sBuffer = __Value.charAt(n);
		if(  (sBuffer >= 'A' && sBuffer <= 'Z') || (sBuffer >= 'a' && sBuffer <= 'z') ) bLetter = true;
		if( sBuffer >= '0' && sBuffer <= '9' ) bNumbers = true;
		if (bNumbers || bLetter){
			bNumbers = bLetter = true; 
		}
		else{
			bReturnValue = false;
			break;
		}
	}
	if (bNumbers && bLetter){
		bReturnValue = true;
	}

//	var patternPasswordNumeric = /^[0-9]{4,}$/;
//	var patternPassword = /\w{4,20}/;
//	
//	else if (patternPasswordNumeric.test(sPassword)==false ){
//		alert ('no numeric');
//		bReturnValue = false;
//	}
	//else if (patternPasswordUpperCase.test(sPassword)==false ){
	//	alert ('no Upper case');
	//	bReturnValue =  false;
	//}
//	else if (patternPassword.test(sPassword)==false ){
//		alert ('no pattern match');
//		bReturnValue =  false;
//	}
//	else{
		//bReturnValue = true;
//	}
	//alert(bReturnValue)
	return bReturnValue;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** Put the backgpround color of the form field when the field lose focus ***/
function UnHighlightWrongField (__oFormItem){try{
	if (__oFormItem.className)
		__oFormItem.className = __oFormItem.className.replace('Missing', '');
		//alert(__oFormItem.getAttribute('ValueViewer'))
	if (__oFormItem.getAttribute('ValueViewer')){
		var oViewer		= getObject(__oFormItem.getAttribute('ValueViewer'), false);
		if (oViewer.className)
			oViewer.className = oViewer.className.replace('Missing', '');
	}
}catch(e){handleClientError('UnHighlightWrongField', e);}}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*** Put the backgpround color of the form field when the field lose focus ***/
function HighlightWrongField (__oFormItem){try{
	//alert(__oFormItem.className + ' - ' + __oFormItem.className.indexOf('Missing') == -1)
	if (__oFormItem.className){
		if (__oFormItem.className.indexOf('Missing') != -1)
			__oFormItem.className = __oFormItem.className.replace('Missing', '');
		__oFormItem.className = __oFormItem.className+'Missing';
	}
	if (__oFormItem.getAttribute('ValueViewer')){
		var oViewer		= getObject(__oFormItem.getAttribute('ValueViewer'), false);
		if (oViewer.className){
			if (oViewer.className.indexOf('Missing') != -1)
			oViewer.className = oViewer.className.replace('Missing', '');
		oViewer.className = oViewer.className+'Missing';
		}
		//alert(oViewer.className)
	}
	//__oFormItem.className = __oFormItem.className+'Missing';
	
}catch(e){handleClientError('HighlightWrongField', e);}}
/*********************************************************
**********************************************************
**********************************************************
FOLLOWING IS AN ADVANCED SELECT FUNCTIONS.
ALLOW US TO INPUT A WHOLE WORD, NOT ONLY THE FIRST LETTER
**********************************************************
*********************************************************/
var g_sToCatch = '';
var g_iSelectTimeOut;
function InputOnKeyPress(oSelect){
	var iKeyCode = event.keyCode;
	if (iKeyCode == 27){
		g_sToCatch = '';
		return;
	}
	g_sToCatch += String.fromCharCode(iKeyCode).toLowerCase();
	oSelect.onchange();
	if (g_iSelectTimeOut ){
		clearTimeout(g_iSelectTimeOut);
	}
	g_iSelectTimeOut = setTimeout('clearString()',1000);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function InputOnChange(oSelect) {
		if (g_sToCatch == ''){return;}
		var oThisSelect  = (oSelect)?oSelect:this;
		var iMaxIndex = oThisSelect.length;
		var isMatching = false;
		for (var i=0 ; i<iMaxIndex;i++){
				var sOptionSubString =  oThisSelect.options[i].text.substr(0,g_sToCatch.length).toLowerCase();
				if ( sOptionSubString == g_sToCatch){
					isMatching = true;
					oThisSelect.selectedIndex = i;
					break;
				}
		}
		//this.onchange();
}
/*********************************************************
**********************************************************
**********************************************************
RICH TEXT EDITOR HANDLING
**********************************************************
*********************************************************/
function showHideEditor (sName, iTab){
	var oTextarea			= getObject(sName+'Container1', true);
	var oTextEditor		= getObject(sName+'Container2', true);
	if (iTab == 1){
		oTextarea.display	= 'inline';
		oTextEditor.display	= 'none';
	}
	else{
		oTextarea.display	= 'none';
		oTextEditor.display	= 'inline';
	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function ateSaveTo(oThis){
		var oThisAte = eval(oThis.name);
		var oThisType = getObject(oThis.name+'Type');
		var iTab = (oThisType.value == 'html') ?2:1;
		var sContent = (iTab == 2)? oThis.value : parseHtml(oThis.value, true)
		oThisAte.outReset(oThis.value, iTab)
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function switchEntryType(oThis,  sContentName){
	var oContent = eval('document.'+oThis.form.name+'.'+sContentName);
	var sSwitchValue = oThis.value;
	var bSwitchToHtml = (oThis.value == 'html') ?true:false;
	oContent.value = parseHtml(oContent.value, bSwitchToHtml);
}

/**********************************************************
***********************************************************
*  Copyright 2004 (c) Aumediage S.P.R.L. All Rights Reserved.								*
*  This is a commercial software product, please visit												*
*  http://www.aumediage.net for more information. or send email to					*
*  aumediage@hotmail.com																						*
*  See http://www.aumediage.net for Commercial License Agreement				*
*  All Copyright statements must always remain in place in all files at all times	*
*		***** PLEASE NOTE: THIS IS NOT FREE SOFTWARE	*****						*
*				*****	IT MUST BE LICENSED FOR ALL USE	*****								*
*  HISTORY																												*
*	Name			Date							Action											Version			*
*	GdB				01/03/2001			Creation										1.00					*
*	GdB				20/10/2003			Added more type support			2.00					*
*																																	*
************************************************************
***********************************************************/
