var selected='images/map-area0.gif';
var sel=0;

function turnJSon(){
document.getElementById("JSWarning").innerHTML="Select your region";

}


function overNB(what){
	what.style.backgroundColor='#ffe6e7';
	what.style.cursor='hand';
}

function outNB(what){
	what.style.backgroundColor='#ffffff';
}

function upNB(what){

}

function closeBoxHover(what){
			what.src='images/closeBox_winxp_hover.jpg';
}

function closeBoxNorm(what){
			what.src='images/closeBox_winxp.jpg';
}

function titlemousein(what){
	what.style.backgroundImage='url(images/draggableWindow_bg_on.jpg)';
}

function titlemouseout(what){
	what.style.backgroundImage='url(images/draggableWindow_bg_off.jpg)';

}

function mapOver(what,which){
if(sel==0){
document.getElementById('solarRegionsMap').src='images/map-area'+what+'.gif';
}
which.style.color='#ff0000';
}

function mapOut(what,which){
if(sel==0){
document.getElementById('solarRegionsMap').src=selected;
}
if(what!=selectedIndex[0]){
which.style.color='#555555';
}

}

function mapSelect(what){
selected='images/map-area'+what+'.gif';
if(sel>0){
document.getElementById('a'+sel).style.color='#555555';

}
sel=what;
selectedIndex[0]=what;
document.getElementById('solarRegionsMap').src='images/map-area'+what+'.gif';
document.getElementById('a'+what).style.color='#ff0000';

testInput();
}

// selectedIndex (region1-5,type1-2,power1000-4000,dateRange,Export);
var powerArray=new Array(0,1000,2000,3000,4000);
var efficiencyArray=new Array(0,76.83,83.33,86.83,90.1,96.33);
var tariffArrayRetro=new Array(0,.413,.378,.346,.316,.288);
var tariffArrayNew=new Array(0,.361,.33,.302,.276,.251);
var selectedIndex=new Array(0,0,0,0,0);
var exportArray=new Array(0,0,25,50,75,100);

//var efficiency=0;
var output=0;
var tariffIncome=0;
var exportIncome=0;






function testInput(){
var ok=true;
for(var i=0;i<selectedIndex.length;i++){
	if (selectedIndex[i]==0){
	ok=false;
}	
}
if (ok==true){
		updateSummary();
		}

//updateTempDiv();		
		
}
// selectedIndex (region1-5,type1-2,power1000-4000,dateRange,Export);
function updateSummary(){
//alert('power output \n'+powerArray[selectedIndex[2]]+'\n'+efficiencyArray[selectedIndex[0]]);
output=powerArray[selectedIndex[2]]/100*efficiencyArray[selectedIndex[0]];
// 1 is new : 2 is retro
if(selectedIndex[1]==2){
tariffIncome=(tariffArrayRetro[selectedIndex[3]]*output).toFixed(2);
}else {
tariffIncome=(tariffArrayNew[selectedIndex[3]]*output).toFixed(2);
}

exportIncome=(output/100*exportArray[selectedIndex[4]]*0.03).toFixed(2);

/*
if(selectedArray[1]==1){
tariffIncome=selectedArray[0]
} else{

}
*/
document.getElementById('annual-generation').innerHTML=output+'kWp';
document.getElementById('annual-tariff').innerHTML='&pound;'+tariffIncome;
var temp2 = (output*0.03/100*exportArray[selectedIndex[4]]).toFixed(2);
document.getElementById('annual-export').innerHTML='&pound;'+exportIncome;

var temp1=(output*0.14/100*(100-exportArray[selectedIndex[4]])).toFixed(2);
document.getElementById('annual-saving').innerHTML='&pound;'+temp1;

//alert(parseFloat(tariffIncome)+"\n"+parseFloat(exportIncome)+"\n"+temp1);
var Ti=parseFloat(tariffIncome)+parseFloat(exportIncome)+parseFloat(temp1);

document.getElementById('annual-total').innerHTML='&pound;'+Ti.toFixed(2);//+output*0.14


document.getElementById('accum-tariff').innerHTML='&pound;'+tariffIncome*25;
document.getElementById('accum-export').innerHTML='&pound;'+temp2*25;
document.getElementById('accum-saving').innerHTML='&pound;'+temp1*25;
var T2=Ti*25;
document.getElementById('accum-total').innerHTML='&pound;'+T2.toFixed(2);
//alert("updating summary");

}

function updateTempDiv(){
//alert("updating tempDiv");
document.getElementById("tempDiv").innerHTML='<div>region : '+selectedIndex[0]+'</div><div>type   : '+selectedIndex[1]+'</div><div>size   : '+selectedIndex[2]+'</div><div>date   : '+selectedIndex[3]+'</div><div>export : '+selectedIndex[4]+'</div><div>Power generation :'+output+'</div><div>Income from tariff :'+tariffIncome+'</div><div>Income from export :'+exportIncome+'</div>';
}

function updateSelectType(what){
//alert("updateSelectType \n "+what.value);
selectedIndex[1]=what.value;
testInput();
}
function updateSelectPower(what){
//alert("updateSelectPower \n "+what.value);
selectedIndex[2]=what.value;
testInput();
}
function updateDate(what){
//alert("updateSelectPower \n "+what.value);
selectedIndex[3]=what.value;
testInput();
}
function updateExport(what){
//alert("updateSelectPower \n "+what.value);
selectedIndex[4]=what.value;
testInput();
}

