
useover = false;
if ((navigator.userAgent.substring(0,9) == "Mozilla/3") || (navigator.userAgent.substring(0,9) == "Mozilla/4"))  useover = true;
else useover = false;

function popupwindow(argURL,width,height,scrollbar,resize) {

	var screenw = screen.availWidth;
	var screenh = screen.availHeight;

	var leftPos = (screenw-width)/2; 
	var topPos = (screenh-height)/2;

	var agt=navigator.userAgent.toLowerCase();

	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);

	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
		&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
		&& (agt.indexOf('webtv')==-1));

	var is_ie   = (agt.indexOf("msie") != -1);
	var is_ie3  = (is_ie && (is_major < 4));
	var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
	var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);

	var is_mac    = (agt.indexOf("mac")!=-1);

	if (is_mac)
	{
	displaypopup = window.open(argURL,'Display','resizable='+resize+',scrollbars='+scrollbar+',width='+width+',height='+height+',left='+leftPos+',top='+topPos+',toolbar=no');
	}
	else if (!is_nav && !is_ie5up)
	{
	displaypopup = window.open(argURL,'Display','resizable='+resize+',scrollbars='+scrollbar+',width='+width+',height='+height+',left='+leftPos+',top='+topPos+',toolbar=no');
	}
	else
	{
	displaypopup = window.open("",'Display','resizable='+resize+',scrollbars='+scrollbar+',width='+width+',height='+height+',left='+leftPos+',top='+topPos+',toolbar=no');
	displaypopup.close();
	displaypopup = window.open(argURL,'Display','resizable='+resize+',scrollbars='+scrollbar+',width='+width+',height='+height+',left='+leftPos+',top='+topPos+',toolbar=no');
	displaypopup.focus();
	}
}


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
pence = num%100;
num = Math.floor(num/100).toString();
if(pence<10)
pence = "0" + pence;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '£' + num + '.' + pence);
}


function calculate()
{


	var petrolPrice	= parseInt(document.calculator.petrolPrice.value)
	var lpgPrice	= parseInt(document.calculator.lpgPrice.value)
	var mpg			= parseInt(document.calculator.mpg.value)
	var mileage		= parseInt(document.calculator.mileage.value)
	
	
	for (var i=0; i < 3; i++) {
		if (document.calculator.conversionCost[i].checked) {
			var conversion	= parseInt(document.calculator.conversionCost[i].value)
			break;
		}
	}	
	

	//
	// calculate answers
	var annualPetrolBill	= ((petrolPrice/100) * 4.55 * (mileage/mpg));
	var annualLPGBill		= ((mileage/mpg) * ((lpgPrice/100) * 4.55));
	var annualSavings		= annualPetrolBill - annualLPGBill;
	var totalAnnualSavings	= annualSavings ;
	// add 17.5% of conversion cost on to conversation if
	// not VAT registered
		conversion = conversion + ((17.5/100) * conversion);
		//conversion = conversion + 262.5;

	var year1Savings	= totalAnnualSavings - (conversion);
	var year2Savings	= totalAnnualSavings + year1Savings;
	var year3Savings	= totalAnnualSavings + year2Savings;
	//
	//populate answer fields
	document.calculator.petrolBill.value	= formatCurrency(annualPetrolBill);
	document.calculator.lpgBill.value		= formatCurrency(annualLPGBill);
	document.calculator.savings.value		= formatCurrency(annualSavings);
	document.calculator.totalSavings.value	= formatCurrency(totalAnnualSavings);
	document.calculator.year1Savings.value	= formatCurrency(year1Savings);
	document.calculator.year2Savings.value	= formatCurrency(year2Savings);
	document.calculator.year3Savings.value	= formatCurrency(year3Savings);
document.calculator.convcost.value= formatCurrency(conversion);

}

