var theMain = "";

var theSubcatID = "";

var theSubcat = "";



var Main   = new Array();

var SubcatIDs = new Array();



Main[0]='Hard Pine $6.20,Rustic Pine  $2.60,Southern Yellow Pine  $3.70,Hickory  Select Long Lane $4.45,Hickory Common $3.65,Hickory Select Random Lane	$4.25,Hickory Lane Caracter $3.70,Cyprus $3.70,Laminate Only (7mm) $5.05,Laminate Only (8mm) $5.35';

SubcatIDs[0]='6.20,2.60,3.70,4.45,3.65,4.25,3.70,3.70,5.05,5.35'; 



Main[1]='Yellow Bamboo horizontal grain $4.69,Carbonized Bamboo horizontal $5.05,Yellow Bamboo vertical $5.50';

SubcatIDs[1]='4.69,5.05,5.50'; 



Main[2]='Red Oak $3.45,White Oak  $3.09,Brazilian Cherry $3.49,American Cherry $4.95,Maple $3.79,Cyprus $3.55,Walnut $4.95,Santos Mahogany $4.30,Yellow Bamboo horizontal grain $4.99,Yellow Bamboo vertical $4.89,Carbonized Bamboo horizontal $4.79';

SubcatIDs[2]='3.45,3.09,3.49,4.95,3.79,3.55,4.95,4.30,4.99,4.89,4.79'; 



Main[3]='Yosemite Natural $5.43,Mojave Wheat $5.43,Yukon Toast $5.43';

SubcatIDs[3]='5.43,5.43,5.43'; 



Main[4]='Everglades Natural $5.43,Cherokee Chestnut $5.43,Coronado Cinnamon $5.43';

SubcatIDs[4]='5.43,5.43,5.43'; 



Main[5]='Breckenridge Natural $5.99,Ozark Bordeaux $5.99';

SubcatIDs[5]='5.99,5.99'; 



function ClearList(OptionList, TitleName)

{       OptionList.length = 0;

        OptionList.options[0] = new Option(TitleName, '', true, true);

}

function LoadMain(Index)

{       // ClearList(document.forms[0].subcategory, '-----Select Finish -----');

        if (Index > 0)

        {       var CurrentMain = Main[Index - 1].split(',');

                var CurrentSubcatIDs = SubcatIDs[Index - 1].split(',');

                for (var i=0; i<CurrentMain.length; i++)

                        document.forms[0].subcategory.options[i+1] = new Option(CurrentMain[i], CurrentSubcatIDs[i], false, false);

                                                

                        if (theSubcat != "" && theMain == document.forms[0].category.options[document.forms[0].category.selectedIndex].value){                                          

                        changeModel(theSubcat);

                        }else{

                        document.forms[0].subcategory.options[0].selected = true;

                        }

        }

}



function changeModel(theOption)

{

document.forms[0].subcategory.options[theOption].selected = true;

}



function ChangeDivision(CalledFromOnLoad)

{       // Clear both of the lists first then add the options if valid category has been selected. -GDC 

        var CurrModel = document.forms[0].subcategory.selectedIndex;

        var Selectedcategory  = document.forms[0].category.options[document.forms[0].category.selectedIndex].value;

        ClearList(document.forms[0].subcategory, '-----Select-----');

        LoadMain(document.forms[0].category.selectedIndex);

        

        if (Selectedcategory == "")

        {

            categoryCheckFlag = false;

        }

        if (CalledFromOnLoad == 1)

        {       

        if (theSubcat == ""){                                           

        document.forms[0].subcategory.selectedIndex = CurrModel;                    

        }                       

        

       }                       

}



function checkType () {

	var floorType = document.forms[0].floor.options[document.forms[0].floor.selectedIndex].value;

	if (floorType == "R") {

	document.location = "rcalc.html";

	}

}



function doCustom() {

	var txtSquareFeet = document.forms[0].txtSquareFeet.value;

  	var	custom = document.forms[0].custom.options[document.forms[0].custom.selectedIndex].value;

    if ( !isNumber(stringToNum(txtSquareFeet)) )

   {

	alert('Please enter number in the "Square Footage in numbers" before clicking on "Calculate".');

   } 

	else  {

		if (custom != 0){

		var nTotalCost = custom * txtSquareFeet;

   		document.forms[0].estimate.value = formatCurrency(nTotalCost);

		}

	}

}





function BackSolve() {



		var woodMain = document.forms[0].category.options[document.forms[0].category.selectedIndex].value;

		if (woodMain == 0) {

			alert("You must select a type of wood");

			return false;

		}else{

			if (woodMain == 3){

				var nInstallation = 4.50

			} else {

				var nInstallation = 3.00

			}

		}

	

	var txtSquareFeet = document.forms[0].txtSquareFeet.value;

    if ( !isNumber(stringToNum(txtSquareFeet)) )

   {

	alert('Please enter number in the "Square Footage in numbers" before clicking on "Calculate".');

   } 

	else  {

 		nSquareFeet = stringToNum(txtSquareFeet.value);

	

		var woodType = document.forms[0].subcategory.options[document.forms[0].subcategory.selectedIndex].value;

		if (woodType == 0) {

			alert("You must select a wood finish");

			return false;

		}else{

			nPrice = woodType;

		}

			

		var nTotalWoodCost = txtSquareFeet * nPrice;

		var nTotalInstallation = txtSquareFeet * nInstallation;

		var nTotalCost = nTotalWoodCost + nTotalInstallation;

   		//document.forms[0].install.value = formatCurrency(nTotalInstallation);

   		document.forms[0].estimate.value = formatCurrency(nTotalCost);

	} 

}



function clearTotal() {

	document.forms[0].estimate.value = "";

	//document.forms[0].install.value = "";

}





function isNumber(inputVal) {

  oneDecimal = false

  inputStr = inputVal.toString()

  for (var i = 0; i < inputStr.length; i++) {

    var oneChar = inputStr.charAt(i)

    if ( i == 0 && (oneChar == "-" || oneChar == "$"))

			continue;

    if (oneChar == "." && !oneDecimal) {

      oneDecimal = true;

      continue;

    }

    if (oneChar < "0" || oneChar > "9")

      return false

  }

  return true

}



function stringToNum (sInStr) {

	theString = new String (sInStr);

	theString = theString.replace (/\$/, "");

	theString = theString.replace (/,/g, "");

	theString = parseFloat (theString);

	return Math.round (theString * 100) / 100;

}



function formatCurrency (number) {

	// formatCurrency() ONLY copyright 1999 by Will Smith (will@newtweb.com)

	var num = new String (number);

	if (num.indexOf (".") == -1) {

		intLen = num.length;

		toEnd = intLen;

		var strLeft = new String (num.substring (0, toEnd));

		var strRight = new String ("00");

	} else {

		pos = eval (num.indexOf ("."));

		var strLeft = new String (num.substring (0, pos));

		intToEnd = num.length;

		intThing = pos + 1;

		var strRight = new String (num.substring (intThing, intToEnd));



		if (strRight.length > 2) {

			nextInt = strRight.charAt(2);

			if (nextInt >= 5) {

				strRight = new String (strRight.substring (0, 2));

				strRight = new String (eval ((strRight * 1) + 1));

				if((strRight * 1) >= 100) {

					strRight = "00";

					strLeft = new String (eval ((strLeft * 1) + 1));

				}

				if (strRight.length <= 1) {

					strRight = new String ("0" + strRight);

				}

			} else {

				strRight = new String (strRight.substring (0, 2));

			}

		} else {

			if (strRight.length != 2)

				strRight = strRight + "0";

		}

	}



	if (strLeft.length > 3) {

		var curPos = (strLeft.length - 3);

		while (curPos > 0) {

			var remainingLeft = new String (strLeft.substring (0, curPos));

			var strLeftLeft = new String (strLeft.substring (0, curPos));

			var strLeftRight = new String (strLeft.substring (curPos, strLeft.length));

			strLeft = new String (strLeftLeft + "," + strLeftRight);

			curPos = (remainingLeft.length - 3);

		}

	}



	strWhole = strLeft + "." + strRight;

	finalValue = "$" + strWhole;

	return (finalValue);

}
