function process_car_form(whichpage)
{
	//useful variables
	var today = new Date();
	var thecookie = ( fetch_cookie('car_form') ? fetch_cookie('car_form').split('|') : new Array() );
	today.setDate(today.getDate() + 7); //7 days from now

	//pull values from everything
	var pickup = fetch_object('pickup');
	var pickup_val = pickup.options[pickup.selectedIndex].value;
	var dropoff = fetch_object('dropoff');
	var dropoff_val = dropoff.options[dropoff.selectedIndex].value;
	var pickup_date = fetch_object('pickup_date');
	var pickup_day_val = pickup_date.value;
	var pickup_time = fetch_object('pickup_time');
	var pickup_time_val = pickup_time.options[pickup_time.selectedIndex].value;
	var dropoff_date = fetch_object('dropoff_date');
	var dropoff_day_val = dropoff_date.value;
	var dropoff_time = fetch_object('dropoff_time');
	var dropoff_time_val = dropoff_time.options[dropoff_time.selectedIndex].value;
	var category = fetch_object('category');
	var category_val = category.options[category.selectedIndex].value;
	var rent_company = fetch_object('rent_company');
	var rent_company_val = rent_company.options[rent_company.selectedIndex].value;

	var pickup_txt = fetch_object('pickup_txt');
	var dropoff_txt = fetch_object('dropoff_txt');

	//detected back button, use cookie values
	if (pickup_val == '???' && thecookie[2] && thecookie[0])
	{
		pickup_val = ( thecookie[2] == pickup_txt.value ? thecookie[0] : '???' );

		if (pickup_val == '???')
		{
			var agree = confirm("You have recently selected to pick up from " + thecookie[2] + ". Would you like to use this location again?");

			if (agree)
			{
				pickup_val = thecookie[0];
				pickup_txt.value = thecookie[2];
			}
			else
			{
				pickup_txt.focus();

				if (pickup_txt.value == '')
				{
					return false;
				}
			}
		}

		pickup.options[pickup.selectedIndex].value = pickup_val;
	}
	if (dropoff_val == '???' && thecookie[3] && thecookie[1])
	{
		dropoff_val = ( thecookie[3] == dropoff_txt.value ? thecookie[1] : '???' );

		if (dropoff_val == '???')
		{
			var agree = confirm("You have recently selected to drop off at " + thecookie[3] + ". Would you like to use this location again?");

			if (agree)
			{
				dropoff_val = thecookie[1];
				dropoff_txt.value = thecookie[3];
			}
			else
			{
				dropoff_txt.focus();

				if (dropoff_txt.value == '')
				{
					return false;
				}
			}
		}

		dropoff.options[dropoff.selectedIndex].value = dropoff_val;
	}

	//make sure valid values in depart and arrive, and that they are different
	if (pickup_val == '' || pickup_val == null || pickup_val == '???' || pickup_txt.value == '')
	{
		alert("Please enter a valid Pickup Location.\n");
		return false;
	}
	if (dropoff_val == '' || dropoff_val == null || dropoff_val == '???' || dropoff_txt.value == '')
	{
		alert("Please enter a valid Dropoff Location.\n");
		return false;
	}

	//send it off to be recorded
	com = new vB_AJAX_Handler(true);
	com.send('http://www.cheapticketscanada.com/forum/form_record.php', 'rec_type=car&searchform=' + whichpage + '&pickup=' + pickup_val + '&dropoff=' + dropoff_val + '&dateleave=' + pickup_day_val + '&timeleave=' + pickup_time_val + '&datereturn=' + dropoff_day_val + '&timereturn=' + dropoff_time_val + '&category=' + category_val + '&rentcompany=' + rent_company_val);

	//create cookies
	thecookie[0] = pickup_val;
	thecookie[1] = dropoff_val;
	thecookie[2] = pickup_txt.value;
	thecookie[3] = dropoff_txt.value;
	thecookie[4] = pickup_day_val;
	thecookie[5] = dropoff_day_val;
	thecookie[6] = pickup_time.selectedIndex;
	thecookie[7] = dropoff_time.selectedIndex;
	thecookie[8] = category.selectedIndex;
	thecookie[9] = rent_company.selectedIndex;

	set_cookie('car_form', thecookie.join('|'), today);

	//swap onto the hidden vars for proper formatting
	fetch_object('pickup_datetime').value = pickup_day_val + ' ' + pickup_time_val + ':00';
	fetch_object('dropoff_datetime').value = dropoff_day_val + ' ' + dropoff_time_val + ':00';

	return true;
}

function init_car_form()
{
	var thecookie = ( fetch_cookie('car_form') ? fetch_cookie('car_form').split('|') : new Array('???', '???', '', '', '1970-1-1', '1970-1-1', 12, 12, 0, 0, 0) );
	fetch_object('pickup_txt').value = thecookie[2];
	fetch_object('dropoff_txt').value = thecookie[3];
	fetch_object('pickup').selectedIndex = 0;
	fetch_object('dropoff').selectedIndex = 0;
	var today = new Date();
	var daybits = thecookie[4].split('-');
	daybits[1] = ( daybits[1].indexOf('0') == 0 ? daybits[1].substr(1) - 1 : daybits[1] - 1 );
	daybits[2] = ( daybits[2].indexOf('0') == 0 ? daybits[2].substr(1) : daybits[2] );
	var com_day = new Date();
	com_day.setFullYear(daybits[0], daybits[1], daybits[2]);

	if (com_day > today)
	{
		today = com_day;
	}
	else
	{
		today.setDate(today.getDate() + 7);
	}

	var pickup_date = fetch_object('pickup_date');
//	pickup_date.readOnly = true;
	pickup_date.value = today.getFullYear() + '-' + ( (today.getMonth() + 1) < 10 ? '0' : '' ) + (today.getMonth() + 1) + '-' + ( today.getDate() < 10 ? '0' : '' ) + today.getDate();		
	daybits = thecookie[5].split('-');
	daybits[1] = ( daybits[1].indexOf('0') == 0 ? daybits[1].substr(1) - 1 : daybits[1] - 1 );
	daybits[2] = ( daybits[2].indexOf('0') == 0 ? daybits[2].substr(1) : daybits[2] );
	com_day = new Date();
	com_day.setFullYear(daybits[0], daybits[1], daybits[2]);

	if (com_day > today)
	{
		today = com_day;
	}
	else
	{
		today.setDate(today.getDate() + 7);
	}

	var dropoff_date = fetch_object('dropoff_date');
//	dropoff_date.readOnly = true;
	dropoff_date.value = today.getFullYear() + '-' + ( (today.getMonth() + 1) < 10 ? '0' : '' ) + (today.getMonth() + 1) + '-' + ( today.getDate() < 10 ? '0' : '' ) + today.getDate();

	fetch_object('pickup_time').selectedIndex = thecookie[6];
	fetch_object('dropoff_time').selectedIndex = thecookie[7];
	fetch_object('category').selectedIndex = thecookie[8];
	fetch_object('rent_company').selectedIndex = thecookie[9];
	
	fetch_object('pickup_txt').disabled = true;
	fetch_object('pickup_date').disabled = true;
	fetch_object('dropoff_txt').disabled = true;
	fetch_object('dropoff_date').disabled = true;
	fetch_object('pickup').disabled = true;
	fetch_object('pickup_time').disabled = true;
	fetch_object('dropoff').disabled = true;
	fetch_object('dropoff_time').disabled = true;
	fetch_object('rent_company').disabled = true;
	fetch_object('category').disabled = true;
	fetch_object('car_button').disabled = true;

	if (document.referrer == '')
	{
		car_enable()
	}
}

function swap_car_pickup()
{
	var dropoff = fetch_object('dropoff');
	var pickup = fetch_object('pickup');
	fetch_object('dropoff_txt').value = fetch_object('pickup_txt').value;
	fetch_object('dropoff').options[0].text = fetch_object('pickup').options[0].text;
	fetch_object('dropoff').options[0].value = fetch_object('pickup').options[0].value;
}

function car_enable()
{
	fetch_object('car_select_out').checked = true;
	fetch_object('pick_message').style.display = 'none';

	fetch_object('pickup_txt').disabled = false;
	fetch_object('pickup_date').disabled = false;
	fetch_object('dropoff_txt').disabled = false;
	fetch_object('dropoff_date').disabled = false;
	fetch_object('pickup').disabled = false;
	fetch_object('pickup_time').disabled = false;
	fetch_object('dropoff').disabled = false;
	fetch_object('dropoff_time').disabled = false;
	fetch_object('rent_company').disabled = false;
	fetch_object('category').disabled = false;
	fetch_object('car_button').disabled = false;
}