function Units(code, name)
{
	this.code = code;
	this.name = name;
}

function FatAcid(name, description)
{
	this.name = name;
	this.description = description;
	this.value= NaN;
	this.unit = "en%";
	this.units = new Array();
	this.units[0] = new Units("en%","% of energy");
	this.units[1] = new Units("gpd","gram per day");
	this.units[2] = new Units("gp100g","% fatty acids");
}

function LongAcid(name, description)
{
	this.name = name;
	this.description = description;
	this.value= NaN;
	this.unit = "en%";
	this.units = new Array();
	//this.units[0] = new Units("en%","% of energy");
	this.units[0] = new Units("mgpd","mgram per day");
	//this.units[2] = new Units("gp100g","% fatty acids");
}
 

function TotalFat(name, description)
{
	this.name = name;
	this.description = description;
	this.value= NaN;
	this.unit = "en%";
	this.units = new Array();
	this.units[0] = new Units("en%","% of energy");
	this.units[1] = new Units("gpd","gram per day");
}              

function Cholesterol(name, description)
{
	this.name = name;
	this.description = description;
	this.value= NaN;
	this.unit = "mgpd";
	this.units = new Array();
//	this.units[0] = new Units("mgpkc","mg per 1000 kcal");
//	this.units[1] = new Units("mgpmj","mg per MJ");
//	this.units[2] = new Units("mgpkj","mg per kJ");
	this.units[0] = new Units("mgpd","mgram per day");
	
}

function Protein(name, description)
{
	this.name = name;
	this.description = description;
	this.value= NaN;
	this.unit = "en%";
	this.units = new Array();
	this.units[0] = new Units("en%","% of energy");
	this.units[1] = new Units("gpd","gram per day");
}              

function TotalEnergy(name, description)
{
	this.name = name;
	this.description = description;
	this.value= NaN;
	this.unit = "calpd";
	this.units = new Array();
	this.units[0] = new Units("calpd","kcal per day");
	this.units[1] = new Units("mjpd","MJ per day");
	this.units[2] = new Units("kjpd","kJ per day");
}

function TotalEnergyOther(name, description)
{
	this.name = name;
	this.description = description;
	this.value= NaN;
	this.unit = "gpd";
	this.units = new Array();
	this.units[0] = new Units("gpd","gram per Day");
}
                                
function diet(name)
/*Please note: variable names in coeff, results and diets should be the same!*/
{
	//this.name =  name;
	/*Define acids */
	
	this.SatFatAcid = new Array();
	this.SatFatAcid.satfatacid = new FatAcid("satfatacid", "Saturated fatty acids");
	
	this.IndAcid = new Array();
	this.IndAcid.C8 = new FatAcid("C8","C8 (medium chain)");
	this.IndAcid.C10 = new FatAcid("C10", "C10 (medium chain)");
	this.IndAcid.C12 = new FatAcid("C12", "C12 (lauric acid)");
	this.IndAcid.C14 = new FatAcid("C14", "C14 (myristic acid)");
	this.IndAcid.C16 = new FatAcid("C16", "C16 (palmitic acid)");
	this.IndAcid.C18 = new FatAcid("C18", "C18 (stearic acid)");
	//this.IndAcid[6] = new FatAcid("other", "other saturates");
	
	this.Acid = new Array();
	this.Acid.mono = new FatAcid("mono", "Cis-monounsaturated fatty acids");
	this.Acid.poly = new FatAcid("poly", "Cis-polyunsaturated fatty acids");
	this.Acid.trans = new FatAcid("trans", "Trans fatty acids");
	
	this.LongAcid = new Array();
	this.LongAcid.fish = new LongAcid("fish", "C20:5n-3 (EPA) + C22:5n-3 (DPA)<br> + C22:6n-3 (DHA)");
	
	this.cholesterol = new Array();
	this.cholesterol.Cholesterol = new Cholesterol("Cholesterol","Cholesterol intake");
	
	this.protein = new Array();
	this.protein.dietprotein = new Protein("dietprotein","Dietary protein");
	
	this.totalfat = new Array();
	this.totalfat.totalfat = new TotalFat("totalfat","Total fat");
	
	this.totalenergy1 = new Array();
	this.totalenergy1.TotalEnergy = new TotalEnergy("TotalEnergy","Total energy intake");
	
	this.totalenergy2 = new Array();
	this.totalenergy2.TotalFat =new TotalEnergyOther("TotalFat"," Total fat intake");  
	this.totalenergy2.Protein =new TotalEnergyOther("Protein"," Protein");
	this.totalenergy2.TotalCarb =new TotalEnergyOther("TotalCarb"," Total carbohydrates");
	this.totalenergy2.Alcohol =new TotalEnergyOther("Alcohol"," Alcohol");

}


/* Here are some initial diets */                         
initdiet = new diet("Initdiet");


var diets = new Array();
diets[0] = new diet();
diets[1] = new diet();
diets[2] = new diet();
//diets[3] = new diet();
//diets[4] = new diet();

/*
diets[0].54lowsat.satfatacid.value = 7.0;
diets[0].54lowsat.mono.value = 13.0;
diets[0].54lowsat.poly.value = 8.0;
diets[0].54lowsat.trans.value = 0.0;
diets[0].54lowsat.dietprotein.value = 16.0;
diets[0].54lowsat.Cholesterol.value = 270;


diets[1].39lowsat.satfatacid.value = 8.0;
diets[1].39lowsat.mono.value = 13.0;
diets[1].39lowsat.poly.value = 8.0;
diets[1].39lowsat.trans.value = 0.0;
diets[1].39lowsat.dietprotein.value = 29.0;
diets[1].39lowsat.Cholesterol.value = 270;
*/

function person(name)
{
	this.name = name;
	this.levels = new Array();
	this.lipids = new Array();
	this.ratio = new Array();
	this.apoproteins = new Array();
}


var persons = new Array();
persons[0] = new person("Custom");
persons[0].lipids = {TotChol:""	,LDL:""	,HDL:""	,Trig:""};
persons[0].ratio = {Ratio:""};
persons[0].apoproteins = {ApoA:""	,ApoB:""};


persons[1] = new person("Av. Am.");
persons[1].lipids = {TotChol:202	,LDL:131	,HDL:52	,Trig:85};
persons[1].ratio = {Ratio:"4.07"};
persons[1].apoproteins = {ApoA:117	,ApoB:142};



function lipid(name)
{
	this.name = name;
	this.value = 0;
	this.level = 0;
	this.unit = 'mmolpl';
	this.result = NaN;
	this.units = new Array();
	this.units[0] = new Units("mgpdl","mg/dL");
	this.units[1] = new Units("mmolpl","mmol/L");
}

function apoprotein(name)
{
	this.name = name;
	this.value = 0;
	this.level = 0;
	this.unit = 'mmolpl';
	this.result = NaN;
	this.units = new Array();
	this.units[0] = new Units("mgpl","mg/L");
	this.units[1] = new Units("mgpdl","mg/dL");
}

var results = new Array()
/*Please note: variable names in coeff, results and diets should be the same!*/
results['lipids'] 				= new Array();
results['lipids']['TotChol'] 	= new lipid("Total cholesterol");
results['lipids']['LDL']		= new lipid("LDL cholesterol");	
results['lipids']['HDL']		= new lipid("HDL cholesterol");	
results['lipids']['Trig']		= new lipid("Triglycerides");
results['ratio'] 				= new Array();
results['ratio']['Ratio']		= new lipid("total/HDL chol. ratio");
results['apoproteins']			= new Array();
results['apoproteins']['ApoA']	= new apoprotein("apoprotein A-I concent.");
results['apoproteins']['ApoB']	= new apoprotein("apoprotein B concent.");

function constant(name,value)
{
	this.name = name;
	this.value = value;
}




var constants = new Array();
constants['AtwaterFat'] 	= 9;
constants['AtwaterProt'] 	= 4;
constants['AtwaterCarb']	= 4;
constants['AtwaterAlc']		= 7;
constants['KcalKJ']			= 4.184;
constants['MolwtChol']		= 386.7;
constants['MolwtTrig']		= 885.7;


var coeff = new Array();
/*Please note: variable names in coeff, results and diets should be the same!*/
coeff.TotChol={satfatacid:0.036 	,C8:0	,C10:0	,C12:0.069	,C14:0.059	,C16:0.041 ,C18:-0.01	,mono:-0.006 	,poly:-0.021 	,fish:0.000041 ,trans:0.034 	,Cholesterol:0.056 		,dietprotein:-0.024};
coeff.LDL	= {satfatacid:0.032 	,C8:0	,C10:0	,C12:0.052	,C14:0.048	,C16:0.039 ,C18:-0.004	,mono:-0.009 	,poly:-0.019 	,fish:0.000060 ,trans:0.041 	,Cholesterol:0.050 		,dietprotein:-0.013};
coeff.HDL	= {satfatacid:0.010 	,C8:0	,C10:0	,C12:0.027	,C14:0.018	,C16:0.010 ,C18:0.002	,mono:0.008		,poly:0.006 	,fish:0.00002 	,trans:-0.001 	,Cholesterol:0.008		,dietprotein:0.000};
coeff.Trig	= {satfatacid:-0.021	,C8:0	,C10:0	,C12:-0.019	,C14:-0.017	,C16:-0.017,C18:-0.017	,mono:-0.019		,poly:-0.026	,fish:-0.000109,trans:0.000 	,Cholesterol:0			,dietprotein:-0.026};
coeff.Ratio	= {satfatacid:0.003		,C8:0	,C10:0	,C12:-0.037	,C14:-0.003	,C16:0.005 ,C18:-0.013	,mono:-0.026		,poly:-0.032	,fish:0		,trans:0.025	,Cholesterol:0.020		,dietprotein:0};
coeff.ApoA	= {satfatacid:5.7		,C8:0	,C10:0	,C12:13.8	,C14:10.4	,C16:7.5   ,C18:-1.6	,mono:5.2		,poly:2.2		,fish:0		,trans:0.7		,Cholesterol:0			,dietprotein:0};
coeff.ApoB	= {satfatacid:2.6		,C8:0	,C10:0	,C12:5.6	,C14:1.9	,C16:4.2   ,C18:-3.8	,mono:-4.8		,poly:-7.7		,fish:0		,trans:6.9		,Cholesterol:0			,dietprotein:0};

var tabindex = 0;

