// Browser test

if (navigator.appVersion.indexOf("MSIE") != -1)
{

	isIE = true;

	isNav = false;
}
	else
{
	isIE = false;
	isNav = true;
}

var knowRecommend = "recommend";

var calculatingNow = false;

var storeBackreamerSize = 0;

var showingMoreQuestions = false;

//var displayingResults = false;
var currentlyMetric = false;
var minCleaningTime = "1 minute";

var yards_per_meter	  = 1.093613298;
var feet_per_yard	  = 3;
var liters_per_gallon = 3.786235457;
var cms_per_inch	  = 2.54;

var backreamerSize;
var fluidVolume1;
var fluidVolume2;
var timeToClean1;
var timeToClean2;
var soilRatio1;
var soilRatio2;
var currentFluidMixture;


var vol1;
var vol2;
var size;
var time1;
var time2;
var additives;
var notes;
var timeToClean, fluidVolume;

var numConduits, conduitSizeIndex, boreLength, soilTypeIndex, pumpRating, viscosityIndex, pipeLength;

var efficiency, actualPumpRating, maxSize;


// conduit sizes in inches
var conduitSizeArray = [1, 1.25, 1.5, 2, 3, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36];

// backreamer sizes in inches
var backreamerTable = new Array(30);
backreamerTable[0] = [2, 2, 3, 3, 6, 6, 10, 12, 14, 18, 22, 24, 26, 30, 32, 34, 36, 38, 40, 42, 46, 48];
backreamerTable[1] = [3, 4, 6, 6, 10, 12, 18, 22, 28, 32];
backreamerTable[2] = [4, 4, 6, 8, 10, 14, 18, 22, 28, 32];
backreamerTable[3] = [4, 6, 6, 8, 12, 16, 24, 28, 32, 40];
backreamerTable[4] = [6, 6, 8, 10, 14, 18, 26, 32, 40];
backreamerTable[5] = [6, 6, 8, 10, 14, 18, 26, 32, 40];
backreamerTable[6] = [6, 6, 8, 10, 14, 18, 26, 32, 40];
backreamerTable[7] = [6, 8, 10, 12, 18, 24, 32, 42];
backreamerTable[8] = [6, 8, 10, 12, 18, 24];
backreamerTable[9] = [8, 8, 10, 14, 20, 28];
backreamerTable[10] = [8, 8, 10, 14, 20, 28];
backreamerTable[11] = [8, 8, 10, 14, 20, 28];
backreamerTable[12] = [8, 8, 10, 14, 20, 28];
backreamerTable[13] = [8, 10, 12, 16, 22, 30];
backreamerTable[14] = [8, 10, 12, 16, 22, 30];
backreamerTable[15] = [8, 10, 12, 16, 22, 30];
backreamerTable[16] = [8, 10, 12, 16, 22, 30];
backreamerTable[17] = [8, 10, 12, 16, 24, 30];
backreamerTable[18] = [8, 10, 12, 16, 24, 30];
backreamerTable[19] = [10, 12, 14, 20, 28, 32];
backreamerTable[20] = [10, 12, 14, 20, 28, 32];
backreamerTable[21] = [10, 12, 14, 20, 28, 32];
backreamerTable[22] = [10, 12, 14, 20, 28, 32];
backreamerTable[23] = [10, 12, 14, 20, 28, 32];
backreamerTable[24] = [10, 12, 14, 20, 28, 32];
backreamerTable[25] = [10, 12, 14, 20, 28, 32];
backreamerTable[26] = [10, 12, 14, 20, 30, 32];
backreamerTable[27] = [10, 12, 14, 20, 30, 32];
backreamerTable[28] = [10, 12, 14, 20, 30, 32];
backreamerTable[29] = [10, 12, 14, 20, 30, 32];


//Minimum Backreamer bit sizes (matches array hddArray order)
var i = 0;
var minBackreamerSize = new Array();
minBackreamerSize[i++] = 0;
minBackreamerSize[i++] = 3;
minBackreamerSize[i++] = 4;
minBackreamerSize[i++] = 4;
minBackreamerSize[i++] = 4;
minBackreamerSize[i++] = 4;
minBackreamerSize[i++] = 5;
minBackreamerSize[i++] = 5;
minBackreamerSize[i++] = 5;
minBackreamerSize[i++] = 6;
minBackreamerSize[i++] = 6;
minBackreamerSize[i++] = 6;
minBackreamerSize[i++] = 6;
minBackreamerSize[i++] = 0;

//Pipe lengths (matches array hddArray order)
var i = 0;
var pipeLengthTable = new Array();
pipeLengthTable[i++] = 0;
pipeLengthTable[i++] = 5;
pipeLengthTable[i++] = 6;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 10;
pipeLengthTable[i++] = 15;
pipeLengthTable[i++] = 15;
pipeLengthTable[i++] = 15;
pipeLengthTable[i++] = 15;
pipeLengthTable[i++] = 0;


// pipe lengths in feet
var pipeLengthArray = [5, 6, 6.5, 10, 15];

function Hdd(name, gpm)
{
	this.name = name;	 //  product name
	this.gpm	 = gpm;	  //	gallons per minute
}

var hddArray = new Array();
var i = 0;
hddArray[i++] = new Hdd("JT520",			   5);
hddArray[i++] = new Hdd("JT920",			   9);
hddArray[i++] = new Hdd("JT920L",			  13);
hddArray[i++] = new Hdd("JT922",			  9);
hddArray[i++] = new Hdd("JT1220 Mach 1",	  15);
hddArray[i++] = new Hdd("JT1720",			  18);
hddArray[i++] = new Hdd("JT1720 Mach 1",	  25);
hddArray[i++] = new Hdd("JT2020 Mach 1",	  30);
hddArray[i++] = new Hdd("JT2720",			  47);
hddArray[i++] = new Hdd("JT2720 Mach 1",	  47);
hddArray[i++] = new Hdd("JT2720 All Terrain", 47);
hddArray[i++] = new Hdd("JT3020 Mach 1",	  50);
hddArray[i++] = new Hdd("JT3020 All Terrain", 50);
hddArray[i++] = new Hdd("JT4020",			  70);
hddArray[i++] = new Hdd("JT4020 Mach 1",	 120);
hddArray[i++] = new Hdd("JT4020 All Terrain",	 120);
hddArray[i++] = new Hdd("JT7020",			  75);
hddArray[i++] = new Hdd("JT7020 Mach 1",	 160);
hddArray[i++] = new Hdd("JT8020 Mach 1",	 230);
hddOther = hddArray.length+1;

function Viscosity(viscosity, efficiency)
{
	this.viscosity = viscosity;
	this.efficiency = efficiency;	 // percent
}

var viscosityArray = new Array();
i = 0;
viscosityArray[i++] = new Viscosity(40, 0.70);
viscosityArray[i++] = new Viscosity(50, 0.60);
viscosityArray[i++] = new Viscosity(60, 0.55);
viscosityArray[i++] = new Viscosity(70, 0.50);
viscosityArray[i++] = new Viscosity(80, 0.45);




//Preload the dynamic images
if (document.images)
{
	//Metric labels
	imageCm = new Image();
	imageCm.src = "Images/Lbl-CM.gif";

	imageMeters = new Image();
	imageMeters.src = "Images/Lbl-Meters.gif";

	imageLitersPerMinute = new Image();
	imageLitersPerMinute.src = "Images/Lbl-LitersPerMinute.gif";

	//US labels
	imageInches = new Image();
	imageInches.src = "Images/Lbl-Inches.gif";

	imageFeet = new Image();
	imageFeet.src = "Images/Lbl-Feet.gif";

	imageGallonsPerMinute = new Image();
	imageGallonsPerMinute.src = "Images/Lbl-GallonsPerMinute.gif";
	
	//Numbers
	imageNumber9 = new Image();
	imageNumber9.src = "Images/Img-Number9.gif";
	imageNumber9_d = new Image();
	imageNumber9_d.src = "Images/Img-Number9_d.gif";
	
	imageNumber10 = new Image();
	imageNumber10.src = "Images/Img-Number10.gif";
	imageNumber10_d = new Image();
	imageNumber10_d.src = "Images/Img-Number10_d.gif";
	
	imageNumber3 = new Image();
	imageNumber3.src = "Images/Img-Number3.gif";
	imageNumber3_d = new Image();
	imageNumber3_d.src = "Images/Img-Number3_d.gif";
	
	imageNumber4 = new Image();
	imageNumber4.src = "Images/Img-Number4.gif";
	imageNumber4_d = new Image();
	imageNumber4_d.src = "Images/Img-Number4_d.gif";

}








// FUNCTIONS START

function FluidMixture(soilType, soilCategory, additives1, additives2, notes1, notes2, soilRatio1, soilRatio2)
{
	this.soilType = soilType;
	this.soilCategory = soilCategory;
	this.additives1 = additives1;	 // U.S.
	this.additives2 = additives2;	 // Metric
	this.notes1 = notes1;		  // U.S.
	this.notes2 = notes2;		  // Metric
	this.soilRatio1 = soilRatio1;
	this.soilRatio2 = soilRatio2;
}

var fluidMixtureArray = new Array();
i = 0;

//DO NOT use special characters like 1/2 or 1/4 characters.
fluidMixtureArray[i++] = new FluidMixture("Sand-Fine", "Sandy Soil", "Bore-Gel - 35 lbs/100gals", "Bore-Gel - 16kg/378L ", "May add Quik Trol @ 1/2 lb. / 100 gals for additional filtrate control.", "May add Quik Trol @ 225g/378L for additional filtrate control.", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Sand-Course", "Sandy Soil", "Bore-Gel - 35 lbs/100gals;<br> No-Sag	- 1/2 lbs/100gals", "Bore-Gel - 16kg/378L;<br> No-Sag	 - 225g/378L", "May add Quik Trol @ 1/2 lb. / 100 gals for additional filtrate control.", "May add Quik Trol @ 225g/378L for additional filtrate control.", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Sand-Fine (Below Water Table)", "Sandy Soil", "Bore-Gel - 40 lbs/100gals;<br> Quik Trol - 3/4 lbs/100gals", "Bore-Gel - 18kg/378L;<br> Quik Trol - 340g/378L", "Add 1/2-1 gallon/100 gallons of Dinomul in high torque situations.", "Add 1.9-3.8L/378L of Dinomul in high torque situations.", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Sand-Course (Below Water Table)", "Sandy Soil", "Bore-Gel - 40 lbs/100gals;<br> Quik Trol - 3/4 lbs/100gals;<br> No-Sag	- 3/4 lbs/100gals", "Bore-Gel - 18kg/378L;<br> Quik Trol - 340g/378L;<br> No-Sag	 - 340g/378L", "Add 1/2 - 1 gallon/100gallons of Dinomul in high torque situations.", "Add 1.9-3.8L/378L of Dinomul in high torque situations.", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Gravel", "Sandy Soil", "Bore-Gel - 50 lbs/100gals;<br> Quik Trol - 3/4 lbs/100gals;<br> No-Sag - 3/4 lbs/100gals", "Bore-Gel - 23kg/378L;<br> Quik Trol - 340g/378L;<br> No-Sag - 340g/378L", "May need to add Barolift @ 1/2 lb/100 gals to reduce loss of returns.", "May need to add Barolift @ 225g/378L to reduce loss of returns.", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Cobble", "Rocky Soil", "Bore-Gel - 50 lbs/100gals;<br> Quik Trol - 3/4 lbs/100gals;<br> No-Sag	 - 3/4 lbs/100gals", "Bore-Gel - 23kg/378L;<br> Quik Trol - 340g/378L;<br> No-Sag	 - 340g/378L", "May need to add Barolift @ 1/2 lb/100 gals to reduce loss of returns.", "May need to add Barolift @ 225g/378L to reduce loss of returns.", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Sand, Gravel, and Clay or Shale", "Rocky Soil", "Bore Gel - 35 - 40lbs/100gals;<br> EZ-Mud	- 1/2 pint/100 gals;<br> Con Det	 - 1/2 gal/100 gals", "Bore Gel - 16-18kg/378L;<br> EZ-Mud	- 0.24L/378L;<br> Con Det	- 1.9L/378L", "Vary mixture according to percent of sand and clay.", "Vary mixture according to percent of sand and clay.", "2", "2");
fluidMixtureArray[i++] = new FluidMixture("Clay", "Soft Soil, Medium Soil, Hard Soil", "Poly Bore - 1/2 lbs/100 gals;<br> Con Det  - 1/2 gal/100 gals", "Poly Bore - 225g/378L;<br> Con Det	 - 1.9L/378L", "Due to the reactivity of clay, a range (3-5:1) for recommended fluid volume to clean the hole is provided. Penetrol may be used in place of ConDet at a rate of 1/4 - 1/2 gal/100gals. This will be dependent upon the swelling characteristics (reactivity) of the clay or shale.	 The more reactive the clay, the more fluid required.", "Due to the reactivity of clay, a range (3-5:1) for recommended fluid volume to clean the hole is provided.	 Penetrol may be used in place of ConDet at a rate of 0.95-1.9L/378L. This will be dependent upon the swelling characteristics (reactivity) of the clay or shale.	 The more reactive the clay, the more fluid required.", "3", "5");
fluidMixtureArray[i++] = new FluidMixture("Clay (swelling/sticky)", "Soft Soil, Medium Soil, Hard Soil", "Poly Bore - 3/4 - 1 lbs/100 gals;<br> Con Det	 - 1/2 - 1 gal/100 gals", "Poly Bore - 340-450g/378L;<br> Con Det	 - 1.9-3.8L/378L", "Due to the reactivity of clay, a range (3-5:1) for recommended fluid volume to clean the hole is provided.  Penetrol may be used in place of ConDet at a rate of 1/4 - 1/2 gal/100gals. This will be dependent upon the swelling characteristics (reactivity) of the clay or shale.	The more reactive the clay, the more fluid required.", "Due to the reactivity of clay, a range (3-5:1) for recommended fluid volume to clean the hole is provided.  Penetrol may be used in place of ConDet at a rate of 0.95-1.9L/378L. This will be dependent upon the swelling characteristics (reactivity) of the clay or shale.	 The more reactive the clay, the more fluid required.", "3", "5");
fluidMixtureArray[i++] = new FluidMixture("Rock - Solid (Shale)", "Soft Rock, Hard Rock", "Bore Gel - 40 lbs/100 gals", "Bore Gel - 18kg/378L", "Reactive shales may require use of EZ-Mud @ 1/2 pint/100 gals. (Do not use linear polymers (i.e. EZ-Mud) in conjunction with reclaiming systems!)", "Reactive shales may require use of EZ-Mud @ 0.24L/378L. (Do not use linear polymers (i.e. EZ-Mud) in conjunction with reclaiming systems!)", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Rock - Solid (Other than shale)", "Soft Rock, Hard Rock", "Bore Gel - 40-50 lbs/100 gals", "Bore Gel - 18-23kg/378L", "Large diameter or longer bores will require 1/2 lb/100 gal of No-Sag.", "Large diameter or longer bores will require 225g/378L of No-Sag.", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Rock / Clay", "Rocky Soil", "Bore Gel - 40-50 lbs/100 gals;<br> EZ-Mud	 - 1/2 pint /100 gals", "Bore Gel - 18-23kg/378L;<br> EZ-Mud	- 0.24L/378L", "Due to the reactivity of clay, a range (3-5:1) for recommended fluid volume to clean the hole is provided. Penetrol may be used in place of ConDet at a rate of 1/4 - 1/2 gal/100gals.	 (Do not use linear polymers (I.e. EZ-Mud) in conjunction with reclaiming systems!)", "Due to the reactivity of clay, a range (3-5:1) for recommended fluid volume to clean the hole is provided.	Penetrol may be used in place of ConDet at a rate of 0.95-1.9L/378L.	 (Do not use linear polymers (I.e. EZ-Mud) in conjunction with reclaiming systems!)", "3", "5");
fluidMixtureArray[i++] = new FluidMixture("Rock / Sand", "Rocky Soil", "Bore Gel - 40-50 lbs./100 gals.", "Bore Gel - 18-23kg/378L", "Large diameter or longer bores will require 1/2 lb/100 gal of No-Sag.", "Large diameter or longer bores will require 225g/378L of No-Sag.", "1", "1");
fluidMixtureArray[i++] = new FluidMixture("Rock / Fractured", "Soft Rock, Hard Rock", "Bore Gel - 50 lbs./100 gals;<br> No-Sag - 1/2 -1 lbs./100 gals", "Bore Gel - 23kg/378L;<br> No-Sag - 225-450g/378L", "1/2 lbs/100 gallons of Barolift to reduce fluid loss to formation", "225g/378L of Barolift to reduce fluid loss to formation", "1", "1");

//============================================================

function radioValue(myRadio)
{
	if (myRadio == null)
	  return "undefined";

	for (var i=0; i < myRadio.length; i++)
	{
	  if (myRadio[i].checked == true)
		 return myRadio[i].value;
	}

	return "undefined";
}

function formatDecimal(myvalue, places)
{
	if (places < 0 || places > 5)
	{
	  return Math.NaN;
	}

	var temp = Math.pow(10, places);

	theReturn = String(Math.round(myvalue * temp) / temp);

	if (theReturn.indexOf(".")<0)
	{
		theReturn = theReturn + ".00";
	}
	else if(theReturn.substr(theReturn.length-1,theReturn.length)==".")
	{
		theReturn = theReturn.substr(0,theReturn.length-1);
	}
	else if(theReturn.indexOf(".")<(theReturn.length-3))
	{
		theReturn = theReturn.substr(0,theReturn.indexOf(".")+3);
	}


	return theReturn;
}

function formatMinutes(inMinutes)
{
	var hours = Math.floor(inMinutes / 60);
	var mins	 = Math.round(inMinutes) % 60;
	var hourLabel = "hours";
	var minLabel = "minutes";

	if (hours==0&&mins==0)
	{
		return minCleaningTime
	}

	if (mins == 1)
	  minLabel = "minute";

	if (hours > 0)
	  return hours + " " + hourLabel + " " + mins + " " + minLabel;
	else
	  return mins + " " + minLabel;
}

function feetToMeters(feet)
{
	return feet / feet_per_yard / yards_per_meter;
}

function metersToFeet(meters)
{
	return meters * yards_per_meter * feet_per_yard;
}

function inchesToCm(inches)
{
	return inches * cms_per_inch;
}

function cmToInches(cm)
{
	return cm / cms_per_inch;
}

function gallonsToLiters(gallons)
{
	return gallons * liters_per_gallon;
}

function litersToGallons(liters)
{
	return liters / liters_per_gallon;
}

function isEmpty(myvalue)
{
	//myvalue = myvalue+"";

	if (myvalue == null || myvalue == "")
	  return true;

	if (myvalue.length == 0)
	  return true;

	return false;
}

function trimSpaces(myValue)
{
	//myValue = myValue+"";

	if (isEmpty(myValue))
	  return "";

	var startIndex;
	var endIndex;
	var i;

	for (i=0; i < myValue.length; i++)
	{
	  if (myValue.charAt(i) != ' ')
	  {
		 startIndex = i;
		 break;
	  }
	}

	//	 string was all whitespace
	if (startIndex >= myValue.length)
	  return "";

	for (i=myValue.length-1; i >= 0; i--)
	{
	  if (myValue.charAt(i) != ' ')
	  {
		 endIndex = i + 1;
		 break;
	  }
	}

	return myValue.substring(startIndex, endIndex);
}

function isFloat(myvalue)
{

	//myvalue= myvalue+"";

	if (isEmpty(myvalue))
	  return false;

	var startChars = ".+-0123456789";
	var otherChars = ".0123456789";
	var decimal = false;
	var foundDigit = false;
	var index;
	var mychar;

	//	 check first character
	mychar = myvalue.charAt(0);
	index = startChars.indexOf(mychar);

	if (index < 0)
	  return false;

	if (mychar == '.')
	{
	  decimal = true;
	}
	else if (mychar != '+' && mychar != "-")
	{
	  foundDigit = true;
	}

	//	 check all other characters
	for (var i=1; i < myvalue.length; i++)
	{
	  mychar = myvalue.charAt(i);
	  index = otherChars.indexOf(mychar);

	  if (index < 0)
		 return false;

	  if (mychar == '.')
	  {
		 if (decimal == true)
			return false;

		 decimal = true;
	  }
	  else
	  {
		 foundDigit = true;
	  }
	}

	return foundDigit;
}

function lookupBackreamerSize(numConduits, conduitSizeIndex)
{
	//	 input:	conduit OD size in inches
	//	 input:	conduitSizeIndex (array index)
	//	 output: backreamer size in inches

	numConduits = parseFloat(numConduits);
	conduitSizeIndex = parseFloat(conduitSizeIndex);

	if (numConduits < 1 || numConduits > backreamerTable.length)
	{
            return "undefined";
	}

	if (conduitSizeIndex < 0 || conduitSizeIndex >= backreamerTable[numConduits-1].length)
	{
            return "undefined";
	}

	theReturn = backreamerTable[numConduits-1][conduitSizeIndex];

	selectedHdd = document.myform.hdd.selectedIndex;
	if (selectedHdd == hddOther)
	{
            var minSize = parseFloat(document.moreQuestionsForm.bitSize.options[document.moreQuestionsForm.bitSize.selectedIndex].value);

            if (theReturn < minSize)
                theReturn = minSize;
	}

	return theReturn;
}

function calcActualPumpRating(pumpRating, efficiency)
{
	//	 input: pumpRating in gallons per minute
	//	 input: efficiency 0.0 - 1.0

	if (efficiency < 0 || efficiency > 1)
	{
	  //alert("Efficiency must be in the range of 0 - 1 (" + efficiency+ ").");
	  return "undefined";
	}

	return pumpRating * efficiency;
}

function calcFluidVolume(backreamerSize, boreLength, soilRatio)
{
	//	 input:	backreamer size in inches
	//	 output: fluid volume in gallons



	backreamerSize = parseFloat(backreamerSize);
	boreLength = parseFloat(boreLength);
	soilRatio = parseFloat(soilRatio);

	//alert("backreamerSize = " + backreamerSize + ", boreLength = " + boreLength + ", soilRatio = " + soilRatio);

	var a = backreamerSize * backreamerSize / 25;
	theReturn =  a * soilRatio * boreLength;

	//alert(theReturn);

	return theReturn;
}

function calcTimeToClean(backreamerSize, soilRatio, pipeLength, pumpOutput)
{
	//	 input:	backreamer size in inches
	//	 input:	soilRatio
	//	 input:	pipeLength in feet
	//	 input:	pumpOutput in gallons per minute
	//	 output: time per pipe to clean hole in minutes

	//alert("backreamerSize = " + backreamerSize + ", soilRatio = " + soilRatio + ", pipeLength = " + pipeLength + ", pumpOutput = " + pumpOutput);


	tempBackreamerSize = parseFloat(backreamerSize);
	tempPipeLength = parseFloat(pipeLength);
	tempPumpOutput = parseFloat(pumpOutput);


	var a = tempBackreamerSize * tempBackreamerSize / 25;
	theReturn =  a * soilRatio * tempPipeLength / tempPumpOutput;

	//alert("theReturn = " + theReturn);

	return theReturn;
}



function calculate(doRefresh)
{
	//alert(knowRecommend);

	//	 get values from form
	
	if(!hasCookies)
	{
		alert("Please Note:\rThe Drilling Fluid Formulator requires that cookies be enabled in your browser.\rIn order to proceed, enable cookies and then reload this page.");
		return;
	}

	numConduits		= document.myform.numConduits.options[document.myform.numConduits.selectedIndex].value;
	conduitSizeIndex = document.myform.conduitSize.options[document.myform.conduitSize.selectedIndex].value;
	boreLength		= parseFloat(trimSpaces(document.myform.boreLength.value));
	soilTypeIndex	= document.myform.soilType.options[document.myform.soilType.selectedIndex].value;
	pumpRating		= parseFloat(document.myform.pumpRating.value);
	viscosityIndex = document.myform.viscosity.options[document.myform.viscosity.selectedIndex].value;

	pipeLength		 = parseFloat(document.moreQuestionsForm.pipeLength.options[document.moreQuestionsForm.pipeLength.selectedIndex].value);

	//var bz = "" ;
	//bz = parseFloat(document.moreQuestionsForm.bitSize.options[document.moreQuestionsForm.bitSize.selectedIndex].value);

	backreamerSize = parseFloat(document.myform.backreamerSize.value);
	//alert("1");

	// If a DitchWitch model is selected, use preset data.
	if (!showingMoreQuestions)
	{
		selectedHdd = document.myform.hdd.selectedIndex;
		pipeLength = pipeLengthTable[selectedHdd];
	}


	//alert("2");
	//	 validate input parameters
	//alert(backreamerSize);
	if ( (isEmpty(document.myform.backreamerSize.value)||document.myform.backreamerSize.value<=0) && (knowRecommend=="know"))
	{
		alert("Please enter a backreamer size, or choose to have one recommended for you.");
		document.myform.backreamerSize.focus();
		redrawLabels();
		return;
	}
	//alert("3");
	if (currentlyMetric)
	{
		backreamerTest = cmToInches(backreamerSize);
		if ( ((backreamerTest<1)||(backreamerTest>48)) && (knowRecommend=="know") )
		{
			alert("Please enter a backreamer size between 3 and 121 cm, or choose to have one recommended for you.");
			document.myform.backreamerSize.focus();
			redrawLabels();
			return;
		}
	}
	else
	{
		backreamerTest = backreamerSize;
		if ( ((backreamerTest<1)||(backreamerTest>48)) && (knowRecommend=="know") )
		{
			alert("Please enter a backreamer size between 1 and 48 inches, or choose to have one recommended for you.");
			document.myform.backreamerSize.focus();
			redrawLabels();
			return;
		}
	}
	//alert("4");

	if ( (isEmpty(numConduits)) && (knowRecommend=="recommend") )
	{
	  alert("Please select the number of conduits.");
	  document.myform.numConduits.focus();
	  redrawLabels();
	  return;
	}
	//alert("5");
	if ( (isEmpty(conduitSizeIndex)) && (knowRecommend=="recommend") )
	{
	  alert("Please select a conduit size.");
	  document.myform.conduitSize.focus();
	  redrawLabels();
	  return;
	}
	//alert("6");
	if ( isEmpty(boreLength+"") || ! isFloat(boreLength+"") || boreLength <= 0)
	{
	  alert("Bore length must be a number greater than 0.");
	  document.myform.boreLength.focus();
	  redrawLabels();
	  return;
	}
	//alert("7");
	if ( isEmpty(soilTypeIndex) )
	{
	  alert("Please select a soil type.");
	  document.myform.soilType.focus();
	  redrawLabels();
	  return;
	}

	//Check HDD System
	selectedHdd = document.myform.hdd.selectedIndex;

	if(selectedHdd==0)
	{
		alert("Please select an HDD System.");
		document.myform.hdd.focus();
		redrawLabels();
		return;
	}


//	 if ( isEmpty(pumpRating) )
//	 {
//		alert("Please select an hdd.");
//		document.myform.hdd.focus();
//		return;
//	 }

	if ( isEmpty(viscosityIndex) )
	{
	  alert("Please select a viscosity.");
	  document.myform.viscosity.focus();
	  redrawLabels();
	  return;
	}


	if(showMoreQuestions && document.myform.hdd.selectedIndex == 13) {

		if(document.moreQuestionsForm.pipeLength.selectedIndex == 0) {
			alert("Please select a pipe length.");
			document.moreQuestionsForm.pipeLength.focus();
			redrawLabels();
			return ;
		}

		if(document.moreQuestionsForm.bitSize.selectedIndex == 0) {
			alert("Please select a bitsize.");
			document.moreQuestionsForm.bitSize.focus();
			redrawLabels();
			return ;
		}

	}


//	if ( isEmpty(pipeLength) )
//	{
//		document.moreQuestionsForm.pipeLength.focus();
//	 	return;
//	}



	if ( isEmpty(pumpRating+"") || ! isFloat(pumpRating+"") || pumpRating <= 0)
	{
	  alert("Pump rating must be a number greater than 0.");
	  document.myform.pumpRating.focus();
	  redrawLabels();
	  return;
	}

	if (currentlyMetric)
	{
	  //	convert bore length and pump rating from metric to US
	  boreLength = metersToFeet(boreLength);
	  pumpRating = litersToGallons(pumpRating);
	}

	//	 perform lookups
	soilRatio1	  = fluidMixtureArray[soilTypeIndex].soilRatio1;
	soilRatio2	  = fluidMixtureArray[soilTypeIndex].soilRatio2;
	currentFluidMixture = fluidMixtureArray[soilTypeIndex];
	efficiency = viscosityArray[viscosityIndex].efficiency;


	if (knowRecommend=="recommend")
	{
		backreamerSize = lookupBackreamerSize(numConduits, conduitSizeIndex);

		if (backreamerSize == "undefined")
		{
			alert("Conduit size too big for the number of conduits being pulled back.");
			document.myform.conduitSize.focus();
			redrawLabels();
			return;
		}
	}
	else
	{
		backreamerSize = parseFloat(document.myform.backreamerSize.value);
		if(currentlyMetric)
		{
			backreamerSize = parseFloat(cmToInches(backreamerSize));
		}
	}






	//Backreamer & Pilot Bore Bit Size validation
	selectedHdd = document.myform.hdd.selectedIndex;

	backreamerSize = parseFloat(backreamerSize);


	if (knowRecommend=="know")
	{
		if (selectedHdd==hddOther)
		{
			testSize = backreamerSize;


			pilotBoreBitSize = parseFloat(document.moreQuestionsForm.bitSize.options[document.moreQuestionsForm.bitSize.selectedIndex].value);

			//alert("testSize = " + testSize + ", pilotBoreBitSize = " + pilotBoreBitSize);
			if (testSize<pilotBoreBitSize)
			{
				alert("To ensure effective backreaming, you must use a backreamer (question 2) with the same size or larger than the selected pilot bore bit size (question 10).");
				document.myform.backreamerSize.focus();
				redrawLabels();
				return;
			}
		}
		else
		{
			if (currentlyMetric)
			{
				testVal = formatDecimal(inchesToCm(minBackreamerSize[selectedHdd]),2);
				testUnits = "CM";
			}
			else
			{
				testVal = minBackreamerSize[selectedHdd];
				testUnits = "Inches";
			}

			if (backreamerSize<testVal)
			{
				alert("To ensure effective backreaming with the Ditch Witch model selected, you must use a backreamer " + testVal + " " + testUnits + " or larger");
				document.myform.backreamerSize.focus();
				redrawLabels(); 
				return;
				//backreamerSize = minBackreamerSize[selectedHdd];
			}
		}
	}

        if (selectedHdd != hddOther)
        {
            var minSize = minBackreamerSize[selectedHdd];
            if (backreamerSize < minSize)
                backreamerSize = minSize;
        }

	//	 perform calculations
	actualPumpRating = calcActualPumpRating(parseFloat(pumpRating), parseFloat(efficiency));
	fluidVolume1 = calcFluidVolume(parseFloat(backreamerSize), parseFloat(boreLength), parseFloat(soilRatio1));
	fluidVolume2 = calcFluidVolume(parseFloat(backreamerSize), parseFloat(boreLength), parseFloat(soilRatio2));
	timeToClean1 = calcTimeToClean(parseFloat(backreamerSize), parseFloat(soilRatio1), parseFloat(pipeLength), parseFloat(actualPumpRating));
	timeToClean2 = calcTimeToClean(parseFloat(backreamerSize), parseFloat(soilRatio2), parseFloat(pipeLength), parseFloat(actualPumpRating));


	//	 output results to user
	updateResults();
	if(doRefresh)
	{
		showResults();
	}

	displayingResults = true;
}

function hideResults()
{
	displayingResults = false;
	hideMoreQuestions();

	clearCookie();

	document.resetForm.submit();
}

function leavingPage()
{
	if (!calculatingNow)
	{
		clearCookie();
	}
}

function clearCookie()
{
	theCookie = "";
	createCookie("DW_DFF_TOOL",theCookie);
}

function showResults()
{
	//document.all.resultsTable.style.visibility = "visible";

	displayingResults=true;

	document.myform.submit();
}


function updateResults()
{
	calculatingNow = true;

	vol1 = fluidVolume1;
	vol2 = fluidVolume2;
	size = backreamerSize;
	time1 = formatMinutes(timeToClean1);
	time2 = formatMinutes(timeToClean2);




	//Account for minimum Backreamer sizes for the different models of HDD Systems
	selectedHdd = document.myform.hdd.selectedIndex;
	//alert("Selected Hdd: " + selectedHdd);
	//alert("minBackreamerSize[selectedHdd] = " + minBackreamerSize[selectedHdd]);






	//if (selectedHdd==hddOther)
	//{
	//	size = parseFloat(document.myform.backreamerSize.value);
	//}


	//alert("size = " + size);



	if (currentlyMetric)
	{
		//vol1 = gallonsToLiters(vol1);
		//vol2 = gallonsToLiters(vol2);
		if(knowRecommend=="recommend")
		{
			size = inchesToCm(size);
		}
		if ( currentFluidMixture != null )
		{
			additives = currentFluidMixture.additives2;
			notes = currentFluidMixture.notes2;
		}
	}
	else
	{
		if ( currentFluidMixture != null )
		{
			additives = currentFluidMixture.additives1;
			notes = currentFluidMixture.notes1;
		}
	}

  // alert("vol1 before = " + vol1);

	vol1 = formatDecimal(vol1, 1);
	vol2 = formatDecimal(vol2, 1);
	size = formatDecimal(size, 1);

	if (currentlyMetric)
	{
		//alert(currentlyMetric);
		vol1 = formatDecimal(gallonsToLiters(vol1),1);
		vol2 = formatDecimal(gallonsToLiters(vol2),1);
	}


	//alert("vol1 after = " + vol1);

 // alert("soilRatio1 = " + soilRatio1 + ", soilRatio2 = " + soilRatio2);

	if (soilRatio1 == soilRatio2)
	{
	  timeToClean = time1;
	  fluidVolume = vol1;
	}
	else
	{
	  timeToClean = time1 + " - " + time2;
	  fluidVolume = vol1 + " - " + vol2;
	}

	theCookie = "";


	// WRITE OUT ORIGINAL FORM FIELDS FOR PREPOPULATION
	if(document.myform.knowRecommend[0].checked)
	{
		theCookie += "knowRecommend:recommend/";
	}
	else
	{
		theCookie += "knowRecommend:know/";
	}

	theCookie +="backreamerSize:" + parseFloat(document.myform.backreamerSize.value) + "/";

	theCookie += "numConduits:" + document.myform.numConduits.selectedIndex + "/";

	theCookie += "conduitSize:" + document.myform.conduitSize.selectedIndex + "/";

	theCookie +="boreLength:" + parseFloat(document.myform.boreLength.value) + "/";

	theCookie += "soilType:" + document.myform.soilType.selectedIndex + "/";

	theCookie += "hdd:" + document.myform.hdd.selectedIndex + "/";

	theCookie +="pumpRating:" + parseFloat(document.myform.pumpRating.value) + "/";

	theCookie += "viscosity:" + document.myform.viscosity.selectedIndex + "/";

	theCookie += "pipeLength:" + document.moreQuestionsForm.pipeLength.selectedIndex + "/";

	theCookie += "bitSize:" + document.moreQuestionsForm.bitSize.selectedIndex + "/";


	theCookie += "showingMoreQuestions:" + showingMoreQuestions + "/";



	// Write out info for Results
	if (currentlyMetric)
	{
		//document.hiddenResults.resultUnits.value = "metric";
		theCookie += "units:metric/";
	}
	else
	{
		//document.hiddenResults.resultUnits.value = "us";
		theCookie += "units:us/";
	}




	theCookie += "fluidVolume:" + superEscape(fluidVolume) + "/";

	if (knowRecommend=="know")
	{
		theCookie += "size:" + superEscape(parseFloat(document.myform.backreamerSize.value)) + "/";
	}
	else
	{
		theCookie += "size:" + superEscape(size) + "/";

	}


	theCookie += "additives:" + superEscape(additives) + "/";
	theCookie += "notes:" + superEscape(notes) + "/";
	theCookie += "timeToClean:" + superEscape(timeToClean) + "/";

	//alert(theCookie);

	theCookie += "displayingResults:true/";

	createCookie("DW_DFF_TOOL",theCookie);

}

// Escape a string, and also deal with any slashes / or semicolons ;
function superEscape(theString)
{
	theString = ""+theString;

	//replace any semi-colons with "SEMICOLON"
	while(theString.indexOf(";")!=-1)
	{
		theString = theString.replace(";","SEMICOLON");
	}


	theString = escape(theString);

	while(theString.indexOf("/")!=-1)
	{
		theString = theString.replace("/","SLSH");
	}

	return theString;
}

// Unescape a string, and also deal with any slashes SLSH or SEMICOLON
function superUnescape(theString)
{
	theString = ""+theString;

	//replace any "SEMICOLON" with semi-colons
	while(theString.indexOf("SEMICOLON")!=-1)
	{
		theString = theString.replace("SEMICOLON",";");
	}

	while(theString.indexOf("SLSH")!=-1)
	{
		theString = theString.replace("SLSH","/");
	}

	return theString;
}

function myReset()
{
	document.myform.reset();
	hideResults();
	americanLabels();
}

function metricLabels()
{
	//document.all.conduitSizeLabelSpan.innerHTML	= "cm";
	document.myform.conduitSizeLabel.src = imageCm.src;

	document.myform.backreamerSizeLabel.src = imageCm.src;

	//document.all.boreLengthLabelSpan.innerHTML		= "meters";
	document.myform.boreLengthLabel.src = imageMeters.src;

	//document.all.pipeLengthLabelSpan.innerHTML		= "meters";
	document.moreQuestionsForm.pipeLengthLabel.src = imageMeters.src;


	//document.all.pumpRatingLabelSpan.innerHTML		= "liters per minute";
	document.myform.pumpRatingLabel.src = imageLitersPerMinute.src;

	document.moreQuestionsForm.bitSizeLabel.src = imageCm.src;

}

function metricDDLBs()
{
	// conduit size
	for (i=1; i < document.myform.conduitSize.options.length; i++)
	{
	  myValue = formatDecimal( inchesToCm(conduitSizeArray[i-1]), 1);

	  //If it's not a number, don't add it to the DDLB
	  testString = ""+myValue;
	  if (testString!="NaN")
	  {
		document.myform.conduitSize.options[i].text = myValue;
	  }
	}

	// pipe length
	for (i=0; i < pipeLengthArray.length; i++)
	{
	  myValue = formatDecimal( feetToMeters(pipeLengthArray[i]), 1);
	 document.moreQuestionsForm.pipeLength.options[i+1].text = myValue;

	}


	//	 bit size
	//alert(document.moreQuestionsForm.bitSize.options.length);

	for (i=1; i < document.moreQuestionsForm.bitSize.options.length; i++)
	{
		myValue = formatDecimal( inchesToCm(document.moreQuestionsForm.bitSize.options[i].text), 1);
		document.moreQuestionsForm.bitSize.options[i].text = myValue;
	}

}

function metricFormFields()
{

	var i;
	var myValue;

	metricDDLBs();

	//	 bore length
	boreLength = parseFloat(trimSpaces(document.myform.boreLength.value));
	if ( !isEmpty(boreLength+"") && isFloat(boreLength+"") )
	{
	  boreLength = formatDecimal(feetToMeters(boreLength), 1);
	  document.myform.boreLength.value = boreLength;
	}

	//	 backreamer size
	backreamerSize = parseFloat(trimSpaces(document.myform.backreamerSize.value));
	if ( !isEmpty(backreamerSize+"") && isFloat(backreamerSize+"") )
	{
	  backreamerSize = formatDecimal(inchesToCm(backreamerSize), 1);
	  document.myform.backreamerSize.value = backreamerSize;
	}

	//	 pump rating
	pumpRating = parseFloat(trimSpaces(document.myform.pumpRating.value));
	if ( !isEmpty(pumpRating) && isFloat(pumpRating+"") )
	{
	  pumpRating = formatDecimal(gallonsToLiters(pumpRating), 1);
	  document.myform.pumpRating.value = pumpRating;
	}

	//	 hdd
	for (i=0; i < hddArray.length; i++)
	{
	  myValue = formatDecimal( gallonsToLiters(hddArray[i].gpm), 0);
	  document.myform.hdd.options[i+1].text = hddArray[i].name;
	}


}

function toMetric()
{

	if (currentlyMetric)
	{
		return;
	}

	metricFormFields();
	if (displayingResults)
	{
		updateResults();
	}
	metricLabels();
	currentlyMetric = true;

	if (displayingResults)
	{
	calculate(1);
	}
}

function americanLabels()
{
	//document.all.conduitSizeLabelSpan.innerHTML	= "inches";
	document.myform.conduitSizeLabel.src = imageInches.src;

	document.myform.backreamerSizeLabel.src = imageInches.src;

	//document.all.boreLengthLabelSpan.innerHTML		= "feet";
	document.myform.boreLengthLabel.src = imageFeet.src;

	//document.all.pipeLengthLabelSpan.innerHTML		= "feet";

	document.moreQuestionsForm.pipeLengthLabel.src = imageFeet.src;


	//document.all.pumpRatingLabelSpan.innerHTML		= "gallons per minute";
	document.myform.pumpRatingLabel.src = imageGallonsPerMinute.src;

	document.moreQuestionsForm.bitSizeLabel.src = imageInches.src

}

function americanDDLBs()
{
	// conduit size
	for (i=1; i < document.myform.conduitSize.options.length; i++)
	{
		document.myform.conduitSize.options[i].text = conduitSizeArray[i-1];
	}

	// pipe length
	for (i=0; i < pipeLengthArray.length; i++)
	{
		document.moreQuestionsForm.pipeLength.options[i+1].text = pipeLengthArray[i];

	}

	//	 bit size
	//alert(document.moreQuestionsForm.bitSize.options.length);

	for (i=1; i < document.moreQuestionsForm.bitSize.options.length; i++)
		{
			document.moreQuestionsForm.bitSize.options[i].text = parseFloat(document.moreQuestionsForm.bitSize.options[i].value);
		}

}

function americanFormFields()
{
	var i;

	americanDDLBs();


	//	 bore length
	boreLength = parseFloat(trimSpaces(document.myform.boreLength.value));
	if ( !isEmpty(boreLength) && isFloat(boreLength+"") )
	{
	  boreLength = formatDecimal(metersToFeet(boreLength), 1);
	  document.myform.boreLength.value = boreLength;
	}

	//	 backreamer size
	backreamerSize = parseFloat(trimSpaces(document.myform.backreamerSize.value));
	if ( !isEmpty(backreamerSize) && isFloat(backreamerSize+"") )
	{
	  backreamerSize = formatDecimal(cmToInches(backreamerSize), 1);
	  document.myform.backreamerSize.value = backreamerSize;
	}

	//	 pump rating
	pumpRating = parseFloat(trimSpaces(document.myform.pumpRating.value));
	if ( !isEmpty(pumpRating) && isFloat(pumpRating+"") )
	{
	  pumpRating = formatDecimal(litersToGallons(pumpRating), 1);
	  document.myform.pumpRating.value = pumpRating;
	}

	//	 hdd
	for (i=0; i < hddArray.length; i++)
	{
	  myValue = hddArray[i].gpm;
	  document.myform.hdd.options[i+1].text = hddArray[i].name;
	}
}

function toAmerican()
{
	if (!currentlyMetric)
	{
		return
	}

	americanFormFields();
	if (displayingResults)
	{
		updateResults();
	}
	americanLabels();

	currentlyMetric = false;

	if (displayingResults)
	{
	calculate(1);
	}
}

//============================================================

function seedNumConduits()
{
	var i;

	for (i=1; i <= backreamerTable.length; i++)
	{
	  document.write('<option value="' + i + '"> ' + i + '</option>');
	}
}

function seedConduitSize()
{
	return;

	var i;

	for (i=0; i < conduitSizeArray.length; i++)
	{
	  document.write('<option value="' + i + '"> ' + conduitSizeArray[i] + '</option>');
	}
}

function seedPipeLengths()
{
	var i;

	for (i=0; i < pipeLengthArray.length; i++)
	{
	  document.write('<option value="' + pipeLengthArray[i] + '"> ' + pipeLengthArray[i] + '</option>');
	}
}

function seedHdd()
{
	var i;

	for (i=0; i < hddArray.length; i++)
	{
	  document.write('<option value="' + hddArray[i].gpm + '"> ' + hddArray[i].name + '</option>');
	}
}

function seedViscosities()
{
	var i;

	for (i=0; i < viscosityArray.length; i++)
	{
	  document.write('<option value="' + i + '"> ' + viscosityArray[i].viscosity + '</option>');
	}
}

function seedSoilTypes()
{
	var i;

	for (i=0; i < fluidMixtureArray.length; i++)
	{
	  document.write('<option value="' + i + '"> ' + fluidMixtureArray[i].soilType + '</option>');
	}
}

function selectHdd()
{
	if (currentlyMetric)
	{
		  var liters = gallonsToLiters(parseFloat(document.myform.hdd.options[document.myform.hdd.selectedIndex].value));
		  document.myform.pumpRating.value = formatDecimal(liters, 2);
	}
	else
	{
	  document.myform.pumpRating.value = parseFloat(document.myform.hdd.options[document.myform.hdd.selectedIndex].value);
	}

	if (document.myform.hdd.selectedIndex == hddOther || document.myform.hdd.selectedIndex == 0)
	{
		showMoreQuestions();
		document.myform.pumpRating.value = 0;
		document.myform.pumpRating.focus();
	}
	else
	{
		hideMoreQuestions();
	}
	
	redrawLabels();
}



// This function takes care of an IE problem in Win2000 which makes images
// disappear when alerts pop up.
function redrawLabels()
{
	if(showingMoreQuestions)
	{
		showMoreQuestions();
	}
	else
	{
		hideMoreQuestions();
		if(currentlyMetric)
		{
			metricLabels();
		}
		else
		{
			americanLabels();
		}
	}

	
}

function showMoreQuestions()
{

	//alert("Enable 9 & 10");
	document.moreQuestionsForm.pipeLength.disabled = false;
	document.moreQuestionsForm.bitSize.disabled = false;

	document.moreQuestionsForm.question9.src = imageNumber9.src;
	document.moreQuestionsForm.question10.src = imageNumber10.src;

	showingMoreQuestions = true;

	if(currentlyMetric)
	{
		metricLabels();
	}
	else
	{
		americanLabels();
	}
	
	if(isNav)
	{
		if(currentlyMetric)
		{
			// pipe length
			document.moreQuestionsForm.pipeLength.options[0].text = "Please Select...";
			for (i=0; i < pipeLengthArray.length; i++)
			{
			  myValue = formatDecimal( feetToMeters(pipeLengthArray[i]), 1);
			 document.moreQuestionsForm.pipeLength.options[i+1].text = myValue;
			}
			
			//	 bit size
			//alert(document.moreQuestionsForm.bitSize.options.length);
			document.moreQuestionsForm.bitSize.options[0].text = "Please Select...";
			for (i=1; i < document.moreQuestionsForm.bitSize.options.length; i++)
			{
				myValue = formatDecimal( inchesToCm(document.moreQuestionsForm.bitSize.options[i].text), 1);
				document.moreQuestionsForm.bitSize.options[i].text = myValue;
			}
	
		}
		else
		{
			// pipe length
			document.moreQuestionsForm.pipeLength.options[0].text = "Please Select...";
			for (i=0; i < pipeLengthArray.length; i++)
			{
				document.moreQuestionsForm.pipeLength.options[i+1].text = pipeLengthArray[i];

			}
			
			//	 bit size
			document.moreQuestionsForm.bitSize.options[0].text = "Please Select...";
			for (i=1; i < document.moreQuestionsForm.bitSize.options.length; i++)
			{
				document.moreQuestionsForm.bitSize.options[i].text = parseFloat(document.moreQuestionsForm.bitSize.options[i].value);
			}
		}
		
	}
}

function hideMoreQuestions()
{
	//alert("Disable 9 & 10");
	document.moreQuestionsForm.pipeLength.disabled = true;
	document.moreQuestionsForm.bitSize.disabled = true;

	document.moreQuestionsForm.question9.src = imageNumber9_d.src;
	document.moreQuestionsForm.question10.src = imageNumber10_d.src;

	showingMoreQuestions = false;
	
	
	if(isNav)
	{
		// pipe length
		document.moreQuestionsForm.pipeLength.options[0].text = "Not required";
		for (i=0; i < pipeLengthArray.length; i++)
		{
		 document.moreQuestionsForm.pipeLength.options[i+1].text = " ";
		}
		document.moreQuestionsForm.pipeLength.selectedIndex = 0;
		
		
		//	 bit size
		document.moreQuestionsForm.bitSize.options[0].text = "Not required";
		for (i=1; i < document.moreQuestionsForm.bitSize.options.length; i++)
		{
			document.moreQuestionsForm.bitSize.options[i].text = " ";
		}
		document.moreQuestionsForm.bitSize.selectedIndex = 0;
	}
	
}

function numConduitsChanged()
{
	if(knowRecommend=="know")
	{
		return;
	}
	
	numConduits = parseFloat(document.myform.numConduits.options[document.myform.numConduits.selectedIndex].value);
	maxSize = 0;
	//document.myform.conduitSize.options.length = 0;
	document.myform.conduitSize.options[0] = new Option('Please Select...','');
	//alert("numConduits: " + numConduits);
	if(numConduits != ""){
		maxSize = backreamerTable[numConduits-1].length
		//alert(maxSize);
		//if(numConduits < 2){
			//maxSize = conduitSizeArray.length;
		//}else{
		//	maxSize = 6;
		//}
	}

	//document.myform.conduitSize.options.length = maxSize;

	for (var i = 0; i < maxSize; i++)
	{

		//alert("loop " + i);

		var myValue = conduitSizeArray[i];

		//alert("myValue " + myValue);

		if ( currentlyMetric )
		{
			myValue = formatDecimal( inchesToCm(myValue), 1);
		}

		document.myform.conduitSize.options[i+1] = new Option(myValue,i);
	}

	for (var i = maxSize; i < 25; i++)
	{
		document.myform.conduitSize.options[i+1] = new Option(" ",i);
	}

	//alert(document.myform.numConduits.options[2].value);
	//alert(document.myform.conduitSize.options.length);
}

function conduitSizeChanged()
{
}

function pumpRatingChanged()
{
	document.myform.hdd.selectedIndex = hddOther;
	showMoreQuestions();
}


//When "Recommend" backreamer size is selected in question 2, activate questions 3 and 4
function doRecommend()
{
	document.myform.question3.src = imageNumber3.src;
	document.myform.question4.src = imageNumber4.src;

	document.myform.numConduits.disabled = false;
	document.myform.conduitSize.disabled = false;

	document.myform.backreamerSize.value = "";

	knowRecommend = "recommend";
	
	if(isNav)
	{
		// num conduits
		document.myform.numConduits.options[0].text = "Please Select...";
		for (i=1; i < document.myform.numConduits.options.length; i++)
		{
		  document.myform.numConduits.options[i].text = i;
		}
		
		// conduit size
		document.myform.conduitSize.options[0].text = "Please Select...";
		numConduitsChanged()
	}
}


//When "Know" backreamer size is selected in question 2, dim questions 3 and 4
function doKnow(dontfocus)
{
	document.myform.question3.src = imageNumber3_d.src;
	document.myform.question4.src = imageNumber4_d.src;
	
	if(dontfocus!="dontfocus")
	{
		document.myform.backreamerSize.focus();
	}

	document.myform.numConduits.disabled = true;
	document.myform.conduitSize.disabled = true;

	knowRecommend = "know";
	
	if(isNav)
	{
		// num conduits
		document.myform.numConduits.options[0].text = "Not required";
		for (i=1; i < document.myform.numConduits.options.length; i++)
		{
		  document.myform.numConduits.options[i].text = " ";
		}
		document.myform.numConduits.selectedIndex = 0;
		
		// conduit size
		document.myform.conduitSize.options[0].text = "Not required";
		for (i=1; i < document.myform.conduitSize.options.length; i++)
		{
		  document.myform.conduitSize.options[i].text = " ";
		}
		document.myform.conduitSize.selectedIndex = 0;
	}
	
}




//============================================================
// Scripts for Cookies (transferring data to results frame)
//============================================================


//escape value before sending to this function!
function createCookie(name, value)
{
	var cookienew = name + "=" + value;
	document.cookie = cookienew;
}



function getCookie(name)
{
	fullCookie = unescape(document.cookie);
	cookieToEnd = fullCookie.substring(fullCookie.indexOf(name),fullCookie.length);

	if (cookieToEnd.indexOf(";")!=-1)
	{
		theCookie = cookieToEnd.substring(0,cookieToEnd.indexOf(";"));
	}
	else
	{
		theCookie = cookieToEnd;
	}

	return theCookie
}



function getProperty(fullCookie,propName)
{
	if(fullCookie.indexOf(propName)==-1)
	{
		return "(error)"
	}

	propToEnd = fullCookie.substring(fullCookie.indexOf(propName),fullCookie.length);

	if (propToEnd.indexOf("/")==-1)
	{
		theProperty = propToEnd;
	}
	else
	{
		theProperty = propToEnd.substring(0,propToEnd.indexOf("/"));
	}

	thePropertyVal = theProperty.substring(theProperty.indexOf(":")+1,theProperty.length);

	return thePropertyVal;

}


function changeBackreamerSize()
{
	if (document.myform.backreamerSize.value=="")
	{
		document.myform.knowRecommend[0].checked = true;
		doRecommend();
	}
	else
	{
		document.myform.knowRecommend[1].checked = true;
		doKnow("dontfocus");
	}
}














