function checkNewPassword()
{
	var theForm = document.forms['adminForm'];
	
	if (theForm.psswd1.value != theForm.psswd2.value)
	{
		alert("Passwords do not match, please verify the password entries.");
	}	
	
	else
	{
		theForm.submit();
	}
}


function validateShippingInput()
{
			
	var msg;
	var empty_fields = "";
	var numErrors = "";
	var miscErrors = "";
	var theForm = document.forms['shippingForm'];
	var checkValue1;
	var checkValue2;
	var sameCheck;
	
	theForm.shipName.display = "Shipping Name";
	theForm.shipStreet.display = "Shipping Street Address";
	theForm.shipStreet2.display = "Shipping Street Address2";
	theForm.shipCity.display = "Shipping City";
	theForm.shipState.display = "Shipping State";
	theForm.shipZip.display = "Shipping Zip Code";
	
	
	theForm.billName.display = "Billing Name";
	theForm.billStreet.display = "Billing Street Address";
	theForm.billStreet2.display = "Billing Street Address 2";
	theForm.billCity.display = "Billing City";
	theForm.billState.display = "Billing State";
	theForm.billZip.display = "Billing Zip Code";
	theForm.billPhone.display = "Phone Number";
	theForm.billEmail.display = "Email Address";
	
	
	
	if(theForm.custLogged.value == "true")
	{
		checkValue1 = theForm.billto[1].checked;
		checkValue2 = theForm.shipto[1].checked;
		sameCheck = theForm.shipto[2].checked;
	}
	
	else
	{
		checkValue1 = theForm.billto.checked;
		checkValue2 = theForm.shipto[0].checked;
		sameCheck = theForm.shipto[1].checked;
		
	}

	if(sameCheck)
	{
		theForm.sameAs.value = "true"
	}
	
		if (document.getElementById("HiddenSubmitVerify") !=null) {theForm.HiddenSubmitVerify.optional = true;}
		if (document.getElementById("txtCouponCode") !=null) {theForm.txtCouponCode.optional = true;}

	if (checkValue1)
	{
		theForm.billName.optional = false; 
		theForm.billStreet.optional = false;
		theForm.billStreet2.optional = true;
		theForm.billCity.optional = false;
		theForm.billState.optional = false;
		theForm.billZip.optional = false;
		theForm.billPhone.optional = false;
		theForm.billEmail.optional = false;
	}
	
	else
	{
		theForm.billName.optional = true; 
		theForm.billStreet.optional = true;
		theForm.billStreet2.optional = true;
		theForm.billCity.optional = true;
		theForm.billState.optional = true;
		theForm.billZip.optional = true;
		theForm.billPhone.optional = true;
		theForm.billEmail.optional = true;
	}
	
	if (checkValue2)
	{
		theForm.shipName.optional = false; 
		theForm.shipStreet.optional = false;
		theForm.shipStreet2.optional = true;
		theForm.shipCity.optional = false;
		theForm.shipState.optional = false;
		theForm.shipZip.optional = false;		
	}
	
	else
	{
		theForm.shipName.optional = true; 
		theForm.shipStreet.optional = true;
		theForm.shipStreet2.optional = true;
		theForm.shipCity.optional = true;
		theForm.shipState.optional = true;
		theForm.shipZip.optional = true;
	}
	
	
	if (theForm.addrEntered.value == "true")
	{
		theForm.ccNum.display = "Credit Card Number";
		theForm.ccExp.display = "Credit Card Expiration";
		theForm.ccNum.number = true;
		
		if (theForm.ccNum.value.length < 15)
		{
			miscErrors += "Please Enter a valid credit card number, at least 15 characters long.";
			
		}
		
		if (theForm.ccExp.value.length < 5)
		{
			miscErrors += "The credit card expiration date must be in the following format: MM/YY.";
			
		}
	}
	
	for (var i = 0; i < theForm.length; i++)
	{
		var e = theForm.elements[i];
		
		if(((e.type == "text") || (e.type == "textarea") ||  (e.type == "select-one" && e.name != "ccType")) && !e.optional)
		{
			if ((e.value == null) || (e.value == "") || (e.value == "0"))
			{
				//alert(e.name);
				empty_fields += "\n			" + e.display;
				continue;
			}
		}
		
		
		if(e.decimal)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
			
			else
			{
				e.value = formatCurrency2(e.value);
			}
		}			
		
		if(e.number)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
		}
		
		if(e.value.length > e.maxlength)
		{
			miscErrors += "\n'" + e.display + "' cannot exceed " + e.maxlength + " characters.\n";
		}
	}
	
	
	if(!empty_fields && !numErrors && !miscErrors)
	{		
		if (document.getElementById("HiddenSubmitVerify") !=null)
		{
			theForm.HiddenSubmitVerify.value='true';
		}
		return true;
	}
	
	msg = "_________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_________________________________________________________\n\n";
	
	if (empty_fields)
	{
		msg += "The following required field(s) are empty:" + empty_fields + "\n";
	}
	
	if(numErrors)
	{
		msg += "\nThe following field(s) must contain a numeric value:" + numErrors + "\n";
	}
	
	if(miscErrors)
	{
		msg += "\n" + miscErrors;
	}
	
	alert(msg);
	return false;

}



function validateShippingInput1()
{
		
		
	var msg;
	var empty_fields = "";
	var numErrors = "";
	var miscErrors = "";
	var theForm = document.forms['shippingForm'];
	var checkValue1;
	var checkValue2;
	var sameCheck;
	
	theForm.shipName.display = "Shipping Name";
	theForm.shipStreet.display = "Shipping Street Address";
	theForm.shipStreet2.display = "Shipping Street Address2";
	theForm.shipCity.display = "Shipping City";
	theForm.shipState.display = "Shipping State";
	theForm.shipZip.display = "Shipping Zip Code";
	
	
	theForm.billName.display = "Billing Name";
	theForm.billStreet.display = "Billing Street Address";
	theForm.billStreet2.display = "Billing Street Address 2";
	theForm.billCity.display = "Billing City";
	theForm.billState.display = "Billing State";
	theForm.billZip.display = "Billing Zip Code";
	theForm.billPhone.display = "Phone Number";
	theForm.billEmail.display = "Email Address";
	
	
	
	if(theForm.custLogged.value == "true")
	{
		checkValue1 = theForm.billto[1].checked;
		checkValue2 = theForm.shipto[1].checked;
		sameCheck = theForm.shipto[2].checked;
	}
	
	else
	{
		checkValue1 = theForm.billto.checked;
		checkValue2 = theForm.shipto[0].checked;
		sameCheck = theForm.shipto[1].checked;
		
	}

	if(sameCheck)
	{
		theForm.sameAs.value = "true"
	}
	
		if (document.getElementById("HiddenSubmitVerify") !=null) {theForm.HiddenSubmitVerify.optional = true;}
		if (document.getElementById("txtCouponCode") !=null) {theForm.txtCouponCode.optional = true;}

	if (checkValue1)
	{
		theForm.billName.optional = false; 
		theForm.billStreet.optional = false;
		theForm.billStreet2.optional = true;
		theForm.billCity.optional = false;
		theForm.billState.optional = false;
		theForm.billZip.optional = false;
		theForm.billPhone.optional = false;
		theForm.billEmail.optional = false;
	}
	
	else
	{
		theForm.billName.optional = true; 
		theForm.billStreet.optional = true;
		theForm.billStreet2.optional = true;
		theForm.billCity.optional = true;
		theForm.billState.optional = true;
		theForm.billZip.optional = true;
		theForm.billPhone.optional = true;
		theForm.billEmail.optional = true;
	}
	
	if (checkValue2)
	{
		theForm.shipName.optional = false; 
		theForm.shipStreet.optional = false;
		theForm.shipStreet2.optional = true;
		theForm.shipCity.optional = false;
		theForm.shipState.optional = false;
		theForm.shipZip.optional = false;		
	}
	
	else
	{
		theForm.shipName.optional = true; 
		theForm.shipStreet.optional = true;
		theForm.shipStreet2.optional = true;
		theForm.shipCity.optional = true;
		theForm.shipState.optional = true;
		theForm.shipZip.optional = true;
	}
	
	
	
	
	for (var i = 0; i < theForm.length; i++)
	{
		var e = theForm.elements[i];
		
		if(((e.type == "text") || (e.type == "textarea") ||  (e.type == "select-one")) && !e.optional)
		{
			if ((e.value == null) || (e.value == "") || (e.value == "0"))
			{
				
				empty_fields += "\n			" + e.display;
				continue;
			}
		}
		
		
		if(e.decimal)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
			
			else
			{
				e.value = formatCurrency2(e.value);
			}
		}			
		
		if(e.number)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
		}
		
		if(e.value.length > e.maxlength)
		{
			miscErrors += "\n'" + e.display + "' cannot exceed " + e.maxlength + " characters.\n";
		}
	}
	
	
	if(!empty_fields && !numErrors && !miscErrors)
	{		
		if (document.getElementById("HiddenSubmitVerify") !=null)
		{
			theForm.HiddenSubmitVerify.value='true';
		}
		return true;
	}
	
	msg = "_________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_________________________________________________________\n\n";
	
	if (empty_fields)
	{
		msg += "The following required field(s) are empty:" + empty_fields + "\n";
	}
	
	if(numErrors)
	{
		msg += "\nThe following field(s) must contain a numeric value:" + numErrors + "\n";
	}
	
	if(miscErrors)
	{
		msg += "\n" + miscErrors;
	}
	
	alert(msg);
	return false;

}

function submitVerify()
{
	if (validateShippingInput())
	{
		var theForm = document.forms['shippingForm'];
		theForm.submit();
	}

}

function changeState()
{	
	var theForm = document.forms['shippingForm'];
	var orderCost = 0;
	var taxes = 0;
	var checkValue
	
	if(theForm.custLogged.value == "true")
	{
		orderCost = Number(theForm.orderCost.value.split("$")[1])
		checkValue = theForm.billto[1].checked
	}
	
	else
	{
		checkValue = theForm.billto.checked

		if (theForm.addrEntered.value == "true")
		{
			orderCost = Number(theForm.orderCost.value.split("$")[1])
		}
	}
	
	if (checkValue)
	{
		if (theForm.billState.value == "WA")
		{
			taxes = orderCost * 0.079;
		}
		
		/*
		else if (theForm.billState.value == "IN")
		{
			taxes = orderCost * 0.06;
		}
		*/
		else
		{
			taxes = 0;
		}
		
		theForm.taxCost.value = formatCurrency(taxes);
		changeShipping();
	}
	else
	{
		
		if (theForm.stateBillHolder.value == "WA")
		{
			taxes = orderCost * 0.079;
		}
		
		else if (theForm.stateBillHolder.value == "IN")
		{
			taxes = orderCost * 0.06;
		}
		
		else
		{
			taxes = 0;
		}
		
		theForm.taxCost.value = formatCurrency(taxes);
	}
}

function changeShipping()
{
	var theForm = document.forms['shippingForm'];
	
	for (var i=0; i < theForm.shipping_method.length; i++)
	{
		if (theForm.shipping_method[i].checked)
		{
			var orderCost = Number(theForm.orderCost.value.split("$")[1]);
			var Discount = Number(theForm.orderDiscount.value.split("$")[1]);
			var shipAry = theForm.shipping_method[i].value.split("~");
			var shippingCost = Number(shipAry[1]);			
			var taxes = Number(theForm.taxCost.value.split("$")[1])
			theForm.shipCost.value = formatCurrency(shippingCost);
			var total = Number(orderCost + shippingCost + taxes - Discount);
			theForm.totalCost.value = formatCurrency(total);
		}		
	}	
}

function addRelatedProduct()
{
	var theForm = document.forms['productForm'];
	theForm.action = "product.aspx?func=relateprod&prodID="+theForm.prod_id.value+"&relateID="+theForm.related_prod_list.value;
	theForm.submit();
	return true;
}

function removeRelatedProduct()
{
	var theForm = document.forms['productForm'];
	theForm.action = "product.aspx?func=unrelateprod&prodID="+theForm.prod_id.value+"&relateID="+theForm.related_products.value;
	theForm.submit();
	return true;
}

function checkAddProduct()
{
	var theForm = document.forms['productForm'];
	var fieldNames = "";
	var errorMsg = "";
	var quantityError = "";
	
	if (document.forms['productForm'].quantityShow.value == "show")
	{
		if (theForm.prod_quantity.value <= 0)
		{
			quantityError = "\n\nPlease enter a valid quantity:"
			quantityError += "\n" + theForm.prod_quantity.value + " is not a valid entry";
		}
	}
	
	if(!fieldNames && !quantityError)
	{
		theForm.action = "product.aspx?func=addline&prodID=" + theForm.product_id.value;
		theForm.submit();
		return true;
	}
	
	else
	{
		errorMsg = "_________________________________________________________\n\n";
		errorMsg += "The item was not added because of the following error(s).\n"
		errorMsg += "Please correct these error(s) and re-submit.\n";
		errorMsg += "_________________________________________________________\n\n";
		errorMsg += "Please select a value for the following option(s):" + fieldNames;
		errorMsg += quantityError;
		alert(errorMsg);
	}
}

function checkUpdateProduct()
{
	var theForm = document.forms['productForm'];
	//var styleBoxes= theForm.stylesHolder.value;
	//var strArray = styleBoxes.split("~");
	var fieldNames = "";
	var errorMsg = "";
	var quantityError = "";
	
	//for (count = 0; count < strArray.length-1; count++)
	//{
		//if(theForm[strArray[count]].selectedIndex == 0)
		//{
			//var styleName = theForm[strArray[count]].value.split("~")[3];
			//fieldNames += "\n" + styleName;
		//}
	//}
	
	if (document.forms['productForm'].quantityShow.value == "show")
	{
		if (theForm.prod_quantity.value <= 0)
		{
			quantityError = "\n\nPlease enter a valid quantity:"
			quantityError += "\n" + theForm.prod_quantity.value + " is not a valid entry";
		}
	}
	
	if(!fieldNames && !quantityError)
	{
		theForm.action = "cart.aspx?func=updateline";
		theForm.submit();
		return true;
	}
	
	else
	{
		errorMsg = "_________________________________________________________\n\n";
		errorMsg += "The item was not added because of the following error(s).\n"
		errorMsg += "Please correct these error(s) and re-submit.\n";
		errorMsg += "_________________________________________________________\n\n";
		errorMsg += "Please select a value for the following option(s):" + fieldNames;
		errorMsg += quantityError;
		alert(errorMsg);
	}
}

function showDiscounts(style)
{
	window.location = "pricing.aspx?func=view&disc=" + document.forms['prodChange'].prodView.value + "&styleID=" + style;
}

function showPrice()
{	
	if (document.forms['productForm'].quantityShow.value == "show")
	{
		var styleBoxes = document.forms['productForm'].stylesHolder.value;
		var prodQuantity = Number(document.forms['productForm'].prod_quantity.value);
		var disval = Number(document.forms['productForm'].product_discount.value);
		var newPrice = 0;
		var productPrice = 0;
		var strArray = styleBoxes.split("~");
		var temp;
		var temp2;
		
		if (isNaN(prodQuantity))
		{
			alert("Quanity must contain a numeric value.");
			document.forms['productForm'].prod_price.value = formatCurrency(0);
			return false;
		}
		
		if(strArray.length == 1)
		{
			productPrice = document.forms['productForm']['product_price'].value;
		}
		
		else
		{
			temp = document.forms['productForm'][strArray[0]].value;
			temp2 = temp.split("~");
			productPrice = temp2[1];
		}
		
		newPrice = prodQuantity * productPrice;
		disval = newPrice * disval/100;
		newPrice1 = newPrice - disval;
		
		if(newPrice != 0)
		{
			document.forms['productForm'].prod_price.value = formatCurrency(newPrice);
		}
		if(newPrice1 != 0 && document.forms['productForm'].prod_price1 != null)
		{
			document.forms['productForm'].prod_price1.value = formatCurrency(newPrice1);
		}
	}
	
	else
	{
		var styleBoxes = document.forms['productForm'].stylesHolder.value;
		var prodQuantity = 1;
		var newPrice = 0;
		var productPrice = 0;
		var strArray = styleBoxes.split("~");
		var temp;
		var temp2;
		
		if (isNaN(prodQuantity))
		{
			alert("Quanity must contain a numeric value.");
			document.forms['productForm'].prod_price.value = formatCurrency(0);
			return false;
		}
		
		if(strArray.length == 1)
		{
			productPrice = document.forms['productForm']['product_price'].value;
		}
		
		else
		{
			temp = document.forms['productForm'][strArray[0]].value;
			temp2 = temp.split("~");
			productPrice = temp2[1];
		}
		
		newPrice = prodQuantity * productPrice;
		
		if(newPrice != 0)
		{
			document.forms['productForm'].prod_price.value = formatCurrency(newPrice);
		}
	}
}

function calcPrice(productPrice, priceMode)
{
	var styleBoxes = document.forms['productForm'].stylesHolder.value;
	var discounts = document.forms['productForm'].discountNames.value;
	
	var strArray = styleBoxes.split("~");
	var discArray = discounts.split("~");
	
	var percentDisc = 0;
	var amountDisc = 0;
	var percentPush = 0;
	var amountPush = 0;
	
	var prodQuantity = Number(document.forms['productForm'].prod_quantity.value);
	
	if (isNaN(prodQuantity))
	{
		alert("Quanity must contain a numeric value.");
		document.forms['productForm'].prod_price.value = formatCurrency(0);
		return false;
	}

	if (priceMode = "retail")
	{
		if (strArray.length == 1)
		{
			var newP = prodQuantity * productPrice;
			document.forms['productForm'].prod_price.value = formatCurrency(newP);
			return true;
		}
		
		for (count = 0; count < strArray.length-1; count++)
		{
			var temp;
			var temp2;
			
			temp = document.forms['productForm'][strArray[count]].value;
			temp2 = temp.split("~");
			
			if(temp2[1] != 0)
			{
				var newP = prodQuantity * temp2[1];
				document.forms['productForm'].prod_price.value = formatCurrency(newP);
			}
		}
	}
	
	else
	{
		for (count = 0; count < strArray.length-1; count++)
		{
			var temp;
			var temp2;
			
			temp = document.forms['productForm'][strArray[count]].value;
			temp2 = temp.split("~");
			
			if (temp2[0] == "percent")
			{
				percentPush += Number(temp2[1]);
			}
			
			else if (temp2[0] == "amount")
			{
				amountPush += Number(temp2[1]);
			}
			
			else
			{
				document.forms['productForm'].prod_price.value = formatCurrency(0);
				return formatCurrency(0);
			}
		}
		
		for (numDisc = 0; numDisc < discArray.length-1; numDisc++)
		{
			var discTemp;
			var discTemp2;
			
			discTemp = document.forms['productForm'][discArray[numDisc]].value;
			discTemp2 = discTemp.split("~");
			
			if(discTemp2[3] == "prod")
			{				
				if(prodQuantity >= Number(discTemp2[0]))
				{
					if (discTemp2[1] == "Percent" && discTemp2[1])
					{
						percentDisc += Number(discTemp2[2]);
					}
					
					else
					{
						amountDisc += Number(discTemp2[2]);
					}
				}
			}
			
			var currentDiscount = 0;
			
			if(discTemp2[3] == "price")
			{
				strArray = styleBoxes.split("~");
				
				for (count = 0; count < strArray.length-1; count++)
				{
					var priceTemp = document.forms['productForm'][strArray[count]].value;
					var priceTemp2 = priceTemp.split("~");
					
					if(discTemp2[4] == priceTemp2[2])
					{
						if(prodQuantity >= Number(discTemp2[0]))
						{
							if (Number(discTemp2[0]) >= currentDiscount)
							{
								percentDisc = 0;
								amountDisc = 0;
							}
							
							if (discTemp2[1] == "Percent" && discTemp2[1])
							{
								percentDisc += Number(discTemp2[2]);
							}
							
							else
							{
								amountDisc += Number(discTemp2[2]);
							}
						}
					}
				}
			}
		}

		var newPrice = parseFloat(productPrice + amountPush + ((percentPush/100) * productPrice));
		newPrice -= parseFloat((percentDisc/100) * productPrice);		
		newPrice -= parseFloat(amountDisc);
		newPrice *= prodQuantity;
		document.forms['productForm'].prod_price.value = formatCurrency(newPrice);
		
		return newPrice;
	}
}

function trace(str)
{
	alert(str);
}

function confimDelete(msg)
{
	return confirm(msg);
}

function submitSuper(formName)
{
	var theForm = document.forms[formName];
	var empty_fields = "";
	var numErrors = "";
	var miscErrors = "";
	
	theForm.disc_quantity.display = "Discount Quantity";
	theForm.disc_quantity.required = true;
	theForm.disc_quantity.number = true;
	
	theForm.disc_amount.display = "Discount Amount";
	theForm.disc_amount.required = true;
	theForm.disc_amount.number = true;
	
	for (var i = 0; i < theForm.length; i++)
	{
		var e = theForm.elements[i];
		
		if(e.required)
		{
			if ((e.value == null) || (e.value == ""))
			{
				empty_fields += "\n			" + e.display;
				continue;
			}
		}
		
		if(e.number)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
		}
		
	}
	
	if(!empty_fields && !numErrors && !miscErrors)
	{		
		theForm.submit();
		return true;
	}
	
	msg = "_________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_________________________________________________________\n\n";
	
	if (empty_fields)
	{
		msg += "The following required field(s) are empty:" + empty_fields + "\n";
	}
	
	if(numErrors)
	{
		msg += "\nThe following field(s) must contain a numeric value:" + numErrors + "\n";
	}
	
	if(miscErrors)
	{
		msg += "\n" + miscErrors;
	}
	
	alert(msg);
	return false;
	
}

function submitDiscForm(formName)
{
	var theForm = document.forms[formName];
	var empty_fields = "";
	var numErrors = "";
	var miscErrors = "";
	
	theForm.discAmount.display = "Discount Amount";
	theForm.discAmount.required = true;
	theForm.discAmount.number = true;
	
	theForm.discQuantity.display = "Discount Quantity";
	theForm.discQuantity.required = true;
	theForm.discQuantity.number = true;
	
	
	for (var i = 0; i < theForm.length; i++)
	{
		var e = theForm.elements[i];
		
		if(e.required)
		{
			if ((e.value == null) || (e.value == ""))
			{
				empty_fields += "\n			" + e.display;
				continue;
			}
		}
		
		if(e.number)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
			
			else
			{
				e.value = formatCurrency2(e.value);
			}
		}
		
	}
	
	if(!empty_fields && !numErrors && !miscErrors)
	{		
		theForm.submit();
		return true;
	}
	
	msg = "_________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_________________________________________________________\n\n";
	
	if (empty_fields)
	{
		msg += "The following required field(s) are empty:" + empty_fields + "\n";
	}
	
	if(numErrors)
	{
		msg += "\nThe following field(s) must contain a numeric value:" + numErrors + "\n";
	}
	
	if(miscErrors)
	{
		msg += "\n" + miscErrors;
	}
	
	alert(msg);
	return false;
}

function doSubmit2(formName)
{
	var theForm = document.forms[formName];
	//theForm.onsubmit();
	theForm.submit();
}

function submitStyleForm(formName)
{
	var theForm = document.forms[formName];
	var empty_fields = "";
	var numErrors = "";
	var miscErrors = "";
	
	theForm.styleName.display = "Style Name";
	theForm.styleName.required = true;
	
	
	for (var i = 0; i < theForm.length; i++)
	{
		var e = theForm.elements[i];
		
		if(e.required)
		{
			if ((e.value == null) || (e.value == ""))
			{
				empty_fields += "\n			" + e.display;
				continue;
			}
		}
		
		if(e.number)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
			
			else
			{
				e.value = formatCurrency2(e.value);
			}
		}
		
	}
	
	if(!empty_fields && !numErrors && !miscErrors)
	{		
		theForm.submit();
		return true;
	}
	
	msg = "_________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_________________________________________________________\n\n";
	
	if (empty_fields)
	{
		msg += "The following required field(s) are empty:" + empty_fields + "\n";
	}
	
	if(numErrors)
	{
		msg += "\nThe following field(s) must contain a numeric value:" + numErrors + "\n";
	}
	
	if(miscErrors)
	{
		msg += "\n" + miscErrors;
	}
	
	alert(msg);
	return false;
}

function submitPriceForm(formName)
{
	var theForm = document.forms[formName];
	var empty_fields = "";
	var numErrors = "";
	var miscErrors = "";

	theForm.priceName.display = "Price Name";
	theForm.priceName.required = true;
	theForm.wholesaleAmount.display = "Wholesale Price";
	theForm.wholesaleAmount.required = true;
	theForm.wholesaleAmount.number = true;
	theForm.retailAmount.display = "Retail Price";
	theForm.retailAmount.required = true;
	theForm.retailAmount.number = true;
	theForm.prodWeight.display = "Product Weight";
	theForm.prodWeight.required = true;
	theForm.prodWeight.number = true;
	
	/*
	if (formName = "addStyleForm")
	{
		theForm.styleName.display = "Style Name";
		theForm.styleName.required = true;
	}
	
	if (formName = "editStyleForm")
	{
		theForm.styleName.display = "Style Name";
		theForm.styleName.required = true;
	}
	*/
	
	for (var i = 0; i < theForm.length; i++)
	{
		var e = theForm.elements[i];
		
		if(e.required)
		{
			if ((e.value == null) || (e.value == ""))
			{
				empty_fields += "\n			" + e.display;
				continue;
			}
		}
		
		if(e.number)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
			
			else
			{
				e.value = formatCurrency2(e.value);
			}
		}
		
	}
	
	if(!empty_fields && !numErrors && !miscErrors)
	{		
		theForm.submit();
		return true;
	}
	
	msg = "_________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_________________________________________________________\n\n";
	
	if (empty_fields)
	{
		msg += "The following required field(s) are empty:" + empty_fields + "\n";
	}
	
	if(numErrors)
	{
		msg += "\nThe following field(s) must contain a numeric value:" + numErrors + "\n";
	}
	
	if(miscErrors)
	{
		msg += "\n" + miscErrors;
	}
	
	alert(msg);
	return false;
}


function doSubmit()
{
	var theForm = document.forms['productForm'];
	theForm.onsubmit();
	theForm.submit();
}


function validateeventInput()
{
	var msg;
	var empty_fields = "";
	var numErrors = "";
	var miscErrors = "";
	var theForm = document.forms['eventform'];
	theForm.onsubmit();
	
	
    theForm.event_title.display = "Event Title";
    theForm.event_desc.display = "Event Description";
    theForm.event_date.display = "Event Startdate";
    theForm.end_date.display = "Event enddate";
    theForm.city.display = "City";
    theForm.event_image.display = "Image";
    theForm.url.display = "Url";
    theForm.url_label.display = "Url label";
    theForm.pdf.display = "Pdf";
    theForm.pdf_label.display = "pdf label";
    theForm.date_deactive.display = "Deactive Date";
    
    //theForm.prod_width.display = "Width";
    //theForm.prod_height.display = "Height";
    //theForm.prod_depth.display = "Depth";
    for (var i = 0; i < theForm.length; i++)
	{
		var e = theForm.elements[i];
		
		if(((e.type == "text") || (e.type == "textarea")) && !e.optional)
		{
			if ((e.value == null) || (e.value == ""))
			{
				empty_fields += "\n			" + e.display;
				continue;
			}
		}
		
		if(e.decimal)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
			
			else
			{
				e.value = formatCurrency2(e.value);
			}
		}			
		
		if(e.number)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
		}
		
		if (e.maxlength != undefined)
		{
			var temp = stripHTML(e.value);
			if(temp.length > e.maxlength)
			{
				miscErrors += "\n'" + e.display + "' cannot exceed " + e.maxlength + " characters.\n";
			}
		}
	}
	
	if(!empty_fields && !numErrors && !miscErrors)
	{
		theForm.submit();
		return true;
	}
	
	msg = "_________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_________________________________________________________\n\n";
	
	if (empty_fields)
	{
		msg += "The following required field(s) are empty:" + empty_fields + "\n";
	}
	
	if(numErrors)
	{
		msg += "\nThe following field(s) must contain a numeric value:" + numErrors + "\n";
	}
	
	if(miscErrors)
	{
		msg += "\n" + miscErrors;
	}
	
	alert(msg);
	return false;
}

function validateProductInput()
{
	var msg;
	var empty_fields = "";
	var numErrors = "";
	var miscErrors = "";
	var theForm = document.forms['productForm'];
	theForm.onsubmit();
	
	
    theForm.prod_title.display = "Product Title";
    theForm.prod_desc.display = "Product Description";
    theForm.prod_shortdesc.display = "Product Short Description";
    theForm.prod_wholesaledesc.display = "Wholesale Description";
    theForm.prod_wprice.display = "Wholesale Price";
    theForm.prod_rprice.display = "Retail Price";
    theForm.prod_image.display = "Image";
    theForm.prod_thumb.display = "Thumbnail";
    theForm.prod_alt.display = "Alternate Image";
    theForm.prod_pounds.display = "Pounds";
    theForm.prod_ounces.display = "Ounces";
    //theForm.prod_width.display = "Width";
    //theForm.prod_height.display = "Height";
    //theForm.prod_depth.display = "Depth";
    theForm.prod_sku.display = "Product SKU"; 
    theForm.prod_rprice.decimal = true;
    theForm.prod_wprice.decimal = true;
    theForm.prod_pounds.number = true;
    theForm.prod_ounces.number = true;
    //theForm.prod_width.number = true;
    //theForm.prod_height.number = true;
    //theForm.prod_depth.number = true;
    theForm.prod_alt.optional = true;
    theForm.prod_desc.optional = false;
    theForm.prod_sku.optional = false;
    theForm.prod_wholesaledesc.optional = true;
    theForm.prod_shortdesc.optional = false;
    //theForm.related_products.optional = true;
    //theForm.related_cats.optional = true;
    theForm.prod_shortdesc.maxlength = 60;
	theForm.prod_wprice.decimal = true;
	
	for (var i = 0; i < theForm.length; i++)
	{
		var e = theForm.elements[i];
		
		if(((e.type == "text") || (e.type == "textarea")) && !e.optional)
		{
			if(e.name != "wsprice" && e.name != "rsprice")
			{
				if ((e.value == null) || (e.value == ""))
				{
					empty_fields += "\n			" + e.display;
					continue;
				}
			}
		}
		
		if(e.decimal)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
			
			else
			{
				e.value = formatCurrency2(e.value);
			}
		}			
		
		if(e.number)
		{
			if(isNaN(e.value))
			{
				numErrors += "\n			" + e.display;
			}
		}
		
		if (e.maxlength != undefined)
		{
			var temp = stripHTML(e.value);
			if(temp.length > e.maxlength)
			{
				miscErrors += "\n'" + e.display + "' cannot exceed " + e.maxlength + " characters.\n";
			}
		}
	}
	
	if(!empty_fields && !numErrors && !miscErrors)
	{
		theForm.submit();
		return true;
	}
	
	msg = "_________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "_________________________________________________________\n\n";
	
	if (empty_fields)
	{
		msg += "The following required field(s) are empty:" + empty_fields + "\n";
	}
	
	if(numErrors)
	{
		msg += "\nThe following field(s) must contain a numeric value:" + numErrors + "\n";
	}
	
	if(miscErrors)
	{
		msg += "\n" + miscErrors;
	}
	
	alert(msg);
	return false;
}

// Steve's megarad übersimple image swapper
function swap(image) 
{
	(image.src.indexOf("_on") > 0) ? image.src = image.src.substring(0, image.src.lastIndexOf('/') + 1) + image.name + image.src.substring(image.src.lastIndexOf('.'), image.src.length) : image.src = image.src.substring(0, image.src.lastIndexOf('/') + 1) + image.name + "_on" + image.src.substring(image.src.lastIndexOf('.'), image.src.length);
}

function stripSearch()
{
	var theForm = document.forms['search'];
	theForm.search.value = stripHTML(theForm.search.value);
	theForm.submit();
}

function PopUp(ref)
{
	var strFeatures="toolbar=no,status<wbr>=no,menubar=no,location=no"
	strFeatures=strFeatures+",scrollbars=no,resizable=no<wbr>,height=520,width=770, left=200, top=100"
	//this part edits the properties of the popup window, left and top are the (x,y) position    
	newWin = window.open(ref,"TellObj",strFeatures);
	newWin.opener = top;
}

function stripHTML(stringIn)
{
  var regExp=/<\S[^><]*>/g;
  var temp ="";
  temp = stringIn.replace(regExp,"");
  return temp;
}


function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function formatCurrency2(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function checkFPForm() {
	var f = document.forms["forgot_password"].elements["email"];
	if (f.value.length < 6) {
		alert("Please enter a valid e-mail address.");
		f.value = "";
		f.focus();
		return false;
	}
	return true;
}

function showTerms()
{
	showLayer("terms");
}

function showLayer(whichLayer) 
{
	if (document.getElementById) 
	{
		// nice browsers
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display = "block";
	}
	else if (document.all) 
	{
		// ie
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display = "block";
	}
	else if (document.layers) 
	{
		// good ol netscape4
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display = "block";
	}
}

function moveScreens()
{

	if (document.getElementById) 
	{
		// nice browsers
		var style2 = document.getElementById("screenHolder");
		var style1 = document.getElementById("screens2");
		
		style1.style.left = style2.style.left + 100;
		style1.y = style2.y;
		
	}
	else if (document.all) 
	{
		// ie
		var style2 = document.all["screenHolder"];
		var style1 = document.all["screens2"];
		style1.x = style2.x + 200 + "px";
		style1.y = style2.y;
		
	}
	else if (document.layers) 
	{
		// good ol netscape4
		var style2 = document.layers["screenHolder"];
		var style1 = document.layers["screens2"];

		style1.x = style2.x;
		style1.y = style2.y;
		
	}
}