// JavaScript Document

function Calculate()
{
	
petctl=getCtl('txtpcost');	
lpgctl=getCtl('txtlcost');
spectl=getCtl('txtspend');

if(petctl.value.search(sth)==-1)
  {
	  
	  
	alert("Please enter value for   Petrol cost per litre")
	petctl.focus();
	return;
	  
  }
	
	if(lpgctl.value.search(sth)==-1)
  {
	  
	  
	alert("Please enter value for LPG cost per litre")
	lpgctl.focus();
	return;
	  
  }
	
	
	if(spectl.value.search(sth)==-1)
  {
	  
	  
	alert("Please enter value for spend ")
	spectl.focus();
	return;
	  
  }
  
  if(petctl.value.search(decreg)==-1)
  {
	  
	  
	alert("Please enter value for   Petrol cost per litre in numbers")
	petctl.focus();
	return;
	  
  }
	
	if(lpgctl.value.search(decreg)==-1)
  {
	  
	  
	alert("Please enter positive value for LPG cost per litre.")
	lpgctl.focus();
	return;
	  
  }
	
	
	if(spectl.value.search(sth)==-1)
  {
	  
	  
	alert("Please enter positive value for spend.")
	spectl.focus();
	return;
	  
  }
  
  
  
  
  var url="res.html";
  var wind=window.open(url,null,'height=300,width=300,top=100,left=100;scrollbars=1');
     var pcost=petctl.value;
var lpgcost= lpgctl.value;
var exp1=spectl.value;
pcost*=1;
lpgcost*=1;
exp1*=1;
var dist= (exp1 / pcost);
var sav=dist*1.30*lpgcost;
weeksaving=Math.round(exp1-sav);
savinga=Math.round(weeksaving*52);
saving3=Math.round(weeksaving*156);

wind.document.write("<div align='center'>Annual Savings :$"+ savinga+"</div>");
wind.document.write("<div align='center'>Weekly Savings:$ "+weeksaving+"</div>");
wind.document.write ("<div align='center'>3 year Savings:$ "+saving3+"</div>");
wind.document.write("<br>");
wind.document.write( "<div>These figures are  indicative only derieved from the following information </div>");
wind.document.write("<br>");
wind.document.write("<div align='center'>Your weekly expenditure:$"+exp1+"</div>");
wind.document.write("<div align='center'>Cost of petrol per litre:$"+ pcost+"</div>");
wind.document.write("<div align='center'>Cost of LPG per litre:$ "+lpgcost+"</div>");
 
 
 
  
	
	
}
function init()
{
	
	
	petctl=getCtl('txtpcost');	
lpgctl=getCtl('txtlcost');
petctl.value=petdef;
	
	lpgctl.value=lpgdef;
	
}
var petdef=1.35;
var lpgdef=0.51;