var EW_splitBy = "`#$";
var EW_ValidationArray = new Array();	//array of validation "objects"
var EW_UniqueValidationArray = new Array();	//array for unicity
var EW_MaxSumValidationArray = new Array();	//array for max sum validator. the sum of the values of the objects contained in this array
var EW_SumValidationArray = new Array();	//array for sum validator. the sum of the values of the objects contained in this array
var EW_MaxLengthValidationArray = new Array();	//array for max length validator
var EW_MinLengthValidationArray = new Array();	//array for min length validator
var EW_ConfirmPasswordValidationArray = new Array();	//array for confirm password validator
var EW_ControlCheckedValidationArray = new Array();	//array of validation "objects" for validate if control checked
var EW_ControlNotCheckedValidationArray = new Array();	//array of validation "objects" for validate if control not checked
var EW_OneValueValidationArray = new Array();	//array of validation "objects" for validate with one value
function EW_AddValidatorWithBlurOption( controlId, controlType, validatorType, errorMessage, messageObjId, buttonId, okMessage, hasOnBlur ){
	EW_AddBasicValidator( controlId, controlType, validatorType, errorMessage, messageObjId, buttonId, okMessage );
	if( hasOnBlur ){
		document.getElementById( controlId ).onblur =  function(e){ EW_ControlValidate( controlId ) };
	}
}//EW_AddValidator

function EW_AddValidator( controlId, controlType, validatorType, errorMessage, messageObjId, buttonId, okMessage ){
	EW_AddValidatorWithBlurOption( controlId, controlType, validatorType, errorMessage, messageObjId, buttonId, okMessage, false )
}//EW_AddValidator
function EW_AddBasicValidator( controlId, controlType, validatorType, errorMessage, messageObjId, buttonId, okMessage ){
	var newIndex = EW_ValidationArray.length;
	EW_ValidationArray[ newIndex ] = new Array( 7 );
	EW_ValidationArray[ newIndex ][ 0 ] = controlId;
	EW_ValidationArray[ newIndex ][ 1 ] = controlType;
	EW_ValidationArray[ newIndex ][ 2 ] = validatorType;
	EW_ValidationArray[ newIndex ][ 3 ] = errorMessage;
	EW_ValidationArray[ newIndex ][ 4 ] = messageObjId;
	EW_ValidationArray[ newIndex ][ 5 ] = buttonId;
	EW_ValidationArray[ newIndex ][ 6 ] = okMessage;
}//EW_AddBasicValidator
function EW_AddUniqueValidatorWithBlurOption( columnName, rowID, val, errorMessage, messageObjId, buttonId, okMessage, hasOnBlur ){
	var newIndex = EW_UniqueValidationArray.length;
	EW_UniqueValidationArray[ newIndex ] = new Array( 7 );
	EW_UniqueValidationArray[ newIndex ][ 0 ] = columnName;
	EW_UniqueValidationArray[ newIndex ][ 1 ] = rowID;
	EW_UniqueValidationArray[ newIndex ][ 2 ] = val;
	EW_UniqueValidationArray[ newIndex ][ 3 ] = errorMessage;
	EW_UniqueValidationArray[ newIndex ][ 4 ] = messageObjId;
	EW_UniqueValidationArray[ newIndex ][ 5 ] = buttonId;
	EW_UniqueValidationArray[ newIndex ][ 6 ] = okMessage;
}
function EW_AddUniqueValidator( columnName, rowID, val, message, messageHolderID, buttonID, okMessage ){
	EW_AddUniqueValidatorWithBlurOption( columnName, rowID, val, message, messageHolderID, buttonID, okMessage, false );
}
function EW_AddSumValidatorWithBlurOption( controlId, controlType, sumMaxVal, totalSumControlId, errorMessage, messageObjId, buttonId, okMessage, hasOnBlur ){
	var newIndex = EW_SumValidationArray.length;
	EW_SumValidationArray[ newIndex ] = new Array( 8 );
	EW_SumValidationArray[ newIndex ][ 0 ] = controlId;
	EW_SumValidationArray[ newIndex ][ 1 ] = controlType;
	EW_SumValidationArray[ newIndex ][ 2 ] = sumMaxVal;
	EW_SumValidationArray[ newIndex ][ 3 ] = totalSumControlId;
	EW_SumValidationArray[ newIndex ][ 4 ] = errorMessage;
	EW_SumValidationArray[ newIndex ][ 5 ] = messageObjId;
	EW_SumValidationArray[ newIndex ][ 6 ] = buttonId;
	EW_SumValidationArray[ newIndex ][ 7 ] = okMessage;
	if( hasOnBlur ){
		document.getElementById( controlId ).onblur =  EW_ValidateSum( document.getElementById( controlId ) );
	}
}
function EW_AddSumValidator( controlId, controlType, sumMaxVal, totalSumControlId, errorMessage, messageObjId, buttonId, okMessage ){
	EW_AddValidatorWithBlurOption( controlId, controlType, sumMaxVal, totalSumControlId, errorMessage, messageObjId, buttonId, okMessage, false )
}
function EW_AddMaxSumValidatorWithBlurOption( controlId, controlType, sumMaxVal, totalSumControlId, errorMessage, messageObjId, buttonId, okMessage, hasOnBlur ){
	var newIndex = EW_MaxSumValidationArray.length;
	EW_MaxSumValidationArray[ newIndex ] = new Array( 8 );
	EW_MaxSumValidationArray[ newIndex ][ 0 ] = controlId;
	EW_MaxSumValidationArray[ newIndex ][ 1 ] = controlType;
	EW_MaxSumValidationArray[ newIndex ][ 2 ] = sumMaxVal;
	EW_MaxSumValidationArray[ newIndex ][ 3 ] = totalSumControlId;
	EW_MaxSumValidationArray[ newIndex ][ 4 ] = errorMessage;
	EW_MaxSumValidationArray[ newIndex ][ 5 ] = messageObjId;
	EW_MaxSumValidationArray[ newIndex ][ 6 ] = buttonId;
	EW_MaxSumValidationArray[ newIndex ][ 7 ] = okMessage;
	if( hasOnBlur ){
		document.getElementById( controlId ).onblur =  EW_ValidateMaxSum( document.getElementById( controlId ) );
	}
}
function EW_AddMaxSumValidator( controlId, controlType, sumMaxVal, totalSumControlId, errorMessage, messageObjId, buttonId, okMessage ){
	EW_AddMaxSumValidatorWithBlurOption( controlId, controlType, sumMaxVal, totalSumControlId, errorMessage, messageObjId, buttonId, okMessage, false )
}
function EW_AddOrValidator( controlsIds, controlsTypes, errorsMessages, messageObjsIds, buttonId, okMessages ){
	controlId = controlsIds.split( EW_splitBy );
	controlType = controlsTypes.split( EW_splitBy );
	errorMessage = errorsMessages.split( EW_splitBy );
	messageObjId = messageObjsIds.split( EW_splitBy );
	okMessage = okMessages.split( EW_splitBy );
	EW_AddBasicOrValidator( controlId, controlType, errorMessage, messageObjId, buttonId, okMessage )
}//EW_AddOrValidator
function EW_AddBasicOrValidator( controlsIds, controlsTypes, errorsMessages, messageObjIds, buttonId, okMessages ){
	//alert( controlsIds + " " + controlsTypes + " " + errorsMessages + " " + messageObjIds + " " + buttonId + " " + okMessages );
	EW_AddBasicValidator( controlsIds, controlsTypes, "or", errorsMessages, messageObjIds, buttonId, okMessages );
}//EW_AddOrValidator
function EW_AddMaxLengthValidatorWithBlurOption( controlId, controlType, maxAllowedLength, errorMessage, messageObjId, buttonId, okMessage, hasOnBlur ){
	var newIndex = EW_MaxLengthValidationArray.length;
	EW_MaxLengthValidationArray[ newIndex ] = new Array( 7 );
	EW_MaxLengthValidationArray[ newIndex ][ 0 ] = controlId;
	EW_MaxLengthValidationArray[ newIndex ][ 1 ] = controlType;
	EW_MaxLengthValidationArray[ newIndex ][ 2 ] = maxAllowedLength;
	EW_MaxLengthValidationArray[ newIndex ][ 3 ] = errorMessage;
	EW_MaxLengthValidationArray[ newIndex ][ 4 ] = messageObjId;
	EW_MaxLengthValidationArray[ newIndex ][ 5 ] = buttonId;
	EW_MaxLengthValidationArray[ newIndex ][ 6 ] = okMessage;
	if( hasOnBlur ){
		document.getElementById( controlId ).onblur =  function(e){ EW_ValidateMaxLength( controlId ) };
	}
}//EW_AddMaxLengthValidatorWithBlurOption
function EW_AddMaxLengthValidator( controlId, controlType, maxAllowedLength, errorMessage, messageObjId, buttonId, okMessage ){
	EW_AddMaxLengthValidatorWithBlurOption( controlId, controlType, maxAllowedLength, errorMessage, messageObjId, buttonId, okMessage, false )
}//EW_AddMaxLengthValidator
function EW_AddMinLengthValidatorWithBlurOption( controlId, controlType, minAllowedLength, errorMessage, messageObjId, buttonId, okMessage, hasOnBlur ){
	var newIndex = EW_MinLengthValidationArray.length;
	EW_MinLengthValidationArray[ newIndex ] = new Array( 7 );
	EW_MinLengthValidationArray[ newIndex ][ 0 ] = controlId;
	EW_MinLengthValidationArray[ newIndex ][ 1 ] = controlType;
	EW_MinLengthValidationArray[ newIndex ][ 2 ] = minAllowedLength;
	EW_MinLengthValidationArray[ newIndex ][ 3 ] = errorMessage;
	EW_MinLengthValidationArray[ newIndex ][ 4 ] = messageObjId;
	EW_MinLengthValidationArray[ newIndex ][ 5 ] = buttonId;
	EW_MinLengthValidationArray[ newIndex ][ 6 ] = okMessage;
	if( hasOnBlur ){
		document.getElementById( controlId ).onblur =  function(e){ EW_ValidateMinLength( controlId ) };
	}
}//EW_AddMinLengthValidatorWithBlurOption
function EW_AddMinLengthValidator( controlId, controlType, minAllowedLength, errorMessage, messageObjId, buttonId, okMessage ){
	EW_AddMinLengthValidatorWithBlurOption( controlId, controlType, minAllowedLength, errorMessage, messageObjId, buttonId, okMessage, false )
}//EW_AddMinLengthValidator
function EW_AddConfirmPasswordValidator( passwordControlId, confirmPasswordControlId, errorMessage, messageObjId, buttonId, okMessage ){
	var newIndex = EW_ConfirmPasswordValidationArray.length;
	EW_ConfirmPasswordValidationArray[ newIndex ] = new Array( 6 );
	EW_ConfirmPasswordValidationArray[ newIndex ][ 0 ] = passwordControlId;
	EW_ConfirmPasswordValidationArray[ newIndex ][ 1 ] = confirmPasswordControlId;
	EW_ConfirmPasswordValidationArray[ newIndex ][ 2 ] = errorMessage;
	EW_ConfirmPasswordValidationArray[ newIndex ][ 3 ] = messageObjId;
	EW_ConfirmPasswordValidationArray[ newIndex ][ 4 ] = buttonId;
	EW_ConfirmPasswordValidationArray[ newIndex ][ 5 ] = okMessage;
}//EW_AddConfirmPasswordValidator
function EW_AddValidateIfControlCheckedValidator( ifCheckedControlID, controlId, controlType, validatorType, errorMessage, messageObjId, buttonId, okMessage ){
	var newIndex = EW_ControlCheckedValidationArray.length;
	EW_ControlCheckedValidationArray[ newIndex ] = new Array( 8 );
	EW_ControlCheckedValidationArray[ newIndex ][ 0 ] = controlId;
	EW_ControlCheckedValidationArray[ newIndex ][ 1 ] = controlType;
	EW_ControlCheckedValidationArray[ newIndex ][ 2 ] = validatorType;
	EW_ControlCheckedValidationArray[ newIndex ][ 3 ] = errorMessage;
	EW_ControlCheckedValidationArray[ newIndex ][ 4 ] = messageObjId;
	EW_ControlCheckedValidationArray[ newIndex ][ 5 ] = buttonId;
	EW_ControlCheckedValidationArray[ newIndex ][ 6 ] = okMessage;
	EW_ControlCheckedValidationArray[ newIndex ][ 7 ] = ifCheckedControlID;
}//EW_AddValidateIfControlCheckedValidator
function EW_AddValidateIfControlNotCheckedValidator( ifNotCheckedControlID, controlId, controlType, validatorType, errorMessage, messageObjId, buttonId, okMessage ){
	var newIndex = EW_ControlNotCheckedValidationArray.length;
	EW_ControlNotCheckedValidationArray[ newIndex ] = new Array( 8 );
	EW_ControlNotCheckedValidationArray[ newIndex ][ 0 ] = controlId;
	EW_ControlNotCheckedValidationArray[ newIndex ][ 1 ] = controlType;
	EW_ControlNotCheckedValidationArray[ newIndex ][ 2 ] = validatorType;
	EW_ControlNotCheckedValidationArray[ newIndex ][ 3 ] = errorMessage;
	EW_ControlNotCheckedValidationArray[ newIndex ][ 4 ] = messageObjId;
	EW_ControlNotCheckedValidationArray[ newIndex ][ 5 ] = buttonId;
	EW_ControlNotCheckedValidationArray[ newIndex ][ 6 ] = okMessage;
	EW_ControlNotCheckedValidationArray[ newIndex ][ 7 ] = ifNotCheckedControlID;
}//EW_AddValidateIfControlNotCheckedValidator
function EW_AddOneValueValidation(controlId, controlType, validatorType, value, errorMessage, messageObjId, buttonId, okMessage){
    var newIndex = EW_OneValueValidationArray.length;
	EW_OneValueValidationArray[ newIndex ] = new Array( 8 );
	EW_OneValueValidationArray[ newIndex ][ 0 ] = controlId;
	EW_OneValueValidationArray[ newIndex ][ 1 ] = controlType;
	EW_OneValueValidationArray[ newIndex ][ 2 ] = validatorType;
	EW_OneValueValidationArray[ newIndex ][ 3 ] = value;
	EW_OneValueValidationArray[ newIndex ][ 4 ] = errorMessage;
	EW_OneValueValidationArray[ newIndex ][ 5 ] = messageObjId;
	EW_OneValueValidationArray[ newIndex ][ 6 ] = buttonId;
	EW_OneValueValidationArray[ newIndex ][ 7 ] = okMessage;
}
function EW_DeleteAllBasicValidator(buttonId)
 {
 EW_len=EW_ValidationArray.length
 for ( var i = 0; i < EW_len; i++ )
	{
	if(EW_ValidationArray[i][5] == buttonId)
	 {
	 EW_ValidationArray.splice(i,1);
	 i--;
	 EW_len--;
	 }
	} 
 }
function EW_ShowAllBasicValidator(buttonId)
 {
 for ( var i = 0; i < EW_ValidationArray.length; i++ )
	{
	if(EW_ValidationArray[i][5] == buttonId)
	 {
		alert(EW_ValidationArray[i][0]+"\n"+i)
	 }
	}
 }
function EW_DeleteBasicValidator(controlId)
 {
 for ( var i = 0; i < EW_ValidationArray.length; i++ ){
  if(EW_ValidationArray[i][0] == controlId)
    {
    EW_ValidationArray.splice(i, 1);
    i=EW_ValidationArray.length;
    }
 }
 }
function EW_Validate( buttonId ){
	for ( var i = 0; i < EW_ValidationArray.length; i++ ){
		if ( EW_ValidationArray[ i ][ 5 ] == buttonId ){
			//the button has to trigger the validation
			try{
			    if( EW_ValidateAccordingToType( i ) == false )
				    return false;
		    }catch (e){
		    }
		}
	}
	return true;
}//EW_Validate
function EW_ValidateOneValue( buttonId ){
	for ( var i = 0; i < EW_OneValueValidationArray.length; i++ ){
		if ( EW_OneValueValidationArray[ i ][ 6 ] == buttonId ){
			//the button has to trigger the validation
			try{
			    if( EW_ValidateAccordingToTypeAndOneValueValidationArray( i ) == false )
				    return false;
		    }catch (e){
		    }
		}
	}
	return true;
}//EW_Validate
function EW_ValidateUnicity( rowID ){
	var row = document.getElementById( rowID );
	var elems = row.getElementsbyTagName( "input" );
	EW_ValidateUnicityElements( elems );
	elems = row.getElementsbyTagName( "select" );
	EW_ValidateUnicityElements( elems );
	elems = row.getElementsbyTagName( "textarea" );
	EW_ValidateUnicityElements( elems );
}
function EW_ValidateUnicityElements( elems, rowID, buttonID ){
	for ( var i = 0; i < elems.length; i++ ){
		if ( elems[ i ].getAttribute( "unique" ) != null && elems[ i ].getAttribute( "unique" ) ){
			if ( ! EW_ValidateUnicityElem( elems[ i ], elems[ i ].getAttribute( "columname" ), rowID, gen_getObjValue( elems[ i ] ), buttonID ) ){
				return false;
			}
		}
	}
	return true;
}
function EW_ValidateUnicityElem( elem, columnName, rowID, val, buttonID ){
	for ( var i = 0; i < EW_UniqueValidationArray.length; i++ ){
		var curArr = EW_UniqueValidationArray[ i ];
		if ( curArr[ 0 ] == columnName && curArr[ 2 ] == val && curArr[ 1 ] != rowID && curArr[ 5 ] == buttonID ){
			//not unique
			return false;
		}
	}
	//unique
	return true;
}
function EW_ControlValidate( obj_id ){
	for ( var i = 0; i < EW_ValidationArray.length; i++ ){
		if ( EW_ValidationArray[ i ][ 0 ] == obj_id ){
			//verify
			if ( EW_ValidateAccordingToType( i ) == false )
				return false;
		}
	}
	return true;
}//EW_ControlValidate
function EW_ValidateAccordingToType( i ){	
	return EW_ValidateAccordingToTypeAndValidationArray( i, EW_ValidationArray );
}
function EW_ValidateAccordingToTypeAndValidationArray( i, EW_ValidationArray ){
	if ( document.getElementById( EW_ValidationArray[ i ][ 0 ] ) != null && document.getElementById( EW_ValidationArray[ i ][ 0 ] ).disabled == true ) return true;
	if ( EW_ValidationArray[ i ][ 2 ] == "required" ){
		//required validator
		var obj;
		if ( EW_ValidationArray[ i ][ 1 ] == "RADIO" ){
			obj =  document.getElementsByName(EW_ValidationArray[ i ][ 0 ]);
		}else{
			obj = document.getElementById( EW_ValidationArray[ i ][ 0 ] );
		}
		if ( ! EW_hasValue( obj , EW_ValidationArray[ i ][ 1 ] ) ){
			//validation failed
			EW_onError( obj, EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "integer" ){
		//integer validator: [+][-][number]
		if ( ! EW_checkinteger( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "numbers" ){
		if ( ! EW_checknumber( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			//validation failed
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "positivenumbers" ){
		if ( ! EW_checkpositivenumber( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "percentage" ){
		if ( ! EW_checkpercentage( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "percentagePhase" ){
		if ( ! EW_checkpercentagePerPhase( document.getElementById( EW_ValidationArray[ i ][ 0 ] ) ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}		
	}else if ( EW_ValidationArray[ i ][ 2 ] == "onlynumbers" ){
		if ( ! EW_checkonlynumbers( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "time" || EW_ValidationArray[ i ][ 2 ] == "HH:MM[:ss]" ){
		if ( ! EW_checkTime( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "hh:MM[:ss]" ){
		if ( ! EW_checkAMPMTime( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "mm/dd/yyyy" ){
		if ( ! EW_checkusdate( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "yyyy/mm/dd" ){
		if ( ! EW_checkdate2( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "yyyy-mm-dd" ){
		if ( ! EW_checkdate( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "dd/mm/yyyy" ){
		if ( ! EW_checkeurodate( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "dd-mm-yyyy" ){
		if ( ! EW_checkromdate( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "email" ){
		if ( ! EW_checkemail( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "emaillist" ){
		if ( ! EW_checkemaillist( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "phoneNumber" ){
		if ( ! EW_checkPhone( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "phoneFormat" ){
		if ( ! EW_checkPhoneFormat( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}			
	}else if ( EW_ValidationArray[ i ][ 2 ] == "titleFormat" ){
		if ( ! EW_checkTitleFormat( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "title" ){
		if ( ! EW_checkTitle( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "title1Format" ){
		if ( ! EW_checkTitle1Format( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "title1" ){
		if ( ! EW_checkTitle1( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "zipCode" ){
		if ( ! EW_checkZipFormat( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "HH:MM" ){
		if ( ! EW_checkSecondlessTime( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "hh:MM" ){
		if ( ! EW_checkSecondlessAMPMTime( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "HH:MM:ss" ){
		if ( ! EW_checkSecondTime( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "hh:MM:ss" ){
		if ( ! EW_checkSecondAMPMTime( document.getElementById( EW_ValidationArray[ i ][ 0 ] ).value ) ){
			EW_onError( document.getElementById( EW_ValidationArray[ i ][ 0 ] ), EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], document.getElementById( EW_ValidationArray[ i ][ 4 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_ValidationArray[ i ][ 4 ] ), EW_ValidationArray[ i ][ 6 ] );
		}
	}else if ( EW_ValidationArray[ i ][ 2 ] == "or" ){
		if ( ! EW_orValidator( EW_ValidationArray[ i ][ 0 ], EW_ValidationArray[ i ][ 1 ] ) ){
			EW_onOrError( EW_ValidationArray[ i ][ 0 ], EW_ValidationArray[ i ][ 1 ], EW_ValidationArray[ i ][ 3 ], EW_ValidationArray[ i ][ 4 ] );
			return false;
		}else{
			EW_notorerror( EW_ValidationArray[ i ][ 4 ], EW_ValidationArray[ i ][ 6 ] );
		}
	}
	return true;
}
function EW_ValidateAccordingToTypeAndOneValueValidationArray( i ){
	if ( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ) != null && document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ).disabled == true ) return true;
	if ( EW_OneValueValidationArray[ i ][ 2 ] == "greather" ){
		if ( ! EW_checkgreather( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 3 ] ) ){
			EW_onError( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 4 ], document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ), EW_OneValueValidationArray[ i ][ 7 ] );
		}
	}else if ( EW_OneValueValidationArray[ i ][ 2 ] == "less" ){
		if ( ! EW_checkless( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 3 ] ) ){
			EW_onError( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 4 ], document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ), EW_OneValueValidationArray[ i ][ 7 ] );
		}
	}else if ( EW_OneValueValidationArray[ i ][ 2 ] == "equal" ){
		if ( ! EW_checkequal( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 3 ] ) ){
			EW_onError( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 4 ], document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ), EW_OneValueValidationArray[ i ][ 7 ] );
		}
	}else if ( EW_OneValueValidationArray[ i ][ 2 ] == "greatherorequal" ){
		if ( ! EW_checkgreatherorequal( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 3 ] ) ){
			EW_onError( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 4 ], document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ), EW_OneValueValidationArray[ i ][ 7 ] );
		}
	}else if ( EW_OneValueValidationArray[ i ][ 2 ] == "lessorequal" ){
		if ( ! EW_checklessorequal( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 3 ] ) ){
			EW_onError( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 4 ], document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ), EW_OneValueValidationArray[ i ][ 7 ] );
		}
	}else if ( EW_OneValueValidationArray[ i ][ 2 ] == "maxsentences" ){
		if ( ! EW_checkmaxsentences( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ).value, EW_OneValueValidationArray[ i ][ 3 ] ) ){
			EW_onError( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 4 ], document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ), EW_OneValueValidationArray[ i ][ 7 ] );
		}
	}else if ( EW_OneValueValidationArray[ i ][ 2 ] == "maxwords" ){
		if ( ! EW_checkmaxwords( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ).value, EW_OneValueValidationArray[ i ][ 3 ] ) ){
			EW_onError( document.getElementById( EW_OneValueValidationArray[ i ][ 0 ] ), EW_OneValueValidationArray[ i ][ 1 ], EW_OneValueValidationArray[ i ][ 4 ], document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_OneValueValidationArray[ i ][ 5 ] ), EW_OneValueValidationArray[ i ][ 7 ] );
		}
	}
}
function EW_ValidateMaxSum( buttonId ){
	var totalSum = parseFloat("0");
	var maxAllowedSum;
	var index = 0;
	for ( var i = 0; i < EW_MaxSumValidationArray.length; i++ ){
		if ( EW_MaxSumValidationArray[ i ][ 6 ] == buttonId ){
			var strVal = document.getElementById( EW_MaxSumValidationArray[ i ][ 0 ] ).value;
			if ( strVal == "" ){
				strVal = "0";
			}
			var val = parseFloat( strVal );
			totalSum += val;
			maxAllowedSum = EW_MaxSumValidationArray[ i ][ 2 ];
			index = i;
		}
	}
	if ( maxAllowedSum != null ){
		if ( totalSum > maxAllowedSum ){
			EW_onError( document.getElementById( EW_MaxSumValidationArray[ index ][ 0 ] ), EW_MaxSumValidationArray[ index ][ 1 ], EW_MaxSumValidationArray[ index ][ 4 ], document.getElementById( EW_MaxSumValidationArray[ index ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_MaxSumValidationArray[ index ][ 5 ] ), EW_MaxSumValidationArray[ index ][ 7 ] );
		}
		var totalSumCtrl = document.getElementById( EW_MaxSumValidationArray[ index ][ 3 ] );
		if ( totalSumCtrl != null ){
			totalSumCtrl.value = totalSum;
		}
	}
	return true;
}
function EW_ValidateSum( rowId ){
	if ( EW_SumValidationArray.length > 0 ){
		var reqElem = document.getElementById( rowId );
		var inputs = reqElem.getElementsByTagName( "input" );
		for( var i = 0; i < inputs.length ;i++ )
		{
			var elem = inputs[ i ];
			if( elem.type == "text" )
			{
				var attr = elem.getAttribute( "TotalSumControlId" );
				if ( attr != null && attr != "" ){
					if ( ! EW_ValidateSumControl( elem ) ){
						return false;
					}
				}
			}
		}
		var textAreas = reqElem.getElementsByTagName( "textarea" );
		for( var i = 0; i < textAreas.length ;i++ )
		{
			var elem = textAreas[ i ];
			var attr = elem.getAttribute( "TotalSumControlId" );
			if ( attr != null && attr != "" ){
				if ( ! EW_ValidateSumControl( elem ) ){
					return false;
				}
			}
		}
		var selects = reqElem.getElementsByTagName( "select" );
		for( var i = 0; i < selects.length ;i++ )
		{
			var elem = selects[ i ];
			var attr = elem.getAttribute( "TotalSumControlId" );
			if ( attr != null && attr != "" ){
				if ( ! EW_ValidateSumControl( elem ) ){
					return false;
				}
			}
		}
	}
	return true;
}
function EW_ValidateSumControl( controlObj ){
	if ( EW_SumValidationArray.length > 0 ){
		var totalSumControlId = controlObj.getAttribute( "TotalSumControlId" );
		var totalSum = 0;
		var maxSum;
		var modifiedIndex;
		var isError = false;
		for ( var i = 0; i < EW_SumValidationArray.length; i++ ){
			if ( EW_SumValidationArray[ i ][ 3 ] == totalSumControlId ){
				maxSum = EW_SumValidationArray[ i ][ 2 ];	//set the max allowed sum, it's the same for all. i've chosen to set it all the
				if ( EW_SumValidationArray[ i ][ 0 ] == controlObj.id ){
					modifiedIndex = i;
				}
				var curVal = gen_getValue( EW_SumValidationArray[ i ][ 0 ] );
				if ( curVal != "" ){
					totalSum += parseInt( curVal );
					if ( totalSum > maxSum ){
						isError = true;
					}
				}
			}
		}
		if ( isError ){
			EW_onError( document.getElementById( EW_SumValidationArray[ modifiedIndex ][ 0 ] ), EW_SumValidationArray[ modifiedIndex ][ 1 ], EW_SumValidationArray[ modifiedIndex ][ 4 ], document.getElementById( EW_SumValidationArray[ modifiedIndex ][ 5 ] ) );
			return false;
		}else{
			EW_noterror( document.getElementById( EW_SumValidationArray[ modifiedIndex ][ 5 ] ), EW_SumValidationArray[ modifiedIndex ][ 7 ] );
		}
		var totalSumCtrl = document.getElementById( EW_SumValidationArray[ modifiedIndex ][ 3 ] );
		if ( totalSumCtrl != null ){
			totalSumCtrl.value = totalSum;
		}
	}
	return true;
}
function EW_ValidateMaxLength( buttonId ){
	for ( var i = 0; i < EW_MaxLengthValidationArray.length; i++ ){
		if ( EW_MaxLengthValidationArray[ i ][ 5 ] == buttonId ){
			try{
			    var val = document.getElementById( EW_MaxLengthValidationArray[ i ][ 0 ] ).value;
			    if( val.length > EW_MaxLengthValidationArray[ i ][ 2 ] ){
				    EW_onError( document.getElementById( EW_MaxLengthValidationArray[ i ][ 0 ] ), EW_MaxLengthValidationArray[ i ][ 1 ], EW_MaxLengthValidationArray[ i ][ 3 ], document.getElementById( EW_MaxLengthValidationArray[ i ][ 4 ] ) );
				    return false;
			    }else{
				    EW_noterror( EW_MaxLengthValidationArray[ i ][ 4 ], EW_MaxLengthValidationArray[ i ][ 6 ] );
			    }
		    }catch(e){
		    }
		}
	}
	return true;
}
function EW_ValidateMinLength( buttonId ){
	for ( var i = 0; i < EW_MinLengthValidationArray.length; i++ ){
		if ( EW_MinLengthValidationArray[ i ][ 5 ] == buttonId ){
			try{
			    var val = document.getElementById( EW_MinLengthValidationArray[ i ][ 0 ] ).value;
			    if( val != "" && val.length < EW_MinLengthValidationArray[ i ][ 2 ] ){
				    EW_onError( document.getElementById( EW_MinLengthValidationArray[ i ][ 0 ] ), EW_MinLengthValidationArray[ i ][ 1 ], EW_MinLengthValidationArray[ i ][ 3 ], document.getElementById( EW_MinLengthValidationArray[ i ][ 4 ] ) );
				    return false;
			    }else{
				    EW_noterror( EW_MinLengthValidationArray[ i ][ 4 ], EW_MinLengthValidationArray[ i ][ 6 ] );
			    }
		    }catch(e){
		    }
		}
	}
	return true;
}//EW_ValidateMinLength
function EW_ValidateConfirmPassword( buttonId ){
	for ( var i = 0; i < EW_ConfirmPasswordValidationArray.length; i++ ){
		if ( EW_ConfirmPasswordValidationArray[ i ][ 4 ] == buttonId ){
			var pass = document.getElementById( EW_ConfirmPasswordValidationArray[ i ][ 0 ] ).value;
			var confPass = document.getElementById( EW_ConfirmPasswordValidationArray[ i ][ 1 ] ).value;
			if( pass != confPass ){
				EW_onError( document.getElementById( EW_ConfirmPasswordValidationArray[ i ][ 0 ] ), "PASSWORD", EW_ConfirmPasswordValidationArray[ i ][ 2 ], document.getElementById( EW_ConfirmPasswordValidationArray[ i ][ 3 ] ) );
				return false;
			}else{
				EW_noterror( EW_ConfirmPasswordValidationArray[ i ][ 3 ], EW_ConfirmPasswordValidationArray[ i ][ 5 ] );
			}
		}
	}
	return true;
}//EW_ValidateConfirmPassword
function EW_ValidateIfControlChecked( buttonId ){
	for ( var i = 0; i < EW_ControlCheckedValidationArray.length; i++ ){
	    try{
		    if ( document.getElementById( EW_ControlCheckedValidationArray[ i ][ 7 ] ).checked ){
			    if ( EW_ControlCheckedValidationArray[ i ][ 5 ] == buttonId ){
				    if( EW_ValidateAccordingToTypeAndValidationArray( i, EW_ControlCheckedValidationArray ) == false )
					    return false;
			    }
		    }
	    }catch(e){
		}
	}
	return true;
}//EW_ValidateIfControlChecked
function EW_ValidateIfControlNotChecked( buttonId ){
	for ( var i = 0; i < EW_ControlNotCheckedValidationArray.length; i++ ){
		try{
		    if ( !document.getElementById( EW_ControlNotCheckedValidationArray[ i ][ 7 ] ).checked ){
			    if ( EW_ControlNotCheckedValidationArray[ i ][ 5 ] == buttonId ){
				    if( EW_ValidateAccordingToTypeAndValidationArray( i, EW_ControlNotCheckedValidationArray ) == false )
					    return false;
			    }
		    }
	    }catch(e){
		}
	}
	return true;
}//EW_ValidateIfControlNotChecked
function EW_onError( input_object, object_type, error_message, error_message_object ) {
	if (object_type == "RADIO" || object_type == "CHECKBOX") {
		if (input_object[0])
			input_object[0].focus();
		else
			input_object.focus();
	}else if (object_type == "TEXT" || object_type == "PASSWORD" || object_type == "TEXTAREA" || object_type == "FILE") {
		input_object.focus();
		input_object.select();
	}else if ( object_type == "SELECT" ){
		input_object.focus();
	}
	msg_showError(error_message);
}//EW_onError
function EW_onOrError( input_objects, objects_types, error_messages, error_messages_objects ) {
	for ( var i = 0; i < input_objects.length; i++ ){
		var error_message = error_messages[ i ];
		var error_message_object = document.getElementById( error_messages_objects[ i ] );
		var object_type = objects_types[ i ];
		var input_object = document.getElementById( input_objects[ i ] );
		if ( i == 0 ){
			EW_onError( input_object, object_type, error_message, error_message_object );
		}else{
			msg_showError(error_message);
		}
	}
}//EW_onOrError
function EW_noterror( error_message_object, okMessage ){
	msg_hideMessage();
}//EW_noterror
function EW_notorerror( error_messages, okMessages ){
	for ( var i = 0; i < error_messages.length; i++ ){
		var error_message_object = document.getElementById( error_messages[ i ] );
		var okMessage = okMessages[ i ];
		EW_noterror( error_message_object, okMessage );
	}
}//EW_noterror
function EW_orValidator( objects, objects_types ){
	for ( var i = 0; i < objects.length; i++ ){
		if ( EW_hasValue( document.getElementById( objects[ i ] ), objects_types[ i ] ) )
			return true;
	}
	return false;
}//EW_orValidator
function EW_hasValue(obj, obj_type) {
	if (obj_type == "TEXT" || obj_type == "PASSWORD" || obj_type == "TEXTAREA" || obj_type == "FILE")	{	
		if (obj.value.length == 0) 
			return false;
		else if (document.all && document.all["_"+obj.name+"_editor"] && (obj.value == '<P>&nbsp;</P>'))
			return false;  
		else 
			return true;
	} else if (obj_type == "SELECT") {
		if (obj.type != "select-multiple" && obj.value <= 0 )
			return false;
		else if (obj.type == "select-multiple" && obj.selectedIndex == -1)
			return false;
		else
			return true;
	} else if (obj_type == "RADIO" || obj_type == "CHECKBOX")	{
		if (obj[0]) {
			for (i=0; i < obj.length; i++) {
				if (obj[i].checked)
					return true;
			}
		} else {
			return (obj.checked);
		}
		return false;	
	} else if (obj_type == "SPAN"){
		if (obj.innerHTML.length == 0)
		    return false;
		 else return true;
	}
}//EW_hasValue
function EW_checkpercentage(object_value){
	if (object_value.length == 0)
		return true;
	
	if ( ! EW_checkonlynumbers( object_value ) ){
		return false
	}
	if ( object_value < 0 || object_value > 100 ){
		return false;
	}
	return true;
}
function EW_checkpercentagePerPhase(object){
	if (object.value.length == 0)
		return true;
	if ( ! EW_checkonlynumbers( object.value ) ){
		return false
	}
	if ( object.value < 0 || object.value > 100 ){
		return false;
	}
	percentage=object.id;
	phase_name = percentage.replace(/PPPercentage/g,"DCPPhaseID");
	current_phase=document.forms[0][phase_name].value;
	wich_elements=document.forms[0]["WichIds"].value;
	wich_elements_array=wich_elements.split(",");
	sum = 0;
	for(i=0,sum=0;i<wich_elements_array.length;i++){
		aux_string="DataList1_DCPPhaseID_ID_"+wich_elements_array[i];
		aux=document.forms[0][aux_string].value;
		aux2_string="DataList1_PPPercentage_ID_"+wich_elements_array[i];
		aux2=document.forms[0][aux2_string].value;
		if(current_phase == aux){
		 	if(aux2!=""){
				sum+=parseInt(aux2);						
				}
		 }
		}
	if(sum > 100){
	 return false;
	 }
	return true;
}
function EW_checkusdate(object_value) {
	if (object_value.length == 0)
		return true;
	isplit = object_value.indexOf('/');
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sMonth = object_value.substring(0, isplit);
	if (sMonth.length == 0)
		return false;
	isplit = object_value.indexOf('/', isplit + 1);
	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;
	sDay = object_value.substring((sMonth.length + 1), isplit);
	if (sDay.length == 0)
		return false;
	isep = object_value.indexOf(' ', isplit + 1); 
	if (isep == -1) {
		sYear = object_value.substring(isplit + 1);
	} else {
		sYear = object_value.substring(isplit + 1, isep);
		sTime = object_value.substring(isep + 1);
		if (!EW_checkTime(sTime))
			return false; 
	}
	return EW_checkdatevalues( sYear, sMonth, sDay );
}//EW_checkusdate
function EW_checkdate2(object_value) {
	if (object_value.length == 0)
		return true;
	isplit = object_value.indexOf('/');
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sYear = object_value.substring(0, isplit);
	isplit = object_value.indexOf('/', isplit + 1);
	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;
	sMonth = object_value.substring((sYear.length + 1), isplit);
	if (sMonth.length == 0)
		return false;
	isep = object_value.indexOf(' ', isplit + 1); 
	if (isep == -1) {
		sDay = object_value.substring(isplit + 1);
	} else {
		sDay = object_value.substring(isplit + 1, isep);
		sTime = object_value.substring(isep + 1);
		if (!EW_checkTime(sTime))
			return false; 
	}
	if (sDay.length == 0)
		return false;
	return EW_checkdatevalues( sYear, sMonth, sDay );
}//EW_checkdate2
function EW_checkdate(object_value) {
	if (object_value.length == 0)
		return true;
	isplit = object_value.indexOf('-');
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sYear = object_value.substring(0, isplit);
	isplit = object_value.indexOf('-', isplit + 1);
	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;
	sMonth = object_value.substring((sYear.length + 1), isplit);
	if (sMonth.length == 0)
		return false;
	isep = object_value.indexOf(' ', isplit + 1); 
	if (isep == -1) {
		sDay = object_value.substring(isplit + 1);
	} else {
		sDay = object_value.substring(isplit + 1, isep);
		sTime = object_value.substring(isep + 1);
		if (!EW_checkTime(sTime))
			return false; 
	}
	if (sDay.length == 0)
		return false;
	
	return EW_checkdatevalues( sYear, sMonth, sDay );
}//EW_checkdate
function EW_checkeurodate(object_value) {
	if (object_value.length == 0)
	  return true;
	isplit = object_value.indexOf('/');
	if (isplit == -1)	{
		isplit = object_value.indexOf('.');
	}
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sDay = object_value.substring(0, isplit);
	monthSplit = isplit + 1;
	isplit = object_value.indexOf('/', monthSplit);
	if (isplit == -1)	{
		isplit = object_value.indexOf('.', monthSplit);
	}
	if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
		return false;
	sMonth = object_value.substring((sDay.length + 1), isplit);
	isep = object_value.indexOf(' ', isplit + 1); 
	if (isep == -1) {
		sYear = object_value.substring(isplit + 1);
	} else {
		sYear = object_value.substring(isplit + 1, isep);
		sTime = object_value.substring(isep + 1);
		if (!EW_checkTime(sTime))
			return false; 
	}
	return EW_checkdatevalues( sYear, sMonth, sDay );
}//EW_checkeurodate
function EW_checkromdate(object_value) {
	if (object_value.length == 0)
	  return true;
	isplit = object_value.indexOf('-');
	if (isplit == -1)	{
		isplit = object_value.indexOf('.');
	}
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sDay = object_value.substring(0, isplit);
	monthSplit = isplit + 1;
	isplit = object_value.indexOf('-', monthSplit);
	if (isplit == -1)	{
		isplit = object_value.indexOf('.', monthSplit);
	}
	if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
		return false;
	sMonth = object_value.substring((sDay.length + 1), isplit);
	isep = object_value.indexOf(' ', isplit + 1); 
	if (isep == -1) {
		sYear = object_value.substring(isplit + 1);
	} else {
		sYear = object_value.substring(isplit + 1, isep);
		sTime = object_value.substring(isep + 1);
		if (!EW_checkTime(sTime))
			return false; 
	}
	return EW_checkdatevalues( sYear, sMonth, sDay );
}//EW_checkeurodate
function EW_checkdatevalues( sYear, sMonth, sDay ){
	if ( sYear.length > 4 )
		return false;
	if ( sMonth.length > 2 )
		return false;
	if ( sDay.length > 2 )
		return false;
	if (!EW_checkonlynumbers(sYear)) 
		return false;
	else if (!EW_checkrange(sYear, 1753, 9999)) 
		return false;   //minimum and maximum year values for mssql
	else if (!EW_checkonlynumbers(sMonth)) 
		return false;
	else if (!EW_checkrange(sMonth, 1, 12)) 
		return false;
	else if (!EW_checkonlynumbers(sYear)) 
		return false;
	else if (!EW_checkrange(sYear, 0, null)) 
		return false;
	else if (!EW_checkonlynumbers(sDay)) 
		return false;
	else if (!EW_checkday(sYear, sMonth, sDay)) 
		return false;
	else
		return true;
}//EW_checkdatevalues
function EW_checkday(checkYear, checkMonth, checkDay) {
	maxDay = 31;
	if (checkMonth == 4 || checkMonth == 6 ||	checkMonth == 9 || checkMonth == 11) {
		maxDay = 30;
	} else if (checkMonth == 2)	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}
	return EW_checkrange(checkDay, 1, maxDay); 
}//EW_checkday
function EW_checkonlynumbers(object_value){
	var number_format = "0123456789";
	for ( var i = 0; i < object_value.length; i++ ){
		if ( number_format.indexOf(object_value.charAt(i)) == -1 ){
			return false;
		}
	}
	return true;
}//EW_checkonlynumbers
function EW_checkinteger(object_value) {
	if ( object_value.length == 0 ){
		return true;
	}
	var start_format = "+-0123456789";
	var number_format = "0123456789";
	if ( start_format.indexOf(object_value.charAt(0)) == -1 ){
		return false
	}
	for ( var i = 1; i < object_value.length; i++ ){
		if ( number_format.indexOf(object_value.charAt(i)) == -1 ){
			return false;
		}
	}
	return true;
}//EW_checkinteger
function EW_numberrange(object_value, min_value, max_value) {
	if (min_value != null) {
		if (object_value < min_value)
			return false;
	}
	if (max_value != null) {
		if (object_value > max_value)
			return false;
	}
	return true;
}//EW_numberrange
function EW_checknumber(object_value) {
	if (object_value.length == 0)
		return true;
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	check_char = start_format.indexOf(object_value.charAt(0));
	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;
	for (var i = 1; i < object_value.length; i++)	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0) {
			return false;
		} else if (check_char == 1)	{
			if (decimal)
				return false;
			else
				decimal = true;
		} else if (check_char == 0) {
			if (decimal || digits)	
			trailing_blank = true;
		}	else if (trailing_blank) { 
			return false;
		} else {
			digits = true;
		}
	}	
	return true;
}//EW_checknumber
function EW_checkpositivenumber(object_value) {
	if (object_value.length == 0)
		return true;
	var start_format = " .+0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	check_char = start_format.indexOf(object_value.charAt(0));
	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;
	for (var i = 1; i < object_value.length; i++)	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0) {
			return false;
		} else if (check_char == 1)	{
			if (decimal)
				return false;
			else
				decimal = true;
		} else if (check_char == 0) {
			if (decimal || digits)	
			trailing_blank = true;
		}	else if (trailing_blank) { 
			return false;
		} else {
			digits = true;
		}
	}	
	return true;
}//EW_checknumber
function EW_checkrange(object_value, min_value, max_value) {
	if (object_value.length == 0)
		return true;
	if (!EW_checknumber(object_value))
		return false;
	else
		return (EW_numberrange((parseFloat(object_value)), min_value, max_value));	
	return true;
}//EW_checkrange
function EW_checkTime(object_value) {
	if (object_value.length == 0)
		return true;
	isplit = object_value.indexOf(':');	//getting the first : (between hour and minute)
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sHour = object_value.substring(0, isplit);	//getting the hour (from the beginnig till the first :)
	iminute = object_value.indexOf(':', isplit + 1);	//getting the second : (between minute and second)
	if (iminute == -1 || iminute == object_value.length)
		sMin = object_value.substring((sHour.length + 1));	//the second : was not found
	else
		sMin = object_value.substring((sHour.length + 1), iminute);	//the second : was found
	if ( sHour.length > 2 )
		return false;
	if (!EW_checkinteger(sHour))
		return false;
	else if (!EW_checkrange(sHour, 0, 23)) 
		return false;
	if ( sMin.length > 2 )
		return false;
	if (!EW_checkinteger(sMin))
		return false;
	else if (!EW_checkrange(sMin, 0, 59))
		return false;
	if (iminute != -1) {
		sSec = object_value.substring(iminute + 1);
		if ( sSec.length > 2 )
			return false;
		if (!EW_checkinteger(sSec))
			return false;
		else if (!EW_checkrange(sSec, 0, 59))
			return false;	
	}
	return true;
}//EW_checkTime
function EW_checkAMPMTime(object_value) {
	var objValLength = object_value.length;
	if (objValLength == 0)
		return true;
	var val = object_value.toLowerCase();
	if ( (val.indexOf( ' am' ) == objValLength - 3) || (val.indexOf( ' pm' ) == objValLength - 3) ){
		val = val.substr( 0, objValLength - 3 );	//if ' am' or ' pm' were found at the end, they are removed, only the time will remain
	}else if ( (val.indexOf( 'am' ) == objValLength - 2) || (val.indexOf( 'pm' ) == objValLength - 2) ){
		val = val.substr( 0, objValLength - 2 );	//if 'am' or 'pm' were found at the end, they are removed, only the time will remain
	}
	isplit = val.indexOf(':');	//getting the first : (between hour and minute)
	if (isplit == -1 || isplit == val.length)
		return false;
	sHour = val.substring(0, isplit);	//getting the hour (from the beginnig till the first :)
	iminute = val.indexOf(':', isplit + 1);	//getting the second : (between minute and second)
	if (iminute == -1 || iminute == val.length)
		sMin = val.substring((sHour.length + 1));	//the second : was not found
	else
		sMin = val.substring((sHour.length + 1), iminute);	//the second : was found
	if ( sHour.length > 2 )
		return false;
	if (!EW_checkinteger(sHour))
		return false;
	else if (!EW_checkrange(sHour, 1, 12)) 
		return false;
	if ( sMin.length > 2 )
		return false;
	if (!EW_checkinteger(sMin))
		return false;
	else if (!EW_checkrange(sMin, 0, 59))
		return false;
	if (iminute != -1) {
		sSec = val.substring(iminute + 1);
		if ( sSec.length > 2 )
			return false;
		if (!EW_checkinteger(sSec))
			return false;
		else if (!EW_checkrange(sSec, 0, 59))
			return false;	
	}
	return true;
}//EW_checkAMPMTime
function EW_checkSecondlessTime(object_value) {
	if (object_value.length == 0)
		return true;
	isplit = object_value.indexOf(':');	//getting the first : (between hour and minute)
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sHour = object_value.substring(0, isplit);	//getting the hour (from the beginnig till the first :)
	sMin = object_value.substring((sHour.length + 1));	//the second : was not found
	if ( sHour.length > 2 )
		return false;
	if (!EW_checkinteger(sHour))
		return false;
	else if (!EW_checkrange(sHour, 0, 23)) 
		return false;
	if ( sMin.length > 2 )
		return false;
	if (!EW_checkinteger(sMin))
		return false;
	else if (!EW_checkrange(sMin, 0, 59))
		return false;
	return true;
}//EW_checkSecondlessTime
function EW_checkSecondlessAMPMTime(object_value) {
	var objValLength = object_value.length;
	if (objValLength == 0)
		return true;
	var val = object_value.toLowerCase();
	if ( (val.indexOf( ' am' ) == objValLength - 3) || (val.indexOf( ' pm' ) == objValLength - 3) ){
		val = val.substr( 0, objValLength - 3 );	//if ' am' or ' pm' were found at the end, they are removed, only the time will remain
	}else if ( (val.indexOf( 'am' ) == objValLength - 2) || (val.indexOf( 'pm' ) == objValLength - 2) ){
		val = val.substr( 0, objValLength - 2 );	//if 'am' or 'pm' were found at the end, they are removed, only the time will remain
	}
	isplit = val.indexOf(':');	//getting the first : (between hour and minute)
	if (isplit == -1 || isplit == val.length)
		return false;
	sHour = val.substring(0, isplit);	//getting the hour (from the beginnig till the first :)
	sMin = val.substring((sHour.length + 1));	//the second : was not found
	if ( sHour.length > 2 )
		return false;
	if (!EW_checkinteger(sHour))
		return false;
	else if (!EW_checkrange(sHour, 1, 12)) 
		return false;
	if ( sMin.length > 2 )
		return false;
	if (!EW_checkinteger(sMin))
		return false;
	else if (!EW_checkrange(sMin, 0, 59))
		return false;
	return true;
}//EW_checkSecondlessAMPMTime
function EW_checkSecondTime(object_value) {
	if (object_value.length == 0)
		return true;
	isplit = object_value.indexOf(':');	//getting the first : (between hour and minute)
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sHour = object_value.substring(0, isplit);	//getting the hour (from the beginnig till the first :)
	iminute = object_value.indexOf(':', isplit + 1);	//getting the second : (between minute and second)
	if (iminute == -1 || iminute == object_value.length)
		return false;	//the second : was not found
	else
		sMin = object_value.substring((sHour.length + 1), iminute);	//the second : was found
	if ( sHour.length > 2 )
		return false;
	if (!EW_checkinteger(sHour))
		return false;
	else if (!EW_checkrange(sHour, 0, 23)) 
		return false;
	if ( sMin.length > 2 )
		return false;
	if (!EW_checkinteger(sMin))
		return false;
	else if (!EW_checkrange(sMin, 0, 59))
		return false;
	sSec = object_value.substring(iminute + 1);
	if ( sSec.length > 2 )
		return false;
	if (!EW_checkinteger(sSec))
		return false;
	else if (!EW_checkrange(sSec, 0, 59))
		return false;	
	return true;
}//EW_checkSecondTime
function EW_checkSecondAMPMTime(object_value) {
	var objValLength = object_value.length;
	if (objValLength == 0)
		return true;
	var val = object_value.toLowerCase();
	if ( (val.indexOf( ' am' ) == objValLength - 3) || (val.indexOf( ' pm' ) == objValLength - 3) ){
		val = val.substr( 0, objValLength - 3 );	//if ' am' or ' pm' were found at the end, they are removed, only the time will remain
	}else if ( (val.indexOf( 'am' ) == objValLength - 2) || (val.indexOf( 'pm' ) == objValLength - 2) ){
		val = val.substr( 0, objValLength - 2 );	//if 'am' or 'pm' were found at the end, they are removed, only the time will remain
	}
	isplit = val.indexOf(':');	//getting the first : (between hour and minute)
	if (isplit == -1 || isplit == val.length)
		return false;
	sHour = val.substring(0, isplit);	//getting the hour (from the beginnig till the first :)
	iminute = val.indexOf(':', isplit + 1);	//getting the second : (between minute and second)
	if (iminute == -1 || iminute == val.length)
		return false;	//the second : was not found
	else
		sMin = val.substring((sHour.length + 1), iminute);	//the second : was found
	if ( sHour.length > 2 )
		return false;
	if (!EW_checkinteger(sHour))
		return false;
	else if (!EW_checkrange(sHour, 1, 12)) 
		return false;
	if ( sMin.length > 2 )
		return false;
	if (!EW_checkinteger(sMin))
		return false;
	else if (!EW_checkrange(sMin, 0, 59))
		return false;
	sSec = val.substring(iminute + 1);
	if ( sSec.length > 2 )
		return false;
	if (!EW_checkinteger(sSec))
		return false;
	else if (!EW_checkrange(sSec, 0, 59))
		return false;
	return true;
}//EW_checksecondAMPMTime
/*
function EW_checkphone(object_value) {
	if (object_value.length == 0)
		return true;
	
	if (object_value.length != 12)
		return false;
	
	if (!EW_checknumber(object_value.substring(0,3)))
		return false;
	else if (!EW_numberrange((eval(object_value.substring(0,3))), 100, 1000))
		return false;
	
	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
		return false
	if (!EW_checknumber(object_value.substring(4,7)))
		return false;
	else if (!EW_numberrange((eval(object_value.substring(4,7))), 100, 1000))
		return false;
	if (object_value.charAt(7) != "-" && object_value.charAt(7) != " ")
		return false;
	if (object_value.charAt(8) == "-" || object_value.charAt(8) == "+")
		return false;
	else
		return (EW_checkinteger(object_value.substring(8,12)));
}
*/
/*
function EW_checkzip(object_value) {
	if (object_value.length == 0)
		return true;
	if (object_value.length != 5 && object_value.length != 10)
		return false;
	if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+")
		return false;
	if (!EW_checkinteger(object_value.substring(0,5)))
		return false;
	if (object_value.length == 5)
		return true;
	if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
		return false;
	if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+")
		return false;
	return (EW_checkinteger(object_value.substring(6,10)));
}
*/
function EW_checkcreditcard(object_value) {
	var white_space = " -";
	var creditcard_string = "";
	var check_char;
	if (object_value.length == 0)
		return true;
	for (var i = 0; i < object_value.length; i++) {
		check_char = white_space.indexOf(object_value.charAt(i));
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}	
	if (creditcard_string.length == 0)
		return false;	 
	if (creditcard_string.charAt(0) == "+")
		return false;
	if (!EW_checkinteger(creditcard_string))
		return false;
	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;
	for (var i = 0; i < creditcard_string.length; i++) {
		tempdigit = eval(creditcard_string.charAt(i));		
		if (doubledigit) {
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);			
			if ((tempdigit / 10) >= 1.0)
				checkdigit++;			
			doubledigit = false;
		}	else {
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}
	return (checkdigit % 10) == 0 ? true : false;
}//EW_checkcreditcard
function EW_checkemail(object_value) {
	if (object_value.length == 0)
		return true;
	var atIndex = object_value.indexOf("@");
	if ( ! ( atIndex > 0 ) )
		return false;
	var dotIndex = object_value.lastIndexOf(".");
	if ( ! ( dotIndex > ( atIndex + 1 ) ) )
		return false;
	if ( ! ( ( object_value.length - 1 ) > dotIndex ) )
		return false;
	return true;
}
function EW_checkemaillist(object_value) {
	if (object_value.length == 0)
		return true;
	var emails = object_value.split(",");
	var i;
	for ( i = 0; i < emails.length; i++){
	    if (!EW_checkemail(emails[i])) return false;    //one email is not correct
	}
	return true;
}
function EW_updatecombo(obj, object_value_array, filter_value) {	
	for (var i = obj.length-1; i > 0; i--) {
		obj.options[i] = null;
	}	
	for (var j=0; j<object_value_array.length; j=j+4) {
		if (object_value_array[j+3].toUpperCase() == filter_value.toUpperCase()) {
			EW_newopt(obj, object_value_array[j], object_value_array[j+1], object_value_array[j+2]);			
		}	
	}
}//EW_updatecombo
function EW_newopt(obj, value, text1, text2) {
	var text = text1;
	if (text2 != "")
		text += ", " + text2;
	var optionName = new Option(text, value, false, false)
	var length = obj.length;
	obj.options[length] = optionName;
}//EW_newopt
function EW_selectopt(obj, value) {
	for (var i = obj.length-1; i>=0; i--) {
		if (obj.options[i].value.toUpperCase() == value.toUpperCase()) {
			obj.selectedIndex = i;
			break;
		}
	}
}//EW_selectopt
function EW_getimagesize(file_object, width_object, height_object) {
	if (navigator.appVersion.indexOf("MSIE") != -1)	{
		myimage = new Image();
		myimage.onload = function () {
			width_object.value = myimage.width; height_object.value = myimage.height;
		}		
		myimage.src = file_object.value;
	}
}//EW_getimagesize
function EW_checkPhone(object_value){
	var _pattern = /(\d{3}\d{3}\d{4})|(\d{3}-\d{3}-\d{4})|(\(\d{3}\)\d{3}\d{4})|(\(\d{3}\)\d{3}-\d{4})/;
	if(object_value.search(_pattern))
	{return false;}
	else
	{return true;}
}
function EW_checkPhoneFormat( object_value ){
    if ( object_value.length != 0)
    {
        if ( EW_checkPhone( object_value ) )
        { return true; }
        else
        { return false; }
    }
    else
    {return true;}
}
function EW_checkTitle(object_value){
	var _pattern = /\W/;
	var rez = _pattern.test(object_value);
	return !rez;
}
function EW_checkTitleFormat( object_value ){
    if ( object_value.length != 0){
        if ( EW_checkTitle( object_value ) )
        { return true; }
        else
        { return false; }
    }
    else
    {return true;}
}
function EW_checkTitle1(object_value){
	var _pattern = /[^a-zA-Z0-9 -]/;
	var rez = _pattern.test(object_value);
	return !rez;
}
function EW_checkTitle1Format( object_value ){
    if ( object_value.length != 0){
        if ( EW_checkTitle1( object_value ) )
        { return true; }
        else
        { return false; }
    }
    else
    {return true;}
}
function EW_checkZipFormat( object_value ){
    if ( object_value.length > 0 ){
        var _pattern = /^\d{5}([\-]\d{4})?$/;
	    if(object_value.search(_pattern)>=0)
	        return true;
        else
            return false;
    }
    else
        return true;
}
function EW_checkgreather(obj, obj_type, compVal) {
	if (obj_type == "TEXT" || obj_type == "TEXTAREA")	{
		if (obj.value <= compVal) 
			return false;
		else 
			return true;
	} else if (obj_type == "SELECT") {
		if (obj.type != "select-multiple" && obj.value <= compVal )
			return false;
		else
			return true;
	} else if (obj_type == "SPAN"){
		if (obj.innerHTML.length <= compVal)
		    return false;
		 else return true;
	}
}//EW_checkgreather
function EW_checkless(obj, obj_type, compVal) {
	if (obj_type == "TEXT" || obj_type == "TEXTAREA")	{
		if (obj.value >= compVal) 
			return false;
		else 
			return true;
	} else if (obj_type == "SELECT") {
		if (obj.type != "select-multiple" && obj.value >= compVal )
			return false;
		else
			return true;
	} else if (obj_type == "SPAN"){
		if (obj.innerHTML.length >= compVal)
		    return false;
		 else return true;
	}
}//EW_checkless
function EW_checkequal(obj, obj_type, compVal) {
	if (obj_type == "TEXT" || obj_type == "TEXTAREA")	{
		if (obj.value != compVal) 
			return false;
		else 
			return true;
	} else if (obj_type == "SELECT") {
		if (obj.type != "select-multiple" && obj.value != compVal )
			return false;
		else
			return true;
	} else if (obj_type == "SPAN"){
		if (obj.innerHTML.length != compVal)
		    return false;
		 else return true;
	}
}//EW_checkequal
function EW_checkgreatherorequal(obj, obj_type, compVal) {
	if (obj_type == "TEXT" || obj_type == "TEXTAREA")	{
		if (obj.value < compVal) 
			return false;
		else 
			return true;
	} else if (obj_type == "SELECT") {
		if (obj.type != "select-multiple" && obj.value < compVal )
			return false;
		else
			return true;
	} else if (obj_type == "SPAN"){
		if (obj.innerHTML.length < compVal)
		    return false;
		 else return true;
	}
}//EW_checkgreatherorequal
function EW_checklessorequal(obj, obj_type, compVal) {
	if (obj_type == "TEXT" || obj_type == "TEXTAREA")	{
		if (obj.value > compVal) 
			return false;
		else 
			return true;
	} else if (obj_type == "SELECT") {
		if (obj.type != "select-multiple" && obj.value > compVal )
			return false;
		else
			return true;
	} else if (obj_type == "SPAN"){
		if (obj.innerHTML.length > compVal)
		    return false;
		 else return true;
	}
}//EW_checklessorequal
function EW_checkmaxsentences(object_value, maxNumber) {
	if (object_value.length == 0)
		return true;
	var sentence_separator = ".!?";
	var lastChar = object_value.charAt(object_value.length - 1);
	if (sentence_separator.indexOf(lastChar) < 0){
	    object_value += ".";
	}
	var numberOfSentences = 0;
	var check_char;
	var previouslyFound = false;
	for (var i = object_value.length - 1; i >= 0; i--)	{
		check_char = sentence_separator.indexOf(object_value.charAt(i))
		if (check_char >= 0) {
			if (!previouslyFound){
			    numberOfSentences++;
			    if (numberOfSentences>maxNumber){
			        return false;
			    }
			}
			previouslyFound = true;
		}else{
		    previouslyFound = false;
		}
	}	
	return true;
}//EW_checkmaxsentences
function EW_checkmaxwords(object_value, maxNumber) {
	if (object_value.length == 0)
		return true;
	var word_separator = " ";
	var numberOfWords = 0;
	var check_char;
	var previouslyFound = false;
	for (var i = 0; i < object_value.length; i++)	{
		check_char = word_separator.indexOf(object_value.charAt(i))
		if (check_char >= 0) {
			if (!previouslyFound){
			    numberOfWords++;
			    if (numberOfWords>=maxNumber){
			        return false;
			    }
			}
			previouslyFound = true;
		}else{
		    previouslyFound = false;
		}
	}	
	return true;
}//EW_checkmaxwords
