// JavaScript Document

// BEGIN: Form controls
function enableSShield()
{
	if ( document.quote.chk_StainShield.checked )
		{ document.quote.txt_stnShield.disabled=false; }
	else
		{ document.quote.txt_stnShield.disabled=true; }
}
function enableSSofa()
{
	if (document.quote.chk_Sectional.checked)
		{ document.quote.drp_Sectional.disabled=false; }
	else
		{ document.quote.drp_Sectional.disabled=true; }
}
function enableValances()
{
	if (document.quote.chk_Valances.checked)
		{ document.quote.txt_addValFt.disabled=false; }
	else
		{ document.quote.txt_addValFt.disabled=true; }
}
function evalBlinds()
{
	if ( document.quote.drp_blndPackage.value == 1 )
		{ document.quote.txt_indBlind.disabled=false; }
	else
		{ document.quote.txt_indBlind.disabled=true; }
}
function set0(field)
{
	with (field)
	{
		if ( value==null || value==""|| value < 0 || isNaN(value) )
		{ value=0; }
	}
}
// END: Form Controls

// BEGIN: Quote calculations

function getQuote() {

	var priceTotal = 0;
	var form = document.quote ; // Set form value simply to save typing
	form.Submit.disabled=false;	// Enable the send button (initially disabled to assure customer will see a quote before sending it)

	var	priceRoom;	//Calculated using room function
	
// Calculate number of rooms
	var roomCnt = parseInt(form.drp_living.value) + parseInt(form.drp_dining.value) + parseInt(form.drp_family.value) + parseInt(form.drp_den.value) + parseInt(form.drp_bath.value) + parseInt(form.drp_bed.value);

switch(roomCnt) {
	case 0:	priceRoom = 0 + (parseFloat(form.txt_stairs.value) * 4); break;
	case 1:	priceRoom = 104.95 + (parseFloat(form.txt_stairs.value) * 4); break;
	case 2:	priceRoom = 149.95 + (parseFloat(form.txt_stairs.value) * 4); break;
	default:
		priceRoom = 149.95 + ((roomCnt - 2) * 60) + (parseFloat(form.drp_kitchen.value) * 40) + (parseFloat(form.txt_stairs.value) * 4);
		break;
}

	var	priceBlinds = 0;	//Calculated using blind function
	
//Blind function

var blindNum = parseInt(form.drp_blndPackage.value);

//Evaluate value of Blind Package dropdown
switch (blindNum) {
	case 5:		priceBlinds = 149.95 + (parseFloat(form.txt_indWoodBlind.value) * 45); break;
	case 10:	priceBlinds = 299.95 + (parseFloat(form.txt_indWoodBlind.value) * 45); break;
	case 15:	priceBlinds = 399.95 + (parseFloat(form.txt_indWoodBlind.value) * 45); break;
	case 20:	priceBlinds = 499.95 + (parseFloat(form.txt_indWoodBlind.value) * 45); break;
	case 0:		priceBlinds = (parseFloat(form.txt_indWoodBlind.value) * 45); break;
	case 1:		priceBlinds = (parseFloat(form.txt_indBlind.value) * 40) + (parseFloat(form.txt_indWoodBlind.value) * 45); break;
}
	

var	priceWindows = 0;

// Calculate window prices
	
if ( (parseFloat(form.txt_add1Pane.value) <= 20) && (parseFloat(form.txt_add1Pane.value) >= 1) ) { priceWindows += 199.95; }
if ( (parseFloat(form.txt_add2Pane.value) <= 20) && (parseFloat(form.txt_add2Pane.value) >= 1) ) { priceWindows += 399.95; }
if (parseFloat(form.txt_add1Pane.value) > 20) { priceWindows = 199.95 + ((parseFloat(form.txt_add1Pane.value) - 20) * 12); }
if (parseFloat(form.txt_add2Pane.value) > 20) { priceWindows = 399.95 + ((parseFloat(form.txt_add1Pane.value) - 20) * 17.5); }

var priceSectional = 0;

if (form.chk_Sectional.checked) { priceSectional = ((parseFloat(form.drp_Sectional.value) - 3) * 50) + 199.95 ; }

	var	priceFurn 	=  priceSectional + (parseFloat(form.drp_Sofa.value) * 119.95) + (parseFloat(form.drp_Loveseat.value) * 89.95) + (parseFloat(form.drp_DiningChair.value) * 17.95) + (parseFloat(form.drp_Chairs.value) * 59.95);
	
var priceValances = 0;

if (form.chk_Valances.checked) { priceValances = (parseFloat(form.txt_addValFt.value) * 12.5); }
var	priceDrapes	= (parseFloat(form.txt_2LyrPleat.value) * 4) + (parseFloat(form.txt_5LyrPleat.value) * 14) + priceValances;
	
	var	priceRugsMin	= (parseFloat(form.txt_handrugFt.value) * 1) + (parseFloat(form.txt_synrugFt.value) * 0.5);
	var	priceRugsMax	= (parseFloat(form.txt_handrugFt.value) * 4) + (parseFloat(form.txt_synrugFt.value) * 1.5);
	var	priceCeiling	= (parseFloat(form.txt_ceilingFt.value) * 1.00);
	var	priceOther	= (parseFloat(form.txt_stnShield.value) * 0.30); // + (parseFloat(form.drp_Deodorizer.value) * 39.95);
	
	
	var	priceMin	= priceRoom + priceBlinds + priceWindows + priceFurn + priceDrapes + priceRugsMin + priceCeiling + priceOther;
	var	priceMax	= priceRoom + priceBlinds + priceWindows + priceFurn + priceDrapes + priceRugsMax + priceCeiling + priceOther;
	priceTotal	= priceRoom + priceBlinds + priceWindows + priceFurn + priceDrapes + priceCeiling + priceOther;
// Set minimum charge of 99.95, or 0 if no data
if (priceMin < 99.95 && priceMin > 0) { priceMin = 99.95; }
if (priceMax < 95.95 && priceMax > 0){ priceMax = 99.95; }
if (priceTotal < 99.95 && priceTotal > 0) { priceTotal = 99.95; }
if (priceMin == 0 || priceMax == 0 || priceTotal == 0) { priceTotal = 0; }

// Write Data to field
if (priceMin == priceMax) //No min/max involved, just write it.
{
	document.getElementById('quoteText').innerHTML = formatCurrency(priceMax);
	form.hdn_quotePrice.value = formatCurrency(priceMax);
} 

if (priceMin < priceMax) //Min/max are involved, write the values with a -
{
	document.getElementById('quoteText').innerHTML = formatCurrency(priceMin)+" - "+formatCurrency(priceMax);
	form.hdn_quotePrice.value = formatCurrency(priceMin)+" - "+formatCurrency(priceMax);
}	


}

// END: Quote calculations

// BEGIN: Format currency

<!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->

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);
}
// END: Format currency

// BEGIN: Callback validation
function validate() {
var valid = 0;
with (document.quote) {
	with (txt_custName) {
		if (value==null||value=="") {
			alert("Please enter your name.");
			document.quote.txt_custName.focus;
			return false;	// Boot out of function
		}
		else {valid += 1;}
	}
	with (txt_custPhone) {
		if (value==null||value==""||value.length<10) {
			alert("Please enter your phone number, including the area code.");
			document.quote.txt_custPhone.focus;
			return false;	// Boot out of function
		}
		else {valid += 1;}
	}
	with (txt_custEmail) {
		if (value.length > 0) {
			apos=value.indexOf("@");
			dotpos=value.lastIndexOf(".");
			if (apos<1||dotpos-apos<2) {	// Check format
				alert("The email address you entered is not valid. Please check it again.");
				document.quote.txt_custEmail.focus;
				return false;	// Boot out of function
			}
		}
		else { valid += 1; }	// Nothing's been entered: valid
	}
	if (valid>=3) { return true; } // All 3 fields validated, allow form submission.
}
}
// END: Callback validation
