// Haffener's Oil Price Calculator

var xmlDoc=null;
	if (window.ActiveXObject)
		{// code for IE
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		}
	else if (document.implementation.createDocument)
		{// code for Mozilla, Firefox, Opera, etc.
		xmlDoc=document.implementation.createDocument("","",null);
		}
	else
	{
		alert('Your browser does not support this script');
	}
	
if (xmlDoc!=null) 
	{
		xmlDoc.async=false;
		xmlDoc.load("./login/Oil_Price.xml");
		var x=xmlDoc.getElementsByTagName("Oil");
	}




	
//Base oil price 250-150 gallons
var base=(x[0].getElementsByTagName("Price")[0].childNodes[0].nodeValue)*1;
var oil=base.toFixed(3);
//
//Base oil price 100-75 gallons
var x=-.1;
var base2=base - x;
var oil2=base2.toFixed(3);
//
//Base oil price 75 gallons
var t=-.15;
var base3=base - t;
var oil3=base3.toFixed(3);
//
//Base oil price 50 gallons
var q=-.20;
var base4=base - q;
var oil4=base4.toFixed(3);
//


//250-150 gallons prices
var b250=(base)*250;
var g250=b250.toFixed(2)
var b200=(base)*200;
var g200=b200.toFixed(2)
var b175=(base)*175;
var g175=b175.toFixed(2)
var b150=(base)*150;
var g150=b150.toFixed(2)
//
//100-75gallons prices
var b100=(base2)*100;
var g100=b100.toFixed(2)
//
//100-75gallons prices
var b75=(base3)*75;
var g75=b75.toFixed(2)
var b50=(base4)*50;
var g50=b50.toFixed(2)

//


function startCalc(){
  interval = setInterval("calc()",1);
}

function calc(){
var _50 = ((base+.20)/base)*50
var _75 = ((base+.15)/base)*75
var _100 = ((base+.1)/base)*100
var Fill = 0
var Other = 0

var t1 = eval(document.oilform.Gallons.value);
var t3 = t1*base
document.oilform.Total.value=("$"+(value=custRound(t3,2)));

}

function custRound(number,decimal_points) {
	if(!decimal_points) return Math.round(number);
	if(number == 0) {
		var decimals = "";
		for(var i=0;i<decimal_points;i++) decimals += "0";
		return "0."+decimals;
	}

	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)

}

