function UpdateSize(item)
{
	if (item == "width")
	{
		if (isNaN(document.theForm.width.value))
		{
			alert("Your input was not a number.\r\n\r\nPlease enter your width in inches.");
			document.theForm.width.focus();
			return false;
		}
		
		if (document.theForm.prop.checked == true)
		{
			//width changed.  calculate new height.
			myR = (document.theForm.width.value / origW);
			newH = Math.round(origH * myR * 100) / 100;
			document.theForm.height.value = newH;
			newW = document.theForm.width.value;
			//alert(newH);
		}
	}
	
	if (item == "height") 
	{
		if (isNaN(document.theForm.height.value)) 
		{			
			alert("Your input was not a number.\r\n\r\nPlease enter your height in inches.");
			document.theForm.height.focus();
			return false;
		}
		else if (document.theForm.prop.checked == true)
		{
			myR = (document.theForm.height.value / origH);
			newW = Math.round(origW * myR * 100) / 100;
			document.theForm.width.value = newW;
			newH = document.theForm.height.value;
		}
	}
	document.theForm.width.value = Math.abs(document.theForm.width.value);
	document.theForm.height.value = Math.abs(document.theForm.height.value);

	if (document.theForm.prop.checked == false)
	{
		ratio = document.theForm.width.value / document.theForm.height.value;
		var maxSize = 400;
		
		if(ratio <= 1)
		{
			var newHeight = maxSize;
			var newWidth = Math.round(newHeight * ratio);
		}
		else
		{
			var newWidth = maxSize;			
			var newHeight = Math.round(newWidth / ratio);
		}
		document.images["aspimg"].height = newHeight;
		document.images["aspimg"].width = newWidth;
	}
	
	if (item == "prop" && document.theForm.prop.checked == true)
	{
		document.theForm.width.value = origW;
		document.theForm.height.value = origH;
		document.images["aspimg"].width = origWpx;
		document.images["aspimg"].height = origHpx;
	}

	if (document.theForm.width.value * document.theForm.height.value < 1)
	{
		alert("The minimum decal size is one square inch.\r\n\r\nPlease enter a larger size");
		return false;
	}

	UpdatePrice();
	return true;
}

function UpdatePrice()
{
	var W = document.theForm.width.value;
	var H = document.theForm.height.value;
	var myImg = "GetDecalPriceColor.asp?W=" + W + "&H=" + H;

	document.images.imgPrice.src = myImg;
}

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 mySubmit(myQty) 
{
	document.theForm.UseSize.value = myQty;
	document.theForm.submit();
}

function myCustomize() 
{
	w = document.theForm.CustomWidth.value;
	if (isNaN(w) == true || w < 1 || w > 999) 
	{
		alert('You must enter a valid width for your custom decal.');
		document.theForm.CustomWidth.focus();
	}
	else
	{
		h = document.theForm.CustomHeight.value;
		if (isNaN(h) == true || h < 1 || h > 999) 
		{
			alert('You must enter a valid height for your custom decal.');
			document.theForm.CustomHeight.focus();
		}
		else
		{
			// Valid size, submit specs.
			document.theForm.action = "customize_decal.asp";
			document.theForm.submit();
		}
	}
}

function CreateSignStd() 
{
	document.theForm.action = "create_std_sign.asp";
	document.theForm.submit();
}

function CreateMagnet() 
{
	document.theForm.action = "create_magnet.asp";
	document.theForm.submit();
}

function CreateBanner() 
{
	document.theForm.action = "create_banner.asp";
	document.theForm.submit();
}

function CreateLicensePlate() 
{
	document.theForm.action = "create_license_plate.asp";
	document.theForm.submit();
}

function CreateSignCustom() 
{
	w = document.theForm.CustomSignWidth.value;
	if (isNaN(w) == true || w < 2 || w > 24) 
	{
		alert('Please enter a width from 2 to 24 inches.');
		document.theForm.CustomSignWidth.focus();
	}
	else
	{
		h = document.theForm.CustomSignHeight.value;
		if (isNaN(h) == true || h < 2 || h > 24)
		{
			alert('Please enter a height from 2 to 24 inches.');
			document.theForm.CustomSignHeight.focus();
		}
		else
		{
			// Valid size, submit specs.
			document.theForm.action = "create_custom_size_sign.asp";
			document.theForm.submit();
		}
	}
}
