<!--

//
// fortheartistrecords.com
//************************
// ftar.js
// mod: 10.21.02
//
// site js functions
//
//


//* --- popup functions --- *//

function popJLMseasons()  {
  window.open("http://www.jasonlmusic.com/seasons", "seasons", "toolbar=0,status=1,menubar=0,scrollbars=1,resizable=1,width=595,height=560");
}

function popWin(url,winName,width,height)  {
  window.open(url, winName, "toolbar=0,status=1,menubar=0,scrollbars=0,resizable=1,width=" + width + ",height=" + height);
}


//* --- order page --- *//

// items, prices
var priceStr_tdoasCD = "10.00";
var priceStr_tdoasKey = "2.00";

// convert price values to 2 decimal places
function dec (value)  {
        if ( value.indexOf(".") != -1 )  {
                pos = value.indexOf(".");
		if ( value.length == pos+2 )  {
			value = value + "0";
                }  else  {
                        value = value.substring(0,pos+3);
		}
        }  else  {
                value = value + ".00";
	}
        return value;
}

function getSubtotal (order)  {
	// verify that item quantities are integers within the given range
	if (parseInt(order.quant_tdoasCD.value) >= 0 && parseInt(order.quant_tdoasKey.value) >= 0)  {
		if (order.quant_tdoasCD.value > 5)  {  // 5 is the max for TDOAS CDs
			reset(order);
	                order.quant_tdoasCD.focus();
		        alert ("To order more than 5 The Driest Of All Seasons CDs, please email \n orders@fortheartistrecords.com (the \'contact us\' link) instead of using this order form.");
			return;
		}  else if (order.quant_tdoasKey.value > 10)  {  // 10 is the max for TDOAS keychains
			reset(order);
	                order.quant_tdoasKey.focus();
		        alert ("To order more than 10 The Driest Of All Seasons Keychains, please email \n orders@fortheartistrecords.com (the \'contact us\' link) instead of using this order form.");
			return;
		}
	}  else  {
		reset(order);
		order.quant_tdoasCD.focus();
		alert ("Please use integers only!");
		return;
	}

	// set variables
	var price_tdoasCD = parseFloat(priceStr_tdoasCD);
	var quant_tdoasCD = parseInt(order.quant_tdoasCD.value);

	var price_tdoasKey = parseFloat(priceStr_tdoasKey);
	var quant_tdoasKey = parseInt(order.quant_tdoasKey.value);

	// get item subtotals and fill up variables
	var subT_tdoasCD = price_tdoasCD * quant_tdoasCD;
	var subT_tdoasCD = parseFloat(subT_tdoasCD);

	var subT_tdoasKey = price_tdoasKey * quant_tdoasKey;
	var subT_tdoasKey = parseFloat(subT_tdoasKey);

	// get items subtotal
	var subT_items = subT_tdoasCD + subT_tdoasKey;

	// get shipping subtotal
	var subTship_tdoasCD = parseFloat("0.00");
	var subTship_tdoasKey = parseFloat("0.00");

	if (quant_tdoasCD == 0)  {
		subTship_tdoasCD = parseFloat("0.00");
	}  else if (quant_tdoasCD < 4)  {
		subTship_tdoasCD = parseFloat("3.00");
	}  else  {
		subTship_tdoasCD = parseFloat("4.00");
	}

	if (quant_tdoasCD != 0 || quant_tdoasKey == 0)  {  // keychain shipping free if they order a CD too...
		subTship_tdoasKey = parseFloat("0.00");
	}  else if (quant_tdoasKey < 6)  {
		subTship_tdoasKey = parseFloat("2.00");
	}  else  {
		subTship_tdoasKey = parseFloat("3.00");
	}

	// display subtotal values
	order.subT_tdoasCD.value = dec(subT_tdoasCD.toString());
	order.subTship_tdoasCD.value = dec(subTship_tdoasCD.toString());

	order.subT_tdoasKey.value = dec(subT_tdoasKey.toString());
	order.subTship_tdoasKey.value = dec(subTship_tdoasKey.toString());

	order.total.value = "";

	// put total in temp variable and reset calculated value
	order.calculated.value = "no";
	var tempTotal = parseFloat(subT_items + subTship_tdoasCD + subTship_tdoasKey);
	order.tempTotal.value = dec(tempTotal.toString());
}

function getTotal (order)  {
	getSubtotal(order);

	// set calculated flag for the form checker
	order.calculated.value = "yes";

	// show total value from temp total
	var total = order.tempTotal.value;
	order.total.value = dec(total.toString());
}

function reset (order)  {
	order.calculated.value = "no";

	order.quant_tdoasCD.value = 0;
	order.subT_tdoasCD.value = "0.00";
	order.subTship_tdoasCD.value = "0.00";

	order.quant_tdoasKey.value = 0;
	order.subT_tdoasKey.value = "0.00";
	order.subTship_tdoasKey.value = "0.00";

	order.tempTotal.value = "0.00";
	order.total.value = "";
}

function checkOrder (order)  {
	if ((order.quant_tdoasCD.value == "" || order.quant_tdoasCD.value == 0) && (order.quant_tdoasKey.value == "" || order.quant_tdoasKey.value == 0)) {
		order.quant_tdoasCD.focus ();
		alert("Please enter a quantity for at least one item.");
	}  else if (order.calculated.value != "yes") {
		order.calculate.focus ();
		alert("Please press the \'calculate total\' button before submitting your order.");
	}  else if (order.name.value == "") {
		order.name.focus ();
		alert("Please enter your name.");
	}  else if (order.address.value == "") {
		order.address.focus ();
		alert("Please enter your street address.");
	}  else if (order.city.value == "") {
		order.city.focus ();
		alert("Please enter your city.");
	}  else if (order.state.value == "") {
		order.state.focus ();
		alert("Please enter your state.");
	}  else if (order.zip.value == "") {
		order.zip.focus ();
		alert("Please enter your zip/postal code.");
	}  else if (order.country.value == "") {
		order.country.focus ();
		alert("Please enter your country.");
	}  else if (order.email.value == "") {
		order.email.focus ();
		alert("Please enter your email address.");
	}  else if (order.phone.value == "") {
		order.phone.focus ();
		alert("Please enter your phone number.");
	}  else  {
		order.submitted.value="order";	
                order.submit();
	}
}


//-->