//listFunctions.js

var sMsgPage = "frmmessage.aspx";
var lOrderUpdate = 0;
var arrCats = new Array();
var lLen = 0;

function Logout(sURL)
{
	if(parent.frmTop)
		var oForm = parent.frmTop.document.getElementById("ocartForm")
	else
		var oForm = parent.parent.frmTop.document.getElementById("ocartForm")
	oForm.bLogout.value = 0;
	var bNavigate = UpdateCartQty(1,0,'');
		
	var bConfirm=true;
	var orderId = GetOrderEditCookie();
	if (bCancelEdit=='True' && orderId!="")
	{
		bConfirm = window.confirm("You have an order edit in progress. Clicking Ok will cancel the edit and remove all items from the cart.\n\nPress OK to Continue, or Cancel to stay on the current page.")		
		if(bConfirm)
		{
			ClearOrderInfo();
			// Send request to remove all items		
			parent.frmMessage.location = sMsgPage + "?orderId=" + orderId + "&act=9&" + getFrameworkParameters();				
			// Update the values in the frame and xml
			UpdateCart(0,0,0,true);
		}		
	}	
	
	//If there weren't any items we just navigate to the URL
	if(bNavigate && bConfirm)	
	try
	{	
		parent.parent.document.location = sURL;
		parent.frmMessage.location = sMsgPage + "?bClearAll=1&" + getFrameworkParameters();	//Changes by Z.S. 07/16/2007
	}
	catch(err1)
	{		
	}
}

function CalcPar(lProdID,lQty,cPrice,bCW,cCWAverage,lCasePackQty)
{
	var oQty = eval("document.formProduct.Q_" + lProdID);
	var oInv = eval("document.formProduct.oInv_" + lProdID);
	var oPar = eval("document.formProduct.oPar_" + lProdID);
	// Fractional par implementation (applies to all)
	if(ValidateFloat(oInv,false,true,99999.00))
	{
		if(oPar.value != "" && (parseFloat(oPar.value) > 0.00))
		{
			if(oInv.value != "")
			{
				var fInv = parseFloat(oInv.value);
				var fPar = parseFloat(oPar.value);
				if(fInv < fPar)
				{
					var lNewQty = Math.ceil(fPar - fInv);
					oQty.value = lNewQty;
				}
				else
					oQty.value = "0";
				LogQtyChange(oQty,false,true,lQty,cPrice,bCW,cCWAverage,lCasePackQty,false);
			}
		}
	}
}

function MoveQty(bRemove,lPid,lQty,cPrice,bCW,cCWAverage,lCasePackQty)
{
	// grab frmTop
	if(parent.frmTop)
		var oFrame = parent.frmTop;
	else
		var oFrame = parent.parent.frmTop;
	// if we are on Par-level edit view then we don't update
	// the cart...
	if(document.formProduct.bParLevels)
		var bUpdateCart = (document.formProduct.bParLevels.value != "1");
	else
		var bUpdateCart = true;

	if(lPid) {
		// This section does individual adds/removes
		if (bRemove) {
			var oQty = eval("document.formProduct.Q_" + lPid);
			// Set only the list qty for this productID to 0
			if(oQty.value.length > 0) {
				var lTemp = oQty.value;
				oQty.value = 0;
				//Update the cart for every change (the third parameter is true)
				LogQtyChange(oQty,false,bUpdateCart,lTemp,cPrice, bCW, cCWAverage, lCasePackQty);
			}
		} else {
			var oQty = eval("document.formProduct.Q_" + lPid);
			// Move only the list qty for this productID
			if(oQty.value.length == 0) {
				oQty.value = lQty;
				var lTemp = 0;
			} else {
				var lTemp = oQty.value;
				oQty.value = lQty;
			}
			//Update the cart for every change (the third parameter is true)
			LogQtyChange(oQty,false,bUpdateCart,lTemp,cPrice, bCW, cCWAverage, lCasePackQty);
		}
	} else {
		// For adding/removing the entire list
		var oForm     = null;
		var bList     = false;
		var oFormProd = document.formProduct;
		var lSortID;
		var lParValue;

		// Grab the right form (this is used on a couple of pages)
		if(document.formList) {
			oForm = document.formList;
			bList = true;
			oForm.lListID.disabled = true;
		} else {
			// lastReceipt.aspx
			oForm = document.formProduct;
			oForm.lRecID.disabled = true;
		}
		// Set the correct message based on whether we are removing or adding
		if(document.formProduct.bParLevels) {
			var sMsg = bRemove ? 'Removing values from par list' : 'Adding default values to par list';
		} else {
			var sMsg = bRemove ? 'Removing items from cart' : 'Adding items to cart';
		}
		// give the user processing feedback
		ToggleDotLabel(sMsg,true);
		if(oFormProd.lSortID) {
			lSortID = oFormProd.lSortID.value;
			oFormProd.lSortID.disabled = true;
		}
		if(oFormProd.lParDefault) {
			lParValue = oFormProd.lParDefault.value;
			oFormProd.lParDefault.disabled = true;
		} else {
			lParValue = 0;
		}
			
		if(bRemove) {
			var sRemove = "1";
		} else {
			var sRemove = "0";
		}
		// if we are adding/removing all to the cart we need to make
		// sure that there are no updates in the current client side
		// dom (Duenas) (BUG05139 - 01/13/05)
		oFrame.EraseCartDom(true);
		if(bList) {
			parent.frmMessage.location = sMsgPage + "?act=5&lListID=" + oForm.lListID.value + "&lSortID=" + lSortID + "&lParDefault=" + lParValue + "&bRemove=" + sRemove + "&" + getFrameworkParameters();
		} else {
			parent.frmMessage.location = sMsgPage + "?act=5&lRecID=" + oForm.lRecID.value + "&lSortID=" + lSortID + "&lParDefault=" + lParValue + "&bRemove=" + sRemove + "&" + getFrameworkParameters();;
		}
			
		if(oFormProd.lSortID) {
			oFormProd.lSortID.disabled = false;
		}
		if(oFormProd.lParDefault) {
			oFormProd.lParDefault.disabled = false;
		}
	}
}
//// Start Changes U.S.N
function MoveQtyReceiveOrder(bRemove,lPid,lQty,cPrice,lProdID)
{		
	if(lPid) 
	{
		// This section does individual adds/removes
		if (bRemove) 
		{			
			var oQty = eval("document.formReceive.Q_" + lPid.substring(lPid.indexOf("_")+1));
			// Set only the list qty for this productID to 0
			if(oQty.value != null) 
			{
				if(oQty.value.length > 0) 
				{
					//var lTemp = oQty.value;
					oQty.value = 0;
					//Update the cart for every change (the third parameter is true)
					//LogQtyChange(oQty,false,bUpdateCart,lTemp,cPrice, bCW, cCWAverage, lCasePackQty);
				}
			}
			else
			{
				oQty.value = 0;
			}
		} 
		else 
		{
			var oQty = eval("document.formReceive.Q_" + lPid.substring(lPid.indexOf("_")+1));
			// Move only the list qty for this productID
			if(oQty.value != null) 
			{
				if(oQty.value.length == 0) 
				{
					oQty.value = lQty;
					//var lTemp = 0;
				} 
				else 
				{
					//var lTemp = oQty.value;
					oQty.value = lQty;
				}
			}
			else 
			{
				oQty.value = 0;
			}
		}
			//Update the cart for every change (the third parameter is true)
			//LogQtyChange(oQty,false,bUpdateCart,lTemp,cPrice, bCW, cCWAverage, lCasePackQty);
	}
else 
	{
		var oForm = document.formReceive;
		var table = document.getElementById("mainTable");
		var rows = table.getElementsByTagName("TR");
		var arr=lProdID.split("|");
		if(!bRemove)
		{
			var arrQty=lQty.split("|");
		}
		for(iCnt=0;iCnt<arr.length;iCnt++)
		{
			//var oQty = eval("document.formReceive." + arr[iCnt]);
			//alert("qty" + oQty.value);
			if(bRemove)
			{				
				var oQty = eval("document.formReceive." + arr[iCnt]);
				if(oQty.value.length > 0) 
				{				
					oQty.value = 0;				
				}
			}
			else
			{
				var oQty = eval("document.formReceive." + arr[iCnt]);			
				if(oQty.value.length == 0) 
				{
					oQty.value = arrQty[iCnt];				
				} else 
				{				
				oQty.value = arrQty[iCnt];
				}
			}
		}
		/*for(iCnt=1;iCnt<=rows.length;iCnt++)
		{
			var itm = document.getElementById("R_"+iCnt);
			itm.
			var oQty = eval("document.formReceive.Q_" + arr[iCnt]);
			alert("qty" + oQty);
			if(bRemove)
			{				
				var oQty = eval("document.formReceive.Q_" + lPid);
				if(oQty.value.length > 0) 
				{				
					oQty.value = 0;				
				}
			}
			else
			{
				var oQty = eval("document.formReceive.Q_" + lPid);			
				if(oQty.value.length == 0) 
				{
					oQty.value = lQty;				
				} else 
				{				
				oQty.value = lQty;
				}
			}	
		}*/
		
	}
}
//// End Changes by Amphire Team on 10/03/2006
function RemoveAll(bUseCart)
{
	var sUrl = sMsgPage + "?act=9";
	if(bUseCart)
	{
		if(parent.frmTop)
			var oFrame = parent.frmTop;
		else
			var oFrame = parent.parent.frmTop;
		// Clear the page
		parent.frmMain.document.body.innerHTML = "";
		// Send request to remove all items
		parent.frmMessage.location = sMsgPage + "?act=9&" + getFrameworkParameters();
		// Update the values in the frame and xml
		UpdateCart(0,0,0,true);
		// Because we are updating the cart with 0's we clear the cart dom
		oFrame.EraseCartDom(true);

		// Set delay so the removal of items has time to process before viewing the cart
		setTimeout("parent.frmMain.location = 'cart.aspx?" + getFrameworkParameters() + "';", 500);
	}
	else
	{
		parent.frmMessage.location = sMsgPage + "?act=10&lid=" + GetListID() + "&" + getFrameworkParameters();
		setTimeout("parent.frmMain.location = 'list.aspx?lid=" + lListID + "&" + getFrameworkParameters() + "';", 500);
	}
}

function LoadItems()
//reloads custom pop-up with selected categoryID/ListID in the QS
{
	var oCategory = document.formCats.lCategoryID;
	var lCategoryID = oCategory.options[oCategory.selectedIndex].value	
	var oItem = document.formCats.sItem;
	var sItem = oItem.options[oItem.selectedIndex].value
	var sAct = document.formCats.act.value;
	var lListID = document.formCats.lListID.value;
	var sReturn= document.formCats.sReturn.value;
	
	document.location =  "customguidepopup.aspx?act=" + sAct + '&lListID=' + lListID + '&lCategoryID=' + lCategoryID + '&sItemID=' + sItem + '&sReturn=' + sReturn + '&' + getFrameworkParameters();
}

function ListLink(iType)
{
	var lListID = GetListID()
	if(lListID == "-2")
		alert("The \"Last Order\" template is special and may not be customized");
	else if(lListID == "0")
		alert("Select a template that you would like to customize")
	else
	{	
		//disable the select box
		document.getElementById("lListID").disabled = false;
		var sReturn = "";
		if(document.getElementById("sReturn"))
		{
			sReturn = document.getElementById("sReturn").value
		}
		//Hide the control
		if (document.getElementById("DataControl"))
			document.getElementById("DataControl").style.display = 'none';
		if (iType == '1' )
		{
			parent.frmMain.location = "customtemplatedandd.aspx?lListID=" + GetListID() + "&sReturn=" + sReturn + "&" + getFrameworkParameters();
		}
		else if (iType == '2' )
		{	
			parent.frmMain.location = "customtemplate.aspx?lListID=" + GetListID() + "&sReturn=" + sReturn + "&" + getFrameworkParameters();
		}
	}
}

function GetListID()
{
	var oList = document.formList.lListID;
	//Check to see if we are using an updateable order
	if(document.formProduct && document.formProduct.updateRecID)
	{
		lOrderUpdate = 1;	
		return document.formProduct.updateRecID.value;
	}
	else
	{
		if(oList)
			return oList.options[oList.selectedIndex].value;		
	}
}

function RenameList()
{
	oErrors			= new Array
	lCount			= 0;
	var lListID        = GetListID();
	var LastOrderListID = "-2";
	
	if(lListID == LastOrderListID)
		alert("The \"Last Order\" template is special and cannot be renamed");
	else if(lListID == "0")
		alert("Please select a template before trying to rename");
	else
	{
		var sListName = window.prompt("Please enter a new name for your current list", "");
		if(sListName == "Last Order")
			alert("\"Last Order\" is a reserved template name.  Please enter a different name for this template");
		else if(sListName != null)
		{
			var maxListNameLen = 50;
			var oIllegalChars  = new Array("#","%");			
	               
			// validate the name
			if (ValidString(sListName, "You did not enter a new name for the list, please try again"))
				if(ValidLen(sListName, 1, maxListNameLen, "The name you have entered is over " + maxListNameLen + " characters, please try again"))
					if (sListName.indexOf(oIllegalChars[0]) > 0 || sListName.indexOf(oIllegalChars[1]) > 0)
						oErrors[lCount] = "You have used an illegal character, either " + oIllegalChars[0] + " or " + oIllegalChars[1] + ", in your name.  Please try again.";
						
			if(!ShowErrors())
			{
				var lListID = GetListID();
				var arrOption = new Array();
				arrOption[0] = new Option(sListName);
				arrOption[0].value = lListID;

				parent.frmMessage.location = sMsgPage + "?act=15&lid=" + lListID + "&ln=" + URLEncode(sListName) + "&" + getFrameworkParameters();
				// Replace existing name with new name in select box
				var oList = document.formList.lListID;
				for(var i=0;i<oList.options.length;i++)
					if(oList.options[i].value == lListID)
					{
						oList.options[i] = arrOption[0];
						oList.options[i].selected = true;	
					}
			}
		}
	}
}

function SaveAsList()
{
	// Make sure they have items in the cart first
	var bNS = (window.Event) ? 1 : 0;
	if(parent.frames.frmTop.document.getElementById("lItems").innerHTML == "0")
		alert("There are no items to create a template from");
	else
		PopUpWin("/access/listsave.aspx" + "?" + getFrameworkParameters(), 400, 200);
}

function DeleteList()
{
	var lListID = GetListID()
	if(lListID == "-2")
		alert("The \"Last Order\" template is special and cannot be deleted");
	else if(lListID == "0")
		alert("Please select a template before trying to delete");
	else if(lDefaultList == lListID)
		alert("The template you are attempting to delete is currently your\ndefault template. You cannot delete this template, unless\n you change the current setting in the preferences section.")
	else
	{
		var arrOption = new Array();
		// Default list always specified by a listID of 2
		var bDelete = window.confirm("Are you sure you would like to delete the selected template?\nPress \"OK\" to delete.")
		if(bDelete)
		{
			parent.frmMessage.location = sMsgPage + "?act=14&lid=" + lListID + '&' + getFrameworkParameters();
			document.location = 'list.aspx?lid=2' + '&' + getFrameworkParameters();
		}
	}
}

function Download(lListID)
{
	if(GetListID() == "0")
		alert("Please select a template before trying to download");
	else
	{
		if(document.formProduct.lListCount)
			var bEmpty = 0;
		else
			var bEmpty = 1;
		// don't allow them to download an empty list
		if(bEmpty == 1) {
			alert("This list is empty.  An empty list cannot be downloaded.");
		} else {
			document.location = "/access/report.aspx?lReportType=3&lListID=" + lListID + "&bEmpty=" + bEmpty + '&' + getFrameworkParameters();
		}
	}
}

function FillQty(oCB, lPID)
{
	var oQty = eval("document.formProduct.Q_" + lPID);
	if(oCB.checked && oQty.value == "")
		oQty.value = "1";
	else if(!oCB.checked)
		oQty.value = "";	
}

function AddSpecial(oButton)
{
	var oForm = document.frmAds
	var lPID = oButton.name
	var lQty = eval("oForm.p_" + lPID + ".value");
	var lCID = eval("oForm.lCID" + lPID + ".value")
	//the parent here might need to be parent.parent for orderguide....test this
	if (lQty > 0)
		parent.frmMessage.location = sMsgPage + "?act=1&pid=" + lPID + "&qty=" + lQty + "&cid=" + lCID + "&" + getFrameworkParameters();
	else
		alert("You must enter a quanity for this product")
}

function SubmitLastReceipt()
{
	var bParEdit  = false;
	var bNavigate = true;
	var oForm = document.formProduct;
	var sURL = "lastreceipt.aspx?lRecID=" + oForm.lRecID.value;
	// Disable it so they can't click again
	oForm.lRecID.disabled = true;
	if(oForm.lCurrentParLevelID.value == "")
	{
		if(oForm.lParDefault)
			sURL += "&lParDefault=" + oForm.lParDefault.value;	
	}
	else
	{
		sURL += "&lParDefault=" + oForm.lCurrentParLevelID.value;
	}
	if(oForm.lSortID)
		sURL += "&lSortID=" + oForm.lSortID.value;
	
	// Check if par-levels were updated
	if(oForm.bParLevels)
	{
		bParEdit = true;
		SetParLevelID(oForm,oForm.lParDefault);
	}	
	document.body.innerHTML = "";
	// Update the (parlevels)
	bNavigate = UpdateCartQty(0,0,sURL,bParEdit);
	if(bNavigate)	
		parent.frames.frmMain.location = sURL + "&" + getFrameworkParameters();
}

function ViewList() 
{
	var sSortQS   = "";
	var sParQS    = "";
	var bNavigate = true;
	var bParEdit  = false;
	var oForm 	= document.formProduct
	if(document.formProduct.lSortID) {
		var oSortID = document.formProduct.lSortID;
	}
	if(document.formProduct.lParDefault) {
		var oParID  = document.formProduct.lParDefault;
	}	
	var oListID = document.formList.lListID;

	//Sometimes with a new login the sort selectbox doesn't exist, if so don't append (preferences will default it)
	if (oSortID && oSortID.length) {
		sSortQS = "&lSortID=" + oSortID.options[oSortID.selectedIndex].value;
	} else {
		sSortQS = "";
	}
	// Par info
	if (oParID && oParID.length) {
		sParQS = "&lParDefault=" + oParID.options[oParID.selectedIndex].value;
	} else {
		if(oForm.lCurrentParLevelID) {
			sParQS = "&lParDefault=" + oForm.lCurrentParLevelID.value;
		}
	}
	// Disable the combo
	if(oListID)
		oListID.disabled = true;
		
	// Check if par-levels were updated
	if(oForm.bParLevels) {
		bParEdit = true;
		SetParLevelID(oForm,oParID);
	}
	
	var sURL = "list.aspx?lid=" + GetListID() + sSortQS + sParQS + "&" + getFrameworkParameters();
	// Clear the document body
	document.body.innerHTML = "";		
	bNavigate = UpdateCartQty(0,0,sURL,bParEdit);
	if(bNavigate)
		parent.frmMain.location = sURL;
}
function getPricesRepost()
{
	var bParEdit  = false;
	var sTarget   = "";
	var bNavigate = true;
	var oForm     = document.formProduct;
	var oSort	  = oForm.lSortID;
	var oPar	  = oForm.lParDefault;

	// Grab all the form variables
	var sQueryStr = ScrapeForm(oForm);
	//Only disable if the value is a parlist id..if new or delete, don't disable. BUG04139
	if (!isNaN(oPar.value))
	{
		if(oSort)
			oSort.disabled = true;
		if(oPar)
			oPar.disabled = true;
	}
	//End bug
	if(oForm.bParLevels){ 
		bParEdit = true;
		// There's a case where this is not passed in
		if(!oPar){
			if(parent.frames.browseSort)
				oPar = parent.frames.browseSort.document.formSort.lParDefault;
			else
				oPar = oForm.lParDefault;
		}
		SetParLevelID(oForm, oPar);
	}
	//Add the flag that this is a repost
	sQueryStr += '&bPricingCall=1;'
	// Build URL
	var sURL = oForm.action;
	if(sURL.indexOf("?") != -1)
	{
		// if there are parameters already then pass those too
		//sQueryStr = sURL.substring(sURL.indexOf("?"), sURL.length) + "&" + sQueryStr.substring(1,sQueryStr.length);
		sURL = sURL.substring(0,sURL.indexOf("?"));
		sURL += sQueryStr;
	}
	else
		sURL += sQueryStr;

	// *************************************************************
	// Update the browseMenu sort value
	var sLocation = new String(document.location);
	if(sLocation.indexOf("productlist.aspx") != -1)
	{
		sTarget = "&prodtarget=browseProd";
		if(parent.parent.browseMenu)
		{
			// This is for the standard catalog
			parent.parent.browseMenu.document.frmIDs.lSortID.value = lSortID;
			sURL += "&lSortID=" + lSortID;
			// Check this (par-levels may be turned off)
			if(oPar)
			{
				sURL += "&lParDefault=" + oPar.value;
			}
			else
			{
				if(oForm.lParDefault)
					sURL += "&lParDefault=" + oForm.lParDefault.value;
			}
		}
	}
	// Clear the form
	document.body.innerHTML = "";
	//correction for BUG3609 CF
	if (sLocation.indexOf('cart') != -1)
	{
		sURL = "/access/cart.aspx" + sURL;
	}
	//END BUG
	// This will return false if the message frame will take care of providing the sort 
	bNavigate = UpdateCartQty(0, 0, sURL + sTarget, bParEdit);
	// Submit the form to reflect the sort if there are no products to be added to the cart
	if(bNavigate)
	{
		if(parent.frames.browseProd)
			parent.frames.browseProd.location = sURL + sTarget + '&' + getFrameworkParameters();
		else
			document.location = sURL + sTarget + '&' + getFrameworkParameters();
	}
}
function ParSort(oPar, oSort)
{
	var sTarget   = "";
	var bNavigate = true;
	var sLocation = new String(document.location);
	var sPage     = "";
	var sURL      = ""
	var bParEdit  = false;	
	var lView     = oPar.value;
	//Disable the select box...BUG03835
	if(oSort)
		oSort.disabled = true;
	if(oPar)
		oPar.disabled = true;
	//End bug
	
	if(oSort)
		var lSortID = oSort.value;
	var oForm	  = document.formProduct;
	if(!IsValidParSelection(oPar, oForm.lCurrentParLevelID))
	{
		//Re-enable the sort and parlist dropdowns. bug04122
		if(oSort)
			oSort.disabled = false;
		if(oPar)
			oPar.disabled = false;
		return;
		
	}
	// For creating a new parlist
	if(oPar.value == "New")
	{
		if(oForm.lCurrentParLevelID.value == "")
			SetSelectBoxOption(oPar, "0");
		else
			SetSelectBoxOption(oPar, oForm.lCurrentParLevelID.value);
		PopUpWin('parlistpopup.aspx' + "?" + getFrameworkParameters(),300,150);
		return;
	}
	// For deleting a par list
	if(oPar.value == "Del")
	{
		// Reselect the previous par value;
		if(oForm.lCurrentParLevelID.value == "")
			SetSelectBoxOption(oPar, "0");
		else
			SetSelectBoxOption(oPar, oForm.lCurrentParLevelID.value);
		PopUpWin('parlistpopup.aspx?lAct=1' + "&" + getFrameworkParameters(),300,150);	
		return;
	}

	// scrape the variables off the form
	sQueryStr = ScrapeForm(oForm);
	
	if(oForm.bParLevels)
	{ 
		bParEdit = true;
		SetParLevelID(oForm,oPar);
	}
	
	// Grab page name (without querystring vars)	
	if(sLocation.indexOf("?") != -1)
		sPage = sLocation.substring(0,sLocation.indexOf("?"));
	else
		sPage = sLocation;
	
	// Create the URL
	sURL = sPage + sQueryStr;

	// *************************************************************
	// Update the browseMenu sort value
	var sLocation = new String(document.location);
	if(sLocation.indexOf("productlist.aspx") != -1)
	{
		sTarget = "&prodtarget=browseProd";
		if(parent.parent.browseMenu)
		{
			// This is for the standard catalog
			sURL +=  "&lSortID=" + lSortID;
			if(oPar)
			{
				if(parent.parent.browseMenu) {
					if(parent.parent.browseMenu.document.frmIDs) {
						parent.parent.browseMenu.document.frmIDs.lParView.value = oPar.value;
						sURL += "&lParDefault=" + oPar.value;
					}
				}
			}
		}
	}
	
	// Clear the form
	document.body.innerHTML = "";	

	// Update the cart before displaying the par values
	bNavigate = UpdateCartQty(0,0,sURL + sTarget, bParEdit);
	if(bNavigate)
	{
		if(parent.frames.browseProd)
			parent.frames.browseProd.location = sURL + sTarget + '&' + getFrameworkParameters();
		else
			document.location = sURL + sTarget + '&' + getFrameworkParameters();
	}
}

function SetParLevelID(oForm,oPar)
{
	if(oPar && oForm)
	{
		if(oForm.lCurrentParLevelID)
			sParListID = oForm.lCurrentParLevelID.value;
		else
			sParListID = '0';

		// First update the par-level edit form in frmTop		
		if(oForm.bParLevels)
		{
			// If we are editing we must have a value
			if(sParListID == '0')
				sParListID = oPar.value;
						
			// Update the browse Menu variable
			if(parent.parent.frames.frmTop)
				parent.parent.frames.frmTop.document.cartForm.lParDefault.value = sParListID;
			if(parent.parent.parent.frames.frmTop)
				parent.parent.parent.frames.frmTop.document.cartForm.lParDefault.value = sParListID;		
		}		
	}
}

function Sort(oSort, oPar)
{
	var bParEdit  = false;
	var sTarget   = "";
	var bNavigate = true;
	var lSortID   = oSort.value;
	var oForm     = document.formProduct;
	
	// Grab all the form variables
	var sQueryStr = ScrapeForm(oForm);
	//Disable the select box...BUG03835
	if(oSort)
		oSort.disabled = true;
	if(oPar)
		oPar.disabled = true;
	//End bug
	if(oForm.bParLevels)
	{ 
		bParEdit = true;
		// There's a case where this is not passed in
		if(!oPar)
		{
			if(parent.frames.browseSort)
				oPar = parent.frames.browseSort.document.formSort.lParDefault;
			else
				oPar = oForm.lParDefault;
		}
		SetParLevelID(oForm, oPar);
	}
	
	// Build URL
	var sURL = oForm.action;
	if(sURL.indexOf("?") != -1)
	{
		// if there are parameters already then pass those too
		//sQueryStr = sURL.substring(sURL.indexOf("?"), sURL.length) + "&" + sQueryStr.substring(1,sQueryStr.length);
		sURL = sURL.substring(0,sURL.indexOf("?"));
		sURL += sQueryStr;
	}
	else
		sURL += sQueryStr;

	// *************************************************************
	// Update the browseMenu sort value
	var sLocation = new String(document.location);
	if(sLocation.indexOf("productlist.aspx") != -1)
	{
		sTarget = "&prodtarget=browseProd";
		if(parent.parent.browseMenu)
		{
			// This is for the standard catalog
			if(parent.parent.browseMenu) {
				if(parent.parent.browseMenu.document.frmIDs) {
					if(parent.parent.browseMenu.document.frmIDs.lSortID) {
						parent.parent.browseMenu.document.frmIDs.lSortID.value = lSortID;
						sURL += "&lSortID=" + lSortID;
					}
				}
			}
			// Check this (par-levels may be turned off)
			if(oPar)
			{
				sURL += "&lParDefault=" + oPar.value;
			}
			else
			{
				if(oForm.lParDefault)
					sURL += "&lParDefault=" + oForm.lParDefault.value;
			}
		}
	}
	// Clear the form
	document.body.innerHTML = "";
	//correction for BUG3609 CF
	if (sLocation.indexOf('cart') != -1)
	{
		sURL = "/access/cart.aspx" + sURL;
	}
	//END BUG
	// This will return false if the message frame will take care of providing the sort 
	bNavigate = UpdateCartQty(0, 0, sURL + sTarget, bParEdit);
	// Submit the form to reflect the sort if there are no products to be added to the cart
	
	// Added by TH 3/13/2006 for BUG14364	
	var qsName = "sProductNoOfItemToReplace";
	var sProdToReplace = getQSValue(qsName,self.location.search);	
	if (sProdToReplace.length > -1)
	{
	   sURL += "&" + qsName + "=" + sProdToReplace;
	}
	// End section Added by TH 3/13/2006 for BUG14364	   
	var qsName = "ReplaceItemContext";
	var sReplaceItemContext = getQSValue(qsName,self.location.search);	
	if (sReplaceItemContext.length > -1)
	{
	   sURL += "&" + qsName + "=" + sReplaceItemContext;
	}
	// 
	if(bNavigate)
	{
		if(parent.frames.browseProd)
			parent.frames.browseProd.location = sURL + sTarget + '&' + getFrameworkParameters();
		else
			document.location = sURL + sTarget + '&' + getFrameworkParameters();
	}
}
function CheckPar(sQueryStr)
{
	if(sQueryStr.indexOf("lPrevPar=2") != -1 || sQueryStr.indexOf("bParLevels=1") != -1)
		return "2";
	if(sQueryStr.indexOf("lPrevPar=1") != -1)
		return "1";
	if(sQueryStr.indexOf("lPrevPar=0") != -1)
		return "0";
	return "";
}
// returns a query string with all form variables in it
function ScrapeForm(oForm)
{
	//declare variables
	
	var sName		= "";
	var sType		= "";
	var sValue		= "";
	var i           = 0;
	var sQueryStr   = "";
	
	if(!oForm) return;
	
	//process All elements
	for (i=0; i<oForm.elements.length; i++)
	{
		sName			= oForm.elements[i].name;
        sType			= oForm.elements[i].type;
        sValue			= oForm.elements[i].value;
        
        // Only process items other than the product list items (for the qty box)
		if(sName.indexOf("sListQty") == -1 && sName.indexOf("oPar") == -1)
		{
			switch(sType)
			{
				case "hidden":
					if(i==0 || sQueryStr.length == 0)
						sQueryStr = "?" + sName + "=" + escape(sValue);
					else
						sQueryStr += "&" + sName + "=" + escape(sValue);
					break;
				case "text":
					break;
				case "button":
					break;
				case "checkbox":
					break;	
				case "select-one":
					if(i==0 || sQueryStr.length == 0)
						sQueryStr = "?" + sName + "=" + escape(sValue);
					else
						sQueryStr += "&" + sName + "=" + escape(sValue);
					break;
				default:
					break;
			}
		}
	}
	return sQueryStr;
}
function UpdateCartQty(bCart, bAlert, sMainURL, bParLevels)
{
	var sPids		= "";
	var sQtys		= "";
	var sComma		= "";
	var sLocation   = "";
	var sVersion = window.navigator.userAgent;
	var sRev = sVersion.substring(sVersion.indexOf("MSIE") + 5, sVersion.indexOf(";", sVersion.indexOf("MSIE")));
	
	// Default return URL if not present
	if(!sMainURL)
		sMainURL = "";
	// The changes will either be on the browse 
	// main page or the page included with this script
	if(document.location.toString().length)
		sLocation = new String(document.location);
	else
		sLocation = "";
	
	if(sLocation.indexOf("browsetitle.aspx") != -1 || sLocation.indexOf("frametop.aspx") != -1)
	{
		var oFrame = parent.parent.frames.frmMain.frames.browseMain;
	}
	else
	{
		if(bNS)
			var oFrame = window.document;
		else
			var oFrame = window;
	}

	// Make sure we grab the topFrame
	if(parent.parent.frmTop)
		var ofrmTop = parent.parent.frames.frmTop;
	else
		var ofrmTop = parent.parent.parent.frames.frmTop;
	
		//for hiltons app
	if(!ofrmTop)
		var ofrmTop = parent.frames.frmTop;
		
	// Check the par-levels
	if(sRev.indexOf("5.0") == -1)
	{
		if(!bParLevels)
		{
			if(parent.frmMain && parent.frmMain.browseMain && parent.frmMain.browseMain.browseProd)
			{
				if(parent.frmMain.browseMain.browseProd.formProduct)
				{
					// grabbing the info off of the catalog browse/view frameset
					if(parent.frmMain.browseMain.browseProd.formProduct.bParLevels)
					{
						bParLevels = true;
						ofrmTop.document.cartForm.lParDefault.value = parent.frmMain.browseMain.browseProd.formProduct.lCurrentParLevelID.value;
					}
				}
			}
			else
			{
				// grabbing the info off of list or lastreceipt
				if(parent.frmMain && parent.frmMain.document.formProduct)
				{
					if(parent.frmMain.document.formProduct)
					{
						if(parent.frmMain.document.formProduct.bParLevels)
						{
							bParLevels = true;
							ofrmTop.document.cartForm.lParDefault.value = parent.frmMain.document.formProduct.lCurrentParLevelID.value;
						}
					}
				}
				else
				{
					if(document.formProduct)
					{
						if(document.formProduct.bParLevels)
						{
							if(ofrmTop) // Changes by S.D. on 11/01/2008
							{
								bParLevels = true;
								ofrmTop.document.cartForm.lParDefault.value = document.formProduct.lCurrentParLevelID.value;
							}
						}
					}
				}
			}
		}
	}	
	else
	{
		// IE 5.x specific checks
		if(document.formProduct)
		{
			if(document.formProduct.bParLevels)
			{
				if(ofrmTop)  // Changes by S.D. on 11/01/2008
				{
					bParLevels = true;
					ofrmTop.document.cartForm.lParDefault.value = document.formProduct.lCurrentParLevelID.value;
					sMainURL = "";
				}
			}
		}
	}	
		
	// This takes care of the (browse popup case, 
	// we don't need to update the cart here)	
	if(ofrmTop)
	{
		// Make sure we've got something to do (valid xml changes)
		if(ofrmTop.CartHasModifiedItems())
		{
			//Submit products for update
			if(bParLevels)
				ofrmTop.ChangeParLevels(sMainURL)
			else		
				ofrmTop.AddToCart(sMainURL);
				
			// Let caller know we are navigating to sMainURL 
			// to make sure updates are reflected
			if(sMainURL.length > 0) return false;
		}
		else
		{
			if (sMainURL.indexOf("exception") != -1) //BUG1337 if no changes to the cart values..just go to the link USually means they clicked the continue button on an exception
 			{
				document.location = sMainURL + '&' + getFrameworkParameters();
			}
			else
			{
				if(bAlert)
					alert("You have not modified any quantities");
				else
					// Let caller know they need to navigate if necessary
					return true;
			}
			
		}
	}
	// if they didn't return in one of the cases above
	// then they definitely need to nav
	return true;
}
function UpdateCart(cSubTotal, lItems, lPieces, bUpdate)
{
	var oFrame = parent.frmTop;
	if(!bUpdate)
	{
		// This updates from the global dom object
		oFrame.UpdateCartTotals();
	}
	else
	{
		// Now update the xml cart
		oFrame.ModifyCartTotals(cSubTotal, lItems, lPieces);
		oFrame.UpdateCartTotals();
	}
}
//Start changes by Z.S 12/15/2006
function SelectItem(lProdID, lSubProdID, sProdNo, sSubProdNo, sParentQty, sParentComment, sReplaceItemContext, lBrowseID, bProdUnAble)
{
	//alert(top.opener.name);			
	if (bProdUnAble == true)
	{
		alert('Product is not available');
		return;
	}
	//End changes by Z.S 12/15/2006
	if (sProdNo == '')
	{
		//alert("if sProdNo = ''");
		AddSub(lProdID, lSubProdID, sProdNo, sSubProdNo, sParentQty, sParentComment, sReplaceItemContext, lBrowseID);	
	}
	else
	{
		if (sProdNo.substring(0,3) == 'Sub')
		{	
			//alert("if sProdNo.substring");
			var sValues;
			sValues = 'replaceItemPopup.aspx';
			sValues += '?lProdID=' + lProdID;
			sValues += '&lSubProdID=' + lSubProdID;
			sValues += '&sProdNo=' + sProdNo;
			sValues += '&sSubProdNo=' + sSubProdNo;
			sValues += '&lBrowseID=' + lBrowseID;
			if (document.getElementById("lListID"))
			{
				if (document.getElementById("lListID").value !='')
					sValues += '&lListID=' + document.getElementById("lListID").value;
			}
			sValues += '&lParentQty=' + sParentQty;
			sValues += '&lParentComment=' + sParentComment;
			sValues += '&ReplaceItemContext=' + sReplaceItemContext;	
			sValues += "&bAddItem=1";
			sValues += "&" + getFrameworkParameters();
			window.document.location = sValues;
		}
		else
		{
			AddSub(lProdID, lSubProdID, sProdNo, sSubProdNo, sParentQty, sParentComment, sReplaceItemContext, lBrowseID);	
		}
	}		
	//top.close();
}
//Start Changes U.S.N
function CloseWin()
{
	window.opener.location = parent.window.opener.location;
	window.close();
}
//End Changes U.S.N
//Start changes by Z.S. 09/12/2007
function 
AddWorksheetItem(lProdID, sProdNo, sSubProdNo, sWrkshtCatId, sWorksheetId, sSnapshotId,lBrowseID)
{
	var sValues;
	sValues = 'replaceItemPopup.aspx';
	sValues += '?lProdID=' + lProdID;
	sValues += '&sProdNo=' + sProdNo;
	sValues += '&sSubProdNo=' + sSubProdNo;
	sValues += '&lBrowseID=' + lBrowseID;
	if (document.getElementById("lListID"))
	{
		if (document.getElementById("lListID").value !='')
			sValues += '&lListID=' + document.getElementById("lListID").value;
	}	
	//Start Changes S.D. 12/21/2007
	if (document.getElementById("bEditFlag"))
	{
		sValues += '&bEditFlag=' + document.getElementById("bEditFlag").value;
	}
	sValues += '&sWrkshtCatId=' + sWrkshtCatId;
	sValues += '&sWorksheetId=' + sWorksheetId;
	sValues += '&sSnapshotId=' + sSnapshotId;
	sValues += "&" + getFrameworkParameters();
	setTimeout("PopUpWin('" + sValues + "',150,100);",100);	
}
//End changes by Z.S. 09/12/2007
function GetInvoice()
{
	oErrors			= new Array
	lCount			= 0;
	var oForm = document.formProduct
	ValidString(oForm.sInvoice.value, 'Please select a valid invoice number')
	if (oForm.sInvoice.value == 0)
		{
		oErrors[lCount] = "No invoice available for selection";
		lCount++;
		}
	if(!ShowErrors())
		//document.location = "/access/invoice.aspx?lSortID=" + oForm.lSortID.value + "&sInvoice=" + oForm.sInvoice.value + "&lInvoiceViewID=" + oForm.lInvoiceViewID.value + '&' + getFrameworkParameters(); //Start U.S.N 05/31/2007
		document.location = "/access/invoice.aspx?sInvoice=" + oForm.sInvoice.value + "&lInvoiceViewID=" + oForm.lInvoiceViewID.value + '&' + getFrameworkParameters();
		
} 

function ViewExtProdInfo(lProdID, bAd, bCommodity)
{ 
	PopUpWin("/access/extprodinfo.aspx?bAd=" + bAd + "&lProductID=" + lProdID + '&' + bCommodity +  '&' + getFrameworkParameters(), 600, 400) 
}

function ViewExtProdInfoXml(lProdID, bAd, bCommodity,lQtyOrdered, bRelated, commodityPrice)
{	
	if(!lQtyOrdered)
		lQtyOrdered = "";
	var url = "/access/extprodinfoxml.aspx?commodityPrice=" + commodityPrice + "&bAd=" + bAd + '&bCommodity=' + bCommodity + "&lProductID=" + lProdID + "&lOrdered=" + lQtyOrdered + "&bRelated=" + bRelated + "&" + getFrameworkParameters();
	var winl = (screen.width - 800) / 2;
	var wint = (screen.height - 600) / 2;
	winprops = 'height=600,width=800,top='+wint+',left='+winl+',scrollbars=1,resizable'
	win = window.open(url, "extinfo", winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function AddToCustomOG(lProdID, bShowPopup)
{
	var bNS = (window.Event) ? 1 : 0;
	
	// Get reference to message frame
	if(parent.parent.parent.frmMessage)
		// We are in the normal frameset
		var oForm = parent.parent.parent.frmMessage
	else
		// We are in the popup frame for selecting a substitute
		var oForm = opener.parent.parent.parent.frmMessage;
		
	if( bShowPopup )
		if(!bNS)
			// Popup the window to let them chose a category
			PopUpWin("customguidepopup.aspx?act=4&lProdID=" + lProdID + "&" + getFrameworkParameters(), 400, 220)	
		else
			PopUpWin("customguidepopup.aspx?act=4&lProdID=" + lProdID + "&" + getFrameworkParameters(), 450, 205)	
	else
		// Send the action to frmmessage.asp and give friendly message 
		parent.parent.parent.frmMessage.location = "frmmessage.aspx?act=4&lProdID=" + lProdID + "&" + getFrameworkParameters();
}

function AddToOrderTemplate(lProdID, bShowPopup)
{
	var bNS = (window.Event) ? 1 : 0;
	// Get reference to message frame
	if(parent.parent.parent.frmMessage)
		// We are in the normal frameset
		var oForm = parent.parent.parent.frmMessage
	else
		// We are in the popup frame for selecting a substitute
		var oForm = opener.parent.parent.parent.frmMessage;
		
	if (bShowPopup) //allow the user to select the list and category
		PopUpWin("templateaddpopup.aspx?lProdID=" + lProdID + "&" + getFrameworkParameters(), 400, 220);
		
	else //use default values stored in the cookies
	{
		//set from
		oForm = document.AddToDefaultTemplate;
		//set prodid that will be added to the template
		oForm.lProdID.value = lProdID;
		oForm.submit();
	}
}

function removeProduct(sProductNumber, lListType, lStatus, lProductID, sMessage)
{
	lViewID = 0;
	lListID = 0;
	if (document.getElementById('lViewID'))
		lViewID = document.getElementById('lViewID').value
	if (document.getElementById('lListID'))
		lListID = document.getElementById('lListID').value
	
	PopUpWin("removeItempopup.aspx?sProductNumber=" + sProductNumber + "&lProductID=" + lProductID + "&lListType=" + lListType + "&lListID=" + lListID + "&lStatus=" + lStatus + "&lViewID=" + lViewID + "&sMessage=" + escape(sMessage) + "&" + getFrameworkParameters(), 400, 220)

}

function refreshWindow()
{
	window.location = window.location;
}

function ProceedWithlistCopy(lSourceListID, lDestListID, sListName, sDestLogonID){
		parent.frmMessage.location = "/access/frmmessage.aspx?bApprove=1&act=39&lSourceListID=" + lSourceListID + "&lDestListID=" + lDestListID + "&sListName=" + sListName + "&sDestLogonID=" + sDestLogonID + "&" + getFrameworkParameters();	
	
}
function RemoveItemFromTemplate(sRow, sItem)
{
	var oForm = document.formList;
	var bConfirmRemove = false;
	var frmURL = "/access/frmmessage.aspx?act=34&lListID=" + oForm.lListID.value + "&sItems=" + sItem + ",&" + getFrameworkParameters() + "&lStartCat=0&lEndCat=1";
	var bConfirm = confirm("Are you sure you want to remove this item from the template? \n \n - Click Cancel to Abandon \n - Click OK to Remove");
	var itemCount = document.getElementById('lListCount').value
	if (bConfirm)
	{
		var r = document.getElementById("R_" + sRow);
		rClass = r.firstChild.className; //GLOBAL VALUE do not VAR
		//Hide the row
		r.style.display = "none";
		if (itemCount < 250)
		{
			//Fix the classes
			//debugger;
			if ( (itemCount/2) > Number(sRow))
			{
				while (r.previousSibling)
				{
					//move to next node
					r=r.previousSibling;
					//set class for row and all children
					ChangeTableRowColors(r)
				}	
			
			}
			else
			{
				while (r.nextSibling)
				{
					//move to next node
					r=r.nextSibling;
					//set class for row and all children
					ChangeTableRowColors(r)
				}	
			}
		}
		document.getElementById('lListCount').value = itemCount -1 
		//Post delete to message frame
		parent.frmMessage.location = frmURL;	
	}
}

function ChangeTableRowColors(r)
{
	//set class for row and all children
	if(r.id != "" && r.style.display != "none")
	{
		SetClassName(r, rClass);
		//Alternate color
		if(rClass == "ListItem")
		{
			rClass = "ListItemAlt"
		}
		else
		{
			rClass = "ListItem"
		}
	}

}

function SetClassName(obj, c)
{
	if (obj.nodeType == 1)
	{
		if (obj.childNodes != null)
		{
			for (var i=0; i < obj.childNodes.length; i++) 
			{ 
				if(obj.childNodes(i).className != null)
				{
					if(obj.childNodes(i).tagName.toLowerCase() == "td")
						obj.childNodes(i).className = c;
				}
				SetClassName(obj.childNodes.item(i), c); 
			}
		}
	}
}

//Start Changes S.D. 01/04/2007
function BuildCartReport()
{
	document.getElementById('TrImgCartid').style.display = "block";
	document.getElementById('TrAcctCartid').style.display = "block";
	window.print();
	document.getElementById('TrImgCartid').style.display = "none";
	document.getElementById('TrAcctCartid').style.display = "none";
}
//End Changes S.D.  01/04/2007
function DisplayUDP(sWrkshtCatId,sWorksheetId,sSnapshotId,lProdID,bEditFlag,SortObject) 
{	//Sort UDP Items U.S.N 12/14/2007
	var sWrkshtCatId =sWrkshtCatId;
	var sWorksheetId = sWorksheetId;
	var sSnapshotId =sSnapshotId;
	var lProdID	= lProdID;
	var bEditFlag = bEditFlag;
	var SortUDPID = SortObject.options[SortObject.selectedIndex].value;
	var sParams = "sWrkshtCatId=" + sWrkshtCatId + "&sWorksheetId=" + sWorksheetId + "&bEditFlag=" + bEditFlag;
	sParams = sParams + "&sSnapshotId=" + sSnapshotId + "&lProdID=" + lProdID + "&lBrowseID=105";
	sParams = sParams + "&sProductsource=UDP&SortUDPID=" + SortUDPID;
	setCookie("SortUDPID",SortUDPID); //Set the Sort Value in Cookie.
	//Setting the productlist parameters	
	parent.browseProd.document.location = "productlist.aspx?" + sParams + "&" + getFrameworkParameters();
	//Adding the lid and sproductsource to browseSort parameters
	var browseSortLocation = new String(parent.browseSort.document.location);
	var url = browseSortLocation.split('?');
	var i_array = url[1].split('&'); // Changes by V.G. 12/13/2007
	var newbrowselocation = new String();
	var ictr=0;
		
	while (ictr < i_array.length)
	{
		if ( i_array[ictr].indexOf("lBrowseID") == -1 )
		{
			if ( i_array[ictr].indexOf("sProductsource") == -1 )
			{
				if ( i_array[ictr].indexOf("lid") == -1 )
				{
					if (newbrowselocation==""){
						newbrowselocation = i_array[ictr];}
					else{
						newbrowselocation = newbrowselocation + "&" + i_array[ictr];}
				}
			}
		}
		ictr+=1;
	}
	parent.browseSort.document.location = url[0] + "?" + newbrowselocation + "&sProductsource=UDP&lBrowseID=105";	
}

//Start changes by S.D. on 08/12/2008
function TemplateChangeSeq(oSeq)
{
	var sSequence = oSeq.value;
	var oValid	= new RegExp("[0-9]{" + sSequence.length + "}");
	if (!oValid.test(sSequence))
	{
		alert("Invalid sequence number...please enter only whole numbers.");
		oSeq.focus();
		oSeq.select();
	}
	else
	{
		var lMaxSeq = document.formList.seqMax.value;
		if(parseInt(oSeq.value, 10) > parseInt(lMaxSeq, 10))
		{
			alert("The maximum allowable sequence number is " + lMaxSeq);
			if(bNS)
				oSeq.value = lMaxSeq;
			oSeq.select();
			oSeq.focus();
		}
		else
		{
			arrCats[lLen] = oSeq.name.substring(oSeq.name.indexOf("_")+1, oSeq.name.length);
			lLen++;
		}
	}
}

function TemplateReSequence(sReturn)
{
	oForm = document.formList;
	var sCats = "";
	// Grab sequence number for all catagories that have been changed
	for(var lCount=0; lCount<arrCats.length; lCount++)
	{
		if (eval("oForm.seq_" + arrCats[lCount] + ".value")!=0 )
			sCats += arrCats[lCount] + "," + eval("oForm.seq_" + arrCats[lCount] + ".value") + ";"
	}
	// Populate the form with changes and submit for saving
	oForm.sCats.value = sCats;
	oForm.act.value = "ReOrder";
	oForm.sReturn.value = sReturn;
	oForm.submit();
}

var arrSequencedItems		= new Array;
arrSequencedItems[0]	= new Array;
arrSequencedItems[1]	= new Array;
var arrMovedItems			= new Array;

function TemplateMoveChange(oItem)
{
	// Check to see if it is checked or not
	if(oItem.checked)
		// If item was checked then just add it		
		arrMovedItems[arrMovedItems.length] = oItem.name.substring(2)
	else
	{
		// If not checked then just remove it
		var lLen = arrMovedItems.length;
		// Loop through all items to make sure is does not exist
		for(var i=0; i < lLen; i++)
			if(arrMovedItems[i] == oItem.name.substring(2))
				arrMovedItems[i] = null;
	}
}

function TemplateMoveItems()
{
	// Make sure they have selected a valid category to move to
	if(ValidSelection(document.formProduct.lMovedCatID))
	{
		// Check to see if they made any changes
		if(arrMovedItems.length == 0)
			// Remind them to check items before moving
			alert("You have not selected any items to move")
		else
		{
			var oForm = document.formProduct;
			// Add array values to form
			oForm.sMovedItems.value = arrMovedItems;
			// Set action specifying a move of items
			oForm.lAction.value = "1";
			// See if they want to apply sequence changes if they exist
			TemplateSequenceItems(true)
			// Send request to move items
			oForm.submit();
			// Give friendly message 
			parent.frmMessage.location = "frmmessage.aspx?msg=" + URLEncode("Items have been moved") + "&" + getFrameworkParameters();
		}
	}
	else
		alert("Please select a category that items will be moved to");
}

function TemplateSequenceItems(bRemind)
{
	// See if they have sequenced any items
	if(arrChanges.length)
	{
		// Changes exist
		if(bRemind)
		{
			// Ask them if they want to capture these changes
			var bSave = window.confirm("You have made changes to item sequences.\nPress \"OK\" to save these changes")
			if(bSave)
				// Continue saving changes
				document.formProduct.sSequencedItems.value = ReturnUpdateString();
				// If "bRemind" is true, then they are already sumbitting the page for another action
		}
		else
		{
			// Save changes to field within the form that will post
			document.formProduct.sSequencedItems.value = ReturnUpdateString();
			// Submit the request
			document.formProduct.submit();
		}
	}
	else
		if(!bRemind)
			// They have pressed the "Re-sequence" button with making any changes
			alert("You have not changed the sequence of any items")			
}
//End changes by S.D. on 08/12/2008