arrCostPerDay      = new Array();
arrCostPerDay[1]  = 10;
arrCostPerDay[2]  = 15;
arrCostPerDay[3]  = 18;
arrCostPerDay[4]  = 20;
arrCostPerDay[5]  = 25;
arrCostPerDay[6]  = 30;
arrCostPerDay[7]  = 33;
arrCostPerDay[8]  = 36;
arrCostPerDay[9]  = 39;
arrCostPerDay[10] = 40;

arrCostPerDay[11] = 42;
arrCostPerDay[12] = 43;
arrCostPerDay[13] = 44;
arrCostPerDay[14] = 46;
arrCostPerDay[15] = 47;
arrCostPerDay[16] = 48;
arrCostPerDay[17] = 48;
arrCostPerDay[18] = 49;
arrCostPerDay[19] = 50;
arrCostPerDay[20] = 50;

arrCostPerDay[21] = 52;
arrCostPerDay[22] = 52;
arrCostPerDay[23] = 53;
arrCostPerDay[24] = 54;
arrCostPerDay[25] = 55;
arrCostPerDay[26] = 56;
arrCostPerDay[27] = 57;
arrCostPerDay[28] = 60;
arrCostPerDay[29] = 62;
arrCostPerDay[30] = 63;
arrCostPerDay[31] = 65;

floCostPerMonthDay  = 2;

arrCostPerMonth     = new Array();
arrCostPerMonth[1]  = 65;
arrCostPerMonth[2]  = 100;
arrCostPerMonth[3]  = 145;
arrCostPerMonth[4]  = 160;
arrCostPerMonth[5]  = 180;
arrCostPerMonth[6]  = 200;
arrCostPerMonth[7]  = 0;
arrCostPerMonth[8]  = 0;
arrCostPerMonth[9]  = 0;
arrCostPerMonth[10] = 0;
arrCostPerMonth[11] = 0;
arrCostPerMonth[12] = 300;
arrCostPerMonth[13] = 300;

arrVehicleType      = new Array();
arrVehicleType['car'] = 1;
arrVehicleType['van'] = 1.2;

arrDaysPerMonth     = new Array(31,28,31,30,31,30,31,31,30,31,30,31)

var floParkingCost    = 0;

function lUpdateCost()
{
	
	objDocument  = parent.document.quoteform;

	objStartDate = objDocument.dc1;
	strStartDate = objStartDate.value;

	objEndDate   = objDocument.dc2;
	strEndDate   = objEndDate.value;
	

	// If the user hasn't picked both dates yet its a wee bit hard to see if they are going outside of the range!
	if(strStartDate == 'dd/mm/yyyy' || strEndDate == 'dd/mm/yyyy')
	{
		Hide('parkingCost');
		return false;
	}

	arrStartDate = strStartDate.split('/');
	arrEndDate   = strEndDate.split('/');
	
	objDate    = new Date();
	objDate.setDate(arrStartDate[0]);
	objDate.setMonth(arrStartDate[1]-1);
	objDate.setFullYear(arrStartDate[2]);
	
	floMSStart = objDate.getTime();
	
	objDate.setDate(arrEndDate[0]);
	objDate.setMonth(arrEndDate[1]-1);
	objDate.setFullYear(arrEndDate[2]);
	floMSEnd   = objDate.getTime();
	
	// Sanity Check 1 - Come back AFTER we've left NOT before
	if(floMSEnd < floMSStart)
	{
		objEndDate.value = 'dd/mm/yyyy';
		alert('Return date must come after departure date');
		Hide('parkingCost');
		return false;
	}

	intDays       = parseInt(document.notused.days.value);
	intMonths     = parseInt(document.notused.months.value);
	
	// Modifer for times...
	strStartTime  = document.quoteform.departtime.value;
	intStartMins  = parseInt(strStartTime.substring(0,2)) * 60;
	if(strStartTime.substring(0,1) == '0')
	{
		intStartMins = parseInt(strStartTime.substring(1,2)) * 60;
	}
	intStartMins += parseInt(strStartTime.substring(3));

	strEndTime    = document.quoteform.returntime.value;
	intEndMins    = parseInt(strEndTime.substring(0,2)) * 60;
	if(strEndTime.substring(0,1) == '0')
	{
		intEndMins = parseInt(strEndTime.substring(1,2)) * 60;
	}
	intEndMins   += parseInt(strEndTime.substring(3));
	
	// Have we just spanned another day?
	if(intEndMins > intStartMins)
	{
		++intDays;
	}
	
	floCost = 0;
	if(intMonths > 0)
	{
		for (intCurrentMonth in arrCostPerMonth)
		{
			if(intCurrentMonth <= intMonths && arrCostPerMonth[intCurrentMonth] > 0)
			{
				floCost  = arrCostPerMonth[intCurrentMonth];
			}
		}
	}
	
	// We need to modify for months that are 7-11... by adding the number of days in our previous month(s) to it...
	if(arrCostPerMonth[intMonths] == 0)
	{
		if(intMonths == 1)
		{
			intDays += arrDaysPerMonth[11];
		}
		else
		{
			intDays += arrDaysPerMonth[intMonths-2];
		}
	}
	
	
	if(intDays > 0)
	{
		if(intMonths == 0)
		{
			floCost += arrCostPerDay[intDays];
		}
		else
		{
			floCost += intDays * floCostPerMonthDay;
		}
	}
	
	// Now check to see if the cost > advancing a month and use that instead
	for (intCurrentMonth in arrCostPerMonth)
	{
		if(intCurrentMonth > intMonths)
		{
			if(arrCostPerMonth[intCurrentMonth] < floCost && arrCostPerMonth[intCurrentMonth] > 0)
			{
				floCost = arrCostPerMonth[intCurrentMonth];
			}
		}
	}
	
	strVehicleType = document.quoteform.vehicle.value;
	floShowCost    = floCost * arrVehicleType[strVehicleType];

	/*
		Rounding
	*/
	floShowCost    = Math.ceil(parseInt(floShowCost*100)/100);

	document.quoteform.cost.value=floShowCost;
}
