 String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } // add trim function to string
  
  function addEvent(obj, evType, fn){ 
	
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); //last param false if you want the ie buble b
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
	return false; 
	} 
}
  
  function Cookies() {

    this.setCookie = function (name, value, days) {

        if (typeof(days) != 'undefined') {
            var date = new Date();
            date.setTime(date.getTime() + (days*24*60*60*1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else {
            var expires = "";
        }

        document.cookie = name.trim() + "=" + escape (value) +expires+"; path=/";
    }
	
	this.setCookieArray = function (name, value, days,index) {
		var cookieArray = this.getCookieArray(name);
		cookieArray[index] = value;
		this.setCookie(name,cookieArray.join(),days);
	}

    this.getCookie = function (name){
        name = name.trim(); + "=";
        var cookies = document.cookie.split(';');
		for (var i in cookies){
			var c = cookies[i].trim();
            if (c.indexOf(name) == 0) return unescape(c.substring(name.length+1,c.length));
        }
        return null;
    }
	
	this.getCookieArray = function (name){
		return this.getCookie(name).split(',');
	}

    this.deleteCookie = function (name) {
        this.setCookie(name, "", -1);
    }

}

var cookies = new Cookies();

function openPopup(obj){
	obj.style.display = "block";
}

function closePopup(obj){
	obj.style.display = "none";
}

var metals = new Array("4","0","8","P","L","S","T");
nummetals = metals.length;
var RDwtGrmv = "";

function  getText(rowsList,rowNamesList,columnsList,columnNamesList,stonelines){
	var str = '';
	for (var rowName in rowsList)
	{
		//alert(rowsList[rowName]);
		//var rowobj = document.getElementById(rowsList[rowName]);

		stnnum = parseInt(rowName)+1;
		if ((stonelines =="") || ((stonelines =="S") && (document.getElementById("Stnqty"+stnnum).value !="0")) || (stonelines =="A"))
		{
			str += rowNamesList[rowName];
			for(var columnName in columnsList){
				//alert (columnsList[columnName]);
				var obj = (stonelines == "S")?document.getElementById(columnsList[columnName]+rowsList[rowName]):document.getElementById(rowsList[rowName]+columnsList[columnName]);
				if(obj && (obj.style.display != 'none')) 
				{
					str += ',';
					str += obj.value.replace(/,/,'');
				}
			}
			str += '\n';
		}
	}
	if( str != '')
	{
		var headStr =''
		for(var columnName in columnsList)
		{
			headStr += ',';
			headStr += columnNamesList[columnName];
		}
		str = headStr + '\n' + str + '\n';
	}
	return(str);
}

function getAllText(){

var MtlRows = new Array();
var MtlRowNames = new Array(); 

    MtlRows[0] = "Market"; MtlRowNames[0] = "Market";
    MtlRows[1] = "Factor"; MtlRowNames[1] = "Factor";   
 if (RDwtGrmv !="G" && RDwtGrmv !="D")
   {MtlRows[2] = "PrcDwt"; MtlRowNames[2] = "Price/Dwt";
    MtlRows[3] = "PrcGrm"; MtlRowNames[3] = "Price/Gram";
    MtlRows[4] = "CalcPrcD"; MtlRowNames[4] = "Price/Dwt w/Mkp";
    MtlRows[5] = "CalcPrcG"; MtlRowNames[5] = "Price/Gram w/Mkp";
    MtlRows[6] = "Dwt"; MtlRowNames[6] = "Dwt";
    MtlRows[7] = "Grm"; MtlRowNames[7] = "Grams";
    MtlRows[8] = "CalcMPrc"; MtlRowNames[8] = "Metal $/Pc w/Mkp";
    MtlRows[9] = "TCost"; MtlRowNames[9] = "Total Item Cost";
    MtlRows[10] = "TPrice"; MtlRowNames[10] = "Total Item Price";
    MtlRows[11] = "TotalCharge"; MtlRowNames[11] = "If I Charge";
    MtlRows[12] = "TotalProfit"; MtlRowNames[12] = "My Profit % is";}
if (RDwtGrmv =="G")
   {MtlRows[2] = "PrcGrm"; MtlRowNames[2] = "Price/Gram";
    MtlRows[3] = "CalcPrcG"; MtlRowNames[3] = "Price/Gram w/Mkp";
    MtlRows[4] = "Grm"; MtlRowNames[4] = "Grams";}
if (RDwtGrmv =="D")
   {MtlRows[2] = "PrcDwt"; MtlRowNames[2] = "Price/Dwt";
    MtlRows[3] = "CalcPrcD"; MtlRowNames[3] = "Price/Dwt w/Mkp";
    MtlRows[4] = "Dwt"; MtlRowNames[4] = "Dwt";} 
if (RDwtGrmv =="G" | RDwtGrmv == "D")
   {MtlRows[5] = "CalcMPrc"; MtlRowNames[5] = "Metal $/Pc w/Mkp";
    MtlRows[6] = "TCost"; MtlRowNames[6] = "Total Item Cost";
    MtlRows[7] = "TPrice"; MtlRowNames[7] = "Total Item Price";
    MtlRows[8] = "TotalCharge"; MtlRowNames[8] = "If I Charge";
    MtlRows[9] = "TotalProfit"; MtlRowNames[9] = "My Profit % is";}
   
var MtlColumns = new Array(); 
var MtlColumnNames = new Array();
var j=0;
var Itemnum = document.getElementById('ItemNumber').value;

str = "";
            if (Itemnum != "")
{
                      
                       str += "Item #,";
                       str += Itemnum;
                       str +='\n';
}

  for(i=0;i<nummetals;i++){
               if (document.getElementById('disp'+metals[i]).Checked == 'true') 
                      {j=j+1;
                   MtlColumns[j-1] = metals[i];
                   MtlColumnNames[j-1] = (i==0)? "Gold 14kt": (i==1)? "Gold 10kt": (i==2)? "Gold 18kt": (i==3)? "Platinum": (i==4)? "Palladium": (i==5)? "Silver": (i==6)? "Total": "";
                   }}
        str += getText(MtlRows,MtlRowNames,MtlColumns,MtlColumnNames,"");
	str += '\n';
	var stonesStr = getText(new Array(1,2,3),new Array(1,2,3),new Array("Stnqty","Stoneshape","Stonetype","Stonesize","Sinputwt","Stnextwt","Sdimension","Stone","Stoneuom","Snotes","Stoneextcost","Stoneextprice"),new Array("Qty","Shape","Type","Size","Karat Wt","Ext Wt","Dimensions","Cost","UOM","Notes","Ext Cost","Ext Price"),"S");
	if( stonesStr != '')
	{
		str += "Stones \n";
		str += stonesStr;
		str += "Total Stones Cost," 
		str += document.getElementById("StnttlCost").value;
		str += '\n';
		str += "Total Stones Price," 
		str += document.getElementById("StnttlPrice").value;
		str += '\n\n'
	}
	str += "Additional Items \n";
	
	str += getText(new Array("Labor"),new Array("Labor"),new Array("1","2","3"),new Array(document.getElementById("laborD1").value,document.getElementById("laborD2").value,document.getElementById("laborD3").value),"A");
	str += "Total Labor Cost,"; 
	str += document.getElementById("LabttlCost").value;
	str += '\n';
	str += "Total Labor Price,"; 
	str += document.getElementById("LabttlPrice").value;
	str += '\n';
	str += getText(new Array("Other"),new Array("Other"),new Array("1","2","3"),new Array(document.getElementById("otherD1").value,document.getElementById("otherD2").value,document.getElementById("otherD3").value),"A");
	str += "Total Other Cost," 
	str += document.getElementById("OthttlCost").value;
	str += '\n';
	str += "Total Other Price," 
	str += document.getElementById("OthttlPrice").value;
	str += '\n';
	document.getElementById('csvdata').value=str;
	var d = new Date();
	var dstr = '';
	dstr += d.getFullYear();
	dstr +=  (d.getMonth() < 10 ? '0' : '') + d.getMonth();
	dstr += (d.getDate() < 10 ? '0' : '') + d.getDate();
	dstr += (d.getHours() < 10 ? '0' : '') + d.getHours();
	dstr += (d.getMinutes() < 10 ? '0' : '') + d.getMinutes();
	document.getElementById('saveas').value = 'lsscalc_' + document.getElementById ('ItemNumber').value + '_' + dstr + '.csv';
	document.forms["csvform"].submit();
	//document.getElementById('data2csv').submit();
	
}
function setStoneDefault(num1){
        document.getElementById('Stonetype'+num1).value="Diamond";
        document.getElementById('Stoneshape'+num1).value="Round";
        setTypeCT(num1);
}


var stonesInit = new Array();
var gravityList= new Array();
        gravityList["Diamond"]=3.51;
        gravityList["Alexandrite"]=3.73;
        gravityList["Amethyst"]=2.65;
        gravityList["Aquamarine"]=2.74;
        gravityList["Citrine"]=2.65;
        gravityList["Emerald"]=2.77;
        gravityList["Peridot"]=3.33;
        gravityList["Ruby"]=4;
        gravityList["Sapphire"]=4;
        gravityList["Tanzanite"]=3.3;
        gravityList["Turquoise"]=2.7;
        gravityList["Lapis"]=2.8;
        gravityList["Moonstone"]=2.65;
        gravityList["Rock Crystal"]=2.65;
        gravityList["Topaz"]=3.55;
        gravityList["Pearl"]=3.51;
        gravityList["Default"]=3.51;

function initStones()
{
	var shapesList  = new Array ("Round","Princess","Emerald","Marquise","Square","Oval","Pear","Asscher","Heart","Cushion","Trillion","Loose","Strand","Default");  
	var typesList = new Array ("Diamond","Alexandrite","Amethyst","Aquamarine","Citrine","Emerald","Pearl","Peridot","Ruby","Sapphire","Tanzanite","Turquoise","Lapis","Moonstone","Rock Crystal","Topaz","Default");
       
for (var i in shapesList)
	{
		stonesInit[shapesList[i]] = new Array();
		for (var j in typesList)
		{
			stonesInit[shapesList[i]][typesList[j]] = new Array();
		}
	}

stonesInit["Round"]["Diamond"]["Size"] = new Array(.005,.0075,.01,.015,.02,.025,.03,.035,.075,.1,.2,.25,.5,.75,1);
	stonesInit["Round"]["Diamond"]["Size"] = new Array(0.01,0.02,0.03,0.05,0.07,0.1,0.15,0.2,0.25,0.33,0.4,0.5,0.65,0.75,0.85,1,1.25,1.5,1.75,2,2.25,2.5,3,4,5,6,7,8,10,15,20);
	stonesInit["Round"]["Diamond"]["Wt"] = new Array(0.01,0.02,0.03,0.05,0.07,0.1,0.15,0.2,0.25,0.33,0.4,0.5,0.65,0.75,0.85,1,1.25,1.5,1.75,2,2.25,2.5,3,4,5,6,7,8,10,15,20);
	stonesInit["Round"]["Diamond"]["Dime"] = new Array('1.0 mm','1.2 mm','1.5 mm','1.7 mm','2.7 mm','3.0 mm','3.4 mm','3.8 mm','4.1 mm','4.4 mm','4.8 mm','5.2 mm','5.6 mm','5.9 mm','6.2 mm','6.5 mm','7.0 mm','7.4 mm','7.8 mm','8.2 mm','8.6 mm','9.0 mm','9.3 mm','10.2 mm','11.0 mm','11.7 mm','12.4 mm','13.0 mm','14.0 mm','16.3 mm','17.6 mm');
	
	stonesInit["Oval"]["Diamond"]["Size"] = new Array (0.2,0.25,0.33,0.4,0.5,0.65,0.75,1,1.25,1.5,1.75,2,3,3.5,4,4.5,5);
	stonesInit["Oval"]["Diamond"]["Wt"] = new Array (0.2,0.25,0.33,0.4,0.5,0.65,0.75,1,1.25,1.5,1.75,2,3,3.5,4,4.5,5);
	stonesInit["Oval"]["Diamond"]["Dime"] =	new Array ('4 x 3 mm','5 x 3 mm','5.5 x 3.5 mm','5.8 x 3.8 mm','6 x 4 mm','6.5 x 4.5 mm','7 x 5 mm','7.5 x 5.5 mm','8 x 6 mm','8.5 x 6.5 mm','9 x 7 mm','9.5 x 7.5 mm','10 x 8 mm','10.5 x 8.5 mm','11 x 9 mm','11.5 x 9.5 mm','12 x 10 mm');
	
	stonesInit["Marquise"]["Diamond"]["Size"] = new Array (0.2,0.25,0.5,0.75,1,1.5,2.5,2.5,3,4,5);
	stonesInit["Marquise"]["Diamond"]["Wt"] = new Array (0.2,0.25,0.5,0.75,1,1.5,2.5,2.5,3,4,5);
	stonesInit["Marquise"]["Diamond"]["Dime"] =	new Array ('4 x 2 mm.','5 x 2 mm.','5.5 x 2.5','8 x 4 mm','9 x 4.5 m','10 x 4.75','10,5 x 5','11 x 5.2','12 x 6 mm','13 x 6.5','14 x 7 mm','16 x 8 mm','17 x 9 mm','20 x 10');
	
	stonesInit["Emerald"]["Diamond"]["Size"] = new Array (0.2,0.25,0.5,0.75,1,1.5,2.5,2.5,3,4,5);
	stonesInit["Emerald"]["Diamond"]["Wt"] = new Array (0.2,0.25,0.5,0.75,1,1.5,2.5,2.5,3,4,5);
	stonesInit["Emerald"]["Diamond"]["Dime"] = new Array ('4 x 3 mm','5 x 3 mm','6 x 4 mm','6.5 x 4.5 mm','7 x 5 mm','8 x 6 mm','9 x 7 mm','8.5 x 6.5 mm','10 x 8 mm','11 x 9 mm','12 x 10 mm');

	stonesInit["Asscher"]["Diamond"]["Size"] = new  Array(0.25,0.5,1,1.5,2,2.5,3,4,5);
	stonesInit["Asscher"]["Diamond"]["Wt"] = new Array (0.25,0.5,1,1.5,2,2.5,3,4,5);
	stonesInit["Asscher"]["Diamond"]["Dime"] = new Array('3.4 x 3.4 mm','4.4 x 4.4 mm','5.5 x 5.5 mm','6.5 x 6.5 mm','7.5 x 7.5 mm','8 x 8 mm','8.3 x 8.3 mm','9 x 9 mm','9.5 x 9.5 mm');

	stonesInit["Trillion"]["Diamond"]["Size"] = new Array (0.2,0.25,0.5,0.75,1,1.5,2.5,2.5,3,4,5);
	stonesInit["Trillion"]["Diamond"]["Wt"] = new Array (0.2,0.25,0.5,0.75,1,1.5,2.5,2.5,3,4,5);
	stonesInit["Trillion"]["Diamond"]["Dime"] = new Array ('4 x 3 mm','5 x 3 mm','6 x 4 mm','6.5 x 4.5 mm','7 x 5 mm','8 x 6 mm','9 x 7 mm','8.5 x 6.5 mm','10 x 8 mm','11 x 9 mm','12 x 10 mm');
	
	stonesInit["Heart"]["Diamond"]["Size"] = new Array (0.25,0.5,1,1.5,2,2.5,3,4,5);
	stonesInit["Heart"]["Diamond"]["Wt"] = new Array (0.25,0.5,1,1.5,2,2.5,3,4,5);
	stonesInit["Heart"]["Diamond"]["Dime"] = new Array ('4 x 4 mm','5 x 5 mm','6.5 x 6.5 mm','7 x 7 mm','8 x 8 mm','8.5 x 8.5 mm','9 x 9 mm','10 x 10 mm','11 x 11 mm');
	
	stonesInit["Pear"]["Diamond"]["Size"] = new Array (0.2,0.25,0.3,0.5,0.75,1,1.5,2,2.5,3,3.5);
	stonesInit["Pear"]["Diamond"]["Wt"] = new Array (0.2,0.25,0.3,0.5,0.75,1,1.5,2,2.5,3,3.5);
	stonesInit["Pear"]["Diamond"]["Dime"] = new Array ('4 x 3 mm','5 x 3 mm','6 x 4 mm','6.5 x 4.5 mm','7 x 5 mm','8 x 6 mm','9 x 7 mm','8.5 x 6.5 mm','10 x 8 mm','11 x 9 mm','12 x 10 mm');

	stonesInit["Princess"]["Diamond"]["Size"] = new Array (0.25,0.5,1,1.5,2,2.5,3,4,5);
	stonesInit["Princess"]["Diamond"]["Wt"] = new Array (0.25,0.5,1,1.5,2,2.5,3,4,5);
	stonesInit["Princess"]["Diamond"]["Dime"] = new Array ('3.4 x 3.4 mm','4.35 x 4.35 mm','5.5 x 5.5 mm','6.5 x 6.5 mm','7.5 x 7.5 mm','8 x 8 mm','8.25 x 8.25 mm','9 x 9 mm','9.5 x 9.5 mm');

	
	stonesInit["Default"]["Pearl"]["Size"] = new Array('2.5-3mm','3-3.5 mm','3.5-4 mm','4-4.5 mm','4.5-5 mm','5-5.5 mm','5.5-6 mm','6-6.5 mm','6.5-7 mm','7-7.5 mm','7.5-8 mm','8-8.5 mm','8.5-9 mm','9-9.5 mm','9.5-10mm','10-10.5mm');
	stonesInit["Default"]["Pearl"]["Wt"] =	new Array(0.00625,0.011111,0.015873,0.025,0.037037,0.052632,0.066667,0.083333,0.107527,0.142857,0.166667,0.2,0.238095,0.285714,0.333333,0.4);
	stonesInit["Default"]["Pearl"]["Dime"] = new Array('2.5-3mm','3-3.5 mm','3.5-4 mm','4-4.5 mm','4.5-5 mm','5-5.5 mm','5.5-6 mm','6-6.5 mm','6.5-7 mm','7-7.5 mm','7.5-8 mm','8-8.5 mm','8.5-9 mm','9-9.5 mm','9.5-10mm','10-10.5mm');
	
//	stonesInit["Round"]["Emerald"]["Size"] = new Array("1.6mm","2mm","3mm","4mm");
//	stonesInit["Round"]["Emerald"]["Wt"] = new Array(","2mm","3mm","4mm");
//	stonesInit["Round"]["Emerald"]["Dime"] = new Array('','','','');
//	stonesInit["Round"]["Ruby"]["Size"] = new Array("1mm","2mm","3mm","4mm");
//	stonesInit["Round"]["Ruby"]["Wt"] = new Array("1mm","2mm","3mm","4mm");
//	stonesInit["Round"]["Ruby"]["Dime"] = new Array('','','','');
//	stonesInit["Round"]["Sapphire"]["Size"] = new Array("1mm","2mm","3mm","4mm");
//	stonesInit["Round"]["Sapphire"]["Wt"] = new Array("1mm","2mm","3mm","4mm");
//	stonesInit["Round"]["Sapphire"]["Dime"] = new Array('','','','');
//	stonesInit["Round"]["Tanzanite"]["Size"] = new Array("1mm","2mm","3mm","4mm");
//	stonesInit["Round"]["Tanzanite"]["Wt"] = new Array("1mm","2mm","3mm","4mm");
//	stonesInit["Round"]["Tanzanite"]["Dime"] = new Array('');
	

	stonesInit["Round"]["Default"]["Size"] = new Array('1.6 mm','2 mm','2.5 mm','3 mm','3.5 mm','4 mm','4.5 mm','5 mm','5.5 mm','6 mm','6.5 mm','7 mm','8 mm','9 mm','10 mm','11 mm','12 mm','13 mm','14 mm','15 mm','16 mm','17 mm','18 mm','19 mm','20 mm','21 mm','22 mm','23 mm','24 mm','25 mm');
	stonesInit["Round"]["Default"]["Wt"] = new Array(0.02,0.03,0.06,0.1,0.16,0.25,0.33,0.5,0.65,0.75,1,1.25,2,2.75,3.5,4.6,6,7.75,9.65,11.85,14.35,17.25,20.5,24,28,34.8,41.8,49.8,57.9,68.7);
	stonesInit["Round"]["Default"]["Dime"] = new Array('1.6 mm','2 mm','2.5 mm','3 mm','3.5 mm','4 mm','4.5 mm','5 mm','5.5 mm','6 mm','6.5 mm','7 mm','8 mm','9 mm','10 mm','11 mm','12 mm','13 mm','14 mm','15 mm','16 mm','17 mm','18 mm','19 mm','20 mm','21 mm','22 mm','23 mm','24 mm','25 mm');	

	stonesInit["Square"]["Default"]["Size"] = new Array('5 mm','6 mm','7 mm','8 mm','9 mm','10 mm','11 mm','12 mm','13 mm','14 mm','15 mm','16 mm');
	stonesInit["Square"]["Default"]["Wt"] = new Array(0.75,1.3,2.05,2.9,4.4,6,8,10.35,13.2,16.5,20.25,24.6);
	stonesInit["Square"]["Default"]["Dime"] = new Array('5 mm','6 mm','7 mm','8 mm','9 mm','10 mm','11 mm','12 mm','13 mm','14 mm','15 mm','16 mm');	
	
	stonesInit["Oval"]["Default"]["Size"] = new Array('5 x 3 mm','6 x 4 mm','7 x 5 mm','8 x 6 mm','9 x 7 mm','10 x 8 mm','11 x 9 mm','12 x 10 mm','14 x 10 mm','14 x 12 mm','16 x 12 mm','18 x 13 mm');
	stonesInit["Oval"]["Default"]["Wt"] =	new Array(0.25,0.5,1,1.5,2.5,3,4,5,6,8,10.5,14.2);
	stonesInit["Oval"]["Default"]["Dime"] = new Array('5 x 3 mm','6 x 4 mm','7 x 5 mm','8 x 6 mm','9 x 7 mm','10 x 8 mm','11 x 9 mm','12 x 10 mm','14 x 10 mm','14 x 12 mm','16 x 12 mm','18 x 13 mm');
	

	stonesInit["Emerald"]["Default"]["Size"] = new Array('6 x 4 mm','7 x 5 mm','8 x 6 mm','9 x 7 mm','10 x 8 mm','11 x 9 mm','12 x 10 mm','14 x 10 mm','14 x 12 mm','16 x 12 mm','18 x 13 mm','20 x 15 mm','25 x 18 mm');
	stonesInit["Emerald"]["Default"]["Wt"]   =  new Array(0.5,1,1.5,2.5,3,4,5,6,8,10.5,14.2,20.3,52.2);
	stonesInit["Emerald"]["Default"]["Dime"] = new Array('6 x 4 mm','7 x 5 mm','8 x 6 mm','9 x 7 mm','10 x 8 mm','11 x 9 mm','12 x 10 mm','14 x 10 mm','14 x 12 mm','16 x 12 mm','18 x 13 mm','20 x 15 mm','25 x 18 mm');	
	
	
	stonesInit["Pear"]["Default"]["Size"] = new Array('6 x 5 mm','7 x 5 mm','8 x 5 mm','9 x 6 mm','10 x 7 mm','11 x 7 mm','12 x 8 mm','13 x 9 mm','15 x 10 mm','16 x 12 mm','18 x 13 mm','20 x 15 mm','22 x 15 mm','25 x 18 mm','30 x 22 mm');
	stonesInit["Pear"]["Default"]["Wt"] =	new Array(0.7,0.75,1,1.5,2,2.25,3,3.5,5.5,8.6,12,17.3,18.7,30.6,54.5);
	stonesInit["Pear"]["Default"]["Dime"] = new Array('6 x 5 mm','7 x 5 mm','8 x 5 mm','9 x 6 mm','10 x 7 mm','11 x 7 mm','12 x 8 mm','13 x 9 mm','15 x 10 mm','16 x 12 mm','18 x 13 mm','20 x 15 mm','22 x 15 mm','25 x 18 mm','30 x 22 mm');

	stonesInit["Default"]["Default"]["Size"] = new Array('1');
	stonesInit["Default"]["Default"]["Wt"] =	new Array('1');
	stonesInit["Default"]["Default"]["Dime"] = new Array('');
     }

function updateStoneDime(num,shape,type,option){
	if (stonesInit[shape][type]["Dime"])
	{
		document.getElementById("Sdimension" + num).value = stonesInit[shape][type]["Dime"][option];
	} else if (stonesInit[shape]["Default"]["Dime"]){
		document.getElementById("Sdimension" + num).value = stonesInit[shape]["Default"]["Dime"][option];
	} else if (stonesInit["Default"][type]["Dime"]){
		document.getElementById("Sdimension" + num).value = stonesInit["Default"][type]["Dime"][option];
	} else if (stonesInit["Default"]["Default"]["Dime"]){
		document.getElementById("Sdimension" + num).value = stonesInit["Default"]["Default"]["Dime"][option];
	} 
}
							
function updateStoneWt(num,shape,type,lookuptype,option){
	if (stonesInit[shape][lookuptype]["Wt"])
	{
	document.getElementById("Sinputwt" + num).value = (stonesInit[shape][lookuptype]["Wt"][option]/3.51*gravityList[type]).toFixed(4);
	}else if (stonesInit[shape]["Default"]["Wt"]){
		document.getElementById("SinputWt" + num).value = (stonesInit[shape]["Default"]["Wt"][option]/3.51*gravityList[type]).toFixed(4);
	} else if (stonesInit["Default"][lookuptype]["Wt"]){
		document.getElementById("Sinputwt" + num).value = (stonesInit["Default"][lookuptype]["Wt"][option]/3.51*gravityList[type]).toFixed(4);
	} else if (stonesInit["Default"]["Default"]["Wt"]){
		document.getElementById("Sinputwt" + num).value = (stonesInit["Default"]["Default"]["Wt"][option]/3.51*gravityList[type]).toFixed(4);
        
    
	}
	updateStoneDime(num,shape,type,option);
}

function setStoneWt(num){
	sType= document.getElementById("Stonetype" + num);
	sShape = document.getElementById("Stoneshape" + num);
	sSize = document.getElementById("Stonesize" + num);
	shape = sShape[sShape.selectedIndex].value;
	type = sType[sType.selectedIndex].value;
	if (stonesInit[shape][type]["Size"])
	{
		updateStoneWt(num,shape,type,type,sSize.selectedIndex);
	} else if (stonesInit[shape]["Default"]["Size"]){
		updateStoneWt(num,shape,type,"Default",sSize.selectedIndex);
	} else if (stonesInit["Default"][type]["Size"]){
		updateStoneWt(num,"Default",type,type,sSize.selectedIndex);
	} else if (stonesInit["Default"]["Default"]["Size"]){
		updateStoneWt(num,"Default",type,"Default",sSize.selectedIndex);
	} 
        updateStnextwt(num);
}

function setSelectOptions(obj,optList){
	obj.options.length = 0;
	for (var i in optList)
	{
		obj.options[obj.length] = new Option(optList[i], optList[i]);

	}

}
function setShapeList(num){
                 if (document.getElementById("Stonetype"+num).value == "Diamond")
            {shapelist= new Array ("Round","Princess","Emerald","Asscher","Marquise","Oval","Pear","Square","Heart","Cushion","Trillion");}
           else if (document.getElementById("Stonetype"+num).value == "Pearl")
             {shapelist= new Array ("Loose","Strand");}
           else
            {shapelist= new Array ("Round","Emerald","Marquise","Oval","Pear","Square");}


         setSelectOptions(document.getElementById("Stoneshape"+num),shapelist);

}
function setTypeCT(num){
	sType= document.getElementById("Stonetype" + num);
	sShape = document.getElementById("Stoneshape" + num);
	sSize = document.getElementById("Stonesize" + num);
	shape = sShape[sShape.selectedIndex].value;
	type = sType[sType.selectedIndex].value;

	if (stonesInit[shape][type]["Size"])
	{
//		alert(shape + type +"both");
		setSelectOptions(sSize,stonesInit[shape][type]["Size"]);
		updateStoneWt(num,shape,type,type,0);
	} else if (stonesInit[shape]["Default"]["Size"]){
//		alert(shape + type +"DefType");
		setSelectOptions(sSize,stonesInit[shape]["Default"]["Size"]) ;
		updateStoneWt(num,shape,type,"Default",0);
	} else if (stonesInit["Default"][type]["Size"]){
//		alert(shape + type +"DefShape");
		setSelectOptions(sSize,stonesInit["Default"][type]["Size"]);
		updateStoneWt(num,"Default",type,type,0);
	} else if (stonesInit["Default"]["Default"]["Size"]){
//		alert(shape + type +"Def");
		setSelectOptions(sSize,stonesInit["Default"]["Default"]["Size"]) ;
		updateStoneWt(num,"Default",type,"Default",0);
	} 
    updateStnextwt(num);   
} 



function setStoneWt1(num2){
        if (document.getElementById("Stonetype"+num2).value == "Diamond")
           {document.getElementById("Sinputwt"+num2).value=
            document.getElementById("Stonesize"+num2).value}
        updateStnextwt(num2);}           

function setTypeUom(num){
	stype= document.getElementById("Stonetype" + num);
        sshape = document.getElementById("Stoneshape"+num);
       	if(stype[stype.selectedIndex].value == 'Pearl' &&
           sshape[sshape.selectedIndex].value == 'Loose'){    
		document.getElementById('Stoneuom' + num)[2].selected = true;
	} else if ( (stype[stype.selectedIndex].value == 'Diamond') || (stype[stype.selectedIndex].value == 'Ruby') || (stype[stype.selectedIndex].value == 'Sapphire')){
		document.getElementById('Stoneuom' + num)[0].selected = true;
	} else{
		document.getElementById('Stoneuom' + num)[1].selected = true;
	}
} 
  
function toggleClassDisplay(rootElement,displayClass,display){
	if ( rootElement == null ) rootElement = document;
	var items = rootElement.getElementsByTagName("*");
	var itemsLen = items.length;
 	var pattern = new RegExp('(^|\\s)' + displayClass + '(\\s|$)');
	for (i = 0; i < itemsLen; i++) {
		if ( pattern.test(items[i].className) == true ) {
			items[i].style.display = (display)?((items[i].tagName.toLowerCase()  == 'span')?'inline-block':'inline-block'):'none';
      	}
	}
}




function testcall(prm){
//alert(prm);
}

function holdPrcDwt(metal) {
         hMarket=document.getElementById("Market"+metal).value;
         if(hMarket.indexOf(',') !=0)
           {hMarket=hMarket.replace(/,/,"");}
         hPrcDwt=(hMarket*
           document.getElementById("Factor"+metal).value/document.getElementById("Dwtozcnv").value).toFixed(4);
      return hPrcDwt;}
	 
function holdPrcGrm(metal) {
          hMarket=document.getElementById("Market"+metal).value;
         if(hMarket.indexOf(',') !=0)
           {hMarket=hMarket.replace(/,/,"");}
         hPrcGrm=(hMarket*
     document.getElementById("Factor"+metal).value/document.getElementById("Grmozcnv").value).toFixed(4);
     return hPrcGrm;}

var tcosthold = new Array();

function updatePrcDwtGrm(frommetal,tometal,mode){
//alert("inupdateprcdwtgrm "+frommetal+" X "+tometal+" X "+mode);
//alert(document.getElementById("dispT").checked);
       if (tometal != frommetal && frommetal != "" &&  (mode == "L" || ! document.getElementById("dispT").checked))
       {
//  		alert("in if  "+frommetal +" X "+ tometal+" X "+mode);

         document.getElementById("PrcDwt"+tometal).value =  
          (document.getElementById("PrcDwt"+frommetal).value/holdPrcDwt(frommetal)*holdPrcDwt(tometal)).toFixed(4);
	 document.getElementById("PrcGrm"+tometal).value =
          (document.getElementById("PrcGrm"+frommetal).value/holdPrcGrm(frommetal)*holdPrcGrm(tometal)).toFixed(4);}
         document.getElementById("CalcPrcD"+tometal).value = 
          (document.getElementById("PrcDwt"+tometal).value*(1.00+document.getElementById("PctOvr").value*.01)).toFixed(4);
         document.getElementById("CalcPrcG"+tometal).value = 
          (document.getElementById("PrcGrm"+tometal).value*(1.00+document.getElementById("PctOvr").value*.01)).toFixed(4);
		
        if (RDwtGrmv != "G")
            {document.getElementById("CalcMPrc"+tometal).value = 
            (document.getElementById("CalcPrcD"+tometal).value*document.getElementById("Dwt"+tometal).value).toFixed(2);
            MtlCsthold =
              document.getElementById("PrcDwt"+tometal).value*document.getElementById("Dwt"+tometal).value;
              CalcMtlCst = (MtlCsthold).toFixed(2);}
         if (RDwtGrmv == "G")
           {document.getElementById("CalcMPrc"+tometal).value = 
            (document.getElementById("CalcPrcG"+tometal).value*document.getElementById("Grm"+tometal).value).toFixed(2);
           MtlCsthold =
              document.getElementById("PrcGrm"+tometal).value*document.getElementById("Grm"+tometal).value;
               CalcMtlCst = (MtlCsthold).toFixed(2);}

          tcosthold[tometal] = 
             MtlCsthold +
             Number(document.getElementById("LabttlCost").value)+
             Number(document.getElementById("StnttlCost").value)+
             Number(document.getElementById("OthttlCost").value);
        document.getElementById("TCost"+tometal).value = 
             (tcosthold[tometal]).toFixed(2);         
        
        document.getElementById("TPrice"+tometal).value = 
          (Number(document.getElementById("CalcMPrc"+tometal).value)+
          Number(document.getElementById("LabttlPrice").value)+
          Number(document.getElementById("StnttlPrice").value)+
          Number(document.getElementById("OthttlPrice").value)).toFixed(2);

        if (document.getElementById("TotalCharge"+tometal).value = "0.00")
           {document.getElementById("TotalCharge"+tometal).value = 
             document.getElementById("TPrice"+tometal).value;}   

        calcProfit(tometal);}

function calcProfit(calcprmetal){
  if (document.getElementById("TotalCharge"+calcprmetal).value !=0 &&
            tcosthold[calcprmetal] !=0)
         {document.getElementById("TotalProfit"+calcprmetal).value = 
          ((document.getElementById("TotalCharge"+calcprmetal).value-
          tcosthold[calcprmetal])/ 
          tcosthold[calcprmetal] * 100).toFixed(2);}}

function calcChgbyProfit(calcmetal){
       if (tcosthold[calcmetal] !=0 && 
            document.getElementById("TotalProfit"+calcmetal).value != 0)
         {document.getElementById("TotalCharge"+calcmetal).value = 
          (tcosthold[calcmetal] *
          (1+document.getElementById("TotalProfit"+calcmetal).value / 100)).toFixed(2);}} 

//function calcProfit(calcprmetal){
//  if (document.getElementById("TotalCharge"+calcprmetal).value !=0 &&
//            document.getElementById("TCost"+calcprmetal).value !=0)
//         {document.getElementById("TotalProfit"+calcprmetal).value = 
//          ((document.getElementById("TotalCharge"+calcprmetal).value-
//          document.getElementById("TCost"+calcprmetal).value)/ 
//          document.getElementById("TCost"+calcprmetal).value * 100).toFixed(2);}}

//function calcChgbyProfit(calcmetal){
//       if (document.getElementById("TCost"+calcmetal).value !=0 && 
//            document.getElementById("TotalProfit"+calcmetal).value != 0)
//         {document.getElementById("TotalCharge"+calcmetal).value = 
//          (document.getElementById("TCost"+calcmetal).value *
//          (1+document.getElementById("TotalProfit"+calcmetal).value / 100)).toFixed(2);}} 

function updatePrcD(changedmetalD){
      document.getElementById("PrcGrm"+changedmetalD).value = 
               (document.getElementById("PrcDwt"+changedmetalD).value*.643).toFixed(4);}

function updatePrcG(changedmetalG){
     document.getElementById("PrcDwt"+changedmetalG).value = 
               (document.getElementById("PrcGrm"+changedmetalG).value/.643).toFixed(4);}	

function updateAllPrc(changedmetal){
            for(i=0;i<nummetals;i++){
//alert("in updateallprc");
              if (metals[i] != "T")
                 {
  updatePrcDwtGrm(changedmetal,metals[i],"C");
}}
          updatetotcolumn();
}

function updatetotcolumn(){
//alert ("in updateottcolumn");
             document.getElementById("CalcMPrcT").value = 0;
             document.getElementById("TCostT").value = 0;
             document.getElementById("TPriceT").value = 0;
             document.getElementById("TotalChargeT").value = 0;
             document.getElementById("TotalProfitT").value = 0;
             tcosthold["T"] = 0;
//alert("in updatetotcol  "+tcosthold["T"]);
          for(j=0;j<nummetals-1;j++){
//alert("disp="+document.getElementById("disp"+metals[j]).checked);
             if (document.getElementById("disp"+metals[j]).checked)
              {
              document.getElementById("CalcMPrcT").value = 
                (Number(document.getElementById("CalcMPrcT").value)+Number(document.getElementById("CalcMPrc"+metals[j]).value)).toFixed(2);
               document.getElementById("TCostT").value =  
                (Number(document.getElementById("TCostT").value)+Number(document.getElementById("TCost"+metals[j]).value)).toFixed(2);
              document.getElementById("TPriceT").value = 
                (Number(document.getElementById("TPriceT").value)+Number(document.getElementById("TPrice"+metals[j]).value)).toFixed(2);
              document.getElementById("TotalChargeT").value = 
                (Number(document.getElementById("TotalChargeT").value)+Number(document.getElementById("TotalCharge"+metals[j]).value)).toFixed(2);
             document.getElementById("TotalProfitT").value = 
                (Number(document.getElementById("TotalProfitT").value)+Number(document.getElementById("TotalProfit"+metals[j]).value)).toFixed(2);
             tcosthold["T"] = (Number(tcosthold["T"])+Number(tcosthold[metals[j]])).toFixed(2);
//alert(j+ " " + metals[j] + "  " + tcosthold[metals[j]] + "   " );
//alert(tcosthold["T"]);
              }}
document.getElementById("TotalProfitT").value =
((document.getElementById("TotalChargeT").value-
          tcosthold["T"])/ 
          tcosthold["T"] * 100).toFixed(2);
}
      
function updatePrcfromMarket(changedmetalP){
          document.getElementById("PrcDwt"+changedmetalP).value=holdPrcDwt(changedmetalP);
          document.getElementById("PrcGrm"+changedmetalP).value=holdPrcGrm(changedmetalP);
//alert ("in Updateprcfrommarket");
          updateAllPrc("");}

function updateAllPrcfromMarket(){
            for(j=0;j<nummetals;j++){
               updatePrcfromMarket(metals[j]);}}

function updateDwtGrm(frommetal,tometal,mode){
//alert("in updateDwtGrm  "+frommetal+"X"+tometal);
         if (tometal != frommetal && mode == "L" && document.getElementById("dispT").checked)
            {document.getElementById("Dwt"+tometal).value = 0;
             document.getElementById("Grm"+tometal).value = 0;}

         if (tometal != frommetal && (
//mode == "L"||
! document.getElementById("dispT").checked))  {
       document.getElementById("Dwt"+tometal).value =  
          (document.getElementById("Dwt"+frommetal).value/
                  document.getElementById("Viscosity"+frommetal).value*
                  document.getElementById("Viscosity"+tometal).value).toFixed(4);
	document.getElementById("Grm"+tometal).value =
          (document.getElementById("Grm"+frommetal).value/
                  document.getElementById("Viscosity"+frommetal).value*
                  document.getElementById("Viscosity"+tometal).value).toFixed(4);}}
 
                  
function updateAllWtsD(changedwtmetal,mode){
 document.getElementById("Grm"+changedwtmetal).value = 
               (document.getElementById("Dwt"+changedwtmetal).value/.643).toFixed(4);
//alert("updateallwtsd  "+changedwtmetal+" X "+mode);
      for(i=0;i<nummetals;i++){
//alert("in loop   "+i+" X  "+ metals[i]);
          if (metals[i] != "T")
               {
  updateDwtGrm(changedwtmetal,metals[i],mode);
  updatePrcDwtGrm(changedwtmetal,metals[i],mode);
                 updatetotcolumn();

}
}}

			   

function updateAllWtsG(changedwtmetal,mode){
 document.getElementById("Dwt"+changedwtmetal).value = 
               (document.getElementById("Grm"+changedwtmetal).value*.643).toFixed(4);
      for(i=0;i<nummetals;i++){
          if (metals[i] != "T")
               {updateDwtGrm(changedwtmetal,metals[i],mode);
               updatePrcDwtGrm(changedwtmetal,metals[i],mode);
               updatetotcolumn();}}}

function updateLab(){
  document.getElementById("LabttlCost").value=
    Number(document.getElementById("Labor1").value)+
    Number(document.getElementById("Labor2").value)+
    Number(document.getElementById("Labor3").value);
  document.getElementById("LabttlPrice").value=
    (document.getElementById("LabttlCost").value*
    (1.00+document.getElementById("LabMkpPct").value*.01)).toFixed(2);
  updateAllPrc("");}

function updateStnextwt(wtstonenum){
     document.getElementById("Stnextwt"+wtstonenum).value =
               (document.getElementById("Stnqty"+wtstonenum).value* 
                document.getElementById("Sinputwt"+wtstonenum).value).toFixed(4);
     updateStn(wtstonenum);
}	

function updateStn(stonenum){
     if (stonenum != "")
        {if (document.getElementById("Stoneuom"+stonenum).value == "Piece")
            {document.getElementById("Stoneextcost"+stonenum).value=
	       (document.getElementById("Stnqty"+stonenum).value *
                document.getElementById("Stone"+stonenum).value).toFixed(2);
		}
		if (document.getElementById("Stoneuom"+stonenum).value == "Carat" ||
                    document.getElementById("Stoneuom"+stonenum).value == "Momme" ||
                    document.getElementById("Stoneuom"+stonenum).value == "Kilo")
		{document.getElementById("Stoneextcost"+stonenum).value=
	         (document.getElementById("Stnextwt"+stonenum).value *
                  document.getElementById("Stone"+stonenum).value).toFixed(2);
		}
	 document.getElementById("Stoneextprice"+stonenum).value= 
         (document.getElementById("Stoneextcost"+stonenum).value* 
         (1.00+document.getElementById("StnMkpPct").value*.01)).toFixed(2);
	}
	document.getElementById("StnttlCost").value=
    Number(document.getElementById("Stoneextcost1").value)+
    Number(document.getElementById("Stoneextcost2").value)+
    Number(document.getElementById("Stoneextcost3").value);
	document.getElementById("StnttlPrice").value=
    (document.getElementById("StnttlCost").value*
    (1.00+document.getElementById("StnMkpPct").value*.01)).toFixed(2);
	updateAllPrc("");
}


function updateOth(){
  document.getElementById("OthttlCost").value=
    Number(document.getElementById("Other1").value)+
    Number(document.getElementById("Other2").value)+
    Number(document.getElementById("Other3").value);
  document.getElementById("OthttlPrice").value=
    (document.getElementById("OthttlCost").value*
    (1.00+document.getElementById("OthMkpPct").value*.01)).toFixed(2);
  updateAllPrc("");}

  

function getallcookies(){
	var rdg = document.getElementsByName("RDwtGrm");
	var rdgcookie = cookies.getCookie("RDwtGrm");
	for (var i=0;i< rdg.length;i++){
		(rdg[i].value == rdgcookie)?rdg[i].checked= true : rdg[i].checked ='';
	}
	
	toggleClassDisplay(document.getElementById('metalsTable'),'GramRow',(rdgcookie != 'Dwt')? true: false);
        toggleClassDisplay(document.getElementById('metalsTable'),'DwtRow',(rdgcookie != 'Grams')? true : false);
        RDwtGrmv = (rdgcookie == 'Dwt')? 'D': (rdgcookie == 'Grams')? 'G': 'B';
		var dispMetals = cookies.getCookieArray("dispMetals");
		var metalsFactor = cookies.getCookieArray("metalsFactor");
		var laborD = cookies.getCookieArray("laborD");
		var otherD = cookies.getCookieArray("otherD");
		document.getElementById('disp4').Checked=dispMetals[0];//cookies.getCookie("disp4");
		toggleClassDisplay(document.getElementById('metalsTable'),'14kCell',dispMetals[0] == 'true');// cookies.getCookie("disp4")=='true');
        document.getElementById('disp0').Checked=dispMetals[1];//cookies.getCookie("disp0");
        toggleClassDisplay(document.getElementById('metalsTable'),'10kCell',dispMetals[1] == 'true');// cookies.getCookie("disp0")=='true');
        document.getElementById('disp8').Checked=dispMetals[2];//cookies.getCookie("disp8");
        toggleClassDisplay(document.getElementById('metalsTable'),'18kCell',dispMetals[2] == 'true');// cookies.getCookie("disp8")=='true');
        document.getElementById('dispP').Checked=dispMetals[3];//cookies.getCookie("dispP");
        toggleClassDisplay(document.getElementById('metalsTable'),'platinumCell',dispMetals[3] == 'true');// cookies.getCookie("dispP")=='true');
        document.getElementById('dispL').Checked=dispMetals[4];//cookies.getCookie("dispL");
        toggleClassDisplay(document.getElementById('metalsTable'),'palladiumCell',dispMetals[4] == 'true');// cookies.getCookie("dispL")=='true');
        document.getElementById('dispS').Checked=dispMetals[5];//cookies.getCookie("dispS");
        toggleClassDisplay(document.getElementById('metalsTable'),'silverCell',dispMetals[5] == 'true');// cookies.getCookie("dispS")=='true');
        document.getElementById('dispT').Checked=dispMetals[6];//cookies.getCookie("dispT");
        toggleClassDisplay(document.getElementById('metalsTable'),'totalCell',dispMetals[6] == 'true');// cookies.getCookie("dispT")=='true');
   		document.getElementById('dispFactors').Checked=cookies.getCookie("dispFactors")=='true';
		toggleClassDisplay(document.getElementById('metalsTable'),'FactorRow',document.getElementById('dispFactors').Checked);
        toggleClassDisplay(document.getElementById('center'),'FactorRow',document.getElementById('dispFactors').Checked);
        document.getElementById('PctOvr').value=cookies.getCookie("PctOvr");
        document.getElementById('StnMkpPct').value=cookies.getCookie("StnMkpPct");
        document.getElementById('LabMkpPct').value=cookies.getCookie("LabMkpPct");
        document.getElementById('OthMkpPct').value=cookies.getCookie("OthMkpPct");
        document.getElementById('Factor4').value=metalsFactor[0];//cookies.getCookie("Factor4");
        document.getElementById('Factor0').value=metalsFactor[1];//cookies.getCookie("Factor0");
        document.getElementById('Factor8').value=metalsFactor[2];//cookies.getCookie("Factor8");
        document.getElementById('FactorP').value=metalsFactor[3];//cookies.getCookie("FactorP");
        document.getElementById('FactorS').value=metalsFactor[4];//cookies.getCookie("FactorS");
        document.getElementById('FactorL').value=metalsFactor[5];//cookies.getCookie("FactorL");
		document.getElementById('laborD1').value=laborD[0];
		document.getElementById('laborD2').value=laborD[1];
		document.getElementById('laborD3').value=laborD[2];
		document.getElementById('otherD1').value=otherD[0];
		document.getElementById('otherD2').value=otherD[1];
		document.getElementById('otherD3').value=otherD[2];
        document.getElementById('Dwtozcnv').value=cookies.getCookie("Dwtozcnv");
        document.getElementById('Grmozcnv').value=cookies.getCookie("Grmozcnv");
        document.getElementById('Viscosity4').value=cookies.getCookie("Viscosity4");
        document.getElementById('Viscosity0').value=cookies.getCookie("Viscosity0");
        document.getElementById('Viscosity8').value=cookies.getCookie("Viscosity8");
        document.getElementById('ViscosityP').value=cookies.getCookie("ViscosityP");
        document.getElementById('ViscosityS').value=cookies.getCookie("ViscosityS");
        document.getElementById('ViscosityL').value=cookies.getCookie("ViscosityL");
        //toggleClassDisplay(document.getElementById('metalsTable'),'FactorRow',false);
        //toggleClassDisplay(document.getElementById('center'),'FactorRow',false);
       }
	   
	function setallcookies(){
		var rdg = document.getElementsByName("RDwtGrm");
		for (var i=0;i< rdg.length;i++){
			if (rdg[i].checked) cookies.setCookie("RDwtGrm",rdg[i].value,365);
		}
		
        var dispMetals = new Array();
		var metalsFactor = new Array();
		var laborD = new Array(); 
		var otherD = new Array();
		dispMetals[0] =document.getElementById('disp4').checked;
		dispMetals[1] =document.getElementById('disp0').checked;
		dispMetals[2] =document.getElementById('disp8').checked;
		dispMetals[3] =document.getElementById('dispP').checked;
		dispMetals[4] =document.getElementById('dispL').checked;
		dispMetals[5] =document.getElementById('dispS').checked;
                dispMetals[6] =document.getElementById('dispT').checked; 
		cookies.setCookie("dispMetals",dispMetals.join(),365);
		cookies.setCookie("dispFactors",document.getElementById("dispFactors").checked,365);
        cookies.setCookie("PctOvr",document.getElementById('PctOvr').value,365);
        cookies.setCookie("StnMkpPct",document.getElementById('StnMkpPct').value,365);
        cookies.setCookie("LabMkpPct",document.getElementById('LabMkpPct').value,365);
        cookies.setCookie("OthMkpPct",document.getElementById('OthMkpPct').value,365);
        metalsFactor[0]=document.getElementById('Factor4').value;
        metalsFactor[1]=document.getElementById('Factor0').value;
        metalsFactor[2]=document.getElementById('Factor8').value;
        metalsFactor[3]=document.getElementById('FactorP').value;
        metalsFactor[4]=document.getElementById('FactorS').value;
        metalsFactor[5]=document.getElementById('FactorL').value;
       		cookies.setCookie("metalsFactor",metalsFactor.join(),365);
		laborD[0]=document.getElementById('laborD1').value;
		laborD[1]=document.getElementById('laborD2').value;
		laborD[2]=document.getElementById('laborD3').value;
		cookies.setCookie("laborD",laborD.join(),365);
		otherD[0]=document.getElementById('otherD1').value;
		otherD[1]=document.getElementById('otherD2').value;
		otherD[2]=document.getElementById('otherD3').value;
		cookies.setCookie("otherD",otherD.join(),365);
        cookies.setCookie("Dwtozcnv",document.getElementById('Dwtozcnv').value,365);
        cookies.setCookie("Grmozcnv",document.getElementById('Grmozcnv').value,365);
        cookies.setCookie("Viscosity4",document.getElementById('Viscosity4').value,365);
        cookies.setCookie("Viscosity0",document.getElementById('Viscosity0').value,365);
        cookies.setCookie("Viscosity8",document.getElementById('Viscosity8').value,365);
        cookies.setCookie("ViscosityP",document.getElementById('ViscosityP').value,365);
        cookies.setCookie("ViscosityS",document.getElementById('ViscosityS').value,365);
        cookies.setCookie("ViscosityL",document.getElementById('ViscosityL').value,365);
    }
 addEvent(window,"load",function(e){setallcookies();getallcookies();});
 addEvent(window,"load",function(e){updateAllWtsD("4","L");}); 
 addEvent(window,"load",function(e){updateAllPrcfromMarket();}); 
 addEvent(window,"load",function(e){initStones();setStoneDefault("1");setStoneDefault("2");setStoneDefault("3");});                                         
 