//===============================================================================
// This file contains the javascript functions that is called from orderentry.aspx
//===============================================================================
// Last Modified:

//===============================================================================

var sCells = "";
var bMouseDownOnSet = false;
var iMouseDownOnSetRow = 0;
var iMouseDownOnSetCol = 0;
var iStartRow, iEndRow, iStartCol, iEndCol;

var isIE = browserName() == 1 ? true : false;
var isNN = browserName() == 2 ? true : false;
var isN4 = document.layers;
var whichElement;
var isDirty = false;
var sOrderType = "A";
var sBgColorSelected = "#FFF6D3";
var sBgColorUnSelected = "#FFFFF7";
var sAllowEdit = "1";
var isCartModified = false;

function onloadBody()
{
	sOrderType = document.getElementById('_OrderType').value;
	sOrderType = "B";
	
	if (document.getElementById('_AllowEdit') != null)
		sAllowEdit = document.getElementById('_AllowEdit').value;

	var inputMode = document.getElementById('_CurrentInputMode').value;
	
	if (sAllowEdit == "1") {
		// Hide item type window for worksheet data entry when screen resolution width < 1025
		//if ((parseInt(screen.width) < 1025) && (sOrderType == "A"))
		//	hideCategoryWindow();

		
		// Hide this option for non IE browsers for now.
		if (sOrderType == "A")
		{
			if (!isIE) {
				inputMode = "K";
				document.getElementById("divSetInputType").style.display = "none";
			}

			if (inputMode == "M")
				setInputTypeM();
			else
				setInputTypeK();
		}
	}
}

function onbeforeunloadBody()
{
	if (isCartModified) {
		event.returnValue = orderentry_PageUnloadAlert;
	}
}

function setWinWH()
{
	if (parseInt(navigator.appVersion)>3) {
		if (isIE) {
			// Subtract 20 for scrollbar
			winW = document.body.offsetWidth - 20;
			winH = document.body.offsetHeight - 20;
		}
		if (isNN) {
			// Subtract 16 for scrollbar
			winW = window.innerWidth - 16;
			winH = window.innerHeight - 16;
		}
	}
}

function setInputTypeM()
{
	if (isIE) {
		document.getElementById("tdKeyboardLink").bgColor = '#ffffff';
		document.getElementById("tdPadLink").bgColor = '#d6d6d6';
		document.getElementById("KeyboardLink").style.display = 'none';
		document.getElementById("SwitchToKeyboardLink").style.display = 'block';
		document.getElementById("PadLink").style.display = 'block';
		document.getElementById("SwitchToPadLink").style.display = 'none';
		
		document.getElementById("_CurrentInputMode").value = "M";
		
		attachTableMouseEvents();
		showKeyPad();
		
	}
	else {
		setInputTypeK();
	}
}

function setInputTypeK()
{
	document.getElementById("tdKeyboardLink").bgColor = '#d6d6d6';
		document.getElementById("tdPadLink").bgColor = '#ffffff';
	document.getElementById("PadLink").style.display = 'none';
	document.getElementById("SwitchToPadLink").style.display = 'block';
	document.getElementById("KeyboardLink").style.display = 'block';
	document.getElementById("SwitchToKeyboardLink").style.display = 'none';
	document.getElementById("_CurrentInputMode").value = "K";

	
	detachTableMouseEvents();
	unselectCells();
	sCells = ""
	hideKeyPad();
}

function setInputType()
{
	if (document.getElementById("_CurrentInputMode").value == "K") {
		if (isIE)
			setInputTypeM();
		else
			alert("This option is currently only available in Microsoft Internet Explorer.");
		
	}
	else {
		setInputTypeK();
		
	}
	window.status = orderentry_InitInputType;

	if (sOrderType == "A")
		setInputTypeA();
	else
		setInputTypeB();
	window.status = "";
}

function setInputTypeA()
{
	var oTable = document.getElementById('tblData');
				
	if (oTable.rows.length > 1) {

		var arPartsInLevel = new Array(20);
		var oTextBox;
		var oDiv;
		var sLevel;	
		var bError = false;
		
		for (var i=1; i < oTable.rows.length; i++) {
			var sPartNumberBase = oTable.rows(i).id;
			arPartsInLevel[0] = sPartNumberBase + "-001";
			arPartsInLevel[1] = sPartNumberBase + "-011";
			arPartsInLevel[2] = sPartNumberBase + "-021";
			arPartsInLevel[3] = sPartNumberBase + "-031";
			arPartsInLevel[4] = sPartNumberBase + "-041";
			arPartsInLevel[5] = sPartNumberBase + "-051";
			arPartsInLevel[6] = sPartNumberBase + "-061";
			arPartsInLevel[7] = sPartNumberBase + "-071";
			arPartsInLevel[8] = sPartNumberBase + "-081";
			arPartsInLevel[9] = sPartNumberBase + "-091";
			arPartsInLevel[10] = sPartNumberBase + "-101";
			arPartsInLevel[11] = sPartNumberBase + "-111";
			arPartsInLevel[12] = sPartNumberBase + "-121";
			arPartsInLevel[13] = sPartNumberBase + "-131";
			arPartsInLevel[14] = sPartNumberBase + "-141";
			arPartsInLevel[15] = sPartNumberBase + "-151";
			arPartsInLevel[16] = sPartNumberBase + "-161";
			arPartsInLevel[17] = sPartNumberBase + "-171";
			arPartsInLevel[18] = sPartNumberBase + "-181";
			arPartsInLevel[19] = sPartNumberBase + "-191";

			for (var j = 0; j < arPartsInLevel.length; j++) {   
				oTextBox = document.getElementById("txtQty" + arPartsInLevel[j]);
				oDiv = document.getElementById("divQty" + arPartsInLevel[j]);
				
				if (document.getElementById("_CurrentInputMode").value == "K") {
					if (oTextBox != null) {
						oTextBox.style.display = "block";
						if (oDiv != null) {
							sQuantity = strtrim(oDiv.innerText);
							if (sQuantity.length > 0) {
								oTextBox.value = sQuantity;
							}
							//else
							//	oTextBox.value = " ";
							oDiv.style.display = "none";
						}
					}
				}
				else {
					if (oTextBox != null) {
						sQuantity = strtrim(oTextBox.value);
						oTextBox.style.display = "none";
						if (sQuantity.length > 0) {
							oDiv.innerText = sQuantity;
						}
						else
						{
							oDiv.innerText = " ";
						}
						oDiv.style.display = "block";
					}
				}
			}
		}
	}
}

function setInputTypeB()
{
	var oTable = document.getElementById('tblData');
				
	if (oTable.rows.length > 1) {

		var oTextBox;
		var oDiv;
		var oDivQtyEdit;
		
		var sPartNumber;	
		var bError = false;
		
		for (var i=1; i < (oTable.rows.length-1); i++) {
			var sPartNumber = oTable.rows(i).id;
			oTextBox = document.getElementById("txtQty" + sPartNumber);
			oDiv = document.getElementById("divQty" + sPartNumber);
			oDivQtyEdit = document.getElementById("divQtyEdit" + sPartNumber);

			if (document.getElementById("_CurrentInputMode").value == "K") {
				if (oTextBox != null) {
					oDivQtyEdit.style.display = "block";
					oTextBox.style.display = "block";
					if (oDiv != null) {
						sQuantity = oDiv.innerText;
						if (sQuantity.length > 0) {
							oTextBox.value = sQuantity;
						}
						oDiv.style.display = "none";
					}
				}
			}
			else {
				if (oTextBox != null) {
					sQuantity = strtrim(oTextBox.value);
					oTextBox.style.display = "none";
					oDivQtyEdit.style.display = "none";
					if (sQuantity.length > 0) {
						oDiv.innerText = sQuantity;
					}
					oDiv.style.display = "block";
				}
			}
		}
	}
}

function handleMouseOver()
{
	//window.status = event.srcElement.id + ' handleMouseOver';
	
	var element = event.srcElement;

	if (element.id.substr(0,5) == "tdQty")	{
		
		window.status = element.parentElement.id;
		
		// Mouse over a worksheet set
		if (bMouseDownOnSet) {
			
			if (sCells.length > 0) {

				// Unselect previous range
				// NOTE: This is important to avoid occassional patches...
				unselectCells();
				
				var iRow = element.parentElement.rowIndex;
				var iCol = element.cellIndex;

				// Now select the entire block of cells begining from the cell
				// where mousedown event was first trapped.
				
				var oTable = document.getElementById('tblData')
				
				if (oTable.rows.length > 1) {
				
					if (iRow >= iMouseDownOnSetRow)	{
						iStartRow = iMouseDownOnSetRow;
						iEndRow = iRow;
					}
					else {
						iStartRow = iRow;
						iEndRow = iMouseDownOnSetRow;
					}
					
					if (iCol > iMouseDownOnSetCol) {
						iStartCol = iMouseDownOnSetCol;
						iEndCol = iCol;
					}
					else {
						iStartCol = iCol;
						iEndCol = iMouseDownOnSetCol;
					}
					
					// Select this range
					for (var i=iStartRow; i<=iEndRow; i++) {
						for (var j=iStartCol; j<=iEndCol; j++) {
							if ((oTable.rows(i).cells(j) != null) && (oTable.rows(i).cells(j).id.substr(0,5) == "tdQty"))
								oTable.rows(i).cells(j).style.backgroundColor = sBgColorSelected;
						}
					}
				}
				
				//element.style.backgroundColor='white';
				sCells += ",";
				sCells += event.srcElement.id;
			}
		}
	}

}

function handleMouseOut()
{
	//window.status = event.srcElement.id + ' handleMouseOut';
}

function handleMouseDown()
{
	//window.status = event.srcElement.id + ' handleMouseDown';

	var element = event.srcElement;
	
	// Set element to <td> if on <div> which is inside the <td>
	if (element.id.substr(0,6) == "divQty") {
		element = element.parentElement;
	}

	if (element.id.substr(0,5) == "tdQty")	{

		//window.status = "in mouse down";

		//Un-select currently selected cells
		unselectCells();

		iMouseDownOnSetRow = element.parentElement.rowIndex;
		iMouseDownOnSetCol = element.cellIndex;
		bMouseDownOnSet = true;
		
		element.style.backgroundColor = sBgColorSelected;
	
		iStartRow = iMouseDownOnSetRow;
		iEndRow = iStartRow;
		iStartCol = iMouseDownOnSetCol;
		iEndCol = iStartCol;

		sCells = event.srcElement.id;
	}
}

function handleMouseUp()
{
	//window.status = event.srcElement.id + ' handleMouseUp';
	bMouseDownOnSet = false;
}

function unselectCells()
{
	var oTable = document.getElementById('tblData')
				
	if (oTable.rows.length > 1) {
				
		for (var i=iStartRow; i<=iEndRow; i++) {
			for (var j=iStartCol; j<=iEndCol; j++) {
				if ((oTable.rows(i).cells(j) != null) && (oTable.rows(i).cells(j).id.substr(0,5) == "tdQty"))
					oTable.rows(i).cells(j).style.backgroundColor = sBgColorUnSelected;
			}
		}
	}
	//var str = iStartRow + ',' + iStartCol + ',' + iEndRow + ',' + iEndCol;
	//window.status = str;
}

function attachTableMouseEvents()
{
	if (sOrderType == "A")
		attachTableMouseEventsA();
	else
		attachTableMouseEventsB();
}

function detachTableMouseEvents()
{
	if (sOrderType == "A")
		detachTableMouseEventsA();
	else
		detachTableMouseEventsB();
}

function attachTableMouseEventsA()
{
	if (isIE) {

		// NOTE: This script must be inserted after the </table> tag
		var oTable = document.getElementById('tblData');
		var iWkSetStartCol = 1;
		var iWkSetEndCol = iWkSetStartCol + 19;

		oTable.attachEvent('onmouseup',handleMouseUp);

		//  The following 3 lines were added.
		oTable.attachEvent('onmousedown',handleMouseDown);
		oTable.attachEvent('onmouseover',handleMouseOver);
		oTable.attachEvent('onmouseout',handleMouseOut);

		// 
		// The following lines were commented because it is not necessary to attach events
		// for each cell.  Instead the events were attached to the table i.e. the above 3
		// lines were added.  Will continue to test before completelyremoving the commented lines.
		/*
		if (oTable.rows.length > 1) {
		
			//window.document.body.style.cursor = "wait";
		
			for (var i=1; i<oTable.rows.length; i++) {
				for (var j=iWkSetStartCol; j<=iWkSetEndCol; j++) {
					if ((oTable.rows(i).cells(j) != null) && (oTable.rows(i).cells(j).id.substr(0,5) == "tdQty")) {
						oTable.rows(i).cells(j).attachEvent('onmousedown',handleMouseDown);
						oTable.rows(i).cells(j).attachEvent('onmouseup',handleMouseUp);
						oTable.rows(i).cells(j).attachEvent('onmouseover',handleMouseOver);
						oTable.rows(i).cells(j).attachEvent('onmouseout',handleMouseOut);
					}
				}
			}
		}
		*/		
		
		disableTableSelect();

		//window.document.body.style.cursor = "default";
	}
	
	whichElement = isIE ? document.all.divKeyPad : document.getElementById("divKeyPad");  
}


function detachTableMouseEventsA()
{
	if (isIE) {

		// NOTE: This script must be inserted after the </table> tag
		var oTable = document.getElementById('tblData');
		var iWkSetStartCol = 1;
		var iWkSetEndCol = iWkSetStartCol + 19;
		
		oTable.detachEvent('onmouseup',handleMouseUp);

		// The following 3 lines were added.
		oTable.detachEvent('onmousedown',handleMouseDown);
		oTable.detachEvent('onmouseover',handleMouseOver);
		oTable.detachEvent('onmouseout',handleMouseOut);

		// 
		// The following lines were commented because it is not necessary to detach events
		// for each cell.  Instead the events were detached to the table i.e. the above 3
		// lines were added.  Will continue to test before completely removing the commented lines.
		/*
		if (oTable.rows.length > 1) {
			for (var i=1; i<oTable.rows.length; i++) {
				for (var j=iWkSetStartCol; j<=iWkSetEndCol; j++) {
					if ((oTable.rows(i).cells(j) != null) && (oTable.rows(i).cells(j).id.substr(0,5) == "tdQty")) {
						oTable.rows(i).cells(j).detachEvent('onmousedown',handleMouseDown);
						oTable.rows(i).cells(j).detachEvent('onmouseup',handleMouseUp);
						oTable.rows(i).cells(j).detachEvent('onmouseover',handleMouseOver);
						oTable.rows(i).cells(j).detachEvent('onmouseout',handleMouseOut);
					}
				}
			}
		}
		*/
				
		enableTableSelect();
	}
	
	whichElement = isIE ? document.all.divKeyPad : document.getElementById("divKeyPad");  

}

function attachTableMouseEventsB()
{
	if (isIE) {
		// NOTE: This script must be inserted after the </table> tag
		var oTable = document.getElementById('tblData');
		var iQtyCol = 2;

		oTable.attachEvent('onmouseup',handleMouseUp);

		//   The following 3 lines were added.
		oTable.attachEvent('onmousedown',handleMouseDown);
		oTable.attachEvent('onmouseover',handleMouseOver);
		oTable.attachEvent('onmouseout',handleMouseOut);

		// 
		// The following lines were commented because it is not necessary to attach events
		// for each cell.  Instead the events were attached to the table i.e. the above 3
		// lines were added.  Will continue to test before completelyremoving the commented lines.
		/*
		if (oTable.rows.length > 1) {
			for (var i=1; i<(oTable.rows.length - 1); i++) {
				oTable.rows(i).cells(iQtyCol).attachEvent('onmousedown',handleMouseDown);
				oTable.rows(i).cells(iQtyCol).attachEvent('onmouseup',handleMouseUp);
				oTable.rows(i).cells(iQtyCol).attachEvent('onmouseover',handleMouseOver);
				oTable.rows(i).cells(iQtyCol).attachEvent('onmouseout',handleMouseOut);
			}
		}		
		*/
		
		disableTableSelect();
	}
	
	whichElement = isIE ? document.all.divKeyPad : document.getElementById("divKeyPad");  
}


function detachTableMouseEventsB()
{
	if (isIE) {

		// NOTE: This script must be inserted after the </table> tag
		var oTable = document.getElementById('tblData');
		var iQtyCol = 1;
		
		oTable.detachEvent('onmouseup',handleMouseUp);

		//  The following 3 lines were added.
		oTable.detachEvent('onmousedown',handleMouseDown);
		oTable.detachEvent('onmouseover',handleMouseOver);
		oTable.detachEvent('onmouseout',handleMouseOut);

		// 
		// The following lines were commented because it is not necessary to detach events
		// for each cell.  Instead the events were detached to the table i.e. the above 3
		// lines were added.  Will continue to test before completely removing the commented lines.
		/*
		if (oTable.rows.length > 1) {
			for (var i=1; i<(oTable.rows.length - 1); i++) {
				oTable.rows(i).cells(iQtyCol).detachEvent('onmousedown',handleMouseDown);
				oTable.rows(i).cells(iQtyCol).detachEvent('onmouseup',handleMouseUp);
				oTable.rows(i).cells(iQtyCol).detachEvent('onmouseover',handleMouseOver);
				oTable.rows(i).cells(iQtyCol).detachEvent('onmouseout',handleMouseOut);
			}
		}
		*/
		
		enableTableSelect();
	}
	
	whichElement = isIE ? document.all.divKeyPad : document.getElementById("divKeyPad");  

}

function enableTableSelect()
{
	var oTable = document.getElementById('tblData')
	oTable.onselectstart = new Function ("return true");
}

function disableTableSelect()
{
	var oTable = document.getElementById('tblData')
	oTable.onselectstart = new Function ("return false");
}

function showKeyPad() 
{
	setWinWH();
	
	document.attachEvent('onmousedown', ddInitKeyPad);
	//document.onmousedown=ddInitKeyPad;
	document.onmouseup=Function("ddEnabled=false");

	if (isIE || isNN) {
		if (whichElement != null) {
//			if (whichElement.style.visibility == 'hidden') {
			if (whichElement.style.display == 'none') {
				//whichElement.style.top = winH - 120;
				//whichElement.style.left = winW - 160;
				whichElement.style.top = winH - 180;
				whichElement.style.left = winW - 225;
				//whichElement.style.visibility = 'visible';
				whichElement.style.display = 'block';
			}
		}
	}
	else if (isN4) {
		if (document.divKeyPad.visibility == "hide") {
			document.divKeyPad.visibility = "show";
		}
	}
}

function hideKeyPad()
{
	document.detachEvent('onmousedown', ddInitKeyPad);

	//if ((isIE||isNN) && (whichElement != null)) whichElement.style.visibility = "hidden";
	//else if (isN4) document.divKeyPad.visibility = "hide";

	if ((isIE||isNN) && (whichElement != null)) whichElement.style.display = "none";
	else if (isN4) document.divKeyPad.visibility = "hide";

}

function ddInitKeyPad(e)
{
	topElement = isIE ? "BODY" : "HTML";
	//whichElement = isIE ? document.all.divKeyPad : document.getElementById("divKeyPad");  
	hotElement = isIE ? event.srcElement : e.target;  
	
	while (hotElement.id != "keypadTitleBar" && hotElement.tagName != topElement) {
	  hotElement = isIE ? hotElement.parentElement : hotElement.parentNode;
	} 
	 
	if (hotElement.id == "keypadTitleBar") {
		offsetx = isIE ? event.clientX : e.clientX;
		offsety = isIE ? event.clientY : e.clientY;
		nowX = parseInt(whichElement.style.left);
		nowY = parseInt(whichElement.style.top);
		ddEnabled = true;
		document.onmousemove = ddKeyPad;
	}
}

function ddKeyPad(e)
{
	if (!ddEnabled) return;
	whichElement.style.left = isIE ? nowX + event.clientX-offsetx : nowX + e.clientX-offsetx; 
	whichElement.style.top = isIE ? nowY + event.clientY-offsety : nowY + e.clientY-offsety;
	return false;  
}

function keypadNumClick(sParam)
{
	var sNumber = strtrim(document.getElementById('txtKeyPad').value);
	
	if (isNumeric(sNumber))	{
		if (sNumber.length < 5) {
			sNumber += sParam;
			document.getElementById('txtKeyPad').value = sNumber;
		}
	}
}

function keypadOkClick()
{
	var sNumber = strtrim(document.getElementById('txtKeyPad').value);
	
	if (isNumeric(sNumber))	{
		var iNumber = parseInt(sNumber, 10);
		iNumber = (iNumber > 0) ? iNumber : " "; 
		setCellData(iNumber);
	}
}

function keypadClrClick()
{
	document.getElementById('txtKeyPad').value = ""
}

function setCellData(sNumber)
{
	if (sOrderType == "A")
		setCellDataA(sNumber);
	else
		setCellDataB(sNumber);
}

function setCellDataA(sNumber)
{
	var oTable = document.getElementById('tblData')

	if (oTable.rows.length > 1) {
		for (var i=iStartRow; i<=iEndRow; i++) {
			for (var j=iStartCol; j<=iEndCol; j++) {
				if (oTable.rows(i).cells(j) != null) {
					var id = oTable.rows(i).cells(j).id;
					if (id.length > 0) {
						var oDiv = document.getElementById("divQty" + id.substr(5));
						if (oDiv != null) {
							var oTextBox = document.getElementById("txtQty" + id.substr(5));
							oDiv.innerText = sNumber ;
							oTextBox.value = sNumber;
							isDirty = true;
						}
					}
				}
			}
		}
		
		// Re-Calculate SubTotal for each affected row
		for (i=iStartRow; i<=iEndRow; i++) {
			var sPartNumberBase = oTable.rows(i).id;
			if (sPartNumberBase.lastIndexOf("-") > 0) {
				var sLevel = sPartNumberBase.substr(sPartNumberBase.lastIndexOf("-")+1);
				sPartNumberBase = "txtQty" + sPartNumberBase;
				calculateSubTotalA(sPartNumberBase);	
			}
		}
	}
} 

function setCellDataB(sNumber)
{
	var oTable = document.getElementById('tblData')
				
	if (oTable.rows.length > 1) {
		for (var i=iStartRow; i<=iEndRow; i++) {
			for (var j=iStartCol; j<=iEndCol; j++) {
				var id = oTable.rows(i).id
				var oDiv = document.getElementById("divQty" + id);
				oDiv.innerText = sNumber;
				var oTextBox = document.getElementById("txtQty" + id);
				oTextBox.value = sNumber;
				isDirty = true;				
			}
		}
		
		// Re-Calculate SubTotal for each affected row
		for (i=iStartRow; i<=iEndRow; i++) {
			var sPartNumber = oTable.rows(i).id;
			calculateSubTotalB(sPartNumber);	
		}
	}
}                    

function saveToCart()
{
	var bReturnValue = false;
	
	if (sOrderType == "A") {
		bReturnValue = saveToCartA();
		if (bReturnValue) {
			bReturnValue = validateWkTotal();
		}
	}
	else if(sOrderType == "B")
		bReturnValue = saveToCartB();
	else 
		bReturnValue = saveToCartC();

	// RM - 10/13/2005 - Alert about cart duration only if cart is currently empty was removed
	if (bReturnValue) {
		var element = document.getElementById("_CartItemCount");
		if (element != null) {
			if (strtrim(element.value) == "0") {
				//alert(orderentry_CartDurationAlert);
			}
		}
	}
	
	return bReturnValue;
}

function validateWkTotal()
{
	var bReturnValue = true;
	var sWkTotal, sMaxWkAllowed, sMaxWkAllowedGrace = "0";
	var iWkTotal, iMaxWkAllowed, iMaxWkAllowedGrace = 0;
	var sMaxWkValidate = "1";
	
	// Check if validation required
	var element = document.getElementById("_MaxWkValidate");
	if (element != null) {
		sMaxWkValidate = strtrim(element.innerHTML);
	}

	// Required if anything other than 0
	if (sMaxWkValidate != "0") {	
		// Total wk in cart
		element = document.getElementById("lblTotalValue");
		if (element != null) {
			sWkTotal = strtrim(element.innerHTML);
			if (isNumeric(sWkTotal)) {
				iWkTotal = parseInt(sWkTotal, 10);
			}
		}
	
		// MaxAllowed
		element = document.getElementById("_MaxWkAllowed");
		if (element != null) {
			sMaxWkAllowed = strtrim(element.value);
			if (isNumeric(sMaxWkAllowed)) {
				iMaxWkAllowed = parseInt(sMaxWkAllowed, 10);
			}
		}
	
		// MaxAllowedGrace
		element = document.getElementById("_MaxWkAllowedGrace");
		if (element != null) {
			sMaxWkAllowedGrace = strtrim(element.value);
			if (isNumeric(sMaxWkAllowedGrace)) {
				iMaxWkAllowedGrace = parseInt(sMaxWkAllowedGrace, 10);
			}
		}
	
		if (iMaxWkAllowedGrace > 0) {
			if (iWkTotal > iMaxWkAllowedGrace) {
				alert(orderentry_WkCountError1);
				bReturnValue = false;
			}
			else if (iWkTotal > iMaxWkAllowed) {
				//alert(orderentry_WkCountError2);
				bReturnValue = true;
			}
			else {
				bReturnValue = true;
			}
		}
	}
	
	return bReturnValue;
	
}

function saveToCartA()
{
	
	if (isIE)
		return saveToCartA_IE();
	else
		return saveToCartA_NN();
}

function saveToCartA_IE()
{
	var bError = false;
	//if (!confirm(orderentry_ConfirmSubmit))
	//	bError = true;
	
	if (!bError) {
		var oTable = document.getElementById('tblData');
					
		if (oTable.rows.length > 1) {

			var arPartsInLevel = new Array(20);
			var oTextBox;
			var sLevel;	
			
			for (var i=1; i < oTable.rows.length; i++) {
				var sPartNumberBase = oTable.rows(i).id;
				sLevel = sPartNumberBase.substr(sPartNumberBase.lastIndexOf("-")+1);
				
				arPartsInLevel[0] = sPartNumberBase + "-001";
				arPartsInLevel[1] = sPartNumberBase + "-011";
				arPartsInLevel[2] = sPartNumberBase + "-021";
				arPartsInLevel[3] = sPartNumberBase + "-031";
				arPartsInLevel[4] = sPartNumberBase + "-041";
				arPartsInLevel[5] = sPartNumberBase + "-051";
				arPartsInLevel[6] = sPartNumberBase + "-061";
				arPartsInLevel[7] = sPartNumberBase + "-071";
				arPartsInLevel[8] = sPartNumberBase + "-081";
				arPartsInLevel[9] = sPartNumberBase + "-091";
				arPartsInLevel[10] = sPartNumberBase + "-101";
				arPartsInLevel[11] = sPartNumberBase + "-111";
				arPartsInLevel[12] = sPartNumberBase + "-121";
				arPartsInLevel[13] = sPartNumberBase + "-131";
				arPartsInLevel[14] = sPartNumberBase + "-141";
				arPartsInLevel[15] = sPartNumberBase + "-151";
				arPartsInLevel[16] = sPartNumberBase + "-161";
				arPartsInLevel[17] = sPartNumberBase + "-171";
				arPartsInLevel[18] = sPartNumberBase + "-181";
				arPartsInLevel[19] = sPartNumberBase + "-191";

				for (var j = 0; j < arPartsInLevel.length; j++) {   
					oTextBox = document.getElementById("txtQty" + arPartsInLevel[j]);
					if (oTextBox != null) {
						sQuantity = strtrim(oTextBox.value);
						if (sQuantity.length > 0) {
							iQuantity = parseInt(sQuantity);
							
							if (isNaN(iQuantity)) {
								alert(orderentry_InvalidQtyInLevel + sLevel);
								bError = true;
								break
							}
						}
						
					}
				}
				
				if (bError) {
					break;
				}
			}
		}
	}
	
	return ((bError) ? false : true)
}

function saveToCartA_NN()
{
	var bError = false;
	//if (!confirm(orderentry_ConfirmSubmit))
	//	bError = true;
	
	if (!bError) {
		var oTable = document.getElementById('tblData');
		var rows = oTable.getElementsByTagName('tr');

		var arPartsInLevel = new Array(20);
		var oTextBox;
		var sLevel;	

		for (var i=1; i < (rows.length-1); i++) {
			var sPartNumberBase = rows[i].id;
			sLevel = sPartNumberBase.substr(sPartNumberBase.lastIndexOf("-")+1);

			arPartsInLevel[0] = sPartNumberBase + "-001";
			arPartsInLevel[1] = sPartNumberBase + "-011";
			arPartsInLevel[2] = sPartNumberBase + "-021";
			arPartsInLevel[3] = sPartNumberBase + "-031";
			arPartsInLevel[4] = sPartNumberBase + "-041";
			arPartsInLevel[5] = sPartNumberBase + "-051";
			arPartsInLevel[6] = sPartNumberBase + "-061";
			arPartsInLevel[7] = sPartNumberBase + "-071";
			arPartsInLevel[8] = sPartNumberBase + "-081";
			arPartsInLevel[9] = sPartNumberBase + "-091";
			arPartsInLevel[10] = sPartNumberBase + "-101";
			arPartsInLevel[11] = sPartNumberBase + "-111";
			arPartsInLevel[12] = sPartNumberBase + "-121";
			arPartsInLevel[13] = sPartNumberBase + "-131";
			arPartsInLevel[14] = sPartNumberBase + "-141";
			arPartsInLevel[15] = sPartNumberBase + "-151";
			arPartsInLevel[16] = sPartNumberBase + "-161";
			arPartsInLevel[17] = sPartNumberBase + "-171";
			arPartsInLevel[18] = sPartNumberBase + "-181";
			arPartsInLevel[19] = sPartNumberBase + "-191";

			for (var j = 0; j < arPartsInLevel.length; j++) {   
				oTextBox = document.getElementById("txtQty" + arPartsInLevel[j]);
				if (oTextBox != null) {
					sQuantity = strtrim(oTextBox.value);
					if (sQuantity.length > 0) {
						iQuantity = parseInt(sQuantity);
						
						if (isNaN(iQuantity)) {
							alert(orderentry_InvalidQtyInLevel + sLevel);
							bError = true;
							break
						}
					}
				}
			}

			if (bError) {
				break;
			}
		}
	}

	return ((bError) ? false : true)
}


function saveToCartB()
{
	//called from add or save RM
	if (isIE)
		return saveToCartB_IE();
	else
		return saveToCartB_NN();
}

function saveToCartB_IE()
{
	var bError = false;
	//if (!confirm(orderentry_ConfirmSubmit))
	//	bError = true;
	
	if (!bError) {
		var oTable = document.getElementById('tblData');
		
		if (oTable != null) {
			if (oTable.rows.length > 1) {
				var oTextBox;
				var sPartNumber;
				var sPartDesc;
				var sQuantity;
				var iQuantity;
				
				for (var i=1; i < (oTable.rows.length - 1); i++) {
					sPartNumber = oTable.rows(i).id;
					if(sPartNumber.substring(0, 8) != "trSpacer"  && sPartNumber.substring(0, 8) != "trBorder")
					{
						sPartDescription = oTable.rows(i).cells(1).innerText;
						oTextBox = document.getElementById("txtQty" + sPartNumber);
						if (oTextBox != null) {
							sQuantity = strtrim(oTextBox.value);
							if (sQuantity.length > 0) {
								iQuantity = parseInt(sQuantity);
								if (isNaN(iQuantity)) {
									alert(orderentry_InvalidQtyForPart + sPartDescription);
									bError = true;
									break
								}
							}
						}
						if (bError) {
							break;
						}
					}
				}
			}
		}
		else {
			bError = true;
		}
	}

	return ((bError) ? false : true)
}

function saveToCartB_NN()
{
	var bError = false;
	//if (!confirm(orderentry_ConfirmSubmit))
	//	bError = true;
	
	if (!bError) {
		var oTable = document.getElementById('tblData');
		
		if (oTable != null) {

			var rows = oTable.getElementsByTagName('tr');
			var oTextBox;
			var sPartNumber;
			var sPartDesc;
			var sQuantity;
			var iQuantity;

			for (var i=1; i < (rows.length-1); i++) {
				sPartNumber = rows[i].id;
				//sPartDescription = rows[i].cells(1).innerText;
				sPartDescription = sPartNumber;
				oTextBox = document.getElementById("txtQty" + sPartNumber);
				if (oTextBox != null) {
					sQuantity = strtrim(oTextBox.value);
					if (sQuantity.length > 0) {
						iQuantity = parseInt(sQuantity);
						if (isNaN(iQuantity)) {
							alert(orderentry_InvalidQtyForPart + sPartDescription);
							bError = true;
							break
						}
					}
				}
				if (bError) {
					break;
				}
			}
		}
		else {
			bError = true;
		}
	}

	return ((bError) ? false : true)
}

function saveToCartC()
{
	if (isIE)
		return saveToCartC_IE();
	else
		return saveToCartC_NN();
}

function saveToCartC_IE()
{
	var bError = false;
	//if (!confirm(orderentry_ConfirmSubmit))
	//	bError = true;
	
	if (!bError) 
	{
		var oTable = document.getElementById('tblData');
		if (oTable.rows.length > 2) 
		{
			var oTextBox;
			for (var i=2; i < oTable.rows.length; i++) 
			{
				var sRowName = oTable.rows(i).name;
				if(sRowName != undefined && sRowName.substr(0,5) == "Total")
				{
					var sPartNumberBase = oTable.rows(i).id;
					var sRowTimes = sRowName.substr(6, sRowName.lastIndexOf("-") - 6);
					var sColTimes = sRowName.substr(sRowName.lastIndexOf("-") + 1);
					for(var k=1; k <= sColTimes; k++)
					{
						oTextBox = document.getElementById("txtQty" + sPartNumberBase + "-" + k);
						if (oTextBox != null) {
							sQuantity = strtrim(oTextBox.value);
							if (sQuantity.length > 0) {
								iQuantity = parseInt(sQuantity);
								if (isNaN(iQuantity)) {
									sLevel = oTextBox.name;
									sLevel = sLevel.substr(sLevel.lastIndexOf("-"));
									sPartNumberBase = sPartNumberBase.substr(0, sPartNumberBase.lastIndexOf("-"));
									alert(orderentry_InvalidQtyInLevel  + document.getElementById(sPartNumberBase).innerText + sLevel);
									bError = true;
									break
								}
							}
						}
						
					}
				}
				if (bError) {
					break;
				}			
			}
		}
	}
	
	return ((bError) ? false : true)
}

function saveToCartC_NN()
{
	var bError = false;
	//if (!confirm(orderentry_ConfirmSubmit))
	//	bError = true;
	
	if (!bError) 
	{
		var oTable = document.getElementById('tblData');
		var rows = oTable.getElementsByTagName('tr');

		var oTextBox;
		var sLevel;	

		for (var i=2; i < (rows.length-1); i++) 
		{
			var sRowName = rows[i].name;
			if(sRowName != undefined && sRowName.substr(0,5) == "Total")
			{
				var sPartNumberBase =rows[i].id;
				var sRowTimes = sRowName.substr(6, sRowName.lastIndexOf("-") - 6);
				var sColTimes = sRowName.substr(sRowName.lastIndexOf("-") + 1);
				for(var k=1; k <= sColTimes; k++)
				{
					oTextBox = document.getElementById("txtQty" + sPartNumberBase + "-" + k);
					if (oTextBox != null) 
					{
						sQuantity = strtrim(oTextBox.value);
						if (sQuantity.length > 0) 
						{
							iQuantity = parseInt(sQuantity);
							if (isNaN(iQuantity)) 
							{
								sLevel = oTextBox.name;
								sLevel = sLevel.substr(sPartNumberBase.length + 5);
								alert(orderentry_InvalidQtyInLevel + sLevel);
								bError = true;
								break
							}
						}
					}
					
				}
				
				if (bError) {
					break;
					}
			}
		}
	}

	return ((bError) ? false : true)

}
//start
function onchangeQty(src, iid)
{	
	//sOrderType = "B";
	//if (sOrderType == "A")
		//onchangeQtyA(src);
	//if(sOrderType == "B")
		onchangeQtyB(src, iid);
	//else
		//onchangeQtyC(src);
}

function onchangeQtyA(src)
{
	var id = src.id;
	var sPartNumberBase = id.substr(0,id.length-4);
	isDirty = true;
	calculateSubTotalA(sPartNumberBase);	
}

function onchangeQtyB(src, iid)
{
	
	var id = src.id;
	var sPartNumber = id.substr(6);
	isDirty = true;
	calculateSubTotalB(sPartNumber, iid);	
}

function onchangeQtyC(src)
{
	
	var id = src.id;
	isDirty = true;
	var sCategoryID = id.substr(6,id.lastIndexOf("-")-6);
	sCategoryID = sCategoryID.substr(0,sCategoryID.lastIndexOf("-"));
	calculateSubTotalC(sCategoryID, id);
}

function calculateSubTotalA(sPartNumberBase)
{
	var iTotal = 0;
	var iQuantity = 0;
	var sQuantity = "";
	var arPartsInLevel = new Array(20);
	var oTextBox;
	var sLevel = sPartNumberBase.substr(sPartNumberBase.lastIndexOf("-")+1);

	// VJ - 05/09/2005 flag to indicate if any qty changed
	isCartModified = true;

	arPartsInLevel[0] = sPartNumberBase + "-001";
	arPartsInLevel[1] = sPartNumberBase + "-011";
	arPartsInLevel[2] = sPartNumberBase + "-021";
	arPartsInLevel[3] = sPartNumberBase + "-031";
	arPartsInLevel[4] = sPartNumberBase + "-041";
	arPartsInLevel[5] = sPartNumberBase + "-051";
	arPartsInLevel[6] = sPartNumberBase + "-061";
	arPartsInLevel[7] = sPartNumberBase + "-071";
	arPartsInLevel[8] = sPartNumberBase + "-081";
	arPartsInLevel[9] = sPartNumberBase + "-091";
	arPartsInLevel[10] = sPartNumberBase + "-101";
	arPartsInLevel[11] = sPartNumberBase + "-111";
	arPartsInLevel[12] = sPartNumberBase + "-121";
	arPartsInLevel[13] = sPartNumberBase + "-131";
	arPartsInLevel[14] = sPartNumberBase + "-141";
	arPartsInLevel[15] = sPartNumberBase + "-151";
	arPartsInLevel[16] = sPartNumberBase + "-161";
	arPartsInLevel[17] = sPartNumberBase + "-171";
	arPartsInLevel[18] = sPartNumberBase + "-181";
	arPartsInLevel[19] = sPartNumberBase + "-191";

    for (i = 0; i < arPartsInLevel.length; i++) {  
		oTextBox = document.getElementById(arPartsInLevel[i]);
		if (oTextBox != null) {
			sQuantity = strtrim(oTextBox.value);
			if (sQuantity.length > 0) {
				iQuantity = parseInt(sQuantity, 10);
				
				if (!isNaN(iQuantity)) {
					iTotal += iQuantity;
				}
				else {
					alert(orderentry_InvalidQtyInLevel + sLevel);
				}
			}
			
		}
    }
		
	var element = document.getElementById("lblTotal" + sLevel);
	if (element != null) {	
		element.innerHTML = iTotal.toString();
	}
	
	calculateTotalA();
	
}



function calculateTotalB()
{
	
	if (isIE)
		{
		
		calculateTotalB_IE();
		}
	else
		{

		calculateTotalB_NN();
		}
		
}


function calculateTotalB_IE()
{
	//alert("calculateTotalBIE");
	var oTable = document.getElementById('tblData');
	var dblTotal = parseFloat("0");
	var dblCategoryTotal = parseFloat("0");
	var sCurrencySymbol = "$";

	var element = document.getElementById("_CartItemTotal");
	if (element != null) 
	{
		
		dblTotal = parseFloat(element.value);
	}
	element = document.getElementById("_CartItemCategoryTotal");
	if (element != null) 
	{
		dblCategoryTotal = parseFloat(element.value);
		dblTotal = dblTotal - dblCategoryTotal
	}

	for (var i=1; i < (oTable.rows.length); i++) 
	{

		
	//	if(oRow != null)
	//{
		//sTotal = oRow.name;
		//sTotal = sTotal.substring(6, sTotal.length);
		//sRow = sTotal.substring(0, sTotal.indexOf("-"));
		//sCol = sTotal.substring(sTotal.indexOf("-") + 1, sTotal.length);
		//sTotalQty = 0;
	//}
		
		//var sPartNumber = oTable.rows(i).id;
		var sPartNumber = oTable.rows(i).id;
		
		//sPartNumber = sPartNumber.substring(4);

		var oItemTotal = document.getElementById("lblTotal" + sPartNumber);
		var dblItemTotal = parseFloat("0");
		//alert(sPartNumber);
		if (oItemTotal != null) 
		{
			
			//alert(sPartNumber);
			var sItemTotal = getNumberFromCurrency(oItemTotal.value);
			

			if (sCurrencySymbol.length == 0)
				sCurrencySymbol	= getSymbolFromCurrency(oItemTotal.value);
			if (sItemTotal.length <= 0)
				sItemTotal = "0";
			dblItemTotal = parseFloat(sItemTotal);

		}
		
		if (!isNaN(dblItemTotal))
			dblTotal += dblItemTotal;

	}

	var oTotal = document.getElementById("lblTotalValue");
	
	if (oTotal != null) 
	{
		//alert(dblTotal);
		oTotal.innerHTML = sCurrencySymbol + formatNum(dblTotal, 2);
		
	}
;
}

function calculateTotalB_NN()
{
	var oTable = document.getElementById('tblData');
	var dblTotal = parseFloat("0");
	var dblCategoryTotal = parseFloat("0");
	var sCurrencySymbol = "";
	var rows = oTable.getElementsByTagName('tr');
	

	var element = document.getElementById("_CartItemTotal");
	if (element != null) {
		dblTotal = parseFloat(element.value);
	}

	// VJ - 05/12/2005 Subtract existing category total to get correct dynamic totalling
	element = document.getElementById("_CartItemCategoryTotal");
	if (element != null) {
		dblCategoryTotal = parseFloat(element.value);
		dblTotal = dblTotal - dblCategoryTotal
	}

	for (var i=1; i < (rows.length-1); i++) {
		var sPartNumber = rows[i].id;
		var oItemTotal = document.getElementById("lblTotal" + sPartNumber);
		var dblItemTotal = parseFloat("0");
		if (oItemTotal != null) {
			var sItemTotal = getNumberFromCurrency(oItemTotal.innerHTML);
			if (sCurrencySymbol.length == 0)
				sCurrencySymbol	= getSymbolFromCurrency(oItemTotal.innerHTML);
			
			if (sItemTotal.length <= 0)
				sItemTotal = "0";
			dblItemTotal = parseFloat(sItemTotal);
		}
		
		if (!isNaN(dblItemTotal))
			dblTotal += dblItemTotal;
	}
	
	var oTotal = document.getElementById("lblTotalValue");
	if (oTotal != null) {
		oTotal.innerHTML = sCurrencySymbol + formatNum(dblTotal, 2);
	}
}

function calculateSubTotalB(sPartNumber,iid)
{
	var bError = false;
	var sError = "";
	var sPrice = "";

	//var sSalePrice = ""; //RM
	//var oSalePrice = document.getElementById("tdSalePrice" + sPartNumber); //RM
	var oPrice = document.getElementById("tdPrice" + sPartNumber);
	
	
	var oTextBox = document.getElementById("txtQty" + sPartNumber);
	var oPart = document.getElementById("tdPart" + sPartNumber);
	var oItemTotal = document.getElementById("lblTotal" + sPartNumber);
	var dblItemTotal = 0.0;
	var sCurrencySymbol = "$";
	var sQuantity = "";
	var iQuantity = 0;
	
	// VJ - 05/09/2005 flag to indicate if any qty changed
	isCartModified = true;

	if (oTextBox != null)
	{
		
			sQuantity = strtrim(oTextBox.value);
			
			
			// Determine quantity
			if (sQuantity.length <= 0) 
				sQuantity = "0";
			if (!isNumeric(sQuantity))
			
				bError = true;
			if (!bError) 
			{
				iQuantity = parseInt(sQuantity, 10);
				if (isNaN(iQuantity))
					bError = true;
			}
		
		if (bError)
			{
			//sError = "Invalid Quantity For Item:" + oPart.innerText;
			sError = "Invalid Quantity!";
			oTextBox.value = "";
			}
	}
		
	/////////RM 05302007			
	////////if(oPrice != null && oPrice.innerHTML != "$0.00")
	////////{
		
		////////sPrice = getNumberFromCurrency(oPrice.value);
		//sCurrencySymbol	= getSymbolFromCurrency(oPrice.value);
		// Determine price
		
		////////if (!bError) 
		////////{
			////////if (sPrice.length <= 0) 
				////////sPrice = "0";
			////////var dblPrice = parseFloat(sPrice);
			
			////////if (isNaN(dblPrice))
				////////bError = true;
			
			////////if (bError)
				////////sError = "Invalid Quantity For Item:" + oPart.innerText;
			////////else
			////////{
				////////dblItemTotal = iQuantity * dblPrice;
				//alert(dblItemTotal);
				////////if (dblItemTotal > 0)
					//alert("HI");
					////////{
						////////oItemTotal.value = sCurrencySymbol + formatNum(dblItemTotal, 2);
						////////document.getElementById(iid).style.backgroundColor="#e3e3e3";
						////////document.getElementById('row2'+iid).style.backgroundColor="#e3e3e3";
						////////document.getElementById('row3'+iid).style.backgroundColor="#e3e3e3";
						////////oItemTotal.style.backgroundColor="#e3e3e3";
						////////calculateTotalB();
					////////}
					
				////////else
					////////{
						////////oItemTotal.value = "";
						////////document.getElementById(iid).style.backgroundColor="white";
						////////document.getElementById('row2'+iid).style.backgroundColor="white";
						////////document.getElementById('row3'+iid).style.backgroundColor="white";
						////////oItemTotal.style.backgroundColor="white";
						////////calculateTotalB();
					////////}
			////////}
		////////}
	////////}
					
	if (bError)
		alert(sError);
	
}

function calculateSubTotalC(sCategoryID)
{
	var bError = false;
	var sError = "";
	var sTotal; var sRow = 0; var sCol = 0; var sTotalQty;
	
	var oRow = document.getElementById(sCategoryID + "-1");

	// VJ - 05/09/2005 flag to indicate if any qty changed
	isCartModified = true;

	if(oRow != null)
	{
		sTotal = oRow.name;
		sTotal = sTotal.substring(6, sTotal.length);
		sRow = sTotal.substring(0, sTotal.indexOf("-"));
		sCol = sTotal.substring(sTotal.indexOf("-") + 1, sTotal.length);
		sTotalQty = 0;
	}
	
	for(var i=1; i<=sRow; i++)
	{
		for(var j=1; j <= sCol; j++)
		{
			var oQty = document.getElementById("txtQty" + sCategoryID + "-" + i + "-" + j);
			if(oQty != null)
			{
				var sQuantity = strtrim(oQty.value);
				if (sQuantity.length <= 0) 
					sQuantity = "0";
				if (!isNumeric(sQuantity))
					bError = true;
				
				if (!bError) 
					if(!isNaN(parseInt(sQuantity,10)))
						sTotalQty = sTotalQty + parseInt(sQuantity,10);	
					else
						bError = true;
				if(bError)
					break;
			}
			else
				break;
		}
		if(bError) 
			break;
	}
	if (bError)
	{
		var oQty = document.getElementById("txtQty" + sCategoryID + "-" + i + "-" + j);
		var sLevel = oQty.name;
		sLevel = sLevel.substr(sLevel.lastIndexOf("-"));
		sError = "Invalid Quantity For Item:" + document.getElementById(sCategoryID).innerText + sLevel;
		alert(sError);		
	}
	else
	{
		var oTotal = document.getElementById("lblTotal" + sCategoryID);
		if(oTotal != null)
			oTotal.innerHTML = sTotalQty;
		
		var oPrice = document.getElementById("lblPrice" + sCategoryID);
		if(oPrice != null)
		{
			if(oPrice.innerText != "$0.00")
			{
				var sCurrencySymbol	= getSymbolFromCurrency(oPrice.innerText);
				var price = getNumberFromCurrency(oPrice.innerText);
				var oCost = document.getElementById("lblCost" + sCategoryID);
				if (!isNaN(price))
					oCost.innerHTML = sCurrencySymbol + formatNum(sTotalQty * price,2);
				calculateTotalC();	
			}
		}
	}
}

function calculateTotalC()
{
	if (isIE)
		calculateTotalC_IE();
	else
		calculateTotalC_NN();
}

function calculateTotalC_IE()
{
	var oTable = document.getElementById('tblData');
	var dblTotal = parseFloat("0");
	var dblCategoryTotal = parseFloat("0");
	var sCurrencySymbol = "";
	var sCategoryID = "";
	var sPreviousCategoryID = "";

	// VJ - 05/04/2005 Default to current cart total
	// Un-comment the following 3 lines if lblTotalValue is 
	// the ShoppingCart total and not just the category total
	var element = document.getElementById("_CartItemTotal");
	if (element != null) {
		dblTotal = parseFloat(element.value);
	}

	// VJ - 05/12/2005 Subtract existing category total to get correct dynamic totalling
	element = document.getElementById("_CartItemCategoryTotal");
	if (element != null) {
		dblCategoryTotal = parseFloat(element.value);
		dblTotal = dblTotal - dblCategoryTotal
	}

	// VJ - 05/04/2005 Re-write to fix Total problem
	for (var i=1; i < (oTable.rows.length-1); i++) {
		sCategoryID = oTable.rows(i).id;
		var pos = sCategoryID.indexOf("-")
		if (pos >=0) {
			sCategoryID = sCategoryID.substring(0,pos);
			if (sPreviousCategoryID != sCategoryID) {
				var oItemTotal = document.getElementById("lblCost" + sCategoryID);
				var dblItemTotal = parseFloat("0");

				if (oItemTotal != null) {
					var sItemTotal = getNumberFromCurrency(oItemTotal.innerHTML);
					if (sCurrencySymbol.length == 0)
						sCurrencySymbol	= getSymbolFromCurrency(oItemTotal.innerHTML);
					
					if (sItemTotal.length <= 0)
						sItemTotal = "0";
					dblItemTotal = parseFloat(sItemTotal);
				}
				if (!isNaN(dblItemTotal))
					dblTotal += dblItemTotal;
				sPreviousCategoryID = sCategoryID;
			}
		}
	}
	
	var oTotal = document.getElementById("lblTotalValue");
	if (oTotal != null) {
		oTotal.innerHTML = sCurrencySymbol + formatNum(dblTotal, 2);
	}
}

function calculateTotalC_NN()
{
	var oTable = document.getElementById('tblData');
	var dblTotal = parseFloat("0");
	var dblCategoryTotal = parseFloat("0");
	var sCurrencySymbol = "";
	var rows = oTable.getElementsByTagName('tr');
	var sCategoryID = "";
	var sPreviousCategoryID = "";

	// VJ - 05/04/2005 Default to current cart total
	// Un-comment the following 3 lines if lblTotalValue is 
	// the ShoppingCart total and not just the category total
	var element = document.getElementById("_CartItemTotal");
	if (element != null) {
		dblTotal = parseFloat(element.value);
	}

	// VJ - 05/12/2005 Subtract existing category total to get correct dynamic totalling
	element = document.getElementById("_CartItemCategoryTotal");
	if (element != null) {
		dblCategoryTotal = parseFloat(element.value);
		dblTotal = dblTotal - dblCategoryTotal
	}

	// VJ - 05/04/2005 Re-write to fix Total problem
	for (var i=1; i < (rows.length-1); i++) {
		sCategoryID = rows[i].id;
		var pos = sCategoryID.indexOf("-")
		if (pos >=0) {
			sCategoryID = sCategoryID.substring(0,pos);
			if (sPreviousCategoryID != sCategoryID) {
				var oItemTotal = document.getElementById("lblCost" + sCategoryID);
				var dblItemTotal = parseFloat("0");

				if (oItemTotal != null) {
					var sItemTotal = getNumberFromCurrency(oItemTotal.innerHTML);
					if (sCurrencySymbol.length == 0)
						sCurrencySymbol	= getSymbolFromCurrency(oItemTotal.innerHTML);
					
					if (sItemTotal.length <= 0)
						sItemTotal = "0";
					dblItemTotal = parseFloat(sItemTotal);
				}
				if (!isNaN(dblItemTotal))
					dblTotal += dblItemTotal;
				sPreviousCategoryID = sCategoryID;
			}
		}
	}
	
	var oTotal = document.getElementById("lblTotalValue");
	if (oTotal != null) {
		oTotal.innerHTML = sCurrencySymbol + formatNum(dblTotal, 2);
	}
}





function openOrderEntryPart(sPartNumber)
{
	var oTextBox = document.getElementById("txtQty" + sPartNumber);
	var oPart = document.getElementById("tdPart" + sPartNumber);
	var bError = false;
	
	var sHref = "./orderentrypart.aspx?PartNumber=" + sPartNumber;
	var sQuantity = "0";
	var sMode = "3";
	
	if (sAllowEdit == "1") {
		sMode = "1";
		if (oTextBox != null) {
			sQuantity = strtrim(oTextBox.value);
			
			// Determine quantity
			if (sQuantity.length <= 0) 
				sQuantity = "0";
			if (!isNumeric(sQuantity))
				bError = true;
			if (!bError) {
				var iQuantity = parseInt(sQuantity, 10);
				if (isNaN(iQuantity))
					bError = true;
			}

			if (bError)
				sError = "Invalid quantity for item " + oPart.innerText;
		}
	}

	if (!bError)	
		location.href = sHref + "&Qty=" + sQuantity + "&Mode=" + sMode;

}

function openOrderEntryPartCoffee(sPartNumber)
{
	var oTextBox = document.getElementById("txtQty" + sPartNumber);
	var oPart = document.getElementById("tdPart" + sPartNumber);
	var bError = false;
	
	var sHref = "./orderentrypartcoffee.aspx?PartNumber=" + sPartNumber;
	var sQuantity = "0";
	var sMode = "3";
	
	if (sAllowEdit == "1") {
		sMode = "1";
		if (oTextBox != null) {
			sQuantity = strtrim(oTextBox.value);
			
			// Determine quantity
			if (sQuantity.length <= 0) 
				sQuantity = "0";
			if (!isNumeric(sQuantity))
				bError = true;
			if (!bError) {
				var iQuantity = parseInt(sQuantity, 10);
				if (isNaN(iQuantity))
					bError = true;
			}

			if (bError)
				sError = "Invalid quantity for item " + oPart.innerText;
		}
	}

	if (!bError)	
		location.href = sHref + "&Qty=" + sQuantity + "&Mode=" + sMode;

}



