
// globals
var gIsStepValid = false;
//-------------------------------------------------------------
// Handle validating user input data on this form, before the form
// is sent to the backend for real processing...
//-------------------------------------------------------------
function initializeForm()
{
	//alert( 'initializeForm() is working' );
	
	changedInput();
	
}
//-------------------------------------------------------------
// Validates the inputs on the form, and if all is ok, enables the Next button
//-------------------------------------------------------------
function changedInput()
{
	gIsStepValid = true;
	
	
	var pickupVal = document.getElementById( 'pickupDropMenu' ).value;
	var pickupDayVal = document.getElementById( 'pickupDay' ).value;
	var pickupMonthVal = document.getElementById( 'pickupMonth' ).value;
	var pickupYearVal = document.getElementById( 'pickupYear' ).value;
	var pickupTimeVal = document.getElementById( 'pickupTime' ).value;
	
	var dropoffVal = document.getElementById( 'dropoffDropMenu' ).value;
	var dropoffDayVal = document.getElementById( 'dropoffDay' ).value;
	var dropoffMonthVal = document.getElementById( 'dropoffMonth' ).value;
	var dropoffYearVal = document.getElementById( 'dropoffYear' ).value;
	
	// Check for valid inputs.
	if ( pickupVal == '-' || dropoffVal == '-' ) {			// Location
		gIsStepValid = false;
	}
	if ( pickupDayVal == '-' || dropoffDayVal == '-' ) {	// Days
		gIsStepValid = false;
	}
	if ( pickupMonthVal == '-' || dropoffMonthVal == '-' ) {	// Days
		gIsStepValid = false;
	}
	if ( pickupYearVal == '-' || dropoffYearVal == '-' ) {	// Days
		gIsStepValid = false;
	}
	if ( pickupTimeVal == '0' ) {							// Pickup Time.
		gIsStepValid = false;
	}
	
	setNextButtonEnabled( gIsStepValid );
	
}
//-------------------------------------------------------------
// Copies the value from Pickup to Dropoff, and then validates form.
//-------------------------------------------------------------
function changedPickupInput()
{
	//alert( 'changedInput() is working' );
	var pickupMenu = document.getElementById( 'pickupDropMenu' );
	var dropoffMenu = document.getElementById( 'dropoffDropMenu' );
	dropoffMenu.value = pickupMenu.value;
	
	changedInput();
	
}
//-------------------------------------------------------------
// 
//-------------------------------------------------------------
function setNextButtonEnabled( enabledFlag )
{
	// If all the dropdown menus are set to Zero, then disable the Next... button.
	var btnNext = document.getElementById( 'submit' );
	//alert( 'enabledFlag: ' + enabledFlag );
	if ( !enabledFlag ) {
		btnNext.disabled = true;
		removeClassName ( btnNext, 'continueBtn' + gLangFileExt );
		addClassName ( btnNext, 'continueBtnDisabled' + gLangFileExt );
	} else {
		btnNext.disabled = false;
		removeClassName ( btnNext, 'continueBtnDisabled' + gLangFileExt );
		addClassName ( btnNext, 'continueBtn' + gLangFileExt );
	}
	
	
}
//-------------------------------------------------------------
// Handle validating user input data on this form, before the form
// is sent to the backend for real processing...
//-------------------------------------------------------------
function updateCurrency()
{
	//alert( 'changeCurrency() is working' );
	var form = document.getElementById( 'carDetailsForm' );
	var hiddenCurrField = document.getElementById( 'autoCurrencyUpdate' );
	
	// Disable the next button while the page updates.
	setNextButtonEnabled( false );
	
	// update the value of the hidden field that controls whether or not
	// the submitted form acts as a Currency updater or just normal add to 
	// basket...
	hiddenCurrField.value = 'yes';
	
	form.submit();
	
}
