	
	
	/** --------------------------------------------------------------------------------------------------------------- //
	#		CymesFormValidator
	// ---------------------------------------------------------------------------------------------------------------- */
	var CFV_WARNING_INPUT_COLOR = null;
	var CFV_WARNING_INPUT_BGCOLOR = '#fff9ea';
	var CFV_WARNING_INPUT_BORDERCOLOR = '#fb9200';
	var CFV_WARNING_LABEL_COLOR = '#fb9200';
	// numer błędu od którego zaczyna się error, należy zsynchronizować z klasą cError
	var CFV_ERROR_NO_FAILED = 1024;
	
	function CymesFormValidator(frm, action, FunctionAlertName){
		this.frm = frm;
		this.action = action;
		this.FunctionAlertName = FunctionAlertName;
		this.errno = this._CONST_ERR_SUCCESS;
	}
	
	
	/* ---------------------------------------------------------------------------------------------------------------- //
	#		CymesFormValidator.prototype
	*/
	CymesFormValidator.prototype = {
		
		_CONST_ERR_SUCCESS: 0,
		_CONST_ERR_BADVALUE: (parent.CFV_ERROR_NO_FAILED + 1),
		_CONST_ERR_BADOBJECT: (parent.CFV_ERROR_NO_FAILED + 2),
		errno: 0,
		errtx: '',
		_CONST_DEFAULT_ERRTX: 'Nieprawidłowa wartość w polu formularza',
		
		/* --------------------------------------------------------------------------------------------
		#		check
		*/
		check: function(argv_inputs_id, argv_missing_reg_expresion, alert_message){
			
			var inputs_id = new Array();		// identyfikatory przekazane w argumencie
			var inputs = new Array();				// tablica obiektów, id przekazane w argumencie
			var regs = new Array();					// tablica regexpów przekazana w argumencie
			
			var i; // iiiiiiiii
			
			var _isValidValue = false;
			
			// jeżeli wcześniej był błąd, nie sprawdzamy dalej
			if( this.errno != this._CONST_ERR_SUCCESS ) return false;
			
			if( typeof(argv_inputs_id)=="string" ){
				inputs_id[0] = argv_inputs_id;
				inputs[0] = this.frm.elements[argv_inputs_id];
				regs[0] = argv_missing_reg_expresion;
			}else{
				inputs_id = argv_inputs_id;
				for(i=0; i<inputs_id.length; i++) inputs[i] = this.frm.elements[inputs_id[i]]; //document.getElementById(inputs_id[i]);
				regs = argv_missing_reg_expresion;
			}
			
			for(i=0; i<inputs.length; i++){
				
				if( inputs[i]==null ) return this.DisplayErrorAlert(this._CONST_ERR_BADOBJECT, '!ERROR: Unknown object (' + typeof(inputs[i]) + '#' + inputs_id[i] + ')');
				
				switch(inputs[i].type){
					case "checkbox":
							if( inputs[0].id.indexOf(":") > 0 ){
								_isValidValue = this.CheckResultForGroup(inputs[i], regs[i]);
							}else{
								_isValidValue = regs[i].test( inputs[i].checked.toString() );
							}
						break;
					case "radio":
							_isValidValue = this.CheckResultForGroup(inputs[i], regs[i]);
						break;
					case "text":
					case "select-one":
					case "file":
					case "password":
					case "textarea":
							_isValidValue = regs[i].test( inputs[i].value.toString() );
						break;
					default:
						return this.DisplayErrorAlert(this._CONST_ERR_BADOBJECT, '!ERROR: Unknown input type (' + inputs[i].tagName + '.' + inputs[i].type + '#' + inputs[i].id + ')');
				}// end switch inputs[i].type
				//
				if( !_isValidValue )this.RaiseError(this._CONST_ERR_BADVALUE, alert_message);
				//
				// zmiana inputa oraz indywidualnego labela
				this.ChangeStateInput(inputs[i], _isValidValue);
				//
				
			}// end for i
			
			// zmiana wspólnego labela
			this.ChangeStateCommonLabel(inputs[0], this.errno==this._CONST_ERR_SUCCESS);
									
			if( this.errno==this._CONST_ERR_SUCCESS ){
				return true;
			}else{
				return this.DisplayErrorAlert();
			}
			
						
		},// end function check
		
		
		/* --------------------------------------------------------------------------------------------
		#		CheckResultForGroup
		*/
		CheckResultForGroup: function(argv_input, argv_missing_reg_expresion){
			var isValidValue = false;
			var r = new RegExp("^.+(:)([0-9]{1,2})$", "ig");
			var a = argv_input.id.match(r);
			var firstItem = RegExp.$2;
			//
			if( isNaN(firstItem) ){
				isValidValue = true;
			}else{
				var nextItem = firstItem;
				var nextID = argv_input.id.replace(/:.*/i, ":" + nextItem);
				var nextInput = document.getElementById(nextID);
				while(nextInput){
					ival = nextInput.checked.toString();
					isValidValue = regexp.test(ival);
					if(isValidValue) break;
					nextItem++;
					nextID = argv_input.id.replace(/:.*/i, ":" + nextItem);
					nextInput = document.getElementById(nextID);
				}
			}
			return isValidValue;
		}, // end function CheckResultForGroup
		
		
		/* --------------------------------------------------------------------------------------------
		#		ChangeStateCommonLabel
		*/
		ChangeStateCommonLabel: function(argv_Input, argv_isValid){
			var pos_last_colon = argv_Input.id.lastIndexOf(":");
			if( pos_last_colon > 0 ){
				var commonLabel = document.getElementById( argv_Input.id.substring(0, pos_last_colon+1) );
				if( commonLabel!=undefined ) commonLabel.style.color = argv_isValid ? '' : CFV_WARNING_LABEL_COLOR;
			}
		}, // end function ChangeStateCommonLabel
		
		
		/* --------------------------------------------------------------------------------------------
		#		ChangeStateInput
		*/
		ChangeStateInput: function(argv_Input, argv_isValid){
			if( !argv_isValid ){
				argv_Input.focus();
			}
			if( argv_Input.type!='checkbox' && argv_Input.type!='radio' ){
				argv_Input.style.backgroundColor = argv_isValid ? '' : CFV_WARNING_INPUT_BGCOLOR;
				if(CFV_WARNING_INPUT_BORDERCOLOR!=undefined){
					argv_Input.style.borderColor = argv_isValid ? '' : CFV_WARNING_INPUT_BORDERCOLOR;
				}
			}
			// zmiana labela indywidualnego dla argv_Input
			var labels = document.getElementsByTagName("LABEL");
			var n = 0;
			var InputID = argv_Input.id;
			for(n=0; n<labels.length; n++){
				if( labels[n].getAttributeNode("FOR") ){
					labelFOR = labels[n].getAttributeNode("FOR").value;
					if( labelFOR==InputID ){
							labels[n].style.color = argv_isValid ? '' : CFV_WARNING_LABEL_COLOR;
							labels[n].title = argv_isValid ? '' : this.errtx;
							break;
					}
				}
			}
		},// end function ChangeStateInput
	
		
		/* --------------------------------------------------------------------------------------------
		#		isValid
		*/
		isValid: function(){
			if(this.errno==this._CONST_ERR_SUCCESS) this.frm.action = this.action;
			return this.errno==this._CONST_ERR_SUCCESS;
		},// end function isValid
		
		
		/* --------------------------------------------------------------------------------------------
		#		DisplayErrorAlert
		*/
		DisplayErrorAlert: function(argv_errno, argv_errtx, argv_Input){
			if(argv_errno!=undefined) this.RaiseError(argv_errno, argv_errtx);
			window.setTimeout(this.FunctionAlertName + '(' + Number(this.errno) + ',"' + this.errtx + '")', 1);
			return false;
		},// end function DisplayErrorAlert
		
		
		/* --------------------------------------------------------------------------------------------
		#		RaiseError
		*/
		RaiseError: function(argv_errno, argv_errtx){
			this.errno = argv_errno;
			this.errtx = argv_errtx==undefined ? this._CONST_DEFAULT_ERRTX : argv_errtx;
		},// end function RaiseError
		
		
		/* --------------------------------------------------------------------------------------------
		#		RaiseErrorOuter
				generuje błąd z zewnątrz obiektu
		*/
		RaiseErrorOuter: function(argv_inputs_id, alert_message){
			var inputs_id = new Array();		// identyfikatory przekazane w argumencie
			var inputs = new Array();				// tablica obiektów, id przekazane w argumencie
			var i; // iiiiiiiii
			var _isValidValue = false;
			//
			if( this.errno != this._CONST_ERR_SUCCESS ) return false; // jeżeli wcześniej był błąd, nie sprawdzamy dalej
			if( typeof(argv_inputs_id)=="string" ){
				inputs_id[0] = argv_inputs_id;
				inputs[0] = this.frm.elements[argv_inputs_id];
			}else{
				inputs_id = argv_inputs_id;
				for(i=0; i<inputs_id.length; i++) inputs[i] = this.frm.elements[inputs_id[i]];
			}
			for(i=0; i<inputs.length; i++){
				if( inputs[i]==null ) return this.DisplayErrorAlert(this._CONST_ERR_BADOBJECT, '!ERROR: Unknown object (' + typeof(inputs[i]) + '#' + inputs_id[i] + ')');
				this.ChangeStateInput(inputs[i], false); // zmiana inputa oraz indywidualnego labela
			}// end for i
			// zmiana wspólnego labela
			this.ChangeStateCommonLabel(inputs[0], false);
			return this.DisplayErrorAlert(this._CONST_ERR_BADVALUE, alert_message);
		}// end function RaiseErrorOuter
		
		
		
				
	}; // end CymesFormValidator.prototype
	//
	/* ---------------------------------------------------------------------------------------------------------------- //
	#		end CymesFormValidator
	// ---------------------------------------------------------------------------------------------------------------- */
	
	
	
	/*	___________________________________________________________________________________________ //
	##	SkipFormPage(this)
			submit form bez validacji
	*/
	function SkipFormPage(frmId, rewindStep){
		var frm = document.forms[frmId];
		frm.elements['_confirm_page'].value = rewindStep;
		frm.submit();
	}// end function SkipFormPage
	
	
	
	
