function oCalculator(premiumCost, premiumIncrement, webCost, webIncrement) {
	this.premiumCost=premiumCost;
	this.premiumIncrement=premiumIncrement;
	this.webCost=webCost;
	this.webIncrement=webIncrement;}

oCalculator.prototype.getPremiumCost=function(resources) {
	return this.premiumCost + this.premiumIncrement * (resources-1);}
	
oCalculator.prototype.getWebCost=function(resources) {
	return this.webCost + this.webIncrement * (resources-1);}
	
oCalculator.display=function(name,value) {
	var i=0;
	while (get(name+i)) {
		get(name+i).innerHTML=value;
		i++;}}

oCalculator.capitalFirst=function(value) {
	return value.substring(0,1).toUpperCase() + value.substring(1);}

function setSelect(calculator, field, lower, upper, step, current, prefix, suffix, plural) {
	var html='<select class="calculator" onchange="' + calculator + 'Calculator.set(\'' + field + '\',this.value)">';
	for (i=lower;i<=upper;i+=step) {
			html+='<option ' + (i==current?'selected ':'') + 'value="' + i + '">' + prefix + i + suffix + (plural!=undefined && i>1?plural:'') + '</option>';}
	get(calculator + oCalculator.capitalFirst(field)).innerHTML=html + '</select>';}

function oSavingsCalculator(calculator, resources, secretary, time, alternative) {
	this.calculator=calculator;
	this.resources=resources;
	this.secretary=secretary;
	this.time=time;
	this.alternative=alternative;}

oSavingsCalculator.prototype.set=function(property, value) {
	this[property]=parseInt(value);
	this.recalculate();}

oSavingsCalculator.prototype.recalculate=function() {
	this.reservoiceMonthly=this.calculator.getPremiumCost(this.resources);
	this.reservoiceAnnual=this.reservoiceMonthly*12;
	this.savings=(this.time * this.secretary * 1000 / 100) + this.alternative - this.reservoiceAnnual;
	this.display();}

oSavingsCalculator.prototype.display=function() {
	for (var p in this) {
		oCalculator.display('savings' + oCalculator.capitalFirst(p), this[p]);}}

function oOpportunityCalculator(calculator, resources, days, hours, capacity, costOfResources, variableCost, fixedCosts) {
	this.calculator=calculator;
	this.resources=resources;
	this.days=days;
	this.hours=hours;
	this.capacity=capacity;
	this.costOfResources=costOfResources;
	this.variableCost=variableCost;
	this.fixedCosts=fixedCosts;}

oOpportunityCalculator.prototype.set=oSavingsCalculator.prototype.set;

oOpportunityCalculator.prototype.recalculate=function() {
	this.reservoiceMonthly=this.calculator.getPremiumCost(this.resources);
	this.reservoiceWeekly=parseInt(this.reservoiceMonthly*12/52);
	this.weeklyHours=parseInt(this.days*this.hours*this.resources*this.capacity/100),
	this.transaction=parseInt(this.reservoiceWeekly*100/this.weeklyHours);
	this.weeklyCost=this.weeklyHours * this.variableCost + this.fixedCosts + this.reservoiceWeekly;
	this.weeklyIncome=this.weeklyHours*this.costOfResources;
	this.profit=(this.weeklyIncome - this.weeklyCost)*52;
	this.display();}

oOpportunityCalculator.prototype.display=function() {
	for (var p in this) {
		oCalculator.display('opportunity' + oCalculator.capitalFirst(p), this[p]);}}
		
function oAffiliateCalculator(calculator, accounts, resources, commission) {
	this.calculator=calculator;
	this.resources=resources;
	this.accounts=accounts;
	this.commission=commission;}

oAffiliateCalculator.prototype.set=oSavingsCalculator.prototype.set;

oAffiliateCalculator.prototype.recalculate=function() {
	this.reservoiceMonthly=this.calculator.getPremiumCost(this.resources);
	this.monthlyCommission=parseInt(this.commission * this.reservoiceMonthly * (12*this.accounts-1) / 100);
	this.display();}

oAffiliateCalculator.prototype.display=function() {
	for (var p in this) {
		oCalculator.display('affiliate' + oCalculator.capitalFirst(p), this[p]);}}