var metric = 1;
var type = 'IE';

if (navigator.userAgent.indexOf('Opera')!=-1 && document.getElementById) {
	type = 'OP';
}
if (document.all) {
	type = 'IE';
}
if (document.layers) {
	type = 'NN';
}
if (!document.all && document.getElementById) {
	type = 'MO';
}

function DivContent(divname, content) {
	if (type == 'IE') {
		eval('document.all.' + divname + '.innerHTML = \'' + content + '\'\;');
	}
	if (type == 'NN') {
		eval('document.' + divname + '.innerHTML = \'' + content + '\'\;');
	}
	if (type == 'MO' || type == 'OP') {
		document.getElementById(divname).innerHTML = content;
	}
}





function SwitchImperial() {
	metric = 0;

	DivContent('StrWallsUnits', 'Sq. Feet');
	DivContent('StrFloorsUnits', 'Sq. Feet');
	DivContent('StrWalls2Units', 'Sq. Feet');
	DivContent('TilPlasteringUnits', 'Sq. Feet');
	DivContent('TilTilingUnits', 'Sq. Feet');
	DivContent('FloHardwoodUnits', 'Sq. Feet');
	DivContent('FloLaminateUnits', 'Sq. Feet');
	DivContent('FloVarnishingUnits', 'Sq. Feet');

	DivContent('Metric', '<a href=" " title="Switch to Metric" onClick="SwitchMetric(); return false;">[Metric]</a>');
	DivContent('Imperial', '<b>[Imperial]</b>');

	Calculate();
}





function SwitchMetric() {
	metric = 1;

	DivContent('StrWallsUnits', 'Sq. Meters');
	DivContent('StrFloorsUnits', 'Sq. Meters');
	DivContent('StrWalls2Units', 'Sq. Meters');
	DivContent('TilPlasteringUnits', 'Sq. Meters');
	DivContent('TilTilingUnits', 'Sq. Meters');
	DivContent('FloHardwoodUnits', 'Sq. Meters');
	DivContent('FloLaminateUnits', 'Sq. Meters');
	DivContent('FloVarnishingUnits', 'Sq. Meters');

	DivContent('Metric', '<b>[Metric]</b>');
	DivContent('Imperial', '<a href=" " title="Switch to Imperial" onClick="SwitchImperial(); return false;">[Imperial]</a>');

	Calculate();
}





function Calculate() {
	var total = 0;
	var frm = document.forms.CalcFrm;

	var StrBath = parseInt(frm.StrBath.value, 10);
	var StrKitchen = parseInt(frm.StrKitchen.value, 10);
	var StrWalls = parseInt(frm.StrWalls.value, 10);
	var StrFloors = parseInt(frm.StrFloors.value, 10);
	var StrWalls2 = parseInt(frm.StrWalls2.value, 10);
	var FitBathroom = parseInt(frm.FitBathroom.value, 10);
	var FitKitchen = parseInt(frm.FitKitchen.value, 10);
	var TilPlastering = parseInt(frm.TilPlastering.value, 10);
	var TilTiling = parseInt(frm.TilTiling.value, 10);
	var TilPainting = parseInt(frm.TilPainting.value, 10);
	var FloHardwood = parseInt(frm.FloHardwood.value, 10);
	var FloLaminate = parseInt(frm.FloLaminate.value, 10);
	var FloVarnishing = parseInt(frm.FloVarnishing.value, 10);
	var ElSocket = parseInt(frm.ElSocket.value, 10);
	var ElSpotlight = parseInt(frm.ElSpotlight.value, 10);
	var ElSwitch = parseInt(frm.ElSwitch.value, 10);
	var RepRadiator = parseInt(frm.RepRadiator.value, 10);
	var RepBath = parseInt(frm.RepBath.value, 10);
	var RepSink = parseInt(frm.RepSink.value, 10);
	var RepToilet = parseInt(frm.RepToilet.value, 10);
	
	if (StrBath > 0) {
		total += StrBath*315;
	}
	if (StrKitchen > 0) {
		total += StrKitchen*375;
	}
	if (StrWalls > 0) {
		if (metric) {
			total += StrWalls*4;
		} else {
			total += (StrWalls*4)/10.76364864;
		}
	}
	if (StrFloors > 0) {
		if (metric) {
			total += StrFloors*2;
		} else {
			total += (StrFloors*2)/10.76364864;
		}
	}
	if (StrWalls2 > 0) {
		if (metric) {
			total += StrWalls2*6;
		} else {
			total += (StrWalls2*6)/10.76364864;
		}
	}
	if (FitBathroom > 0) {
		total += FitBathroom*1800;
	}
	if (FitKitchen > 0) {
		total += FitKitchen*1500;
	}
	if (TilPlastering > 0) {
		if (metric) {
			total += TilPlastering*7;
		} else {
			total += (TilPlastering*7)/10.76364864;
		}
	}
	if (TilTiling > 0) {
		if (metric) {
			total += TilTiling*23;
		} else {
			total += (TilTiling*23)/10.76364864;
		}
	}
	if (TilPainting > 0) {
		if (TilPainting < 2) {
			total += 1200;
		} else {
			if (TilPainting < 3) {
				total += 1800;
			} else {
				total += 1800 + 550*(TilPainting - 2);
			}
		}
	}
	if (FloHardwood > 0) {
		if (metric) {
			total += FloHardwood*37;
		} else {
			total += (FloHardwood*37)/10.76364864;
		}
	}
	if (FloLaminate > 0) {
		if (metric) {
			total += FloLaminate*17;
		} else {
			total += (FloLaminate*17)/10.76364864;
		}
	}
	if (FloVarnishing > 0) {
		if (metric) {
			total += FloVarnishing*4;
		} else {
			total += (FloVarnishing*4)/10.76364864;
		}
	}
	if (ElSocket > 0) {
		total += ElSocket*50;
	}
	if (ElSpotlight > 0) {
		total += ElSpotlight*37;
	}
	if (ElSwitch > 0) {
		total += ElSwitch*45;
	}
	if (RepRadiator > 0) {
		total += RepRadiator*80;
	}
	if (RepBath > 0) {
		total += RepBath*285;
	}
	if (RepSink > 0) {
		total += RepSink*90;
	}
	if (RepToilet > 0) {
		total += RepToilet*115;
	}

	total = Math.round(total);

	DivContent('Total', total);
}