
	var buffyOut = "";
	var m = new member();
	var productList = createProducts();	
	var chronicList = createChronics();
	var chronicExpensesList = createChronicExpenses();
	var expensesList = createExpenses();
	var valid = 0;

	

	function member() {
		this.name = "";
		this.email = "";
		this.age = 0;
		this.spouse_age = 0;
		this.adult_dependants = new Array();
		this.child_dependants = new Array();
		this.selection = null;
		this.chronic = null;
		this.chronic_expenses = "";
		this.expenses = "";
		this.oheb = 0;
		this.dgmc =0;	
	}
	
	function product(name, member, adult, child, oheb, safety, clf, clp, d2d, file) {
		this.name = name;
		this.member_rate = member;
		this.adult_dependant_rate  = adult;
		this.child_dependant_rate  = child;
		this.oheb = oheb;
		this.safety_net = safety;
		this.chronic_limit_family = clf;
		this.chronic_limit_person = clp;
		this.d2d = d2d;
		this.pdf = file;
	}

	function chronic(name, exception, min_benefit) {
		this.name = name;
		this.exception = exception;
		this.min_benefit = min_benefit;
	}

	function chronicExpense(value) {
		this.value = value;
	}

	function expense(value) {
		this.value = value;
	}

	function day2day(member, adult, child, oheb) {
		this.dd_member = member;
		this.dd_adult = adult;
		this.dd_child = child;
		this.dd_oheb = oheb; //0 for non OHEB || 1 for OHEB
	}
	
	// rates for 2008
	// values products.push(
	//new product(
	//"product name", 
	//contributions principal, dependant, child, 
	//new Array(OHEB principal, dependant, child), 
	//new Array(savety net principal, dependant, child), 
	//chronic limit family, person,
	//new day2day(principal, dependant, child, 0), //the day2day depenant value for the ultima products should exclude the oheb value since it will be added later
	//"link to product page"));
	function createProducts() {
		var products = new Array();
		products.push(new product("Maxima Plus", 3188, 2710, 956, new Array(5950, 4300, 1330), new Array(8900, 6750, 2350), 18280, 9775, new day2day(8830, 6748, 2194, 0), "nm_fullplans_maxima_plus.asp"));
		products.push(new product("Maxima Exec", 3188, 2710, 956, new Array(5950, 4300, 1330), new Array(8900, 6750, 2350), 18280, 9775, new day2day(8830, 6748, 2194, 0), "nm_fullplans_maxima_plus.asp"));
		products.push(new product("Maxima Standard", 1632, 1388, 490, new Array(3070, 2220, 300), new Array(7720, 5900, 2050), 7300, 3650, new day2day(4858, 3744, 840, 0), "nm_fullplans_maxima_standard.asp"));
		products.push(new product("Maxima Basis", 1316, 1118, 395, new Array(2160, 1620, 220), new Array(7720, 5900, 2050), 4828, 2415, new day2day(2160, 1620, 220, 0), "nm_fullplans_maxima_basis.asp"));
		products.push(new product("Maxima Core", 1029, 876, 360, new Array(), new Array(7720, 5900, 2050), 2415, 1207, new day2day(180, 156, 60, 0), "nm_fullplans_maxima_core.asp"));
		products.push(new product("Maxima Entry Zone", 1029, 876, 360, new Array(), new Array(7720, 5900, 2050), 2415, 1207, new day2day(180, 156, 60, 0), "nm_fullplans_maxima_core.asp"));
		products.push(new product("Ultimax", 4334, 3683, 1300, new Array(1900, 1060), new Array(9070, 6800, 2270), 30400, 18280, new day2day(5404, 2976, 1044, 1), "profile_ultimax.asp"));
		products.push(new product("Ultima 300", 3006, 2555, 902, new Array(1840, 1020), new Array(8700, 6150, 2000), 10920, 6095, new day2day(4000, 1836, 648, 1), "nm_fullplans_ultima300.asp"));		
		products.push(new product("Ultima 200", 1375, 1170, 412, new Array(), new Array(), 5460, 3040, new day2day(252, 204, 84, 0), "nm_fullplans_ultima200.asp"));
		buffyOut = buffyOut + "Products loaded("+products.length+") ";
		return products;		
	}

	function createChronics() {
		var c = new Array();
		c.push(new chronic("Addison's Disease", 0, 1));
		c.push(new chronic("Alzheimer's Disease", 1, 0));
		c.push(new chronic("Angina", 0, 1));
		c.push(new chronic("Ankylosing Spondylitis", 0, 0));
		c.push(new chronic("Anorexia Nervosa", 0, 0));
		c.push(new chronic("Asthma", 0, 1));
		c.push(new chronic("Attention Deficit Disorder", 0, 0));
		c.push(new chronic("Barrett's Oesophagus", 0, 0));
		c.push(new chronic("Benign Prostatic Hyperplasia", 1, 0));
		c.push(new chronic("Bipolar Mood Disorder", 0, 0));
		c.push(new chronic("Brochiectasis", 0, 1));
		c.push(new chronic("Bulimia Nervosa", 0, 0));
		c.push(new chronic("Cardiac Arrhythmias", 0, 1));
		c.push(new chronic("Cardiomyopathy", 0, 1));
		c.push(new chronic("Chronic Bronchitis", 0, 1));
		c.push(new chronic("Chronic Obstructive Pulmonary Disease", 0, 1));
		c.push(new chronic("Chronic Renal Failure", 0, 1));
		c.push(new chronic("Congestive Cardiac Failure", 0, 1));
		c.push(new chronic("Conn's Syndrome", 0, 0));
		c.push(new chronic("Coronary Artery Disease", 0, 1));
		c.push(new chronic("Crohn's Disease", 0, 1));
		c.push(new chronic("Cushing's Syndrome", 0, 0));
		c.push(new chronic("Cystic Fibrosis", 1, 0));
		c.push(new chronic("Deep Vein Thrombrosis", 0, 0));
		c.push(new chronic("Depression", 0, 0));
		c.push(new chronic("Dermatomyositis", 0, 0));
		c.push(new chronic("Diabetes Insipidus", 0, 1));
		c.push(new chronic("Diabetes Mellitus type 1 & 2", 0, 1));
		c.push(new chronic("Emphysema", 0, 1));
		c.push(new chronic("Epilepsy", 0, 1));
		c.push(new chronic("Gastro-Oesophageal Reflux Disease", 0, 0));
		c.push(new chronic("Generalised Anxiety Disorder", 0, 0));
		c.push(new chronic("Glaucoma", 0, 1));
		c.push(new chronic("Gout", 1, 0));
		c.push(new chronic("Haemophilia", 0, 1));
		c.push(new chronic("Hypercholesterolaemia with risk factors", 0, 1));
		c.push(new chronic("Hypertension", 0, 1));
		c.push(new chronic("Hypoparathyroidism", 1, 0));
		c.push(new chronic("Hypothyroidism", 0, 1));
		c.push(new chronic("Ischaemic Heart Disease", 0, 1));
		c.push(new chronic("Menopuase", 1, 0));
		c.push(new chronic("Motor Neuron Disease", 1, 0));
		c.push(new chronic("Multiple Sclerosis", 0, 1));
		c.push(new chronic("Muscular Dystrophy", 1, 0));
		c.push(new chronic("Myasthenia Gravis", 1, 0));
		c.push(new chronic("Narcolepsy", 0, 0));
		c.push(new chronic("Obsessive Compulsive Disorder", 0, 0));
		c.push(new chronic("Osteoporosis", 1, 0));
		c.push(new chronic("Paget's Disease of the Bone", 1, 0));
		c.push(new chronic("Pancreatic Disease", 1, 0));
		c.push(new chronic("Panic Disorder", 0, 0));
		c.push(new chronic("Paraplegia/ Quadriplegia (associated medicine)", 0, 0));
		c.push(new chronic("Parkinson's Disease", 0, 1));
		c.push(new chronic("Pemphigus", 1, 0));
		c.push(new chronic("Polyarteritis Nodosa", 0, 0));
		c.push(new chronic("Post-Traumatic Stress Syndrome", 0, 0));
		c.push(new chronic("Pulmonary Interstital Fibrosis", 0, 1));
		c.push(new chronic("Rheumatoid Arthritis", 0, 1));
		c.push(new chronic("Schizophrenia", 0, 1));
		c.push(new chronic("Scleroderma", 0, 0));
		c.push(new chronic("Stroke", 1, 0));
		c.push(new chronic("Systemic Lupus Erythematosus", 0, 1));
		c.push(new chronic("Thromboangitis Obliterans", 0, 0));
		c.push(new chronic("Thrombocytopaenic Purpura", 0, 0));
		c.push(new chronic("Tourette's Syndrome", 0, 0));
		c.push(new chronic("Ulcerative Colitis", 0, 1));
		c.push(new chronic("Unipolar Mood Disorder", 0, 0));
		c.push(new chronic("Valvular Heart Disease", 0, 0));
		c.push(new chronic("Zollinger-Ellison Syndrome", 0, 0));
		buffyOut = buffyOut + "Chronic conditions loaded("+c.length+") ";
		return c;
	}

	function createChronicExpenses() {
		var ce = new Array();
		ce.push(new chronicExpense("< R200 pm"));
		ce.push(new chronicExpense("R200 - R400 pm"));
		ce.push(new chronicExpense("R400 - R800 pm"));
		ce.push(new chronicExpense("R800 - R2200 pm"));
		buffyOut = buffyOut + "Chronic expenses loaded("+ce.length+") ";
		return ce;
	}

	function createExpenses() {
		var e = new Array();
		e.push(new expense("< R500 pm"));
		e.push(new expense("R500 - R800 pm"));
		e.push(new expense("R800 - R1300 pm"));
		e.push(new expense("> R1300pm"));
		buffyOut = buffyOut + "Expenses loaded("+e.length+") ";
		return e;
	}

	function setSpouse(form) {
		if (form.spouse_age.value != "" && isFinite(form.spouse_age.value)) {
			m.spouse_age = form.spouse_age.value;
			valid = 1;
		}
		else {
			valid = 0;
			alert("Please enter your partner's age.");
		}
		refreshDetails();
	}
	
	function setSelection(form) {
		valid = 0;
		m.selection = new Array();
		for (var i =0; i < form.product.length; i++) {
			if (form.product[i].checked) {
				var s = m.selection.push(i);
				valid = 1;
			}
		}
		if(valid == 0){alert("Please select at least one product.");}
		refreshDetails();
	}

	function setChronic(form) {
		m.chronic = new Array();
		for (var i =0; i < form.chronic.length; i++) {
			if (form.chronic[i].checked) {var s = m.chronic.push(i);}
		}
		for (var i =0; i < form.chronicExpenses.length; i++) {
			if (form.chronicExpenses[i].selected) {m.chronic_expenses = form.chronicExpenses[i].value;}
		}
		checkUltima();
		refreshDetails();
	}

	function setExpenses(form) {
		for (var i =0; i < form.expenses.length; i++) {
			if (form.expenses[i].selected) {m.expenses = form.expenses[i].value;}
		}
		if (form.dgmc != null && form.dgmc.checked) {m.dgmc = form.dgmc.value;}
		if (form.oheb != null && form.oheb.checked) {m.oheb = form.oheb.value;}
		refreshDetails();
	}	
	
	function setDetails(form) {
		var errorString = "";
		if (form.name.value != "" && form.email.value != "" && form.age.value != "" && isFinite(form.age.value)){
			valid = 1;
		} else {valid = 0;}
		if (form.name.value != "") {
			m.name = form.name.value;
		}
		else { 
			errorString += "Please enter your name.\n";
		}
		if (form.email.value != "") {
			m.email = form.email.value;
		}
		else {
			errorString += "Please enter your email address.\n";
		}
		if (form.age.value != "" && isFinite(form.age.value)) {
			m.age = form.age.value;
		}
		else {
			errorString += "Please enter your age.\n";
		}
		if(valid == 0 ){alert(errorString);}
		else{refreshDetails();}
	}
	
	function addDependant(age){
		var d
		if (age != 0 && isFinite(age)) {
			if (age >= 27) {
				d = m.adult_dependants.push(age);
			}
			else {
				d = m.child_dependants.push(age);
			}
			valid = 1;
		}
		else {
			alert("Please enter an age.");
		}
		refreshDetails();
	}

	function countSelection(form) {
		var checkedItems = new Array();
		for(var i=0; i<form.product.length; i++) {
			if (form.product[i].checked) {checkedItems.push(i);}
		}
		if (checkedItems.length >= 4) {
			for(var i=0; i<form.product.length; i++) {
				if (!form.product[i].checked) {form.product[i].disabled = true;}
			}
		}
		else {
			for(var i=0; i<form.product.length; i++) {
				form.product[i].disabled = false;
			}
		}
	}

	function checkUltima() { //check if any ultima product would be part of the suggestion
		var ultima = "";
		var temp_suggestion = getSuggestion();
		for (var i=0; i<temp_suggestion.length;i++) {
			if(temp_suggestion[i] == 6 || temp_suggestion[i] == 10){
				show("ultima_questions");
				break;
			}
		}
		//output("ultima_questions", ultima);
	}

	function getSuggestion() {		
		var pMaxPlus = 0;
		var pMaxStd = 1;
		var pMaxBasis = 2;
		var pMaxCore = 3;
		var pUltimax = 4;
		var pUltima200 = 7;
		var pUltima300 = 5;
		
		if(m.oheb == 1) {
			pUltima200 = 6;
			pUltima300 = 5;
		}

		var ultima_con = 0;
		var suggestion = null;
		if (m.chronic != null) {
			for (var i=0; i<m.chronic.length; i++){
				//alert(chronicList[m.chronic[i]].name);
				if (chronicList[m.chronic[i]].exception == 1) {
					ultima_con = 1;
					break;
				}
			}
		}
		switch (m.chronic_expenses) {
			case "": //no chronic cover needed
				//if (m.age < 46) {suggestion = new Array(pMaxCore,pMaxBasis,pMaxStd,pMaxPlus);}
				if (m.age < 46) {suggestion = new Array(pMaxStd,pMaxCore,pMaxBasis,pMaxPlus);}
				else {suggestion = new Array(pUltima200,pUltima300,pUltimax);}
				break;
			case "0": //chronic cover under 200
				if (ultima_con==1){suggestion = new Array(pUltima200,pUltima300,pUltimax);}
				if (ultima_con==0){
					if (m.age < 46) {
						suggestion = new Array(pMaxCore,pMaxBasis,pMaxStd,pMaxPlus);
					}
					else {
						suggestion = new Array(pUltima200,pUltima300,pUltimax);
					}
				}
				break;
			case "1": //chronic cover 200-400
				if (ultima_con==1){suggestion = new Array(pUltima200,pUltima300,pUltimax);}
				if (ultima_con==0){
					if (m.age < 46) {
						suggestion = new Array(pMaxBasis,pUltima200,pMaxCore,pMaxStd);
					}
					else {
						suggestion = new Array(pUltima200,pUltima300,pUltimax);
					}
				}
				break;
			case "2": //chronic cover 400-800
				if (ultima_con==1){suggestion = new Array(pUltima300,pUltima200,pUltimax);}
				if (ultima_con==0){
					if (m.age < 46) {
						suggestion = new Array(pMaxBasis,pUltima200,pMaxCore,pMaxStd);
					}
					else {
						suggestion = new Array(pUltima300,pUltima200,pUltimax);
					}
				}
				break;
			case "3": //chronic cover 800-2200
				if (ultima_con==1){suggestion = new Array(pUltimax,pUltima300,pUltima200);}
				if (ultima_con==0){
					if (m.age < 46) {
						suggestion = new Array(pMaxPlus,pUltimax,pUltima300,pUltima200);
					}
					else {
						suggestion = new Array(pUltimax,pUltima300,pUltima200);
					}
				}
				break;
			default: //
				suggestion = new Array();
				break;
		}
		
		var doChange = 1;
		switch (m.expenses ) { //check for expenses
			case "0": // <500
				for (var i=0; i<suggestion.length; i++) {
					if(suggestion[i] == pMaxBasis) {
						doChange = 0;
						break;
					}
				}	
				if(doChange == 1) {if(suggestion.length < 4){suggestion.push(pMaxBasis);}}
				break;
			case "1": // 500-800
				for (var i=0; i<suggestion.length; i++) {
					if(suggestion[i] == pUltimax) {
						doChange = 0;
						break;
					}
				}
				if(doChange == 1) {if(suggestion.length < 4){suggestion.push(pUltimax);}}
				doChange = 1
				for (var i=0; i<suggestion.length; i++) {
					if(suggestion[i] == pUltima300) {
						doChange = 0;
						break;
					}
				}
				if(doChange == 1) {if(suggestion.length < 4){suggestion.push(pUltima300);}}
				break;	
			case "2": // 800-1300
				//alert(m.expenses + "reset primary");
				suggestion = resetPrimary(suggestion, pMaxStd);
				for (var i=0; i<suggestion.length; i++) {
					if(suggestion[i] == pUltima300) {
						doChange = 0;
						break;
					}
				}	
				if(doChange == 1) {if(suggestion.length < 4){suggestion.push(pUltima300);}}
				break;
			case "3": // >1300
				suggestion = resetPrimary(suggestion, pMaxPlus);
				break;
			default:
		}
		//alert(productList[suggestion[0]].name);
		return suggestion;
	}

	function resetPrimary(sgstn, primarySgstn) {
		var pMaxPlus = 0;
		var pMaxStd = 1;
		var pMaxBasis = 2;
		var pMaxCore = 3;
		var newSgstn = new Array();
		var buffySgstn = "";
		var doChange = 1;
		//if (sgstn[0] == pMaxBasis || sgstn[0] == pMaxCore) {
		if (sgstn[0] == pMaxBasis || sgstn[0] == pMaxStd) {
			newSgstn.push(primarySgstn);
			for (var i=0; i<sgstn.length; i++) {
				if (sgstn[i] == pMaxPlus || sgstn[i] == pMaxStd || sgstn[i] == pMaxBasis || sgstn[i] == pMaxCore) {
					if(sgstn[i] != primarySgstn) {newSgstn.push(sgstn[i]);}
				}
				else {buffySgstn = sgstn[i];}
			}
			if(newSgstn.length < 4) {newSgstn.push(buffySgstn);}
		}
		else {
			newSgstn = sgstn;
			if(newSgstn.length < 4) {
				for (var i=0; i<newSgstn.length; i++) {
					if(newSgstn[i] == primarySgstn){
						doChange = 0;
						break
					}
				}
				if(doChange == 1) {newSgstn.push(primarySgstn);}
			}
		}
		return newSgstn;
	}
	
	function getOheb(choice) {
		var ohebBenefits = new Array();
		for (var i=0; i<choice.length; i++) {
			if(productList[choice[i]].oheb.length == 0) {
				// no oheb
				ohebBenefits.push("n/a");				
			}
			if(productList[choice[i]].oheb.length == 2) {
				// oheb with simple dependent benefits
				var sb = productList[choice[i]].oheb[0];
				if(m.spouse_age != 0 || m.adult_dependants.length != 0 || m.child_dependants.length != 0) { 
					sb += productList[choice[i]].oheb[1];
				}
				ohebBenefits.push(sb);
			}
			if(productList[choice[i]].oheb.length == 3) {
				// oheb with benefits per dependent
				var db = productList[choice[i]].oheb[0];
				if(m.spouse_age != 0) {
					db += productList[choice[i]].oheb[1];
				} 
				db += (productList[choice[i]].oheb[1]*m.adult_dependants.length) + (productList[choice[i]].oheb[2]*m.child_dependants.length);
				ohebBenefits.push(db);
			}
		}
		output("display", "Calculated benefits: "+ohebBenefits.length);
		return ohebBenefits;
	}

	function getSafetyNet(choice) {
		var s_net = new Array();
		var child_multiply = 0;
		for(var i=0; i<choice.length; i++) {
			if(productList[choice[i]].safety_net.length == 0) {
				s_net.push("n/a");
			}
			if(productList[choice[i]].safety_net.length == 3) {
				var sn = productList[choice[i]].safety_net[0];
				if (m.spouse_age != 0) {
					sn += productList[choice[i]].safety_net[1];
				}
				sn += productList[choice[i]].safety_net[1]*m.adult_dependants.length;
				if (m.child_dependants.length > 3) {child_multiply =3;}
				else {child_multiply = m.child_dependants.length;}
				sn += productList[choice[i]].safety_net[2]*child_multiply;
				s_net.push(sn);
			}
		}
		output("display", "Calculated safety net: "+s_net.length);
		return s_net;
	}

	function getDay2Day(choice) {
		var d2d = new Array();
		for(var i=0; i<choice.length; i++) {
			var dd = productList[choice[i]].d2d.dd_member;
			if (m.spouse_age != 0) {
				dd += productList[choice[i]].d2d.dd_adult;
			}
			dd += (productList[choice[i]].d2d.dd_adult*m.adult_dependants.length) + (productList[choice[i]].d2d.dd_child*m.child_dependants.length);
			
			if(productList[choice[i]].d2d.dd_oheb == 1 && (m.adult_dependants.length > 0 || m.child_dependants.length > 0 || m.spouse_age != 0)) {
				dd += productList[choice[i]].oheb[1];
			} //adds one dependant oheb
			//alert(dd);
			d2d.push(dd);
		}
		return d2d;
	}
		
	function showQuote() {
		var choice = null;
		var total = new Array(0,0,0,0);
		if (m.selection != null && m.selection.length >= 1) {
			choice = m.selection;
		}
		else {
			choice = getSuggestion();
		}
		var oheb_benefits = getOheb(choice);
		var safety_net = getSafetyNet(choice);
		var day_2_day = getDay2Day(choice);
		var aBuffy = null;
		var cBuffy = null;
		for (var i=0; i<4; i++) {
			aBuffy = "";
			cBuffy = "";
			if (choice.length >= i+1) {
				output("quote_"+(i+1), productList[choice[i]].name);
				output("member_rate_"+(i+1),"R" +productList[choice[i]].member_rate);
				total[i] += productList[choice[i]].member_rate;
				if(m.spouse_age != 0){
					output("spouse_rate_"+(i+1),"R" +productList[choice[i]].adult_dependant_rate);
					total[i] += productList[choice[i]].adult_dependant_rate;
				}
				else {
					output("spouse_rate_"+(i+1),"n/a");
				}
				if (m.adult_dependants.length != 0) {
					for (var j=0; j<m.adult_dependants.length; j++) {
						aBuffy = aBuffy + "1xAdult ("+m.adult_dependants[j] + "yrs) R" +productList[choice[i]].adult_dependant_rate+"<br>";					
						total[i] += productList[choice[i]].adult_dependant_rate;
					}
					output("adult_rate_"+(i+1), aBuffy);
				}
				else {output("adult_rate_"+(i+1), "n/a");}
				if (m.child_dependants.length != 0) {
					for (var j=0; j<m.child_dependants.length; j++) {
						cBuffy = cBuffy + "1xChild ("+m.child_dependants[j] + "yrs) R" +productList[choice[i]].child_dependant_rate+"<br>";					
						total[i] += productList[choice[i]].child_dependant_rate;
					}
					output("child_rate_"+(i+1), cBuffy);
				}
				else {output("child_rate_"+(i+1), "n/a");}
			}
			else {
				output("quote_"+(i+1), "");
				output("member_rate_"+(i+1),"");
				output("spouse_rate_"+(i+1),"");
				output("adult_rate_"+(i+1), "");
				output("child_rate_"+(i+1), "");
			}
		}
		for (var i=0; i<4; i++) {
			if (choice.length >= i+1) {
				if (total[i] != 0) {output("total_"+(i+1), "R" +total[i]);}
				else {output("total_"+(i+1), "");}
				if(isFinite(oheb_benefits[i])){output("oheb_"+(i+1), "R" +oheb_benefits[i]);}
				else{output("oheb_"+(i+1), oheb_benefits[i]);}
				if(isFinite(safety_net[i])){output("safetynet_"+(i+1), "R" +safety_net[i]);}
				else {output("safetynet_"+(i+1), safety_net[i]);}
				if(isNaN(oheb_benefits[i])){
					output("saving_"+(i+1), "R" + day_2_day[i]);
				}
				else {
					if((day_2_day[i]-oheb_benefits[i]) > 0){
						output("saving_"+(i+1), "R" + (day_2_day[i]-oheb_benefits[i]));
					} 
					else {output("saving_"+(i+1), "");}					
				}
				output("limit_person_"+(i+1), "R" +productList[choice[i]].chronic_limit_person);
				output("limit_family_"+(i+1), "R" +productList[choice[i]].chronic_limit_family);
				//alert(day_2_day[i]);
				output("d2d_cover_"+(i+1), "R" +day_2_day[i]);
				var pay_gap = 0;
				if(isFinite(safety_net[i])){pay_gap = safety_net[i] - day_2_day[i];}
				if (pay_gap > 0) {output("pay_gap_"+(i+1), "R" +pay_gap);}
				else {output("pay_gap_"+(i+1), "");}
				output("download_"+(i+1), "<a href=\""+productList[choice[i]].pdf+"\" target=\"blank\" class=\"productLink\">Option Detail</a>");
			}
			else {
				output("total_"+(i+1), "");
				output("oheb_"+(i+1), "");
				output("safetynet_"+(i+1), "");
				output("saving_"+(i+1), "");
				output("limit_person_"+(i+1), "");
				output("limit_family_"+(i+1), "");
				output("d2d_cover_"+(i+1), "");
				output("pay_gap_"+(i+1), "");
				output("download_"+(i+1), "");
			}			
		}	
	}
	
	function refreshDetails () {
		var vis = 0;
		var dgmcOhebBuffy = new Array();
		var date = new Date();
		var month = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		var year = date.getYear();
		if(year < 999) year+=1900;
		output("date", date.getDate()+ " " + month[date.getMonth()] + " " + year);
		if(m.name != "") {
			output("member_name", m.name);
			vis =1;
		} else {output("member_name", "");}
		if(m.email != "") {
			output("member_email", m.email);
			vis =1;
		} else {output("member_email", "");}
		if(m.age != 0) {
			output("member_age", m.age);
			vis =1;
		} else {output("member_age", "");}
		if(m.spouse_age != 0) {
			output("partner_age", m.spouse_age);
			vis =1;
		} else {output("partner_age", "");}
		if(m.adult_dependants.length >= 1) {
			output("adult_dependant", m.adult_dependants.length+" ("+m.adult_dependants.join(", ")+")");
			vis =1;
		} else {output("adult_dependant", "");}
		if(m.child_dependants.length >= 1) {
			output("child_dependant", m.child_dependants.length+" ("+m.child_dependants.join(", ")+")");
			vis =1;
		} else {output("child_dependant", "");}
		if(m.chronic != null) {
			var expChronics = "";
			if(m.chronic_expenses != "") {
				expChronics = " (expenses: "+chronicExpensesList[m.chronic_expenses].value+")";
			}
			var selChronics = new Array();
			for(var i=0; i<m.chronic.length; i++) {
				selChronics.push(chronicList[m.chronic[i]].name);
				//alert (chronicList[m.chronic[i]].name);
			}
			output("chronic_conditions", selChronics.join(", ")+expChronics);
			vis =1;
		} else {output("chronic_conditions", "");}
		if(m.expenses != "") {
			output("monthly_expenses", expensesList[m.expenses].value);
		} else {output("monthly_expenses", "");}
		if(m.dgmc != 0) {
			dgmcOhebBuffy.push("Donald Gordon Medical Centre");
		}
		if(m.oheb != 0) {
			dgmcOhebBuffy.push("Out of Hospital Expenses Benefit");
		}
		if(dgmcOhebBuffy.length != 0) {
			output("dgmc_oheb", "Including: "+dgmcOhebBuffy.join(" and "));
		} else {output("dgmc_oheb", "");}
		if (vis == 1) {
			show("detail_output");
		}
		else {
			hide("detail_output");
		}
	}
		
	function switchView(to) {
		if(valid == 1) {
			var divList = new Array("detail", "spouse","dependant", "product", "chronic", "expenses", "quote");
			for (var i=0; i<divList.length; i++) {
				hide(divList[i]);
			}
			show(to);
		}
	}

	function outputBuffy() {
		output("display", buffyOut);
	}
	
	function output(element, content) {
		if(element == "display"){content = " "+content;}
		document.getElementById(element).innerHTML = content;
	}
	
	function restart() {
		var forms = new Array("detailForm", "spouseForm", "dependantForm", "productForm", "chronicForm", "expensesForm");
		//resets all forms
		for (var i=0; i<forms.length; i++) {
			document.forms[i].reset()
		}
		//resets locked checkboxes of productform
		countSelection(document.forms["productForm"]);
		m = new member();
		hide("detail_output");
		switchView("detail");
	}

	function emailQuote() {
		//alert("email quote to : "+m.email);
		document.forms[6].email.value = m.email;
		document.getElementById("contentField").value = document.getElementById("detail_output").innerHTML + document.getElementById("quote_span").innerHTML;
		document.forms[6].action = "xt_emailquote.asp";
		document.forms[6].method = "POST";
		document.forms[6].submit();
	}

	function show(element) {
		document.getElementById(element).style.visibility="visible";
		document.getElementById(element).style.display = 'block';
	}

	function hide(element) {
		document.getElementById(element).style.visibility="hidden";
		document.getElementById(element).style.display = 'none';
	}

