var arrChanges		= new Array();	//Used in the LogCBChange() and LogValueChange() functions
var lCount			= 0;			//Used in the LogCBChange() and LogValueChange() functions
var sVersion = window.navigator.userAgent; //Get the user again..this is used for mac related detection

function CreateErrorInformation(errObj, errorFunction) {
	try {
		errorInfo = "FUNCTION: " + errorFunction + "\n"
		errorInfo += "TYPE: " + errObj.type + "\n"
		errorInfo += "MESSAGE: " + errObj.message + "\n"
		errorInfo += "CAUSE: " + errObj.cause + "\n"
		alert(errorInfo)
	} catch(err1) {
		alert(err1.message)
	}
}

//Start Changes by S.D. on 12/10/2007
function ConvertIntoInteger(oObj)
{
	if (oObj.value != '' )
		oObj.value=Math.round(oObj.value);
	if(oObj.value =='NaN')
		oObj.value='';
}

function LogQtyChange(oQty, bTrimPrefix, bUpdateTotal, lOriginalQty, cPrice, bCW, cCWAverage, lCasePackQty)
{
	var lPrevQty = -1;	
	var bCalcTotals = false;
	var oFrame = parent.parent.frmTop;
	var bValid = false;
	
	if(!oFrame)
		oFrame = parent.parent.parent.frmTop;
		
		//Hilton needs this
	if(!oFrame){
		oFrame = parent.frmTop;
	}
		
	// This is specific to the par-level functionality
	if (document.formProduct) //this checks for ads...when you have an ad that adds to cart...the page may not have formproduct on it
	{
		if(document.formProduct.bParLevels)
		{
			if(document.formProduct.bParLevels.value == "1")
				var bParLevel = true;
			else
				var bParLevel = false;
		}
		else
			var bParLevel = false;
	}
	else
		var bParLevel = false;
	// if we are validating par-levels then we use float
	// because all users can use the fractional piece...
	// max value is 99999.00
	if(bParLevel) {
		bValid = ValidateFloat(oQty,false,true,99999.00);
	} else {
		bValid = ValidateQty(oQty);
	}
	// Make sure this is a valid quantity
	if(bValid)
	{
		// parse out the product id
		var sProductID = oQty.name.substring(2);
		// if the item is found then the previous qty is in the dom
		lPrevQty = oFrame.GetCartItemQty(sProductID);
		//alert(sProductID + ":" + lPrevQty + ":" + lOriginalQty);
		if(lOriginalQty > 0)
		{
			// Not found in the dom
			if(lPrevQty == -1)
			{
				// If the value is not the original qty then add it to the dom
				if(oQty.value != lOriginalQty)
				{
					lPrevQty = lOriginalQty;
					oFrame.ModifyCartItem("Add",sProductID,oQty.value);
					bCalcTotals = true;
				}
			}
			else
			{
				// Item in the dom and either the original qty is different
				// or the qty passed in as the new value is different
				if(lPrevQty != lOriginalQty || oQty.value != lOriginalQty)
				{					
					oFrame.ModifyCartItem("Add",sProductID,oQty.value);
					bCalcTotals = true;
				}
			}
		}
		else
		{
			// reset the Previous qty to the passed in value
			// and add the value to the cart
			if(lPrevQty != lOriginalQty || (oQty.value.length > 0 && oQty.value != 0))
			{
				if(lPrevQty == -1)
				{
					lPrevQty = lOriginalQty;
					oFrame.ModifyCartItem("Add",sProductID,oQty.value);
					bCalcTotals = true;
				}
				else
				{
					oFrame.ModifyCartItem("Add",sProductID,oQty.value);
					bCalcTotals = true;				
				}
			}
		}
	}
	else
	{
		// parse out the product id
		var sProductID = oQty.name.substring(2);
		// if the item is found then the previous qty is in the dom
		lPrevQty = oFrame.GetCartItemQty(sProductID);	
		// item had a quantity to begin with and was set to ''
		if(lOriginalQty > 0)
		{
			oQty.value = "";
			// Only if the value was not found we set this to the original qty
			if(lPrevQty == -1) lPrevQty = lOriginalQty;
			oFrame.ModifyCartItem("Add",sProductID,0);
			bCalcTotals = true;
		}
		else
		{
			// If the product original quantity was not there
			// but they had added it in this session, remove it
			if(lPrevQty != -1)
			{
				oQty.value = "";
				// Remove the item from the cart
				oFrame.ModifyCartItem("Rem",sProductID);
				bCalcTotals = true;
			}
		}
	}

	// Calculate the totals and update the xml cart		
	if(bCalcTotals && !bParLevel)
	{
		var lCurrentQty = oQty.value;
		
		// Get the current cart totals
		var arrTotals = oFrame.GetCartTotals().split(",");
		var cCurrentSubtotal = Number(arrTotals[0]);
		var lCurrentItems = Number(arrTotals[1]);
		var lCurrentPieces = Number(arrTotals[2]);
		if(cCurrentSubtotal < 0.01) cCurrentSubtotal = 0;
		
		// First get the calculated quantity (could be negative or positive)
		if(lPrevQty < lCurrentQty) {
			var lCalculationQty = lCurrentQty - lPrevQty;
		} else {
			var lCalculationQty = -1 * (lPrevQty - lCurrentQty);
		}
			
		// Update the item price totals
		if(bCW == "True")
		{
			if(lCasePackQty != '0')
				var cSubTotal = (lCalculationQty * cPrice * cCWAverage * lCasePackQty);
			else
				var cSubTotal = (lCalculationQty * cPrice * cCWAverage);
		}
		else
			var cSubTotal = (lCalculationQty * cPrice);
			
		// Update the current totals
		cCurrentSubtotal = cCurrentSubtotal + cSubTotal;
		// Round the subtotal up to the nearest 0.01
		if(cCurrentSubtotal > 0) cCurrentSubtotal = Math.round(cCurrentSubtotal * 100) / 100;
		lCurrentPieces = lCurrentPieces + lCalculationQty;
		// Update the line item totals
		if(lCurrentQty == 0 && lPrevQty != 0) {
			lCurrentItems = lCurrentItems - 1;
		} else if(lPrevQty == 0 && lCurrentQty > 0) {
			lCurrentItems = lCurrentItems + 1;
		}
		// Added this to prevent round off error (if they don't have items then the subtotal should be zero)
		if(cCurrentSubtotal < 0.01 || lCurrentItems == 0) cCurrentSubtotal = 0;
		// Now update the xml cart
		oFrame.ModifyCartTotals(cCurrentSubtotal, lCurrentItems, lCurrentPieces);
		if(bUpdateTotal)
			oFrame.UpdateCartTotals();
	}
}

//Added by S.D. 12/19/2007 for Inventory Quantity without cart updates
function LogInvQtyChange(oQty, bTrimPrefix, bUpdateTotal, lOriginalQty, cPrice, bCW, cCWAverage, lCasePackQty)
{
	var lPrevQty = -1;	
	var bCalcTotals = false;
	var oFrame = parent.parent.frmTop;
	var bValid = false;
	
	if(!oFrame)
		oFrame = parent.parent.parent.frmTop;
		
		//Hilton needs this
	if(!oFrame){
		oFrame = parent.frmTop;
	}
		
	// This is specific to the par-level functionality
	if (document.formProduct) //this checks for ads...when you have an ad that adds to cart...the page may not have formproduct on it
	{
		if(document.formProduct.bParLevels)
		{
			if(document.formProduct.bParLevels.value == "1")
				var bParLevel = true;
			else
				var bParLevel = false;
		}
		else
			var bParLevel = false;
	}
	else
		var bParLevel = false;
	// if we are validating par-levels then we use float
	// because all users can use the fractional piece...
	// max value is 99999.00
	if(bParLevel) {
		bValid = ValidateFloat(oQty,false,true,99999.00);
	} else {
			ValidateIntFloatQty(oQty); //Allow Float values. U.S.N 02/14/2008
	}
}

function ClearCache()
{
	document.location = "/access/frmmessage.aspx?act=42" + '&' + getFrameworkParameters();;
}

function XmlEncode(sString)
{
	sString = sString.replace(/&/g,  "&amp;");
	sString = sString.replace(/</g,  "&lt;");
	sString = sString.replace(/>/g,  "&gt;");
	sString = sString.replace(/'/g,  "&apos;");
	return sString;
}

function StripSpecial(sString)
{
	return sString.replace(/[\!\@\#\^\&\*\(\)\_\+\-\=\<\>\?\:\;\'\"{\}\\\/]/g, "")
}
// Finds the next edit box that is not disabled on a product list
// Parameters:
// oCurrentBox - the current edit box that has the focus
// listCount   - the total number of items in the product list
//
function FindNextEditBox(oCurrentBox, listCount) {
	var sObjId = oCurrentBox.id;
	var sId = sObjId.split("_");
	if(sId[1] >= 1) {
		oForwardBox = null;
		var sForward = Number(sId[1]) + 1;
		var oForwardBox = eval("document.all." + sId[0] + "_" + sForward);
		if(!oForwardBox) //Start changes by V.G. 12/21/2007
		{
			while (sForward <= listCount)
			{
				sForward = sForward + 1;
				oForwardBox = eval("document.all." + sId[0] + "_" + sForward);
				if (oForwardBox)
				{
					break;
				}
			}
		}//End changes by V.G. 12/21/2007
		//Changes by S.D. 11/30/2007
		while(oForwardBox && sForward <= listCount) {
			if(oForwardBox != null && oForwardBox.disabled == true) {
				oForwardBox = eval("document.all." + sId[0] + "_" + sForward);
			} else {
				// box is not disabled (set the focus)
				if(oForwardBox) {
					setTimeout("document.all." + oForwardBox.id + ".focus()", 50);
					oForwardBox = null;
					sForward = listCount;	// exit the loop
				}
			}
			sForward = Number(sForward) + 1;	// increment the counter
			oForwardBox = eval("document.all." + sId[0] + "_" + sForward);
		}
	}		
}
// Finds the previous edit box that is not disabled on a product list
// Parameters:
// oCurrentBox - the current edit box that has the focus
// listCount   - the total number of items in the product list
//
function FindPrevEditBox(oCurrentBox, listCount) {
	var sObjId = oCurrentBox.id;
	var sId = sObjId.split("_");
	if(sId[1] > 1) {
		oBackwardBox = null;
		var sBack = Number(sId[1]) - 1;
		var oBackwardBox = eval("document.all." + sId[0] + "_" + sBack);
		while(oBackwardBox|| sBack > 0) {
			if(oBackwardBox != null && oBackwardBox.disabled == true) {
				oBackwardBox = eval("document.all." + sId[0] + "_" + sBack);
			} else {
				if(oBackwardBox) {
					setTimeout("document.all." + oBackwardBox.id + ".focus()", 50);
					oBackwardBox = null;
					sBack = 0;	// exit the loop
				}
			}
			sBack = Number(sBack) - 1;	// decrement the counter
			oBackwardBox = eval("document.all." + sId[0] + "_" + sBack);
		}					
	}
}
function TabForwardOrBackward(currentId,bInv,sPrefix) {
	var listCount;
	var sEvalStr = "";
	
	//tab forward functionality has never been supported for NS (document.all just thorws error)
	if (sVersion.indexOf("Netscape") == -1) {
		if(bInv) 
		{
			sEvalStr = "document.all.oInventory_";
		} 
		else if(sPrefix)
		{
			sEvalStr = "document.all." + sPrefix;
		}
		else 
		{
			sEvalStr = "document.all.oQty_";
		}
		// get the product list count
		if(formProduct.lListCount) {
			listCount = formProduct.lListCount.value - 1;
		}
		// first grab the current box
		var oCurrentBox = eval(sEvalStr + currentId);
		// if we cannot get the current box just exit
		if(oCurrentBox == null) return;
		
		if(window.event) {
			if(window.event.shiftKey) {
				if(window.event.keyCode == 9 || window.event.keyCode == 13) {
					FindPrevEditBox(oCurrentBox, listCount);
					window.event.returnValue = false;
				}
				else
				{
					if(sPrefix) //Allow Shift+ other key inputs.U.S.N 02/14/2008
						if(sPrefix.indexOf("oShelfBinNo_") < 0)
							window.event.returnValue = false;
				}				
				return;
			}
		}
		if(window.event.keyCode == 9 || window.event.keyCode == 13) {
			if(oCurrentBox) {
				FindNextEditBox(oCurrentBox,listCount);
			}
			window.event.returnValue = false;
			return;
		}
	}
}
function LogItemSequence(oQty, bTrimPrefix, bSetToZero, lPrevQty, oNextQty)
{
	var bCalculateTotals = false;
	// Make sure this is a valid quantity
	if(ValidateQty(oQty))
	{
		// Build update string
		if(bTrimPrefix)
		{
			var sProductID = oQty.name.substring(2);
			var sChange = sProductID + "," + oQty.value;
		}
		else
		{
			var sProductID = oQty.name;
			var sChange = sProductID + "," + oQty.value;
		}
		// Get current number of changes
		var lLen = arrChanges.length;
		// We first need to check if we have already logged this change
		for(var i=0; i<lLen; i++)
		{
			// need to check the control to compare the values
			var arrTemp1 = arrChanges[i].split(",");
			var arrTemp2 = sChange.split(",");
			if(arrTemp1[0] == arrTemp2[0])
			{
				lLen = i;
				lPrevQty = arrChanges[i].substr(arrChanges[i].indexOf(",")+1);
				break;
			}
		}
		if(sChange != ",")
			arrChanges[lLen] = sChange
		// There is a case where we don't have the correct previous quantity when the change array 
		// has been re-initialized and a change was to the original quantity value.
		if(lLen==0 && oQty.value != lPrevQty)
			lPrevQty = oQty.value;
	}
	else
	{
		if(bSetToZero && oQty.value == "")
		{
			oQty.value = "0";
			LogValueChange(oQty.value,0);
		}
	}
}

function LogValueChange(lIDVal,bOn)
{
	//lIDVal = value passed in; lOn = whether it's being removed or added (0 or 1).	
	// Build functionID/value string
	var sChange = lIDVal + "," + bOn;
	// this was placed to handle the crazy if problem, when true the IF would not execute
	if (bOn == 1)
		bRev = 0;
	else
		bRev = 1;
	var sRev	=  lIDVal + "," + bRev;
	// Get length of array
	var lLen = arrChanges.length;
	// We first need to check if we have already logged this functionID
	for(var i=0; i<lLen; i++)
	{
		// need to check the control to compare the values
		if (arrChanges[i] != null)
		{
			arrTemp1 = arrChanges[i].split(",");
			arrTemp2 = sRev.split(",");
			if(arrTemp1[0] == arrTemp2[0])
			{
				lLen = i;
				sChange = null;
				break;
			}
		}
	}
	arrChanges[lLen] = sChange
}

function LogCBChange(oCB)
{
	// Grab functionID from end of checkbox name
	var lIDVal = oCB.name.substr(oCB.name.indexOf("_")+1);
	// See if it's checked or not
	var bOn = 0;
	if(oCB.checked == true)
		bOn = 1;
	// Build lIDVal/value string
	var sChange = lIDVal + "," + bOn;
	// this was placed to handle the crazy if problem, when true the IF would not execute
	if (bOn == 1)
		bRev = 0;
	else
		bRev = 1;
	var sRev	=  lIDVal + "," + bRev;
	// Get length of array
	var lLen = arrChanges.length;
	// We first need to check if we have already logged this lIDVal
	for(var i=0; i<lLen; i++)
	{
		// need to check the control to compare the values
		if (arrChanges[i] != null)
		{
			var arrTemp1 = arrChanges[i].split(",");
			var arrTemp2 = sRev.split(",");
			if(arrTemp1[0] == arrTemp2[0])	
			{
				lLen = i;
				sChange = null;
				break;
			}
		}
	}
	arrChanges[lLen] = sChange;
}

function ReturnUpdateString()
{
	var lLen		= arrChanges.length;
	var sChanges	= "";
	
	// Make sure we have changes to update by checking the length of the change array
	if(lLen > 0)
		{
			// If changes were made, append to string variable with ID,(0 or 1);
			for(var i=0; i<lLen; i++)
				if (arrChanges[i] != null)
					sChanges += arrChanges[i] + ";"
			// Reset the array
			arrChanges = new Array();
			// Return the string
			return sChanges;
		}
	else
		return "";
	
}

function checkBrowser(sSite)
{
	//sSite (community or access) is for community or access
	var sVersion = window.navigator.userAgent;

	if (sSite == 'community')
	{
		//get he browser version
		sRev = sVersion.substring(sVersion.indexOf("MSIE") + 4, sVersion.indexOf(";", sVersion.indexOf("MSIE")));
		if(sRev < 5 || isNaN(sRev)) 
			top.location = "/community/browser.aspx?" + getFrameworkParameters();
	}
	else
	{
		if (sVersion.indexOf("MSIE") == -1)
		{
			//non-microsoft browser
			sRev = parseFloat(sVersion.substring(sVersion.indexOf("Netscape6")+10));
			//check rev
			if (sVersion.indexOf("Netscape/7") == -1) //check for version 7
				if(sRev < 6.2 || isNaN(sRev)) 
					parent.location = "/access/browser.aspx?" + getFrameworkParameters();
		}
		else //Microsoft Internet Explorer
		{
			sRev = sVersion.substring(sVersion.indexOf("MSIE") + 5, sVersion.indexOf(";", sVersion.indexOf("MSIE")));
			//check rev for access we tell them we need version 5 or better but we will allow a 4 of IE
			if(sRev < 4)
				parent.location = "/access/browser.aspx?" + getFrameworkParameters();
		}
	}
}	

function DimensionArray(lRecs, lAtts)
{
	var arr = new Array(lRecs);
	for(var lCount=0;lCount<lAtts;lCount++)
		arr[lCount] = new Array();
	return arr;
}
//Start changes by Z.S. 02/12/2007
function SetSortSelections(oSort, lBrowseID, lViewID, lSelectedSort, lHidePrice)
{
	var pageID = 1;
	var viewID;
    var browseID;
        
	if (lViewID)	//if lViewID is not available then assign 'N' to it.
	{
		viewID = lViewID.value;
	}
	else
	{
		viewID = 'N';
	}
	
	if (lBrowseID)	//if lBrowseID is not available then assign 'N' to it.
	{
		browseID = lBrowseID.value;
	}
	else
	{
		browseID = 'N';
	}
	
	//Set the flag
    var iCnt;
    var bDefBrow=false;    
    for(iCnt=0;iCnt<=arrBrowse.length-1;iCnt++)
    {					
		if(arrBrowse[iCnt][0]==pageID+","+browseID)
		{				
			if(arrBrowse[iCnt][2]=="1")
			{						
				bDefBrow=true;
				break;
			}
		}
    }
    
	//If order guide changes value, hide the sort box.BUG05061
	if(lViewID == 12)
		oSort.style.display = 'none';
	else
		oSort.style.display = 'block';
			
	oSort.options.length = 0;			//Empty the sort combo from previously populated values
	
    //Fill the sort combo with applicable elements
    var iElementCnt=0;    
    for(var cnt=0;cnt<=arrSort.length-1;cnt++)
    {      
        var arrSp = arrSort[cnt][0].split(","); 
        if (pageID + ',' + browseID + ',' + viewID == arrSp[0] + ',' + arrSp[1] + ',' + arrSp[2])
        {   
        	oSort.options[iElementCnt]= new Option(arrSort[cnt][1],arrSp[arrSp.length-1]);	//Add a new element to sort combo            
            if(lSelectedSort == oSort.options[iElementCnt].value)	//If Selected sort value is available and the current element is same then set it as selected
            {
				if(bDefBrow==true || browseID == "N")
				{
					oSort.options[iElementCnt].selected = true;                                                       
				}
			}
			if(lSelectedSort == "" || lSelectedSort == undefined)		//If Selected sort value is not available and the current element is same with the saved value then set it as selected
			{
				if (pageID + ',' + browseID + ',' + viewID + ',' + arrSort[cnt][2] == arrSp[0] + ',' + arrSp[1] + ',' + arrSp[2] + ',1')
				{	
					if(bDefBrow==true || browseID == "N")
					{
						oSort.options[iElementCnt].selected = true;
					}
				}
            }
            iElementCnt+=1;
        }
    }      		
}
//End changes by Z.S. 02/12/2007

function GetButtonNames(sID)
{
	var oFrame = parent.frmTop;
	if(oFrame)
	{
		var sButtonName = oFrame.document.getElementById(sID);
		if (sButtonName) //Button may  not exist under some uum conditions
			if (sButtonName.innerHTML != "") 
			{
			   return document.write(sButtonName.innerHTML);
			}
	}
}

function SetPrefViewSelections(oForm, lSelectedView)
{
	var oBrowseID = oForm.lBrowseID;
	var oViewID = oForm.lViewID;
	var oSortID = oForm.lSortID; // Changes by Z.S. 02/16/2007
	var bSelected = false;
	
	//Mac IE bug fix please leave cf
	if (sVersion.indexOf("Mac") > -1) //IF mac then submit the form
	{
		if (sVersion.indexOf("Netscape") == -1)  //This would be true for MAC/IE
		{
			if (!oBrowseID)
				oBrowseID = document.all("lBrowseID")
			if (!oViewID)
				oViewID = document.all("lViewID")
		}
	}
	
	
    
	if (oBrowseID)
	{
		var browseID = oBrowseID.options[oBrowseID.selectedIndex].value;
        var arr = browseID.split(",");        
        browseID = arr[arr.length-1];           
        var pageID = 1;     
        var iElementCnt=0;  
        //Set the flag
		var iCnt;
		var bDefBrow=false;    
		for(iCnt=0;iCnt<=arrBrowse.length-1;iCnt++)
		{					
			if(arrBrowse[iCnt][0]==pageID+","+browseID)
			{				
				if(arrBrowse[iCnt][2]=="1")
				{						
					bDefBrow=true;
					break;
				}
			}
		}
                         
        oViewID.options.length = 0;
        oSortID.options.length = 0;        
        
        for(var cnt=0;cnt<=arrView.length-1;cnt++)
        {      
            var arrSp = arrView[cnt][0].split(",");        
            if (pageID + ',' + browseID == arrSp[0] + ',' + arrSp[1])
            {   				
				oViewID.options[iElementCnt]= new Option(arrView[cnt][1],arrSp[arrSp.length-1]);                            
                if (pageID + ',' + browseID + ',' + arrView[cnt][2] == arrSp[0] + ',' + arrSp[1] + ',1')
                {	
					if(bDefBrow==true || browseID == "N")
					{
						oViewID.options[iElementCnt].selected = true;
					}
                }
                iElementCnt+=1;
            }
        }
            
        SetSortSelections(oForm.lSortID, oForm.lBrowseID, oForm.lViewID);  //Call SetSortSelections to set sort element.
        		
	}
}

function PopUpWin(sPage, lWidth, lHeight,sScroll)
{
	if(!lWidth)
		lWidth = 680;
	if(!lHeight)
		lHeight = 400;
	if(!sScroll)
		sScroll = 'yes';
	mywin = open(sPage,'PopUp','width=' + lWidth + ',height=' + lHeight + ',scrollbars=' + sScroll + ',toolbar=no,location=no,status=no,resizable=yes,menubar=no');
	if(mywin)
		mywin.focus();
}

function setFocus()
{
	var oForm = document.formLogin;
	var oUser = oForm.vsLogonName;
	if(oUser.value == "")
		oUser.focus();
	else
		oForm.vsPassword.focus();
}

function URLEncode(sVal)
{
	// Use regular expressions to replace problem characters
	var regExpr
	// Replace "&"
	regExpr = /&/g
	sVal = sVal.replace(regExpr, "%26")
	// Replace "#"
	regExpr = /#/g
	sVal = sVal.replace(regExpr, "%23")
	// Replace " "
	regExpr = / /g
	sVal = sVal.replace(regExpr, "%20")
	// Replace double quotes
	regExpr = /"/g
	sVal = sVal.replace(regExpr, "%22")
	// Replace single quotes
	regExpr = /'/g
	sVal = sVal.replace(regExpr, "%27")
	regExpr = /\//g
	sVal = sVal.replace(regExpr, "%2F")
	return sVal;
}

function HTMLEncode(sVal)
{
	// Use regular expressions to replace problem characters
	var regExpr
	// Replace "<"
	regExpr = /</g
	sVal = sVal.replace(regExpr, "&lt;")
	// Replace ">"
	regExpr = />/g
	sVal = sVal.replace(regExpr, "&gt;")
	return sVal;
}

function HTMLUnEncode(sVal)
{
	// Use regular expressions to replace problem characters
	var regExpr
	// Replace "<"
	regExpr = /&lt;/g
	sVal = sVal.replace(regExpr, "<")
	// Replace ">"
	regExpr = /&gt;/g
	sVal = sVal.replace(regExpr, ">")
	return sVal;
}
function RemoveScriptTags(sVal)
{
	// Use regular expressions to replace problem characters
	var regExpr
	// Replace "<"
	regExpr = /</g
	sVal = sVal.replace(regExpr, "")
	// Replace ">"
	regExpr = />/g
	sVal = sVal.replace(regExpr, "")
	// Replace /
	regExpr = /\//g
	sVal = sVal.replace(regExpr, "")	
	regExpr = /_/g   //Tommy asked we remove _'s from searches
	sVal = sVal.replace(regExpr, "")
	return sVal;
}
function GetCookie(sName)
{
	var aCookie = document.cookie.split("; "); 
	for (var i=0; i < aCookie.length; i++) 
	{
		//determin if we are working with a cookie Dictionary
		if (aCookie[i].indexOf("&") != -1)
		{
			//with cookie dictionary the cookie name gets mixed up with the first 
			//crumb value when spliting by the "&" so we have to strip off the name
			aCookie[i] = aCookie[i].substring(aCookie[i].indexOf("=") + 1, aCookie[i].length);
			//split into an array
			var aDic = aCookie[i].split("&");
			//look at each value
			for (var x=0; x < aDic.length; x++)
			{
				// split a value into the name and value ex DE=4 aCrumb[0] = DE aCrumb[1] = 4
				var aCrumb = aDic[x].split("=");
				if (sName == aCrumb[0]) 
					return unescape(aCrumb[1]);
			}
		}
		else
		{
			//Not cookie dictionary
			var aCrumb = aCookie[i].split("=");
			//	This was added when we went to dot net...we had added the vitural root to the cookies
			//	and this funcion wouldn't work alert("access_" + sName == aCrumb[0])
			if (sName == aCrumb[0] || "access_" + sName == aCrumb[0]) 
				return unescape(aCrumb[1]);
		}
	}
}
function getCookie2(name)
{ 
	// use: getCookie("name");
	var re = new RegExp(name + "=([^;]+)");
	var value = re.exec(document.cookie);
	return (value != null) ? unescape(value[1]) : null;
}

function setCookie(name, value)
{ 
	// use: setCookie("name", value);
	var today = new Date();
	var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days	
	//The access_ was added when we went to dotnet...the aspx function adds the virtaul root to every cookie and the java script functions 
	//needed to do the same
	document.cookie="access_" + name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + ";path=/"; //PATH ADDED TO CORRECT DOUBLE COOKIES FROM CLIENT AND SERVER
}

function DeleteCookie(name)
{
	var date = new Date();
	date.setTime(date.getTime()+(-1*24*60*60*1000)); //Delete cookies with a path or without. This is caused by client side, and server side setting of the cookies.
	document.cookie="access_" + name + "=" + "" + "; expires=" + date.toGMTString() + ";path=/";
	document.cookie="access_" + name + "=" + "" + "; expires=" + date.toGMTString() + ";";
}
function ResetSaved10Key()
{
	var arrSaved10Key = eval("parent.frmTop.arr10Key");
	// Reset the saved array if it exists
	if(arrSaved10Key)
		parent.frmTop.arr10Key = new Array();
	// Set the nav button to clicked (so the user is not confused)
	parent.frmTop.SetNavClicked('button3');
}

function findString(fullS,subS)
{
	// finds subS in fullS
	for( var i=0; i < fullS.length; i++ )
	{
		if(fullS.substring(i,i+subS.length) == subS)
		{
			return true;
		}   
	}
	return false;
}

function GetSelectBoxValue(oSelect)
{
	if(oSelect)
		return oSelect.options[oSelect.selectedIndex].value;
	else
		return "0";
}

function Resubmit10Key(oForm, oSubmitBtn)
{
	oSubmitBtn.disabled = true;
	oForm.sFeatures.value = '';	//Changes by U.S.N 05/03/2007
	oForm.submit();
}

//fuction to check or uncheck all checkboxes in a form...pass the form and true to check, false to uncheck
function ModifyAllCheckBoxes(oForm, bCheck)
{
	for (i=0; i<oForm.elements.length; i++)
	{
		sType  = oForm.elements[i].type;
		if (sType == "checkbox")
		{
			if (bCheck)
				oForm.elements[i].checked = true;
			else
				oForm.elements[i].checked = false;
		}
	}
}

function LocateMyIframe(oItem, oFrame, bLeft, lAdjustX, lAdjustYUp, lAdjustYDown)
{
    //oItem is the item your clicking on
    //oFrame is the frame you want to move
    //bLeft is take on the left position of the item you clicked on
    //lAdjustX is a value to move the X positions + or -
    //lAdjustYUp lets you ajust the position for X when the iframe poops up ABOVE the item you clicked on
    //lAdjustYUp lets you ajust the position for X when the iframe poops up BELOW the item you clicked on
    var eL=0;var eT=0;
    for(var p=oItem; p&&p.tagName!='BODY'; p=p.offsetParent)
    {
        eL +=p.offsetLeft;
		eT += p.offsetTop;
    }
    var eH = oItem.offsetHeight;
    var eW = oItem.offsetWidth;
    var dH = oFrame.style.pixelHeight;
    var dW = oFrame.style.pixelWidth;
    var sT = document.body.scrollTop;

    if (bLeft)
		oFrame.style.left=eL;
		
	//if we are off the screen move us back to the left
	if(eL+eW+dW + lAdjustX > document.body.clientWidth)
		oFrame.style.left=eL - dW + eW + lAdjustX
	else
	{
		//Used to tweak the position if needed...some elements have funny 0,0 poistions and you have to addjust a little
		if (lAdjustX != 0)
			oFrame.style.left = eL + lAdjustX
	}
	
		
    if(eT-dH >= sT && eT+eH+dH > document.body.clientHeight+sT)
		oFrame.style.top=eT-dH + lAdjustYUp;
    else
		oFrame.style.top=eT+eH + lAdjustYDown;
}

function ResizeMyIFrame(oFrame, lHeight, lWidth)
{
	//width and height should be a precentage of the window ex 80 would give you 80%
	if(lWidth > 0)
		document.all(oFrame.name).style.width = document.body.offsetWidth * (lWidth / 100); 
	document.all(oFrame.name).style.height = document.body.offsetHeight * (lHeight / 100);
}

function CloseFrameWin()
{
	parent.document.getElementById(this.name).style.display="none";
}

function ToggleImageUp(sLink,bDelay)
{
	var oImage;
	var sString = "oImg" + sLink
	if(document.getElementById(sString))
		oImage = document.getElementById(sString);
	else
		oImage = parent.document.getElementById(sString);
	if(oImage)
	{
		if(bDelay)
		{
			if(document.getElementById(sString))
				setTimeout("document.getElementById(" + sString + ").src = '/assets/images/wiparrow_up.gif';",100);
			else
				setTimeout("parent.document.getElementById(" + sString + ").src = '/assets/images/wiparrow_up.gif';",100);
		}
		else
			oImage.src = "/assets/images/wiparrow_up.gif"
	}
}

function ToggleImageDn(sLink,bDelay)
{
	var oImage;
	var sString = "oImg" + sLink
	if(document.getElementById(sString))
		oImage = document.getElementById(sString);
	else
		oImage = parent.document.getElementById(sString);
	if(oImage)
	{
		if(bDelay)
		{
			if(document.getElementById(sString))
				setTimeout("document.getElementById('" + sString + "').src = '/assets/images/wiparrow_down.gif';",100);
			else
				setTimeout("parent.document.getElementById('" + sString + "').src = '/assets/images/wiparrow_down.gif';",100);
			
		}
		else
			oImage.src = "/assets/images/wiparrow_down.gif"
	}
}

function SetSelectBoxOption(oSelect, sValue)
{
	if(oSelect.options)
	{
		for(var lCount=0; lCount<oSelect.options.length; lCount++)
			if(oSelect.options[lCount].value == sValue)
			{
				oSelect.options[lCount].selected = true;
				return;	
			}
	}
}

function CheckForUndefined(vValue)
{
	if(vValue == "undefined" || typeof vValue == "undefined")
		return ""
	else
		return vValue;
}
// Sets order edit information in the actual DB for the customer object NOT THE COOKIE.  Originally this information
// was stored in the cookie and this asynchornous web service call is named such for legacy reasons.
function GetOrderEditCookie(orderRecID)
{
	return CheckForUndefined(GetCookie("lOrderEditRecID_" + GetCookie("LI")))
}

// This function has been modified to get the order edit information from a webservice call rather than from
// the cookie.  This fuction calls out to the web service from within javascript and parses the result.
function SetOrderEditCookie(orderRecID)
{
	//alert(self.location)
	parent.frmMessage.location = 'frmmessage.aspx?set=1&orderId=' +  orderRecID + '&act=46&' + getFrameworkParameters();
	setCookie("lOrderEditRecID_" + GetCookie("LI"), orderRecID);
}

function SaveOrderInfo(lRecID)
{
	// At checkout we need the order id and order type
	//setCookie("lOrderEditRecID_" + GetCookie("LI"), lRecID);
	SetOrderEditCookie(lRecID);
}

function ShowOrderEditModeSection(lRecID)
{
	// At checkout we need the order id and order type
	parent.frmTop.document.getElementById("oOrderModeID").innerHTML = lRecID;
	parent.frmTop.document.getElementById("oOrderEditStatus").style.display = "block";
}

function ClearOrderInfo()
{
	// At checkout we need the order id and order type
	//setCookie("lOrderEditRecID_" + GetCookie("LI"), "");
	SetOrderEditCookie("")
	// Now hide the order edit mode section in frmTop
	if(parent.frmTop.document.getElementById("oOrderEditStatus"))
		parent.frmTop.document.getElementById("oOrderEditStatus").style.display = "none";
}

function ToggleDotLabel(sLabel, bToggle)
{
	document.getElementById('oDotLabel').innerHTML = sLabel;
	if(bToggle)
	{
		document.getElementById('oDotLabel').style.display = "block";
		document.getElementById('oloading').style.display = "block";
		document.getElementById('oMain').style.display = "none";
	}
	else
	{
		document.getElementById('oDotLabel').style.display = "none";
		document.getElementById('oloading').style.display = "none";
		document.getElementById('oMain').style.display = "block";
	}
	return true;
}

function IsValidParSelection(oParList, oPreviousValue, bUpdatePreviousValue)
{
	if(oParList && oParList.value == "none")
	{
		// Reset the previous value
		if(oPreviousValue.value == "")
			SetSelectBoxOption(oParList, "0");
		else
			SetSelectBoxOption(oParList, oPreviousValue.value);
		return false;
	}
	else
	{
		if(bUpdatePreviousValue)
		// They passed in the hidden field that keeps track of the last valid selection
		// Let's update it if the current selection is valid.
			oPreviousValue.value = oParList.value
		return true;
	}
}
function trim(str)
{
	return((""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}
function popExternalHelp(url, reSize) {
	if (reSize == 1)
	{
		window.open(url, null,"status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes, resizable=1");
	}
	else
	{
		window.open(url, null,"status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
	}
}
// Added by TH 3/13/2006 in support of BUG14364
// given a querystring name, will return that names value if it exists on the querystring and false otherwise
function getQSValue(name, querystring)
{
	var value = "";
    var qsToken = name + "=";    
	var foundAt = querystring.indexOf(qsToken);
	if (foundAt > -1) // found our token
	{
		var valueStartsAt = foundAt + qsToken.length;
		var restOfQS = querystring.substring(valueStartsAt, querystring.length);
		var lenOfValue = restOfQS.indexOf("&");
		if (lenOfValue > -1)
		   value = querystring.substring(valueStartsAt, (valueStartsAt + lenOfValue)); 
		else
		   value = querystring.substring(valueStartsAt, (querystring.length - valueStartsAt)); 
	}
	return value;
	
}
//Start Changes U.S.N
function setFocus(currentId,listCount)
{
	var oCurrentBox = eval(currentId);
	// if we cannot get the current box just exit
	if(oCurrentBox == null) return;
	
	if(window.event) {
		if(window.event.shiftKey) {
			if(window.event.keyCode == 9 || window.event.keyCode == 13) {
				FindPrevEditBox(oCurrentBox, listCount);
			}
			window.event.returnValue = false;
			return;
		}
	}
	if(window.event.keyCode == 9 || window.event.keyCode == 13) {
		if(oCurrentBox) {
			FindNextEditBox(oCurrentBox,listCount);
		}
		window.event.returnValue = false;
		return;
	}
}
//End Changes U.S.N
function ShowBudget(CategoryID) //Start U.S.N 08/06/2007
{	
	var budgetIframe = document.getElementById('budgetIframe');	
	budgetIframe.src = "/access/BudgetInfo.aspx?CategoryID=" + CategoryID + "&" + getFrameworkParameters();
	budgetIframe.style.display = "block";
	
}
function ShowIFDADocLinkURL(IFDADocLinkURL, sSPSIMfrNum, sSPSIMfrProdCode) //Start changes by V.G. 10/23/2007
{
	var url = IFDADocLinkURL + "&mfr_num=" + sSPSIMfrNum + "&mfr_prd_num=" + sSPSIMfrProdCode;
	window.open(url, null,"status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}	//End changes by V.G. 10/23/2007

function ShowNSCSpecPageLinkURL(specPageUrl) //Start changes by S.D. 11/26/2008
{
	window.open(specPageUrl, null,"height=500,width=750,left=150,top=100,screenX=0,screenY=100,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}	//End changes by S.D. 11/26/2008
function ShowPrice(sFSAUrl, sProductID)	//Start changes by V.G. 05/04/2009
{
	var url = sFSAUrl + "&item=" + sProductID;
	window.open(url, "Pricing","height=300,width=456,status=yes,toolbar=no,menubar=no,location=no,resizable=no");
}	//End changes by V.G. 05/04/2009