function insertContact(theName, linkText)
{
	theDomain = 'aeoluspower' + '-windenergy' + '.co.uk';
	theAddress = theName + "&#064;" + theDomain;

	document.write("<A class='menu' HREF=\"mailto");
	document.write(":" + theAddress);
	document.write( "\">" + theAddress + "<\/a>");
}


function insertContactSubject(theName, linkText)
{
	theDomain = 'aeolus' + 'power' + '.co.uk';
	theAddress = theName + "&#064;" + theDomain;

	document.write("<A class='menu' HREF=\"mailto");
	document.write(":" + theAddress + "?subject=" + linkText);
	document.write( "\">" + theAddress + "<\/a>");
}


function showEmail(theName)
{
	theDomain = 'aeolus' + 'power' + '.co.uk';
	theAddress = theName + "&#064;" + theDomain;
	showString = "<A class='menu' HREF=\"mailto" + ":" + theAddress + "\">" + theAddress + "<\/a>";
	return (showString);
}


function openWindow(imageName,imageWidth,imageHeight,alt,comments,materials) 
{
	
	image_height = parseInt(imageHeight) + 80;
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+image_height);
	newWindow.document.open();
	newWindow.document.write('<html><link rel=stylesheet type="text/css" href="styles/gen_styles.css"><head><title>'+alt+'</title></head><body bgcolor="#fefbed" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">'); 
	newWindow.document.write('<img src="'+imageName+'" width="'+imageWidth+'" height="'+imageHeight+'" alt="'+alt+'">');
	newWindow.document.write('<br><b><center>'+comments+'</center></b>'+materials+'<br>');
	newWindow.document.write('<a href="JavaScript:self.close()" title="Close Window"><center><img src="images/install/closebut.gif" width="60" height="20" border="0" alt="Close this window"></center></a>'); 
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}

var kWhpa = [[120000, 160000, 210000], [15300, 23600, 31300], [9018, 13429, 17423]];
var power = [50, 10, 6];
var windspeed = [5, 6, 7];
var prices = [250000, 45000, 25000];
var startPrices = [200000, 35000, 22000];
var perKwh = [0.241, 0.267, 0.267];
var exportRate = [0.05, 0.03, 0.03];
var savingRate = 0.12;

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function updateTable() 
{
	//alert(choice.turbine.options.selectedIndex);
	var which = document.choice.turbine.options.selectedIndex;
	var text;
	var incomeRate, incomeRate1;
	var rate, income, payback;
	var line0, line1, line2, line3, line4, line5;
	var incomeSaving;
	var totalIncome;
	var text0;
	var kwhRate;
	
	text = document.getElementById('totalcost');	
	text.innerHTML = "Total Cost ranges from &pound;" + addCommas(startPrices[which]) + " to &pound;" +  addCommas(prices[which]);

	incomeRate = document.getElementById('incomeRate');
	rate = ((perKwh[which] + exportRate[which]) * 100);
	incomeRate.innerHTML = "Income \@" + rate.toFixed(1) + "p";
	
	incomeRate1 = document.getElementById('incomeRate1');
	rate = (perKwh[which] * 100);
	incomeRate1.innerHTML = "Income \@" + rate.toFixed(1) + "p";
	
	// calculate income for first wind speed, for 'export'
	income = kWhpa[which][0] * (perKwh[which] + exportRate[which]);
	payback = prices[which] / income;
    line0 = document.getElementById('tariffs').rows[4].cells;
	line0[1].innerHTML = addCommas(kWhpa[which][0]);
	line0[2].innerHTML = payback.toFixed(1) + " years";
	line0[3].innerHTML = "&pound;" + addCommas(income.toFixed(0));

	// calculate the 'onsite' figures
	income = kWhpa[which][0] * (perKwh[which]);
	incomeSaving = kWhpa[which][0] * savingRate;
	totalIncome = income + incomeSaving;
	payback = prices[which] / totalIncome;
	
	line3 = document.getElementById('tariffs').rows[10].cells;
	line3[1].innerHTML = addCommas(kWhpa[which][0]);
	line3[2].innerHTML = payback.toFixed(1) + " years";
	line3[3].innerHTML = "&pound;" + addCommas(income.toFixed(0));
	line3[4].innerHTML = "&pound;" + addCommas(incomeSaving.toFixed(0));
	line3[5].innerHTML = "&pound;" + addCommas(totalIncome.toFixed(0));

	
	
	// repeat for second wind speed
	income = kWhpa[which][1] * (perKwh[which] + exportRate[which]);
	payback = prices[which] / income;

	line1 = document.getElementById('tariffs').rows[5].cells;
	line1[1].innerHTML = addCommas(kWhpa[which][1]);
	line1[2].innerHTML = payback.toFixed(1) + " years";
	line1[3].innerHTML = "&pound;" + addCommas(income.toFixed(0));
	
	
	// calculate the 'onsite' figures
	income = kWhpa[which][1] * (perKwh[which]);
	incomeSaving = kWhpa[which][1] * savingRate;
	totalIncome = income + incomeSaving;
	payback = prices[which] / totalIncome;
	
	line4 = document.getElementById('tariffs').rows[11].cells;
	line4[1].innerHTML = addCommas(kWhpa[which][1]);
	line4[2].innerHTML = payback.toFixed(1) + " years";
	line4[3].innerHTML = "&pound;" + addCommas(income.toFixed(0));
	line4[4].innerHTML = "&pound;" + addCommas(incomeSaving.toFixed(0));
	line4[5].innerHTML = "&pound;" + addCommas(totalIncome.toFixed(0));
	
	
	
	// repeat for third wind speed
	income = kWhpa[which][2] * (perKwh[which] + exportRate[which]);
	payback = prices[which] / income;

	line2 = document.getElementById('tariffs').rows[6].cells;
	line2[1].innerHTML = addCommas(kWhpa[which][2]);
	line2[2].innerHTML = payback.toFixed(1) + " years";
	line2[3].innerHTML = "&pound;" + addCommas(income.toFixed(0));
		
	
	// calculate the 'onsite' figures
	income = kWhpa[which][2] * (perKwh[which]);
	incomeSaving = kWhpa[which][2] * savingRate;
	totalIncome = income + incomeSaving;
	payback = prices[which] / totalIncome;
	
	line5 = document.getElementById('tariffs').rows[12].cells;
	line5[1].innerHTML = addCommas(kWhpa[which][2]);
	line5[2].innerHTML = payback.toFixed(1) + " years";
	line5[3].innerHTML = "&pound;" + addCommas(income.toFixed(0));
	line5[4].innerHTML = "&pound;" + addCommas(incomeSaving.toFixed(0));
	line5[5].innerHTML = "&pound;" + addCommas(totalIncome.toFixed(0));
	
	
	
	
	// now tackle the text in the boxes underneath
	text0 = document.getElementById('tariffs').rows[13].cells;
	kwhRate = perKwh[which] * 100;
	text0[0].innerHTML = "<p>These figures are based on the Feed in Tariffs introduced in April 2010. For a "
	+ power[which] + "kW turbine you will be paid "
	+ kwhRate.toFixed(1) + "p per kWh produced and "
	+ exportRate[which] * 100 + "p per kWh exported. Savings are based on average cost of imported electricity at "
	+ savingRate * 100 + "p/kWh. The kWh production is based on smooth laminar airflow.</p>";
}


