

		function MDrawCompoIDesign (id)
		{
			this.m_elementId = id;

			this.m_unserialized = false;
			this.m_displaySelects = true;
			this.m_lock = false;

			this.m_cells = new Array ();
			this.m_logic = new Array ();
            this.m_blocks = new Array ();
            this.m_acceptors = new Array ();

			this.m_iconMin;
			this.m_altMin;
			this.m_iconMax;
			this.m_altMax;
			this.m_iconLock;
            this.m_altLock;
			this.m_iconUnlock;
            this.m_altUnlock;

			this.m_sendFn = 'execute(#)';

			this.m_cssValidateError;
			this.m_cssValidateOk;
            this.m_cssBubble;
            this.m_exclamationSystemField = '';
			this.m_firstBad = null;
            this.m_exclamationMessage = null;

            this.m_iconExtensions; 
            this.m_pathUpload;
            this.m_translations;
            
            this.m_imgPicNone;
            this.m_imgFileNone;
            this.m_altPicNone;
            this.m_altFileNone;
            this.m_altPicEdit;
            this.m_altFileEdit;
            
			this.m_refObjectCalendar;
            this.m_refCollection;

			this.config = MDrawCompoIDesign_config;
				this._unserialize = _MDrawCompoIDesign_unserialize;
				this._serializeBlocks = _MDrawCompoIDesign_serializeBlocks;

			this.controlAll = MDrawCompoIDesign_controlAll;
            this.controlMultiple = MDrawCompoIDesign_controlMultiple;
            this.controlEmptyMultiple = MDrawCompoIDesign_controlEmptyMultiple;
			this.controlInput = MDrawCompoIDesign_controlInput;
                this._controlEmptyInput = _MDrawCompoIDesign_controlEmptyInput;
                this.isDisabled = MDrawCompoIDesign_isDisabled;
            this.controlBond = MDrawCompoIDesign_controlBond;
				this._checkValue = _MDrawCompoIDesign_checkValue;
				this._checkDate = _MDrawCompoIDesign_checkDate;
				this._checkTime = _MDrawCompoIDesign_checkTime;
				this._checkNumber = _MDrawCompoIDesign_checkNumber;

            this.complete = MDrawCompoIDesign_complete;
            this.completeAcceptor = MDrawCompoIDesign_completeAcceptor;
                this._rememberAcceptor = _MDrawCompoIDesign_rememberAcceptor;
                
				this._showExclamation = _MDrawCompoIDesign_showExclamation;
				this._hideExclamation = _MDrawCompoIDesign_hideExclamation;

			this.onSearchable = MDrawCompoIDesign_onSearchable;
			this.onCallBack = MDrawCompoIDesign_onCallBack;

				this._showSelects = _MDrawCompoIDesign_showSelects;
				this._hideSelects = _MDrawCompoIDesign_hideSelects;

			this.onFocus = MDrawCompoIDesign_onFocus;
			this.onBlock = MDrawCompoIDesign_onBlock;
			this.onLock = MDrawCompoIDesign_onLock;
                this._lock = _MDrawCompoIDesign_lock;
                
			this.onEvent = MDrawCompoIDesign_onEvent;
		}


MDrawCompoIDesign.lookUpMethods = new Array();
MDrawCompoIDesign.lookUpMethods[1] = _MDrawCompoIDesign_lookUpNumeric;
MDrawCompoIDesign.resolveMethods = new Array();
MDrawCompoIDesign.resolveMethods[1] = _MDrawCompoIDesign_resolveNumeric;

				function _MDrawCompoIDesign_unserialize ()
				{
//debug ('unserialize');
					this._hideExclamation ();

					if (!this.m_unserialized)
					{
						var blocks = unescape (document.all [this.m_elementId + '_blocks'].value);
						this.m_blocks = unserialize (blocks);
						if (!this.m_blocks)
							this.m_blocks = new Array ();
//debug (this.m_blocks, 'this.m_blocks');
						var logic = unescape (document.all [this.m_elementId + '_idesigns'].value);
						this.m_logic = unserialize (logic);
						if (!this.m_logic)
							this.m_logic = new Array ();
//debug (this.m_logic, 'this.m_logic');
						var cells = unescape (document.all [this.m_elementId + '_cells'].value);
						this.m_cells = unserialize (cells);
						if (!this.m_cells)
							this.m_cells = new Array ();
//debug (this.m_cells, 'this.m_cells');

                        for (var i in this.m_cells)
                        {
                            var object = document.all [i];
//debug (i, 'object');
                            if (object && object.type && object.type == 'hidden')
                                continue;
                                
                            if (object)
                            {
                                if (this.m_cells [i]['d'] && !object.onblur)
                                {
                                    var fn = new Function (this.m_elementId + '.complete(\'' + i + '\')');
                                    object.attachEvent ('onblur', fn);
                                }
                           
                                if (this.m_cells [i]['_c'] && !object.onclick)
                                {
                                    var fn = new Function (this.m_refCollection + '.completeActiveControler(\'' + this.m_cells [i]['_c'] + '\')');

                                    if (object.length && !object.tagName)
                                    {
                                        for (var it = 0; it < object.length; it++)
                                            object [it].attachEvent ('onclick', fn);
                                    }
                                    else
                                        object.attachEvent ('onclick', fn);
                                }

                                if (this.m_cells [i]['a'])
                                {
                                    this.m_acceptors [i] = ' ';
                                    this.completeAcceptor (i, true);

                                    if (!object.onfocus)
                                    {
                                        var fn = new Function (this.m_elementId + '._rememberAcceptor(\'' + i + '\')');
                                        object.attachEvent ('onfocus', fn);
                                    }
                                    
                                    if (!object.onblur)
                                    {
                                        var fn = new Function (this.m_elementId + '.completeAcceptor(\'' + i + '\')');
                                        object.attachEvent ('onblur', fn);
                                    }
                                }
                            }
                        }

                        if (document.all [this.m_elementId + '_extensions'])
                        {
                            var extensions = unescape (document.all [this.m_elementId + '_extensions'].value);
                            this.m_iconExtensions = unserialize (extensions);
    						if (!this.m_iconExtensions)
    							this.m_iconExtensions = new Array ();
                        }

                        if (document.all [this.m_elementId + '_translations'])
                        {
                            var translations = unescape (document.all [this.m_elementId + '_translations'].value);
                            this.m_translations = unserialize (translations);
    						if (!this.m_translations)
    							this.m_tranlations = new Array ();
                        }
                        
						this.m_unserialized = true;
					}
				}


				function _MDrawCompoIDesign_serializeBlocks ()
				{
					var hidden = escape (serialize (this.m_blocks));
					document.all [this.m_elementId + '_blocks'].value = hidden;
				}


				function _MDrawCompoIDesign_showSelects (flag)
				{
					if (!this.m_displaySelects)
					{
						for (var i in this.m_cells) {
							if (this.m_cells [i]['h'] && document.all [i])
							{
                                if (!flag || (flag == true && this.m_firstBad != i))
                                {
    								var object = document.all [i];
    								object.style.display = 'inline';
    
    								var replaceObject = document.all [i + 'f'];
                                    if (replaceObject)
        								replaceObject.removeNode (true);
                                }
							}
                        }

						this.m_displaySelects = true;
					}
				}


				function _MDrawCompoIDesign_hideSelects (flag)
				{
					if (this.m_displaySelects)
					{
						for (var i in this.m_cells) {
							if (this.m_cells [i]['h'] && document.all [i])
							{
                                if (!flag || (flag == true && this.m_firstBad != i))
                                {
    								var object = document.all [i];

    								object.style.display = 'none';
    								var replaceObject = document.createElement('font');
    
    								replaceObject.id = i + 'f';
    								replaceObject.className = object.className;
    								replaceObject.style.width = object.style.width;
    								replaceObject.style.height = object.style.height;
    
    								object.insertAdjacentElement('afterEnd',replaceObject);
                                }
							}
                        }
						this.m_displaySelects = false;
					}
				}


		function MDrawCompoIDesign_config (property, value)
		{
			switch (property)
			{
				case 'MDC_ICON_MIN':
					this.m_iconMin = value;
					break;
				case 'MDC_ICON_MAX':
					this.m_iconMax = value;
					break;
				case 'MDC_ICON_LOCK':
					this.m_iconLock = value;
					break;
				case 'MDC_ICON_UNLOCK':
					this.m_iconUnlock = value;
					break;
				case 'MDC_ALT_MIN':
					this.m_altMin = value;
					break;
				case 'MDC_ALT_MAX':
					this.m_altMax = value;
					break;
				case 'MDC_ALT_LOCK':
					this.m_altLock = value;
					break;
				case 'MDC_ALT_UNLOCK':
					this.m_altUnlock = value;
					break;
				case 'MDC_CLASS_VALIDATE_ERROR':
					this.m_cssValidateError = value;
					break;
				case 'MDC_CLASS_VALIDATE_OK':
					this.m_cssValidateOk = value;
					break;
				case 'MDC_CLASS_BUBBLE':
					this.m_cssBubble = value;
					break;
				case 'MDC_SEND_FUNCTION':
					this.m_sendFn = value;
					break;
				case 'MDC_PANEL_CALENDAR':
					this.m_refObjectCalendar = value;
					break;
				case 'MDC_COLLECTION':
					this.m_refCollection = value;
					break;
                case 'MDC_PATH_UPLOAD':
                    this.m_pathUpload = value;
                    break;
                case 'MDC_TEXT_SYSTEM_FIELD':
                    this.m_exclamationSystemField = value;
                    break;
				default:
					break;
			}
		}


		function MDrawCompoIDesign_onEvent (id, field, indexer, action, target, location)
		{
			var type = window.event.type;
			var flag = false;

			switch (type)
			{
				case 'keydown':
					var keyCode = window.event.keyCode;

					if (keyCode == 13)
						flag = true;

					break;

				case 'change':
				case 'click':
					flag = true;

					break;
			}

			if (flag)
			{
                var control = false;
//alert('action: ' + action);
                switch (parseInt (action)) {
                    case 400002:
                    case 400061:
                    case 400048:
                    case 400075:
                        eval ('control = ' + this.m_refCollection + '.controlAll ();');
                        break;
                        
                    default:
                        control = this.controlAll(id);
//alert('control: ' + control);
                        break;
                }
                
                if (control)
                {
    				var parts = this.m_sendFn.split ('#');
    				eval (parts [0] + parseInt(id) + ',null,' + indexer +',\'' + action + '\',\'' + target + '\',\'' + location + '\'' + parts [1] + ';');
                }

			}

			window.event.cancelBubble = true;
		}


		function MDrawCompoIDesign_onSearchable (name)
		{
			this._unserialize ();

			if (!this.m_lock && this.m_cells [name] && this.m_cells [name]['f'] == 'date')
			{
				var object = document.all [name];

				eval (this.m_refCollection + '.hideSelects ();');

                var source = window.event.srcElement;
				var positionLocator = document.createElement ('div');
        		    positionLocator.style.position = 'absolute';
        
        		source.insertAdjacentElement ('beforeBegin', positionLocator);

                var left = positionLocator.offsetLeft + Math.round (source.offsetWidth / 2);
                var top = positionLocator.offsetTop + Math.round (source.offsetHeight / 2);

				if (positionLocator)
					positionLocator.removeNode (true);
                    
                eval (this.m_refObjectCalendar + '.config(\'MC_FUNCTION_CLOSE\',\'' + this.m_elementId + '.onCallBack("' + name + '","")\');');
				eval (this.m_refObjectCalendar + '.onOpen(' + top + ',' + left + ',\'' + this.m_elementId + '.onCallBack("' + name + '",#)\');');
				eval (this.m_refObjectCalendar + '.onSetDate(\'' + object.value + '\',true);');

				this.m_lock = true;
			}
		}


		function MDrawCompoIDesign_onCallBack (name, value, type)
		{
			if (this.m_cells [name] && this.m_cells [name]['f'] == 'date')
			{
				eval (this.m_refCollection + '.showSelects ();');
            
                if (value != '')
                {
    				eval (this.m_refObjectCalendar + '.onClose();');

    				var object = document.all [name];
    
    				value = this._checkValue (value, 'date');
    				if (value != false)
    				{
    					object.value = value;
    					this.controlInput (object, true);
                        object.focus ();
    				}
                }

				this.m_lock = false;
			}
            else if (type == 'text')
            {
                var object = document.all [name];
                
				object.value = unescape (value);

                if (this.m_cells [name])
    				this.controlInput (object, true, true);
                
                object.focus ();
            }
            else if (type == 'image')
            {
                if (value != '-1')
                {
                    var values = value.split (';');
                    document.all [name + '_img'].src = this.m_pathUpload + values [1];
                    document.all [name + '_img'].alt = this.m_altPicEdit;
                    /* Reizo 13.03.2003 - doplnil som unescape pre prvu cast values, ta druha sa neurlencoduje*/
                    document.all [name].value = unescape(values [0]);
                }
                else
                {
                    document.all [name + '_img'].src = this.m_imgPicNone;
                    document.all [name + '_img'].alt = this.m_altPicNone;
                    document.all [name].value = '';
                }
            }
            else if (type == 'file')
            {
                if (value != '-1')
                {
                    var values = value.split (';');
                    /* Reizo 13.03.2003 - doplnil som unescape pre prvu cast values, ta druha sa neurlencoduje*/
                    value = unescape(values [0]);
                    
                    var extension = value.substr (value.lastIndexOf ('.') + 1);
                    document.all [name + '_img'].src = (this.m_iconExtensions [extension]) ? this.m_iconExtensions [extension] : '';
                    document.all [name + '_img'].alt = this.m_altFileEdit;
                    
                    var fileName = value.substring (value.lastIndexOf ('/') + 1, value.lastIndexOf ('_'));
                    document.all [name].value = fileName;
                    this.complete (name, true);
                    
                    document.all [name].value = value;
                }
                else
                {
                    document.all [name + '_img'].src = this.m_imgFileNone;
                    document.all [name + '_img'].alt = this.m_altFileNone;
                    document.all [name].value = '';
                }
            }
		}


		function MDrawCompoIDesign_onFocus (id)
		{
			this._unserialize ();

			if (this.m_logic [id][3])
			{
				var object = document.all [this.m_logic [id][3]];
                if (object.name && this.m_cells[object.name] && this.m_cells[object.name]['_wo']) {
                    eval (this.m_cells[object.name]['_ro'] + '.config(\'MDC_CONTAINER\',\'' + this.m_elementId + '._hideExclamation()\');');
                    object = document.all[this.m_cells[object.name]['_wo']];
                }
                if (object && object.disabled)
                    return;
                    
				var index = id;
				var flag = true;

                while (this.m_logic [index])
                {
                    if (typeof (this.m_blocks [index]) == 'undefined' || this.m_blocks [index] & 1)
                        index = this.m_logic [index][2];
                    else
                    {
                        flag = false;
                        break;
                    }
                }
                
				if (flag)
					object.focus ();
			}
		}


		function MDrawCompoIDesign_onBlock (id)
		{
			this._unserialize ();

            if (!document.all [this.m_elementId + '_divBlock[' + id + ']'])
                return;
                
			var block = document.all [this.m_elementId + '_divBlock[' + id + ']'];
			var object = document.all [this.m_elementId + '_imgBlock[' + id + ']'];

			if (this.m_blocks [id] & 1)
			{
				object.src = this.m_iconMin;
				object.alt = this.m_altMin;
				block.style.display = 'none';

				if (document.all [this.m_elementId + '_tblBlock[' + id + ']'])
					document.all [this.m_elementId + '_tblBlock[' + id + ']'].style.height = '';
				else
					document.all [this.m_elementId + '_tblWrapper'].style.height = '';

				this.m_blocks [id] ^= 1;
			}
			else
			{
				object.src = this.m_iconMax;
				object.alt = this.m_altMax;
				block.style.display = 'inline';
				this.m_blocks [id] ^= 1;

				if (document.all [this.m_elementId + '_tblBlock[' + id + ']'] && this.m_logic [id][4] != '*')
					document.all [this.m_elementId + '_tblBlock[' + id + ']'].style.height = this.m_logic [id][4];
				else if (this.m_logic [id][4] != '*')
					document.all [this.m_elementId + '_tblWrapper'].style.height = this.m_logic [id][4];

				this.onFocus (id);
			}

			this._serializeBlocks ();
		}


		function MDrawCompoIDesign_onLock (object, id)
		{
			this._unserialize ();

            if (this.m_logic [id] && this.m_logic [id][8] && this.m_logic [id][7])
            {
    			var button;
    			if (document.all [this.m_elementId + '_imgSharing[' + id + ']'])
    				button = document.all [this.m_elementId + '_imgSharing[' + id + ']'];
            
    			var icon = this.m_iconUnlock;
                var alt = this.m_altUnlock;
    			var sharing = 'none';
            
                var prefix = this.m_logic [id][8];
                var locked = document.all [prefix + '[' + this.m_logic [id][7][0] + ']'].value;
                
    			if (locked & 1)
    			{
    				icon = this.m_iconLock;
                    alt = this.m_altLock;
    				sharing = 'inline';
    			}
                
    			locked ^= 1;
                
       			object.src = icon;
                object.alt = alt;
    
    			if (button)
    				button.style.display = sharing;
                
                this._lock (id, locked);
            }
		}
        
        
                function _MDrawCompoIDesign_lock (id, locked)
                {
                    var prefix = this.m_logic [id][8];
                    
                    if (this.m_logic [id][7])
                        for (var i = 0; i < this.m_logic [id][7].length; i++)
                            document.all [prefix + '[' + this.m_logic [id][7][i] + ']'].value = locked;

                    if (this.m_logic [id][9])
                        for (var i = 0; i < this.m_logic[id][9].length; i++)                
                            this._lock (this.m_logic[id][9][i], locked);
                }

				function _MDrawCompoIDesign_showExclamation (object, text)
				{
					if (this.m_firstBad)
					{
						eval (this.m_refCollection + '.hideSelects (true);');

						var bubble = document.createElement ('div');

						bubble.id = this.m_elementId + 'bubble';
						bubble.className = this.m_cssBubble;
						bubble.innerHTML = (text) ? text : this.m_exclamationSystemField;
						bubble.style.position = 'absolute';
						bubble.noWrap = true;

						var maxWidth = document.body.clientLeft + document.body.clientWidth;

						object.insertAdjacentElement ('beforeBegin', bubble);

						var maxBubbleWidth = bubble.offsetLeft + bubble.offsetWidth;
						var newLeft = bubble.offsetLeft - bubble.offsetWidth + object.offsetWidth;
						if (maxBubbleWidth > maxWidth && newLeft > 0)
							bubble.style.left = newLeft;

						bubble.style.top = bubble.offsetTop - bubble.offsetHeight;
					}
				}


				function _MDrawCompoIDesign_hideExclamation ()
				{
					var bubbleName = this.m_elementId + 'bubble';

					if (document.all [bubbleName])
					{
						eval (this.m_refCollection + '.showSelects (true);');

						var bubble = document.all [bubbleName];
						bubble.removeNode (true);
					}
				}


        function MDrawCompoIDesign_complete (name, flag)
        {
            if (this.m_cells [name] && this.m_cells [name]['d'] && ((window.event && window.event.type == 'blur') || flag))
            {
                var object = document.all [name];
                eval (this.m_refCollection + '.complete(\'' + this.m_cells [name]['d'] + '\',object);');
            }
        }

        
        function MDrawCompoIDesign_completeAcceptor (name, flag, force)
        {
            if (this.m_cells [name] && this.m_cells [name]['a'] && ((window.event && window.event.type == 'blur') || flag || force))
            {
                var object = document.all [name];
                
                if (typeof (object.value) != 'undefined' && this.m_acceptors [name])
                {
                    if (object.value == '')
                        eval (this.m_refCollection + '.completeAcceptor(\'' + this.m_cells [name]['a'] + '\',\'' + name + '\',false,flag);');
                    else if (object.value != this.m_acceptors [name])
                        eval (this.m_refCollection + '.completeAcceptor(\'' + this.m_cells [name]['a'] + '\',\'' + name + '\',true,flag);');
                }
            }
        }
        
        
                function _MDrawCompoIDesign_rememberAcceptor (i)
                {
                    var object = document.all [i];
                    this.m_acceptors [i] = object.value;
                }
                
                
        function MDrawCompoIDesign_controlMultiple (id, count)
        {
            if (count > 0)
            {
    			var allowEmpty = this.controlEmptyMultiple (id);
                var ret = this.controlAll (id, false, allowEmpty);
                
                if (typeof (this.m_blocks [id]) != 'undefined' && !(this.m_blocks [id] & 1) && ret)
                {
                    this.m_blocks [id] ^= 1;
        			this._serializeBlocks ();                 
                }
                    
                return ret;
            }
            else
                return false;
        }
                
                
		function MDrawCompoIDesign_controlAll (id, flag, allowEmpty)
		{
			this._unserialize ();
			
			if (!flag) {
				this.m_firstBad = null;
				this.m_firstBadObject = null;
				this.m_exclamationMessage = null;
            } else if (this.m_logic [id] && this.m_logic [id][5] >= 0) {
				allowEmpty = this.controlEmptyMultiple (id);
//alert('id: ' + id + '\nm_logic [5]: ' + this.m_logic [id][5] + '\nallowEmpty: ' + allowEmpty);
            }
            
			var raiseError = false;

            if (this.m_logic [id] && this.m_logic [id][0])
            {
    			for (var i in this.m_logic [id][0])
    			{
    				var ret = this.controlAll (this.m_logic [id][0][i], true, allowEmpty);
    				raiseError |= !ret;
    			}
            }
//alert('allowEmpty: ' + allowEmpty);
			if (allowEmpty != true)
			{
//debug(this.m_logic[id], 'logic');
				if (this.m_logic [id] && this.m_logic [id][1])
				{
					for (var i = 0; i < this.m_logic [id][1].length; i++)
					{
						var cellName = this.m_logic [id][1][i];
						if (!this.m_cells[cellName])
							continue;
//@todo control existing
						var ret;
						if (this.m_cells[cellName]['_xr']) {
							ret = this.controlExistingList(cellName);
						    raiseError |= !ret;
						} else {
							var _raiseError = false;
							var element = document.all[cellName];
							if (element.length > 0 && element[0].type == 'password') {
								var sameValue = element[0].value;
								for (var p = 0; p < element.length; p++) {
									ret = this.controlInput(element[p], true);
								    _raiseError |= !ret;
								}
								if (!_raiseError) { 
									for (var p = 0; p < element.length; p++) {
										if (sameValue != element[p].value) {
									    	_raiseError |= true;
											if (!this.m_firstBad) {
												this.m_firstBad = cellName;
										    	//@todo chyba multi inputu
								                this.m_exclamationMessage = this.m_exclamationInvalidMultiField;
								            }
									    	break;
									    }
									}	
								}
								raiseError |= _raiseError;
							} else {
	   							ret = this.controlInput(element, true);
							    raiseError |= !ret;
	   						}
   						}
//alert('cellName: ' + cellName + '\nret: ' + ret);
					}
				}

	            if (this.m_logic [id] && this.m_logic [id][6])
	            {
                    for (var i = 0; i < this.m_logic [id][6].length; i++)
                    {
    	                var ret = this.controlBond (this.m_logic [id][6][i]);
    	                raiseError |= !ret;
                    }
	            }
			}
//alert('raiseError: ' + raiseError);
			if (!flag && raiseError)
			{
				if (this.m_firstBad)
				{
					var object = document.all [this.m_firstBad];                    
                    if (this.m_firstBadObject && object != this.m_firstBadObject) {
                    	object = this.m_firstBadObject;
                    }
                    
                    var compo;
                    var text;

					if (this.m_firstBad.substr (0, 3) == 'bnd') {
                        for (var l in this.m_logic)
                        {
                            if (this.m_logic [l][6] == this.m_firstBad)
                                compo = l;
                        }
                        
                        text = this.m_exclamationSystemField;
                    } else if (this.m_cells[this.m_firstBad] && this.m_cells[this.m_firstBad]['_xr']) {
                    	object = document.all[this.m_cells[this.m_firstBad]['_xr'] + '_divBody'];
                    	compo = this.m_cells[this.m_firstBad]['c'];
                        text = this.m_exclamationSystemField;
                    } else {
    					compo = this.m_cells [this.m_firstBad]['c'];
                        text = this.m_cells [this.m_firstBad]['e'];
                        if (this.m_exclamationMessage)
                        {
                            text = this.m_exclamationMessage;
                            this.m_exclamationMessage = null;
                        }
                    }
                    
  					var allow = true;
                    
                    if (compo)
                    {
    					while (this.m_logic [compo])
    					{
    						if (typeof (this.m_blocks [compo]) == 'undefined' || this.m_blocks [compo] & 1)
    							compo = this.m_logic [compo][2];
    						else
    						{
    							allow = false;
    							break;
    						}
    					}
                    }

					if (!allow)
					{
						this.onBlock (compo);
						document.all [this.m_elementId + '_imgBlock[' + compo + ']'].scrollIntoView ();
					}
                    
                    if (object.tagName && object.tagName.toLowerCase () == 'select') {
                    } else if (document.all [this.m_firstBad + '_img']) {
                        object = document.all [this.m_firstBad + '_img'];
                    } else if (object.length && object.length > 0) {
                        object = object [0];
                    }
                    
                    if (object.name && this.m_cells [object.name] && this.m_cells [object.name]['_wo']) {
                        eval (this.m_cells[object.name]['_ro'] + '.config(\'MDC_CONTAINER\',\'' + this.m_elementId + '._hideExclamation()\');');
                        object = document.all [this.m_cells [object.name]['_wo']];
                    }
                    
					object.focus ();
                    
					this._showExclamation (object, text);
				}
			}

			return (!raiseError == 1) ? true : false;
		}


        function MDrawCompoIDesign_controlEmptyMultiple (id)
        {
            var empty = true;

			if (this.m_logic [id] && this.m_logic [id][1]) {
				for (var i = 0; i < this.m_logic [id][1].length; i++) {
                    var object = document.all [this.m_logic [id][1][i]];
                    
                    var ret = this._controlEmptyInput (object);
//debug (ret, empty + ' after: ' + (empty & ret) + ' type: ' + object.type + '\nid: ' + object.name);
                    empty &= ret;                    
				}
			}
//debug (empty, id + ' - after fields');
			if (this.m_logic [id] && this.m_logic [id][0])
			{
//debug (this.m_logic [id][0], 'sub idesigns');
				for (var i in this.m_logic [id][0])
				{
					var ret = this.controlEmptyMultiple (this.m_logic [id][0][i]);
//debug (ret, id + ' - inner XXX ' + this.m_logic [id][0][i]);
					empty &= ret;
				}
			}
//debug (empty, id + ' - after all');
            return empty;
        }


        function MDrawCompoIDesign_controlBond (name)
        {
            var object = document.all [name];
            var raiseError = this._controlEmptyInput (object);

			if (raiseError)
			{
				if (!this.m_firstBad)
					this.m_firstBad = name;
            }
          
			return !raiseError;
        }

        
                function _MDrawCompoIDesign_controlEmptyInput (object)
                {
                    var empty = true;
                    if (object.tagName && object.tagName.toLowerCase () == 'select' && object.disabled != true)
                    {
                        for (var i = 0; i < object.length; i++)
                            if (object [i].selected == true && object [i].value != '')
                            {
                                empty = false;
                                break;
                            }
                    }
                    else
                    {
                        if (object.length)
                        {
                            for (var i = 0; i < object.length; i++)
                                if (object [i].checked == true)
                                {
                                    if (object [i].disabled)
                                        empty = object [i].disabled;
                                    else
                                        empty = false;
                                    break;
                                }
                        }
                        else
                        {
                            switch (object.type)
                            {
                                case 'checkbox':
                                case 'radio':
                                    if (object.checked == true && object.disabled != true)
                                        empty = false;
                                    break;
                                    
                                default:
                                    if (object.value && object.value != '' && !object.value.match ('^\\s*$'))
                                    {
//debug (object.disabled, 'object.disabled');
                                        if (object.disabled)
                                            empty = object.disabled;
                                        else
                                            empty = false;
                                    }
                                    break;
                            }
                        }
                    }

        			return empty;
                }
                
                
                function MDrawCompoIDesign_isDisabled (name)
                {
                    if (this.m_cells [name] && this.m_cells [name]['o'] == 1)
                        return false;
                    
                    return true;
                }
        

		function MDrawCompoIDesign_controlInput (object, flag, force)
		{
			this._unserialize ();
//debug ('controlInput', window.event.type);
			var tag = object.tagName;
			var name = object.name;
			
			var raiseError = false;
            var empty = false;

            if (this.m_cells [name] && this.m_cells [name]['_ro']) {
//debug(this.m_cells [name]['_wo'], this.m_cells [name]['_ro']);
                eval(this.m_cells [name]['_ro'] + '.toServerSide();');
            }
            
			var empty = this._controlEmptyInput (object);

//debug (this._controlEmptyInput (object), name + ' - controlEmptyInput: ' + object.type);
/*			if (!object.value || object.value == '')
                empty = true;    
*/
            if (this.m_cells [name] && this.m_cells [name]['o'] == 1)
                return true;

			if (this.m_cells [name] && this.m_cells [name]['s'] && this.m_cells [name]['s'] != '0' && empty) {
				raiseError = true;
				if (!this.m_firstBad) {
	                this.m_exclamationMessage = this.m_exclamationSystemField;
	            }
            }
/* doplnanie */
            if (this.m_cells [name] && this.m_cells [name]['d'] && ((window.event && window.event.type == 'blur') || force))
                eval (this.m_refCollection + '.complete(\'' + this.m_cells [name]['d'] + '\',object);');
                
            if (this.m_cells [name] && this.m_cells [name]['_c'])
                eval (this.m_refCollection + '.completeActiveControler(\'' + this.m_cells [name]['_c'] + '\');');
                
            if (this.m_cells [name] && this.m_cells [name]['a'] && ((window.event && window.event.type == 'blur') || force))
                this.completeAcceptor (name, false, force);
/*@*/
            if (!empty && this.m_cells[name])
            {
            	var lookUp = -1;
            	if (this.m_cells[name]['l']) {
            		lookUp = this.m_cells[name]['l'];
            	}
            	if (MDrawCompoIDesign.lookUpMethods[lookUp]) {
					var values = MDrawCompoIDesign.lookUpMethods[lookUp](object.value, flag);
					if (flag) {
//debug(values, 'values');
						if (typeof(values) != 'boolean') {
							var dataFormat = false;
							var regexp = false;
			    			if (this.m_cells [name]['f'] && this.m_cells [name]['f'] != '') {
			    				dataFormat = this.m_cells [name]['f'];
			    			}
			    			if (this.m_cells [name]['x'] && this.m_cells [name]['x'] != '') {
			    				regexp = this.m_cells [name]['x'];
			    			}
//debug(dataFormat, 'dataFormat');
			    			if (dataFormat || regexp) {
			    				var newValues = new Array();
			    				for (var v = 0; v < values.length; v++) {
			    					if (dataFormat) {
				    					var newValue = this._checkValue(values[v], dataFormat);
//debug(newValue, 'newValue - ' + v);
					    		   		if ((typeof(newValue) == 'boolean' && newValue == false) || typeof(newValue) == 'undefined') {
					    		   			newValues[v] = values[v];
					                        raiseError = true;
					                    } else {
					                    	newValues[v] = newValue;
					                    }
									}
									if (regexp && !empty && !newValues[v].match(regexp)) {
										raiseError = true;
									}
			    				}
//debug(newValues, 'newValues');
			    				object.value = MDrawCompoIDesign.resolveMethods[lookUp](object.value, newValues);
			    			}
						} else if (values == false) {
							raiseError = true;
							if (!this.m_firstBad) {
	                			this.m_exclamationMessage = this.m_exclamationSearchField;
	            			}
						}
					} else if (values == false) {
						raiseError = true;
					}
            	} else {
//debug(flag, 'flag');
//debug(this.m_cells[name]['f'], 'this.m_cells [name][f]');
	    			if (flag && this.m_cells [name]['f'] && this.m_cells [name]['f'] != '') {
	    				var dataFormat = this.m_cells [name]['f'];
	    				var newValue = this._checkValue (object.value, dataFormat);
	    		   		if ((typeof(newValue) == 'boolean' && newValue == false) || typeof(newValue) == 'undefined') {
	                        raiseError = true;
							if (!this.m_firstBad) {
				                this.m_exclamationMessage = this.m_exclamationFormatField;
				            }
	    				} else {
	    					object.value = newValue;
	    				}
	    			}
	            
	    			if (this.m_cells [name]['x'] && this.m_cells [name]['x'] != '') {
	    				var regexp = this.m_cells [name]['x'];
	    		   		if (!empty && !object.value.match(regexp)) {
	    					raiseError = true;
	    				}
	    			}
	    		}
            }

			if (raiseError)
			{
				if (!this.m_firstBad) {
					this.m_firstBad = name;
					this.m_firstBadObject = object;
				}

				object.className = this.m_cssValidateError;
			}
			else
				object.className = this.m_cssValidateOk;

			return !raiseError;
		}


	            function _MDrawCompoIDesign_checkDate (value)
				{
	                var val = value;
	                var date_arr = new Array();

	                date_arr[2] = parseInt(val, 10) + '';
	                var cut = date_arr[2].length;

					if (date_arr[2] < 10 && val.substring(0,1) == '0') {
	                    cut++;
	                }

	                val = val.substring(cut+1);

	                date_arr[1] = parseInt(val, 10) + '';
	                cut = date_arr[1].length;
	                if (date_arr[1] < 10 && val.substring(0,1) == '0')
	                    cut++;

	                val = val.substring(cut+1);

	                date_arr[0] = parseInt(val, 10) + '';
                    
	    			if (date_arr[0] >= 1900 && date_arr[0] < 2000) {
	    				date_arr[0] = parseInt(date_arr[0].substring(2), 10);
	    			} else if (date_arr[0] >= 0 && date_arr[0] < 100) {
	    			    date_arr[0] = parseInt(date_arr[0], 10);
	    			    date_arr[0] += 2000;
	    			}

	    			var formDay   = date_arr[2];
	    			var formMonth = date_arr[1]-1;
	    			var formYear  = date_arr[0];

	    			var datum = new Date(formYear, formMonth, formDay);
	    			if (!((datum.getDate() == formDay) && (datum.getMonth() == formMonth) && (datum.getYear() == formYear))) {
	    			    return false;
	    			} else {
	    				return (datum.getDate() < 10 ? '0' : '') + datum.getDate() + '.' + (datum.getMonth() < 9 ? '0' : '') + (datum.getMonth()+1) + '.' + (datum.getYear() < 100 ? '19' : '') + (datum.getYear() < 10 ? '0' : '') + datum.getYear();
	    			}
	            }


	            function _MDrawCompoIDesign_checkTime (value)
				{
	                var time = value.split (':');
                    
	                time [0] = parseInt (time [0], 10);
	                time [1] = parseInt (time [1], 10);

                    var result = '';
                    
	                if (time [0] >= 0 && time [0] < 24)
	                    result = (time [0] < 10 ? '0' : '') + time [0];
                    else
	                    return false;
                    
                    if (time [1])    
                    {
	                    if (time [1] && time [1] >= 0 && time [1] < 60)
	                        result += ':' + (time [1] < 10 ? '0' : '') + time [1];
                        else
                            return false;
                    }
                    else
	                    result += ':00';
                        
	                if (time [2])
                    {
	                    time [2] = parseInt (time [2], 10);
	                    if (time [2] >= 0 && time [2] < 60)
	                        result += ':' + (time [2] < 10 ? '0' : '') + time [2];
	                }
                    
	                return result;
	            }


	            function _MDrawCompoIDesign_checkValue (value, format)
				{
					if (format == 'text')
						return value;

	                var temp_arr = new Array();
	                temp_arr = format.split(' ');
	                if (temp_arr.length != null && temp_arr.length == 1) {
	                    switch (format) {
	                        case 'date':    return this._checkDate(value);
	                                        break;
	                        case 'time':    return this._checkTime(value);
	                                        break;
	                        case 'datetime':    var temp_arr = new Array();
	                                            temp_arr = value.split(' ');
	                                            var date_ret = this._checkDate(temp_arr[0]);
	                                            var time_ret = this._checkTime(temp_arr[1]);
	                                            if (date_ret != false && time_ret != false) {
	                                                return date_ret + ' ' + time_ret;
	                                            } else
	                                                return false;
	                                            break;
	                    }
	                } else if (temp_arr.length == 3) {
                         value = value.replace(',','.');
	                    if (parseFloat(value) == value && temp_arr[0] == "number" && temp_arr[1] == "decimal" && parseInt(temp_arr[2]) == temp_arr[2]) {
                            return this._checkNumber (value, temp_arr);
	                    } else
	                        return false;

	                } else {
	                    return false;
	                }
	            }


				function _MDrawCompoIDesign_checkNumber(value, temp_arr)
				{
                     if (!value.match('^[0-9]*(\.|,)?[0-9]*'))
                         return false;
                     var act = 0;
                     var num = parseInt(temp_arr[2], 10);
                     value = value.replace(',','.');
                     var num_arr = new Array();num_arr = value.split('.');
                     if (num_arr == value) {
                         num_arr[0] = parseInt(value, 10) + '';
                         num_arr[1] = '';
                     } else {
                         num_arr[1] += '';
                         act = num_arr[1].length;
                         if (num_arr[0] == '')
                             num_arr[0] = '0';
                         else
                             num_arr[0] = parseInt(num_arr[0], 10) + '';
                     }

                     if (act > num) {
                         var rounded = Math.round(parseFloat(num_arr[1].substring(0,num) + '.' + num_arr[1].substring(num))) + '';
                         num_arr[1] = rounded.substring(0, num);
                     } else {
                         for (;act < num; act++) {
                             num_arr[1] += '0';
                         }
                     }
                     
                     return num_arr[0] + (num_arr[1] != '' ? '.' + num_arr[1] : '');
				}
				
				MDrawCompoIDesign.prototype.controlExistingList = function (name) {
					var raiseError = false;
		            var empty = true;
		            
				 	if (this.m_cells [name] && this.m_cells [name]['o'] == 1) {
		            	return true;
		           	}

					if (this.m_cells[name] && this.m_cells[name]['_xr']) {
						var cells = null;
						var list = null;
						eval('if(' + this.m_cells[name]['_xr'] + ' != -1){list = ' + this.m_cells[name]['_xr'] + ';}');
						if (list != null) {
							cells = list.m_cells;
						}
						if (cells != null) {
							for (var i in cells) {
								if (cells[i]) {
									empty = false;
									break;
								}
							}
						}
					}

					if (this.m_cells [name] && this.m_cells [name]['s'] 
						&& this.m_cells [name]['s'] != '0' && empty) {
						raiseError = true;
		                this.m_exclamationMessage = this.m_exclamationSystemField;
            		}
            		
            		if (raiseError) {
						if (!this.m_firstBad)
							this.m_firstBad = name;
					}

					return !raiseError;
				}
				
function _MDrawCompoIDesign_lookUpNumeric (value, flag) {
	var regexp = /^\s*(((<|>)?(=)?)|(<>)?)?\s*([\+\-]?\d+([\.,]\d*)?)(\s*(\s+AND\s+|\s+OR\s+)?(((<|>)?(=)?)|(<>)?)?\s*([\+\-]?\d+([\.,]\d*)?))*\s*$/;
	var stripper = /([\+\-]?\d+([\.,]\d*)?)/g;
	if (value != '') {
		if (value.match(regexp)) {
			if (flag) {
				var grab = value.match(stripper);
				var valueIndex = 0;
				var values = new Array();
				while (grab[valueIndex]) {
					values[valueIndex] = grab[valueIndex];
					valueIndex++;
				}
				return values;
			} else {
				return true;
			}
		} else {
			return false;
		}
	}
	return true;
}

function _MDrawCompoIDesign_resolveNumeric (value, values) {
	var spliter = /([^\+\-\d\.\,]+)/g;
	var grab = value.match(spliter);

	var valueIndex = 0;
	var separations = new Array();
	while (grab && grab[valueIndex]) {
		separations[valueIndex] = grab[valueIndex];
		valueIndex++;
	}
	if ((separations.length < values.length)
		|| (separations.length == values.length && grab.lastIndex == value.length)) {
		var temp = separations;
		separations = values;
		values = temp;
	}
	var newValue = '';
	for (var s = 0; s < separations.length; s++) {
		if (separations[s]) {
			newValue += separations[s];
		}
		if (values[s]) {
			newValue += values[s];
		}
	}
	return newValue;
}