			function OptionAddItem (iAction, Action)
			{
				//Update the saleprice hidden input field
				//Does this quantity input exist?
				/*for (var i=0;i<document.Options.length;i++)
				{
				    current = document.Options.elements[i];
				    if (current.name == ("Quantity" + iAction))
						//alert ("Success! " + current.name);
						if (current.value > 1){ //Value of Select Shipping Method
							alert ("Quantity is greater than 1");
							//Update SalePrice Input Field
							saleprice = eval("document.Options.SalePrice" + iAction); 
							alert ("SalePrice: " + saleprice.value);
							saleprice.value = saleprice.value * current.value;
							alert ("NewSalePrice: " + saleprice.value);
							
						}
						else{
							alert ("Quantity is 1");
						}
				}*/
				document.Options.ID.value = iAction;
				document.Options.Action.value = Action;
				document.Options.submit();
			}
			function DeptAddItem (iAction, Action)
			{
				document.Dept.ID.value = iAction;
				document.Dept.Action.value = Action;
				document.Dept.submit();
			}
			function PartAddItem (iAction, Action)
			{
				document.Part.ID.value = iAction;
				document.Part.Action.value = Action;
				document.Part.submit();
			}
			function ProductTableAddItem(iAction, Action)
			{
				document.Product.ID.value = iAction;
				document.Product.Action.value = Action;
				document.Product.submit();
			}
			function ComplexProductTableAddItem(iAction, Action)
			{
				document.ComplexProduct.ComplexID.value = iAction;
				document.ComplexProduct.ComplexAction.value = Action;
				document.ComplexProduct.submit();
			}
			function ProductDropAddItem(Action)
			{
				if (document.Product.Drop_ID.value == "")
				{
					alert ("Please Select A Product.");
					document.Product.Drop_ID.value();
					return false;
				}
				else
				{
					document.Product.ID.value = document.Product.Drop_ID.value;
					document.Product.Action.value = Action;
					document.Product.submit();
				}				
			}
			function ProductDropAddItemQuantity(Action, Qty)
			{
				if (document.Product.Drop_ID.value == "")
				{
					alert ("Please Select A Product.");
					document.Product.Drop_ID.value();
					return false;
				}
				else
				{
					document.Product.ID.value = document.Product.Drop_ID.value;
					document.Product.Action.value = Action;
					document.Product.Quantity.value = Qty;
					document.Product.submit();
				}				
			}
			function ProductAddItem (iAction, Action)
			{
				document.Product.ID.value = iAction;
				document.Product.Action.value = Action;
				document.Product.submit();
			}
			function RemoveItem (iAction, Action)
			{
				document.Basket.ID.value = iAction;
				document.Basket.Action.value = Action;
				document.Basket.submit();
			}
			function RemoveAssignItem (iAction, Action)
			{
				document.ShipAssign.ID.value = iAction;
				document.ShipAssign.Action.value = Action;
				document.ShipAssign.submit();
			}
			function ClearCart (iAction, Action)
			{
				var answer = confirm ("Remove all items in cart?");
				if (answer){
					document.CartTotals.ID.value = iAction;
					document.CartTotals.Action.value = Action;
					document.CartTotals.submit();
				}
			}
			function UpdateItem (iAction, Action)
			{
				bValid = true;	
				quantity = document.getElementById('Quantity' + iAction);
				if (quantity.value < 1){
					bValid = false;
					alert("You must enter a quantity greater than or equal to 1.");
					quantity.focus();
				}
				
				if (bValid){
					document.Basket.ID.value = iAction;
					document.Basket.Action.value = Action;
					document.Basket.submit();
				}
			}
			function UpdateAssignItem (iAction, Action)
			{
				bValid = true;	
				quantity = document.getElementById('Quantity' + iAction);
				if (quantity.value < 1){
					bValid = false;
					alert("You must enter a quantity greater than or equal to 1.");
					quantity.focus();
				}
				
				if (bValid){				
					document.ShipAssign.ID.value = iAction;
					document.ShipAssign.Action.value = Action;
					document.ShipAssign.submit();
				}
			}
			function ShipAssign (Action)
			{
				document.ShipAssign.Action.value = Action;
				document.ShipAssign.submit();
			}
			function CompleteBasket (Action)
			{
				document.ShipAssign.Action.value = Action;
				document.ShipAssign.submit();
			}
			function CheckLogin()
				{
					if (document.login.Login.value == "")
					{
						alert ("Please Enter Email Address.");
						document.login.Login.focus();
					}
					else if (document.login.Password.value == "")
					{
						alert ("Please Enter your Password.");
						document.login.Password.focus();
					}		
					else
					{
						document.login.submit();
					}		
			}
			function AddAddress(iAction)
			{
				document.Address.status.value = iAction;
				bValid = true;							
				if (document.Address.First_Name.value == "")
				{
					alert ("Please enter a first name.");
					document.Address.First_Name.focus();
					bValid = false;
				}	
				else if (document.Address.Last_Name.value == "")
				{
					alert ("Please enter a last name.");
					document.Address.Last_Name.focus();
					bValid = false;
				}
				else if (document.Address.Email.value == "")
				{
					alert ("Please enter an email address.");
					document.Address.Email.focus();
					bValid = false;
				}
				else if (document.Address.Street1.value == "")
				{
					alert ("Please enter a street address 1.");
					document.Address.Street1.focus();
					bValid = false;
				}
				else if (document.Address.City.value == "")
				{
					alert ("Please enter a city.");
					document.Address.City.focus();
					bValid = false;
				}
				else if (document.Address.Phone.value == "")
				{
					alert ("Please enter a phone number.");
					document.Address.Phone.focus();
					bValid = false;
				}
				else if ((document.Address.CountryList[document.Address.CountryList.selectedIndex].value == "US") ||
						 (document.Address.CountryList[document.Address.CountryList.selectedIndex].value == "CA"))
				{
					if (document.Address.StateList[document.Address.StateList.selectedIndex].value == "")
					{
						alert ("Please select a state.");
						document.Address.StateList.focus();
						bValid = false;
					}
					else
					{
						if ((document.Address.CountryList[document.Address.CountryList.selectedIndex].value == "US") &&
							(!Validate (document.Address.Zip.value, MASK_ZIP_US)))
						{
							alert ("Please enter a valid United State zip code.");
							document.Address.Zip.focus();
							bValid = false;
						}
						else if ((document.Address.CountryList[document.Address.CountryList.selectedIndex].value == "CA") &&
							(!Validate (document.Address.Zip.value, MASK_ZIP_CA)))
						{
							alert ("Please enter a valid Canada zip code.");
							document.Address.Zip.focus();
							bValid = false;
						}	
					}
				}						
				if (bValid)
				{
					document.Address.submit();
				}
			}	
			function SaveAddress(iAction)
			{
				document.Address.status.value = iAction;
				bValid = true;							
				if (document.Address.First_Name.value == "")
				{
					alert ("Please enter your first name.");
					document.Address.First_Name.focus();
					bValid = false;
				}	
				else if (document.Address.Last_Name.value == "")
				{
					alert ("Please enter your last name.");
					document.Address.Last_Name.focus();
					bValid = false;
				}
				else if (document.Address.Street1.value == "")
				{
					alert ("Please enter street address 1.");
					document.Address.Street1.focus();
					bValid = false;
				}
				else if (document.Address.City.value == "")
				{
					alert ("Please enter city.");
					document.Address.City.focus();
					bValid = false;
				}
				else if (document.Address.Phone.value == "")
				{
					alert ("Please enter a phone number.");
					document.Address.Phone.focus();
					bValid = false;
				}
				else if ((document.Address.CountryList[document.Address.CountryList.selectedIndex].value == "US") ||
						 (document.Address.CountryList[document.Address.CountryList.selectedIndex].value == "CA"))
				{
					if (document.Address.StateList[document.Address.StateList.selectedIndex].value == "")
					{
						alert ("Please select your state.");
						document.Address.StateList.focus();
						bValid = false;
					}
					else
					{
						if ((document.Address.CountryList[document.Address.CountryList.selectedIndex].value == "US") &&
							(!Validate (document.Address.Zip.value, MASK_ZIP_US)))
						{
							alert ("Please enter a valid United State zip code.");
							document.MultiAddress.Zip.focus();
							bValid = false;
						}
						else if ((document.Address.CountryList[document.Address.CountryList.selectedIndex].value == "CA") &&
							(!Validate (document.Address.Zip.value, MASK_ZIP_CA)))
						{
							alert ("Please enter a valid Canada zip code.");
							document.Address.Zip.focus();
							bValid = false;
						}	
					}
				}						
				if (bValid)
				{
					document.Address.submit();
				}
			}	
			function DeleteAddress (iAction)
			{
				document.Address.status.value = iAction;
				document.Address.submit();
			}
			function DeleteAddressFromList (iAction,ID)
			{
				document.Address.ID.value = ID;
				document.Address.status.value = iAction;
				document.Address.submit();
			}
			function  ShipSingle1 (iAction) {
				document.Address.status.value = iAction;
				document.Address.submit();
			}
			function  ShipSingle (iAction) {
				document.Address.status.value = iAction;
					bValid = false;
			  for (var i=0;i<document.Address.SelectedAddress.length;i++) 
			  {
					if (document.Address.SelectedAddress[i].checked)
					{
						bValid = true;
					}
				}
				if (bValid)
				{
					document.Address.submit();
				}
			  else
			  {
				 alert('Select a Shipment Location.');
				 bValid = false;
				 }	
			}
			function ShipToAddress(iAction, iID) {
				document.Address.status.value = iAction;
				document.Address.ShipToId.value = iID;
				document.Address.submit();
			}
			function ShipMulti (iAction)
			{
				document.Address.status.value = iAction;
				document.Address.submit();
			}	 		
			function windowClose(){
			 popup = window.close()
			}
			function ChangeTotal (Action)
			{
				document.ShipSummary.Action.value = 7;
				document.ShipSummary.submit();
			}			
			function ShipSummary ()
			{				
				bValid = true;
				//alert (document.ShipSummary.ShippingRate4714.value);
				//alert (document.ShipSummary.LocationId.value);
				for (var i=0;i<document.ShipSummary.length;i++)
				{
				    current = document.ShipSummary.elements[i];
				    if (current.name == ("ShippingRate" + (document.ShipSummary.LocationId.value)))
						//alert ("Success! " + current.name);
						if (current.value == 0){ //Value of Select Shipping Method
							alert ("Please Select a Shipping Method");
							bValid = false;
						}
						else{ 
							bValid = true;
							//alert ("Success! Current Value = " + current.value);
						}
				}
				if (bValid)
				{
					document.ShipSummary.submit();
				}				
			}

function ValidatePayment ()
{
	bValid = true;
	if (document.Payment.cc_number.value == "")
	{
		alert ("Please enter your credit card number.");
		document.Payment.cc_number.focus();
		bValid = false;
	}
	else if (document.Payment.cc_id_code.value == "")
	{
		alert ("Please enter your credit card verification code.");
		document.Payment.cc_id_code.focus();
		bValid = false;
	}
	else if (document.Payment.cc_name.value == "")
	{
		alert ("Please enter your name.");
		document.Payment.cc_name.focus();
		bValid = false;
	}
	if (bValid)
	{
		document.Payment.submit();
		document.getElementById('processing').style.display='block';
	}
}

function CCRemoveItem (iAction, Action)
{
	document.CCBasket.ID.value = iAction;
	document.CCBasket.Action.value = Action;
	document.CCBasket.submit();
}

function CCClearCart (iAction, Action)
{
	var answer = confirm ("Remove all items in cart?");
	if (answer){
		document.CCCartTotals.ID.value = iAction;
		document.CCCartTotals.Action.value = Action;
		document.CCCartTotals.submit();
	}
}

function ValidateRange(rangeId, start, end)
{
    var bValid = true;
	var range = document.getElementById(rangeId);
	
	if (range.value == "")
	{
		alert ("Please enter a range.");
		range.focus();
		bValid = false;
	}
	else if (range.value < Number(start))
	{
		alert ("Please enter a value greater than " + start + ".");
		range.style.background = "#ffffe0";
		range.value = Number(start);
		range.focus();
		bValid = false;		
	}
	else if (range.value > Number(end))
	{
		alert ("Please enter a value less than " + end + ".");
		range.style.background = "#ffffe0";
		range.value = Number(end);
		range.focus();
		bValid = false;	
	}
	
	if (bValid == true)
	{
		if (range.value.length < end.length)
		{
			padZeroes = end.length - range.value.length;
			newRange = "";
			for (i=0; i<padZeroes; i++)
			{
				newRange += "0";
			}
			newRange += range.value;
			range.value = newRange;
		}
		range.style.background = "#ffffff";
	}
}

function ValidateUDValue(valueId, maxCount, typeId)
{

    var bValid = true;
	var range = document.getElementById(valueId);
	
	if (range.value == "")
	{
		alert ("Please enter a value.");
		range.focus();
		bValid = false;
	}
	else if (range.value.length > Number(maxCount))
	{
		alert ("Please enter a value of " + maxCount + " characters or less.");
		range.style.background = "#ffffe0";
		range.value = "";
		range.focus();
		bValid = false;		
	}
	else if (typeId == 1)
	{
		//Numeric Characters Only
		if (isNaN(range.value) == true)
		{
			alert ("Please enter numeric characters only.");
			range.style.background = "#ffffe0";
			range.value = "";
			range.focus();
			bValid = false;	
		}
	}
	else if (typeId == 2)
	{
		//Alpha Characters Only
		for( i=0; i < range.value.length; i++)
		{
			if (!(range.value.charCodeAt(i) >= 65 && range.value.charCodeAt(i) <= 90) && !(range.value.charCodeAt(i) >= 97 && range.value.charCodeAt(i) <=122))
			{
				alert ("Please enter letter characters only.");
				range.style.background = "#ffffe0";
				range.value = "";
				range.focus();
				bValid = false;	
				break;
			}
		}
	}
	else if (typeId == 3)
	{
		//AlphaNumeric Characters Only
		for( i=0; i < range.value.length; i++)
		{
			if (!(range.value.charCodeAt(i) >= 48 && range.value.charCodeAt(i) <=57) && !(range.value.charCodeAt(i) >= 65 && range.value.charCodeAt(i) <= 90) && !(range.value.charCodeAt(i) >= 97 && range.value.charCodeAt(i) <= 122))
			{
				alert ("Please enter numeric or letter characters only.");
				range.style.background = "#ffffe0";
				range.value = "";
				range.focus();
				bValid = false;	
				break;
			}		
		}
	}

	if (bValid == true)
	{
		range.style.background = "#ffffff";
	}
}

function ValidateBuildToOrder(basePrice, baseSKU)
{
	bValid = true;
	for (var i=0;i<document.BuildToOrder.length;i++)
	{
	    current = document.BuildToOrder.elements[i];
	    if (!isNaN(current.name)){
			if (current.value == ""){
				alert ("Please enter a value.");
				current.style.background = "#ffffe0";
				current.focus();
				bValid = false;
				break;
			}
		}
	}
	if (bValid)
	{
		//CalculatePricing
		CalculateBuildToOrderPrice(basePrice);
		CalculateBuildToOrderSKU(baseSKU);
	}	
}

function BuildToOrderAddToCart(basePrice, baseSKU)
{
	bValid = true;
	for (var i=0;i<document.BuildToOrder.length;i++)
	{
	    current = document.BuildToOrder.elements[i];
	    if (!isNaN(current.name)){
			if (current.value == ""){
				alert ("Please enter a value.");
				current.style.background = "#ffffe0";
				current.focus();
				bValid = false;
				break;
			}
		}
	}
	if (bValid)
	{
		//CalculatePricing
		CalculateBuildToOrderPrice(basePrice);
		CalculateBuildToOrderSKU(baseSKU);
		document.BuildToOrder.submit();
	}	
}

function CalculateBuildToOrderPrice(basePrice)
{
	//Assumes that the array pricingArray has been created by the BuildToOrder page
	//Get the first PricingGroup's VariantIdString
	var currentGroupId = "";
	var additionalCost = 0;
	var rangeValue = 0;
	for (a=0; a<pricingArray.length; a++){
		if (pricingArray[a][0] != currentGroupId){
			//Update currentGroupId
			currentGroupId = pricingArray[a][0];			
			//Does this row contain a user defined value?
			isUserDefined = pricingArray[a][5];
			
			//We know that the 3rd column of the array contains the VariantIdString
			VariantIdString = (pricingArray[a][2]).substring(0,(pricingArray[a][2]).length-1);	
			variantArray = VariantIdString.split("|");
			newValueIdString = "";
			
			//Build a string of user selected values for each variant id in the string
			//If isUserDefined, then the last variant value will be 0
			if (isUserDefined == 'True'){
				for (k=0; k < variantArray.length; k++){
					if(variantArray[k].indexOf("-") == 0){
						newValueIdString = newValueIdString + "0|";
						rangeValue = document.getElementById(variantArray[k].replace("-", "")).value;
					}
					else{
						var value = document.getElementById(variantArray[k]).value;
						newValueIdString = newValueIdString + document.getElementById(variantArray[k]).value + "|";
					}
				}				
			}
			else{
				for (k=0; k < variantArray.length; k++){
					newValueIdString = newValueIdString + document.getElementById(variantArray[k]).value + "|";
				}
			}
			
			
			//Now find this string in pricingArray
			for (i=0; i<pricingArray.length; i++){
				if ( pricingArray[i][3] == newValueIdString ){
					price = pricingArray[i][4];
					//Check if it's a multiplier
					if (pricingArray[i][6] == 'True'){
						//multiply price by the rangeValue
						additionalCost = parseFloat(additionalCost) + (parseFloat(price) * parseFloat(rangeValue));
					}
					else{
						//additional cost
						additionalCost = parseFloat(additionalCost) + parseFloat(price);
					}
				}
			}
		}
	}
	additionalCost = parseFloat(additionalCost) + parseFloat(basePrice);
	
	price = additionalCost
	result = Math.floor(price)+".";		
	var cents= 100*(price-Math.floor(price))+0.5;
	if(Math.floor(cents) == "100"){
	 cents = "0";
	 result = Math.floor(price) + 1;
	 result = result + ".";
	 }
    result += Math.floor(cents/10);
    result += Math.floor(cents%10);	
	document.getElementById("listprice").value = result;
}

function CalculateBuildToOrderSKU(baseSKU){
	var newSKU = baseSKU;
	var userSelections = "";
	for (var i=0;i<document.BuildToOrder.length;i++)
	{
	    current = document.BuildToOrder.elements[i];
	    if (!isNaN(current.name)){
			//If name doesn't contain SKU
			if ((current.name).indexOf("SKU") != 0){ 
				partialSKU = document.getElementById("SKU" + (current.value));
				userSelections = userSelections + current.name + "|";
				if (partialSKU == null){
					//we've found a user defined value
					newSKU = newSKU + current.value;
					userSelections = userSelections + "1" + "|" + current.value + "|";
				}
				else{
					newSKU = newSKU + partialSKU.value;
					userSelections = userSelections + "0" + "|" + current.value + "|";
				}
			}
		}
	}
	document.getElementById("partnum").value = newSKU;
	document.BuildToOrder.userSelections.value = userSelections;
}