
var ZForms={

	EVENT_TYPE_ON_INIT:'oninit',

	EVENT_TYPE_ON_CHANGE:'onchange',

	EVENT_TYPE_ON_BEFORE_SUBMIT:'onbeforesubmit',

	createWidget:function(){return new arguments[0](arguments[1][0],arguments[1][1],arguments[1][2])},

	createTextInput:function(){return this.createWidget(ZForms.Widget.Text,arguments)},

	createNumberInput:function(){return this.createWidget(ZForms.Widget.Text.Number,arguments)},

	createSelectInput:function(){return this.createWidget(ZForms.Widget.Select,arguments)},

	createComboInput:function(){return this.createWidget(ZForms.Widget.Text.Combo,arguments)},

	createContainer:function(){return this.createWidget(ZForms.Widget.Container,arguments)},

	createDateInput:function(){return this.createWidget(ZForms.Widget.Container.Date,arguments)},

	createInputGroup:function(){var a=this.createWidget(arguments[0],arguments[1]);if(arguments[1][3]){for(var i=0;i<arguments[1][3].length;i++){a.addChild(this.createStateInput(arguments[1][3][i][0],arguments[1][3][i][1],arguments[1][2]))}}return a},

	createStateInput:function(){return this.createWidget(ZForms.Widget.Text.State,arguments)},

	createCheckBoxGroup:function(){return this.createInputGroup(ZForms.Widget.Container.Group.CheckBox,arguments)},

	createRadioButtonGroup:function(){return this.createInputGroup(ZForms.Widget.Container.Group.RadioButton,arguments)},

	createSlider:function(){return this.createWidget(ZForms.Widget.Container.Slider,arguments)},

	createSliderVertical:function(){return this.createWidget(ZForms.Widget.Container.Slider.Vertical,arguments)},

	createButton:function(){return this.createWidget(ZForms.Widget.Button,arguments)},

	createSubmitButton:function(){return this.createWidget(ZForms.Widget.Button.Submit,arguments)},

	createSheet:function(){return this.createWidget(ZForms.Widget.Container.Sheet,arguments)},

	createSheetContainer:function(){return this.createWidget(ZForms.Widget.Container.SheetContainer,arguments)},

	createMultiplicator:function(){return this.createWidget(ZForms.Widget.Container.Multiplicator,arguments)},

	createForm:function(){return this.createWidget(ZForms.Widget.Container.Form,arguments)},

	createEnableDependence:function(a,b,c,d){return new this.Dependence(this.Dependence.TYPE_ENABLE,a,b,c,d)},

	createRequiredDependence:function(a,b,c){return new this.Dependence.Required(a,c?new RegExp('\\S{'+c+',}'):/\S+/,b,false,c)},

	createValidDependence:function(a,b,c,d){return new this.Dependence.Valid(a,b,c,d)},

	createValidEmailDependence:function(a){return this.createValidDependence(a,/^[a-zA-Z0-9][a-zA-Z0-9\.\-\_\~]*\@[a-zA-Z0-9\.\-\_]+\.[a-zA-Z]{2,4}$/)},

	createOptionsDependence:function(a,b,c){return new this.Dependence.Options(this.Dependence.TYPE_OPTIONS,a,b,c)},

	createClassDependence:function(a,b,c){return new this.Dependence.Class(a,b,c)},

	createFunctionDependence:function(a,b,c,d,e){return new this.Dependence.Function(a,b,c,d,e)},

	createCompareDependence:function(a,b,c,d,e,f){var g=function(){return(arguments.callee.sType==ZForms.Dependence.TYPE_VALID&&(arguments.callee.oWidget.getValue().isEmpty()||(arguments.callee.mArgument instanceof ZForms.Widget&&arguments.callee.mArgument.getValue().isEmpty())))||arguments.callee.oWidget.getValue()[arguments.callee.sFunctionName](arguments.callee.mArgument instanceof ZForms.Widget?arguments.callee.mArgument.getValue():arguments.callee.mArgument)},mResult=new this.Dependence.Function(a,b,g,e,f);g.sType=a;g.oWidget=b;g.mArgument=d;g.sFunctionName=this.Dependence.COMPARE_FUNCTIONS[c||'='];if(!(d instanceof ZForms.Widget)){return mResult}return[mResult,new this.Dependence.Function(a,d,g,e,f)]},

	createValidCompareDependence:function(a,b,c,d,e){return this.createCompareDependence(this.Dependence.TYPE_VALID,a,b,c,d,e)},

	createEnableCompareDependence:function(a,b,c,d,e){return this.createCompareDependence(this.Dependence.TYPE_ENABLE,a,b,c,d,e)},

	createBuilder:function(a){return new this.Builder(a)},

	aForms:[],

	getFormById:function(a){return this.aForms[a]}
};

ZForms.Value=Abstract.inheritTo({
	__constructor:function(a){this.mValue=null;this.reset();if(a!=null){this.set(a)}},

	reset:function(){this.set('')},

	get:function(){return this.mValue},

	set:function(a){this.mValue=typeof(a)=='string'?a:a.toString()},

	match:function(a){return a.test(this.get())},

	clone:function(){var a=new this.__self();a.set(this.get());return a},

	isEqual:function(a){if(!this.checkForCompareTypes(a)){return false}var b=(a instanceof this.__self)?a:new this.__self(a);return this.mValue===b.mValue},

	isGreater:function(a){if(!this.checkForCompareTypes(a)){return false}var b=(a instanceof this.__self)?a:new this.__self(a);return this.get().length>b.get().length},

	isGreaterOrEqual:function(a){return this.isGreater(a)||this.isEqual(a)},

	isLess:function(a){return this.checkForCompareTypes(a)&&!this.isGreaterOrEqual(a)},

	isLessOrEqual:function(a){return this.checkForCompareTypes(a)&&!this.isGreater(a)},

	checkForCompareTypes:function(a){return a instanceof this.__self||typeof(a)=='string'},

	isEmpty:function(){return this.mValue===''},

	toStr:function(){return this.get().toString()}
});

ZForms.Value.Number=ZForms.Value.inheritTo({
	set:function(a){this.mValue=parseFloat(a.toString().replace(/[^0-9\.\,\-]/g,'').replace(/\,/g,'.'))},

	match:function(a){return!isNaN(this.mValue)&&a.test(this.mValue.toString())},

	isEmpty:function(){return isNaN(this.mValue)},

	isEqual:function(a){if(!this.checkForCompareTypes(a)){return false}var b=(a instanceof this.__self)?a:new this.__self((a instanceof ZForms.Value)?a.get():a);return this.get()===b.get()},

	isGreater:function(a){if(!this.checkForCompareTypes(a)){return false}var b=(a instanceof this.__self)?a:new this.__self((a instanceof ZForms.Value)?a.get():a);return this.get()>b.get()},

	checkForCompareTypes:function(a){return a instanceof this.__self||(a instanceof ZForms.Value&&!isNaN(parseFloat(a.get())))||typeof(a)=='number'||(typeof(a)=='string'&&!isNaN(parseFloat(a.toString())))},

	toStr:function(){return isNaN(this.mValue)?'':this.mValue.toString()}
});

ZForms.Value.Multiple=ZForms.Value.inheritTo({
	reset:function(){this.set([])},

	set:function(a){this.mValue=a instanceof Array?a:[a]},

	match:function(a){if(this.isEmpty()){return a.test('')}for(var i=0;i<this.mValue.length;i++){if(a.test(this.mValue[i])){return true}}return false},

	clone:function(){var a=new this.__self();for(var i=0;i<this.mValue.length;i++){a.add(this.mValue[i])}return a},

	isEqual:function(a){if(!(a instanceof this.__self||a instanceof Array)){return this.mValue.length==1&&this.mValue[0]===(a instanceof ZForms.Value?a.get():a)}var b=a instanceof this.__self?a:new this.__self(a);if(this.mValue.length!=b.mValue.length){return false}for(var i=0;i<this.mValue.length;i++){if(this.mValue[i]!=b.mValue[i]){return false}}return true},

	isGreater:function(a){if(!(a instanceof this.__self||a instanceof Array)){return false}return this.get().length>(a instanceof this.__self?a:new this.__self(a)).get().length},

	checkForCompareTypes:function(a){return a instanceof this.__self||a instanceof Array},

	isEmpty:function(){return this.mValue.length==0},

	add:function(a){if(this.mValue.contains(a)){return}this.mValue.push(a)},

	remove:function(a){this.mValue.remove(a)}
});

ZForms.Value.Date=ZForms.Value.inheritTo({
	reset:function(){this.mValue=[];this.mValue[this.__self.PART_YEAR]='';this.mValue[this.__self.PART_MONTH]='';this.mValue[this.__self.PART_DAY]=''},

	get:function(){if(this.isEmpty()){return''}return this.getYear()+'-'+this.getMonth()+'-'+this.getDay()},

	set:function(a){var b=null;if(a instanceof Date){b=a}else{var c=a.match(/^(-?\d{1,4})-(\d{1,2})-(-?\d{1,2})/);if(c){b=new Date(parseInt(c[1],10),parseInt(c[2],10)-1,parseInt(c[3],10))}}if(b){this.mValue[this.__self.PART_YEAR]=b.getFullYear();this.mValue[this.__self.PART_MONTH]=b.getMonth()+1;this.mValue[this.__self.PART_DAY]=b.getDate()}else{this.reset()}},

	isEqual:function(a){if(a instanceof this.__self.Time){return this.get()+' 0:0:0'==a.get()}if(a instanceof this.__self){return this.get()==a.get()}if(a instanceof ZForms.Value){return this.get()==a.get()}if(a instanceof Date){return this.get()==new this.__self(a).get()}return this.get()===a},

	isGreater:function(a){var b=(a instanceof ZForms.Value.Date)?a:new ZForms.Value.Date((a instanceof ZForms.Value)?a.get():a);if(this.isEmpty()||b.isEmpty()){return false}if(this.getYear()>b.getYear()){return true}if(this.getYear()==b.getYear()){if(this.getMonth()>b.getMonth()){return true}return this.getMonth()==b.getMonth()&&this.getDay()>b.getDay()}return false},

	checkForCompareTypes:function(a){if(a instanceof this.__self||a instanceof this.__self.Time){return!a.isEmpty()}if(a instanceof ZForms.Value){return!(new ZForms.Value.Date(a.get()).isEmpty())}if(typeof(a)=='string'){return!(new ZForms.Value.Date(a).isEmpty())}return a instanceof Date},

	isEmpty:function(){return!this.mValue||this.mValue[this.__self.PART_YEAR]==''||this.mValue[this.__self.PART_MONTH]==''||this.mValue[this.__self.PART_DAY]==''},

	getYear:function(){return this.mValue[this.__self.PART_YEAR]},

	getMonth:function(){return this.mValue[this.__self.PART_MONTH]},

	getDay:function(){return this.mValue[this.__self.PART_DAY]},

	toStr:function(){if(this.isEmpty()){return''}return this.getYear()+'-'+(this.getMonth()<10?'0':'')+this.getMonth()+'-'+(this.getDay()<10?'0':'')+this.getDay()}},{PART_YEAR:'year',PART_MONTH:'month',PART_DAY:'day'
});

ZForms.Value.Date.Time=ZForms.Value.Date.inheritTo({
	reset:function(){this.__base();this.mValue[this.__self.PART_HOUR]='';this.mValue[this.__self.PART_MINUTE]='';this.mValue[this.__self.PART_SECOND]=''},

	get:function(){if(this.isEmpty()){return''}return this.__base()+' '+this.getHour()+':'+this.getMinute()+':'+this.getSecond()},

	set:function(a){var b=null;if(a instanceof Date){b=a}else{var c=a.match(/^(-?\d{1,4})-(\d{1,2})-(-?\d{1,2})( (-?\d{1,2}):(-?\d{1,2}):(-?\d{1,2}))?/);if(c){b=new Date(parseInt(c[1],10),parseInt(c[2],10)-1,parseInt(c[3],10),c[5]?parseInt(c[5],10):0,c[6]?parseInt(c[6],10):0,c[7]?parseInt(c[7],10):0)}}if(b){this.mValue[this.__self.PART_YEAR]=b.getFullYear();this.mValue[this.__self.PART_MONTH]=b.getMonth()+1;this.mValue[this.__self.PART_DAY]=b.getDate();this.mValue[this.__self.PART_HOUR]=b.getHours();this.mValue[this.__self.PART_MINUTE]=b.getMinutes();this.mValue[this.__self.PART_SECOND]=b.getSeconds()}else{this.reset()}},

	isEqual:function(a){if(a instanceof this.__self){return this.get()==a.get()}if(a instanceof ZForms.Value.Date){return this.get()==a.get()+' 0:0:0'}if(a instanceof ZForms.Value||typeof(a)=='string'){return this.isEqual(new this.__self(typeof(a)=='string'?a:a.get()))}if(a instanceof Date){return this.get()==new this.__self(a).get()}return false},

	isGreater:function(a){if(this.__base(a)){return true}var b=(a instanceof this.__self)?a:new this.__self((a instanceof ZForms.Value.Date?a.get()+' 0:0:0':(a instanceof ZForms.Value?a.get():a)));if(this.getDay()==b.getDay()){if(this.getHour()>b.getHour()){return true}else if(this.getHour()==b.getHour()){if(this.getMinute()>b.getMinute()){return true}else{return this.getMinute()==b.getMinute()&&this.getSecond()>b.getSecond()}}}return false},

	checkForCompareTypes:function(a){if(a instanceof this.__self||a instanceof ZForms.Value.Date){return!a.isEmpty()}if(a instanceof ZForms.Value){return!(new ZForms.Value.Date(a.get()).isEmpty())}if(typeof(a)=='string'){return!(new ZForms.Value.Date.Time(a).isEmpty())}return a instanceof Date},

	isEmpty:function(){return this.__base()||this.mValue[this.__self.PART_HOUR]===''||this.mValue[this.__self.PART_MINUTE]===''||this.mValue[this.__self.PART_SECOND]===''},

	getHour:function(){return this.mValue[this.__self.PART_HOUR]},

	getMinute:function(){return this.mValue[this.__self.PART_MINUTE]},

	getSecond:function(){return this.mValue[this.__self.PART_SECOND]},

	toStr:function(){if(this.isEmpty()){return''}return this.__base()+' '+(this.getHour()<10?'0':'')+this.getHour()+':'+(this.getMinute()<10?'0':'')+this.getMinute()+':'+(this.getSecond()<10?'0':'')+this.getSecond()}},{PART_HOUR:'hour',PART_MINUTE:'minute',PART_SECOND:'second'
});

ZForms.Widget=Abstract.inheritTo({
	__constructor:function(a,b,c){this.oElement=a;this.oClassElement=b||a;this.oOptions=c?Common.Object.extend(this.getDefaultOptions(),c,true):this.getDefaultOptions();this.sId=Common.Dom.getAttribute(a,'id')||Common.Dom.getUniqueId(a);this.oDependenceProcessor=new ZForms.DependenceProcessor(this);this.aObservers=[];this.aOuterObservers=[];this.oParent=null;this.oForm=null;this.bEnabled=true;this.bRequired=false;this.bValid=true;this.oMultiplier=null;this.oValue=this.createValue();this.setValueFromElement(true);this.oInitialValue=this.oValue.clone();this.oLastProcessedValue=this.oValue.clone();this.bInitialValueChanged=false;this.addHandlers()},

	getDefaultOptions:function(){return{bTemplate:false}},

	createValue:function(a){return new ZForms.Value(a)},

	addHandlers:function(){if(this.isTemplate()){return}var b=this;function process(a){var a=Common.Event.normalize(a);a.cancelBubble=true;b.processEvents(true)}Common.Event.add(this.oElement,this.getEventList(),process)},

	getEventList:function(){return[]},

	processEvents:function(a,b,c){this.setValueFromElement();if(!(b||this.isChanged())||this.isTemplate()){return}else{this.checkForInitialValueChanged();this.updateLastProcessedValue()}this.notifyObservers();this.notifyOuterObservers(ZForms.EVENT_TYPE_ON_CHANGE);if(!c){if(this.oParent){this.oParent.processEvents(a,true)}else if(a&&this.oForm){this.oForm.updateSubmit()}}},

	isChanged:function(){return!this.oValue.isEqual(this.oLastProcessedValue)},

	updateLastProcessedValue:function(){this.oLastProcessedValue=this.oValue.clone()},

	isInitialValueChanged:function(){return this.bInitialValueChanged},

	checkForInitialValueChanged:function(){if(!this.oForm){return}if(!this.isInitialValueChanged()&&!this.oValue.isEqual(this.oInitialValue)){this.oForm.increaseChangedCounter();this.bInitialValueChanged=true;this.addClass(this.__self.CLASS_NAME_CHANGED)}else if(this.isInitialValueChanged()&&this.oValue.isEqual(this.oInitialValue)){this.oForm.decreaseChangedCounter();this.bInitialValueChanged=false;this.removeClass(this.__self.CLASS_NAME_CHANGED)}},

	init:function(){this.addClass(this.getInitedClassName());if(this.isTemplate()){return}if(this.oElement.disabled){this.disable()}this.processEvents(false,true);this.notifyOuterObservers(ZForms.EVENT_TYPE_ON_INIT)},

	getValue:function(){return this.oValue},

	setValue:function(a){if(!this.hasValue()){return}this.oValue=a;this.processEvents(true)},

	setValueFromElement:function(){},

	hasValue:function(){return true},

	getId:function(){return this.sId},

	setId:function(a){this.sId=a},

	getName:function(){return this.oElement.name},

	isTemplate:function(){return this.oOptions.bTemplate},

	addClass:function(a,b){Common.Class.add(b?b:this.oClassElement,a)},

	removeClass:function(a,b){Common.Class.remove(b?b:this.oClassElement,a)},

	replaceClass:function(a,b,c){Common.Class.replace(c?c:this.oClassElement,a,b)},

	getInitedClassName:function(){return this.__self.CLASS_NAME_INITED},

	disable:function(a){if(!this.isEnabled()){return false}this.bEnabled=false;this.oElement.disabled=true;this.oClassElement.disabled=true;this.addClass(this.__self.CLASS_NAME_DISABLED);if(a){this.processEvents(true,true,true)}if(this.oMultiplier){this.oMultiplier.disableByOuter()}return true},

	enable:function(a){if(!this.allowEnable()){return false}this.bEnabled=true;this.oElement.disabled=false;this.oClassElement.disabled=false;this.removeClass(this.__self.CLASS_NAME_DISABLED);if(a){this.processEvents(true,true,true);this.updateByObservable(true)}if(this.oMultiplier){this.oMultiplier.enableByOuter()}return true},

	allowEnable:function(){return!this.isEnabled()&&!(this.oParent&&!this.oParent.isEnabled())},

	isEnabled:function(){return this.bEnabled},

	setRequired:function(){this.bRequired=true;this.replaceClass(this.__self.CLASS_NAME_REQUIRED_OK,this.__self.CLASS_NAME_REQUIRED)},

	unsetRequired:function(){this.bRequired=false;this.replaceClass(this.__self.CLASS_NAME_REQUIRED,this.__self.CLASS_NAME_REQUIRED_OK)},

	isRequired:function(){return this.bRequired},

	setValid:function(){this.bValid=true;this.removeClass(this.__self.CLASS_NAME_INVALID)},

	setInvalid:function(){this.bValid=false;this.addClass(this.__self.CLASS_NAME_INVALID)},

	isValid:function(){return this.bValid},

	isReadyForSubmit:function(){return!this.isEnabled()||(!this.isRequired()&&(!this.oForm.oOptions.bCheckForValid||this.isValid()))},

	setParent:function(a){this.oParent=a},

	setForm:function(a){if(this.oForm){return}this.oForm=a;a.addWidget(this)},

	hide:function(){this.addClass(this.__self.CLASS_NAME_INVISIBLE)},

	show:function(){this.removeClass(this.__self.CLASS_NAME_INVISIBLE)},

	focus:function(){var a=this.oParent;do{if(a instanceof ZForms.Widget.Container.Sheet){a.oParent.select(a)}a=a.oParent}while(a);try{this.oElement.focus()}catch(oException){}},

	attachObserver:function(a){this.aObservers.push(a)},

	detachObserver:function(a){this.aObservers.remove(a)},

	detachObservers:function(){for(var i=0,aDependencies,oObserver;i<this.aObservers.length;){if(this.aObservers[i]==this){i++;continue}oObserver=this.aObservers[i];aDependencies=this.aObservers[i].getDependencies();for(var j=0;j<aDependencies.length;j++){if(aDependencies[j].getFrom()==this){this.aObservers[i].removeDependence(aDependencies[j])}}this.detachObserver(oObserver);if(oObserver.oParent){oObserver.updateByObservable()}}},

	notifyObservers:function(){for(var i=0;i<this.aObservers.length;i++){this.aObservers[i].updateByObservable()}},

	updateByObservable:function(a){this.oDependenceProcessor.process();if(!a&&this.oParent){this.oParent.oDependenceProcessor.process()}},

	addDependence:function(a){if(a instanceof Array){for(var i=0;i<a.length;i++){this.addDependence(a[i])}return}a.getFrom().attachObserver(this);this.oDependenceProcessor.addDependence(a)},

	removeDependence:function(a){this.oDependenceProcessor.removeDependence(a)},

	getDependencies:function(){return this.oDependenceProcessor.getDependencies()},

	getMultiplier:function(){return this.oMultiplier},

	setMultiplier:function(a){this.oMultiplier=a},

	updateElements:function(a){this.oElement=document.getElementById(a>0?this.oElement.id.match(ZForms.Widget.Container.Multiplicator.REG_EXP_REPLACE)[1]+'_'+a:this.oElement.id);this.oClassElement=document.getElementById(a>0?this.oClassElement.id.match(ZForms.Widget.Container.Multiplicator.REG_EXP_REPLACE)[1]+'_'+a:this.oClassElement.id);this.updateId(this.oElement.id);if(this.oElement.attachEvent){this.addHandlers();this.addExtendedHandlers()}},

	updateId:function(a){this.oForm.removeWidget(this);this.setId(a);this.oForm.addWidget(this)},

	addChild:function(a){return a},

	getCountChildrenByPattern:function(){return 0},

	destruct:function(){this.oElement=null;this.oClassElement=null;if(this.oMultiplier){this.oMultiplier.destruct()}},

	afterClone:function(){this.processEvents(true,true)},

	prepareForSubmit:function(){},

	addExtendedHandlers:function(){},

	removeChild:function(a){},

	removeChildren:function(a){},

	enableOptionsByValue:function(a,b){},

	attachOuterObserver:function(a,b,c){if(a instanceof Array){for(var i=0;i<a.length;i++){this.attachOuterObserver(a[i],b,c)}return}if(b instanceof Array){for(var i=0;i<b.length;i++){this.attachOuterObserver(a,b[i],c)}return}if(!this.aOuterObservers[a]){this.aOuterObservers[a]=[]}this.aOuterObservers[a].push(b);if(c){this.notifyOuterObserver(a,b)}},

	detachOuterObserver:function(a,b){if(a instanceof Array){for(var i=0;i<a.length;i++){this.detachOuterObserver(a[i],b)}return}if(b instanceof Array){for(var i=0;i<b.length;i++){this.detachOuterObserver(a,b[i])}return}if(this.aOuterObservers[a]&&this.aOuterObservers[a].contains(b)){this.aOuterObservers[a].remove(b)}},

	notifyOuterObservers:function(a){if(!this.aOuterObservers[a]){return}for(var i=0;i<this.aOuterObservers[a].length;i++){this.notifyOuterObserver(a,this.aOuterObservers[a][i])}},

	notifyOuterObserver:function(a,b){if(b instanceof Function){b(a,this)}},

	clone:function(a,b,c){var d=Common.Object.extend({bTemplate:false},this.oOptions);return new this.__self(a,b,d)}},{CLASS_NAME_REQUIRED:'required',CLASS_NAME_REQUIRED_OK:'required-ok',CLASS_NAME_INVALID:'invalid',CLASS_NAME_DISABLED:'disabled',CLASS_NAME_INVISIBLE:'invisible',CLASS_NAME_SELECTED:'selected',CLASS_NAME_HIDDEN:'hidden',CLASS_NAME_INITED:'widget-inited',CLASS_NAME_SELECTED_INITIAL:'selected-initial',CLASS_NAME_CHANGED:'changed',KEY_CODE_ARROW_RIGHT:39,KEY_CODE_ARROW_LEFT:37,KEY_CODE_ARROW_UP:38,KEY_CODE_ARROW_DOWN:40,KEY_CODE_PAGE_UP:33,KEY_CODE_PAGE_DOWN:34,KEY_CODE_HOME:36,KEY_CODE_END:35,KEY_CODE_ENTER:13,KEY_CODE_TAB:9,DOM_EVENT_TYPE_KEYUP:'keyup',DOM_EVENT_TYPE_KEYDOWN:'keydown',DOM_EVENT_TYPE_KEYPRESS:'keypress',DOM_EVENT_TYPE_CLICK:'click',DOM_EVENT_TYPE_BLUR:'blur',DOM_EVENT_TYPE_FOCUS:'focus',DOM_EVENT_TYPE_CHANGE:'change',DOM_EVENT_TYPE_MOUSEDOWN:'mousedown',DOM_EVENT_TYPE_MOUSEUP:'mouseup',DOM_EVENT_TYPE_MOUSEMOVE:'mousemove',DOM_EVENT_TYPE_SELECTSTART:'selectstart',DOM_EVENT_TYPE_UNLOAD:'unload',DOM_EVENT_TYPE_BEFOREUNLOAD:'beforeunload',EVENT_TYPE_ON_CHANGE:'onchange'
});

ZForms.Widget.Container=ZForms.Widget.inheritTo({
	__constructor:function(a,b,c){this.aChildren=[];this.__base(a,b,c)},

	addChild:function(a,b){if(b>-1&&b<this.aChildren.length){this.aChildren.splice(b,0,a)}else{this.aChildren.push(a)}a.setParent(this);if(this.oForm){a.setForm(this.oForm)}return a},

	removeChild:function(a){a.detachObservers();a.removeChildren();this.aChildren.remove(a);if(this.oForm){this.oForm.removeWidget(a);if(a.isInitialValueChanged()){this.oForm.decreaseChangedCounter()}}a.setParent(null);a=null},

	removeChildren:function(){while(this.aChildren.length>0){this.removeChild(this.aChildren[0])}},

	getChildren:function(){return this.aChildren},

	setForm:function(a){this.__base(a);for(var i=0,iLength=this.aChildren.length;i<iLength;i++){this.aChildren[i].setForm(a)}},

	disable:function(a){if(!this.__base(a)){return false}for(var i=0,iLength=this.aChildren.length;i<iLength;i++){this.aChildren[i].disable(true)}return true},

	enable:function(a){if(!this.allowEnable()){return false}this.bEnabled=true;for(var i=0,iLength=this.aChildren.length;i<iLength;i++){this.aChildren[i].enable(true);this.aChildren[i].updateByObservable(true)}this.bEnabled=false;this.__base(a);return true},

	isValid:function(){if(!this.__base()){return false}for(var i=0,iLength=this.aChildren.length;i<iLength;i++){if(!this.aChildren[i].isValid()&&this.aChildren[i].isEnabled()){return false}}return true},

	isRequired:function(){if(this.__base()){return true}for(var i=0,iLength=this.aChildren.length;i<iLength;i++){if(this.aChildren[i].isRequired()&&this.aChildren[i].isEnabled()){return true}}return false},

	init:function(){this.__base();for(var i=0,iLength=this.aChildren.length;i<iLength;i++){this.aChildren[i].init()}},

	afterClone:function(){this.__base();for(var i=0,iLength=this.aChildren.length;i<iLength;i++){this.aChildren[i].afterClone()}},

	hasValue:function(){return false},

	isChanged:function(){return true},

	focus:function(){if(this.aChildren.length>0){this.aChildren[0].focus()}},

	getCountChildrenByPattern:function(a){var b=0;for(var i=0,iLength=this.aChildren.length;i<iLength;i++){if(!this.aChildren[i].isEnabled()){continue}if(this.aChildren[i]instanceof FieldContainer){if(this.aChildren[i].getCountChildrenByPattern(a)>0){b++}}else if(this.aChildren[i].getValue().match(a)){b++}}return b},

	updateElements:function(a){this.__base(a);for(var i=0,iLength=this.aChildren.length;i<iLength;i++){this.aChildren[i].updateElements(a)}},

	clone:function(a,b,c){var d=this.__base(a,b,c);this.cloneChildren(d,c);return d},

	cloneChildren:function(a,b){for(var i=0,iLength=this.aChildren.length;i<iLength;i++){a.addChild(this.aChildren[i].clone(document.getElementById(this.aChildren[i].oElement.id.match(ZForms.Widget.Container.Multiplicator.REG_EXP_REPLACE)[1]+'_'+b),document.getElementById(this.aChildren[i].oClassElement.id.match(ZForms.Widget.Container.Multiplicator.REG_EXP_REPLACE)[1]+'_'+b),b))}},

	destruct:function(){for(var i=0,iLength=this.aChildren.length;i<iLength;i++){this.aChildren[i].destruct()}this.__base()},

	prepareForSubmit:function(){for(var i=0,iLength=this.aChildren.length;i<iLength;i++){this.aChildren[i].prepareForSubmit()}this.__base()}
});

ZForms.Widget.Container.Sheet=ZForms.Widget.Container.inheritTo({
	__constructor:function(a,b,c){this.__base(a,b,c);this.oLegendButton=null;this.oPrevButton=null;this.oNextButton=null;if(this.oOptions.oElementLegend){this.addLegendButton(new ZForms.Widget.Button(this.oOptions.oElementLegend,null,{bTemplate:this.oOptions.bTemplate}))}if(this.oOptions.oElementPrev){this.addPrevButton(new ZForms.Widget.Button(this.oOptions.oElementPrev,null,{bTemplate:this.oOptions.bTemplate}))}if(this.oOptions.oElementNext){this.addNextButton(new ZForms.Widget.Button(this.oOptions.oElementNext,null,{bTemplate:this.oOptions.bTemplate}))}this.bSelected=Common.Class.match(this.oClassElement,this.__self.CLASS_NAME_SELECTED)},

	addLegendButton:function(a){this.oLegendButton=a;this.addChild(a);var b=this;a.setHandler(function(){b.oParent.select(b);return false})},

	addPrevButton:function(a){this.oPrevButton=a;this.addChild(a);var b=this;a.setHandler(function(){b.oParent.prev(b);return false})},

	addNextButton:function(a){this.oNextButton=a;this.addChild(a);var b=this;a.setHandler(function(){b.oParent.next(b);return false})},

	setParent:function(a){this.__base(a);if(this.isSelected()){this.oParent.select(this)}},

	isSelected:function(){return this.bSelected},

	select:function(){this.bSelected=true;this.addClass(this.__self.CLASS_NAME_SELECTED);if(this.oLegendButton){this.oLegendButton.addClass(this.__self.CLASS_NAME_SELECTED)}},

	unselect:function(){this.bSelected=false;this.removeClass(this.__self.CLASS_NAME_SELECTED);if(this.oLegendButton){this.oLegendButton.removeClass(this.__self.CLASS_NAME_SELECTED)}},

	destruct:function(){if(this.oLegendButton){this.oLegendButton.destruct()}if(this.oPrevButton){this.oPrevButton.destruct()}if(this.oNextButton){this.oNextButton.destruct()}this.__base()}
});

ZForms.Widget.Container.SheetContainer=ZForms.Widget.Container.inheritTo({
	__constructor:function(a,b,c){this.__base(a||document.createElement('div'),b,c);this.iCurrentSheetIndex=0},

	addChild:function(a){if(!(a instanceof ZForms.Widget.Container.Sheet)){return}return this.__base(a)},

	findSheetIndex:function(a){return this.aChildren.indexOf(a)},

	select:function(a){this.selectByIndex(this.findSheetIndex(a))},

	prev:function(a){this.selectByIndex(this.findSheetIndex(a)-1)},

	next:function(a){this.selectByIndex(this.findSheetIndex(a)+1)},

	selectByIndex:function(a){if(!this.aChildren[a]){return}this.aChildren[this.iCurrentSheetIndex].unselect();this.aChildren[a].select();this.iCurrentSheetIndex=a}},{CLASS_NAME_INITED:'sheet-container-inited'
});

ZForms.Widget.Container.Group=ZForms.Widget.Container.inheritTo({
	hasValue:function(){return true},

	getName:function(){return this.aChildren[0]?this.aChildren[0].getName():''},

	addChild:function(a){if(!(a instanceof ZForms.Widget.Text.State)){return}return this.__base(a)},

	processEvents:function(a,b,c){this.__base(a,b,c);if(!c){for(var i=0;i<this.aChildren.length;i++){this.aChildren[i].updateLastProcessedValue();if(this.aChildren[i].isChecked()){this.aChildren[i].addClass(this.__self.CLASS_NAME_SELECTED)}else{this.aChildren[i].removeClass(this.__self.CLASS_NAME_SELECTED)}}}},

	enable:function(a){var b=this.__base(a);if(b&&!a){this.setValueFromElement()}return b},

	disable:function(a){var b=this.__base(this,a);if(b&&!a){this.setValueFromElement()}return b},

	isChanged:function(){return this.__base()}
});

ZForms.Widget.Container.Group.CheckBox=ZForms.Widget.Container.Group.inheritTo({
	createValue:function(a){return new ZForms.Value.Multiple(a)},

	setValue:function(a){for(var i=0,aValues=a.get();i<this.aChildren.length;i++){if(aValues.contains(this.aChildren[i].getValue().get())){this.aChildren[i].check()}else{this.aChildren[i].uncheck()}}this.__base(a)},

	setValueFromElement:function(){this.oValue.reset();for(var i=0;i<this.aChildren.length;i++){if(this.aChildren[i].isChecked()&&this.aChildren[i].isEnabled()){this.oValue.add(this.aChildren[i].getValue().get())}}this.__base()},

	addChild:function(a){if(!this.__base(a)){return}if(a.isChecked()){this.oValue.add(a.getValue().get());this.oInitialValue.add(a.getValue().get())}return a},

	enableOptionsByValue:function(a,b,c){for(var i=0,bMatched,oChild,bEnable;i<this.aChildren.length;i++){oChild=this.aChildren[i];bEnable=false;for(var j=0;j<a.length;j++){bMatched=false;for(var k=0;k<a[j].length&&!bMatched;k++){bMatched=oChild.getValue().match(a[j][k])?true:false}if(bMatched){if(b||j==0){bEnable=true}}else if(!b){bEnable=false}}if(bEnable){if(c){oChild.check()}else if(this.isEnabled()){oChild.enable()}}else{if(c){oChild.uncheck()}else{oChild.disable()}}}this.processEvents(true)}
});

ZForms.Widget.Container.Group.RadioButton=ZForms.Widget.Container.Group.inheritTo({
	setValue:function(a){for(var i=0;i<this.aChildren.length;i++){if(a.isEqual(this.aChildren[i].getValue())){this.aChildren[i].check()}}this.__base(a)},

	setValueFromElement:function(){this.oValue.reset();for(var i=0;i<this.aChildren.length;i++){if(this.aChildren[i].isChecked()&&this.aChildren[i].isEnabled()){this.oValue.set(this.aChildren[i].getValue().get());break}}this.__base()},

	addChild:function(a){if(!this.__base(a)){return}if(a.isChecked()){this.oValue.set(a.getValue().get());this.oInitialValue.set(a.getValue().get())}return a},

	enableOptionsByValue:function(a,b){var c=false,iFirstEnabledChildIndex=-1;for(var i=0,bMatched,oChild,bEnable;i<this.aChildren.length;i++){oChild=this.aChildren[i];bEnable=false;for(var j=0;j<a.length;j++){bMatched=false;for(var k=0;k<a[j].length&&!bMatched;k++){bMatched=oChild.getValue().match(a[j][k])?true:false}if(bMatched){if(iFirstEnabledChildIndex<0){iFirstEnabledChildIndex=i}if(b||j==0){bEnable=true}}else if(!b){bEnable=false}}if(bEnable&&this.isEnabled()){oChild.enable()}else if(oChild.isEnabled()){oChild.disable()}if(!oChild.isEnabled()&&oChild.isChecked()){c=true}}if(c&&iFirstEnabledChildIndex>-1){this.oValue.set(this.aChildren[iFirstEnabledChildIndex].getValue());this.aChildren[iFirstEnabledChildIndex].check()}this.processEvents(true)}
});

ZForms.Widget.Text=ZForms.Widget.inheritTo({
	__constructor:function(a,b,c){this.__base(a,b,c);this.bPlaceHolderEnabled=false;this.iMaxLength=a.maxLength?a.maxLength:0;if(!this.isTemplate()){this.addExtendedHandlers()}},

	getDefaultOptions:function(){return Common.Object.extend(this.__base(),{sPlaceHolder:''},true)},

	updateElementValue:function(a){this.oElement.value=a.toStr()},

	setValue:function(a){if(a.isEmpty()){this.updateElementValue(a);this.enablePlaceHolder()}else{this.disablePlaceHolder();this.updateElementValue(a)}this.__base(a)},

	getEventList:function(){return[this.__self.DOM_EVENT_TYPE_KEYUP,this.__self.DOM_EVENT_TYPE_BLUR,this.__self.DOM_EVENT_TYPE_CHANGE]},

	setValueFromElement:function(){if(this.bPlaceHolderEnabled){return}this.oValue.set(this.oElement.value);this.__base()},

	init:function(){this.__base();if(!this.isTemplate()){this.enablePlaceHolder()}},

	afterClone:function(){this.__base();this.enablePlaceHolder()},

	hasPlaceHolder:function(){return!!this.oOptions.sPlaceHolder},

	addExtendedHandlers:function(){if(this.isTemplate()){return false}if(!this.hasPlaceHolder()){return true}var a=this;Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_FOCUS,function(){a.disablePlaceHolder()});Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_BLUR,function(){a.enablePlaceHolder()});return true},

	enablePlaceHolder:function(){if(!this.hasPlaceHolder()||!this.getValue().isEmpty()){return}this.addClass(this.__self.CLASS_NAME_PLACE_HOLDER,this.oElement);if(this.iMaxLength>0){this.oElement.maxLength=this.oOptions.sPlaceHolder.length}this.oElement.value=this.oOptions.sPlaceHolder;this.bPlaceHolderEnabled=true},

	disablePlaceHolder:function(){if(!this.hasPlaceHolder()||!this.getValue().isEmpty()){return}this.removeClass(this.__self.CLASS_NAME_PLACE_HOLDER,this.oElement);if(this.iMaxLength>0){this.oElement.maxLength=this.iMaxLength}this.oElement.value='';this.bPlaceHolderEnabled=false},

	destruct:function(){this.disablePlaceHolder();this.__base()},

	prepareForSubmit:function(){this.disablePlaceHolder();this.__base()}},{CLASS_NAME_PLACE_HOLDER:'placeholder'
});

ZForms.Widget.Text.Number=ZForms.Widget.Text.inheritTo({
	__constructor:function(a,b,c){this.__base(a,b,c);this.oHiddenElement=null;if(this.isTemplate()){return}this.replaceElement(a)},

	replaceElement:function(a){this.oHiddenElement=a.parentNode.insertBefore(Common.Dom.createElement('input',{'type':'hidden','id':'value-'+a.getAttribute('id'),'name':a.getAttribute('name'),'value':a.value}),a);a.name='to-str-'+a.name},

	getName:function(){return this.oHiddenElement?this.oHiddenElement.name:this.oElement.name},

	getDefaultOptions:function(){return Common.Object.extend(this.__base(),{bFloat:false,bNegative:false},true)},

	createValue:function(a){return new ZForms.Value.Number(a)},

	addExtendedHandlers:function(){if(!this.__base()){return}var b=this,iKeyDownCode=-1;if(Common.Browser.isOpera()&&this.oElement.isSameNode){Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_KEYDOWN,function(a){iKeyDownCode=a.keyCode})}Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_KEYPRESS,function(a){var a=Common.Event.normalize(a);if(a.ctrlKey||a.charCode==0||a.which==0||(iKeyDownCode==a.keyCode&&(a.keyCode==46||a.keyCode==45||a.keyCode==36||a.keyCode==35||a.keyCode==9||a.keyCode==8))||(a.iKeyCode>=48&&a.iKeyCode<=57)||(b.oOptions.bFloat&&(a.iKeyCode==44||a.iKeyCode==46))||(b.oOptions.bNegative&&a.iKeyCode==45)){return}Common.Event.cancel(a)});Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_BLUR,function(){if(b.bPlaceHolderEnabled){return}b.setValue(b.createValue(b.oElement.value))})},

	updateElementValue:function(a){this.oHiddenElement.value=a.toStr();if(ZForms.Resources.getNumberSeparator()==','){a=new ZForms.Value(a.toStr().replace(/\./g,','))}this.__base(a)},

	setValue:function(a){if(!a.isEmpty()){if(!this.oOptions.bFloat){a.set(parseInt(a.get().toString().replace(/[\.\,].*/g,''),10))}if(!this.oOptions.bNegative&&a.get()<0){a.set(a.get()*-1)}}return this.__base(a)},

	init:function(){this.__base();if(this.oElement.value!==this.getValue().toStr()){this.setValue(this.getValue())}},

	destruct:function(){this.oHiddenElement=null;this.__base()}
});

ZForms.Widget.Container.Date=ZForms.Widget.Container.inheritTo({
	__constructor:function(a,b,c){this.__base(a,b,c);if(this.isTemplate()){return}this.oDayInput=this.createNumberInput('day',2,this.oOptions.oPlaceHolders&&this.oOptions.oPlaceHolders.sDay?this.oOptions.oPlaceHolders.sDay:null);this.oMonthInput=this.createMonthInput('month');this.oYearInput=this.createNumberInput('year',4,this.oOptions.oPlaceHolders&&this.oOptions.oPlaceHolders.sYear?this.oOptions.oPlaceHolders.sYear:null);if(this.oOptions.bWithTime){this.oHourInput=this.createNumberInput('hour',2,this.oOptions.oPlaceHolders&&this.oOptions.oPlaceHolders.sHour?this.oOptions.oPlaceHolders.sHour:null);this.oMinuteInput=this.createNumberInput('minute',2,this.oOptions.oPlaceHolders&&this.oOptions.oPlaceHolders.sMinute?this.oOptions.oPlaceHolders.sMinute:null);this.oSecondInput=this.createNumberInput('second',2,this.oOptions.oPlaceHolders&&this.oOptions.oPlaceHolders.sSecond?this.oOptions.oPlaceHolders.sSecond:null)}this.addChild(this.oDayInput);this.addChild(this.oMonthInput);this.addChild(this.oYearInput);if(this.oOptions.bWithTime){this.addChild(this.oHourInput);this.addChild(this.oMinuteInput);this.addChild(this.oSecondInput)}this.replaceElement();this.setValueFromElement();this.addExtendedHandlers();this.initValue();this.oCalendar=this.oOptions.oPickerOpenerElement?new ZForms.Calendar(this):null},

	getDefaultOptions:function(){return Common.Object.extend(this.__base(),{bWithTime:false,bOnlyMonths:false,oPlaceHolders:{sDay:'',sYear:'',sHour:'',sMinute:'',sSecond:''}},true)},

	createValue:function(a){return this.oOptions.bWithTime?new ZForms.Value.Date.Time(a):new ZForms.Value.Date(a)},

	hasValue:function(){return true},

	setValue:function(a){var b=this.oDayInput.createValue(a.getDay()),oValueYear=this.oYearInput.createValue(a.getYear());if((this.oYearInput.getValue().isEmpty()||!oValueYear.isEmpty())&&!oValueYear.isEqual(this.oYearInput.getValue())){this.oYearInput.setValue(oValueYear)}this.oMonthInput.setValue(this.oMonthInput.createValue(a.getMonth()));if((this.oDayInput.getValue().isEmpty()||!b.isEmpty())&&!b.isEqual(this.oDayInput.getValue())){this.oDayInput.setValue(b)}if(this.oOptions.bWithTime){var c=this.oHourInput.createValue(a.getHour()),oValueMinute=this.oMinuteInput.createValue(a.getMinute()),oValueSecond=this.oSecondInput.createValue(a.getSecond());if((this.oHourInput.getValue().isEmpty()||!c.isEmpty())&&!c.isEqual(this.oHourInput.getValue())){this.oHourInput.setValue(c)}if((this.oMinuteInput.getValue().isEmpty()||!oValueMinute.isEmpty())&&!oValueMinute.isEqual(this.oMinuteInput.getValue())){this.oMinuteInput.setValue(oValueMinute)}if((this.oSecondInput.getValue().isEmpty()||!oValueSecond.isEmpty())&&!oValueSecond.isEqual(this.oSecondInput.getValue())){this.oSecondInput.setValue(oValueSecond)}}this.oElement.value=a.toStr();this.__base(a)},

	isRequired:function(){return ZForms.Widget.prototype.isRequired.call(this)},

	isValid:function(){return ZForms.Widget.prototype.isValid.call(this)},

	isChanged:function(){return ZForms.Widget.prototype.isChanged.call(this)},

	replaceElement:function(){var a=Common.Dom.createElement('input',{'type':'hidden','id':this.oElement.getAttribute('id'),'name':this.oElement.getAttribute('name'),'value':this.oElement.value});this.oElement.parentNode.replaceChild(a,this.oElement);this.oElement=a},

	addExtendedHandlers:function(){if(this.isTemplate()){return}var b=this,aWidgets=this.oOptions.bWithTime?[this.oDayInput.oElement,this.oMonthInput.oElement,this.oYearInput.oElement,this.oHourInput.oElement,this.oMinuteInput.oElement,this.oSecondInput.oElement]:[this.oDayInput.oElement,this.oMonthInput.oElement,this.oYearInput.oElement];Common.Event.add(aWidgets,this.__self.DOM_EVENT_TYPE_BLUR,function(){b.processDate()});Common.Event.add(aWidgets,this.__self.DOM_EVENT_TYPE_KEYDOWN,function(a){if(Common.Event.normalize(a).iKeyCode==b.__self.KEY_CODE_ENTER){b.processDate()}})},

	processDate:function(){var a=this.oYearInput.getValue().get(),iMonth=this.oMonthInput.getValue().get(),iDay=this.oDayInput.getValue().isEmpty()&&this.oOptions.bOnlyMonths?1:this.oDayInput.getValue().get(),iHour=this.oOptions.bWithTime?this.oHourInput.getValue().get():0,iMinute=this.oOptions.bWithTime?this.oMinuteInput.getValue().get():0,iSecond=this.oOptions.bWithTime?this.oSecondInput.getValue().get():0;this.setValue(this.createValue(this.oOptions.bWithTime?a+'-'+iMonth+'-'+iDay+' '+iHour+':'+iMinute+':'+iSecond:a+'-'+iMonth+'-'+iDay))},

	createNumberInput:function(a,b,c){return ZForms.createNumberInput(this.oElement.parentNode.insertBefore(Common.Dom.createElement('input',{'type':this.oOptions.bOnlyMonths&&a=='day'?'hidden':'text','id':a+'-'+this.oElement.id,'name':a+'-'+this.oElement.name,'size':b,'maxlength':b,'class':'input-'+a}),this.oElement),null,{sPlaceHolder:c})},

	createMonthInput:function(a){var b=Common.Dom.createElement('select',{'id':a+'-'+this.oElement.id,'name':a+'-'+this.oElement.name,'class':'input-'+a}),aMonths=this.oOptions.bOnlyMonths?ZForms.Resources.getMonthsByType('normal'):ZForms.Resources.getMonthsByType('genitive');document.body.appendChild(b);b.options.length=0;for(var i=0;i<aMonths.length;i++){b.options[b.options.length]=new Option(aMonths[i],i+1)}return ZForms.createSelectInput(this.oElement.parentNode.insertBefore(document.body.removeChild(b),this.oElement))},

	setValueFromElement:function(){if(this.isTemplate()||!this.oYearInput){return}this.oValue.set(this.oYearInput.getValue().get()+'-'+this.oMonthInput.getValue().get()+'-'+(this.oOptions.bOnlyMonths&&this.oDayInput.getValue().isEmpty()?1:this.oDayInput.getValue().get())+(this.oOptions.bWithTime?' '+this.oHourInput.getValue().get()+':'+this.oMinuteInput.getValue().get()+':'+this.oSecondInput.getValue().get():''));ZForms.Widget.prototype.setValueFromElement.call(this)},

	initValue:function(){this.oInitialValue=this.createValue(this.oElement.value);this.setValue(this.oInitialValue.clone());this.oDayInput.oInitialValue=this.oDayInput.createValue(this.oValue.getDay());this.oMonthInput.oInitialValue=this.oMonthInput.createValue(this.oValue.getMonth());this.oYearInput.oInitialValue=this.oYearInput.createValue(this.oValue.getYear());if(this.oOptions.bWithTime){this.oHourInput.oInitialValue=this.oHourInput.createValue(this.oValue.getHour());this.oMinuteInput.oInitialValue=this.oMinuteInput.createValue(this.oValue.getMinute());this.oSecondInput.oInitialValue=this.oSecondInput.createValue(this.oValue.getSecond())}if(!this.getValue().isEmpty()){this.addClass(this.__self.CLASS_NAME_SELECTED_INITIAL,this.oMonthInput.oElement.options[this.oMonthInput.oElement.selectedIndex])}},

	disable:function(a){if(this.__base(a)){return false}if(this.oCalendar){this.oCalendar.disable()}return true},

	enable:function(a){if(this.__base(a)){return false}if(this.oCalendar){this.oCalendar.enable()}return true},

	clone:function(a,b,c){var d=Common.Object.extend({oPickerOpenerElement:this.oOptions.oPickerOpenerElement?document.getElementById(this.oOptions.oPickerOpenerElement.id.match(ZForms.Widget.Container.Multiplicator.REG_EXP_REPLACE)[1]+'_'+c):null,bTemplate:false},this.oOptions);return new this.__self(a,b,d)},

	destruct:function(){this.__base();if(this.oCalendar){this.oCalendar.destruct()}}
});

ZForms.Widget.Text.State=ZForms.Widget.Text.inheritTo({
	__constructor:function(a,b,c){this.__base(a,b,c);this.bLastProcessedChecked=null},

	check:function(){this.oElement.checked=true},

	uncheck:function(){this.oElement.checked=false},

	isChecked:function(){return this.oElement.checked},

	getEventList:function(){return[this.__self.DOM_EVENT_TYPE_CLICK]},

	isChanged:function(){return this.bLastProcessedChecked!=this.oElement.checked},

	updateLastProcessedValue:function(){this.bLastProcessedChecked=this.oElement.checked}
});

ZForms.Widget.Select=ZForms.Widget.inheritTo({
	__constructor:function(a,b,c){this.__base(a,b,c);this.aOptions=[];for(var i=0;i<this.oElement.options.length;i++){this.aOptions[i]={sLabel:this.oElement.options[i].innerHTML,sValue:this.oElement.options[i].value}}},

	setValue:function(a){for(var i=0;i<this.aOptions.length;i++){if(this.aOptions[i].sValue==a.toStr()){this.oElement.selectedIndex=i;break}}this.__base(a)},

	getEventList:function(){return[this.__self.DOM_EVENT_TYPE_CHANGE,this.__self.DOM_EVENT_TYPE_KEYUP]},

	setValueFromElement:function(){if(this.oElement.selectedIndex>=0){this.oValue.set(this.oElement.options[this.oElement.selectedIndex].value)}else{this.oValue.reset()}this.__base()},

	enableOptionsByValue:function(a,b){this.oElement.options.length=0;for(var i=0,bMatched,bEnable,oOption;i<this.aOptions.length;i++){oOption=this.aOptions[i];bEnable=false;for(var j=0;j<a.length;j++){bMatched=false;for(var k=0;k<a[j].length&&!bMatched;k++){bMatched=a[j][k].test(oOption.sValue)}if(bMatched){if(b||j==0){bEnable=true}}else if(!b){bEnable=false}}if(bEnable){this.oElement.options[this.oElement.options.length]=new Option(oOption.sLabel,oOption.sValue,this.getValue().isEqual(oOption.sValue))}}this.processEvents(true)}
});

ZForms.Widget.Text.Combo=ZForms.Widget.Text.inheritTo({
	__constructor:function(a,b,c){if(!c.bTemplate&&Common.Browser.isOpera()){var d=Common.Dom.createElement('select',{'name':c.oOptionsElement.name,'id':c.oOptionsElement.id,'class':c.oOptionsElement.className});for(var i=0,aOptions=c.oOptionsElement.options;i<aOptions.length;i++){d.options[d.options.length]=new Option(aOptions[i].innerHTML,aOptions[i].value)}c.oOptionsElement.parentNode.replaceChild(d,c.oOptionsElement);c.oOptionsElement=d;c.oOptionsElement.size=this.__self.DEFAULT_PAGE_SIZE}this.oShowOptionsButton=null;if(!c.bTemplate&&c.oShowOptionsElement){c.oShowOptionsElement.tabIndex=-1;this.oShowOptionsButton=ZForms.createButton(c.oShowOptionsElement)}this.__base(a,b,c);this.oOptions.oOptionsElement=c.oOptionsElement;this.oOptions.oOptionsElement.tabIndex=-1;if(this.isTemplate()){return}this.iPageSize=this.oOptions.oOptionsElement.size||this.__self.DEFAULT_PAGE_SIZE;Common.Class.add(this.oOptions.oOptionsElement,this.__self.CLASS_NAME_COMBO_LIST);this.bOptionsShowed=false;this.aOptions=[];this.aOptionsCurrent=[];this.oElement.setAttribute('autocomplete','off');this.oOptions.oOptionsElement.setAttribute('size',this.iPageSize);this.iSelectedIndex=0;this.sLastSearchValue=null;this.initOptions();this.hideOptions();this.oOptions.oOptionsElement.options.length=0},

	addExtendedHandlers:function(){var b=this,bProcessFocus=true,bProcessBlur=true;if(this.hasPlaceHolder()){Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_FOCUS,function(){b.disablePlaceHolder()})}Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_KEYUP,function(a){b.dispatchKeyEvent(Common.Event.normalize(a).iKeyCode)});Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_FOCUS,function(){if(!bProcessFocus){bProcessFocus=true;return}if(b.bPlaceHolderEnabled){b.disablePlaceHolder()}b.updateOptions(true)});Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_KEYPRESS,function(a){var a=Common.Event.normalize(a);if(a.iKeyCode==b.__self.KEY_CODE_ENTER){Common.Event.cancel(a)}});Common.Event.add(document,this.__self.DOM_EVENT_TYPE_CLICK,function(a){if(Common.Event.normalize(a).target==b.oElement){return}b.hideOptions();if(!b.bPlaceHolderEnabled){b.enablePlaceHolder()}});Common.Event.add([this.oOptions.oOptionsElement,this.oElement],this.__self.DOM_EVENT_TYPE_BLUR,function(){if(bProcessBlur&&b.hasPlaceHolder()){b.enablePlaceHolder()}if(bProcessBlur){b.hideOptions()}bProcessBlur=true});Common.Event.add(this.oOptions.oOptionsElement,this.__self.DOM_EVENT_TYPE_FOCUS,function(){b.showOptions()});Common.Event.add(this.oOptions.oOptionsElement,this.__self.DOM_EVENT_TYPE_CHANGE,function(){b.selectFromOptions();bProcessFocus=false;b.oElement.focus()});Common.Event.add([this.oOptions.oOptionsElement].concat(this.oOptions.oShowOptionsElement?[this.oOptions.oShowOptionsElement]:[]),this.__self.DOM_EVENT_TYPE_MOUSEDOWN,function(){bProcessBlur=false});if(this.oShowOptionsButton){Common.Event.add(this.oOptions.oShowOptionsElement,this.__self.DOM_EVENT_TYPE_MOUSEUP,function(){bProcessBlur=true});this.oShowOptionsButton.setHandler(function(a){Common.Event.cancel(a);b.updateOptions(true,'');bProcessFocus=false;b.oElement.focus()})}},

	initOptions:function(){var a=this.oOptions.oOptionsElement.options;for(var i=0;i<a.length;i++){this.aOptions[i]={sLabel:a[i].innerHTML,sValue:a[i].value,sSearchValue:a[i].innerHTML.toLowerCase()}}this.aOptionsCurrent=this.aOptions},

	dispatchKeyEvent:function(a){switch(a){case this.__self.KEY_CODE_ARROW_UP:this.selectPrevOption();break;case this.__self.KEY_CODE_ARROW_DOWN:this.selectNextOption();break;case this.__self.KEY_CODE_PAGE_UP:this.selectPrevPage();break;case this.__self.KEY_CODE_PAGE_DOWN:this.selectNextPage();break;case this.__self.KEY_CODE_HOME:this.selectFirstOption();break;case this.__self.KEY_CODE_END:this.selectLastOption();break;case this.__self.KEY_CODE_ENTER:if(this.bOptionsShowed){this.selectFromOptions()}break;case this.__self.KEY_CODE_TAB:return;break;default:this.updateOptions(false);break}},

	selectPrevOption:function(){if(this.iSelectedIndex>0){this.iSelectedIndex--}this.updateSelectedIndex()},

	selectNextOption:function(){if(this.iSelectedIndex<this.oOptions.oOptionsElement.options.length-1){this.iSelectedIndex++}this.updateSelectedIndex()},

	selectPrevPage:function(){var a=this.iSelectedIndex-this.iPageSize;if(a>0){this.iSelectedIndex=a}else{this.iSelectedIndex=0}this.updateSelectedIndex()},

	selectNextPage:function(){var a=this.iSelectedIndex+this.iPageSize;if(a<this.oOptions.oOptionsElement.options.length-1){this.iSelectedIndex=a}else{this.iSelectedIndex=this.oOptions.oOptionsElement.options.length-1}this.updateSelectedIndex()},

	selectFirstOption:function(){this.iSelectedIndex=0;this.updateSelectedIndex()},

	selectLastOption:function(){this.iSelectedIndex=this.oOptions.oOptionsElement.options.length-1;this.updateSelectedIndex()},

	selectFromOptions:function(){if(this.oOptions.oOptionsElement.options.length>0&&this.oOptions.oOptionsElement.selectedIndex>-1){if(this.hasPlaceHolder()){this.disablePlaceHolder()}this.iSelectedIndex=this.oOptions.oOptionsElement.selectedIndex;this.sLastSearchValue=this.oElement.value.toLowerCase();this.setValue(new ZForms.Value(this.oOptions.oOptionsElement.options[this.iSelectedIndex].innerHTML))}var a=this;setTimeout(function(){a.hideOptions()},0)},

	updateSelectedIndex:function(){if(this.iSelectedIndex>-1){this.oOptions.oOptionsElement.selectedIndex=this.iSelectedIndex}},

	updateOptions:function(a,b){var c=this.oElement.value.toLowerCase(),sNewValue=typeof(b)=='undefined'?c:b;if(!a&&this.sLastSearchValue==sNewValue){return}var i=0,iLength=this.aOptionsCurrent.length,iOptionsCount=0,bFound=false,aOptions=this.oOptions.oOptionsElement.options;this.sLastSearchValue=sNewValue;this.oOptions.oOptionsElement.options.length=0;this.oOptions.oOptionsElement.innerHTML='';while(i<iLength){if(this.aOptionsCurrent[i].sSearchValue.indexOf(sNewValue)>-1){aOptions[iOptionsCount++]=new Option(this.aOptionsCurrent[i].sLabel,this.aOptionsCurrent[i].sValue);if(c==this.aOptionsCurrent[i].sSearchValue){this.iSelectedIndex=iOptionsCount-1;bFound=true}}i++}if(!bFound){this.iSelectedIndex=-1}if(iOptionsCount>0){this.updateSelectedIndex();this.showOptions()}else{this.hideOptions()}},

	showOptions:function(){if(this.bOptionsShowed){return}this.addClass(this.__self.CLASS_NAME_COMBO_LIST_ACTIVE);this.bOptionsShowed=true},

	hideOptions:function(){if(!this.bOptionsShowed){return}this.removeClass(this.__self.CLASS_NAME_COMBO_LIST_ACTIVE);this.bOptionsShowed=false},

	enableOptionsByValue:function(a,b){this.aOptionsCurrent=[];for(var i=0,bMatched,bEnable,oOption;i<this.aOptions.length;i++){oOption=this.aOptions[i];bEnable=false;for(var j=0;j<a.length;j++){bMatched=false;for(var k=0;k<a[j].length&&!bMatched;k++){bMatched=a[j][k].test(oOption.sValue)}if(bMatched){if(b||j==0){bEnable=true}}else if(!b){bEnable=false}}if(bEnable){this.aOptionsCurrent.push(oOption)}}this.sLastSearchValue=null;this.iSelectedIndex=-1},

	disable:function(a){if(!this.__base(a)){return false}this.oOptions.oOptionsElement.disabled=true;if(this.oShowOptionsButton){this.oShowOptionsButton.disable()}return true},

	enable:function(a){if(!this.__base(a)){return false}this.oOptions.oOptionsElement.disabled=false;if(this.oShowOptionsButton){this.oShowOptionsButton.enable()}return true},

	updateElements:function(a){this.oOptions.oOptionsElement=document.getElementById(a>0?this.oOptions.oOptionsElement.id.match(ZForms.Widget.Container.Multiplicator.REG_EXP_REPLACE)[1]+'_'+a:this.oOptions.oOptionsElement.id);this.__base(a)},

	clone:function(a,b,c){var d=Common.Object.extend({oOptionsElement:document.getElementById(this.oOptions.oOptionsElement.id.match(ZForms.Widget.Container.Multiplicator.REG_EXP_REPLACE)[1]+'_'+c),oShowOptionsElement:this.oOptions.oShowOptionsElement?document.getElementById(this.oOptions.oShowOptionsElement.id.match(ZForms.Widget.Container.Multiplicator.REG_EXP_REPLACE)[1]+'_'+c):null,bTemplate:false},this.oOptions);return new this.__self(a,b,d)},

	destruct:function(){this.oOptions.oOptionsElement=null;if(this.oShowOptionsButton){this.oShowOptionsButton.destruct()}this.__base()}},{DEFAULT_PAGE_SIZE:5,CLASS_NAME_COMBO_LIST:'combo-list',CLASS_NAME_COMBO_LIST_ACTIVE:'combo-field-active'
});

ZForms.Widget.Container.Slider=ZForms.Widget.Container.inheritTo({
	__constructor:function(a,b,c){c=c||{};this.aSlideRules=c.aSlideRules||this.getDefaultOptions().aSlideRules;this.dMin=this.aSlideRules[0].dValue;this.dMax=this.aSlideRules[this.aSlideRules.length-1].dValue;this.__base(a,b,c);if(this.isTemplate()){return}this.aSlideRules[0].dPercent=0;this.aSlideRules[this.aSlideRules.length-1].dPercent=100;var d=this.createElements(a);this.oContainer=d.oContainer;this.oScaleElement=d.oScaleElement;this.aControls=[];this.aMarks=this.createMarks(d.oScaleElement);this.bEnabled=true;this.iLastControlPosition=0;this.iCurrentControlIndex=-1;this.iFocusedChildIndex=-1;this.oContainerOffset=null;this.fClickHandler=null;this.fDragStartHandler=null;this.fDragHandler=null;this.fDragEndHandler=null;this.fNullHandler=null;this.fSyncHandler=null;this.addExtendedHandlers();this.iIndex=this.__self.add(this);this.oLastProcessedValue=null},

	getDefaultOptions:function(){return Common.Object.extend(this.__base(),{aSlideRules:[{dValue:0,dPercent:0,dStep:1,sLabel:'0'},{dValue:100,dPercent:100,dStep:1,sLabel:'100'}]},true)},

	createElements:function(a){var b={oContainer:document.createElement('div'),oScaleElement:document.createElement('div'),aMarkElements:[]};b.oContainer.id='container-'+this.oElement.id;Common.Class.add(b.oContainer,this.__self.CLASS_NAME_SLIDER_CONTAINER);Common.Class.add(b.oContainer,this.__self.CLASS_NAME_SLIDER);Common.Class.add(b.oScaleElement,this.__self.CLASS_NAME_SLIDER_SCALE);b.oContainer.appendChild(b.oScaleElement);a.insertBefore(b.oContainer,a.firstChild);return b},

	createMarks:function(a){var b=[];for(var i=0,oElement;i<this.aSlideRules.length;i++){oElement=document.createElement('div');Common.Class.add(oElement,this.__self.CLASS_NAME_MARK_ELEMENT+' '+this.__self.CLASS_NAME_MARK_ELEMENT+'-'+this.aSlideRules[i].dValue);this.setupMarkElementPosition(oElement,this.aSlideRules[i].dPercent);if(typeof this.aSlideRules[i].sLabel!='undefined'){oElement.innerHTML='<span>'+this.aSlideRules[i].sLabel+'</span>'}a.appendChild(oElement);b.push({oElement:oElement,dValue:this.aSlideRules[i].dValue,bSelected:false})}return b},

	setupMarkElementPosition:function(a,b){a.style.left=b+'%'},

	createControl:function(b,c){var d={oElement:document.createElement('div'),oValueElement:document.createElement('div')},oThis=this,iIndex=this.getChildren().length-1;d.oElement.id='control-'+b;Common.Class.add(d.oElement,this.__self.CLASS_NAME_CONTROL_ELEMENT+' '+this.__self.CLASS_NAME_CONTROL_ELEMENT+'-'+iIndex);Common.Class.add(d.oValueElement,this.__self.CLASS_NAME_VALUE_ELEMENT);c.appendChild(d.oElement);c.appendChild(d.oValueElement);Common.Event.add(d.oElement,this.__self.DOM_EVENT_TYPE_MOUSEDOWN,function(a){if(oThis.iFocusedChildIndex>-1){oThis.aChildren[oThis.iFocusedChildIndex].oElement.blur()}Common.Event.cancel(a);oThis.__self.setActiveIndex(oThis.iIndex);oThis.fDragStartHandler(iIndex)});return d},

	createRangeElements:function(a){this.aControls[a].oLeftRangeElement=a==0?this.createRangeElement(a):this.aControls[a-1].oRightRangeElement;this.aControls[a].oRightRangeElement=this.createRangeElement(a+1)},

	createRangeElement:function(a){var b=document.createElement('div');Common.Class.add(b,this.__self.CLASS_NAME_RANGE_ELEMENT+' '+this.__self.CLASS_NAME_RANGE_ELEMENT+'-'+a);this.oContainer.insertBefore(b,this.oScaleElement);return b},

	addChild:function(c,d){if(!(c instanceof ZForms.Widget.Text.Number)){return}var e=this.__base(c,d);if(this.isTemplate()){return e}var f=this.createControl(c.oElement.id,this.oScaleElement);this.aControls.push({oElement:f.oElement,oValueElement:f.oValueElement,dPosition:null,bSelected:false});this.createRangeElements(this.aControls.length-1,this.oContainer);var g=this,d=this.getChildren().length-1;Common.Event.add(c.oElement,this.__self.DOM_EVENT_TYPE_FOCUS,function(){g.iFocusedChildIndex=d});Common.Event.add(c.oElement,this.__self.DOM_EVENT_TYPE_BLUR,function(){g.iFocusedChildIndex=-1;g.fSyncHandler(d)});c.setValue=function(a,b){if(a.isGreater(g.getMax())){a.set(g.getMax())}else if(a.isLess(g.getMin())){a.set(g.getMin())}ZForms.Widget.Text.Number.prototype.setValue.call(c,a);if(!b){g.fSyncHandler(d)}};c.disable=function(a){if(!ZForms.Widget.prototype.disable.call(this,a)){return false}g.disableControlByIndex(d)};c.enable=function(a){if(!ZForms.Widget.prototype.enable.call(this,a)){return false}g.enableControlByIndex(d)};this.setCurrentControlIndex(d);this.setValue(c.getValue());return e},

	addExtendedHandlers:function(){var c=this;this.fClickHandler=function(a){var a=Common.Event.normalize(a),iNearestControlIndex=c.getNearestControlIndex(a);if(iNearestControlIndex<0){return iNearestControlIndex}c.__self.setActiveIndex(c.iIndex);c.setCurrentControlIndex(iNearestControlIndex);c.drag(a);return iNearestControlIndex};this.fDragStartHandler=function(a){c.dragStart(a)};this.fDragHandler=function(a){c.drag(Common.Event.normalize(a))};this.fDragEndHandler=function(a){c.dragEnd(Common.Event.normalize(a))};this.fNullHandler=function(a){Common.Event.cancel(a)};this.fSyncHandler=function(a){c.setCurrentControlIndex(a);c.setValue(c.getChildren()[a].getValue(),true)};Common.Event.add(this.oContainer,this.__self.DOM_EVENT_TYPE_MOUSEDOWN,function(a){Common.Event.cancel(a);if(c.iFocusedChildIndex>-1){c.aChildren[c.iFocusedChildIndex].oElement.blur()}var b=c.fClickHandler(a);if(b>=0){c.fDragStartHandler(b)}})},

	getMin:function(){return this.dMin},

	getMax:function(){return this.dMax},

	getCurrentControl:function(){return this.aControls[this.iCurrentControlIndex]},

	getCurrentControlIndex:function(){return this.iCurrentControlIndex},

	setCurrentControlIndex:function(a){if(this.getCurrentControlIndex()==a){return}if(this.getCurrentControlIndex()>-1){Common.Class.remove(this.getCurrentControl().oElement,this.__self.CLASS_NAME_CONTROL_ELEMENT_SELECTED)}this.iCurrentControlIndex=a;Common.Class.add(this.getCurrentControl().oElement,this.__self.CLASS_NAME_CONTROL_ELEMENT_SELECTED)},

	getNearestControlIndex:function(a){this.updateContainerOffset();var b=this.calculateValueByOffset(this.calculateOffset(a)),iResult=-1,dMinDifference=Math.abs(this.getMax()-this.getMin());for(var i=0,dDifference;i<this.aChildren.length;i++){if(!this.aChildren[i].isEnabled()){continue}dDifference=Math.abs(this.aChildren[i].getValue().get()-b.get());if(dDifference<dMinDifference||(Math.abs(dDifference-dMinDifference)<0.00001&&this.aChildren[i].getValue().get()<b.get())){dMinDifference=dDifference;iResult=i}}return iResult},

	dragStart:function(a){if(!this.isEnabled()||!this.getChildren()[a].isEnabled()){return false}this.setCurrentControlIndex(a);this.updateContainerOffset();Common.Event.add(document,this.__self.DOM_EVENT_TYPE_SELECTSTART,this.fNullHandler);Common.Event.add(document,this.__self.DOM_EVENT_TYPE_MOUSEMOVE,this.fDragHandler);Common.Event.add(document,this.__self.DOM_EVENT_TYPE_MOUSEUP,this.fDragEndHandler)},

	drag:function(a){if(!this.isEnabled()){return false}this.updateContainerOffset();this.setValue(this.calculateValueByOffset(this.calculateOffset(a)))},

	dragEnd:function(){Common.Event.remove(document,this.__self.DOM_EVENT_TYPE_MOUSEMOVE,this.fDragHandler);Common.Event.remove(document,this.__self.DOM_EVENT_TYPE_MOUSEUP,this.fDragEndHandler);Common.Event.remove(document,this.__self.DOM_EVENT_TYPE_SELECTSTART,this.fNullHandler)},

	setValue:function(a,b){if(!this.getCurrentControl()){return}var c=this.findSlideRuleIndexByValue(a),oSlideRule=this.getSlideRuleByIndex(c),oPrevSlideRule=this.getSlideRuleByIndex(c-1),oNextSlideRule=this.getSlideRuleByIndex(c+1),dNewValue=parseFloat((Math.round((a.get()-oSlideRule.dValue)/oSlideRule.dStep)*oSlideRule.dStep+oSlideRule.dValue).toFixed(8)),oPrevControlWidget=this.getChildren()[this.getCurrentControlIndex()-1],oNextControlWidget=this.getChildren()[this.getCurrentControlIndex()+1],oChild;if(oPrevSlideRule&&dNewValue<oPrevSlideRule.dValue){dNewValue=oPrevSlideRule.dValue}else if(oNextSlideRule&&dNewValue>oNextSlideRule.dValue){dNewValue=oNextSlideRule.dValue}if(dNewValue<this.getMin()){dNewValue=this.getMin()}if(oPrevControlWidget&&oPrevControlWidget.getValue().get()>dNewValue){if(b&&this.getChildren()[this.getCurrentControlIndex()-1].isEnabled()){oChild=this.getChildren()[this.getCurrentControlIndex()];oChild.setValue(oChild.createValue(parseFloat(dNewValue)),true);this.iCurrentControlIndex--;this.setValue(oChild.createValue(parseFloat(dNewValue)),b);this.iCurrentControlIndex++}dNewValue=oPrevControlWidget.getValue().get()}else if(oNextControlWidget&&oNextControlWidget.getValue().get()<dNewValue){if(b&&this.getChildren()[this.getCurrentControlIndex()+1].isEnabled()){oChild=this.getChildren()[this.getCurrentControlIndex()];oChild.setValue(oChild.createValue(parseFloat(dNewValue)),true);this.iCurrentControlIndex++;this.setValue(oChild.createValue(parseFloat(dNewValue)),b);this.iCurrentControlIndex--}dNewValue=oNextControlWidget.getValue().get()}oChild=this.getChildren()[this.getCurrentControlIndex()];oChild.setValue(oChild.createValue(parseFloat(dNewValue)),true);this.syncControlElement()},

	syncControlElement:function(){var a=this.calculatePositionByValue(this.getChildren()[this.getCurrentControlIndex()].getValue());if(a==this.getCurrentControl().dPosition){return}this.getCurrentControl().dPosition=a;this.updateControlElement();this.updateRanges();this.updateBounds()},

	updateControlElement:function(){var a=this.getCurrentControl();a.oElement.style.left=Math.round(a.dPosition)+'%';a.oValueElement.style.left=Math.round(a.dPosition)+'%';a.oValueElement.innerHTML=this.getChildren()[this.getCurrentControlIndex()].getValue().get().formatNumber()},

	updateRanges:function(){var a=this.getCurrentControlIndex(),oCurrentControl=this.getCurrentControl();this.moveRangeElement(oCurrentControl.oLeftRangeElement,a>0?this.aControls[a-1].dPosition:0,oCurrentControl.dPosition);this.moveRangeElement(oCurrentControl.oRightRangeElement,oCurrentControl.dPosition,a<this.aControls.length-1?this.aControls[a+1].dPosition:100)},

	moveRangeElement:function(a,b,c){Common.Dom.setStyle(a,'left: '+Math.round(b)+'%;'+'width: '+(Math.round(c)-Math.round(b))+'%')},

	updateBounds:function(){var c=[],aChildren=this.getChildren(),fCompareFunction=function(a,b){return a.dValue==b};for(var i=0,dValue;i<aChildren.length;i++){dValue=parseFloat(aChildren[i].getValue().get());c.push(dValue);if(this.aControls[i].bSelected){if(!this.aMarks.contains(dValue,fCompareFunction)){Common.Class.remove(this.aControls[i].oValueElement,this.__self.CLASS_NAME_VALUE_ELEMENT_SELECTED);this.aControls[i].bSelected=false}}else if(this.aMarks.contains(dValue,fCompareFunction)){Common.Class.add(this.aControls[i].oValueElement,this.__self.CLASS_NAME_VALUE_ELEMENT_SELECTED);this.aControls[i].bSelected=true}}for(var i=0;i<this.aMarks.length;i++){if(this.aMarks[i].bSelected){if(!c.contains(this.aMarks[i].dValue)){Common.Class.remove(this.aMarks[i].oElement,this.__self.CLASS_NAME_MARK_ELEMENT_SELECTED);this.aMarks[i].bSelected=false}}else if(c.contains(this.aMarks[i].dValue)){Common.Class.add(this.aMarks[i].oElement,this.__self.CLASS_NAME_MARK_ELEMENT_SELECTED);this.aMarks[i].bSelected=true}}},

	next:function(){if(!this.isEnabled()||!this.getChildren()[this.getCurrentControlIndex()].isEnabled()){return false}var a=this.getChildren()[this.getCurrentControlIndex()].getValue();this.setValue(new ZForms.Value.Number(parseFloat(a.get())+parseFloat(this.findNextStepByValue(a))))},

	prev:function(){if(!this.isEnabled()||!this.getChildren()[this.getCurrentControlIndex()].isEnabled()){return false}var a=this.getChildren()[this.getCurrentControlIndex()].getValue();this.setValue(new ZForms.Value.Number(parseFloat(a.get())-parseFloat(this.findPrevStepByValue(a))))},

	updateContainerOffset:function(){this.oContainerOffset=Common.Dom.getAbsoluteCoords(this.oContainer)},

	calculateOffset:function(a){return Common.Event.getAbsoluteCoords(a).iLeft-this.oContainerOffset.iLeft},

	calculatePositionByValue:function(a){var b=this.findSlideRuleIndexByValue(a),oSlideRuleFrom=this.getSlideRuleByIndex(b),oSlideRuleTo=this.getSlideRuleByIndex(b+1);return(a.get()-oSlideRuleFrom.dValue)/(oSlideRuleTo.dValue-oSlideRuleFrom.dValue)*(oSlideRuleTo.dPercent-oSlideRuleFrom.dPercent)+oSlideRuleFrom.dPercent},

	calculateValueByOffset:function(a){var b=this.calculatePercentByOffset(a);if(b>100){b=100}else if(b<0){b=0}var c=this.findSlideRuleIndexByPercent(b),oSlideRuleFrom=this.getSlideRuleByIndex(c),oSlideRuleTo=this.getSlideRuleByIndex(c+1);return new ZForms.Value.Number((b-this.aSlideRules[c].dPercent)/(oSlideRuleTo.dPercent-oSlideRuleFrom.dPercent)*(oSlideRuleTo.dValue-oSlideRuleFrom.dValue)+oSlideRuleFrom.dValue)},

	calculatePercentByOffset:function(a){return a/this.oContainer.offsetWidth*100},

	findSlideRuleIndexByPercent:function(a){if(a==0){return 0}for(var i=0;i<this.aSlideRules.length;i++){if(this.aSlideRules[i].dPercent>=a){return i-1}}return this.aSlideRules.length-2},

	findSlideRuleIndexByValue:function(a){if(a.get()==this.getMin()){return 0}for(var i=1;i<this.aSlideRules.length;i++){if(this.aSlideRules[i].dValue>=a.get()){return i-1}}return this.aSlideRules.length-2},

	findNextStepByValue:function(a){if(a.get()==this.getMin()){return this.aSlideRules[0].dStep}for(var i=0;i<this.aSlideRules.length;i++){if(this.aSlideRules[i].dValue==a.get()){return this.aSlideRules[i].dStep}else if(this.aSlideRules[i].dValue>a.get()){return this.aSlideRules[i-1].dStep}}return this.aSlideRules[this.aSlideRules.length-1].dStep},

	findPrevStepByValue:function(a){if(a.get()==this.getMin()){return this.aSlideRules[0].dStep}for(var i=0;i<this.aSlideRules.length;i++){if(this.aSlideRules[i].dValue>=a.get()){return this.aSlideRules[i-1].dStep}}return this.aSlideRules[this.aSlideRules.length-1].dStep},

	getSlideRuleByIndex:function(a){return this.aSlideRules[a]},

	disableControlByIndex:function(a){Common.Class.add(this.aControls[a].oElement,this.__self.CLASS_NAME_CONTROL_ELEMENT_DISABLED);Common.Class.add(this.aControls[a].oValueElement,this.__self.CLASS_NAME_VALUE_ELEMENT_DISABLED)},

	enableControlByIndex:function(a){Common.Class.remove(this.aControls[a].oElement,this.__self.CLASS_NAME_CONTROL_ELEMENT_DISABLED);Common.Class.remove(this.aControls[a].oValueElement,this.__self.CLASS_NAME_VALUE_ELEMENT_DISABLED)},

	destruct:function(){this.oContainer=null;this.oScaleElement=null;if(!this.isTemplate()){for(i=0;i<this.aMarks.length;i++){this.aMarks[i].oElement=null}for(i=0;i<this.aControls.length;i++){this.aControls[i].oElement=null;this.aControls[i].oValueElement=null;this.aControls[i].oLeftRangeElement=null;this.aControls[i].oRightRangeElement=null}}this.__base()}},{CLASS_NAME_SLIDER_CONTAINER:'slider',CLASS_NAME_SLIDER:'slider-horizontal',CLASS_NAME_SLIDER_SCALE:'slider-scale',CLASS_NAME_CONTROL_ELEMENT:'slider-control',CLASS_NAME_CONTROL_ELEMENT_SELECTED:'slider-control-selected',CLASS_NAME_CONTROL_ELEMENT_DISABLED:'slider-control-disabled',CLASS_NAME_VALUE_ELEMENT:'slider-value',CLASS_NAME_VALUE_ELEMENT_SELECTED:'slider-value-selected',CLASS_NAME_VALUE_ELEMENT_DISABLED:'slider-value-disabled',CLASS_NAME_MARK_ELEMENT:'slider-mark',CLASS_NAME_MARK_ELEMENT_SELECTED:'slider-mark-selected',CLASS_NAME_RANGE_ELEMENT:'slider-range',CLASS_NAME_INITED:'slider-inited',aAll:[],iActiveIndex:0,

	add:function(b){if(!(b instanceof this)){return}var c=this;if(this.aAll.isEmpty()){Common.Event.add(document,this.DOM_EVENT_TYPE_KEYUP,function(a){c.processKeyPress(a)})}this.aAll.push(b);return this.aAll.length-1},

	setActiveIndex:function(a){this.iActiveIndex=a},

	processKeyPress:function(a){var a=Common.Event.normalize(a),oSliderInput=this.aAll[this.iActiveIndex];if(!oSliderInput){return}switch(a.iKeyCode){case this.KEY_CODE_ARROW_RIGHT:oSliderInput.next();break;case this.KEY_CODE_ARROW_LEFT:oSliderInput.prev();break;default:break}}
});

ZForms.Widget.Container.Slider.Vertical=ZForms.Widget.Container.Slider.inheritTo({
	setupMarkElementPosition:function(a,b){a.style.bottom=b+'%'},

	updateControlElement:function(){var a=this.getCurrentControl();a.oElement.style.bottom=Math.round(a.dPosition)+'%';a.oValueElement.style.bottom=Math.round(a.dPosition)+'%';a.oValueElement.innerHTML=this.getChildren()[this.getCurrentControlIndex()].getValue().get().formatNumber()},

	moveRangeElement:function(a,b,c){var d=Math.round(c)-Math.round(b);Common.Dom.setStyle(a,'bottom: '+Math.round(b)+'%;'+'height: '+(d>0?(a.parentNode.offsetHeight*d/100+'px;'):'0px;'))},

	calculateOffset:function(a){return this.oContainerOffset.iTop+this.oContainer.offsetHeight-Common.Event.getAbsoluteCoords(a).iTop},

	calculatePercentByOffset:function(a){return a/this.oContainer.offsetHeight*100}},{CLASS_NAME_SLIDER:'slider-vertical'
});

ZForms.Widget.Button=ZForms.Widget.inheritTo({
	__constructor:function(b,c,d){this.__base(b,c,d);this.fHandler=null;this.fDisableHandler=function(a){Common.Event.cancel(a)}},

	hasValue:function(){return false},

	setHandler:function(a){if(this.fHandler){Common.Event.remove(this.oElement,this.__self.DOM_EVENT_TYPE_CLICK,this.fHandler)}this.fHandler=a;if(this.isEnabled()){this.enable(false,true)}},

	enable:function(a,b){var c=this.__base(a);if(!(c||b)){return false}if((b||c)&&this.fHandler){Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_CLICK,this.fHandler)}if(c){Common.Event.remove([this.oElement,this.oClassElement],[this.__self.DOM_EVENT_TYPE_CLICK,this.__self.DOM_EVENT_TYPE_MOUSEDOWN,this.__self.DOM_EVENT_TYPE_SELECTSTART],this.fDisableHandler)}return c},

	disable:function(a){if(!this.__base(a)){return false}if(this.fHandler){Common.Event.remove(this.oElement,this.__self.DOM_EVENT_TYPE_CLICK,this.fHandler)}Common.Event.add([this.oElement,this.oClassElement],[this.__self.DOM_EVENT_TYPE_CLICK,this.__self.DOM_EVENT_TYPE_MOUSEDOWN,this.__self.DOM_EVENT_TYPE_SELECTSTART],this.fDisableHandler);return true}},{CLASS_NAME_BUTTON:'button'
});

ZForms.Widget.Button.Submit=ZForms.Widget.Button.inheritTo({
	__constructor:function(a,b,c){this.__base(a,b,c)},

	getDefaultOptions:function(){return Common.Object.extend(this.__base(),{bDisableOnSubmit:true},true)},

	setForm:function(a){this.__base(a);this.oForm.addSubmit(this)},

	prepareForSubmit:function(){if(this.oOptions.bDisableOnSubmit){this.disable()}this.__base()},

	addDependence:function(a){}
});

ZForms.Widget.Container.Form=ZForms.Widget.Container.inheritTo({
	__constructor:function(a,b,c){this.__base(a,b,c);this.oForm=this;this.aWidgets=[];this.aWidgets[this.getId()]=this;this.aSubmits=[];this.iChangedCounter=0;this.bSubmitted=false;this.addExtendedHandlers();ZForms.aForms[this.getId()]=this},

	getDefaultOptions:function(){return Common.Object.extend(this.__base(),{bUpdatableSubmit:true,bCheckForValid:true,bCheckForChanged:false,bPreventSubmit:false},true)},

	addExtendedHandlers:function(){var b=this;Common.Event.add(this.oElement,this.__self.DOM_EVENT_TYPE_SUBMIT,function(a){if(!b.checkForSubmit()||b.bSubmitted){return Common.Event.cancel(a)}b.notifyOuterObservers(ZForms.EVENT_TYPE_ON_BEFORE_SUBMIT);if(b.oOptions.bPreventSubmit){return Common.Event.cancel(a)}b.prepareForSubmit();b.bSubmitted=true});Common.Event.add(window,Common.Browser.isIE()?this.__self.DOM_EVENT_TYPE_BEFOREUNLOAD:this.__self.DOM_EVENT_TYPE_UNLOAD,function(){b.destruct()})},

	checkForSubmit:function(){if(this.isReadyForSubmit()){return true}this.getFirstErrorWidget().focus();this.addClass(this.__self.CLASS_NAME_SUBMITTED);return false},

	init:function(){var a=this;setTimeout(function(){ZForms.Widget.Container.prototype.init.call(a);a.updateSubmit()},0)},

	setForm:function(a){},

	increaseChangedCounter:function(){this.iChangedCounter++},

	decreaseChangedCounter:function(){this.iChangedCounter--},

	isChanged:function(){return this.iChangedCounter>0},

	addChild:function(a){a.setForm(this);return this.__base(a)},

	addSubmit:function(a){if(!(a instanceof ZForms.Widget.Button.Submit)){return}this.aSubmits.push(a)},

	updateSubmit:function(){if(!(this.oOptions.bUpdatableSubmit&&this.aSubmits.length>0)){return}if(this.shouldEnableSubmit()){this.enableSubmit()}else{this.disableSubmit()}},

	shouldEnableSubmit:function(){return this.isReadyForSubmit()&&(!this.oOptions.bCheckForChanged||this.isChanged())},

	enableSubmit:function(){for(var i=0;i<this.aSubmits.length;i++){this.aSubmits[i].enable()}},

	disableSubmit:function(){for(var i=0;i<this.aSubmits.length;i++){this.aSubmits[i].disable()}},

	addWidget:function(a){this.aWidgets[a.getId()]=a},

	removeWidget:function(a){delete this.aWidgets[a.getId()]},

	getWidgetById:function(a){return this.aWidgets[a]},

	getWidgets:function(){return this.aWidgets},

	isReadyForSubmit:function(){var a=this.aWidgets;for(var b in a){if(!a.hasOwnProperty(b)||a[b]==this){continue}if(!a[b].isReadyForSubmit()){return false}}return true},

	getFirstErrorWidget:function(){for(var a in this.aWidgets){if(!this.aWidgets.hasOwnProperty(a)){continue}oWidget=this.aWidgets[a];if(oWidget.isEnabled()&&(oWidget.bRequired||(this.oOptions.bCheckForValid&&!oWidget.bValid))){return oWidget}}},

	reset:function(){this.oElement.reset()}},{CLASS_NAME_SUBMITTED:'submitted',DOM_EVENT_TYPE_SUBMIT:'submit'
});

ZForms.Widget.Container.Multiplicator=ZForms.Widget.Container.inheritTo({
	__constructor:function(a,b,c){var a=a||document.createElement('div');this.oTemplate=null;this.sButtonAddId=c.sButtonAddId;this.sButtonRemoveId=c.sButtonRemoveId;this.sButtonUpId=c.sButtonUpId;this.sButtonDownId=c.sButtonDownId;this.sInitialChildrenHash=null;this.sLastProcessedChildrenHash=null;this.__base(a,b,c)},

	getDefaultOptions:function(){return Common.Object.extend(this.__base(),{iMin:1,iMax:10},true)},

	addChild:function(a,b){var c=b>-1?b:this.aChildren.length,oMultiplier=new ZForms.Multiplier(this,a),sPostfix=(c>0?'_'+c:'');if(this.sButtonAddId){oMultiplier.addAddButton(ZForms.createButton(document.getElementById(this.sButtonAddId+sPostfix)))}if(this.sButtonRemoveId){oMultiplier.addRemoveButton(ZForms.createButton(document.getElementById(this.sButtonRemoveId+sPostfix)))}if(this.sButtonUpId){oMultiplier.addUpButton(ZForms.createButton(document.getElementById(this.sButtonUpId+sPostfix)))}if(this.sButtonDownId){oMultiplier.addDownButton(ZForms.createButton(document.getElementById(this.sButtonDownId+sPostfix)))}a.setMultiplier(oMultiplier);this.updateChildIndex(a,0,c);return this.__base(a,b)},

	addTemplate:function(a){this.oTemplate=a;return a},

	normalizeTemplateAttributes:function(a){var b=a.oClassElement.getElementsByTagName('script');while(b.length>0){b[0].parentNode.removeChild(b[0])}this.replacePostfixAtElement(a.oClassElement,this.oOptions.iMax+1);a.setId(a.oElement.id)},

	calculateCurrentChildrenHash:function(){var a='';for(var i=0,iLength=this.aChildren.length;i<iLength;i++){a+=Common.Dom.getUniqueId(this.aChildren[i].oElement)}return a},

	processChildrenHashChanged:function(){var a=this.calculateCurrentChildrenHash();if(this.sInitialChildrenHash==a){if(this.sLastProcessedChildrenHash!=this.sInitialChildrenHash){this.oForm.decreaseChangedCounter();this.oForm.updateSubmit()}}else if(this.sLastProcessedChildrenHash==this.sInitialChildrenHash){this.oForm.increaseChangedCounter();this.oForm.updateSubmit()}this.sLastProcessedChildrenHash=a},

	init:function(){this.__base();this.oTemplate.hide();this.oTemplate.disable();this.normalizeTemplateAttributes(this.oTemplate);this.updateMultipliers();this.sInitialChildrenHash=this.calculateCurrentChildrenHash();this.sLastProcessedChildrenHash=this.sInitialChildrenHash},

	updateMultipliers:function(){for(var i=0;i<this.aChildren.length;i++){this.aChildren[i].getMultiplier().updateState(this.aChildren.length<this.oOptions.iMax,this.aChildren.length>this.oOptions.iMin,i>0,i<this.aChildren.length-1)}},

	add:function(a){var b=this.aChildren.indexOf(a)+1,oNewElement=this.oTemplate.oClassElement.cloneNode(true);this.increaseChildrenPostfix(b);this.removePostfixFromElement(oNewElement);this.addPostfixToElement(oNewElement,b);if(a.oClassElement.nextSibling){a.oClassElement.parentNode.insertBefore(oNewElement,a.oClassElement.nextSibling)}else{a.oClassElement.parentNode.appendChild(oNewElement)}var c=this.oTemplate.clone(document.getElementById(this.oTemplate.oElement.id.match(this.__self.REG_EXP_REPLACE)[1]+'_'+b),document.getElementById(this.oTemplate.oClassElement.id.match(this.__self.REG_EXP_REPLACE)[1]+'_'+b),b);this.addChild(c,b);c.disable();c.enable();this.addInitedClassName(c);c.show();this.updateMultipliers();this.addTemplateDependencies(this.oTemplate,c,c);c.afterClone();this.repaintFix();this.processChildrenHashChanged()},

	addInitedClassName:function(a){if(a instanceof ZForms.Widget.Container){for(var i=0;i<a.aChildren.length;i++){this.addInitedClassName(a.aChildren[i])}}a.addClass(a.getInitedClassName())},

	addTemplateDependencies:function(a,b,c){this.addDependenciesFrom(a,b,c);this.addDependenciesTo(a,b,c);if(a instanceof ZForms.Widget.Container){for(var i=0;i<a.aChildren.length;i++){this.addTemplateDependencies(a.aChildren[i],b.aChildren[i],c)}}},

	addDependenciesFrom:function(a,b,c){for(var i=0,aDependencies=a.getDependencies(),oFrom,oDependenceCloned;i<aDependencies.length;i++){oFrom=this.findCorrespondingWidgetByTemplate(aDependencies[i].getFrom(),this.oTemplate,c)||aDependencies[i].getFrom();oDependenceCloned=aDependencies[i].clone(oFrom);if(oDependenceCloned instanceof ZForms.Dependence.Function&&aDependencies[i].getFunction().mArgument instanceof ZForms.Widget){oDependenceCloned.getFunction().mArgument=this.findCorrespondingWidgetByTemplate(aDependencies[i].getFunction().mArgument,this.oTemplate,c)||aDependencies[i].getFunction().mArgument;oDependenceCloned.getFunction().oWidget=this.findCorrespondingWidgetByTemplate(aDependencies[i].getFunction().oWidget,this.oTemplate,c)||aDependencies[i].getFunction().oWidget;oDependenceCloned.getFunction().sType=aDependencies[i].getFunction().sType;oDependenceCloned.getFunction().sFunctionName=aDependencies[i].getFunction().sFunctionName}b.addDependence(oDependenceCloned);oFrom.processEvents(true,true)}},

	addDependenciesTo:function(a,b,c){for(var i=0,aDependencies;i<a.aObservers.length;i++){if(this.findCorrespondingWidgetByTemplate(a.aObservers[i],this.oTemplate,c)){continue}aDependencies=a.aObservers[i].getDependencies();for(var j=0;j<aDependencies.length;j++){if(aDependencies[j].getFrom()==a){a.aObservers[i].addDependence(aDependencies[j].clone(b))}}}},

	findCorrespondingWidgetByTemplate:function(a,b,c){if(b==a){return c}if(b instanceof ZForms.Widget.Container){for(var i=0,oFoundedWidget;i<b.aChildren.length;i++){oFoundedWidget=this.findCorrespondingWidgetByTemplate(a,b.aChildren[i],c.aChildren[i]);if(oFoundedWidget){return oFoundedWidget}}}},

	remove:function(a){var b=this.aChildren.indexOf(a);a.oClassElement.parentNode.removeChild(a.oClassElement);this.decreaseChildrenPostfix(b+1);this.removeChild(a);this.processEvents(true);this.updateMultipliers();this.repaintFix();this.processChildrenHashChanged()},

	up:function(a){var b=this.aChildren.indexOf(a);this.aChildren[b-1].oClassElement.parentNode.insertBefore(a.oClassElement.parentNode.removeChild(a.oClassElement),this.aChildren[b-1].oClassElement);this.aChildren.remove(a);this.aChildren.splice(b-1,0,a);if(b-1>0){this.replacePostfixAtElement(this.aChildren[b].oClassElement,b)}else{this.addPostfixToElement(this.aChildren[b].oClassElement,b)}this.updateChildIndex(this.aChildren[b-1],b,b-1);this.replacePostfixAtElement(this.aChildren[b-1].oClassElement,b-1);this.aChildren[b-1].updateElements(b-1);this.updateChildIndex(this.aChildren[b],b-1,b);this.aChildren[b].updateElements(b);this.updateMultipliers();this.repaintFix();this.processChildrenHashChanged()},

	down:function(a){var b=this.aChildren.indexOf(a);if(this.aChildren[b+2]){this.aChildren[b+2].oClassElement.parentNode.insertBefore(a.oClassElement.parentNode.removeChild(a.oClassElement),this.aChildren[b+2].oClassElement)}else{this.aChildren[b+1].oClassElement.parentNode.insertBefore(a.oClassElement.parentNode.removeChild(a.oClassElement),this.oTemplate.oClassElement)}this.aChildren.remove(a);this.aChildren.splice(b+1,0,a);this.updateChildIndex(this.aChildren[b],b+1,b);this.replacePostfixAtElement(this.aChildren[b].oClassElement,b);this.aChildren[b].updateElements(b);this.updateChildIndex(this.aChildren[b+1],b,b+1);if(b>0){this.replacePostfixAtElement(this.aChildren[b+1].oClassElement,b+1)}else{this.addPostfixToElement(this.aChildren[b+1].oClassElement,b+1)}this.aChildren[b+1].updateElements(b+1);this.updateMultipliers();this.repaintFix();this.processChildrenHashChanged()},

	updateChildIndex:function(a,b,c){a.replaceClass(this.__self.CHILD_INDEX_CLASS_NAME_PREFIX+b,this.__self.CHILD_INDEX_CLASS_NAME_PREFIX+c)},

	increaseChildrenPostfix:function(a){for(var i=this.aChildren.length-1;i>=a;i--){this.replacePostfixAtElement(this.aChildren[i].oClassElement,i+1);this.aChildren[i].updateElements(i+1);this.updateChildIndex(this.aChildren[i],i,i+1)}},

	decreaseChildrenPostfix:function(a){for(var i=a;i<this.aChildren.length;i++){this.replacePostfixAtElement(this.aChildren[i].oClassElement,i-1);this.aChildren[i].updateElements(i-1);this.updateChildIndex(this.aChildren[i],i,i-1)}},

	replacePostfixAtElement:function(a,b){for(var i=0;i<a.childNodes.length;i++){this.replacePostfixAtElement(a.childNodes[i],b)}this.replacePostfixAtNode(a,b)},

	replacePostfixAtNode:function(a,b){if(a.id){a.id=a.id.replace(this.__self.REG_EXP_REPLACE,'$1'+(b>0?'_'+b:''))}if(a.htmlFor){a.htmlFor=a.htmlFor.replace(this.__self.REG_EXP_REPLACE,'$1'+(b>0?'_'+b:''))}if(a.name){a.name=a.name.replace(this.__self.REG_EXP_REPLACE,'$1'+(b>0?'_'+b:'')+'$2');this.fixNode(a)}},

	removePostfixFromElement:function(a){for(var i=0;i<a.childNodes.length;i++){this.removePostfixFromElement(a.childNodes[i])}this.removePostfixFromNode(a)},

	removePostfixFromNode:function(a){if(a.name){a.name=a.name.replace(this.__self.REG_EXP_REPLACE,'$1$2')}if(a.id){a.id=a.id.replace(this.__self.REG_EXP_REPLACE,'$1')}if(a.htmlFor){a.htmlFor=a.htmlFor.replace(this.__self.REG_EXP_REPLACE,'$1')}},

	addPostfixToElement:function(a,b){for(var i=0;i<a.childNodes.length;i++){this.addPostfixToElement(a.childNodes[i],b)}this.addPostfixToNode(a,b)},

	addPostfixToNode:function(a,b){if(a.id){a.id+='_'+b}if(a.htmlFor){a.htmlFor+='_'+b}if(a.name){a.name=a.name.replace(/^([^\[]+)(\[\])?$/,'$1_'+b+'$2');this.fixNode(a)}},

	fixNode:function(a){var b=a.type.toLowerCase();if(!Common.Browser.isIE()||!(b=='text'||b=='radio'||b=='checkbox')){return}var c={'type':a.type,'name':a.name,'id':a.id,'class':a.className,'size':a.size,'maxlength':a.maxLength,'value':a.value,'style':a.style.cssText};if(a.checked){c.checked='checked'}a.parentNode.insertBefore(Common.Dom.createElement('input',c),a);a=a.parentNode.removeChild(a);a.outerHTML=''},

	destruct:function(){if(this.oTemplate){this.oTemplate.destruct()}this.__base()},

	repaintFix:function(){if(document.compatMode){return}document.body.className+=''}},{POSTFIX_ID:'_multiplicator',REG_EXP_REPLACE:new RegExp('^(.+)_\\d+(\\[\\])?$'),CHILD_INDEX_CLASS_NAME_PREFIX:'child_'
});

ZForms.Multiplier=Abstract.inheritTo({
	__constructor:function(a,b){this.oMultiplicator=a;this.oWidget=b;this.bCanAdd=true;this.bCanRemove=true;this.bCanUp=true;this.bCanDown=true;this.oAddButton=null;this.oRemoveButton=null;this.oUpButton=null;this.oDownButton=null;this.bDisabledByOuter=false},

	addAddButton:function(a){this.oAddButton=a;var b=this;a.setHandler(function(){b.oMultiplicator.add(b.oWidget);return false})},

	addRemoveButton:function(a){this.oRemoveButton=a;var b=this;a.setHandler(function(){b.oMultiplicator.remove(b.oWidget);return false})},

	addUpButton:function(a){this.oUpButton=a;var b=this;a.setHandler(function(){b.oMultiplicator.up(b.oWidget);return false})},

	addDownButton:function(a){this.oDownButton=a;var b=this;a.setHandler(function(){b.oMultiplicator.down(b.oWidget);return false})},

	enableByOuter:function(){this.bDisabledByOuter=false;if(this.bCanAdd){this.enableAdd()}if(this.bCanRemove){this.enableRemove()}},

	disableByOuter:function(){this.bDisabledByOuter=true;if(this.oAddButton){this.oAddButton.disable()}if(this.oRemoveButton){this.oRemoveButton.disable()}},

	enableAdd:function(){this.bCanAdd=true;if(this.bDisabledByOuter){return}if(this.oAddButton){this.oAddButton.enable()}},

	disableAdd:function(){this.bCanAdd=false;if(this.oAddButton){this.oAddButton.disable()}},

	enableRemove:function(){this.bCanRemove=true;if(this.bDisabledByOuter){return}if(this.oRemoveButton){this.oRemoveButton.enable()}},

	disableRemove:function(){this.bCanRemove=false;if(this.oRemoveButton){this.oRemoveButton.disable()}},

	enableUp:function(){this.bCanUp=true;if(this.bDisabledByOuter){return}if(this.oUpButton){this.oUpButton.enable()}},

	disableUp:function(){this.bCanUp=false;if(this.oUpButton){this.oUpButton.disable()}},

	enableDown:function(){this.bCanDown=true;if(this.bDisabledByOuter){return}if(this.oDownButton){this.oDownButton.enable()}},

	disableDown:function(){this.bCanDown=false;if(this.oDownButton){this.oDownButton.disable()}},

	updateState:function(a,b,c,d){if(a){this.enableAdd()}else{this.disableAdd()}if(b){this.enableRemove()}else{this.disableRemove()}if(c){this.enableUp()}else{this.disableUp()}if(d){this.enableDown()}else{this.disableDown()}},

	destruct:function(){if(this.oAddButton){this.oAddButton.destruct()}if(this.oRemoveButton){this.oRemoveButton.destruct()}if(this.oUpButton){this.oUpButton.destruct()}if(this.oDownButton){this.oDownButton.destruct()}}
});

ZForms.Dependence=Abstract.inheritTo({
	__constructor:function(a,b,c,d,e){this.iType=a;this.oFrom=b;this.sPattern=c;this.iLogic=d||this.__self.LOGIC_OR;this.bInverse=e||false},

	check:function(){if(this.oFrom.isTemplate()){return true}var a=this.oFrom.getValue().match(this.sPattern);return this.isInverse()?!a:a},

	getType:function(){return this.iType},

	getFrom:function(){return this.oFrom},

	getPattern:function(){return this.sPattern},

	getLogic:function(){return this.iLogic},

	isInverse:function(){return this.bInverse},

	clone:function(a){return new this.__self(this.getType(),a,this.getPattern(),this.getLogic(),this.isInverse())},

	getResult:function(){}},{TYPE_REQUIRED:1,TYPE_VALID:2,TYPE_ENABLE:3,TYPE_OPTIONS:4,TYPE_CLASS:5,TYPE_CHECK:6,LOGIC_OR:1,LOGIC_AND:2,COMPARE_FUNCTIONS:{'=':'isEqual','>':'isGreater','>=':'isGreaterOrEqual','<':'isLess','<=':'isLessOrEqual'}
});

ZForms.Dependence.Valid=ZForms.Dependence.inheritTo({
	__constructor:function(a,b,c,d){this.__base(this.__self.TYPE_VALID,a,b,c,d)},

	check:function(){if(this.oFrom.isTemplate()||this.oFrom.getValue().isEmpty()){return true}return this.__base()},

	clone:function(a){return new this.__self(a,this.getPattern(),this.getLogic(),this.isInverse())}
});

ZForms.Dependence.Options=ZForms.Dependence.inheritTo({
	__constructor:function(a,b,c,d,e){this.__base(a,b,null,d,e);this.aPatterns=c;this.aResult=[];},

	getPatterns:function(){return this.aPatterns},

	getPattern:function(){return this.aPatterns},

	check:function(){
		if(this.oFrom.isTemplate() || !this.aPatterns){return true}
		this.aResult=[];
		var a=this.oFrom.getValue(),bMatched=false;
		for(var i=0;i<this.aPatterns.length;i++){
			bMatched=a.match(this.aPatterns[i].rSource);
			if(this.bInverse?!bMatched:bMatched){
				this.aResult.push(this.aPatterns[i].rDestination)
			}
		}
		return true
	},

	getResult:function(){return this.aResult}
});

ZForms.Dependence.Required=ZForms.Dependence.inheritTo({
	__constructor:function(a,b,c,d,e){this.__base(this.__self.TYPE_REQUIRED,a,b,c,d);this.iMin=e||1;if(!(this.getFrom()instanceof ZForms.Widget.Container)){this.iMin=1}},

	getMin:function(){return this.iMin},

	check:function(){if(this.oFrom.isTemplate()){return true}var a=0,bHasRequiredChild=false,bHasEnabledChild=true,bResult=false;if(this.oFrom instanceof ZForms.Widget.Container.Group){for(var i=0;i<this.oFrom.aChildren.length;i++){if(this.oFrom.aChildren[i].isChecked()){a++}}}else if(this.oFrom instanceof ZForms.Widget.Container&&!(this.oFrom instanceof ZForms.Widget.Container.Date)){bHasEnabledChild=false;for(var i=0;i<this.oFrom.aChildren.length;i++){if(this.oFrom.aChildren[i].isEnabled()){bHasEnabledChild=true}else{continue}if(this.oFrom.aChildren[i]instanceof ZForms.Widget.Container&&!(this.oFrom.aChildren[i]instanceof ZForms.Widget.Container.Date)){if(this.oFrom.aChildren[i].isRequired()){bHasRequiredChild=true}else{var b=0;if(this.oFrom.aChildren[i]instanceof ZForms.Widget.Container.Group){for(var j=0;j<this.oFrom.aChildren[i].aChildren.length;j++){if(this.oFrom.aChildren[i].aChildren[j].isChecked()){b++}}}else{b=this.oFrom.aChildren[i].getCountChildrenByPattern(this.sPattern)}if(this.oFrom.aChildren[i]instanceof ZForms.Widget.Container.Multiplicator){a+=b}else if(b>0){a++}}}else if(this.oFrom.aChildren[i].isRequired()){bHasRequiredChild=true}else if(this.oFrom.aChildren[i].getValue().match(/\S+/)){a++}}}else if(this.oFrom.getValue().match(this.sPattern)){a++}bResult=!bHasRequiredChild&&(a>=this.iMin||!bHasEnabledChild);return this.isInverse()?!bResult:bResult},

	clone:function(a){return new this.__self(a,this.getPattern(),this.getLogic(),this.isInverse(),this.getMin())}
});

ZForms.Dependence.Class=ZForms.Dependence.inheritTo({
	__constructor:function(a,b,c){this.__base(this.__self.TYPE_CLASS,a,null,c,false);this.aPatternToClasses=b;this.aResult=[]},

	getPatternToClasses:function(){return this.aPatternToClasses},

	check:function(){if(this.oFrom.isTemplate()){return true}this.aResult=[];var a=this.oFrom.getValue();for(var i=0;i<this.aPatternToClasses.length;i++){this.aResult.push({sClassName:this.aPatternToClasses[i].sClassName,bMatched:a.match(this.aPatternToClasses[i].rPattern)})}return this.aResult.length>0},

	clone:function(a){return new this.__self(a,this.getPatternToClasses(),this.getLogic())},

	getResult:function(){return this.aResult}
});

ZForms.Dependence.Function=ZForms.Dependence.inheritTo({
	__constructor:function(a,b,c,d,e){this.__base(a,b,null,d,e);this.fFunction=c;this.aResult=[]},

	getFunction:function(){return this.fFunction},

	check:function(){if(this.oFrom.isTemplate()){return true}this.aResult=[];var a=this.fFunction(this.oFrom,this.aResult);return this.isInverse()?!a:a},

	getResult:function(){return this.aResult},

	clone:function(a){eval('var fClonedFunction = '+this.getFunction().toString());return new this.__self(this.getType(),a,fClonedFunction,this.getLogic(),this.isInverse())}
});

ZForms.DependenceGroup=Abstract.inheritTo({
	__constructor:function(a){this.iType=a;this.aDependencies=[]},

	getType:function(){return this.iType},

	addDependence:function(a){this.aDependencies.push(a)},

	removeDependence:function(a){this.aDependencies.remove(a)},

	getDependencies:function(){return this.aDependencies},

	check:function(){var a=this.aDependencies.length==0,bDependenceCheckResult=false;for(var i=0;i<this.aDependencies.length;i++){bDependenceCheckResult=this.aDependencies[i].check();if(bDependenceCheckResult&&this.aDependencies[i].getLogic()==ZForms.Dependence.LOGIC_OR){a=true;if(!(this.getType()==ZForms.Dependence.TYPE_CLASS||this.getType()==ZForms.Dependence.TYPE_OPTIONS)){break}}else if(!bDependenceCheckResult&&this.aDependencies[i].getLogic()==ZForms.Dependence.LOGIC_AND){a=false;break}else{a=bDependenceCheckResult}}return a},

	getResult:function(){for(var i=0,aResult=[],aDependencyResult;i<this.aDependencies.length;i++){aResult.push(this.aDependencies[i].getResult())}return aResult}
});

ZForms.DependenceProcessor=Abstract.inheritTo({
	__constructor:function(a){this.oWidget=a;this.aDependenceGroups=[];this.aCheckingOrder=[ZForms.Dependence.TYPE_ENABLE,ZForms.Dependence.TYPE_VALID,ZForms.Dependence.TYPE_REQUIRED,ZForms.Dependence.TYPE_OPTIONS,ZForms.Dependence.TYPE_CHECK,ZForms.Dependence.TYPE_CLASS]},

	addDependence:function(a){if(!this.hasDependenciesByType(a.getType())){this.aDependenceGroups[a.getType()]=new ZForms.DependenceGroup(a.getType())}this.aDependenceGroups[a.getType()].addDependence(a)},

	removeDependence:function(a){this.aDependenceGroups[a.getType()].removeDependence(a)},

	getDependencies:function(){var a=[];for(var i=0;i<this.aCheckingOrder.length;i++){if(!this.hasDependenciesByType(this.aCheckingOrder[i])){continue}a=a.concat(this.aDependenceGroups[this.aCheckingOrder[i]].getDependencies())}return a},

	hasDependenciesByType:function(a){return this.aDependenceGroups[a]&&this.aDependenceGroups[a].getDependencies().length>0?true:false},

	process:function(){if(this.oWidget.isTemplate()){return}for(var i=0;i<this.aCheckingOrder.length;i++){this.dispatchProcessDependencies(this.aCheckingOrder[i])}},

	dispatchProcessDependencies:function(a){if(!this.hasDependenciesByType(a)){return}switch(a){case ZForms.Dependence.TYPE_ENABLE:this.processEnableDependencies();break;case ZForms.Dependence.TYPE_VALID:this.processValidDependencies();break;case ZForms.Dependence.TYPE_REQUIRED:this.processRequiredDependencies();break;case ZForms.Dependence.TYPE_OPTIONS:case ZForms.Dependence.TYPE_CHECK:this.processOptionsDependencies(a);break;case ZForms.Dependence.TYPE_CLASS:this.processClassDependencies();break;default:break}},

	processEnableDependencies:function(){if(this.aDependenceGroups[ZForms.Dependence.TYPE_ENABLE].check()){this.oWidget.enable()}else{this.oWidget.disable()}},

	processValidDependencies:function(){if(this.aDependenceGroups[ZForms.Dependence.TYPE_VALID].check()){this.oWidget.setValid()}else{this.oWidget.setInvalid()}},

	processRequiredDependencies:function(){if(this.aDependenceGroups[ZForms.Dependence.TYPE_REQUIRED].check()&&this.oWidget.isValid()){this.oWidget.unsetRequired()}else{this.oWidget.setRequired()}},

	processOptionsDependencies:function(a){var b=this.aDependenceGroups[a].check(),aPatternGroups=this.aDependenceGroups[a].getResult();this.oWidget.enableOptionsByValue(aPatternGroups,this.aDependenceGroups[a].getDependencies()[0].getLogic()==ZForms.Dependence.LOGIC_OR,a==ZForms.Dependence.TYPE_CHECK)},

	processClassDependencies:function(){var a=this.aDependenceGroups[ZForms.Dependence.TYPE_CLASS].check(),aClassesGroups=this.aDependenceGroups[ZForms.Dependence.TYPE_CLASS].getResult(),bIntersect=this.aDependenceGroups[ZForms.Dependence.TYPE_CLASS].getDependencies()[0].getLogic()==ZForms.Dependence.LOGIC_AND,aClasses=[];for(var i=0;i<aClassesGroups.length;i++){aClasses=this.joinClassGroup(aClasses,aClassesGroups[i],bIntersect)}if(a&&aClasses.length==0){return}for(var i=0;i<aClasses.length;i++){if(aClasses[i].bMatched){this.oWidget.addClass(aClasses[i].sClassName)}else{this.oWidget.removeClass(aClasses[i].sClassName)}}},

	joinClassGroup:function(a,b,c){if(a.length==0){return b}for(var i=0,iLength=a.length;i<iLength;i++){for(var j=0;j<b.length;j++){if(a[i].sClassName==b[j].sClassName){if((!c&&b[j].bMatched)||(c&&!b[j].bMatched)){a[i]=b[j]}else{b[j]=a[i]}}else if(!a.contains(b[j])){a[a.length]=b[j]}}}return a}
});

ZForms.Calendar=Abstract.inheritTo({
	__constructor:function(a){this.oWidget=a;this.oPickerButton=ZForms.createButton(a.oOptions.oPickerOpenerElement);this.oElement=Common.Dom.createElement('table',{'class':this.__self.CLASS_NAME_CALENDAR+' '+this.__self.CLASS_NAME_HIDDEN}).appendChild(Common.Dom.createElement('tbody'));this.oYearTitleElement=Common.Dom.createElement('span',{'class':this.__self.CLASS_NAME_TITLE});this.oMonthTitleElement=Common.Dom.createElement('span',{'class':this.__self.CLASS_NAME_TITLE});this.oDate=new Date();this.oDateNow=new Date();this.bShowed=false;this.init()},

	init:function(){var b=this.oElement.parentNode.insertBefore(document.createElement('thead'),this.oElement),oYearRowElement=b.appendChild(document.createElement('tr')).appendChild(Common.Dom.createElement('th',{'colspan':7})),oYearArrowPrevElement=oYearRowElement.appendChild(Common.Dom.createElement('input',{'type':'button','value':'?','class':this.__self.CLASS_NAME_ARROW_PREV+' '+ZForms.Widget.Button.CLASS_NAME_BUTTON})),oYearArrowNextElement=oYearRowElement.appendChild(Common.Dom.createElement('input',{'type':'button','value':'?','class':this.__self.CLASS_NAME_ARROW_NEXT+' '+ZForms.Widget.Button.CLASS_NAME_BUTTON})),oMonthRowElement=b.appendChild(document.createElement('tr')).appendChild(Common.Dom.createElement('th',{'colspan':7})),oMonthArrowPrevElement=oMonthRowElement.appendChild(Common.Dom.createElement('input',{'type':'button','value':'?','class':this.__self.CLASS_NAME_ARROW_PREV+' '+ZForms.Widget.Button.CLASS_NAME_BUTTON})),oMonthArrowNextElement=oMonthRowElement.appendChild(Common.Dom.createElement('input',{'type':'button','value':'?','class':this.__self.CLASS_NAME_ARROW_NEXT+' '+ZForms.Widget.Button.CLASS_NAME_BUTTON})),oDaysOfWeekRowElement=b.appendChild(document.createElement('tr'));oYearRowElement.appendChild(this.oYearTitleElement);oMonthRowElement.appendChild(this.oMonthTitleElement);for(var i=0;i<7;i++){oDaysOfWeekRowElement.appendChild(Common.Dom.createElement('th',{'class':i>4?this.__self.CLASS_NAME_WEEKEND:null},ZForms.Resources.getDaysOfWeek()[i]))}var c=this;this.oPickerButton.setHandler(function(){if(c.isShowed()){c.hide()}else{var a=c.oWidget.getValue();if(c.oWidget.oOptions.bWithTime&&a.isEmpty()&&!c.oWidget.oYearInput.getValue().isEmpty()){c.setDate(new Date(c.oWidget.oYearInput.getValue().get(),c.oWidget.oMonthInput.getValue().get(),c.oWidget.oDayInput.getValue().get()))}else if(!a.isEmpty()){c.setDate(new Date(a.getYear(),a.getMonth()-1,a.getDay()))}c.show()}});Common.Event.add(this.oElement.parentNode,'click',function(a){Common.Event.cancel(a)});Common.Event.add(document,'click',function(a){if(Common.Event.normalize(a).target!=c.oPickerButton.oElement){c.hide()}});Common.Event.add(oYearArrowPrevElement,'click',function(){c.setPrevYear()});Common.Event.add(oYearArrowNextElement,'click',function(){c.setNextYear()});Common.Event.add(oMonthArrowPrevElement,'click',function(){c.setPrevMonth()});Common.Event.add(oMonthArrowNextElement,'click',function(){c.setNextMonth()});this.oPickerButton.oElement.parentNode.appendChild(this.oElement.parentNode)},

	setDate:function(a){this.oDate=a;if(this.isShowed()){this.render()}},

	isShowed:function(){return this.bShowed},

	show:function(){if(this.isShowed()){return}this.render();this.oWidget.addClass(this.__self.CLASS_NAME_PICKER_ACTIVE);Common.Class.remove(this.oElement.parentNode,this.__self.CLASS_NAME_HIDDEN);this.bShowed=true},

	hide:function(){if(!this.isShowed()){return}Common.Class.add(this.oElement.parentNode,this.__self.CLASS_NAME_HIDDEN);this.oWidget.removeClass(this.__self.CLASS_NAME_PICKER_ACTIVE);this.bShowed=false},

	render:function(){this.oYearTitleElement.innerHTML=this.oDate.getFullYear();this.oMonthTitleElement.innerHTML=ZForms.Resources.getMonthsByType('normal')[this.oDate.getMonth()];var b=new Date(this.oDate.getFullYear(),this.oDate.getMonth(),1),iCountDaysInPrevMonth=new Date(this.oDate.getFullYear(),this.oDate.getMonth(),-0.5).getDate(),iCountShowedDaysInPrevMonth=(b.getDay()==0?7:b.getDay())-1,oLastDayInMonth=new Date(this.oDate.getFullYear(),this.oDate.getMonth()+1,-0.5),iCountShowedDaysInNextMonth=7-(oLastDayInMonth.getDay()==0?7:oLastDayInMonth.getDay()),sHtml='<table>';for(var i=1;i<=iCountShowedDaysInPrevMonth;i++){if(i%7==1){sHtml+=(i>1?'</tr>':'')+'<tr>'}sHtml+='<td class="add'+(i%7==6||i%7==0?' weekend':'')+'">'+(iCountDaysInPrevMonth-iCountShowedDaysInPrevMonth+i)+'</td>'}for(var i=iCountShowedDaysInPrevMonth+1,iCountDays=oLastDayInMonth.getDate(),iDay=1,sClassName;iDay<=iCountDays;i++){if(i%7==1){sHtml+='</tr><tr>'}sClassName='';if(iDay==this.oDateNow.getDate()&&this.oDate.getMonth()==this.oDateNow.getMonth()&&this.oDate.getYear()==this.oDateNow.getYear()){sClassName='now'}if(i%7==6||i%7==0){sClassName+=(sClassName.length>0?' ':'')+'weekend'}sHtml+='<td'+(sClassName.length>0?' class="'+sClassName+'"':'')+'>'+iDay++ +'</td>'}for(var i=iCountShowedDaysInPrevMonth+iCountDays+1,iDay=1;iDay<=iCountShowedDaysInNextMonth;i++){if(i%7==1){sHtml+='</tr><tr>'}sHtml+='<td class="add'+(i%7==6||i%7==0?' weekend':'')+'">'+iDay++ +'</td>'}sHtml+='</tr></table>';var c=document.createElement('div');c.innerHTML=sHtml;c=c.getElementsByTagName('tbody')[0];this.oElement.parentNode.replaceChild(c,this.oElement);this.oElement=c;var d=this;Common.Event.add(this.oElement,'click',function(a){d.hide();d.setDate(new Date(d.oDate.getFullYear(),d.oDate.getMonth(),Common.Event.normalize(a).target.innerHTML));if(d.oWidget.oOptions.bWithTime){d.oDate.setHours(d.oWidget.oHourInput.getValue().isEmpty()?0:d.oWidget.oHourInput.getValue().get());d.oDate.setMinutes(d.oWidget.oMinuteInput.getValue().isEmpty()?0:d.oWidget.oMinuteInput.getValue().get());d.oDate.setSeconds(d.oWidget.oSecondInput.getValue().isEmpty()?0:d.oWidget.oSecondInput.getValue().get())}d.oWidget.setValue(d.oWidget.createValue(d.oDate))});if(Common.Browser.isOpera()||(Common.Browser.isIE()&&(!document.compatMode||document.compatMode=='BackCompat'||!window.XMLHttpRequest))){Common.Event.add(this.oElement.getElementsByTagName('td'),['mouseover','mouseout'],function(a){if(Common.Browser.isOpera()){a.target.style.display='none';a.target.style.display='table-cell'}else{var a=Common.Event.normalize(a);Common.Class[a.type=='mouseover'?'add':'remove'](a.target,d.__self.CLASS_NAME_HOVERED)}})}},

	setPrevMonth:function(){this.setDate(new Date(this.oDate.getFullYear(),this.oDate.getMonth(),-0.5))},

	setNextMonth:function(){this.setDate(new Date(this.oDate.getFullYear(),this.oDate.getMonth(),32))},

	setPrevYear:function(){this.setDate(new Date(this.oDate.getFullYear()-1,this.oDate.getMonth(),1))},

	setNextYear:function(){this.setDate(new Date(this.oDate.getFullYear()+1,this.oDate.getMonth(),1))},

	enable:function(){this.oPickerButton.enable()},

	disable:function(){this.hide();this.oPickerButton.disable()},

	destruct:function(){this.oWidget=null;this.oElement=null;this.oYearTitleElement=null;this.oMonthTitleElement=null;this.oPickerButton.destruct()}},{CLASS_NAME_CALENDAR:'calendar',CLASS_NAME_HIDDEN:ZForms.Widget.CLASS_NAME_HIDDEN,CLASS_NAME_ARROW_PREV:'arrow-prev',CLASS_NAME_ARROW_NEXT:'arrow-next',CLASS_NAME_TITLE:'title',CLASS_NAME_WEEKEND:'weekend',CLASS_NAME_NOW:'now',CLASS_NAME_PICKER_ACTIVE:'picker-active',CLASS_NAME_HOVERED:'hovered'
});

ZForms.Resources={sLanguage:(document.documentElement.lang?document.documentElement.getAttribute('lang'):'ru'),aMonths:{ru:{'normal':['январь','февраль','март','апрель','май','июнь','июль','август','сентябрь','октябрь','ноябрь','декабрь'],'genitive':['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря']},en:{'normal':['january','february','march','april','may','june','july','august','september','october','november','december'],'genitive':['january','february','march','april','may','june','july','august','september','october','november','december']}},aDaysOfWeek:{ru:['пн','вт','ср','чт','пт','сб','вс'],en:['Mon','Tue','Wed','Thu','Fri','Sat','Sun']},aNumberSeparators:{ru:',',en:'.'},

	getNumberSeparator:function(){return this.aNumberSeparators[this.sLanguage]},

	getDaysOfWeek:function(){return this.aDaysOfWeek[this.sLanguage]},

	getMonthsByType:function(a){return this.aMonths[this.sLanguage][a]}
};


ZForms.Builder=Abstract.inheritTo({
	__constructor:function(a){this.bFakedSafari=Common.Browser.isSafari()&&!navigator.appVersion.match(/Version\/3/);this.aLabels=this.fillLabels();this.aElementsByName=[];this.aTemplates=[];this.oForm=null;this.build(a);this.fillElements();this.addDependencies(a)},

	fillLabels:function(){var a=[];if(!this.bFakedSafari){return a}var b=document.getElementsByTagName('label');for(var i=0;i<b.length;i++){if(b[i].htmlFor){a[b[i].htmlFor]=b[i]}}return a},

	getForm:function(){return this.oForm},

	build:function(a){for(var i=0,iLength=a.length;i<iLength;i++){this.createWidgetByObject(a[i].sID,a[i])}},

	createWidgetByObject:function(a,b){if(b.oMove){this.moveObject(b)}if(b.oRepeat){this.makeMultiplicator(b)}if(b.sType!='form'){if(!(b.oRepeat&&b.oRepeat.bTemplate)){if(!this.getElementById(this.getParentId(b))){alert(b.sID)}}}var c=b.sType=='form'?false:((b.oRepeat&&b.oRepeat.bTemplate)||this.getElementById(this.getParentId(b)).isTemplate());switch(b.sType){case'form':return this.makeForm(b);break;case'fieldset':case'sheet':if(b.oSheet){return this.makeSheet(b,c)}else if(b.oSlider){return this.makeSliderInput(b,c)}else{return this.makeFieldContainer(b,c)}break;case'number':case'integer':case'decimal':return this.makeNumberInput(b,c);break;case'date':case'datetime':case'datemonth':return this.makeDateInput(b,c);break;case'select':return this.makeSelectInput(b,c);break;case'checkbox':return this.makeCheckBoxGroup(b,c);break;case'radio':return this.makeRadioButtonGroup(b,c);break;case'combobox':return this.makeComboInput(b,c);break;case'button':return this.makeButton(b,c);break;case'submit':return this.makeSubmitButton(b,c);break;default:return this.makeTextInput(b,c);break}},

	makeMultiplicator:function(a){var b=this.getElementById(a.oRepeat.sID+ZForms.Widget.Container.Multiplicator.POSTFIX_ID);if(b){return b}var c=document.createElement('div');c.id=a.oRepeat.sID+ZForms.Widget.Container.Multiplicator.POSTFIX_ID;return this.getElementById(a.sParent_ID).addChild(ZForms.createMultiplicator(c,null,{sButtonAddId:a.oRepeat.sAppend_ID,sButtonRemoveId:a.oRepeat.sRemove_ID,sButtonUpId:a.oRepeat.sUp_ID,sButtonDownId:a.oRepeat.sDown_ID,iMin:a.oRepeat.iMin||1,iMax:a.oRepeat.iMax||10}))},

	makeForm:function(a){this.oForm=ZForms.createForm(this.$(a.sID),this.getRow(a),{bUpdatableSubmit:a.oSubmit?a.oSubmit.bDisabled_button:null,bCheckForValid:a.oSubmit?a.oSubmit.bValid:null,bCheckForChanged:a.oSubmit?a.oSubmit.bChanged:null,bPreventSubmit:a.oSubmit?a.oSubmit.bPreventSubmit:null})},

	makeFieldContainer:function(a,b){return this.addChild(ZForms.createContainer(this.$(a.sID),this.getRow(a),{bTemplate:b}),a)},

	makeSheetContainer:function(a){var b;try{b=this.$(a.oSheet.sParent_ID)}catch(oException){b=Common.Dom.createElement('div',{id:a.oSheet.sParent_ID})}this.addChild(ZForms.createSheetContainer(b),a)},

	makeSheet:function(a,b){if(!this.getElementById(a.oSheet.sParent_ID)){this.makeSheetContainer(a)}if(a.oSheet.sLegend_ID&&a.oSheet.sParent_ID){this.makeTab(a.oSheet.sLegend_ID,a.oSheet.sParent_ID)}var c=ZForms.createSheet(this.$(a.sID),this.getRow(a),{bTemplate:b});if(a.oSheet.sLegend_ID){c.addLegendButton(ZForms.createButton(this.$(a.oSheet.sLegend_ID)))}if(a.oSheet.sPrev_ID){c.addPrevButton(ZForms.createButton(this.$(a.oSheet.sPrev_ID)))}if(a.oSheet.sNext_ID){c.addNextButton(ZForms.createButton(this.$(a.oSheet.sNext_ID)))}return this.addChild(c,a)},

	makeTextInput:function(a,b){return this.addChild(ZForms.createTextInput(this.$(a.sID),this.getRow(a),{sPlaceHolder:a.sPlaceHolder||'',bTemplate:b}),a)},

	makeNumberInput:function(a,b){return this.addChild(ZForms.createNumberInput(this.$(a.sID),this.getRow(a),{bTemplate:b,sPlaceHolder:a.sPlaceHolder||'',bFloat:a.sType=='decimal',bNegative:a.bNegative}),a)},

	makeSliderInput:function(a,b){return this.addChild(ZForms['createSlider'+(a.oSlider.sType=='vertical'?'Vertical':'')](this.$(a.sID),this.getRow(a),{bTemplate:b,aSlideRules:a.oSlider.aRules}),a)},

	makeDateInput:function(a,b){return this.addChild(ZForms.createDateInput(this.$(a.sID),this.getRow(a),{bTemplate:b,bOnlyMonths:a.sType=='datemonth',bWithTime:a.sType=='datetime',oPlaceHolders:a.oPlaceHolders,oPickerOpenerElement:a.sPicker_ID?this.$(a.sPicker_ID):null}),a)},

	makeSelectInput:function(a,b){return this.addChild(ZForms.createSelectInput(this.$(a.sID),this.getRow(a),{bTemplate:b}),a)},

	makeComboInput:function(a,b){return this.addChild(ZForms.createComboInput(this.$(a.sID),this.getRow(a),{bTemplate:b,sPlaceHolder:a.sPlaceHolder||'',oOptionsElement:this.$(a.sFrom_ID),oShowOptionsElement:a.sShowOptions_ID?this.$(a.sShowOptions_ID):null}),a)},

	makeInputGroup:function(a,b,c){var d=[];for(var i=0;i<a.asOption_ID.length;i++){d.push([this.$(a.asOption_ID[i][0]),this.$(a.asOption_ID[i][1])])}var e=ZForms[c](this.$(a.sID),this.getRow(a),{bTemplate:b},d);for(var i=0;i<e.aChildren.length;i++){this.makeEnablableLabel(e.aChildren[i])}return this.addChild(e,a)},

	makeCheckBoxGroup:function(a,b){return this.makeInputGroup(a,b,'createCheckBoxGroup')},

	makeRadioButtonGroup:function(a,b){return this.makeInputGroup(a,b,'createRadioButtonGroup')},

	makeEnablableLabel:function(a){if(!this.bFakedSafari){return}var b=this.aLabels[a.oElement.id],bChecked=a.isChecked();if(!b){return}Common.Event.add(b,ZForms.Widget.DOM_EVENT_TYPE_MOUSEDOWN,function(){bChecked=a.isChecked()});Common.Event.add(b,ZForms.Widget.DOM_EVENT_TYPE_MOUSEUP,function(){if(!a.isEnabled()){return}if(bChecked==a.isChecked()){a.check();a.processEvents(true)}})},

	makeButton:function(a,b){return this.addChild(ZForms.createButton(this.$(a.sID),this.getRow(a),{bTemplate:b}),a)},

	makeSubmitButton:function(a,b){return this.addChild(ZForms.createSubmitButton(this.$(a.sID),this.getRow(a),{bDisableOnSubmit:a.bDisableOnSubmit,bTemplate:b}),a)},

	makeTab:function(a,b){var c=this.$(a),oTabsContainerNode;try{oTabsContainerNode=this.$(b+'_tabs')}catch(oException){var d=this.$(b);oTabsContainerNode=d.insertBefore(document.createElement('div'),d.firstChild);oTabsContainerNode.id=b+'_tabs';Common.Class.add(oTabsContainerNode,'tabs')}oTabsContainerNode.appendChild(c.parentNode.removeChild(c))},

	addChild:function(a,b){var c=this.getElementById(this.getParentId(b));if(b.oRepeat&&b.oRepeat.bTemplate&&c instanceof ZForms.Widget.Container.Multiplicator){this.addTemplate(a);return c.addTemplate(a)}else if(a.isTemplate()){this.addTemplate(a)}return c.addChild(a)},

	addTemplate:function(a){this.aTemplates[a.getId()]=a},$:function(a){var b=document.getElementById(a);if(!b){throw('Element with id "'+a+'" no exists');}return b},

	getRow:function(a){if(a.sRow_ID){return this.$(a.sRow_ID)}return this.$(a.sID)},

	getParentId:function(a){if(a.oRepeat){return a.oRepeat.sID+ZForms.Widget.Container.Multiplicator.POSTFIX_ID}if(a.oSheet&&this.getElementById(a.oSheet.sParent_ID)){return a.oSheet.sParent_ID}return a.sParent_ID},

	moveObject:function(a){if(a.oMove.sBefore_ID){var b=this.$(a.oMove.sBefore_ID);if(b){var c=this.$(a.sRow_ID||a.sID);b.parentNode.insertBefore(c.parentNode.removeChild(c),b)}}},

	fillElements:function(a){var a=a||this.oForm;if(a.getName()){this.aElementsByName[a.getName()]=a}if(a instanceof ZForms.Widget.Container.Group){this.aElementsByName[a.getName()]=a}else if(a instanceof ZForms.Widget.Container){for(var i=0;i<a.aChildren.length;i++){this.fillElements(a.aChildren[i])}if(a.oTemplate){this.fillElements(a.oTemplate)}}},

	getElementById:function(a){var b=this.oForm.getWidgetById(a)||this.getTemplateById(a);return b},

	getElementByName:function(a){return this.aElementsByName[a]},

	getTemplateById:function(a){return this.aTemplates[a]},

	addDependencies:function(a){for(var i=0,iLength=a.length;i<iLength;i++){if(a[i].oValid){this.makeValidDependence(a[i].sID,a[i].oValid)}if(a[i].sType=='email'){this.makeEmailDependence(a[i].sID)}if(a[i].oRequired){this.makeRequiredDependence(a[i].sID,a[i].oRequired)}if(a[i].oDepended){this.makeEnableDependence(a[i].sID,a[i].oDepended)}if(a[i].oOptions_depended){this.makeOptionsDependence(ZForms.Dependence.TYPE_OPTIONS,a[i].sID,a[i].oOptions_depended)}if(a[i].oOptions_checked){this.makeOptionsDependence(ZForms.Dependence.TYPE_CHECK,a[i].sID,a[i].oOptions_checked)}if(a[i].oClass){this.makeClassDependence(a[i].sID,a[i].oClass)}}},

	makeRequiredDependence:function(a,b){var c=this.getElementById(a),iLogic=(b.sLogic=='or'?ZForms.Dependence.LOGIC_OR:ZForms.Dependence.LOGIC_AND);c.addDependence(ZForms.createRequiredDependence(c,iLogic,b.iMin));if(b.aFrom){for(var i=0,oWidgetFrom;i<b.aFrom.length;i++){oWidgetFrom=this.getElementByName(b.aFrom[i].sName);if(!oWidgetFrom){this.throwDependenceException(b.aFrom[i].sName,c.getName()||c.getId());}if(b.aFrom[i].mData&&b.aFrom[i].mData instanceof Function){c.addDependence(ZForms.createFunctionDependence(ZForms.Dependence.TYPE_REQUIRE,oWidgetFrom,b.aFrom[i].mData,iLogic,b.aFrom[i].bInverse))}else{c.addDependence(new ZForms.Dependence.Required(oWidgetFrom,b.aFrom[i].mData||/.+/,iLogic,b.aFrom[i].bInverse,b.iMin?b.iMin:1))}}}},

	makeValidDependence:function(a,b){var c=this.getElementById(a),iLogic=(b.sLogic=='or'?ZForms.Dependence.LOGIC_OR:ZForms.Dependence.LOGIC_AND);for(var i=0,oWidgetFrom;i<b.aFrom.length;i++){oWidgetFrom=b.aFrom[i].sName?this.getElementByName(b.aFrom[i].sName):c;if(!oWidgetFrom){this.throwDependenceException(b.aFrom[i].sName,c.getName()||c.getId());}if(b.aFrom[i].mData instanceof Function){c.addDependence(ZForms.createFunctionDependence(ZForms.Dependence.TYPE_VALID,oWidgetFrom,b.aFrom[i].mData,iLogic,b.aFrom[i].bInverse))}else if(b.aFrom[i].oCompare){c.addDependence(ZForms.createValidCompareDependence(oWidgetFrom,b.aFrom[i].oCompare.sCondition,b.aFrom[i].oCompare.sName?this.getElementByName(b.aFrom[i].oCompare.sName):b.aFrom[i].oCompare.sValue,iLogic,b.aFrom[i].bInverse))}else{c.addDependence(ZForms.createValidDependence(oWidgetFrom,typeof b.aFrom[i].mData=='undefined'?/.+/:(b.aFrom[i].mData instanceof RegExp?b.aFrom[i].mData:new RegExp('^'+b.aFrom[i].mData+'$')),iLogic,b.aFrom[i].bInverse))}}},

	makeEmailDependence:function(a){var b=this.getElementById(a);b.addDependence(ZForms.createValidEmailDependence(b))},

	makeEnableDependence:function(a,b){var c=this.getElementById(a),iLogic=(b.sLogic=='or'?ZForms.Dependence.LOGIC_OR:ZForms.Dependence.LOGIC_AND);for(var i=0,oWidgetFrom;i<b.aFrom.length;i++){oWidgetFrom=this.getElementByName(b.aFrom[i].sName);if(!oWidgetFrom){this.throwDependenceException(b.aFrom[i].sName,c.getName()||c.getId());}if(b.aFrom[i].mData instanceof Function){c.addDependence(Dependence.createFunctionDependence(ZForms.Dependence.TYPE_ENABLE,oWidgetFrom,b.aFrom[i].mData,iLogic,b.aFrom[i].bInverse))}else if(b.aFrom[i].oCompare){c.addDependence(ZForms.createEnableCompareDependence(oWidgetFrom,b.aFrom[i].oCompare.sCondition,b.aFrom[i].oCompare.sName?this.getElementByName(b.aFrom[i].oCompare.sName):b.aFrom[i].oCompare.sValue,iLogic,b.aFrom[i].bInverse))}else{c.addDependence(ZForms.createEnableDependence(oWidgetFrom,typeof b.aFrom[i].mData=='undefined'?/.+/:(b.aFrom[i].mData instanceof RegExp?b.aFrom[i].mData:new RegExp('^'+b.aFrom[i].mData+'$')),iLogic,b.aFrom[i].bInverse?true:false))}}},

	makeOptionsDependence:function(a,b,c){var d=this.getElementById(b),iLogic=(c.sLogic=='or'?ZForms.Dependence.LOGIC_OR:ZForms.Dependence.LOGIC_AND);for(var i=0,oWidgetFrom,aPatterns;i<c.aFrom.length;i++){oWidgetFrom=this.getElementByName(c.aFrom[i].sName);if(!oWidgetFrom){this.throwDependenceException(c.aFrom[i].sName,d.getName()||d.getId());}if(c.aFrom[i].mData instanceof Function){d.addDependence(ZForms.createFunctionDependence(ZForms.Dependence.TYPE_OPTIONS,oWidgetFrom,c.aFrom[i].mData,iLogic,c.aFrom[i].bInverse))}else{aPatterns=[];for(var j=0;j<c.aFrom[i].mData.length;j++){aPatterns.push({rSource:c.aFrom[i].mData[j][0]instanceof RegExp?c.aFrom[i].mData[j][0]:new RegExp('^'+c.aFrom[i].mData[j][0]+'$'),rDestination:c.aFrom[i].mData[j][1]instanceof RegExp?c.aFrom[i].mData[j][1]:new RegExp('^'+c.aFrom[i].mData[j][1]+'$')})}d.addDependence(ZForms.createOptionsDependence(oWidgetFrom,aPatterns,iLogic))}}},

	makeClassDependence:function(a,b){var c=this.getElementById(a),iLogic=(b.sLogic=='or'?ZForms.Dependence.LOGIC_OR:ZForms.Dependence.LOGIC_AND);for(var i=0,oWidgetFrom,aPatternToClasses;i<b.aFrom.length;i++){oWidgetFrom=this.getElementByName(b.aFrom[i].sName);if(!oWidgetFrom){this.throwDependenceException(b.aFrom[i].sName,c.getName()||c.getId());}if(b.aFrom[i].mData instanceof Function){c.addDependence(ZForms.createFunctionDependence(ZForms.Dependence.TYPE_CLASS,oWidgetFrom,b.aFrom[i].mData,iLogic,b.aFrom[i].bInverse))}else{aPatternToClasses=[];for(var j=0;j<b.aFrom[i].mData.length;j++){aPatternToClasses.push({rPattern:b.aFrom[i].mData[j][0]instanceof RegExp?b.aFrom[i].mData[j][0]:new RegExp('^'+b.aFrom[i].mData[j][0]+'$'),sClassName:b.aFrom[i].mData[j][1]})}}c.addDependence(ZForms.createClassDependence(oWidgetFrom,aPatternToClasses,iLogic))}},

	throwDependenceException:function(a,b){throw('Widget with name "'+a+'" no exists (adding dependence to widget with name/id "'+b+'")');}}
);


var FormBuilder = ZForms.Builder;
for(var sZForms in ZForms){
	if(!window[sZForms]){
		window[sZForms] = ZForms[sZForms];
	}
}
