// JavaScript Document
function calculate () {
	var price = $('#price').val();
	var petrol = $('#petrol').val();
	var miles = $('#miles').val();
	var msg = "<p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span>Please check the following errors:-<ul>";
	var res = true;
	var result_data = "";
	
	if(price.length == 0 || price.length == null)
	{
		msg += "<li>Please fill in the amount petrol costs at the time of purchase. </li>";
		res = false;
	}
	if(petrol.length == 0 || petrol.length == null)
	{
		msg += "<li>Please provide the amount spent on petrol. </li>";
		res = false;
	}
	if(miles.length == 0 || miles.length == null)
	{
		msg += "<li>Please provide the distance of miles you travelled.</li>";
		res = false;
	}
	msg += "</ul></p>";
	if(res == false)
	{
		$('#dialog').html(msg);
		$('#dialog').dialog('open');
		return false;
	}
	
	var LitresInGallon = 4.54609188;
	var GallonsInLitre = 0.219969157;		
	
	if(res == true)	
	{
		var Litres = petrol/(price/100);
		var Gallons = Litres * GallonsInLitre;
		result_data =  Math.round((miles/Gallons),2);
		$('#mpg').html(result_data);
		$('#result_area').show('slow');
	}	
	
}
