// JavaScript Document

function sendEmail() {
	window.open("code/email.asp","email","width=420,height=350,status=yes")
}

function VerifyForm () {
	var val = document.orderForm.state.value;
	if (document.orderForm.state.selectedIndex == "0") {
		alert ("Please select your State");
		document.orderForm.state.focus();
	    return false;
		} else {
		document.checkOut.STATE.value = val;
		document.checkOut.STATETOSHIP.value = val;
		return true;
		}	
}		 

function Go() {
CheckState();
}

function stripDollarSigns(f) {
	f = f.substring(1,f.length);
	return f;
}

function stripCommas(f) {
	f = f.replace(/,/,"");
	return f;
}

function roundCost(val) {

	if (val == 0)
	{
		return 0;
	}
	return (Math.round(val * 100) /100);
}

function formatMoney(val) {

	val = roundCost(val);
	var x = (val.toString()).indexOf(".");
	var y = (val.toString()).substring(x);
	if (y.length == 2) //This means there is only one digit after the decimal.
	{
		return (val+"0");
	}
	return (val);
}

function CheckState() {
temp = document.orderForm.state.selectedIndex;
if (temp == 10) {
		AddTax();
	    
} else if ((temp !=9) && (document.orderForm.FlSalesTax.value != "0")) {
	DeleteTax();
} else {
  var temp = document.orderForm.OrderTotal.value;
  temp = stripDollarSigns(temp);
  document.checkOut.AMOUNT.value = formatMoney(temp);
}				

return true;
}	 	
	
function AddTax  () {
var tx = .07;
var subTotal = document.orderForm.subTotal.value;
subTotal = stripDollarSigns(subTotal);
subTotal = stripCommas(subTotal);
var val = parseFloat(subTotal);
var tax = (tx * (val));
tax = Math.round(tax*100)/100;
document.orderForm.FlSalesTax.value = "$"+(formatMoney(tax));
document.orderForm.OrderTotal.value = "$"+(formatMoney((val) + tax));
document.checkOut.AMOUNT.value = formatMoney((val) + tax);

return true;
}

function DeleteTax  () {
var subTotalX = document.orderForm.FlSalesTax.value
var subTotalY = document.orderForm.OrderTotal.value
subTotalX = stripDollarSigns(subTotalX);
subTotalY = stripDollarSigns(subTotalY);
x = parseFloat(subTotalX);
y = parseFloat(subTotalY);
document.orderForm.FlSalesTax.value = "0";
document.orderForm.OrderTotal.value="$"+(formatMoney((y - x)));
document.checkOut.AMOUNT.value = formatMoney((y - x));

return true;
}
