var dxFormComponents = new Array();

function dxFormAddComponent( oComponent )
{
	dxFormComponents[ dxFormComponents.length ] = oComponent;
	return oComponent;
}

function dxFormValidate()
{
	var totalInfo = new DXFormatValidationInfo( true );
	for( var ff=0; ff<dxFormComponents.length; ff++ )
	{
		var component = dxFormComponents[ff];
		var info = component.Validate();
		if( !info.Success )
		{
			totalInfo.Success = false;
			totalInfo.AddMessage( component.NameInForm + ": " + info.Message );
		}
	}
	if( !totalInfo.Success )
		alert( totalInfo.Message );
		
	return totalInfo.Success;
}

function DXFormComponent( id )
{
	this.Id = id;
	this.Format = null;

	this.ClientId = null;
}

DXFormComponent.prototype.GetValue = function()
{
	if( this.ClientId )
		return document.getElementById( this.ClientId ).value;
	else
		return "";
}

DXFormComponent.prototype.AddFormat = function( format )
{
	this.Format = format;
	return format;
}

DXFormComponent.prototype.Validate = function()
{
	if( this.Format )
		return this.Format.Validate( this.GetValue() );
	else
		return new DXFormatValidationInfo( true );
}

function DXFormatValidationInfo( success, message )
{
	this.Success = success;
	this.Message = message ? message : "";
}

DXFormatValidationInfo.prototype.AddMessage = function( message )
{
	if( this.Message && this.Message != "" )
		this.Message += "\n";
	this.Message += message;
}



function DXFormat( id )
{
	this.Id = id;
}

DXFormat.prototype.Validate = function( value )
{
	return new DXFormatValidationInfo( true );
}

DXFormat.prototype.GetErrorMessage = function(svText, enText) {
    if (this.ErrorMessage)
        return this.ErrorMessage;
    else
        return dxLocalizedString.GetText(svText, enText);
}

