
CForm = function(){};
CForm.prototype = {
	init: function(Obj){
		this.returnOk = 'ok';
		this.errorClass = 'err';
		this.formId = Obj.formId;
		this.form = this.getForm();
		this.VElements = Obj.elements?Obj.elements : [];
		this.VType = Obj.vtype?Obj.vtype : {};
		return false;
	},
	getForm: function()
	{
		return document.getElementById(this.formId);
	},
	el: function(id){
		el = eval('this.form.' + id);
		if (el)
		return el;
		return null;
	},
	getLength: function(formElement){
		el = new String(formElement.value);
		return el.length;
	},
	showErr: function(Error)
	{
		classEl = new String(Error.VErrEl.className);
		if (-1 == classEl.indexOf(this.errorClass))
		{
			Error.VErrEl.className = Error.VErrEl.className?Error.VErrEl.className + ' ' + this.errorClass:this.errorClass;
		}
		Error.VErrEl.title = Error.VErrText;
	},
	hideErr: function(el)
	{
		classEl = new String(el.className);
		if (-1 < classEl.indexOf(this.errorClass))
		{
			el.className = classEl.replace(/err/,'');
		}
		el.title = '';
	},

	submit: function(){
		var isntvalidate = false;
		for (i=0;i<this.VElements.length;i++)
		{
			var validateResult = this.validate(this.VElements[i]);
			if (this.returnOk != validateResult)
			{
				isntvalidate = true;
			}
		}
		if (isntvalidate)
		return false;
		this.form.submit();
		return true;
	},
	load: function(){},
	validate: function (id)
	{
		var opt = eval('this.VType.' + id);
		if (!id)	return this.returnOk;
		if (!opt)	return this.returnOk;
		var el = this.el(id);
		if (!el)	return this.returnOk;
		opt.type = opt.type?opt.type:'text';

		if ('text' == opt.type)
		{
			opt.maxLength = opt.maxLength?opt.maxLength:255;
			opt.minLength = opt.minLength?opt.minLength:0;
			if (this.getLength(el) > opt.maxLength || this.getLength(el) < opt.minLength)
			{
				this.showErr({VErrEl:el,VErrText:'MinMaxErr'});
				return {VErrEl:el,VErrText:'MinMaxErr'};
			}
		}
		this.hideErr(el);
		return this.returnOk;

	}

}




