			var currentPositionHor = 0 // 0 = Left, 1 = Right
			var currentPositionVer = 1
			var shownLines = 0
			var nextField
			
			function showQty(index) {
				if (currentPositionVer > shownLines) {
					$('qoQty' + index).style.display ='block';
					$('qoLine' + (parseInt(index) + 1)).style.display ='block';
					//$('typeIn' + index).innerHTML = '';
					shownLines = shownLines + 1;
					//alert(shownLines);
				}
			}
			
			function fetchData(index) 
			{
				
				if ($('itemNo' + index).value.replace('-', '') > 0){
					itemNo = $('itemNo' + index).value.replace('-', '');
				} else {
					itemNo = 0
				}
				
				if ($('itemQty' + index).value > 0){
					itemQty = $('itemQty' + index).value
				} else {
					itemQty = 0
				}
				
				//alert(parseInt(itemNo));
				//alert(parseInt($('itemHFNo' + index).value));
				//alert(parseInt(itemQty));
				//alert(parseInt($('itemHFQty' + index).value));
				if (parseInt(itemNo) != parseInt($('itemHFNo' + index).value) || parseInt(itemQty) != parseInt($('itemHFQty' + index).value) ){
				activateFetchData(index, 1);
				}
			}
			
			function activateFetchData(index, counter) {
				
				blnIsRowBusy = $('orderLineBusy' + index).value == 'true';
				// alert('Value: ' + $('orderLineBusy' + index).value + "  _ " + blnIsRowBusy + " _ " + counter);
				
				if (!blnIsRowBusy || counter == 10) {
					$('orderLineBusy' + index).value = 'true'; // Sets busy-state
					// alert('FIRE IN THE HOLE!');
					$('typeIn' + index).innerHTML = "<table style='margin-top:6px; margin-left:10px; height:37px;'><tr><td class='qoArrowText' style='color:#bababa'>" + qo003 + "</td></tr></table>";
					//setTimeout('ajaxData(' + index + ')', 100);
					ajaxData(index);
				}
				else 
				{
					setTimeout('fetchData(' + index + ', ' + (counter + 1) + ')', 1000);
				}
				
			}
			
			
			
			function ajaxData(index) {	
				var url = '/ajax/quickOrder.asp';
				
				if ($('itemNo' + index).value.replace('-', '') > 0){
					itemNo = $('itemNo' + index).value.replace('-', '');
				} else {
					itemNo = 0
				}
				
				if ($('itemQty' + index).value > 0){
					itemQty = $('itemQty' + index).value
				} else {
					itemQty = 0
				}
				
				if ($('orderLineGuid' + index).value > 0){
					entityLine = $('orderLineGuid' + index).value
				} else {
					entityLine = -1
				}
				
				if ($('currentLineIndex' + index).value > 0){
					currentLineIndex = $('currentLineIndex' + index).value
				} else {
					currentLineIndex = -1
				}
				
				var pars = 'itemNo=' + itemNo + '&itemQty=' + itemQty + "&orderLineGuid=" + entityLine + "&currentLineIndex=" + currentLineIndex;
				var myAjax = new Ajax.Updater(
					'typeIn' + index, 
					url,
					{
						method: 'get', 
						parameters: pars,
						evalScripts:true
					});
			}
			
			function setMatrix(val1,val2)	{
				currentPositionHor = val1;
				currentPositionVer = val2;
			}
			
			document.onkeydown = function(event) {
			evt = event || window.event;
			el = evt.srcElement || evt.target;
			if (el.name) {
				//alert(el.id);
				//return true;
		
				switch (evt.keyCode) {
					// left arrow key
					case 37: 	if (currentPositionHor == 0 && shownLines != 0){
										nextField = $('itemQty' + currentPositionVer);
										nextField.focus();
										nextField.select();
									} else {
										nextField = $('itemNo' + currentPositionVer);
										nextField.focus();
										nextField.select();
									} return false; 
									break;
					
					case 39: 	if (currentPositionHor == 0 && shownLines != 0){
										nextField = $('itemQty' + currentPositionVer);
										nextField.focus();
										nextField.select();
									} else {
										nextField = $('itemNo' + currentPositionVer);
										nextField.focus();
										nextField.select();
									} return false; 
									break;
									
					case 38:  	if (currentPositionVer != 1 && currentPositionHor == 0 && shownLines != 0){
										nextField = $('itemNo' + (parseInt(currentPositionVer)-1));
										nextField.focus();
										nextField.select();
									} else if  (currentPositionVer != 1 && currentPositionHor == 1 && shownLines != 0) {
										nextField = $('itemQty' + (parseInt(currentPositionVer)-1));
										nextField.focus();
										nextField.select();
									} return false; 
									break; 
					case 13:		
					case 40: 	if (currentPositionVer != shownLines && currentPositionHor == 0 && shownLines != 0){
										nextField = $('itemNo' + (parseInt(currentPositionVer)+1));
										nextField.focus();
										nextField.select();
									} else if  (currentPositionVer != shownLines && currentPositionHor == 1 && shownLines != 0) {
										nextField = $('itemQty' + (parseInt(currentPositionVer)+1));
										nextField.focus();
										nextField.select();
									} else if  (currentPositionVer == shownLines && currentPositionHor == 1 && shownLines != 0 || currentPositionVer == shownLines && currentPositionHor == 0 && shownLines != 0) {
										nextField = $('itemNo' + (parseInt(currentPositionVer)+1));
										nextField.focus();
										nextField.select();
									} return false; 
									break;
					
				}
			
				return true;
				} else {
				return true;
			}
		}

			
