// Online Residential Dome Evaluator
// (c) 2003 David South Jr

// $Id: evaluator.js,v 1.9 2003/08/12 16:08:04 dj Exp dj $

//
function changesf(house) {

	var bed1s = 50;
	var bed2s = 70;
	var bed3s = 100;
	var bed4s = 120;
	var bed5s = 150;
	var bed6s = 200;
	var bed7s = 300;

	var bed1 = bed1s * parseFloat(house.bed1i.selectedIndex);
	house.bed1o.value = bed1;
	var bed2 = bed2s * parseFloat(house.bed2i.selectedIndex);
	house.bed2o.value = bed2;
	var bed3 = bed3s * parseFloat(house.bed3i.selectedIndex);
	house.bed3o.value = bed3;
	var bed4 = bed4s * parseFloat(house.bed4i.selectedIndex);
	house.bed4o.value = bed4;
	var bed5 = bed5s * parseFloat(house.bed5i.selectedIndex);
	house.bed5o.value = bed5;
	var bed6 = bed6s * parseFloat(house.bed6i.selectedIndex);
	house.bed6o.value = bed6;
	var bed7 = bed7s * parseFloat(house.bed7i.selectedIndex);
	house.bed7o.value = bed7;

	subtotal = bed1+bed2+bed3+bed4+bed5+bed6+bed7;

	var bath1s = 21;
	var bath2s = 35;
	var bath3s = 35;
	var bath4s = 40;
	var bath5s = 44;
	var bath6s = 56;
	var bath7s = 64;
	var bath8s = 100;
	var bath9s = 125;
	var bath10s = 175;

	var bath1 = bath1s * parseFloat(house.bath1i.selectedIndex);
	house.bath1o.value = bath1;
	var bath2 = bath2s * parseFloat(house.bath2i.selectedIndex);
	house.bath2o.value = bath2;
	var bath3 = bath3s * parseFloat(house.bath3i.selectedIndex);
	house.bath3o.value = bath3;
	var bath4 = bath4s * parseFloat(house.bath4i.selectedIndex);
	house.bath4o.value = bath4;
	var bath5 = bath5s * parseFloat(house.bath5i.selectedIndex);
	house.bath5o.value = bath5;
	var bath6 = bath6s * parseFloat(house.bath6i.selectedIndex);
	house.bath6o.value = bath6;
	var bath7 = bath7s * parseFloat(house.bath7i.selectedIndex);
	house.bath7o.value = bath7;
	var bath8 = bath8s * parseFloat(house.bath8i.selectedIndex);
	house.bath8o.value = bath8;
	var bath9 = bath9s * parseFloat(house.bath9i.selectedIndex);
	house.bath9o.value = bath9;
	var bath10 = bath10s * parseFloat(house.bath10i.selectedIndex);
	house.bath10o.value = bath10;

	subtotal = subtotal+bath1+bath2+bath3+bath4+bath5+bath6+bath7+bath8+bath9+bath10;


	var stor1s = 4;
	var stor2s = 6;
	var stor3s = 12;
	var stor4s = 16;
	var stor5s = 20;
	var stor6s = 9;
	var stor7s = 16;
	var stor8s = 24;
	var stor9s = 48;
	var stor10s = 80;
	var stor11s = 120;

	var stor1 = stor1s * parseFloat(house.stor1i.selectedIndex);
	house.stor1o.value = stor1;
	var stor2 = stor2s * parseFloat(house.stor2i.selectedIndex);
	house.stor2o.value = stor2;
	var stor3 = stor3s * parseFloat(house.stor3i.selectedIndex);
	house.stor3o.value = stor3;
	var stor4 = stor4s * parseFloat(house.stor4i.selectedIndex);
	house.stor4o.value = stor4;
	var stor5 = stor5s * parseFloat(house.stor5i.selectedIndex);
	house.stor5o.value = stor5;
	var stor6 = stor6s * parseFloat(house.stor6i.selectedIndex);
	house.stor6o.value = stor6;
	var stor7 = stor7s * parseFloat(house.stor7i.selectedIndex);
	house.stor7o.value = stor7;
	var stor8 = stor8s * parseFloat(house.stor8i.selectedIndex);
	house.stor8o.value = stor8;
	var stor9 = stor9s * parseFloat(house.stor9i.selectedIndex);
	house.stor9o.value = stor9;
	var stor10 = stor10s * parseFloat(house.stor10i.selectedIndex);
	house.stor10o.value = stor10;
	var stor11 = stor11s * parseFloat(house.stor11i.selectedIndex);
	house.stor11o.value = stor11;

	subtotal = subtotal+stor1+stor2+stor3+stor4+stor5+stor6+stor7+stor8+stor9+stor10+stor11;


	var kitchen1s = 20;
	var kitchen2s = 40;
	var kitchen3s = 100;
	var kitchen4s = 120;
	var kitchen5s = 150;
	var kitchen6s = 200;

	var kitchen1 = kitchen1s * parseFloat(house.kitchen1i.selectedIndex);
	house.kitchen1o.value = kitchen1;
	var kitchen2 = kitchen2s * parseFloat(house.kitchen2i.selectedIndex);
	house.kitchen2o.value = kitchen2;
	var kitchen3 = kitchen3s * parseFloat(house.kitchen3i.selectedIndex);
	house.kitchen3o.value = kitchen3;
	var kitchen4 = kitchen4s * parseFloat(house.kitchen4i.selectedIndex);
	house.kitchen4o.value = kitchen4;
	var kitchen5 = kitchen5s * parseFloat(house.kitchen5i.selectedIndex);
	house.kitchen5o.value = kitchen5;
	var kitchen6 = kitchen6s * parseFloat(house.kitchen6i.selectedIndex);
	house.kitchen6o.value = kitchen6;

	subtotal = subtotal+kitchen1+kitchen2+kitchen3+kitchen4+kitchen5+kitchen6;


	var pantry1s = 6;
	var pantry2s = 8;
	var pantry3s = 30;
	var pantry4s = 70;
	var pantry5s = 120;

	var pantry1 = pantry1s * parseFloat(house.pantry1i.selectedIndex);
	house.pantry1o.value = pantry1;
	var pantry2 = pantry2s * parseFloat(house.pantry2i.selectedIndex);
	house.pantry2o.value = pantry2;
	var pantry3 = pantry3s * parseFloat(house.pantry3i.selectedIndex);
	house.pantry3o.value = pantry3;
	var pantry4 = pantry4s * parseFloat(house.pantry4i.selectedIndex);
	house.pantry4o.value = pantry4;
	var pantry5 = pantry5s * parseFloat(house.pantry5i.selectedIndex);
	house.pantry5o.value = pantry5;

	subtotal = subtotal+pantry1+pantry2+pantry3+pantry4+pantry5;


	var addon1s = 20;
	var addon2s = 60;
	var addon3s = 90;

	var addon1 = addon1s * parseFloat(house.addon1i.selectedIndex);
	house.addon1o.value = addon1;
	var addon2 = addon2s * parseFloat(house.addon2i.selectedIndex);
	house.addon2o.value = addon2;
	var addon3 = addon3s * parseFloat(house.addon3i.selectedIndex);
	house.addon3o.value = addon3;

	subtotal = subtotal+addon1+addon2+addon3;


	var great1s = 100;
	var great2s = 140;
	var great3s = 250;
	var great4s = 500;
	var great5s = 750;

	var great1 = great1s * parseFloat(house.great1i.selectedIndex);
	house.great1o.value = great1;
	var great2 = great2s * parseFloat(house.great2i.selectedIndex);
	house.great2o.value = great2;
	var great3 = great3s * parseFloat(house.great3i.selectedIndex);
	house.great3o.value = great3;
	var great4 = great4s * parseFloat(house.great4i.selectedIndex);
	house.great4o.value = great4;
	var great5 = great5s * parseFloat(house.great5i.selectedIndex);
	house.great5o.value = great5;

	subtotal = subtotal+great1+great2+great3+great4+great5;


	var dine1s = 90;
	var dine2s = 120;
	var dine3s = 150;
	var dine4s = 200;

	var dine1 = dine1s * parseFloat(house.dine1i.selectedIndex);
	house.dine1o.value = dine1;
	var dine2 = dine2s * parseFloat(house.dine2i.selectedIndex);
	house.dine2o.value = dine2;
	var dine3 = dine3s * parseFloat(house.dine3i.selectedIndex);
	house.dine3o.value = dine3;
	var dine4 = dine4s * parseFloat(house.dine4i.selectedIndex);
	house.dine4o.value = dine4;

	subtotal = subtotal+dine1+dine2+dine3+dine4;


	var parlor1s = 100;
	var parlor2s = 144;
	var parlor3s = 192;
	var parlor4s = 256;

	var parlor1 = parlor1s * parseFloat(house.parlor1i.selectedIndex);
	house.parlor1o.value = parlor1;
	var parlor2 = parlor2s * parseFloat(house.parlor2i.selectedIndex);
	house.parlor2o.value = parlor2;
	var parlor3 = parlor3s * parseFloat(house.parlor3i.selectedIndex);
	house.parlor3o.value = parlor3;
	var parlor4 = parlor4s * parseFloat(house.parlor4i.selectedIndex);
	house.parlor4o.value = parlor4;

	subtotal = subtotal+parlor1+parlor2+parlor3+parlor4;


	var office1s = 64;
	var office2s = 100;
	var office3s = 150;
	var office4s = 250;

	var office1 = office1s * parseFloat(house.office1i.selectedIndex);
	house.office1o.value = office1;
	var office2 = office2s * parseFloat(house.office2i.selectedIndex);
	house.office2o.value = office2;
	var office3 = office3s * parseFloat(house.office3i.selectedIndex);
	house.office3o.value = office3;
	var office4 = office4s * parseFloat(house.office4i.selectedIndex);
	house.office4o.value = office4;

	subtotal = subtotal+office1+office2+office3+office4;


	var utility1s = 20;
	var utility2s = 56;
	var utility3s = 70;
	var utility4s = 100;
	var utility5s = 144;

	var utility1 = utility1s * parseFloat(house.utility1i.selectedIndex);
	house.utility1o.value = utility1;
	var utility2 = utility2s * parseFloat(house.utility2i.selectedIndex);
	house.utility2o.value = utility2;
	var utility3 = utility3s * parseFloat(house.utility3i.selectedIndex);
	house.utility3o.value = utility3;
	var utility4 = utility4s * parseFloat(house.utility4i.selectedIndex);
	house.utility4o.value = utility4;
	var utility5 = utility5s * parseFloat(house.utility5i.selectedIndex);
	house.utility5o.value = utility5;

	subtotal = subtotal+utility1+utility2+utility3+utility4+utility5;


	var extra1 = parseFloat(house.extra1s.value);
	var extra2 = parseFloat(house.extra2s.value);
	var extra3 = parseFloat(house.extra3s.value);
	var extra4 = parseFloat(house.extra4s.value);
	var extra5 = parseFloat(house.extra5s.value);

	subtotal = subtotal+extra1+extra2+extra3+extra4+extra5;

	house.sfsub.value = subtotal;

	allowances = Math.round(subtotal * .20);
	sf = subtotal + allowances;
	house.allowances.value = allowances;
	house.sftotal.value = sf;


	// Cost Estimator
	var finish_quality = new Array(125, 150, 200);
	balance = sf * finish_quality[house.finishquality.selectedIndex];
	house.finishbalance.value = formatCurrency(balance);

	// Orion Style
	var orion_style = new Array(1.0, 1.1);
	balance = balance * orion_style[house.orionstyle.selectedIndex];
	house.orionbalance.value = formatCurrency(balance);

//	// Garage
//	var garage = new Array(0, 100, 200, 300, 400, 500, 600);
//	balance = balance + garage[house.garagestyle.selectedIndex];
//	house.garagebalance.value = money(balance);

	// Multiplier
	// ELIMINATE THIS ITEM 
	var multiplier = new Array(0.95, 1.00, 1.15);
	balance = balance * multiplier[house.areafactor.selectedIndex];
	house.areabalance.value = formatCurrency(balance);

	// Dome size functions
	var d10d = Math.sqrt(sf / Math.PI) * 2;
	house.dome10d.value = rd(d10d);
	house.dome10h.value = rd(domeh(d10d));

	//var d20d = Math.sqrt((sf * (2/3)) / Math.PI) * 2;
	var d20d = Math.sqrt((sf * .55) / Math.PI) * 2;
	if (d20d >= 28) { // limit diameter for having 2d floor 
		house.dome20d.value = rd(d20d);
		house.dome20h.value = rd(domeh(d20d) * 1.05);
	}
	else {
		house.dome20d.value = "n/a";
		house.dome20h.value = "n/a";
	}
	//house.dome20h.value = rd(domeh(d20d)); // original script
	
	var d30d = Math.sqrt((sf * .4) / Math.PI) * 2;
	if (d30d >= 41) { // limit diameter for having 2d floor 
		house.dome30d.value = rd(d30d);
		house.dome30h.value = rd(domeh(d30d) * 1.25);
	}
	else {
		house.dome30d.value = "n/a";
		house.dome30h.value = "n/a";
	}

}

// Calculate height
function domeh(n) {
	// return n / 2 / 1.4; // original 
	return n / 2 / 1;
}

// Round n to two decimal places
function rd(n) {
	return Math.round(n * 100)/100;
}


// formatCurrency()
// Thanks to -> http://javascriptsource.com
// Script is here -> http://javascript.internet.com/forms/currency-format.html
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);
}
