/*global window, YAHOO, MEDECO */
/*jslint white: true, onevar: true, browser: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: false, newcap: true, immed: true */
if (!this.MEDECO) {
	this.MEDECO = {};
}
(function () {

	//VERSION
	//14.0.1.8

	//Aliasses
	var Y = YAHOO,
		Event = Y.util.Event,
		Dom = Y.util.Dom,
		Cookie = Y.util.Cookie;

	//EXTEND Y.util.Dom
	if (typeof Dom.createElement !== 'function') {
		Dom.createElement = function (type, id, className, innerHTML, parent) {
			var oElement = document.createElement(type);
			if (id) {
				oElement.id = id;
			} else {
				//Set unique ID
				Y.util.Dom.generateId(oElement, 'syn-gen');
			}
			
			if (className) {
				oElement.className = className;
			}
			if (typeof innerHTML !== 'undefined' && innerHTML !== null) { 
				if (typeof oElement.innerHTML !== 'undefined') {
					oElement.innerHTML = innerHTML;
				}
			}			
			if (parent) {
				parent.appendChild(oElement);
			}
			//Null
			parent = null;
			//Result
			return oElement;
		};
	}

	//Dom.createCheckbox
	if (typeof Dom.createCheckbox !== 'function') {
		Dom.createCheckbox = function (id, className, value, parent) {
			var oElement = document.createElement('input');
			oElement.type = 'checkbox';
			if (id) {
				oElement.id = id;
			} else {
				//Set unique ID
				Y.util.Dom.generateId(oElement, 'syn-gen');
			}
			
			if (className) {
				oElement.className = className;
			}
			oElement.value = value;
			if (parent) {
				parent.appendChild(oElement);
			}
			//Null
			parent = null;
			//Result
			return oElement;
		};
	}


	//HELPERS
	//--------------------------------------------------------------

	//MEDECO.helpers
	if (typeof MEDECO.helpers !== 'object') {
		MEDECO.helpers = {};
	}

	//MEDECO.helpers.showHide
	if (typeof MEDECO.helpers.showHide !== 'function') {
		MEDECO.helpers.showHide = function (objName) {
			var obj = Dom.get(objName);
			if (obj) {
				if (Dom.hasClass(obj, 'pb-hidden')) {
					Dom.removeClass(obj, 'pb-hidden');
				} else {
					Dom.addClass(obj, 'pb-hidden');
				}
			}
			return false;
		};
	}

	//MEDECO.helpers.userFilter
	if (typeof MEDECO.helpers.userFilter !== 'object') {
		MEDECO.helpers.userFilter = {
			'name' : 'userFilter',
			'cover' : null,
			'dialog' : null,
			'filters' : [],
			//add
			'add' : function () { 
				//Var
				var html = '',
					nodes,
					i,
					l,
					n;
				
				//Validate
				if (!this.validateSelectedItems()) {
					return;
				}
				
				
				//Test for currently active cover
				if (Y.lang.isObject(this.cover)) {
					return;
				}				
			
				//Create elements
				this.cover = Dom.createElement('div', 'pb-throbber-cover');
				this.dialog = Dom.createElement('div', 'pb-throbber-dialog-white');
				
				//Node
				nodes = this.getSelectedNodes();
				
				//Build html
				
				
				
				html += '<div class="inner">';
				html += '<div style="position: absolute; top : 0px; right: 0px; padding: 8px; cursor : pointer;" onclick="MEDECO.helpers.userFilter.close();"><b>X</b></div>';
				html += '<form method="post" action="/html/medbis/assortmentfilters/setFilter" onsubmit="return MEDECO.helpers.userFilter.validateForm();">';
				html += '<table cellpadding="3" cellspacing="3" border="0">';
				html += '	<tr>';
				html += '		<td colspan="2"><b>Selectie toevoegen aan filter</b></td>';
				html += '	</tr>';

				html += '	<tr>';
				html += '		<td colspan="2">U kunt hier aangeven aan welke filters de geselecteerde artikelen moeten worden toegevoegd. Kies &eacute;&eacute;n of meerdere filters om de artikelen aan toe te voegen. Het is ook mogelijk om direct een nieuw filter aan te leggen.</td>';
				html += '	</tr>';
				
				html += '	<tr>';
				html += '		<td valign="top">Kies &eacute;&eacute;n of meerdere filters.</td>';
				html += '		<td>';
				html += '			<div class="pb-filter-box">';
					//Add filters
				l = MEDECO.helpers.userFilter.filters.length;
				for (i = 0; i < l; i += 1) {
					n = MEDECO.helpers.userFilter.filters[i];
					html += '<label><input type="checkbox" class="filterCheckbox" name="filterSelection[]" id="filterSelection_' + i + '" value="' + n.Id + '">' + n.Name  + '</label><br>';
				}					
				html += '			</div>';
				html += '		</td>';
				html += '	</tr>';

				html += '	<tr>';
				html += '		<td>of maak een nieuw filter</td>';
				html += '		<td><input type="text" name="filterName" id="filterName" value="" style="width: 244px;" class="pb-field"></td>';
				html += '	</tr>';
				
				//nodes
				html += '	<tr>';
				html += '		<td>&nbsp;</td>';
				html += '		<td>';
				l = nodes.length;
				for (i = 0; i < l; i += 1) {
					html += '	<input type="hidden" name="FilterValue[]" value="' + nodes[i] + '">';
				}
				html += '			<input type="submit" value="Toevoegen aan filter" class="pb-button-large">';
				html += '		</td>';
				html += '	</tr>';
				
				
				html += '</table>';
				html += '</form>';
				html += '</div>';
		
				//Add message
				this.dialog.innerHTML = html;
				
				//Append
				document.body.appendChild(this.cover);
				document.body.appendChild(this.dialog);
			
				//Resize
				this.resize();
				
				//Add listener
				Event.addListener(window, 'resize', MEDECO.helpers.userFilter.resize);
				Event.addListener(window, 'scroll', MEDECO.helpers.userFilter.resize);				
			},
			//remove
			'remove' : function () { 
				//Var
				var html = '',
					nodes,
					i,
					l,
					n;
				
				//Validate
				if (!this.validateSelectedItems()) {
					return;
				}
				
				
				//Test for currently active cover
				if (Y.lang.isObject(this.cover)) {
					return;
				}				
			
				//Create elements
				this.cover = Dom.createElement('div', 'pb-throbber-cover');
				this.dialog = Dom.createElement('div', 'pb-throbber-dialog-white');
				
				//Node
				nodes = this.getSelectedNodes();
				
				//Build html
				
				
				
				html += '<div class="inner">';
				html += '<div style="position: absolute; top : 0px; right: 0px; padding: 8px; cursor : pointer;" onclick="MEDECO.helpers.userFilter.close();"><b>X</b></div>';
				html += '<form method="post" action="/html/medbis/assortmentfilters/removeFilter" onsubmit="return MEDECO.helpers.userFilter.validateForm();">';
				html += '<table cellpadding="3" cellspacing="3" border="0">';
				html += '	<tr>';
				html += '		<td colspan="2"><b>Selectie verwijderen uit filter</b></td>';
				html += '	</tr>';

				html += '	<tr>';
				html += '		<td colspan="2">U kunt hier aangeven uit welke filters de geselecteerde artikelen moeten worden verwijderd. Kies &eacute;&eacute;n of meerdere filters om de artikelen uit te verwijderen.</td>';
				html += '	</tr>';
				
				html += '	<tr>';
				html += '		<td valign="top">Kies &eacute;&eacute;n of meerdere filters.</td>';
				html += '		<td>';
				html += '			<div class="pb-filter-box">';
				//Add filters
				l = MEDECO.helpers.userFilter.filters.length;
				for (i = 0; i < l; i += 1) {
					n = MEDECO.helpers.userFilter.filters[i];
					html += '<label><input type="checkbox" class="filterCheckbox" name="filterSelection[]" id="filterSelection_' + i + '" value="' + n.Id + '">' + n.Name  + '</label><br>';
				}					
				html += '			</div>';
				html += '		</td>';
				html += '	</tr>';

				//nodes
				html += '	<tr>';
				html += '		<td>&nbsp;</td>';
				html += '		<td>';
				l = nodes.length;
				for (i = 0; i < l; i += 1) {
					html += '	<input type="hidden" name="FilterValue[]" value="' + nodes[i] + '">';
				}
				html += '			<input type="submit" value="Verwijderen uit filter" class="pb-button-large">';
				html += '		</td>';
				html += '	</tr>';
				
				
				html += '</table>';
				html += '</form>';
				html += '</div>';
		
				//Add message
				this.dialog.innerHTML = html;
				
				//Append
				document.body.appendChild(this.cover);
				document.body.appendChild(this.dialog);
			
				//Resize
				this.resize();
				
				//Add listener
				Event.addListener(window, 'resize', MEDECO.helpers.userFilter.resize);
				Event.addListener(window, 'scroll', MEDECO.helpers.userFilter.resize);				
			},
			//validateForm
			'validateForm' : function () {
				//Var
				var listCheckboxes = Dom.getElementsByClassName('filterCheckbox'),
					oName = document.getElementById('filterName'),
					newName = Y.lang.trim(oName.value),
					valid = false,
					i,
					l = listCheckboxes.length,
					k;
				
				//Loop checkboxes
				for (i = 0; i < l; i += 1) {
					k = listCheckboxes[i];
					if (k.checked) {
						valid = true;
					}
				}
				
				if (newName !== '') {
					valid = true;
				}
				
				//Test values				
				if (!valid) {
					alert('Kies een bestaand filter of maak een nieuw aan.');
					return false;
				}
				
				//Result
				return true;
			},
			//close
			'close' : function () {
				//Var
				var hlp = MEDECO.helpers.userFilter;
				//REmove events
				Event.removeListener(window, 'resize', MEDECO.helpers.userFilter.resize);
				Event.removeListener(window, 'scroll', MEDECO.helpers.userFilter.resize);				
				//Remove from body
				if (Y.lang.isObject(hlp.cover)) {
					document.body.removeChild(hlp.cover);
				}
				if (Y.lang.isObject(hlp.dialog)) {
					document.body.removeChild(hlp.dialog);
				}
				//Set null
				hlp.cover = null;
				hlp.dialog = null;				
			},
			//resize
			'resize' : function () {
				//Var
				var o = MEDECO.helpers.userFilter,
					vpWidth = Dom.getViewportWidth(),
					vpHeight = Dom.getViewportHeight(),
					scrollTop = Dom.getDocumentScrollTop(),
					scrollLeft = Dom.getDocumentScrollLeft(),
					cvWidth = vpWidth,
					cvHeight = vpHeight,
					cvTop = scrollTop,
					cvLeft = scrollLeft,
					thRegion,
					thTop,
					thLeft;	
					
				//Test for currently active cover
				if (!Y.lang.isObject(o.cover)) {
					return;
				}					

				//GEt region
				thRegion = Dom.getRegion(o.dialog);
				
				//Test regin
				if (!thRegion) {
					return;
				}
				
				//Calc dialog pos
				thTop = ((vpHeight - thRegion.height) / 2) + scrollTop;
				thLeft = ((vpWidth - thRegion.width) / 2) + scrollLeft;

				//Test for 0
				cvWidth = (cvWidth < 0) ? 0 : cvWidth;
				cvHeight = (cvHeight < 0) ? 0 : cvHeight;
				
				//Set cover
				Dom.setStyle(o.cover, 'position', 'absolute');
				Dom.setStyle(o.cover, 'top', cvTop + 'px');
				Dom.setStyle(o.cover, 'left', cvLeft + 'px');
				Dom.setStyle(o.cover, 'width', cvWidth + 'px');
				Dom.setStyle(o.cover, 'height', cvHeight + 'px');
				Dom.setStyle(o.cover, 'opacity', 0.5); 
				
				//Set dialog
				Dom.setStyle(o.dialog, 'position', 'absolute');
				Dom.setStyle(o.dialog, 'top', thTop + 'px');
				Dom.setStyle(o.dialog, 'left', thLeft + 'px');				
												
			},
			//validateSelectedItems
			'validateSelectedItems' : function () {
				//Retrieve
				var list = this.getSelectedNodes();
				
				//Test
				if (list.length < 1) {
					alert('Selecteer 1 of meerdere artikelen om toe te voegen aan uw filter.');
					return false;
				}
				
				//Result
				return true;
			},
			//getSelectedNodes
			'getSelectedNodes' : function () {
				//Var
				var nodeList = Dom.getElementsByClassName('userFilter'),
					i,
					l = nodeList.length,
					n,
					nodes = [];
				//Loop
				for (i = 0; i < l; i += 1) {
					n = nodeList[i];
					if (n.checked) {
						nodes.push(n.value);
					}
				}
				//Result
				return nodes;				
			}
		};
	}

	//productPopup
	if (typeof MEDECO.helpers.productPopup !== 'object') {
		MEDECO.helpers.productPopup = {
			'productList' : null,
			'instance' : null,
			'clear' : function () {
				//Remove from body
				if (MEDECO.helpers.productPopup.instance) {
					Event.removeListener(MEDECO.helpers.productPopup.instance, 'mouseover');
					document.body.removeChild(MEDECO.helpers.productPopup.instance);
					MEDECO.helpers.productPopup.instance = null;
				}
				Event.removeListener(document, 'mouseover');
			},
			'stopMouseOverEvent' : function (e) {
				Event.stopEvent(e);
			},
			'show' : function (e, prd_id) {
				var product = MEDECO.helpers.productPopup.productList[prd_id],
					ev = Event.getEvent(e),
					targetEl = Event.getTarget(ev),
					vpHeight = Dom.getViewportHeight(),
					scrollTop = document.body.scrollTop || document.documentElement.scrollTop,
					maxY = vpHeight + scrollTop,
					popupEl,
					icoEl,
					hEl,
					pEl,
					clearEl,
					xy = Dom.getXY(targetEl),
					topPos = xy[1] + 5,
					leftPos = xy[0] + 10,
					elHeight,
					currentY;
					//xy = Event.getXY(ev);
				
				//Test for instance
				if (MEDECO.helpers.productPopup.instance) {
					MEDECO.helpers.productPopup.clear();
				}
				
				//Test for product
				if (product) {
					//Create new child
					popupEl = Dom.createElement('div', null, 'pb-assortment-productinfo');
					Event.on(popupEl, 'mouseover', MEDECO.helpers.productPopup.stopMouseOverEvent);
					if (product.icon) {
						icoEl = Dom.createElement('img');
						icoEl.src = product.icon;
						popupEl.appendChild(icoEl);
					}
					//hEl = Dom.createElement('h3', null, null, 'ScrollTop:' + scrollTop + ' vpHeight: ' + vpHeight, popupEl);
					
					hEl = Dom.createElement('h3', null, null, product.name, popupEl);
					pEl = Dom.createElement('p', null, null, product.indi, popupEl);
					pEl = Dom.createElement('p', null, null, product.info, popupEl);
					clearEl = Dom.createElement('div', null, 'pb-clear', null, popupEl);
					
					//Set top + left
					popupEl.style.top = topPos + 'px';
					popupEl.style.left = leftPos + 'px';
					
					//Map
					MEDECO.helpers.productPopup.instance = popupEl;
					
					//Append
					document.body.appendChild(MEDECO.helpers.productPopup.instance);
					
					//Test for maxY
					elHeight = MEDECO.helpers.productPopup.instance.offsetHeight;
					currentY = elHeight + topPos;
					
					if (currentY > maxY) {
						topPos = maxY - elHeight;
						popupEl.style.top = topPos + 'px';
					}
					
					
					//Kill event
					Event.stopEvent(ev);
					
					//Set new event
					Event.on(document, 'mouseover', MEDECO.helpers.productPopup.clear);
					
					//Null
					targetEl = null;
					popupEl = null;
					icoEl = null;
					hEl = null;
					pEl = null;
					clearEl = null;
					product = null;
					ev = null;
					
				}
			}
		};
	}

	//MEDECO.helpers.getPackagePrice
	if (typeof MEDECO.helpers.getPackagePrice !== 'function') {
		MEDECO.helpers.getPackagePrice = function (unit_id, mat_id, fieldName) {
						
			//handleDataReceived
			function handleDataReceived(o) {
				//Var
				var result = MEDECO.helpers.parseRequest(o),
					fldObj = Dom.get(fieldName);
				
				//Test on code
				if (result.code.toString() === '200') {
					if (fldObj) {
						fldObj.innerHTML = '&euro; ' + result.data;
					}
				} else {
					alert(result.message);
				}
			}
			
			//handleFailure
			function handleFailure(o) {
				alert(o.status + '-' + o.statusText);
			}
			
			//request
			function request() {
				var type = 'get',
					url = '/json/medbis/assortment/getPackagePrice/' + mat_id + '/' + unit_id,
					handlers = {
						failure : handleFailure,
						success : handleDataReceived
					};
				
				//Exec
				Y.util.Connect.asyncRequest(type, url, handlers);	
			}

			request();
		};
	}

	//MEDECO.helpers.throbber
	if (typeof MEDECO.helpers.throbber !== 'object') {
		MEDECO.helpers.throbber = {
			cover : null,
			dialog : null,
			show : function (message) {
				//Var
				var hlp = MEDECO.helpers.throbber,
					html = '';
				
				//Test for currently active cover
				if (Y.lang.isObject(hlp.cover)) {
					return;
				}
				
				//Create divs
				hlp.cover = Dom.createElement('div', 'pb-throbber-cover');
				hlp.dialog = Dom.createElement('div', 'pb-throbber-dialog');
				
				//Build html
				html += '<div class="inner">';
				html += '<table cellpadding="2" cellspacing="2" border="0">';
				html += '	<tr>';
				html += '		<td colspan="2" style="text-align: center"><b>Een ogenblik geduld A.U.B</b></td>';
				html += '	</tr>';
				html += '	<tr>';
				html += '		<td valign="top"><img src="/framework/modules/General/images/check.png" alt=""></td>';
				html += '		<td valign="top">' + message + '</td>';
				html += '	</tr>';
				html += '</table>';
				html += '</div>';
		
				//Add message
				hlp.dialog.innerHTML = html;
				
				//Append
				document.body.appendChild(hlp.cover);
				document.body.appendChild(hlp.dialog);
				
				//Resize
				hlp.resize();
				
				//Add listener
				Event.addListener(window, 'resize', hlp.resize);
				Event.addListener(window, 'scroll', hlp.resize);
				
			},
			resize: function () {
				//Var
				var hlp = MEDECO.helpers.throbber,
					vpWidth = Dom.getViewportWidth(),
					vpHeight = Dom.getViewportHeight(),
					scrollTop = Dom.getDocumentScrollTop(),
					scrollLeft = Dom.getDocumentScrollLeft(),
					cvWidth = vpWidth,
					cvHeight = vpHeight,
					cvTop = scrollTop,
					cvLeft = scrollLeft,
					thRegion,
					thTop,
					thLeft;

				//Test for currently active cover
				if (!Y.lang.isObject(hlp.cover)) {
					return;
				}
				
				//GEt region
				thRegion = Dom.getRegion(hlp.dialog);
				
				//Test regin
				if (!thRegion) {
					return;
				}
				
				//Calc dialog pos
				thTop = ((vpHeight - thRegion.height) / 2) + scrollTop;
				thLeft = ((vpWidth - thRegion.width) / 2) + scrollLeft;
				
				//Test for 0
				cvWidth = (cvWidth < 0) ? 0 : cvWidth;
				cvHeight = (cvHeight < 0) ? 0 : cvHeight;
				
				//Set cover
				Dom.setStyle(hlp.cover, 'position', 'absolute');
				Dom.setStyle(hlp.cover, 'top', cvTop + 'px');
				Dom.setStyle(hlp.cover, 'left', cvLeft + 'px');
				Dom.setStyle(hlp.cover, 'width', cvWidth + 'px');
				Dom.setStyle(hlp.cover, 'height', cvHeight + 'px');
				Dom.setStyle(hlp.cover, 'opacity', 0.5);  

				//Set dialog
				Dom.setStyle(hlp.dialog, 'position', 'absolute');
				Dom.setStyle(hlp.dialog, 'top', thTop + 'px');
				Dom.setStyle(hlp.dialog, 'left', thLeft + 'px');
			},
			close : function () {
				//Var
				var hlp = MEDECO.helpers.throbber;

				//Remove listener
				Event.removeListener(window, 'resize', hlp.resize);
				Event.removeListener(window, 'scroll', hlp.resize);

				//Remove from body
				if (Y.lang.isObject(hlp.cover)) {
					document.body.removeChild(hlp.cover);
				}
				if (Y.lang.isObject(hlp.dialog)) {
					document.body.removeChild(hlp.dialog);
				}
				//Set null
				hlp.cover = null;
				hlp.dialog = null;
			}
		};
	}

	//MEDECO.helpers.imagePopup
	if (typeof MEDECO.helpers.imagePopup !== 'object') {
		MEDECO.helpers.imagePopup = {
			cover : null,
			dialog : null,
			imageList : [],
			currentImage : null,
			addImage : function (imageLocation) {
				MEDECO.helpers.imagePopup.imageList.push(imageLocation);
			},
			show : function (currentImage) {
				//Var
				var hlp = MEDECO.helpers.imagePopup,
					imgWidth,
					imgHeight,
					topBar,
					closeButtton;
				
				//Test for currently active cover
				if (Y.lang.isObject(hlp.cover)) {
					return;
				}
//				alert(currentImage);

				//Create divs
				hlp.cover = Dom.createElement('div', 'pb-throbber-cover');
				hlp.dialog = Dom.createElement('div', 'pb-image-dialog');
				
				//Create top bar with close button
				topBar = Dom.createElement('div', null, 'pb-image-topbar', null, hlp.dialog);
				closeButtton = Dom.createElement('div', null, 'pb-image-topbar-close', 'X', topBar);
				
				Event.on(closeButtton, 'click', hlp.close);
				
				//Load image
				hlp.currentImage = Dom.createElement('img');
				hlp.currentImage.src = currentImage;
				
				//Get width & height
				imgWidth = hlp.currentImage.width;
				imgHeight = hlp.currentImage.height;
				
				
				hlp.dialog.style.width = (imgWidth + 2) + 'px';
				
				hlp.dialog.appendChild(hlp.currentImage);
				//hlp.cover = Dom.createElement('div', 'pb-throbber-cover');
				
				//hlp.resize();
				
				//Append
				document.body.appendChild(hlp.cover);
				document.body.appendChild(hlp.dialog);
				
				//Event.on(hlp.currentImage, 'load', hlp.resize);
				//Resize
				
				hlp.resize();
				
				//Event.onDOMReady(hlp.resize);
				
				//Add listener
				Event.addListener(window, 'resize', hlp.resize);
				Event.addListener(window, 'scroll', hlp.resize);
				
			},
			resize: function () {
				//Var
				var hlp = MEDECO.helpers.imagePopup,
					vpWidth = Dom.getViewportWidth(),
					vpHeight = Dom.getViewportHeight(),
					scrollTop = Dom.getDocumentScrollTop(),
					scrollLeft = Dom.getDocumentScrollLeft(),
					cvWidth = vpWidth,
					cvHeight = vpHeight,
					cvTop = scrollTop,
					cvLeft = scrollLeft,
					thRegion,
					thTop,
					thLeft;

				//Test for currently active cover
				if (!Y.lang.isObject(hlp.cover)) {
					return;
				}
				
				//GEt region
				thRegion = Dom.getRegion(hlp.dialog);
				
				//Test regin
				if (!thRegion) {
					return;
				}
				
				//Calc dialog pos
				thTop = ((vpHeight - thRegion.height) / 2) + scrollTop;
				thLeft = ((vpWidth - thRegion.width) / 2) + scrollLeft;
				
				//Test for 0
				cvWidth = (cvWidth < 0) ? 0 : cvWidth;
				cvHeight = (cvHeight < 0) ? 0 : cvHeight;
				
				//Set cover
				Dom.setStyle(hlp.cover, 'position', 'absolute');
				Dom.setStyle(hlp.cover, 'top', cvTop + 'px');
				Dom.setStyle(hlp.cover, 'left', cvLeft + 'px');
				Dom.setStyle(hlp.cover, 'width', cvWidth + 'px');
				Dom.setStyle(hlp.cover, 'height', cvHeight + 'px');
				Dom.setStyle(hlp.cover, 'opacity', 0.5);  

				//Set dialog
				Dom.setStyle(hlp.dialog, 'position', 'absolute');
				Dom.setStyle(hlp.dialog, 'top', thTop + 'px');
				Dom.setStyle(hlp.dialog, 'left', thLeft + 'px');
				//alert([vpWidth, thRegion.width]);
			},
			close : function () {
				//Var
				var hlp = MEDECO.helpers.imagePopup;

				//Remove listener
				Event.removeListener(window, 'resize', hlp.resize); 
				Event.removeListener(window, 'scroll', hlp.resize);

				//Remove from body
				if (Y.lang.isObject(hlp.cover)) {
					document.body.removeChild(hlp.cover);
				}
				if (Y.lang.isObject(hlp.dialog)) {
					document.body.removeChild(hlp.dialog);
				}
				//Set null
				hlp.cover = null;
				//hlp.dialog = null;
			}
		};
	}


	//MEDECO.helpers.checkAssortimentDownload
	if (typeof MEDECO.helpers.checkAssortimentDownload !== 'function') {
		MEDECO.helpers.checkAssortimentDownload = function () {
			var formatEl = Dom.get('downloadFormat');
			
			if (formatEl) {
				if (formatEl.value !== '') {
					return true;
				} else {
					alert('Geef een export formaat op!');
				}
			}
			
			return false;
		};
	}

	//MEDECO.helpers.checkConversieDownload
	if (typeof MEDECO.helpers.checkConversieDownload !== 'function') {
		MEDECO.helpers.checkConversieDownload = function () {
			var el,
				fields = [
					{ 'key' : 'format', 'message' : 'Geef een apotheeksysteem op!' },
					{ 'key' : 'email', 'message' : 'Vul een geldig e-mailadres in!' },
					{ 'key' : 'apotheek', 'message' : 'Vul de naam van uw apotheek in!' }
				],
				i, 
				l = fields.length, 
				k,
				valid = true;
			
			for (i = 0; i < l; i += 1) {
				k = fields[i];
				el = Dom.get(k.key);
				if (el) {
					if (Y.lang.trim(el.value) === '') {
						el.className = 'pb-field-invalid';
//						alert(k.message);
						valid = false;
					} else {
						el.className = 'pb-field';
					}
				}
			}
			
			
			return valid;
		};
	}

	//MEDECO.helpers.parseRequest
	if (typeof MEDECO.helpers.parseRequest !== 'function') {
		MEDECO.helpers.parseRequest = function (o) {
			var result;
			//Try parse
			try {
				result = YAHOO.lang.JSON.parse(o.responseText);
			} catch (ex) {
				alert('Ontvangen JSON bericht voldoet niet aan de specificaties.\n ');
				alert(o.responseText);
				return false;
			}
			//Test object
			if (typeof result !== 'object') {
				alert('JSON result is not an object.');
				alert(o.responseText);
				return false;					
			}
			return result;				
		};
	}

	//MEDECO.helpers.toggleComboboxSelection
	if (typeof MEDECO.helpers.toggleComboboxSelection !== 'function') {
		MEDECO.helpers.toggleComboboxSelection = function (elName, isChecked) {
			//Var
			var dep = Dom.get(elName),
				i, 
				l, 
				k, 
				checkValue = (isChecked) ? true : false;
			
			//Test for type
			if (typeof dep.options !== 'object') {
				return false;
			}
			
			//Length
			l = dep.options.length;
			
			//Loop
			for (i = 0; i < l; i += 1) {
				k = dep.options[i];
				k.selected = checkValue;
			}
		};
	}	
	
	//MEDECO.helpers.toggleCheckboxSelection
	if (typeof MEDECO.helpers.toggleCheckboxSelection !== 'function') {
		MEDECO.helpers.toggleCheckboxSelectionByClassName = function (elName, isChecked) {
			//Var
			var checks = Dom.getElementsByClassName(elName),
				i, 
				l, 
				k, 
				checkValue = (isChecked) ? true : false;
			
			if (!checks) {
				return;
			}
			
			l = checks.length;
			for (i = 0; i < l; i += 1) {
				k = checks[i];
				k.checked = checkValue;
			}			
		};
	}		

	//MEDECO.helpers.toggleCheckbox
	if (typeof MEDECO.helpers.toggleCheckbox !== 'function') {
		MEDECO.helpers.toggleCheckbox = function (formName, checkboxName) {
			//Var
			var form = Dom.get(formName),
				i, 
				l, 
				idx, 
				k;
			if (form && form.elements) {
				l = form.elements.length;
				for (i = 0; i < l; i += 1) {
					k = form.elements[i];
					
					if (k.type === 'checkbox') {
						idx = k.name.indexOf(checkboxName);
						if (idx >= 0) {
							if (k.disabled) {
								continue;
							}
							k.checked = !k.checked;
						}
					}
				}
			}
		};
	}	

	//MEDECO.helpers.validateEmailAddress
	if (typeof MEDECO.helpers.validateEmailAddress !== 'function') {
		MEDECO.helpers.validateEmailAddress = function (address) {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if (reg.test(address) === false) {
				return false;
			}
			return true;
		};
	}

	//MEDECO.helpers.validateFormFields
	if (typeof MEDECO.helpers.validateFormFields !== 'function') {
		MEDECO.helpers.validateFormFields = function () {
			var i, k, l = arguments.length, o, valid = true,
				classParts, orgClass, validationType, submitButton,
				messageBreak = Dom.get('messageBreak');

			function getClassParts(className) {
				var parts = className.split(' ');
				return parts;
			}
			
			//alert(arguments);
			for (i = 0; i < l; i += 1) {
				k = arguments[i];
				//alert(k);
				o = Dom.get(k);
				if (o) {
					//Get org class
					orgClass = o.className;
					
					//Use org or set org
					if (o.orgClass) {
						orgClass = o.orgClass;
					} else {
						o.orgClass = orgClass;	
					}
					
					//Get parts
					classParts = getClassParts(orgClass);
					
					//Set normal before validation
					o.className = orgClass;
					o.title = '';
					
					//Test for validation type
					validationType = (classParts.length > 1) ? classParts[1].toLowerCase() : '';

					//Second part is type
					if (validationType === 'email') {
						if (!MEDECO.helpers.validateEmailAddress(o.value)) {
							valid = false;
							o.className = orgClass + ' pb-field-invalid';
							o.title = 'Het e-mail adres is ongeldig.';
						}
					} else {
						if (o.type.toLowerCase() === 'checkbox') {
							if (!o.checked) {
								valid = false;
								o.title = 'Het veld mag niet leeg zijn.';
								o.className = orgClass + ' pb-field-invalid';
							}
							
						} else {
							if (Y.lang.trim(o.value) === '') {
								valid = false;
								o.className = orgClass + ' pb-field-invalid';
								o.title = 'Het veld mag niet leeg zijn.';
							}
						}
					}
				}
			}
			if (!valid) {
				if (messageBreak) {
					MEDECO.helpers.writeErrorMessage('Vul alle verplichte velden.', 'messageBreak');
					window.location.href = '#top';
				} else {
					alert('Vul alle verplichte velden.');
				}
				return false;
			}
			
			//Set waiting
			MEDECO.helpers.throbber.show('De gegevens zijn naar de server verstuurd.');
			
			submitButton = Dom.get('formSubmitButton');
			if (submitButton) {
				submitButton.disabled = true;
			}
			//Disable submit if its available formSubmitButton
			
			return true;
		};
	}
	
	//MEDECO.helpers.submitToCart
	if (typeof MEDECO.helpers.submitToCart !== 'function') {
		MEDECO.helpers.submitToCart = function () {
			//Show throbber
			MEDECO.helpers.throbber.show('De artikelen worden toegevoegd aan uw winkelmand.');
			
			//Parse memory fields
			MEDECO.controls.assortmentMemory.clear();

			//Var
			var submitButtonTop, submitButtonBottom;
			submitButtonTop = Dom.get('submitToCartTopButton');
			if (submitButtonTop) {
				submitButtonTop.disabled = true;
			}
			submitButtonBottom = Dom.get('submitToCartBottomButton');
			if (submitButtonBottom) {
				submitButtonBottom.disabled = true;
			}
			return true;
		};
	}
	
	//MEDECO.helpers.sendAbbReport
	if (typeof MEDECO.helpers.sendAbbReport !== 'function') {
		MEDECO.helpers.sendAbbReport = function () {
			//Var
			var dep = Dom.get('dep_id'),
				quarter = Dom.get('quarter'),
				year = Dom.get('year'),
				i, 
				l, 
				k, 
				depString = '',
				url;
			
			if (typeof dep.options === 'object') {
				//Length
				l = dep.options.length;
				
				//Loop
				for (i = 0; i < l; i += 1) {
					k = dep.options[i];
					if (k.selected) {
						depString += k.value + '/';
						//depList[depList.length] = k.value;
					}
				}					
			}
			
			//Build url
			url = '/html/medbis/abb/report/' + year.value + '/' + quarter.value + '/' + depString;
			
			//Open window
			window.open(url);
			
			//Send false to form submit
			return false;
		};
	}

	//MEDECO.helpers.submitGeneral
	if (typeof MEDECO.helpers.submitGeneral !== 'function') {
		MEDECO.helpers.submitGeneral = function (msg) {
			//Show throbber
			MEDECO.helpers.throbber.show(msg);
			return true;
		};
	}	

	//MEDECO.helpers.handleMaterialSearch
	if (typeof MEDECO.helpers.handleMaterialSearch !== 'function') {
		MEDECO.helpers.handleMaterialSearch = function (e, skipPackages) {
			if (Event.getCharCode(e) === 13) {
				Event.stopEvent(e);
				MEDECO.helpers.populateMaterial(Event.getTarget(e).value, skipPackages);
			}
		};
	}
	
	//MEDECO.helpers.populateMaterial
	if (typeof MEDECO.helpers.populateMaterial !== 'function') {
		MEDECO.helpers.populateMaterial = function (mat_code, skipPackages) {
			
			//setFieldValue
			function setFieldValue(elName, value) {
				var el = Dom.get(elName);
				if (el) {
					el.value = value;
				}
				el = null;
			}
			
			//populateSelect
			function populateSelect(elName, values) {
				//Var
				var el = Dom.get(elName),
					i,
					l,
					k,
					valid = false;
				
				//Clear
				el.options.length = 0;
				
				//Test for array
				if (Y.lang.isArray(values)) {
					l = values.length;
					for (i = 0; i < l; i += 1) {
						k = values[i];
						if (k) {
							el.options[el.options.length] = new Option(k.name, k.id);
							valid = true;
						}
					}
				}
				
				if (!valid) {
					el.options[el.options.length] = new Option('--Selecteer--', '');
				}
				
				//Null
				el = null;
			}
			
			//handleDataReceived
			function handleDataReceived(o) {
				//Var
				var result = MEDECO.helpers.parseRequest(o);
				
				//Test on code
				if (result.code.toString() === '200') {
					//Set field values
					setFieldValue('MatId', result.data.id);
					setFieldValue('MatCode', result.data.code);
					setFieldValue('MatDescription', result.data.description);
					if (!skipPackages) {
						populateSelect('UnitId', result.data.units);
					}
				} else {
					setFieldValue('MatId', '');
					setFieldValue('MatCode', '');
					setFieldValue('MatDescription', '');
					if (!skipPackages) {
						populateSelect('UnitId');
					}
					alert(result.message);
				}
			}
			
			//handleFailure
			function handleFailure(o) {
				alert(o.status + '-' + o.statusText);
			}
			
			//request
			function request() {
				var type = 'get',
					url = '/json/admin/actionmaterials/populatematerial/?code=' + mat_code,
					handlers = {
						failure : handleFailure,
						success : handleDataReceived
					};
				
				//Exec
				Y.util.Connect.asyncRequest(type, url, handlers);	
			}
			
			//Exec
			request();

		};
	}

	//MEDECO.helpers.populateSelect
	if (typeof MEDECO.helpers.populateSelect !== 'function') {
		MEDECO.helpers.populateSelect = function (selectBox, moduleName, className, eventName, value, secondarySelects) {
			
			//handleDataReceived
			function handleDataReceived(o) {
				//Var
				var result = MEDECO.helpers.parseRequest(o),
					i, 
					l, 
					k,
					g, 
					h, 
					q, 
					obj,
					box = Dom.get(selectBox);
					
				//Test result
				if (!result) {
					alert('No result');
					return;
				}
				
				//Test List
				l = result.List.length;
				
				if (secondarySelects) {
					q = secondarySelects.length;
					for (g = 0; g < q; g += 1) {
						h = secondarySelects[g];
						obj = Dom.get(h);
						if (obj) {
							obj.options.length = 0;
							obj.options[obj.options.length] = new Option('-- Selecteer --', '');
						}
					}
				}
				
				//Clear 
				box.options.length = 0;
				
				//Add empty
				box.options[box.options.length] = new Option('-- Selecteer --', '');
				
				for (i = 0; i < l; i += 1) {
					k = result.List[i];
					
					box.options[box.options.length] = new Option(k.Name, k.Id);
					
					//alert(k.Name);
				}
				
//				YAHOO.lang.debugObject(result);
			}
			
			//handleFailure
			function handleFailure(o) {
				alert(o.status + '-' + o.statusText);
			}
			
			//request
			function request() {
				var type = 'get',
					box = Dom.get(selectBox),
					url = '/json/' + moduleName + '/' + className + '/' + eventName + '/?id=' + value,
					handlers = {
						failure : handleFailure,
						success : handleDataReceived
					};

				//Clear 
				box.options.length = 0;
				box.options[box.options.length] = new Option('-- De gegevens worden geladen --', '');
				
				//Exec
				Y.util.Connect.asyncRequest(type, url, handlers);	
			}
			
			//Exec
			request();
			
		};
	}

	//MEDECO.helpers.clearShoppingcart
	if (typeof MEDECO.helpers.clearShoppingcart !== 'function') {
		MEDECO.helpers.clearShoppingcart = function () {
			//Var
			var valid = false;
			
			//handleDataReceived
			function handleDataReceived(o) {
				valid = true;
				var frm = Dom.get('placeorderForm');
				if (frm) {
					//alert('Form submit via JS');
					frm.submit();
				}
			}
			
			//handleFailure
			function handleFailure(o) {
			}
			
			//request
			function request() {
				var type = 'get',
					url = '/json/medbis/shoppingcart/clear/',
					handlers = {
						failure : handleFailure,
						success : handleDataReceived
					};

				//Exec
				Y.util.Connect.asyncRequest(type, url, handlers);	
			}
			
			//Exec
			request();
			
			return valid;
		};
	}

	//MEDECO.helpers.validatePhotoField
	if (typeof MEDECO.helpers.validatePhotoField !== 'function') {
		MEDECO.helpers.validatePhotoField = function (fileObj) {
			if (fileObj.value === '') {
				return true;
			}
			var ext = fileObj.value.split('.').pop().toLowerCase();
			if (ext !== 'jpg' && ext !== 'jpeg' && ext !== 'png' && ext !== 'gif') {
				alert('Alleen bestanden met de extensie (JPG, JPEG, PNG en GIF zijn toegestaan.)');
			}
		};
	}

	//MEDECO.helpers.clearPhotoField
	if (typeof MEDECO.helpers.clearPhotoField !== 'function') {
		MEDECO.helpers.clearPhotoField = function (fieldName, optionTr) {
			var field = Dom.get(fieldName),
				tr = Dom.get(optionTr);
			if (confirm('Weet u zeker dat u de foto wilt verwijderen?')) {
				if (field) {
					field.value = '';
				}
				tr.style.display = 'none';
			}
		};
	}

	//MEDECO.helpers.clearFileField
	if (typeof MEDECO.helpers.clearFileField !== 'function') {
		MEDECO.helpers.clearFileField = function (fieldName, optionTr) {
			var field = Dom.get(fieldName),
				tr = Dom.get(optionTr);
			if (confirm('Weet u zeker dat u het bestand wilt verwijderen?')) {
				if (field) {
					field.value = '';
				}
				tr.style.display = 'none';
			}
		};
	}

	//MEDECO.helpers.submitForm
	if (typeof MEDECO.helpers.submitForm !== 'function') {
		MEDECO.helpers.submitForm = function (formName) {
			var frm = Dom.get(formName);
			if (frm) {
				frm.submit();
			}
		};
	}	

	//MEDECO.helpers.validatePharmacyForm
	if (typeof MEDECO.helpers.validatePharmacyForm !== 'function') {
		MEDECO.helpers.validatePharmacyForm = function () {
			var ref = Dom.get('reference_code');
				
			if (ref) {
				if (Y.lang.trim(ref.value) === '') {
					MEDECO.helpers.writeErrorMessage('Order referentie is verplicht', 'messageBreak');		
					return false;
				}
			}
			
			return true;
		};
	}	
	
	//MEDECO.helpers.submitPharmacyForm
	if (typeof MEDECO.helpers.submitPharmacyForm !== 'function') {
		MEDECO.helpers.submitPharmacyForm = function (autoSubmit) {
			var frm = Dom.get('selectionForm'),
				valid = MEDECO.helpers.validatePharmacyForm();
			if (frm && autoSubmit && valid) {
				frm.submit();
			}
			
			return valid;
		};
	}	

	//YAHOO.util.Dom.popup
	if (typeof MEDECO.helpers.popup !== 'function') {
		MEDECO.helpers.popup = function (o) {
			var oPopup = {
					name : 'pbPopup',
					url : '#',
					width : 800,
					height : 600,
					scrollbars : true,
					location : false,
					menubar : false,
					dependent : false,
					resizable : true,
					statusbar : false,
					toolbar : false,
					top : 10,
					left: 10
				},
				i, 
				w, 
				windowArg = '';
			
			//Test for url only
			if (typeof o === 'string') {
				//Add o as url
				oPopup.url = o;
			} else if (typeof o === 'object') {
				for (i in oPopup) {
					if (oPopup.hasOwnProperty(i)) {
						if (typeof o[i] !== 'undefined') {
							oPopup[i] = o[i];
						}
					}
				}
			} else {
				alert('Not enough arguments to create a popup');
				return;
			}
			
			//Internal function printBool
			function printBool(val) {
				return (val) ? 'yes' : 'no';
			}
			
			//Build window arguments
			windowArg += 'width=' + oPopup.width + ',';
			windowArg += 'height=' + oPopup.height + ',';
			windowArg += 'scrollbars=' + printBool(oPopup.scrollbars) + ',';
			windowArg += 'location=' + printBool(oPopup.location) + ',';
			windowArg += 'menubar=' + printBool(oPopup.menubar) + ',';
			windowArg += 'dependent=' + printBool(oPopup.dependent) + ',';
			windowArg += 'resizable=' + printBool(oPopup.resizable) + ',';
			windowArg += 'statusbar=' + printBool(oPopup.statusbar) + ',';
			windowArg += 'toolbar=' + printBool(oPopup.toolbar) + ',';
			windowArg += 'left=' + oPopup.left + ',';
			windowArg += 'top=' + oPopup.top;
			
						
			//Build window
			w = window.open(oPopup.url, oPopup.name, windowArg);
			
			//Focus
			if (w && typeof w.focus === 'function') {
				w.focus();
			}
		};
	}

	//MEDECO.helpers.hrefPopup
	if (typeof MEDECO.helpers.hrefPopup !== 'function') {
		MEDECO.helpers.hrefPopup = function (uri, width, height, windowName) {
			windowName = (windowName) ? windowName : 'pbPopup';
			var obj = window.open(uri, windowName, 'width=' + width + ',height=' + height + ',location=no,dependent=no,menubar=no,scrollbars=yes,statusbar=no,toolbar=no,resizable=yes');
			if (obj) {
				if (typeof obj.focus === 'function') {
					obj.focus();
				}
			}
			return false;
		};
	}

	//MEDECO.helpers.createPrintLink
	if (typeof MEDECO.helpers.createPrintLink !== 'function') {
		MEDECO.helpers.createPrintLink = function (id, className) {
			//Var
			var printEl = Dom.get(id);
			
			//Print function
			function printPage(e) {
				window.print();
				Event.stopEvent(e);
				return false;
			}
			
			//Test el
			if (printEl) {
				printEl.className = className;
				Event.on(printEl, 'click', printPage);
			}
			
			//Null
			printEl = null;
		};
	}
	
	//MEDECO.helpers.confirmRemoveViaForm
	if (typeof MEDECO.helpers.confirmRemoveViaForm !== 'function') {
		MEDECO.helpers.confirmRemoveViaForm = function (description) {
			if (!description) {
				description = 'Weet u zeker dat u dit item wilt verwijderen?';
			}
			if (confirm(description)) {
				return true;
			}
			return false;
		};
	}

	//MEDECO.helpers.confirmBookAllViaForm
	if (typeof MEDECO.helpers.confirmBookAllViaForm !== 'function') {
		MEDECO.helpers.confirmBookAllViaForm = function (description) {
			if (!description) {
				description = 'Weet u zeker dat u alle artikelen wilt binnenboeken?';
			}
			if (confirm(description)) {
				return true;
			}
			return false;
		};
	}	

	//MEDECO.helpers.setCheckOnSelection
	if (typeof MEDECO.helpers.setCheckOnSelection !== 'function') {
		MEDECO.helpers.setCheckOnSelection = function (value, checkboxName) {
			var obj = Dom.get(checkboxName);
			if (!obj) {
				return;
			}
			if (value) {
				obj.checked = true;
			} else {
				obj.checked = false;
			}
		};
	}

	//MEDECO.helpers.writeErrorMessage 
	if (typeof MEDECO.helpers.writeErrorMessage !== 'function') {
		MEDECO.helpers.writeErrorMessage = function (message, afterElementName, isOk) {
			var alertObj = Dom.get('pb-alert-message'),
				afterObj = Dom.get(afterElementName),
				msgObj,
				msgClass = (isOk) ? 'medbis-box-green-small' : 'medbis-box-orange-small',
				icoFile = (isOk) ? 'check.png' : 'error.png';
			

			function createContents(rootNode) {
				//Var
				var cnt = '';
				//Build
				cnt += '    <div class="tl">';
				cnt += '        <div class="tr">';
				cnt += '            <div class="tm"></div>';
				cnt += '        </div>';
				cnt += '    </div>';
				cnt += '    <div class="ml">';
				cnt += '        <div class="mr">';
				cnt += '            <div class="mm">';
				cnt += '				<img src="/framework/modules/General/images/' + icoFile + '" alt="Foutbericht" class="check-icon"><strong>' + message + '</strong>';
				cnt += '			</div>';
				cnt += '        </div>';
				cnt += '    </div>';
				cnt += '    <div class="bl">';
				cnt += '        <div class="br">';
				cnt += '            <div class="bm"></div>';
				cnt += '        </div>';
				cnt += '    </div>';
				cnt += '</div>';		
				//Set
				rootNode.innerHTML = cnt;
			}
			
			function createMessage() {
				var div = Dom.createElement('div', 'pb-alert-message', msgClass);
				div.innerHTML = '';
				createContents(div);
				return div;
			}
			
			
			if (alertObj) {
				alertObj.className = msgClass;
				alertObj.innerHTML = '';
				createContents(alertObj);
			} else {
				if (afterObj) {
					msgObj = createMessage();
					Dom.insertAfter(msgObj, afterObj);
					Dom.insertAfter(Dom.createElement('br'), msgObj);
					
				}
			}
		};
	}

	//MEDECO.helpers.validateAssortmentManagementForm
	if (typeof MEDECO.helpers.validateAssortmentManagementForm !== 'function') {
		MEDECO.helpers.validateAssortmentManagementForm = function () {
			var objAction = Dom.get('action'),
				objDepartment = Dom.get('dep_id');
			
//			alert(objDepartment);
			
			function getCheckboxes() {
				var form = Dom.get('selectionForm'),
					i, 
					l, 
					idx = 0, 
					selectName, 
					selectObj, 
					commit = true, 
					message = '', 
					k;
				if (form && form.elements) {
					l = form.elements.length;
					for (i = 0; i < l; i += 1) {
						k = form.elements[i];
						if (k.type === 'checkbox') {
							selectName = k.id.replace('material_check', 'unit');
							selectObj = Dom.get(selectName);
							if (k.checked) {
								if (selectObj) {
									if (!selectObj.value) {
										message = 'Geef een verpakking op voor de geselecteerde artikelen.';
										selectObj.className = 'pb-field-invalid';
										commit =  false;
									} else {
										selectObj.className = 'pb-field';
									}
								}
								idx += 1;
							} else {
								if (selectObj) {
									selectObj.className = 'pb-field';
								}
							}
							
						}
					}
				}
				
				//Test commit
				if (!commit) {
					MEDECO.helpers.writeErrorMessage(message, 'messageBreak');
					return false;
				}
				
				if (idx < 1) {
					MEDECO.helpers.writeErrorMessage('Selecteer minimaal 1 artikel / verpakking', 'messageBreak');
					return false;
				}
				
				return true;
			}
			
			if (!objAction.value) {
				MEDECO.helpers.writeErrorMessage('Kies een actie voor de selectie.', 'messageBreak');
				return false;
			}
			if (objAction.value === 'add') {
				//alert('add' + objDepartment.value);
				if (!objDepartment || !objDepartment.value) {
					MEDECO.helpers.writeErrorMessage('Kies een afdeling om de selectie aan toe te voegen.', 'messageBreak');
					return false;
				}
				if (!getCheckboxes()) {
					return false;
				}
			} else if (objAction.value === 'removeall') {
				return true;
			}
			
			//Result
			return true;
		};
	}

	//MEDECO.helpers.deliveryMemory
	if (typeof MEDECO.helpers.deliveryMemory !== 'object') {
		MEDECO.helpers.deliveryMemory = [];
	}

	//MEDECO.helpers.populateDeliveryLines 
	if (typeof MEDECO.helpers.populateDeliveryLines !== 'function') {
		MEDECO.helpers.populateDeliveryLines = function (message, afterElementName) {
			var i, l, k, fld;
			
			//Test for memory			
			if (!MEDECO.helpers.deliveryMemory) {
				return;
			}
			
			//Count
			l = MEDECO.helpers.deliveryMemory.length;
			
			//Loop
			for (i = 0; i < l; i += 1) {
				//Map
				k = MEDECO.helpers.deliveryMemory[i];
				
				//Get field
				fld = Dom.get('delivery_quantity_' + k.id);
				
				//Test
				if (fld) {
					fld.value = k.quantity;
				}
			}
		};
	}

	//MEDECO.helpers.copyMonthlyFieldValue
	if (typeof MEDECO.helpers.copyMonthlyFieldValue !== 'function') {
		MEDECO.helpers.copyMonthlyFieldValue = function (fieldname, value) {
			//Var
			var fld, i;
			
			//Test for empty value
			if (value === null || value === '') {
				return;
			}
			
			//Loop months
			for (i = 1; i <= 12; i += 1) {
				fld = Dom.get(fieldname + i);
				if (fld) {
					fld.value = value;
				}
			}
		};
	}

	//MEDECO.helpers.switchImage
	if (typeof MEDECO.helpers.switchImage !== 'function') {
		MEDECO.helpers.switchImage = function (fieldname, value) {
			//Var
			var img = Dom.get(fieldname);
			
			//Set
			if (img && value) {
				img.src = value;
			}
			
			//Null
			img = null;
		};
	}
	
	//MEDECO.helpers.connectTab
	if (typeof MEDECO.helpers.connectTab !== 'function') {
		MEDECO.helpers.connectTab = function (tabPages) {
			var i, k, l = tabPages.length,
				elLink, elHref;
			
			for (i = 0; i < l; i += 1) {
				k = tabPages[i];
				elLink =  Dom.get('tablink_' + k);
				elHref =  Dom.get('ahreflink_' + k);
				
				if (elLink) {
					Event.on(elLink, 'click', MEDECO.helpers.switchTab, [k, tabPages]);
				}

				if (elHref) {
					elHref.removeAttribute('href');
					Event.on(elHref, 'click', MEDECO.helpers.switchTab, [k, tabPages]);
				}

			}
		};
	}
	
	//MEDECO.helpers.switchTab
	if (typeof MEDECO.helpers.switchTab !== 'function') {
		MEDECO.helpers.switchTab = function (e, arg) {
			var key = arg[0],
				tabPages = arg[1],
				i, 
				k, 
				l = tabPages.length,
				elLink, 
				elTab;
			for (i = 0; i < l; i += 1) {
				k = tabPages[i];
				elLink =  Dom.get('tablink_' + k);
				elTab =  Dom.get('tabpage_' + k);
				if (elLink && elTab) {
					elLink.className = (k === key) ? 'selected' : '';
					elTab.className = (k === key) ? 'mat-tab' : 'pb-hidden';
				}
			}
			
			return false;
		};
	}

	//MEDECO.helpers.banner
	if (typeof MEDECO.helpers.banner !== 'object') {
		MEDECO.helpers.banner = {
			'index' : 0,
			'milisec' : 2000,
			'imageList' : [],
			'setConfig' : function (list, milisec) {
				MEDECO.helpers.banner.imageList = list;
				MEDECO.helpers.banner.milisec = parseInt(milisec, 10);
				MEDECO.helpers.banner.preload();
			},
			'preload' : function () {
				var i, k, l = MEDECO.helpers.banner.imageList.length, img;
				for (i = 0; i < l; i += 1) {
					k = MEDECO.helpers.banner.imageList[i];
					if (k.file) {
						img = new Image();
						img.src = k.file;
						img = null;
					}
				}
			},
			'run' : function () {
				setInterval(MEDECO.helpers.banner.timerTick, MEDECO.helpers.banner.milisec);
			},
			'timerTick' : function () {
				var imgData = MEDECO.helpers.banner.imageList[MEDECO.helpers.banner.index],
					elLink, 
					elImage;
				if (imgData) {
					//Get elements					
					elLink = Dom.get('banner_link');
					elImage = Dom.get('banner_image');
					if (elLink && elImage) {
						elLink.setAttribute('href', imgData.url);
						elImage.src = imgData.file;
					}
				}
				
				//Determin new index
				MEDECO.helpers.banner.index += 1;
				if (MEDECO.helpers.banner.index > (MEDECO.helpers.banner.imageList.length - 1)) {
					MEDECO.helpers.banner.index = 0;
				}				

				//Null
				elLink = null;
				elImage = null;
			}
		};
	}

	//MEDECO.helpers.shoppingcartNext
	if (typeof MEDECO.helpers.shoppingcartNext !== 'function') {
		MEDECO.helpers.shoppingcartNext = function () {
			var elRedirect = Dom.get('redirect'),
				elFrm = Dom.get('selectionForm'),
				submitButtonTop, 
				submitButtonBottom;
			if (elRedirect) {
				elRedirect.value = 'shoppingcart';
			}
			if (elFrm) {
				//Show throbber
				MEDECO.helpers.throbber.show('De artikelen worden toegevoegd aan uw winkelmand.');
				
				//Parse memory fields
				MEDECO.controls.assortmentMemory.clear();
	
				submitButtonTop = Dom.get('submitToCartTopButton');
				if (submitButtonTop) {
					submitButtonTop.disabled = true;
				}
				submitButtonBottom = Dom.get('submitToCartBottomButton');
				if (submitButtonBottom) {
					submitButtonBottom.disabled = true;
				}
				
				elFrm.submit();
			}
//			alert('next');
		};
	}

	//MEDECO.helpers.refreshReports
	if (typeof MEDECO.helpers.refreshReports !== 'function') {
		MEDECO.helpers.refreshReports = function () {

			//handleDataReceived
			function handleDataReceived(o) {
				//Var
				var result = MEDECO.helpers.parseRequest(o),
					i,
					l,
					k,
					divEl = Dom.get('ReportList'),
					html = '';
				
				//DIV NAME ReportList
				
				//divEl.innerHTML = '';
				
				//alert(Y.lang.dump(result));
				
				//Test on code
				if (result.code.toString() === '200') {
					if (result.data) {
						l = result.data.length;
						html = '<ul>';
						
						for (i = 0; i < l; i += 1) {
							k = result.data[i];
							html += '<li><a href="' + k.url + '">' + k.name + '</a></li>';	
						}
						
						html += '</ul>';
						
						divEl.innerHTML = html;
					}
					
				}
			}
			
			//handleFailure
			function handleFailure(o) {
				alert(o.status + '-' + o.statusText);
			}
			
			//request
			function request() {
				var type = 'get',
					url = '/json//medbis/reports/reportlistJson',
					handlers = {
						failure : handleFailure,
						success : handleDataReceived
					};
				
				//Exec
				Y.util.Connect.asyncRequest(type, url, handlers);	
			}			
			
			setInterval(request, 10000);
			
		};
	}

	//MEDECO.helpers.progressThrobber
	if (typeof MEDECO.helpers.progressThrobber !== 'object') {
		MEDECO.helpers.progressThrobber = {
			'name' : 'progressThrobber',
			'cover' : null,
			'dialog' : null,
			'elements' : [],
			'oInterval' : null,
			'tick' : 0,
			//start
			'start' : function () {
				MEDECO.helpers.progressThrobber.tick = 1;
				MEDECO.helpers.progressThrobber.oInterval = setInterval(MEDECO.helpers.progressThrobber.timerTick, 100);
			},
			//stop
			'stop' : function () {
				clearInterval(MEDECO.helpers.progressThrobber.oInterval);
				MEDECO.helpers.progressThrobber.tick = 1;
			},
			//timerTick
			'timerTick' : function () {
				var o = MEDECO.helpers.progressThrobber,
					divName = 'divProgress_' + o.tick,
					el = o.elements[divName];
					
				if (el) {
					if (Dom.hasClass(el, 'selected')) {
						Dom.removeClass(el, 'selected');
					} else {
						Dom.addClass(el, 'selected');
					}
				}
						
				//Set tick				
				o.tick = (o.tick === 10) ? o.tick = 1 : o.tick += 1;
				
				//NUll
				el = null;
				o = null;
			},
			//show
			'show' : function () { 
				//Test for currently active cover
				if (Y.lang.isObject(this.cover)) {
					return;
				}				

				//Var
				var divInner = Dom.createElement('div', null, 'inner'),
					divTop = Dom.createElement('div', null, 'progressHeader', '<h2 class="progress-center">Rapportage gegevens ophalen</h2><p class="progress-center">Het ophalen van de rapportage gegevens kan enkele minuten duren. Een ogenblik geduld A.U.B.</p>', divInner),
					divProgressContainer = Dom.createElement('div', null, 'progressContainer', null, divInner),
					divBottom = Dom.createElement('div', null, 'progressFooter', '<p class="progress-center">Sluit het venster niet totdat de download is voltooid.</p>', divInner),
					i,
					addClass = '';
					
					
				//Create progress points	
				for (i = 1; i < 11; i += 1) {
					if (i === 10) {
						addClass = ' lastPointer';
					}
					MEDECO.helpers.progressThrobber.elements['divProgress_' + i] = Dom.createElement('div', null, 'progressPoint' + addClass, null, divProgressContainer);
				}
						
				//Add clear
				Dom.createElement('div', null, 'pb-clear', null, divProgressContainer);
							
				//Create elements
				this.cover = Dom.createElement('div', 'pb-throbber-cover');
				this.dialog = Dom.createElement('div', 'pb-throbber-dialog-white');

				//Add message
				//this.dialog.innerHTML = '<div class="inner">jadijada</div>';
				this.dialog.appendChild(divInner);
				
				//Append
				document.body.appendChild(this.cover);
				document.body.appendChild(this.dialog);
			
				//Resize
				this.resize();
				
				//Add listener
				Event.addListener(window, 'resize', MEDECO.helpers.progressThrobber.resize);
				Event.addListener(window, 'scroll', MEDECO.helpers.progressThrobber.resize);
				
				//Null
				divTop = null;
				divBottom = null;
					
				//Start
				this.start();
			},
			//close
			'close' : function () {
				//Var
				var hlp = MEDECO.helpers.progressThrobber;
				//Stop
				hlp.stop();
				//Remove events
				Event.removeListener(window, 'resize', MEDECO.helpers.progressThrobber.resize);
				Event.removeListener(window, 'scroll', MEDECO.helpers.progressThrobber.resize);				
				//Remove from body
				if (Y.lang.isObject(hlp.cover)) {
					document.body.removeChild(hlp.cover);
				}
				if (Y.lang.isObject(hlp.dialog)) {
					document.body.removeChild(hlp.dialog);
				}
				//Set null
				hlp = null;
				hlp.cover = null;
				hlp.dialog = null;				
			},
			//resize
			'resize' : function () {
				//Var
				var o = MEDECO.helpers.progressThrobber,
					vpWidth = Dom.getViewportWidth(),
					vpHeight = Dom.getViewportHeight(),
					scrollTop = Dom.getDocumentScrollTop(),
					scrollLeft = Dom.getDocumentScrollLeft(),
					cvWidth = vpWidth,
					cvHeight = vpHeight,
					cvTop = scrollTop,
					cvLeft = scrollLeft,
					thRegion,
					thTop,
					thLeft;	
					
				//Test for currently active cover
				if (!Y.lang.isObject(o.cover)) {
					return;
				}					

				//GEt region
				thRegion = Dom.getRegion(o.dialog);
				
				//Test regin
				if (!thRegion) {
					return;
				}
				
				//Calc dialog pos
				thTop = (((vpHeight - thRegion.height) / 2) / 2) + scrollTop;
				thLeft = ((vpWidth - thRegion.width) / 2) + scrollLeft;

				//Test for 0
				cvWidth = (cvWidth < 0) ? 0 : cvWidth;
				cvHeight = (cvHeight < 0) ? 0 : cvHeight;
				
				//Set cover
				Dom.setStyle(o.cover, 'position', 'absolute');
				Dom.setStyle(o.cover, 'top', cvTop + 'px');
				Dom.setStyle(o.cover, 'left', cvLeft + 'px');
				Dom.setStyle(o.cover, 'width', cvWidth + 'px');
				Dom.setStyle(o.cover, 'height', cvHeight + 'px');
				Dom.setStyle(o.cover, 'opacity', 0.5); 
				
				//Set dialog
				Dom.setStyle(o.dialog, 'position', 'absolute');
				Dom.setStyle(o.dialog, 'top', thTop + 'px');
				Dom.setStyle(o.dialog, 'left', thLeft + 'px');				
												
			}
		};
	}
	
	//MEDECO.helpers.requestSapReports
	if (typeof MEDECO.helpers.requestSapReports !== 'function') {
		MEDECO.helpers.requestSapReports = function (cus_id) {
			//Var
			var oInterval = null,
				progressRequest = false;
			
			//handleDataReceived
			function handleDataReceived(o) {
				//alert('req data received');
				//alert(o.responseText);
				//Var
				var result = MEDECO.helpers.parseRequest(o);
				
				if (result.code.toString() === '500') {
					alert(result.message);
				} else {
					if (result.type === 'completed') {
						clearInterval(oInterval);
						window.location.href = '/html/medbis/reports/reportlist';
					}
				}
				
				//Set
				progressRequest = false;
			}
			
			//handleRequestReceived
			function handleRequestReceived(o) {
				var result = MEDECO.helpers.parseRequest(o);
				if (result.code.toString() === '500') {
					alert(result.message);
				}
				alert(result.message);
			}
			
			//handleFailure
			function handleFailure(o) {
				alert(o.status + '-' + o.statusText);
			}

			//requestSapProgress
			function requestSapProgress() {
				//Test already progress
				if (progressRequest) {
					return;
				}
				
				//Set
				progressRequest = true;
				
				//Var
				var type = 'get',
					url = '/json/medbis/reports/requestSapProgress/' + cus_id,
					handlers = {
						failure : handleFailure,
						success : handleDataReceived
					};
				
				//Exec
				Y.util.Connect.asyncRequest(type, url, handlers);	
			}
			
			//requestReport
			function requestReport() {
				var type = 'get',
					url = '/json/medbis/reports/requestSapReportJson/',
					handlers = {
						failure : handleFailure,
						success : handleRequestReceived
					};
				
				//Exec
				Y.util.Connect.asyncRequest(type, url, handlers);				
			}
			
			//init
			function init() {
				//Start progress throbber
				MEDECO.helpers.progressThrobber.show();
				
				//Request report
				requestReport();
				
				//Set interval
				oInterval = setInterval(requestSapProgress, 10000);
			}
			
			//init
			init();			
		};
	}

	//MEDECO.helpers.groupConflict
	if (typeof MEDECO.helpers.groupConflict !== 'function') {
		MEDECO.helpers.groupConflict = function (grpObj, groups) {
			//Var
			var i, l, k, o, valid = false;
			
			//Count
			l = groups.length;
			
			//Test if in array()
			for (i = 0; i < l; i += 1) {
				k = groups[i];
				if (grpObj.value.toString() === k.toString()) {
					valid = true;
				}
			}
			
			//Test for valid comparisson
			if (!valid) {
				return false;
			}
			
			
			//Test for checked
			if (grpObj.checked) {
				
				for (i = 0; i < l; i += 1) {
					k = groups[i];
					if (k.toString() !== grpObj.value.toString()) {
						o = Dom.get('Rol_' + k);
						if (o) {
							o.checked = false;
						}
					}
				}
			}
			
		};
	}

	//CONTROLS
	//--------------------------------------------------------------
	
	//MEDECO.controls
	if (typeof MEDECO.controls !== 'object') {
		MEDECO.controls = {};
	}

	//MEDECO.controls.numericBox
	if (typeof MEDECO.controls.numericBox !== 'function') {
		MEDECO.controls.numericBox = function (fieldId) {
			//Var
			var fld = Dom.get(fieldId);

			//isAllowedCharCode
			function isAllowedCharCode(char) {
				var allowed = [8, 9, 35, 36, 37, 39, 46, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105],
					i, 
					k, 
					l = allowed.length;
				for (i = 0; i < l; i += 1) {
					k = allowed[i];
					if (k === char) {
						return true;
					}
				}
				//alert(char);
				return false;
			}
			
			//handleKeyDown
			function handleKeyDown(e) {
				//getEvent
				var char = Event.getCharCode(e);
				
				//Test for return
				if (char === 13) {
					return true;
				}
				
				//Test alt
				if (e.altKey) {
					Event.stopEvent(e);
					return false;
				}
				
				//Test shift
				if (e.shiftKey) {
					if (char !== 35 && char !== 36 && char !== 37 && char !== 39) {
						Event.stopEvent(e);
						return false;
					}
				}
				
				//Test for ctrl +x, +v, +c
				if ((char === 88 || char === 67 || char === 86) && e.ctrlKey) {
					return true;
				}
				
				//Result char
				if (!isAllowedCharCode(char)) {
					Event.stopEvent(e);
					return false;
				}
				return true;
			}			
			
			//validate
			function validate() {
				//Var
				var value = Y.lang.trim(fld.value),
					numericValue;

				//Valid
				//that.setValid();
				
				//Replace , with .
				value = value.replace(/,/g, '.');
				
				//Parse to float or integer
				numericValue = parseInt(value, 10);
				
				//Test number
				if (Y.lang.isNumber(numericValue)) {
					value = numericValue;
				} else {
					value = '';
				}

				//Set
				fld.value = value;
											
				//Result
				return true;
			}

			//Add listeners
			Event.addListener(fld, "keydown", handleKeyDown);
			Event.addListener(fld, "blur", validate);
			
			return fld;
		};
	}
	
	//MEDECO.controls.createNumericBoxes
	if (typeof MEDECO.controls.createNumericBoxes !== 'function') {
		MEDECO.controls.createNumericBoxes = function () {
			var i, l = arguments.length;
			for (i = 0; i < l; i += 1) {
				MEDECO.controls.numericBox(arguments[i]);
			}
		};
	}
	
	//MEDECO.controls.createNumericBoxesByForm
	if (typeof MEDECO.controls.createNumericBoxesByForm !== 'function') {
		MEDECO.controls.createNumericBoxesByForm = function (formName, fieldPrefix) {
			//Var
			var form = Dom.get(formName),
				i, 
				l, 
				prefixLength = fieldPrefix.length, 
				k;
			if (form && form.elements) {
				l = form.elements.length;
				for (i = 0; i < l; i += 1) {
					k = form.elements[i];
					if (k.id.substr(0, prefixLength) === fieldPrefix) {
						MEDECO.controls.numericBox(k.id);
					}
				}
			}			
			
		};
	}

	//MEDECO.controls.assortmentMemory
	if (typeof MEDECO.controls.assortmentMemory !== 'function') {
		MEDECO.controls.assortmentMemory = {
			mem : [],
			set : function (o) {
				var itmIdx = MEDECO.controls.assortmentMemory.findItem(o);
				if (itmIdx !== false) {
					//Splice it
					MEDECO.controls.assortmentMemory.mem.splice(itmIdx, 1);
				}
				//Add always the new one
				if (o.quantity !== '') {
					MEDECO.controls.assortmentMemory.mem[MEDECO.controls.assortmentMemory.mem.length] = o;
				}
				//Save
				MEDECO.controls.assortmentMemory.save();
			},
			load : function () {
				//Var
				var cookieString = Cookie.get('myAssortment', { path : '/' }),
					parts, 
					i, 
					l, 
					k, 
					pieces;
				//Test
				if (cookieString) {
					parts = cookieString.split(',');
					l = parts.length;
					for (i = 0; i < l; i += 1) {
						k = parts[i];
						pieces = k.split('|');
						MEDECO.controls.assortmentMemory.mem[MEDECO.controls.assortmentMemory.mem.length] = {
							'mat_id' : pieces[0],
							'quantity' : pieces[1],
							'unit_id' : pieces[2]
						};
					}
				}
			},
			save : function () {
				//Var
				var i, l, k, ar = [];
				//Count
				l = MEDECO.controls.assortmentMemory.mem.length;
				//Loop
				for (i = 0; i < l; i += 1) {
					k = MEDECO.controls.assortmentMemory.mem[i];
					ar[ar.length] = k.mat_id + '|' + k.quantity + '|' + k.unit_id;
				}
				//Clear
				MEDECO.controls.assortmentMemory.clear();
				//Set new value
				Cookie.set('myAssortment', ar, { path : '/' });
			},
			dump : function () {
				//Var
				var i, l, k, fieldIndex = 40, 
					checkField, frm = Dom.get('selectionForm');
				//Count
				l = MEDECO.controls.assortmentMemory.mem.length;
				
				function addField(name, value, form) {
					var f = document.createElement('input');
					f.type = 'hidden';
					//f.type = 'text';
					f.name = name;
					f.value = value;
					frm.appendChild(f);					
				}
				
				//Loop
				for (i = 0; i < l; i += 1) {
					k = MEDECO.controls.assortmentMemory.mem[i];
					fieldIndex += 1;
					checkField = Dom.get('quantity_' + k.mat_id);
					if (!checkField) {
						//Create the fields
						addField('material[' + fieldIndex + '][mat_id]', k.mat_id, frm);
						addField('material[' + fieldIndex + '][quantity]', k.quantity, frm);
						addField('material[' + fieldIndex + '][unit_id]', k.unit_id, frm);
					}
					//ar[ar.length] = k.mat_id + '|' + k.quantity + '|' + k.unit_id;
				}
			},
			clear : function () {
				if (Cookie.exists('myAssortment', { path : '/' })) {
					Cookie.remove('myAssortment', { path : '/' });
				}				
			},
			findItem : function (o) {
				var i, l, k;
				l = MEDECO.controls.assortmentMemory.mem.length;
				for (i = 0; i < l; i += 1) {
					k = MEDECO.controls.assortmentMemory.mem[i];
					if (Y.lang.trim(k.mat_id) === Y.lang.trim(o.mat_id)) {
						return i;
					}
				}
				return false;
			},
			findValue : function (mat_id) {
				var itm, itmIdx = MEDECO.controls.assortmentMemory.findItem({
					'mat_id' : mat_id
				});
				if (itmIdx !== false) {
					//alert('found');
					itm = MEDECO.controls.assortmentMemory.mem[itmIdx];
					//return itm.quantity;
					return itm;
				}
				return false;
			}
		};
		//Load
		MEDECO.controls.assortmentMemory.load();
	}

	//MEDECO.controls.createNumericBoxesByAssortmentForm
	if (typeof MEDECO.controls.createNumericBoxesByAssortmentForm !== 'function') {
		MEDECO.controls.createNumericBoxesByAssortmentForm = function (formName, fieldPrefix) {
			//Var
			var form = Dom.get(formName),
				i, 
				l, 
				prefixLength = fieldPrefix.length, 
				k, 
				fld, 
				matID, 
				idParts, 
				itmVal, 
				unitFld;
			
			function saveAssortmentPicks(e) {
				var target = Event.getTarget(e),
					id, 
					parts,
					quantityEl,
					unitEl, 
					unitVal = '', 
					quantityVal = '';
				if (target) {
					//Split
					parts = target.id.split('_');
					//Get id
					id = parts[1];
					quantityEl = Dom.get('quantity_' + id);
					if (quantityEl) {
						//Map values
						quantityVal = quantityEl.value;
					}
					//Map names
					unitEl = Dom.get('unit_' + id);
					if (unitEl) {
						unitVal = unitEl.value;
					}
					MEDECO.controls.assortmentMemory.set({
						'mat_id' : id,
						'quantity' : quantityVal,
						'unit_id' : unitVal
					});
				}

			}
			
			
			if (form && form.elements) {
				l = form.elements.length;
				for (i = 0; i < l; i += 1) {
					k = form.elements[i];
					idParts = k.id.split('_');
					matID = idParts[1];
					if (k.id.substr(0, prefixLength) === fieldPrefix) {
						fld = MEDECO.controls.numericBox(k.id);
						unitFld = Dom.get('unit_' + matID);
						
						//Get item value			
						itmVal = MEDECO.controls.assortmentMemory.findValue(matID);
						
						//Set quantity value
						if (itmVal !== false) {
							//Set quantity value
							fld.value = itmVal.quantity;
							//Test for dropdown
							if (unitFld.tagName.toLowerCase() === 'select') {
								//Set dropdown value
								unitFld.value = itmVal.unit_id;
							}
						}
						
						//In case of select set value
						if (unitFld.tagName.toLowerCase() === 'select') {
							Event.addListener(unitFld, "change", saveAssortmentPicks);
						}
						
						
						//fld
						//Event.addListener(fld, "blur", saveAssortmentPicks);
						Event.addListener(fld, "change", saveAssortmentPicks);
						
					}
				}
			}			
			
			MEDECO.controls.assortmentMemory.dump();
			
		};
	}	
	
	//MEDECO.controls.createNumericBoxesByClass
	if (typeof MEDECO.controls.createNumericBoxesByClass !== 'function') {
		MEDECO.controls.createNumericBoxesByClass = function (className, config) {
			var elements = Dom.getElementsByClassName(className),
				i;
			if (elements) {
				//Loop
				for (i in elements) {
					if (elements.hasOwnProperty(i)) {
						MEDECO.controls.numericBox(elements[i]);
					}
				}
			}
		};
	}

	
}());
