// JavaScript source code
var whichAction = "ViewRecipe.asp";
var Hard = parseFloat(0);
var Cleansing = parseFloat(0);
var Bubbly = parseFloat(0);
var Conditioning = parseFloat(0);
var Creamy = parseFloat(0);
var Iodine = parseFloat(0);
var INS = parseFloat(0);
var Lauric = parseFloat(0);
var Linoleic = parseFloat(0)
var Linolenic = parseFloat(0);
var Myristic = parseFloat(0);
var Oleic = parseFloat(0);
var Palmitic = parseFloat(0);
var Ricinoleic = parseFloat(0);
var Stearic = parseFloat(0);

var Saturated = parseFloat(0);
var MonoUnsaturated = parseFloat(0);
var PolyUnsaturated = parseFloat(0);
//---
var ary14RecipeWeightVals = new Array(14);
var ary14RecipeSapVals = new Array(14);
var ary14RecipeSelIndexes = new Array(14);
var ary14RecipePercentVals = new Array(14);
var ary14SelectedOilIds = new Array(14);
//- popup text was here
var g_radio;
var g_tot = parseFloat(0);
var g_Computed = false;
var unit = "lb";
var FixedConc;
var FixedRatio;
// ,unique,hard,clean,cond,fluff,stable
function Oil(id,name,sap,iodine,ins,lauric,myristic,palmitic,stearic,ricinoleic,oleic,linoleic,linolenic){
    this.id = id;
    this.name = name;
    this.sap = sap;
    this.iodine = iodine;
    this.ins = ins;
    this.lauric = lauric;
    this.myristic = myristic;
    this.palmitic = palmitic;
    this.stearic = stearic;
    this.ricinoleic = ricinoleic;
    this.oleic = oleic;
    this.linoleic = linoleic;
    this.linolenic = linolenic;
}
var aryAllOils = new Array();
aryAllOils.push(new Oil(114,'Almond Butter',0.188,70,118,0,1,9,15,0,58,16,0));aryAllOils.push(new Oil(1,'Almond Oil, sweet',0.195,99,97,0,0,7,0,0,71,18,0));aryAllOils.push(new Oil(68,'Aloe Butter',0.251,2,249,0,0,0,0,0,0,0,0));aryAllOils.push(new Oil(96,'Andiroba Oil,karaba,crabwood',0.188,68,120,0,0,28,8,0,51,9,0));aryAllOils.push(new Oil(2,'Apricot Kernal Oil',0.195,100,91,0,0,6,0,0,66,27,0));aryAllOils.push(new Oil(58,'Argan Oil',0.191,95,95,0,1,14,0,0,46,34,1));aryAllOils.push(new Oil(53,'Avocado butter',0.187,67,120,0,0,21,10,0,53,6,2));aryAllOils.push(new Oil(3,'Avocado Oil',0.186,86,99,0,0,20,2,0,58,12,0));aryAllOils.push(new Oil(4,'Babassu Oil',0.245,15,230,50,20,11,4,0,10,0,0));aryAllOils.push(new Oil(59,'Baobab Oil',0.200,75,125,0,1,24,4,0,37,28,2));aryAllOils.push(new Oil(5,'Beeswax',0.094,10,84,0,0,0,0,0,0,0,0));aryAllOils.push(new Oil(6,'Black Cumin Seed Oil, nigella sativa',0.195,133,62,0,0,13,3,0,22,60,1));aryAllOils.push(new Oil(66,'Borage Oil',0.190,135,55,0,0,10,4,0,20,43,5));aryAllOils.push(new Oil(60,'Camelina Seed Oil',0.188,144,44,0,0,6,2,0,24,19,45));aryAllOils.push(new Oil(80,'Camellia Oil, Tea Seed',0.195,85,110,0,0,9,2,0,77,8,0));aryAllOils.push(new Oil(84,'Canola Oil, high oleic',0.186,96,90,0,0,4,2,0,74,12,4));aryAllOils.push(new Oil(7,'Canola Oil, rapeseed',0.186,110,56,0,0,4,2,0,61,21,9));aryAllOils.push(new Oil(8,'Castor Oil',0.180,86,95,0,0,0,0,90,4,4,0));aryAllOils.push(new Oil(79,'Cherry Kern1 Oil, p. avium',0.190,128,62,0,0,8,3,0,31,45,11));aryAllOils.push(new Oil(90,'Cherry Kern2 Oil, p. cesarus',0.192,118,74,0,0,6,3,0,50,40,0));aryAllOils.push(new Oil(56,'Chicken Fat',0.195,69,130,0,1,25,7,0,38,21,0));aryAllOils.push(new Oil(9,'Cocoa Butter',0.194,37,157,0,0,28,33,0,35,3,0));aryAllOils.push(new Oil(10,'Coconut Oil, 76 deg',0.257,10,258,48,19,9,3,0,8,2,0));aryAllOils.push(new Oil(72,'Coconut Oil, 92 deg',0.257,10,258,48,19,9,3,0,8,2,0));aryAllOils.push(new Oil(65,'Coconut Oil, fractionated',0.325,1,324,2,1,0,0,0,0,0,0));aryAllOils.push(new Oil(93,'Coffee Bean Oil, green',0.185,85,100,0,0,38,8,0,9,39,2));aryAllOils.push(new Oil(74,'Coffee Bean Oil, roasted',0.180,87,93,0,0,40,0,0,8,38,2));aryAllOils.push(new Oil(102,'Cohune Oil',0.205,30,175,51,13,8,3,0,18,3,0));aryAllOils.push(new Oil(11,'Corn Oil',0.192,117,69,0,0,12,2,0,32,51,1));aryAllOils.push(new Oil(12,'Cottonseed Oil',0.194,108,89,0,0,13,13,0,18,52,1));aryAllOils.push(new Oil(92,'Cranberry Seed Oil',0.190,150,40,0,0,6,2,0,23,37,32));aryAllOils.push(new Oil(104,'Crisco, new w/palm',0.193,111,82,0,0,20,5,0,28,40,6));aryAllOils.push(new Oil(13,'Crisco, old',0.192,93,115,0,0,13,13,0,18,52,0));aryAllOils.push(new Oil(101,'Cupuacu Butter',0.193,38,155,0,0,8,34,0,41,3,0));aryAllOils.push(new Oil(87,'Duck Fat, flesh & skin',0.194,72,122,0,1,26,9,0,44,13,1));aryAllOils.push(new Oil(14,'Emu Oil',0.190,60,128,0,0,23,9,0,47,8,0));aryAllOils.push(new Oil(15,'Evening Primrose Oil',0.190,160,30,0,0,0,0,0,0,80,9));aryAllOils.push(new Oil(16,'Flax Oil, linseed',0.190,180,-6,0,0,6,3,0,27,13,50));aryAllOils.push(new Oil(95,'Ghee, any bovine',0.227,30,191,4,11,28,12,0,19,2,1));aryAllOils.push(new Oil(17,'Goose Fat',0.192,65,130,0,0,21,6,0,54,10,0));aryAllOils.push(new Oil(18,'Grapeseed Oil',0.181,131,66,0,0,8,4,0,20,68,0));aryAllOils.push(new Oil(19,'Hazelnut Oil',0.195,97,94,0,0,5,3,0,75,10,0));aryAllOils.push(new Oil(20,'Hemp Oil',0.193,165,39,0,0,6,2,0,12,57,21));aryAllOils.push(new Oil(94,'Horse Oil',0.196,79,117,0,3,26,5,0,10,20,19));aryAllOils.push(new Oil(62,'Illipe Butter',0.185,33,0,0,0,17,45,0,35,0,0));aryAllOils.push(new Oil(108,'Jatropha Oil, soapnut seed oil',0.193,102,91,0,0,9,7,0,44,34,0));aryAllOils.push(new Oil(21,'Jojoba Oil (a Liquid Wax Ester)',0.092,83,11,0,0,0,0,0,12,0,0));aryAllOils.push(new Oil(51,'Karanja Oil',0.183,85,98,0,0,6,6,0,58,15,0));aryAllOils.push(new Oil(23,'Kokum Butter',0.190,35,155,0,0,4,56,0,36,1,0));aryAllOils.push(new Oil(86,'Kpangnan Butter',0.191,42,149,0,0,6,44,0,49,1,0));aryAllOils.push(new Oil(24,'Kukui nut Oil',0.189,168,24,0,0,6,2,0,20,42,29));aryAllOils.push(new Oil(25,'Lanolin liquid Wax',0.106,27,83,0,0,0,0,0,0,0,0));aryAllOils.push(new Oil(26,'Lard, Pig Tallow (Manteca)',0.198,57,139,0,1,28,13,0,46,6,0));aryAllOils.push(new Oil(127,'Laurel Fruit Oil',0.198,74,124,25,1,15,1,0,31,26,1));aryAllOils.push(new Oil(125,'Lauric Acid',0.280,0,280,99,1,0,0,0,0,0,0));aryAllOils.push(new Oil(27,'Linseed Oil, flax',0.190,180,-6,0,0,6,3,0,27,13,50));aryAllOils.push(new Oil(119,'Loofa Seed Oil, Luffa cylinderica',0.187,108,79,0,0,9,18,0,30,47,0));aryAllOils.push(new Oil(124,'Macadamia Nut Butter',0.188,70,118,0,1,6,12,0,56,3,1));aryAllOils.push(new Oil(28,'Macadamia Nut Oil',0.195,76,119,0,0,9,5,0,59,2,0));aryAllOils.push(new Oil(29,'Mango Seed Butter',0.191,45,146,0,0,7,42,0,45,3,0));aryAllOils.push(new Oil(30,'Mango Seed Oil',0.190,60,130,0,0,8,27,0,52,8,1));aryAllOils.push(new Oil(99,'Marula Oil',0.192,73,119,0,0,11,7,0,75,4,0));aryAllOils.push(new Oil(31,'Meadowfoam Oil',0.169,92,77,0,0,0,0,0,0,0,0));aryAllOils.push(new Oil(32,'Milk Fat, any bovine',0.227,30,191,4,11,28,12,0,19,2,1));aryAllOils.push(new Oil(67,'Mink Oil',0.196,55,141,0,0,0,0,0,0,0,0));aryAllOils.push(new Oil(69,'Monoi de Tahiti  Oil',0.255,9,246,44,16,10,3,0,0,2,0));aryAllOils.push(new Oil(109,'Moringa Oil',0.192,68,124,0,0,7,7,0,71,2,0));aryAllOils.push(new Oil(63,'Mowrah Butter',0.194,62,132,0,0,24,22,0,36,15,0));aryAllOils.push(new Oil(106,'Murumuru Butter',0.275,25,250,47,26,6,3,0,15,3,0));aryAllOils.push(new Oil(103,'Mustard Oil, kachi ghani',0.173,101,72,0,0,2,2,0,18,14,9));aryAllOils.push(new Oil(76,'Myristic Acid',0.247,1,246,0,99,0,0,0,0,0,0));aryAllOils.push(new Oil(121,'Neatsfoot Oil',0.180,90,90,0,0,0,0,0,0,0,0));aryAllOils.push(new Oil(33,'Neem Tree Oil',0.195,89,124,0,0,18,15,0,50,13,0));aryAllOils.push(new Oil(117,'Oat Oil',0.190,104,86,0,0,15,2,0,40,39,0));aryAllOils.push(new Oil(88,'Oleic Acid',0.202,92,110,0,0,0,0,0,99,0,0));aryAllOils.push(new Oil(34,'Olive Oil',0.190,85,105,0,0,14,3,0,69,12,1));aryAllOils.push(new Oil(52,'Olive Oil  pomace',0.188,84,104,0,0,14,3,0,69,12,2));aryAllOils.push(new Oil(82,'Ostrich Oil',0.1946,97,128,3,1,26,6,0,37,17,3));aryAllOils.push(new Oil(35,'Palm Kernel Oil',0.247,20,227,49,16,8,2,0,15,3,0));aryAllOils.push(new Oil(126,'Palm Kernel Oil Flakes, hydrogenated',0.247,20,227,49,17,8,16,0,4,0,0));aryAllOils.push(new Oil(36,'Palm Oil',0.199,53,145,0,1,44,5,0,39,10,0));aryAllOils.push(new Oil(113,'Palm Stearin',0.199,48,151,0,2,60,5,0,26,7,0));aryAllOils.push(new Oil(77,'Palmitic Acid',0.215,2,213,0,0,98,0,0,0,0,0));aryAllOils.push(new Oil(120,'Papaya seed oil, Carica papaya',0.158,67,91,0,0,13,5,0,76,3,0));aryAllOils.push(new Oil(37,'Passion Fruit Seed Oil',0.183,136,47,0,0,10,3,0,15,70,1));aryAllOils.push(new Oil(70,'Peach Kernel Oil',0.191,108,87,0,0,6,2,0,65,25,1));aryAllOils.push(new Oil(38,'Peanut Oil',0.192,92,99,0,0,8,3,0,56,26,0));aryAllOils.push(new Oil(75,'Perilla Seed Oil',0.190,196,-6,0,0,6,2,0,15,16,56));aryAllOils.push(new Oil(85,'Pine Tar, lye calc only no FA',0.060,0,0,0,0,0,0,0,0,0,0));aryAllOils.push(new Oil(39,'Pistachio Oil',0.186,95,92,0,0,11,1,0,63,25,0));aryAllOils.push(new Oil(107,'Plum Kernel Oil',0.194,98,0,0,0,3,0,0,68,23,0));aryAllOils.push(new Oil(128,'Pomegranate Seed Oil',0.190,22,168,0,0,3,3,0,7,7,78));aryAllOils.push(new Oil(73,'Poppy Seed Oil',0.194,140,54,0,0,10,2,0,17,69,2));aryAllOils.push(new Oil(83,'Pumpkin Seed Oil virgin',0.195,128,67,0,0,11,8,0,33,50,0));aryAllOils.push(new Oil(91,'Rabbit Fat',0.201,85,116,0,3,30,6,0,30,20,5));aryAllOils.push(new Oil(40,'Rapeseed Oil',0.174,108,56,0,0,3,1,0,13,13,9));aryAllOils.push(new Oil(89,'Red Palm Butter',0.199,53,145,0,1,44,5,0,39,10,0));aryAllOils.push(new Oil(41,'Rice Bran Oil',0.179,110,70,0,1,22,3,0,43,26,0));aryAllOils.push(new Oil(61,'Rosehip Oil',0.187,188,10,0,0,4,2,0,12,46,31));aryAllOils.push(new Oil(122,'Sacha Inchi, Plukenetia volubilis',0.188,141,47,0,0,4,3,0,10,35,48));aryAllOils.push(new Oil(42,'Safflower Oil',0.192,145,47,0,0,7,0,0,15,75,0));aryAllOils.push(new Oil(78,'Safflower Oil, high oleic',0.190,93,97,0,0,5,2,0,77,15,0));aryAllOils.push(new Oil(64,'Sal Butter',0.185,39,146,0,0,6,44,0,40,2,0));aryAllOils.push(new Oil(111,'Saw Palmetto Extract',0.230,45,185,29,11,8,2,0,35,4,1));aryAllOils.push(new Oil(110,'Saw Palmetto Oil',0.220,44,176,29,13,9,2,0,31,4,1));aryAllOils.push(new Oil(116,'Sea Buckthorn Oil, seed',0.195,165,30,0,0,7,3,0,14,36,38));aryAllOils.push(new Oil(115,'Sea Buckthorn Oil, seed and berry',0.183,86,97,0,0,30,1,0,28,10,0));aryAllOils.push(new Oil(43,'Sesame Oil',0.188,110,81,0,0,10,5,0,40,43,0));aryAllOils.push(new Oil(44,'Shea Butter',0.179,59,116,0,0,5,40,0,48,6,0));aryAllOils.push(new Oil(22,'Shea Oil, fractionated',0.185,83,102,0,0,6,10,0,73,11,0));aryAllOils.push(new Oil(45,'Soybean Oil',0.191,131,61,0,0,11,5,0,24,50,8));aryAllOils.push(new Oil(81,'Soybean, 27.5% hydrogenated',0.191,78,113,0,0,9,15,0,41,7,1));aryAllOils.push(new Oil(46,'Stearic Acid',0.198,2,196,0,0,0,99,0,0,0,0));aryAllOils.push(new Oil(47,'Sunflower Oil',0.189,133,63,0,0,7,4,0,16,70,1));aryAllOils.push(new Oil(71,'Sunflower Oil, high oleic',0.189,83,106,0,0,3,4,0,83,4,1));aryAllOils.push(new Oil(112,'Tallow Bear',0.1946,92,100,0,2,7,3,0,70,9,0));aryAllOils.push(new Oil(48,'Tallow Beef',0.200,45,147,2,6,28,22,0,36,3,1));aryAllOils.push(new Oil(54,'Tallow Deer',0.193,31,166,0,1,20,24,0,30,15,3));aryAllOils.push(new Oil(123,'Tallow Goat',0.192,40,152,5,11,23,30,0,29,2,0));aryAllOils.push(new Oil(55,'Tallow Sheep',0.194,54,156,4,10,24,13,0,26,5,0));aryAllOils.push(new Oil(57,'Tamanu Oil, kamani',0.208,111,82,0,0,12,13,0,34,38,1));aryAllOils.push(new Oil(97,'Tucuma Seed Butter',0.238,13,175,48,23,6,0,0,13,0,0));aryAllOils.push(new Oil(100,'Ucuuba Butter',0.205,38,167,0,0,0,31,0,44,5,0));aryAllOils.push(new Oil(105,'Walmart GV Shortening, beef tallow, palm',0.198,49,151,1,4,35,14,0,37,6,1));aryAllOils.push(new Oil(49,'Walnut Oil',0.189,145,45,0,0,7,2,0,18,60,0));aryAllOils.push(new Oil(50,'Wheat Germ Oil',0.183,128,58,0,0,17,2,0,17,58,0));aryAllOils.push(new Oil(98,'Yangu, cape chestnut',0.192,95,97,0,0,18,5,0,45,30,1));aryAllOils.push(new Oil(118,'Zapote seed oil, (Aceite de Sapuyul or Mamey)',0.188,72,116,0,0,9,21,0,52,13,0));
//======================================
function twOnClick(){
	if (document.getElementById('oilWeight0').checked == true){
        document.getElementById('TWunit').innerHTML = "Pounds";
        document.getElementById('lblWT').innerHTML="lb";
		document.getElementById("lbloilWeight0").innerHTML = "<strong>Pounds</strong>";		
		document.getElementById("lbloilWeight1").innerHTML = "Ounces";		
		document.getElementById("lbloilWeight2").innerHTML = "Grams";		
		g_radio = 0;
        unit = "lb";
        document.getElementById('FragranceRatioUnit').innerHTML = "Oz per Lb";
        document.getElementById('txtTW').value = "1";
        }
    if (document.getElementById('oilWeight1').checked == true){
        document.getElementById('TWunit').innerHTML = "Ounces";
        document.getElementById('lblWT').innerHTML="oz";
		document.getElementById("lbloilWeight0").innerHTML = "Pounds";		
		document.getElementById("lbloilWeight1").innerHTML = "<strong>Ounces</strong>";		
		document.getElementById("lbloilWeight2").innerHTML = "Grams";		
        g_radio = 1;
        unit = "oz";
        document.getElementById('FragranceRatioUnit').innerHTML = "Oz per Lb";
		document.getElementById('txtTW').value = "16";
		}
    if (document.getElementById('oilWeight2').checked == true){
        document.getElementById('TWunit').innerHTML= "Grams";
        document.getElementById('lblWT').innerHTML="gm";
		document.getElementById("lbloilWeight0").innerHTML = "Pounds";		
		document.getElementById("lbloilWeight1").innerHTML = "Ounces";		
		document.getElementById("lbloilWeight2").innerHTML = "<strong>Grams</strong>";		
        g_radio = 2;
        unit = "gm";
        document.getElementById('FragranceRatioUnit').innerHTML = "Gm per Kg";
        document.getElementById('txtTW').value = "500";
        }
	document.getElementById('txtTW').focus();
}
//================================
function selOilOnChange(){
resetProps()
var idx = document.getElementById('selOil').selectedIndex;
getProperties(idx, false, 1.0);
var sap = parseFloat(aryAllOils[idx].sap)
document.getElementById('txtSAPKOH').value = sap;
document.getElementById('txtSAPNaOH').value = roundNumber(sap * (40.0 / 56.1), 3);
}
//============
function resetAllArraysAndHdnVals(){
	for (var k = 0; k < 14; k++){
		document.getElementById("hdnValue" + (k)).value = "-1"
		document.getElementById("hdnSap" + (k)).value = "-1"
		document.getElementById("hdnIndex" + (k)).value = "-1"
		ary14RecipeWeightVals[k] = parseFloat(0.0);
		ary14RecipeSapVals[k] = parseFloat(0.0);
		ary14RecipeSelIndexes[k] = parseInt(0);
		ary14RecipePercentVals[k] = parseFloat(0.0);
		ary14SelectedOilIds[k] = parseInt(-1);
		}
}
function resetPCandWTArrays(){
	for (var k = 0; k < 14; k++){
		ary14RecipeWeightVals[k] = parseFloat(0.0);
		ary14RecipePercentVals[k] = parseFloat(0.0);
		}
}
//=========
function clearAll(confrm){
if (confrm){
	if ( ! confirm("This will clear all values in the calculator and set it to its default state.\n\nClick OK or press the Enter key to do this."))
		return
}
textChanged(); //g_Computed == false; setButtons(false);

for ( var k = 0; k < 14; k++){
    removeOil(k); // also onclick for remove button
	}
resetProps();
resetAllArraysAndHdnVals();
document.getElementById("spnHard2").value = " ";
document.getElementById("spnCleansing2").value = " ";
document.getElementById("spnConditioning2").value = " ";
document.getElementById("spnBubbly2").value = " ";
document.getElementById("spnCreamy2").value =  " ";
document.getElementById("spnIodine2").value = " ";
document.getElementById("spnINS2").value = " ";
document.getElementById("spnLauric2").value = " ";
document.getElementById("spnLinoleic2").value = " ";
document.getElementById("spnLinolenic2").value = " ";
document.getElementById("spnMyristic2").value = " ";
document.getElementById("spnOleic2").value = " ";
document.getElementById("spnPalmitic2").value = " ";
document.getElementById("spnRicinoleic2").value = " ";
document.getElementById("spnStearic2").value = " ";
document.getElementById("tdSatRatioMain").value = " ";
document.getElementById("hdnHard2").value = "-1";
document.getElementById("hdnCleansing2").value =  "-1";
document.getElementById("hdnConditioning2").value = "-1";
document.getElementById("hdnBubbly2").value = "-1";
document.getElementById("hdnCreamy2").value = "-1";
document.getElementById("hdnIodine2").value = "-1";
document.getElementById("hdnINS2").value = "-1";
document.getElementById("hdnLauric2").value = "-1";
document.getElementById("hdnMyristic2").value = "-1";
document.getElementById("hdnPalmitic2").value = "-1";
document.getElementById("hdnStearic2").value = "-1";
document.getElementById("hdnRicinoleic2").value = "-1";
document.getElementById("hdnOleic2").value = "-1";
document.getElementById("hdnLinoleic2").value = "-1";
document.getElementById("hdnLinolenic2").value = "-1";
document.getElementById("hydroxide0").checked = true;
document.getElementById("oilWeight0").checked = true;
document.getElementById("waterAmount0").checked = true;
document.getElementById("txtTW").value = "1";   
setWaterPercent(false);
document.getElementById("chkHowToPrint").checked = false;
document.getElementById("chkBold").checked = false;

document.getElementById("spnLyeConc").value="";
document.getElementById("spnWaterLyeRatio").value="";
document.getElementById("txtDiscount").value = "5";
document.getElementById('selOil').selectedIndex = 0;
document.getElementById("txtFragranceRatio").value = "";
document.getElementById("txtTotalPerCent").value = "";
document.getElementById("txtTotalRecipeWeight").value = "";
document.getElementById("spnFragranceRequired").value = "";
}
//=========
function addOil(num){
var sel = document.getElementById("selOil");
var oilName = sel.options[sel.selectedIndex].text;
//alert(oilName);
var OilId = new String(sel.options[sel.selectedIndex].id);
var id = parseInt(OilId.substr(2));
for( k=0;k<14;k++){
	if(ary14SelectedOilIds[k] == id){
		alert(oilName + " is already on the list.");
		return;
	}
}
ary14SelectedOilIds[num] = id;
document.getElementById("txtOil" + (num+1)).value = oilName;
document.getElementById("hdnIndex" + num).value = sel.selectedIndex;
document.getElementById("hdnSap" + num).value = sel.options[sel.selectedIndex].value
ary14RecipeSelIndexes[num] = parseInt(sel.selectedIndex);
ary14RecipeSapVals[num] = parseFloat(sel.options[sel.selectedIndex].value);
textChanged();
}
//=========
function removeOil(num){
document.getElementById("hdnIndex" + num).value = "-1";
document.getElementById("txtOil" + (num+1)).value = "";
document.getElementById("hdnSap" + num).value = "-1";
ary14RecipeSelIndexes[num] = parseInt(0);
ary14RecipeSapVals[num]  = parseFloat(0.0);
ary14SelectedOilIds[num] = parseInt(-1);;
document.getElementById("hdnValue" + (num)).value =  "-1";
document.getElementById("txtPerCent" + (num+1)).value = "";
document.getElementById("txtWeight" + (num+1)).value = "";
textChanged();
}
//=========
function autoAddOil(){
    for (var k = 0 ; k < 14 ; k++){
        if ( document.getElementById("txtOil" + (k+1)).value.length == 0){
            addOil(k); // array number
            break;
        }
    }
	
}
//--------------------------------------
function getProperties(idx, isCompute, percentOfRecipe){
var str, sap, weightSave
var spacer
	pc = parseFloat(aryAllOils[idx].lauric)
	if ( pc > 0 ){
		Hard += pc * percentOfRecipe
		Cleansing += pc * percentOfRecipe
		Bubbly += pc * percentOfRecipe
		Lauric  += pc * percentOfRecipe
		Saturated +=  pc * percentOfRecipe
		}
	pc = parseFloat(aryAllOils[idx].myristic)
	if ( pc > 0 ){
		Hard += pc * percentOfRecipe
		Cleansing += pc * percentOfRecipe
		Bubbly += pc * percentOfRecipe
		Myristic += pc * percentOfRecipe
		Saturated +=  pc * percentOfRecipe
		}
	pc = parseFloat(aryAllOils[idx].palmitic)
	if ( pc > 0 ){
		Hard += pc * percentOfRecipe
		Creamy += pc * percentOfRecipe
		Palmitic += pc * percentOfRecipe
		Saturated +=  pc * percentOfRecipe
		}
	pc = parseFloat(aryAllOils[idx].stearic)
	if ( pc > 0 ){
		Hard += pc * percentOfRecipe
		Creamy += pc * percentOfRecipe
		Stearic += pc * percentOfRecipe
		Saturated +=  pc * percentOfRecipe
		}
	pc = parseFloat(aryAllOils[idx].ricinoleic)
	if ( pc > 0 ){
		Conditioning += pc * percentOfRecipe
		Bubbly += pc * percentOfRecipe
		Creamy += pc * percentOfRecipe
		Ricinoleic += pc * percentOfRecipe
		MonoUnsaturated +=  pc * percentOfRecipe
		}
		pc = parseFloat(aryAllOils[idx].oleic)
	if ( pc > 0 ){
		Conditioning += pc * percentOfRecipe
		Oleic += pc * percentOfRecipe
		MonoUnsaturated +=  pc * percentOfRecipe
		}
	pc = parseFloat(aryAllOils[idx].linoleic)
	if ( pc > 0 ){
		Conditioning += pc * percentOfRecipe
		Linoleic += pc * percentOfRecipe
		PolyUnsaturated +=  pc * percentOfRecipe
		}
	pc = parseFloat(aryAllOils[idx].linolenic)
	if ( pc > 0 ){
		Conditioning += pc * percentOfRecipe
		Linolenic += pc * percentOfRecipe
		PolyUnsaturated +=  pc * percentOfRecipe
		}
	
	// Meadowfoam
	str = new String(aryAllOils[idx].name)
	if ( str.indexOf("Meadowfoam") != -1 ){
		Conditioning += 84 * percentOfRecipe
		Cleansing += 16 * percentOfRecipe
		PolyUnsaturated +=  100 * percentOfRecipe
		}
	// fractionated Coconut - mostly caprylic/capric triglyceride C8:0
	//str = aryAllOils[idx].name 
	if ( str.indexOf("Coconut Oil, fractionated") != -1 ){
	//if ( idx == 64 ){
		Hard += 90 * percentOfRecipe
		Cleansing += 90 * percentOfRecipe
		Bubbly += 90 * percentOfRecipe
		Saturated +=  90 * percentOfRecipe
		}
		
	INS += parseFloat(aryAllOils[idx].ins) * percentOfRecipe
	Iodine += parseFloat(aryAllOils[idx].iodine)  * percentOfRecipe 
	
	if ( ! isCompute ){
	document.getElementById('spnHard').value = " " + Hard;
	document.getElementById('spnCleansing').value = " " +  Cleansing;
	document.getElementById('spnConditioning').value = " " +  Conditioning;
	document.getElementById('spnBubbly').value = " " +  Bubbly;
	document.getElementById('spnCreamy').value = " " +  Creamy;
	document.getElementById('spnIodine').value = " " +  Iodine
	document.getElementById('spnINS').value = " " +  INS
	
	document.getElementById('spnLauric').value = " " +  roundNumber(Lauric,0);
	document.getElementById('spnLinoleic').value = " " +  roundNumber(Linoleic,0);
	document.getElementById('spnLinolenic').value = " " +  roundNumber(Linolenic,0);
	document.getElementById('spnMyristic').value = " " +  roundNumber(Myristic,0);
	document.getElementById('spnOleic').value = " " +  roundNumber(Oleic,0);
	document.getElementById('spnPalmitic').value = " " +  roundNumber(Palmitic,0);
	document.getElementById('spnRicinoleic').value = " " +  roundNumber(Ricinoleic,0);
	document.getElementById('spnStearic').value = " " +  roundNumber(Stearic,0);
	}

}
//========================================
function resetProps(){
    Hard = parseInt(0);
    Cleansing = parseInt(0);
    Bubbly = parseInt(0);
    Conditioning = parseInt(0);
    Creamy = parseInt(0);
    Iodine = parseInt(0);
    INS = parseInt(0);

    Lauric = parseFloat(0);
    Linoleic = parseFloat(0);
    Linolenic = parseFloat(0);
    Myristic = parseFloat(0);
    Oleic = parseFloat(0);
    Palmitic = parseFloat(0);
    Ricinoleic = parseFloat(0);
    Stearic = parseFloat(0);
	
	Saturated = parseFloat(0);
	MonoUnsaturated = parseFloat(0);
	PolyUnsaturated = parseFloat(0);
}
//===========++++++++++++++++++++++++++++++++++++++++++++++++++++++
function  validate(){
var txtTW = new String(document.getElementById("txtTW").value);
var radPercent =  document.getElementById("radPercent0");
var twOils, pc, totalPerCent, adjust, whichway;
var txtWT, totalWeight;
var strOilName = new String();
var strOilPercent = new String();
var strOilWeight = new String();
var k;

for (k = 1; k <= 14 ; k++)
	strOilName += document.getElementById("txtOil" + k).value;
if ( strOilName.length == 0 ){
	alert("Please add at least one oil or fat to your recipe.\n\nClick help button 6 for instructions on how to add or remove an oil."); 
	return false;
}
totalPerCent = 0;
// Total Oil Weight in Lb, Oz or Gm
if ( radPercent.checked == true ){
    if (txtTW.length == 0){
        alert("Please fill in Total Oil Weight.");
        return false;
    }
    else{
        if (isNaN(txtTW)){
		alert("Total Oil Weight is not a number.");
		return false;
		}
		else{
		twOils = parseFloat(txtTW);
        }
    }
    if (twOils <= 0.0 ){
            alert("Total Oil Weight can not be less than 0 (zero).");
            return false;
    }
//--           
    for (k = 1; k <= 14 ; k++){
        strOilName = document.getElementById("txtOil" + k).value;
		strOilPercent = document.getElementById("txtPerCent" + k).value;
		if (  ! isEmpty(strOilName)){
			if ( isEmpty(strOilPercent)  ){
				alert("Please enter a value for Oil Number " + k + ", " + strOilName + ", or remove it from the recipe.");
				return false;
			}
			pc = parseFloat(strOilPercent);
			if (isNaN(pc)){
				alert("Value for Oil Number " + k + " is not a number");
				return false;
			}
			if (parseFloat(strOilPercent) <= 0.0){
				alert("Percent value for Oil Number " + k + " can not be zero or less. Either remove oil or put in a number greater than zero.");
				return false;
			}
		}
		else{
			if ( !isEmpty(strOilPercent)){
				alert("There is no oil name listed for Oil Number " + k + "  but the percentage column contains a value.\n\nPlease either add an oil for number " + k + " or click the minus sign next to item " + k +" to remove the percentage.");
				return false;
			}
			continue;
		}
		totalPerCent += pc;
    }
        var testPerCent = roundNumber(totalPerCent, 1);
		document.getElementById("txtTotalPerCent").value = testPerCent;
        if (testPerCent != 100.0){
			adjust = roundNumber((100.0 - testPerCent),4);
			
			document.getElementById("txtTotalPerCent").style.color = "#FF0000";
			if ( adjust > 0 )
				whichway = " adding ";
			else
				whichway = " taking away ";
			alert("Total Per Cent does not equal 100%\n\nAdjust by" + whichway + Math.abs(adjust) + " %");
        return false;
        }
		else
			document.getElementById("txtTotalPerCent").style.color = "#000000";
}
// radPercent is NOT checked
else{ 
    totalWeight = 0;
    for (k = 1; k <= 14; k++){
        strOilWeight = document.getElementById("txtWeight" + k).value;
        strOilName = document.getElementById("txtOil" + k).value;
		
		if (  ! isEmpty(strOilName) ){
			if ( isEmpty(strOilWeight)){
				alert("There is no weight value for Oil Number " + k + ".  \n\nEither add a weight value for Oil Number " + k + " or click the minus sign next to item " + k +" to remove it.");
				return false;
			}
			if (isNaN(strOilWeight) && strOilWeight.length > 0 ){
				alert("Weight value for Oil Number " + k + " is not a number");
				return false;
			}
			if (parseFloat(strOilWeight) <= 0.0){
				alert("Weight value for Oil Number " + k + " can not be zero or less. Either remove oil or put in a number greater than zero.");
				return false;
			}
			totalWeight += parseFloat(strOilWeight);
		}
		else{
			
        	if ( !isEmpty(strOilWeight)){
				alert("There is no oil name listed for Oil Number " + k + "  but the weight column contains a value.\n\nPlease either add an oil for number " + k + " or click the minus sign next to item " + k +" to remove the weight.");
				return false;
			}	
			continue;
		}
    }
    
}
//*************************************************

if (document.getElementById("waterAmount1").checked == false && document.getElementById("waterAmount2").checked == false){
    var waterPercent = document.getElementById("txtWaterPercent").value;
    if( isWhitespace (waterPercent) || isNaN(waterPercent)){
        alert("\"Water as % of Oils\" is not a number.");
        return false;
        }
}

var superFat = document.getElementById("txtDiscount").value;
if( isWhitespace (superFat) || isNaN(superFat)){
        alert("\"Super Fat/Discount %\" is not a number.  Please set to 0 or greater.");
        return false;
        }

str = document.getElementById("txtFragranceRatio").value
if (str.length == 0){
    fr = 0.0;
    }
else{
    if (isNaN(str)){
        alert("Fragrance ratio is not a number");
        return false;
        }
    else{
        fr = parseFloat(str);
        }
    }

if ( FixedConc == true ){
    var strSet = document.getElementById("spnLyeConc").value
    if( isNaN (parseFloat(strSet))){
        alert("Lye Concentration value must be a number.\nEither uncheck the Lye Concentration 'Set' box or enter a number.");
        return false;
        }
}
if (FixedRatio == true ){
    var strRatio = new String(document.getElementById("spnWaterLyeRatio").value);
    if ( strRatio.indexOf(":") == -1){
        alert("The ratio must be expressed as 'Water:Lye'.\nA colon, : , must be be between the water value and the lye value.");
        return false;
    }
    var ratioArray = strRatio.split(":");
    if(isNaN(ratioArray[0]) || isNaN(ratioArray[1])){
        alert("Water and Lye values in the ratio must both be numbers.");
        return false;
    }
}

        
return true;
}
//==================================
function ComputeUsingPC(){
var pc 
var weight, totalWeight, twOils, totalPerCent, pcValue
var oil, txtOil, txtWeight, txtWeightOZ, txtWeightGM

totalPerCent = parseFloat(0.0);
totalWeight = parseFloat(0.0);
weight = parseFloat(0.0);
	
twOils = parseFloat(document.getElementById("txtTW").value);
for (var k = 1; k <= 14 ; k++){
	pc = parseFloat(document.getElementById("txtPerCent" + k).value);
	if ( isNaN(pc))
		pc = 0.0;
	
	ary14RecipePercentVals[k-1] = pc / 100.0;
	totalPerCent += pc;
	//weight = roundNumber(pc * twOils / 100, 3);
	weight = pc * twOils / 100;
	if( pc > 0.0)
		document.getElementById("txtWeight" + k).value = fixPCrounding(weight);
	
	
	ary14RecipeWeightVals[k-1] = weight;
	totalWeight +=  weight;
	
	txtOil = document.getElementById("txtOil" + k);
	txtWeight = document.getElementById("txtWeight" + k);
	if (txtOil.value == "")
		txtWeight.value = "";
	else
		txtWeight.value = weight;

	}
	document.getElementById("txtTotalPerCent").value = roundNumber(totalPerCent,4)
	document.getElementById("txtTotalRecipeWeight").value = roundNumber(totalWeight, 3) 

}
function ComputeUsingWT(){
var txtWT = new String();
var txtPC = new String();
var msg = new String();
var TotalPerCent = 0;
var totalWeight = 0;
var weight;   
var j = 0;
    // get individual weights
    for (var k = 1; k <= 14; k++){
        txtWT = document.getElementById("txtWeight" + k).value
		if (txtWT.length > 0){
			ary14RecipeWeightVals[k-1] = parseFloat(txtWT);
			totalWeight += ary14RecipeWeightVals[k-1];
		}
		else{
			ary14RecipeWeightVals[k-1] = parseFloat(0.0);
		}
	}
    
	// get individual percent for recipe
    for ( k = 1; k <= 14; k++){
        // convert weights into percent
        ary14RecipePercentVals[k-1] = (ary14RecipeWeightVals[k-1] / totalWeight) * 100.0
		//alert(aryPerCent[k]);
		txtPC = document.getElementById("txtPerCent" + k)
		if (ary14RecipePercentVals[k-1] == 0)
			txtPC.value = "";
        else
			//txtPC.value = (roundNumber(aryPerCent[k], 4));
			txtPC.value = fixPCrounding(ary14RecipePercentVals[k-1]);
			TotalPerCent += ary14RecipePercentVals[k-1];
	}
			
	document.getElementById("txtTotalPerCent").value = roundNumber(TotalPerCent,4);
	document.getElementById("txtTotalRecipeWeight").value = roundNumber(totalWeight, 3) 
	document.getElementById("txtTW").value = roundNumber(totalWeight, 3)

}

//--------------------------------------------
function computeRecipe(print){
var  k, idx, weight, percentOfRecipe;
var str = new String();
weight = parseFloat(0.0);
idx = parseInt(0);

// reset to 0
resetPCandWTArrays(); 
resetProps();

if ( ! validate() )
	return;
// fill PC & WT arrays
var radPercent =  document.getElementById("radPercent0");
if ( radPercent.checked == true )
	ComputeUsingPC();
else
	ComputeUsingWT();
g_tot = parseFloat(0.0);
for ( k = 0 ; k < ary14RecipeWeightVals.length; k++ ){
	if ( ary14RecipeWeightVals[k] == 0.0 )
			continue;
	g_tot += ary14RecipeWeightVals[k];
}	

for ( k = 1 ; k <= 14; k++ ){
	var str = document.getElementById("txtOil" + (k)).value
	if ( str.length > 0 ){ 
		idx  = ary14RecipeSelIndexes[k-1]
		weight = ary14RecipeWeightVals[k-1]/g_tot
		getProperties(idx, true, weight)
		}
	}		
document.getElementById("spnHard2").value = " " +  roundNumber(Hard, 0);
document.getElementById("spnCleansing2").value = " " +  roundNumber(Cleansing, 0);
document.getElementById("spnConditioning2").value = " " +  roundNumber(Conditioning, 0) ;
document.getElementById("spnBubbly2").value = " " +  roundNumber(Bubbly, 0);
document.getElementById("spnCreamy2").value = " " +  roundNumber(Creamy, 0);
document.getElementById("spnIodine2").value = " " +  roundNumber(Iodine, 0); 
document.getElementById("spnINS2").value = " " +  roundNumber(INS,0);

document.getElementById("spnLauric2").value = " " +  roundNumber(Lauric,0);
document.getElementById("spnLinoleic2").value = " " +  roundNumber(Linoleic,0);
document.getElementById("spnLinolenic2").value = " " +  roundNumber(Linolenic,0);
document.getElementById("spnMyristic2").value = " " +  roundNumber(Myristic,0);
document.getElementById("spnOleic2").value = " " +  roundNumber(Oleic,0);
document.getElementById("spnPalmitic2").value = " " +  roundNumber(Palmitic,0);
document.getElementById("spnRicinoleic2").value = " " +  roundNumber(Ricinoleic,0);
document.getElementById("spnStearic2").value = " " +  roundNumber(Stearic,0);
	
	
// compute fragrance
if (document.getElementById("txtFragranceRatio").value.length == 0){
	fr = 0.0;
	}
else{
	fr = parseFloat(document.getElementById("txtFragranceRatio").value);
	}
if (document.getElementById("oilWeight0").checked == true )
	document.getElementById("spnFragranceRequired").value = " " +  roundNumber((fr * g_tot),3) + " Oz";
if (document.getElementById("oilWeight1").checked == true){
	lb = g_tot/16.0;
	document.getElementById("spnFragranceRequired").value = " " +  roundNumber((fr * lb),3) + " Oz";
	}
if (document.getElementById("oilWeight2").checked == true)
	document.getElementById("spnFragranceRequired").value = " " +  roundNumber((fr * g_tot/1000),2) + " Gm";
showSatRatio(roundNumber(Saturated,0),roundNumber(MonoUnsaturated,0), roundNumber(PolyUnsaturated,0));
g_Computed = true;
setButtons(true);
}
//==========================
function textChanged(){
g_Computed = false;
setButtons(false);
}
//==========================
function printRecipe(){
	var win, percentOfRecipe;
	var str = new String();
	
	// set hdnValue
for ( k = 1 ; k <= 14; k++ ){
	str = document.getElementById("txtOil" + k).value
	if ( str.length > 0 ){ 
		idx  = ary14RecipeSelIndexes[k-1];
		//alert(idx);
		percentOfRecipe = ary14RecipeWeightVals[k-1]/g_tot;
		getProperties(idx, true, percentOfRecipe);
		if ( document.getElementById("radPercent0").checked == true ){
			document.getElementById("hdnValue" + (k-1)).value = percentOfRecipe;
			//alert("k= " + k + "\nhdnVal = " + document.getElementById("hdnValue" + (k-1)).value)
		}
		else{
			document.getElementById("hdnValue" + (k-1)).value = ary14RecipeWeightVals[k-1];
		}
	}
}
	document.getElementById("hdnHard2").value =document.getElementById("spnHard2").value;
	document.getElementById("hdnCleansing2").value = document.getElementById("spnCleansing2").value;
	document.getElementById("hdnConditioning2").value = document.getElementById("spnConditioning2").value;
	document.getElementById("hdnBubbly2").value = document.getElementById("spnBubbly2").value;
	document.getElementById("hdnCreamy2").value = document.getElementById("spnCreamy2").value;
	document.getElementById("hdnIodine2").value = document.getElementById("spnIodine2").value;
	document.getElementById("hdnINS2").value = document.getElementById("spnINS2").value;
	document.getElementById("hdnLauric2").value = document.getElementById("spnLauric2").value;
	document.getElementById("hdnMyristic2").value = document.getElementById("spnMyristic2").value;
	document.getElementById("hdnPalmitic2").value = document.getElementById("spnPalmitic2").value;
	document.getElementById("hdnStearic2").value = document.getElementById("spnStearic2").value;
	document.getElementById("hdnRicinoleic2").value = document.getElementById("spnRicinoleic2").value;
	document.getElementById("hdnOleic2").value = document.getElementById("spnOleic2").value; 
	document.getElementById("hdnLinoleic2").value = document.getElementById("spnLinoleic2").value;
	document.getElementById("hdnLinolenic2").value = document.getElementById("spnLinolenic2").value;
	
	// submit form
	if(g_Computed == true){
		if ( document.getElementById("chkHowToPrint").checked ){
			document.getElementById("recipeData").target = "_blank";
		}
		else{
			document.getElementById("recipeData").target = "printWin";
			//win = window.open(whichAction, "printWin");
		}
		document.forms["recipeData"].submit();
	}	
}
//========================
function setButtons(on){
if (on){
	document.getElementById("btnViewRecipe").disabled = false;
	document.getElementById("btnSaveRecipe").disabled = false;
	document.getElementById("btnViewRecipe").style.cursor = "pointer";
	document.getElementById("btnSaveRecipe").style.cursor = "pointer";
}
else{
	document.getElementById("btnViewRecipe").disabled = true;
	document.getElementById("btnSaveRecipe").disabled = true;
	document.getElementById("btnViewRecipe").style.cursor = "default";
	document.getElementById("btnSaveRecipe").style.cursor = "default";
}
}
//------------------------------------------
function setWaterPercent(isFocus){
var txtPercent = document.getElementById("txtWaterPercent");
var txtConc = document.getElementById("spnLyeConc");
var txtRatio = document.getElementById("spnWaterLyeRatio");
FixedConc = false;
FixedRatio = false;
txtPercent.value = "38";
txtPercent.style.backgroundColor="#C9FCD0";
txtPercent.readOnly = false;
document.getElementById("lblwaterAmount0").style.fontWeight = "900";
txtConc.readOnly = true;
txtConc.style.backgroundColor="#FFFFFF";
document.getElementById("lblwaterAmount1").style.fontWeight = "400";
txtRatio.readOnly = true;
txtRatio.style.backgroundColor="#FFFFFF";
document.getElementById("lblwaterAmount2").style.fontWeight = "400";
if(isFocus)
	txtPercent.focus();
}
//----------------
function setLyeConcentration(isFocus){
var txtPercent = document.getElementById("txtWaterPercent");
var txtConc = document.getElementById("spnLyeConc");
var txtRatio = document.getElementById("spnWaterLyeRatio");
FixedConc = true;
FixedRatio = false;
//txtPercent.value = "";
txtConc.style.backgroundColor="#C9FCD0";
txtConc.readOnly = false;
document.getElementById("lblwaterAmount1").style.fontWeight = "900";
txtPercent.style.backgroundColor="#FFFFFF";
txtPercent.readOnly = true;
document.getElementById("lblwaterAmount0").style.fontWeight = "400";
txtRatio.style.backgroundColor="#FFFFFF";
txtRatio.readOnly = true;
document.getElementById("lblwaterAmount2").style.fontWeight = "400";
if(isFocus)
	txtConc.focus();	
}
//--------------------
function setWaterLyeRatio(isFocus){
var txtPercent = document.getElementById("txtWaterPercent");
var txtConc = document.getElementById("spnLyeConc");
var txtRatio = document.getElementById("spnWaterLyeRatio");
FixedConc = false;
FixedRatio = true;
//txtPercent.value = "";
txtRatio.style.backgroundColor="#C9FCD0";
txtRatio.readOnly = false;
document.getElementById("lblwaterAmount2").style.fontWeight = "900";
txtPercent.style.backgroundColor="#FFFFFF";
txtPercent.readOnly = true;
document.getElementById("lblwaterAmount0").style.fontWeight = "400";
txtConc.style.backgroundColor="#FFFFFF";
txtConc.readOnly = true;
document.getElementById("lblwaterAmount1").style.fontWeight = "400";
if(isFocus)
	txtRatio.focus();
}
//===================
function setFixedWaterMethod(obj)
{
    if ( obj == null)
		return -1;
		
	FixedConc = false;
    FixedRatio = false;
    
	var val = parseInt(obj.value);
	switch (val) {
		case 0:
			setWaterPercent(true);
			break;
		case 1:
			setLyeConcentration(true);
			break;
        case 2:
			 setWaterLyeRatio(true);
			break;
		default: return;
			break;
	}
}
function PorWClick(){
    g_Computed = false;
	setButtons(false);
	// if Weight is checked
    if (document.getElementById('radPercent1').checked == true){
        document.getElementById('hdnPorW').value = "1";
		for (var k = 1; k <= 14 ; k++){
            document.getElementById("txtPerCent" + k).style.backgroundColor = "#FFFFFF";
            document.getElementById("txtPerCent" + k).readOnly = true;
            document.getElementById("txtWeight" + k).readOnly = false;
            document.getElementById("txtWeight" + k).style.backgroundColor = "#C9FCD0";
		}
        document.getElementById('radPercent0').checked = false;
        document.getElementById('radPercent1').checked = true;
		document.getElementById('txtTW').style.backgroundColor = "#FFFFFF";
		document.getElementById('txtTW').readOnly = true;
	}
    else{
        document.getElementById('hdnPorW').value = "0";
		for (var k = 1; k <= 14 ; k++){
			document.getElementById("txtPerCent" + k).style.backgroundColor = "#C9FCD0";
			document.getElementById("txtPerCent" + k).readOnly = false;
			document.getElementById("txtWeight" + k).style.backgroundColor = "#FFFFFF";
			document.getElementById("txtWeight" + k).readOnly = true;
			document.getElementById("txtWeight" + k).style.backgroundColor="#FFFFFF";
       }
        document.getElementById('radPercent0').checked = true;
        document.getElementById('radPercent1').checked = false;
		document.getElementById('txtTW').style.backgroundColor = "#C9FCD0";
		document.getElementById('txtTW').readOnly = false;
	}
}
//=================
function hydroxideChange(obj){
	if (obj == null){
		if(document.getElementsByName("R2")[0].checked)
			obj = document.getElementById("hydroxide0");
		else (document.getElementsByName("R2")[1].checked)
			obj = document.getElementById("hydroxide1");
	}
	if ( obj.value == 1){
		document.getElementById("lblNaOH").innerHTML = "&nbsp;NaOH";		
		document.getElementById("lblKOH").innerHTML = "<strong>&nbsp;KOH</strong>";		
	}
	else{
		document.getElementById("lblNaOH").innerHTML = "<strong>&nbsp;NaOH</strong>";		
		document.getElementById("lblKOH").innerHTML = "&nbsp;KOH";		
	}
}
//=================
function SaveRecipe(){
var k, str; 
var strIndex, strPerCent;
var v;
var recipeName; 

var expire = new Date();
var plus30 = expire.getTime() + (31536000000)//360 365 days;
expire.setTime(plus30);

var hdnIndex;
var str = new String("");
var str2 = new String(""); 
recipeName = document.getElementById("selRecipeName").value;

for ( k = 1 ; k <= 14; k++ ){
    if(document.getElementById("radPercent0").checked == true)
        v = document.getElementById("txtPerCent" + k);
    else
        v = document.getElementById("txtWeight" + k);
// PC  10^25@7^22@48^40@44^5@-1^0@-1^0@-1^0@14^2@-1^0@-1^0@-1^0@8^6#unit^lb@wt^1@wpc^38@wdis^5@lyecon^@wlratio^@chklc^false@chkwl^false@pw^true@wpc^38@wdis^5@naoh^true@cream^false@creamNaOH^@frag^
// WT  10^1.3@48^2.1@7^1.636@44^.15@-1^0@-1^0@-1^0@14^.12@-1^0@-1^0@-1^0@41^.175#unit^lb@wt^5.481@wpc^38@wdis^5@lyecon^@wlratio^@chklc^false@chkwl^false@pw^false@wpc^38@wdis^5@naoh^true@cream^false@creamNaOH^@frag^.8
// if value is present
    hdnIndex = document.getElementById("hdnIndex" + (k-1))
    if (hdnIndex.value != -1){
        if ( k == 14 ){
            str += aryAllOils[hdnIndex.value].id + "^" + v.value + "#";
            }
        else{
            str += aryAllOils[hdnIndex.value].id + "^" + v.value + "@";
            }
        }
    else{
        if ( k == 14 )
            str += hdnIndex.value + "^" + 0 + "#";
        else
            str += hdnIndex.value + "^" + 0 + "@";
        }
    }
    // other settings
    var unit;
    if (document.getElementById("oilWeight0").checked == true)
        str2 += "unit^lb@"
    if (document.getElementById("oilWeight1").checked == true)
        str2 += "unit^oz@"
    if (document.getElementById("oilWeight2").checked == true)
        str2 += "unit^gm@"
    str2 += "wt^" + document.getElementById("txtTW").value + "@";
    str2 += "wpc^" +  document.getElementById("txtWaterPercent").value + "@";
    str2 += "wdis^" +  document.getElementById("txtDiscount").value + "@";
    str2 += "lyecon^" +  document.getElementById("spnLyeConc").value + "@";
    str2 += "wlratio^" +  document.getElementById("spnWaterLyeRatio").value + "@";
	str2 += "chklc^" +  document.getElementById("waterAmount1").checked + "@";
    str2 += "chkwl^" +  document.getElementById("waterAmount2").checked + "@";
    str2 += "pw^" +  document.getElementById("radPercent0").checked + "@";
    
    str2 += "wpc^" +  document.getElementById("txtWaterPercent").value + "@";
    str2 += "wdis^" +  document.getElementById("txtDiscount").value + "@";
    str2 += "naoh^" +  document.getElementById("hydroxide0").checked + "@";
    str2 += "frag^" +  document.getElementById("txtFragranceRatio").value;
var cookie = str + str2;

document.cookie = recipeName + "=" + cookie + ";" + "expires=" + expire.toGMTString();
}
function GetCookie(name){
var allCookies = document.cookie;
var pos = allCookies.indexOf(name);
if(pos != -1){
    var start = pos + name.length + 1;  // +1 for the = sign
    var end = allCookies.indexOf(";",start);
    if (end == -1) end = allCookies.length;
    var value = allCookies.substring(start,end);
    value = unescape(value);
    return (value);
    }
else{
    return ("");
    }
}
function GetRecipe(){
    
var name = document.getElementById("selRecipeName").value;
var aryIDfromCookie = new Array();
var aryIDValue = new Array();
var txtIDValue, oilTxtObject, hdnUserOilIDXobject;
var cookieVal = GetCookie(name);
var j = 0, idx;
var sel = document.getElementById("selOil");
var pos = name.lastIndexOf("e");
var strName = name.substring(0,pos + 1);
var recipeNumber = name.substring(pos + 1);
var totalPerCent = parseFloat(0.0);

clearAll(false); //g_Computed set to false in clearAll()

strName += " " + recipeNumber;
if ( cookieVal.length == 0){
    alert(strName + " has not been saved as a cookie on your computer.");
    return;
    }
else{
    for( var k=1; k <= 14; k++){
    document.getElementById("txtWeight" + k).value = "";
    document.getElementById("txtPerCent" + k).value = "";
    }
    document.getElementById("spnFragranceRequired").value = "";
    document.getElementById("txtTotalPerCent").value = "";
    document.getElementById("txtTotalRecipeWeight").value = "";
    
	var txtPercent = document.getElementById("txtWaterPercent");
    var txtConc = document.getElementById("spnLyeConc");
    var txtRatio = document.getElementById("spnWaterLyeRatio");
    var lblPercent = document.getElementById("lblwaterAmount0");
	var lblConc = document.getElementById("lblwaterAmount1");
	var lblRatio = document.getElementById("lblwaterAmount2");
	
	
    var allValues = cookieVal.split('#');
    //  48:50 @ 10:25 @ 7:25 # tow:3@

    var a = allValues[0].split('@');
    var b;
    // oil values
    for (var i = 0; i < a.length; i++){
        b = a[i].split('^');
        aryIDfromCookie[i] = b[0]
        aryIDValue[i] = b[1];
        }
    // other values
    a = allValues[1].split('@');
    for (i = 0; i < a.length; i++){
        b = a[i].split('^');
        switch (b[0]){
            case "unit":
                if ( b[1] == "lb"){
                    document.getElementById("oilWeight0").checked = true;
                    document.getElementById('lblWT').innerHTML="lb";
                    document.getElementById('TWunit').innerHTML="Pounds";
                    document.getElementById('FragranceRatioUnit').innerHTML = "Oz per Lb";
                    unit = "lb";
                }
                if ( b[1] == "oz"){
                    document.getElementById("oilWeight1").checked = true;
                    document.getElementById('lblWT').innerHTML="oz";
                    document.getElementById('TWunit').innerHTML="Ounces";
                    document.getElementById('FragranceRatioUnit').innerHTML = "Oz per Lb";
                    unit = "oz";
                }
                if ( b[1] == "gm"){
                    document.getElementById("oilWeight2").checked = true;
                    document.getElementById('lblWT').innerHTML="gm";
                    document.getElementById('TWunit').innerHTML="Grams";
                    document.getElementById('FragranceRatioUnit').innerHTML = "Gm per Kg";
                    unit = "gm";
                }
                break;
            case "wt":
                document.getElementById("txtTW").value = b[1];
                document.getElementById("txtTotalRecipeWeight").value = b[1];
                break;
            case "wpc":
                document.getElementById("txtWaterPercent").value = b[1];
                break;
            case "wdis":
                document.getElementById("txtDiscount").value = b[1];
                break;
            case "lyecon":
                document.getElementById("spnLyeConc").value = b[1];
                break;
            case "wlratio":
                document.getElementById("spnWaterLyeRatio").value = b[1];
                break;
            case "chklc":
                if ( b[1] == "true"){
                    document.forms['recipeData'].elements['R4'][1].checked = true;
					txtConc.style.backgroundColor="#C9FCD0";
					txtConc.focus();
					txtConc.readOnly = false;
					lblConc.style.fontWeight = "900";
					FixedConc = true;
				}
                else{
                    document.forms['recipeData'].elements['R4'][1].checked = false;
					txtConc.style.backgroundColor="#FFFFFF";
					txtConc.readOnly = true;
					lblConc.style.fontWeight = "400";
					FixedConc = false;
				}
                break;
            case "chkwl":
                if ( b[1] == "true"){
                    document.forms['recipeData'].elements['R4'][2].checked = true;
					txtRatio.style.backgroundColor="#C9FCD0";
					txtRatio.focus();
					txtRatio.readOnly = false;
					lblRatio.style.fontWeight = "900";
					FixedRatio = true;
				}
				else{
                    document.forms['recipeData'].elements['R4'][2].checked = false;
					txtRatio.style.backgroundColor="#FFFFFF";
					txtRatio.readOnly = true;
					lblRatio.style.fontWeight = "400";
					FixedRatio = false;
				}
				break;
            case "pw":
                if ( b[1] == "true"){
                    document.getElementById("radPercent0").checked = true;
					document.getElementById('txtTW').style.backgroundColor = "#C9FCD0";
					document.getElementById('txtTW').readOnly = true;
				}
                else{
                    document.getElementById("radPercent1").checked = true;
					document.getElementById('txtTW').style.backgroundColor = "#FFFFFF";
					document.getElementById('txtTW').readOnly = true;
				}
                break;
            case "wpc":
                document.getElementById("txtWaterPercent").value = b[1];
                break;
            case "wdis":
                document.getElementById("txtDiscount").value = b[1];
                break;
            case "naoh":
				hydroxideChange(document.getElementById("hydroxide0"));
                if ( b[1] == "true"){
                    document.getElementById("hydroxide0").checked = true;
				}
                else{
                    document.getElementById("hydroxide1").checked = true;
				}
                break;
            case "frag":
                document.getElementById("txtFragranceRatio").value = b[1];
                break;
        }
    }
  
	if ( document.forms['recipeData'].elements['R4'][1].checked == false && document.forms['recipeData'].elements['R4'][2].checked == false){
		document.forms['recipeData'].elements['R4'][0].checked = true;
		txtPercent.style.backgroundColor="#C9FCD0";
		txtPercent.focus();
		txtPercent.readOnly = false;
		lblPercent.style.fontWeight = "900";
		FixedConc = false;
	}
	else{
		txtPercent.style.backgroundColor="#FFFFFF";
		txtPercent.readOnly = true;
		lblPercent.style.fontWeight = "400";
	}
	 
    for (i = 0; i < aryIDfromCookie.length; i++){
        idx = i + 1;
        if(document.getElementById("radPercent0").checked == true)
            pcTxtObject = document.getElementById("txtPerCent" + idx );
        else
            pcTxtObject = document.getElementById("txtWeight" + idx );
        
		oilTxtObject = document.getElementById("txtOil" + idx);
        hdnUserOilIDXobject = document.getElementById("hdnIndex" + i);
        if (aryIDfromCookie[i] == -1 ){
            oilTxtObject.value = "";
            pcTxtObject.value = "";
            hdnUserOilIDXobject.value = "-1";
            // was i-1 on below 2 lines
			ary14RecipeSapVals[i] = parseFloat(0.0);
            ary14RecipeSelIndexes[i] = parseInt(0);
            continue;
            }
		if( isNaN (aryIDValue[i]))
			pcTxtObject.value = "";
		else{
	        pcTxtObject.value = aryIDValue[i];
			if(document.getElementById("radPercent0").checked == true)
        		totalPerCent += parseFloat(aryIDValue[i]);
		}
        //alert(aryIDfromCookie[i]);
        // FIND aryAllOils INDEX
        for (var x=0; x < aryAllOils.length; x++){
            if ( aryIDfromCookie[i] == aryAllOils[x].id )
                break;
            }
		oilTxtObject.value = sel.options[x].text;
        ary14RecipeSelIndexes[i] = x;
        hdnUserOilIDXobject.value = x;
        ary14RecipeSapVals[i] = parseFloat(sel.options[x].value);
		document.getElementById("hdnSap" + (i)).value = sel.options[x].value;
		}
    
    }
	if(document.getElementById("radPercent0").checked == true){
		document.getElementById("txtTotalPerCent").value = totalPerCent;
		if ( roundNumber(totalPerCent,1) != 100.0)
			document.getElementById("txtTotalPerCent").style.color = "#FF0000";
		else
			document.getElementById("txtTotalPerCent").style.color = "#000000";
	}
        
    PorWClick(); //xxx
	setFixedWaterMethod();
    
} 
//======
//======
//===============================
function roundNumber(number, dec) {
    return Math.round(number*Math.pow(10,dec))/Math.pow(10,dec);
}
//---------
function isWhitespace (s)
{   
    var i;
    var whitespace = " \t\n\r";
    if (isEmpty(s)) return true;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}
//==================
// Is string empty.
function isEmpty(s)
{   
    return ((s == null) || (s.length == 0))
}
//=====================
function fixPCrounding(num){
var sInt, sDec, sTmp, sRet;
var lr;
var trueRound;
var s1 = new String(num);

// return on whole integer
if (s1.indexOf(".") == -1 )
    return num;
lr = s1.split(".");
sInt = lr[0];
sDec = lr[1];
sTmp = sDec.slice(0,12);
return parseFloat(sInt + "." + sTmp)
}
function hideHelp(){
    var newWin
	divHelp.style.visibility = "hidden";
    newWin.close();
}
//===================
function showHelp(obj){
var tmp = new String(obj.id);
var helpnum = parseInt(tmp.substr(4));
var help = document.getElementById("divOnPageHelp");
switch (helpnum){
case 0:
writeHelp(0);
break;
case 1:
writeHelp(1);
break;
case 2:
writeHelp(2);
break;
case 3:
writeHelp(3);
break;
case 4:
writeHelp(4);
break;
case 5:
writeHelp(5);
break;
case 6:
writeHelp(6);
break;
case 7:
writeHelp(7);
break;
case 8:
writeHelp(8);
break;
}
document.getElementById("divOnPageHelp").style.display = "block";
}
function closeOnPageHelp(){
    document.getElementById("divOnPageHelp").style.display = "none";
}

//==========================
function showCount(){
	document.getElementById("spnCount").style.display = "inline";
}
function hideCount(){
	document.getElementById("spnCount").style.display = "none";
}
//=========================
function showFADetail(idx){
	document.getElementById("divFADetail").innerHTML = aryFADetail[idx] + tailFADetail;
	document.getElementById("divFADetail").style.display = "block";
}
function hideFADetail(){
	document.getElementById("divFADetail").style.display = "none";
}
//=========================
function showRanges(idx){
	document.getElementById("divRanges").innerHTML = aryRanges[idx];
	document.getElementById("divRanges").style.display = "block";
}
function hideRanges(){
	document.getElementById("divRanges").style.display = "none";
}
//=========================
function showSatRatio(Sat, MonoUnSat, PolyUnSat){
	var Unsat = MonoUnSat + PolyUnSat;
	var unknown = 100 - (Sat + Unsat);
	var percentSat = Sat/(Sat + Unsat);
	var xtraSat = roundNumber(unknown * (Sat/(Sat + Unsat)), 0);
	var xtraUnsat = roundNumber(unknown * (Unsat/(Sat + Unsat)), 0);
	//alert(xtraSat + " - " + xtraUnsat)
	var sr = (Sat + xtraSat) + " : " + (Unsat + xtraUnsat);
	document.getElementById("tdSatRatioMain").value = sr; 
}
//===============
/*function cursorControl(which){
	switch (which){
		case 0:
			document.body.style.cursor = "default";
			break;
		case 1:
			document.body.style.cursor = "hand";
			break;
		default:document.body.style.cursor = "default";
	}
}*/
//***************
//=============

