<!-- Hide script from old browser

////////////////////////////////////////////
////////// START PAINT CALCULATOR //////////
////////////////////////////////////////////

// Hide script from old browser
//need to add in rough and medium textures with current smooth for walls and ceilings
// round for money decimal of 2 places
function Paint_calcRound(num) {
   result=Math.floor(num)+"." 
   n = result.length

   if (num>1000 && num<999999) {  
   result=result.substring(1,n-4)+","+result.substring(n-4,n)

   }

   if (num>1000000) {  

     result = result.substring(1,n-7)+","+result.substring(n-7,n-4)+","+result.substring(n-4,n)

   }

   var cents=100*(num-Math.floor(num))+0.5
   result += Math.floor(cents/10)
   result += Math.floor(cents%10)
   return(result)

}

// make sure it is a number or a decimal
function Paint_ValidateNumber(rVal)
{
inLen = rVal.length;

for(var i=0; i<inLen; i++) {
var ch = rVal.substring(i,i+1);
if (! (ch> "0" || "9"> ch || ch == ".") ) 
{ 
alert("Entry incorrect, please re-enter");
return -1;
}
}

return rVal;
}

function Paint_ValidateJob()
{

Paint_ExecuteJob();

if (gallonsc > gallons) {
		gallons = Math.round(gallons) + 1;
	} // make sure you buy enough paint!!!!
	else {
 	gallons = Math.round(gallons);
	}

document.forms[0].sqfeet.value = feet;
	document.forms[0].paintgals.value= gallons;
document.forms[0].sqfeetc.value = feetc;
	document.forms[0].paintgalsc.value= gallonsc;
document.forms[0].pexpense.value = Paint_calcRound(gallons * pexpense);
}

function Paint_ExecuteJob()
{

var width = Paint_ValidateNumber(document.forms[0].width.value); // check input
if (width == -1) { // -1 means invalid input
document.forms[0].width.value = 0;// reset form field
width = 0; // zero out variable
}

var length = Paint_ValidateNumber(document.forms[0].length.value);
if (length == -1) {
document.forms[0].length.value = 0;
length = 0;
}

var height = Paint_ValidateNumber(document.forms[0].height.value);
if (height == -1) {
document.forms[0].height.value = 0;
height = 0;
}

	var areadoor = 21; // square feet of average door
	var qtydoor = Paint_ValidateNumber(document.forms[0].qtydoor.value);
if (qtydoor == -1) {
document.forms[0].qtydoor.value = 0;
qtydoor = 0;
}
	
	var areawin = 16; // square feet of average window
	var qtywin = Paint_ValidateNumber(document.forms[0].qtywin.value);
if (qtywin == -1) {
document.forms[0].qtydoor.value = 0;
qtywin = 0;
}

	var pcost = Paint_ValidateNumber(document.forms[0].pcost.value); // decimal
if (pcost == -1) { // -1 means invalid input
document.forms[0].pcost.value = 0;
pcost = 0; // cost per gallon of paint
}

Paint_calcRound (pcost); //format money to 2 decimal places

	pexpense = pcost;
		
	if (document.forms[0].qtyapps[1].checked)
	{
		qtyapps = 2;
}
	else
	{
		qtyapps = 1;
 	}

	
	if (document.forms[0].wayapps[0].checked)
	{
		wayapps = 1.15; // spraying = 15% more material
}
	else
	{
		wayapps = 1; // rolled or brushed
 	}

	feet = 2 * (height * width) + 2 * (height * length); 
	feet = (feet - (qtydoor * areadoor) - (qtywin * areawin));//number of feet painted
	
	if (document.forms[0].ceiling.checked) {
feet = feet + (width * length); // paint the ceiling
	}
	if (document.forms[0].ceilinga.checked) {
feet = feet + ((width * length) * 1.85); // paint the
//ceiling heavily if acoustical, add both if very dry
	}

if (feet> 0) {
		gallonsc = ((feet * qtyapps * wayapps) / 350 + .95);
		gallons = Math.round((feet * qtyapps * wayapps) / 350 + .95);
		feetc = (feet);
		feet = Math.round(feet);
	}
	else {
	feet = 0; 
	feetc = 0; 
	gallons =0;
	gallonsc =0;
	}
	
}

////////////////////////////////////////////
/////////// END PAINT CALCULATOR ///////////
////////////////////////////////////////////



/////////////////////////////////////////////
////////// START CARPET CALCULATOR //////////
/////////////////////////////////////////////

// round for money decimal of 2 places
function Carpet_calcRound(num) {
   result=Math.floor(num)+"." 
   n = result.length

   if (num>1000 && num<999999) {  
   result=result.substring(1,n-4)+","+result.substring(n-4,n)

   }

   if (num>1000000) {  

     result = result.substring(1,n-7)+","+result.substring(n-7,n-4)+","+result.substring(n-4,n)

   }

   var cents=100*(num-Math.floor(num))+0.5
   result += Math.floor(cents/10)
   result += Math.floor(cents%10)
   return(result)

}

function Carpet_ValidateNumber(rVal)
{
    inLen = rVal.length;
    
    for(var i=0; i<inLen; i++) {
        var ch = rVal.substring(i,i+1);

        if (! (ch> "0" || "9"> ch || ch == ".") ) 
        {                         
            alert("Entry incorrect, please re-enter");
            return -1;
        }
    }
    
    return rVal;
} 

function Carpet_ValidateJob()
{   
    document.forms[0].results.value = Carpet_ExecuteJob();
    window.focus();
}


function Carpet_ExecuteJob()
{  
       
    var width = Carpet_ValidateNumber(document.forms[0].RoomWidth.value); // check input
    if (width == -1) {                                           // -1 means invalid input
        document.forms[0].RoomWidth.value = 0;                    // reset form field
        width = 0;                                               // zero out variable
    }
        
    var length = Carpet_ValidateNumber(document.forms[0].RoomLength.value);
    if (length == -1) {
        document.forms[0].RoomLength.value = 0;
        length = 0;
    }
        
    var costyard = Carpet_ValidateNumber(document.forms[0].CostPerYard.value);
    if (costyard == -1) {
        document.forms[0].CostPerYard.value = 0;
        costyard = 0;
    }
        
    var lcostyard = Carpet_ValidateNumber(document.forms[0].LCostPerYard.value);
    if (lcostyard == -1) {
        document.forms[0].LCostPerYard.value = 0;
        lcostyard = 0;
    }

    var placesizeft = Math.round(width * length);  
    var placesizeyd = Math.round((width * length)/9);  
    var placevalue = Carpet_calcRound(Math.round((width * length)/9 * costyard));// main equation  
    var lplacevalue = Carpet_calcRound(Math.round((width * length)/9 * lcostyard));// main equation  
document.forms[0].reqsf.value = eval(placesizeft);
document.forms[0].reqsy.value = eval(placesizeyd);
document.forms[0].lresults.value = Carpet_calcRound(eval(lplacevalue));
    return placevalue;
}

///////////////////////////////////////////
////////// END CARPET CALCULATOR //////////
///////////////////////////////////////////



///////////////////////////////////////////////
////////// START CONCRETE CALCULATOR //////////
///////////////////////////////////////////////

//define and initialize variables both calcs
// has re-inforcement calculations
function Concrete_CalcBags() {
  //initial value

var BagCost = 0;
var BagsY3 = 0;
var CostY3 = 0;
var Feet3V = 0;
var Inches3V = 0;
var Yards3V = 0;
var ConCostV = 0;
var UnitV = 0;
var InUnitV = 0;

  UnitV = eval(document.forms[0].Unit.value); //cubic feet 
  InUnitV = eval(document.forms[0].InUnit.value); //quantity
  BagCost = eval(document.forms[0].Cost.value);

     //massage floating point values   
	 Feet3V = (UnitV * InUnitV); // cubic feet from bag and quantity
	 Yards3V = ((UnitV * InUnitV) / 27); // cubic yards from cubic feet
	 Inches3V = ((UnitV * InUnitV) * 1728); // cubic inches from cubic feet
     ConCostV = Concrete_moneyRound((BagCost) * (InUnitV));
     BagsY3 =  (27 / (UnitV));
     CostY3 =  Concrete_moneyRound(((BagCost) * (InUnitV)) / (Yards3V));
	 //assign display
     document.forms[0].Inches3r.value = Concrete_perRound(Inches3V);
     document.forms[0].Feet3r.value = Concrete_perRound(Feet3V);
     document.forms[0].Yards3r.value = Concrete_perRound(Yards3V);
     document.forms[0].Inches3.value = (Inches3V);
     document.forms[0].Feet3.value = (Feet3V);
     document.forms[0].Yards3.value = (Yards3V);
     document.forms[0].ConCost.value = (ConCostV);
     document.forms[0].CostY3.value = (CostY3);
     document.forms[0].BagsY3.value = (BagsY3);
}
// round for percent decimal of 3 places
function Concrete_perRound(num) {
   result=Math.floor(num)+"." 
   var percents=1000*(num-Math.floor(num))+0.5
   result += Math.floor(percents/100)
   result += Math.floor(percents%100)
   return(result)
}

// send the value in as "num" in a variable

// clears field of default value
function Concrete_clear_field(field) {
		if (field.value==field.defaultValue) {
			field.value=''
		}
	}

// round for money decimal of 2 places
function Concrete_moneyRound(num) {
   result=Math.floor(num)+"." 
   n = result.length

   var cents=100*(num-Math.floor(num))+0.5
   result += Math.floor(cents/10)
   result += Math.floor(cents%10)
   return(result)
}

/////////////////////////////////////////////
////////// END CONCRETE CALCULATOR //////////
/////////////////////////////////////////////




/////////////////////////////////////////////////
////////// START FOUNDATION CALCULATOR //////////
/////////////////////////////////////////////////

function Foundation_Mode() {

	if ( document.forms[0].selectMode[1].checked ) { // American ROUTINE
		var sqlength = "Feet";
		var sqwidth = "Feet";
		var sqlength2 = "Inches";
		var sqwidth2 = "Inches";
		var disMode = "American"; // display value
		var disMode2 = "American"; // display value
		document.forms[0].disMode.value = disMode; // display value
		document.forms[0].disMode2.value = disMode2; // display value
		document.forms[0].sqwidth.value = sqwidth; // display value
		document.forms[0].sqwidth2.value = sqwidth2; // display value
		document.forms[0].sqlength.value = sqlength; // display value
		document.forms[0].sqlength2.value = sqlength2; // display value
}

	else { // METRIC ROUTINE
		var sqlength = "Meters";
		var sqwidth = "Meters";
		var sqlength2 = "Not Used";
		var sqwidth2 = "Not Used";
		var disMode = "Metric"; // display value
		var disMode2 = "Metric"; // display value
		document.forms[0].disMode.value = disMode; // display value
		document.forms[0].disMode2.value = disMode2; // display value
		document.forms[0].sqwidth.value = sqwidth; // display value
		document.forms[0].sqwidth2.value = sqwidth2; // display value
		document.forms[0].sqlength.value = sqlength; // display value
		document.forms[0].sqlength2.value = sqlength2; // display value
}
}
// round for percent decimal of 3 places
function Foundation_perRound(num) {
   result=Math.floor(num)+"." 
   var percents=1000*(num-Math.floor(num))+0.5
   result += Math.floor(percents/100)
   result += Math.floor(percents%100)
   return(result)
}
// send the value in as "num" in a variable

// clears field of default value
function Foundation_clear_field(field) {
		if (field.value==field.defaultValue) {
			field.value=''
		}
	}
function Foundation_calculate() {

	if ( document.forms[0].sqlength2.value == "Inches" ) { // American ROUTINE possibility 1
		var sqlength2 = 0;
		var disMode = "By Feet"; // display value
		document.forms[0].disMode.value = disMode; // display value
		document.forms[0].sqlength2.value = sqlength2; // display value
}

	if ( document.forms[0].sqwidth2.value == "Inches" ) { // American ROUTINE possibility 2
		var sqwidth2 = 0;
		var disMode2 = "By Feet"; // display value
		document.forms[0].disMode2.value = disMode2; // display value
		document.forms[0].sqwidth2.value = sqwidth2; // display value
}

	if ( document.forms[0].selectMode[1].checked ) { // METRIC ROUTINE
		var sqlength2 = "Not Used";
		var sqwidth2 = "Not Used";
		var disMode = "By Meters"; // display value
		var disMode2 = "By Meters"; // display value
		document.forms[0].disMode.value = disMode; // display value
		document.forms[0].disMode2.value = disMode2; // display value
		document.forms[0].sqwidth2.value = sqwidth2; // display value
		document.forms[0].sqlength2.value = sqlength2; // display value
}

// inches field reset now to 0

	var finalFractional = 0;
	var sqlengthVal = document.forms[0].sqlength.value; //feet or meters
	var sqwidthVal  = document.forms[0].sqwidth.value; //feet or meters
	var sqlengthVal2 = document.forms[0].sqlength2.value; //inches only
	var sqwidthVal2 = document.forms[0].sqwidth2.value; //inches only
	var hypotenuse = Math.sqrt ( (sqwidthVal * sqwidthVal) + (sqlengthVal * sqlengthVal) ); //metric
	var hyp1 = (((sqwidthVal * 12) + (1 * sqwidthVal2)) * ((sqwidthVal * 12) + (1 * sqwidthVal2)))  + (((sqlengthVal * 12) + (1 * sqlengthVal2)) * ((sqlengthVal * 12) + (1 * sqlengthVal2))); //convert to inches
	
	if ( document.forms[0].selectMode[0].checked ) { // American ROUTINE
		var allinches = (hyp1); // inches and decimal fraction
		var reminches = ((hyp1) - (parseInt (hyp1))); // inches and decimal fraction
		var tmpfeet = (Math.sqrt (allinches)) / 12; // Only feet (temporary variable)
		var feet = Math.floor(tmpfeet); // Only feet
		convertInches = (((tmpfeet) - (feet)) * 12); // remaining inches (and fraction in decimal)
		if (convertInches >=1) {
			fracInches = convertInches - (parseInt (convertInches) ); // get decimal of inches
		}
		else { fracInches = convertInches; }		
	
		finalinches = convertInches - fracInches; // isolating full inches

		if (finalinches < 1) { finalinches = 0;}
		if (fracInches >= 0 && fracInches < 0.0155) { finalFractional = ""; }
		if (fracInches >= 0.0156 && fracInches < 0.0311) { finalFractional = "1/64"; }
		if (fracInches >= 0.0312 && fracInches < 0.0468) { finalFractional = "1/32"; }
		if (fracInches >= 0.0469 && fracInches < 0.0624) { finalFractional = "3/64"; }
		if (fracInches >= 0.0625 && fracInches < 0.0780) { finalFractional = "1/16"; }
		if (fracInches >= 0.0781 && fracInches < 0.0937) { finalFractional = "5/64"; }
		if (fracInches >= 0.0938 && fracInches < 0.1093) { finalFractional = "3/32"; }
		if (fracInches >= 0.1094 && fracInches < 0.1249) { finalFractional = "7/64"; }
		if (fracInches >= 0.1250 && fracInches < 0.1405) { finalFractional = "1/8"; }
		if (fracInches >= 0.1406 && fracInches < 0.1561) { finalFractional = "9/64"; }
		if (fracInches >= 0.1562 && fracInches < 0.1718) { finalFractional = "5/32"; }
		if (fracInches >= 0.1719 && fracInches < 0.1874) { finalFractional = "11/64"; }
		if (fracInches >= 0.1875 && fracInches < 0.2030) { finalFractional = "3/16"; }
		if (fracInches >= 0.2031 && fracInches < 0.2187) { finalFractional = "13/64"; }
		if (fracInches >= 0.2188 && fracInches < 0.2343) { finalFractional = "7/32"; }
		if (fracInches >= 0.2344 && fracInches < 0.2499) { finalFractional = "15/64"; }
		if (fracInches >= 0.2500 && fracInches < 0.2655) { finalFractional = "1/4"; }
		if (fracInches >= 0.2656 && fracInches < 0.2811) { finalFractional = "17/64"; }
		if (fracInches >= 0.2812 && fracInches < 0.2968) { finalFractional = "9/32"; }
		if (fracInches >= 0.2969 && fracInches < 0.3124) { finalFractional = "19/64"; }
		if (fracInches >= 0.3125 && fracInches < 0.3280) { finalFractional = "5/16"; }
		if (fracInches >= 0.3281 && fracInches < 0.3437) { finalFractional = "21/64"; }
		if (fracInches >= 0.3438 && fracInches < 0.3593) { finalFractional = "11/32"; }
		if (fracInches >= 0.3594 && fracInches < 0.3749) { finalFractional = "23/64"; }
		if (fracInches >= 0.3750 && fracInches < 0.3905) { finalFractional = "3/8"; }
		if (fracInches >= 0.3906 && fracInches < 0.4061) { finalFractional = "25/64"; }
		if (fracInches >= 0.4062 && fracInches < 0.4219) { finalFractional = "13/32"; }
		if (fracInches >= 0.4220 && fracInches < 0.4374) { finalFractional = "27/64"; }
		if (fracInches >= 0.4375 && fracInches < 0.4530) { finalFractional = "7/16"; }
		if (fracInches >= 0.4531 && fracInches < 0.4687) { finalFractional = "29/64"; }
		if (fracInches >= 0.4688 && fracInches < 0.4843) { finalFractional = "15/32"; }
		if (fracInches >= 0.4844 && fracInches < 0.4999) { finalFractional = "31/64"; }
		if (fracInches >= 0.5000 && fracInches < 0.5155) { finalFractional = "1/2"; }
		if (fracInches >= 0.5156 && fracInches < 0.5311) { finalFractional = "33/64"; }
		if (fracInches >= 0.5312 && fracInches < 0.5468) { finalFractional = "17/32"; }
		if (fracInches >= 0.5469 && fracInches < 0.5624) { finalFractional = "35/64"; }
		if (fracInches >= 0.5625 && fracInches < 0.5780) { finalFractional = "9/16"; }
		if (fracInches >= 0.5781 && fracInches < 0.5937) { finalFractional = "37/64"; }
		if (fracInches >= 0.5938 && fracInches < 0.6093) { finalFractional = "19/32"; }
		if (fracInches >= 0.6094 && fracInches < 0.6249) { finalFractional = "39/64"; }
		if (fracInches >= 0.6250 && fracInches < 0.6405) { finalFractional = "5/8"; }
		if (fracInches >= 0.6406 && fracInches < 0.6561) { finalFractional = "41/64"; }
		if (fracInches >= 0.6562 && fracInches < 0.6718) { finalFractional = "21/32"; }
		if (fracInches >= 0.6719 && fracInches < 0.6874) { finalFractional = "43/64"; }
		if (fracInches >= 0.6875 && fracInches < 0.7030) { finalFractional = "11/16"; }
		if (fracInches >= 0.7031 && fracInches < 0.7187) { finalFractional = "45/64"; }
		if (fracInches >= 0.7188 && fracInches < 0.7343) { finalFractional = "23/32"; }
		if (fracInches >= 0.7344 && fracInches < 0.7499) { finalFractional = "47/64"; }
		if (fracInches >= 0.7500 && fracInches < 0.7655) { finalFractional = "3/4"; }
		if (fracInches >= 0.7656 && fracInches < 0.7811) { finalFractional = "49/64"; }
		if (fracInches >= 0.7812 && fracInches < 0.7968) { finalFractional = "25/32"; }
		if (fracInches >= 0.7969 && fracInches < 0.8124) { finalFractional = "51/64"; }
		if (fracInches >= 0.8125 && fracInches < 0.8280) { finalFractional = "13/16"; }
		if (fracInches >= 0.8281 && fracInches < 0.8437) { finalFractional = "53/64"; }
		if (fracInches >= 0.8438 && fracInches < 0.8593) { finalFractional = "27/32"; }
		if (fracInches >= 0.8594 && fracInches < 0.8749) { finalFractional = "55/64"; }
		if (fracInches >= 0.8750 && fracInches < 0.8905) { finalFractional = "7/8"; }
		if (fracInches >= 0.8906 && fracInches < 0.9061) { finalFractional = "57/64"; }
		if (fracInches >= 0.9062 && fracInches < 0.9218) { finalFractional = "29/32"; }
		if (fracInches >= 0.9219 && fracInches < 0.9374) { finalFractional = "59/64"; }
		if (fracInches >= 0.9375 && fracInches < 0.9530) { finalFractional = "15/16"; }
		if (fracInches >= 0.9531 && fracInches < 0.9687) { finalFractional = "61/64"; }
		if (fracInches >= 0.9688 && fracInches < 0.9839) { finalFractional = "31/32"; }
		if (fracInches >= 0.8125 && fracInches < 0.9375) { finalFractional = "63/64"; }
		if (fracInches >= 0.9940 && fracInches < 1) { 
			finalinches = finalinches + 1;
			finalFractional = "";
			if (finalinches == 12) {
				feet = feet +1;
				finalinches = "";
			}
		 }	
		if (finalinches == "" && finalFractional == "") { finalinches = 0; }
		if (finalinches == "0" && finalFractional != "") {
			document.forms[0].result.value= feet + " feet " + finalFractional + " inch(es)";}		
		else { document.forms[0].result.value = feet + " feet " + finalinches + " " + finalFractional + " inch(es)";}
//	test point here
	}

	else { // METRIC ROUTINE
		if (hypotenuse < 1) {
			metricInt = 0;
			metricFrac = hypotenuse;
		}
		else {
			metricInt = parseInt (hypotenuse);
			metricFrac = hypotenuse - metricInt; 
		}
		metricFracString = "" + metricFrac + "";
		if (metricFracString.substring(0,2) == "0.") {
			metricFracString = metricFracString.substring (1,5)
		}
		if (metricFracString.length > 4) { 	metricFracString = metricFracString.substring (0,4);}
	
		if (metricInt < 1) {
			document.forms[0].result.value = "0" + "metricFracString" + " meter(s)";
		}
		if (metricFracString == "0") {
			document.forms[0].result.value = metricInt + "." + metricFracString + " meter(s)";
		}
		else { document.forms[0].result.value = metricInt + metricFracString + " meter(s)";}

	} // End of METRIC routine
} // end of Foundation_calculate

///////////////////////////////////////////////
////////// END FOUNDATION CALCULATOR //////////
///////////////////////////////////////////////




///////////////////////////////////////////////////
////////// START WALL FRAMING CALCULATOR //////////
///////////////////////////////////////////////////

function Wall_calcRound(num) {
   result=Math.floor(num)+"." 
   n = result.length

   if (num>1000 && num<999999) {  
   result=result.substring(1,n-4)+","+result.substring(n-4,n)

   }

   if (num>1000000) {  

 result = result.substring(1,n-7)+","+result.substring(n-7,n-4)+","+result.substring(n-4,n)

   }

   var cents=100*(num-Math.floor(num))+0.5
   result += Math.floor(cents/10)
   result += Math.floor(cents%10)
   return(result)

}

function Wall_DoCalcs (form) {
answer = 0;
costanswer = 0;
oal = form.stdwallen.value * 2;
oao = oal / 8;
cal1 = form.stdwallen.value / 1.3 + 1.01;
cal2 = cal1 * .125;
cal3 = form.stdwallen.value - cal2;
cal4 = cal3 / 8;
cost = Wall_calcRound((form.studcost.value), 2);
form.studcost.value = (cost);
form.answer.value = Math.round(oao + cal1 + cal4);
form.costanswer.value = Wall_calcRound((cost) * (form.answer.value));
}

/////////////////////////////////////////////////
////////// END WALL FRAMING CALCULATOR //////////
/////////////////////////////////////////////////




///////////////////////////////////////////////////
////////// START BREATH BEATS CALCULATOR //////////
///////////////////////////////////////////////////

//function to validate date entered
function Breath_doCalc(mfactor, bfactor)
{
	var myObj;

	//if (!document.forms[0]) { alert('Please specify a valid form for this page with the name forms[0]'); return false; }
	myObj = document.forms[0]
	if (!myObj.year) { alert('Please specify a valid form field for birth year with the name year'); return false; }
	if (!myObj.month) { alert('Please specify a valid form field for birth month with the name month'); return false; }
	if (!myObj.day) { alert('Please specify a valid form field for birth day with the name day'); return false; }

	if (myObj.day.options[myObj.day.selectedIndex].value == '' || isNaN(parseInt(myObj.day.options[myObj.day.selectedIndex].value))) { alert('Please specify a valid birth day'); return false;	}
	if (myObj.month.options[myObj.month.selectedIndex].value == '') { alert('Please specify a valid month'); return false;	}
	if (myObj.year.value == '' || isNaN(parseInt(myObj.year.value)) || myObj.year.value.length != 4) { alert('Please specify a valid 4-digit birth year'); return false; }
	

	var bdate = new Date(myObj.month.options[myObj.month.selectedIndex].value + ' ' + myObj.day.options[myObj.day.selectedIndex].value + ', ' + myObj.year.value)
	var nowdate = new Date()
	var bdatems = bdate.getTime()
	var nowdatems = nowdate.getTime()

	if (bdatems > nowdatems) { alert('Your birthdate cannot be in the future!!'); return false; }
	
	var timeElapsed = nowdatems - bdatems
	timeElapsed = Math.round(timeElapsed / 60000) //in minutes
	timeElapsed = (mfactor * timeElapsed) + bfactor
	
	var strTime = timeElapsed.toString()
	var strTemp = strTime
	var strTemp1
	var strTemp2
	var retVal = ''
	while (strTemp.length > 3) {
		strTemp1 = strTemp
		strTemp = strTemp1.substring(0, strTemp1.length - 3)
		strTemp2 = strTemp1.substring(strTemp1.length-3,strTemp1.length)
		retVal = ',' + strTemp2 + retVal
	}
	retVal = strTemp + retVal

	return retVal
}

/////////////////////////////////////////////////
////////// END BREATH BEATS CALCULATOR //////////
/////////////////////////////////////////////////




//////////////////////////////////////////
////////// START BAC CALCULATOR //////////
//////////////////////////////////////////

function BAC_cal_bac(wgt, num, hrs, dt, gen) {
   kgs = wgt / 2.2046; //Kilograms
   tbw = kgs * gen * 1000; //Total body water (in milliliters)
   walc = 23.36; //Weight of alcohol/oz
   ac = walc / tbw; //Alcohol concentration for one ounce of alcohol
   acb = ac * .806; //Alcohol concentration in blood
   ibac = acb * 100; //Instantaneous BAC
   
   tac = ibac * dt * num;  // Total Alcohol Consumed

   bac = tac - (hrs * 0.012);  //Final BAC

	if (bac < 0) {
		bac = 0;
	}

   diff = bac * 10000;
   f_bac = Math.round(diff);
   bac = f_bac / 10000;

   return bac;
}

function BAC_compute() {
   var f = document.forms[0];
   var gen = f.gen.options[f.gen.selectedIndex].value;
   var dt = f.dt.options[f.dt.selectedIndex].value;
   var num = f.num.value;
   var wt = f.wt.value;
   var hrs = f.hrs.value;

   if (BAC_chkw(wt)){
		if (BAC_chkw(num)){
			if (BAC_chkw(hrs)){
				f.bac.value = BAC_cal_bac(wt, num, hrs, dt, gen);
			} else {
					f.hrs.focus();
					alert("Please enter the number of hours consuming the drinks."); 
			}
		} else {
				f.num.focus();
				alert("Please enter the number of drinks."); 
		}
   } else {
		f.wt.focus();
		alert("Please enter a number for your weight."); 
   }
   // Set cookies for future views of this page
   // Expires when user closes browser
   document.cookie = "bac=" + f.bac.value;
   document.cookie = "wt=" + f.wt.value;
   document.cookie = "num=" + f.num.value;
   document.cookie = "hrs=" + f.hrs.value;
   document.cookie = "gen=" + f.gen.selectedIndex;
   document.cookie = "dt=" + f.dt.selectedIndex;
}

function BAC_chkw(w) {
   if (isNaN(w)) {
      return false;
   } else if (w < 0) {
      return false;
   }
   else {
      return true;
   }
}

function BAC_load_cookies() {
	var f = document.forms[0];
	f.wt.value = BAC_loadcookie("wt");
	f.bac.value = BAC_loadcookie("bac");
	f.hrs.value = BAC_loadcookie("hrs");
	f.num.value = BAC_loadcookie("num");
	f.dt.selectedIndex = BAC_loadcookie("dt");
	f.gen.selectedIndex = BAC_loadcookie("gen");
}

function BAC_loadcookie(name) {
    var allcookies = document.cookie;
	var value;
	var pos = allcookies.indexOf(name + "=");
	//alert("Name: " + name + " All: " + allcookies);
	var len = name.length + 1;  // length of name + 1
	if (pos != -1) {
		var start = pos + len;  //Start of cookie value
		var end = allcookies.indexOf(";", start);  //End of cookie value
		if (end == -1) end = allcookies.length;
		value = allcookies.substring(start,end); //Extract the value
		//alert("Name: " + name + " Value: " + value);
		value = unescape(value);  // Decode it, if encoded.
    	return value;
	}

    return 0;
}

////////////////////////////////////////
////////// END BAC CALCULATOR //////////
////////////////////////////////////////




//////////////////////////////////////////
////////// START BMR CALCULATOR //////////
//////////////////////////////////////////

function BMR_lcal_bmr(lbs, ins, gen, age) {
   hcm = ins * 2.54; // convert to centimeters
   wkg = lbs * 0.4536; //convert to kilos
   if (gen == "F") {
	bmr = 655 + 9.6 * wkg + 1.8 * hcm - 4.7 * age;
   } else {
	bmr = 66 + 13.7 * wkg + 5 * hcm - 6.8 * age;
   }
   f_bmr = Math.floor(bmr);
   diff  = bmr - f_bmr;
   diff = diff * 10;
   diff = Math.round(diff);

   if (diff == 10) {
      // Need to bump up the whole thing instead
      f_bmr += 1;
      diff = 0;
   }

   bmr = f_bmr + "." + diff;
   return bmr;
}

function BMR_compute() {
   var f = document.forms[0];
   var gen = f.gen.options[f.gen.selectedIndex].value;
   var age = f.age.value;
   var fi = parseInt(f.htf.options[f.htf.selectedIndex].value * 12);
   var ii = parseInt(f.hti.options[f.hti.selectedIndex].value);
   var i = fi + ii;
 

   w = f.wt.value;
   if (BMR_chkw(w) && BMR_chkw(age)){
      f.bmr.value = BMR_lcal_bmr(w, i, gen, age);
   } else { 
      alert("Please enter a number for your weight."); 
   }
   // Set cookies for future views of this page
   // Expires when user closes browser
   document.cookie = "age=" + f.age.value;
   document.cookie = "bmr=" + f.bmr.value;
   document.cookie = "wt=" + f.wt.value;
   document.cookie = "gen=" + f.gen.selectedIndex;
   document.cookie = "htf=" + f.htf.selectedIndex;
   document.cookie = "hti=" + f.hti.selectedIndex;
}

function BMR_chkw(w) {
   if (isNaN(parseInt(w))) {
      return false;
   } else if (w < 0) {
      return false;
   }
   else {
      return true;
   }
}

////////////////////////////////////////
////////// END BMR CALCULATOR //////////
////////////////////////////////////////




//////////////////////////////////////////
////////// START BMI CALCULATOR //////////
//////////////////////////////////////////

function BMI_cal_bmi(lbs, ins) {
   h2 = ins * ins;
   bmi = lbs/h2 * 704.5 // to convert to metric
   f_bmi = Math.floor(bmi);
   diff  = bmi - f_bmi;
   diff = diff * 10;
   diff = Math.round(diff);

   if (diff == 10) {
      // Need to bump up the whole thing instead
      f_bmi += 1;
      diff = 0;
   }

   bmi = f_bmi + "." + diff;
   return bmi;
}

function BMI_compute() {
   var f = document.forms[0];
   var fi = parseInt(f.htf.options[f.htf.selectedIndex].value * 12);
   var ii = parseInt(f.hti.options[f.hti.selectedIndex].value);
   var i = fi + ii;
 

   w = f.wt.value;
   if (BMI_chkw(w)){
      f.bmi.value = BMI_cal_bmi(w, i);
   } else { 
      alert("Please enter a number for your weight."); 
   }
   // Set cookies for future views of this page
   // Expires when user closes browser
   document.cookie = "bmi=" + f.bmi.value;
   document.cookie = "wt=" + f.wt.value;
   document.cookie = "htf=" + f.htf.selectedIndex;
   document.cookie = "hti=" + f.hti.selectedIndex;
}

function BMI_chkw(w) {
   if (isNaN(parseInt(w))) {
      return false;
   } else if (w < 0) {
      return false;
   }
   else {
      return true;
   }
}

function BMI_load_cookies() {
	var f = document.forms[0];
	f.wt.value = BMI_loadcookie("wt");
	f.bmi.value = BMI_loadcookie("bmi");
	f.htf.selectedIndex = BMI_loadcookie("htf");
	f.hti.selectedIndex = BMI_loadcookie("hti");
}

function BMI_loadcookie(name) {
    var allcookies = document.cookie;
	var value;
	var pos = allcookies.indexOf(name + "=");
	//alert("Name: " + name + " All: " + allcookies);
	var len = name.length + 1;  // length of name + 1
	if (pos != -1) {
		var start = pos + len;  //Start of cookie value
		var end = allcookies.indexOf(";", start);  //End of cookie value
		if (end == -1) end = allcookies.length;
		value = allcookies.substring(start,end); //Extract the value
		//alert("Name: " + name + " Value: " + value);
		value = unescape(value);  // Decode it, if encoded.
    	return value;
	}

    return 0;
}

////////////////////////////////////////
////////// END BMI CALCULATOR //////////
////////////////////////////////////////




//////////////////////////////////////////////
////////// START SMOKING CALCULATOR //////////
//////////////////////////////////////////////

function CSI_cal_csi(cigs, price, time) {
   csi = (cigs * (price / 20) * time);
   //window.alert(csi + "; " + cigs + "; " + time);
   f_csi = Math.floor(csi);
   diff  = csi - f_csi;
   diff = diff * 100;
   //window.alert(diff);
   diff = Math.round(diff);
   //window.alert(diff);

   if (diff == 10) {
      // Need to bump up the whole thing instead
      f_csi += 1;
      diff = 0;
   }

   if (diff == 0) {
	diff = "00";
   }

   csi = "$" + f_csi + "." + diff;
   return csi;
}

function CSI_compute() {

   var f = document.forms[0];
   var cigs = parseInt(f.cigs.value);
   
   var price = f.price.value;
   var time = parseInt(f.time.options[f.time.selectedIndex].value);
   //window.alert(cigs + "; " + price + "; " + time);

;

   if (CSI_chkw(cigs)){
		if (CSI_chkw(price)){
			f.csi.value = CSI_cal_csi(cigs, price, time);
		} else {
			f.price.focus();
			alert("Please enter a number for your price."); 
		}
   } else { 
			f.cigs.focus();
      alert("Please enter a number for the number of cigarettes per day."); 
   }
   
   
   // Set cookies for future views of this page
   // Expires when user closes browser
   document.cookie = "csi=" + f.csi.value;
   document.cookie = "cigs=" + f.cigs.value;
   document.cookie = "price=" + f.price.value;
   document.cookie = "time=" + f.time.selectedIndex;
}

function CSI_chkw(w) {
   if (isNaN(parseInt(w))) {
      return false;
   } else if (w < 0) {
      return false;
   }
   else {
      return true;
   }
}

function CSI_load_cookies() {
	var f = document.forms[0];
	f.cigs.value = CSI_loadcookie("cigs");
	f.price.value = CSI_loadcookie("price");
	f.csi.value = CSI_loadcookie("csi");
	f.time.selectedIndex = CSI_loadcookie("time");
}

function CSI_loadcookie(name) {
    var allcookies = document.cookie;
	var value;
	var pos = allcookies.indexOf(name + "=");
	//alert("Name: " + name + " All: " + allcookies);
	var len = name.length + 1;  // length of name + 1
	if (pos != -1) {
		var start = pos + len;  //Start of cookie value
		var end = allcookies.indexOf(";", start);  //End of cookie value
		if (end == -1) end = allcookies.length;
		value = allcookies.substring(start,end); //Extract the value
		//alert("Name: " + name + " Value: " + value);
		value = unescape(value);  // Decode it, if encoded.
    	return value;
	}

    return 0;
}

////////////////////////////////////////////
////////// END SMOKING CALCULATOR //////////
////////////////////////////////////////////




/////////////////////////////////////////////////
////////// START HEART RATE CALCULATOR //////////
/////////////////////////////////////////////////

function THR_cal_thr(age, il, gen) {
   
   if (gen == "F") {
		if (il == "cardio") {
			thr = (226 - age) * 0.6;
		} else {
			thr = (226 - age) * 0.8;
		}
   } else {
		if (il == "cardio") {
			thr = (220 - age) * 0.6;
		} else {
			thr = (220 - age) * 0.8;
		}
   }
   
   return thr;
}

function THR_compute() {
   var f = document.forms[0];
   var il = f.il.options[f.il.selectedIndex].value;
   var gen = f.gen.options[f.gen.selectedIndex].value;
   var age = f.age.value;

   if (THR_chkw(age)){
      f.thr.value = THR_cal_thr(age, il, gen);
   } else { 
      alert("Please enter a number for your age."); 
   }
   // Set cookies for future views of this page
   // Expires when user closes browser
   document.cookie = "thr=" + f.thr.value;
   document.cookie = "gen=" + f.gen.selectedIndex;
   document.cookie = "age=" + f.age.value;
   document.cookie = "i=" + f.il.selectedIndex;
}

function THR_chkw(w) {
   if (isNaN(parseInt(w))) {
      return false;
   } else if (w < 0) {
      return false;
   }
   else {
      return true;
   }
}

function THR_load_cookies() {
	var f = document.forms[0];
	f.thr.value = THR_loadcookie("thr");
	f.gen.selectedIndex = THR_loadcookie("gen");
	f.age.value = THR_loadcookie("age");
	f.il.selectedIndex = THR_loadcookie("il");
}

function THR_loadcookie(name) {
    var allcookies = document.cookie;
	var value;
	var pos = allcookies.indexOf(name + "=");
	//alert("Name: " + name + " All: " + allcookies);
	var len = name.length + 1;  // length of name + 1
	if (pos != -1) {
		var start = pos + len;  //Start of cookie value
		var end = allcookies.indexOf(";", start);  //End of cookie value
		if (end == -1) end = allcookies.length;
		value = allcookies.substring(start,end); //Extract the value
		//alert("Name: " + name + " Value: " + value);
		value = unescape(value);  // Decode it, if encoded.
    	return value;
	}

    return 0;
}

///////////////////////////////////////////////
////////// END HEART RATE CALCULATOR //////////
///////////////////////////////////////////////
// End the hiding here. -->