function isFieldEmpty(inputStr)
{
	var oneChar = ""
	var isEmpty = true
	for (var i = 0; i < inputStr.length; i++)
	{
		oneChar = inputStr.charAt(i)
		if (oneChar != " " && oneChar != null && oneChar != "")
		{
		isEmpty = false
		break
		}
	}
return isEmpty
}


function ResetZip()
{
document.purchases.ZipCode.value = (' ');
Calculate();
}

function ValidateOrder()
{
if (document.purchases.Qty.options[0].selected)
	{
	alert('You have not chosen a quantity.');
	return;
	}
if ((isFieldEmpty(document.purchases.ZipCode.value)) && (!document.purchases.OutsideUS.checked))
	{
	alert('You must enter a value for your zipcode, so that we can calculate shipping costs.\nIf you just want to see the product price, please check the \"Show Price Without Shipping\" box.');
	document.purchases.Qty.options[0].selected = true;
	return;
	}	
if (!(document.purchases.OutsideUS.checked))
	{	
	var Phone1 = document.purchases.txtPhone1.value;
	var Phone2 = document.purchases.txtPhone2.value;
	var Phone3 = document.purchases.txtPhone3.value;
	document.purchases.amount.value = document.purchases.Total.value;
	document.purchases.item_number.value = document.purchases.product_name.value + ' Phone[' + Phone1 + '-' + Phone2 + '-' + Phone3 + '] Amt=' + document.purchases.Qty.value;
	document.purchases.submit();
	}
}

function toDollarsAndCents(n) 
{
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

function Calculate()
{
if ((isFieldEmpty(document.purchases.ZipCode.value)) && (!document.purchases.OutsideUS.checked))
	{
	alert('You must enter a value for your zipcode, so that we can calculate shipping costs.\nIf you only want to see the product price, please check the \"Show Price Without Shipping\" box.');
	document.purchases.Qty.options[0].selected = true;
	return;
	}

if (!(document.purchases.Qty.options[0].selected))
	{
	document.purchases.TPrice.value = (toDollarsAndCents(document.purchases.Qty.value * document.purchases.Price.value));

	if (!(isFieldEmpty(document.purchases.ZipCode.value)))
		{
		var ShipZone = CalZone(document.purchases.ZipCode.value);
		if (ShipZone == 0)
			{
			alert('Please check the zip code that you entered.\nIf it is correct then call us to complete your order because that value is not showing up in our list of valid zip codes');
			document.purchases.Qty.options[0].selected = true;
			return;
			}
		var TotShipPrice = CalShipPrice(ShipZone);	
		document.purchases.TShipping.value = (toDollarsAndCents(TotShipPrice));
		document.purchases.Total.value = toDollarsAndCents((document.purchases.TPrice.value - 0) + (document.purchases.TShipping.value - 0));
		}
		else
		{
		document.purchases.TShipping.value = ('Call for price');
		document.purchases.Total.value = (' ');
		}
	}
else
	{
	document.purchases.TPrice.value = (' ');
	document.purchases.TShipping.value = (' ');
	document.purchases.Total.value = (' ');
	}		
}


