<!-- Hiding ...


/*
Trim

Removes leading and trailing spaces from the passed string. Also removes
consecutive spaces and replaces it with one space. If something besides a string
is passed in (null, custom object, etc.) then return the input.
*/		
function Trim (str)
{
	
	// Verify Parameter
	if (typeof str != "string") { return str; }
	
	var retValue = str;
	var ch = retValue.substring (0, 1);
	

	/* Left Trim */

	while (ch == " ")
	{
		retValue = retValue.substring (1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	
	ch = retValue.substring (retValue.length-1, retValue.length);
	
	
	/* Right Trim */
	
	while (ch == " ")
	{
		retValue = retValue.substring (0, retValue.length-1);
		ch = retValue.substring (retValue.length-1, retValue.length);
	}

	
	/* Double Spaces Trim */

	while (retValue.indexOf ("  ") != -1)
	{
		retValue = retValue.substring (0, retValue.indexOf ("  ")) + retValue.substring (retValue.indexOf ("  ")+1, retValue.length);
	}
	
	// Return the trimmed string.
	return retValue;
}


/*
Get Token

*/
function GetToken (list, position, delimitor)
{

	var strDelimitor = ",";
	
	if (delimitor != null)
		strDelimitor = delimitor;
	
	var nStartPos = 0;
	var nEndPos = -1;
	
	for (var i=0; i<position; i++)
	{
		nStartPos = nEndPos + 1;
		nEndPos = list.indexOf (strDelimitor, nStartPos);
		
		if (nEndPos == -1)
			nEndPos = list.length;
	}

	return list.substring (nStartPos, nEndPos);
}

function ListFind (list, item, delimitor)
{
	var strDelimitor = (delimitor != null) ? delimitor : ",";
	var nListLength = ListLength (list, delimitor);
	
	if (nListLength>0)
	{
		for (var i=1; i<=nListLength; i++)
		{
			if (GetToken(list,i) == item)
				return true;
		}
	}
	return false;
}


/*
List Length

*/
function ListLength (list, delimitor)
{

	var strDelimitor = (delimitor != null) ? delimitor : ",";	
	var nStartPos = 0;
	var nTokenCount = 0;

	
	if (list.length)
	{
	
		nTokenCount++;
		
		while ((nStartPos = list.indexOf (strDelimitor, nStartPos)) != -1)
		{
			nTokenCount++;
			nStartPos++;
		}
	}
	
	return nTokenCount;
}


/*
Update Hierarchy List

*/
function UpdateHierarchyList (mymid, partid, level)
{

	/* COOKIE DATA */
	var strHierarchyData = GetCookie("POS_UserHierarchy");

	
	// Check if the Hierarchy cookie exists ...
	if (strHierarchyData == null)
		SetCookie ("POS_UserHierarchy", mymid + ";" + partid, null, "/");
	else
	{
	
		/*
		Extract the data from the cookie
		
		format:
		mymid[;partid(0),partid(1), ... ,partid(n)]
		*/
		var nModelYearMatchId 	= GetToken (strHierarchyData, 1, ";");
		var lPartIds 			= GetToken (strHierarchyData, 2, ";");
		var nHierarchyLevels	= parseInt (ListLength (lPartIds));
		
		// Determine where the user has selected a part within the hierarchy.
		if (level >= nHierarchyLevels)
		{
		
			// User has moved down past the lowest level.
			
			if (lPartIds.length)
				lPartIds += "," + partid;
			else
				lPartIds += partid;
		}
		else
		{
		
			// User has selected a part id within the hierarchy structure.
		
			// Build a new list of selected part ids.
			var tmp_lPartIds = "";
			for (var i=0; i<nHierarchyLevels; i++)
			{
				//alert (i + " = " + nHierarchyLevels);
				
				if (i < level)
				{
					if (tmp_lPartIds.length)
						tmp_lPartIds += "," + GetToken (lPartIds, i+1);
					else
						tmp_lPartIds += GetToken (lPartIds, i+1);
				}
				else
				{
					//alert (GetToken (lPartIds, i+1) + " = " + partid);
					
					if (GetToken (lPartIds, i+1) != partid)
					{
						if (tmp_lPartIds.length)
							tmp_lPartIds += "," + partid;
						else
							tmp_lPartIds += partid;
					}
					break;
				}
			}
			
			// Replace the current part id list with the "new" list.
			lPartIds = tmp_lPartIds;
		}
		
		// Store the user's hierarchy data.
		if (lPartIds.length)
			SetCookie ("POS_UserHierarchy", nModelYearMatchId + ";" + lPartIds, null, "/");
		else
			SetCookie ("POS_UserHierarchy", nModelYearMatchId, null, "/");
	}
	
	// Reload the page.
	document.location.href = "partslist.cfm";
}



//-->