function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return true;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

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);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
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)?'':'-') + 'Total: $AUD ' + num + '.' + cents);
}

function calcTotal()
{
//prices
var mag_current_price = 8.50;
var mag_previous_price = 5.44;
var mag_sub_1yr_price = 32.00;
var mag_sub_2yr_price = 56.00;
var days_perth_price = 12.95;
var weekends_perth_price = 19.95;
var holland_track_price = 12.95;
var holland_track_gps_price = 24.95;
var days_melbourne_price = 10.95;
var days_melbourne_gps_price = 24.95;
var days_goldfields_price = 17.95;
var days_south_coast_wa_price = 17.95;
var days_wheel_cover_price = 32.5;
var explore_pilbara_price = 19.95;
var cc_fee_amex = 103.5;
var cc_fee_visa = 103.5;
var cc_fee_bankcard = 103.5;
var cc_fee_diners = 103.5;
var cc_fee_mastercard = 103.5;

//$5.50 shipping
var totalAmount = 0.0;
var freightAmount = 0.0;

//Added the following to give free shipping to WA subscribers.
//9/11/2004
//Christian Inkster for Haymarket. (I didnt write(?) any of the other code :P)
if((((document.forms[0].Subscription_4wd_2yr_Quantity.value!='') && (document.forms[0].Subscription_4wd_2yr_Quantity.value!='0'))|| 
((document.forms[0].Subscription_4wd_1yr_Quantity.value!='') && 
(document.forms[0].Subscription_4wd_1yr_Quantity.value!='0')))&&
(document.forms[0].Ecom_ShipTo_Postal_StateProv.options[document.forms[0].Ecom_ShipTo_Postal_StateProv.selectedIndex].value == 'WA') ){
	freightAmount = 0.0;
	freightdiv = document.getElementById('freight');
	freightdiv.style.marginLeft = '-1000em';
}
else {
	freightAmount = 5.5;
	freightdiv = document.getElementById('freight');
	freightdiv.style.marginLeft = '0em';
}

if(document.forms[0].Current_4wd_Quantity.value!='' && document.forms[0].Current_4wd_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Current_4wd_Quantity.value * mag_current_price)
}

if(document.forms[0].Subscription_4wd_1yr_Quantity.value!='' && document.forms[0].Subscription_4wd_1yr_Quantity.value!='0')
{
totalAmount = totalAmount + (document.forms[0].Subscription_4wd_1yr_Quantity.value * mag_sub_1yr_price);
}

if(document.forms[0].Subscription_4wd_2yr_Quantity.value!='' && document.forms[0].Subscription_4wd_2yr_Quantity.value!='0')
{
totalAmount = totalAmount + (document.forms[0].Subscription_4wd_2yr_Quantity.value * mag_sub_2yr_price);
}

var checkcount = 0;
	for (i=0 ; i<document.forms[0].elements['Previous_4wd_Numbers[]'].length ; i++) {
		
		if (document.forms[0].elements['Previous_4wd_Numbers[]'][i].checked) {
			checkcount = checkcount +1;
		}
	}
	
if(checkcount != 0) {
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
};
document.forms[0].Previous_4wd_Quantity.value = checkcount;

totalAmount = totalAmount + (checkcount * mag_previous_price);

if(document.forms[0].Days_Perth_Quantity.value!='' && document.forms[0].Days_Perth_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Days_Perth_Quantity.value * days_perth_price);
}

//if(document.forms[0].Weekends_Perth_Quantity.value!='' && document.forms[0].Weekends_Perth_Quantity.value!='0')
//{
//totalAmount = totalAmount + (document.forms[0].Weekends_Perth_Quantity.value * weekends_perth_price)
//}

if(document.forms[0].Weekends_Perth_Quantity.value!='' && document.forms[0].Weekends_Perth_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Weekends_Perth_Quantity.value * weekends_perth_price);
}

if(document.forms[0].Holland_Track_Quantity.value!='' && document.forms[0].Holland_Track_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Holland_Track_Quantity.value * holland_track_price);
}

if(document.forms[0].Holland_Track_GPS_Quantity.value!='' && document.forms[0].Holland_Track_GPS_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Holland_Track_GPS_Quantity.value * holland_track_gps_price);
}

if(document.forms[0].Days_Melbourne_Quantity.value!='' && document.forms[0].Days_Melbourne_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Days_Melbourne_Quantity.value * days_melbourne_price);
}

if(document.forms[0].Days_Melbourne_GPS_Quantity.value!='' && document.forms[0].Days_Melbourne_GPS_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Days_Melbourne_GPS_Quantity.value * days_melbourne_gps_price);
}

if(document.forms[0].Days_Goldfields_Quantity.value!='' && document.forms[0].Days_Goldfields_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Days_Goldfields_Quantity.value * days_goldfields_price);
}

if(document.forms[0].Days_South_Coast_WA_Quantity.value!='' && document.forms[0].Days_South_Coast_WA_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Days_South_Coast_WA_Quantity.value * days_south_coast_wa_price);
}

if(document.forms[0].Explore_Pilbara_Quantity.value!='' && document.forms[0].Explore_Pilbara_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Explore_Pilbara_Quantity.value * explore_pilbara_price);
}

if(document.forms[0].Wheel_Cover_Quantity.value!='' && document.forms[0].Wheel_Cover_Quantity.value!='0')
{
freightAmount = 5.5;
freightdiv = document.getElementById('freight');
freightdiv.style.marginLeft = '0em';
totalAmount = totalAmount + (document.forms[0].Wheel_Cover_Quantity.value * days_wheel_cover_price);
}

//document.forms[0].Total.value = formatCurrency(totalAmount + freightAmount);

if (freightAmount == 0.0) {
	creditchargediv = document.getElementById('creditcharge');
	creditchargediv.style.marginLeft = '0em';
	document.forms[0].Total.value = formatCurrency(totalAmount *1.035);
} else {
	creditchargediv = document.getElementById('creditcharge');
	// creditchargediv.style.marginLeft = '-1000em';
	// document.forms[0].Total.value = formatCurrency(totalAmount + freightAmount);
	creditchargediv.style.marginLeft = '0em';
	document.forms[0].Total.value = formatCurrency(totalAmount *1.035);

}

}

