var excgendomrate=0;
var excdayrate=0;
var excnightrate=0;
var region='';
var tariff='';
var gdbillkwh='';
var daybillkwh='';
var nightbillkwh='';
var billcost='';



function showGasPrice(){
	
gasbillkwh=MWJ_findObj('gasbillkwh').value; //get KWH from input field
/*gasrate=getRefToDiv('gasrate'); //read rate from html on page
alert('gasrate');

gr=gasrate.innerHTML;
*/

if(!gasbillkwh==''){ // OK to calculate
	var g = parseFloat(gasbillkwh, 4);
	//var grate = parseFloat(gr, 4)/100;
	var grate = 3.5/100; // 30.4.09 changed so that vat-exclusive figure is used for calcs.
	//alert(gasrate);
	excvat=g*grate;
	incvat=excvat*1.05;
	//alert(ebicost);
	divwrite('idexcvat', '£'+ excvat.toFixed(2));
	divwrite('idincvat', '£'+ incvat.toFixed(2));
	MWJ_changeDisplay('result', 'block');
	
	}
else{ // Can't calculate because there's an empty field
	alert('Please enter figures into the field');
	}	
	
}


function showEbicoPrice(){
// billcost=MWJ_findObj('billcost').value;
gdbillkwh=MWJ_findObj('gdbillkwh').value;
daybillkwh=MWJ_findObj('daybillkwh').value;
nightbillkwh=MWJ_findObj('nightbillkwh').value;

if((tariff=='gd' && !gdbillkwh=='') || (tariff=='e7' && !daybillkwh=='' && !nightbillkwh=='')) // removed " && !billcost=='' " from each
	{ // OK to calculate
	//var bc = parseFloat(billcost, 4);
	if(tariff=='gd')
		{
		var gd = parseFloat(gdbillkwh, 4);
		var grate = parseFloat(excgendomrate, 4)/100;
		excebicost=gd*grate;
		}
	else 
		{ // tariff=='e7' 
		var day = parseFloat(daybillkwh, 4);
		var drate = parseFloat(excdayrate, 4)/100;
		var night = parseFloat(nightbillkwh, 4);
		var nrate = parseFloat(excnightrate, 4)/100;
		excebicost=day*drate+night*nrate;
		}
	
/*	if (bc < ebicost){ // there's no saving
		MWJ_changeDisplay('saving', 'none');
		}
	else{// there is a saving
		var save= bc-ebicost;
		var perc= Math.round(save/bc*100);
		//alert(perc);
		MWJ_changeDisplay('saving', 'block');
		divwrite('saving', 'That’s a saving of <strong>£'+ save.toFixed(2) + '<\/strong> or <strong>' + perc + '%<\/strong>.');
		}
	//but whether there's a saving or not...
*/
	incebicost=excebicost*1.05;
	divwrite('excresultcost', '£'+ excebicost.toFixed(2));
	divwrite('incresultcost', '£'+ incebicost.toFixed(2));
	MWJ_changeDisplay('result', 'block');
	}
	
else{ // Can't calculate because there's an empty field
	alert('Please enter figures into the field(s)');
	}
}


function tariffSelect(theform,nom) { // called when the "Tariff select" pop-up changes

// Make sure they've selected a region
if (region==''){
alert('First click on the map to select your region.\nThen you can select a tariff.');
return;
}

tariff=theform[nom].value; // what they chose
//alert(tariff);
MWJ_changeDisplay('showme', 'none'); // to make it move to new position
MWJ_changeDisplay('result', 'none'); // to hide old figures
clearfields();

if (tariff=="") { // set display to its initial state and tell them to select a tariff
MWJ_changeDisplay('e7wrapper', 'none');
MWJ_changeDisplay('gdbillkwhwrapper', 'none');
MWJ_changeDisplay('billcostwrapper', 'none');
MWJ_changeDisplay('result', 'none');
alert('Please select a tariff');}

else {
if (tariff=="gd") { // they chose General Domestic
MWJ_changeDisplay('e7wrapper', 'none');
MWJ_changeDisplay('gdbillkwhwrapper', 'block');
MWJ_findObj('gdbillkwh').focus();
}
if (tariff=="e7") { // they chose Economy 7
MWJ_changeDisplay('e7wrapper', 'block');
MWJ_changeDisplay('gdbillkwhwrapper', 'none');
MWJ_findObj('daybillkwh').focus();
}

// now reveal the "Show me the Ebico price" button
// MWJ_changeDisplay('billcostwrapper', 'block'); // Phil doesn't want this now

//MWJ_changeDisplay('navbottom', 'none'); // to make it move to new position

MWJ_changeDisplay('showme', 'block');
//MWJ_changeDisplay('navbottom', 'block'); // to make it move to new position

}
}

function clearfields() {
}




function pickmap(n){
//alert ('number is: ' + n);

//read table columns into arrays

var gendomnode = getRefToDiv('gendom');
var econ7node = getRefToDiv('econ7');
var regionArray =getElementsByClass('region', econ7node,'td'); 
region=regionArray[n].innerHTML;
divwrite('regiontitle', region + ' Region');

//var gendomArray =getElementsByClass('incvat', gendomnode,'td'); 
//gendomrate=gendomArray[n].innerHTML;
//divwrite('gdrate', '<span class=\"rate\">' + gendomrate + '<\/span> per KWh (inc VAT)');

var excgendomArray =getElementsByClass('excvat', gendomnode,'td'); 
excgendomrate=excgendomArray[n].innerHTML;
var incgendomArray =getElementsByClass('incvat', gendomnode,'td'); 
incgendomrate=incgendomArray[n].innerHTML;
divwrite('gdrate', '<span class=\"rate\">' + excgendomrate + '<\/span> per KWh exc VAT <br> (' + incgendomrate + ' per KWh inc VAT)');




//var dayIncvatArray =getElementsByClass('incvat', econ7node,'td'); 
//dayrate=dayIncvatArray[n].innerHTML;
//divwrite('dayrate', 'day: <span class=\"rate\">' + dayrate + '<\/span> per KWh (inc VAT)');


var dayExcvatArray =getElementsByClass('excvat', econ7node,'td'); 
excdayrate=dayExcvatArray[n].innerHTML;
var dayIncvatArray =getElementsByClass('incvat', econ7node,'td'); 
incdayrate=dayIncvatArray[n].innerHTML;
divwrite('dayrate', 'day: <span class=\"rate\">' + excdayrate + '<\/span> per KWh exc VAT <br> (' + incdayrate + ' per KWh inc VAT)');

//var nightIncvatArray =getElementsByClass('incvat_', econ7node,'td'); 
//nightrate=nightIncvatArray[n].innerHTML;
//divwrite('nitrate', 'night: <span class=\"rate\">' + nightrate + '<\/span> per KWh (inc VAT)');

var nightExcvatArray =getElementsByClass('excvat_', econ7node,'td'); 
excnightrate=nightExcvatArray[n].innerHTML;
var nightIncvatArray =getElementsByClass('incvat_', econ7node,'td'); 
incnightrate=nightIncvatArray[n].innerHTML;
divwrite('nitrate', 'night: <span class=\"rate\">' + excnightrate + '<\/span> per KWh exc VAT <br> (' + incnightrate + ' per KWh inc VAT)');

}


