var m_fLineQtyIsCorrect=false;
var m_fLineQtyIsValid=false;
var m_fReady = false;
var m_PopupWindow; 

function is()
{ 
	var agt=navigator.userAgent.toLowerCase()
	this.major = parseInt(navigator.appVersion)
	this.nav = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)))
	this.nav4 = (this.nav && (this.major == 4))
	this.nav4up = this.nav && (this.major >= 4)
	
	this.netscape = (agt.indexOf('netscape') != -1);
	this.firefox = (agt.indexOf('firefox') != -1);
	this.opera = (agt.indexOf('opera') != -1);
	this.safari = (agt.indexOf('safari') != -1);

	this.ie = ((agt.indexOf("msie") != -1) && (!this.netscape) && (!this.firefox) && (!this.opera));
	this.iePC = this.ie && (agt.indexOf("windows") != -1);
	this.ieMac = this.ie && (agt.indexOf("MAC") != -1);
}

function GetChildCtl( childNodes )
{ 
	for ( var i=0; i<childNodes.length; i++ )
		if ( childNodes[i].className == 'WebControl')
			return childNodes[i];
}

function VerifyLineQuantities( TableID, ColText_StepQty, ColText_Qty1, ColText_Qty2 )
{
	//m_fReady = true;
	m_fLineQtyIsCorrect = true;
	m_fLineQtyIsValid = true;
	var tbl = document.getElementById( TableID );
	if ( tbl.rows.length < 2 )
		return;
	
	// get cell indexes for the StepQty and Qty-to... columns
	var colStepQty = -1;
	var colQty1 = -1;
	var colQty2 = -1;
	for ( var i=0; i<tbl.rows[1].cells.length; i++ )
	{
		if ( ColText_StepQty == tbl.rows[1].cells[i].innerHTML )
			colStepQty = i;
		else if ( ColText_Qty1 == tbl.rows[1].cells[i].innerHTML )
			colQty1 = i;
		else if ((ColText_Qty2!='') && (ColText_Qty2 == tbl.rows[1].cells[i].innerHTML))
			colQty2 = i;
	}
	if ((colStepQty == -1) || (colQty1 == -1))
		return;
		
	// highlight rows with invalid quantities
	for ( var i=2; i<tbl.rows.length; i++ )
	{
		var row = tbl.rows[i];
		var stepqty = parseFloat( row.cells[colStepQty].innerHTML);
		
		var qty1 = parseFloat(GetChildCtl(row.cells[colQty1].childNodes).value);
		if ( GetChildCtl(row.cells[colQty1].childNodes).value == "")
			qty1 = NaN;
		
		var qty2 = 0;
		if ( colQty2 != -1 )
		{
			qty2 = parseFloat( GetChildCtl(row.cells[colQty2].childNodes).value);
			if (GetChildCtl(row.cells[colQty2].childNodes).value == "")
				qty2 = NaN;
		}
	
		var chk = GetChildCtl(row.cells[0].childNodes).childNodes[0];
		if ( chk == null )
			return;
			
		// check whether quantity is numeric and not empty
		if (chk.checked && (isNaN(qty1) || isNaN(qty2)))
		{
			m_fLineQtyIsValid = false;
			row.className = "NormalGridSelectedItem";
		}
		else
		{
			if (  (i % 2) == 0)
				row.className = "NormalGridItem";
			else
				row.className = "NormalGridAltItem";
		}
	}
	if ( m_fLineQtyIsValid == false)
		return;
		
	for ( var i=2; i<tbl.rows.length; i++ )
	{
		var row = tbl.rows[i];
		var stepqty = parseFloat( row.cells[colStepQty].innerHTML);
		var qty1 = parseFloat(GetChildCtl(row.cells[colQty1].childNodes).value); //parseFloat( row.cells[colQty1].childNodes[0].value);
		var qty2 = 0;
		if ( colQty2 != -1 )
			qty2 = parseFloat( GetChildCtl(row.cells[colQty2].childNodes).value);
		
		var chk = GetChildCtl(row.cells[0].childNodes).childNodes[0];
		if ( chk == null )
			return;
		
		// check whether quantity is correct
		if (chk.checked && ((qty1+qty2) > stepqty))
		{
			row.className = "NormalGridSelectedItem";
			m_fLineQtyIsCorrect = false;
		}
	}
}

function OpenCalendar( Path, idname, CheckBoxID )
{
	m_PopupWindow = window.open( Path + '?FormName=' + document.forms[0].name + 
		'&Id=' + idname + '&InitDate=' + document.forms[0].elements[idname].value +
		'&CheckBoxID=' + CheckBoxID,
		'calendar', 
		'width=212,height=270,left=200,top=250');
}

function SetDate(formName, id, newDate, CheckBoxID )
{
	eval('var theform = document.' + formName + ';');
	m_PopupWindow.close();
	theform.elements[id].value = newDate;

	if ((CheckBoxID != '') && (theform.elements[CheckBoxID] != null))
		theform.elements[CheckBoxID].checked = true;
}

function OpenItemLookup( Path, ProgramID, 
	TextBoxID_ForItemID, TextBoxID_ForPartNum, 
	TextBoxID_ForItemDesc, TextBoxID_ForItemOnHand, 
	TextBoxID_ForItemPrice, TextBoxID_ForFixedLoc, 
	TextBoxID_ForItemIds, TextBoxID_ForItemQtys, fPostBack,
	TextBoxID_ForInBoundUom, TextBoxID_ForOutBoundUom, ControlID_ForItemUom,
	TextBoxID_ForUomIds, OrderType)
{
	var scrstr = is.ie?'':',scrollbars=yes';
	m_PopupWindow = window.open( Path + '?ProgramID=' + ProgramID + 
		'&ResultFormName=' + document.forms[0].name + 
		'&TextBoxID_ForItemID=' + TextBoxID_ForItemID + 
		'&TextBoxID_ForPartNum=' + TextBoxID_ForPartNum +
		'&TextBoxID_ForItemDesc=' + TextBoxID_ForItemDesc +
		'&TextBoxID_ForItemOnHand=' + TextBoxID_ForItemOnHand +
		'&TextBoxID_ForItemPrice=' + TextBoxID_ForItemPrice +
		'&TextBoxID_ForFixedLoc=' + TextBoxID_ForFixedLoc +
		'&TextBoxID_ForItemIds=' + TextBoxID_ForItemIds +
		'&TextBoxID_ForUomIds=' + TextBoxID_ForUomIds +
		'&TextBoxID_ForItemQtys=' + TextBoxID_ForItemQtys +
		'&TextBoxID_ForInBoundUom=' + TextBoxID_ForInBoundUom +
		'&TextBoxID_ForOutBoundUom=' + TextBoxID_ForOutBoundUom +
		'&ControlID_ForItemUom=' + ControlID_ForItemUom +
		'&OrderType=' + OrderType +
		'&fPostBack=' + fPostBack,
		'Items', 
		'width=500,height=480,left=220,top=150'+scrstr);
	m_PopupWindow.focus();
}
function SetFoundItemData( ResultFormName, 
	TextBoxID_ForItemID, TextBoxID_ForPartNum, TextBoxID_ForItemDesc, 
	TextBoxID_ForItemOnHand, TextBoxID_ForItemPrice, TextBoxID_ForFixedLoc,
	TextBoxID_ForInBoundUom,TextBoxID_ForOutBoundUom, ControlID_ForItemUom,
	SelectedItemID, SelectedPartNum, SelectedItemDesc, SelectedItemOnHand,
	SelectedItemPrice, SelectedFixedLoc,
	SelectedInBoundUom, SelectedOutBoundUom, fPostBack )
{
	eval('var theform = document.' + ResultFormName + ';');
	if ( m_PopupWindow != null)
		m_PopupWindow.close();
		
	if ( TextBoxID_ForItemID != '' )
		theform.elements[TextBoxID_ForItemID].value = SelectedItemID;
	if ( TextBoxID_ForPartNum != '' )
		theform.elements[TextBoxID_ForPartNum].value = SelectedPartNum;
	if ( TextBoxID_ForItemDesc != '' )
		theform.elements[TextBoxID_ForItemDesc].value = SelectedItemDesc;
	if ( TextBoxID_ForItemOnHand != '' )
		theform.elements[TextBoxID_ForItemOnHand].value = SelectedItemOnHand;
	if ( TextBoxID_ForItemPrice != '' )
		theform.elements[TextBoxID_ForItemPrice].value = SelectedItemPrice;
	if ( TextBoxID_ForFixedLoc != '' )
		theform.elements[TextBoxID_ForFixedLoc].value = SelectedFixedLoc;
	if ( TextBoxID_ForInBoundUom != '' && theform.elements[TextBoxID_ForInBoundUom] != null)
		theform.elements[TextBoxID_ForInBoundUom].value = SelectedInBoundUom;
	if ( TextBoxID_ForOutBoundUom != '' && theform.elements[TextBoxID_ForOutBoundUom] != null)
		theform.elements[TextBoxID_ForOutBoundUom].value = SelectedOutBoundUom;
	if ( ControlID_ForItemUom != '' && theform.elements[ControlID_ForItemUom] != null) {
		setCurUomId(TextBoxID_ForPartNum,TextBoxID_ForItemID,TextBoxID_ForFixedLoc,TextBoxID_ForItemDesc,TextBoxID_ForItemOnHand,TextBoxID_ForInBoundUom,TextBoxID_ForOutBoundUom,ControlID_ForItemUom);
	}
	if (typeof ItemLookup_OnItemSelect == 'function')
		ItemLookup_OnItemSelect();
		
	if( document.location.pathname.toUpperCase().indexOf('/TRANSACTIONS/EXECTRANS.ASPX') > -1 ||
		document.location.pathname.toUpperCase().indexOf('/TAGS/EXECTRANS.ASPX') > -1 ||
		document.location.pathname.toUpperCase().indexOf('/TAGS/EXECTRANSFER.ASPX') > -1 )
		LoadItemData(theform.elements[TextBoxID_ForPartNum].parentNode.parentNode);
	
	if ( fPostBack )
		theform.submit();
}
function SetMultipleItems( thisDoc, ResultFormName, UomColNum, GridID, TextBoxID_ForItemIds, TextBoxID_ForUomIds,TextBoxID_ForItemQtys, LabelParentID, LabelID, LabelText, ConfirmationText )
{
	thisDoc.getElementById(LabelParentID).style.display = "none";
	
	eval('var theform = document.' + ResultFormName + ';');
	var itemIds = ''; //theform.elements[TextBoxID_ForItemIds].value;
	var uomIds = ''; //theform.elements[TextBoxID_ForUomIds].value;
	var itemQtys = ''; //theform.elements[TextBoxID_ForItemQtys].value;
	var colItemID = 0;
	var colItemQty = 10;
	var index = 0;
	var grid = thisDoc.getElementById( GridID );

	if ( grid != null )
	{
		for ( i=0; i<grid.rows.length; i++ )
		{
			if (grid.rows[i].cells[colItemQty] != null)
			{
				var txtId, txtQty, txtUom, j;
				for ( j=0; j<grid.rows[i].cells[colItemQty].childNodes.length; j++ )
					if ( 'INPUT' == grid.rows[i].cells[colItemID].childNodes[j].nodeName )
						txtId = grid.rows[i].cells[colItemID].childNodes[j];
				
				for ( j=0; j<grid.rows[i].cells[colItemQty].childNodes.length; j++ )
					if ( 'INPUT' == grid.rows[i].cells[colItemQty].childNodes[j].nodeName )
						txtQty = grid.rows[i].cells[colItemQty].childNodes[j];

				txtUom= grid.rows[i].cells[UomColNum].innerHTML;
						
				if (txtId!=null && txtQty!=null &&  txtQty!=null && !isNaN(parseInt(txtUom)) && (0 <= parseInt(txtUom)) && !isNaN(parseFloat(txtQty.value)) && (0 != parseFloat(txtQty.value)))
				{
					itemIds = itemIds + "," + txtId.value;
					uomIds =  uomIds + "," + txtUom;
					itemQtys = itemQtys + "," + parseFloat(txtQty.value);
					txtQty.value = '';
					index = index + 1;
				}
			}
		}
		
		if ( index > 0)
		{
			theform.elements[TextBoxID_ForItemIds].value = itemIds.substring(1);
			theform.elements[TextBoxID_ForUomIds].value = uomIds.substring(1);
			theform.elements[TextBoxID_ForItemQtys].value = itemQtys.substring(1);
			theform.submit();				
			
			thisDoc.getElementById(LabelParentID).style.display = "block";
			thisDoc.getElementById(LabelID).innerHTML = LabelText + index;
			if ( m_PopupWindow != null )
				m_PopupWindow.focus();
		}
	}
}

function OpenKitLookup( Path, ProgramID, TextBoxID_ForKitID, TextBoxID_ForKitNum, 
			TextBoxID_ForKitName, fPostBack )
{
	m_PopupWindow = window.open( Path + '?ProgramID=' + ProgramID + 
		'&ResultFormName=' + document.forms[0].name + 
		'&TextBoxID_ForKitID=' + TextBoxID_ForKitID + 
		'&TextBoxID_ForKitNum=' + TextBoxID_ForKitNum + 
		'&TextBoxID_ForKitName=' + TextBoxID_ForKitName + 
		'&fPostBack=' + fPostBack,
		'KitLookup', 
		'width=478,height=480,left=200,top=120');
}
function SetFoundKitData( ResultFormName, TextBoxID_ForKitID, 
	TextBoxID_ForKitNum, TextBoxID_ForKitName, 
	SelectedKitID, SelectedKitNum, SelectedKitName, fPostBack )
{
	eval('var theform = document.' + ResultFormName + ';');
	if ( m_PopupWindow == null)
		window.self.close();
	else
		m_PopupWindow.close();
	if (TextBoxID_ForKitID != '')
		theform.elements[TextBoxID_ForKitID].value = SelectedKitID;
	if (TextBoxID_ForKitNum != '')
		theform.elements[TextBoxID_ForKitNum].value = SelectedKitNum;
	if (TextBoxID_ForKitName != '')
		theform.elements[TextBoxID_ForKitName].value = SelectedKitName;
	if ( fPostBack )
		theform.submit();
}

function CheckAllBoxes( chkAll, chkBoxName, txtHidden_ToCheck ) 
{
	var i, elems, fFlag;
	elems = document.forms[0].elements;	

	for (i=0; i<elems.length; i++) 
	{
		if ((elems[i].type == 'checkbox') &&  (elems[i].name.indexOf(chkBoxName) > -1)) 
		{
			tr = GetParentNode( elems[i], 'tr' );			
			if ((txtHidden_ToCheck == null) || (txtHidden_ToCheck == ''))
				elems[i].checked = chkAll.checked;
			else 
			{
				if (tr.getAttribute(txtHidden_ToCheck) == 'true')
					elems[i].checked = chkAll.checked;
			}
		}
	}
}

function IsCheckBoxChecked( chkBoxName )
{
	var i, elems, cflag;
	elems = document.forms[0].elements;
	cflag = false;
	
	for (i=0; i<elems.length; i++)
	{
		if ((elems[i].type == 'checkbox') && (elems[i].name.indexOf(chkBoxName) > -1))
		{
			if (elems[i].checked)
			{
				cflag = true;
				break;
			}
		}
	}
	if (!cflag)
	{
		alert( 'No Items selected' );
	}
	
	return cflag;
}

function GetParentNode( elem, parentTag )
{
	var node = elem;
	while (node != null)
	{
		node = node.parentNode;
		if ( node.tagName.toLowerCase() == parentTag.toLowerCase())
			return node;
	}
	return null;
}

function LookupSNs( Path, HeaderID, LineID, ItemID, SysStepID, LineNo, PartNum, ItemDesc, Qty ) 
{
	m_PopupWindow = window.open( Path + 
		'?OrderHeaderID=' + HeaderID + 
		'&OrderLineID=' + LineID + 
		'&ItemID=' + ItemID + 
		'&SysStepID=' + SysStepID + 
		'&LineNo=' + LineNo + 
		'&PartNumber=' + PartNum + 
		'&ItemDesc=' + ItemDesc +
		'&Quantity=' + Qty,
		'Lookup', 
		'width=480,height=496,left=220,top=100');
}

function OpenLocationLookup( Path, ProgramID, TextBoxID_ForLocID, 
	TextBoxID_ForCompany, TextBoxID_ForLocName,
	TextBoxID_ForContact, TextBoxID_ForAddr1, TextBoxID_ForAddr2, 
	TextBoxID_ForPhone, TextBoxID_ForFax, AddressLabelID, TextBoxID_ForStoredText, ControlID_ForLocation )
{
	m_PopupWindow = window.open( Path + 
		'?ResultFormName=' + document.forms[0].name + 
		'&ProgramID=' + ProgramID +
		'&TextBoxID_ForLocID=' + TextBoxID_ForLocID + 
		'&TextBoxID_ForCompany=' + TextBoxID_ForCompany + 
		'&TextBoxID_ForLocName=' + TextBoxID_ForLocName + 
		'&TextBoxID_ForContact=' + TextBoxID_ForContact +
		'&TextBoxID_ForAddr1=' + TextBoxID_ForAddr1 +
		'&TextBoxID_ForAddr2=' + TextBoxID_ForAddr2 +
		'&TextBoxID_ForPhone=' + TextBoxID_ForPhone +
		'&TextBoxID_ForFax=' + TextBoxID_ForFax +
		'&AddressLabelID=' + AddressLabelID +
		'&TextBoxID_ForStoredText=' + TextBoxID_ForStoredText +
		'&ControlID_ForLocation=' + ControlID_ForLocation,
		'Lookup', 
		'width=520,height=500,left=220,top=120');
}
function SetFoundLocationData( ResultFormName, TextBoxID_ForLocID, 
	TextBoxID_ForCompany, TextBoxID_ForLocName, TextBoxID_ForContact, 
	TextBoxID_ForAddr1, TextBoxID_ForAddr2, TextBoxID_ForPhone, TextBoxID_ForFax, 
	AddressLabelID, TextBoxID_ForStoredText, ControlID_ForLocation, 
	SelectedLocID, SelectedCompany, SelectedLocName, SelectedContact, 
	SelectedAddr1, SelectedAddr2, SelectedPhone, SelectedFax )
{
	if ( SelectedLocID != '' )
	{
		eval('var theform = document.' + ResultFormName + ';');
		if ( m_PopupWindow == null)
			window.self.close();
		else
			m_PopupWindow.close();

		if ( TextBoxID_ForLocID != '' )
			theform.elements[TextBoxID_ForLocID].value = SelectedLocID;
		if ( TextBoxID_ForCompany != '' )
			theform.elements[TextBoxID_ForCompany].value = SelectedCompany;
		if ( TextBoxID_ForLocName != '' )
			theform.elements[TextBoxID_ForLocName].value = SelectedLocName;
		if ( TextBoxID_ForContact != '' )
			theform.elements[TextBoxID_ForContact].value = SelectedContact;
		if ( TextBoxID_ForAddr1 != '' )
			theform.elements[TextBoxID_ForAddr1].value = SelectedAddr1;
		if ( TextBoxID_ForAddr2 != '' )
			theform.elements[TextBoxID_ForAddr2].value = SelectedAddr2;
		if ( TextBoxID_ForPhone != '' )
			theform.elements[TextBoxID_ForPhone].value = SelectedPhone;
		if ( TextBoxID_ForFax != '' )
			theform.elements[TextBoxID_ForFax].value = SelectedFax;
		if ( ControlID_ForLocation != '' && theform.elements[ControlID_ForLocation] )
			theform.elements[ControlID_ForLocation].value = 0;

		if ( AddressLabelID != null )
		{
			var label = document.getElementById( AddressLabelID );
			label.innerHTML = SelectedLocName + '<BR>' + SelectedContact + '<BR>' + SelectedAddr1 + '<BR>' + SelectedAddr2 + '<BR>';
			if ((SelectedPhone != null) && (SelectedPhone != '') && (SelectedPhone != ' '))
				label.innerHTML += 'Ph: ' + SelectedPhone + '  ';
			if ((SelectedFax != null) && (SelectedFax != '') && (SelectedFax != ' '))
				label.innerHTML += 'Fax: ' + SelectedFax;
			
			if ( TextBoxID_ForStoredText != '' )
				theform.elements[TextBoxID_ForStoredText].value = label.innerHTML;
		}
		if (typeof LocationLookup_OnItemSelect == 'function')
			LocationLookup_OnItemSelect();
	}
}

function SwapOrderHeader( SourceCtl, FullDivID )
{
	var DivFull = document.getElementById( FullDivID );
	if ( DivFull.style.display == "block" )
	{
		DivFull.style.display = "none";
	}
	else
	{
		DivFull.style.display = "block";
	}
}
function OpenPrintOrder( url, xslDropDownID )
{
	var pageUrl = url ;
	if (null != xslDropDownID) {
		var styleSheetName = document.getElementById( xslDropDownID ).value;
		pageUrl+='&xsl=' + styleSheetName;
	}
	window.open(pageUrl,'new');
}
function ShowHideTip( SourceCtl, TipDivID )
{
	var div = document.getElementById( TipDivID );
	if ((div.style.visibility==null) || (div.style.visibility=="hidden"))
	{
		div.style.visibility = "visible";
	}
	else
	{
		div.style.visibility = "hidden";
	}
	var x = 0, y = 0;
	var obj = SourceCtl;
	while( obj != null )	{
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	obj = SourceCtl;
	while( obj != null )	{
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}	
	
	div.style.left = x;
	div.style.top = y + SourceCtl.offsetHeight;
}

function GotoExecPage( PageUrl, TextBoxID_OrderID, SysStepID )
{
	var txtOrderID = document.getElementById( TextBoxID_OrderID );
	
    var exp = /^\s*[-\+]?\d+\s*$/;
    if (txtOrderID.value.match(exp) == null) 
		return;
    else
    {
		var ID = parseInt( txtOrderID.value, 10);
	    if ( isNaN(ID) || (ID<=0))
			return;
		else
	    	document.location.href = PageUrl + "?Data=" + ID + "," + SysStepID;
    }
}

function AddSN( TextBoxID_Value, TextBoxID_CSString, DivID_SNs )
{
	var txtValue = document.getElementById( TextBoxID_Value );
	var txtCSS = document.getElementById( TextBoxID_CSString );
	var divSNs = document.getElementById( DivID_SNs );
	
	if ( txtValue.value == '' )
		return;
	if ( txtCSS.value == '' )
	{
		txtCSS.value = txtValue.value;
		divSNs.innerHTML = txtValue.value;
	}
	else
	{
		txtCSS.value = txtCSS.value + "\t" + txtValue.value;
		divSNs.innerHTML = txtValue.value + ", " + divSNs.innerHTML;
	}
	txtValue.value = '';
	txtValue.focus();
}

function RedirEnterKey( ActionButtonID )
{	
	if ( is.ie )
	{
		var btn = document.getElementById( ActionButtonID );
		if ( window.event.keyCode == 13)
		{
			if ( btn.click )
				btn.click();
			return false;
		}
	}
}

function ConvertToMoneyFormat( value, precision )
{
	if ( isNaN(parseFloat(value)))
		value = "0";

	var fMinus = false;
	if ( value < 0)
		fMinus = true;
	value = Math.abs(value);
	var valueFloat = parseFloat(value);
	var intPart = Math.floor( valueFloat );
	var decPart = value - intPart;
	for ( var i=0; i<precision; i++ )
		decPart *= 10;		
	decPart = Math.round(decPart) + '';
	
	for ( var i=decPart.length; i<precision; i++ )
		decPart = '0' + decPart;
	
	var retStr;
	if ( precision == 0 )
		retStr = intPart + parseInt(decPart);	
	else
		retStr = intPart + "." + decPart;
		
	if ( fMinus )
		return "-" + retStr;
	else
		return retStr;
}

function LocalToStdDecimal( value, LocalNumGroupSep, LocalNumDecimalSep )
{
	var StdGroupSep = "";
	var StdDecimalSep = ".";
	value = value + "";
	value = value.replace( LocalNumGroupSep, StdGroupSep );
	value = value.replace( LocalNumDecimalSep, StdDecimalSep );
	if ( isNaN(parseFloat(value)))
		return 0;
	else
		return parseFloat(value);
}
function StdToLocalDecimal( value, LocalNumGroupSep, LocalNumDecimalSep )
{
	var StdDecimalSep = ".";
	value = value + "";
	return value.replace( StdDecimalSep, LocalNumDecimalSep );
}

function RecalcCharges( MoneyPrecision, LocalNumGroupSep, LocalNumDecimalSep, TableID, Discounts, DiscountPcts, Taxes )
{	
	// MoneyPrecision - number of digits to the right of the decimal point (may differ from current locale currency format)
	// LocalNumGroupSep - group separator (thousands) used in numeric format of current locale
	// LocalNumDecimalSep - decimal separator used in numeric format of current locale	
	var total = 0;
	var tbl = document.getElementById( TableID );

	for ( var i=0; i<tbl.rows.length; i++ )
	{
		var row = tbl.rows[i];
		if ( row.cells[0].hasChildNodes())
		{
			var rowid = row.cells[0].childNodes.item(0).value;
			if ( rowid != null )
			{
				var txtPrice = document.getElementById('txt_Price' + rowid);
				var txtQty = document.getElementById('txt_Qty' + rowid);
				var txtSubTotal = document.getElementById('txt_SubTotal' + rowid);
				
				if ((txtPrice !=null) && (txtQty !=null) && (txtSubTotal !=null))
				{
					var qty = LocalToStdDecimal(txtQty.value, LocalNumGroupSep, LocalNumDecimalSep );
					var price = LocalToStdDecimal(txtPrice.value, LocalNumGroupSep, LocalNumDecimalSep );
					var subtotal = qty * price;
					//txtSubTotal.value = StdToLocalDecimal(ConvertToMoneyFormat( subtotal, MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
					total += subtotal;

					txtPrice.value = StdToLocalDecimal( ConvertToMoneyFormat( price, MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
					txtSubTotal.value = StdToLocalDecimal( ConvertToMoneyFormat( subtotal, MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
				}
			}
		}
	}
	document.getElementById('txt_Total1').value = StdToLocalDecimal( ConvertToMoneyFormat(total,MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
	
	// calculate sub-total after discounts
	if ( Discounts > 0)
	{
		var pcts = DiscountPcts.split( "," );
		for ( var i=0; i<Discounts; i++ )
		{
			var txt = document.getElementById('txt_Discount' + i);
			var txt_pct = document.getElementById('txt_Discount_Pct' + i);
			
			var pct = "";
			if ( txt_pct == null )
				pct = pcts[i];
			else
			{
				txt_pct.value = StdToLocalDecimal( ConvertToMoneyFormat(txt_pct.value,MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
				pct = txt_pct.value;
			}
			
			if ( pct == "" )
			{
				total = total - LocalToStdDecimal( txt.value, LocalNumGroupSep, LocalNumDecimalSep );
				txt.value = StdToLocalDecimal( ConvertToMoneyFormat(txt.value,MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
			}
			else
			{
				pct = total * parseFloat(pct) / 100;
				txt.value = StdToLocalDecimal( ConvertToMoneyFormat( pct, MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
				total -= pct;
			}
		}
		document.getElementById('txt_Total2').value = StdToLocalDecimal( ConvertToMoneyFormat(total,MoneyPrecision ), LocalNumGroupSep, LocalNumDecimalSep );
	}
	
	// recalculate the taxes
	if ( Taxes != "" )
	{
		var taxes = Taxes.split( "," );
		for ( var i=0; i<taxes.length; i++ )
			if ( taxes[i] != "" )
			{
				var tax = total * parseFloat(taxes[i]) / 100;
				var txt = document.getElementById('txt_Tax' + i);			
				txt.value = StdToLocalDecimal( ConvertToMoneyFormat( tax, MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
				total += tax;
			}
	}
	document.getElementById('txt_Total3').value = StdToLocalDecimal( ConvertToMoneyFormat( total, MoneyPrecision), LocalNumGroupSep, LocalNumDecimalSep );
}

function OpenHelp( Path, SourcePageRaw, SourcePagePath )
{
	window.open( Path + '?SourceUrl=' + SourcePageRaw + '&SourcePath=' + SourcePagePath,
		'', 'location=no,resizable=yes,scrollbars=yes,titlebar=yes');
}

function SwapHelpEditMode( btnEdit, EditDivID, textEditMode, textViewMode )
{
	var divID = document.getElementById( EditDivID );
	if ( divID.style.display == "block" )
	{
		divID.style.display = "none";
		btnEdit.value = textEditMode;
		btnEdit.className = 'WebControl';
		document.getElementById('btnSysPreview').style.visibility = 'hidden';
		document.getElementById('btnSysSave').style.visibility = 'hidden';
	}
	else
	{
		divID.style.display = "block";
		btnEdit.value = textViewMode;
		btnEdit.className = 'WebControl';
		document.getElementById('btnSysPreview').style.visibility = 'visible';
		document.getElementById('btnSysSave').style.visibility = 'visible';
	}
}

function StepExecNotif_ValidateParamValue( source, args )
{
	if ( args.Value.indexOf( '"' ) == -1)
		args.IsValid = true;
	else
		args.IsValid = false;
}

function ShowHideItemUrls( lblUrlsID )
{
	var lblUrls = document.getElementById( lblUrlsID );
	var div = document.getElementById( 'divUrls' );
	if ((div.style.visibility==null) || (div.style.visibility=="hidden"))
	{
		var x = 0, y = 0;
		var obj = lblUrls;
		while( obj != null )	{
			x += obj.offsetLeft;
			obj = obj.offsetParent;
		}
		obj = lblUrls;
		while( obj != null )	{
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
		
		div.style.left = x;
		div.style.top = y + lblUrls.offsetHeight + 2;
		div.style.visibility = "visible";
		
		if ( is.ieMac )
		{
			div.style.top = parseInt(div.style.top,10) + 14;
		}
	}
	else
		div.style.visibility = "hidden";
}

function OnPrintClick( btnSource )
{
	if ( window.print )
		window.print();
	else
		alert( 'Press Command+P to print this page' );
	return false;
}

function LocationLookup_ShowTab( tabID_Active, tabID_Inactive, divID_Active, divID_Inactive )
{
	var tabActive = document.getElementById( tabID_Active );
	var tabInactive = document.getElementById( tabID_Inactive );
	var divActive = document.getElementById( divID_Active );
	var divInactive = document.getElementById( divID_Inactive );
	
	tabActive.className = 'ActiveTab';
	tabInactive.className = 'InactiveTab';
	divActive.style.display = 'block';
	divInactive.style.display = "none";
}


function OpenTagLookup( Path, TextBoxID_ForTagName, TextBoxID_ForPartNum, DropDownID_ForTagTypeID )
{
	var ddl = document.getElementById(DropDownID_ForTagTypeID);
	var typeId;
	if (ddl)
		typeId = ddl.options[ddl.selectedIndex].value;
	else
		typeId = 0;
	m_PopupWindow = window.open( Path + '?TypeID=' + typeId +
		'&ResultFormName=' + document.forms[0].name + 
		'&TextBoxID_ForTagName=' + TextBoxID_ForTagName + 
		'&TextBoxID_ForPartNum=' + TextBoxID_ForPartNum + 
		'&DropDownID_ForTagTypeID=' + DropDownID_ForTagTypeID,
		'Tags', 
		'width=440,height=440,left=220,top=150');
	m_PopupWindow.focus();
}

function SetFoundTagData( ResultFormName, TextBoxID_ForTagName, TextBoxID_ForPartNum, 
		DropDownID_ForTagTypeID, SelectedTagName, SelectedPartNum, SelectedTagTypeID )
{
	eval('var theform = document.' + ResultFormName + ';');
	if ( m_PopupWindow == null)
		window.self.close();
	else
		m_PopupWindow.close();
		
	if ( TextBoxID_ForTagName != '' ) {
		theform.elements[TextBoxID_ForTagName].value = SelectedTagName;
		if(SelectedTagName != '') {
			if(TextBoxID_ForTagName == 'txtTag')
				if(document.getElementById('ReqValTag'))
					document.getElementById('ReqValTag').style.display = 'none';
			else
				if(document.getElementById('ReqValToTag'))
					document.getElementById('ReqValToTag').style.display = 'none';
		}
	}
	if ((TextBoxID_ForPartNum != '') && (SelectedPartNum != '')) {
		theform.elements[TextBoxID_ForPartNum].value = SelectedPartNum;
		if(document.getElementById('ReqValItem'))
			document.getElementById('ReqValItem').style.display = 'none';
	}
	if ( DropDownID_ForTagTypeID != '' )
		theform.elements[DropDownID_ForTagTypeID].value = SelectedTagTypeID;
}

function TagTransaction_OnTransTypeClick( ddlTrans, TransferTypeID, tblToTagId, lblFromTagId, lblToTagId, tagText, fromTagText, toTagText, reqValID )
{
	var tblToTag = document.getElementById( tblToTagId );
	var lblFromTag = document.getElementById( lblFromTagId );
	var lblToTag = document.getElementById( lblToTagId );
	var val = document.getElementById( reqValID );
	
	if ( ddlTrans.value == TransferTypeID )
	{
		tblToTag.style.display = 'block';
		lblToTag.style.display = 'block';
		lblFromTag.innerHTML = fromTagText;
		lblToTag.innerHTML = toTagText;
		if ( is.ie )
		{
			ValidatorEnable( val, true );
			val.style.display = 'none';
		}
	}
	else
	{
		tblToTag.style.display = 'none';
		lblToTag.style.display = 'none';
		lblFromTag.innerHTML = tagText;
		if ( is.ie )
		{
			ValidatorEnable( val, false );
		}
	}
}

function setFilterCookie(value) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+365);
  document.cookie = "ProgramFilter="+escape(value)+"; path=/; expires="+exdate.toGMTString();
}

function getFilterCookie() {
  if(document.cookie.length>0) { 
	cstart=document.cookie.indexOf("ProgramFilter=");
	if(cstart!=-1) { 
	  cstart=cstart + 14; 
	  cend=document.cookie.indexOf(";",cstart);
	  if (cend==-1) cend=document.cookie.length;
	  return unescape(document.cookie.substring(cstart,cend))
	} 
  }
  return "";
}

function validateDate(id){
var datePat=/^(0?[1-9]|1[012]|[1-9])\/(0?[1-9]|[12][0-9]|3[01])\/(19|20)\d\d$/;
var v=trim($(id).value);
if((''!=v)&&!datePat.test(v))return false;
else if((''!=v)&&!isValidDate(v))return false;
return true;
}
function isValidDate(v){
var ar=v.split('/');
var da=dateObj(v);
return ((ar[1]==da.getDate())&&(ar[0]-1==da.getMonth())&&(ar[2]==da.getFullYear()));
}
function dateObj(v){var ar=v.split('/');return (new Date(ar[2],ar[0]-1,ar[1]));}
function compareDate(fv,tv){if(''!=fv&&''!=tv){if(dateObj(fv)>dateObj(tv))return false;}return true;}

function trim(stringToTrim){return stringToTrim.replace(/^\s+|\s+$/g,"");}

function $(i){return document.getElementById(i);}

var JSON=function(){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},s={'boolean':function(x){return String(x);},number:function(x){return isFinite(x)?String(x):'null';},string:function(x){if(/["\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c;}
c=b.charCodeAt();return'\\u00'+
Math.floor(c/16).toString(16)+
(c%16).toString(16);});}
return'"'+x+'"';},object:function(x){if(x){var a=[],b,f,i,l,v;if(x instanceof Array){a[0]='[';l=x.length;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a[a.length]=v;b=true;}}}
a[a.length]=']';}else if(x instanceof Object){a[0]='{';for(i in x){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a.push(s.string(i),':',v);b=true;}}}
a[a.length]='}';}else{return;}
return a.join('');}
return'null';}};return{copyright:'(c)2005 JSON.org',license:'http://www.JSON.org/license.html',stringify:function(v){var f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){return v;}}
return null;},parse:function(text){try{return!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g,'')))&&eval('('+text+')');}catch(e){return false;}}};}();

String.prototype.ltrim =function(){return this.replace(/^\s\s*/,"");}
String.prototype.rtrim =function(){return this.replace(/\s\s*$/,"");}
String.prototype.trim =function(){return this.ltrim().rtrim();}

function ShowMsg(ctlId,errMsg){alert(errMsg);$(ctlId).focus();return false;}
function disableElementByName(name,bflag){var arrElems=document.getElementsByName(name);for(var i=0;i<arrElems.length;i++)arrElems[i].disabled=bflag;}